Release 951124
[wine/multimedia.git] / misc / commdlg.c
blob73df1d10f1802ef3da6f0c069f83ee56c45e71d7
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 strncpy(str,newPath,511); str[511]=0;
175 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(str2));
176 strncat(str,str2,511-strlen(str)); str[511]=0;
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, WPARAM wParam, LPARAM 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 str[0]=0;
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, WPARAM wParam, LPARAM 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, WPARAM wParam, LPARAM 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 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
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 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
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 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
351 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
352 tmpstr[511]=0;
353 printf("nFilterIndex = %ld // SetText of edt1 to '%s'\n",
354 lpofn->nFilterIndex, tmpstr);
355 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
356 /* get drive list */
357 *tmpstr = 0;
358 DlgDirListComboBox(hWnd, MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
359 /* read initial directory */
360 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
362 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
363 tmpstr[510]=0;
364 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
365 && tmpstr[strlen(tmpstr)-1] != ':')
366 strcat(tmpstr,"\\");
368 else
369 *tmpstr = 0;
370 if (!FILEDLG_ScanDir(hWnd, tmpstr))
371 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
372 /* select current drive in combo 2 */
373 n = DOS_GetDefaultDrive();
374 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, n, 0);
375 if (!(lpofn->Flags & OFN_SHOWHELP))
376 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
377 if (lpofn->Flags & OFN_HIDEREADONLY)
378 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
379 return TRUE;
382 /***********************************************************************
383 * FILEDLG_WMCommand [internal]
385 static LRESULT FILEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
387 LONG lRet;
388 LPOPENFILENAME lpofn;
389 char tmpstr[512], tmpstr2[512];
390 LPSTR pstr, pstr2;
392 lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
393 switch (wParam)
395 case lst1: /* file list */
396 FILEDLG_StripEditControl(hWnd);
397 if (HIWORD(lParam) == LBN_DBLCLK)
398 goto almost_ok;
399 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
400 if (lRet == LB_ERR) return TRUE;
401 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
402 MAKE_SEGPTR(tmpstr));
403 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
404 return TRUE;
405 case lst2: /* directory list */
406 FILEDLG_StripEditControl(hWnd);
407 if (HIWORD(lParam) == LBN_DBLCLK)
409 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
410 if (lRet == LB_ERR) return TRUE;
411 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet,
412 MAKE_SEGPTR(tmpstr));
413 if (tmpstr[0] == '[')
415 tmpstr[strlen(tmpstr) - 1] = 0;
416 strcpy(tmpstr,tmpstr+1);
418 strcat(tmpstr, "\\");
419 goto reset_scan;
421 return TRUE;
422 case cmb1: /* file type drop list */
423 if (HIWORD(lParam) == CBN_SELCHANGE)
425 *tmpstr = 0;
426 goto reset_scan;
428 return TRUE;
429 case cmb2: /* disk drop list */
430 FILEDLG_StripEditControl(hWnd);
431 lRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
432 if (lRet == LB_ERR) return 0;
433 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, MAKE_SEGPTR(tmpstr));
434 sprintf(tmpstr, "%c:", tmpstr[2]);
435 reset_scan:
436 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
437 if (lRet == LB_ERR)
438 return TRUE;
439 pstr = FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
440 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
441 lRet);
442 strncpy(tmpstr2, pstr, 511); tmpstr2[511]=0;
443 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
444 FILEDLG_ScanDir(hWnd, tmpstr);
445 return TRUE;
446 case chx1:
447 return TRUE;
448 case pshHelp:
449 return TRUE;
450 case IDOK:
451 almost_ok:
452 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(tmpstr));
453 pstr = strrchr(tmpstr, '\\');
454 if (pstr == NULL)
455 pstr = strrchr(tmpstr, ':');
456 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
458 /* edit control contains wildcards */
459 if (pstr != NULL)
461 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
462 *(pstr+1) = 0;
464 else
466 strcpy(tmpstr2, tmpstr);
467 *tmpstr=0;
469 printf("commdlg: %s, %s\n", tmpstr, tmpstr2);
470 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
471 FILEDLG_ScanDir(hWnd, tmpstr);
472 return TRUE;
474 /* no wildcards, we might have a directory or a filename */
475 /* try appending a wildcard and reading the directory */
476 pstr2 = tmpstr + strlen(tmpstr);
477 if (pstr == NULL || *(pstr+1) != 0)
478 strcat(tmpstr, "\\");
479 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
480 if (lRet == LB_ERR) return TRUE;
481 lpofn->nFilterIndex = lRet + 1;
482 printf("commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
483 strncpy(tmpstr2,
484 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
485 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
486 lRet), 511);
487 tmpstr2[511]=0;
488 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
489 /* if ScanDir succeeds, we have changed the directory */
490 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
491 /* if not, this must be a filename */
492 *pstr2 = 0;
493 if (pstr != NULL)
495 /* strip off the pathname */
496 *pstr = 0;
497 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
498 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
499 /* Should we MessageBox() if this fails? */
500 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
501 strcpy(tmpstr, tmpstr2);
503 else
504 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
505 ShowWindow(hWnd, SW_HIDE);
507 int drive;
508 drive = DOS_GetDefaultDrive();
509 tmpstr2[0] = 'A'+ drive;
510 tmpstr2[1] = ':';
511 tmpstr2[2] = '\\';
512 strncpy(tmpstr2 + 3, DOS_GetCurrentDir(drive), 507); tmpstr2[510]=0;
513 if (strlen(tmpstr2) > 3)
514 strcat(tmpstr2, "\\");
515 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
516 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
518 lpofn->nFileOffset = 0;
519 lpofn->nFileExtension = 0;
520 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
521 lpofn->nFileExtension++;
522 if (lpofn->nFileExtension == '\0')
523 lpofn->nFileExtension = 0;
524 else
525 lpofn->nFileExtension++;
526 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
528 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
529 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
530 MAKE_SEGPTR(tmpstr));
531 printf("strcpy'ing '%s'\n",tmpstr); fflush(stdout);
532 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
534 EndDialog(hWnd, TRUE);
535 return TRUE;
536 case IDCANCEL:
537 EndDialog(hWnd, FALSE);
538 return TRUE;
540 return FALSE;
544 /***********************************************************************
545 * FileOpenDlgProc (COMMDLG.6)
547 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
549 switch (wMsg)
551 case WM_INITDIALOG:
552 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
553 case WM_MEASUREITEM:
554 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
555 case WM_DRAWITEM:
556 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
557 case WM_COMMAND:
558 return FILEDLG_WMCommand(hWnd, wParam, lParam);
559 #if 0
560 case WM_CTLCOLOR:
561 SetBkColor((HDC)wParam, 0x00C0C0C0);
562 switch (HIWORD(lParam))
564 case CTLCOLOR_BTN:
565 SetTextColor((HDC)wParam, 0x00000000);
566 return hGRAYBrush;
567 case CTLCOLOR_STATIC:
568 SetTextColor((HDC)wParam, 0x00000000);
569 return hGRAYBrush;
571 break;
572 #endif
574 return FALSE;
578 /***********************************************************************
579 * FileSaveDlgProc (COMMDLG.7)
581 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
583 switch (wMsg) {
584 case WM_INITDIALOG:
585 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
587 case WM_MEASUREITEM:
588 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
590 case WM_DRAWITEM:
591 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
593 case WM_COMMAND:
594 return FILEDLG_WMCommand(hWnd, wParam, lParam);
598 case WM_CTLCOLOR:
599 SetBkColor((HDC)wParam, 0x00C0C0C0);
600 switch (HIWORD(lParam))
602 case CTLCOLOR_BTN:
603 SetTextColor((HDC)wParam, 0x00000000);
604 return hGRAYBrush;
605 case CTLCOLOR_STATIC:
606 SetTextColor((HDC)wParam, 0x00000000);
607 return hGRAYBrush;
609 return FALSE;
612 return FALSE;
616 /***********************************************************************
617 * ChooseColor (COMMDLG.5)
619 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
621 HANDLE hInst, hDlgTmpl;
622 BOOL bRet;
624 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_CHOOSE_COLOR.bytes,
625 sysres_DIALOG_CHOOSE_COLOR.size,
626 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
627 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
628 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
629 GetWndProcEntry16("ColorDlgProc"),
630 (DWORD)lpChCol );
631 GLOBAL_FreeBlock( hDlgTmpl );
632 return bRet;
636 /***********************************************************************
637 * ColorDlgProc (COMMDLG.8)
639 LRESULT ColorDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
641 switch (wMsg)
643 case WM_INITDIALOG:
644 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
645 ShowWindow(hWnd, SW_SHOWNORMAL);
646 return (TRUE);
647 case WM_COMMAND:
648 switch (wParam)
650 case IDOK:
651 EndDialog(hWnd, TRUE);
652 return(TRUE);
653 case IDCANCEL:
654 EndDialog(hWnd, FALSE);
655 return(TRUE);
657 return(FALSE);
659 return FALSE;
663 /***********************************************************************
664 * FindTextDlg (COMMDLG.11)
666 BOOL FindText(LPFINDREPLACE lpFind)
668 HANDLE hInst, hDlgTmpl;
669 BOOL bRet;
671 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_FIND_TEXT.bytes,
672 sysres_DIALOG_FIND_TEXT.size,
673 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
674 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
675 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
676 GetWndProcEntry16("FindTextDlgProc"),
677 (DWORD)lpFind );
678 GLOBAL_FreeBlock( hDlgTmpl );
679 return bRet;
683 /***********************************************************************
684 * ReplaceTextDlg (COMMDLG.12)
686 BOOL ReplaceText(LPFINDREPLACE lpFind)
688 HANDLE hInst, hDlgTmpl;
689 BOOL bRet;
691 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_REPLACE_TEXT.bytes,
692 sysres_DIALOG_REPLACE_TEXT.size,
693 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
694 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
695 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
696 GetWndProcEntry16("ReplaceTextDlgProc"),
697 (DWORD)lpFind );
698 GLOBAL_FreeBlock( hDlgTmpl );
699 return bRet;
703 /***********************************************************************
704 * FindTextDlgProc (COMMDLG.13)
706 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
708 switch (wMsg)
710 case WM_INITDIALOG:
711 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
712 ShowWindow(hWnd, SW_SHOWNORMAL);
713 return (TRUE);
714 case WM_COMMAND:
715 switch (wParam)
717 case IDOK:
718 EndDialog(hWnd, TRUE);
719 return(TRUE);
720 case IDCANCEL:
721 EndDialog(hWnd, FALSE);
722 return(TRUE);
724 return(FALSE);
726 return FALSE;
730 /***********************************************************************
731 * ReplaceTextDlgProc (COMMDLG.14)
733 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
735 switch (wMsg)
737 case WM_INITDIALOG:
738 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
739 ShowWindow(hWnd, SW_SHOWNORMAL);
740 return (TRUE);
741 case WM_COMMAND:
742 switch (wParam)
744 case IDOK:
745 EndDialog(hWnd, TRUE);
746 return(TRUE);
747 case IDCANCEL:
748 EndDialog(hWnd, FALSE);
749 return(TRUE);
751 return(FALSE);
753 return FALSE;
757 /***********************************************************************
758 * PrintDlg (COMMDLG.20)
760 BOOL PrintDlg(LPPRINTDLG lpPrint)
762 HANDLE hInst, hDlgTmpl;
763 BOOL bRet;
765 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
767 if (lpPrint->Flags & PD_RETURNDEFAULT)
768 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
769 return TRUE;
771 if (lpPrint->Flags & PD_PRINTSETUP)
772 hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED,
773 sysres_DIALOG_PRINT_SETUP.bytes,
774 sysres_DIALOG_PRINT_SETUP.size,
775 GetCurrentPDB(), FALSE,
776 FALSE, TRUE, NULL );
777 else
778 hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED, sysres_DIALOG_PRINT.bytes,
779 sysres_DIALOG_PRINT.size,
780 GetCurrentPDB(), FALSE,
781 FALSE, TRUE, NULL );
783 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
784 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
785 (lpPrint->Flags & PD_PRINTSETUP) ?
786 GetWndProcEntry16("PrintSetupDlgProc") :
787 GetWndProcEntry16("PrintDlgProc"),
788 (DWORD)lpPrint );
789 GLOBAL_FreeBlock( hDlgTmpl );
790 return bRet;
794 /***********************************************************************
795 * PrintDlgProc (COMMDLG.21)
797 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
799 switch (wMsg)
801 case WM_INITDIALOG:
802 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
803 ShowWindow(hWnd, SW_SHOWNORMAL);
804 return (TRUE);
805 case WM_COMMAND:
806 switch (wParam)
808 case IDOK:
809 EndDialog(hWnd, TRUE);
810 return(TRUE);
811 case IDCANCEL:
812 EndDialog(hWnd, FALSE);
813 return(TRUE);
815 return(FALSE);
817 return FALSE;
821 /***********************************************************************
822 * PrintSetupDlgProc (COMMDLG.22)
824 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
826 switch (wMsg)
828 case WM_INITDIALOG:
829 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
830 ShowWindow(hWnd, SW_SHOWNORMAL);
831 return (TRUE);
832 case WM_COMMAND:
833 switch (wParam) {
834 case IDOK:
835 EndDialog(hWnd, TRUE);
836 return(TRUE);
837 case IDCANCEL:
838 EndDialog(hWnd, FALSE);
839 return(TRUE);
841 return(FALSE);
843 return FALSE;
847 /***********************************************************************
848 * CommDlgExtendError (COMMDLG.26)
850 DWORD CommDlgExtendError(void)
852 return CommDlgLastError;
856 /***********************************************************************
857 * GetFileTitle (COMMDLG.27)
859 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
861 int i, len;
862 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
863 if (lpFile == NULL || lpTitle == NULL)
864 return -1;
865 len = strlen(lpFile);
866 if (len == 0)
867 return -1;
868 if (strpbrk(lpFile, "*[]"))
869 return -1;
870 len--;
871 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
872 return -1;
873 for (i = len; i >= 0; i--)
874 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
876 i++;
877 break;
879 printf("\n---> '%s' ", &lpFile[i]);
880 len = MIN(cbBuf, strlen(&lpFile[i]) + 1);
881 strncpy(lpTitle, &lpFile[i], len + 1);
882 if (len != cbBuf)
883 return len;
884 else
885 return 0;