4 * Copyright 1994 Martin Ayotte
15 #include "selectors.h"
19 #include "stackframe.h"
23 static DWORD CommDlgLastError
= 0;
25 static HBITMAP hFolder
= 0;
26 static HBITMAP hFolder2
= 0;
27 static HBITMAP hFloppy
= 0;
28 static HBITMAP hHDisk
= 0;
29 static HBITMAP hCDRom
= 0;
31 /***********************************************************************
32 * FileDlg_Init [internal]
34 static BOOL
FileDlg_Init()
36 static BOOL initialized
= 0;
39 if (!hFolder
) hFolder
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER
));
40 if (!hFolder2
) hFolder2
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2
));
41 if (!hFloppy
) hFloppy
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY
));
42 if (!hHDisk
) hHDisk
= LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK
));
43 if (!hCDRom
) hCDRom
= LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM
));
44 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
45 hHDisk
== 0 || hCDRom
== 0)
47 fprintf(stderr
, "FileDlg_Init // Error loading bitmaps !");
55 /***********************************************************************
56 * GetOpenFileName (COMMDLG.1)
58 BOOL
GetOpenFileName(LPOPENFILENAME lpofn
)
61 HANDLE hDlgTmpl
, hResInfo
;
64 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
66 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpofn
->hInstance
;
67 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
69 if (!(hResInfo
= FindResource( lpofn
->hInstance
,
70 lpofn
->lpTemplateName
, RT_DIALOG
)))
72 CommDlgLastError
= CDERR_FINDRESFAILURE
;
75 hDlgTmpl
= LoadResource( lpofn
->hInstance
, hResInfo
);
77 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_OPEN_FILE
);
80 CommDlgLastError
= CDERR_LOADRESFAILURE
;
84 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
85 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpofn
->hwndOwner
,
86 GetWndProcEntry16("FileOpenDlgProc"),
89 if (!(lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
))
91 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) FreeResource( hDlgTmpl
);
92 else SYSRES_FreeResource( hDlgTmpl
);
95 dprintf_commdlg(stddeb
,"GetOpenFileName // return lpstrFile='%s' !\n",
96 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
101 /***********************************************************************
102 * GetSaveFileName (COMMDLG.2)
104 BOOL
GetSaveFileName(LPOPENFILENAME lpofn
)
107 HANDLE hDlgTmpl
, hResInfo
;
110 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
112 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpofn
->hInstance
;
113 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
115 hInst
= lpofn
->hInstance
;
116 if (!(hResInfo
= FindResource( lpofn
->hInstance
,
117 lpofn
->lpTemplateName
, RT_DIALOG
)))
119 CommDlgLastError
= CDERR_FINDRESFAILURE
;
122 hDlgTmpl
= LoadResource( lpofn
->hInstance
, hResInfo
);
124 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE
);
126 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
127 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpofn
->hwndOwner
,
128 GetWndProcEntry16("FileSaveDlgProc"),
130 if (!(lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
))
132 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) FreeResource( hDlgTmpl
);
133 else SYSRES_FreeResource( hDlgTmpl
);
136 dprintf_commdlg(stddeb
, "GetSaveFileName // return lpstrFile='%s' !\n",
137 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
141 /***********************************************************************
142 * FILEDLG_StripEditControl [internal]
143 * Strip pathnames off the contents of the edit control.
145 static void FILEDLG_StripEditControl(HWND hwnd
)
149 SendDlgItemMessage(hwnd
, edt1
, WM_GETTEXT
, 511, (LPARAM
)MAKE_SEGPTR(temp
));
150 cp
= strrchr(temp
, '\\');
154 cp
= strrchr(temp
, ':');
160 /***********************************************************************
161 * FILEDLG_ScanDir [internal]
163 static BOOL
FILEDLG_ScanDir(HWND hWnd
, LPSTR newPath
)
165 char str
[512],str2
[512];
167 strncpy(str
,newPath
,511); str
[511]=0;
168 SendDlgItemMessage(hWnd
, edt1
, WM_GETTEXT
, 511, (LPARAM
)MAKE_SEGPTR(str2
));
169 strncat(str
,str2
,511-strlen(str
)); str
[511]=0;
170 if (!DlgDirList(hWnd
, MAKE_SEGPTR(str
), lst1
, 0, 0x0000)) return FALSE
;
171 strcpy( str
, "*.*" );
172 DlgDirList(hWnd
, MAKE_SEGPTR(str
), lst2
, stc1
, 0x8010);
176 /***********************************************************************
177 * FILEDLG_GetFileType [internal]
180 static LPSTR
FILEDLG_GetFileType(LPSTR cfptr
, LPSTR fptr
, WORD index
)
185 for ( ;(n
= strlen(cfptr
)) != 0; i
++)
190 cfptr
+= strlen(cfptr
) + 1;
193 for ( ;(n
= strlen(fptr
)) != 0; i
++)
198 fptr
+= strlen(fptr
) + 1;
203 /***********************************************************************
204 * FILEDLG_WMDrawItem [internal]
206 static LONG
FILEDLG_WMDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
208 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
211 HBITMAP hBitmap
, hPrevBitmap
;
216 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
) {
217 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
218 SelectObject(lpdis
->hDC
, hBrush
);
219 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
220 SendMessage(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
221 (LPARAM
)MAKE_SEGPTR(str
));
222 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
224 if (lpdis
->itemState
!= 0) {
225 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
230 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
) {
231 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
232 SelectObject(lpdis
->hDC
, hBrush
);
233 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
234 SendMessage(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
235 (LPARAM
)MAKE_SEGPTR(str
));
238 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
239 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
240 lpdis
->rcItem
.top
, str
, strlen(str
));
241 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
242 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
243 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
244 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
245 SelectObject(hMemDC
, hPrevBitmap
);
247 if (lpdis
->itemState
!= 0) {
248 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
252 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
) {
253 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
254 SelectObject(lpdis
->hDC
, hBrush
);
255 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
256 SendMessage(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
257 (LPARAM
)MAKE_SEGPTR(str
));
258 switch(DRIVE_GetType( str
[2] - 'a' ))
260 case TYPE_FLOPPY
: hBitmap
= hFloppy
; break;
261 case TYPE_CDROM
: hBitmap
= hCDRom
; break;
264 default: hBitmap
= hHDisk
; break;
266 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
267 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
268 lpdis
->rcItem
.top
, str
, strlen(str
));
269 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
270 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
271 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
272 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
273 SelectObject(hMemDC
, hPrevBitmap
);
275 if (lpdis
->itemState
!= 0) {
276 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
283 /***********************************************************************
284 * FILEDLG_WMMeasureItem [internal]
286 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
289 LPMEASUREITEMSTRUCT lpmeasure
;
291 GetObject(hFolder2
, sizeof(BITMAP
), (LPSTR
)&bm
);
292 lpmeasure
= (LPMEASUREITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
293 lpmeasure
->itemHeight
= bm
.bmHeight
;
297 /***********************************************************************
298 * FILEDLG_HookCallChk [internal]
300 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn
)
303 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
309 /***********************************************************************
310 * FILEDLG_WMInitDialog [internal]
313 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
317 LPOPENFILENAME lpofn
;
320 SetWindowLong(hWnd
, DWL_USER
, lParam
);
321 lpofn
= (LPOPENFILENAME
)lParam
;
322 /* read custom filter information */
323 if (lpofn
->lpstrCustomFilter
)
325 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
);
326 dprintf_commdlg(stddeb
,"lpstrCustomFilter = %p\n", pstr
);
330 strncpy(tmpstr
, pstr
, 511); tmpstr
[511]=0;
331 dprintf_commdlg(stddeb
,"lpstrCustomFilter // add tmpstr='%s' ", tmpstr
);
332 i
= SendDlgItemMessage(hWnd
, cmb1
, CB_ADDSTRING
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
335 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
336 SendDlgItemMessage(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
340 /* read filter information */
341 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
345 strncpy(tmpstr
, pstr
, 511); tmpstr
[511]=0;
346 dprintf_commdlg(stddeb
,"lpstrFilter // add tmpstr='%s' ", tmpstr
);
347 i
= SendDlgItemMessage(hWnd
, cmb1
, CB_ADDSTRING
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
350 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
351 SendDlgItemMessage(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
354 /* set default filter */
355 if (lpofn
->nFilterIndex
== 0 && lpofn
->lpstrCustomFilter
== (SEGPTR
)NULL
)
356 lpofn
->nFilterIndex
= 1;
357 SendDlgItemMessage(hWnd
, cmb1
, CB_SETCURSEL
, lpofn
->nFilterIndex
- 1, 0);
358 strncpy(tmpstr
, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
359 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lpofn
->nFilterIndex
- 1),511);
361 dprintf_commdlg(stddeb
,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
362 lpofn
->nFilterIndex
, tmpstr
);
363 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
366 DlgDirListComboBox(hWnd
, MAKE_SEGPTR(tmpstr
), cmb2
, 0, 0xC000);
367 /* read initial directory */
368 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
)
370 strncpy(tmpstr
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
), 510);
372 if (strlen(tmpstr
) > 0 && tmpstr
[strlen(tmpstr
)-1] != '\\'
373 && tmpstr
[strlen(tmpstr
)-1] != ':')
378 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
379 fprintf(stderr
, "FileDlg: couldn't read initial directory %s!\n", tmpstr
);
380 /* select current drive in combo 2 */
381 n
= DRIVE_GetCurrentDrive();
382 SendDlgItemMessage(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
383 if (!(lpofn
->Flags
& OFN_SHOWHELP
))
384 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
385 if (lpofn
->Flags
& OFN_HIDEREADONLY
)
386 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
387 if (FILEDLG_HookCallChk(lpofn
))
388 return (BOOL
)CallWindowProc(lpofn
->lpfnHook
,
389 hWnd
, WM_INITDIALOG
, wParam
,(LPARAM
)MAKE_SEGPTR(lpofn
));
394 /***********************************************************************
395 * FILEDLG_WMCommand [internal]
397 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
400 LPOPENFILENAME lpofn
;
402 char tmpstr
[512], tmpstr2
[512];
404 UINT control
,notification
;
406 /* Notifications are packaged differently in Win32 */
408 control
= LOWORD(wParam
);
409 notification
= HIWORD(wParam
);
412 notification
= HIWORD(lParam
);
415 lpofn
= (LPOPENFILENAME
)GetWindowLong(hWnd
, DWL_USER
);
418 case lst1
: /* file list */
419 FILEDLG_StripEditControl(hWnd
);
420 if (notification
== LBN_DBLCLK
)
422 lRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0);
423 if (lRet
== LB_ERR
) return TRUE
;
424 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, lRet
,
425 (LPARAM
)MAKE_SEGPTR(tmpstr
));
426 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
428 if (FILEDLG_HookCallChk(lpofn
))
429 CallWindowProc (lpofn
->lpfnHook
, hWnd
,
430 RegisterWindowMessage(MAKE_SEGPTR(LBSELCHSTRING
)),
431 control
, MAKELONG(lRet
,CD_LBSELCHANGE
));
432 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
434 case lst2
: /* directory list */
435 FILEDLG_StripEditControl(hWnd
);
436 if (notification
== LBN_DBLCLK
)
438 lRet
= SendDlgItemMessage(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
439 if (lRet
== LB_ERR
) return TRUE
;
440 SendDlgItemMessage(hWnd
, lst2
, LB_GETTEXT
, lRet
,
441 (LPARAM
)MAKE_SEGPTR(tmpstr
));
442 if (tmpstr
[0] == '[')
444 tmpstr
[strlen(tmpstr
) - 1] = 0;
445 strcpy(tmpstr
,tmpstr
+1);
447 strcat(tmpstr
, "\\");
451 case cmb1
: /* file type drop list */
452 if (notification
== CBN_SELCHANGE
)
458 case cmb2
: /* disk drop list */
459 FILEDLG_StripEditControl(hWnd
);
460 lRet
= SendDlgItemMessage(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
461 if (lRet
== LB_ERR
) return 0;
462 SendDlgItemMessage(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
, (LPARAM
)MAKE_SEGPTR(tmpstr
));
463 sprintf(tmpstr
, "%c:", tmpstr
[2]);
465 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
468 pstr
= (LPSTR
)SendDlgItemMessage(hWnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
469 dprintf_commdlg(stddeb
,"Selected filter : %s\n", pstr
);
470 strncpy(tmpstr2
, pstr
, 511); tmpstr2
[511]=0;
471 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr2
));
472 FILEDLG_ScanDir(hWnd
, tmpstr
);
480 ofn2
=*lpofn
; /* for later restoring */
481 SendDlgItemMessage(hWnd
, edt1
, WM_GETTEXT
, 511, (LPARAM
)MAKE_SEGPTR(tmpstr
));
482 pstr
= strrchr(tmpstr
, '\\');
484 pstr
= strrchr(tmpstr
, ':');
485 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
487 /* edit control contains wildcards */
490 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
495 strcpy(tmpstr2
, tmpstr
);
498 dprintf_commdlg(stddeb
,"commdlg: %s, %s\n", tmpstr
, tmpstr2
);
499 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr2
));
500 FILEDLG_ScanDir(hWnd
, tmpstr
);
503 /* no wildcards, we might have a directory or a filename */
504 /* try appending a wildcard and reading the directory */
505 pstr2
= tmpstr
+ strlen(tmpstr
);
506 if (pstr
== NULL
|| *(pstr
+1) != 0)
507 strcat(tmpstr
, "\\");
508 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
509 if (lRet
== LB_ERR
) return TRUE
;
510 lpofn
->nFilterIndex
= lRet
+ 1;
511 dprintf_commdlg(stddeb
,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn
->nFilterIndex
);
513 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
514 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
517 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr2
));
518 /* if ScanDir succeeds, we have changed the directory */
519 if (FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
520 /* if not, this must be a filename */
524 /* strip off the pathname */
526 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
527 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr2
));
528 /* Should we MessageBox() if this fails? */
529 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
530 strcpy(tmpstr
, tmpstr2
);
533 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
535 ShowWindow(hWnd
, SW_HIDE
); /* this should not be necessary ?! (%%%) */
538 int drive
= DRIVE_GetCurrentDrive();
539 tmpstr2
[0] = 'A'+ drive
;
542 strncpy(tmpstr2
+ 3, DRIVE_GetDosCwd(drive
), 507); tmpstr2
[510]=0;
543 if (strlen(tmpstr2
) > 3)
544 strcat(tmpstr2
, "\\");
545 strncat(tmpstr2
, tmpstr
, 511-strlen(tmpstr2
)); tmpstr2
[511]=0;
546 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), tmpstr2
);
548 lpofn
->nFileOffset
= 0;
549 lpofn
->nFileExtension
= 0;
550 while(tmpstr2
[lpofn
->nFileExtension
] != '.' && tmpstr2
[lpofn
->nFileExtension
] != '\0')
551 lpofn
->nFileExtension
++;
552 if (lpofn
->nFileExtension
== '\0')
553 lpofn
->nFileExtension
= 0;
555 lpofn
->nFileExtension
++;
556 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
)
558 lRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0);
559 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, lRet
,
560 (LPARAM
)MAKE_SEGPTR(tmpstr
));
561 dprintf_commdlg(stddeb
,"strcpy'ing '%s'\n",tmpstr
); fflush(stdout
);
562 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
), tmpstr
);
564 if (FILEDLG_HookCallChk(lpofn
))
566 lRet
= (BOOL
)CallWindowProc (lpofn
->lpfnHook
,
567 hWnd
, RegisterWindowMessage(MAKE_SEGPTR(FILEOKSTRING
)),
568 0, (LPARAM
)MAKE_SEGPTR(lpofn
));
571 *lpofn
=ofn2
; /* restore old state */
573 ShowWindow(hWnd
, SW_SHOW
); /* only if above (%%%) SW_HIDE used */
578 EndDialog(hWnd
, TRUE
);
581 EndDialog(hWnd
, FALSE
);
588 /***********************************************************************
589 * FileOpenDlgProc (COMMDLG.6)
591 LRESULT
FileOpenDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
593 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)GetWindowLong(hWnd
, DWL_USER
);
595 if (wMsg
!=WM_INITDIALOG
)
596 if (FILEDLG_HookCallChk(lpofn
))
598 LRESULT lRet
=(BOOL
)CallWindowProc(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
600 return lRet
; /* else continue message processing */
605 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
607 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
609 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
);
611 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
614 SetBkColor((HDC
)wParam
, 0x00C0C0C0);
615 switch (HIWORD(lParam
))
618 SetTextColor((HDC
)wParam
, 0x00000000);
620 case CTLCOLOR_STATIC
:
621 SetTextColor((HDC
)wParam
, 0x00000000);
631 /***********************************************************************
632 * FileSaveDlgProc (COMMDLG.7)
634 LRESULT
FileSaveDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
636 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)GetWindowLong(hWnd
, DWL_USER
);
638 if (wMsg
!=WM_INITDIALOG
)
639 if (FILEDLG_HookCallChk(lpofn
))
641 LRESULT lRet
=(BOOL
)CallWindowProc(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
643 return lRet
; /* else continue message processing */
647 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
650 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
653 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
);
656 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
661 SetBkColor((HDC)wParam, 0x00C0C0C0);
662 switch (HIWORD(lParam))
665 SetTextColor((HDC)wParam, 0x00000000);
667 case CTLCOLOR_STATIC:
668 SetTextColor((HDC)wParam, 0x00000000);
678 /***********************************************************************
679 * ChooseColor (COMMDLG.5)
681 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
683 HANDLE hInst
, hDlgTmpl
;
686 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR
);
687 hInst
= WIN_GetWindowInstance( lpChCol
->hwndOwner
);
688 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpChCol
->hwndOwner
,
689 GetWndProcEntry16("ColorDlgProc"),
691 SYSRES_FreeResource( hDlgTmpl
);
696 /***********************************************************************
697 * ColorDlgProc (COMMDLG.8)
699 LRESULT
ColorDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
704 dprintf_commdlg(stddeb
,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
705 ShowWindow(hWnd
, SW_SHOWNORMAL
);
711 EndDialog(hWnd
, TRUE
);
714 EndDialog(hWnd
, FALSE
);
723 /***********************************************************************
724 * FindTextDlg (COMMDLG.11)
726 BOOL
FindText(LPFINDREPLACE lpFind
)
728 HANDLE hInst
, hDlgTmpl
;
733 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
734 * For now, only the standard dialog works.
737 * FIXME : We should do error checking on the lpFind structure here
738 * and make CommDlgExtendedError() return the error condition.
740 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT
);
741 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
742 if (!(ptr
= (SEGPTR
)WIN16_GlobalLock( hDlgTmpl
))) return -1;
743 bRet
= CreateDialogIndirectParam( hInst
, ptr
, lpFind
->hwndOwner
,
744 GetWndProcEntry16("FindTextDlgProc"),
746 GlobalUnlock( hDlgTmpl
);
747 SYSRES_FreeResource( hDlgTmpl
);
752 /***********************************************************************
753 * ReplaceTextDlg (COMMDLG.12)
755 BOOL
ReplaceText(LPFINDREPLACE lpFind
)
757 HANDLE hInst
, hDlgTmpl
;
762 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
763 * For now, only the standard dialog works.
766 * FIXME : We should do error checking on the lpFind structure here
767 * and make CommDlgExtendedError() return the error condition.
769 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT
);
770 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
771 if (!(ptr
= (SEGPTR
)WIN16_GlobalLock( hDlgTmpl
))) return -1;
772 bRet
= CreateDialogIndirectParam( hInst
, ptr
, lpFind
->hwndOwner
,
773 GetWndProcEntry16("ReplaceTextDlgProc"),
775 GlobalUnlock( hDlgTmpl
);
776 SYSRES_FreeResource( hDlgTmpl
);
781 /***********************************************************************
782 * FINDDLG_WMInitDialog [internal]
784 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
788 SetWindowLong(hWnd
, DWL_USER
, lParam
);
789 lpfr
= (LPFINDREPLACE
)lParam
;
790 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
792 * FIXME : If the initial FindWhat string is empty, we should disable the
793 * FindNext (IDOK) button. Only after typing some text, the button should be
796 SetDlgItemText(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
797 CheckRadioButton(hWnd
, rad1
, rad2
, (lpfr
->Flags
& FR_DOWN
) ? rad2
: rad1
);
798 if (lpfr
->Flags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
799 EnableWindow(GetDlgItem(hWnd
, rad1
), FALSE
);
800 EnableWindow(GetDlgItem(hWnd
, rad2
), FALSE
);
802 if (lpfr
->Flags
& FR_HIDEUPDOWN
) {
803 ShowWindow(GetDlgItem(hWnd
, rad1
), SW_HIDE
);
804 ShowWindow(GetDlgItem(hWnd
, rad2
), SW_HIDE
);
805 ShowWindow(GetDlgItem(hWnd
, grp1
), SW_HIDE
);
807 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
808 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
809 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
810 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
811 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
812 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
813 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
814 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
815 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
816 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
817 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
818 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
819 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
821 ShowWindow(hWnd
, SW_SHOWNORMAL
);
826 /***********************************************************************
827 * FINDDLG_WMCommand [internal]
829 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
832 int uFindReplaceMessage
= RegisterWindowMessage(MAKE_SEGPTR(FINDMSGSTRING
));
833 int uHelpMessage
= RegisterWindowMessage(MAKE_SEGPTR(HELPMSGSTRING
));
835 lpfr
= (LPFINDREPLACE
)GetWindowLong(hWnd
, DWL_USER
);
838 GetDlgItemText(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
839 if (IsDlgButtonChecked(hWnd
, rad2
))
840 lpfr
->Flags
|= FR_DOWN
;
841 else lpfr
->Flags
&= ~FR_DOWN
;
842 if (IsDlgButtonChecked(hWnd
, chx1
))
843 lpfr
->Flags
|= FR_WHOLEWORD
;
844 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
845 if (IsDlgButtonChecked(hWnd
, chx2
))
846 lpfr
->Flags
|= FR_MATCHCASE
;
847 else lpfr
->Flags
&= ~FR_MATCHCASE
;
848 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
849 lpfr
->Flags
|= FR_FINDNEXT
;
850 SendMessage(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
853 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
854 lpfr
->Flags
|= FR_DIALOGTERM
;
855 SendMessage(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
859 /* FIXME : should lpfr structure be passed as an argument ??? */
860 SendMessage(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
867 /***********************************************************************
868 * FindTextDlgProc (COMMDLG.13)
870 LRESULT
FindTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
874 return FINDDLG_WMInitDialog(hWnd
, wParam
, lParam
);
876 return FINDDLG_WMCommand(hWnd
, wParam
, lParam
);
882 /***********************************************************************
883 * REPLACEDLG_WMInitDialog [internal]
885 static LRESULT
REPLACEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
889 SetWindowLong(hWnd
, DWL_USER
, lParam
);
890 lpfr
= (LPFINDREPLACE
)lParam
;
891 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
893 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
894 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
897 SetDlgItemText(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
898 SetDlgItemText(hWnd
, edt2
, lpfr
->lpstrReplaceWith
);
899 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
900 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
901 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
902 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
903 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
904 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
905 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
906 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
907 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
908 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
909 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
910 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
911 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
913 ShowWindow(hWnd
, SW_SHOWNORMAL
);
918 /***********************************************************************
919 * REPLACEDLG_WMCommand [internal]
921 static LRESULT
REPLACEDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
924 int uFindReplaceMessage
= RegisterWindowMessage(MAKE_SEGPTR(FINDMSGSTRING
));
925 int uHelpMessage
= RegisterWindowMessage(MAKE_SEGPTR(HELPMSGSTRING
));
927 lpfr
= (LPFINDREPLACE
)GetWindowLong(hWnd
, DWL_USER
);
930 GetDlgItemText(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
931 GetDlgItemText(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
932 if (IsDlgButtonChecked(hWnd
, chx1
))
933 lpfr
->Flags
|= FR_WHOLEWORD
;
934 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
935 if (IsDlgButtonChecked(hWnd
, chx2
))
936 lpfr
->Flags
|= FR_MATCHCASE
;
937 else lpfr
->Flags
&= ~FR_MATCHCASE
;
938 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
939 lpfr
->Flags
|= FR_FINDNEXT
;
940 SendMessage(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
943 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
944 lpfr
->Flags
|= FR_DIALOGTERM
;
945 SendMessage(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
949 GetDlgItemText(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
950 GetDlgItemText(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
951 if (IsDlgButtonChecked(hWnd
, chx1
))
952 lpfr
->Flags
|= FR_WHOLEWORD
;
953 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
954 if (IsDlgButtonChecked(hWnd
, chx2
))
955 lpfr
->Flags
|= FR_MATCHCASE
;
956 else lpfr
->Flags
&= ~FR_MATCHCASE
;
957 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
958 lpfr
->Flags
|= FR_REPLACE
;
959 SendMessage(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
962 GetDlgItemText(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
963 GetDlgItemText(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
964 if (IsDlgButtonChecked(hWnd
, chx1
))
965 lpfr
->Flags
|= FR_WHOLEWORD
;
966 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
967 if (IsDlgButtonChecked(hWnd
, chx2
))
968 lpfr
->Flags
|= FR_MATCHCASE
;
969 else lpfr
->Flags
&= ~FR_MATCHCASE
;
970 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
971 lpfr
->Flags
|= FR_REPLACEALL
;
972 SendMessage(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
975 /* FIXME : should lpfr structure be passed as an argument ??? */
976 SendMessage(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
983 /***********************************************************************
984 * ReplaceTextDlgProc (COMMDLG.14)
986 LRESULT
ReplaceTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
990 return REPLACEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
992 return REPLACEDLG_WMCommand(hWnd
, wParam
, lParam
);
998 /***********************************************************************
999 * PrintDlg (COMMDLG.20)
1001 BOOL
PrintDlg(LPPRINTDLG lpPrint
)
1003 HANDLE hInst
, hDlgTmpl
;
1006 dprintf_commdlg(stddeb
,"PrintDlg(%p) // Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
1008 if (lpPrint
->Flags
& PD_RETURNDEFAULT
)
1009 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1012 if (lpPrint
->Flags
& PD_PRINTSETUP
)
1013 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP
);
1015 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT
);
1017 hInst
= WIN_GetWindowInstance( lpPrint
->hwndOwner
);
1018 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpPrint
->hwndOwner
,
1019 (lpPrint
->Flags
& PD_PRINTSETUP
) ?
1020 GetWndProcEntry16("PrintSetupDlgProc") :
1021 GetWndProcEntry16("PrintDlgProc"),
1023 SYSRES_FreeResource( hDlgTmpl
);
1028 /***********************************************************************
1029 * PrintDlgProc (COMMDLG.21)
1031 LRESULT
PrintDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
1036 dprintf_commdlg(stddeb
,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1037 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1043 EndDialog(hWnd
, TRUE
);
1046 EndDialog(hWnd
, FALSE
);
1055 /***********************************************************************
1056 * PrintSetupDlgProc (COMMDLG.22)
1058 LRESULT
PrintSetupDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
1063 dprintf_commdlg(stddeb
,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1064 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1069 EndDialog(hWnd
, TRUE
);
1072 EndDialog(hWnd
, FALSE
);
1081 /***********************************************************************
1082 * CommDlgExtendedError (COMMDLG.26)
1084 DWORD
CommDlgExtendedError(void)
1086 return CommDlgLastError
;
1090 /***********************************************************************
1091 * GetFileTitle (COMMDLG.27)
1093 short GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT cbBuf
)
1096 dprintf_commdlg(stddeb
,"GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
1097 if (lpFile
== NULL
|| lpTitle
== NULL
)
1099 len
= strlen(lpFile
);
1102 if (strpbrk(lpFile
, "*[]"))
1105 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
1107 for (i
= len
; i
>= 0; i
--)
1108 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
1113 dprintf_commdlg(stddeb
,"\n---> '%s' ", &lpFile
[i
]);
1115 len
= strlen(lpFile
+i
)+1;
1119 strncpy(lpTitle
, &lpFile
[i
], len
);