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
)
589 WCHAR diskname
[BUFFILE
];
594 lRet
= SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETCURSEL
, 0, 0);
597 pstr
= (LPWSTR
)SendDlgItemMessageW(lfs
->hwnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
598 TRACE("Selected filter : %s\n", debugstr_w(pstr
));
599 SetDlgItemTextW( lfs
->hwnd
, edt1
, pstr
);
601 return FD31_Validate( lfs
, NULL
, cmb1
, lRet
, TRUE
);
604 /***********************************************************************
605 * FD31_WMCommand [internal]
607 LRESULT
FD31_WMCommand(HWND hWnd
, LPARAM lParam
, UINT notification
,
608 UINT control
, PFD31_DATA lfs
)
612 case lst1
: /* file list */
613 FD31_StripEditControl(hWnd
);
614 if (notification
== LBN_DBLCLK
)
616 if (FD31_Validate( lfs
, NULL
, control
, 0, FALSE
))
617 EndDialog(hWnd
, TRUE
);
620 else if (notification
== LBN_SELCHANGE
)
621 return FD31_FileListSelect( lfs
);
624 case lst2
: /* directory list */
625 FD31_StripEditControl(hWnd
);
626 if (notification
== LBN_DBLCLK
)
627 return FD31_DirListDblClick( lfs
);
630 case cmb1
: /* file type drop list */
631 if (notification
== CBN_SELCHANGE
)
632 return FD31_FileTypeChange( lfs
);
641 case cmb2
: /* disk dropdown combo */
642 if (notification
== CBN_SELCHANGE
)
643 return FD31_DiskChange( lfs
);
647 TRACE("OK pressed\n");
648 if (FD31_Validate( lfs
, NULL
, control
, 0, FALSE
))
649 EndDialog(hWnd
, TRUE
);
653 EndDialog(hWnd
, FALSE
);
656 case IDABORT
: /* can be sent by the hook procedure */
657 EndDialog(hWnd
, TRUE
);
663 /************************************************************************
664 * FD31_MapStringPairsToW [internal]
665 * map string pairs to Unicode
667 static LPWSTR
FD31_MapStringPairsToW(LPCSTR strA
, UINT size
)
677 n
= s
+ 1 - strA
; /* Don't forget the other \0 */
678 if (n
< size
) n
= size
;
680 len
= MultiByteToWideChar( CP_ACP
, 0, strA
, n
, NULL
, 0 );
681 x
= HeapAlloc(GetProcessHeap(),0, len
* sizeof(WCHAR
));
682 MultiByteToWideChar( CP_ACP
, 0, strA
, n
, x
, len
);
687 /************************************************************************
688 * FD31_DupToW [internal]
689 * duplicates an Ansi string to unicode, with a buffer size
691 static LPWSTR
FD31_DupToW(LPCSTR str
, DWORD size
)
694 if (str
&& (size
> 0))
696 strW
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
697 if (strW
) MultiByteToWideChar( CP_ACP
, 0, str
, -1, strW
, size
);
702 /************************************************************************
703 * FD31_MapOfnStructA [internal]
704 * map a 32 bits Ansi structure to an Unicode one
706 void FD31_MapOfnStructA(LPOPENFILENAMEA ofnA
, LPOPENFILENAMEW ofnW
, BOOL open
)
709 UNICODE_STRING usBuffer
;
711 ofnW
->lStructSize
= sizeof(OPENFILENAMEW
);
712 ofnW
->hwndOwner
= ofnA
->hwndOwner
;
713 ofnW
->hInstance
= ofnA
->hInstance
;
714 if (ofnA
->lpstrFilter
)
715 ofnW
->lpstrFilter
= FD31_MapStringPairsToW(ofnA
->lpstrFilter
, 0);
717 if ((ofnA
->lpstrCustomFilter
) && (*(ofnA
->lpstrCustomFilter
)))
718 ofnW
->lpstrCustomFilter
= FD31_MapStringPairsToW(ofnA
->lpstrCustomFilter
, ofnA
->nMaxCustFilter
);
719 ofnW
->nMaxCustFilter
= ofnA
->nMaxCustFilter
;
720 ofnW
->nFilterIndex
= ofnA
->nFilterIndex
;
721 ofnW
->nMaxFile
= ofnA
->nMaxFile
;
722 ofnW
->lpstrFile
= FD31_DupToW(ofnA
->lpstrFile
, ofnW
->nMaxFile
);
723 ofnW
->nMaxFileTitle
= ofnA
->nMaxFileTitle
;
724 ofnW
->lpstrFileTitle
= FD31_DupToW(ofnA
->lpstrFileTitle
, ofnW
->nMaxFileTitle
);
725 if (ofnA
->lpstrInitialDir
)
727 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpstrInitialDir
);
728 ofnW
->lpstrInitialDir
= usBuffer
.Buffer
;
730 if (ofnA
->lpstrTitle
)
731 str
= ofnA
->lpstrTitle
;
733 /* Allocates default title (FIXME : get it from resource) */
734 str
= open
? "Open File" : "Save as";
735 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,str
);
736 ofnW
->lpstrTitle
= usBuffer
.Buffer
;
737 ofnW
->Flags
= ofnA
->Flags
;
738 ofnW
->nFileOffset
= ofnA
->nFileOffset
;
739 ofnW
->nFileExtension
= ofnA
->nFileExtension
;
740 ofnW
->lpstrDefExt
= FD31_DupToW(ofnA
->lpstrDefExt
, 3);
741 if ((ofnA
->Flags
& OFN_ENABLETEMPLATE
) && (ofnA
->lpTemplateName
))
743 if (HIWORD(ofnA
->lpTemplateName
))
745 RtlCreateUnicodeStringFromAsciiz (&usBuffer
,ofnA
->lpTemplateName
);
746 ofnW
->lpTemplateName
= usBuffer
.Buffer
;
748 else /* numbered resource */
749 ofnW
->lpTemplateName
= (LPWSTR
) ofnA
->lpTemplateName
;
754 /************************************************************************
755 * FD31_FreeOfnW [internal]
756 * Undo all allocations done by FD31_MapOfnStructA
758 void FD31_FreeOfnW(LPOPENFILENAMEW ofnW
)
760 if (ofnW
->lpstrFilter
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrFilter
);
761 if (ofnW
->lpstrCustomFilter
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrCustomFilter
);
762 if (ofnW
->lpstrFile
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFile
);
763 if (ofnW
->lpstrFileTitle
) HeapFree(GetProcessHeap(), 0, ofnW
->lpstrFileTitle
);
764 if (ofnW
->lpstrInitialDir
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrInitialDir
);
765 if (ofnW
->lpstrTitle
) HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpstrTitle
);
766 if ((ofnW
->lpTemplateName
) && (HIWORD(ofnW
->lpTemplateName
)))
767 HeapFree(GetProcessHeap(), 0, (LPWSTR
) ofnW
->lpTemplateName
);
770 /************************************************************************
771 * FD31_DestroyPrivate [internal]
772 * destroys the private object
774 void FD31_DestroyPrivate(PFD31_DATA lfs
)
779 TRACE("destroying private allocation %p\n", lfs
);
780 lfs
->callbacks
->Destroy(lfs
);
781 HeapFree(GetProcessHeap(), 0, lfs
);
782 RemovePropA(hwnd
, FD31_OFN_PROP
);
785 /************************************************************************
786 * FD31_AllocPrivate [internal]
787 * allocate a private object to hold 32 bits Unicode
788 * structure that will be used throughtout the calls, while
789 * keeping available the original structures and a few variables
790 * On entry : type = dialog procedure type (16,32A,32W)
791 * dlgType = dialog type (open or save)
793 PFD31_DATA
FD31_AllocPrivate(LPARAM lParam
, UINT dlgType
,
794 PFD31_CALLBACKS callbacks
, DWORD data
)
796 PFD31_DATA lfs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FD31_DATA
));
798 TRACE("alloc private buf %p\n", lfs
);
799 if (!lfs
) return NULL
;
801 lfs
->lParam
= lParam
;
802 lfs
->open
= (dlgType
== OPEN_DIALOG
);
803 lfs
->callbacks
= callbacks
;
804 if (! lfs
->callbacks
->Init(lParam
, lfs
, data
))
806 FD31_DestroyPrivate(lfs
);
809 lfs
->lbselchstring
= RegisterWindowMessageA(LBSELCHSTRINGA
);
810 lfs
->fileokstring
= RegisterWindowMessageA(FILEOKSTRINGA
);
815 /***********************************************************************
816 * FD31_WMInitDialog [internal]
819 LONG
FD31_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
822 WCHAR tmpstr
[BUFFILE
];
823 LPWSTR pstr
, old_pstr
;
825 PFD31_DATA lfs
= (PFD31_DATA
) lParam
;
827 if (!lfs
) return FALSE
;
828 SetPropA(hWnd
, FD31_OFN_PROP
, (HANDLE
)lfs
);
832 TRACE("flags=%lx initialdir=%s\n", ofn
->Flags
, debugstr_w(ofn
->lpstrInitialDir
));
834 SetWindowTextW( hWnd
, ofn
->lpstrTitle
);
835 /* read custom filter information */
836 if (ofn
->lpstrCustomFilter
)
838 pstr
= ofn
->lpstrCustomFilter
;
840 TRACE("lpstrCustomFilter = %p\n", pstr
);
844 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
845 (LPARAM
)(ofn
->lpstrCustomFilter
) + n
);
846 n
+= lstrlenW(pstr
) + 1;
847 pstr
+= lstrlenW(pstr
) + 1;
848 TRACE("add str=%s associated to %s\n",
849 debugstr_w(old_pstr
), debugstr_w(pstr
));
850 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
851 n
+= lstrlenW(pstr
) + 1;
852 pstr
+= lstrlenW(pstr
) + 1;
855 /* read filter information */
856 if (ofn
->lpstrFilter
) {
857 pstr
= (LPWSTR
) ofn
->lpstrFilter
;
861 i
= SendDlgItemMessageW(hWnd
, cmb1
, CB_ADDSTRING
, 0,
862 (LPARAM
)(ofn
->lpstrFilter
+ n
) );
863 n
+= lstrlenW(pstr
) + 1;
864 pstr
+= lstrlenW(pstr
) + 1;
865 TRACE("add str=%s associated to %s\n",
866 debugstr_w(old_pstr
), debugstr_w(pstr
));
867 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
868 n
+= lstrlenW(pstr
) + 1;
869 pstr
+= lstrlenW(pstr
) + 1;
872 /* set default filter */
873 if (ofn
->nFilterIndex
== 0 && ofn
->lpstrCustomFilter
== NULL
)
874 ofn
->nFilterIndex
= 1;
875 SendDlgItemMessageW(hWnd
, cmb1
, CB_SETCURSEL
, ofn
->nFilterIndex
- 1, 0);
876 lstrcpynW(tmpstr
, FD31_GetFileType(ofn
->lpstrCustomFilter
,
877 (LPWSTR
)ofn
->lpstrFilter
, ofn
->nFilterIndex
- 1),BUFFILE
);
878 TRACE("nFilterIndex = %ld, SetText of edt1 to %s\n",
879 ofn
->nFilterIndex
, debugstr_w(tmpstr
));
880 SetDlgItemTextW( hWnd
, edt1
, tmpstr
);
883 DlgDirListComboBoxW(hWnd
, tmpstr
, cmb2
, 0, DDL_DRIVES
| DDL_EXCLUSIVE
);
884 /* read initial directory */
885 /* FIXME: Note that this is now very version-specific (See MSDN description of
886 * the OPENFILENAME structure). For example under 2000/XP any path in the
887 * lpstrFile overrides the lpstrInitialDir, but not under 95/98/ME
889 if (ofn
->lpstrInitialDir
!= NULL
)
892 lstrcpynW(tmpstr
, ofn
->lpstrInitialDir
, 511);
893 len
= lstrlenW(tmpstr
);
894 if (len
> 0 && tmpstr
[len
-1] != '\\' && tmpstr
[len
-1] != ':') {
901 if (!FD31_ScanDir(hWnd
, tmpstr
)) {
903 if (!FD31_ScanDir(hWnd
, tmpstr
))
904 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr
));
906 /* select current drive in combo 2, omit missing drives */
909 char str
[4] = "a:\\";
910 GetCurrentDirectoryA( sizeof(dir
), dir
);
911 for(i
= 0, n
= -1; i
< 26; i
++)
914 if (GetDriveTypeA(str
) > DRIVE_NO_ROOT_DIR
) n
++;
915 if (toupper(str
[0]) == toupper(dir
[0])) break;
918 SendDlgItemMessageW(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
919 if (!(ofn
->Flags
& OFN_SHOWHELP
))
920 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
921 if (ofn
->Flags
& OFN_HIDEREADONLY
)
922 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
924 return (BOOL
) FD31_CallWindowProc(lfs
, WM_INITDIALOG
, wParam
, lfs
->lParam
);
928 int FD31_GetFldrHeight(void)