2 * COMMDLG - File Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
14 #include "wine/winbase16.h"
15 #include "wine/winuser16.h"
16 #include "wine/unicode.h"
24 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(commdlg
);
34 #define BUFFILEALLOC 512 * sizeof(WCHAR)
38 HWND hwnd
; /* file dialog window handle */
39 BOOL hook
; /* TRUE if the dialog is hooked */
40 UINT lbselchstring
; /* registered message id */
41 UINT fileokstring
; /* registered message id */
42 LPARAM lParam
; /* save original lparam */
43 HANDLE16 hDlgTmpl16
; /* handle for resource 16 */
44 HANDLE16 hResource16
; /* handle for allocated resource 16 */
45 HANDLE16 hGlobal16
; /* 16 bits mem block (resources) */
46 LPCVOID
template; /* template for 32 bits resource */
47 BOOL open
; /* TRUE if open dialog, FALSE if save dialog */
48 OPENFILENAMEW
*ofnW
; /* original structure or work struct */
49 OPENFILENAMEA
*ofnA
; /* original structure if 32bits ansi dialog */
50 OPENFILENAME16
*ofn16
; /* original structure if 16 bits dialog */
54 #define LFSPRIVATE struct FSPRIVATE *
60 static const WCHAR FILE_star
[] = {'*','.','*', 0};
61 static const WCHAR FILE_bslash
[] = {'\\', 0};
62 static const WCHAR FILE_specc
[] = {'%','c',':', 0};
64 static HICON16 hFolder
= 0;
65 static HICON16 hFolder2
= 0;
66 static HICON16 hFloppy
= 0;
67 static HICON16 hHDisk
= 0;
68 static HICON16 hCDRom
= 0;
69 static HICON16 hNet
= 0;
70 static int fldrHeight
= 0;
71 static int fldrWidth
= 0;
73 #define OFN_PROP "FILEDLG_OFN"
75 static const char defaultfilter
[]=" \0\0";
76 static char defaultopen
[]="Open File";
77 static char defaultsave
[]="Save as";
79 /***********************************************************************
81 * Windows 3.1 style OpenFileName/SaveFileName dialog
85 LRESULT WINAPI
FileOpenDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
87 LRESULT WINAPI
FileSaveDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
90 static LRESULT WINAPI
FileOpenDlgProc(HWND hDlg
, UINT msg
,
91 WPARAM wParam
, LPARAM lParam
);
93 /***********************************************************************
94 * FileDlg_Init [internal]
96 static BOOL
FileDlg_Init(void)
98 static BOOL initialized
= 0;
99 CURSORICONINFO
*fldrInfo
;
102 if (!hFolder
) hFolder
= LoadIcon16(0, MAKEINTRESOURCE16(OIC_FOLDER
));
103 if (!hFolder2
) hFolder2
= LoadIcon16(0, MAKEINTRESOURCE16(OIC_FOLDER2
));
104 if (!hFloppy
) hFloppy
= LoadIcon16(0, MAKEINTRESOURCE16(OIC_FLOPPY
));
105 if (!hHDisk
) hHDisk
= LoadIcon16(0, MAKEINTRESOURCE16(OIC_HDISK
));
106 if (!hCDRom
) hCDRom
= LoadIcon16(0, MAKEINTRESOURCE16(OIC_CDROM
));
107 if (!hNet
) hNet
= LoadIcon16(0, MAKEINTRESOURCE16(OIC_NETWORK
));
108 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
109 hHDisk
== 0 || hCDRom
== 0 || hNet
== 0)
111 ERR("Error loading icons !\n");
114 fldrInfo
= (CURSORICONINFO
*) GlobalLock16( hFolder2
);
117 ERR("Error measuring icons !\n");
120 fldrHeight
= fldrInfo
-> nHeight
;
121 fldrWidth
= fldrInfo
-> nWidth
;
122 GlobalUnlock16( hFolder2
);
129 /***********************************************************************
130 * Get32BitsTemplate [internal]
132 * Get a template (or FALSE if failure) when 16 bits dialogs are used
133 * by a 32 bits application
136 BOOL
Get32BitsTemplate(LFSPRIVATE lfs
)
138 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
141 if (ofnW
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
143 if (!(lfs
->template = LockResource( ofnW
->hInstance
)))
145 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
149 else if (ofnW
->Flags
& OFN_ENABLETEMPLATE
)
153 hResInfo
= FindResourceA(lfs
->ofnA
->hInstance
,
154 lfs
->ofnA
->lpTemplateName
,
157 hResInfo
= FindResourceW(ofnW
->hInstance
,
158 ofnW
->lpTemplateName
,
162 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
165 if (!(hDlgTmpl
= LoadResource(ofnW
->hInstance
,
167 !(lfs
->template = LockResource(hDlgTmpl
)))
169 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
172 } else { /* get it from internal Wine resource */
174 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
,
175 lfs
->open
? "OPEN_FILE":"SAVE_FILE", RT_DIALOGA
)))
177 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
180 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
181 !(lfs
->template = LockResource( hDlgTmpl
)))
183 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
191 /***********************************************************************
192 * Get16BitsTemplate [internal]
194 * Get a template (FALSE if failure) when 16 bits dialogs are used
195 * by a 16 bits application
198 BOOL
Get16BitsTemplate(LFSPRIVATE lfs
)
200 LPOPENFILENAME16 ofn16
= lfs
->ofn16
;
202 HGLOBAL16 hGlobal16
= 0;
204 if (ofn16
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
205 lfs
->hDlgTmpl16
= ofn16
->hInstance
;
206 else if (ofn16
->Flags
& OFN_ENABLETEMPLATE
)
209 if (!(hResInfo
= FindResource16(ofn16
->hInstance
,
210 ofn16
->lpTemplateName
,
213 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
216 if (!(lfs
->hDlgTmpl16
= LoadResource16( ofn16
->hInstance
, hResInfo
)))
218 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
221 lfs
->hResource16
= lfs
->hDlgTmpl16
;
224 { /* get resource from (32 bits) own Wine resource; convert it to 16 */
225 HANDLE hResInfo
, hDlgTmpl32
;
229 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
,
230 lfs
->open
? "OPEN_FILE":"SAVE_FILE", RT_DIALOGA
)))
232 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
235 if (!(hDlgTmpl32
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
236 !(template32
= LockResource( hDlgTmpl32
)))
238 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
241 size
= SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo
);
242 hGlobal16
= GlobalAlloc16(0, size
);
245 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
246 ERR("alloc failure for %ld bytes\n", size
);
249 template = GlobalLock16(hGlobal16
);
252 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
253 ERR("global lock failure for %x handle\n", hGlobal16
);
254 GlobalFree16(hGlobal16
);
257 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
258 lfs
->hDlgTmpl16
= hGlobal16
;
259 lfs
->hGlobal16
= hGlobal16
;
264 /***********************************************************************
265 * FILEDLG_StripEditControl [internal]
266 * Strip pathnames off the contents of the edit control.
268 static void FILEDLG_StripEditControl(HWND hwnd
)
270 WCHAR temp
[BUFFILE
], *cp
;
272 GetDlgItemTextW( hwnd
, edt1
, temp
, sizeof(temp
) );
273 cp
= strrchrW(temp
, '\\');
277 cp
= strrchrW(temp
, ':');
281 /* FIXME: shouldn't we do something with the result here? ;-) */
286 /***********************************************************************
287 * FILEDLG_CallWindowProc [internal]
289 * Call the appropriate hook
291 static BOOL
FILEDLG_CallWindowProc(LFSPRIVATE lfs
, UINT wMsg
, WPARAM wParam
,
296 return (BOOL16
) CallWindowProc16(
297 (WNDPROC16
)lfs
->ofn16
->lpfnHook
, lfs
->hwnd
,
298 (UINT16
)wMsg
, (WPARAM16
)wParam
, lParam
);
302 return (BOOL
) CallWindowProcA(
303 (WNDPROC
)lfs
->ofnA
->lpfnHook
, lfs
->hwnd
,
304 wMsg
, wParam
, lParam
);
309 return (BOOL
) CallWindowProcW(
310 (WNDPROC
)lfs
->ofnW
->lpfnHook
, lfs
->hwnd
,
311 wMsg
, wParam
, lParam
);
317 /***********************************************************************
318 * FILEDLG_ScanDir [internal]
320 static BOOL
FILEDLG_ScanDir(HWND hWnd
, LPWSTR newPath
)
322 WCHAR buffer
[BUFFILE
];
325 lstrcpynW(buffer
, newPath
, sizeof(buffer
));
327 if ( !SetCurrentDirectoryW( newPath
))
329 /* get the list of spec files */
330 GetDlgItemTextW(hWnd
, edt1
, buffer
, sizeof(buffer
));
332 if ((hdlg
= GetDlgItem(hWnd
, lst1
)) != 0) {
333 WCHAR
* scptr
; /* ptr on semi-colon */
334 WCHAR
* filter
= buffer
;
336 TRACE("Using filter %s\n", debugstr_w(filter
));
337 SendMessageW(hdlg
, LB_RESETCONTENT
, 0, 0);
339 scptr
= strchrW(filter
, ';');
340 if (scptr
) *scptr
= 0;
341 while (*filter
== ' ') filter
++;
342 TRACE("Using file spec %s\n", debugstr_w(filter
));
343 if (SendMessageW(hdlg
, LB_DIR
, 0, (LPARAM
)filter
) == LB_ERR
)
345 if (scptr
) *scptr
= ';';
346 filter
= (scptr
) ? (scptr
+ 1) : 0;
349 /* list of directories */
350 strcpyW(buffer
, FILE_star
);
351 return DlgDirListW(hWnd
, buffer
, lst2
, stc1
, DDL_EXCLUSIVE
| DDL_DIRECTORY
);
354 /***********************************************************************
355 * FILEDLG_GetFileType [internal]
358 static LPWSTR
FILEDLG_GetFileType(LPWSTR cfptr
, LPWSTR fptr
, WORD index
)
363 for ( ;(n
= lstrlenW(cfptr
)) != 0; i
++)
368 cfptr
+= lstrlenW(cfptr
) + 1;
371 for ( ;(n
= lstrlenW(fptr
)) != 0; i
++)
376 fptr
+= lstrlenW(fptr
) + 1;
378 return (LPWSTR
) FILE_star
; /* FIXME */
381 /***********************************************************************
382 * FILEDLG_WMDrawItem [internal]
384 static LONG
FILEDLG_WMDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
,
385 int savedlg
, LPDRAWITEMSTRUCT lpdis
)
389 COLORREF oldText
= 0, oldBk
= 0;
391 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
393 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
))) return FALSE
;
394 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
397 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
399 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
400 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
403 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_GRAYTEXT
) );
405 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ 1,
406 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
407 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
409 if (lpdis
->itemState
& ODS_SELECTED
)
410 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
412 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
414 SetBkColor( lpdis
->hDC
, oldBk
);
415 SetTextColor( lpdis
->hDC
, oldText
);
417 HeapFree(GetProcessHeap(), 0, str
);
421 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
423 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
425 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
428 if (lpdis
->itemState
& ODS_SELECTED
)
430 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
431 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
433 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
434 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
435 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
437 if (lpdis
->itemState
& ODS_SELECTED
)
438 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
440 if (lpdis
->itemState
& ODS_SELECTED
)
442 SetBkColor( lpdis
->hDC
, oldBk
);
443 SetTextColor( lpdis
->hDC
, oldText
);
445 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hFolder
);
446 HeapFree(GetProcessHeap(), 0, str
);
449 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
451 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
453 SendMessageW(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
455 switch(DRIVE_GetType( str
[2] - 'a' ))
457 case TYPE_FLOPPY
: hIcon
= hFloppy
; break;
458 case TYPE_CDROM
: hIcon
= hCDRom
; break;
459 case TYPE_NETWORK
: hIcon
= hNet
; break;
461 default: hIcon
= hHDisk
; break;
463 if (lpdis
->itemState
& ODS_SELECTED
)
465 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
466 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
468 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
469 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
470 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
472 if (lpdis
->itemState
& ODS_SELECTED
)
474 SetBkColor( lpdis
->hDC
, oldBk
);
475 SetTextColor( lpdis
->hDC
, oldText
);
477 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hIcon
);
478 HeapFree(GetProcessHeap(), 0, str
);
484 /***********************************************************************
485 * FILEDLG_WMMeasureItem [internal]
487 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
489 LPMEASUREITEMSTRUCT lpmeasure
;
491 lpmeasure
= (LPMEASUREITEMSTRUCT
)lParam
;
492 lpmeasure
->itemHeight
= fldrHeight
;
496 /***********************************************************************
497 * FILEDLG_WMMeasureItem16 [internal]
499 static LONG
FILEDLG_WMMeasureItem16(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
501 LPMEASUREITEMSTRUCT16 lpmeasure
;
503 lpmeasure
= (LPMEASUREITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
504 lpmeasure
->itemHeight
= fldrHeight
;
508 /***********************************************************************
509 * FILEDLG_WMInitDialog [internal]
512 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
515 WCHAR tmpstr
[BUFFILE
];
516 LPWSTR pstr
, old_pstr
;
518 LFSPRIVATE lfs
= (LFSPRIVATE
) lParam
;
520 if (!lfs
) return FALSE
;
521 SetPropA(hWnd
, OFN_PROP
, (HANDLE
)lfs
);
525 TRACE("flags=%lx initialdir=%s\n", ofn
->Flags
, debugstr_w(ofn
->lpstrInitialDir
));
527 SetWindowTextW( hWnd
, ofn
->lpstrTitle
);
528 /* read custom filter information */
529 if (ofn
->lpstrCustomFilter
)
531 pstr
= ofn
->lpstrCustomFilter
;
533 TRACE("lpstrCustomFilter = %p\n", pstr
);
537 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
538 (LPARAM
)(ofn
->lpstrCustomFilter
) + n
);
539 n
+= lstrlenW(pstr
) + 1;
540 pstr
+= lstrlenW(pstr
) + 1;
541 TRACE("add str='%s' "
542 "associated to '%s'\n", debugstr_w(old_pstr
), debugstr_w(pstr
));
543 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
544 n
+= lstrlenW(pstr
) + 1;
545 pstr
+= lstrlenW(pstr
) + 1;
548 /* read filter information */
549 if (ofn
->lpstrFilter
) {
550 pstr
= (LPWSTR
) ofn
->lpstrFilter
;
554 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
555 (LPARAM
)(ofn
->lpstrFilter
+ n
) );
556 n
+= lstrlenW(pstr
) + 1;
557 pstr
+= lstrlenW(pstr
) + 1;
558 TRACE("add str='%s' "
559 "associated to '%s'\n", debugstr_w(old_pstr
), debugstr_w(pstr
));
560 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
561 n
+= lstrlenW(pstr
) + 1;
562 pstr
+= lstrlenW(pstr
) + 1;
565 /* set default filter */
566 if (ofn
->nFilterIndex
== 0 && ofn
->lpstrCustomFilter
== NULL
)
567 ofn
->nFilterIndex
= 1;
568 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETCURSEL
, ofn
->nFilterIndex
- 1, 0);
569 lstrcpynW(tmpstr
, FILEDLG_GetFileType(ofn
->lpstrCustomFilter
,
570 (LPWSTR
)ofn
->lpstrFilter
, ofn
->nFilterIndex
- 1),BUFFILE
);
571 TRACE("nFilterIndex = %ld, SetText of edt1 to '%s'\n",
572 ofn
->nFilterIndex
, debugstr_w(tmpstr
));
573 SetDlgItemTextW( hWnd
, edt1
, tmpstr
);
576 DlgDirListComboBoxW(hWnd
, tmpstr
, cmb2
, 0, DDL_DRIVES
| DDL_EXCLUSIVE
);
577 /* read initial directory */
578 if (ofn
->lpstrInitialDir
!= NULL
)
581 lstrcpynW(tmpstr
, ofn
->lpstrInitialDir
, 511);
582 len
= lstrlenW(tmpstr
);
583 if (len
> 0 && tmpstr
[len
-1] != '\\' && tmpstr
[len
-1] != ':') {
590 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) {
592 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
593 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr
));
595 /* select current drive in combo 2, omit missing drives */
596 for(i
= 0, n
= -1; i
<= DRIVE_GetCurrentDrive(); i
++)
597 if (DRIVE_IsValid(i
)) n
++;
598 SendDlgItemMessageW(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
599 if (!(ofn
->Flags
& OFN_SHOWHELP
))
600 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
601 if (ofn
->Flags
& OFN_HIDEREADONLY
)
602 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
604 return (BOOL
) FILEDLG_CallWindowProc(lfs
, WM_INITDIALOG
, wParam
, lfs
->lParam
);
608 /***********************************************************************
609 * FILEDLG_UpdateResult [internal]
610 * update the displayed file name (with path)
612 void FILEDLG_UpdateResult(LFSPRIVATE lfs
, WCHAR
*tmpstr
, WCHAR
*tmpstr2
)
615 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
617 GetCurrentDirectoryW(BUFFILE
, tmpstr2
);
618 lenstr2
= lstrlenW(tmpstr2
);
620 tmpstr2
[lenstr2
++]='\\';
621 lstrcpynW(tmpstr2
+lenstr2
, tmpstr
, BUFFILE
-lenstr2
);
623 lstrcpynW(ofnW
->lpstrFile
, tmpstr2
, ofnW
->nMaxFile
);
624 ofnW
->nFileOffset
= strrchrW(tmpstr2
,'\\') - tmpstr2
+1;
625 ofnW
->nFileExtension
= 0;
626 while(tmpstr2
[ofnW
->nFileExtension
] != '.' && tmpstr2
[ofnW
->nFileExtension
] != '\0')
627 ofnW
->nFileExtension
++;
628 if (tmpstr2
[ofnW
->nFileExtension
] == '\0')
629 ofnW
->nFileExtension
= 0;
631 ofnW
->nFileExtension
++;
632 /* update the real client structures if any */
635 lstrcpynWtoA(PTR_SEG_TO_LIN(lfs
->ofn16
->lpstrFile
), ofnW
->lpstrFile
, ofnW
->nMaxFile
);
636 lfs
->ofn16
->nFileOffset
= ofnW
->nFileOffset
;
637 lfs
->ofn16
->nFileExtension
= ofnW
->nFileExtension
;
641 lstrcpynWtoA(lfs
->ofnA
->lpstrFile
, ofnW
->lpstrFile
, ofnW
->nMaxFile
);
642 lfs
->ofnA
->nFileOffset
= ofnW
->nFileOffset
;
643 lfs
->ofnA
->nFileExtension
= ofnW
->nFileExtension
;
648 /***********************************************************************
649 * FILEDLG_UpdateFileTitle [internal]
650 * update the displayed file name (without path)
652 void FILEDLG_UpdateFileTitle(LFSPRIVATE lfs
)
655 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
656 if (ofnW
->lpstrFileTitle
!= NULL
)
658 lRet
= SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETCURSEL
, 0, 0);
659 SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETTEXT
, lRet
,
660 (LPARAM
)ofnW
->lpstrFileTitle
);
662 lstrcpynWtoA(PTR_SEG_TO_LIN(lfs
->ofn16
->lpstrFileTitle
),ofnW
->lpstrFileTitle
,
663 ofnW
->nMaxFileTitle
);
665 lstrcpynWtoA(lfs
->ofnA
->lpstrFileTitle
,ofnW
->lpstrFileTitle
,
666 ofnW
->nMaxFileTitle
);
670 /***********************************************************************
671 * FILEDLG_WMCommand [internal]
673 BOOL in_update
=FALSE
;
675 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, LPARAM lParam
, UINT notification
,
676 UINT control
, LFSPRIVATE lfs
)
680 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
681 WCHAR tmpstr
[BUFFILE
], tmpstr2
[BUFFILE
];
686 case lst1
: /* file list */
687 FILEDLG_StripEditControl(hWnd
);
688 if (notification
== LBN_DBLCLK
)
691 lRet
= SendDlgItemMessageW(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
692 if (lRet
== LB_ERR
) return TRUE
;
693 if ((pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
695 SendDlgItemMessageW(hWnd
, lst1
, LB_GETTEXT
, lRet
,
697 SetDlgItemTextW( hWnd
, edt1
, pstr
);
698 HeapFree(GetProcessHeap(), 0, pstr
);
701 FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, control
,
702 MAKELONG(lRet
,CD_LBSELCHANGE
));
703 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
706 case lst2
: /* directory list */
707 FILEDLG_StripEditControl(hWnd
);
708 if (notification
== LBN_DBLCLK
)
710 /* get the raw string (with brackets) */
711 lRet
= SendDlgItemMessageW(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
712 if (lRet
== LB_ERR
) return TRUE
;
713 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
714 SendDlgItemMessageW(hWnd
, lst2
, LB_GETTEXT
, lRet
,
716 strcpyW( tmpstr
, pstr
);
717 HeapFree(GetProcessHeap(), 0, pstr
);
718 /* get the selected directory in tmpstr */
719 if (tmpstr
[0] == '[')
721 tmpstr
[lstrlenW(tmpstr
) - 1] = 0;
722 strcpyW(tmpstr
,tmpstr
+1);
724 strcatW(tmpstr
, FILE_bslash
);
725 /* directory *has* to be changed before notifying the hook */
726 SetCurrentDirectoryW( tmpstr
);
730 if (FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, control
,
731 MAKELONG(lRet
,CD_LBSELCHANGE
)))
738 case cmb1
: /* file type drop list */
739 if (notification
== CBN_SELCHANGE
)
751 case cmb2
: /* disk drop list */
752 FILEDLG_StripEditControl(hWnd
);
753 lRet
= SendDlgItemMessageW(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
754 if (lRet
== LB_ERR
) return 0;
755 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
756 SendDlgItemMessageW(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
,
758 wsprintfW(tmpstr
, FILE_specc
, pstr
[2]);
759 HeapFree(GetProcessHeap(), 0, pstr
);
760 if (notification
!= CBN_SELCHANGE
) return TRUE
;
762 /* on entry tmpstr points to the new path to scan */
764 lRet
= SendDlgItemMessageW(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
767 pstr
= (LPWSTR
)SendDlgItemMessageW(hWnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
768 TRACE("Selected filter : %s\n", debugstr_w(pstr
));
769 SetDlgItemTextW( hWnd
, edt1
, pstr
);
770 FILEDLG_ScanDir(hWnd
, tmpstr
);
776 ofn2
= *ofnW
; /* for later restoring */
777 /* get current file name */
778 GetDlgItemTextW( hWnd
, edt1
, tmpstr
, sizeof(tmpstr
) );
779 pstr
= strrchrW(tmpstr
, '\\');
781 pstr
= strrchrW(tmpstr
, ':');
783 if (strchrW(tmpstr
,'*') != NULL
|| strchrW(tmpstr
,'?') != NULL
)
785 /* edit control contains wildcards */
788 lstrcpynW(tmpstr2
, pstr
+1, BUFFILE
);
793 strcpyW(tmpstr2
, tmpstr
);
797 TRACE("tmpstr=%s, tmpstr2=%s\n", debugstr_w(tmpstr
), debugstr_w(tmpstr2
));
798 SetDlgItemTextW( hWnd
, edt1
, tmpstr2
);
799 FILEDLG_ScanDir(hWnd
, tmpstr
);
802 /* no wildcards, we might have a directory or a filename */
803 /* try appending a wildcard and reading the directory */
804 pstr2
= tmpstr
+ lstrlenW(tmpstr
);
805 if (pstr
== NULL
|| *(pstr
+1) != 0)
806 strcatW(tmpstr
, FILE_bslash
);
807 lRet
= SendDlgItemMessageW(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
808 if (lRet
== LB_ERR
) return TRUE
;
809 ofnW
->nFilterIndex
= lRet
+ 1;
810 TRACE("ofn->nFilterIndex=%ld\n", ofnW
->nFilterIndex
);
812 FILEDLG_GetFileType(ofnW
->lpstrCustomFilter
,
813 (LPWSTR
) ofnW
->lpstrFilter
,
814 lRet
), sizeof(tmpstr2
));
815 SetDlgItemTextW( hWnd
, edt1
, tmpstr2
);
819 /* if ScanDir succeeds, we have changed the directory */
820 if (FILEDLG_ScanDir(hWnd
, tmpstr
))
823 /* if not, this must be a filename */
824 *pstr2
= 0; /* remove the wildcard added before */
828 /* strip off the pathname */
830 SetDlgItemTextW( hWnd
, edt1
, pstr
+ 1 );
831 lstrcpynW(tmpstr2
, pstr
+1, sizeof(tmpstr2
) );
832 /* Should we MessageBox() if this fails? */
833 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
834 strcpyW(tmpstr
, tmpstr2
);
836 else SetDlgItemTextW( hWnd
, edt1
, tmpstr
);
837 FILEDLG_UpdateResult(lfs
, tmpstr
, tmpstr2
);
841 FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, control
,
842 MAKELONG(lRet
,CD_LBSELCHANGE
));
846 FILEDLG_UpdateFileTitle(lfs
);
849 lRet
= (BOOL
)FILEDLG_CallWindowProc(lfs
, lfs
->fileokstring
,
853 *ofnW
= ofn2
; /* restore old state */
857 if ((ofnW
->Flags
& OFN_ALLOWMULTISELECT
) && (ofnW
->Flags
& OFN_EXPLORER
)) {
858 if (ofnW
->lpstrFile
) {
859 LPWSTR str
= (LPWSTR
)ofnW
->lpstrFile
;
860 LPWSTR ptr
= strrchrW(str
, '\\');
861 str
[lstrlenW(str
) + 1] = '\0';
865 EndDialog(hWnd
, TRUE
);
868 EndDialog(hWnd
, FALSE
);
870 case IDABORT
: /* can be sent by the hook procedure */
871 EndDialog(hWnd
, TRUE
);
878 /***********************************************************************
879 * FILEDLG_MapDrawItemStruct [internal]
880 * map a 16 bits drawitem struct to 32
882 void FILEDLG_MapDrawItemStruct(LPDRAWITEMSTRUCT16 lpdis16
, LPDRAWITEMSTRUCT lpdis
)
884 lpdis
->CtlType
= lpdis16
->CtlType
;
885 lpdis
->CtlID
= lpdis16
->CtlID
;
886 lpdis
->itemID
= lpdis16
->itemID
;
887 lpdis
->itemAction
= lpdis16
->itemAction
;
888 lpdis
->itemState
= lpdis16
->itemState
;
889 lpdis
->hwndItem
= lpdis16
->hwndItem
;
890 lpdis
->hDC
= lpdis16
->hDC
;
891 lpdis
->rcItem
.right
= lpdis16
->rcItem
.right
;
892 lpdis
->rcItem
.left
= lpdis16
->rcItem
.left
;
893 lpdis
->rcItem
.top
= lpdis16
->rcItem
.top
;
894 lpdis
->rcItem
.bottom
= lpdis16
->rcItem
.bottom
;
895 lpdis
->itemData
= lpdis16
->itemData
;
898 /************************************************************************
899 * FILEDLG_MapStringPairsToW [internal]
900 * map string pairs to Unicode
902 LPWSTR
FILEDLG_MapStringPairsToW(LPCSTR strA
, UINT size
)
913 if (n
< size
) n
= size
;
915 x
= y
= HeapAlloc(GetProcessHeap(),0, n
* sizeof(WCHAR
));
927 /************************************************************************
928 * FILEDLG_DupToW [internal]
929 * duplicates an Ansi string to unicode, with a buffer size
931 LPWSTR
FILEDLG_DupToW(LPCSTR str
, UINT size
)
934 if (str
&& (size
> 0))
936 strW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
937 lstrcpynAtoW(strW
, str
, size
);
945 /************************************************************************
946 * FILEDLG_MapOfnStructA [internal]
947 * map a 32 bits Ansi structure to an Unicode one
949 void FILEDLG_MapOfnStructA(LPOPENFILENAMEA ofnA
, LPOPENFILENAMEW ofnW
, BOOL open
)
953 ofnW
->lStructSize
= sizeof(OPENFILENAMEW
);
954 ofnW
->hwndOwner
= ofnA
->hwndOwner
;
955 ofnW
->hInstance
= ofnA
->hInstance
;
956 if (ofnA
->lpstrFilter
)
957 ofnW
->lpstrFilter
= FILEDLG_MapStringPairsToW(ofnA
->lpstrFilter
, 0);
959 ofnW
->lpstrFilter
= FILEDLG_MapStringPairsToW(defaultfilter
, 0);
961 if ((ofnA
->lpstrCustomFilter
) && (*(ofnA
->lpstrCustomFilter
)))
962 ofnW
->lpstrCustomFilter
= FILEDLG_MapStringPairsToW(ofnA
->lpstrCustomFilter
, ofnA
->nMaxCustFilter
);
963 ofnW
->nMaxCustFilter
= ofnA
->nMaxCustFilter
;
964 ofnW
->nFilterIndex
= ofnA
->nFilterIndex
;
965 ofnW
->lpstrFile
= FILEDLG_DupToW(ofnA
->lpstrFile
, ofnA
->nMaxFile
);
966 ofnW
->nMaxFile
= ofnA
->nMaxFile
;
967 ofnW
->lpstrFileTitle
= FILEDLG_DupToW(ofnA
->lpstrFileTitle
, ofnA
->nMaxFileTitle
);
968 ofnW
->nMaxFileTitle
= ofnA
->nMaxFileTitle
;
969 if (ofnA
->lpstrInitialDir
)
970 ofnW
->lpstrInitialDir
= HEAP_strdupAtoW(GetProcessHeap(),0,ofnA
->lpstrInitialDir
);
971 if (ofnA
->lpstrTitle
)
972 str
= ofnA
->lpstrTitle
;
974 /* Allocates default title (FIXME : get it from resource) */
975 str
= open
? defaultopen
:defaultsave
;
976 ofnW
->lpstrTitle
= HEAP_strdupAtoW(GetProcessHeap(),0, str
);
977 ofnW
->Flags
= ofnA
->Flags
;
978 ofnW
->nFileOffset
= ofnA
->nFileOffset
;
979 ofnW
->nFileExtension
= ofnA
->nFileExtension
;
980 ofnW
->lpstrDefExt
= FILEDLG_DupToW(ofnA
->lpstrDefExt
, 3);
981 if ((ofnA
->Flags
& OFN_ENABLETEMPLATE
) && (ofnA
->lpTemplateName
))
983 if (HIWORD(ofnA
->lpTemplateName
))
984 ofnW
->lpTemplateName
= HEAP_strdupAtoW(GetProcessHeap(), 0, ofnA
->lpTemplateName
);
985 else /* numbered resource */
986 ofnW
->lpTemplateName
= (LPWSTR
) ofnA
->lpTemplateName
;
991 /************************************************************************
992 * FILEDLG_MapOfnStruct16 [internal]
993 * map a 16 bits structure to an Unicode one
995 void FILEDLG_MapOfnStruct16(LPOPENFILENAME16 ofn16
, LPOPENFILENAMEW ofnW
, BOOL open
)
998 /* first convert to linear pointers */
999 memset(&ofnA
, 0, sizeof(OPENFILENAMEA
));
1000 ofnA
.lStructSize
= sizeof(OPENFILENAMEA
);
1001 ofnA
.hwndOwner
= ofn16
->hwndOwner
;
1002 ofnA
.hInstance
= ofn16
->hInstance
;
1003 if (ofn16
->lpstrFilter
)
1004 ofnA
.lpstrFilter
= PTR_SEG_TO_LIN(ofn16
->lpstrFilter
);
1005 if (ofn16
->lpstrCustomFilter
)
1006 ofnA
.lpstrCustomFilter
= PTR_SEG_TO_LIN(ofn16
->lpstrCustomFilter
);
1007 ofnA
.nMaxCustFilter
= ofn16
->nMaxCustFilter
;
1008 ofnA
.nFilterIndex
= ofn16
->nFilterIndex
;
1009 ofnA
.lpstrFile
= PTR_SEG_TO_LIN(ofn16
->lpstrFile
);
1010 ofnA
.nMaxFile
= ofn16
->nMaxFile
;
1011 ofnA
.lpstrFileTitle
= PTR_SEG_TO_LIN(ofn16
->lpstrFileTitle
);
1012 ofnA
.nMaxFileTitle
= ofn16
->nMaxFileTitle
;
1013 ofnA
.lpstrInitialDir
= PTR_SEG_TO_LIN(ofn16
->lpstrInitialDir
);
1014 ofnA
.lpstrTitle
= PTR_SEG_TO_LIN(ofn16
->lpstrTitle
);
1015 ofnA
.Flags
= ofn16
->Flags
;
1016 ofnA
.nFileOffset
= ofn16
->nFileOffset
;
1017 ofnA
.nFileExtension
= ofn16
->nFileExtension
;
1018 ofnA
.lpstrDefExt
= PTR_SEG_TO_LIN(ofn16
->lpstrDefExt
);
1019 if (HIWORD(ofn16
->lpTemplateName
))
1020 ofnA
.lpTemplateName
= PTR_SEG_TO_LIN(ofn16
->lpTemplateName
);
1022 ofnA
.lpTemplateName
= (LPSTR
) ofn16
->lpTemplateName
; /* ressource number */
1023 /* now calls the 32 bits Ansi to Unicode version to complete the job */
1024 FILEDLG_MapOfnStructA(&ofnA
, ofnW
, open
);
1028 /************************************************************************
1029 * FILEDLG_DestroyPrivate [internal]
1030 * destroys the private object
1032 void FILEDLG_DestroyPrivate(LFSPRIVATE lfs
)
1037 /* free resources for a 16 bits dialog */
1038 if (lfs
->hResource16
) FreeResource16(lfs
->hResource16
);
1041 GlobalUnlock16(lfs
->hGlobal16
);
1042 GlobalFree16(lfs
->hGlobal16
);
1044 /* if ofnW has been allocated, have to free everything in it */
1045 if (lfs
->ofn16
|| lfs
->ofnA
)
1047 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
1048 if (ofnW
->lpstrFilter
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrFilter
);
1049 if (ofnW
->lpstrCustomFilter
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrCustomFilter
);
1050 if (ofnW
->lpstrFile
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFile
);
1051 if (ofnW
->lpstrFileTitle
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFileTitle
);
1052 if (ofnW
->lpstrInitialDir
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrInitialDir
);
1053 if (ofnW
->lpstrTitle
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrTitle
);
1054 if ((ofnW
->lpTemplateName
) && (HIWORD(ofnW
->lpTemplateName
)))
1055 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpTemplateName
);
1056 HeapFree(GetProcessHeap(), 0, ofnW
);
1058 TRACE("destroying private allocation %p\n", lfs
);
1059 HeapFree(GetProcessHeap(), 0, lfs
);
1060 RemovePropA(hwnd
, OFN_PROP
);
1063 /************************************************************************
1064 * FILEDLG_AllocPrivate [internal]
1065 * allocate a private object to hold 32 bits Unicode
1066 * structure that will be used throughtout the calls, while
1067 * keeping available the original structures and a few variables
1068 * On entry : type = dialog procedure type (16,32A,32W)
1069 * dlgType = dialog type (open or save)
1071 LFSPRIVATE
FILEDLG_AllocPrivate(LPARAM lParam
, int type
, UINT dlgType
)
1073 LFSPRIVATE lfs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct FSPRIVATE
));
1075 TRACE("alloc private buf %p\n", lfs
);
1076 if (!lfs
) return NULL
;
1078 lfs
->lParam
= lParam
;
1079 if (dlgType
== OPEN_DIALOG
)
1083 lfs
->lbselchstring
= RegisterWindowMessageA(LBSELCHSTRING
);
1084 lfs
->fileokstring
= RegisterWindowMessageA(FILEOKSTRING
);
1088 lfs
->ofn16
= (LPOPENFILENAME16
) PTR_SEG_TO_LIN(lParam
);
1089 if (lfs
->ofn16
->Flags
& OFN_ENABLEHOOK
)
1090 if (lfs
->ofn16
->lpfnHook
)
1096 lfs
->ofnA
= (LPOPENFILENAMEA
) lParam
;
1097 if (lfs
->ofnA
->Flags
& OFN_ENABLEHOOK
)
1098 if (lfs
->ofnA
->lpfnHook
)
1103 lfs
->ofnW
= (LPOPENFILENAMEW
) lParam
;
1104 if (lfs
->ofnW
->Flags
& OFN_ENABLEHOOK
)
1105 if (lfs
->ofnW
->lpfnHook
)
1111 { /* this structure is needed internally, so create it */
1112 lfs
->ofnW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(OPENFILENAMEW
));
1116 FILEDLG_MapOfnStruct16(lfs
->ofn16
, lfs
->ofnW
, lfs
->open
);
1118 FILEDLG_MapOfnStructA(lfs
->ofnA
, lfs
->ofnW
, lfs
->open
);
1125 if (!Get16BitsTemplate(lfs
)) ret
= NULL
;
1128 if (!Get32BitsTemplate(lfs
)) ret
= NULL
;
1129 if (!ret
) FILEDLG_DestroyPrivate(lfs
);
1134 /***********************************************************************
1135 * GetFileName31A [internal]
1137 * Creates a win31 style dialog box for the user to select a file to open/save.
1139 BOOL WINAPI
GetFileName31A(
1140 LPOPENFILENAMEA lpofn
, /* addess of structure with data*/
1141 UINT dlgType
/* type dialogue : open/save */
1148 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1150 lfs
= FILEDLG_AllocPrivate((LPARAM
) lpofn
, LFS32A
, dlgType
);
1153 hInst
= GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1154 bRet
= DialogBoxIndirectParamA( hInst
, lfs
->template, lpofn
->hwndOwner
,
1155 (DLGPROC
) FileOpenDlgProc
, (DWORD
) lfs
);
1156 FILEDLG_DestroyPrivate(lfs
);
1159 TRACE("return lpstrFile='%s' !\n", lpofn
->lpstrFile
);
1164 /***********************************************************************
1165 * GetFileName31W [internal]
1167 * Creates a win31 style dialog box for the user to select a file to open/save
1169 BOOL WINAPI
GetFileName31W(
1170 LPOPENFILENAMEW lpofn
, /* addess of structure with data*/
1171 UINT dlgType
/* type dialogue : open/save */
1178 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1180 lfs
= FILEDLG_AllocPrivate((LPARAM
) lpofn
, LFS32W
, dlgType
);
1183 hInst
= GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1184 bRet
= DialogBoxIndirectParamW( hInst
, lfs
->template, lpofn
->hwndOwner
,
1185 (DLGPROC
) FileOpenDlgProc
, (DWORD
) lfs
);
1186 FILEDLG_DestroyPrivate(lfs
);
1189 TRACE("return lpstrFile='%s' !\n", debugstr_w(lpofn
->lpstrFile
));
1194 /* ------------------ Dialog procedures ---------------------- */
1196 /***********************************************************************
1197 * FileOpenDlgProc16 (COMMDLG.6)
1199 LRESULT WINAPI
FileOpenDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
1202 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1205 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1206 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1208 LRESULT lRet
= (BOOL16
)FILEDLG_CallWindowProc(lfs
, wMsg
, wParam
, lParam
);
1210 return lRet
; /* else continue message processing */
1215 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
1217 case WM_MEASUREITEM
:
1218 return FILEDLG_WMMeasureItem16(hWnd
, wParam
, lParam
);
1221 FILEDLG_MapDrawItemStruct((LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
), &dis
);
1222 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
, &dis
);
1225 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(lParam
),wParam
, lfs
);
1228 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
1229 switch (HIWORD(lParam
))
1232 SetTextColor((HDC16
)wParam
, 0x00000000);
1234 case CTLCOLOR_STATIC
:
1235 SetTextColor((HDC16
)wParam
, 0x00000000);
1244 /***********************************************************************
1245 * FileSaveDlgProc16 (COMMDLG.7)
1247 LRESULT WINAPI
FileSaveDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
1250 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1253 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1254 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1257 lRet
= (BOOL16
)FILEDLG_CallWindowProc(lfs
, wMsg
, wParam
, lParam
);
1259 return lRet
; /* else continue message processing */
1263 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
1265 case WM_MEASUREITEM
:
1266 return FILEDLG_WMMeasureItem16(hWnd
, wParam
, lParam
);
1269 FILEDLG_MapDrawItemStruct((LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
), &dis
);
1270 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
, &dis
);
1273 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(lParam
), wParam
, lfs
);
1278 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1279 switch (HIWORD(lParam))
1282 SetTextColor((HDC16)wParam, 0x00000000);
1284 case CTLCOLOR_STATIC:
1285 SetTextColor((HDC16)wParam, 0x00000000);
1294 /***********************************************************************
1295 * FileOpenDlgProc [internal]
1296 * Used for open and save, in fact.
1298 static LRESULT WINAPI
FileOpenDlgProc(HWND hWnd
, UINT wMsg
,
1299 WPARAM wParam
, LPARAM lParam
)
1301 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1303 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1304 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1307 lRet
= (BOOL
)FILEDLG_CallWindowProc(lfs
, wMsg
, wParam
, lParam
);
1309 return lRet
; /* else continue message processing */
1314 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
1316 case WM_MEASUREITEM
:
1317 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
1320 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, !lfs
->open
, (DRAWITEMSTRUCT
*)lParam
);
1323 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(wParam
), LOWORD(wParam
), lfs
);
1326 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
1327 switch (HIWORD(lParam
))
1330 SetTextColor((HDC16
)wParam
, 0x00000000);
1332 case CTLCOLOR_STATIC
:
1333 SetTextColor((HDC16
)wParam
, 0x00000000);
1342 /* ------------------ APIs ---------------------- */
1344 /***********************************************************************
1345 * GetOpenFileName16 (COMMDLG.1)
1347 * Creates a dialog box for the user to select a file to open.
1350 * TRUE on success: user selected a valid file
1351 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1354 * unknown, there are some FIXME's left.
1356 BOOL16 WINAPI
GetOpenFileName16(
1357 SEGPTR ofn
/* addess of structure with data*/
1362 LPOPENFILENAME16 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(ofn
);
1366 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1368 lfs
= FILEDLG_AllocPrivate((LPARAM
) ofn
, LFS16
, OPEN_DIALOG
);
1371 hInst
= GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1372 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (SEGPTR
) 6);
1373 bRet
= DialogBoxIndirectParam16( hInst
, lfs
->hDlgTmpl16
, lpofn
->hwndOwner
,
1374 (DLGPROC16
) ptr
, (DWORD
) lfs
);
1375 FILEDLG_DestroyPrivate(lfs
);
1378 TRACE("return lpstrFile='%s' !\n",
1379 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
1383 /***********************************************************************
1384 * GetSaveFileName16 (COMMDLG.2)
1386 * Creates a dialog box for the user to select a file to save.
1389 * TRUE on success: user enters a valid file
1390 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1393 * unknown. There are some FIXME's left.
1395 BOOL16 WINAPI
GetSaveFileName16(
1396 SEGPTR ofn
/* addess of structure with data*/
1401 LPOPENFILENAME16 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(ofn
);
1405 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1407 lfs
= FILEDLG_AllocPrivate((LPARAM
) ofn
, LFS16
, SAVE_DIALOG
);
1410 hInst
= GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1411 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (SEGPTR
) 7);
1412 bRet
= DialogBoxIndirectParam16( hInst
, lfs
->hDlgTmpl16
, lpofn
->hwndOwner
,
1413 (DLGPROC16
) ptr
, (DWORD
) lfs
);
1414 FILEDLG_DestroyPrivate(lfs
);
1417 TRACE("return lpstrFile='%s' !\n",
1418 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
1422 /***********************************************************************
1423 * GetOpenFileNameA (COMDLG32.10)
1425 * Creates a dialog box for the user to select a file to open.
1428 * TRUE on success: user enters a valid file
1429 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1432 BOOL WINAPI
GetOpenFileNameA(
1433 LPOPENFILENAMEA ofn
) /* address of init structure */
1437 /* some flags don't allow to match the TWEAK_WineLook */
1438 if (ofn
->Flags
& (OFN_ALLOWMULTISELECT
|OFN_ENABLEHOOK
|OFN_ENABLETEMPLATE
))
1440 newlook
= (ofn
->Flags
& OFN_EXPLORER
) ? TRUE
: FALSE
;
1444 /* no special flags set, we can match the TWEAK_WineLook */
1445 newlook
= (TWEAK_WineLook
>WIN31_LOOK
) ? TRUE
: FALSE
;
1450 return GetFileDialog95A(ofn
, OPEN_DIALOG
);
1454 return GetFileName31A(ofn
, OPEN_DIALOG
);
1458 /***********************************************************************
1459 * GetOpenFileNameW (COMDLG32.11)
1461 * Creates a dialog box for the user to select a file to open.
1464 * TRUE on success: user enters a valid file
1465 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1468 BOOL WINAPI
GetOpenFileNameW(
1469 LPOPENFILENAMEW ofn
) /* address of init structure */
1473 /* some flags don't allow to match the TWEAK_WineLook */
1474 if (ofn
->Flags
& (OFN_ALLOWMULTISELECT
|OFN_ENABLEHOOK
|OFN_ENABLETEMPLATE
))
1476 newlook
= (ofn
->Flags
& OFN_EXPLORER
) ? TRUE
: FALSE
;
1480 /* no special flags set, we can match the TWEAK_WineLook */
1481 newlook
= (TWEAK_WineLook
>WIN31_LOOK
) ? TRUE
: FALSE
;
1486 return GetFileDialog95W(ofn
, OPEN_DIALOG
);
1490 return GetFileName31W(ofn
, OPEN_DIALOG
);
1494 /***********************************************************************
1495 * GetSaveFileNameA (COMDLG32.12)
1497 * Creates a dialog box for the user to select a file to save.
1500 * TRUE on success: user enters a valid file
1501 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1504 BOOL WINAPI
GetSaveFileNameA(
1505 LPOPENFILENAMEA ofn
) /* address of init structure */
1509 /* some flags don't allow to match the TWEAK_WineLook */
1510 if (ofn
->Flags
& (OFN_ALLOWMULTISELECT
|OFN_ENABLEHOOK
|OFN_ENABLETEMPLATE
))
1512 newlook
= (ofn
->Flags
& OFN_EXPLORER
) ? TRUE
: FALSE
;
1516 /* no special flags set, we can match the TWEAK_WineLook */
1517 newlook
= (TWEAK_WineLook
>WIN31_LOOK
) ? TRUE
: FALSE
;
1522 return GetFileDialog95A(ofn
, SAVE_DIALOG
);
1526 return GetFileName31A(ofn
, SAVE_DIALOG
);
1530 /***********************************************************************
1531 * GetSaveFileNameW (COMDLG32.13)
1533 * Creates a dialog box for the user to select a file to save.
1536 * TRUE on success: user enters a valid file
1537 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1540 BOOL WINAPI
GetSaveFileNameW(
1541 LPOPENFILENAMEW ofn
) /* address of init structure */
1545 /* some flags don't allow to match the TWEAK_WineLook */
1546 if (ofn
->Flags
& (OFN_ALLOWMULTISELECT
|OFN_ENABLEHOOK
|OFN_ENABLETEMPLATE
))
1548 newlook
= (ofn
->Flags
& OFN_EXPLORER
) ? TRUE
: FALSE
;
1552 /* no special flags set, we can match the TWEAK_WineLook */
1553 newlook
= (TWEAK_WineLook
>WIN31_LOOK
) ? TRUE
: FALSE
;
1558 return GetFileDialog95W(ofn
, SAVE_DIALOG
);
1562 return GetFileName31W(ofn
, SAVE_DIALOG
);