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 hFolder = LoadImageA( COMDLG32_hInstance, "FOLDER", IMAGE_ICON, 16, 16, LR_SHARED );
99 hFolder2 = LoadImageA( COMDLG32_hInstance, "FOLDER2", IMAGE_ICON, 16, 16, LR_SHARED );
100 hFloppy = LoadImageA( COMDLG32_hInstance, "FLOPPY", IMAGE_ICON, 16, 16, LR_SHARED );
101 hHDisk = LoadImageA( COMDLG32_hInstance, "HDISK", IMAGE_ICON, 16, 16, LR_SHARED );
102 hCDRom = LoadImageA( COMDLG32_hInstance, "CDROM", IMAGE_ICON, 16, 16, LR_SHARED );
103 hNet = LoadImageA( COMDLG32_hInstance, "NETWORK", IMAGE_ICON, 16, 16, LR_SHARED );
104 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
105 hHDisk == 0 || hCDRom == 0 || hNet == 0)
107 ERR("Error loading icons !\n");
115 /***********************************************************************
116 * Get32BitsTemplate [internal]
118 * Get a template (or FALSE if failure) when 16 bits dialogs are used
119 * by a 32 bits application
122 BOOL Get32BitsTemplate(LFSPRIVATE lfs)
124 LPOPENFILENAMEW ofnW = lfs->ofnW;
127 if (ofnW->Flags & OFN_ENABLETEMPLATEHANDLE)
129 if (!(lfs->template = LockResource( ofnW->hInstance )))
131 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
135 else if (ofnW->Flags & OFN_ENABLETEMPLATE)
139 hResInfo = FindResourceA(lfs->ofnA->hInstance,
140 lfs->ofnA->lpTemplateName,
143 hResInfo = FindResourceW(ofnW->hInstance,
144 ofnW->lpTemplateName,
148 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
151 if (!(hDlgTmpl = LoadResource(ofnW->hInstance,
153 !(lfs->template = LockResource(hDlgTmpl)))
155 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
158 } else { /* get it from internal Wine resource */
160 if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
161 lfs->open? "OPEN_FILE":"SAVE_FILE", (LPSTR)RT_DIALOG)))
163 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
166 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
167 !(lfs->template = LockResource( hDlgTmpl )))
169 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
176 /***********************************************************************
177 * Get16BitsTemplate [internal]
179 * Get a template (FALSE if failure) when 16 bits dialogs are used
180 * by a 16 bits application
183 BOOL Get16BitsTemplate(LFSPRIVATE lfs)
185 LPOPENFILENAME16 ofn16 = lfs->ofn16;
187 HGLOBAL16 hGlobal16 = 0;
189 if (ofn16->Flags & OFN_ENABLETEMPLATEHANDLE)
190 lfs->hDlgTmpl16 = ofn16->hInstance;
191 else if (ofn16->Flags & OFN_ENABLETEMPLATE)
194 if (!(hResInfo = FindResource16(ofn16->hInstance,
195 MapSL(ofn16->lpTemplateName),
198 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
201 if (!(lfs->hDlgTmpl16 = LoadResource16( ofn16->hInstance, hResInfo )))
203 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
206 lfs->hResource16 = lfs->hDlgTmpl16;
209 { /* get resource from (32 bits) own Wine resource; convert it to 16 */
215 if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
216 lfs->open ? "OPEN_FILE":"SAVE_FILE", (LPSTR)RT_DIALOG)))
218 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
221 if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) ||
222 !(template32 = LockResource( hDlgTmpl32 )))
224 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
227 size = SizeofResource(COMDLG32_hInstance, hResInfo);
228 hGlobal16 = GlobalAlloc16(0, size);
231 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
232 ERR("alloc failure for %ld bytes\n", size);
235 template = GlobalLock16(hGlobal16);
238 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
239 ERR("global lock failure for %x handle\n", hGlobal16);
240 GlobalFree16(hGlobal16);
243 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
244 lfs->hDlgTmpl16 = hGlobal16;
245 lfs->hGlobal16 = hGlobal16;
250 /***********************************************************************
251 * FILEDLG_StripEditControl [internal]
252 * Strip pathnames off the contents of the edit control.
254 static void FILEDLG_StripEditControl(HWND hwnd)
256 WCHAR temp[BUFFILE], *cp;
258 GetDlgItemTextW( hwnd, edt1, temp, sizeof(temp)/sizeof(WCHAR));
259 cp = strrchrW(temp, '\\');
263 cp = strrchrW(temp, ':');
267 /* FIXME: shouldn't we do something with the result here? ;-) */
270 /***********************************************************************
271 * FILEDLG_CallWindowProc [internal]
273 * Call the appropriate hook
275 static BOOL FILEDLG_CallWindowProc(LFSPRIVATE lfs, UINT wMsg, WPARAM wParam,
280 return (BOOL) CallWindowProcA(
281 (WNDPROC)lfs->ofnA->lpfnHook, lfs->hwnd,
282 wMsg, wParam, lParam);
287 return (BOOL) CallWindowProcW(
288 (WNDPROC)lfs->ofnW->lpfnHook, lfs->hwnd,
289 wMsg, wParam, lParam);
294 /***********************************************************************
295 * FILEDLG_ScanDir [internal]
297 static BOOL FILEDLG_ScanDir(HWND hWnd, LPWSTR newPath)
299 WCHAR buffer[BUFFILE];
302 HCURSOR hCursorWait, oldCursor;
304 TRACE("Trying to change to %s\n", debugstr_w(newPath));
305 if ( !SetCurrentDirectoryW( newPath ))
307 lstrcpynW(buffer, newPath, sizeof(buffer)/sizeof(WCHAR));
309 /* get the list of spec files */
310 GetDlgItemTextW(hWnd, edt1, buffer, sizeof(buffer)/sizeof(WCHAR));
312 hCursorWait = LoadCursorA(0, (LPSTR)IDC_WAIT);
313 oldCursor = SetCursor(hCursorWait);
316 if ((hdlg = GetDlgItem(hWnd, lst1)) != 0) {
317 WCHAR* scptr; /* ptr on semi-colon */
318 WCHAR* filter = buffer;
320 TRACE("Using filter %s\n", debugstr_w(filter));
321 SendMessageW(hdlg, LB_RESETCONTENT, 0, 0);
323 scptr = strchrW(filter, ';');
324 if (scptr) *scptr = 0;
325 while (*filter == ' ') filter++;
326 TRACE("Using file spec %s\n", debugstr_w(filter));
327 if (SendMessageW(hdlg, LB_DIR, 0, (LPARAM)filter) == LB_ERR)
329 if (scptr) *scptr = ';';
330 filter = (scptr) ? (scptr + 1) : 0;
334 /* list of directories */
335 strcpyW(buffer, FILE_star);
337 if ((hdlgDir = GetDlgItem(hWnd, lst2)) != 0) {
338 lRet = DlgDirListW(hWnd, buffer, lst2, stc1, DDL_EXCLUSIVE | DDL_DIRECTORY);
340 SetCursor(oldCursor);
344 /***********************************************************************
345 * FILEDLG_GetFileType [internal]
348 static LPWSTR FILEDLG_GetFileType(LPWSTR cfptr, LPWSTR fptr, WORD index)
353 for ( ;(n = lstrlenW(cfptr)) != 0; i++)
358 cfptr += lstrlenW(cfptr) + 1;
361 for ( ;(n = lstrlenW(fptr)) != 0; i++)
366 fptr += lstrlenW(fptr) + 1;
368 return (LPWSTR) FILE_star; /* FIXME */
371 /***********************************************************************
372 * FILEDLG_WMDrawItem [internal]
374 static LONG FILEDLG_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam,
375 int savedlg, LPDRAWITEMSTRUCT lpdis)
379 COLORREF oldText = 0, oldBk = 0;
381 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
383 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC))) return FALSE;
384 SendMessageW(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
387 if ((lpdis->itemState & ODS_SELECTED) && !savedlg)
389 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
390 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
393 SetTextColor(lpdis->hDC,GetSysColor(COLOR_GRAYTEXT) );
395 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + 1,
396 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
397 &(lpdis->rcItem), str, lstrlenW(str), NULL);
399 if (lpdis->itemState & ODS_SELECTED)
400 DrawFocusRect( lpdis->hDC, &(lpdis->rcItem) );
402 if ((lpdis->itemState & ODS_SELECTED) && !savedlg)
404 SetBkColor( lpdis->hDC, oldBk );
405 SetTextColor( lpdis->hDC, oldText );
407 HeapFree(GetProcessHeap(), 0, str);
411 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
413 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
415 SendMessageW(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
418 if (lpdis->itemState & ODS_SELECTED)
420 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
421 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
423 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + fldrWidth,
424 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
425 &(lpdis->rcItem), str, lstrlenW(str), NULL);
427 if (lpdis->itemState & ODS_SELECTED)
428 DrawFocusRect( lpdis->hDC, &(lpdis->rcItem) );
430 if (lpdis->itemState & ODS_SELECTED)
432 SetBkColor( lpdis->hDC, oldBk );
433 SetTextColor( lpdis->hDC, oldText );
435 DrawIcon(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hFolder);
436 HeapFree(GetProcessHeap(), 0, str);
439 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
442 if (!(str = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
444 SendMessageW(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
446 root[0] += str[2] - 'a';
447 switch(GetDriveTypeA(root))
449 case DRIVE_REMOVABLE: hIcon = hFloppy; break;
450 case DRIVE_CDROM: hIcon = hCDRom; break;
451 case DRIVE_REMOTE: hIcon = hNet; break;
453 default: hIcon = hHDisk; break;
455 if (lpdis->itemState & ODS_SELECTED)
457 oldBk = SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
458 oldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
460 ExtTextOutW(lpdis->hDC, lpdis->rcItem.left + fldrWidth,
461 lpdis->rcItem.top + 1, ETO_OPAQUE | ETO_CLIPPED,
462 &(lpdis->rcItem), str, lstrlenW(str), NULL);
464 if (lpdis->itemState & ODS_SELECTED)
466 SetBkColor( lpdis->hDC, oldBk );
467 SetTextColor( lpdis->hDC, oldText );
469 DrawIcon(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hIcon);
470 HeapFree(GetProcessHeap(), 0, str);
476 /***********************************************************************
477 * FILEDLG_UpdateResult [internal]
478 * update the displayed file name (with path)
480 void FILEDLG_UpdateResult(LFSPRIVATE lfs, WCHAR *tmpstr)
483 LPOPENFILENAMEW ofnW = lfs->ofnW;
484 WCHAR tmpstr2[BUFFILE];
487 TRACE("%s\n", debugstr_w(tmpstr));
488 if(ofnW->Flags & OFN_NOVALIDATE)
491 GetCurrentDirectoryW(BUFFILE, tmpstr2);
492 lenstr2 = strlenW(tmpstr2);
494 tmpstr2[lenstr2++]='\\';
495 lstrcpynW(tmpstr2+lenstr2, tmpstr, BUFFILE-lenstr2);
497 lstrcpynW(ofnW->lpstrFile, tmpstr2, ofnW->nMaxFile);
498 if((bs = strrchrW(tmpstr2, '\\')) != NULL)
499 ofnW->nFileOffset = bs - tmpstr2 +1;
501 ofnW->nFileOffset = 0;
502 ofnW->nFileExtension = 0;
503 while(tmpstr2[ofnW->nFileExtension] != '.' && tmpstr2[ofnW->nFileExtension] != '\0')
504 ofnW->nFileExtension++;
505 if (tmpstr2[ofnW->nFileExtension] == '\0')
506 ofnW->nFileExtension = 0;
508 ofnW->nFileExtension++;
509 /* update the real client structures if any */
511 { /* we have to convert to short (8.3) path */
512 char tmp[1024]; /* MAX_PATHNAME_LEN */
513 LPOPENFILENAME16 ofn16 = lfs->ofn16;
514 char *dest = MapSL(ofn16->lpstrFile);
516 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1,
517 tmp, sizeof(tmp), NULL, NULL ))
518 tmp[sizeof(tmp)-1] = 0;
519 GetShortPathNameA(tmp, dest, ofn16->nMaxFile);
521 /* the same procedure as every year... */
522 if((bs16 = strrchr(dest, '\\')) != NULL)
523 ofn16->nFileOffset = bs16 - dest +1;
525 ofn16->nFileOffset = 0;
526 ofn16->nFileExtension = 0;
527 while(dest[ofn16->nFileExtension] != '.' && dest[ofn16->nFileExtension] != '\0')
528 ofn16->nFileExtension++;
529 if (dest[ofn16->nFileExtension] == '\0')
530 ofn16->nFileExtension = 0;
532 ofn16->nFileExtension++;
536 if (ofnW->nMaxFile &&
537 !WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1,
538 lfs->ofnA->lpstrFile, ofnW->nMaxFile, NULL, NULL ))
539 lfs->ofnA->lpstrFile[ofnW->nMaxFile-1] = 0;
540 lfs->ofnA->nFileOffset = ofnW->nFileOffset;
541 lfs->ofnA->nFileExtension = ofnW->nFileExtension;
545 /***********************************************************************
546 * FILEDLG_UpdateFileTitle [internal]
547 * update the displayed file name (without path)
549 void FILEDLG_UpdateFileTitle(LFSPRIVATE lfs)
552 LPOPENFILENAMEW ofnW = lfs->ofnW;
553 if (ofnW->lpstrFileTitle != NULL)
555 lRet = SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL, 0, 0);
556 SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETTEXT, lRet,
557 (LPARAM)ofnW->lpstrFileTitle );
560 char *dest = MapSL(lfs->ofn16->lpstrFileTitle);
561 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1,
562 dest, ofnW->nMaxFileTitle, NULL, NULL ))
563 dest[ofnW->nMaxFileTitle-1] = 0;
567 if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1,
568 lfs->ofnA->lpstrFileTitle, ofnW->nMaxFileTitle, NULL, NULL ))
569 lfs->ofnA->lpstrFileTitle[ofnW->nMaxFileTitle-1] = 0;
574 /***********************************************************************
575 * FILEDLG_DirListDblClick [internal]
577 static LRESULT FILEDLG_DirListDblClick( LFSPRIVATE lfs )
580 HWND hWnd = lfs->hwnd;
582 WCHAR tmpstr[BUFFILE];
584 /* get the raw string (with brackets) */
585 lRet = SendDlgItemMessageW(hWnd, lst2, LB_GETCURSEL, 0, 0);
586 if (lRet == LB_ERR) return TRUE;
587 pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
588 SendDlgItemMessageW(hWnd, lst2, LB_GETTEXT, lRet,
590 strcpyW( tmpstr, pstr );
591 HeapFree(GetProcessHeap(), 0, pstr);
592 /* get the selected directory in tmpstr */
593 if (tmpstr[0] == '[')
595 tmpstr[lstrlenW(tmpstr) - 1] = 0;
596 strcpyW(tmpstr,tmpstr+1);
598 strcatW(tmpstr, FILE_bslash);
600 FILEDLG_ScanDir(hWnd, tmpstr);
604 if (FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, lst2,
605 MAKELONG(lRet,CD_LBSELCHANGE)))
611 /***********************************************************************
612 * FILEDLG_FileListSelect [internal]
613 * called when a new item is picked in the file list
615 static LRESULT FILEDLG_FileListSelect( LFSPRIVATE lfs )
618 HWND hWnd = lfs->hwnd;
621 lRet = SendDlgItemMessageW(hWnd, lst1, LB_GETCURSEL16, 0, 0);
625 /* set the edit control to the choosen file */
626 if ((pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
628 SendDlgItemMessageW(hWnd, lst1, LB_GETTEXT, lRet,
630 SetDlgItemTextW( hWnd, edt1, pstr );
631 HeapFree(GetProcessHeap(), 0, pstr);
635 FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, lst1,
636 MAKELONG(lRet,CD_LBSELCHANGE));
638 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD,
643 /***********************************************************************
644 * FILEDLG_TestPath [internal]
645 * before accepting the file name, test if it includes wild cards
646 * tries to scan the directory and returns TRUE if no error.
648 static LRESULT FILEDLG_TestPath( LFSPRIVATE lfs, LPWSTR path )
650 HWND hWnd = lfs->hwnd;
651 LPWSTR pBeginFileName, pstr2;
652 WCHAR tmpstr2[BUFFILE];
654 pBeginFileName = strrchrW(path, '\\');
655 if (pBeginFileName == NULL)
656 pBeginFileName = strrchrW(path, ':');
658 if (strchrW(path,'*') != NULL || strchrW(path,'?') != NULL)
660 /* edit control contains wildcards */
661 if (pBeginFileName != NULL)
663 lstrcpynW(tmpstr2, pBeginFileName + 1, BUFFILE);
664 *(pBeginFileName + 1) = 0;
668 strcpyW(tmpstr2, path);
669 if(!(lfs->ofnW->Flags & OFN_NOVALIDATE))
673 TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path), debugstr_w(tmpstr2));
674 SetDlgItemTextW( hWnd, edt1, tmpstr2 );
675 FILEDLG_ScanDir(hWnd, path);
676 return (lfs->ofnW->Flags & OFN_NOVALIDATE) ? TRUE : FALSE;
679 /* no wildcards, we might have a directory or a filename */
680 /* try appending a wildcard and reading the directory */
682 pstr2 = path + lstrlenW(path);
683 if (pBeginFileName == NULL || *(pBeginFileName + 1) != 0)
684 strcatW(path, FILE_bslash);
686 /* if ScanDir succeeds, we have changed the directory */
687 if (FILEDLG_ScanDir(hWnd, path))
688 return FALSE; /* and path is not a valid file name */
690 /* if not, this must be a filename */
692 *pstr2 = 0; /* remove the wildcard added before */
694 if (pBeginFileName != NULL)
696 /* strip off the pathname */
698 SetDlgItemTextW( hWnd, edt1, pBeginFileName + 1 );
700 lstrcpynW(tmpstr2, pBeginFileName + 1, sizeof(tmpstr2)/sizeof(WCHAR) );
701 /* Should we MessageBox() if this fails? */
702 if (!FILEDLG_ScanDir(hWnd, path))
706 strcpyW(path, tmpstr2);
709 SetDlgItemTextW( hWnd, edt1, path );
713 /***********************************************************************
714 * FILEDLG_Validate [internal]
715 * called on: click Ok button, Enter in edit, DoubleClick in file list
717 static LRESULT FILEDLG_Validate( LFSPRIVATE lfs, LPWSTR path, UINT control, INT itemIndex,
721 HWND hWnd = lfs->hwnd;
722 OPENFILENAMEW ofnsav;
723 LPOPENFILENAMEW ofnW = lfs->ofnW;
724 WCHAR filename[BUFFILE];
726 ofnsav = *ofnW; /* for later restoring */
728 /* get current file name */
730 lstrcpynW(filename, path, sizeof(filename)/sizeof(WCHAR));
732 GetDlgItemTextW( hWnd, edt1, filename, sizeof(filename)/sizeof(WCHAR));
734 TRACE("got filename = %s\n", debugstr_w(filename));
735 /* if we did not click in file list to get there */
738 if (!FILEDLG_TestPath( lfs, filename) )
741 FILEDLG_UpdateResult(lfs, filename);
744 { /* called internally after a change in a combo */
747 FILEDLG_CallWindowProc(lfs, lfs->lbselchstring, control,
748 MAKELONG(itemIndex,CD_LBSELCHANGE));
753 FILEDLG_UpdateFileTitle(lfs);
756 lRet = (BOOL)FILEDLG_CallWindowProc(lfs, lfs->fileokstring,
760 *ofnW = ofnsav; /* restore old state */
764 if ((ofnW->Flags & OFN_ALLOWMULTISELECT) && (ofnW->Flags & OFN_EXPLORER))
768 LPWSTR str = (LPWSTR)ofnW->lpstrFile;
769 LPWSTR ptr = strrchrW(str, '\\');
770 str[lstrlenW(str) + 1] = '\0';
777 /***********************************************************************
778 * FILEDLG_DiskChange [internal]
779 * called when a new item is picked in the disk selection combo
781 static LRESULT FILEDLG_DiskChange( LFSPRIVATE lfs )
784 HWND hWnd = lfs->hwnd;
786 WCHAR diskname[BUFFILE];
788 FILEDLG_StripEditControl(hWnd);
789 lRet = SendDlgItemMessageW(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
792 pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
793 SendDlgItemMessageW(hWnd, cmb2, CB_GETLBTEXT, lRet,
795 wsprintfW(diskname, FILE_specc, pstr[2]);
796 HeapFree(GetProcessHeap(), 0, pstr);
798 return FILEDLG_Validate( lfs, diskname, cmb2, lRet, TRUE );
801 /***********************************************************************
802 * FILEDLG_FileTypeChange [internal]
803 * called when a new item is picked in the file type combo
805 static LRESULT FILEDLG_FileTypeChange( LFSPRIVATE lfs )
808 WCHAR diskname[BUFFILE];
813 lRet = SendDlgItemMessageW(lfs->hwnd, cmb1, CB_GETCURSEL, 0, 0);
816 pstr = (LPWSTR)SendDlgItemMessageW(lfs->hwnd, cmb1, CB_GETITEMDATA, lRet, 0);
817 TRACE("Selected filter : %s\n", debugstr_w(pstr));
818 SetDlgItemTextW( lfs->hwnd, edt1, pstr );
820 return FILEDLG_Validate( lfs, NULL, cmb1, lRet, TRUE );
823 /***********************************************************************
824 * FILEDLG_WMCommand [internal]
826 static LRESULT FILEDLG_WMCommand(HWND hWnd, LPARAM lParam, UINT notification,
827 UINT control, LFSPRIVATE lfs )
831 case lst1: /* file list */
832 FILEDLG_StripEditControl(hWnd);
833 if (notification == LBN_DBLCLK)
835 if (FILEDLG_Validate( lfs, NULL, control, 0, FALSE ))
836 EndDialog(hWnd, TRUE);
839 else if (notification == LBN_SELCHANGE)
840 return FILEDLG_FileListSelect( lfs );
843 case lst2: /* directory list */
844 FILEDLG_StripEditControl(hWnd);
845 if (notification == LBN_DBLCLK)
846 return FILEDLG_DirListDblClick( lfs );
849 case cmb1: /* file type drop list */
850 if (notification == CBN_SELCHANGE)
851 return FILEDLG_FileTypeChange( lfs );
860 case cmb2: /* disk dropdown combo */
861 if (notification == CBN_SELCHANGE)
862 return FILEDLG_DiskChange( lfs );
866 TRACE("OK pressed\n");
867 if (FILEDLG_Validate( lfs, NULL, control, 0, FALSE ))
868 EndDialog(hWnd, TRUE);
872 EndDialog(hWnd, FALSE);
875 case IDABORT: /* can be sent by the hook procedure */
876 EndDialog(hWnd, TRUE);
882 /***********************************************************************
883 * FILEDLG_MapDrawItemStruct [internal]
884 * map a 16 bits drawitem struct to 32
886 static void FILEDLG_MapDrawItemStruct(LPDRAWITEMSTRUCT16 lpdis16, LPDRAWITEMSTRUCT lpdis)
888 lpdis->CtlType = lpdis16->CtlType;
889 lpdis->CtlID = lpdis16->CtlID;
890 lpdis->itemID = lpdis16->itemID;
891 lpdis->itemAction = lpdis16->itemAction;
892 lpdis->itemState = lpdis16->itemState;
893 lpdis->hwndItem = HWND_32(lpdis16->hwndItem);
894 lpdis->hDC = HDC_32(lpdis16->hDC);
895 lpdis->rcItem.right = lpdis16->rcItem.right;
896 lpdis->rcItem.left = lpdis16->rcItem.left;
897 lpdis->rcItem.top = lpdis16->rcItem.top;
898 lpdis->rcItem.bottom = lpdis16->rcItem.bottom;
899 lpdis->itemData = lpdis16->itemData;
902 /************************************************************************
903 * FILEDLG_MapStringPairsToW [internal]
904 * map string pairs to Unicode
906 static LPWSTR FILEDLG_MapStringPairsToW(LPCSTR strA, UINT size)
916 n = s + 1 - strA; /* Don't forget the other \0 */
917 if (n < size) n = size;
919 len = MultiByteToWideChar( CP_ACP, 0, strA, n, NULL, 0 );
920 x = HeapAlloc(GetProcessHeap(),0, len * sizeof(WCHAR));
921 MultiByteToWideChar( CP_ACP, 0, strA, n, x, len );
926 /************************************************************************
927 * FILEDLG_DupToW [internal]
928 * duplicates an Ansi string to unicode, with a buffer size
930 LPWSTR FILEDLG_DupToW(LPCSTR str, DWORD size)
933 if (str && (size > 0))
935 strW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
936 if (strW) MultiByteToWideChar( CP_ACP, 0, str, -1, strW, size );
942 /************************************************************************
943 * FILEDLG_MapOfnStructA [internal]
944 * map a 32 bits Ansi structure to an Unicode one
946 void FILEDLG_MapOfnStructA(LPOPENFILENAMEA ofnA, LPOPENFILENAMEW ofnW, BOOL open)
949 UNICODE_STRING usBuffer;
951 ofnW->lStructSize = sizeof(OPENFILENAMEW);
952 ofnW->hwndOwner = ofnA->hwndOwner;
953 ofnW->hInstance = ofnA->hInstance;
954 if (ofnA->lpstrFilter)
955 ofnW->lpstrFilter = FILEDLG_MapStringPairsToW(ofnA->lpstrFilter, 0);
957 if ((ofnA->lpstrCustomFilter) && (*(ofnA->lpstrCustomFilter)))
958 ofnW->lpstrCustomFilter = FILEDLG_MapStringPairsToW(ofnA->lpstrCustomFilter, ofnA->nMaxCustFilter);
959 ofnW->nMaxCustFilter = ofnA->nMaxCustFilter;
960 ofnW->nFilterIndex = ofnA->nFilterIndex;
961 ofnW->nMaxFile = ofnA->nMaxFile;
962 ofnW->lpstrFile = FILEDLG_DupToW(ofnA->lpstrFile, ofnW->nMaxFile);
963 ofnW->nMaxFileTitle = ofnA->nMaxFileTitle;
964 ofnW->lpstrFileTitle = FILEDLG_DupToW(ofnA->lpstrFileTitle, ofnW->nMaxFileTitle);
965 if (ofnA->lpstrInitialDir)
967 RtlCreateUnicodeStringFromAsciiz (&usBuffer,ofnA->lpstrInitialDir);
968 ofnW->lpstrInitialDir = usBuffer.Buffer;
970 if (ofnA->lpstrTitle)
971 str = ofnA->lpstrTitle;
973 /* Allocates default title (FIXME : get it from resource) */
974 str = open ? defaultopen:defaultsave;
975 RtlCreateUnicodeStringFromAsciiz (&usBuffer,ofnA->lpstrTitle);
976 ofnW->lpstrTitle = usBuffer.Buffer;
977 ofnW->Flags = ofnA->Flags;
978 ofnW->nFileOffset = ofnA->nFileOffset;
979 ofnW->nFileExtension = ofnA->nFileExtension;
980 ofnW->lpstrDefExt = FILEDLG_DupToW(ofnA->lpstrDefExt, 3);
981 if ((ofnA->Flags & OFN_ENABLETEMPLATE) && (ofnA->lpTemplateName))
983 if (HIWORD(ofnA->lpTemplateName))
985 RtlCreateUnicodeStringFromAsciiz (&usBuffer,ofnA->lpTemplateName);
986 ofnW->lpTemplateName = usBuffer.Buffer;
988 else /* numbered resource */
989 ofnW->lpTemplateName = (LPWSTR) ofnA->lpTemplateName;
993 /************************************************************************
994 * FILEDLG_MapOfnStruct16 [internal]
995 * map a 16 bits structure to an Unicode one
997 void FILEDLG_MapOfnStruct16(LPOPENFILENAME16 ofn16, LPOPENFILENAMEW ofnW, BOOL open)
1000 /* first convert to linear pointers */
1001 memset(&ofnA, 0, sizeof(OPENFILENAMEA));
1002 ofnA.lStructSize = sizeof(OPENFILENAMEA);
1003 ofnA.hwndOwner = HWND_32(ofn16->hwndOwner);
1004 ofnA.hInstance = HINSTANCE_32(ofn16->hInstance);
1005 if (ofn16->lpstrFilter)
1006 ofnA.lpstrFilter = MapSL(ofn16->lpstrFilter);
1007 if (ofn16->lpstrCustomFilter)
1008 ofnA.lpstrCustomFilter = MapSL(ofn16->lpstrCustomFilter);
1009 ofnA.nMaxCustFilter = ofn16->nMaxCustFilter;
1010 ofnA.nFilterIndex = ofn16->nFilterIndex;
1011 ofnA.lpstrFile = MapSL(ofn16->lpstrFile);
1012 ofnA.nMaxFile = ofn16->nMaxFile;
1013 ofnA.lpstrFileTitle = MapSL(ofn16->lpstrFileTitle);
1014 ofnA.nMaxFileTitle = ofn16->nMaxFileTitle;
1015 ofnA.lpstrInitialDir = MapSL(ofn16->lpstrInitialDir);
1016 ofnA.lpstrTitle = MapSL(ofn16->lpstrTitle);
1017 ofnA.Flags = ofn16->Flags;
1018 ofnA.nFileOffset = ofn16->nFileOffset;
1019 ofnA.nFileExtension = ofn16->nFileExtension;
1020 ofnA.lpstrDefExt = MapSL(ofn16->lpstrDefExt);
1021 if (HIWORD(ofn16->lpTemplateName))
1022 ofnA.lpTemplateName = MapSL(ofn16->lpTemplateName);
1024 ofnA.lpTemplateName = (LPSTR) ofn16->lpTemplateName; /* ressource number */
1025 /* now calls the 32 bits Ansi to Unicode version to complete the job */
1026 FILEDLG_MapOfnStructA(&ofnA, ofnW, open);
1029 /************************************************************************
1030 * FILEDLG_DestroyPrivate [internal]
1031 * destroys the private object
1033 static void FILEDLG_DestroyPrivate(LFSPRIVATE lfs)
1038 /* free resources for a 16 bits dialog */
1039 if (lfs->hResource16) FreeResource16(lfs->hResource16);
1042 GlobalUnlock16(lfs->hGlobal16);
1043 GlobalFree16(lfs->hGlobal16);
1045 /* if ofnW has been allocated, have to free everything in it */
1046 if (lfs->ofn16 || lfs->ofnA)
1048 LPOPENFILENAMEW ofnW = lfs->ofnW;
1049 if (ofnW->lpstrFilter) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrFilter);
1050 if (ofnW->lpstrCustomFilter) HeapFree(GetProcessHeap(), 0, ofnW->lpstrCustomFilter);
1051 if (ofnW->lpstrFile) HeapFree(GetProcessHeap(), 0, ofnW->lpstrFile);
1052 if (ofnW->lpstrFileTitle) HeapFree(GetProcessHeap(), 0, ofnW->lpstrFileTitle);
1053 if (ofnW->lpstrInitialDir) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrInitialDir);
1054 if (ofnW->lpstrTitle) HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpstrTitle);
1055 if ((ofnW->lpTemplateName) && (HIWORD(ofnW->lpTemplateName)))
1056 HeapFree(GetProcessHeap(), 0, (LPWSTR) ofnW->lpTemplateName);
1057 HeapFree(GetProcessHeap(), 0, ofnW);
1059 TRACE("destroying private allocation %p\n", lfs);
1060 HeapFree(GetProcessHeap(), 0, lfs);
1061 RemovePropA(hwnd, OFN_PROP);
1064 /************************************************************************
1065 * FILEDLG_AllocPrivate [internal]
1066 * allocate a private object to hold 32 bits Unicode
1067 * structure that will be used throughtout the calls, while
1068 * keeping available the original structures and a few variables
1069 * On entry : type = dialog procedure type (16,32A,32W)
1070 * dlgType = dialog type (open or save)
1072 static LFSPRIVATE FILEDLG_AllocPrivate(LPARAM lParam, int type, UINT dlgType)
1074 LFSPRIVATE lfs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct FSPRIVATE));
1076 TRACE("alloc private buf %p\n", lfs);
1077 if (!lfs) return NULL;
1079 lfs->lParam = lParam;
1080 if (dlgType == OPEN_DIALOG)
1084 lfs->lbselchstring = RegisterWindowMessageA(LBSELCHSTRINGA);
1085 lfs->fileokstring = RegisterWindowMessageA(FILEOKSTRINGA);
1089 lfs->ofn16 = MapSL(lParam);
1090 if (lfs->ofn16->Flags & OFN_ENABLEHOOK)
1091 if (lfs->ofn16->lpfnHook)
1097 lfs->ofnA = (LPOPENFILENAMEA) lParam;
1098 if (lfs->ofnA->Flags & OFN_ENABLEHOOK)
1099 if (lfs->ofnA->lpfnHook)
1104 lfs->ofnW = (LPOPENFILENAMEW) lParam;
1105 if (lfs->ofnW->Flags & OFN_ENABLEHOOK)
1106 if (lfs->ofnW->lpfnHook)
1112 { /* this structure is needed internally, so create it */
1113 lfs->ofnW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OPENFILENAMEW));
1117 FILEDLG_MapOfnStruct16(lfs->ofn16, lfs->ofnW, lfs->open);
1119 FILEDLG_MapOfnStructA(lfs->ofnA, lfs->ofnW, lfs->open);
1126 if (!Get16BitsTemplate(lfs)) ret = NULL;
1129 if (!Get32BitsTemplate(lfs)) ret = NULL;
1130 if (!ret) FILEDLG_DestroyPrivate(lfs);
1134 /***********************************************************************
1135 * FILEDLG_CallWindowProc16 [internal]
1137 * Call the appropriate hook
1139 static BOOL FILEDLG_CallWindowProc16(LFSPRIVATE lfs, UINT wMsg, WPARAM wParam,
1144 return (BOOL16) CallWindowProc16(
1145 (WNDPROC16)lfs->ofn16->lpfnHook, HWND_16(lfs->hwnd),
1146 (UINT16)wMsg, (WPARAM16)wParam, lParam);
1151 /***********************************************************************
1152 * FILEDLG_WMInitDialog16 [internal]
1153 * The is a duplicate of the 32bit FILEDLG_WMInitDialog function
1154 * The only differnce is that it calls FILEDLG_CallWindowProc16
1155 * for a 16 bit Window Proc.
1158 static LONG FILEDLG_WMInitDialog16(HWND hWnd, WPARAM wParam, LPARAM lParam)
1161 WCHAR tmpstr[BUFFILE];
1162 LPWSTR pstr, old_pstr;
1163 LPOPENFILENAMEW ofn;
1164 LFSPRIVATE lfs = (LFSPRIVATE) lParam;
1166 if (!lfs) return FALSE;
1167 SetPropA(hWnd, OFN_PROP, (HANDLE)lfs);
1171 TRACE("flags=%lx initialdir=%s\n", ofn->Flags, debugstr_w(ofn->lpstrInitialDir));
1173 SetWindowTextW( hWnd, ofn->lpstrTitle );
1174 /* read custom filter information */
1175 if (ofn->lpstrCustomFilter)
1177 pstr = ofn->lpstrCustomFilter;
1179 TRACE("lpstrCustomFilter = %p\n", pstr);
1183 i = SendDlgItemMessageW(hWnd, cmb1, CB_ADDSTRING, 0,
1184 (LPARAM)(ofn->lpstrCustomFilter) + n );
1185 n += lstrlenW(pstr) + 1;
1186 pstr += lstrlenW(pstr) + 1;
1187 TRACE("add str=%s associated to %s\n",
1188 debugstr_w(old_pstr), debugstr_w(pstr));
1189 SendDlgItemMessageW(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
1190 n += lstrlenW(pstr) + 1;
1191 pstr += lstrlenW(pstr) + 1;
1194 /* read filter information */
1195 if (ofn->lpstrFilter) {
1196 pstr = (LPWSTR) ofn->lpstrFilter;
1200 i = SendDlgItemMessageW(hWnd, cmb1, CB_ADDSTRING, 0,
1201 (LPARAM)(ofn->lpstrFilter + n) );
1202 n += lstrlenW(pstr) + 1;
1203 pstr += lstrlenW(pstr) + 1;
1204 TRACE("add str=%s associated to %s\n",
1205 debugstr_w(old_pstr), debugstr_w(pstr));
1206 SendDlgItemMessageW(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
1207 n += lstrlenW(pstr) + 1;
1208 pstr += lstrlenW(pstr) + 1;
1211 /* set default filter */
1212 if (ofn->nFilterIndex == 0 && ofn->lpstrCustomFilter == NULL)
1213 ofn->nFilterIndex = 1;
1214 SendDlgItemMessageW(hWnd, cmb1, CB_SETCURSEL, ofn->nFilterIndex - 1, 0);
1215 lstrcpynW(tmpstr, FILEDLG_GetFileType(ofn->lpstrCustomFilter,
1216 (LPWSTR)ofn->lpstrFilter, ofn->nFilterIndex - 1),BUFFILE);
1217 TRACE("nFilterIndex = %ld, SetText of edt1 to %s\n",
1218 ofn->nFilterIndex, debugstr_w(tmpstr));
1219 SetDlgItemTextW( hWnd, edt1, tmpstr );
1220 /* get drive list */
1222 DlgDirListComboBoxW(hWnd, tmpstr, cmb2, 0, DDL_DRIVES | DDL_EXCLUSIVE);
1223 /* read initial directory */
1224 /* FIXME: Note that this is now very version-specific (See MSDN description of
1225 * the OPENFILENAME structure). For example under 2000/XP any path in the
1226 * lpstrFile overrides the lpstrInitialDir, but not under 95/98/ME
1228 if (ofn->lpstrInitialDir != NULL)
1231 lstrcpynW(tmpstr, ofn->lpstrInitialDir, 511);
1232 len = lstrlenW(tmpstr);
1233 if (len > 0 && tmpstr[len-1] != '\\' && tmpstr[len-1] != ':') {
1240 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
1242 if (!FILEDLG_ScanDir(hWnd, tmpstr))
1243 WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr));
1245 /* select current drive in combo 2, omit missing drives */
1248 char str[4] = "a:\\";
1249 GetCurrentDirectoryA( sizeof(dir), dir );
1250 for(i = 0, n = -1; i < 26; i++)
1253 if (GetDriveTypeA(str) > DRIVE_NO_ROOT_DIR) n++;
1254 if (toupper(str[0]) == toupper(dir[0])) break;
1257 SendDlgItemMessageW(hWnd, cmb2, CB_SETCURSEL, n, 0);
1258 if (!(ofn->Flags & OFN_SHOWHELP))
1259 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
1260 if (ofn->Flags & OFN_HIDEREADONLY)
1261 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
1263 return (BOOL) FILEDLG_CallWindowProc16(lfs, WM_INITDIALOG, wParam, lfs->lParam);
1267 /***********************************************************************
1268 * FILEDLG_WMMeasureItem16 [internal]
1270 static LONG FILEDLG_WMMeasureItem16(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
1272 LPMEASUREITEMSTRUCT16 lpmeasure;
1274 lpmeasure = MapSL(lParam);
1275 lpmeasure->itemHeight = fldrHeight;
1279 /* ------------------ Dialog procedures ---------------------- */
1281 /***********************************************************************
1282 * FileOpenDlgProc (COMMDLG.6)
1284 BOOL16 CALLBACK FileOpenDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
1287 HWND hWnd = HWND_32(hWnd16);
1288 LFSPRIVATE lfs = (LFSPRIVATE)GetPropA(hWnd,OFN_PROP);
1291 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg, wParam, lParam);
1292 if ((wMsg != WM_INITDIALOG) && lfs && lfs->hook)
1294 LRESULT lRet = (BOOL16)FILEDLG_CallWindowProc16(lfs, wMsg, wParam, lParam);
1296 return lRet; /* else continue message processing */
1301 return FILEDLG_WMInitDialog16(hWnd, wParam, lParam);
1303 case WM_MEASUREITEM:
1304 return FILEDLG_WMMeasureItem16(hWnd16, wParam, lParam);
1307 FILEDLG_MapDrawItemStruct(MapSL(lParam), &dis);
1308 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE, &dis);
1311 return FILEDLG_WMCommand(hWnd, lParam, HIWORD(lParam),wParam, lfs);
1314 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1315 switch (HIWORD(lParam))
1318 SetTextColor((HDC16)wParam, 0x00000000);
1320 case CTLCOLOR_STATIC:
1321 SetTextColor((HDC16)wParam, 0x00000000);
1330 /***********************************************************************
1331 * FileSaveDlgProc (COMMDLG.7)
1333 BOOL16 CALLBACK FileSaveDlgProc16(HWND16 hWnd16, UINT16 wMsg, WPARAM16 wParam,
1336 HWND hWnd = HWND_32(hWnd16);
1337 LFSPRIVATE lfs = (LFSPRIVATE)GetPropA(hWnd,OFN_PROP);
1340 TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg, wParam, lParam);
1341 if ((wMsg != WM_INITDIALOG) && lfs && lfs->hook)
1344 lRet = (BOOL16)FILEDLG_CallWindowProc16(lfs, wMsg, wParam, lParam);
1346 return lRet; /* else continue message processing */
1350 return FILEDLG_WMInitDialog16(hWnd, wParam, lParam);
1352 case WM_MEASUREITEM:
1353 return FILEDLG_WMMeasureItem16(hWnd16, wParam, lParam);
1356 FILEDLG_MapDrawItemStruct(MapSL(lParam), &dis);
1357 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE, &dis);
1360 return FILEDLG_WMCommand(hWnd, lParam, HIWORD(lParam), wParam, lfs);
1365 SetBkColor((HDC16)wParam, 0x00C0C0C0);
1366 switch (HIWORD(lParam))
1369 SetTextColor((HDC16)wParam, 0x00000000);
1371 case CTLCOLOR_STATIC:
1372 SetTextColor((HDC16)wParam, 0x00000000);
1381 /* ------------------ APIs ---------------------- */
1383 /***********************************************************************
1384 * GetOpenFileName (COMMDLG.1)
1386 * Creates a dialog box for the user to select a file to open.
1389 * TRUE on success: user selected a valid file
1390 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1393 * unknown, there are some FIXME's left.
1395 BOOL16 WINAPI GetOpenFileName16(
1396 SEGPTR ofn /* [in/out] address of structure with data*/
1401 LPOPENFILENAME16 lpofn = MapSL(ofn);
1405 if (!lpofn || !FileDlg_Init()) return FALSE;
1407 lfs = FILEDLG_AllocPrivate((LPARAM) ofn, LFS16, OPEN_DIALOG);
1410 hInst = GetWindowWord( HWND_32(lpofn->hwndOwner), GWL_HINSTANCE );
1411 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 6);
1412 bRet = DialogBoxIndirectParam16( hInst, lfs->hDlgTmpl16, lpofn->hwndOwner,
1413 (DLGPROC16) ptr, (LPARAM) lfs);
1414 FILEDLG_DestroyPrivate(lfs);
1417 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn->lpstrFile));
1421 /***********************************************************************
1422 * GetSaveFileName (COMMDLG.2)
1424 * Creates a dialog box for the user to select a file to save.
1427 * TRUE on success: user enters a valid file
1428 * FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
1431 * unknown. There are some FIXME's left.
1433 BOOL16 WINAPI GetSaveFileName16(
1434 SEGPTR ofn /* [in/out] addess of structure with data*/
1439 LPOPENFILENAME16 lpofn = MapSL(ofn);
1443 if (!lpofn || !FileDlg_Init()) return FALSE;
1445 lfs = FILEDLG_AllocPrivate((LPARAM) ofn, LFS16, SAVE_DIALOG);
1448 hInst = GetWindowWord( HWND_32(lpofn->hwndOwner), GWL_HINSTANCE );
1449 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 7);
1450 bRet = DialogBoxIndirectParam16( hInst, lfs->hDlgTmpl16, lpofn->hwndOwner,
1451 (DLGPROC16) ptr, (LPARAM) lfs);
1452 FILEDLG_DestroyPrivate(lfs);
1455 TRACE("return lpstrFile='%s' !\n", (char *)MapSL(lpofn->lpstrFile));