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;
87 static char defaultopen[]="Open File";
88 static char defaultsave[]="Save as";
90 /***********************************************************************
91 * FileDlg_Init [internal]
93 static BOOL FileDlg_Init(void)
95 static BOOL initialized = 0;
98 HINSTANCE inst = GetModuleHandleA( "comdlg32.dll" );
101 ERR( "cannot get comdlg32.dll instance\n" );
104 hFolder = LoadImageA( inst, "FOLDER", IMAGE_ICON, 16, 16, LR_SHARED );
105 hFolder2 = LoadImageA( inst, "FOLDER2", IMAGE_ICON, 16, 16, LR_SHARED );
106 hFloppy = LoadImageA( inst, "FLOPPY", IMAGE_ICON, 16, 16, LR_SHARED );
107 hHDisk = LoadImageA( inst, "HDISK", IMAGE_ICON, 16, 16, LR_SHARED );
108 hCDRom = LoadImageA( inst, "CDROM", IMAGE_ICON, 16, 16, LR_SHARED );
109 hNet = LoadImageA( inst, "NETWORK", IMAGE_ICON, 16, 16, LR_SHARED );
110 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
111 hHDisk == 0 || hCDRom == 0 || hNet == 0)
113 ERR("Error loading icons !\n");
121 /***********************************************************************
122 * Get32BitsTemplate [internal]
124 * Get a template (or FALSE if failure) when 16 bits dialogs are used
125 * by a 32 bits application
128 BOOL Get32BitsTemplate(LFSPRIVATE lfs)
130 LPOPENFILENAMEW ofnW = lfs->ofnW;
133 if (ofnW->Flags & OFN_ENABLETEMPLATEHANDLE)
135 if (!(lfs->template = LockResource( ofnW->hInstance )))
137 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
141 else if (ofnW->Flags & OFN_ENABLETEMPLATE)
145 hResInfo = FindResourceA(lfs->ofnA->hInstance,
146 lfs->ofnA->lpTemplateName,
149 hResInfo = FindResourceW(ofnW->hInstance,
150 ofnW->lpTemplateName,
154 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
157 if (!(hDlgTmpl = LoadResource(ofnW->hInstance,
159 !(lfs->template = LockResource(hDlgTmpl)))
161 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
164 } else { /* get it from internal Wine resource */
166 if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
167 lfs->open? "OPEN_FILE":"SAVE_FILE", (LPSTR)RT_DIALOG)))
169 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
172 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
173 !(lfs->template = LockResource( hDlgTmpl )))
175 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
182 /***********************************************************************
183 * Get16BitsTemplate [internal]
185 * Get a template (FALSE if failure) when 16 bits dialogs are used
186 * by a 16 bits application
189 BOOL Get16BitsTemplate(LFSPRIVATE lfs)
191 LPOPENFILENAME16 ofn16 = lfs->ofn16;
193 HGLOBAL16 hGlobal16 = 0;
195 if (ofn16->Flags & OFN_ENABLETEMPLATEHANDLE)
196 lfs->hDlgTmpl16 = ofn16->hInstance;
197 else if (ofn16->Flags & OFN_ENABLETEMPLATE)
200 if (!(hResInfo = FindResource16(ofn16->hInstance,
201 MapSL(ofn16->lpTemplateName),
204 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
207 if (!(lfs->hDlgTmpl16 = LoadResource16( ofn16->hInstance, hResInfo )))
209 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
212 lfs->hResource16 = lfs->hDlgTmpl16;
215 { /* get resource from (32 bits) own Wine resource; convert it to 16 */
221 if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
222 lfs->open ? "OPEN_FILE":"SAVE_FILE", (LPSTR)RT_DIALOG)))
224 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
227 if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) ||
228 !(template32 = LockResource( hDlgTmpl32 )))
230 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
233 size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo);
234 hGlobal16 = GlobalAlloc16(0, size);
237 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
238 ERR("alloc failure for %ld bytes\n", size);
241 template = GlobalLock16(hGlobal16);
244 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
245 ERR("global lock failure for %x handle\n", hGlobal16);
246 GlobalFree16(hGlobal16);
249 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
250 lfs->hDlgTmpl16 = hGlobal16;
251 lfs->hGlobal16 = hGlobal16;
256 /***********************************************************************
257 * FILEDLG_StripEditControl [internal]
258 * Strip pathnames off the contents of the edit control.
260 static void FILEDLG_StripEditControl(HWND hwnd)
262 WCHAR temp[BUFFILE], *cp;
264 GetDlgItemTextW( hwnd, edt1, temp, sizeof(temp)/sizeof(WCHAR));
265 cp = strrchrW(temp, '\\');
269 cp = strrchrW(temp, ':');
273 /* FIXME: shouldn't we do something with the result here? ;-) */
276 /***********************************************************************
277 * FILEDLG_CallWindowProc [internal]
279 * Call the appropriate hook
281 static BOOL FILEDLG_CallWindowProc(LFSPRIVATE lfs, UINT wMsg, WPARAM wParam,
286 return (BOOL) CallWindowProcA(
287 (WNDPROC)lfs->ofnA->lpfnHook, lfs->hwnd,
288 wMsg, wParam, lParam);
293 return (BOOL) CallWindowProcW(
294 (WNDPROC)lfs->ofnW->lpfnHook, lfs->hwnd,
295 wMsg, wParam, lParam);
300 /***********************************************************************
301 * FILEDLG_ScanDir [internal]
303 static BOOL FILEDLG_ScanDir(HWND hWnd, LPWSTR newPath)
305 WCHAR buffer[BUFFILE];
308 HCURSOR hCursorWait, oldCursor;
310 TRACE("Trying to change to %s\n", debugstr_w(newPath));
311 if ( !SetCurrentDirectoryW( newPath ))
313 lstrcpynW(buffer, newPath, sizeof(buffer)/sizeof(WCHAR));
315 /* get the list of spec files */
316 GetDlgItemTextW(hWnd, edt1, buffer, sizeof(buffer)/sizeof(WCHAR));
318 hCursorWait = LoadCursorA(0, (LPSTR)IDC_WAIT);
319 oldCursor = SetCursor(hCursorWait);
322 if ((hdlg = GetDlgItem(hWnd, lst1)) != 0) {
323 WCHAR* scptr; /* ptr on semi-colon */
324 WCHAR* filter = buffer;
326 TRACE("Using filter %s\n", debugstr_w(filter));
327 SendMessageW(hdlg, LB_RESETCONTENT, 0, 0);
329 scptr = strchrW(filter, ';');
330 if (scptr) *scptr = 0;
331 while (*filter == ' ') filter++;
332 TRACE("Using file spec %s\n", debugstr_w(filter));
333 if (SendMessageW(hdlg, LB_DIR, 0, (LPARAM)filter) == LB_ERR)
335 if (scptr) *scptr = ';';
336 filter = (scptr) ? (scptr + 1) : 0;
340 /* list of directories */
341 strcpyW(buffer, FILE_star);
343 if ((hdlgDir = GetDlgItem(hWnd, lst2)) != 0) {
344 lRet = DlgDirListW(hWnd, buffer, lst2, stc1, DDL_EXCLUSIVE | DDL_DIRECTORY);
346 SetCursor(oldCursor);
350 /***********************************************************************
351 * FILEDLG_GetFileType [internal]
354 static LPWSTR FILEDLG_GetFileType(LPWSTR cfptr, LPWSTR fptr, WORD index)
359 for ( ;(n = lstrlenW(cfptr)) != 0; i++)
364 cfptr += lstrlenW(cfptr) + 1;
367 for ( ;(n = lstrlenW(fptr)) != 0; i++)
372 fptr += lstrlenW(fptr) + 1;
374 return (LPWSTR) FILE_star; /* FIXME */
377 /***********************************************************************
378 * FILEDLG_WMDrawItem [internal]
380 static LONG FILEDLG_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam,
381 int savedlg, LPDRAWITEMSTRUCT lpdis)
385 COLORREF oldText = 0, oldBk = 0;
387 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
389 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC))) return FALSE;
390 SendMessageW(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
393 if ((lpdis->itemState & ODS_SELECTED) && !savedlg)
395 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
396 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
399 SetTextColor(lpdis->hDC,GetSysColor(COLOR_GRAYTEXT) );
401 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + 1,
402 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
403 &(lpdis->rcItem), str, lstrlenW(str), NULL);
405 if (lpdis->itemState & ODS_SELECTED)
406 DrawFocusRect( lpdis->hDC, &(lpdis->rcItem) );
408 if ((lpdis->itemState & ODS_SELECTED) && !savedlg)
410 SetBkColor( lpdis->hDC, oldBk );
411 SetTextColor( lpdis->hDC, oldText );
413 HeapFree(GetProcessHeap(), 0, str);
417 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
419 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
421 SendMessageW(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
424 if (lpdis->itemState & ODS_SELECTED)
426 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
427 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
429 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + fldrWidth,
430 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
431 &(lpdis->rcItem), str, lstrlenW(str), NULL);
433 if (lpdis->itemState & ODS_SELECTED)
434 DrawFocusRect( lpdis->hDC, &(lpdis->rcItem) );
436 if (lpdis->itemState & ODS_SELECTED)
438 SetBkColor( lpdis->hDC, oldBk );
439 SetTextColor( lpdis->hDC, oldText );
441 DrawIcon(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hFolder);
442 HeapFree(GetProcessHeap(), 0, str);
445 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
448 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
450 SendMessageW(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
452 root[0] += str[2] - 'a';
453 switch(GetDriveTypeA(root))
455 case DRIVE_REMOVABLE: hIcon = hFloppy; break;
456 case DRIVE_CDROM: hIcon = hCDRom; break;
457 case DRIVE_REMOTE: hIcon = hNet; break;
459 default: hIcon = hHDisk; break;
461 if (lpdis->itemState & ODS_SELECTED)
463 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
464 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
466 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + fldrWidth,
467 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
468 &(lpdis->rcItem), str, lstrlenW(str), NULL);
470 if (lpdis->itemState & ODS_SELECTED)
472 SetBkColor( lpdis->hDC, oldBk );
473 SetTextColor( lpdis->hDC, oldText );
475 DrawIcon(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hIcon);
476 HeapFree(GetProcessHeap(), 0, str);
482 /***********************************************************************
483 * FILEDLG_UpdateResult [internal]
484 * update the displayed file name (with path)
486 void FILEDLG_UpdateResult(LFSPRIVATE lfs, WCHAR *tmpstr)
489 LPOPENFILENAMEW ofnW = lfs->ofnW;
490 WCHAR tmpstr2[BUFFILE];
493 TRACE("%s\n", debugstr_w(tmpstr));
494 if(ofnW->Flags & OFN_NOVALIDATE)
497 GetCurrentDirectoryW(BUFFILE, tmpstr2);
498 lenstr2 = strlenW(tmpstr2);
500 tmpstr2[lenstr2++]='\\';
501 lstrcpynW(tmpstr2+lenstr2, tmpstr, BUFFILE-lenstr2);
503 lstrcpynW(ofnW->lpstrFile, tmpstr2, ofnW->nMaxFile);
504 if((bs = strrchrW(tmpstr2, '\\')) != NULL)
505 ofnW->nFileOffset = bs - tmpstr2 +1;
507 ofnW->nFileOffset = 0;
508 ofnW->nFileExtension = 0;
509 while(tmpstr2[ofnW->nFileExtension] != '.' && tmpstr2[ofnW->nFileExtension] != '\0')
510 ofnW->nFileExtension++;
511 if (tmpstr2[ofnW->nFileExtension] == '\0')
512 ofnW->nFileExtension = 0;
514 ofnW->nFileExtension++;
515 /* update the real client structures if any */
517 { /* we have to convert to short (8.3) path */
518 char tmp[1024]; /* MAX_PATHNAME_LEN */
519 LPOPENFILENAME16 ofn16 = lfs->ofn16;
520 char *dest = MapSL(ofn16->lpstrFile);
522 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1,
523 tmp, sizeof(tmp), NULL, NULL ))
524 tmp[sizeof(tmp)-1] = 0;
525 GetShortPathNameA(tmp, dest, ofn16->nMaxFile);
527 /* the same procedure as every year... */
528 if((bs16 = strrchr(dest, '\\')) != NULL)
529 ofn16->nFileOffset = bs16 - dest +1;
531 ofn16->nFileOffset = 0;
532 ofn16->nFileExtension = 0;
533 while(dest[ofn16->nFileExtension] != '.' && dest[ofn16->nFileExtension] != '\0')
534 ofn16->nFileExtension++;
535 if (dest[ofn16->nFileExtension] == '\0')
536 ofn16->nFileExtension = 0;
538 ofn16->nFileExtension++;
542 if (ofnW->nMaxFile &&
543 !WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1,
544 lfs->ofnA->lpstrFile, ofnW->nMaxFile, NULL, NULL ))
545 lfs->ofnA->lpstrFile[ofnW->nMaxFile-1] = 0;
546 lfs->ofnA->nFileOffset = ofnW->nFileOffset;
547 lfs->ofnA->nFileExtension = ofnW->nFileExtension;
551 /***********************************************************************
552 * FILEDLG_UpdateFileTitle [internal]
553 * update the displayed file name (without path)
555 void FILEDLG_UpdateFileTitle(LFSPRIVATE lfs)
558 LPOPENFILENAMEW ofnW = lfs->ofnW;
559 if (ofnW->lpstrFileTitle != NULL)
561 lRet = SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL, 0, 0);
562 SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETTEXT, lRet,
563 (LPARAM)ofnW->lpstrFileTitle );
566 char *dest = MapSL(lfs->ofn16->lpstrFileTitle);
567 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1,
568 dest, ofnW->nMaxFileTitle, NULL, NULL ))
569 dest[ofnW->nMaxFileTitle-1] = 0;
573 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1,
574 lfs->ofnA->lpstrFileTitle, ofnW->nMaxFileTitle, NULL, NULL ))
575 lfs->ofnA->lpstrFileTitle[ofnW->nMaxFileTitle-1] = 0;
580 /***********************************************************************
581 * FILEDLG_DirListDblClick [internal]
583 static LRESULT FILEDLG_DirListDblClick( LFSPRIVATE lfs )
586 HWND hWnd = lfs->hwnd;
588 WCHAR tmpstr[BUFFILE];
590 /* get the raw string (with brackets) */
591 lRet = SendDlgItemMessageW(hWnd, lst2, LB_GETCURSEL, 0, 0);
592 if (lRet == LB_ERR) return TRUE;
593 pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
594 SendDlgItemMessageW(hWnd, lst2, LB_GETTEXT, lRet,
596 strcpyW( tmpstr, pstr );
597 HeapFree(GetProcessHeap(), 0, pstr);
598 /* get the selected directory in tmpstr */
599 if (tmpstr[0] == '[')
601 tmpstr[lstrlenW(tmpstr) - 1] = 0;
602 strcpyW(tmpstr,tmpstr+1);
604 strcatW(tmpstr, FILE_bslash);
606 FILEDLG_ScanDir(hWnd, tmpstr);
610 if (FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, lst2,
611 MAKELONG(lRet,CD_LBSELCHANGE)))
617 /***********************************************************************
618 * FILEDLG_FileListSelect [internal]
619 * called when a new item is picked in the file list
621 static LRESULT FILEDLG_FileListSelect( LFSPRIVATE lfs )
624 HWND hWnd = lfs->hwnd;
627 lRet = SendDlgItemMessageW(hWnd, lst1, LB_GETCURSEL16, 0, 0);
631 /* set the edit control to the choosen file */
632 if ((pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
634 SendDlgItemMessageW(hWnd, lst1, LB_GETTEXT, lRet,
636 SetDlgItemTextW( hWnd, edt1, pstr );
637 HeapFree(GetProcessHeap(), 0, pstr);
641 FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, lst1,
642 MAKELONG(lRet,CD_LBSELCHANGE));
644 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD,
649 /***********************************************************************
650 * FILEDLG_TestPath [internal]
651 * before accepting the file name, test if it includes wild cards
652 * tries to scan the directory and returns TRUE if no error.
654 static LRESULT FILEDLG_TestPath( LFSPRIVATE lfs, LPWSTR path )
656 HWND hWnd = lfs->hwnd;
657 LPWSTR pBeginFileName, pstr2;
658 WCHAR tmpstr2[BUFFILE];
660 pBeginFileName = strrchrW(path, '\\');
661 if (pBeginFileName == NULL)
662 pBeginFileName = strrchrW(path, ':');
664 if (strchrW(path,'*') != NULL || strchrW(path,'?') != NULL)
666 /* edit control contains wildcards */
667 if (pBeginFileName != NULL)
669 lstrcpynW(tmpstr2, pBeginFileName + 1, BUFFILE);
670 *(pBeginFileName + 1) = 0;
674 strcpyW(tmpstr2, path);
675 if(!(lfs->ofnW->Flags & OFN_NOVALIDATE))
679 TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path), debugstr_w(tmpstr2));
680 SetDlgItemTextW( hWnd, edt1, tmpstr2 );
681 FILEDLG_ScanDir(hWnd, path);
682 return (lfs->ofnW->Flags & OFN_NOVALIDATE) ? TRUE : FALSE;
685 /* no wildcards, we might have a directory or a filename */
686 /* try appending a wildcard and reading the directory */
688 pstr2 = path + lstrlenW(path);
689 if (pBeginFileName == NULL || *(pBeginFileName + 1) != 0)
690 strcatW(path, FILE_bslash);
692 /* if ScanDir succeeds, we have changed the directory */
693 if (FILEDLG_ScanDir(hWnd, path))
694 return FALSE; /* and path is not a valid file name */
696 /* if not, this must be a filename */
698 *pstr2 = 0; /* remove the wildcard added before */
700 if (pBeginFileName != NULL)
702 /* strip off the pathname */
704 SetDlgItemTextW( hWnd, edt1, pBeginFileName + 1 );
706 lstrcpynW(tmpstr2, pBeginFileName + 1, sizeof(tmpstr2)/sizeof(WCHAR) );
707 /* Should we MessageBox() if this fails? */
708 if (!FILEDLG_ScanDir(hWnd, path))
712 strcpyW(path, tmpstr2);
715 SetDlgItemTextW( hWnd, edt1, path );
719 /***********************************************************************
720 * FILEDLG_Validate [internal]
721 * called on: click Ok button, Enter in edit, DoubleClick in file list
723 static LRESULT FILEDLG_Validate( LFSPRIVATE lfs, LPWSTR path, UINT control, INT itemIndex,
727 HWND hWnd = lfs->hwnd;
728 OPENFILENAMEW ofnsav;
729 LPOPENFILENAMEW ofnW = lfs->ofnW;
730 WCHAR filename[BUFFILE];
732 ofnsav = *ofnW; /* for later restoring */
734 /* get current file name */
736 lstrcpynW(filename, path, sizeof(filename)/sizeof(WCHAR));
738 GetDlgItemTextW( hWnd, edt1, filename, sizeof(filename)/sizeof(WCHAR));
740 TRACE("got filename = %s\n", debugstr_w(filename));
741 /* if we did not click in file list to get there */
744 if (!FILEDLG_TestPath( lfs, filename) )
747 FILEDLG_UpdateResult(lfs, filename);
750 { /* called internally after a change in a combo */
753 FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, control,
754 MAKELONG(itemIndex,CD_LBSELCHANGE));
759 FILEDLG_UpdateFileTitle(lfs);
762 lRet = (BOOL)FILEDLG_CallWindowProc(lfs, lfs->fileokstring,
766 *ofnW = ofnsav; /* restore old state */
770 if ((ofnW->Flags & OFN_ALLOWMULTISELECT) && (ofnW->Flags & OFN_EXPLORER))
774 LPWSTR str = (LPWSTR)ofnW->lpstrFile;
775 LPWSTR ptr = strrchrW(str, '\\');
776 str[lstrlenW(str) + 1] = '\0';
783 /***********************************************************************
784 * FILEDLG_DiskChange [internal]
785 * called when a new item is picked in the disk selection combo
787 static LRESULT FILEDLG_DiskChange( LFSPRIVATE lfs )
790 HWND hWnd = lfs->hwnd;
792 WCHAR diskname[BUFFILE];
794 FILEDLG_StripEditControl(hWnd);
795 lRet = SendDlgItemMessageW(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
798 pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
799 SendDlgItemMessageW(hWnd, cmb2, CB_GETLBTEXT, lRet,
801 wsprintfW(diskname, FILE_specc, pstr[2]);
802 HeapFree(GetProcessHeap(), 0, pstr);
804 return FILEDLG_Validate( lfs, diskname, cmb2, lRet, TRUE );
807 /***********************************************************************
808 * FILEDLG_FileTypeChange [internal]
809 * called when a new item is picked in the file type combo
811 static LRESULT FILEDLG_FileTypeChange( LFSPRIVATE lfs )
814 WCHAR diskname[BUFFILE];
819 lRet = SendDlgItemMessageW(lfs->hwnd, cmb1, CB_GETCURSEL, 0, 0);
822 pstr = (LPWSTR)SendDlgItemMessageW(lfs->hwnd, cmb1, CB_GETITEMDATA, lRet, 0);
823 TRACE("Selected filter : %s\n", debugstr_w(pstr));
824 SetDlgItemTextW( lfs->hwnd, edt1, pstr );
826 return FILEDLG_Validate( lfs, NULL, cmb1, lRet, TRUE );
829 /***********************************************************************
830 * FILEDLG_WMCommand [internal]
832 static LRESULT FILEDLG_WMCommand(HWND hWnd, LPARAM lParam, UINT notification,
833 UINT control, LFSPRIVATE lfs )
837 case lst1: /* file list */
838 FILEDLG_StripEditControl(hWnd);
839 if (notification == LBN_DBLCLK)
841 if (FILEDLG_Validate( lfs, NULL, control, 0, FALSE ))
842 EndDialog(hWnd, TRUE);
845 else if (notification == LBN_SELCHANGE)
846 return FILEDLG_FileListSelect( lfs );
849 case lst2: /* directory list */
850 FILEDLG_StripEditControl(hWnd);
851 if (notification == LBN_DBLCLK)
852 return FILEDLG_DirListDblClick( lfs );
855 case cmb1: /* file type drop list */
856 if (notification == CBN_SELCHANGE)
857 return FILEDLG_FileTypeChange( lfs );
866 case cmb2: /* disk dropdown combo */
867 if (notification == CBN_SELCHANGE)
868 return FILEDLG_DiskChange( lfs );
872 TRACE("OK pressed\n");
873 if (FILEDLG_Validate( lfs, NULL, control, 0, FALSE ))
874 EndDialog(hWnd, TRUE);
878 EndDialog(hWnd, FALSE);
881 case IDABORT: /* can be sent by the hook procedure */
882 EndDialog(hWnd, TRUE);
888 /***********************************************************************
889 * FILEDLG_MapDrawItemStruct [internal]
890 * map a 16 bits drawitem struct to 32
892 static void FILEDLG_MapDrawItemStruct(LPDRAWITEMSTRUCT16 lpdis16, LPDRAWITEMSTRUCT lpdis)
894 lpdis->CtlType = lpdis16->CtlType;
895 lpdis->CtlID = lpdis16->CtlID;
896 lpdis->itemID = lpdis16->itemID;
897 lpdis->itemAction = lpdis16->itemAction;
898 lpdis->itemState = lpdis16->itemState;
899 lpdis->hwndItem = HWND_32(lpdis16->hwndItem);
900 lpdis->hDC = HDC_32(lpdis16->hDC);
901 lpdis->rcItem.right = lpdis16->rcItem.right;
902 lpdis->rcItem.left = lpdis16->rcItem.left;
903 lpdis->rcItem.top = lpdis16->rcItem.top;
904 lpdis->rcItem.bottom = lpdis16->rcItem.bottom;
905 lpdis->itemData = lpdis16->itemData;
908 /************************************************************************
909 * FILEDLG_MapStringPairsToW [internal]
910 * map string pairs to Unicode
912 static LPWSTR FILEDLG_MapStringPairsToW(LPCSTR strA, UINT size)
922 n = s + 1 - strA; /* Don't forget the other \0 */
923 if (n < size) n = size;
925 len = MultiByteToWideChar( CP_ACP, 0, strA, n, NULL, 0 );
926 x = HeapAlloc(GetProcessHeap(),0, len * sizeof(WCHAR));
927 MultiByteToWideChar( CP_ACP, 0, strA, n, x, len );
932 /************************************************************************
933 * FILEDLG_DupToW [internal]
934 * duplicates an Ansi string to unicode, with a buffer size
936 LPWSTR FILEDLG_DupToW(LPCSTR str, DWORD size)
939 if (str && (size > 0))
941 strW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
942 if (strW) MultiByteToWideChar( CP_ACP, 0, str, -1, strW, size );
948 /************************************************************************
949 * FILEDLG_MapOfnStructA [internal]
950 * map a 32 bits Ansi structure to an Unicode one
952 void FILEDLG_MapOfnStructA(LPOPENFILENAMEA ofnA, LPOPENFILENAMEW ofnW, BOOL open)
955 UNICODE_STRING usBuffer;
957 ofnW->lStructSize = sizeof(OPENFILENAMEW);
958 ofnW->hwndOwner = ofnA->hwndOwner;
959 ofnW->hInstance = ofnA->hInstance;
960 if (ofnA->lpstrFilter)
961 ofnW->lpstrFilter = FILEDLG_MapStringPairsToW(ofnA->lpstrFilter, 0);
963 if ((ofnA->lpstrCustomFilter) && (*(ofnA->lpstrCustomFilter)))
964 ofnW->lpstrCustomFilter = FILEDLG_MapStringPairsToW(ofnA->lpstrCustomFilter, ofnA->nMaxCustFilter);
965 ofnW->nMaxCustFilter = ofnA->nMaxCustFilter;
966 ofnW->nFilterIndex = ofnA->nFilterIndex;
967 ofnW->nMaxFile = ofnA->nMaxFile;
968 ofnW->lpstrFile = FILEDLG_DupToW(ofnA->lpstrFile, ofnW->nMaxFile);
969 ofnW->nMaxFileTitle = ofnA->nMaxFileTitle;
970 ofnW->lpstrFileTitle = FILEDLG_DupToW(ofnA->lpstrFileTitle, ofnW->nMaxFileTitle);
971 if (ofnA->lpstrInitialDir)
973 RtlCreateUnicodeStringFromAsciiz (&usBuffer,ofnA->lpstrInitialDir);
974 ofnW->lpstrInitialDir = usBuffer.Buffer;
976 if (ofnA->lpstrTitle)
977 str = ofnA->lpstrTitle;
979 /* Allocates default title (FIXME : get it from resource) */
980 str = open ? defaultopen:defaultsave;
981 RtlCreateUnicodeStringFromAsciiz (&usBuffer,ofnA->lpstrTitle);
982 ofnW->lpstrTitle = usBuffer.Buffer;
983 ofnW->Flags = ofnA->Flags;
984 ofnW->nFileOffset = ofnA->nFileOffset;
985 ofnW->nFileExtension = ofnA->nFileExtension;
986 ofnW->lpstrDefExt = FILEDLG_DupToW(ofnA->lpstrDefExt, 3);
987 if ((ofnA->Flags & OFN_ENABLETEMPLATE) && (ofnA->lpTemplateName))
989 if (HIWORD(ofnA->lpTemplateName))
991 RtlCreateUnicodeStringFromAsciiz (&usBuffer,ofnA->lpTemplateName);
992 ofnW->lpTemplateName = usBuffer.Buffer;
994 else /* numbered resource */
995 ofnW->lpTemplateName = (LPWSTR) ofnA->lpTemplateName;
999 /************************************************************************
1000 * FILEDLG_MapOfnStruct16 [internal]
1001 * map a 16 bits structure to an Unicode one
1003 void FILEDLG_MapOfnStruct16(LPOPENFILENAME16 ofn16, LPOPENFILENAMEW ofnW, BOOL open)
1006 /* first convert to linear pointers */
1007 memset(&ofnA, 0, sizeof(OPENFILENAMEA));
1008 ofnA.lStructSize = sizeof(OPENFILENAMEA);
1009 ofnA.hwndOwner = HWND_32(ofn16->hwndOwner);
1010 ofnA.hInstance = HINSTANCE_32(ofn16->hInstance);
1011 if (ofn16->lpstrFilter)
1012 ofnA.lpstrFilter = MapSL(ofn16->lpstrFilter);
1013 if (ofn16->lpstrCustomFilter)
1014 ofnA.lpstrCustomFilter = MapSL(ofn16->lpstrCustomFilter);
1015 ofnA.nMaxCustFilter = ofn16->nMaxCustFilter;
1016 ofnA.nFilterIndex = ofn16->nFilterIndex;
1017 ofnA.lpstrFile = MapSL(ofn16->lpstrFile);
1018 ofnA.nMaxFile = ofn16->nMaxFile;
1019 ofnA.lpstrFileTitle = MapSL(ofn16->lpstrFileTitle);
1020 ofnA.nMaxFileTitle = ofn16->nMaxFileTitle;
1021 ofnA.lpstrInitialDir = MapSL(ofn16->lpstrInitialDir);
1022 ofnA.lpstrTitle = MapSL(ofn16->lpstrTitle);
1023 ofnA.Flags = ofn16->Flags;
1024 ofnA.nFileOffset = ofn16->nFileOffset;
1025 ofnA.nFileExtension = ofn16->nFileExtension;
1026 ofnA.lpstrDefExt = MapSL(ofn16->lpstrDefExt);
1027 if (HIWORD(ofn16->lpTemplateName))
1028 ofnA.lpTemplateName = MapSL(ofn16->lpTemplateName);
1030 ofnA.lpTemplateName = (LPSTR) ofn16->lpTemplateName; /* ressource number */
1031 /* now calls the 32 bits Ansi to Unicode version to complete the job */
1032 FILEDLG_MapOfnStructA(&ofnA, ofnW, open);
1035 /************************************************************************
1036 * FILEDLG_DestroyPrivate [internal]
1037 * destroys the private object
1039 static void FILEDLG_DestroyPrivate(LFSPRIVATE lfs)
1044 /* free resources for a 16 bits dialog */
1045 if (lfs->hResource16) FreeResource16(lfs->hResource16);
1048 GlobalUnlock16(lfs->hGlobal16);
1049 GlobalFree16(lfs->hGlobal16);
1051 /* if ofnW has been allocated, have to free everything in it */
1052 if (lfs->ofn16 || lfs->ofnA)
1054 LPOPENFILENAMEW ofnW = lfs->ofnW;
1055 if (ofnW->lpstrFilter) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrFilter);
1056 if (ofnW->lpstrCustomFilter) HeapFree(GetProcessHeap(), 0, ofnW->lpstrCustomFilter);
1057 if (ofnW->lpstrFile) HeapFree(GetProcessHeap(), 0, ofnW->lpstrFile);
1058 if (ofnW->lpstrFileTitle) HeapFree(GetProcessHeap(), 0, ofnW->lpstrFileTitle);
1059 if (ofnW->lpstrInitialDir) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrInitialDir);
1060 if (ofnW->lpstrTitle) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrTitle);
1061 if ((ofnW->lpTemplateName) && (HIWORD(ofnW->lpTemplateName)))
1062 HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpTemplateName);
1063 HeapFree(GetProcessHeap(), 0, ofnW);
1065 TRACE("destroying private allocation %p\n", lfs);
1066 HeapFree(GetProcessHeap(), 0, lfs);
1067 RemovePropA(hwnd, OFN_PROP);
1070 /************************************************************************
1071 * FILEDLG_AllocPrivate [internal]
1072 * allocate a private object to hold 32 bits Unicode
1073 * structure that will be used throughtout the calls, while
1074 * keeping available the original structures and a few variables
1075 * On entry : type = dialog procedure type (16,32A,32W)
1076 * dlgType = dialog type (open or save)
1078 static LFSPRIVATE FILEDLG_AllocPrivate(LPARAM lParam, int type, UINT dlgType)
1080 LFSPRIVATE lfs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct FSPRIVATE));
1082 TRACE("alloc private buf %p\n", lfs);
1083 if (!lfs) return NULL;
1085 lfs->lParam = lParam;
1086 if (dlgType == OPEN_DIALOG)
1090 lfs->lbselchstring = RegisterWindowMessageA(LBSELCHSTRINGA);
1091 lfs->fileokstring = RegisterWindowMessageA(FILEOKSTRINGA);
1095 lfs->ofn16 = MapSL(lParam);
1096 if (lfs->ofn16->Flags & OFN_ENABLEHOOK)
1097 if (lfs->ofn16->lpfnHook)
1103 lfs->ofnA = (LPOPENFILENAMEA) lParam;
1104 if (lfs->ofnA->Flags & OFN_ENABLEHOOK)
1105 if (lfs->ofnA->lpfnHook)
1110 lfs->ofnW = (LPOPENFILENAMEW) lParam;
1111 if (lfs->ofnW->Flags & OFN_ENABLEHOOK)
1112 if (lfs->ofnW->lpfnHook)
1118 { /* this structure is needed internally, so create it */
1119 lfs->ofnW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OPENFILENAMEW));
1123 FILEDLG_MapOfnStruct16(lfs->ofn16, lfs->ofnW, lfs->open);
1125 FILEDLG_MapOfnStructA(lfs->ofnA, lfs->ofnW, lfs->open);
1132 if (!Get16BitsTemplate(lfs)) ret = NULL;
1135 if (!Get32BitsTemplate(lfs)) ret = NULL;
1136 if (!ret) FILEDLG_DestroyPrivate(lfs);
1140 /***********************************************************************
1141 * FILEDLG_CallWindowProc16 [internal]
1143 * Call the appropriate hook
1145 static BOOL FILEDLG_CallWindowProc16(LFSPRIVATE lfs, UINT wMsg, WPARAM wParam,
1150 return (BOOL16) CallWindowProc16(
1151 (WNDPROC16)lfs->ofn16->lpfnHook, HWND_16(lfs->hwnd),
1152 (UINT16)wMsg, (WPARAM16)wParam, lParam);
1157 /***********************************************************************
1158 * FILEDLG_WMInitDialog16 [internal]
1159 * The is a duplicate of the 32bit FILEDLG_WMInitDialog function
1160 * The only differnce is that it calls FILEDLG_CallWindowProc16
1161 * for a 16 bit Window Proc.
1164 static LONG FILEDLG_WMInitDialog16(HWND hWnd, WPARAM wParam, LPARAM lParam)
1167 WCHAR tmpstr[BUFFILE];
1168 LPWSTR pstr, old_pstr;
1169 LPOPENFILENAMEW ofn;
1170 LFSPRIVATE lfs = (LFSPRIVATE) lParam;
1172 if (!lfs) return FALSE;
1173 SetPropA(hWnd, OFN_PROP, (HANDLE)lfs);
1177 TRACE("flags=%lx initialdir=%s\n", ofn->Flags, debugstr_w(ofn->lpstrInitialDir));
1179 SetWindowTextW( hWnd, ofn->lpstrTitle );
1180 /* read custom filter information */
1181 if (ofn->lpstrCustomFilter)
1183 pstr = ofn->lpstrCustomFilter;
1185 TRACE("lpstrCustomFilter = %p\n", pstr);
1189 i = SendDlgItemMessageW(hWnd, cmb1, CB_ADDSTRING, 0,
1190 (LPARAM)(ofn->lpstrCustomFilter) + n );
1191 n += lstrlenW(pstr) + 1;
1192 pstr += lstrlenW(pstr) + 1;
1193 TRACE("add str=%s associated to %s\n",
1194 debugstr_w(old_pstr), debugstr_w(pstr));
1195 SendDlgItemMessageW(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
1196 n += lstrlenW(pstr) + 1;
1197 pstr += lstrlenW(pstr) + 1;
1200 /* read filter information */
1201 if (ofn->lpstrFilter) {
1202 pstr = (LPWSTR) ofn->lpstrFilter;
1206 i = SendDlgItemMessageW(hWnd, cmb1, CB_ADDSTRING, 0,
1207 (LPARAM)(ofn->lpstrFilter + n) );
1208 n += lstrlenW(pstr) + 1;
1209 pstr += lstrlenW(pstr) + 1;
1210 TRACE("add str=%s associated to %s\n",
1211 debugstr_w(old_pstr), debugstr_w(pstr));
1212 SendDlgItemMessageW(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
1213 n += lstrlenW(pstr) + 1;
1214 pstr += lstrlenW(pstr) + 1;
1217 /* set default filter */
1218 if (ofn->nFilterIndex == 0 && ofn->lpstrCustomFilter == NULL)
1219 ofn->nFilterIndex = 1;
1220 SendDlgItemMessageW(hWnd, cmb1, CB_SETCURSEL, ofn->nFilterIndex - 1, 0);
1221 lstrcpynW(tmpstr, FILEDLG_GetFileType(ofn->lpstrCustomFilter,
1222 (LPWSTR)ofn->lpstrFilter, ofn->nFilterIndex - 1),BUFFILE);
1223 TRACE("nFilterIndex = %ld, SetText of edt1 to %s\n",
1224 ofn->nFilterIndex, debugstr_w(tmpstr));
1225 SetDlgItemTextW( hWnd, edt1, tmpstr );
1226 /* get drive list */
1228 DlgDirListComboBoxW(hWnd, tmpstr, cmb2, 0, DDL_DRIVES | DDL_EXCLUSIVE);
1229 /* read initial directory */
1230 /* FIXME: Note that this is now very version-specific (See MSDN description of
1231 * the OPENFILENAME structure). For example under 2000/XP any path in the
1232 * lpstrFile overrides the lpstrInitialDir, but not under 95/98/ME
1234 if (ofn->lpstrInitialDir != NULL)
1237 lstrcpynW(tmpstr, ofn->lpstrInitialDir, 511);
1238 len = lstrlenW(tmpstr);
1239 if (len > 0 && tmpstr[len-1] != '\\' && tmpstr[len-1] != ':') {
1246 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
1248 if (!FILEDLG_ScanDir(hWnd, tmpstr))
1249 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr));
1251 /* select current drive in combo 2, omit missing drives */
1254 char str[4] = "a:\\";
1255 GetCurrentDirectoryA( sizeof(dir), dir );
1256 for(i = 0, n = -1; i < 26; i++)
1259 if (GetDriveTypeA(str) > DRIVE_NO_ROOT_DIR) n++;
1260 if (toupper(str[0]) == toupper(dir[0])) break;
1263 SendDlgItemMessageW(hWnd, cmb2, CB_SETCURSEL, n, 0);
1264 if (!(ofn->Flags & OFN_SHOWHELP))
1265 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
1266 if (ofn->Flags & OFN_HIDEREADONLY)
1267 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
1269 return (BOOL) FILEDLG_CallWindowProc16(lfs, WM_INITDIALOG, wParam, lfs->lParam);
1273 /***********************************************************************
1274 * FILEDLG_WMMeasureItem16 [internal]
1276 static LONG FILEDLG_WMMeasureItem16(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
1278 LPMEASUREITEMSTRUCT16 lpmeasure;
1280 lpmeasure = MapSL(lParam);
1281 lpmeasure->itemHeight = fldrHeight;
1285 /* ------------------ Dialog procedures ---------------------- */
1287 /***********************************************************************
1288 * FileOpenDlgProc (COMMDLG.6)
1290 BOOL16 CALLBACK FileOpenDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
1293 HWND hWnd = HWND_32(hWnd16);
1294 LFSPRIVATE lfs = (LFSPRIVATE)GetPropA(hWnd,OFN_PROP);
1297 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg, wParam, lParam);
1298 if ((wMsg != WM_INITDIALOG) && lfs && lfs->hook)
1300 LRESULT lRet = (BOOL16)FILEDLG_CallWindowProc16(lfs, wMsg, wParam, lParam);
1302 return lRet; /* else continue message processing */
1307 return FILEDLG_WMInitDialog16(hWnd, wParam, lParam);
1309 case WM_MEASUREITEM:
1310 return FILEDLG_WMMeasureItem16(hWnd16, wParam, lParam);
1313 FILEDLG_MapDrawItemStruct(MapSL(lParam), &dis);
1314 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE, &dis);
1317 return FILEDLG_WMCommand(hWnd, lParam, HIWORD(lParam),wParam, lfs);
1320 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1321 switch (HIWORD(lParam))
1324 SetTextColor((HDC16)wParam, 0x00000000);
1326 case CTLCOLOR_STATIC:
1327 SetTextColor((HDC16)wParam, 0x00000000);
1336 /***********************************************************************
1337 * FileSaveDlgProc (COMMDLG.7)
1339 BOOL16 CALLBACK FileSaveDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
1342 HWND hWnd = HWND_32(hWnd16);
1343 LFSPRIVATE lfs = (LFSPRIVATE)GetPropA(hWnd,OFN_PROP);
1346 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg, wParam, lParam);
1347 if ((wMsg != WM_INITDIALOG) && lfs && lfs->hook)
1350 lRet = (BOOL16)FILEDLG_CallWindowProc16(lfs, wMsg, wParam, lParam);
1352 return lRet; /* else continue message processing */
1356 return FILEDLG_WMInitDialog16(hWnd, wParam, lParam);
1358 case WM_MEASUREITEM:
1359 return FILEDLG_WMMeasureItem16(hWnd16, wParam, lParam);
1362 FILEDLG_MapDrawItemStruct(MapSL(lParam), &dis);
1363 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE, &dis);
1366 return FILEDLG_WMCommand(hWnd, lParam, HIWORD(lParam), wParam, lfs);
1371 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1372 switch (HIWORD(lParam))
1375 SetTextColor((HDC16)wParam, 0x00000000);
1377 case CTLCOLOR_STATIC:
1378 SetTextColor((HDC16)wParam, 0x00000000);
1387 /* ------------------ APIs ---------------------- */
1389 /***********************************************************************
1390 * GetOpenFileName (COMMDLG.1)
1392 * Creates a dialog box for the user to select a file to open.
1395 * TRUE on success: user selected a valid file
1396 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1399 * unknown, there are some FIXME's left.
1401 BOOL16 WINAPI GetOpenFileName16(
1402 SEGPTR ofn /* [in/out] address of structure with data*/
1407 LPOPENFILENAME16 lpofn = MapSL(ofn);
1411 if (!lpofn || !FileDlg_Init()) return FALSE;
1413 lfs = FILEDLG_AllocPrivate((LPARAM) ofn, LFS16, OPEN_DIALOG);
1416 hInst = GetWindowWord( HWND_32(lpofn->hwndOwner), GWL_HINSTANCE );
1417 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 6);
1418 bRet = DialogBoxIndirectParam16( hInst, lfs->hDlgTmpl16, lpofn->hwndOwner,
1419 (DLGPROC16) ptr, (LPARAM) lfs);
1420 FILEDLG_DestroyPrivate(lfs);
1423 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn->lpstrFile));
1427 /***********************************************************************
1428 * GetSaveFileName (COMMDLG.2)
1430 * Creates a dialog box for the user to select a file to save.
1433 * TRUE on success: user enters a valid file
1434 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1437 * unknown. There are some FIXME's left.
1439 BOOL16 WINAPI GetSaveFileName16(
1440 SEGPTR ofn /* [in/out] addess of structure with data*/
1445 LPOPENFILENAME16 lpofn = MapSL(ofn);
1449 if (!lpofn || !FileDlg_Init()) return FALSE;
1451 lfs = FILEDLG_AllocPrivate((LPARAM) ofn, LFS16, SAVE_DIALOG);
1454 hInst = GetWindowWord( HWND_32(lpofn->hwndOwner), GWL_HINSTANCE );
1455 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 7);
1456 bRet = DialogBoxIndirectParam16( hInst, lfs->hDlgTmpl16, lpofn->hwndOwner,
1457 (DLGPROC16) ptr, (LPARAM) lfs);
1458 FILEDLG_DestroyPrivate(lfs);
1461 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn->lpstrFile));