Release 960114
[wine/gsoc-2012-control.git] / misc / commdlg.c
blob8991597f0140754c4f2c8b5f2a95c4887a45e275
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 "drive.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 = SYSRES_LoadResource( SYSRES_DIALOG_OPEN_FILE );
76 if (!hDlgTmpl)
78 CommDlgLastError = CDERR_LOADRESFAILURE;
79 return FALSE;
82 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
83 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
84 GetWndProcEntry16("FileOpenDlgProc"),
85 (DWORD)lpofn );
87 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
89 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( hDlgTmpl );
90 else SYSRES_FreeResource( hDlgTmpl );
93 printf("GetOpenFileName // return lpstrFile='%s' !\n",
94 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
95 return bRet;
99 /***********************************************************************
100 * GetSaveFileName (COMMDLG.2)
102 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
104 HINSTANCE hInst;
105 HANDLE hDlgTmpl, hResInfo;
106 BOOL bRet;
108 if (!lpofn || !FileDlg_Init()) return FALSE;
110 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
111 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
113 hInst = lpofn->hInstance;
114 if (!(hResInfo = FindResource( lpofn->hInstance,
115 lpofn->lpTemplateName, RT_DIALOG )))
117 CommDlgLastError = CDERR_FINDRESFAILURE;
118 return FALSE;
120 hDlgTmpl = LoadResource( lpofn->hInstance, hResInfo );
122 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE );
124 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
125 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
126 GetWndProcEntry16("FileSaveDlgProc"),
127 (DWORD)lpofn);
128 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
130 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( hDlgTmpl );
131 else SYSRES_FreeResource( hDlgTmpl );
134 printf( "GetSaveFileName // return lpstrFile='%s' !\n",
135 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
136 return bRet;
139 /***********************************************************************
140 * FILEDLG_StripEditControl [internal]
141 * Strip pathnames off the contents of the edit control.
143 static void FILEDLG_StripEditControl(HWND hwnd)
145 char temp[512], *cp;
147 SendDlgItemMessage(hwnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(temp));
148 cp = strrchr(temp, '\\');
149 if (cp != NULL) {
150 strcpy(temp, cp+1);
152 cp = strrchr(temp, ':');
153 if (cp != NULL) {
154 strcpy(temp, cp+1);
158 /***********************************************************************
159 * FILEDLG_ScanDir [internal]
161 static BOOL FILEDLG_ScanDir(HWND hWnd, LPSTR newPath)
163 char str[512],str2[512];
165 strncpy(str,newPath,511); str[511]=0;
166 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(str2));
167 strncat(str,str2,511-strlen(str)); str[511]=0;
168 if (!DlgDirList(hWnd, MAKE_SEGPTR(str), lst1, 0, 0x0000)) return FALSE;
169 strcpy( str, "*.*" );
170 DlgDirList(hWnd, MAKE_SEGPTR(str), lst2, stc1, 0x8010);
171 return TRUE;
174 /***********************************************************************
175 * FILEDLG_GetFileType [internal]
178 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
180 int n, i;
181 i = 0;
182 if (cfptr)
183 for ( ;(n = strlen(cfptr)) != 0; i++)
185 cfptr += n + 1;
186 if (i == index)
187 return cfptr;
188 cfptr += strlen(cfptr) + 1;
190 if (fptr)
191 for ( ;(n = strlen(fptr)) != 0; i++)
193 fptr += n + 1;
194 if (i == index)
195 return fptr;
196 fptr += strlen(fptr) + 1;
198 return NULL;
201 /***********************************************************************
202 * FILEDLG_WMDrawItem [internal]
204 static LONG FILEDLG_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
206 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
207 char str[512];
208 HBRUSH hBrush;
209 HBITMAP hBitmap, hPrevBitmap;
210 BITMAP bm;
211 HDC hMemDC;
213 str[0]=0;
214 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
215 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
216 SelectObject(lpdis->hDC, hBrush);
217 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
218 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
219 (LPARAM)MAKE_SEGPTR(str));
220 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
221 str, strlen(str));
222 if (lpdis->itemState != 0) {
223 InvertRect(lpdis->hDC, &lpdis->rcItem);
225 return TRUE;
228 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2) {
229 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
230 SelectObject(lpdis->hDC, hBrush);
231 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
232 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
233 (LPARAM)MAKE_SEGPTR(str));
235 hBitmap = hFolder;
236 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
237 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
238 lpdis->rcItem.top, str, strlen(str));
239 hMemDC = CreateCompatibleDC(lpdis->hDC);
240 hPrevBitmap = SelectObject(hMemDC, hBitmap);
241 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
242 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
243 SelectObject(hMemDC, hPrevBitmap);
244 DeleteDC(hMemDC);
245 if (lpdis->itemState != 0) {
246 InvertRect(lpdis->hDC, &lpdis->rcItem);
248 return TRUE;
250 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2) {
251 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
252 SelectObject(lpdis->hDC, hBrush);
253 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
254 SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
255 (LPARAM)MAKE_SEGPTR(str));
256 switch(str[2]) {
257 case 'a': case 'b':
258 hBitmap = hFloppy;
259 break;
260 default:
261 hBitmap = hHDisk;
262 break;
264 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
265 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
266 lpdis->rcItem.top, str, strlen(str));
267 hMemDC = CreateCompatibleDC(lpdis->hDC);
268 hPrevBitmap = SelectObject(hMemDC, hBitmap);
269 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
270 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
271 SelectObject(hMemDC, hPrevBitmap);
272 DeleteDC(hMemDC);
273 if (lpdis->itemState != 0) {
274 InvertRect(lpdis->hDC, &lpdis->rcItem);
276 return TRUE;
278 return FALSE;
281 /***********************************************************************
282 * FILEDLG_WMMeasureItem [internal]
284 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
286 BITMAP bm;
287 LPMEASUREITEMSTRUCT lpmeasure;
289 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
290 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
291 lpmeasure->itemHeight = bm.bmHeight;
292 return TRUE;
295 /***********************************************************************
296 * FILEDLG_WMInitDialog [internal]
299 static LONG FILEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
301 int n;
302 LPOPENFILENAME lpofn;
303 char tmpstr[512];
304 LPSTR pstr;
305 SetWindowLong(hWnd, DWL_USER, lParam);
306 lpofn = (LPOPENFILENAME)lParam;
307 /* read custom filter information */
308 if (lpofn->lpstrCustomFilter)
310 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
311 printf("lpstrCustomFilter = %p\n", pstr);
312 while(*pstr)
314 n = strlen(pstr);
315 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
316 printf("lpstrCustomFilter // add tmpstr='%s' ", tmpstr);
317 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
318 pstr += n + 1;
319 n = strlen(pstr);
320 printf("associated to '%s'\n", pstr);
321 pstr += n + 1;
324 /* read filter information */
325 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
326 while(*pstr)
328 n = strlen(pstr);
329 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
330 printf("lpstrFilter // add tmpstr='%s' ", tmpstr);
331 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
332 pstr += n + 1;
333 n = strlen(pstr);
334 printf("associated to '%s'\n", pstr);
335 pstr += n + 1;
337 /* set default filter */
338 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
339 lpofn->nFilterIndex = 1;
340 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL, lpofn->nFilterIndex - 1, 0);
341 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
342 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
343 tmpstr[511]=0;
344 printf("nFilterIndex = %ld // SetText of edt1 to '%s'\n",
345 lpofn->nFilterIndex, tmpstr);
346 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
347 /* get drive list */
348 *tmpstr = 0;
349 DlgDirListComboBox(hWnd, MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
350 /* read initial directory */
351 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
353 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
354 tmpstr[510]=0;
355 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
356 && tmpstr[strlen(tmpstr)-1] != ':')
357 strcat(tmpstr,"\\");
359 else
360 *tmpstr = 0;
361 if (!FILEDLG_ScanDir(hWnd, tmpstr))
362 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
363 /* select current drive in combo 2 */
364 n = DRIVE_GetCurrentDrive();
365 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, n, 0);
366 if (!(lpofn->Flags & OFN_SHOWHELP))
367 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
368 if (lpofn->Flags & OFN_HIDEREADONLY)
369 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
370 return TRUE;
373 /***********************************************************************
374 * FILEDLG_WMCommand [internal]
376 static LRESULT FILEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
378 LONG lRet;
379 LPOPENFILENAME lpofn;
380 char tmpstr[512], tmpstr2[512];
381 LPSTR pstr, pstr2;
382 UINT control,notification;
384 /* Notifications are packaged differently in Win32 */
385 #ifdef WINELIB32
386 control = LOWORD(wParam);
387 notification = HIWORD(wParam);
388 #else
389 control = wParam;
390 notification = HIWORD(lParam);
391 #endif
393 lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
394 switch (control)
396 case lst1: /* file list */
397 FILEDLG_StripEditControl(hWnd);
398 if (notification == LBN_DBLCLK)
399 goto almost_ok;
400 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
401 if (lRet == LB_ERR) return TRUE;
402 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
403 (LPARAM)MAKE_SEGPTR(tmpstr));
404 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
405 return TRUE;
406 case lst2: /* directory list */
407 FILEDLG_StripEditControl(hWnd);
408 if (notification == LBN_DBLCLK)
410 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
411 if (lRet == LB_ERR) return TRUE;
412 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet,
413 (LPARAM)MAKE_SEGPTR(tmpstr));
414 if (tmpstr[0] == '[')
416 tmpstr[strlen(tmpstr) - 1] = 0;
417 strcpy(tmpstr,tmpstr+1);
419 strcat(tmpstr, "\\");
420 goto reset_scan;
422 return TRUE;
423 case cmb1: /* file type drop list */
424 if (notification == CBN_SELCHANGE)
426 *tmpstr = 0;
427 goto reset_scan;
429 return TRUE;
430 case cmb2: /* disk drop list */
431 FILEDLG_StripEditControl(hWnd);
432 lRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
433 if (lRet == LB_ERR) return 0;
434 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, (LPARAM)MAKE_SEGPTR(tmpstr));
435 sprintf(tmpstr, "%c:", tmpstr[2]);
436 reset_scan:
437 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
438 if (lRet == LB_ERR)
439 return TRUE;
440 pstr = FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
441 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
442 lRet);
443 strncpy(tmpstr2, pstr, 511); tmpstr2[511]=0;
444 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
445 FILEDLG_ScanDir(hWnd, tmpstr);
446 return TRUE;
447 case chx1:
448 return TRUE;
449 case pshHelp:
450 return TRUE;
451 case IDOK:
452 almost_ok:
453 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(tmpstr));
454 pstr = strrchr(tmpstr, '\\');
455 if (pstr == NULL)
456 pstr = strrchr(tmpstr, ':');
457 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
459 /* edit control contains wildcards */
460 if (pstr != NULL)
462 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
463 *(pstr+1) = 0;
465 else
467 strcpy(tmpstr2, tmpstr);
468 *tmpstr=0;
470 printf("commdlg: %s, %s\n", tmpstr, tmpstr2);
471 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
472 FILEDLG_ScanDir(hWnd, tmpstr);
473 return TRUE;
475 /* no wildcards, we might have a directory or a filename */
476 /* try appending a wildcard and reading the directory */
477 pstr2 = tmpstr + strlen(tmpstr);
478 if (pstr == NULL || *(pstr+1) != 0)
479 strcat(tmpstr, "\\");
480 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
481 if (lRet == LB_ERR) return TRUE;
482 lpofn->nFilterIndex = lRet + 1;
483 printf("commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
484 strncpy(tmpstr2,
485 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
486 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
487 lRet), 511);
488 tmpstr2[511]=0;
489 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
490 /* if ScanDir succeeds, we have changed the directory */
491 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
492 /* if not, this must be a filename */
493 *pstr2 = 0;
494 if (pstr != NULL)
496 /* strip off the pathname */
497 *pstr = 0;
498 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
499 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
500 /* Should we MessageBox() if this fails? */
501 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
502 strcpy(tmpstr, tmpstr2);
504 else
505 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
506 ShowWindow(hWnd, SW_HIDE);
508 int drive = DRIVE_GetCurrentDrive();
509 tmpstr2[0] = 'A'+ drive;
510 tmpstr2[1] = ':';
511 tmpstr2[2] = '\\';
512 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(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 (LPARAM)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 = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR );
625 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
626 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
627 GetWndProcEntry16("ColorDlgProc"),
628 (DWORD)lpChCol );
629 SYSRES_FreeResource( hDlgTmpl );
630 return bRet;
634 /***********************************************************************
635 * ColorDlgProc (COMMDLG.8)
637 LRESULT ColorDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
639 switch (wMsg)
641 case WM_INITDIALOG:
642 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
643 ShowWindow(hWnd, SW_SHOWNORMAL);
644 return (TRUE);
645 case WM_COMMAND:
646 switch (wParam)
648 case IDOK:
649 EndDialog(hWnd, TRUE);
650 return(TRUE);
651 case IDCANCEL:
652 EndDialog(hWnd, FALSE);
653 return(TRUE);
655 return(FALSE);
657 return FALSE;
661 /***********************************************************************
662 * FindTextDlg (COMMDLG.11)
664 BOOL FindText(LPFINDREPLACE lpFind)
666 HANDLE hInst, hDlgTmpl;
667 BOOL bRet;
669 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT );
670 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
671 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
672 GetWndProcEntry16("FindTextDlgProc"),
673 (DWORD)lpFind );
674 SYSRES_FreeResource( hDlgTmpl );
675 return bRet;
679 /***********************************************************************
680 * ReplaceTextDlg (COMMDLG.12)
682 BOOL ReplaceText(LPFINDREPLACE lpFind)
684 HANDLE hInst, hDlgTmpl;
685 BOOL bRet;
687 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT );
688 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
689 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpFind->hwndOwner,
690 GetWndProcEntry16("ReplaceTextDlgProc"),
691 (DWORD)lpFind );
692 SYSRES_FreeResource( hDlgTmpl );
693 return bRet;
697 /***********************************************************************
698 * FindTextDlgProc (COMMDLG.13)
700 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
702 switch (wMsg)
704 case WM_INITDIALOG:
705 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
706 ShowWindow(hWnd, SW_SHOWNORMAL);
707 return (TRUE);
708 case WM_COMMAND:
709 switch (wParam)
711 case IDOK:
712 EndDialog(hWnd, TRUE);
713 return(TRUE);
714 case IDCANCEL:
715 EndDialog(hWnd, FALSE);
716 return(TRUE);
718 return(FALSE);
720 return FALSE;
724 /***********************************************************************
725 * ReplaceTextDlgProc (COMMDLG.14)
727 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
729 switch (wMsg)
731 case WM_INITDIALOG:
732 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
733 ShowWindow(hWnd, SW_SHOWNORMAL);
734 return (TRUE);
735 case WM_COMMAND:
736 switch (wParam)
738 case IDOK:
739 EndDialog(hWnd, TRUE);
740 return(TRUE);
741 case IDCANCEL:
742 EndDialog(hWnd, FALSE);
743 return(TRUE);
745 return(FALSE);
747 return FALSE;
751 /***********************************************************************
752 * PrintDlg (COMMDLG.20)
754 BOOL PrintDlg(LPPRINTDLG lpPrint)
756 HANDLE hInst, hDlgTmpl;
757 BOOL bRet;
759 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
761 if (lpPrint->Flags & PD_RETURNDEFAULT)
762 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
763 return TRUE;
765 if (lpPrint->Flags & PD_PRINTSETUP)
766 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP );
767 else
768 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT );
770 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
771 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
772 (lpPrint->Flags & PD_PRINTSETUP) ?
773 GetWndProcEntry16("PrintSetupDlgProc") :
774 GetWndProcEntry16("PrintDlgProc"),
775 (DWORD)lpPrint );
776 SYSRES_FreeResource( hDlgTmpl );
777 return bRet;
781 /***********************************************************************
782 * PrintDlgProc (COMMDLG.21)
784 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
786 switch (wMsg)
788 case WM_INITDIALOG:
789 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
790 ShowWindow(hWnd, SW_SHOWNORMAL);
791 return (TRUE);
792 case WM_COMMAND:
793 switch (wParam)
795 case IDOK:
796 EndDialog(hWnd, TRUE);
797 return(TRUE);
798 case IDCANCEL:
799 EndDialog(hWnd, FALSE);
800 return(TRUE);
802 return(FALSE);
804 return FALSE;
808 /***********************************************************************
809 * PrintSetupDlgProc (COMMDLG.22)
811 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
813 switch (wMsg)
815 case WM_INITDIALOG:
816 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
817 ShowWindow(hWnd, SW_SHOWNORMAL);
818 return (TRUE);
819 case WM_COMMAND:
820 switch (wParam) {
821 case IDOK:
822 EndDialog(hWnd, TRUE);
823 return(TRUE);
824 case IDCANCEL:
825 EndDialog(hWnd, FALSE);
826 return(TRUE);
828 return(FALSE);
830 return FALSE;
834 /***********************************************************************
835 * CommDlgExtendedError (COMMDLG.26)
837 DWORD CommDlgExtendedError(void)
839 return CommDlgLastError;
843 /***********************************************************************
844 * GetFileTitle (COMMDLG.27)
846 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
848 int i, len;
849 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
850 if (lpFile == NULL || lpTitle == NULL)
851 return -1;
852 len = strlen(lpFile);
853 if (len == 0)
854 return -1;
855 if (strpbrk(lpFile, "*[]"))
856 return -1;
857 len--;
858 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
859 return -1;
860 for (i = len; i >= 0; i--)
861 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
863 i++;
864 break;
866 printf("\n---> '%s' ", &lpFile[i]);
868 len = strlen(lpFile+i)+1;
869 if (cbBuf < len)
870 return len;
872 strncpy(lpTitle, &lpFile[i], len);
873 return 0;