2 * COMMDLG - File Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
17 #include "wine/unicode.h"
22 #include "debugtools.h"
26 DEFAULT_DEBUG_CHANNEL(commdlg
);
31 #define BUFFILEALLOC 512 * sizeof(WCHAR)
35 HWND hwnd
; /* file dialog window handle */
36 BOOL hook
; /* TRUE if the dialog is hooked */
37 UINT lbselchstring
; /* registered message id */
38 UINT fileokstring
; /* registered message id */
39 LPARAM lParam
; /* save original lparam */
40 HANDLE16 hDlgTmpl16
; /* handle for resource 16 */
41 HANDLE16 hResource16
; /* handle for allocated resource 16 */
42 HANDLE16 hGlobal16
; /* 16 bits mem block (resources) */
43 LPCVOID
template; /* template for 32 bits resource */
44 BOOL open
; /* TRUE if open dialog, FALSE if save dialog */
45 OPENFILENAMEW
*ofnW
; /* original structure or work struct */
46 OPENFILENAMEA
*ofnA
; /* original structure if 32bits ansi dialog */
47 OPENFILENAME16
*ofn16
; /* original structure if 16 bits dialog */
51 #define LFSPRIVATE struct FSPRIVATE *
57 static const WCHAR FILE_star
[] = {'*','.','*', 0};
58 static const WCHAR FILE_bslash
[] = {'\\', 0};
59 static const WCHAR FILE_specc
[] = {'%','c',':', 0};
61 static HICON16 hFolder
= 0;
62 static HICON16 hFolder2
= 0;
63 static HICON16 hFloppy
= 0;
64 static HICON16 hHDisk
= 0;
65 static HICON16 hCDRom
= 0;
66 static HICON16 hNet
= 0;
67 static int fldrHeight
= 0;
68 static int fldrWidth
= 0;
70 #define OFN_PROP "FILEDLG_OFN"
72 static const char defaultfilter
[]=" \0\0";
73 static char defaultopen
[]="Open File";
74 static char defaultsave
[]="Save as";
76 /***********************************************************************
78 * Windows 3.1 style OpenFileName/SaveFileName dialog
82 LRESULT WINAPI
FileOpenDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
84 LRESULT WINAPI
FileSaveDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
87 static LRESULT WINAPI
FileOpenDlgProc(HWND hDlg
, UINT msg
,
88 WPARAM wParam
, LPARAM lParam
);
90 /***********************************************************************
91 * FileDlg_Init [internal]
93 static BOOL
FileDlg_Init(void)
95 static BOOL initialized
= 0;
96 CURSORICONINFO
*fldrInfo
;
99 if (!hFolder
) hFolder
= LoadIconA(0, MAKEINTRESOURCEA(OIC_FOLDER
));
100 if (!hFolder2
) hFolder2
= LoadIconA(0, MAKEINTRESOURCEA(OIC_FOLDER2
));
101 if (!hFloppy
) hFloppy
= LoadIconA(0, MAKEINTRESOURCEA(OIC_FLOPPY
));
102 if (!hHDisk
) hHDisk
= LoadIconA(0, MAKEINTRESOURCEA(OIC_HDISK
));
103 if (!hCDRom
) hCDRom
= LoadIconA(0, MAKEINTRESOURCEA(OIC_CDROM
));
104 if (!hNet
) hNet
= LoadIconA(0, MAKEINTRESOURCEA(OIC_NETWORK
));
105 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
106 hHDisk
== 0 || hCDRom
== 0 || hNet
== 0)
108 ERR("Error loading icons !\n");
111 fldrInfo
= (CURSORICONINFO
*) GlobalLock16( hFolder2
);
114 ERR("Error measuring icons !\n");
117 fldrHeight
= fldrInfo
-> nHeight
;
118 fldrWidth
= fldrInfo
-> nWidth
;
119 GlobalUnlock16( hFolder2
);
126 /***********************************************************************
127 * Get32BitsTemplate [internal]
129 * Get a template (or FALSE if failure) when 16 bits dialogs are used
130 * by a 32 bits application
133 BOOL
Get32BitsTemplate(LFSPRIVATE lfs
)
135 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
138 if (ofnW
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
140 if (!(lfs
->template = LockResource( ofnW
->hInstance
)))
142 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
146 else if (ofnW
->Flags
& OFN_ENABLETEMPLATE
)
150 hResInfo
= FindResourceA(lfs
->ofnA
->hInstance
,
151 lfs
->ofnA
->lpTemplateName
,
154 hResInfo
= FindResourceW(ofnW
->hInstance
,
155 ofnW
->lpTemplateName
,
159 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
162 if (!(hDlgTmpl
= LoadResource(ofnW
->hInstance
,
164 !(lfs
->template = LockResource(hDlgTmpl
)))
166 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
169 } else { /* get it from internal Wine resource */
171 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
,
172 lfs
->open
? "OPEN_FILE":"SAVE_FILE", RT_DIALOGA
)))
174 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
177 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
178 !(lfs
->template = LockResource( hDlgTmpl
)))
180 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
188 /***********************************************************************
189 * Get16BitsTemplate [internal]
191 * Get a template (FALSE if failure) when 16 bits dialogs are used
192 * by a 16 bits application
195 BOOL
Get16BitsTemplate(LFSPRIVATE lfs
)
197 LPOPENFILENAME16 ofn16
= lfs
->ofn16
;
199 HGLOBAL16 hGlobal16
= 0;
201 if (ofn16
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
202 lfs
->hDlgTmpl16
= ofn16
->hInstance
;
203 else if (ofn16
->Flags
& OFN_ENABLETEMPLATE
)
206 if (!(hResInfo
= FindResource16(ofn16
->hInstance
,
207 PTR_SEG_TO_LIN(ofn16
->lpTemplateName
),
210 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
213 if (!(lfs
->hDlgTmpl16
= LoadResource16( ofn16
->hInstance
, hResInfo
)))
215 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
218 lfs
->hResource16
= lfs
->hDlgTmpl16
;
221 { /* get resource from (32 bits) own Wine resource; convert it to 16 */
222 HANDLE hResInfo
, hDlgTmpl32
;
226 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
,
227 lfs
->open
? "OPEN_FILE":"SAVE_FILE", RT_DIALOGA
)))
229 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
232 if (!(hDlgTmpl32
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
233 !(template32
= LockResource( hDlgTmpl32
)))
235 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
238 size
= SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo
);
239 hGlobal16
= GlobalAlloc16(0, size
);
242 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
243 ERR("alloc failure for %ld bytes\n", size
);
246 template = GlobalLock16(hGlobal16
);
249 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
250 ERR("global lock failure for %x handle\n", hGlobal16
);
251 GlobalFree16(hGlobal16
);
254 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
255 lfs
->hDlgTmpl16
= hGlobal16
;
256 lfs
->hGlobal16
= hGlobal16
;
261 /***********************************************************************
262 * FILEDLG_StripEditControl [internal]
263 * Strip pathnames off the contents of the edit control.
265 static void FILEDLG_StripEditControl(HWND hwnd
)
267 WCHAR temp
[BUFFILE
], *cp
;
269 GetDlgItemTextW( hwnd
, edt1
, temp
, sizeof(temp
) );
270 cp
= strrchrW(temp
, '\\');
274 cp
= strrchrW(temp
, ':');
278 /* FIXME: shouldn't we do something with the result here? ;-) */
283 /***********************************************************************
284 * FILEDLG_CallWindowProc [internal]
286 * Call the appropriate hook
288 static BOOL
FILEDLG_CallWindowProc(LFSPRIVATE lfs
, UINT wMsg
, WPARAM wParam
,
293 return (BOOL16
) CallWindowProc16(
294 (WNDPROC16
)lfs
->ofn16
->lpfnHook
, lfs
->hwnd
,
295 (UINT16
)wMsg
, (WPARAM16
)wParam
, lParam
);
299 return (BOOL
) CallWindowProcA(
300 (WNDPROC
)lfs
->ofnA
->lpfnHook
, lfs
->hwnd
,
301 wMsg
, wParam
, lParam
);
306 return (BOOL
) CallWindowProcW(
307 (WNDPROC
)lfs
->ofnW
->lpfnHook
, lfs
->hwnd
,
308 wMsg
, wParam
, lParam
);
314 /***********************************************************************
315 * FILEDLG_ScanDir [internal]
317 static BOOL
FILEDLG_ScanDir(HWND hWnd
, LPWSTR newPath
)
319 WCHAR buffer
[BUFFILE
];
322 HCURSOR hCursorWait
, oldCursor
;
324 if ( !SetCurrentDirectoryW( newPath
))
326 lstrcpynW(buffer
, newPath
, sizeof(buffer
));
328 /* get the list of spec files */
329 GetDlgItemTextW(hWnd
, edt1
, buffer
, sizeof(buffer
));
331 hCursorWait
= LoadCursorA(0, IDC_WAITA
);
332 oldCursor
= SetCursor(hCursorWait
);
335 if ((hdlg
= GetDlgItem(hWnd
, lst1
)) != 0) {
336 WCHAR
* scptr
; /* ptr on semi-colon */
337 WCHAR
* filter
= buffer
;
339 TRACE("Using filter %s\n", debugstr_w(filter
));
340 SendMessageW(hdlg
, LB_RESETCONTENT
, 0, 0);
342 scptr
= strchrW(filter
, ';');
343 if (scptr
) *scptr
= 0;
344 while (*filter
== ' ') filter
++;
345 TRACE("Using file spec %s\n", debugstr_w(filter
));
346 if (SendMessageW(hdlg
, LB_DIR
, 0, (LPARAM
)filter
) == LB_ERR
)
348 if (scptr
) *scptr
= ';';
349 filter
= (scptr
) ? (scptr
+ 1) : 0;
353 /* list of directories */
354 strcpyW(buffer
, FILE_star
);
356 if ((hdlgDir
= GetDlgItem(hWnd
, lst2
)) != 0) {
357 lRet
= DlgDirListW(hWnd
, buffer
, lst2
, stc1
, DDL_EXCLUSIVE
| DDL_DIRECTORY
);
359 SetCursor(oldCursor
);
364 /***********************************************************************
365 * FILEDLG_GetFileType [internal]
368 static LPWSTR
FILEDLG_GetFileType(LPWSTR cfptr
, LPWSTR fptr
, WORD index
)
373 for ( ;(n
= lstrlenW(cfptr
)) != 0; i
++)
378 cfptr
+= lstrlenW(cfptr
) + 1;
381 for ( ;(n
= lstrlenW(fptr
)) != 0; i
++)
386 fptr
+= lstrlenW(fptr
) + 1;
388 return (LPWSTR
) FILE_star
; /* FIXME */
391 /***********************************************************************
392 * FILEDLG_WMDrawItem [internal]
394 static LONG
FILEDLG_WMDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
,
395 int savedlg
, LPDRAWITEMSTRUCT lpdis
)
399 COLORREF oldText
= 0, oldBk
= 0;
401 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
403 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
))) return FALSE
;
404 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
407 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
409 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
410 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
413 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_GRAYTEXT
) );
415 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ 1,
416 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
417 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
419 if (lpdis
->itemState
& ODS_SELECTED
)
420 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
422 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
424 SetBkColor( lpdis
->hDC
, oldBk
);
425 SetTextColor( lpdis
->hDC
, oldText
);
427 HeapFree(GetProcessHeap(), 0, str
);
431 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
433 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
435 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
438 if (lpdis
->itemState
& ODS_SELECTED
)
440 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
441 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
443 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
444 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
445 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
447 if (lpdis
->itemState
& ODS_SELECTED
)
448 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
450 if (lpdis
->itemState
& ODS_SELECTED
)
452 SetBkColor( lpdis
->hDC
, oldBk
);
453 SetTextColor( lpdis
->hDC
, oldText
);
455 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hFolder
);
456 HeapFree(GetProcessHeap(), 0, str
);
459 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
462 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
464 SendMessageW(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
466 root
[0] += str
[2] - 'a';
467 switch(GetDriveTypeA(root
))
469 case DRIVE_REMOVABLE
: hIcon
= hFloppy
; break;
470 case DRIVE_CDROM
: hIcon
= hCDRom
; break;
471 case DRIVE_REMOTE
: hIcon
= hNet
; break;
473 default: hIcon
= hHDisk
; break;
475 if (lpdis
->itemState
& ODS_SELECTED
)
477 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
478 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
480 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
481 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
482 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
484 if (lpdis
->itemState
& ODS_SELECTED
)
486 SetBkColor( lpdis
->hDC
, oldBk
);
487 SetTextColor( lpdis
->hDC
, oldText
);
489 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hIcon
);
490 HeapFree(GetProcessHeap(), 0, str
);
496 /***********************************************************************
497 * FILEDLG_WMMeasureItem [internal]
499 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
501 LPMEASUREITEMSTRUCT lpmeasure
;
503 lpmeasure
= (LPMEASUREITEMSTRUCT
)lParam
;
504 lpmeasure
->itemHeight
= fldrHeight
;
508 /***********************************************************************
509 * FILEDLG_WMMeasureItem16 [internal]
511 static LONG
FILEDLG_WMMeasureItem16(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
513 LPMEASUREITEMSTRUCT16 lpmeasure
;
515 lpmeasure
= (LPMEASUREITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
516 lpmeasure
->itemHeight
= fldrHeight
;
520 /***********************************************************************
521 * FILEDLG_WMInitDialog [internal]
524 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
527 WCHAR tmpstr
[BUFFILE
];
528 LPWSTR pstr
, old_pstr
;
530 LFSPRIVATE lfs
= (LFSPRIVATE
) lParam
;
532 if (!lfs
) return FALSE
;
533 SetPropA(hWnd
, OFN_PROP
, (HANDLE
)lfs
);
537 TRACE("flags=%lx initialdir=%s\n", ofn
->Flags
, debugstr_w(ofn
->lpstrInitialDir
));
539 SetWindowTextW( hWnd
, ofn
->lpstrTitle
);
540 /* read custom filter information */
541 if (ofn
->lpstrCustomFilter
)
543 pstr
= ofn
->lpstrCustomFilter
;
545 TRACE("lpstrCustomFilter = %p\n", pstr
);
549 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
550 (LPARAM
)(ofn
->lpstrCustomFilter
) + n
);
551 n
+= lstrlenW(pstr
) + 1;
552 pstr
+= lstrlenW(pstr
) + 1;
553 TRACE("add str='%s' "
554 "associated to '%s'\n", debugstr_w(old_pstr
), debugstr_w(pstr
));
555 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
556 n
+= lstrlenW(pstr
) + 1;
557 pstr
+= lstrlenW(pstr
) + 1;
560 /* read filter information */
561 if (ofn
->lpstrFilter
) {
562 pstr
= (LPWSTR
) ofn
->lpstrFilter
;
566 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
567 (LPARAM
)(ofn
->lpstrFilter
+ n
) );
568 n
+= lstrlenW(pstr
) + 1;
569 pstr
+= lstrlenW(pstr
) + 1;
570 TRACE("add str='%s' "
571 "associated to '%s'\n", debugstr_w(old_pstr
), debugstr_w(pstr
));
572 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
573 n
+= lstrlenW(pstr
) + 1;
574 pstr
+= lstrlenW(pstr
) + 1;
577 /* set default filter */
578 if (ofn
->nFilterIndex
== 0 && ofn
->lpstrCustomFilter
== NULL
)
579 ofn
->nFilterIndex
= 1;
580 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETCURSEL
, ofn
->nFilterIndex
- 1, 0);
581 lstrcpynW(tmpstr
, FILEDLG_GetFileType(ofn
->lpstrCustomFilter
,
582 (LPWSTR
)ofn
->lpstrFilter
, ofn
->nFilterIndex
- 1),BUFFILE
);
583 TRACE("nFilterIndex = %ld, SetText of edt1 to '%s'\n",
584 ofn
->nFilterIndex
, debugstr_w(tmpstr
));
585 SetDlgItemTextW( hWnd
, edt1
, tmpstr
);
588 DlgDirListComboBoxW(hWnd
, tmpstr
, cmb2
, 0, DDL_DRIVES
| DDL_EXCLUSIVE
);
589 /* read initial directory */
590 if (ofn
->lpstrInitialDir
!= NULL
)
593 lstrcpynW(tmpstr
, ofn
->lpstrInitialDir
, 511);
594 len
= lstrlenW(tmpstr
);
595 if (len
> 0 && tmpstr
[len
-1] != '\\' && tmpstr
[len
-1] != ':') {
602 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) {
604 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
605 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr
));
607 /* select current drive in combo 2, omit missing drives */
610 char str
[4] = "a:\\";
611 GetCurrentDirectoryA( sizeof(dir
), dir
);
612 for(i
= 0, n
= -1; i
< 26; i
++)
615 if (GetDriveTypeA(str
) != DRIVE_DOESNOTEXIST
) n
++;
616 if (toupper(str
[0]) == toupper(dir
[0])) break;
619 SendDlgItemMessageW(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
620 if (!(ofn
->Flags
& OFN_SHOWHELP
))
621 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
622 if (ofn
->Flags
& OFN_HIDEREADONLY
)
623 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
625 return (BOOL
) FILEDLG_CallWindowProc(lfs
, WM_INITDIALOG
, wParam
, lfs
->lParam
);
629 /***********************************************************************
630 * FILEDLG_UpdateResult [internal]
631 * update the displayed file name (with path)
633 void FILEDLG_UpdateResult(LFSPRIVATE lfs
, WCHAR
*tmpstr
)
636 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
637 WCHAR tmpstr2
[BUFFILE
];
639 GetCurrentDirectoryW(BUFFILE
, tmpstr2
);
640 lenstr2
= strlenW(tmpstr2
);
642 tmpstr2
[lenstr2
++]='\\';
643 lstrcpynW(tmpstr2
+lenstr2
, tmpstr
, BUFFILE
-lenstr2
);
645 lstrcpynW(ofnW
->lpstrFile
, tmpstr2
, ofnW
->nMaxFile
);
646 ofnW
->nFileOffset
= strrchrW(tmpstr2
,'\\') - tmpstr2
+1;
647 ofnW
->nFileExtension
= 0;
648 while(tmpstr2
[ofnW
->nFileExtension
] != '.' && tmpstr2
[ofnW
->nFileExtension
] != '\0')
649 ofnW
->nFileExtension
++;
650 if (tmpstr2
[ofnW
->nFileExtension
] == '\0')
651 ofnW
->nFileExtension
= 0;
653 ofnW
->nFileExtension
++;
654 /* update the real client structures if any */
657 char *dest
= PTR_SEG_TO_LIN(lfs
->ofn16
->lpstrFile
);
658 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFile
, -1,
659 dest
, ofnW
->nMaxFile
, NULL
, NULL
))
660 dest
[ofnW
->nMaxFile
-1] = 0;
661 lfs
->ofn16
->nFileOffset
= ofnW
->nFileOffset
;
662 lfs
->ofn16
->nFileExtension
= ofnW
->nFileExtension
;
666 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFile
, -1,
667 lfs
->ofnA
->lpstrFile
, ofnW
->nMaxFile
, NULL
, NULL
))
668 lfs
->ofnA
->lpstrFile
[ofnW
->nMaxFile
-1] = 0;
669 lfs
->ofnA
->nFileOffset
= ofnW
->nFileOffset
;
670 lfs
->ofnA
->nFileExtension
= ofnW
->nFileExtension
;
675 /***********************************************************************
676 * FILEDLG_UpdateFileTitle [internal]
677 * update the displayed file name (without path)
679 void FILEDLG_UpdateFileTitle(LFSPRIVATE lfs
)
682 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
683 if (ofnW
->lpstrFileTitle
!= NULL
)
685 lRet
= SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETCURSEL
, 0, 0);
686 SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETTEXT
, lRet
,
687 (LPARAM
)ofnW
->lpstrFileTitle
);
690 char *dest
= PTR_SEG_TO_LIN(lfs
->ofn16
->lpstrFileTitle
);
691 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFileTitle
, -1,
692 dest
, ofnW
->nMaxFileTitle
, NULL
, NULL
))
693 dest
[ofnW
->nMaxFileTitle
-1] = 0;
697 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFileTitle
, -1,
698 lfs
->ofnA
->lpstrFileTitle
, ofnW
->nMaxFileTitle
, NULL
, NULL
))
699 lfs
->ofnA
->lpstrFileTitle
[ofnW
->nMaxFileTitle
-1] = 0;
706 /***********************************************************************
707 * FILEDLG_DirListDblClick [internal]
709 static LRESULT
FILEDLG_DirListDblClick( LFSPRIVATE lfs
)
712 HWND hWnd
= lfs
->hwnd
;
714 WCHAR tmpstr
[BUFFILE
];
716 /* get the raw string (with brackets) */
717 lRet
= SendDlgItemMessageW(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
718 if (lRet
== LB_ERR
) return TRUE
;
719 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
720 SendDlgItemMessageW(hWnd
, lst2
, LB_GETTEXT
, lRet
,
722 strcpyW( tmpstr
, pstr
);
723 HeapFree(GetProcessHeap(), 0, pstr
);
724 /* get the selected directory in tmpstr */
725 if (tmpstr
[0] == '[')
727 tmpstr
[lstrlenW(tmpstr
) - 1] = 0;
728 strcpyW(tmpstr
,tmpstr
+1);
730 strcatW(tmpstr
, FILE_bslash
);
732 FILEDLG_ScanDir(hWnd
, tmpstr
);
736 if (FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, lst2
,
737 MAKELONG(lRet
,CD_LBSELCHANGE
)))
744 /***********************************************************************
745 * FILEDLG_FileListSelect [internal]
746 * called when a new item is picked in the file list
748 static LRESULT
FILEDLG_FileListSelect( LFSPRIVATE lfs
)
751 HWND hWnd
= lfs
->hwnd
;
754 lRet
= SendDlgItemMessageW(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
758 /* set the edit control to the choosen file */
759 if ((pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
761 SendDlgItemMessageW(hWnd
, lst1
, LB_GETTEXT
, lRet
,
763 SetDlgItemTextW( hWnd
, edt1
, pstr
);
764 HeapFree(GetProcessHeap(), 0, pstr
);
768 FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, lst1
,
769 MAKELONG(lRet
,CD_LBSELCHANGE
));
771 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD,
776 /***********************************************************************
777 * FILEDLG_TestPath [internal]
778 * before accepting the file name, test if it includes wild cards
779 * tries to scan the directory and returns TRUE if no error.
781 static LRESULT
FILEDLG_TestPath( LFSPRIVATE lfs
, LPWSTR path
)
783 HWND hWnd
= lfs
->hwnd
;
784 LPWSTR pBeginFileName
, pstr2
;
785 WCHAR tmpstr2
[BUFFILE
];
787 pBeginFileName
= strrchrW(path
, '\\');
788 if (pBeginFileName
== NULL
)
789 pBeginFileName
= strrchrW(path
, ':');
791 if (strchrW(path
,'*') != NULL
|| strchrW(path
,'?') != NULL
)
793 /* edit control contains wildcards */
794 if (pBeginFileName
!= NULL
)
796 lstrcpynW(tmpstr2
, pBeginFileName
+ 1, BUFFILE
);
797 *(pBeginFileName
+ 1) = 0;
801 strcpyW(tmpstr2
, path
);
805 TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path
), debugstr_w(tmpstr2
));
806 SetDlgItemTextW( hWnd
, edt1
, tmpstr2
);
807 FILEDLG_ScanDir(hWnd
, path
);
811 /* no wildcards, we might have a directory or a filename */
812 /* try appending a wildcard and reading the directory */
814 pstr2
= path
+ lstrlenW(path
);
815 if (pBeginFileName
== NULL
|| *(pBeginFileName
+ 1) != 0)
816 strcatW(path
, FILE_bslash
);
818 /* if ScanDir succeeds, we have changed the directory */
819 if (FILEDLG_ScanDir(hWnd
, path
))
822 /* if not, this must be a filename */
824 *pstr2
= 0; /* remove the wildcard added before */
826 if (pBeginFileName
!= NULL
)
828 /* strip off the pathname */
830 SetDlgItemTextW( hWnd
, edt1
, pBeginFileName
+ 1 );
832 lstrcpynW(tmpstr2
, pBeginFileName
+ 1, sizeof(tmpstr2
) );
833 /* Should we MessageBox() if this fails? */
834 if (!FILEDLG_ScanDir(hWnd
, path
))
838 strcpyW(path
, tmpstr2
);
841 SetDlgItemTextW( hWnd
, edt1
, path
);
845 /***********************************************************************
846 * FILEDLG_Validate [internal]
847 * called on: click Ok button, Enter in edit, DoubleClick in file list
849 static LRESULT
FILEDLG_Validate( LFSPRIVATE lfs
, LPWSTR path
, UINT control
, INT itemIndex
,
853 HWND hWnd
= lfs
->hwnd
;
854 OPENFILENAMEW ofnsav
;
855 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
856 WCHAR filename
[BUFFILE
];
858 ofnsav
= *ofnW
; /* for later restoring */
860 /* get current file name */
862 lstrcpynW(filename
, path
, sizeof(filename
));
864 GetDlgItemTextW( hWnd
, edt1
, filename
, sizeof(filename
) );
866 /* if we did not click in file list to get there */
869 if (!FILEDLG_TestPath( lfs
, filename
) )
872 FILEDLG_UpdateResult(lfs
, filename
);
875 { /* called internally after a change in a combo */
878 FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, control
,
879 MAKELONG(itemIndex
,CD_LBSELCHANGE
));
884 FILEDLG_UpdateFileTitle(lfs
);
887 lRet
= (BOOL
)FILEDLG_CallWindowProc(lfs
, lfs
->fileokstring
,
891 *ofnW
= ofnsav
; /* restore old state */
895 if ((ofnW
->Flags
& OFN_ALLOWMULTISELECT
) && (ofnW
->Flags
& OFN_EXPLORER
))
899 LPWSTR str
= (LPWSTR
)ofnW
->lpstrFile
;
900 LPWSTR ptr
= strrchrW(str
, '\\');
901 str
[lstrlenW(str
) + 1] = '\0';
908 /***********************************************************************
909 * FILEDLG_DiskChange [internal]
910 * called when a new item is picked in the disk selection combo
912 static LRESULT
FILEDLG_DiskChange( LFSPRIVATE lfs
)
915 HWND hWnd
= lfs
->hwnd
;
917 WCHAR diskname
[BUFFILE
];
919 FILEDLG_StripEditControl(hWnd
);
920 lRet
= SendDlgItemMessageW(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
923 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
924 SendDlgItemMessageW(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
,
926 wsprintfW(diskname
, FILE_specc
, pstr
[2]);
927 HeapFree(GetProcessHeap(), 0, pstr
);
929 return FILEDLG_Validate( lfs
, diskname
, cmb2
, lRet
, TRUE
);
933 /***********************************************************************
934 * FILEDLG_FileTypeChange [internal]
935 * called when a new item is picked in the file type combo
937 static LRESULT
FILEDLG_FileTypeChange( LFSPRIVATE lfs
)
940 WCHAR diskname
[BUFFILE
];
945 lRet
= SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETCURSEL
, 0, 0);
948 pstr
= (LPWSTR
)SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
949 TRACE("Selected filter : %s\n", debugstr_w(pstr
));
950 SetDlgItemTextW( lfs
->hwnd
, edt1
, pstr
);
952 return FILEDLG_Validate( lfs
, NULL
, cmb1
, lRet
, TRUE
);
955 /***********************************************************************
956 * FILEDLG_WMCommand [internal]
958 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, LPARAM lParam
, UINT notification
,
959 UINT control
, LFSPRIVATE lfs
)
963 case lst1
: /* file list */
964 FILEDLG_StripEditControl(hWnd
);
965 if (notification
== LBN_DBLCLK
)
967 if (FILEDLG_Validate( lfs
, NULL
, control
, 0, FALSE
))
968 EndDialog(hWnd
, TRUE
);
971 else if (notification
== LBN_SELCHANGE
)
972 return FILEDLG_FileListSelect( lfs
);
975 case lst2
: /* directory list */
976 FILEDLG_StripEditControl(hWnd
);
977 if (notification
== LBN_DBLCLK
)
978 return FILEDLG_DirListDblClick( lfs
);
981 case cmb1
: /* file type drop list */
982 if (notification
== CBN_SELCHANGE
)
983 return FILEDLG_FileTypeChange( lfs
);
992 case cmb2
: /* disk dropdown combo */
993 if (notification
== CBN_SELCHANGE
)
994 return FILEDLG_DiskChange( lfs
);
998 if (FILEDLG_Validate( lfs
, NULL
, control
, 0, FALSE
))
999 EndDialog(hWnd
, TRUE
);
1003 EndDialog(hWnd
, FALSE
);
1006 case IDABORT
: /* can be sent by the hook procedure */
1007 EndDialog(hWnd
, TRUE
);
1013 /***********************************************************************
1014 * FILEDLG_MapDrawItemStruct [internal]
1015 * map a 16 bits drawitem struct to 32
1017 void FILEDLG_MapDrawItemStruct(LPDRAWITEMSTRUCT16 lpdis16
, LPDRAWITEMSTRUCT lpdis
)
1019 lpdis
->CtlType
= lpdis16
->CtlType
;
1020 lpdis
->CtlID
= lpdis16
->CtlID
;
1021 lpdis
->itemID
= lpdis16
->itemID
;
1022 lpdis
->itemAction
= lpdis16
->itemAction
;
1023 lpdis
->itemState
= lpdis16
->itemState
;
1024 lpdis
->hwndItem
= lpdis16
->hwndItem
;
1025 lpdis
->hDC
= lpdis16
->hDC
;
1026 lpdis
->rcItem
.right
= lpdis16
->rcItem
.right
;
1027 lpdis
->rcItem
.left
= lpdis16
->rcItem
.left
;
1028 lpdis
->rcItem
.top
= lpdis16
->rcItem
.top
;
1029 lpdis
->rcItem
.bottom
= lpdis16
->rcItem
.bottom
;
1030 lpdis
->itemData
= lpdis16
->itemData
;
1033 /************************************************************************
1034 * FILEDLG_MapStringPairsToW [internal]
1035 * map string pairs to Unicode
1037 LPWSTR
FILEDLG_MapStringPairsToW(LPCSTR strA
, UINT size
)
1048 if (n
< size
) n
= size
;
1050 len
= MultiByteToWideChar( CP_ACP
, 0, strA
, n
, NULL
, 0 );
1051 x
= HeapAlloc(GetProcessHeap(),0, len
* sizeof(WCHAR
));
1052 MultiByteToWideChar( CP_ACP
, 0, strA
, n
, x
, len
);
1057 /************************************************************************
1058 * FILEDLG_DupToW [internal]
1059 * duplicates an Ansi string to unicode, with a buffer size
1061 LPWSTR
FILEDLG_DupToW(LPCSTR str
, DWORD size
)
1064 if (str
&& (size
> 0))
1066 strW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1067 if (strW
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, strW
, size
);
1073 /************************************************************************
1074 * FILEDLG_MapOfnStructA [internal]
1075 * map a 32 bits Ansi structure to an Unicode one
1077 void FILEDLG_MapOfnStructA(LPOPENFILENAMEA ofnA
, LPOPENFILENAMEW ofnW
, BOOL open
)
1081 ofnW
->lStructSize
= sizeof(OPENFILENAMEW
);
1082 ofnW
->hwndOwner
= ofnA
->hwndOwner
;
1083 ofnW
->hInstance
= ofnA
->hInstance
;
1084 if (ofnA
->lpstrFilter
)
1085 ofnW
->lpstrFilter
= FILEDLG_MapStringPairsToW(ofnA
->lpstrFilter
, 0);
1087 ofnW
->lpstrFilter
= FILEDLG_MapStringPairsToW(defaultfilter
, 0);
1089 if ((ofnA
->lpstrCustomFilter
) && (*(ofnA
->lpstrCustomFilter
)))
1090 ofnW
->lpstrCustomFilter
= FILEDLG_MapStringPairsToW(ofnA
->lpstrCustomFilter
, ofnA
->nMaxCustFilter
);
1091 ofnW
->nMaxCustFilter
= ofnA
->nMaxCustFilter
;
1092 ofnW
->nFilterIndex
= ofnA
->nFilterIndex
;
1093 ofnW
->nMaxFile
= ofnA
->nMaxFile
;
1094 ofnW
->lpstrFile
= FILEDLG_DupToW(ofnA
->lpstrFile
, ofnW
->nMaxFile
);
1095 ofnW
->nMaxFileTitle
= ofnA
->nMaxFileTitle
;
1096 ofnW
->lpstrFileTitle
= FILEDLG_DupToW(ofnA
->lpstrFileTitle
, ofnW
->nMaxFileTitle
);
1097 if (ofnA
->lpstrInitialDir
)
1098 ofnW
->lpstrInitialDir
= HEAP_strdupAtoW(GetProcessHeap(),0,ofnA
->lpstrInitialDir
);
1099 if (ofnA
->lpstrTitle
)
1100 str
= ofnA
->lpstrTitle
;
1102 /* Allocates default title (FIXME : get it from resource) */
1103 str
= open
? defaultopen
:defaultsave
;
1104 ofnW
->lpstrTitle
= HEAP_strdupAtoW(GetProcessHeap(),0, str
);
1105 ofnW
->Flags
= ofnA
->Flags
;
1106 ofnW
->nFileOffset
= ofnA
->nFileOffset
;
1107 ofnW
->nFileExtension
= ofnA
->nFileExtension
;
1108 ofnW
->lpstrDefExt
= FILEDLG_DupToW(ofnA
->lpstrDefExt
, 3);
1109 if ((ofnA
->Flags
& OFN_ENABLETEMPLATE
) && (ofnA
->lpTemplateName
))
1111 if (HIWORD(ofnA
->lpTemplateName
))
1112 ofnW
->lpTemplateName
= HEAP_strdupAtoW(GetProcessHeap(), 0, ofnA
->lpTemplateName
);
1113 else /* numbered resource */
1114 ofnW
->lpTemplateName
= (LPWSTR
) ofnA
->lpTemplateName
;
1119 /************************************************************************
1120 * FILEDLG_MapOfnStruct16 [internal]
1121 * map a 16 bits structure to an Unicode one
1123 void FILEDLG_MapOfnStruct16(LPOPENFILENAME16 ofn16
, LPOPENFILENAMEW ofnW
, BOOL open
)
1126 /* first convert to linear pointers */
1127 memset(&ofnA
, 0, sizeof(OPENFILENAMEA
));
1128 ofnA
.lStructSize
= sizeof(OPENFILENAMEA
);
1129 ofnA
.hwndOwner
= ofn16
->hwndOwner
;
1130 ofnA
.hInstance
= ofn16
->hInstance
;
1131 if (ofn16
->lpstrFilter
)
1132 ofnA
.lpstrFilter
= PTR_SEG_TO_LIN(ofn16
->lpstrFilter
);
1133 if (ofn16
->lpstrCustomFilter
)
1134 ofnA
.lpstrCustomFilter
= PTR_SEG_TO_LIN(ofn16
->lpstrCustomFilter
);
1135 ofnA
.nMaxCustFilter
= ofn16
->nMaxCustFilter
;
1136 ofnA
.nFilterIndex
= ofn16
->nFilterIndex
;
1137 ofnA
.lpstrFile
= PTR_SEG_TO_LIN(ofn16
->lpstrFile
);
1138 ofnA
.nMaxFile
= ofn16
->nMaxFile
;
1139 ofnA
.lpstrFileTitle
= PTR_SEG_TO_LIN(ofn16
->lpstrFileTitle
);
1140 ofnA
.nMaxFileTitle
= ofn16
->nMaxFileTitle
;
1141 ofnA
.lpstrInitialDir
= PTR_SEG_TO_LIN(ofn16
->lpstrInitialDir
);
1142 ofnA
.lpstrTitle
= PTR_SEG_TO_LIN(ofn16
->lpstrTitle
);
1143 ofnA
.Flags
= ofn16
->Flags
;
1144 ofnA
.nFileOffset
= ofn16
->nFileOffset
;
1145 ofnA
.nFileExtension
= ofn16
->nFileExtension
;
1146 ofnA
.lpstrDefExt
= PTR_SEG_TO_LIN(ofn16
->lpstrDefExt
);
1147 if (HIWORD(ofn16
->lpTemplateName
))
1148 ofnA
.lpTemplateName
= PTR_SEG_TO_LIN(ofn16
->lpTemplateName
);
1150 ofnA
.lpTemplateName
= (LPSTR
) ofn16
->lpTemplateName
; /* ressource number */
1151 /* now calls the 32 bits Ansi to Unicode version to complete the job */
1152 FILEDLG_MapOfnStructA(&ofnA
, ofnW
, open
);
1156 /************************************************************************
1157 * FILEDLG_DestroyPrivate [internal]
1158 * destroys the private object
1160 void FILEDLG_DestroyPrivate(LFSPRIVATE lfs
)
1165 /* free resources for a 16 bits dialog */
1166 if (lfs
->hResource16
) FreeResource16(lfs
->hResource16
);
1169 GlobalUnlock16(lfs
->hGlobal16
);
1170 GlobalFree16(lfs
->hGlobal16
);
1172 /* if ofnW has been allocated, have to free everything in it */
1173 if (lfs
->ofn16
|| lfs
->ofnA
)
1175 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
1176 if (ofnW
->lpstrFilter
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrFilter
);
1177 if (ofnW
->lpstrCustomFilter
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrCustomFilter
);
1178 if (ofnW
->lpstrFile
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFile
);
1179 if (ofnW
->lpstrFileTitle
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFileTitle
);
1180 if (ofnW
->lpstrInitialDir
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrInitialDir
);
1181 if (ofnW
->lpstrTitle
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrTitle
);
1182 if ((ofnW
->lpTemplateName
) && (HIWORD(ofnW
->lpTemplateName
)))
1183 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpTemplateName
);
1184 HeapFree(GetProcessHeap(), 0, ofnW
);
1186 TRACE("destroying private allocation %p\n", lfs
);
1187 HeapFree(GetProcessHeap(), 0, lfs
);
1188 RemovePropA(hwnd
, OFN_PROP
);
1191 /************************************************************************
1192 * FILEDLG_AllocPrivate [internal]
1193 * allocate a private object to hold 32 bits Unicode
1194 * structure that will be used throughtout the calls, while
1195 * keeping available the original structures and a few variables
1196 * On entry : type = dialog procedure type (16,32A,32W)
1197 * dlgType = dialog type (open or save)
1199 LFSPRIVATE
FILEDLG_AllocPrivate(LPARAM lParam
, int type
, UINT dlgType
)
1201 LFSPRIVATE lfs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct FSPRIVATE
));
1203 TRACE("alloc private buf %p\n", lfs
);
1204 if (!lfs
) return NULL
;
1206 lfs
->lParam
= lParam
;
1207 if (dlgType
== OPEN_DIALOG
)
1211 lfs
->lbselchstring
= RegisterWindowMessageA(LBSELCHSTRING
);
1212 lfs
->fileokstring
= RegisterWindowMessageA(FILEOKSTRING
);
1216 lfs
->ofn16
= (LPOPENFILENAME16
) PTR_SEG_TO_LIN(lParam
);
1217 if (lfs
->ofn16
->Flags
& OFN_ENABLEHOOK
)
1218 if (lfs
->ofn16
->lpfnHook
)
1224 lfs
->ofnA
= (LPOPENFILENAMEA
) lParam
;
1225 if (lfs
->ofnA
->Flags
& OFN_ENABLEHOOK
)
1226 if (lfs
->ofnA
->lpfnHook
)
1231 lfs
->ofnW
= (LPOPENFILENAMEW
) lParam
;
1232 if (lfs
->ofnW
->Flags
& OFN_ENABLEHOOK
)
1233 if (lfs
->ofnW
->lpfnHook
)
1239 { /* this structure is needed internally, so create it */
1240 lfs
->ofnW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(OPENFILENAMEW
));
1244 FILEDLG_MapOfnStruct16(lfs
->ofn16
, lfs
->ofnW
, lfs
->open
);
1246 FILEDLG_MapOfnStructA(lfs
->ofnA
, lfs
->ofnW
, lfs
->open
);
1253 if (!Get16BitsTemplate(lfs
)) ret
= NULL
;
1256 if (!Get32BitsTemplate(lfs
)) ret
= NULL
;
1257 if (!ret
) FILEDLG_DestroyPrivate(lfs
);
1262 /***********************************************************************
1263 * GetFileName31A [internal]
1265 * Creates a win31 style dialog box for the user to select a file to open/save.
1267 BOOL WINAPI
GetFileName31A(
1268 LPOPENFILENAMEA lpofn
, /* addess of structure with data*/
1269 UINT dlgType
/* type dialogue : open/save */
1276 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1278 lfs
= FILEDLG_AllocPrivate((LPARAM
) lpofn
, LFS32A
, dlgType
);
1281 hInst
= GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1282 bRet
= DialogBoxIndirectParamA( hInst
, lfs
->template, lpofn
->hwndOwner
,
1283 (DLGPROC
) FileOpenDlgProc
, (DWORD
) lfs
);
1284 FILEDLG_DestroyPrivate(lfs
);
1287 TRACE("return lpstrFile='%s' !\n", lpofn
->lpstrFile
);
1292 /***********************************************************************
1293 * GetFileName31W [internal]
1295 * Creates a win31 style dialog box for the user to select a file to open/save
1297 BOOL WINAPI
GetFileName31W(
1298 LPOPENFILENAMEW lpofn
, /* addess of structure with data*/
1299 UINT dlgType
/* type dialogue : open/save */
1306 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1308 lfs
= FILEDLG_AllocPrivate((LPARAM
) lpofn
, LFS32W
, dlgType
);
1311 hInst
= GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1312 bRet
= DialogBoxIndirectParamW( hInst
, lfs
->template, lpofn
->hwndOwner
,
1313 (DLGPROC
) FileOpenDlgProc
, (DWORD
) lfs
);
1314 FILEDLG_DestroyPrivate(lfs
);
1317 TRACE("return lpstrFile='%s' !\n", debugstr_w(lpofn
->lpstrFile
));
1322 /* ------------------ Dialog procedures ---------------------- */
1324 /***********************************************************************
1325 * FileOpenDlgProc16 (COMMDLG.6)
1327 LRESULT WINAPI
FileOpenDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
1330 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1333 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1334 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1336 LRESULT lRet
= (BOOL16
)FILEDLG_CallWindowProc(lfs
, wMsg
, wParam
, lParam
);
1338 return lRet
; /* else continue message processing */
1343 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
1345 case WM_MEASUREITEM
:
1346 return FILEDLG_WMMeasureItem16(hWnd
, wParam
, lParam
);
1349 FILEDLG_MapDrawItemStruct((LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
), &dis
);
1350 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
, &dis
);
1353 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(lParam
),wParam
, lfs
);
1356 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
1357 switch (HIWORD(lParam
))
1360 SetTextColor((HDC16
)wParam
, 0x00000000);
1362 case CTLCOLOR_STATIC
:
1363 SetTextColor((HDC16
)wParam
, 0x00000000);
1372 /***********************************************************************
1373 * FileSaveDlgProc16 (COMMDLG.7)
1375 LRESULT WINAPI
FileSaveDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
1378 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1381 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1382 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1385 lRet
= (BOOL16
)FILEDLG_CallWindowProc(lfs
, wMsg
, wParam
, lParam
);
1387 return lRet
; /* else continue message processing */
1391 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
1393 case WM_MEASUREITEM
:
1394 return FILEDLG_WMMeasureItem16(hWnd
, wParam
, lParam
);
1397 FILEDLG_MapDrawItemStruct((LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
), &dis
);
1398 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
, &dis
);
1401 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(lParam
), wParam
, lfs
);
1406 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1407 switch (HIWORD(lParam))
1410 SetTextColor((HDC16)wParam, 0x00000000);
1412 case CTLCOLOR_STATIC:
1413 SetTextColor((HDC16)wParam, 0x00000000);
1422 /***********************************************************************
1423 * FileOpenDlgProc [internal]
1424 * Used for open and save, in fact.
1426 static LRESULT WINAPI
FileOpenDlgProc(HWND hWnd
, UINT wMsg
,
1427 WPARAM wParam
, LPARAM lParam
)
1429 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1431 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1432 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1435 lRet
= (BOOL
)FILEDLG_CallWindowProc(lfs
, wMsg
, wParam
, lParam
);
1437 return lRet
; /* else continue message processing */
1442 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
1444 case WM_MEASUREITEM
:
1445 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
1448 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, !lfs
->open
, (DRAWITEMSTRUCT
*)lParam
);
1451 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(wParam
), LOWORD(wParam
), lfs
);
1454 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
1455 switch (HIWORD(lParam
))
1458 SetTextColor((HDC16
)wParam
, 0x00000000);
1460 case CTLCOLOR_STATIC
:
1461 SetTextColor((HDC16
)wParam
, 0x00000000);
1470 /* ------------------ APIs ---------------------- */
1472 /***********************************************************************
1473 * GetOpenFileName16 (COMMDLG.1)
1475 * Creates a dialog box for the user to select a file to open.
1478 * TRUE on success: user selected a valid file
1479 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1482 * unknown, there are some FIXME's left.
1484 BOOL16 WINAPI
GetOpenFileName16(
1485 SEGPTR ofn
/* addess of structure with data*/
1490 LPOPENFILENAME16 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(ofn
);
1494 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1496 lfs
= FILEDLG_AllocPrivate((LPARAM
) ofn
, LFS16
, OPEN_DIALOG
);
1499 hInst
= GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1500 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 6);
1501 bRet
= DialogBoxIndirectParam16( hInst
, lfs
->hDlgTmpl16
, lpofn
->hwndOwner
,
1502 (DLGPROC16
) ptr
, (DWORD
) lfs
);
1503 FILEDLG_DestroyPrivate(lfs
);
1506 TRACE("return lpstrFile='%s' !\n",
1507 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
1511 /***********************************************************************
1512 * GetSaveFileName16 (COMMDLG.2)
1514 * Creates a dialog box for the user to select a file to save.
1517 * TRUE on success: user enters a valid file
1518 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1521 * unknown. There are some FIXME's left.
1523 BOOL16 WINAPI
GetSaveFileName16(
1524 SEGPTR ofn
/* addess of structure with data*/
1529 LPOPENFILENAME16 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(ofn
);
1533 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1535 lfs
= FILEDLG_AllocPrivate((LPARAM
) ofn
, LFS16
, SAVE_DIALOG
);
1538 hInst
= GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1539 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 7);
1540 bRet
= DialogBoxIndirectParam16( hInst
, lfs
->hDlgTmpl16
, lpofn
->hwndOwner
,
1541 (DLGPROC16
) ptr
, (DWORD
) lfs
);
1542 FILEDLG_DestroyPrivate(lfs
);
1545 TRACE("return lpstrFile='%s' !\n",
1546 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
1550 /***********************************************************************
1551 * GetOpenFileNameA (COMDLG32.10)
1553 * Creates a dialog box for the user to select a file to open.
1556 * TRUE on success: user enters a valid file
1557 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1560 BOOL WINAPI
GetOpenFileNameA(
1561 LPOPENFILENAMEA ofn
) /* address of init structure */
1565 /* some flags don't allow to match the TWEAK_WineLook */
1566 if (ofn
->Flags
& (OFN_ALLOWMULTISELECT
|OFN_ENABLEHOOK
|OFN_ENABLETEMPLATE
))
1568 newlook
= (ofn
->Flags
& OFN_EXPLORER
) ? TRUE
: FALSE
;
1572 /* no special flags set, we can match the TWEAK_WineLook */
1573 newlook
= (TWEAK_WineLook
>WIN31_LOOK
) ? TRUE
: FALSE
;
1578 return GetFileDialog95A(ofn
, OPEN_DIALOG
);
1582 return GetFileName31A(ofn
, OPEN_DIALOG
);
1586 /***********************************************************************
1587 * GetOpenFileNameW (COMDLG32.11)
1589 * Creates a dialog box for the user to select a file to open.
1592 * TRUE on success: user enters a valid file
1593 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1596 BOOL WINAPI
GetOpenFileNameW(
1597 LPOPENFILENAMEW ofn
) /* address of init structure */
1601 /* some flags don't allow to match the TWEAK_WineLook */
1602 if (ofn
->Flags
& (OFN_ALLOWMULTISELECT
|OFN_ENABLEHOOK
|OFN_ENABLETEMPLATE
))
1604 newlook
= (ofn
->Flags
& OFN_EXPLORER
) ? TRUE
: FALSE
;
1608 /* no special flags set, we can match the TWEAK_WineLook */
1609 newlook
= (TWEAK_WineLook
>WIN31_LOOK
) ? TRUE
: FALSE
;
1614 return GetFileDialog95W(ofn
, OPEN_DIALOG
);
1618 return GetFileName31W(ofn
, OPEN_DIALOG
);
1622 /***********************************************************************
1623 * GetSaveFileNameA (COMDLG32.12)
1625 * Creates a dialog box for the user to select a file to save.
1628 * TRUE on success: user enters a valid file
1629 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1632 BOOL WINAPI
GetSaveFileNameA(
1633 LPOPENFILENAMEA ofn
) /* address of init structure */
1637 /* some flags don't allow to match the TWEAK_WineLook */
1638 if (ofn
->Flags
& (OFN_ALLOWMULTISELECT
|OFN_ENABLEHOOK
|OFN_ENABLETEMPLATE
))
1640 newlook
= (ofn
->Flags
& OFN_EXPLORER
) ? TRUE
: FALSE
;
1644 /* no special flags set, we can match the TWEAK_WineLook */
1645 newlook
= (TWEAK_WineLook
>WIN31_LOOK
) ? TRUE
: FALSE
;
1650 return GetFileDialog95A(ofn
, SAVE_DIALOG
);
1654 return GetFileName31A(ofn
, SAVE_DIALOG
);
1658 /***********************************************************************
1659 * GetSaveFileNameW (COMDLG32.13)
1661 * Creates a dialog box for the user to select a file to save.
1664 * TRUE on success: user enters a valid file
1665 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1668 BOOL WINAPI
GetSaveFileNameW(
1669 LPOPENFILENAMEW ofn
) /* address of init structure */
1673 /* some flags don't allow to match the TWEAK_WineLook */
1674 if (ofn
->Flags
& (OFN_ALLOWMULTISELECT
|OFN_ENABLEHOOK
|OFN_ENABLETEMPLATE
))
1676 newlook
= (ofn
->Flags
& OFN_EXPLORER
) ? TRUE
: FALSE
;
1680 /* no special flags set, we can match the TWEAK_WineLook */
1681 newlook
= (TWEAK_WineLook
>WIN31_LOOK
) ? TRUE
: FALSE
;
1686 return GetFileDialog95W(ofn
, SAVE_DIALOG
);
1690 return GetFileName31W(ofn
, SAVE_DIALOG
);