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/unicode.h"
32 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
45 #include "filedlg31.h"
48 #define BUFFILEALLOC 512 * sizeof(WCHAR)
50 static const WCHAR FILE_star
[] = {'*','.','*', 0};
51 static const WCHAR FILE_bslash
[] = {'\\', 0};
52 static const WCHAR FILE_specc
[] = {'%','c',':', 0};
53 static const int fldrHeight
= 16;
54 static const int fldrWidth
= 20;
56 static HICON hFolder
= 0;
57 static HICON hFolder2
= 0;
58 static HICON hFloppy
= 0;
59 static HICON hHDisk
= 0;
60 static HICON hCDRom
= 0;
61 static HICON hNet
= 0;
63 /***********************************************************************
64 * FD31_Init [internal]
68 static BOOL initialized
= 0;
71 hFolder
= LoadImageA( COMDLG32_hInstance
, "FOLDER", IMAGE_ICON
, 16, 16, LR_SHARED
);
72 hFolder2
= LoadImageA( COMDLG32_hInstance
, "FOLDER2", IMAGE_ICON
, 16, 16, LR_SHARED
);
73 hFloppy
= LoadImageA( COMDLG32_hInstance
, "FLOPPY", IMAGE_ICON
, 16, 16, LR_SHARED
);
74 hHDisk
= LoadImageA( COMDLG32_hInstance
, "HDISK", IMAGE_ICON
, 16, 16, LR_SHARED
);
75 hCDRom
= LoadImageA( COMDLG32_hInstance
, "CDROM", IMAGE_ICON
, 16, 16, LR_SHARED
);
76 hNet
= LoadImageA( COMDLG32_hInstance
, "NETWORK", IMAGE_ICON
, 16, 16, LR_SHARED
);
77 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
78 hHDisk
== 0 || hCDRom
== 0 || hNet
== 0)
80 ERR("Error loading icons !\n");
88 /***********************************************************************
89 * FD31_StripEditControl [internal]
90 * Strip pathnames off the contents of the edit control.
92 static void FD31_StripEditControl(HWND hwnd
)
94 WCHAR temp
[BUFFILE
], *cp
;
96 GetDlgItemTextW( hwnd
, edt1
, temp
, sizeof(temp
)/sizeof(WCHAR
));
97 cp
= strrchrW(temp
, '\\');
101 cp
= strrchrW(temp
, ':');
105 /* FIXME: shouldn't we do something with the result here? ;-) */
108 /***********************************************************************
109 * FD31_CallWindowProc [internal]
111 * Call the appropriate hook
113 BOOL
FD31_CallWindowProc(PFD31_DATA lfs
, UINT wMsg
, WPARAM wParam
,
116 return lfs
->callbacks
->CWP(lfs
, wMsg
, wParam
, lParam
);
119 /***********************************************************************
120 * FD31_ScanDir [internal]
122 static BOOL
FD31_ScanDir(HWND hWnd
, LPWSTR newPath
)
124 WCHAR buffer
[BUFFILE
];
127 HCURSOR hCursorWait
, oldCursor
;
129 TRACE("Trying to change to %s\n", debugstr_w(newPath
));
130 if ( newPath
[0] && !SetCurrentDirectoryW( newPath
))
132 lstrcpynW(buffer
, newPath
, sizeof(buffer
)/sizeof(WCHAR
));
134 /* get the list of spec files */
135 GetDlgItemTextW(hWnd
, edt1
, buffer
, sizeof(buffer
)/sizeof(WCHAR
));
137 hCursorWait
= LoadCursorA(0, (LPSTR
)IDC_WAIT
);
138 oldCursor
= SetCursor(hCursorWait
);
141 if ((hdlg
= GetDlgItem(hWnd
, lst1
)) != 0) {
142 WCHAR
* scptr
; /* ptr on semi-colon */
143 WCHAR
* filter
= buffer
;
145 TRACE("Using filter %s\n", debugstr_w(filter
));
146 SendMessageW(hdlg
, LB_RESETCONTENT
, 0, 0);
148 scptr
= strchrW(filter
, ';');
149 if (scptr
) *scptr
= 0;
150 while (*filter
== ' ') filter
++;
151 TRACE("Using file spec %s\n", debugstr_w(filter
));
152 if (SendMessageW(hdlg
, LB_DIR
, 0, (LPARAM
)filter
) == LB_ERR
)
154 if (scptr
) *scptr
= ';';
155 filter
= (scptr
) ? (scptr
+ 1) : 0;
159 /* list of directories */
160 strcpyW(buffer
, FILE_star
);
162 if ((hdlgDir
= GetDlgItem(hWnd
, lst2
)) != 0) {
163 lRet
= DlgDirListW(hWnd
, buffer
, lst2
, stc1
, DDL_EXCLUSIVE
| DDL_DIRECTORY
);
165 SetCursor(oldCursor
);
169 /***********************************************************************
170 * FD31_GetFileType [internal]
173 static LPWSTR
FD31_GetFileType(LPWSTR cfptr
, LPWSTR fptr
, WORD index
)
178 for ( ;(n
= lstrlenW(cfptr
)) != 0; i
++)
183 cfptr
+= lstrlenW(cfptr
) + 1;
186 for ( ;(n
= lstrlenW(fptr
)) != 0; i
++)
191 fptr
+= lstrlenW(fptr
) + 1;
193 return (LPWSTR
) FILE_star
; /* FIXME */
196 /***********************************************************************
197 * FD31_WMDrawItem [internal]
199 LONG
FD31_WMDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
,
200 int savedlg
, LPDRAWITEMSTRUCT lpdis
)
204 COLORREF oldText
= 0, oldBk
= 0;
206 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
208 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
))) return FALSE
;
209 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
212 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
214 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
215 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
218 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_GRAYTEXT
) );
220 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ 1,
221 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
222 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
224 if (lpdis
->itemState
& ODS_SELECTED
)
225 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
227 if ((lpdis
->itemState
& ODS_SELECTED
) && !savedlg
)
229 SetBkColor( lpdis
->hDC
, oldBk
);
230 SetTextColor( lpdis
->hDC
, oldText
);
232 HeapFree(GetProcessHeap(), 0, str
);
236 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
238 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
240 SendMessageW(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
243 if (lpdis
->itemState
& ODS_SELECTED
)
245 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
246 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
248 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
249 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
250 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
252 if (lpdis
->itemState
& ODS_SELECTED
)
253 DrawFocusRect( lpdis
->hDC
, &(lpdis
->rcItem
) );
255 if (lpdis
->itemState
& ODS_SELECTED
)
257 SetBkColor( lpdis
->hDC
, oldBk
);
258 SetTextColor( lpdis
->hDC
, oldText
);
260 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hFolder
);
261 HeapFree(GetProcessHeap(), 0, str
);
264 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
267 if (!(str
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
269 SendMessageW(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
271 root
[0] += str
[2] - 'a';
272 switch(GetDriveTypeA(root
))
274 case DRIVE_REMOVABLE
: hIcon
= hFloppy
; break;
275 case DRIVE_CDROM
: hIcon
= hCDRom
; break;
276 case DRIVE_REMOTE
: hIcon
= hNet
; break;
278 default: hIcon
= hHDisk
; break;
280 if (lpdis
->itemState
& ODS_SELECTED
)
282 oldBk
= SetBkColor( lpdis
->hDC
, GetSysColor( COLOR_HIGHLIGHT
) );
283 oldText
= SetTextColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
285 ExtTextOutW(lpdis
->hDC
, lpdis
->rcItem
.left
+ fldrWidth
,
286 lpdis
->rcItem
.top
+ 1, ETO_OPAQUE
| ETO_CLIPPED
,
287 &(lpdis
->rcItem
), str
, lstrlenW(str
), NULL
);
289 if (lpdis
->itemState
& ODS_SELECTED
)
291 SetBkColor( lpdis
->hDC
, oldBk
);
292 SetTextColor( lpdis
->hDC
, oldText
);
294 DrawIcon(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
, hIcon
);
295 HeapFree(GetProcessHeap(), 0, str
);
301 /***********************************************************************
302 * FD31_UpdateResult [internal]
303 * update the displayed file name (with path)
305 void FD31_UpdateResult(PFD31_DATA lfs
, WCHAR
*tmpstr
)
308 LPOPENFILENAMEW ofnW
= &lfs
->ofnW
;
309 WCHAR tmpstr2
[BUFFILE
];
312 TRACE("%s\n", debugstr_w(tmpstr
));
313 if(ofnW
->Flags
& OFN_NOVALIDATE
)
316 GetCurrentDirectoryW(BUFFILE
, tmpstr2
);
317 lenstr2
= strlenW(tmpstr2
);
319 tmpstr2
[lenstr2
++]='\\';
320 lstrcpynW(tmpstr2
+lenstr2
, tmpstr
, BUFFILE
-lenstr2
);
322 lstrcpynW(ofnW
->lpstrFile
, tmpstr2
, ofnW
->nMaxFile
);
323 if((bs
= strrchrW(tmpstr2
, '\\')) != NULL
)
324 ofnW
->nFileOffset
= bs
- tmpstr2
+1;
326 ofnW
->nFileOffset
= 0;
327 ofnW
->nFileExtension
= 0;
328 while(tmpstr2
[ofnW
->nFileExtension
] != '.' && tmpstr2
[ofnW
->nFileExtension
] != '\0')
329 ofnW
->nFileExtension
++;
330 if (tmpstr2
[ofnW
->nFileExtension
] == '\0')
331 ofnW
->nFileExtension
= 0;
333 ofnW
->nFileExtension
++;
334 /* update the real client structures if any */
335 lfs
->callbacks
->UpdateResult(lfs
);
338 /***********************************************************************
339 * FD31_UpdateFileTitle [internal]
340 * update the displayed file name (without path)
342 void FD31_UpdateFileTitle(PFD31_DATA lfs
)
345 LPOPENFILENAMEW ofnW
= &lfs
->ofnW
;
346 if (ofnW
->lpstrFileTitle
!= NULL
)
348 lRet
= SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETCURSEL
, 0, 0);
349 SendDlgItemMessageW(lfs
->hwnd
, lst1
, LB_GETTEXT
, lRet
,
350 (LPARAM
)ofnW
->lpstrFileTitle
);
351 lfs
->callbacks
->UpdateFileTitle(lfs
);
355 /***********************************************************************
356 * FD31_DirListDblClick [internal]
358 static LRESULT
FD31_DirListDblClick( PFD31_DATA lfs
)
361 HWND hWnd
= lfs
->hwnd
;
363 WCHAR tmpstr
[BUFFILE
];
365 /* get the raw string (with brackets) */
366 lRet
= SendDlgItemMessageW(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
367 if (lRet
== LB_ERR
) return TRUE
;
368 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
369 SendDlgItemMessageW(hWnd
, lst2
, LB_GETTEXT
, lRet
,
371 strcpyW( tmpstr
, pstr
);
372 HeapFree(GetProcessHeap(), 0, pstr
);
373 /* get the selected directory in tmpstr */
374 if (tmpstr
[0] == '[')
376 tmpstr
[lstrlenW(tmpstr
) - 1] = 0;
377 strcpyW(tmpstr
,tmpstr
+1);
379 strcatW(tmpstr
, FILE_bslash
);
381 FD31_ScanDir(hWnd
, tmpstr
);
385 if (FD31_CallWindowProc(lfs
, lfs
->lbselchstring
, lst2
,
386 MAKELONG(lRet
,CD_LBSELCHANGE
)))
392 /***********************************************************************
393 * FD31_FileListSelect [internal]
394 * called when a new item is picked in the file list
396 static LRESULT
FD31_FileListSelect( PFD31_DATA lfs
)
399 HWND hWnd
= lfs
->hwnd
;
402 lRet
= lfs
->callbacks
->SendLbGetCurSel(lfs
);
406 /* set the edit control to the choosen file */
407 if ((pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
)))
409 SendDlgItemMessageW(hWnd
, lst1
, LB_GETTEXT
, lRet
,
411 SetDlgItemTextW( hWnd
, edt1
, pstr
);
412 HeapFree(GetProcessHeap(), 0, pstr
);
416 FD31_CallWindowProc(lfs
, lfs
->lbselchstring
, lst1
,
417 MAKELONG(lRet
,CD_LBSELCHANGE
));
419 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD,
424 /***********************************************************************
425 * FD31_TestPath [internal]
426 * before accepting the file name, test if it includes wild cards
427 * tries to scan the directory and returns TRUE if no error.
429 static LRESULT
FD31_TestPath( PFD31_DATA lfs
, LPWSTR path
)
431 HWND hWnd
= lfs
->hwnd
;
432 LPWSTR pBeginFileName
, pstr2
;
433 WCHAR tmpstr2
[BUFFILE
];
435 pBeginFileName
= strrchrW(path
, '\\');
436 if (pBeginFileName
== NULL
)
437 pBeginFileName
= strrchrW(path
, ':');
439 if (strchrW(path
,'*') != NULL
|| strchrW(path
,'?') != NULL
)
441 /* edit control contains wildcards */
442 if (pBeginFileName
!= NULL
)
444 lstrcpynW(tmpstr2
, pBeginFileName
+ 1, BUFFILE
);
445 *(pBeginFileName
+ 1) = 0;
449 strcpyW(tmpstr2
, path
);
450 if(!(lfs
->ofnW
.Flags
& OFN_NOVALIDATE
))
454 TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path
), debugstr_w(tmpstr2
));
455 SetDlgItemTextW( hWnd
, edt1
, tmpstr2
);
456 FD31_ScanDir(hWnd
, path
);
457 return (lfs
->ofnW
.Flags
& OFN_NOVALIDATE
) ? TRUE
: FALSE
;
460 /* no wildcards, we might have a directory or a filename */
461 /* try appending a wildcard and reading the directory */
463 pstr2
= path
+ lstrlenW(path
);
464 if (pBeginFileName
== NULL
|| *(pBeginFileName
+ 1) != 0)
465 strcatW(path
, FILE_bslash
);
467 /* if ScanDir succeeds, we have changed the directory */
468 if (FD31_ScanDir(hWnd
, path
))
469 return FALSE
; /* and path is not a valid file name */
471 /* if not, this must be a filename */
473 *pstr2
= 0; /* remove the wildcard added before */
475 if (pBeginFileName
!= NULL
)
477 /* strip off the pathname */
479 SetDlgItemTextW( hWnd
, edt1
, pBeginFileName
+ 1 );
481 lstrcpynW(tmpstr2
, pBeginFileName
+ 1, sizeof(tmpstr2
)/sizeof(WCHAR
) );
482 /* Should we MessageBox() if this fails? */
483 if (!FD31_ScanDir(hWnd
, path
))
487 strcpyW(path
, tmpstr2
);
490 SetDlgItemTextW( hWnd
, edt1
, path
);
494 /***********************************************************************
495 * FD31_Validate [internal]
496 * called on: click Ok button, Enter in edit, DoubleClick in file list
498 static LRESULT
FD31_Validate( PFD31_DATA lfs
, LPWSTR path
, UINT control
, INT itemIndex
,
502 HWND hWnd
= lfs
->hwnd
;
503 OPENFILENAMEW ofnsav
;
504 LPOPENFILENAMEW ofnW
= &lfs
->ofnW
;
505 WCHAR filename
[BUFFILE
];
507 ofnsav
= *ofnW
; /* for later restoring */
509 /* get current file name */
511 lstrcpynW(filename
, path
, sizeof(filename
)/sizeof(WCHAR
));
513 GetDlgItemTextW( hWnd
, edt1
, filename
, sizeof(filename
)/sizeof(WCHAR
));
515 TRACE("got filename = %s\n", debugstr_w(filename
));
516 /* if we did not click in file list to get there */
519 if (!FD31_TestPath( lfs
, filename
) )
522 FD31_UpdateResult(lfs
, filename
);
525 { /* called internally after a change in a combo */
528 FD31_CallWindowProc(lfs
, lfs
->lbselchstring
, control
,
529 MAKELONG(itemIndex
,CD_LBSELCHANGE
));
534 FD31_UpdateFileTitle(lfs
);
537 lRet
= (BOOL
)FD31_CallWindowProc(lfs
, lfs
->fileokstring
,
541 *ofnW
= ofnsav
; /* restore old state */
545 if ((ofnW
->Flags
& OFN_ALLOWMULTISELECT
) && (ofnW
->Flags
& OFN_EXPLORER
))
549 LPWSTR str
= (LPWSTR
)ofnW
->lpstrFile
;
550 LPWSTR ptr
= strrchrW(str
, '\\');
551 str
[lstrlenW(str
) + 1] = '\0';
558 /***********************************************************************
559 * FD31_DiskChange [internal]
560 * called when a new item is picked in the disk selection combo
562 static LRESULT
FD31_DiskChange( PFD31_DATA lfs
)
565 HWND hWnd
= lfs
->hwnd
;
567 WCHAR diskname
[BUFFILE
];
569 FD31_StripEditControl(hWnd
);
570 lRet
= SendDlgItemMessageW(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
573 pstr
= HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC
);
574 SendDlgItemMessageW(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
,
576 wsprintfW(diskname
, FILE_specc
, pstr
[2]);
577 HeapFree(GetProcessHeap(), 0, pstr
);
579 return FD31_Validate( lfs
, diskname
, cmb2
, lRet
, TRUE
);
582 /***********************************************************************
583 * FD31_FileTypeChange [internal]
584 * called when a new item is picked in the file type combo
586 static LRESULT
FD31_FileTypeChange( PFD31_DATA lfs
)
591 lRet
= SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETCURSEL
, 0, 0);
594 pstr
= (LPWSTR
)SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
595 TRACE("Selected filter : %s\n", debugstr_w(pstr
));
596 SetDlgItemTextW( lfs
->hwnd
, edt1
, pstr
);
598 return FD31_Validate( lfs
, NULL
, cmb1
, lRet
, TRUE
);
601 /***********************************************************************
602 * FD31_WMCommand [internal]
604 LRESULT
FD31_WMCommand(HWND hWnd
, LPARAM lParam
, UINT notification
,
605 UINT control
, PFD31_DATA lfs
)
609 case lst1
: /* file list */
610 FD31_StripEditControl(hWnd
);
611 if (notification
== LBN_DBLCLK
)
613 if (FD31_Validate( lfs
, NULL
, control
, 0, FALSE
))
614 EndDialog(hWnd
, TRUE
);
617 else if (notification
== LBN_SELCHANGE
)
618 return FD31_FileListSelect( lfs
);
621 case lst2
: /* directory list */
622 FD31_StripEditControl(hWnd
);
623 if (notification
== LBN_DBLCLK
)
624 return FD31_DirListDblClick( lfs
);
627 case cmb1
: /* file type drop list */
628 if (notification
== CBN_SELCHANGE
)
629 return FD31_FileTypeChange( lfs
);
638 case cmb2
: /* disk dropdown combo */
639 if (notification
== CBN_SELCHANGE
)
640 return FD31_DiskChange( lfs
);
644 TRACE("OK pressed\n");
645 if (FD31_Validate( lfs
, NULL
, control
, 0, FALSE
))
646 EndDialog(hWnd
, TRUE
);
650 EndDialog(hWnd
, FALSE
);
653 case IDABORT
: /* can be sent by the hook procedure */
654 EndDialog(hWnd
, TRUE
);
660 /************************************************************************
661 * FD31_MapStringPairsToW [internal]
662 * map string pairs to Unicode
664 static LPWSTR
FD31_MapStringPairsToW(LPCSTR strA
, UINT size
)
674 n
= s
+ 1 - strA
; /* Don't forget the other \0 */
675 if (n
< size
) n
= size
;
677 len
= MultiByteToWideChar( CP_ACP
, 0, strA
, n
, NULL
, 0 );
678 x
= HeapAlloc(GetProcessHeap(),0, len
* sizeof(WCHAR
));
679 MultiByteToWideChar( CP_ACP
, 0, strA
, n
, x
, len
);
684 /************************************************************************
685 * FD31_DupToW [internal]
686 * duplicates an Ansi string to unicode, with a buffer size
688 static LPWSTR
FD31_DupToW(LPCSTR str
, DWORD size
)
691 if (str
&& (size
> 0))
693 strW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
694 if (strW
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, strW
, size
);
699 /************************************************************************
700 * FD31_MapOfnStructA [internal]
701 * map a 32 bits Ansi structure to an Unicode one
703 void FD31_MapOfnStructA(LPOPENFILENAMEA ofnA
, LPOPENFILENAMEW ofnW
, BOOL open
)
705 UNICODE_STRING usBuffer
;
707 ofnW
->lStructSize
= sizeof(OPENFILENAMEW
);
708 ofnW
->hwndOwner
= ofnA
->hwndOwner
;
709 ofnW
->hInstance
= ofnA
->hInstance
;
710 if (ofnA
->lpstrFilter
)
711 ofnW
->lpstrFilter
= FD31_MapStringPairsToW(ofnA
->lpstrFilter
, 0);
713 if ((ofnA
->lpstrCustomFilter
) && (*(ofnA
->lpstrCustomFilter
)))
714 ofnW
->lpstrCustomFilter
= FD31_MapStringPairsToW(ofnA
->lpstrCustomFilter
, ofnA
->nMaxCustFilter
);
715 ofnW
->nMaxCustFilter
= ofnA
->nMaxCustFilter
;
716 ofnW
->nFilterIndex
= ofnA
->nFilterIndex
;
717 ofnW
->nMaxFile
= ofnA
->nMaxFile
;
718 ofnW
->lpstrFile
= FD31_DupToW(ofnA
->lpstrFile
, ofnW
->nMaxFile
);
719 ofnW
->nMaxFileTitle
= ofnA
->nMaxFileTitle
;
720 ofnW
->lpstrFileTitle
= FD31_DupToW(ofnA
->lpstrFileTitle
, ofnW
->nMaxFileTitle
);
721 if (ofnA
->lpstrInitialDir
)
723 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpstrInitialDir
);
724 ofnW
->lpstrInitialDir
= usBuffer
.Buffer
;
726 if (ofnA
->lpstrTitle
) {
727 RtlCreateUnicodeStringFromAsciiz (&usBuffer
, ofnA
->lpstrTitle
);
728 ofnW
->lpstrTitle
= usBuffer
.Buffer
;
732 LoadStringW(COMDLG32_hInstance
, open
? IDS_OPEN_FILE
: IDS_SAVE_AS
,
733 buf
, sizeof(buf
)/sizeof(WCHAR
));
734 len
= lstrlenW(buf
)+1;
735 ofnW
->lpstrTitle
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
736 memcpy((void*)ofnW
->lpstrTitle
, buf
, len
*sizeof(WCHAR
));
738 ofnW
->Flags
= ofnA
->Flags
;
739 ofnW
->nFileOffset
= ofnA
->nFileOffset
;
740 ofnW
->nFileExtension
= ofnA
->nFileExtension
;
741 ofnW
->lpstrDefExt
= FD31_DupToW(ofnA
->lpstrDefExt
, 3);
742 if ((ofnA
->Flags
& OFN_ENABLETEMPLATE
) && (ofnA
->lpTemplateName
))
744 if (HIWORD(ofnA
->lpTemplateName
))
746 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpTemplateName
);
747 ofnW
->lpTemplateName
= usBuffer
.Buffer
;
749 else /* numbered resource */
750 ofnW
->lpTemplateName
= (LPWSTR
) ofnA
->lpTemplateName
;
755 /************************************************************************
756 * FD31_FreeOfnW [internal]
757 * Undo all allocations done by FD31_MapOfnStructA
759 void FD31_FreeOfnW(LPOPENFILENAMEW ofnW
)
761 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrFilter
);
762 HeapFree(GetProcessHeap(), 0, ofnW
->lpstrCustomFilter
);
763 HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFile
);
764 HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFileTitle
);
765 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrInitialDir
);
766 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrTitle
);
767 if ((ofnW
->lpTemplateName
) && (HIWORD(ofnW
->lpTemplateName
)))
768 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpTemplateName
);
771 /************************************************************************
772 * FD31_DestroyPrivate [internal]
773 * destroys the private object
775 void FD31_DestroyPrivate(PFD31_DATA lfs
)
780 TRACE("destroying private allocation %p\n", lfs
);
781 lfs
->callbacks
->Destroy(lfs
);
782 HeapFree(GetProcessHeap(), 0, lfs
);
783 RemovePropA(hwnd
, FD31_OFN_PROP
);
786 /************************************************************************
787 * FD31_AllocPrivate [internal]
788 * allocate a private object to hold 32 bits Unicode
789 * structure that will be used throughtout the calls, while
790 * keeping available the original structures and a few variables
791 * On entry : type = dialog procedure type (16,32A,32W)
792 * dlgType = dialog type (open or save)
794 PFD31_DATA
FD31_AllocPrivate(LPARAM lParam
, UINT dlgType
,
795 PFD31_CALLBACKS callbacks
, DWORD data
)
797 PFD31_DATA lfs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FD31_DATA
));
799 TRACE("alloc private buf %p\n", lfs
);
800 if (!lfs
) return NULL
;
802 lfs
->lParam
= lParam
;
803 lfs
->open
= (dlgType
== OPEN_DIALOG
);
804 lfs
->callbacks
= callbacks
;
805 if (! lfs
->callbacks
->Init(lParam
, lfs
, data
))
807 FD31_DestroyPrivate(lfs
);
810 lfs
->lbselchstring
= RegisterWindowMessageA(LBSELCHSTRINGA
);
811 lfs
->fileokstring
= RegisterWindowMessageA(FILEOKSTRINGA
);
816 /***********************************************************************
817 * FD31_WMInitDialog [internal]
820 LONG
FD31_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
823 WCHAR tmpstr
[BUFFILE
];
824 LPWSTR pstr
, old_pstr
;
826 PFD31_DATA lfs
= (PFD31_DATA
) lParam
;
828 if (!lfs
) return FALSE
;
829 SetPropA(hWnd
, FD31_OFN_PROP
, (HANDLE
)lfs
);
833 TRACE("flags=%lx initialdir=%s\n", ofn
->Flags
, debugstr_w(ofn
->lpstrInitialDir
));
835 SetWindowTextW( hWnd
, ofn
->lpstrTitle
);
836 /* read custom filter information */
837 if (ofn
->lpstrCustomFilter
)
839 pstr
= ofn
->lpstrCustomFilter
;
841 TRACE("lpstrCustomFilter = %p\n", pstr
);
845 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
846 (LPARAM
)(ofn
->lpstrCustomFilter
) + n
);
847 n
+= lstrlenW(pstr
) + 1;
848 pstr
+= lstrlenW(pstr
) + 1;
849 TRACE("add str=%s associated to %s\n",
850 debugstr_w(old_pstr
), debugstr_w(pstr
));
851 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
852 n
+= lstrlenW(pstr
) + 1;
853 pstr
+= lstrlenW(pstr
) + 1;
856 /* read filter information */
857 if (ofn
->lpstrFilter
) {
858 pstr
= (LPWSTR
) ofn
->lpstrFilter
;
862 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
863 (LPARAM
)(ofn
->lpstrFilter
+ n
) );
864 n
+= lstrlenW(pstr
) + 1;
865 pstr
+= lstrlenW(pstr
) + 1;
866 TRACE("add str=%s associated to %s\n",
867 debugstr_w(old_pstr
), debugstr_w(pstr
));
868 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
869 n
+= lstrlenW(pstr
) + 1;
870 pstr
+= lstrlenW(pstr
) + 1;
873 /* set default filter */
874 if (ofn
->nFilterIndex
== 0 && ofn
->lpstrCustomFilter
== NULL
)
875 ofn
->nFilterIndex
= 1;
876 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETCURSEL
, ofn
->nFilterIndex
- 1, 0);
877 lstrcpynW(tmpstr
, FD31_GetFileType(ofn
->lpstrCustomFilter
,
878 (LPWSTR
)ofn
->lpstrFilter
, ofn
->nFilterIndex
- 1),BUFFILE
);
879 TRACE("nFilterIndex = %ld, SetText of edt1 to %s\n",
880 ofn
->nFilterIndex
, debugstr_w(tmpstr
));
881 SetDlgItemTextW( hWnd
, edt1
, tmpstr
);
884 DlgDirListComboBoxW(hWnd
, tmpstr
, cmb2
, 0, DDL_DRIVES
| DDL_EXCLUSIVE
);
885 /* read initial directory */
886 /* FIXME: Note that this is now very version-specific (See MSDN description of
887 * the OPENFILENAME structure). For example under 2000/XP any path in the
888 * lpstrFile overrides the lpstrInitialDir, but not under 95/98/ME
890 if (ofn
->lpstrInitialDir
!= NULL
)
893 lstrcpynW(tmpstr
, ofn
->lpstrInitialDir
, 511);
894 len
= lstrlenW(tmpstr
);
895 if (len
> 0 && tmpstr
[len
-1] != '\\' && tmpstr
[len
-1] != ':') {
902 if (!FD31_ScanDir(hWnd
, tmpstr
)) {
904 if (!FD31_ScanDir(hWnd
, tmpstr
))
905 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr
));
907 /* select current drive in combo 2, omit missing drives */
910 char str
[4] = "a:\\";
911 GetCurrentDirectoryA( sizeof(dir
), dir
);
912 for(i
= 0, n
= -1; i
< 26; i
++)
915 if (GetDriveTypeA(str
) > DRIVE_NO_ROOT_DIR
) n
++;
916 if (toupper(str
[0]) == toupper(dir
[0])) break;
919 SendDlgItemMessageW(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
920 if (!(ofn
->Flags
& OFN_SHOWHELP
))
921 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
922 if (ofn
->Flags
& OFN_HIDEREADONLY
)
923 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
925 return (BOOL
) FD31_CallWindowProc(lfs
, WM_INITDIALOG
, wParam
, lfs
->lParam
);
929 int FD31_GetFldrHeight(void)