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
);
49 #define BUFFILEALLOC 512 * sizeof(WCHAR)
53 HWND hwnd
; /* file dialog window handle */
54 BOOL hook
; /* TRUE if the dialog is hooked */
55 UINT lbselchstring
; /* registered message id */
56 UINT fileokstring
; /* registered message id */
57 LPARAM lParam
; /* save original lparam */
58 HANDLE16 hDlgTmpl16
; /* handle for resource 16 */
59 HANDLE16 hResource16
; /* handle for allocated resource 16 */
60 HANDLE16 hGlobal16
; /* 16 bits mem block (resources) */
61 LPCVOID
template; /* template for 32 bits resource */
62 BOOL open
; /* TRUE if open dialog, FALSE if save dialog */
63 OPENFILENAMEW
*ofnW
; /* original structure or work struct */
64 OPENFILENAMEA
*ofnA
; /* original structure if 32bits ansi dialog */
65 OPENFILENAME16
*ofn16
; /* original structure if 16 bits dialog */
68 #define LFSPRIVATE struct FSPRIVATE *
72 #define OFN_PROP "FILEDLG_OFN"
74 static const WCHAR FILE_star
[] = {'*','.','*', 0};
75 static const WCHAR FILE_bslash
[] = {'\\', 0};
76 static const WCHAR FILE_specc
[] = {'%','c',':', 0};
77 static const int fldrHeight
= 16;
78 static const int fldrWidth
= 20;
80 static HICON hFolder
= 0;
81 static HICON hFolder2
= 0;
82 static HICON hFloppy
= 0;
83 static HICON hHDisk
= 0;
84 static HICON hCDRom
= 0;
85 static HICON hNet
= 0;
86 static char defaultopen
[]="Open File";
87 static char defaultsave
[]="Save as";
89 /***********************************************************************
90 * FileDlg_Init [internal]
92 static BOOL
FileDlg_Init(void)
94 static BOOL initialized
= 0;
97 HINSTANCE inst
= GetModuleHandleA( "comdlg32.dll" );
100 ERR( "cannot get comdlg32.dll instance\n" );
103 hFolder
= LoadImageA( inst
, "FOLDER", IMAGE_ICON
, 16, 16, LR_SHARED
);
104 hFolder2
= LoadImageA( inst
, "FOLDER2", IMAGE_ICON
, 16, 16, LR_SHARED
);
105 hFloppy
= LoadImageA( inst
, "FLOPPY", IMAGE_ICON
, 16, 16, LR_SHARED
);
106 hHDisk
= LoadImageA( inst
, "HDISK", IMAGE_ICON
, 16, 16, LR_SHARED
);
107 hCDRom
= LoadImageA( inst
, "CDROM", IMAGE_ICON
, 16, 16, LR_SHARED
);
108 hNet
= LoadImageA( inst
, "NETWORK", IMAGE_ICON
, 16, 16, LR_SHARED
);
109 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
110 hHDisk
== 0 || hCDRom
== 0 || hNet
== 0)
112 ERR("Error loading icons !\n");
120 /***********************************************************************
121 * Get32BitsTemplate [internal]
123 * Get a template (or FALSE if failure) when 16 bits dialogs are used
124 * by a 32 bits application
127 BOOL
Get32BitsTemplate(LFSPRIVATE lfs
)
129 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
132 if (ofnW
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
134 if (!(lfs
->template = LockResource( ofnW
->hInstance
)))
136 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
140 else if (ofnW
->Flags
& OFN_ENABLETEMPLATE
)
144 hResInfo
= FindResourceA(lfs
->ofnA
->hInstance
,
145 lfs
->ofnA
->lpTemplateName
,
148 hResInfo
= FindResourceW(ofnW
->hInstance
,
149 ofnW
->lpTemplateName
,
153 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
156 if (!(hDlgTmpl
= LoadResource(ofnW
->hInstance
,
158 !(lfs
->template = LockResource(hDlgTmpl
)))
160 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
163 } else { /* get it from internal Wine resource */
165 if (!(hResInfo
= FindResourceA(COMDLG32_hInstance
,
166 lfs
->open
? "OPEN_FILE":"SAVE_FILE", (LPSTR
)RT_DIALOG
)))
168 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
171 if (!(hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
172 !(lfs
->template = LockResource( hDlgTmpl
)))
174 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
181 /***********************************************************************
182 * Get16BitsTemplate [internal]
184 * Get a template (FALSE if failure) when 16 bits dialogs are used
185 * by a 16 bits application
188 BOOL
Get16BitsTemplate(LFSPRIVATE lfs
)
190 LPOPENFILENAME16 ofn16
= lfs
->ofn16
;
192 HGLOBAL16 hGlobal16
= 0;
194 if (ofn16
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
195 lfs
->hDlgTmpl16
= ofn16
->hInstance
;
196 else if (ofn16
->Flags
& OFN_ENABLETEMPLATE
)
199 if (!(hResInfo
= FindResource16(ofn16
->hInstance
,
200 MapSL(ofn16
->lpTemplateName
),
203 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
206 if (!(lfs
->hDlgTmpl16
= LoadResource16( ofn16
->hInstance
, hResInfo
)))
208 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
211 lfs
->hResource16
= lfs
->hDlgTmpl16
;
214 { /* get resource from (32 bits) own Wine resource; convert it to 16 */
220 if (!(hResInfo
= FindResourceA(COMDLG32_hInstance
,
221 lfs
->open
? "OPEN_FILE":"SAVE_FILE", (LPSTR
)RT_DIALOG
)))
223 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
226 if (!(hDlgTmpl32
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
227 !(template32
= LockResource( hDlgTmpl32
)))
229 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
232 size
= SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo
);
233 hGlobal16
= GlobalAlloc16(0, size
);
236 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
237 ERR("alloc failure for %ld bytes\n", size
);
240 template = GlobalLock16(hGlobal16
);
243 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
244 ERR("global lock failure for %x handle\n", hGlobal16
);
245 GlobalFree16(hGlobal16
);
248 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
249 lfs
->hDlgTmpl16
= hGlobal16
;
250 lfs
->hGlobal16
= hGlobal16
;
255 /***********************************************************************
256 * FILEDLG_StripEditControl [internal]
257 * Strip pathnames off the contents of the edit control.
259 static void FILEDLG_StripEditControl(HWND hwnd
)
261 WCHAR temp
[BUFFILE
], *cp
;
263 GetDlgItemTextW( hwnd
, edt1
, temp
, sizeof(temp
)/sizeof(WCHAR
));
264 cp
= strrchrW(temp
, '\\');
268 cp
= strrchrW(temp
, ':');
272 /* FIXME: shouldn't we do something with the result here? ;-) */
275 /***********************************************************************
276 * FILEDLG_CallWindowProc [internal]
278 * Call the appropriate hook
280 static BOOL
FILEDLG_CallWindowProc(LFSPRIVATE lfs
, UINT wMsg
, WPARAM wParam
,
285 return (BOOL
) CallWindowProcA(
286 (WNDPROC
)lfs
->ofnA
->lpfnHook
, lfs
->hwnd
,
287 wMsg
, wParam
, lParam
);
292 return (BOOL
) CallWindowProcW(
293 (WNDPROC
)lfs
->ofnW
->lpfnHook
, lfs
->hwnd
,
294 wMsg
, wParam
, lParam
);
299 /***********************************************************************
300 * FILEDLG_ScanDir [internal]
302 static BOOL
FILEDLG_ScanDir(HWND hWnd
, LPWSTR newPath
)
304 WCHAR buffer
[BUFFILE
];
307 HCURSOR hCursorWait
, oldCursor
;
309 TRACE("Trying to change to %s\n", debugstr_w(newPath
));
310 if ( !SetCurrentDirectoryW( newPath
))
312 lstrcpynW(buffer
, newPath
, sizeof(buffer
)/sizeof(WCHAR
));
314 /* get the list of spec files */
315 GetDlgItemTextW(hWnd
, edt1
, buffer
, sizeof(buffer
)/sizeof(WCHAR
));
317 hCursorWait
= LoadCursorA(0, (LPSTR
)IDC_WAIT
);
318 oldCursor
= SetCursor(hCursorWait
);
321 if ((hdlg
= GetDlgItem(hWnd
, lst1
)) != 0) {
322 WCHAR
* scptr
; /* ptr on semi-colon */
323 WCHAR
* filter
= buffer
;
325 TRACE("Using filter %s\n", debugstr_w(filter
));
326 SendMessageW(hdlg
, LB_RESETCONTENT
, 0, 0);
328 scptr
= strchrW(filter
, ';');
329 if (scptr
) *scptr
= 0;
330 while (*filter
== ' ') filter
++;
331 TRACE("Using file spec %s\n", debugstr_w(filter
));
332 if (SendMessageW(hdlg
, LB_DIR
, 0, (LPARAM
)filter
) == LB_ERR
)
334 if (scptr
) *scptr
= ';';
335 filter
= (scptr
) ? (scptr
+ 1) : 0;
339 /* list of directories */
340 strcpyW(buffer
, FILE_star
);
342 if ((hdlgDir
= GetDlgItem(hWnd
, lst2
)) != 0) {
343 lRet
= DlgDirListW(hWnd
, buffer
, lst2
, stc1
, DDL_EXCLUSIVE
| DDL_DIRECTORY
);
345 SetCursor(oldCursor
);
349 /***********************************************************************
350 * FILEDLG_GetFileType [internal]
353 static LPWSTR
FILEDLG_GetFileType(LPWSTR cfptr
, LPWSTR fptr
, WORD index
)
358 for ( ;(n
= lstrlenW(cfptr
)) != 0; i
++)
363 cfptr
+= lstrlenW(cfptr
) + 1;
366 for ( ;(n
= lstrlenW(fptr
)) != 0; i
++)
371 fptr
+= lstrlenW(fptr
) + 1;
373 return (LPWSTR
) FILE_star
; /* FIXME */
376 /***********************************************************************
377 * FILEDLG_WMDrawItem [internal]
379 static LONG
FILEDLG_WMDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
,
380 int savedlg
, LPDRAWITEMSTRUCT lpdis
)
384 COLORREF oldText
= 0, oldBk
= 0;
386 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
388 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
))) return FALSE
;
389 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
392 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
394 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
395 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
398 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_GRAYTEXT
) );
400 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ 1,
401 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
402 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
404 if (lpdis
->itemState
& ODS_SELECTED
)
405 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
407 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
409 SetBkColor( lpdis
->hDC
, oldBk
);
410 SetTextColor( lpdis
->hDC
, oldText
);
412 HeapFree(GetProcessHeap(), 0, str
);
416 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
418 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
420 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
423 if (lpdis
->itemState
& ODS_SELECTED
)
425 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
426 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
428 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
429 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
430 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
432 if (lpdis
->itemState
& ODS_SELECTED
)
433 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
435 if (lpdis
->itemState
& ODS_SELECTED
)
437 SetBkColor( lpdis
->hDC
, oldBk
);
438 SetTextColor( lpdis
->hDC
, oldText
);
440 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hFolder
);
441 HeapFree(GetProcessHeap(), 0, str
);
444 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
447 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
449 SendMessageW(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
451 root
[0] += str
[2] - 'a';
452 switch(GetDriveTypeA(root
))
454 case DRIVE_REMOVABLE
: hIcon
= hFloppy
; break;
455 case DRIVE_CDROM
: hIcon
= hCDRom
; break;
456 case DRIVE_REMOTE
: hIcon
= hNet
; break;
458 default: hIcon
= hHDisk
; break;
460 if (lpdis
->itemState
& ODS_SELECTED
)
462 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
463 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
465 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
466 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
467 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
469 if (lpdis
->itemState
& ODS_SELECTED
)
471 SetBkColor( lpdis
->hDC
, oldBk
);
472 SetTextColor( lpdis
->hDC
, oldText
);
474 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hIcon
);
475 HeapFree(GetProcessHeap(), 0, str
);
481 /***********************************************************************
482 * FILEDLG_UpdateResult [internal]
483 * update the displayed file name (with path)
485 void FILEDLG_UpdateResult(LFSPRIVATE lfs
, WCHAR
*tmpstr
)
488 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
489 WCHAR tmpstr2
[BUFFILE
];
492 TRACE("%s\n", debugstr_w(tmpstr
));
493 if(ofnW
->Flags
& OFN_NOVALIDATE
)
496 GetCurrentDirectoryW(BUFFILE
, tmpstr2
);
497 lenstr2
= strlenW(tmpstr2
);
499 tmpstr2
[lenstr2
++]='\\';
500 lstrcpynW(tmpstr2
+lenstr2
, tmpstr
, BUFFILE
-lenstr2
);
502 lstrcpynW(ofnW
->lpstrFile
, tmpstr2
, ofnW
->nMaxFile
);
503 if((bs
= strrchrW(tmpstr2
, '\\')) != NULL
)
504 ofnW
->nFileOffset
= bs
- tmpstr2
+1;
506 ofnW
->nFileOffset
= 0;
507 ofnW
->nFileExtension
= 0;
508 while(tmpstr2
[ofnW
->nFileExtension
] != '.' && tmpstr2
[ofnW
->nFileExtension
] != '\0')
509 ofnW
->nFileExtension
++;
510 if (tmpstr2
[ofnW
->nFileExtension
] == '\0')
511 ofnW
->nFileExtension
= 0;
513 ofnW
->nFileExtension
++;
514 /* update the real client structures if any */
516 { /* we have to convert to short (8.3) path */
517 char tmp
[1024]; /* MAX_PATHNAME_LEN */
518 LPOPENFILENAME16 ofn16
= lfs
->ofn16
;
519 char *dest
= MapSL(ofn16
->lpstrFile
);
521 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFile
, -1,
522 tmp
, sizeof(tmp
), NULL
, NULL
))
523 tmp
[sizeof(tmp
)-1] = 0;
524 GetShortPathNameA(tmp
, dest
, ofn16
->nMaxFile
);
526 /* the same procedure as every year... */
527 if((bs16
= strrchr(dest
, '\\')) != NULL
)
528 ofn16
->nFileOffset
= bs16
- dest
+1;
530 ofn16
->nFileOffset
= 0;
531 ofn16
->nFileExtension
= 0;
532 while(dest
[ofn16
->nFileExtension
] != '.' && dest
[ofn16
->nFileExtension
] != '\0')
533 ofn16
->nFileExtension
++;
534 if (dest
[ofn16
->nFileExtension
] == '\0')
535 ofn16
->nFileExtension
= 0;
537 ofn16
->nFileExtension
++;
541 if (ofnW
->nMaxFile
&&
542 !WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFile
, -1,
543 lfs
->ofnA
->lpstrFile
, ofnW
->nMaxFile
, NULL
, NULL
))
544 lfs
->ofnA
->lpstrFile
[ofnW
->nMaxFile
-1] = 0;
545 lfs
->ofnA
->nFileOffset
= ofnW
->nFileOffset
;
546 lfs
->ofnA
->nFileExtension
= ofnW
->nFileExtension
;
550 /***********************************************************************
551 * FILEDLG_UpdateFileTitle [internal]
552 * update the displayed file name (without path)
554 void FILEDLG_UpdateFileTitle(LFSPRIVATE lfs
)
557 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
558 if (ofnW
->lpstrFileTitle
!= NULL
)
560 lRet
= SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETCURSEL
, 0, 0);
561 SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETTEXT
, lRet
,
562 (LPARAM
)ofnW
->lpstrFileTitle
);
565 char *dest
= MapSL(lfs
->ofn16
->lpstrFileTitle
);
566 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFileTitle
, -1,
567 dest
, ofnW
->nMaxFileTitle
, NULL
, NULL
))
568 dest
[ofnW
->nMaxFileTitle
-1] = 0;
572 if (!WideCharToMultiByte( CP_ACP
, 0, ofnW
->lpstrFileTitle
, -1,
573 lfs
->ofnA
->lpstrFileTitle
, ofnW
->nMaxFileTitle
, NULL
, NULL
))
574 lfs
->ofnA
->lpstrFileTitle
[ofnW
->nMaxFileTitle
-1] = 0;
579 /***********************************************************************
580 * FILEDLG_DirListDblClick [internal]
582 static LRESULT
FILEDLG_DirListDblClick( LFSPRIVATE lfs
)
585 HWND hWnd
= lfs
->hwnd
;
587 WCHAR tmpstr
[BUFFILE
];
589 /* get the raw string (with brackets) */
590 lRet
= SendDlgItemMessageW(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
591 if (lRet
== LB_ERR
) return TRUE
;
592 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
593 SendDlgItemMessageW(hWnd
, lst2
, LB_GETTEXT
, lRet
,
595 strcpyW( tmpstr
, pstr
);
596 HeapFree(GetProcessHeap(), 0, pstr
);
597 /* get the selected directory in tmpstr */
598 if (tmpstr
[0] == '[')
600 tmpstr
[lstrlenW(tmpstr
) - 1] = 0;
601 strcpyW(tmpstr
,tmpstr
+1);
603 strcatW(tmpstr
, FILE_bslash
);
605 FILEDLG_ScanDir(hWnd
, tmpstr
);
609 if (FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, lst2
,
610 MAKELONG(lRet
,CD_LBSELCHANGE
)))
616 /***********************************************************************
617 * FILEDLG_FileListSelect [internal]
618 * called when a new item is picked in the file list
620 static LRESULT
FILEDLG_FileListSelect( LFSPRIVATE lfs
)
623 HWND hWnd
= lfs
->hwnd
;
626 lRet
= SendDlgItemMessageW(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
630 /* set the edit control to the choosen file */
631 if ((pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
633 SendDlgItemMessageW(hWnd
, lst1
, LB_GETTEXT
, lRet
,
635 SetDlgItemTextW( hWnd
, edt1
, pstr
);
636 HeapFree(GetProcessHeap(), 0, pstr
);
640 FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, lst1
,
641 MAKELONG(lRet
,CD_LBSELCHANGE
));
643 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD,
648 /***********************************************************************
649 * FILEDLG_TestPath [internal]
650 * before accepting the file name, test if it includes wild cards
651 * tries to scan the directory and returns TRUE if no error.
653 static LRESULT
FILEDLG_TestPath( LFSPRIVATE lfs
, LPWSTR path
)
655 HWND hWnd
= lfs
->hwnd
;
656 LPWSTR pBeginFileName
, pstr2
;
657 WCHAR tmpstr2
[BUFFILE
];
659 pBeginFileName
= strrchrW(path
, '\\');
660 if (pBeginFileName
== NULL
)
661 pBeginFileName
= strrchrW(path
, ':');
663 if (strchrW(path
,'*') != NULL
|| strchrW(path
,'?') != NULL
)
665 /* edit control contains wildcards */
666 if (pBeginFileName
!= NULL
)
668 lstrcpynW(tmpstr2
, pBeginFileName
+ 1, BUFFILE
);
669 *(pBeginFileName
+ 1) = 0;
673 strcpyW(tmpstr2
, path
);
674 if(!(lfs
->ofnW
->Flags
& OFN_NOVALIDATE
))
678 TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path
), debugstr_w(tmpstr2
));
679 SetDlgItemTextW( hWnd
, edt1
, tmpstr2
);
680 FILEDLG_ScanDir(hWnd
, path
);
681 return (lfs
->ofnW
->Flags
& OFN_NOVALIDATE
) ? TRUE
: FALSE
;
684 /* no wildcards, we might have a directory or a filename */
685 /* try appending a wildcard and reading the directory */
687 pstr2
= path
+ lstrlenW(path
);
688 if (pBeginFileName
== NULL
|| *(pBeginFileName
+ 1) != 0)
689 strcatW(path
, FILE_bslash
);
691 /* if ScanDir succeeds, we have changed the directory */
692 if (FILEDLG_ScanDir(hWnd
, path
))
695 /* if not, this must be a filename */
697 *pstr2
= 0; /* remove the wildcard added before */
699 if (pBeginFileName
!= NULL
)
701 /* strip off the pathname */
703 SetDlgItemTextW( hWnd
, edt1
, pBeginFileName
+ 1 );
705 lstrcpynW(tmpstr2
, pBeginFileName
+ 1, sizeof(tmpstr2
)/sizeof(WCHAR
) );
706 /* Should we MessageBox() if this fails? */
707 if (!FILEDLG_ScanDir(hWnd
, path
))
711 strcpyW(path
, tmpstr2
);
714 SetDlgItemTextW( hWnd
, edt1
, path
);
718 /***********************************************************************
719 * FILEDLG_Validate [internal]
720 * called on: click Ok button, Enter in edit, DoubleClick in file list
722 static LRESULT
FILEDLG_Validate( LFSPRIVATE lfs
, LPWSTR path
, UINT control
, INT itemIndex
,
726 HWND hWnd
= lfs
->hwnd
;
727 OPENFILENAMEW ofnsav
;
728 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
729 WCHAR filename
[BUFFILE
];
731 ofnsav
= *ofnW
; /* for later restoring */
733 /* get current file name */
735 lstrcpynW(filename
, path
, sizeof(filename
)/sizeof(WCHAR
));
737 GetDlgItemTextW( hWnd
, edt1
, filename
, sizeof(filename
)/sizeof(WCHAR
));
739 TRACE("got filename = %s\n", debugstr_w(filename
));
740 /* if we did not click in file list to get there */
743 if (!FILEDLG_TestPath( lfs
, filename
) )
746 FILEDLG_UpdateResult(lfs
, filename
);
749 { /* called internally after a change in a combo */
752 FILEDLG_CallWindowProc(lfs
, lfs
->lbselchstring
, control
,
753 MAKELONG(itemIndex
,CD_LBSELCHANGE
));
758 FILEDLG_UpdateFileTitle(lfs
);
761 lRet
= (BOOL
)FILEDLG_CallWindowProc(lfs
, lfs
->fileokstring
,
765 *ofnW
= ofnsav
; /* restore old state */
769 if ((ofnW
->Flags
& OFN_ALLOWMULTISELECT
) && (ofnW
->Flags
& OFN_EXPLORER
))
773 LPWSTR str
= (LPWSTR
)ofnW
->lpstrFile
;
774 LPWSTR ptr
= strrchrW(str
, '\\');
775 str
[lstrlenW(str
) + 1] = '\0';
782 /***********************************************************************
783 * FILEDLG_DiskChange [internal]
784 * called when a new item is picked in the disk selection combo
786 static LRESULT
FILEDLG_DiskChange( LFSPRIVATE lfs
)
789 HWND hWnd
= lfs
->hwnd
;
791 WCHAR diskname
[BUFFILE
];
793 FILEDLG_StripEditControl(hWnd
);
794 lRet
= SendDlgItemMessageW(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
797 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
798 SendDlgItemMessageW(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
,
800 wsprintfW(diskname
, FILE_specc
, pstr
[2]);
801 HeapFree(GetProcessHeap(), 0, pstr
);
803 return FILEDLG_Validate( lfs
, diskname
, cmb2
, lRet
, TRUE
);
806 /***********************************************************************
807 * FILEDLG_FileTypeChange [internal]
808 * called when a new item is picked in the file type combo
810 static LRESULT
FILEDLG_FileTypeChange( LFSPRIVATE lfs
)
813 WCHAR diskname
[BUFFILE
];
818 lRet
= SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETCURSEL
, 0, 0);
821 pstr
= (LPWSTR
)SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
822 TRACE("Selected filter : %s\n", debugstr_w(pstr
));
823 SetDlgItemTextW( lfs
->hwnd
, edt1
, pstr
);
825 return FILEDLG_Validate( lfs
, NULL
, cmb1
, lRet
, TRUE
);
828 /***********************************************************************
829 * FILEDLG_WMCommand [internal]
831 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, LPARAM lParam
, UINT notification
,
832 UINT control
, LFSPRIVATE lfs
)
836 case lst1
: /* file list */
837 FILEDLG_StripEditControl(hWnd
);
838 if (notification
== LBN_DBLCLK
)
840 if (FILEDLG_Validate( lfs
, NULL
, control
, 0, FALSE
))
841 EndDialog(hWnd
, TRUE
);
844 else if (notification
== LBN_SELCHANGE
)
845 return FILEDLG_FileListSelect( lfs
);
848 case lst2
: /* directory list */
849 FILEDLG_StripEditControl(hWnd
);
850 if (notification
== LBN_DBLCLK
)
851 return FILEDLG_DirListDblClick( lfs
);
854 case cmb1
: /* file type drop list */
855 if (notification
== CBN_SELCHANGE
)
856 return FILEDLG_FileTypeChange( lfs
);
865 case cmb2
: /* disk dropdown combo */
866 if (notification
== CBN_SELCHANGE
)
867 return FILEDLG_DiskChange( lfs
);
871 TRACE("OK pressed\n");
872 if (FILEDLG_Validate( lfs
, NULL
, control
, 0, FALSE
))
873 EndDialog(hWnd
, TRUE
);
877 EndDialog(hWnd
, FALSE
);
880 case IDABORT
: /* can be sent by the hook procedure */
881 EndDialog(hWnd
, TRUE
);
887 /***********************************************************************
888 * FILEDLG_MapDrawItemStruct [internal]
889 * map a 16 bits drawitem struct to 32
891 static void FILEDLG_MapDrawItemStruct(LPDRAWITEMSTRUCT16 lpdis16
, LPDRAWITEMSTRUCT lpdis
)
893 lpdis
->CtlType
= lpdis16
->CtlType
;
894 lpdis
->CtlID
= lpdis16
->CtlID
;
895 lpdis
->itemID
= lpdis16
->itemID
;
896 lpdis
->itemAction
= lpdis16
->itemAction
;
897 lpdis
->itemState
= lpdis16
->itemState
;
898 lpdis
->hwndItem
= HWND_32(lpdis16
->hwndItem
);
899 lpdis
->hDC
= HDC_32(lpdis16
->hDC
);
900 lpdis
->rcItem
.right
= lpdis16
->rcItem
.right
;
901 lpdis
->rcItem
.left
= lpdis16
->rcItem
.left
;
902 lpdis
->rcItem
.top
= lpdis16
->rcItem
.top
;
903 lpdis
->rcItem
.bottom
= lpdis16
->rcItem
.bottom
;
904 lpdis
->itemData
= lpdis16
->itemData
;
907 /************************************************************************
908 * FILEDLG_MapStringPairsToW [internal]
909 * map string pairs to Unicode
911 static LPWSTR
FILEDLG_MapStringPairsToW(LPCSTR strA
, UINT size
)
921 n
= s
+ 1 - strA
; /* Don't forget the other \0 */
922 if (n
< size
) n
= size
;
924 len
= MultiByteToWideChar( CP_ACP
, 0, strA
, n
, NULL
, 0 );
925 x
= HeapAlloc(GetProcessHeap(),0, len
* sizeof(WCHAR
));
926 MultiByteToWideChar( CP_ACP
, 0, strA
, n
, x
, len
);
931 /************************************************************************
932 * FILEDLG_DupToW [internal]
933 * duplicates an Ansi string to unicode, with a buffer size
935 LPWSTR
FILEDLG_DupToW(LPCSTR str
, DWORD size
)
938 if (str
&& (size
> 0))
940 strW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
941 if (strW
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, strW
, size
);
947 /************************************************************************
948 * FILEDLG_MapOfnStructA [internal]
949 * map a 32 bits Ansi structure to an Unicode one
951 void FILEDLG_MapOfnStructA(LPOPENFILENAMEA ofnA
, LPOPENFILENAMEW ofnW
, BOOL open
)
954 UNICODE_STRING usBuffer
;
956 ofnW
->lStructSize
= sizeof(OPENFILENAMEW
);
957 ofnW
->hwndOwner
= ofnA
->hwndOwner
;
958 ofnW
->hInstance
= ofnA
->hInstance
;
959 if (ofnA
->lpstrFilter
)
960 ofnW
->lpstrFilter
= FILEDLG_MapStringPairsToW(ofnA
->lpstrFilter
, 0);
962 if ((ofnA
->lpstrCustomFilter
) && (*(ofnA
->lpstrCustomFilter
)))
963 ofnW
->lpstrCustomFilter
= FILEDLG_MapStringPairsToW(ofnA
->lpstrCustomFilter
, ofnA
->nMaxCustFilter
);
964 ofnW
->nMaxCustFilter
= ofnA
->nMaxCustFilter
;
965 ofnW
->nFilterIndex
= ofnA
->nFilterIndex
;
966 ofnW
->nMaxFile
= ofnA
->nMaxFile
;
967 ofnW
->lpstrFile
= FILEDLG_DupToW(ofnA
->lpstrFile
, ofnW
->nMaxFile
);
968 ofnW
->nMaxFileTitle
= ofnA
->nMaxFileTitle
;
969 ofnW
->lpstrFileTitle
= FILEDLG_DupToW(ofnA
->lpstrFileTitle
, ofnW
->nMaxFileTitle
);
970 if (ofnA
->lpstrInitialDir
)
972 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpstrInitialDir
);
973 ofnW
->lpstrInitialDir
= usBuffer
.Buffer
;
975 if (ofnA
->lpstrTitle
)
976 str
= ofnA
->lpstrTitle
;
978 /* Allocates default title (FIXME : get it from resource) */
979 str
= open
? defaultopen
:defaultsave
;
980 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpstrTitle
);
981 ofnW
->lpstrTitle
= usBuffer
.Buffer
;
982 ofnW
->Flags
= ofnA
->Flags
;
983 ofnW
->nFileOffset
= ofnA
->nFileOffset
;
984 ofnW
->nFileExtension
= ofnA
->nFileExtension
;
985 ofnW
->lpstrDefExt
= FILEDLG_DupToW(ofnA
->lpstrDefExt
, 3);
986 if ((ofnA
->Flags
& OFN_ENABLETEMPLATE
) && (ofnA
->lpTemplateName
))
988 if (HIWORD(ofnA
->lpTemplateName
))
990 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpTemplateName
);
991 ofnW
->lpTemplateName
= usBuffer
.Buffer
;
993 else /* numbered resource */
994 ofnW
->lpTemplateName
= (LPWSTR
) ofnA
->lpTemplateName
;
998 /************************************************************************
999 * FILEDLG_MapOfnStruct16 [internal]
1000 * map a 16 bits structure to an Unicode one
1002 void FILEDLG_MapOfnStruct16(LPOPENFILENAME16 ofn16
, LPOPENFILENAMEW ofnW
, BOOL open
)
1005 /* first convert to linear pointers */
1006 memset(&ofnA
, 0, sizeof(OPENFILENAMEA
));
1007 ofnA
.lStructSize
= sizeof(OPENFILENAMEA
);
1008 ofnA
.hwndOwner
= HWND_32(ofn16
->hwndOwner
);
1009 ofnA
.hInstance
= HINSTANCE_32(ofn16
->hInstance
);
1010 if (ofn16
->lpstrFilter
)
1011 ofnA
.lpstrFilter
= MapSL(ofn16
->lpstrFilter
);
1012 if (ofn16
->lpstrCustomFilter
)
1013 ofnA
.lpstrCustomFilter
= MapSL(ofn16
->lpstrCustomFilter
);
1014 ofnA
.nMaxCustFilter
= ofn16
->nMaxCustFilter
;
1015 ofnA
.nFilterIndex
= ofn16
->nFilterIndex
;
1016 ofnA
.lpstrFile
= MapSL(ofn16
->lpstrFile
);
1017 ofnA
.nMaxFile
= ofn16
->nMaxFile
;
1018 ofnA
.lpstrFileTitle
= MapSL(ofn16
->lpstrFileTitle
);
1019 ofnA
.nMaxFileTitle
= ofn16
->nMaxFileTitle
;
1020 ofnA
.lpstrInitialDir
= MapSL(ofn16
->lpstrInitialDir
);
1021 ofnA
.lpstrTitle
= MapSL(ofn16
->lpstrTitle
);
1022 ofnA
.Flags
= ofn16
->Flags
;
1023 ofnA
.nFileOffset
= ofn16
->nFileOffset
;
1024 ofnA
.nFileExtension
= ofn16
->nFileExtension
;
1025 ofnA
.lpstrDefExt
= MapSL(ofn16
->lpstrDefExt
);
1026 if (HIWORD(ofn16
->lpTemplateName
))
1027 ofnA
.lpTemplateName
= MapSL(ofn16
->lpTemplateName
);
1029 ofnA
.lpTemplateName
= (LPSTR
) ofn16
->lpTemplateName
; /* ressource number */
1030 /* now calls the 32 bits Ansi to Unicode version to complete the job */
1031 FILEDLG_MapOfnStructA(&ofnA
, ofnW
, open
);
1034 /************************************************************************
1035 * FILEDLG_DestroyPrivate [internal]
1036 * destroys the private object
1038 static void FILEDLG_DestroyPrivate(LFSPRIVATE lfs
)
1043 /* free resources for a 16 bits dialog */
1044 if (lfs
->hResource16
) FreeResource16(lfs
->hResource16
);
1047 GlobalUnlock16(lfs
->hGlobal16
);
1048 GlobalFree16(lfs
->hGlobal16
);
1050 /* if ofnW has been allocated, have to free everything in it */
1051 if (lfs
->ofn16
|| lfs
->ofnA
)
1053 LPOPENFILENAMEW ofnW
= lfs
->ofnW
;
1054 if (ofnW
->lpstrFilter
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrFilter
);
1055 if (ofnW
->lpstrCustomFilter
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrCustomFilter
);
1056 if (ofnW
->lpstrFile
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFile
);
1057 if (ofnW
->lpstrFileTitle
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFileTitle
);
1058 if (ofnW
->lpstrInitialDir
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrInitialDir
);
1059 if (ofnW
->lpstrTitle
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrTitle
);
1060 if ((ofnW
->lpTemplateName
) && (HIWORD(ofnW
->lpTemplateName
)))
1061 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpTemplateName
);
1062 HeapFree(GetProcessHeap(), 0, ofnW
);
1064 TRACE("destroying private allocation %p\n", lfs
);
1065 HeapFree(GetProcessHeap(), 0, lfs
);
1066 RemovePropA(hwnd
, OFN_PROP
);
1069 /************************************************************************
1070 * FILEDLG_AllocPrivate [internal]
1071 * allocate a private object to hold 32 bits Unicode
1072 * structure that will be used throughtout the calls, while
1073 * keeping available the original structures and a few variables
1074 * On entry : type = dialog procedure type (16,32A,32W)
1075 * dlgType = dialog type (open or save)
1077 static LFSPRIVATE
FILEDLG_AllocPrivate(LPARAM lParam
, int type
, UINT dlgType
)
1079 LFSPRIVATE lfs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct FSPRIVATE
));
1081 TRACE("alloc private buf %p\n", lfs
);
1082 if (!lfs
) return NULL
;
1084 lfs
->lParam
= lParam
;
1085 if (dlgType
== OPEN_DIALOG
)
1089 lfs
->lbselchstring
= RegisterWindowMessageA(LBSELCHSTRINGA
);
1090 lfs
->fileokstring
= RegisterWindowMessageA(FILEOKSTRINGA
);
1094 lfs
->ofn16
= MapSL(lParam
);
1095 if (lfs
->ofn16
->Flags
& OFN_ENABLEHOOK
)
1096 if (lfs
->ofn16
->lpfnHook
)
1102 lfs
->ofnA
= (LPOPENFILENAMEA
) lParam
;
1103 if (lfs
->ofnA
->Flags
& OFN_ENABLEHOOK
)
1104 if (lfs
->ofnA
->lpfnHook
)
1109 lfs
->ofnW
= (LPOPENFILENAMEW
) lParam
;
1110 if (lfs
->ofnW
->Flags
& OFN_ENABLEHOOK
)
1111 if (lfs
->ofnW
->lpfnHook
)
1117 { /* this structure is needed internally, so create it */
1118 lfs
->ofnW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(OPENFILENAMEW
));
1122 FILEDLG_MapOfnStruct16(lfs
->ofn16
, lfs
->ofnW
, lfs
->open
);
1124 FILEDLG_MapOfnStructA(lfs
->ofnA
, lfs
->ofnW
, lfs
->open
);
1131 if (!Get16BitsTemplate(lfs
)) ret
= NULL
;
1134 if (!Get32BitsTemplate(lfs
)) ret
= NULL
;
1135 if (!ret
) FILEDLG_DestroyPrivate(lfs
);
1139 /***********************************************************************
1140 * FILEDLG_CallWindowProc16 [internal]
1142 * Call the appropriate hook
1144 static BOOL
FILEDLG_CallWindowProc16(LFSPRIVATE lfs
, UINT wMsg
, WPARAM wParam
,
1149 return (BOOL16
) CallWindowProc16(
1150 (WNDPROC16
)lfs
->ofn16
->lpfnHook
, HWND_16(lfs
->hwnd
),
1151 (UINT16
)wMsg
, (WPARAM16
)wParam
, lParam
);
1156 /***********************************************************************
1157 * FILEDLG_WMInitDialog16 [internal]
1158 * The is a duplicate of the 32bit FILEDLG_WMInitDialog function
1159 * The only differnce is that it calls FILEDLG_CallWindowProc16
1160 * for a 16 bit Window Proc.
1163 static LONG
FILEDLG_WMInitDialog16(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1166 WCHAR tmpstr
[BUFFILE
];
1167 LPWSTR pstr
, old_pstr
;
1168 LPOPENFILENAMEW ofn
;
1169 LFSPRIVATE lfs
= (LFSPRIVATE
) lParam
;
1171 if (!lfs
) return FALSE
;
1172 SetPropA(hWnd
, OFN_PROP
, (HANDLE
)lfs
);
1176 TRACE("flags=%lx initialdir=%s\n", ofn
->Flags
, debugstr_w(ofn
->lpstrInitialDir
));
1178 SetWindowTextW( hWnd
, ofn
->lpstrTitle
);
1179 /* read custom filter information */
1180 if (ofn
->lpstrCustomFilter
)
1182 pstr
= ofn
->lpstrCustomFilter
;
1184 TRACE("lpstrCustomFilter = %p\n", pstr
);
1188 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
1189 (LPARAM
)(ofn
->lpstrCustomFilter
) + n
);
1190 n
+= lstrlenW(pstr
) + 1;
1191 pstr
+= lstrlenW(pstr
) + 1;
1192 TRACE("add str=%s associated to %s\n",
1193 debugstr_w(old_pstr
), debugstr_w(pstr
));
1194 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
1195 n
+= lstrlenW(pstr
) + 1;
1196 pstr
+= lstrlenW(pstr
) + 1;
1199 /* read filter information */
1200 if (ofn
->lpstrFilter
) {
1201 pstr
= (LPWSTR
) ofn
->lpstrFilter
;
1205 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
1206 (LPARAM
)(ofn
->lpstrFilter
+ n
) );
1207 n
+= lstrlenW(pstr
) + 1;
1208 pstr
+= lstrlenW(pstr
) + 1;
1209 TRACE("add str=%s associated to %s\n",
1210 debugstr_w(old_pstr
), debugstr_w(pstr
));
1211 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
1212 n
+= lstrlenW(pstr
) + 1;
1213 pstr
+= lstrlenW(pstr
) + 1;
1216 /* set default filter */
1217 if (ofn
->nFilterIndex
== 0 && ofn
->lpstrCustomFilter
== NULL
)
1218 ofn
->nFilterIndex
= 1;
1219 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETCURSEL
, ofn
->nFilterIndex
- 1, 0);
1220 lstrcpynW(tmpstr
, FILEDLG_GetFileType(ofn
->lpstrCustomFilter
,
1221 (LPWSTR
)ofn
->lpstrFilter
, ofn
->nFilterIndex
- 1),BUFFILE
);
1222 TRACE("nFilterIndex = %ld, SetText of edt1 to %s\n",
1223 ofn
->nFilterIndex
, debugstr_w(tmpstr
));
1224 SetDlgItemTextW( hWnd
, edt1
, tmpstr
);
1225 /* get drive list */
1227 DlgDirListComboBoxW(hWnd
, tmpstr
, cmb2
, 0, DDL_DRIVES
| DDL_EXCLUSIVE
);
1228 /* read initial directory */
1229 /* FIXME: Note that this is now very version-specific (See MSDN description of
1230 * the OPENFILENAME structure). For example under 2000/XP any path in the
1231 * lpstrFile overrides the lpstrInitialDir, but not under 95/98/ME
1233 if (ofn
->lpstrInitialDir
!= NULL
)
1236 lstrcpynW(tmpstr
, ofn
->lpstrInitialDir
, 511);
1237 len
= lstrlenW(tmpstr
);
1238 if (len
> 0 && tmpstr
[len
-1] != '\\' && tmpstr
[len
-1] != ':') {
1245 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) {
1247 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
1248 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr
));
1250 /* select current drive in combo 2, omit missing drives */
1253 char str
[4] = "a:\\";
1254 GetCurrentDirectoryA( sizeof(dir
), dir
);
1255 for(i
= 0, n
= -1; i
< 26; i
++)
1258 if (GetDriveTypeA(str
) > DRIVE_NO_ROOT_DIR
) n
++;
1259 if (toupper(str
[0]) == toupper(dir
[0])) break;
1262 SendDlgItemMessageW(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
1263 if (!(ofn
->Flags
& OFN_SHOWHELP
))
1264 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
1265 if (ofn
->Flags
& OFN_HIDEREADONLY
)
1266 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
1268 return (BOOL
) FILEDLG_CallWindowProc16(lfs
, WM_INITDIALOG
, wParam
, lfs
->lParam
);
1272 /***********************************************************************
1273 * FILEDLG_WMMeasureItem16 [internal]
1275 static LONG
FILEDLG_WMMeasureItem16(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
1277 LPMEASUREITEMSTRUCT16 lpmeasure
;
1279 lpmeasure
= MapSL(lParam
);
1280 lpmeasure
->itemHeight
= fldrHeight
;
1284 /* ------------------ Dialog procedures ---------------------- */
1286 /***********************************************************************
1287 * FileOpenDlgProc (COMMDLG.6)
1289 BOOL16 CALLBACK
FileOpenDlgProc16(HWND16 hWnd16
, UINT16 wMsg
, WPARAM16 wParam
,
1292 HWND hWnd
= HWND_32(hWnd16
);
1293 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1296 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1297 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1299 LRESULT lRet
= (BOOL16
)FILEDLG_CallWindowProc16(lfs
, wMsg
, wParam
, lParam
);
1301 return lRet
; /* else continue message processing */
1306 return FILEDLG_WMInitDialog16(hWnd
, wParam
, lParam
);
1308 case WM_MEASUREITEM
:
1309 return FILEDLG_WMMeasureItem16(hWnd16
, wParam
, lParam
);
1312 FILEDLG_MapDrawItemStruct(MapSL(lParam
), &dis
);
1313 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
, &dis
);
1316 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(lParam
),wParam
, lfs
);
1319 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
1320 switch (HIWORD(lParam
))
1323 SetTextColor((HDC16
)wParam
, 0x00000000);
1325 case CTLCOLOR_STATIC
:
1326 SetTextColor((HDC16
)wParam
, 0x00000000);
1335 /***********************************************************************
1336 * FileSaveDlgProc (COMMDLG.7)
1338 BOOL16 CALLBACK
FileSaveDlgProc16(HWND16 hWnd16
, UINT16 wMsg
, WPARAM16 wParam
,
1341 HWND hWnd
= HWND_32(hWnd16
);
1342 LFSPRIVATE lfs
= (LFSPRIVATE
)GetPropA(hWnd
,OFN_PROP
);
1345 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg
, wParam
, lParam
);
1346 if ((wMsg
!= WM_INITDIALOG
) && lfs
&& lfs
->hook
)
1349 lRet
= (BOOL16
)FILEDLG_CallWindowProc16(lfs
, wMsg
, wParam
, lParam
);
1351 return lRet
; /* else continue message processing */
1355 return FILEDLG_WMInitDialog16(hWnd
, wParam
, lParam
);
1357 case WM_MEASUREITEM
:
1358 return FILEDLG_WMMeasureItem16(hWnd16
, wParam
, lParam
);
1361 FILEDLG_MapDrawItemStruct(MapSL(lParam
), &dis
);
1362 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
, &dis
);
1365 return FILEDLG_WMCommand(hWnd
, lParam
, HIWORD(lParam
), wParam
, lfs
);
1370 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1371 switch (HIWORD(lParam))
1374 SetTextColor((HDC16)wParam, 0x00000000);
1376 case CTLCOLOR_STATIC:
1377 SetTextColor((HDC16)wParam, 0x00000000);
1386 /* ------------------ APIs ---------------------- */
1388 /***********************************************************************
1389 * GetOpenFileName (COMMDLG.1)
1391 * Creates a dialog box for the user to select a file to open.
1394 * TRUE on success: user selected a valid file
1395 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1398 * unknown, there are some FIXME's left.
1400 BOOL16 WINAPI
GetOpenFileName16(
1401 SEGPTR ofn
/* [in/out] address of structure with data*/
1406 LPOPENFILENAME16 lpofn
= MapSL(ofn
);
1410 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1412 lfs
= FILEDLG_AllocPrivate((LPARAM
) ofn
, LFS16
, OPEN_DIALOG
);
1415 hInst
= GetWindowWord( HWND_32(lpofn
->hwndOwner
), GWL_HINSTANCE
);
1416 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 6);
1417 bRet
= DialogBoxIndirectParam16( hInst
, lfs
->hDlgTmpl16
, lpofn
->hwndOwner
,
1418 (DLGPROC16
) ptr
, (LPARAM
) lfs
);
1419 FILEDLG_DestroyPrivate(lfs
);
1422 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn
->lpstrFile
));
1426 /***********************************************************************
1427 * GetSaveFileName (COMMDLG.2)
1429 * Creates a dialog box for the user to select a file to save.
1432 * TRUE on success: user enters a valid file
1433 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1436 * unknown. There are some FIXME's left.
1438 BOOL16 WINAPI
GetSaveFileName16(
1439 SEGPTR ofn
/* [in/out] addess of structure with data*/
1444 LPOPENFILENAME16 lpofn
= MapSL(ofn
);
1448 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
1450 lfs
= FILEDLG_AllocPrivate((LPARAM
) ofn
, LFS16
, SAVE_DIALOG
);
1453 hInst
= GetWindowWord( HWND_32(lpofn
->hwndOwner
), GWL_HINSTANCE
);
1454 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 7);
1455 bRet
= DialogBoxIndirectParam16( hInst
, lfs
->hDlgTmpl16
, lpofn
->hwndOwner
,
1456 (DLGPROC16
) ptr
, (LPARAM
) lfs
);
1457 FILEDLG_DestroyPrivate(lfs
);
1460 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn
->lpstrFile
));