Release 951105
[wine/multimedia.git] / misc / commdlg.c
blob5b86ad3a3faf1fca8f8d431797db1cb7a3971f7d
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), 510); tmpstr2[510]=0;
513 if (strlen(tmpstr2) > 3)
514 strcat(tmpstr2, "\\");
515 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
516 printf("strcpy'ing '%s'\n",tmpstr2); fflush(stdout);
517 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
519 lpofn->nFileOffset = 0;
520 lpofn->nFileExtension = 0;
521 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
522 lpofn->nFileExtension++;
523 if (lpofn->nFileExtension == '\0')
524 lpofn->nFileExtension = 0;
525 else
526 lpofn->nFileExtension++;
527 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
529 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
530 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
531 MAKE_SEGPTR(tmpstr));
532 printf("strcpy'ing '%s'\n",tmpstr); fflush(stdout);
533 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
535 EndDialog(hWnd, TRUE);
536 return TRUE;
537 case IDCANCEL:
538 EndDialog(hWnd, FALSE);
539 return TRUE;
541 return FALSE;
545 /***********************************************************************
546 * FileOpenDlgProc (COMMDLG.6)
548 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
550 switch (wMsg)
552 case WM_INITDIALOG:
553 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
554 case WM_MEASUREITEM:
555 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
556 case WM_DRAWITEM:
557 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
558 case WM_COMMAND:
559 return FILEDLG_WMCommand(hWnd, wParam, lParam);
560 #if 0
561 case WM_CTLCOLOR:
562 SetBkColor((HDC)wParam, 0x00C0C0C0);
563 switch (HIWORD(lParam))
565 case CTLCOLOR_BTN:
566 SetTextColor((HDC)wParam, 0x00000000);
567 return hGRAYBrush;
568 case CTLCOLOR_STATIC:
569 SetTextColor((HDC)wParam, 0x00000000);
570 return hGRAYBrush;
572 break;
573 #endif
575 return FALSE;
579 /***********************************************************************
580 * FileSaveDlgProc (COMMDLG.7)
582 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
584 switch (wMsg) {
585 case WM_INITDIALOG:
586 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
588 case WM_MEASUREITEM:
589 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
591 case WM_DRAWITEM:
592 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
594 case WM_COMMAND:
595 return FILEDLG_WMCommand(hWnd, wParam, lParam);
599 case WM_CTLCOLOR:
600 SetBkColor((HDC)wParam, 0x00C0C0C0);
601 switch (HIWORD(lParam))
603 case CTLCOLOR_BTN:
604 SetTextColor((HDC)wParam, 0x00000000);
605 return hGRAYBrush;
606 case CTLCOLOR_STATIC:
607 SetTextColor((HDC)wParam, 0x00000000);
608 return hGRAYBrush;
610 return FALSE;
613 return FALSE;
617 /***********************************************************************
618 * ChooseColor (COMMDLG.5)
620 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
622 HANDLE hInst, hDlgTmpl;
623 BOOL bRet;
625 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_CHOOSE_COLOR.bytes,
626 sysres_DIALOG_CHOOSE_COLOR.size,
627 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
628 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
629 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
630 GetWndProcEntry16("ColorDlgProc"),
631 (DWORD)lpChCol );
632 GLOBAL_FreeBlock( hDlgTmpl );
633 return bRet;
637 /***********************************************************************
638 * ColorDlgProc (COMMDLG.8)
640 LRESULT ColorDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
642 switch (wMsg)
644 case WM_INITDIALOG:
645 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
646 ShowWindow(hWnd, SW_SHOWNORMAL);
647 return (TRUE);
648 case WM_COMMAND:
649 switch (wParam)
651 case IDOK:
652 EndDialog(hWnd, TRUE);
653 return(TRUE);
654 case IDCANCEL:
655 EndDialog(hWnd, FALSE);
656 return(TRUE);
658 return(FALSE);
660 return FALSE;
664 /***********************************************************************
665 * FindTextDlg (COMMDLG.11)
667 BOOL FindText(LPFINDREPLACE lpFind)
669 HANDLE hInst, hDlgTmpl;
670 BOOL bRet;
672 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_FIND_TEXT.bytes,
673 sysres_DIALOG_FIND_TEXT.size,
674 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
675 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
676 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
677 GetWndProcEntry16("FindTextDlgProc"),
678 (DWORD)lpFind );
679 GLOBAL_FreeBlock( hDlgTmpl );
680 return bRet;
684 /***********************************************************************
685 * ReplaceTextDlg (COMMDLG.12)
687 BOOL ReplaceText(LPFINDREPLACE lpFind)
689 HANDLE hInst, hDlgTmpl;
690 BOOL bRet;
692 hDlgTmpl = GLOBAL_CreateBlock(GMEM_FIXED, sysres_DIALOG_REPLACE_TEXT.bytes,
693 sysres_DIALOG_REPLACE_TEXT.size,
694 GetCurrentPDB(), FALSE, FALSE, TRUE, NULL );
695 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
696 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
697 GetWndProcEntry16("ReplaceTextDlgProc"),
698 (DWORD)lpFind );
699 GLOBAL_FreeBlock( hDlgTmpl );
700 return bRet;
704 /***********************************************************************
705 * FindTextDlgProc (COMMDLG.13)
707 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
709 switch (wMsg)
711 case WM_INITDIALOG:
712 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
713 ShowWindow(hWnd, SW_SHOWNORMAL);
714 return (TRUE);
715 case WM_COMMAND:
716 switch (wParam)
718 case IDOK:
719 EndDialog(hWnd, TRUE);
720 return(TRUE);
721 case IDCANCEL:
722 EndDialog(hWnd, FALSE);
723 return(TRUE);
725 return(FALSE);
727 return FALSE;
731 /***********************************************************************
732 * ReplaceTextDlgProc (COMMDLG.14)
734 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
736 switch (wMsg)
738 case WM_INITDIALOG:
739 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
740 ShowWindow(hWnd, SW_SHOWNORMAL);
741 return (TRUE);
742 case WM_COMMAND:
743 switch (wParam)
745 case IDOK:
746 EndDialog(hWnd, TRUE);
747 return(TRUE);
748 case IDCANCEL:
749 EndDialog(hWnd, FALSE);
750 return(TRUE);
752 return(FALSE);
754 return FALSE;
758 /***********************************************************************
759 * PrintDlg (COMMDLG.20)
761 BOOL PrintDlg(LPPRINTDLG lpPrint)
763 HANDLE hInst, hDlgTmpl;
764 BOOL bRet;
766 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
768 if (lpPrint->Flags & PD_RETURNDEFAULT)
769 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
770 return TRUE;
772 if (lpPrint->Flags & PD_PRINTSETUP)
773 hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED,
774 sysres_DIALOG_PRINT_SETUP.bytes,
775 sysres_DIALOG_PRINT_SETUP.size,
776 GetCurrentPDB(), FALSE,
777 FALSE, TRUE, NULL );
778 else
779 hDlgTmpl = GLOBAL_CreateBlock( GMEM_FIXED, sysres_DIALOG_PRINT.bytes,
780 sysres_DIALOG_PRINT.size,
781 GetCurrentPDB(), FALSE,
782 FALSE, TRUE, NULL );
784 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
785 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
786 (lpPrint->Flags & PD_PRINTSETUP) ?
787 GetWndProcEntry16("PrintSetupDlgProc") :
788 GetWndProcEntry16("PrintDlgProc"),
789 (DWORD)lpPrint );
790 GLOBAL_FreeBlock( hDlgTmpl );
791 return bRet;
795 /***********************************************************************
796 * PrintDlgProc (COMMDLG.21)
798 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
800 switch (wMsg)
802 case WM_INITDIALOG:
803 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
804 ShowWindow(hWnd, SW_SHOWNORMAL);
805 return (TRUE);
806 case WM_COMMAND:
807 switch (wParam)
809 case IDOK:
810 EndDialog(hWnd, TRUE);
811 return(TRUE);
812 case IDCANCEL:
813 EndDialog(hWnd, FALSE);
814 return(TRUE);
816 return(FALSE);
818 return FALSE;
822 /***********************************************************************
823 * PrintSetupDlgProc (COMMDLG.22)
825 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
827 switch (wMsg)
829 case WM_INITDIALOG:
830 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
831 ShowWindow(hWnd, SW_SHOWNORMAL);
832 return (TRUE);
833 case WM_COMMAND:
834 switch (wParam) {
835 case IDOK:
836 EndDialog(hWnd, TRUE);
837 return(TRUE);
838 case IDCANCEL:
839 EndDialog(hWnd, FALSE);
840 return(TRUE);
842 return(FALSE);
844 return FALSE;
848 /***********************************************************************
849 * CommDlgExtendError (COMMDLG.26)
851 DWORD CommDlgExtendError(void)
853 return CommDlgLastError;
857 /***********************************************************************
858 * GetFileTitle (COMMDLG.27)
860 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
862 int i, len;
863 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
864 if (lpFile == NULL || lpTitle == NULL)
865 return -1;
866 len = strlen(lpFile);
867 if (len == 0)
868 return -1;
869 if (strpbrk(lpFile, "*[]"))
870 return -1;
871 len--;
872 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
873 return -1;
874 for (i = len; i >= 0; i--)
875 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
877 i++;
878 break;
880 printf("\n---> '%s' ", &lpFile[i]);
881 len = MIN(cbBuf, strlen(&lpFile[i]) + 1);
882 strncpy(lpTitle, &lpFile[i], len + 1);
883 if (len != cbBuf)
884 return len;
885 else
886 return 0;