Release 950620
[wine] / misc / commdlg.c
1 /*
2  * COMMDLG functions
3  *
4  * Copyright 1994 Martin Ayotte
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "dialog.h"
11 #include "win.h"
12 #include "user.h"
13 #include "message.h"
14 #include "commdlg.h"
15 #include "dlgs.h"
16 #include "selectors.h"
17 #include "../rc/sysres.h"
18 #include "dos_fs.h"
19 #include "stackframe.h"
20
21 #define OPENFILEDLG2                    11
22 #define SAVEFILEDLG2                    12
23
24 static  DWORD           CommDlgLastError = 0;
25
26 static  HBITMAP         hFolder = 0;
27 static  HBITMAP         hFolder2 = 0;
28 static  HBITMAP         hFloppy = 0;
29 static  HBITMAP         hHDisk = 0;
30 static  HBITMAP         hCDRom = 0;
31
32 /***********************************************************************
33  *                              FileDlg_Init                    [internal]
34  */
35 static BOOL FileDlg_Init()
36 {
37     static BOOL initialized = 0;
38     
39     if (!initialized) {
40         if (!hFolder) hFolder = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER));
41         if (!hFolder2) hFolder2 = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2));
42         if (!hFloppy) hFloppy = LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY));
43         if (!hHDisk) hHDisk = LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK));
44         if (!hCDRom) hCDRom = LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM));
45         if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 || 
46             hHDisk == 0 || hCDRom == 0)
47         {       
48             fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
49             return FALSE;
50         }
51         initialized = TRUE;
52     }
53     return TRUE;
54 }
55
56 /***********************************************************************
57  *                              GetOpenFileName                 [COMMDLG.1]
58  */
59 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
60 {
61   HANDLE    hDlgTmpl;
62   HANDLE    hResInfo;
63   HINSTANCE hInst;
64   BOOL      bRet;
65   LPCSTR    dlgTemplate;
66   
67   if (!FileDlg_Init()) return FALSE;
68     
69   if (lpofn == NULL) return FALSE;
70   if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
71     dlgTemplate = GlobalLock(lpofn->hInstance);
72     if (!dlgTemplate) {
73       CommDlgLastError = CDERR_LOADRESFAILURE;
74       return FALSE;
75     }
76   } else {
77     if (lpofn->Flags & OFN_ENABLETEMPLATE) {
78       hInst = lpofn->hInstance;
79       hResInfo = FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG);
80       if (hResInfo == 0) {
81         CommDlgLastError = CDERR_FINDRESFAILURE;
82         return FALSE;
83       }
84       hDlgTmpl = LoadResource(hInst, hResInfo);
85       if (hDlgTmpl == 0) {
86         CommDlgLastError = CDERR_LOADRESFAILURE;
87         return FALSE;
88       }
89       dlgTemplate = GlobalLock(hDlgTmpl);
90     } else {
91       dlgTemplate = sysres_DIALOG_3;
92     }
93   }
94   hInst = GetWindowWord(lpofn->hwndOwner, GWW_HINSTANCE);
95   bRet = DialogBoxIndirectParamPtr(hInst, dlgTemplate, lpofn->hwndOwner,
96                                    GetWndProcEntry16("FileOpenDlgProc"),
97                                    (DWORD)lpofn);
98   
99   printf("GetOpenFileName // return lpstrFile='%s' !\n", 
100          (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
101   return bRet;
102 }
103
104
105 /***********************************************************************
106  *                              GetSaveFileName                 [COMMDLG.2]
107  */
108 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
109 {
110   HANDLE    hDlgTmpl;
111   HANDLE    hResInfo;
112   HINSTANCE hInst;
113   BOOL      bRet;
114   LPCSTR    dlgTemplate;
115   
116   if (!FileDlg_Init()) return FALSE;
117
118   if (lpofn == NULL) return FALSE;
119   if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
120     dlgTemplate = GlobalLock(lpofn->hInstance);
121     if (!dlgTemplate) {
122       CommDlgLastError = CDERR_LOADRESFAILURE;
123       return FALSE;
124     }
125   } else {
126     if (lpofn->Flags & OFN_ENABLETEMPLATE) {
127       hInst = lpofn->hInstance;
128       hResInfo = FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG);
129       if (hResInfo == 0) {
130         CommDlgLastError = CDERR_FINDRESFAILURE;
131         return FALSE;
132       }
133       hDlgTmpl = LoadResource(hInst, hResInfo);
134       if (hDlgTmpl == 0) {
135         CommDlgLastError = CDERR_LOADRESFAILURE;
136         return FALSE;
137       }
138       dlgTemplate = GlobalLock(hDlgTmpl);
139     } else {
140       dlgTemplate = sysres_DIALOG_4; /* SAVEFILEDIALOG */
141     }
142   }
143   hInst = GetWindowWord(lpofn->hwndOwner, GWW_HINSTANCE);
144   bRet = DialogBoxIndirectParamPtr(hInst, dlgTemplate, lpofn->hwndOwner,
145                                    GetWndProcEntry16("FileSaveDlgProc"),
146                                    (DWORD)lpofn); 
147   printf("GetSaveFileName // return lpstrFile='%s' !\n", 
148          (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
149   return bRet;
150 }
151
152 /***********************************************************************
153  *                              FILEDLG_StripEditControl        [internal]
154  * Strip pathnames off the contents of the edit control.
155  */
156 static void FILEDLG_StripEditControl(HWND hwnd)
157 {
158     char temp[512], *cp;
159
160     SendDlgItemMessage(hwnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(temp));
161     cp = strrchr(temp, '\\');
162     if (cp != NULL) {
163         strcpy(temp, cp+1);
164     }
165     cp = strrchr(temp, ':');
166     if (cp != NULL) {
167         strcpy(temp, cp+1);
168     }
169 }
170
171 /***********************************************************************
172  *                              FILEDLG_ScanDir                 [internal]
173  */
174 static BOOL FILEDLG_ScanDir(HWND hWnd, LPSTR newPath)
175 {
176   char str[512],str2[512];
177
178   strcpy(str,newPath);
179   SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(str2));
180   strcat(str, str2);
181   if (!DlgDirList(hWnd, str, lst1, 0, 0x0000)) return FALSE;
182   DlgDirList(hWnd, "*.*", lst2, stc1, 0x8010);
183   
184   return TRUE;
185 }
186
187 /***********************************************************************
188  *                              FILEDLG_GetFileType             [internal]
189  */
190 static LPSTR FILEDLG_GetFileType(LPSTR ptr, WORD index)
191 {
192     int n, i;
193     
194     if  (ptr == NULL) return NULL;
195     
196     for (i = 1;;i++) {
197         n = strlen(ptr);
198         if (n == 0) break;
199         ptr += n + 1;
200         if (i == index) return ptr;
201         n = strlen(ptr);
202         ptr += n + 1;
203     }
204     return NULL;
205 }
206
207 /***********************************************************************
208  *                              FILEDLG_WMDrawItem              [internal]
209  */
210 static LONG FILEDLG_WMDrawItem(HWND hWnd, WORD wParam, LONG lParam)
211 {
212     LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
213     char str[512];
214     HBRUSH hBrush;
215     HBITMAP hBitmap, hPrevBitmap;
216     BITMAP bm;
217     HDC hMemDC;
218
219     strcpy(str, "");
220     if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
221         hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
222         SelectObject(lpdis->hDC, hBrush);
223         FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
224         SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID, 
225                     MAKE_SEGPTR(str));
226         TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
227                 str, strlen(str));
228         if (lpdis->itemState != 0) {
229             InvertRect(lpdis->hDC, &lpdis->rcItem);
230         }
231         return TRUE;
232     }
233     
234     if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2) {
235         hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
236         SelectObject(lpdis->hDC, hBrush);
237         FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
238         SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID, 
239                     MAKE_SEGPTR(str));
240
241         hBitmap = hFolder;
242         GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
243         TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth, 
244                 lpdis->rcItem.top, str, strlen(str));
245         hMemDC = CreateCompatibleDC(lpdis->hDC);
246         hPrevBitmap = SelectObject(hMemDC, hBitmap);
247         BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
248                bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
249         SelectObject(hMemDC, hPrevBitmap);
250         DeleteDC(hMemDC);
251         if (lpdis->itemState != 0) {
252             InvertRect(lpdis->hDC, &lpdis->rcItem);
253         }
254         return TRUE;
255     }
256     if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2) {
257         hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
258         SelectObject(lpdis->hDC, hBrush);
259         FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
260         SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID, 
261                     MAKE_SEGPTR(str));
262         switch(str[2]) {
263          case 'a': case 'b':
264             hBitmap = hFloppy;
265             break;
266          default:
267             hBitmap = hHDisk;
268             break;
269         }
270         GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
271         TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth, 
272                 lpdis->rcItem.top, str, strlen(str));
273         hMemDC = CreateCompatibleDC(lpdis->hDC);
274         hPrevBitmap = SelectObject(hMemDC, hBitmap);
275         BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
276                bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
277         SelectObject(hMemDC, hPrevBitmap);
278         DeleteDC(hMemDC);
279         if (lpdis->itemState != 0) {
280             InvertRect(lpdis->hDC, &lpdis->rcItem);
281         }
282         return TRUE;
283     }
284     return FALSE;
285 }
286
287 /***********************************************************************
288  *                              FILEDLG_WMMeasureItem           [internal]
289  */
290 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WORD wParam, LONG lParam) 
291 {
292     BITMAP bm;
293     LPMEASUREITEMSTRUCT lpmeasure;
294     
295     GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
296     lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
297     lpmeasure->itemHeight = bm.bmHeight;
298     return TRUE;
299 }
300
301 /***********************************************************************
302  *                              FILEDLG_WMInitDialog            [internal]
303  */
304 static LONG FILEDLG_WMInitDialog(HWND hWnd, WORD wParam, LONG lParam) 
305 {
306     int n;
307     LPOPENFILENAME lpofn;
308     char tmpstr[512];
309     LPSTR pstr;
310     
311     SetWindowLong(hWnd, DWL_USER, lParam);
312     lpofn = (LPOPENFILENAME)lParam;
313     
314     /* read filter information */
315     pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
316     while(*pstr) {
317       n = strlen(pstr);
318       strcpy(tmpstr, pstr);
319       SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, MAKE_SEGPTR(tmpstr));
320       pstr += n + 1;
321       n = strlen(pstr);
322       pstr += n + 1;
323     }
324       
325     /* set default filter */
326     SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
327                        lpofn->nFilterIndex - 1, 0);
328     strcpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), 
329                                        lpofn->nFilterIndex));
330     SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
331       
332     /* get drive list */
333     strcpy(tmpstr,"");
334     DlgDirListComboBox(hWnd, MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
335
336     /* read initial directory */
337     if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL) {
338         strcpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir));
339         if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\' 
340             && tmpstr[strlen(tmpstr)-1] != ':')
341         {
342             strcat(tmpstr,"\\");
343         }
344     } else {
345         strcpy(tmpstr,"");
346     }
347     if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
348         fprintf(stderr, "FileDlg: couldn't read initial directory!\n");
349     } 
350
351     /* select current drive in combo 2 */
352     n = DOS_GetDefaultDrive();
353     SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, n, 0);
354     
355     if (!(lpofn->Flags & OFN_SHOWHELP)) {
356       ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
357     }
358     if (lpofn->Flags & OFN_HIDEREADONLY) {
359       ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE); 
360     }
361     return TRUE;
362 }
363
364 /***********************************************************************
365  *                              FILEDLG_WMCommand               [internal]
366  */
367 static LONG FILEDLG_WMCommand(HWND hWnd, WORD wParam, LONG lParam) 
368 {
369     LONG lRet;
370     LPOPENFILENAME lpofn;
371     char tmpstr[512], tmpstr2[512];
372     LPSTR pstr, pstr2;
373     
374     lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
375     switch (wParam) {
376      case lst1:
377         FILEDLG_StripEditControl(hWnd);
378         if (HIWORD(lParam) == LBN_DBLCLK) {
379             lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
380             if (lRet == LB_ERR) return TRUE;
381             SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
382             SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
383             return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
384         }
385         return TRUE;
386      case lst2:
387         FILEDLG_StripEditControl(hWnd);
388         if (HIWORD(lParam) == LBN_DBLCLK) {
389             lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
390             if (lRet == LB_ERR) return TRUE;
391             SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
392             
393             if (tmpstr[0] == '[') {
394                 tmpstr[strlen(tmpstr) - 1] = 0;
395                 strcpy(tmpstr,tmpstr+1);
396             }
397             strcat(tmpstr, "\\");
398             FILEDLG_ScanDir(hWnd, tmpstr);
399         }
400         return TRUE;
401         
402      case cmb1:
403         if (HIWORD(lParam) == CBN_SELCHANGE) {
404             lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
405             if (lRet == LB_ERR) return TRUE;
406             strcpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter), 
407                                                lRet + 1));
408             SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
409             FILEDLG_ScanDir(hWnd, "");
410         }
411         return TRUE;
412         
413      case cmb2:
414         FILEDLG_StripEditControl(hWnd);
415         lRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
416         if (lRet == LB_ERR) return 0;
417         SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, MAKE_SEGPTR(tmpstr));
418         sprintf(tmpstr, "%c:", tmpstr[2]);
419         FILEDLG_ScanDir(hWnd, tmpstr);
420         return TRUE;
421         
422      case chx1:
423         return TRUE;
424         
425      case pshHelp:
426         return TRUE;
427
428      case IDOK:
429         SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(tmpstr));
430
431         pstr = strrchr(tmpstr, '\\');
432         if (pstr == NULL) pstr = strrchr(tmpstr, ':');
433         
434         if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL) {
435             /* edit control contains wildcards */
436             if (pstr != NULL) {
437                 strcpy(tmpstr2, pstr+1);
438                 *(pstr+1) = 0;
439             } else {
440                 strcpy(tmpstr2, tmpstr);
441                 strcpy(tmpstr, "");
442             }
443             printf("commdlg: %s, %s\n", tmpstr, tmpstr2);
444             SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
445             FILEDLG_ScanDir(hWnd, tmpstr);
446             return TRUE;
447         }
448
449         /* no wildcards, we might have a directory or a filename */
450         /* try appending a wildcard and reading the directory */
451         pstr2 = tmpstr + strlen(tmpstr);
452         if (pstr == NULL || *(pstr+1) != 0) {
453             strcat(tmpstr, "\\");
454         }
455         lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
456         if (lRet == LB_ERR) return TRUE;
457         strcpy(tmpstr2, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter),
458                                             lRet + 1));
459         SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
460         /* if ScanDir succeeds, we have changed the directory */
461         if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
462         
463         /* if not, this must be a filename */
464         *pstr2 = 0;
465         
466         if (pstr != NULL) {
467             /* strip off the pathname */
468             *pstr = 0;
469             strcpy(tmpstr2, pstr+1);
470             SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
471             /* Should we MessageBox() if this fails? */
472             if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
473             strcpy(tmpstr, tmpstr2);
474         } else {
475             SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
476         }
477         
478         ShowWindow(hWnd, SW_HIDE);
479         strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr);
480         lpofn->nFileOffset = 0;
481         lpofn->nFileExtension = strlen(PTR_SEG_TO_LIN(lpofn->lpstrFile)) - 3;
482         if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) {
483             lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
484             SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
485             strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
486         }
487         EndDialog(hWnd, TRUE);
488         return TRUE;
489      case IDCANCEL:
490         EndDialog(hWnd, FALSE);
491         return TRUE;
492     }
493     return FALSE;
494 }
495
496 /***********************************************************************
497  *                              FileOpenDlgProc                 [COMMDLG.6]
498  */
499 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
500 {  
501   switch (wMsg) {
502    case WM_INITDIALOG:
503       return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
504       
505    case WM_MEASUREITEM:
506       return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
507     
508    case WM_DRAWITEM:
509       return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
510
511    case WM_COMMAND:
512       return FILEDLG_WMCommand(hWnd, wParam, lParam);
513   }
514   
515   /*
516   case WM_CTLCOLOR:
517    SetBkColor((HDC)wParam, 0x00C0C0C0);
518    switch (HIWORD(lParam))
519    {
520     case CTLCOLOR_BTN:
521      SetTextColor((HDC)wParam, 0x00000000);
522      return hGRAYBrush;
523     case CTLCOLOR_STATIC:
524      SetTextColor((HDC)wParam, 0x00000000);
525      return hGRAYBrush;
526    }
527    return FALSE;
528    
529    */
530   return FALSE;
531 }
532
533
534 /***********************************************************************
535  *                              FileSaveDlgProc                 [COMMDLG.7]
536  */
537 BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
538 {
539   switch (wMsg) {
540    case WM_INITDIALOG:
541       return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
542       
543    case WM_MEASUREITEM:
544       return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
545     
546    case WM_DRAWITEM:
547       return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
548
549    case WM_COMMAND:
550       return FILEDLG_WMCommand(hWnd, wParam, lParam);
551   }
552   
553   /*
554   case WM_CTLCOLOR:
555    SetBkColor((HDC)wParam, 0x00C0C0C0);
556    switch (HIWORD(lParam))
557    {
558     case CTLCOLOR_BTN:
559      SetTextColor((HDC)wParam, 0x00000000);
560      return hGRAYBrush;
561     case CTLCOLOR_STATIC:
562      SetTextColor((HDC)wParam, 0x00000000);
563      return hGRAYBrush;
564    }
565    return FALSE;
566    
567    */
568   return FALSE;
569 }
570
571
572 /***********************************************************************
573  *                              ChooseColor                             [COMMDLG.5]
574  */
575 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
576 {
577         WND     *wndPtr;
578         BOOL    bRet;
579         wndPtr = WIN_FindWndPtr(lpChCol->hwndOwner);
580         bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, sysres_DIALOG_8,
581                 lpChCol->hwndOwner, GetWndProcEntry16("ColorDlgProc"), 
582                 (DWORD)lpChCol);
583         return bRet;
584 }
585
586
587 /***********************************************************************
588  *                              ColorDlgProc                    [COMMDLG.8]
589  */
590 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
591 {
592         switch (wMsg) {
593                 case WM_INITDIALOG:
594                         printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
595                         ShowWindow(hWnd, SW_SHOWNORMAL);
596                         return (TRUE);
597
598                 case WM_COMMAND:
599                         switch (wParam) {
600                                 case IDOK:
601                                         EndDialog(hWnd, TRUE);
602                                         return(TRUE);
603                                 case IDCANCEL:
604                                         EndDialog(hWnd, FALSE);
605                                         return(TRUE);
606                                 }
607                         return(FALSE);
608                 }
609         return FALSE;
610 }
611
612
613 /***********************************************************************
614  *                              FindTextDlg                             [COMMDLG.11]
615  */
616 BOOL FindText(LPFINDREPLACE lpFind)
617 {
618   WND    *wndPtr;
619   BOOL   bRet;
620   LPCSTR lpTemplate;
621   
622   lpTemplate = sysres_DIALOG_9;
623   wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
624   bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
625                                 lpFind->hwndOwner, GetWndProcEntry16("FindTextDlgProc"),
626                                 (DWORD)lpFind);
627   return bRet;
628 }
629
630
631 /***********************************************************************
632  *                              ReplaceTextDlg                  [COMMDLG.12]
633  */
634 BOOL ReplaceText(LPFINDREPLACE lpFind)
635 {
636   WND    *wndPtr;
637   BOOL   bRet;
638   LPCSTR lpTemplate;
639
640   lpTemplate = sysres_DIALOG_10;
641   wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
642   bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
643                                    lpFind->hwndOwner, GetWndProcEntry16("ReplaceTextDlgProc"),
644                                    (DWORD)lpFind);
645   return bRet;
646 }
647
648
649 /***********************************************************************
650  *                              FindTextDlgProc                 [COMMDLG.13]
651  */
652 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
653 {
654   switch (wMsg) {
655    case WM_INITDIALOG:
656     printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
657     ShowWindow(hWnd, SW_SHOWNORMAL);
658     return (TRUE);
659     
660    case WM_COMMAND:
661     switch (wParam) {
662      case IDOK:
663       EndDialog(hWnd, TRUE);
664       return(TRUE);
665      case IDCANCEL:
666       EndDialog(hWnd, FALSE);
667       return(TRUE);
668     }
669     return(FALSE);
670   }
671   return FALSE;
672 }
673
674
675 /***********************************************************************
676  *                              ReplaceTextDlgProc              [COMMDLG.14]
677  */
678 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
679 {
680   switch (wMsg) {
681    case WM_INITDIALOG:
682     printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
683     ShowWindow(hWnd, SW_SHOWNORMAL);
684     return (TRUE);
685     
686    case WM_COMMAND:
687     switch (wParam) {
688      case IDOK:
689       EndDialog(hWnd, TRUE);
690       return(TRUE);
691      case IDCANCEL:
692       EndDialog(hWnd, FALSE);
693       return(TRUE);
694     }
695     return(FALSE);
696   }
697   return FALSE;
698 }
699
700
701 /***********************************************************************
702  *                              PrintDlg                                [COMMDLG.20]
703  */
704 BOOL PrintDlg(LPPRINTDLG lpPrint)
705 {
706   WND    *wndPtr;
707   BOOL   bRet;
708   LPCSTR lpTemplate;
709   
710   printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags);
711   if (lpPrint->Flags & PD_PRINTSETUP)  {
712     lpTemplate = sysres_DIALOG_6;
713   } else  {
714     lpTemplate = sysres_DIALOG_5;
715   }
716   wndPtr = WIN_FindWndPtr(lpPrint->hwndOwner);
717   if (lpPrint->Flags & PD_PRINTSETUP)
718   bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
719                                    lpPrint->hwndOwner, GetWndProcEntry16("PrintSetupDlgProc"),
720                                    (DWORD)lpPrint);
721   else
722   bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
723                                    lpPrint->hwndOwner, GetWndProcEntry16("PrintDlgProc"),
724                                    (DWORD)lpPrint);
725   return bRet;
726 }
727
728
729 /***********************************************************************
730  *                              PrintDlgProc                    [COMMDLG.21]
731  */
732 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
733 {
734   switch (wMsg) {
735    case WM_INITDIALOG:
736     printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
737     ShowWindow(hWnd, SW_SHOWNORMAL);
738     return (TRUE);
739     
740    case WM_COMMAND:
741     switch (wParam) {
742      case IDOK:
743       EndDialog(hWnd, TRUE);
744       return(TRUE);
745      case IDCANCEL:
746       EndDialog(hWnd, FALSE);
747       return(TRUE);
748     }
749     return(FALSE);
750   }
751   return FALSE;
752 }
753
754
755 /***********************************************************************
756  *                              PrintSetupDlgProc               [COMMDLG.22]
757  */
758 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
759 {
760   switch (wMsg) {
761    case WM_INITDIALOG:
762     printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
763     ShowWindow(hWnd, SW_SHOWNORMAL);
764     return (TRUE);
765     
766    case WM_COMMAND:
767     switch (wParam) {
768      case IDOK:
769       EndDialog(hWnd, TRUE);
770       return(TRUE);
771      case IDCANCEL:
772       EndDialog(hWnd, FALSE);
773       return(TRUE);
774     }
775     return(FALSE);
776   }
777   return FALSE;
778 }
779
780
781 /***********************************************************************
782  *                              CommDlgExtendError              [COMMDLG.26]
783  */
784 DWORD CommDlgExtendError(void)
785 {
786         return CommDlgLastError;
787 }
788
789
790 /***********************************************************************
791  *                              GetFileTitle                    [COMMDLG.27]
792  */
793 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
794 {
795         int     i, len;
796         printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
797         if (lpFile == NULL || lpTitle == NULL) return -1;
798         len = strlen(lpFile);
799         if (len == 0) return -1;
800         if (strchr(lpFile, '*') != NULL) return -1;
801         if (strchr(lpFile, '[') != NULL) return -1;
802         if (strchr(lpFile, ']') != NULL) return -1;
803         len--;
804         if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') return -1;
805         for (i = len; i >= 0; i--) {
806           if (lpFile[i] == '/' ||  lpFile[i] == '\\' ||  lpFile[i] == ':') {
807             i++;
808             break;
809           }
810         }
811         printf("\n---> '%s' ", &lpFile[i]);
812         len = min(cbBuf, strlen(&lpFile[i]) + 1);
813         strncpy(lpTitle, &lpFile[i], len + 1);
814         if (len != cbBuf)
815                 return len;
816         else
817                 return 0;
818 }