source: trunk/src/comdlg32/filedlg.c@ 5280

Last change on this file since 5280 was 4942, checked in by sandervl, 25 years ago

misc comdlg fixes

File size: 54.6 KB
Line 
1/*
2 * COMMDLG - File Dialogs
3 *
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
7#include <ctype.h>
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11#include "windef.h"
12#include "winnls.h"
13#include "winbase.h"
14#include "wingdi.h"
15#include "wine/winbase16.h"
16#include "wine/winuser16.h"
17#include "wine/unicode.h"
18#include "heap.h"
19#include "commdlg.h"
20#include "debugtools.h"
21#include "cderr.h"
22
23#ifdef __WIN32OS2__
24#include <win\cursoricon.h>
25
26#define GlobalFree16 GlobalFree
27#define GlobalLock16 GlobalLock
28#define GlobalUnlock16 GlobalUnlock
29#define GlobalAlloc16 GlobalAlloc
30#define FreeResource16 FreeResource
31#define LoadResource16 LoadResourceA
32#define FindResource16 FindResourceA
33#define MapSL(a) a
34#define CallWindowProc16 CallWindowProcA
35
36#endif
37
38DEFAULT_DEBUG_CHANNEL(commdlg);
39
40#include "cdlg.h"
41
42#define BUFFILE 512
43#define BUFFILEALLOC 512 * sizeof(WCHAR)
44
45struct FSPRIVATE
46{
47 HWND hwnd; /* file dialog window handle */
48 BOOL hook; /* TRUE if the dialog is hooked */
49 UINT lbselchstring; /* registered message id */
50 UINT fileokstring; /* registered message id */
51 LPARAM lParam; /* save original lparam */
52#ifdef __WIN32OS2__
53 HANDLE hDlgTmpl16; /* handle for resource 16 */
54 HANDLE hResource16; /* handle for allocated resource 16 */
55 HANDLE hGlobal16; /* 16 bits mem block (resources) */
56#else
57 HANDLE16 hDlgTmpl16; /* handle for resource 16 */
58 HANDLE16 hResource16; /* handle for allocated resource 16 */
59 HANDLE16 hGlobal16; /* 16 bits mem block (resources) */
60#endif
61 LPCVOID template; /* template for 32 bits resource */
62 BOOL open; /* TRUE if open dialog, FALSE if save dialog */
63 OPENFILENAMEW *ofnW; /* original structure or work struct */
64 OPENFILENAMEA *ofnA; /* original structure if 32bits ansi dialog */
65#ifndef __WIN32OS2__
66 OPENFILENAME16 *ofn16; /* original structure if 16 bits dialog */
67#endif
68};
69
70
71#define LFSPRIVATE struct FSPRIVATE *
72
73#define LFS16 1
74#define LFS32A 2
75#define LFS32W 3
76
77static const WCHAR FILE_star[] = {'*','.','*', 0};
78static const WCHAR FILE_bslash[] = {'\\', 0};
79static const WCHAR FILE_specc[] = {'%','c',':', 0};
80
81#ifdef __WIN32OS2__
82static HICON hFolder = 0;
83static HICON hFolder2 = 0;
84static HICON hFloppy = 0;
85static HICON hHDisk = 0;
86static HICON hCDRom = 0;
87static HICON hNet = 0;
88#else
89static HICON16 hFolder = 0;
90static HICON16 hFolder2 = 0;
91static HICON16 hFloppy = 0;
92static HICON16 hHDisk = 0;
93static HICON16 hCDRom = 0;
94static HICON16 hNet = 0;
95#endif
96static int fldrHeight = 0;
97static int fldrWidth = 0;
98
99#define OFN_PROP "FILEDLG_OFN"
100
101static const char defaultfilter[]=" \0\0";
102static char defaultopen[]="Open File";
103static char defaultsave[]="Save as";
104
105/***********************************************************************
106 *
107 * Windows 3.1 style OpenFileName/SaveFileName dialog
108 *
109 */
110
111LRESULT WINAPI FileOpenDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
112 LPARAM lParam);
113LRESULT WINAPI FileSaveDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
114 LPARAM lParam);
115
116static LRESULT WINAPI FileOpenDlgProc(HWND hDlg, UINT msg,
117 WPARAM wParam, LPARAM lParam);
118
119/***********************************************************************
120 * FileDlg_Init [internal]
121 */
122static BOOL FileDlg_Init(void)
123{
124 static BOOL initialized = 0;
125 CURSORICONINFO *fldrInfo;
126
127 if (!initialized) {
128#ifdef __WIN32OS2__
129 if (!hFolder) hFolder = LoadImageA(0, MAKEINTRESOURCEA(OIC_FOLDER), IMAGE_ICON, 16, 16, LR_SHARED);
130 if (!hFolder2) hFolder2 = LoadImageA(0, MAKEINTRESOURCEA(OIC_FOLDER2), IMAGE_ICON, 16, 16, LR_SHARED);
131 if (!hFloppy) hFloppy = LoadImageA(0, MAKEINTRESOURCEA(OIC_FLOPPY), IMAGE_ICON, 16, 16, LR_SHARED);
132 if (!hHDisk) hHDisk = LoadImageA(0, MAKEINTRESOURCEA(OIC_HDISK), IMAGE_ICON, 16, 16, LR_SHARED);
133 if (!hCDRom) hCDRom = LoadImageA(0, MAKEINTRESOURCEA(OIC_CDROM), IMAGE_ICON, 16, 16, LR_SHARED);
134 if (!hNet) hNet = LoadImageA(0, MAKEINTRESOURCEA(OIC_NETWORK), IMAGE_ICON, 16, 16, LR_SHARED);
135#else
136 if (!hFolder) hFolder = LoadIconA(0, MAKEINTRESOURCEA(OIC_FOLDER));
137 if (!hFolder2) hFolder2 = LoadIconA(0, MAKEINTRESOURCEA(OIC_FOLDER2));
138 if (!hFloppy) hFloppy = LoadIconA(0, MAKEINTRESOURCEA(OIC_FLOPPY));
139 if (!hHDisk) hHDisk = LoadIconA(0, MAKEINTRESOURCEA(OIC_HDISK));
140 if (!hCDRom) hCDRom = LoadIconA(0, MAKEINTRESOURCEA(OIC_CDROM));
141 if (!hNet) hNet = LoadIconA(0, MAKEINTRESOURCEA(OIC_NETWORK));
142#endif
143 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
144 hHDisk == 0 || hCDRom == 0 || hNet == 0)
145 {
146 ERR("Error loading icons !\n");
147 return FALSE;
148 }
149 fldrInfo = (CURSORICONINFO *) GlobalLock16( hFolder2 );
150 if (!fldrInfo)
151 {
152 ERR("Error measuring icons !\n");
153 return FALSE;
154 }
155 fldrHeight = fldrInfo -> nHeight;
156 fldrWidth = fldrInfo -> nWidth;
157 GlobalUnlock16( hFolder2 );
158 initialized = TRUE;
159 }
160 return TRUE;
161}
162
163
164/***********************************************************************
165 * Get32BitsTemplate [internal]
166 *
167 * Get a template (or FALSE if failure) when 16 bits dialogs are used
168 * by a 32 bits application
169 *
170 */
171BOOL Get32BitsTemplate(LFSPRIVATE lfs)
172{
173 LPOPENFILENAMEW ofnW = lfs->ofnW;
174 HANDLE hDlgTmpl;
175
176 if (ofnW->Flags & OFN_ENABLETEMPLATEHANDLE)
177 {
178 if (!(lfs->template = LockResource( ofnW->hInstance )))
179 {
180 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
181 return FALSE;
182 }
183 }
184 else if (ofnW->Flags & OFN_ENABLETEMPLATE)
185 {
186 HANDLE hResInfo;
187 if (lfs->ofnA)
188 hResInfo = FindResourceA(lfs->ofnA->hInstance,
189 lfs->ofnA->lpTemplateName,
190 RT_DIALOGA);
191 else
192 hResInfo = FindResourceW(ofnW->hInstance,
193 ofnW->lpTemplateName,
194 RT_DIALOGW);
195 if (!hResInfo)
196 {
197 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
198 return FALSE;
199 }
200 if (!(hDlgTmpl = LoadResource(ofnW->hInstance,
201 hResInfo)) ||
202 !(lfs->template = LockResource(hDlgTmpl)))
203 {
204 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
205 return FALSE;
206 }
207 } else { /* get it from internal Wine resource */
208 HANDLE hResInfo;
209 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
210 lfs->open? "OPEN_FILE":"SAVE_FILE", RT_DIALOGA)))
211 {
212 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
213 return FALSE;
214 }
215 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
216 !(lfs->template = LockResource( hDlgTmpl )))
217 {
218 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
219 return FALSE;
220 }
221 }
222 return TRUE;
223}
224
225#ifndef __WIN32OS2__
226/***********************************************************************
227 * Get16BitsTemplate [internal]
228 *
229 * Get a template (FALSE if failure) when 16 bits dialogs are used
230 * by a 16 bits application
231 *
232 */
233BOOL Get16BitsTemplate(LFSPRIVATE lfs)
234{
235 LPOPENFILENAME16 ofn16 = lfs->ofn16;
236 LPCVOID template;
237 HGLOBAL16 hGlobal16 = 0;
238
239 if (ofn16->Flags & OFN_ENABLETEMPLATEHANDLE)
240 lfs->hDlgTmpl16 = ofn16->hInstance;
241 else if (ofn16->Flags & OFN_ENABLETEMPLATE)
242 {
243 HANDLE16 hResInfo;
244 if (!(hResInfo = FindResource16(ofn16->hInstance,
245 MapSL(ofn16->lpTemplateName),
246 RT_DIALOGA)))
247 {
248 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
249 return FALSE;
250 }
251 if (!(lfs->hDlgTmpl16 = LoadResource16( ofn16->hInstance, hResInfo )))
252 {
253 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
254 return FALSE;
255 }
256 lfs->hResource16 = lfs->hDlgTmpl16;
257 }
258 else
259 { /* get resource from (32 bits) own Wine resource; convert it to 16 */
260 HANDLE hResInfo, hDlgTmpl32;
261 LPCVOID template32;
262 DWORD size;
263
264 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32,
265 lfs->open ? "OPEN_FILE":"SAVE_FILE", RT_DIALOGA)))
266 {
267 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
268 return FALSE;
269 }
270 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
271 !(template32 = LockResource( hDlgTmpl32 )))
272 {
273 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
274 return FALSE;
275 }
276 size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo);
277 hGlobal16 = GlobalAlloc16(0, size);
278 if (!hGlobal16)
279 {
280 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
281 ERR("alloc failure for %ld bytes\n", size);
282 return FALSE;
283 }
284 template = GlobalLock16(hGlobal16);
285 if (!template)
286 {
287 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
288 ERR("global lock failure for %x handle\n", hGlobal16);
289 GlobalFree16(hGlobal16);
290 return FALSE;
291 }
292 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
293 lfs->hDlgTmpl16 = hGlobal16;
294 lfs->hGlobal16 = hGlobal16;
295 }
296 return TRUE;
297}
298#endif
299
300/***********************************************************************
301 * FILEDLG_StripEditControl [internal]
302 * Strip pathnames off the contents of the edit control.
303 */
304static void FILEDLG_StripEditControl(HWND hwnd)
305{
306 WCHAR temp[BUFFILE], *cp;
307
308 GetDlgItemTextW( hwnd, edt1, temp, sizeof(temp)/sizeof(WCHAR));
309 cp = strrchrW(temp, '\\');
310 if (cp != NULL) {
311 strcpyW(temp, cp+1);
312 }
313 cp = strrchrW(temp, ':');
314 if (cp != NULL) {
315 strcpyW(temp, cp+1);
316 }
317 /* FIXME: shouldn't we do something with the result here? ;-) */
318}
319
320
321
322/***********************************************************************
323 * FILEDLG_CallWindowProc [internal]
324 *
325 * Call the appropriate hook
326 */
327static BOOL FILEDLG_CallWindowProc(LFSPRIVATE lfs, UINT wMsg, WPARAM wParam,
328 LPARAM lParam)
329{
330#ifndef __WIN32OS2__
331 if (lfs->ofn16)
332 {
333 return (BOOL16) CallWindowProc16(
334 (WNDPROC16)lfs->ofn16->lpfnHook, lfs->hwnd,
335 (UINT16)wMsg, (WPARAM16)wParam, lParam);
336 }
337#endif
338 if (lfs->ofnA)
339 {
340 return (BOOL) CallWindowProcA(
341 (WNDPROC)lfs->ofnA->lpfnHook, lfs->hwnd,
342 wMsg, wParam, lParam);
343 }
344
345 if (lfs->ofnW)
346 {
347 return (BOOL) CallWindowProcW(
348 (WNDPROC)lfs->ofnW->lpfnHook, lfs->hwnd,
349 wMsg, wParam, lParam);
350 }
351 return FALSE;
352}
353
354
355/***********************************************************************
356 * FILEDLG_ScanDir [internal]
357 */
358static BOOL FILEDLG_ScanDir(HWND hWnd, LPWSTR newPath)
359{
360 WCHAR buffer[BUFFILE];
361 HWND hdlg, hdlgDir;
362 LRESULT lRet = TRUE;
363 HCURSOR hCursorWait, oldCursor;
364
365 if ( !SetCurrentDirectoryW( newPath ))
366 return FALSE;
367 lstrcpynW(buffer, newPath, sizeof(buffer)/sizeof(WCHAR));
368
369 /* get the list of spec files */
370 GetDlgItemTextW(hWnd, edt1, buffer, sizeof(buffer)/sizeof(WCHAR));
371
372 hCursorWait = LoadCursorA(0, IDC_WAITA);
373 oldCursor = SetCursor(hCursorWait);
374
375 /* list of files */
376 if ((hdlg = GetDlgItem(hWnd, lst1)) != 0) {
377 WCHAR* scptr; /* ptr on semi-colon */
378 WCHAR* filter = buffer;
379
380 TRACE("Using filter %s\n", debugstr_w(filter));
381 SendMessageW(hdlg, LB_RESETCONTENT, 0, 0);
382 while (filter) {
383 scptr = strchrW(filter, ';');
384 if (scptr) *scptr = 0;
385 while (*filter == ' ') filter++;
386 TRACE("Using file spec %s\n", debugstr_w(filter));
387 if (SendMessageW(hdlg, LB_DIR, 0, (LPARAM)filter) == LB_ERR)
388 return FALSE;
389 if (scptr) *scptr = ';';
390 filter = (scptr) ? (scptr + 1) : 0;
391 }
392 }
393
394 /* list of directories */
395 strcpyW(buffer, FILE_star);
396
397 if ((hdlgDir = GetDlgItem(hWnd, lst2)) != 0) {
398 lRet = DlgDirListW(hWnd, buffer, lst2, stc1, DDL_EXCLUSIVE | DDL_DIRECTORY);
399 }
400 SetCursor(oldCursor);
401 return lRet;
402}
403
404
405/***********************************************************************
406 * FILEDLG_GetFileType [internal]
407 */
408
409static LPWSTR FILEDLG_GetFileType(LPWSTR cfptr, LPWSTR fptr, WORD index)
410{
411 int n, i;
412 i = 0;
413 if (cfptr)
414 for ( ;(n = lstrlenW(cfptr)) != 0; i++)
415 {
416 cfptr += n + 1;
417 if (i == index)
418 return cfptr;
419 cfptr += lstrlenW(cfptr) + 1;
420 }
421 if (fptr)
422 for ( ;(n = lstrlenW(fptr)) != 0; i++)
423 {
424 fptr += n + 1;
425 if (i == index)
426 return fptr;
427 fptr += lstrlenW(fptr) + 1;
428 }
429 return (LPWSTR) FILE_star; /* FIXME */
430}
431
432/***********************************************************************
433 * FILEDLG_WMDrawItem [internal]
434 */
435static LONG FILEDLG_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam,
436 int savedlg, LPDRAWITEMSTRUCT lpdis)
437{
438 WCHAR *str;
439 HICON hIcon;
440 COLORREF oldText = 0, oldBk = 0;
441
442 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
443 {
444 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC))) return FALSE;
445 SendMessageW(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
446 (LPARAM)str);
447
448 if ((lpdis->itemState & ODS_SELECTED) && !savedlg)
449 {
450 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
451 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
452 }
453 if (savedlg)
454 SetTextColor(lpdis->hDC,GetSysColor(COLOR_GRAYTEXT) );
455
456 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + 1,
457 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
458 &(lpdis->rcItem), str, lstrlenW(str), NULL);
459
460 if (lpdis->itemState & ODS_SELECTED)
461 DrawFocusRect( lpdis->hDC, &(lpdis->rcItem) );
462
463 if ((lpdis->itemState & ODS_SELECTED) && !savedlg)
464 {
465 SetBkColor( lpdis->hDC, oldBk );
466 SetTextColor( lpdis->hDC, oldText );
467 }
468 HeapFree(GetProcessHeap(), 0, str);
469 return TRUE;
470 }
471
472 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
473 {
474 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
475 return FALSE;
476 SendMessageW(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
477 (LPARAM)str);
478
479 if (lpdis->itemState & ODS_SELECTED)
480 {
481 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
482 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
483 }
484 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + fldrWidth,
485 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
486 &(lpdis->rcItem), str, lstrlenW(str), NULL);
487
488 if (lpdis->itemState & ODS_SELECTED)
489 DrawFocusRect( lpdis->hDC, &(lpdis->rcItem) );
490
491 if (lpdis->itemState & ODS_SELECTED)
492 {
493 SetBkColor( lpdis->hDC, oldBk );
494 SetTextColor( lpdis->hDC, oldText );
495 }
496 DrawIcon(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hFolder);
497 HeapFree(GetProcessHeap(), 0, str);
498 return TRUE;
499 }
500 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
501 {
502 char root[] = "a:";
503 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
504 return FALSE;
505 SendMessageW(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
506 (LPARAM)str);
507 root[0] += str[2] - 'a';
508 switch(GetDriveTypeA(root))
509 {
510 case DRIVE_REMOVABLE: hIcon = hFloppy; break;
511 case DRIVE_CDROM: hIcon = hCDRom; break;
512 case DRIVE_REMOTE: hIcon = hNet; break;
513 case DRIVE_FIXED:
514 default: hIcon = hHDisk; break;
515 }
516 if (lpdis->itemState & ODS_SELECTED)
517 {
518 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
519 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
520 }
521 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + fldrWidth,
522 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
523 &(lpdis->rcItem), str, lstrlenW(str), NULL);
524
525 if (lpdis->itemState & ODS_SELECTED)
526 {
527 SetBkColor( lpdis->hDC, oldBk );
528 SetTextColor( lpdis->hDC, oldText );
529 }
530 DrawIcon(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hIcon);
531 HeapFree(GetProcessHeap(), 0, str);
532 return TRUE;
533 }
534 return FALSE;
535}
536
537/***********************************************************************
538 * FILEDLG_WMMeasureItem [internal]
539 */
540static LONG FILEDLG_WMMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
541{
542 LPMEASUREITEMSTRUCT lpmeasure;
543
544 lpmeasure = (LPMEASUREITEMSTRUCT)lParam;
545 lpmeasure->itemHeight = fldrHeight;
546 return TRUE;
547}
548/***********************************************************************
549 * FILEDLG_WMMeasureItem16 [internal]
550 */
551#ifdef __WIN32OS2__
552static LONG FILEDLG_WMMeasureItem16(HWND hWnd, WPARAM wParam, LPARAM lParam)
553{
554 LPMEASUREITEMSTRUCT lpmeasure;
555
556 lpmeasure = (LPMEASUREITEMSTRUCT)lParam;
557 lpmeasure->itemHeight = fldrHeight;
558 return TRUE;
559}
560#else
561static LONG FILEDLG_WMMeasureItem16(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
562{
563 LPMEASUREITEMSTRUCT16 lpmeasure;
564
565 lpmeasure = MapSL(lParam);
566 lpmeasure->itemHeight = fldrHeight;
567 return TRUE;
568}
569#endif
570
571/***********************************************************************
572 * FILEDLG_WMInitDialog [internal]
573 */
574
575static LONG FILEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
576{
577 int i, n;
578 WCHAR tmpstr[BUFFILE];
579 LPWSTR pstr, old_pstr;
580 LPOPENFILENAMEW ofn;
581 LFSPRIVATE lfs = (LFSPRIVATE) lParam;
582
583 if (!lfs) return FALSE;
584 SetPropA(hWnd, OFN_PROP, (HANDLE)lfs);
585 lfs->hwnd = hWnd;
586 ofn = lfs->ofnW;
587
588 TRACE("flags=%lx initialdir=%s\n", ofn->Flags, debugstr_w(ofn->lpstrInitialDir));
589
590 SetWindowTextW( hWnd, ofn->lpstrTitle );
591 /* read custom filter information */
592 if (ofn->lpstrCustomFilter)
593 {
594 pstr = ofn->lpstrCustomFilter;
595 n = 0;
596 TRACE("lpstrCustomFilter = %p\n", pstr);
597 while(*pstr)
598 {
599 old_pstr = pstr;
600 i = SendDlgItemMessageW(hWnd, cmb1, CB_ADDSTRING, 0,
601 (LPARAM)(ofn->lpstrCustomFilter) + n );
602 n += lstrlenW(pstr) + 1;
603 pstr += lstrlenW(pstr) + 1;
604 TRACE("add str='%s' "
605 "associated to '%s'\n", debugstr_w(old_pstr), debugstr_w(pstr));
606 SendDlgItemMessageW(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
607 n += lstrlenW(pstr) + 1;
608 pstr += lstrlenW(pstr) + 1;
609 }
610 }
611 /* read filter information */
612 if (ofn->lpstrFilter) {
613 pstr = (LPWSTR) ofn->lpstrFilter;
614 n = 0;
615 while(*pstr) {
616 old_pstr = pstr;
617 i = SendDlgItemMessageW(hWnd, cmb1, CB_ADDSTRING, 0,
618 (LPARAM)(ofn->lpstrFilter + n) );
619 n += lstrlenW(pstr) + 1;
620 pstr += lstrlenW(pstr) + 1;
621 TRACE("add str='%s' "
622 "associated to '%s'\n", debugstr_w(old_pstr), debugstr_w(pstr));
623 SendDlgItemMessageW(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
624 n += lstrlenW(pstr) + 1;
625 pstr += lstrlenW(pstr) + 1;
626 }
627 }
628 /* set default filter */
629 if (ofn->nFilterIndex == 0 && ofn->lpstrCustomFilter == NULL)
630 ofn->nFilterIndex = 1;
631 SendDlgItemMessageW(hWnd, cmb1, CB_SETCURSEL, ofn->nFilterIndex - 1, 0);
632 lstrcpynW(tmpstr, FILEDLG_GetFileType(ofn->lpstrCustomFilter,
633 (LPWSTR)ofn->lpstrFilter, ofn->nFilterIndex - 1),BUFFILE);
634 TRACE("nFilterIndex = %ld, SetText of edt1 to '%s'\n",
635 ofn->nFilterIndex, debugstr_w(tmpstr));
636 SetDlgItemTextW( hWnd, edt1, tmpstr );
637 /* get drive list */
638 *tmpstr = 0;
639 DlgDirListComboBoxW(hWnd, tmpstr, cmb2, 0, DDL_DRIVES | DDL_EXCLUSIVE);
640 /* read initial directory */
641 if (ofn->lpstrInitialDir != NULL)
642 {
643 int len;
644 lstrcpynW(tmpstr, ofn->lpstrInitialDir, 511);
645 len = lstrlenW(tmpstr);
646 if (len > 0 && tmpstr[len-1] != '\\' && tmpstr[len-1] != ':') {
647 tmpstr[len]='\\';
648 tmpstr[len+1]='\0';
649 }
650 }
651 else
652#ifdef __WIN32OS2__
653 GetCurrentDirectoryW(BUFFILE, tmpstr);
654#else
655 *tmpstr = 0;
656#endif
657
658 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
659 *tmpstr = 0;
660 if (!FILEDLG_ScanDir(hWnd, tmpstr))
661 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr));
662 }
663 /* select current drive in combo 2, omit missing drives */
664 {
665 char dir[MAX_PATH];
666#ifdef __WIN32OS2__
667 DWORD drives;
668#endif
669 char str[4] = "a:\\";
670 GetCurrentDirectoryA( sizeof(dir), dir );
671
672#ifdef __WIN32OS2__
673 drives = GetLogicalDrives();
674
675 //Don't use GetDriveType here. Calling it for a floppy drive causes
676 //the drive to become active for a brief moment
677 for(i = 0, n = -1; i < 26; i++)
678 {
679 str[0] = 'a' + i;
680 if(drives & (1 << i)) n++;
681
682 if (toupper(str[0]) == toupper(dir[0])) break;
683 }
684#else
685 for(i = 0, n = -1; i < 26; i++)
686 {
687 str[0] = 'a' + i;
688#ifdef __WIN32OS2__
689 //bugfix
690 if (GetDriveTypeA(str) > DRIVE_NO_ROOT_DIR) n++;
691#else
692 if (GetDriveTypeA(str) <= DRIVE_NO_ROOT_DIR) n++;
693#endif
694 if (toupper(str[0]) == toupper(dir[0])) break;
695 }
696#endif
697 }
698 SendDlgItemMessageW(hWnd, cmb2, CB_SETCURSEL, n, 0);
699 if (!(ofn->Flags & OFN_SHOWHELP))
700 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
701 if (ofn->Flags & OFN_HIDEREADONLY)
702 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
703 if (lfs->hook)
704 return (BOOL) FILEDLG_CallWindowProc(lfs, WM_INITDIALOG, wParam, lfs->lParam);
705 return TRUE;
706}
707
708/***********************************************************************
709 * FILEDLG_UpdateResult [internal]
710 * update the displayed file name (with path)
711 */
712void FILEDLG_UpdateResult(LFSPRIVATE lfs, WCHAR *tmpstr)
713{
714 int lenstr2;
715 LPOPENFILENAMEW ofnW = lfs->ofnW;
716 WCHAR tmpstr2[BUFFILE];
717
718 GetCurrentDirectoryW(BUFFILE, tmpstr2);
719 lenstr2 = strlenW(tmpstr2);
720 if (lenstr2 > 3)
721 tmpstr2[lenstr2++]='\\';
722 lstrcpynW(tmpstr2+lenstr2, tmpstr, BUFFILE-lenstr2);
723 if (ofnW->lpstrFile)
724 lstrcpynW(ofnW->lpstrFile, tmpstr2, ofnW->nMaxFile);
725 ofnW->nFileOffset = strrchrW(tmpstr2,'\\') - tmpstr2 +1;
726 ofnW->nFileExtension = 0;
727 while(tmpstr2[ofnW->nFileExtension] != '.' && tmpstr2[ofnW->nFileExtension] != '\0')
728 ofnW->nFileExtension++;
729 if (tmpstr2[ofnW->nFileExtension] == '\0')
730 ofnW->nFileExtension = 0;
731 else
732 ofnW->nFileExtension++;
733 /* update the real client structures if any */
734#ifndef __WIN32OS2__
735 if (lfs->ofn16)
736 { /* we have to convert to short (8.3) path */
737 char tmp[1024]; /* MAX_PATHNAME_LEN */
738 LPOPENFILENAME16 ofn16 = lfs->ofn16;
739 char *dest = MapSL(ofn16->lpstrFile);
740 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1,
741 tmp, ofnW->nMaxFile, NULL, NULL ))
742 tmp[ofnW->nMaxFile-1] = 0;
743 GetShortPathNameA(tmp, dest, ofn16->nMaxFile);
744
745 /* the same procedure as every year... */
746 ofn16->nFileOffset = strrchr(dest,'\\') - dest +1;
747 ofn16->nFileExtension = 0;
748 while(dest[ofn16->nFileExtension] != '.' && dest[ofn16->nFileExtension] != '\0')
749 ofn16->nFileExtension++;
750 if (dest[ofn16->nFileExtension] == '\0')
751 ofn16->nFileExtension = 0;
752 else
753 ofn16->nFileExtension++;
754 }
755#endif
756 if (lfs->ofnA)
757 {
758 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1,
759 lfs->ofnA->lpstrFile, ofnW->nMaxFile, NULL, NULL ))
760 lfs->ofnA->lpstrFile[ofnW->nMaxFile-1] = 0;
761 lfs->ofnA->nFileOffset = ofnW->nFileOffset;
762 lfs->ofnA->nFileExtension = ofnW->nFileExtension;
763 }
764}
765
766
767/***********************************************************************
768 * FILEDLG_UpdateFileTitle [internal]
769 * update the displayed file name (without path)
770 */
771void FILEDLG_UpdateFileTitle(LFSPRIVATE lfs)
772{
773 LONG lRet;
774 LPOPENFILENAMEW ofnW = lfs->ofnW;
775 if (ofnW->lpstrFileTitle != NULL)
776 {
777 lRet = SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL, 0, 0);
778 SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETTEXT, lRet,
779 (LPARAM)ofnW->lpstrFileTitle );
780#ifndef __WIN32OS2__
781 if (lfs->ofn16)
782 {
783 char *dest = MapSL(lfs->ofn16->lpstrFileTitle);
784 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1,
785 dest, ofnW->nMaxFileTitle, NULL, NULL ))
786 dest[ofnW->nMaxFileTitle-1] = 0;
787 }
788#endif
789 if (lfs->ofnA)
790 {
791 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1,
792 lfs->ofnA->lpstrFileTitle, ofnW->nMaxFileTitle, NULL, NULL ))
793 lfs->ofnA->lpstrFileTitle[ofnW->nMaxFileTitle-1] = 0;
794 }
795 }
796}
797
798
799
800/***********************************************************************
801 * FILEDLG_DirListDblClick [internal]
802 */
803static LRESULT FILEDLG_DirListDblClick( LFSPRIVATE lfs )
804{
805 LONG lRet;
806 HWND hWnd = lfs->hwnd;
807 LPWSTR pstr;
808 WCHAR tmpstr[BUFFILE];
809
810 /* get the raw string (with brackets) */
811 lRet = SendDlgItemMessageW(hWnd, lst2, LB_GETCURSEL, 0, 0);
812 if (lRet == LB_ERR) return TRUE;
813 pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
814 SendDlgItemMessageW(hWnd, lst2, LB_GETTEXT, lRet,
815 (LPARAM)pstr);
816 strcpyW( tmpstr, pstr );
817 HeapFree(GetProcessHeap(), 0, pstr);
818 /* get the selected directory in tmpstr */
819 if (tmpstr[0] == '[')
820 {
821 tmpstr[lstrlenW(tmpstr) - 1] = 0;
822 strcpyW(tmpstr,tmpstr+1);
823 }
824 strcatW(tmpstr, FILE_bslash);
825
826 FILEDLG_ScanDir(hWnd, tmpstr);
827 /* notify the app */
828 if (lfs->hook)
829 {
830 if (FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, lst2,
831 MAKELONG(lRet,CD_LBSELCHANGE)))
832 return TRUE;
833 }
834 return TRUE;
835}
836
837
838/***********************************************************************
839 * FILEDLG_FileListSelect [internal]
840 * called when a new item is picked in the file list
841 */
842static LRESULT FILEDLG_FileListSelect( LFSPRIVATE lfs )
843{
844 LONG lRet;
845 HWND hWnd = lfs->hwnd;
846 LPWSTR pstr;
847
848#ifdef __WIN32OS2__
849 lRet = SendDlgItemMessageW(hWnd, lst1, LB_GETCURSEL, 0, 0);
850#else
851 lRet = SendDlgItemMessageW(hWnd, lst1, LB_GETCURSEL16, 0, 0);
852#endif
853 if (lRet == LB_ERR)
854 return TRUE;
855
856 /* set the edit control to the choosen file */
857 if ((pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
858 {
859 SendDlgItemMessageW(hWnd, lst1, LB_GETTEXT, lRet,
860 (LPARAM)pstr);
861 SetDlgItemTextW( hWnd, edt1, pstr );
862 HeapFree(GetProcessHeap(), 0, pstr);
863 }
864 if (lfs->hook)
865 {
866 FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, lst1,
867 MAKELONG(lRet,CD_LBSELCHANGE));
868 }
869 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD,
870 CD_LBSELNOITEMS */
871 return TRUE;
872}
873
874/***********************************************************************
875 * FILEDLG_TestPath [internal]
876 * before accepting the file name, test if it includes wild cards
877 * tries to scan the directory and returns TRUE if no error.
878 */
879static LRESULT FILEDLG_TestPath( LFSPRIVATE lfs, LPWSTR path )
880{
881 HWND hWnd = lfs->hwnd;
882 LPWSTR pBeginFileName, pstr2;
883 WCHAR tmpstr2[BUFFILE];
884
885 pBeginFileName = strrchrW(path, '\\');
886 if (pBeginFileName == NULL)
887 pBeginFileName = strrchrW(path, ':');
888
889 if (strchrW(path,'*') != NULL || strchrW(path,'?') != NULL)
890 {
891 /* edit control contains wildcards */
892 if (pBeginFileName != NULL)
893 {
894 lstrcpynW(tmpstr2, pBeginFileName + 1, BUFFILE);
895 *(pBeginFileName + 1) = 0;
896 }
897 else
898 {
899 strcpyW(tmpstr2, path);
900 *path = 0;
901 }
902
903 TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path), debugstr_w(tmpstr2));
904 SetDlgItemTextW( hWnd, edt1, tmpstr2 );
905 FILEDLG_ScanDir(hWnd, path);
906 return FALSE;
907 }
908
909 /* no wildcards, we might have a directory or a filename */
910 /* try appending a wildcard and reading the directory */
911
912 pstr2 = path + lstrlenW(path);
913 if (pBeginFileName == NULL || *(pBeginFileName + 1) != 0)
914 strcatW(path, FILE_bslash);
915
916 /* if ScanDir succeeds, we have changed the directory */
917 if (FILEDLG_ScanDir(hWnd, path))
918 return TRUE;
919
920 /* if not, this must be a filename */
921
922 *pstr2 = 0; /* remove the wildcard added before */
923
924 if (pBeginFileName != NULL)
925 {
926 /* strip off the pathname */
927 *pBeginFileName = 0;
928 SetDlgItemTextW( hWnd, edt1, pBeginFileName + 1 );
929
930 lstrcpynW(tmpstr2, pBeginFileName + 1, sizeof(tmpstr2)/sizeof(WCHAR) );
931 /* Should we MessageBox() if this fails? */
932 if (!FILEDLG_ScanDir(hWnd, path))
933 {
934 return FALSE;
935 }
936 strcpyW(path, tmpstr2);
937 }
938 else
939 SetDlgItemTextW( hWnd, edt1, path );
940 return TRUE;
941}
942
943/***********************************************************************
944 * FILEDLG_Validate [internal]
945 * called on: click Ok button, Enter in edit, DoubleClick in file list
946 */
947static LRESULT FILEDLG_Validate( LFSPRIVATE lfs, LPWSTR path, UINT control, INT itemIndex,
948 BOOL internalUse )
949{
950 LONG lRet;
951 HWND hWnd = lfs->hwnd;
952 OPENFILENAMEW ofnsav;
953 LPOPENFILENAMEW ofnW = lfs->ofnW;
954 WCHAR filename[BUFFILE];
955
956 ofnsav = *ofnW; /* for later restoring */
957
958 /* get current file name */
959 if (path)
960 lstrcpynW(filename, path, sizeof(filename)/sizeof(WCHAR));
961 else
962 GetDlgItemTextW( hWnd, edt1, filename, sizeof(filename)/sizeof(WCHAR));
963
964 /* if we did not click in file list to get there */
965 if (control != lst1)
966 {
967 if (!FILEDLG_TestPath( lfs, filename) )
968 return FALSE;
969 }
970 FILEDLG_UpdateResult(lfs, filename);
971
972 if (internalUse)
973 { /* called internally after a change in a combo */
974 if (lfs->hook)
975 {
976 FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, control,
977 MAKELONG(itemIndex,CD_LBSELCHANGE));
978 }
979 return TRUE;
980 }
981
982 FILEDLG_UpdateFileTitle(lfs);
983 if (lfs->hook)
984 {
985 lRet = (BOOL)FILEDLG_CallWindowProc(lfs, lfs->fileokstring,
986 0, lfs->lParam );
987 if (lRet)
988 {
989 *ofnW = ofnsav; /* restore old state */
990 return FALSE;
991 }
992 }
993 if ((ofnW->Flags & OFN_ALLOWMULTISELECT) && (ofnW->Flags & OFN_EXPLORER))
994 {
995 if (ofnW->lpstrFile)
996 {
997 LPWSTR str = (LPWSTR)ofnW->lpstrFile;
998 LPWSTR ptr = strrchrW(str, '\\');
999 str[lstrlenW(str) + 1] = '\0';
1000 *ptr = 0;
1001 }
1002 }
1003 return TRUE;
1004}
1005
1006/***********************************************************************
1007 * FILEDLG_DiskChange [internal]
1008 * called when a new item is picked in the disk selection combo
1009 */
1010static LRESULT FILEDLG_DiskChange( LFSPRIVATE lfs )
1011{
1012 LONG lRet;
1013 HWND hWnd = lfs->hwnd;
1014 LPWSTR pstr;
1015 WCHAR diskname[BUFFILE];
1016
1017 FILEDLG_StripEditControl(hWnd);
1018 lRet = SendDlgItemMessageW(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
1019 if (lRet == LB_ERR)
1020 return 0;
1021 pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
1022 SendDlgItemMessageW(hWnd, cmb2, CB_GETLBTEXT, lRet,
1023 (LPARAM)pstr);
1024 wsprintfW(diskname, FILE_specc, pstr[2]);
1025 HeapFree(GetProcessHeap(), 0, pstr);
1026
1027 return FILEDLG_Validate( lfs, diskname, cmb2, lRet, TRUE );
1028}
1029
1030
1031/***********************************************************************
1032 * FILEDLG_FileTypeChange [internal]
1033 * called when a new item is picked in the file type combo
1034 */
1035static LRESULT FILEDLG_FileTypeChange( LFSPRIVATE lfs )
1036{
1037 LONG lRet;
1038 WCHAR diskname[BUFFILE];
1039 LPWSTR pstr;
1040
1041 diskname[0] = 0;
1042
1043 lRet = SendDlgItemMessageW(lfs->hwnd, cmb1, CB_GETCURSEL, 0, 0);
1044 if (lRet == LB_ERR)
1045 return TRUE;
1046 pstr = (LPWSTR)SendDlgItemMessageW(lfs->hwnd, cmb1, CB_GETITEMDATA, lRet, 0);
1047 TRACE("Selected filter : %s\n", debugstr_w(pstr));
1048 SetDlgItemTextW( lfs->hwnd, edt1, pstr );
1049
1050 return FILEDLG_Validate( lfs, NULL, cmb1, lRet, TRUE );
1051}
1052
1053/***********************************************************************
1054 * FILEDLG_WMCommand [internal]
1055 */
1056static LRESULT FILEDLG_WMCommand(HWND hWnd, LPARAM lParam, UINT notification,
1057 UINT control, LFSPRIVATE lfs )
1058{
1059 switch (control)
1060 {
1061 case lst1: /* file list */
1062 FILEDLG_StripEditControl(hWnd);
1063 if (notification == LBN_DBLCLK)
1064 {
1065 if (FILEDLG_Validate( lfs, NULL, control, 0, FALSE ))
1066 EndDialog(hWnd, TRUE);
1067 return TRUE;
1068 }
1069 else if (notification == LBN_SELCHANGE)
1070 return FILEDLG_FileListSelect( lfs );
1071 break;
1072
1073 case lst2: /* directory list */
1074 FILEDLG_StripEditControl(hWnd);
1075 if (notification == LBN_DBLCLK)
1076 return FILEDLG_DirListDblClick( lfs );
1077 break;
1078
1079 case cmb1: /* file type drop list */
1080 if (notification == CBN_SELCHANGE)
1081 return FILEDLG_FileTypeChange( lfs );
1082 break;
1083
1084 case chx1:
1085 break;
1086
1087 case pshHelp:
1088 break;
1089
1090 case cmb2: /* disk dropdown combo */
1091 if (notification == CBN_SELCHANGE)
1092 return FILEDLG_DiskChange( lfs );
1093 break;
1094
1095 case IDOK:
1096 if (FILEDLG_Validate( lfs, NULL, control, 0, FALSE ))
1097 EndDialog(hWnd, TRUE);
1098 return TRUE;
1099
1100 case IDCANCEL:
1101 EndDialog(hWnd, FALSE);
1102 return TRUE;
1103
1104 case IDABORT: /* can be sent by the hook procedure */
1105 EndDialog(hWnd, TRUE);
1106 return TRUE;
1107 }
1108 return FALSE;
1109}
1110
1111#ifndef __WIN32OS2__
1112/***********************************************************************
1113 * FILEDLG_MapDrawItemStruct [internal]
1114 * map a 16 bits drawitem struct to 32
1115 */
1116void FILEDLG_MapDrawItemStruct(LPDRAWITEMSTRUCT16 lpdis16, LPDRAWITEMSTRUCT lpdis)
1117{
1118 lpdis->CtlType = lpdis16->CtlType;
1119 lpdis->CtlID = lpdis16->CtlID;
1120 lpdis->itemID = lpdis16->itemID;
1121 lpdis->itemAction = lpdis16->itemAction;
1122 lpdis->itemState = lpdis16->itemState;
1123 lpdis->hwndItem = lpdis16->hwndItem;
1124 lpdis->hDC = lpdis16->hDC;
1125 lpdis->rcItem.right = lpdis16->rcItem.right;
1126 lpdis->rcItem.left = lpdis16->rcItem.left;
1127 lpdis->rcItem.top = lpdis16->rcItem.top;
1128 lpdis->rcItem.bottom = lpdis16->rcItem.bottom;
1129 lpdis->itemData = lpdis16->itemData;
1130}
1131#endif
1132
1133/************************************************************************
1134 * FILEDLG_MapStringPairsToW [internal]
1135 * map string pairs to Unicode
1136 */
1137LPWSTR FILEDLG_MapStringPairsToW(LPCSTR strA, UINT size)
1138{
1139 LPCSTR s;
1140 LPWSTR x;
1141 int n, len;
1142
1143 s = strA;
1144 while (*s)
1145 s = s+strlen(s)+1;
1146 s++;
1147 n = s - strA;
1148 if (n < size) n = size;
1149
1150 len = MultiByteToWideChar( CP_ACP, 0, strA, n, NULL, 0 );
1151 x = HeapAlloc(GetProcessHeap(),0, len * sizeof(WCHAR));
1152 MultiByteToWideChar( CP_ACP, 0, strA, n, x, len );
1153 return x;
1154}
1155
1156
1157/************************************************************************
1158 * FILEDLG_DupToW [internal]
1159 * duplicates an Ansi string to unicode, with a buffer size
1160 */
1161LPWSTR FILEDLG_DupToW(LPCSTR str, DWORD size)
1162{
1163 LPWSTR strW = NULL;
1164 if (str && (size > 0))
1165 {
1166 strW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
1167 if (strW) MultiByteToWideChar( CP_ACP, 0, str, -1, strW, size );
1168 }
1169 return strW;
1170}
1171
1172
1173/************************************************************************
1174 * FILEDLG_MapOfnStructA [internal]
1175 * map a 32 bits Ansi structure to an Unicode one
1176 */
1177void FILEDLG_MapOfnStructA(LPOPENFILENAMEA ofnA, LPOPENFILENAMEW ofnW, BOOL open)
1178{
1179 LPCSTR str;
1180
1181 ofnW->lStructSize = sizeof(OPENFILENAMEW);
1182 ofnW->hwndOwner = ofnA->hwndOwner;
1183 ofnW->hInstance = ofnA->hInstance;
1184 if (ofnA->lpstrFilter)
1185 ofnW->lpstrFilter = FILEDLG_MapStringPairsToW(ofnA->lpstrFilter, 0);
1186 else
1187#ifdef __WIN32OS2__
1188 ofnW->lpstrFilter = NULL;
1189#else
1190 ofnW->lpstrFilter = FILEDLG_MapStringPairsToW(defaultfilter, 0);
1191#endif
1192
1193 if ((ofnA->lpstrCustomFilter) && (*(ofnA->lpstrCustomFilter)))
1194 ofnW->lpstrCustomFilter = FILEDLG_MapStringPairsToW(ofnA->lpstrCustomFilter, ofnA->nMaxCustFilter);
1195 ofnW->nMaxCustFilter = ofnA->nMaxCustFilter;
1196 ofnW->nFilterIndex = ofnA->nFilterIndex;
1197 ofnW->nMaxFile = ofnA->nMaxFile;
1198 ofnW->lpstrFile = FILEDLG_DupToW(ofnA->lpstrFile, ofnW->nMaxFile);
1199 ofnW->nMaxFileTitle = ofnA->nMaxFileTitle;
1200 ofnW->lpstrFileTitle = FILEDLG_DupToW(ofnA->lpstrFileTitle, ofnW->nMaxFileTitle);
1201 if (ofnA->lpstrInitialDir)
1202 ofnW->lpstrInitialDir = HEAP_strdupAtoW(GetProcessHeap(),0,ofnA->lpstrInitialDir);
1203 if (ofnA->lpstrTitle)
1204 str = ofnA->lpstrTitle;
1205 else
1206 /* Allocates default title (FIXME : get it from resource) */
1207 str = open ? defaultopen:defaultsave;
1208 ofnW->lpstrTitle = HEAP_strdupAtoW(GetProcessHeap(),0, str);
1209 ofnW->Flags = ofnA->Flags;
1210 ofnW->nFileOffset = ofnA->nFileOffset;
1211 ofnW->nFileExtension = ofnA->nFileExtension;
1212 ofnW->lpstrDefExt = FILEDLG_DupToW(ofnA->lpstrDefExt, 3);
1213 if ((ofnA->Flags & OFN_ENABLETEMPLATE) && (ofnA->lpTemplateName))
1214 {
1215 if (HIWORD(ofnA->lpTemplateName))
1216 ofnW->lpTemplateName = HEAP_strdupAtoW(GetProcessHeap(), 0, ofnA->lpTemplateName);
1217 else /* numbered resource */
1218 ofnW->lpTemplateName = (LPWSTR) ofnA->lpTemplateName;
1219 }
1220}
1221
1222#ifndef __WIN32OS2__
1223/************************************************************************
1224 * FILEDLG_MapOfnStruct16 [internal]
1225 * map a 16 bits structure to an Unicode one
1226 */
1227void FILEDLG_MapOfnStruct16(LPOPENFILENAME16 ofn16, LPOPENFILENAMEW ofnW, BOOL open)
1228{
1229 OPENFILENAMEA ofnA;
1230 /* first convert to linear pointers */
1231 memset(&ofnA, 0, sizeof(OPENFILENAMEA));
1232 ofnA.lStructSize = sizeof(OPENFILENAMEA);
1233 ofnA.hwndOwner = ofn16->hwndOwner;
1234 ofnA.hInstance = ofn16->hInstance;
1235 if (ofn16->lpstrFilter)
1236 ofnA.lpstrFilter = MapSL(ofn16->lpstrFilter);
1237 if (ofn16->lpstrCustomFilter)
1238 ofnA.lpstrCustomFilter = MapSL(ofn16->lpstrCustomFilter);
1239 ofnA.nMaxCustFilter = ofn16->nMaxCustFilter;
1240 ofnA.nFilterIndex = ofn16->nFilterIndex;
1241 ofnA.lpstrFile = MapSL(ofn16->lpstrFile);
1242 ofnA.nMaxFile = ofn16->nMaxFile;
1243 ofnA.lpstrFileTitle = MapSL(ofn16->lpstrFileTitle);
1244 ofnA.nMaxFileTitle = ofn16->nMaxFileTitle;
1245 ofnA.lpstrInitialDir = MapSL(ofn16->lpstrInitialDir);
1246 ofnA.lpstrTitle = MapSL(ofn16->lpstrTitle);
1247 ofnA.Flags = ofn16->Flags;
1248 ofnA.nFileOffset = ofn16->nFileOffset;
1249 ofnA.nFileExtension = ofn16->nFileExtension;
1250 ofnA.lpstrDefExt = MapSL(ofn16->lpstrDefExt);
1251 if (HIWORD(ofn16->lpTemplateName))
1252 ofnA.lpTemplateName = MapSL(ofn16->lpTemplateName);
1253 else
1254 ofnA.lpTemplateName = (LPSTR) ofn16->lpTemplateName; /* ressource number */
1255 /* now calls the 32 bits Ansi to Unicode version to complete the job */
1256 FILEDLG_MapOfnStructA(&ofnA, ofnW, open);
1257}
1258#endif
1259
1260/************************************************************************
1261 * FILEDLG_DestroyPrivate [internal]
1262 * destroys the private object
1263 */
1264void FILEDLG_DestroyPrivate(LFSPRIVATE lfs)
1265{
1266 HWND hwnd;
1267 if (!lfs) return;
1268 hwnd = lfs->hwnd;
1269 /* free resources for a 16 bits dialog */
1270 if (lfs->hResource16) FreeResource16(lfs->hResource16);
1271 if (lfs->hGlobal16)
1272 {
1273 GlobalUnlock16(lfs->hGlobal16);
1274 GlobalFree16(lfs->hGlobal16);
1275 }
1276 /* if ofnW has been allocated, have to free everything in it */
1277#ifndef __WIN32OS2__
1278 if (lfs->ofn16 || lfs->ofnA)
1279#else
1280 if (lfs->ofnA)
1281#endif
1282 {
1283 LPOPENFILENAMEW ofnW = lfs->ofnW;
1284 if (ofnW->lpstrFilter) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrFilter);
1285 if (ofnW->lpstrCustomFilter) HeapFree(GetProcessHeap(), 0, ofnW->lpstrCustomFilter);
1286 if (ofnW->lpstrFile) HeapFree(GetProcessHeap(), 0, ofnW->lpstrFile);
1287 if (ofnW->lpstrFileTitle) HeapFree(GetProcessHeap(), 0, ofnW->lpstrFileTitle);
1288 if (ofnW->lpstrInitialDir) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrInitialDir);
1289 if (ofnW->lpstrTitle) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrTitle);
1290 if ((ofnW->lpTemplateName) && (HIWORD(ofnW->lpTemplateName)))
1291 HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpTemplateName);
1292 HeapFree(GetProcessHeap(), 0, ofnW);
1293 }
1294 TRACE("destroying private allocation %p\n", lfs);
1295 HeapFree(GetProcessHeap(), 0, lfs);
1296 RemovePropA(hwnd, OFN_PROP);
1297}
1298
1299/************************************************************************
1300 * FILEDLG_AllocPrivate [internal]
1301 * allocate a private object to hold 32 bits Unicode
1302 * structure that will be used throughtout the calls, while
1303 * keeping available the original structures and a few variables
1304 * On entry : type = dialog procedure type (16,32A,32W)
1305 * dlgType = dialog type (open or save)
1306 */
1307LFSPRIVATE FILEDLG_AllocPrivate(LPARAM lParam, int type, UINT dlgType)
1308{
1309 LFSPRIVATE lfs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct FSPRIVATE));
1310 LFSPRIVATE ret;
1311 TRACE("alloc private buf %p\n", lfs);
1312 if (!lfs) return NULL;
1313 lfs->hook = FALSE;
1314 lfs->lParam = lParam;
1315 if (dlgType == OPEN_DIALOG)
1316 lfs->open = TRUE;
1317 else
1318 lfs->open = FALSE;
1319 lfs->lbselchstring = RegisterWindowMessageA(LBSELCHSTRING);
1320 lfs->fileokstring = RegisterWindowMessageA(FILEOKSTRING);
1321 switch(type)
1322 {
1323#ifndef __WIN32OS2__
1324 case LFS16:
1325 lfs->ofn16 = MapSL(lParam);
1326 if (lfs->ofn16->Flags & OFN_ENABLEHOOK)
1327 if (lfs->ofn16->lpfnHook)
1328 lfs->hook = TRUE;
1329
1330 break;
1331#endif
1332 case LFS32A:
1333 lfs->ofnA = (LPOPENFILENAMEA) lParam;
1334 if (lfs->ofnA->Flags & OFN_ENABLEHOOK)
1335 if (lfs->ofnA->lpfnHook)
1336 lfs->hook = TRUE;
1337 break;
1338
1339 case LFS32W:
1340 lfs->ofnW = (LPOPENFILENAMEW) lParam;
1341 if (lfs->ofnW->Flags & OFN_ENABLEHOOK)
1342 if (lfs->ofnW->lpfnHook)
1343 lfs->hook = TRUE;
1344 break;
1345 }
1346 ret = lfs;
1347 if (!lfs->ofnW)
1348 { /* this structure is needed internally, so create it */
1349 lfs->ofnW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OPENFILENAMEW));
1350 if (lfs->ofnW)
1351 {
1352#ifndef __WIN32OS2__
1353 if (lfs->ofn16)
1354 FILEDLG_MapOfnStruct16(lfs->ofn16, lfs->ofnW, lfs->open);
1355#endif
1356 if (lfs->ofnA)
1357 FILEDLG_MapOfnStructA(lfs->ofnA, lfs->ofnW, lfs->open);
1358 }
1359 else
1360 ret = NULL;
1361 }
1362#ifndef __WIN32OS2__
1363 if (lfs->ofn16)
1364 {
1365 if (!Get16BitsTemplate(lfs)) ret = NULL;
1366 }
1367 else
1368#endif
1369 if (!Get32BitsTemplate(lfs)) ret = NULL;
1370 if (!ret) FILEDLG_DestroyPrivate(lfs);
1371 return ret;
1372}
1373
1374
1375/***********************************************************************
1376 * GetFileName31A [internal]
1377 *
1378 * Creates a win31 style dialog box for the user to select a file to open/save.
1379 */
1380BOOL WINAPI GetFileName31A(
1381 LPOPENFILENAMEA lpofn, /* addess of structure with data*/
1382 UINT dlgType /* type dialogue : open/save */
1383 )
1384{
1385 HINSTANCE hInst;
1386 BOOL bRet = FALSE;
1387 LFSPRIVATE lfs;
1388
1389 if (!lpofn || !FileDlg_Init()) return FALSE;
1390
1391 lfs = FILEDLG_AllocPrivate((LPARAM) lpofn, LFS32A, dlgType);
1392 if (lfs)
1393 {
1394 hInst = GetWindowLongA( lpofn->hwndOwner, GWL_HINSTANCE );
1395 bRet = DialogBoxIndirectParamA( hInst, lfs->template, lpofn->hwndOwner,
1396 (DLGPROC) FileOpenDlgProc, (DWORD) lfs);
1397 FILEDLG_DestroyPrivate(lfs);
1398 }
1399
1400 TRACE("return lpstrFile='%s' !\n", lpofn->lpstrFile);
1401 return bRet;
1402}
1403
1404
1405/***********************************************************************
1406 * GetFileName31W [internal]
1407 *
1408 * Creates a win31 style dialog box for the user to select a file to open/save
1409 */
1410BOOL WINAPI GetFileName31W(
1411 LPOPENFILENAMEW lpofn, /* addess of structure with data*/
1412 UINT dlgType /* type dialogue : open/save */
1413 )
1414{
1415 HINSTANCE hInst;
1416 BOOL bRet = FALSE;
1417 LFSPRIVATE lfs;
1418
1419 if (!lpofn || !FileDlg_Init()) return FALSE;
1420
1421 lfs = FILEDLG_AllocPrivate((LPARAM) lpofn, LFS32W, dlgType);
1422 if (lfs)
1423 {
1424 hInst = GetWindowLongA( lpofn->hwndOwner, GWL_HINSTANCE );
1425 bRet = DialogBoxIndirectParamW( hInst, lfs->template, lpofn->hwndOwner,
1426 (DLGPROC) FileOpenDlgProc, (DWORD) lfs);
1427 FILEDLG_DestroyPrivate(lfs);
1428 }
1429
1430 TRACE("return lpstrFile='%s' !\n", debugstr_w(lpofn->lpstrFile));
1431 return bRet;
1432}
1433
1434
1435/* ------------------ Dialog procedures ---------------------- */
1436
1437#ifndef __WIN32OS2__
1438/***********************************************************************
1439 * FileOpenDlgProc16 (COMMDLG.6)
1440 */
1441LRESULT WINAPI FileOpenDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1442 LPARAM lParam)
1443{
1444 LFSPRIVATE lfs = (LFSPRIVATE)GetPropA(hWnd,OFN_PROP);
1445 DRAWITEMSTRUCT dis;
1446
1447 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg, wParam, lParam);
1448 if ((wMsg != WM_INITDIALOG) && lfs && lfs->hook)
1449 {
1450 LRESULT lRet = (BOOL16)FILEDLG_CallWindowProc(lfs, wMsg, wParam, lParam);
1451 if (lRet)
1452 return lRet; /* else continue message processing */
1453 }
1454 switch (wMsg)
1455 {
1456 case WM_INITDIALOG:
1457 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
1458
1459 case WM_MEASUREITEM:
1460 return FILEDLG_WMMeasureItem16(hWnd, wParam, lParam);
1461
1462 case WM_DRAWITEM:
1463 FILEDLG_MapDrawItemStruct(MapSL(lParam), &dis);
1464 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE, &dis);
1465
1466 case WM_COMMAND:
1467 return FILEDLG_WMCommand(hWnd, lParam, HIWORD(lParam),wParam, lfs);
1468#if 0
1469 case WM_CTLCOLOR:
1470 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1471 switch (HIWORD(lParam))
1472 {
1473 case CTLCOLOR_BTN:
1474 SetTextColor((HDC16)wParam, 0x00000000);
1475 return hGRAYBrush;
1476 case CTLCOLOR_STATIC:
1477 SetTextColor((HDC16)wParam, 0x00000000);
1478 return hGRAYBrush;
1479 }
1480 break;
1481#endif
1482 }
1483 return FALSE;
1484}
1485
1486/***********************************************************************
1487 * FileSaveDlgProc16 (COMMDLG.7)
1488 */
1489LRESULT WINAPI FileSaveDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1490 LPARAM lParam)
1491{
1492 LFSPRIVATE lfs = (LFSPRIVATE)GetPropA(hWnd,OFN_PROP);
1493 DRAWITEMSTRUCT dis;
1494
1495 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg, wParam, lParam);
1496 if ((wMsg != WM_INITDIALOG) && lfs && lfs->hook)
1497 {
1498 LRESULT lRet;
1499 lRet = (BOOL16)FILEDLG_CallWindowProc(lfs, wMsg, wParam, lParam);
1500 if (lRet)
1501 return lRet; /* else continue message processing */
1502 }
1503 switch (wMsg) {
1504 case WM_INITDIALOG:
1505 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
1506
1507 case WM_MEASUREITEM:
1508 return FILEDLG_WMMeasureItem16(hWnd, wParam, lParam);
1509
1510 case WM_DRAWITEM:
1511 FILEDLG_MapDrawItemStruct(MapSL(lParam), &dis);
1512 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE, &dis);
1513
1514 case WM_COMMAND:
1515 return FILEDLG_WMCommand(hWnd, lParam, HIWORD(lParam), wParam, lfs);
1516 }
1517
1518 /*
1519 case WM_CTLCOLOR:
1520 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1521 switch (HIWORD(lParam))
1522 {
1523 case CTLCOLOR_BTN:
1524 SetTextColor((HDC16)wParam, 0x00000000);
1525 return hGRAYBrush;
1526 case CTLCOLOR_STATIC:
1527 SetTextColor((HDC16)wParam, 0x00000000);
1528 return hGRAYBrush;
1529 }
1530 return FALSE;
1531
1532 */
1533 return FALSE;
1534}
1535#endif //__WIN32OS2__
1536
1537/***********************************************************************
1538 * FileOpenDlgProc [internal]
1539 * Used for open and save, in fact.
1540 */
1541static LRESULT WINAPI FileOpenDlgProc(HWND hWnd, UINT wMsg,
1542 WPARAM wParam, LPARAM lParam)
1543{
1544 LFSPRIVATE lfs = (LFSPRIVATE)GetPropA(hWnd,OFN_PROP);
1545
1546 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg, wParam, lParam);
1547 if ((wMsg != WM_INITDIALOG) && lfs && lfs->hook)
1548 {
1549 LRESULT lRet;
1550 lRet = (BOOL)FILEDLG_CallWindowProc(lfs, wMsg, wParam, lParam);
1551 if (lRet)
1552 return lRet; /* else continue message processing */
1553 }
1554 switch (wMsg)
1555 {
1556 case WM_INITDIALOG:
1557 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
1558
1559 case WM_MEASUREITEM:
1560 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
1561
1562 case WM_DRAWITEM:
1563 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, !lfs->open, (DRAWITEMSTRUCT *)lParam);
1564
1565 case WM_COMMAND:
1566 return FILEDLG_WMCommand(hWnd, lParam, HIWORD(wParam), LOWORD(wParam), lfs);
1567#if 0
1568 case WM_CTLCOLOR:
1569 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1570 switch (HIWORD(lParam))
1571 {
1572 case CTLCOLOR_BTN:
1573 SetTextColor((HDC16)wParam, 0x00000000);
1574 return hGRAYBrush;
1575 case CTLCOLOR_STATIC:
1576 SetTextColor((HDC16)wParam, 0x00000000);
1577 return hGRAYBrush;
1578 }
1579 break;
1580#endif
1581 }
1582 return FALSE;
1583}
1584
1585/* ------------------ APIs ---------------------- */
1586#ifndef __WIN32OS2__
1587/***********************************************************************
1588 * GetOpenFileName16 (COMMDLG.1)
1589 *
1590 * Creates a dialog box for the user to select a file to open.
1591 *
1592 * RETURNS
1593 * TRUE on success: user selected a valid file
1594 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1595 *
1596 * BUGS
1597 * unknown, there are some FIXME's left.
1598 */
1599BOOL16 WINAPI GetOpenFileName16(
1600 SEGPTR ofn /* [in/out] address of structure with data*/
1601 )
1602{
1603 HINSTANCE hInst;
1604 BOOL bRet = FALSE;
1605 LPOPENFILENAME16 lpofn = MapSL(ofn);
1606 LFSPRIVATE lfs;
1607 FARPROC16 ptr;
1608
1609 if (!lpofn || !FileDlg_Init()) return FALSE;
1610
1611 lfs = FILEDLG_AllocPrivate((LPARAM) ofn, LFS16, OPEN_DIALOG);
1612 if (lfs)
1613 {
1614 hInst = GetWindowLongA( lpofn->hwndOwner, GWL_HINSTANCE );
1615 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 6);
1616 bRet = DialogBoxIndirectParam16( hInst, lfs->hDlgTmpl16, lpofn->hwndOwner,
1617 (DLGPROC16) ptr, (DWORD) lfs);
1618 FILEDLG_DestroyPrivate(lfs);
1619 }
1620
1621 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn->lpstrFile));
1622 return bRet;
1623}
1624
1625/***********************************************************************
1626 * GetSaveFileName16 (COMMDLG.2)
1627 *
1628 * Creates a dialog box for the user to select a file to save.
1629 *
1630 * RETURNS
1631 * TRUE on success: user enters a valid file
1632 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1633 *
1634 * BUGS
1635 * unknown. There are some FIXME's left.
1636 */
1637BOOL16 WINAPI GetSaveFileName16(
1638 SEGPTR ofn /* [in/out] addess of structure with data*/
1639 )
1640{
1641 HINSTANCE hInst;
1642 BOOL bRet = FALSE;
1643 LPOPENFILENAME16 lpofn = MapSL(ofn);
1644 LFSPRIVATE lfs;
1645 FARPROC16 ptr;
1646
1647 if (!lpofn || !FileDlg_Init()) return FALSE;
1648
1649 lfs = FILEDLG_AllocPrivate((LPARAM) ofn, LFS16, SAVE_DIALOG);
1650 if (lfs)
1651 {
1652 hInst = GetWindowLongA( lpofn->hwndOwner, GWL_HINSTANCE );
1653 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 7);
1654 bRet = DialogBoxIndirectParam16( hInst, lfs->hDlgTmpl16, lpofn->hwndOwner,
1655 (DLGPROC16) ptr, (DWORD) lfs);
1656 FILEDLG_DestroyPrivate(lfs);
1657 }
1658
1659 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn->lpstrFile));
1660 return bRet;
1661}
1662#endif //__WIN32OS2__
1663
1664/***********************************************************************
1665 * GetOpenFileNameA (COMDLG32.10)
1666 *
1667 * Creates a dialog box for the user to select a file to open.
1668 *
1669 * RETURNS
1670 * TRUE on success: user enters a valid file
1671 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1672 *
1673 */
1674BOOL WINAPI GetOpenFileNameA(
1675 LPOPENFILENAMEA ofn) /* [in/out] address of init structure */
1676{
1677 BOOL newlook = TRUE; /* FIXME: TWEAK_WineLook */
1678
1679#ifdef __WIN32OS2__
1680 dprintf(("GetOpenFileNameA %x", ofn));
1681#endif
1682
1683 /* some flags don't allow to match the TWEAK_WineLook */
1684 if (ofn->Flags & (OFN_ALLOWMULTISELECT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE))
1685 {
1686 newlook = (ofn->Flags & OFN_EXPLORER) ? TRUE : FALSE;
1687 }
1688
1689 if (newlook)
1690 {
1691 return GetFileDialog95A(ofn, OPEN_DIALOG);
1692 }
1693 else
1694 {
1695 return GetFileName31A(ofn, OPEN_DIALOG);
1696 }
1697}
1698
1699/***********************************************************************
1700 * GetOpenFileNameW (COMDLG32.11)
1701 *
1702 * Creates a dialog box for the user to select a file to open.
1703 *
1704 * RETURNS
1705 * TRUE on success: user enters a valid file
1706 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1707 *
1708 */
1709BOOL WINAPI GetOpenFileNameW(
1710 LPOPENFILENAMEW ofn) /* [in/out] address of init structure */
1711{
1712 BOOL newlook = TRUE; /* FIXME: TWEAK_WineLook */
1713
1714#ifdef __WIN32OS2__
1715 dprintf(("GetOpenFileNameW %x", ofn));
1716#endif
1717
1718 /* some flags don't allow to match the TWEAK_WineLook */
1719 if (ofn->Flags & (OFN_ALLOWMULTISELECT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE))
1720 {
1721 newlook = (ofn->Flags & OFN_EXPLORER) ? TRUE : FALSE;
1722 }
1723
1724 if (newlook)
1725 {
1726 return GetFileDialog95W(ofn, OPEN_DIALOG);
1727 }
1728 else
1729 {
1730 return GetFileName31W(ofn, OPEN_DIALOG);
1731 }
1732}
1733
1734/***********************************************************************
1735 * GetSaveFileNameA (COMDLG32.12)
1736 *
1737 * Creates a dialog box for the user to select a file to save.
1738 *
1739 * RETURNS
1740 * TRUE on success: user enters a valid file
1741 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1742 *
1743 */
1744BOOL WINAPI GetSaveFileNameA(
1745 LPOPENFILENAMEA ofn) /* [in/out] address of init structure */
1746{
1747 BOOL newlook = TRUE; /* FIXME: TWEAK_WineLook */
1748
1749#ifdef __WIN32OS2__
1750 dprintf(("GetSaveFileNameA %x", ofn));
1751#endif
1752
1753 /* some flags don't allow to match the TWEAK_WineLook */
1754 if (ofn->Flags & (OFN_ALLOWMULTISELECT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE))
1755 {
1756 newlook = (ofn->Flags & OFN_EXPLORER) ? TRUE : FALSE;
1757 }
1758
1759 if (newlook)
1760 {
1761 return GetFileDialog95A(ofn, SAVE_DIALOG);
1762 }
1763 else
1764 {
1765 return GetFileName31A(ofn, SAVE_DIALOG);
1766 }
1767}
1768
1769/***********************************************************************
1770 * GetSaveFileNameW (COMDLG32.13)
1771 *
1772 * Creates a dialog box for the user to select a file to save.
1773 *
1774 * RETURNS
1775 * TRUE on success: user enters a valid file
1776 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1777 *
1778 */
1779BOOL WINAPI GetSaveFileNameW(
1780 LPOPENFILENAMEW ofn) /* [in/out] address of init structure */
1781{
1782 BOOL newlook = TRUE; /* FIXME: TWEAK_WineLook */
1783
1784#ifdef __WIN32OS2__
1785 dprintf(("GetSaveFileNameW %x", ofn));
1786#endif
1787
1788 /* some flags don't allow to match the TWEAK_WineLook */
1789 if (ofn->Flags & (OFN_ALLOWMULTISELECT|OFN_ENABLEHOOK|OFN_ENABLETEMPLATE))
1790 {
1791 newlook = (ofn->Flags & OFN_EXPLORER) ? TRUE : FALSE;
1792 }
1793
1794 if (newlook)
1795 {
1796 return GetFileDialog95W(ofn, SAVE_DIALOG);
1797 }
1798 else
1799 {
1800 return GetFileName31W(ofn, SAVE_DIALOG);
1801 }
1802}
Note: See TracBrowser for help on using the repository browser.