Release 951226
[wine/multimedia.git] / misc / commdlg.c
blobd147dde9b3c64b5b92b3ad8a38f4ecc6dc6557d3
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 "message.h"
13 #include "commdlg.h"
14 #include "dlgs.h"
15 #include "selectors.h"
16 #include "resource.h"
17 #include "dos_fs.h"
18 #include "stackframe.h"
20 static DWORD CommDlgLastError = 0;
22 static HBITMAP hFolder = 0;
23 static HBITMAP hFolder2 = 0;
24 static HBITMAP hFloppy = 0;
25 static HBITMAP hHDisk = 0;
26 static HBITMAP hCDRom = 0;
28 /***********************************************************************
29 * FileDlg_Init [internal]
31 static BOOL FileDlg_Init()
33 static BOOL initialized = 0;
35 if (!initialized) {
36 if (!hFolder) hFolder = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER));
37 if (!hFolder2) hFolder2 = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2));
38 if (!hFloppy) hFloppy = LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY));
39 if (!hHDisk) hHDisk = LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK));
40 if (!hCDRom) hCDRom = LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM));
41 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
42 hHDisk == 0 || hCDRom == 0)
44 fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
45 return FALSE;
47 initialized = TRUE;
49 return TRUE;
52 /***********************************************************************
53 * GetOpenFileName (COMMDLG.1)
55 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
57 HINSTANCE hInst;
58 HANDLE hDlgTmpl, hResInfo;
59 BOOL bRet;
61 if (!lpofn || !FileDlg_Init()) return FALSE;
63 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
64 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
66 if (!(hResInfo = FindResource( lpofn->hInstance,
67 lpofn->lpTemplateName, RT_DIALOG)))
69 CommDlgLastError = CDERR_FINDRESFAILURE;
70 return FALSE;
72 hDlgTmpl = LoadResource( lpofn->hInstance, hResInfo );
74 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_OPEN_FILE );
75 if (!hDlgTmpl)
77 CommDlgLastError = CDERR_LOADRESFAILURE;
78 return FALSE;
81 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
82 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
83 GetWndProcEntry16("FileOpenDlgProc"),
84 (DWORD)lpofn );
86 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
88 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( hDlgTmpl );
89 else SYSRES_FreeResource( hDlgTmpl );
92 printf("GetOpenFileName // return lpstrFile='%s' !\n",
93 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
94 return bRet;
98 /***********************************************************************
99 * GetSaveFileName (COMMDLG.2)
101 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
103 HINSTANCE hInst;
104 HANDLE hDlgTmpl, hResInfo;
105 BOOL bRet;
107 if (!lpofn || !FileDlg_Init()) return FALSE;
109 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
110 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
112 hInst = lpofn->hInstance;
113 if (!(hResInfo = FindResource( lpofn->hInstance,
114 lpofn->lpTemplateName, RT_DIALOG )))
116 CommDlgLastError = CDERR_FINDRESFAILURE;
117 return FALSE;
119 hDlgTmpl = LoadResource( lpofn->hInstance, hResInfo );
121 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE );
123 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
124 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
125 GetWndProcEntry16("FileSaveDlgProc"),
126 (DWORD)lpofn);
127 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
129 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( hDlgTmpl );
130 else SYSRES_FreeResource( hDlgTmpl );
133 printf( "GetSaveFileName // return lpstrFile='%s' !\n",
134 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
135 return bRet;
138 /***********************************************************************
139 * FILEDLG_StripEditControl [internal]
140 * Strip pathnames off the contents of the edit control.
142 static void FILEDLG_StripEditControl(HWND hwnd)
144 char temp[512], *cp;
146 SendDlgItemMessage(hwnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(temp));
147 cp = strrchr(temp, '\\');
148 if (cp != NULL) {
149 strcpy(temp, cp+1);
151 cp = strrchr(temp, ':');
152 if (cp != NULL) {
153 strcpy(temp, cp+1);
157 /***********************************************************************
158 * FILEDLG_ScanDir [internal]
160 static BOOL FILEDLG_ScanDir(HWND hWnd, LPSTR newPath)
162 char str[512],str2[512];
164 strncpy(str,newPath,511); str[511]=0;
165 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(str2));
166 strncat(str,str2,511-strlen(str)); str[511]=0;
167 if (!DlgDirList(hWnd, str, lst1, 0, 0x0000)) return FALSE;
168 DlgDirList(hWnd, "*.*", lst2, stc1, 0x8010);
170 return TRUE;
173 /***********************************************************************
174 * FILEDLG_GetFileType [internal]
177 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
179 int n, i;
180 i = 0;
181 if (cfptr)
182 for ( ;(n = strlen(cfptr)) != 0; i++)
184 cfptr += n + 1;
185 if (i == index)
186 return cfptr;
187 cfptr += strlen(cfptr) + 1;
189 if (fptr)
190 for ( ;(n = strlen(fptr)) != 0; i++)
192 fptr += n + 1;
193 if (i == index)
194 return fptr;
195 fptr += strlen(fptr) + 1;
197 return NULL;
200 /***********************************************************************
201 * FILEDLG_WMDrawItem [internal]
203 static LONG FILEDLG_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
205 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
206 char str[512];
207 HBRUSH hBrush;
208 HBITMAP hBitmap, hPrevBitmap;
209 BITMAP bm;
210 HDC hMemDC;
212 str[0]=0;
213 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
214 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
215 SelectObject(lpdis->hDC, hBrush);
216 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
217 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
218 (LPARAM)MAKE_SEGPTR(str));
219 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
220 str, strlen(str));
221 if (lpdis->itemState != 0) {
222 InvertRect(lpdis->hDC, &lpdis->rcItem);
224 return TRUE;
227 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2) {
228 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
229 SelectObject(lpdis->hDC, hBrush);
230 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
231 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
232 (LPARAM)MAKE_SEGPTR(str));
234 hBitmap = hFolder;
235 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
236 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
237 lpdis->rcItem.top, str, strlen(str));
238 hMemDC = CreateCompatibleDC(lpdis->hDC);
239 hPrevBitmap = SelectObject(hMemDC, hBitmap);
240 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
241 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
242 SelectObject(hMemDC, hPrevBitmap);
243 DeleteDC(hMemDC);
244 if (lpdis->itemState != 0) {
245 InvertRect(lpdis->hDC, &lpdis->rcItem);
247 return TRUE;
249 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2) {
250 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
251 SelectObject(lpdis->hDC, hBrush);
252 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
253 SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
254 (LPARAM)MAKE_SEGPTR(str));
255 switch(str[2]) {
256 case 'a': case 'b':
257 hBitmap = hFloppy;
258 break;
259 default:
260 hBitmap = hHDisk;
261 break;
263 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
264 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
265 lpdis->rcItem.top, str, strlen(str));
266 hMemDC = CreateCompatibleDC(lpdis->hDC);
267 hPrevBitmap = SelectObject(hMemDC, hBitmap);
268 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
269 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
270 SelectObject(hMemDC, hPrevBitmap);
271 DeleteDC(hMemDC);
272 if (lpdis->itemState != 0) {
273 InvertRect(lpdis->hDC, &lpdis->rcItem);
275 return TRUE;
277 return FALSE;
280 /***********************************************************************
281 * FILEDLG_WMMeasureItem [internal]
283 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
285 BITMAP bm;
286 LPMEASUREITEMSTRUCT lpmeasure;
288 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
289 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
290 lpmeasure->itemHeight = bm.bmHeight;
291 return TRUE;
294 /***********************************************************************
295 * FILEDLG_WMInitDialog [internal]
298 static LONG FILEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
300 int n;
301 LPOPENFILENAME lpofn;
302 char tmpstr[512];
303 LPSTR pstr;
304 SetWindowLong(hWnd, DWL_USER, lParam);
305 lpofn = (LPOPENFILENAME)lParam;
306 /* read custom filter information */
307 if (lpofn->lpstrCustomFilter)
309 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
310 printf("lpstrCustomFilter = %p\n", pstr);
311 while(*pstr)
313 n = strlen(pstr);
314 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
315 printf("lpstrCustomFilter // add tmpstr='%s' ", tmpstr);
316 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
317 pstr += n + 1;
318 n = strlen(pstr);
319 printf("associated to '%s'\n", pstr);
320 pstr += n + 1;
323 /* read filter information */
324 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
325 while(*pstr)
327 n = strlen(pstr);
328 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
329 printf("lpstrFilter // add tmpstr='%s' ", tmpstr);
330 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
331 pstr += n + 1;
332 n = strlen(pstr);
333 printf("associated to '%s'\n", pstr);
334 pstr += n + 1;
336 /* set default filter */
337 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
338 lpofn->nFilterIndex = 1;
339 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL, lpofn->nFilterIndex - 1, 0);
340 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
341 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
342 tmpstr[511]=0;
343 printf("nFilterIndex = %ld // SetText of edt1 to '%s'\n",
344 lpofn->nFilterIndex, tmpstr);
345 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
346 /* get drive list */
347 *tmpstr = 0;
348 DlgDirListComboBox(hWnd, MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
349 /* read initial directory */
350 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
352 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
353 tmpstr[510]=0;
354 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
355 && tmpstr[strlen(tmpstr)-1] != ':')
356 strcat(tmpstr,"\\");
358 else
359 *tmpstr = 0;
360 if (!FILEDLG_ScanDir(hWnd, tmpstr))
361 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
362 /* select current drive in combo 2 */
363 n = DOS_GetDefaultDrive();
364 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, n, 0);
365 if (!(lpofn->Flags & OFN_SHOWHELP))
366 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
367 if (lpofn->Flags & OFN_HIDEREADONLY)
368 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
369 return TRUE;
372 /***********************************************************************
373 * FILEDLG_WMCommand [internal]
375 static LRESULT FILEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
377 LONG lRet;
378 LPOPENFILENAME lpofn;
379 char tmpstr[512], tmpstr2[512];
380 LPSTR pstr, pstr2;
382 lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
383 switch (wParam)
385 case lst1: /* file list */
386 FILEDLG_StripEditControl(hWnd);
387 if (HIWORD(lParam) == LBN_DBLCLK)
388 goto almost_ok;
389 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
390 if (lRet == LB_ERR) return TRUE;
391 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
392 (LPARAM)MAKE_SEGPTR(tmpstr));
393 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
394 return TRUE;
395 case lst2: /* directory list */
396 FILEDLG_StripEditControl(hWnd);
397 if (HIWORD(lParam) == LBN_DBLCLK)
399 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
400 if (lRet == LB_ERR) return TRUE;
401 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet,
402 (LPARAM)MAKE_SEGPTR(tmpstr));
403 if (tmpstr[0] == '[')
405 tmpstr[strlen(tmpstr) - 1] = 0;
406 strcpy(tmpstr,tmpstr+1);
408 strcat(tmpstr, "\\");
409 goto reset_scan;
411 return TRUE;
412 case cmb1: /* file type drop list */
413 if (HIWORD(lParam) == CBN_SELCHANGE)
415 *tmpstr = 0;
416 goto reset_scan;
418 return TRUE;
419 case cmb2: /* disk drop list */
420 FILEDLG_StripEditControl(hWnd);
421 lRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
422 if (lRet == LB_ERR) return 0;
423 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, (LPARAM)MAKE_SEGPTR(tmpstr));
424 sprintf(tmpstr, "%c:", tmpstr[2]);
425 reset_scan:
426 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
427 if (lRet == LB_ERR)
428 return TRUE;
429 pstr = FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
430 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
431 lRet);
432 strncpy(tmpstr2, pstr, 511); tmpstr2[511]=0;
433 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
434 FILEDLG_ScanDir(hWnd, tmpstr);
435 return TRUE;
436 case chx1:
437 return TRUE;
438 case pshHelp:
439 return TRUE;
440 case IDOK:
441 almost_ok:
442 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(tmpstr));
443 pstr = strrchr(tmpstr, '\\');
444 if (pstr == NULL)
445 pstr = strrchr(tmpstr, ':');
446 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
448 /* edit control contains wildcards */
449 if (pstr != NULL)
451 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
452 *(pstr+1) = 0;
454 else
456 strcpy(tmpstr2, tmpstr);
457 *tmpstr=0;
459 printf("commdlg: %s, %s\n", tmpstr, tmpstr2);
460 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
461 FILEDLG_ScanDir(hWnd, tmpstr);
462 return TRUE;
464 /* no wildcards, we might have a directory or a filename */
465 /* try appending a wildcard and reading the directory */
466 pstr2 = tmpstr + strlen(tmpstr);
467 if (pstr == NULL || *(pstr+1) != 0)
468 strcat(tmpstr, "\\");
469 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
470 if (lRet == LB_ERR) return TRUE;
471 lpofn->nFilterIndex = lRet + 1;
472 printf("commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
473 strncpy(tmpstr2,
474 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
475 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
476 lRet), 511);
477 tmpstr2[511]=0;
478 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
479 /* if ScanDir succeeds, we have changed the directory */
480 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
481 /* if not, this must be a filename */
482 *pstr2 = 0;
483 if (pstr != NULL)
485 /* strip off the pathname */
486 *pstr = 0;
487 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
488 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
489 /* Should we MessageBox() if this fails? */
490 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
491 strcpy(tmpstr, tmpstr2);
493 else
494 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
495 ShowWindow(hWnd, SW_HIDE);
497 int drive;
498 drive = DOS_GetDefaultDrive();
499 tmpstr2[0] = 'A'+ drive;
500 tmpstr2[1] = ':';
501 tmpstr2[2] = '\\';
502 strncpy(tmpstr2 + 3, DOS_GetCurrentDir(drive), 507); tmpstr2[510]=0;
503 if (strlen(tmpstr2) > 3)
504 strcat(tmpstr2, "\\");
505 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
506 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
508 lpofn->nFileOffset = 0;
509 lpofn->nFileExtension = 0;
510 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
511 lpofn->nFileExtension++;
512 if (lpofn->nFileExtension == '\0')
513 lpofn->nFileExtension = 0;
514 else
515 lpofn->nFileExtension++;
516 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
518 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
519 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
520 (LPARAM)MAKE_SEGPTR(tmpstr));
521 printf("strcpy'ing '%s'\n",tmpstr); fflush(stdout);
522 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
524 EndDialog(hWnd, TRUE);
525 return TRUE;
526 case IDCANCEL:
527 EndDialog(hWnd, FALSE);
528 return TRUE;
530 return FALSE;
534 /***********************************************************************
535 * FileOpenDlgProc (COMMDLG.6)
537 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
539 switch (wMsg)
541 case WM_INITDIALOG:
542 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
543 case WM_MEASUREITEM:
544 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
545 case WM_DRAWITEM:
546 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
547 case WM_COMMAND:
548 return FILEDLG_WMCommand(hWnd, wParam, lParam);
549 #if 0
550 case WM_CTLCOLOR:
551 SetBkColor((HDC)wParam, 0x00C0C0C0);
552 switch (HIWORD(lParam))
554 case CTLCOLOR_BTN:
555 SetTextColor((HDC)wParam, 0x00000000);
556 return hGRAYBrush;
557 case CTLCOLOR_STATIC:
558 SetTextColor((HDC)wParam, 0x00000000);
559 return hGRAYBrush;
561 break;
562 #endif
564 return FALSE;
568 /***********************************************************************
569 * FileSaveDlgProc (COMMDLG.7)
571 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
573 switch (wMsg) {
574 case WM_INITDIALOG:
575 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
577 case WM_MEASUREITEM:
578 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
580 case WM_DRAWITEM:
581 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
583 case WM_COMMAND:
584 return FILEDLG_WMCommand(hWnd, wParam, lParam);
588 case WM_CTLCOLOR:
589 SetBkColor((HDC)wParam, 0x00C0C0C0);
590 switch (HIWORD(lParam))
592 case CTLCOLOR_BTN:
593 SetTextColor((HDC)wParam, 0x00000000);
594 return hGRAYBrush;
595 case CTLCOLOR_STATIC:
596 SetTextColor((HDC)wParam, 0x00000000);
597 return hGRAYBrush;
599 return FALSE;
602 return FALSE;
606 /***********************************************************************
607 * ChooseColor (COMMDLG.5)
609 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
611 HANDLE hInst, hDlgTmpl;
612 BOOL bRet;
614 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR );
615 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
616 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
617 GetWndProcEntry16("ColorDlgProc"),
618 (DWORD)lpChCol );
619 SYSRES_FreeResource( hDlgTmpl );
620 return bRet;
624 /***********************************************************************
625 * ColorDlgProc (COMMDLG.8)
627 LRESULT ColorDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
629 switch (wMsg)
631 case WM_INITDIALOG:
632 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
633 ShowWindow(hWnd, SW_SHOWNORMAL);
634 return (TRUE);
635 case WM_COMMAND:
636 switch (wParam)
638 case IDOK:
639 EndDialog(hWnd, TRUE);
640 return(TRUE);
641 case IDCANCEL:
642 EndDialog(hWnd, FALSE);
643 return(TRUE);
645 return(FALSE);
647 return FALSE;
651 /***********************************************************************
652 * FindTextDlg (COMMDLG.11)
654 BOOL FindText(LPFINDREPLACE lpFind)
656 HANDLE hInst, hDlgTmpl;
657 BOOL bRet;
659 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT );
660 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
661 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
662 GetWndProcEntry16("FindTextDlgProc"),
663 (DWORD)lpFind );
664 SYSRES_FreeResource( hDlgTmpl );
665 return bRet;
669 /***********************************************************************
670 * ReplaceTextDlg (COMMDLG.12)
672 BOOL ReplaceText(LPFINDREPLACE lpFind)
674 HANDLE hInst, hDlgTmpl;
675 BOOL bRet;
677 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT );
678 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
679 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
680 GetWndProcEntry16("ReplaceTextDlgProc"),
681 (DWORD)lpFind );
682 SYSRES_FreeResource( hDlgTmpl );
683 return bRet;
687 /***********************************************************************
688 * FindTextDlgProc (COMMDLG.13)
690 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
692 switch (wMsg)
694 case WM_INITDIALOG:
695 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
696 ShowWindow(hWnd, SW_SHOWNORMAL);
697 return (TRUE);
698 case WM_COMMAND:
699 switch (wParam)
701 case IDOK:
702 EndDialog(hWnd, TRUE);
703 return(TRUE);
704 case IDCANCEL:
705 EndDialog(hWnd, FALSE);
706 return(TRUE);
708 return(FALSE);
710 return FALSE;
714 /***********************************************************************
715 * ReplaceTextDlgProc (COMMDLG.14)
717 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
719 switch (wMsg)
721 case WM_INITDIALOG:
722 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
723 ShowWindow(hWnd, SW_SHOWNORMAL);
724 return (TRUE);
725 case WM_COMMAND:
726 switch (wParam)
728 case IDOK:
729 EndDialog(hWnd, TRUE);
730 return(TRUE);
731 case IDCANCEL:
732 EndDialog(hWnd, FALSE);
733 return(TRUE);
735 return(FALSE);
737 return FALSE;
741 /***********************************************************************
742 * PrintDlg (COMMDLG.20)
744 BOOL PrintDlg(LPPRINTDLG lpPrint)
746 HANDLE hInst, hDlgTmpl;
747 BOOL bRet;
749 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
751 if (lpPrint->Flags & PD_RETURNDEFAULT)
752 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
753 return TRUE;
755 if (lpPrint->Flags & PD_PRINTSETUP)
756 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP );
757 else
758 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT );
760 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
761 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
762 (lpPrint->Flags & PD_PRINTSETUP) ?
763 GetWndProcEntry16("PrintSetupDlgProc") :
764 GetWndProcEntry16("PrintDlgProc"),
765 (DWORD)lpPrint );
766 SYSRES_FreeResource( hDlgTmpl );
767 return bRet;
771 /***********************************************************************
772 * PrintDlgProc (COMMDLG.21)
774 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
776 switch (wMsg)
778 case WM_INITDIALOG:
779 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
780 ShowWindow(hWnd, SW_SHOWNORMAL);
781 return (TRUE);
782 case WM_COMMAND:
783 switch (wParam)
785 case IDOK:
786 EndDialog(hWnd, TRUE);
787 return(TRUE);
788 case IDCANCEL:
789 EndDialog(hWnd, FALSE);
790 return(TRUE);
792 return(FALSE);
794 return FALSE;
798 /***********************************************************************
799 * PrintSetupDlgProc (COMMDLG.22)
801 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
803 switch (wMsg)
805 case WM_INITDIALOG:
806 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
807 ShowWindow(hWnd, SW_SHOWNORMAL);
808 return (TRUE);
809 case WM_COMMAND:
810 switch (wParam) {
811 case IDOK:
812 EndDialog(hWnd, TRUE);
813 return(TRUE);
814 case IDCANCEL:
815 EndDialog(hWnd, FALSE);
816 return(TRUE);
818 return(FALSE);
820 return FALSE;
824 /***********************************************************************
825 * CommDlgExtendedError (COMMDLG.26)
827 DWORD CommDlgExtendedError(void)
829 return CommDlgLastError;
833 /***********************************************************************
834 * GetFileTitle (COMMDLG.27)
836 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
838 int i, len;
839 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
840 if (lpFile == NULL || lpTitle == NULL)
841 return -1;
842 len = strlen(lpFile);
843 if (len == 0)
844 return -1;
845 if (strpbrk(lpFile, "*[]"))
846 return -1;
847 len--;
848 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
849 return -1;
850 for (i = len; i >= 0; i--)
851 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
853 i++;
854 break;
856 printf("\n---> '%s' ", &lpFile[i]);
858 len = strlen(lpFile+i)+1;
859 if (cbBuf < len)
860 return len;
862 strncpy(lpTitle, &lpFile[i], len);
863 return 0;