2 * COMMDLG - File Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/winbase16.h"
32 #include "wine/winuser16.h"
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
50 #define BUFFILEALLOC 512 * sizeof(WCHAR)
54 HWND hwnd
; /* file dialog window handle */
55 BOOL hook
; /* TRUE if the dialog is hooked */
56 UINT lbselchstring
; /* registered message id */
57 UINT fileokstring
; /* registered message id */
58 LPARAM lParam
; /* save original lparam */
59 HANDLE16 hDlgTmpl16
; /* handle for resource 16 */
60 HANDLE16 hResource16
; /* handle for allocated resource 16 */
61 HANDLE16 hGlobal16
; /* 16 bits mem block (resources) */
62 LPCVOID
template; /* template for 32 bits resource */
63 BOOL open
; /* TRUE if open dialog, FALSE if save dialog */
64 OPENFILENAMEW
*ofnW
; /* original structure or work struct */
65 OPENFILENAMEA
*ofnA
; /* original structure if 32bits ansi dialog */
66 OPENFILENAME16
*ofn16
; /* original structure if 16 bits dialog */
69 #define LFSPRIVATE struct FSPRIVATE *
73 #define OFN_PROP "FILEDLG_OFN"
75 static const WCHAR FILE_star
[] = {'*','.','*', 0};
76 static const WCHAR FILE_bslash
[] = {'\\', 0};
77 static const WCHAR FILE_specc
[] = {'%','c',':', 0};
78 static const int fldrHeight
= 16;
79 static const int fldrWidth
= 20;
81 static HICON hFolder
= 0;
82 static HICON hFolder2
= 0;
83 static HICON hFloppy
= 0;
84 static HICON hHDisk
= 0;
85 static HICON hCDRom
= 0;
86 static HICON hNet
= 0;
88 /***********************************************************************
89 * FileDlg_Init [internal]
91 static BOOL
FileDlg_Init(void)
93 static BOOL initialized
= 0;
96 hFolder
= LoadImageA( COMDLG32_hInstance
, "FOLDER", IMAGE_ICON
, 16, 16, LR_SHARED
);
97 hFolder2
= LoadImageA( COMDLG32_hInstance
, "FOLDER2", IMAGE_ICON
, 16, 16, LR_SHARED
);
98 hFloppy
= LoadImageA( COMDLG32_hInstance
, "FLOPPY", IMAGE_ICON
, 16, 16, LR_SHARED
);
99 hHDisk
= LoadImageA( COMDLG32_hInstance
, "HDISK", IMAGE_ICON
, 16, 16, LR_SHARED
);
100 hCDRom
= LoadImageA( COMDLG32_hInstance
, "CDROM", IMAGE_ICON
, 16, 16, LR_SHARED
);
101 hNet
= LoadImageA( COMDLG32_hInstance
, "NETWORK", IMAGE_ICON
, 16, 16, LR_SHARED
);
102 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
103 hHDisk
== 0 || hCDRom
== 0 || hNet
== 0)
105 ERR("Error loading icons !\n");
113 /***********************************************************************
114 * Get32BitsTemplate [internal]
116 * Get a template (or FALSE if failure) when 16 bits dialogs are used
117 * by a 32 bits application
120 BOOL
Get32BitsTemplate(LFSPRIVATE lfs
)
122 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
125 if (ofnW
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
127 if (!(lfs
->template = LockResource( ofnW
->hInstance
)))
129 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
133 else if (ofnW
->Flags
& OFN_ENABLETEMPLATE
)
137 hResInfo
= FindResourceA(lfs
->ofnA
->hInstance
,
138 lfs
->ofnA
->lpTemplateName
,
141 hResInfo
= FindResourceW(ofnW
->hInstance
,
142 ofnW
->lpTemplateName
,
146 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
149 if (!(hDlgTmpl
= LoadResource(ofnW
->hInstance
,
151 !(lfs
->template = LockResource(hDlgTmpl
)))
153 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
156 } else { /* get it from internal Wine resource */
158 if (!(hResInfo
= FindResourceA(COMDLG32_hInstance
,
159 lfs
->open
? "OPEN_FILE":"SAVE_FILE", (LPSTR
)RT_DIALOG
)))
161 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
164 if (!(hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
165 !(lfs
->template = LockResource( hDlgTmpl
)))
167 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
174 /***********************************************************************
175 * Get16BitsTemplate [internal]
177 * Get a template (FALSE if failure) when 16 bits dialogs are used
178 * by a 16 bits application
181 BOOL
Get16BitsTemplate(LFSPRIVATE lfs
)
183 LPOPENFILENAME16 ofn16
= lfs
->ofn16
;
185 HGLOBAL16 hGlobal16
= 0;
187 if (ofn16
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
188 lfs
->hDlgTmpl16
= ofn16
->hInstance
;
189 else if (ofn16
->Flags
& OFN_ENABLETEMPLATE
)
192 if (!(hResInfo
= FindResource16(ofn16
->hInstance
,
193 MapSL(ofn16
->lpTemplateName
),
196 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
199 if (!(lfs
->hDlgTmpl16
= LoadResource16( ofn16
->hInstance
, hResInfo
)))
201 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
204 lfs
->hResource16
= lfs
->hDlgTmpl16
;
207 { /* get resource from (32 bits) own Wine resource; convert it to 16 */
213 if (!(hResInfo
= FindResourceA(COMDLG32_hInstance
,
214 lfs
->open
? "OPEN_FILE":"SAVE_FILE", (LPSTR
)RT_DIALOG
)))
216 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
219 if (!(hDlgTmpl32
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
220 !(template32
= LockResource( hDlgTmpl32
)))
222 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
225 size
= SizeofResource(COMDLG32_hInstance
, hResInfo
);
226 hGlobal16
= GlobalAlloc16(0, size
);
229 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
230 ERR("alloc failure for %ld bytes\n", size
);
233 template = GlobalLock16(hGlobal16
);
236 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
237 ERR("global lock failure for %x handle\n", hGlobal16
);
238 GlobalFree16(hGlobal16
);
241 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
242 lfs
->hDlgTmpl16
= hGlobal16
;
243 lfs
->hGlobal16
= hGlobal16
;
248 /***********************************************************************
249 * FILEDLG_StripEditControl [internal]
250 * Strip pathnames off the contents of the edit control.
252 static void FILEDLG_StripEditControl(HWND hwnd
)
254 WCHAR temp
[BUFFILE
], *cp
;
256 GetDlgItemTextW( hwnd
, edt1
, temp
, sizeof(temp
)/sizeof(WCHAR
));
257 cp
= strrchrW(temp
, '\\');
261 cp
= strrchrW(temp
, ':');
265 /* FIXME: shouldn't we do something with the result here? ;-) */
268 /***********************************************************************
269 * FILEDLG_CallWindowProc [internal]
271 * Call the appropriate hook
273 static BOOL
FILEDLG_CallWindowProc(LFSPRIVATE lfs
, UINT wMsg
, WPARAM wParam
,
278 return (BOOL
) CallWindowProcA(
279 (WNDPROC
)lfs
->ofnA
->lpfnHook
, lfs
->hwnd
,
280 wMsg
, wParam
, lParam
);
285 return (BOOL
) CallWindowProcW(
286 (WNDPROC
)lfs
->ofnW
->lpfnHook
, lfs
->hwnd
,
287 wMsg
, wParam
, lParam
);
292 /***********************************************************************
293 * FILEDLG_ScanDir [internal]
295 static BOOL
FILEDLG_ScanDir(HWND hWnd
, LPWSTR newPath
)
297 WCHAR buffer
[BUFFILE
];
300 HCURSOR hCursorWait
, oldCursor
;
302 TRACE("Trying to change to %s\n", debugstr_w(newPath
));
303 if ( !SetCurrentDirectoryW( newPath
))
305 lstrcpynW(buffer
, newPath
, sizeof(buffer
)/sizeof(WCHAR
));
307 /* get the list of spec files */
308 GetDlgItemTextW(hWnd
, edt1
, buffer
, sizeof(buffer
)/sizeof(WCHAR
));
310 hCursorWait
= LoadCursorA(0, (LPSTR
)IDC_WAIT
);
311 oldCursor
= SetCursor(hCursorWait
);
314 if ((hdlg
= GetDlgItem(hWnd
, lst1
)) != 0) {
315 WCHAR
* scptr
; /* ptr on semi-colon */
316 WCHAR
* filter
= buffer
;
318 TRACE("Using filter %s\n", debugstr_w(filter
));
319 SendMessageW(hdlg
, LB_RESETCONTENT
, 0, 0);
321 scptr
= strchrW(filter
, ';');
322 if (scptr
) *scptr
= 0;
323 while (*filter
== ' ') filter
++;
324 TRACE("Using file spec %s\n", debugstr_w(filter
));
325 if (SendMessageW(hdlg
, LB_DIR
, 0, (LPARAM
)filter
) == LB_ERR
)
327 if (scptr
) *scptr
= ';';
328 filter
= (scptr
) ? (scptr
+ 1) : 0;
332 /* list of directories */
333 strcpyW(buffer
, FILE_star
);
335 if ((hdlgDir
= GetDlgItem(hWnd
, lst2
)) != 0) {
336 lRet
= DlgDirListW(hWnd
, buffer
, lst2
, stc1
, DDL_EXCLUSIVE
| DDL_DIRECTORY
);
338 SetCursor(oldCursor
);
342 /***********************************************************************
343 * FILEDLG_GetFileType [internal]
346 static LPWSTR
FILEDLG_GetFileType(LPWSTR cfptr
, LPWSTR fptr
, WORD index
)
351 for ( ;(n
= lstrlenW(cfptr
)) != 0; i
++)
356 cfptr
+= lstrlenW(cfptr
) + 1;
359 for ( ;(n
= lstrlenW(fptr
)) != 0; i
++)
364 fptr
+= lstrlenW(fptr
) + 1;
366 return (LPWSTR
) FILE_star
; /* FIXME */
369 /***********************************************************************
370 * FILEDLG_WMDrawItem [internal]
372 static LONG
FILEDLG_WMDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
,
373 int savedlg
, LPDRAWITEMSTRUCT lpdis
)
377 COLORREF oldText
= 0, oldBk
= 0;
379 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
381 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
))) return FALSE
;
382 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
385 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
387 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
388 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
391 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_GRAYTEXT
) );
393 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ 1,
394 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
395 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
397 if (lpdis
->itemState
& ODS_SELECTED
)
398 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
400 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
402 SetBkColor( lpdis
->hDC
, oldBk
);
403 SetTextColor( lpdis
->hDC
, oldText
);
405 HeapFree(GetProcessHeap(), 0, str
);
409 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
411 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
413 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
416 if (lpdis
->itemState
& ODS_SELECTED
)
418 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
419 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
421 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
422 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
423 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
425 if (lpdis
->itemState
& ODS_SELECTED
)
426 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
428 if (lpdis
->itemState
& ODS_SELECTED
)
430 SetBkColor( lpdis
->hDC
, oldBk
);
431 SetTextColor( lpdis
->hDC
, oldText
);
433 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hFolder
);
434 HeapFree(GetProcessHeap(), 0, str
);
437 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
440 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
442 SendMessageW(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
444 root
[0] += str
[2] - 'a';
445 switch(GetDriveTypeA(root
))
447 case DRIVE_REMOVABLE
: hIcon
= hFloppy
; break;
448 case DRIVE_CDROM
: hIcon
= hCDRom
; break;
449 case DRIVE_REMOTE
: hIcon
= hNet
; break;
451 default: hIcon
= hHDisk
; break;
453 if (lpdis
->itemState
& ODS_SELECTED
)
455 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
456 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
458 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
459 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
460 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
462 if (lpdis
->itemState
& ODS_SELECTED
)
464 SetBkColor( lpdis
->hDC
, oldBk
);
465 SetTextColor( lpdis
->hDC
, oldText
);
467 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hIcon
);
468 HeapFree(GetProcessHeap(), 0, str
);
474 /***********************************************************************
475 * FILEDLG_UpdateResult [internal]
476 * update the displayed file name (with path)
478 void FILEDLG_UpdateResult(LFSPRIVATE lfs
, WCHAR
*tmpstr
)
481 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
482 WCHAR tmpstr2
[BUFFILE
];
485 TRACE("%s\n", debugstr_w(tmpstr
));
486 if(ofnW
->Flags
& OFN_NOVALIDATE
)
489 GetCurrentDirectoryW(BUFFILE
, tmpstr2
);
490 lenstr2
= strlenW(tmpstr2
);
492 tmpstr2
[lenstr2
++]='\\';
493 lstrcpynW(tmpstr2
+lenstr2
, tmpstr
, BUFFILE
-lenstr2
);
495 lstrcpynW(ofnW
->lpstrFile
, tmpstr2
, ofnW
->nMaxFile
);
496 if((bs
= strrchrW(tmpstr2
, '\\')) != NULL
)
497 ofnW
->nFileOffset
= bs
- tmpstr2
+1;
499 ofnW
->nFileOffset
= 0;
500 ofnW
->nFileExtension
= 0;
501 while(tmpstr2
[ofnW
->nFileExtension
] != '.' && tmpstr2
[ofnW
->nFileExtension
] != '\0')
502 ofnW
->nFileExtension
++;
503 if (tmpstr2
[ofnW
->nFileExtension
] == '\0')
504 ofnW
->nFileExtension
= 0;
506 ofnW
->nFileExtension
++;
507 /* update the real client structures if any */
509 { /* we have to convert to short (8.3) path */
510 char tmp
[1024]; /* MAX_PATHNAME_LEN */
511 LPOPENFILENAME16 ofn16
= lfs
->ofn16
;
512 char *dest
= MapSL(ofn16
->lpstrFile
);
514 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFile
, -1,
515 tmp
, sizeof(tmp
), NULL
, NULL
))
516 tmp
[sizeof(tmp
)-1] = 0;
517 GetShortPathNameA(tmp
, dest
, ofn16
->nMaxFile
);
519 /* the same procedure as every year... */
520 if((bs16
= strrchr(dest
, '\\')) != NULL
)
521 ofn16
->nFileOffset
= bs16
- dest
+1;
523 ofn16
->nFileOffset
= 0;
524 ofn16
->nFileExtension
= 0;
525 while(dest
[ofn16
->nFileExtension
] != '.' && dest
[ofn16
->nFileExtension
] != '\0')
526 ofn16
->nFileExtension
++;
527 if (dest
[ofn16
->nFileExtension
] == '\0')
528 ofn16
->nFileExtension
= 0;
530 ofn16
->nFileExtension
++;
534 if (ofnW
->nMaxFile
&&
535 !WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFile
, -1,
536 lfs
->ofnA
->lpstrFile
, ofnW
->nMaxFile
, NULL
, NULL
))
537 lfs
->ofnA
->lpstrFile
[ofnW
->nMaxFile
-1] = 0;
538 lfs
->ofnA
->nFileOffset
= ofnW
->nFileOffset
;
539 lfs
->ofnA
->nFileExtension
= ofnW
->nFileExtension
;
543 /***********************************************************************
544 * FILEDLG_UpdateFileTitle [internal]
545 * update the displayed file name (without path)
547 void FILEDLG_UpdateFileTitle(LFSPRIVATE lfs
)
550 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
551 if (ofnW
->lpstrFileTitle
!= NULL
)
553 lRet
= SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETCURSEL
, 0, 0);
554 SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETTEXT
, lRet
,
555 (LPARAM
)ofnW
->lpstrFileTitle
);
558 char *dest
= MapSL(lfs
->ofn16
->lpstrFileTitle
);
559 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFileTitle
, -1,
560 dest
, ofnW
->nMaxFileTitle
, NULL
, NULL
))
561 dest
[ofnW
->nMaxFileTitle
-1] = 0;
565 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFileTitle
, -1,
566 lfs
->ofnA
->lpstrFileTitle
, ofnW
->nMaxFileTitle
, NULL
, NULL
))
567 lfs
->ofnA
->lpstrFileTitle
[ofnW
->nMaxFileTitle
-1] = 0;
572 /***********************************************************************
573 * FILEDLG_DirListDblClick [internal]
575 static LRESULT
FILEDLG_DirListDblClick( LFSPRIVATE lfs
)
578 HWND hWnd
= lfs
->hwnd
;
580 WCHAR tmpstr
[BUFFILE
];
582 /* get the raw string (with brackets) */
583 lRet
= SendDlgItemMessageW(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
584 if (lRet
== LB_ERR
) return TRUE
;
585 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
586 SendDlgItemMessageW(hWnd
, lst2
, LB_GETTEXT
, lRet
,
588 strcpyW( tmpstr
, pstr
);
589 HeapFree(GetProcessHeap(), 0, pstr
);
590 /* get the selected directory in tmpstr */
591 if (tmpstr
[0] == '[')
593 tmpstr
[lstrlenW(tmpstr
) - 1] = 0;
594 strcpyW(tmpstr
,tmpstr
+1);
596 strcatW(tmpstr
, FILE_bslash
);
598 FILEDLG_ScanDir(hWnd
, tmpstr
);
602 if (FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, lst2
,
603 MAKELONG(lRet
,CD_LBSELCHANGE
)))
609 /***********************************************************************
610 * FILEDLG_FileListSelect [internal]
611 * called when a new item is picked in the file list
613 static LRESULT
FILEDLG_FileListSelect( LFSPRIVATE lfs
)
616 HWND hWnd
= lfs
->hwnd
;
619 lRet
= SendDlgItemMessageW(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
623 /* set the edit control to the choosen file */
624 if ((pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
626 SendDlgItemMessageW(hWnd
, lst1
, LB_GETTEXT
, lRet
,
628 SetDlgItemTextW( hWnd
, edt1
, pstr
);
629 HeapFree(GetProcessHeap(), 0, pstr
);
633 FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, lst1
,
634 MAKELONG(lRet
,CD_LBSELCHANGE
));
636 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD,
641 /***********************************************************************
642 * FILEDLG_TestPath [internal]
643 * before accepting the file name, test if it includes wild cards
644 * tries to scan the directory and returns TRUE if no error.
646 static LRESULT
FILEDLG_TestPath( LFSPRIVATE lfs
, LPWSTR path
)
648 HWND hWnd
= lfs
->hwnd
;
649 LPWSTR pBeginFileName
, pstr2
;
650 WCHAR tmpstr2
[BUFFILE
];
652 pBeginFileName
= strrchrW(path
, '\\');
653 if (pBeginFileName
== NULL
)
654 pBeginFileName
= strrchrW(path
, ':');
656 if (strchrW(path
,'*') != NULL
|| strchrW(path
,'?') != NULL
)
658 /* edit control contains wildcards */
659 if (pBeginFileName
!= NULL
)
661 lstrcpynW(tmpstr2
, pBeginFileName
+ 1, BUFFILE
);
662 *(pBeginFileName
+ 1) = 0;
666 strcpyW(tmpstr2
, path
);
667 if(!(lfs
->ofnW
->Flags
& OFN_NOVALIDATE
))
671 TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path
), debugstr_w(tmpstr2
));
672 SetDlgItemTextW( hWnd
, edt1
, tmpstr2
);
673 FILEDLG_ScanDir(hWnd
, path
);
674 return (lfs
->ofnW
->Flags
& OFN_NOVALIDATE
) ? TRUE
: FALSE
;
677 /* no wildcards, we might have a directory or a filename */
678 /* try appending a wildcard and reading the directory */
680 pstr2
= path
+ lstrlenW(path
);
681 if (pBeginFileName
== NULL
|| *(pBeginFileName
+ 1) != 0)
682 strcatW(path
, FILE_bslash
);
684 /* if ScanDir succeeds, we have changed the directory */
685 if (FILEDLG_ScanDir(hWnd
, path
))
686 return FALSE
; /* and path is not a valid file name */
688 /* if not, this must be a filename */
690 *pstr2
= 0; /* remove the wildcard added before */
692 if (pBeginFileName
!= NULL
)
694 /* strip off the pathname */
696 SetDlgItemTextW( hWnd
, edt1
, pBeginFileName
+ 1 );
698 lstrcpynW(tmpstr2
, pBeginFileName
+ 1, sizeof(tmpstr2
)/sizeof(WCHAR
) );
699 /* Should we MessageBox() if this fails? */
700 if (!FILEDLG_ScanDir(hWnd
, path
))
704 strcpyW(path
, tmpstr2
);
707 SetDlgItemTextW( hWnd
, edt1
, path
);
711 /***********************************************************************
712 * FILEDLG_Validate [internal]
713 * called on: click Ok button, Enter in edit, DoubleClick in file list
715 static LRESULT
FILEDLG_Validate( LFSPRIVATE lfs
, LPWSTR path
, UINT control
, INT itemIndex
,
719 HWND hWnd
= lfs
->hwnd
;
720 OPENFILENAMEW ofnsav
;
721 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
722 WCHAR filename
[BUFFILE
];
724 ofnsav
= *ofnW
; /* for later restoring */
726 /* get current file name */
728 lstrcpynW(filename
, path
, sizeof(filename
)/sizeof(WCHAR
));
730 GetDlgItemTextW( hWnd
, edt1
, filename
, sizeof(filename
)/sizeof(WCHAR
));
732 TRACE("got filename = %s\n", debugstr_w(filename
));
733 /* if we did not click in file list to get there */
736 if (!FILEDLG_TestPath( lfs
, filename
) )
739 FILEDLG_UpdateResult(lfs
, filename
);
742 { /* called internally after a change in a combo */
745 FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, control
,
746 MAKELONG(itemIndex
,CD_LBSELCHANGE
));
751 FILEDLG_UpdateFileTitle(lfs
);
754 lRet
= (BOOL
)FILEDLG_CallWindowProc(lfs
, lfs
->fileokstring
,
758 *ofnW
= ofnsav
; /* restore old state */
762 if ((ofnW
->Flags
& OFN_ALLOWMULTISELECT
) && (ofnW
->Flags
& OFN_EXPLORER
))
766 LPWSTR str
= (LPWSTR
)ofnW
->lpstrFile
;
767 LPWSTR ptr
= strrchrW(str
, '\\');
768 str
[lstrlenW(str
) + 1] = '\0';
775 /***********************************************************************
776 * FILEDLG_DiskChange [internal]
777 * called when a new item is picked in the disk selection combo
779 static LRESULT
FILEDLG_DiskChange( LFSPRIVATE lfs
)
782 HWND hWnd
= lfs
->hwnd
;
784 WCHAR diskname
[BUFFILE
];
786 FILEDLG_StripEditControl(hWnd
);
787 lRet
= SendDlgItemMessageW(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
790 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
791 SendDlgItemMessageW(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
,
793 wsprintfW(diskname
, FILE_specc
, pstr
[2]);
794 HeapFree(GetProcessHeap(), 0, pstr
);
796 return FILEDLG_Validate( lfs
, diskname
, cmb2
, lRet
, TRUE
);
799 /***********************************************************************
800 * FILEDLG_FileTypeChange [internal]
801 * called when a new item is picked in the file type combo
803 static LRESULT
FILEDLG_FileTypeChange( LFSPRIVATE lfs
)
806 WCHAR diskname
[BUFFILE
];
811 lRet
= SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETCURSEL
, 0, 0);
814 pstr
= (LPWSTR
)SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
815 TRACE("Selected filter : %s\n", debugstr_w(pstr
));
816 SetDlgItemTextW( lfs
->hwnd
, edt1
, pstr
);
818 return FILEDLG_Validate( lfs
, NULL
, cmb1
, lRet
, TRUE
);
821 /***********************************************************************
822 * FILEDLG_WMCommand [internal]
824 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, LPARAM lParam
, UINT notification
,
825 UINT control
, LFSPRIVATE lfs
)
829 case lst1
: /* file list */
830 FILEDLG_StripEditControl(hWnd
);
831 if (notification
== LBN_DBLCLK
)
833 if (FILEDLG_Validate( lfs
, NULL
, control
, 0, FALSE
))
834 EndDialog(hWnd
, TRUE
);
837 else if (notification
== LBN_SELCHANGE
)
838 return FILEDLG_FileListSelect( lfs
);
841 case lst2
: /* directory list */
842 FILEDLG_StripEditControl(hWnd
);
843 if (notification
== LBN_DBLCLK
)
844 return FILEDLG_DirListDblClick( lfs
);
847 case cmb1
: /* file type drop list */
848 if (notification
== CBN_SELCHANGE
)
849 return FILEDLG_FileTypeChange( lfs
);
858 case cmb2
: /* disk dropdown combo */
859 if (notification
== CBN_SELCHANGE
)
860 return FILEDLG_DiskChange( lfs
);
864 TRACE("OK pressed\n");
865 if (FILEDLG_Validate( lfs
, NULL
, control
, 0, FALSE
))
866 EndDialog(hWnd
, TRUE
);
870 EndDialog(hWnd
, FALSE
);
873 case IDABORT
: /* can be sent by the hook procedure */
874 EndDialog(hWnd
, TRUE
);
880 /***********************************************************************
881 * FILEDLG_MapDrawItemStruct [internal]
882 * map a 16 bits drawitem struct to 32
884 static void FILEDLG_MapDrawItemStruct(LPDRAWITEMSTRUCT16 lpdis16
, LPDRAWITEMSTRUCT lpdis
)
886 lpdis
->CtlType
= lpdis16
->CtlType
;
887 lpdis
->CtlID
= lpdis16
->CtlID
;
888 lpdis
->itemID
= lpdis16
->itemID
;
889 lpdis
->itemAction
= lpdis16
->itemAction
;
890 lpdis
->itemState
= lpdis16
->itemState
;
891 lpdis
->hwndItem
= HWND_32(lpdis16
->hwndItem
);
892 lpdis
->hDC
= HDC_32(lpdis16
->hDC
);
893 lpdis
->rcItem
.right
= lpdis16
->rcItem
.right
;
894 lpdis
->rcItem
.left
= lpdis16
->rcItem
.left
;
895 lpdis
->rcItem
.top
= lpdis16
->rcItem
.top
;
896 lpdis
->rcItem
.bottom
= lpdis16
->rcItem
.bottom
;
897 lpdis
->itemData
= lpdis16
->itemData
;
900 /************************************************************************
901 * FILEDLG_MapStringPairsToW [internal]
902 * map string pairs to Unicode
904 static LPWSTR
FILEDLG_MapStringPairsToW(LPCSTR strA
, UINT size
)
914 n
= s
+ 1 - strA
; /* Don't forget the other \0 */
915 if (n
< size
) n
= size
;
917 len
= MultiByteToWideChar( CP_ACP
, 0, strA
, n
, NULL
, 0 );
918 x
= HeapAlloc(GetProcessHeap(),0, len
* sizeof(WCHAR
));
919 MultiByteToWideChar( CP_ACP
, 0, strA
, n
, x
, len
);
924 /************************************************************************
925 * FILEDLG_DupToW [internal]
926 * duplicates an Ansi string to unicode, with a buffer size
928 LPWSTR
FILEDLG_DupToW(LPCSTR str
, DWORD size
)
931 if (str
&& (size
> 0))
933 strW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
934 if (strW
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, strW
, size
);
940 /************************************************************************
941 * FILEDLG_MapOfnStructA [internal]
942 * map a 32 bits Ansi structure to an Unicode one
944 void FILEDLG_MapOfnStructA(LPOPENFILENAMEA ofnA
, LPOPENFILENAMEW ofnW
, BOOL open
)
947 UNICODE_STRING usBuffer
;
949 ofnW
->lStructSize
= sizeof(OPENFILENAMEW
);
950 ofnW
->hwndOwner
= ofnA
->hwndOwner
;
951 ofnW
->hInstance
= ofnA
->hInstance
;
952 if (ofnA
->lpstrFilter
)
953 ofnW
->lpstrFilter
= FILEDLG_MapStringPairsToW(ofnA
->lpstrFilter
, 0);
955 if ((ofnA
->lpstrCustomFilter
) && (*(ofnA
->lpstrCustomFilter
)))
956 ofnW
->lpstrCustomFilter
= FILEDLG_MapStringPairsToW(ofnA
->lpstrCustomFilter
, ofnA
->nMaxCustFilter
);
957 ofnW
->nMaxCustFilter
= ofnA
->nMaxCustFilter
;
958 ofnW
->nFilterIndex
= ofnA
->nFilterIndex
;
959 ofnW
->nMaxFile
= ofnA
->nMaxFile
;
960 ofnW
->lpstrFile
= FILEDLG_DupToW(ofnA
->lpstrFile
, ofnW
->nMaxFile
);
961 ofnW
->nMaxFileTitle
= ofnA
->nMaxFileTitle
;
962 ofnW
->lpstrFileTitle
= FILEDLG_DupToW(ofnA
->lpstrFileTitle
, ofnW
->nMaxFileTitle
);
963 if (ofnA
->lpstrInitialDir
)
965 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpstrInitialDir
);
966 ofnW
->lpstrInitialDir
= usBuffer
.Buffer
;
968 if (ofnA
->lpstrTitle
)
969 str
= ofnA
->lpstrTitle
;
971 /* Allocates default title (FIXME : get it from resource) */
972 str
= open
? "Open File" : "Save as";
973 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,str
);
974 ofnW
->lpstrTitle
= usBuffer
.Buffer
;
975 ofnW
->Flags
= ofnA
->Flags
;
976 ofnW
->nFileOffset
= ofnA
->nFileOffset
;
977 ofnW
->nFileExtension
= ofnA
->nFileExtension
;
978 ofnW
->lpstrDefExt
= FILEDLG_DupToW(ofnA
->lpstrDefExt
, 3);
979 if ((ofnA
->Flags
& OFN_ENABLETEMPLATE
) && (ofnA
->lpTemplateName
))
981 if (HIWORD(ofnA
->lpTemplateName
))
983 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpTemplateName
);
984 ofnW
->lpTemplateName
= usBuffer
.Buffer
;
986 else /* numbered resource */
987 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
= HWND_32(ofn16
->hwndOwner
);
1002 ofnA
.hInstance
= HINSTANCE_32(ofn16
->hInstance
);
1003 if (ofn16
->lpstrFilter
)
1004 ofnA
.lpstrFilter
= MapSL(ofn16
->lpstrFilter
);
1005 if (ofn16
->lpstrCustomFilter
)
1006 ofnA
.lpstrCustomFilter
= MapSL(ofn16
->lpstrCustomFilter
);
1007 ofnA
.nMaxCustFilter
= ofn16
->nMaxCustFilter
;
1008 ofnA
.nFilterIndex
= ofn16
->nFilterIndex
;
1009 ofnA
.lpstrFile
= MapSL(ofn16
->lpstrFile
);
1010 ofnA
.nMaxFile
= ofn16
->nMaxFile
;
1011 ofnA
.lpstrFileTitle
= MapSL(ofn16
->lpstrFileTitle
);
1012 ofnA
.nMaxFileTitle
= ofn16
->nMaxFileTitle
;
1013 ofnA
.lpstrInitialDir
= MapSL(ofn16
->lpstrInitialDir
);
1014 ofnA
.lpstrTitle
= MapSL(ofn16
->lpstrTitle
);
1015 ofnA
.Flags
= ofn16
->Flags
;
1016 ofnA
.nFileOffset
= ofn16
->nFileOffset
;
1017 ofnA
.nFileExtension
= ofn16
->nFileExtension
;
1018 ofnA
.lpstrDefExt
= MapSL(ofn16
->lpstrDefExt
);
1019 if (HIWORD(ofn16
->lpTemplateName
))
1020 ofnA
.lpTemplateName
= MapSL(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
);
1027 /************************************************************************
1028 * FILEDLG_DestroyPrivate [internal]
1029 * destroys the private object
1031 static void FILEDLG_DestroyPrivate(LFSPRIVATE lfs
)
1036 /* free resources for a 16 bits dialog */
1037 if (lfs
->hResource16
) FreeResource16(lfs
->hResource16
);
1040 GlobalUnlock16(lfs
->hGlobal16
);
1041 GlobalFree16(lfs
->hGlobal16
);
1043 /* if ofnW has been allocated, have to free everything in it */
1044 if (lfs
->ofn16
|| lfs
->ofnA
)
1046 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
1047 if (ofnW
->lpstrFilter
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrFilter
);
1048 if (ofnW
->lpstrCustomFilter
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrCustomFilter
);
1049 if (ofnW
->lpstrFile
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFile
);
1050 if (ofnW
->lpstrFileTitle
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFileTitle
);
1051 if (ofnW
->lpstrInitialDir
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrInitialDir
);
1052 if (ofnW
->lpstrTitle
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrTitle
);
1053 if ((ofnW
->lpTemplateName
) && (HIWORD(ofnW
->lpTemplateName
)))
1054 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpTemplateName
);
1055 HeapFree(GetProcessHeap(), 0, ofnW
);
1057 TRACE("destroying private allocation %p\n", lfs
);
1058 HeapFree(GetProcessHeap(), 0, lfs
);
1059 RemovePropA(hwnd
, OFN_PROP
);
1062 /************************************************************************
1063 * FILEDLG_AllocPrivate [internal]
1064 * allocate a private object to hold 32 bits Unicode
1065 * structure that will be used throughtout the calls, while
1066 * keeping available the original structures and a few variables
1067 * On entry : type = dialog procedure type (16,32A,32W)
1068 * dlgType = dialog type (open or save)
1070 static LFSPRIVATE
FILEDLG_AllocPrivate(LPARAM lParam
, int type
, UINT dlgType
)
1072 LFSPRIVATE lfs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct FSPRIVATE
));
1074 TRACE("alloc private buf %p\n", lfs
);
1075 if (!lfs
) return NULL
;
1077 lfs
->lParam
= lParam
;
1078 if (dlgType
== OPEN_DIALOG
)
1082 lfs
->lbselchstring
= RegisterWindowMessageA(LBSELCHSTRINGA
);
1083 lfs
->fileokstring
= RegisterWindowMessageA(FILEOKSTRINGA
);
1087 lfs
->ofn16
= MapSL(lParam
);
1088 if (lfs
->ofn16
->Flags
& OFN_ENABLEHOOK
)
1089 if (lfs
->ofn16
->lpfnHook
)
1095 lfs
->ofnA
= (LPOPENFILENAMEA
) lParam
;
1096 if (lfs
->ofnA
->Flags
& OFN_ENABLEHOOK
)
1097 if (lfs
->ofnA
->lpfnHook
)
1102 lfs
->ofnW
= (LPOPENFILENAMEW
) lParam
;
1103 if (lfs
->ofnW
->Flags
& OFN_ENABLEHOOK
)
1104 if (lfs
->ofnW
->lpfnHook
)
1110 { /* this structure is needed internally, so create it */
1111 lfs
->ofnW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(OPENFILENAMEW
));
1115 FILEDLG_MapOfnStruct16(lfs
->ofn16
, lfs
->ofnW
, lfs
->open
);
1117 FILEDLG_MapOfnStructA(lfs
->ofnA
, lfs
->ofnW
, lfs
->open
);
1124 if (!Get16BitsTemplate(lfs
)) ret
= NULL
;
1127 if (!Get32BitsTemplate(lfs
)) ret
= NULL
;
1128 if (!ret
) FILEDLG_DestroyPrivate(lfs
);
1132 /***********************************************************************
1133 * FILEDLG_CallWindowProc16 [internal]
1135 * Call the appropriate hook
1137 static BOOL
FILEDLG_CallWindowProc16(LFSPRIVATE lfs
, UINT wMsg
, WPARAM wParam
,
1142 return (BOOL16
) CallWindowProc16(
1143 (WNDPROC16
)lfs
->ofn16
->lpfnHook
, HWND_16(lfs
->hwnd
),
1144 (UINT16
)wMsg
, (WPARAM16
)wParam
, lParam
);
1149 /***********************************************************************
1150 * FILEDLG_WMInitDialog [internal]
1153 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1156 WCHAR tmpstr
[BUFFILE
];
1157 LPWSTR pstr
, old_pstr
;
1158 LPOPENFILENAMEW ofn
;
1159 LFSPRIVATE lfs
= (LFSPRIVATE
) lParam
;
1161 if (!lfs
) return FALSE
;
1162 SetPropA(hWnd
, OFN_PROP
, (HANDLE
)lfs
);
1166 TRACE("flags=%lx initialdir=%s\n", ofn
->Flags
, debugstr_w(ofn
->lpstrInitialDir
));
1168 SetWindowTextW( hWnd
, ofn
->lpstrTitle
);
1169 /* read custom filter information */
1170 if (ofn
->lpstrCustomFilter
)
1172 pstr
= ofn
->lpstrCustomFilter
;
1174 TRACE("lpstrCustomFilter = %p\n", pstr
);
1178 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
1179 (LPARAM
)(ofn
->lpstrCustomFilter
) + n
);
1180 n
+= lstrlenW(pstr
) + 1;
1181 pstr
+= lstrlenW(pstr
) + 1;
1182 TRACE("add str=%s associated to %s\n",
1183 debugstr_w(old_pstr
), debugstr_w(pstr
));
1184 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
1185 n
+= lstrlenW(pstr
) + 1;
1186 pstr
+= lstrlenW(pstr
) + 1;
1189 /* read filter information */
1190 if (ofn
->lpstrFilter
) {
1191 pstr
= (LPWSTR
) ofn
->lpstrFilter
;
1195 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
1196 (LPARAM
)(ofn
->lpstrFilter
+ n
) );
1197 n
+= lstrlenW(pstr
) + 1;
1198 pstr
+= lstrlenW(pstr
) + 1;
1199 TRACE("add str=%s associated to %s\n",
1200 debugstr_w(old_pstr
), debugstr_w(pstr
));
1201 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
1202 n
+= lstrlenW(pstr
) + 1;
1203 pstr
+= lstrlenW(pstr
) + 1;
1206 /* set default filter */
1207 if (ofn
->nFilterIndex
== 0 && ofn
->lpstrCustomFilter
== NULL
)
1208 ofn
->nFilterIndex
= 1;
1209 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETCURSEL
, ofn
->nFilterIndex
- 1, 0);
1210 lstrcpynW(tmpstr
, FILEDLG_GetFileType(ofn
->lpstrCustomFilter
,
1211 (LPWSTR
)ofn
->lpstrFilter
, ofn
->nFilterIndex
- 1),BUFFILE
);
1212 TRACE("nFilterIndex = %ld, SetText of edt1 to %s\n",
1213 ofn
->nFilterIndex
, debugstr_w(tmpstr
));
1214 SetDlgItemTextW( hWnd
, edt1
, tmpstr
);
1215 /* get drive list */
1217 DlgDirListComboBoxW(hWnd
, tmpstr
, cmb2
, 0, DDL_DRIVES
| DDL_EXCLUSIVE
);
1218 /* read initial directory */
1219 /* FIXME: Note that this is now very version-specific (See MSDN description of
1220 * the OPENFILENAME structure). For example under 2000/XP any path in the
1221 * lpstrFile overrides the lpstrInitialDir, but not under 95/98/ME
1223 if (ofn
->lpstrInitialDir
!= NULL
)
1226 lstrcpynW(tmpstr
, ofn
->lpstrInitialDir
, 511);
1227 len
= lstrlenW(tmpstr
);
1228 if (len
> 0 && tmpstr
[len
-1] != '\\' && tmpstr
[len
-1] != ':') {
1235 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) {
1237 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
1238 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr
));
1240 /* select current drive in combo 2, omit missing drives */
1243 char str
[4] = "a:\\";
1244 GetCurrentDirectoryA( sizeof(dir
), dir
);
1245 for(i
= 0, n
= -1; i
< 26; i
++)
1248 if (GetDriveTypeA(str
) > DRIVE_NO_ROOT_DIR
) n
++;
1249 if (toupper(str
[0]) == toupper(dir
[0])) break;
1252 SendDlgItemMessageW(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
1253 if (!(ofn
->Flags
& OFN_SHOWHELP
))
1254 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
1255 if (ofn
->Flags
& OFN_HIDEREADONLY
)
1256 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
1258 return (BOOL
) FILEDLG_CallWindowProc(lfs
, WM_INITDIALOG
, wParam
, lfs
->lParam
);
1265 /***********************************************************************
1266 * FILEDLG_WMInitDialog16 [internal]
1267 * The is a duplicate of the 32bit FILEDLG_WMInitDialog function
1268 * The only differnce is that it calls FILEDLG_CallWindowProc16
1269 * for a 16 bit Window Proc.
1272 static LONG
FILEDLG_WMInitDialog16(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1275 WCHAR tmpstr
[BUFFILE
];
1276 LPWSTR pstr
, old_pstr
;
1277 LPOPENFILENAMEW ofn
;
1278 LFSPRIVATE lfs
= (LFSPRIVATE
) lParam
;
1280 if (!lfs
) return FALSE
;
1281 SetPropA(hWnd
, OFN_PROP
, (HANDLE
)lfs
);
1285 TRACE("flags=%lx initialdir=%s\n", ofn
->Flags
, debugstr_w(ofn
->lpstrInitialDir
));
1287 SetWindowTextW( hWnd
, ofn
->lpstrTitle
);
1288 /* read custom filter information */
1289 if (ofn
->lpstrCustomFilter
)
1291 pstr
= ofn
->lpstrCustomFilter
;
1293 TRACE("lpstrCustomFilter = %p\n", pstr
);
1297 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
1298 (LPARAM
)(ofn
->lpstrCustomFilter
) + n
);
1299 n
+= lstrlenW(pstr
) + 1;
1300 pstr
+= lstrlenW(pstr
) + 1;
1301 TRACE("add str=%s associated to %s\n",
1302 debugstr_w(old_pstr
), debugstr_w(pstr
));
1303 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
1304 n
+= lstrlenW(pstr
) + 1;
1305 pstr
+= lstrlenW(pstr
) + 1;
1308 /* read filter information */
1309 if (ofn
->lpstrFilter
) {
1310 pstr
= (LPWSTR
) ofn
->lpstrFilter
;
1314 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
1315 (LPARAM
)(ofn
->lpstrFilter
+ n
) );
1316 n
+= lstrlenW(pstr
) + 1;
1317 pstr
+= lstrlenW(pstr
) + 1;
1318 TRACE("add str=%s associated to %s\n",
1319 debugstr_w(old_pstr
), debugstr_w(pstr
));
1320 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
1321 n
+= lstrlenW(pstr
) + 1;
1322 pstr
+= lstrlenW(pstr
) + 1;
1325 /* set default filter */
1326 if (ofn
->nFilterIndex
== 0 && ofn
->lpstrCustomFilter
== NULL
)
1327 ofn
->nFilterIndex
= 1;
1328 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETCURSEL
, ofn
->nFilterIndex
- 1, 0);
1329 lstrcpynW(tmpstr
, FILEDLG_GetFileType(ofn
->lpstrCustomFilter
,
1330 (LPWSTR
)ofn
->lpstrFilter
, ofn
->nFilterIndex
- 1),BUFFILE
);
1331 TRACE("nFilterIndex = %ld, SetText of edt1 to %s\n",
1332 ofn
->nFilterIndex
, debugstr_w(tmpstr
));
1333 SetDlgItemTextW( hWnd
, edt1
, tmpstr
);
1334 /* get drive list */
1336 DlgDirListComboBoxW(hWnd
, tmpstr
, cmb2
, 0, DDL_DRIVES
| DDL_EXCLUSIVE
);
1337 /* read initial directory */
1338 /* FIXME: Note that this is now very version-specific (See MSDN description of
1339 * the OPENFILENAME structure). For example under 2000/XP any path in the
1340 * lpstrFile overrides the lpstrInitialDir, but not under 95/98/ME
1342 if (ofn
->lpstrInitialDir
!= NULL
)
1345 lstrcpynW(tmpstr
, ofn
->lpstrInitialDir
, 511);
1346 len
= lstrlenW(tmpstr
);
1347 if (len
> 0 && tmpstr
[len
-1] != '\\' && tmpstr
[len
-1] != ':') {
1354 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) {
1356 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
1357 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr
));
1359 /* select current drive in combo 2, omit missing drives */
1362 char str
[4] = "a:\\";
1363 GetCurrentDirectoryA( sizeof(dir
), dir
);
1364 for(i
= 0, n
= -1; i
< 26; i
++)
1367 if (GetDriveTypeA(str
) > DRIVE_NO_ROOT_DIR
) n
++;
1368 if (toupper(str
[0]) == toupper(dir
[0])) break;
1371 SendDlgItemMessageW(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
1372 if (!(ofn
->Flags
& OFN_SHOWHELP
))
1373 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
1374 if (ofn
->Flags
& OFN_HIDEREADONLY
)
1375 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
1377 return (BOOL
) FILEDLG_CallWindowProc16(lfs
, WM_INITDIALOG
, wParam
, lfs
->lParam
);
1381 /***********************************************************************
1382 * FILEDLG_WMMeasureItem [internal]
1384 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1386 LPMEASUREITEMSTRUCT lpmeasure
;
1388 lpmeasure
= (LPMEASUREITEMSTRUCT
)lParam
;
1389 lpmeasure
->itemHeight
= fldrHeight
;
1394 /***********************************************************************
1395 * FILEDLG_WMMeasureItem16 [internal]
1397 static LONG
FILEDLG_WMMeasureItem16(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
1399 LPMEASUREITEMSTRUCT16 lpmeasure
;
1401 lpmeasure
= MapSL(lParam
);
1402 lpmeasure
->itemHeight
= fldrHeight
;
1406 /* ------------------ Dialog procedures ---------------------- */
1408 /***********************************************************************
1409 * FileOpenDlgProc [internal]
1410 * Used for open and save, in fact.
1412 static INT_PTR CALLBACK
FileOpenDlgProc(HWND hWnd
, UINT wMsg
,
1413 WPARAM wParam
, LPARAM lParam
)
1415 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1417 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1418 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1421 lRet
= (INT_PTR
)FILEDLG_CallWindowProc(lfs
, wMsg
, wParam
, lParam
);
1423 return lRet
; /* else continue message processing */
1428 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
1430 case WM_MEASUREITEM
:
1431 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
1434 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, !lfs
->open
, (DRAWITEMSTRUCT
*)lParam
);
1437 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(wParam
), LOWORD(wParam
), lfs
);
1440 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
1441 switch (HIWORD(lParam
))
1444 SetTextColor((HDC16
)wParam
, 0x00000000);
1446 case CTLCOLOR_STATIC
:
1447 SetTextColor((HDC16
)wParam
, 0x00000000);
1456 /***********************************************************************
1457 * FileOpenDlgProc (COMMDLG.6)
1459 BOOL16 CALLBACK
FileOpenDlgProc16(HWND16 hWnd16
, UINT16 wMsg
, WPARAM16 wParam
,
1462 HWND hWnd
= HWND_32(hWnd16
);
1463 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1466 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1467 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1469 LRESULT lRet
= (BOOL16
)FILEDLG_CallWindowProc16(lfs
, wMsg
, wParam
, lParam
);
1471 return lRet
; /* else continue message processing */
1476 return FILEDLG_WMInitDialog16(hWnd
, wParam
, lParam
);
1478 case WM_MEASUREITEM
:
1479 return FILEDLG_WMMeasureItem16(hWnd16
, wParam
, lParam
);
1482 FILEDLG_MapDrawItemStruct(MapSL(lParam
), &dis
);
1483 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
, &dis
);
1486 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(lParam
),wParam
, lfs
);
1489 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
1490 switch (HIWORD(lParam
))
1493 SetTextColor((HDC16
)wParam
, 0x00000000);
1495 case CTLCOLOR_STATIC
:
1496 SetTextColor((HDC16
)wParam
, 0x00000000);
1505 /***********************************************************************
1506 * FileSaveDlgProc (COMMDLG.7)
1508 BOOL16 CALLBACK
FileSaveDlgProc16(HWND16 hWnd16
, UINT16 wMsg
, WPARAM16 wParam
,
1511 HWND hWnd
= HWND_32(hWnd16
);
1512 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1515 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1516 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1519 lRet
= (BOOL16
)FILEDLG_CallWindowProc16(lfs
, wMsg
, wParam
, lParam
);
1521 return lRet
; /* else continue message processing */
1525 return FILEDLG_WMInitDialog16(hWnd
, wParam
, lParam
);
1527 case WM_MEASUREITEM
:
1528 return FILEDLG_WMMeasureItem16(hWnd16
, wParam
, lParam
);
1531 FILEDLG_MapDrawItemStruct(MapSL(lParam
), &dis
);
1532 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
, &dis
);
1535 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(lParam
), wParam
, lfs
);
1540 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1541 switch (HIWORD(lParam))
1544 SetTextColor((HDC16)wParam, 0x00000000);
1546 case CTLCOLOR_STATIC:
1547 SetTextColor((HDC16)wParam, 0x00000000);
1558 /***********************************************************************
1559 * GetFileName31A [internal]
1561 * Creates a win31 style dialog box for the user to select a file to open/save.
1563 BOOL
GetFileName31A(
1564 LPOPENFILENAMEA lpofn
, /* addess of structure with data*/
1565 UINT dlgType
/* type dialogue : open/save */
1572 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1574 TRACE("ofn flags %08lx\n", lpofn
->Flags
);
1575 lfs
= FILEDLG_AllocPrivate((LPARAM
) lpofn
, LFS32A
, dlgType
);
1578 hInst
= (HINSTANCE
)GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1579 bRet
= DialogBoxIndirectParamA( hInst
, lfs
->template, lpofn
->hwndOwner
,
1580 FileOpenDlgProc
, (LPARAM
)lfs
);
1581 FILEDLG_DestroyPrivate(lfs
);
1584 TRACE("return lpstrFile='%s' !\n", lpofn
->lpstrFile
);
1588 /***********************************************************************
1589 * GetFileName31W [internal]
1591 * Creates a win31 style dialog box for the user to select a file to open/save
1593 BOOL
GetFileName31W(
1594 LPOPENFILENAMEW lpofn
, /* addess of structure with data*/
1595 UINT dlgType
/* type dialogue : open/save */
1602 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1604 lfs
= FILEDLG_AllocPrivate((LPARAM
) lpofn
, LFS32W
, dlgType
);
1607 hInst
= (HINSTANCE
)GetWindowLongA( lpofn
->hwndOwner
, GWL_HINSTANCE
);
1608 bRet
= DialogBoxIndirectParamW( hInst
, lfs
->template, lpofn
->hwndOwner
,
1609 FileOpenDlgProc
, (LPARAM
)lfs
);
1610 FILEDLG_DestroyPrivate(lfs
);
1613 TRACE("return lpstrFile=%s !\n", debugstr_w(lpofn
->lpstrFile
));
1623 /* ------------------ APIs ---------------------- */
1625 /***********************************************************************
1626 * GetOpenFileName (COMMDLG.1)
1628 * Creates a dialog box for the user to select a file to open.
1631 * TRUE on success: user selected a valid file
1632 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1635 * unknown, there are some FIXME's left.
1637 BOOL16 WINAPI
GetOpenFileName16(
1638 SEGPTR ofn
/* [in/out] address of structure with data*/
1643 LPOPENFILENAME16 lpofn
= MapSL(ofn
);
1647 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1649 lfs
= FILEDLG_AllocPrivate((LPARAM
) ofn
, LFS16
, OPEN_DIALOG
);
1652 hInst
= GetWindowWord( HWND_32(lpofn
->hwndOwner
), GWL_HINSTANCE
);
1653 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 6);
1654 bRet
= DialogBoxIndirectParam16( hInst
, lfs
->hDlgTmpl16
, lpofn
->hwndOwner
,
1655 (DLGPROC16
) ptr
, (LPARAM
) lfs
);
1656 FILEDLG_DestroyPrivate(lfs
);
1659 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn
->lpstrFile
));
1663 /***********************************************************************
1664 * GetSaveFileName (COMMDLG.2)
1666 * Creates a dialog box for the user to select a file to save.
1669 * TRUE on success: user enters a valid file
1670 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1673 * unknown. There are some FIXME's left.
1675 BOOL16 WINAPI
GetSaveFileName16(
1676 SEGPTR ofn
/* [in/out] addess of structure with data*/
1681 LPOPENFILENAME16 lpofn
= MapSL(ofn
);
1685 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1687 lfs
= FILEDLG_AllocPrivate((LPARAM
) ofn
, LFS16
, SAVE_DIALOG
);
1690 hInst
= GetWindowWord( HWND_32(lpofn
->hwndOwner
), GWL_HINSTANCE
);
1691 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 7);
1692 bRet
= DialogBoxIndirectParam16( hInst
, lfs
->hDlgTmpl16
, lpofn
->hwndOwner
,
1693 (DLGPROC16
) ptr
, (LPARAM
) lfs
);
1694 FILEDLG_DestroyPrivate(lfs
);
1697 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn
->lpstrFile
));