Release 951003
[wine/hacks.git] / misc / commdlg.c
blobf85624fb61ce5948ddaafc55be544c425e0c9f84
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "win.h"
11 #include "user.h"
12 #include "global.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"
21 static DWORD CommDlgLastError = 0;
23 static HBITMAP hFolder = 0;
24 static HBITMAP hFolder2 = 0;
25 static HBITMAP hFloppy = 0;
26 static HBITMAP hHDisk = 0;
27 static HBITMAP hCDRom = 0;
29 /***********************************************************************
30 * FileDlg_Init [internal]
32 static BOOL FileDlg_Init()
34 static BOOL initialized = 0;
36 if (!initialized) {
37 if (!hFolder) hFolder = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER));
38 if (!hFolder2) hFolder2 = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2));
39 if (!hFloppy) hFloppy = LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY));
40 if (!hHDisk) hHDisk = LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK));
41 if (!hCDRom) hCDRom = LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM));
42 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
43 hHDisk == 0 || hCDRom == 0)
45 fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
46 return FALSE;
48 initialized = TRUE;
50 return TRUE;
53 /***********************************************************************
54 * GetOpenFileName (COMMDLG.1)
56 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
58 HINSTANCE hInst;
59 HANDLE hDlgTmpl, hResInfo;
60 BOOL bRet;
62 if (!lpofn || !FileDlg_Init()) return FALSE;
64 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
65 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
67 if (!(hResInfo = FindResource( lpofn->hInstance,
68 lpofn->lpTemplateName, RT_DIALOG)))
70 CommDlgLastError = CDERR_FINDRESFAILURE;
71 return FALSE;
73 hDlgTmpl = LoadResource( lpofn->hInstance, hResInfo );
75 else hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED,
76 sysres_DIALOG_OPEN_FILE.bytes,
77 sysres_DIALOG_OPEN_FILE.size,
78 GetCurrentPDB(), FALSE, FALSE,
79 TRUE, NULL );
80 if (!hDlgTmpl)
82 CommDlgLastError = CDERR_LOADRESFAILURE;
83 return FALSE;
86 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
87 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
88 GetWndProcEntry16("FileOpenDlgProc"),
89 (DWORD)lpofn );
91 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
93 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( hDlgTmpl );
94 else GLOBAL_FreeBlock( hDlgTmpl );
97 printf("GetOpenFileName // return lpstrFile='%s' !\n",
98 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
99 return bRet;
103 /***********************************************************************
104 * GetSaveFileName (COMMDLG.2)
106 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
108 HINSTANCE hInst;
109 HANDLE hDlgTmpl, hResInfo;
110 BOOL bRet;
112 if (!lpofn || !FileDlg_Init()) return FALSE;
114 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
115 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
117 hInst = lpofn->hInstance;
118 if (!(hResInfo = FindResource( lpofn->hInstance,
119 lpofn->lpTemplateName, RT_DIALOG )))
121 CommDlgLastError = CDERR_FINDRESFAILURE;
122 return FALSE;
124 hDlgTmpl = LoadResource( lpofn->hInstance, hResInfo );
126 else hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED,
127 sysres_DIALOG_SAVE_FILE.bytes,
128 sysres_DIALOG_SAVE_FILE.size,
129 GetCurrentPDB(), FALSE, FALSE,
130 TRUE, NULL );
133 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
134 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
135 GetWndProcEntry16("FileSaveDlgProc"),
136 (DWORD)lpofn);
137 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
139 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( hDlgTmpl );
140 else GLOBAL_FreeBlock( hDlgTmpl );
143 printf( "GetSaveFileName // return lpstrFile='%s' !\n",
144 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
145 return bRet;
148 /***********************************************************************
149 * FILEDLG_StripEditControl [internal]
150 * Strip pathnames off the contents of the edit control.
152 static void FILEDLG_StripEditControl(HWND hwnd)
154 char temp[512], *cp;
156 SendDlgItemMessage(hwnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(temp));
157 cp = strrchr(temp, '\\');
158 if (cp != NULL) {
159 strcpy(temp, cp+1);
161 cp = strrchr(temp, ':');
162 if (cp != NULL) {
163 strcpy(temp, cp+1);
167 /***********************************************************************
168 * FILEDLG_ScanDir [internal]
170 static BOOL FILEDLG_ScanDir(HWND hWnd, LPSTR newPath)
172 char str[512],str2[512];
174 strcpy(str,newPath);
175 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(str2));
176 strcat(str, str2);
177 if (!DlgDirList(hWnd, str, lst1, 0, 0x0000)) return FALSE;
178 DlgDirList(hWnd, "*.*", lst2, stc1, 0x8010);
180 return TRUE;
183 /***********************************************************************
184 * FILEDLG_GetFileType [internal]
187 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
189 int n, i;
190 i = 0;
191 if (cfptr)
192 for ( ;(n = strlen(cfptr)) != 0; i++)
194 cfptr += n + 1;
195 if (i == index)
196 return cfptr;
197 cfptr += strlen(cfptr) + 1;
199 if (fptr)
200 for ( ;(n = strlen(fptr)) != 0; i++)
202 fptr += n + 1;
203 if (i == index)
204 return fptr;
205 fptr += strlen(fptr) + 1;
207 return NULL;
210 /***********************************************************************
211 * FILEDLG_WMDrawItem [internal]
213 static LONG FILEDLG_WMDrawItem(HWND hWnd, WORD wParam, LONG lParam)
215 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
216 char str[512];
217 HBRUSH hBrush;
218 HBITMAP hBitmap, hPrevBitmap;
219 BITMAP bm;
220 HDC hMemDC;
222 strcpy(str, "");
223 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
224 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
225 SelectObject(lpdis->hDC, hBrush);
226 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
227 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
228 MAKE_SEGPTR(str));
229 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
230 str, strlen(str));
231 if (lpdis->itemState != 0) {
232 InvertRect(lpdis->hDC, &lpdis->rcItem);
234 return TRUE;
237 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2) {
238 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
239 SelectObject(lpdis->hDC, hBrush);
240 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
241 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
242 MAKE_SEGPTR(str));
244 hBitmap = hFolder;
245 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
246 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
247 lpdis->rcItem.top, str, strlen(str));
248 hMemDC = CreateCompatibleDC(lpdis->hDC);
249 hPrevBitmap = SelectObject(hMemDC, hBitmap);
250 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
251 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
252 SelectObject(hMemDC, hPrevBitmap);
253 DeleteDC(hMemDC);
254 if (lpdis->itemState != 0) {
255 InvertRect(lpdis->hDC, &lpdis->rcItem);
257 return TRUE;
259 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2) {
260 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
261 SelectObject(lpdis->hDC, hBrush);
262 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
263 SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
264 MAKE_SEGPTR(str));
265 switch(str[2]) {
266 case 'a': case 'b':
267 hBitmap = hFloppy;
268 break;
269 default:
270 hBitmap = hHDisk;
271 break;
273 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
274 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
275 lpdis->rcItem.top, str, strlen(str));
276 hMemDC = CreateCompatibleDC(lpdis->hDC);
277 hPrevBitmap = SelectObject(hMemDC, hBitmap);
278 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
279 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
280 SelectObject(hMemDC, hPrevBitmap);
281 DeleteDC(hMemDC);
282 if (lpdis->itemState != 0) {
283 InvertRect(lpdis->hDC, &lpdis->rcItem);
285 return TRUE;
287 return FALSE;
290 /***********************************************************************
291 * FILEDLG_WMMeasureItem [internal]
293 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WORD wParam, LONG lParam)
295 BITMAP bm;
296 LPMEASUREITEMSTRUCT lpmeasure;
298 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
299 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
300 lpmeasure->itemHeight = bm.bmHeight;
301 return TRUE;
304 /***********************************************************************
305 * FILEDLG_WMInitDialog [internal]
308 static LONG FILEDLG_WMInitDialog(HWND hWnd, WORD wParam, LONG lParam)
310 int n;
311 LPOPENFILENAME lpofn;
312 char tmpstr[512];
313 LPSTR pstr;
314 SetWindowLong(hWnd, DWL_USER, lParam);
315 lpofn = (LPOPENFILENAME)lParam;
316 /* read custom filter information */
317 if (lpofn->lpstrCustomFilter)
319 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
320 printf("lpstrCustomFilter = %p\n", pstr);
321 while(*pstr)
323 n = strlen(pstr);
324 strcpy(tmpstr, pstr);
325 printf("lpstrCustomFilter // add tmpstr='%s' ", tmpstr);
326 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, MAKE_SEGPTR(tmpstr));
327 pstr += n + 1;
328 n = strlen(pstr);
329 printf("associated to '%s'\n", pstr);
330 pstr += n + 1;
333 /* read filter information */
334 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
335 while(*pstr)
337 n = strlen(pstr);
338 strcpy(tmpstr, pstr);
339 printf("lpstrFilter // add tmpstr='%s' ", tmpstr);
340 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, MAKE_SEGPTR(tmpstr));
341 pstr += n + 1;
342 n = strlen(pstr);
343 printf("associated to '%s'\n", pstr);
344 pstr += n + 1;
346 /* set default filter */
347 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
348 lpofn->nFilterIndex = 1;
349 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL, lpofn->nFilterIndex - 1, 0);
350 strcpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
351 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1));
352 printf("nFilterIndex = %ld // SetText of edt1 to '%s'\n",
353 lpofn->nFilterIndex, tmpstr);
354 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
355 /* get drive list */
356 *tmpstr = 0;
357 DlgDirListComboBox(hWnd, MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
358 /* read initial directory */
359 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
361 strcpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir));
362 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
363 && tmpstr[strlen(tmpstr)-1] != ':')
364 strcat(tmpstr,"\\");
366 else
367 *tmpstr = 0;
368 if (!FILEDLG_ScanDir(hWnd, tmpstr))
369 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
370 /* select current drive in combo 2 */
371 n = DOS_GetDefaultDrive();
372 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, n, 0);
373 if (!(lpofn->Flags & OFN_SHOWHELP))
374 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
375 if (lpofn->Flags & OFN_HIDEREADONLY)
376 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
377 return TRUE;
380 /***********************************************************************
381 * FILEDLG_WMCommand [internal]
383 static LONG FILEDLG_WMCommand(HWND hWnd, WORD wParam, LONG lParam)
385 LONG lRet;
386 LPOPENFILENAME lpofn;
387 char tmpstr[512], tmpstr2[512];
388 LPSTR pstr, pstr2;
390 lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
391 switch (wParam)
393 case lst1: /* file list */
394 FILEDLG_StripEditControl(hWnd);
395 if (HIWORD(lParam) == LBN_DBLCLK)
396 goto almost_ok;
397 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
398 if (lRet == LB_ERR) return TRUE;
399 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
400 MAKE_SEGPTR(tmpstr));
401 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
402 return TRUE;
403 case lst2: /* directory list */
404 FILEDLG_StripEditControl(hWnd);
405 if (HIWORD(lParam) == LBN_DBLCLK)
407 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
408 if (lRet == LB_ERR) return TRUE;
409 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet,
410 MAKE_SEGPTR(tmpstr));
411 if (tmpstr[0] == '[')
413 tmpstr[strlen(tmpstr) - 1] = 0;
414 strcpy(tmpstr,tmpstr+1);
416 strcat(tmpstr, "\\");
417 goto reset_scan;
419 return TRUE;
420 case cmb1: /* file type drop list */
421 if (HIWORD(lParam) == CBN_SELCHANGE)
423 *tmpstr = 0;
424 goto reset_scan;
426 return TRUE;
427 case cmb2: /* disk drop list */
428 FILEDLG_StripEditControl(hWnd);
429 lRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
430 if (lRet == LB_ERR) return 0;
431 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, MAKE_SEGPTR(tmpstr));
432 sprintf(tmpstr, "%c:", tmpstr[2]);
433 reset_scan:
434 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
435 if (lRet == LB_ERR)
436 return TRUE;
437 pstr = FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
438 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
439 lRet);
440 strcpy(tmpstr2, pstr);
441 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
442 FILEDLG_ScanDir(hWnd, tmpstr);
443 return TRUE;
444 case chx1:
445 return TRUE;
446 case pshHelp:
447 return TRUE;
448 case IDOK:
449 almost_ok:
450 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(tmpstr));
451 pstr = strrchr(tmpstr, '\\');
452 if (pstr == NULL)
453 pstr = strrchr(tmpstr, ':');
454 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
456 /* edit control contains wildcards */
457 if (pstr != NULL)
459 strcpy(tmpstr2, pstr+1);
460 *(pstr+1) = 0;
462 else
464 strcpy(tmpstr2, tmpstr);
465 strcpy(tmpstr, "");
467 printf("commdlg: %s, %s\n", tmpstr, tmpstr2);
468 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
469 FILEDLG_ScanDir(hWnd, tmpstr);
470 return TRUE;
472 /* no wildcards, we might have a directory or a filename */
473 /* try appending a wildcard and reading the directory */
474 pstr2 = tmpstr + strlen(tmpstr);
475 if (pstr == NULL || *(pstr+1) != 0)
476 strcat(tmpstr, "\\");
477 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
478 if (lRet == LB_ERR) return TRUE;
479 lpofn->nFilterIndex = lRet + 1;
480 printf("commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
481 strcpy(tmpstr2,
482 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
483 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
484 lRet));
485 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
486 /* if ScanDir succeeds, we have changed the directory */
487 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
488 /* if not, this must be a filename */
489 *pstr2 = 0;
490 if (pstr != NULL)
492 /* strip off the pathname */
493 *pstr = 0;
494 strcpy(tmpstr2, pstr+1);
495 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
496 /* Should we MessageBox() if this fails? */
497 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
498 strcpy(tmpstr, tmpstr2);
500 else
501 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
502 ShowWindow(hWnd, SW_HIDE);
504 int drive;
505 drive = DOS_GetDefaultDrive();
506 tmpstr2[0] = 'A'+ drive;
507 tmpstr2[1] = ':';
508 tmpstr2[2] = '\\';
509 strcpy(tmpstr2 + 3, DOS_GetCurrentDir(drive));
510 if (strlen(tmpstr2) > 3)
511 strcat(tmpstr2, "\\");
512 strcat(tmpstr2, tmpstr);
513 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
515 lpofn->nFileOffset = 0;
516 lpofn->nFileExtension = 0;
517 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
518 lpofn->nFileExtension++;
519 if (lpofn->nFileExtension == '\0')
520 lpofn->nFileExtension = 0;
521 else
522 lpofn->nFileExtension++;
523 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
525 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
526 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
527 MAKE_SEGPTR(tmpstr));
528 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
530 EndDialog(hWnd, TRUE);
531 return TRUE;
532 case IDCANCEL:
533 EndDialog(hWnd, FALSE);
534 return TRUE;
536 return FALSE;
540 /***********************************************************************
541 * FileOpenDlgProc (COMMDLG.6)
543 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
545 switch (wMsg)
547 case WM_INITDIALOG:
548 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
549 case WM_MEASUREITEM:
550 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
551 case WM_DRAWITEM:
552 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
553 case WM_COMMAND:
554 return FILEDLG_WMCommand(hWnd, wParam, lParam);
555 #if 0
556 case WM_CTLCOLOR:
557 SetBkColor((HDC)wParam, 0x00C0C0C0);
558 switch (HIWORD(lParam))
560 case CTLCOLOR_BTN:
561 SetTextColor((HDC)wParam, 0x00000000);
562 return hGRAYBrush;
563 case CTLCOLOR_STATIC:
564 SetTextColor((HDC)wParam, 0x00000000);
565 return hGRAYBrush;
567 break;
568 #endif
570 return FALSE;
574 /***********************************************************************
575 * FileSaveDlgProc (COMMDLG.7)
577 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
579 switch (wMsg) {
580 case WM_INITDIALOG:
581 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
583 case WM_MEASUREITEM:
584 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
586 case WM_DRAWITEM:
587 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
589 case WM_COMMAND:
590 return FILEDLG_WMCommand(hWnd, wParam, lParam);
594 case WM_CTLCOLOR:
595 SetBkColor((HDC)wParam, 0x00C0C0C0);
596 switch (HIWORD(lParam))
598 case CTLCOLOR_BTN:
599 SetTextColor((HDC)wParam, 0x00000000);
600 return hGRAYBrush;
601 case CTLCOLOR_STATIC:
602 SetTextColor((HDC)wParam, 0x00000000);
603 return hGRAYBrush;
605 return FALSE;
608 return FALSE;
612 /***********************************************************************
613 * ChooseColor (COMMDLG.5)
615 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
617 HANDLE hInst, hDlgTmpl;
618 BOOL bRet;
620 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_CHOOSE_COLOR.bytes,
621 sysres_DIALOG_CHOOSE_COLOR.size,
622 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
623 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
624 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
625 GetWndProcEntry16("ColorDlgProc"),
626 (DWORD)lpChCol );
627 GLOBAL_FreeBlock( hDlgTmpl );
628 return bRet;
632 /***********************************************************************
633 * ColorDlgProc (COMMDLG.8)
635 LRESULT ColorDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
637 switch (wMsg)
639 case WM_INITDIALOG:
640 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
641 ShowWindow(hWnd, SW_SHOWNORMAL);
642 return (TRUE);
643 case WM_COMMAND:
644 switch (wParam)
646 case IDOK:
647 EndDialog(hWnd, TRUE);
648 return(TRUE);
649 case IDCANCEL:
650 EndDialog(hWnd, FALSE);
651 return(TRUE);
653 return(FALSE);
655 return FALSE;
659 /***********************************************************************
660 * FindTextDlg (COMMDLG.11)
662 BOOL FindText(LPFINDREPLACE lpFind)
664 HANDLE hInst, hDlgTmpl;
665 BOOL bRet;
667 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_FIND_TEXT.bytes,
668 sysres_DIALOG_FIND_TEXT.size,
669 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
670 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
671 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
672 GetWndProcEntry16("FindTextDlgProc"),
673 (DWORD)lpFind );
674 GLOBAL_FreeBlock( hDlgTmpl );
675 return bRet;
679 /***********************************************************************
680 * ReplaceTextDlg (COMMDLG.12)
682 BOOL ReplaceText(LPFINDREPLACE lpFind)
684 HANDLE hInst, hDlgTmpl;
685 BOOL bRet;
687 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_REPLACE_TEXT.bytes,
688 sysres_DIALOG_REPLACE_TEXT.size,
689 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
690 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
691 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
692 GetWndProcEntry16("ReplaceTextDlgProc"),
693 (DWORD)lpFind );
694 GLOBAL_FreeBlock( hDlgTmpl );
695 return bRet;
699 /***********************************************************************
700 * FindTextDlgProc (COMMDLG.13)
702 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
704 switch (wMsg)
706 case WM_INITDIALOG:
707 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
708 ShowWindow(hWnd, SW_SHOWNORMAL);
709 return (TRUE);
710 case WM_COMMAND:
711 switch (wParam)
713 case IDOK:
714 EndDialog(hWnd, TRUE);
715 return(TRUE);
716 case IDCANCEL:
717 EndDialog(hWnd, FALSE);
718 return(TRUE);
720 return(FALSE);
722 return FALSE;
726 /***********************************************************************
727 * ReplaceTextDlgProc (COMMDLG.14)
729 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
731 switch (wMsg)
733 case WM_INITDIALOG:
734 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
735 ShowWindow(hWnd, SW_SHOWNORMAL);
736 return (TRUE);
737 case WM_COMMAND:
738 switch (wParam)
740 case IDOK:
741 EndDialog(hWnd, TRUE);
742 return(TRUE);
743 case IDCANCEL:
744 EndDialog(hWnd, FALSE);
745 return(TRUE);
747 return(FALSE);
749 return FALSE;
753 /***********************************************************************
754 * PrintDlg (COMMDLG.20)
756 BOOL PrintDlg(LPPRINTDLG lpPrint)
758 HANDLE hInst, hDlgTmpl;
759 BOOL bRet;
761 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
763 if (lpPrint->Flags & PD_RETURNDEFAULT)
764 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
765 return TRUE;
767 if (lpPrint->Flags & PD_PRINTSETUP)
768 hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED,
769 sysres_DIALOG_PRINT_SETUP.bytes,
770 sysres_DIALOG_PRINT_SETUP.size,
771 GetCurrentPDB(), FALSE,
772 FALSE, TRUE, NULL );
773 else
774 hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED, sysres_DIALOG_PRINT.bytes,
775 sysres_DIALOG_PRINT.size,
776 GetCurrentPDB(), FALSE,
777 FALSE, TRUE, NULL );
779 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
780 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
781 (lpPrint->Flags & PD_PRINTSETUP) ?
782 GetWndProcEntry16("PrintSetupDlgProc") :
783 GetWndProcEntry16("PrintDlgProc"),
784 (DWORD)lpPrint );
785 GLOBAL_FreeBlock( hDlgTmpl );
786 return bRet;
790 /***********************************************************************
791 * PrintDlgProc (COMMDLG.21)
793 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
795 switch (wMsg)
797 case WM_INITDIALOG:
798 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
799 ShowWindow(hWnd, SW_SHOWNORMAL);
800 return (TRUE);
801 case WM_COMMAND:
802 switch (wParam)
804 case IDOK:
805 EndDialog(hWnd, TRUE);
806 return(TRUE);
807 case IDCANCEL:
808 EndDialog(hWnd, FALSE);
809 return(TRUE);
811 return(FALSE);
813 return FALSE;
817 /***********************************************************************
818 * PrintSetupDlgProc (COMMDLG.22)
820 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
822 switch (wMsg)
824 case WM_INITDIALOG:
825 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
826 ShowWindow(hWnd, SW_SHOWNORMAL);
827 return (TRUE);
828 case WM_COMMAND:
829 switch (wParam) {
830 case IDOK:
831 EndDialog(hWnd, TRUE);
832 return(TRUE);
833 case IDCANCEL:
834 EndDialog(hWnd, FALSE);
835 return(TRUE);
837 return(FALSE);
839 return FALSE;
843 /***********************************************************************
844 * CommDlgExtendError (COMMDLG.26)
846 DWORD CommDlgExtendError(void)
848 return CommDlgLastError;
852 /***********************************************************************
853 * GetFileTitle (COMMDLG.27)
855 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
857 int i, len;
858 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
859 if (lpFile == NULL || lpTitle == NULL)
860 return -1;
861 len = strlen(lpFile);
862 if (len == 0)
863 return -1;
864 if (strpbrk(lpFile, "*[]"))
865 return -1;
866 len--;
867 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
868 return -1;
869 for (i = len; i >= 0; i--)
870 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
872 i++;
873 break;
875 printf("\n---> '%s' ", &lpFile[i]);
876 len = min(cbBuf, strlen(&lpFile[i]) + 1);
877 strncpy(lpTitle, &lpFile[i], len + 1);
878 if (len != cbBuf)
879 return len;
880 else
881 return 0;