Release 961023
[wine/multimedia.git] / misc / commdlg.c
blobec93f7c7eb65e2ee0fbb9f36e7435c546514372b
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "win.h"
12 #include "heap.h"
13 #include "message.h"
14 #include "commdlg.h"
15 #include "dlgs.h"
16 #include "module.h"
17 #include "resource.h"
18 #include "dos_fs.h"
19 #include "drive.h"
20 #include "stddebug.h"
21 #include "debug.h"
23 static DWORD CommDlgLastError = 0;
25 static HBITMAP16 hFolder = 0;
26 static HBITMAP16 hFolder2 = 0;
27 static HBITMAP16 hFloppy = 0;
28 static HBITMAP16 hHDisk = 0;
29 static HBITMAP16 hCDRom = 0;
30 static HBITMAP16 hBitmapTT = 0;
32 /***********************************************************************
33 * FileDlg_Init [internal]
35 static BOOL FileDlg_Init()
37 static BOOL initialized = 0;
39 if (!initialized) {
40 if (!hFolder) hFolder = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER));
41 if (!hFolder2) hFolder2 = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER2));
42 if (!hFloppy) hFloppy = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FLOPPY));
43 if (!hHDisk) hHDisk = LoadBitmap16(0, MAKEINTRESOURCE(OBM_HDISK));
44 if (!hCDRom) hCDRom = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CDROM));
45 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
46 hHDisk == 0 || hCDRom == 0)
48 fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
49 return FALSE;
51 initialized = TRUE;
53 return TRUE;
56 /***********************************************************************
57 * GetOpenFileName (COMMDLG.1)
59 BOOL GetOpenFileName( SEGPTR ofn )
61 HINSTANCE16 hInst;
62 HANDLE16 hDlgTmpl, hResInfo;
63 BOOL bRet;
64 LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(ofn);
66 if (!lpofn || !FileDlg_Init()) return FALSE;
68 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
69 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
71 if (!(hResInfo = FindResource16(lpofn->hInstance,
72 lpofn->lpTemplateName, RT_DIALOG)))
74 CommDlgLastError = CDERR_FINDRESFAILURE;
75 return FALSE;
77 hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo );
79 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_OPEN_FILE );
80 if (!hDlgTmpl)
82 CommDlgLastError = CDERR_LOADRESFAILURE;
83 return FALSE;
86 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
87 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpofn->hwndOwner,
88 (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
89 ofn );
91 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
93 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
94 else SYSRES_FreeResource( hDlgTmpl );
97 dprintf_commdlg(stddeb,"GetOpenFileName // return lpstrFile='%s' !\n",
98 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
99 return bRet;
103 /***********************************************************************
104 * GetSaveFileName (COMMDLG.2)
106 BOOL GetSaveFileName( SEGPTR ofn)
108 HINSTANCE16 hInst;
109 HANDLE16 hDlgTmpl, hResInfo;
110 BOOL bRet;
111 LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(ofn);
113 if (!lpofn || !FileDlg_Init()) return FALSE;
115 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
116 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
118 hInst = lpofn->hInstance;
119 if (!(hResInfo = FindResource16(lpofn->hInstance,
120 lpofn->lpTemplateName, RT_DIALOG )))
122 CommDlgLastError = CDERR_FINDRESFAILURE;
123 return FALSE;
125 hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo );
127 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE );
129 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
130 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpofn->hwndOwner,
131 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
132 ofn );
133 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
135 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
136 else SYSRES_FreeResource( hDlgTmpl );
139 dprintf_commdlg(stddeb, "GetSaveFileName // return lpstrFile='%s' !\n",
140 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
141 return bRet;
144 /***********************************************************************
145 * FILEDLG_StripEditControl [internal]
146 * Strip pathnames off the contents of the edit control.
148 static void FILEDLG_StripEditControl(HWND hwnd)
150 char temp[512], *cp;
152 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
153 cp = strrchr(temp, '\\');
154 if (cp != NULL) {
155 strcpy(temp, cp+1);
157 cp = strrchr(temp, ':');
158 if (cp != NULL) {
159 strcpy(temp, cp+1);
161 /* FIXME: shouldn't we do something with the result here? ;-) */
164 /***********************************************************************
165 * FILEDLG_ScanDir [internal]
167 static BOOL FILEDLG_ScanDir(HWND hWnd, LPSTR newPath)
169 BOOL32 ret = FALSE;
170 int len;
171 char *str = SEGPTR_ALLOC(512);
172 if (!str) return TRUE;
174 lstrcpyn32A( str, newPath, 512 );
175 len = strlen(str);
176 GetDlgItemText32A( hWnd, edt1, str + len, 512 - len );
177 if (DlgDirList(hWnd, SEGPTR_GET(str), lst1, 0, 0x0000))
179 strcpy( str, "*.*" );
180 DlgDirList(hWnd, SEGPTR_GET(str), lst2, stc1, 0x8010 );
181 ret = TRUE;
183 SEGPTR_FREE(str);
184 return ret;
187 /***********************************************************************
188 * FILEDLG_GetFileType [internal]
191 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
193 int n, i;
194 i = 0;
195 if (cfptr)
196 for ( ;(n = strlen(cfptr)) != 0; i++)
198 cfptr += n + 1;
199 if (i == index)
200 return cfptr;
201 cfptr += strlen(cfptr) + 1;
203 if (fptr)
204 for ( ;(n = strlen(fptr)) != 0; i++)
206 fptr += n + 1;
207 if (i == index)
208 return fptr;
209 fptr += strlen(fptr) + 1;
211 return NULL;
214 /***********************************************************************
215 * FILEDLG_WMDrawItem [internal]
217 static LONG FILEDLG_WMDrawItem(HWND hWnd, WPARAM16 wParam, LPARAM lParam,int savedlg)
219 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
220 char *str;
221 HBRUSH16 hBrush;
222 HBITMAP16 hBitmap, hPrevBitmap;
223 BITMAP16 bm;
224 HDC16 hMemDC;
226 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
228 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
229 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
230 SelectObject(lpdis->hDC, hBrush);
231 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
232 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
233 (LPARAM)SEGPTR_GET(str));
235 if (savedlg) /* use _gray_ text in FileSaveDlg */
236 if (!lpdis->itemState)
237 SetTextColor(lpdis->hDC,GetSysColor(COLOR_GRAYTEXT) );
238 else
239 SetTextColor(lpdis->hDC,GetSysColor(COLOR_WINDOWTEXT) );
240 /* inversion of gray would be bad readable */
242 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
243 str, strlen(str));
244 if (lpdis->itemState != 0) {
245 InvertRect16(lpdis->hDC, &lpdis->rcItem);
247 SEGPTR_FREE(str);
248 return TRUE;
251 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
253 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
254 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
255 SelectObject(lpdis->hDC, hBrush);
256 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
257 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
258 (LPARAM)SEGPTR_GET(str));
260 hBitmap = hFolder;
261 GetObject16( hBitmap, sizeof(bm), &bm );
262 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
263 lpdis->rcItem.top, str, strlen(str));
264 hMemDC = CreateCompatibleDC(lpdis->hDC);
265 hPrevBitmap = SelectObject(hMemDC, hBitmap);
266 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
267 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
268 SelectObject(hMemDC, hPrevBitmap);
269 DeleteDC(hMemDC);
270 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
271 SEGPTR_FREE(str);
272 return TRUE;
274 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
276 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
277 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
278 SelectObject(lpdis->hDC, hBrush);
279 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
280 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
281 (LPARAM)SEGPTR_GET(str));
282 switch(DRIVE_GetType( str[2] - 'a' ))
284 case TYPE_FLOPPY: hBitmap = hFloppy; break;
285 case TYPE_CDROM: hBitmap = hCDRom; break;
286 case TYPE_HD:
287 case TYPE_NETWORK:
288 default: hBitmap = hHDisk; break;
290 GetObject16( hBitmap, sizeof(bm), &bm );
291 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
292 lpdis->rcItem.top, str, strlen(str));
293 hMemDC = CreateCompatibleDC(lpdis->hDC);
294 hPrevBitmap = SelectObject(hMemDC, hBitmap);
295 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
296 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
297 SelectObject(hMemDC, hPrevBitmap);
298 DeleteDC(hMemDC);
299 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
300 SEGPTR_FREE(str);
301 return TRUE;
303 return FALSE;
306 /***********************************************************************
307 * FILEDLG_WMMeasureItem [internal]
309 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WPARAM16 wParam, LPARAM lParam)
311 BITMAP16 bm;
312 LPMEASUREITEMSTRUCT16 lpmeasure;
314 GetObject16( hFolder2, sizeof(bm), &bm );
315 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
316 lpmeasure->itemHeight = bm.bmHeight;
317 return TRUE;
320 /***********************************************************************
321 * FILEDLG_HookCallChk [internal]
323 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn)
325 if (lpofn)
326 if (lpofn->Flags & OFN_ENABLEHOOK)
327 if (lpofn->lpfnHook)
328 return 1;
329 return 0;
332 /***********************************************************************
333 * FILEDLG_WMInitDialog [internal]
336 static LONG FILEDLG_WMInitDialog(HWND hWnd, WPARAM16 wParam, LPARAM lParam)
338 int i, n;
339 LPOPENFILENAME lpofn;
340 char tmpstr[512];
341 LPSTR pstr;
342 SetWindowLong32A(hWnd, DWL_USER, lParam);
343 lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(lParam);
344 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
345 /* read custom filter information */
346 if (lpofn->lpstrCustomFilter)
348 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
349 n = 0;
350 dprintf_commdlg(stddeb,"lpstrCustomFilter = %p\n", pstr);
351 while(*pstr)
353 dprintf_commdlg(stddeb,"lpstrCustomFilter // add str='%s' ",pstr);
354 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING, 0,
355 (LPARAM)lpofn->lpstrCustomFilter + n );
356 n += strlen(pstr) + 1;
357 pstr += strlen(pstr) + 1;
358 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
359 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
360 n += strlen(pstr) + 1;
361 pstr += strlen(pstr) + 1;
364 /* read filter information */
365 if (lpofn->lpstrFilter) {
366 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
367 n = 0;
368 while(*pstr) {
369 dprintf_commdlg(stddeb,"lpstrFilter // add str='%s' ", pstr);
370 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING, 0,
371 (LPARAM)lpofn->lpstrFilter + n );
372 n += strlen(pstr) + 1;
373 pstr += strlen(pstr) + 1;
374 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
375 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
376 n += strlen(pstr) + 1;
377 pstr += strlen(pstr) + 1;
380 /* set default filter */
381 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
382 lpofn->nFilterIndex = 1;
383 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL, lpofn->nFilterIndex - 1, 0);
384 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
385 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
386 tmpstr[511]=0;
387 dprintf_commdlg(stddeb,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
388 lpofn->nFilterIndex, tmpstr);
389 SetDlgItemText32A( hWnd, edt1, tmpstr );
390 /* get drive list */
391 pstr = SEGPTR_ALLOC(1);
392 *pstr = 0;
393 DlgDirListComboBox16(hWnd, SEGPTR_GET(pstr), cmb2, 0, 0xC000);
394 SEGPTR_FREE(pstr);
395 /* read initial directory */
396 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
398 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
399 tmpstr[510]=0;
400 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
401 && tmpstr[strlen(tmpstr)-1] != ':')
402 strcat(tmpstr,"\\");
404 else
405 *tmpstr = 0;
406 if (!FILEDLG_ScanDir(hWnd, tmpstr))
407 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
408 /* select current drive in combo 2 */
409 n = DRIVE_GetCurrentDrive();
410 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL, n, 0);
411 if (!(lpofn->Flags & OFN_SHOWHELP))
412 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
413 if (lpofn->Flags & OFN_HIDEREADONLY)
414 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
415 if (FILEDLG_HookCallChk(lpofn))
416 return (BOOL)CallWindowProc16(lpofn->lpfnHook,
417 hWnd, WM_INITDIALOG, wParam, lParam );
418 else
419 return TRUE;
422 /***********************************************************************
423 * FILEDLG_WMCommand [internal]
425 static LRESULT FILEDLG_WMCommand(HWND hWnd, WPARAM16 wParam, LPARAM lParam)
427 LONG lRet;
428 LPOPENFILENAME lpofn;
429 OPENFILENAME ofn2;
430 char tmpstr[512], tmpstr2[512];
431 LPSTR pstr, pstr2;
432 UINT control,notification;
434 /* Notifications are packaged differently in Win32 */
435 control = wParam;
436 notification = HIWORD(lParam);
438 lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
439 switch (control)
441 case lst1: /* file list */
442 FILEDLG_StripEditControl(hWnd);
443 if (notification == LBN_DBLCLK)
444 goto almost_ok;
445 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
446 if (lRet == LB_ERR) return TRUE;
447 if ((pstr = SEGPTR_ALLOC(512)))
449 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
450 (LPARAM)SEGPTR_GET(pstr));
451 SetDlgItemText32A( hWnd, edt1, pstr );
452 SEGPTR_FREE(pstr);
454 if (FILEDLG_HookCallChk(lpofn))
455 CallWindowProc16(lpofn->lpfnHook, hWnd,
456 RegisterWindowMessage32A( LBSELCHSTRING ),
457 control, MAKELONG(lRet,CD_LBSELCHANGE));
458 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
459 return TRUE;
460 case lst2: /* directory list */
461 FILEDLG_StripEditControl(hWnd);
462 if (notification == LBN_DBLCLK)
464 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
465 if (lRet == LB_ERR) return TRUE;
466 pstr = SEGPTR_ALLOC(512);
467 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
468 (LPARAM)SEGPTR_GET(pstr));
469 strcpy( tmpstr, pstr );
470 SEGPTR_FREE(pstr);
471 if (tmpstr[0] == '[')
473 tmpstr[strlen(tmpstr) - 1] = 0;
474 strcpy(tmpstr,tmpstr+1);
476 strcat(tmpstr, "\\");
477 goto reset_scan;
479 return TRUE;
480 case cmb1: /* file type drop list */
481 if (notification == CBN_SELCHANGE)
483 *tmpstr = 0;
484 goto reset_scan;
486 return TRUE;
487 case cmb2: /* disk drop list */
488 FILEDLG_StripEditControl(hWnd);
489 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
490 if (lRet == LB_ERR) return 0;
491 pstr = SEGPTR_ALLOC(512);
492 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT, lRet,
493 (LPARAM)SEGPTR_GET(pstr));
494 sprintf(tmpstr, "%c:", pstr[2]);
495 SEGPTR_FREE(pstr);
496 reset_scan:
497 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL, 0, 0);
498 if (lRet == LB_ERR)
499 return TRUE;
500 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA, lRet, 0);
501 dprintf_commdlg(stddeb,"Selected filter : %s\n", pstr);
502 SetDlgItemText32A( hWnd, edt1, pstr );
503 FILEDLG_ScanDir(hWnd, tmpstr);
504 return TRUE;
505 case chx1:
506 return TRUE;
507 case pshHelp:
508 return TRUE;
509 case IDOK:
510 almost_ok:
511 ofn2=*lpofn; /* for later restoring */
512 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
513 pstr = strrchr(tmpstr, '\\');
514 if (pstr == NULL)
515 pstr = strrchr(tmpstr, ':');
516 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
518 /* edit control contains wildcards */
519 if (pstr != NULL)
521 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
522 *(pstr+1) = 0;
524 else
526 strcpy(tmpstr2, tmpstr);
527 *tmpstr=0;
529 dprintf_commdlg(stddeb,"commdlg: %s, %s\n", tmpstr, tmpstr2);
530 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
531 FILEDLG_ScanDir(hWnd, tmpstr);
532 return TRUE;
534 /* no wildcards, we might have a directory or a filename */
535 /* try appending a wildcard and reading the directory */
536 pstr2 = tmpstr + strlen(tmpstr);
537 if (pstr == NULL || *(pstr+1) != 0)
538 strcat(tmpstr, "\\");
539 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL, 0, 0);
540 if (lRet == LB_ERR) return TRUE;
541 lpofn->nFilterIndex = lRet + 1;
542 dprintf_commdlg(stddeb,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
543 lstrcpyn32A(tmpstr2,
544 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
545 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
546 lRet), sizeof(tmpstr2));
547 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
548 /* if ScanDir succeeds, we have changed the directory */
549 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
550 /* if not, this must be a filename */
551 *pstr2 = 0;
552 if (pstr != NULL)
554 /* strip off the pathname */
555 *pstr = 0;
556 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
557 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
558 /* Should we MessageBox() if this fails? */
559 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
560 strcpy(tmpstr, tmpstr2);
562 else SetDlgItemText32A( hWnd, edt1, tmpstr );
563 #if 0
564 ShowWindow(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
565 #endif
567 int drive = DRIVE_GetCurrentDrive();
568 tmpstr2[0] = 'A'+ drive;
569 tmpstr2[1] = ':';
570 tmpstr2[2] = '\\';
571 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
572 if (strlen(tmpstr2) > 3)
573 strcat(tmpstr2, "\\");
574 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
575 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
577 lpofn->nFileOffset = 0;
578 lpofn->nFileExtension = 0;
579 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
580 lpofn->nFileExtension++;
581 if (lpofn->nFileExtension == '\0')
582 lpofn->nFileExtension = 0;
583 else
584 lpofn->nFileExtension++;
585 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
587 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
588 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
589 lpofn->lpstrFileTitle );
591 if (FILEDLG_HookCallChk(lpofn))
593 lRet= (BOOL)CallWindowProc16(lpofn->lpfnHook,
594 hWnd, RegisterWindowMessage32A( FILEOKSTRING ), 0, lParam );
595 if (lRet)
597 *lpofn=ofn2; /* restore old state */
598 #if 0
599 ShowWindow(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
600 #endif
601 break;
604 EndDialog(hWnd, TRUE);
605 return TRUE;
606 case IDCANCEL:
607 EndDialog(hWnd, FALSE);
608 return TRUE;
610 return FALSE;
614 /***********************************************************************
615 * FileOpenDlgProc (COMMDLG.6)
617 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
619 LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
621 if (wMsg!=WM_INITDIALOG)
622 if (FILEDLG_HookCallChk(lpofn))
624 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
625 if (lRet)
626 return lRet; /* else continue message processing */
628 switch (wMsg)
630 case WM_INITDIALOG:
631 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
632 case WM_MEASUREITEM:
633 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
634 case WM_DRAWITEM:
635 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
636 case WM_COMMAND:
637 return FILEDLG_WMCommand(hWnd, wParam, lParam);
638 #if 0
639 case WM_CTLCOLOR:
640 SetBkColor((HDC16)wParam, 0x00C0C0C0);
641 switch (HIWORD(lParam))
643 case CTLCOLOR_BTN:
644 SetTextColor((HDC16)wParam, 0x00000000);
645 return hGRAYBrush;
646 case CTLCOLOR_STATIC:
647 SetTextColor((HDC16)wParam, 0x00000000);
648 return hGRAYBrush;
650 break;
651 #endif
653 return FALSE;
657 /***********************************************************************
658 * FileSaveDlgProc (COMMDLG.7)
660 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
662 LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
664 if (wMsg!=WM_INITDIALOG)
665 if (FILEDLG_HookCallChk(lpofn))
667 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
668 if (lRet)
669 return lRet; /* else continue message processing */
671 switch (wMsg) {
672 case WM_INITDIALOG:
673 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
675 case WM_MEASUREITEM:
676 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
678 case WM_DRAWITEM:
679 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
681 case WM_COMMAND:
682 return FILEDLG_WMCommand(hWnd, wParam, lParam);
686 case WM_CTLCOLOR:
687 SetBkColor((HDC16)wParam, 0x00C0C0C0);
688 switch (HIWORD(lParam))
690 case CTLCOLOR_BTN:
691 SetTextColor((HDC16)wParam, 0x00000000);
692 return hGRAYBrush;
693 case CTLCOLOR_STATIC:
694 SetTextColor((HDC16)wParam, 0x00000000);
695 return hGRAYBrush;
697 return FALSE;
700 return FALSE;
704 /***********************************************************************
705 * FindTextDlg (COMMDLG.11)
707 BOOL FindText( SEGPTR find )
709 HANDLE16 hInst, hDlgTmpl;
710 BOOL bRet;
711 LPCVOID ptr;
712 LPFINDREPLACE lpFind = (LPFINDREPLACE)PTR_SEG_TO_LIN(find);
715 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
716 * For now, only the standard dialog works.
719 * FIXME : We should do error checking on the lpFind structure here
720 * and make CommDlgExtendedError() return the error condition.
722 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT );
723 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
724 if (!(ptr = GlobalLock16( hDlgTmpl ))) return -1;
725 bRet = CreateDialogIndirectParam16( hInst, ptr, lpFind->hwndOwner,
726 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
727 find );
728 GlobalUnlock16( hDlgTmpl );
729 SYSRES_FreeResource( hDlgTmpl );
730 return bRet;
734 /***********************************************************************
735 * ReplaceTextDlg (COMMDLG.12)
737 BOOL ReplaceText( SEGPTR find )
739 HANDLE16 hInst, hDlgTmpl;
740 BOOL bRet;
741 LPCVOID ptr;
742 LPFINDREPLACE lpFind = (LPFINDREPLACE)PTR_SEG_TO_LIN(find);
745 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
746 * For now, only the standard dialog works.
749 * FIXME : We should do error checking on the lpFind structure here
750 * and make CommDlgExtendedError() return the error condition.
752 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT );
753 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
754 if (!(ptr = GlobalLock16( hDlgTmpl ))) return -1;
755 bRet = CreateDialogIndirectParam16( hInst, ptr, lpFind->hwndOwner,
756 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
757 find );
758 GlobalUnlock16( hDlgTmpl );
759 SYSRES_FreeResource( hDlgTmpl );
760 return bRet;
764 /***********************************************************************
765 * FINDDLG_WMInitDialog [internal]
767 static LRESULT FINDDLG_WMInitDialog(HWND hWnd, WPARAM16 wParam, LPARAM lParam)
769 LPFINDREPLACE lpfr;
771 SetWindowLong32A(hWnd, DWL_USER, lParam);
772 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(lParam);
773 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
775 * FIXME : If the initial FindWhat string is empty, we should disable the
776 * FindNext (IDOK) button. Only after typing some text, the button should be
777 * enabled.
779 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
780 CheckRadioButton(hWnd, rad1, rad2, (lpfr->Flags & FR_DOWN) ? rad2 : rad1);
781 if (lpfr->Flags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
782 EnableWindow(GetDlgItem(hWnd, rad1), FALSE);
783 EnableWindow(GetDlgItem(hWnd, rad2), FALSE);
785 if (lpfr->Flags & FR_HIDEUPDOWN) {
786 ShowWindow(GetDlgItem(hWnd, rad1), SW_HIDE);
787 ShowWindow(GetDlgItem(hWnd, rad2), SW_HIDE);
788 ShowWindow(GetDlgItem(hWnd, grp1), SW_HIDE);
790 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
791 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
792 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
793 if (lpfr->Flags & FR_HIDEWHOLEWORD)
794 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
795 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
796 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
797 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
798 if (lpfr->Flags & FR_HIDEMATCHCASE)
799 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
800 if (!(lpfr->Flags & FR_SHOWHELP)) {
801 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
802 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
804 ShowWindow(hWnd, SW_SHOWNORMAL);
805 return TRUE;
809 /***********************************************************************
810 * FINDDLG_WMCommand [internal]
812 static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM16 wParam, LPARAM lParam)
814 LPFINDREPLACE lpfr;
815 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
816 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
818 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
819 switch (wParam) {
820 case IDOK:
821 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
822 if (IsDlgButtonChecked(hWnd, rad2))
823 lpfr->Flags |= FR_DOWN;
824 else lpfr->Flags &= ~FR_DOWN;
825 if (IsDlgButtonChecked(hWnd, chx1))
826 lpfr->Flags |= FR_WHOLEWORD;
827 else lpfr->Flags &= ~FR_WHOLEWORD;
828 if (IsDlgButtonChecked(hWnd, chx2))
829 lpfr->Flags |= FR_MATCHCASE;
830 else lpfr->Flags &= ~FR_MATCHCASE;
831 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
832 lpfr->Flags |= FR_FINDNEXT;
833 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
834 GetWindowLong32A(hWnd, DWL_USER) );
835 return TRUE;
836 case IDCANCEL:
837 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
838 lpfr->Flags |= FR_DIALOGTERM;
839 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
840 GetWindowLong32A(hWnd, DWL_USER) );
841 DestroyWindow(hWnd);
842 return TRUE;
843 case pshHelp:
844 /* FIXME : should lpfr structure be passed as an argument ??? */
845 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
846 return TRUE;
848 return FALSE;
852 /***********************************************************************
853 * FindTextDlgProc (COMMDLG.13)
855 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
857 switch (wMsg) {
858 case WM_INITDIALOG:
859 return FINDDLG_WMInitDialog(hWnd, wParam, lParam);
860 case WM_COMMAND:
861 return FINDDLG_WMCommand(hWnd, wParam, lParam);
863 return FALSE;
867 /***********************************************************************
868 * REPLACEDLG_WMInitDialog [internal]
870 static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, WPARAM16 wParam, LPARAM lParam)
872 LPFINDREPLACE lpfr;
874 SetWindowLong32A(hWnd, DWL_USER, lParam);
875 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(lParam);
876 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
878 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
879 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
880 * enabled.
882 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
883 SetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith);
884 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
885 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
886 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
887 if (lpfr->Flags & FR_HIDEWHOLEWORD)
888 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
889 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
890 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
891 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
892 if (lpfr->Flags & FR_HIDEMATCHCASE)
893 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
894 if (!(lpfr->Flags & FR_SHOWHELP)) {
895 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
896 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
898 ShowWindow(hWnd, SW_SHOWNORMAL);
899 return TRUE;
903 /***********************************************************************
904 * REPLACEDLG_WMCommand [internal]
906 static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM16 wParam, LPARAM lParam)
908 LPFINDREPLACE lpfr;
909 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
910 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
912 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
913 switch (wParam) {
914 case IDOK:
915 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
916 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
917 if (IsDlgButtonChecked(hWnd, chx1))
918 lpfr->Flags |= FR_WHOLEWORD;
919 else lpfr->Flags &= ~FR_WHOLEWORD;
920 if (IsDlgButtonChecked(hWnd, chx2))
921 lpfr->Flags |= FR_MATCHCASE;
922 else lpfr->Flags &= ~FR_MATCHCASE;
923 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
924 lpfr->Flags |= FR_FINDNEXT;
925 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
926 GetWindowLong32A(hWnd, DWL_USER) );
927 return TRUE;
928 case IDCANCEL:
929 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
930 lpfr->Flags |= FR_DIALOGTERM;
931 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
932 GetWindowLong32A(hWnd, DWL_USER) );
933 DestroyWindow(hWnd);
934 return TRUE;
935 case psh1:
936 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
937 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
938 if (IsDlgButtonChecked(hWnd, chx1))
939 lpfr->Flags |= FR_WHOLEWORD;
940 else lpfr->Flags &= ~FR_WHOLEWORD;
941 if (IsDlgButtonChecked(hWnd, chx2))
942 lpfr->Flags |= FR_MATCHCASE;
943 else lpfr->Flags &= ~FR_MATCHCASE;
944 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
945 lpfr->Flags |= FR_REPLACE;
946 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
947 GetWindowLong32A(hWnd, DWL_USER) );
948 return TRUE;
949 case psh2:
950 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
951 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
952 if (IsDlgButtonChecked(hWnd, chx1))
953 lpfr->Flags |= FR_WHOLEWORD;
954 else lpfr->Flags &= ~FR_WHOLEWORD;
955 if (IsDlgButtonChecked(hWnd, chx2))
956 lpfr->Flags |= FR_MATCHCASE;
957 else lpfr->Flags &= ~FR_MATCHCASE;
958 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
959 lpfr->Flags |= FR_REPLACEALL;
960 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
961 GetWindowLong32A(hWnd, DWL_USER) );
962 return TRUE;
963 case pshHelp:
964 /* FIXME : should lpfr structure be passed as an argument ??? */
965 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
966 return TRUE;
968 return FALSE;
972 /***********************************************************************
973 * ReplaceTextDlgProc (COMMDLG.14)
975 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
977 switch (wMsg) {
978 case WM_INITDIALOG:
979 return REPLACEDLG_WMInitDialog(hWnd, wParam, lParam);
980 case WM_COMMAND:
981 return REPLACEDLG_WMCommand(hWnd, wParam, lParam);
983 return FALSE;
987 /***********************************************************************
988 * PrintDlg (COMMDLG.20)
990 BOOL PrintDlg( SEGPTR printdlg )
992 HANDLE16 hInst, hDlgTmpl;
993 BOOL bRet;
994 LPPRINTDLG lpPrint = (LPPRINTDLG)PTR_SEG_TO_LIN(printdlg);
996 dprintf_commdlg(stddeb,"PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
998 if (lpPrint->Flags & PD_RETURNDEFAULT)
999 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1000 return TRUE;
1002 if (lpPrint->Flags & PD_PRINTSETUP)
1003 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP );
1004 else
1005 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT );
1007 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1008 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpPrint->hwndOwner,
1009 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
1010 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1011 MODULE_GetWndProcEntry16("PrintDlgProc")),
1012 printdlg );
1013 SYSRES_FreeResource( hDlgTmpl );
1014 return bRet;
1018 /***********************************************************************
1019 * PrintDlgProc (COMMDLG.21)
1021 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
1023 switch (wMsg)
1025 case WM_INITDIALOG:
1026 dprintf_commdlg(stddeb,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1027 ShowWindow(hWnd, SW_SHOWNORMAL);
1028 return (TRUE);
1029 case WM_COMMAND:
1030 switch (wParam)
1032 case IDOK:
1033 EndDialog(hWnd, TRUE);
1034 return(TRUE);
1035 case IDCANCEL:
1036 EndDialog(hWnd, FALSE);
1037 return(TRUE);
1039 return(FALSE);
1041 return FALSE;
1045 /***********************************************************************
1046 * PrintSetupDlgProc (COMMDLG.22)
1048 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
1050 switch (wMsg)
1052 case WM_INITDIALOG:
1053 dprintf_commdlg(stddeb,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1054 ShowWindow(hWnd, SW_SHOWNORMAL);
1055 return (TRUE);
1056 case WM_COMMAND:
1057 switch (wParam) {
1058 case IDOK:
1059 EndDialog(hWnd, TRUE);
1060 return(TRUE);
1061 case IDCANCEL:
1062 EndDialog(hWnd, FALSE);
1063 return(TRUE);
1065 return(FALSE);
1067 return FALSE;
1071 /***********************************************************************
1072 * CommDlgExtendedError (COMMDLG.26)
1074 DWORD CommDlgExtendedError(void)
1076 return CommDlgLastError;
1080 /***********************************************************************
1081 * GetFileTitle (COMMDLG.27)
1083 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
1085 int i, len;
1086 dprintf_commdlg(stddeb,"GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1087 if (lpFile == NULL || lpTitle == NULL)
1088 return -1;
1089 len = strlen(lpFile);
1090 if (len == 0)
1091 return -1;
1092 if (strpbrk(lpFile, "*[]"))
1093 return -1;
1094 len--;
1095 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1096 return -1;
1097 for (i = len; i >= 0; i--)
1098 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1100 i++;
1101 break;
1103 dprintf_commdlg(stddeb,"\n---> '%s' ", &lpFile[i]);
1105 len = strlen(lpFile+i)+1;
1106 if (cbBuf < len)
1107 return len;
1109 strncpy(lpTitle, &lpFile[i], len);
1110 return 0;
1114 /* ------------------------ Choose Color Dialog --------------------------- */
1116 /***********************************************************************
1117 * ChooseColor (COMMDLG.5)
1119 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
1121 HINSTANCE16 hInst;
1122 HANDLE16 hDlgTmpl, hResInfo;
1123 BOOL bRet;
1125 dprintf_commdlg(stddeb,"ChooseColor\n");
1126 if (!lpChCol) return FALSE;
1127 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE) hDlgTmpl = lpChCol->hInstance;
1128 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1130 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1131 lpChCol->lpTemplateName, RT_DIALOG)))
1133 CommDlgLastError = CDERR_FINDRESFAILURE;
1134 return FALSE;
1136 hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo );
1138 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR );
1139 if (!hDlgTmpl)
1141 CommDlgLastError = CDERR_LOADRESFAILURE;
1142 return FALSE;
1144 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1145 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpChCol->hwndOwner,
1146 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1147 (DWORD)lpChCol);
1148 if (!(lpChCol->Flags & CC_ENABLETEMPLATEHANDLE))
1150 if (lpChCol->Flags & CC_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
1151 else SYSRES_FreeResource( hDlgTmpl );
1153 return bRet;
1157 static const COLORREF predefcolors[6][8]=
1159 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1160 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1161 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1162 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1164 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1165 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1166 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1167 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1169 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1170 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1171 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1172 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1175 struct CCPRIVATE
1177 LPCHOOSECOLOR lpcc; /* points to public known data structure */
1178 int nextuserdef; /* next free place in user defined color array */
1179 HDC16 hdcMem; /* color graph used for BitBlt() */
1180 HBITMAP16 hbmMem; /* color graph bitmap */
1181 RECT16 fullsize; /* original dialog window size */
1182 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
1183 RECT16 old3angle; /* last position of l-marker */
1184 RECT16 oldcross; /* last position of color/satuation marker */
1185 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1186 int h;
1187 int s;
1188 int l; /* for temporary storing of hue,sat,lum */
1191 /***********************************************************************
1192 * CC_HSLtoRGB [internal]
1194 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1196 int res=0,maxrgb;
1198 /* hue */
1199 switch(c)
1201 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1202 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1203 case 'B':break;
1206 /* l below 120 */
1207 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1208 if (hue< 80)
1209 res=0;
1210 else
1211 if (hue< 120)
1213 res=(hue-80)* maxrgb; /* 0...10240 */
1214 res/=40; /* 0...256 */
1216 else
1217 if (hue< 200)
1218 res=maxrgb;
1219 else
1221 res=(240-hue)* maxrgb;
1222 res/=40;
1224 res=res-maxrgb/2; /* -128...128 */
1226 /* saturation */
1227 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1229 /* lum above 120 */
1230 if (lum>120 && res<256)
1231 res+=((lum-120) * (256-res))/120;
1233 return MIN(res,255);
1236 /***********************************************************************
1237 * CC_RGBtoHSL [internal]
1239 static int CC_RGBtoHSL(char c,int r,int g,int b)
1241 WORD maxi,mini,mmsum,mmdif,result=0;
1242 int iresult=0;
1244 maxi=MAX(r,b);
1245 maxi=MAX(maxi,g);
1246 mini=MIN(r,b);
1247 mini=MIN(mini,g);
1249 mmsum=maxi+mini;
1250 mmdif=maxi-mini;
1252 switch(c)
1254 /* lum */
1255 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1256 result=mmsum/255; /* 0...240 */
1257 break;
1258 /* saturation */
1259 case 'S':if (!mmsum)
1260 result=0;
1261 else
1262 if (!mini || maxi==255)
1263 result=240;
1264 else
1266 result=mmdif*240; /* 0...61200=255*240 */
1267 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1269 break;
1270 /* hue */
1271 case 'H':if (!mmdif)
1272 result=160;
1273 else
1275 if (maxi==r)
1277 iresult=40*(g-b); /* -10200 ... 10200 */
1278 iresult/=(int)mmdif; /* -40 .. 40 */
1279 if (iresult<0)
1280 iresult+=240; /* 0..40 and 200..240 */
1282 else
1283 if (maxi==g)
1285 iresult=40*(b-r);
1286 iresult/=(int)mmdif;
1287 iresult+=80; /* 40 .. 120 */
1289 else
1290 if (maxi==b)
1292 iresult=40*(r-g);
1293 iresult/=(int)mmdif;
1294 iresult+=160; /* 120 .. 200 */
1296 result=iresult;
1298 break;
1300 return result; /* is this integer arithmetic precise enough ? */
1303 #define DISTANCE 4
1305 /***********************************************************************
1306 * CC_MouseCheckPredefColorArray [internal]
1308 static int CC_MouseCheckPredefColorArray(HWND hDlg,int dlgitem,int rows,int cols,
1309 LPARAM lParam,COLORREF *cr)
1311 HWND hwnd;
1312 POINT16 point = MAKEPOINT16(lParam);
1313 RECT16 rect;
1314 int dx,dy,x,y;
1316 ClientToScreen16(hDlg,&point);
1317 hwnd=GetDlgItem(hDlg,dlgitem);
1318 GetWindowRect16(hwnd,&rect);
1319 if (PtInRect16(&rect,point))
1321 dx=(rect.right-rect.left)/cols;
1322 dy=(rect.bottom-rect.top)/rows;
1323 ScreenToClient16(hwnd,&point);
1325 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1327 x=point.x/dx;
1328 y=point.y/dy;
1329 *cr=predefcolors[y][x];
1330 /* FIXME: Draw_a_Focus_Rect() */
1331 return 1;
1334 return 0;
1337 /***********************************************************************
1338 * CC_MouseCheckUserColorArray [internal]
1340 static int CC_MouseCheckUserColorArray(HWND hDlg,int dlgitem,int rows,int cols,
1341 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1343 HWND hwnd;
1344 POINT16 point = MAKEPOINT16(lParam);
1345 RECT16 rect;
1346 int dx,dy,x,y;
1348 ClientToScreen16(hDlg,&point);
1349 hwnd=GetDlgItem(hDlg,dlgitem);
1350 GetWindowRect16(hwnd,&rect);
1351 if (PtInRect16(&rect,point))
1353 dx=(rect.right-rect.left)/cols;
1354 dy=(rect.bottom-rect.top)/rows;
1355 ScreenToClient16(hwnd,&point);
1357 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1359 x=point.x/dx;
1360 y=point.y/dy;
1361 *cr=crarr[x+cols*y];
1362 /* FIXME: Draw_a_Focus_Rect() */
1363 return 1;
1366 return 0;
1369 #define MAXVERT 240
1370 #define MAXHORI 239
1372 /* 240 ^...... ^^ 240
1373 | . ||
1374 SAT | . || LUM
1375 | . ||
1376 +-----> 239 ----
1379 /***********************************************************************
1380 * CC_MouseCheckColorGraph [internal]
1382 static int CC_MouseCheckColorGraph(HWND hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1384 HWND hwnd;
1385 POINT16 point = MAKEPOINT16(lParam);
1386 RECT16 rect;
1387 long x,y;
1389 ClientToScreen16(hDlg,&point);
1390 hwnd=GetDlgItem(hDlg,dlgitem);
1391 GetWindowRect16(hwnd,&rect);
1392 if (PtInRect16(&rect,point))
1394 GetClientRect16(hwnd,&rect);
1395 ScreenToClient16(hwnd,&point);
1397 x=(long)point.x*MAXHORI;
1398 x/=rect.right;
1399 y=(long)(rect.bottom-point.y)*MAXVERT;
1400 y/=rect.bottom;
1402 if (hori)
1403 *hori=x;
1404 if (vert)
1405 *vert=y;
1406 return 1;
1408 else
1409 return 0;
1411 /***********************************************************************
1412 * CC_MouseCheckResultWindow [internal]
1414 static int CC_MouseCheckResultWindow(HWND hDlg,LPARAM lParam)
1416 HWND hwnd;
1417 POINT16 point = MAKEPOINT16(lParam);
1418 RECT16 rect;
1420 ClientToScreen16(hDlg,&point);
1421 hwnd=GetDlgItem(hDlg,0x2c5);
1422 GetWindowRect16(hwnd,&rect);
1423 if (PtInRect16(&rect,point))
1425 PostMessage(hDlg,WM_COMMAND,0x2c9,0);
1426 return 1;
1428 return 0;
1431 /***********************************************************************
1432 * CC_CheckDigitsInEdit [internal]
1434 static int CC_CheckDigitsInEdit(HWND hwnd,int maxval)
1436 int i,k,m,result,value;
1437 long editpos;
1438 char buffer[30];
1439 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1440 m=strlen(buffer);
1441 result=0;
1443 for (i=0;i<m;i++)
1444 if (buffer[i]<'0' || buffer[i]>'9')
1446 for (k=i+1;k<=m;k++) /* delete bad character */
1448 buffer[i]=buffer[k];
1449 m--;
1451 buffer[m]=0;
1452 result=1;
1455 value=atoi(buffer);
1456 if (value>maxval) /* build a new string */
1458 sprintf(buffer,"%d",maxval);
1459 result=2;
1461 if (result)
1463 editpos=SendMessage16(hwnd,EM_GETSEL,0,0);
1464 SetWindowText32A(hwnd,buffer);
1465 SendMessage16(hwnd,EM_SETSEL,0,editpos);
1467 return value;
1472 /***********************************************************************
1473 * CC_PaintSelectedColor [internal]
1475 static void CC_PaintSelectedColor(HWND hDlg,COLORREF cr)
1477 RECT16 rect;
1478 HDC32 hdc;
1479 HBRUSH16 hBrush;
1480 HWND hwnd=GetDlgItem(hDlg,0x2c5);
1481 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1483 hdc=GetDC32(hwnd);
1484 GetClientRect16 (hwnd, &rect) ;
1485 hBrush = CreateSolidBrush(cr);
1486 if (hBrush)
1488 hBrush = SelectObject (hdc, hBrush) ;
1489 Rectangle (hdc, rect.left,rect.top,rect.right/2,rect.bottom);
1490 DeleteObject (SelectObject (hdc,hBrush)) ;
1491 hBrush=CreateSolidBrush(GetNearestColor(hdc,cr));
1492 if (hBrush)
1494 hBrush= SelectObject (hdc, hBrush) ;
1495 Rectangle (hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
1496 DeleteObject (SelectObject (hdc, hBrush)) ;
1499 ReleaseDC32(hwnd,hdc);
1503 /***********************************************************************
1504 * CC_PaintTriangle [internal]
1506 static void CC_PaintTriangle(HWND hDlg,int y)
1508 HDC32 hDC;
1509 long temp;
1510 int w=GetDialogBaseUnits();
1511 POINT16 points[3];
1512 int height;
1513 int oben;
1514 RECT16 rect;
1515 HWND hwnd=GetDlgItem(hDlg,0x2be);
1516 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1518 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1520 GetClientRect16(hwnd,&rect);
1521 height=rect.bottom;
1522 hDC=GetDC32(hDlg);
1524 points[0].y=rect.top;
1525 points[0].x=rect.right; /* | /| */
1526 ClientToScreen16(hwnd,points); /* | / | */
1527 ScreenToClient16(hDlg,points); /* |< | */
1528 oben=points[0].y; /* | \ | */
1529 /* | \| */
1530 temp=(long)height*(long)y;
1531 points[0].y=oben+height -temp/(long)MAXVERT;
1532 points[1].y=points[0].y+w;
1533 points[2].y=points[0].y-w;
1534 points[2].x=points[1].x=points[0].x + w;
1536 if (lpp->old3angle.left)
1537 FillRect16(hDC,&lpp->old3angle,GetStockObject(WHITE_BRUSH));
1538 lpp->old3angle.left =points[0].x;
1539 lpp->old3angle.right =points[1].x+1;
1540 lpp->old3angle.top =points[2].y-1;
1541 lpp->old3angle.bottom=points[1].y+1;
1542 Polygon16(hDC,points,3);
1543 ReleaseDC32(hDlg,hDC);
1548 /***********************************************************************
1549 * CC_PaintCross [internal]
1551 static void CC_PaintCross(HWND hDlg,int x,int y)
1553 HDC32 hDC;
1554 int w=GetDialogBaseUnits();
1555 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1556 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1557 RECT16 rect;
1558 POINT16 point;
1559 HPEN16 hPen;
1561 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1563 GetClientRect16(hwnd,&rect);
1564 hDC=GetDC32(hwnd);
1565 SelectClipRgn(hDC,CreateRectRgnIndirect16(&rect));
1566 hPen=CreatePen(PS_SOLID,2,0);
1567 hPen=SelectObject(hDC,hPen);
1568 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
1569 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
1570 if (lpp->oldcross.left!=lpp->oldcross.right)
1571 BitBlt(hDC,lpp->oldcross.left,lpp->oldcross.top,
1572 lpp->oldcross.right-lpp->oldcross.left,
1573 lpp->oldcross.bottom-lpp->oldcross.top,
1574 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
1575 lpp->oldcross.left =point.x-w-1;
1576 lpp->oldcross.right =point.x+w+1;
1577 lpp->oldcross.top =point.y-w-1;
1578 lpp->oldcross.bottom=point.y+w+1;
1580 MoveTo(hDC,point.x-w,point.y);
1581 LineTo(hDC,point.x+w,point.y);
1582 MoveTo(hDC,point.x,point.y-w);
1583 LineTo(hDC,point.x,point.y+w);
1584 DeleteObject(SelectObject(hDC,hPen));
1585 ReleaseDC32(hwnd,hDC);
1590 #define XSTEPS 48
1591 #define YSTEPS 24
1594 /***********************************************************************
1595 * CC_PrepareColorGraph [internal]
1597 static void CC_PrepareColorGraph(HWND hDlg)
1599 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
1600 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1601 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1602 HBRUSH16 hbrush;
1603 HDC32 hdc ;
1604 RECT16 rect,client;
1605 HCURSOR16 hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
1607 GetClientRect16(hwnd,&client);
1608 hdc=GetDC32(hwnd);
1609 lpp->hdcMem = CreateCompatibleDC(hdc);
1610 lpp->hbmMem = CreateCompatibleBitmap(hdc,client.right,client.bottom);
1611 SelectObject(lpp->hdcMem,lpp->hbmMem);
1613 xdif=client.right /XSTEPS;
1614 ydif=client.bottom/YSTEPS+1;
1615 hdif=239/XSTEPS;
1616 sdif=240/YSTEPS;
1617 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
1619 rect.right=rect.left+xdif;
1620 rect.bottom=client.bottom;
1621 for(sat=0;sat<240+sdif;sat+=sdif)
1623 rect.top=rect.bottom-ydif;
1624 r=CC_HSLtoRGB('R',hue,sat,120);
1625 g=CC_HSLtoRGB('G',hue,sat,120);
1626 b=CC_HSLtoRGB('B',hue,sat,120);
1627 hbrush=CreateSolidBrush(RGB(r,g,b));
1628 FillRect16(lpp->hdcMem,&rect,hbrush);
1629 DeleteObject(hbrush);
1630 rect.bottom=rect.top;
1632 rect.left=rect.right;
1634 ReleaseDC32(hwnd,hdc);
1635 SetCursor(hcursor);
1638 /***********************************************************************
1639 * CC_PaintColorGraph [internal]
1641 static void CC_PaintColorGraph(HWND hDlg)
1643 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1644 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1645 HDC32 hDC;
1646 RECT16 rect;
1647 if (IsWindowVisible(hwnd)) /* if full size */
1649 if (!lpp->hdcMem)
1650 CC_PrepareColorGraph(hDlg); /* should not be necessary */
1652 hDC=GetDC32(hwnd);
1653 GetClientRect16(hwnd,&rect);
1654 if (lpp->hdcMem)
1655 BitBlt(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
1656 else
1657 fprintf(stderr,"choose color: hdcMem is not defined\n");
1658 ReleaseDC32(hwnd,hDC);
1661 /***********************************************************************
1662 * CC_PaintLumBar [internal]
1664 static void CC_PaintLumBar(HWND hDlg,int hue,int sat)
1666 HWND hwnd=GetDlgItem(hDlg,0x2be);
1667 RECT16 rect,client;
1668 int lum,ldif,ydif,r,g,b;
1669 HBRUSH16 hbrush;
1670 HDC32 hDC;
1672 if (IsWindowVisible(hwnd))
1674 hDC=GetDC32(hwnd);
1675 GetClientRect16(hwnd,&client);
1676 rect=client;
1678 ldif=240/YSTEPS;
1679 ydif=client.bottom/YSTEPS+1;
1680 for(lum=0;lum<240+ldif;lum+=ldif)
1682 rect.top=MAX(0,rect.bottom-ydif);
1683 r=CC_HSLtoRGB('R',hue,sat,lum);
1684 g=CC_HSLtoRGB('G',hue,sat,lum);
1685 b=CC_HSLtoRGB('B',hue,sat,lum);
1686 hbrush=CreateSolidBrush(RGB(r,g,b));
1687 FillRect16(hDC,&rect,hbrush);
1688 DeleteObject(hbrush);
1689 rect.bottom=rect.top;
1691 GetClientRect16(hwnd,&rect);
1692 FrameRect16(hDC,&rect,GetStockObject(BLACK_BRUSH));
1693 ReleaseDC32(hwnd,hDC);
1697 /***********************************************************************
1698 * CC_EditSetRGB [internal]
1700 static void CC_EditSetRGB(HWND hDlg,COLORREF cr)
1702 char buffer[10];
1703 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1704 int r=GetRValue(cr);
1705 int g=GetGValue(cr);
1706 int b=GetBValue(cr);
1707 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1709 lpp->updating=TRUE;
1710 sprintf(buffer,"%d",r);
1711 SetWindowText32A(GetDlgItem(hDlg,0x2c2),buffer);
1712 sprintf(buffer,"%d",g);
1713 SetWindowText32A(GetDlgItem(hDlg,0x2c3),buffer);
1714 sprintf(buffer,"%d",b);
1715 SetWindowText32A(GetDlgItem(hDlg,0x2c4),buffer);
1716 lpp->updating=FALSE;
1720 /***********************************************************************
1721 * CC_EditSetHSL [internal]
1723 static void CC_EditSetHSL(HWND hDlg,int h,int s,int l)
1725 char buffer[10];
1726 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1727 lpp->updating=TRUE;
1728 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1730 lpp->updating=TRUE;
1731 sprintf(buffer,"%d",h);
1732 SetWindowText32A(GetDlgItem(hDlg,0x2bf),buffer);
1733 sprintf(buffer,"%d",s);
1734 SetWindowText32A(GetDlgItem(hDlg,0x2c0),buffer);
1735 sprintf(buffer,"%d",l);
1736 SetWindowText32A(GetDlgItem(hDlg,0x2c1),buffer);
1737 lpp->updating=FALSE;
1739 CC_PaintLumBar(hDlg,h,s);
1742 /***********************************************************************
1743 * CC_SwitchToFullSize [internal]
1745 static void CC_SwitchToFullSize(HWND hDlg,COLORREF result,LPRECT16 lprect)
1747 int i;
1748 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1750 EnableWindow(GetDlgItem(hDlg,0x2cf),FALSE);
1751 CC_PrepareColorGraph(hDlg);
1752 for (i=0x2bf;i<0x2c5;i++)
1753 EnableWindow(GetDlgItem(hDlg,i),TRUE);
1754 for (i=0x2d3;i<0x2d9;i++)
1755 EnableWindow(GetDlgItem(hDlg,i),TRUE);
1756 EnableWindow(GetDlgItem(hDlg,0x2c9),TRUE);
1757 EnableWindow(GetDlgItem(hDlg,0x2c8),TRUE);
1759 if (lprect)
1760 SetWindowPos(hDlg,NULL,0,0,lprect->right-lprect->left,
1761 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
1763 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_SHOW);
1764 ShowWindow(GetDlgItem(hDlg,0x2be),SW_SHOW);
1765 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_SHOW);
1767 CC_EditSetRGB(hDlg,result);
1768 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1771 /***********************************************************************
1772 * CC_PaintPredefColorArray [internal]
1774 static void CC_PaintPredefColorArray(HWND hDlg,int rows,int cols)
1776 HWND hwnd=GetDlgItem(hDlg,0x2d0);
1777 RECT16 rect;
1778 HDC32 hdc;
1779 HBRUSH16 hBrush;
1780 int dx,dy,i,j,k;
1782 GetClientRect16(hwnd,&rect);
1783 dx=rect.right/cols;
1784 dy=rect.bottom/rows;
1785 k=rect.left;
1787 hdc=GetDC32(hwnd);
1788 GetClientRect16 (hwnd, &rect) ;
1790 for (j=0;j<rows;j++)
1792 for (i=0;i<cols;i++)
1794 hBrush = CreateSolidBrush(predefcolors[j][i]);
1795 if (hBrush)
1797 hBrush = SelectObject (hdc, hBrush) ;
1798 Rectangle (hdc, rect.left, rect.top,
1799 rect.left+dx-DISTANCE,rect.top+dy-DISTANCE);
1800 rect.left=rect.left+dx;
1801 DeleteObject (SelectObject (hdc, hBrush)) ;
1804 rect.top=rect.top+dy;
1805 rect.left=k;
1807 ReleaseDC32(hwnd,hdc);
1808 /* FIXME: draw_a_focus_rect */
1810 /***********************************************************************
1811 * CC_PaintUserColorArray [internal]
1813 static void CC_PaintUserColorArray(HWND hDlg,int rows,int cols,COLORREF* lpcr)
1815 HWND hwnd=GetDlgItem(hDlg,0x2d1);
1816 RECT16 rect;
1817 HDC32 hdc;
1818 HBRUSH16 hBrush;
1819 int dx,dy,i,j,k;
1821 GetClientRect16(hwnd,&rect);
1823 dx=rect.right/cols;
1824 dy=rect.bottom/rows;
1825 k=rect.left;
1827 hdc=GetDC32(hwnd);
1828 if (hdc)
1830 for (j=0;j<rows;j++)
1832 for (i=0;i<cols;i++)
1834 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
1835 if (hBrush)
1837 hBrush = SelectObject (hdc, hBrush) ;
1838 Rectangle (hdc, rect.left, rect.top,
1839 rect.left+dx-DISTANCE,rect.top+dy-DISTANCE);
1840 rect.left=rect.left+dx;
1841 DeleteObject (SelectObject (hdc, hBrush)) ;
1844 rect.top=rect.top+dy;
1845 rect.left=k;
1847 ReleaseDC32(hwnd,hdc);
1849 /* FIXME: draw_a_focus_rect */
1854 /***********************************************************************
1855 * CC_HookCallChk [internal]
1857 static BOOL CC_HookCallChk(LPCHOOSECOLOR lpcc)
1859 if (lpcc)
1860 if(lpcc->Flags & CC_ENABLEHOOK)
1861 if (lpcc->lpfnHook)
1862 return TRUE;
1863 return FALSE;
1866 /***********************************************************************
1867 * CC_WMInitDialog [internal]
1869 static LONG CC_WMInitDialog(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
1871 int i,res;
1872 HWND hwnd;
1873 RECT16 rect;
1874 POINT16 point;
1875 struct CCPRIVATE * lpp;
1877 dprintf_commdlg(stddeb,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1878 lpp=calloc(1,sizeof(struct CCPRIVATE));
1879 lpp->lpcc=(LPCHOOSECOLOR)lParam;
1880 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR))
1882 EndDialog (hDlg, 0) ;
1883 return FALSE;
1885 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
1887 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
1888 ShowWindow(GetDlgItem(hDlg,0x40e),SW_HIDE);
1889 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
1890 #if 0
1891 cpos=MAKELONG(5,7); /* init */
1892 if (lpp->lpcc->Flags & CC_RGBINIT)
1894 for (i=0;i<6;i++)
1895 for (j=0;j<8;j++)
1896 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
1898 cpos=MAKELONG(i,j);
1899 goto found;
1902 found:
1903 /* FIXME: Draw_a_focus_rect & set_init_values */
1904 #endif
1905 GetWindowRect16(hDlg,&lpp->fullsize);
1906 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1908 hwnd=GetDlgItem(hDlg,0x2cf);
1909 EnableWindow(hwnd,FALSE);
1911 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1913 rect=lpp->fullsize;
1914 res=rect.bottom-rect.top;
1915 hwnd=GetDlgItem(hDlg,0x2c6); /* cut at left border */
1916 point.x=point.y=0;
1917 ClientToScreen16(hwnd,&point);
1918 ScreenToClient16(hDlg,&point);
1919 GetClientRect16(hDlg,&rect);
1920 point.x+=GetSystemMetrics(SM_CXDLGFRAME);
1921 SetWindowPos(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
1923 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_HIDE);
1924 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_HIDE);
1926 else
1927 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
1928 res=TRUE;
1929 for (i=0x2bf;i<0x2c5;i++)
1930 SendMessage16(GetDlgItem(hDlg,i),EM_LIMITTEXT,3,0); /* max 3 digits: xyz */
1931 if (CC_HookCallChk(lpp->lpcc))
1932 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1933 return res;
1936 /***********************************************************************
1937 * CC_WMCommand [internal]
1939 static LRESULT CC_WMCommand(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
1941 int r,g,b,i,xx;
1942 UINT cokmsg;
1943 HDC32 hdc;
1944 COLORREF *cr;
1945 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1946 dprintf_commdlg(stddeb,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
1947 switch (wParam)
1949 case 0x2c2: /* edit notify RGB */
1950 case 0x2c3:
1951 case 0x2c4:
1952 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1954 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
1955 r=GetRValue(lpp->lpcc->rgbResult);
1956 g=GetGValue(lpp->lpcc->rgbResult);
1957 b=GetBValue(lpp->lpcc->rgbResult);
1958 xx=0;
1959 switch (wParam)
1961 case 0x2c2:if ((xx=(i!=r))) r=i;break;
1962 case 0x2c3:if ((xx=(i!=g))) g=i;break;
1963 case 0x2c4:if ((xx=(i!=b))) b=i;break;
1965 if (xx) /* something has changed */
1967 lpp->lpcc->rgbResult=RGB(r,g,b);
1968 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1969 lpp->h=CC_RGBtoHSL('H',r,g,b);
1970 lpp->s=CC_RGBtoHSL('S',r,g,b);
1971 lpp->l=CC_RGBtoHSL('L',r,g,b);
1972 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1973 CC_PaintCross(hDlg,lpp->h,lpp->s);
1974 CC_PaintTriangle(hDlg,lpp->l);
1977 break;
1979 case 0x2bf: /* edit notify HSL */
1980 case 0x2c0:
1981 case 0x2c1:
1982 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1984 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
1985 xx=0;
1986 switch (wParam)
1988 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
1989 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
1990 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
1992 if (xx) /* something has changed */
1994 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
1995 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
1996 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
1997 lpp->lpcc->rgbResult=RGB(r,g,b);
1998 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1999 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2000 CC_PaintCross(hDlg,lpp->h,lpp->s);
2001 CC_PaintTriangle(hDlg,lpp->l);
2004 break;
2006 case 0x2cf:
2007 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
2008 InvalidateRect32( hDlg, NULL, TRUE );
2009 SetFocus32(GetDlgItem(hDlg,0x2bf));
2010 break;
2012 case 0x2c8: /* add colors ... column by column */
2013 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
2014 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
2015 if (++lpp->nextuserdef==16)
2016 lpp->nextuserdef=0;
2017 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2018 break;
2020 case 0x2c9: /* resulting color */
2021 hdc=GetDC32(hDlg);
2022 lpp->lpcc->rgbResult=GetNearestColor(hdc,lpp->lpcc->rgbResult);
2023 ReleaseDC32(hDlg,hdc);
2024 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2025 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2026 r=GetRValue(lpp->lpcc->rgbResult);
2027 g=GetGValue(lpp->lpcc->rgbResult);
2028 b=GetBValue(lpp->lpcc->rgbResult);
2029 lpp->h=CC_RGBtoHSL('H',r,g,b);
2030 lpp->s=CC_RGBtoHSL('S',r,g,b);
2031 lpp->l=CC_RGBtoHSL('L',r,g,b);
2032 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2033 CC_PaintCross(hDlg,lpp->h,lpp->s);
2034 CC_PaintTriangle(hDlg,lpp->l);
2035 break;
2037 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2038 i=RegisterWindowMessage32A( HELPMSGSTRING );
2039 if (lpp->lpcc->hwndOwner)
2040 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2041 if (CC_HookCallChk(lpp->lpcc))
2042 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2043 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2044 break;
2046 case IDOK :
2047 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2048 if (lpp->lpcc->hwndOwner)
2049 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2050 break; /* do NOT close */
2052 EndDialog (hDlg, 1) ;
2053 return TRUE ;
2055 case IDCANCEL :
2056 EndDialog (hDlg, 0) ;
2057 return TRUE ;
2060 return FALSE;
2063 /***********************************************************************
2064 * CC_WMPaint [internal]
2066 static LRESULT CC_WMPaint(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
2068 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2069 /* we have to paint dialog children except text and buttons */
2071 CC_PaintPredefColorArray(hDlg,6,8);
2072 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2073 CC_PaintColorGraph(hDlg);
2074 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2075 CC_PaintCross(hDlg,lpp->h,lpp->s);
2076 CC_PaintTriangle(hDlg,lpp->l);
2077 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2079 /* special necessary for Wine */
2080 ValidateRect32(GetDlgItem(hDlg,0x2d0),NULL);
2081 ValidateRect32(GetDlgItem(hDlg,0x2d1),NULL);
2082 ValidateRect32(GetDlgItem(hDlg,0x2c6),NULL);
2083 ValidateRect32(GetDlgItem(hDlg,0x2be),NULL);
2084 ValidateRect32(GetDlgItem(hDlg,0x2c5),NULL);
2085 /* hope we can remove it later -->FIXME */
2086 return 0;
2090 /***********************************************************************
2091 * CC_WMLButtonDown [internal]
2093 static LRESULT CC_WMLButtonDown(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
2095 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2096 int r,g,b,i;
2097 i=0;
2098 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2099 i=1;
2100 else
2101 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2102 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2103 i=1;
2104 else
2105 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2106 i=2;
2107 else
2108 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2109 i=2;
2110 if (i==2)
2112 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2113 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2114 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2115 lpp->lpcc->rgbResult=RGB(r,g,b);
2117 if (i==1)
2119 r=GetRValue(lpp->lpcc->rgbResult);
2120 g=GetGValue(lpp->lpcc->rgbResult);
2121 b=GetBValue(lpp->lpcc->rgbResult);
2122 lpp->h=CC_RGBtoHSL('H',r,g,b);
2123 lpp->s=CC_RGBtoHSL('S',r,g,b);
2124 lpp->l=CC_RGBtoHSL('L',r,g,b);
2126 if (i)
2128 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2129 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2130 CC_PaintCross(hDlg,lpp->h,lpp->s);
2131 CC_PaintTriangle(hDlg,lpp->l);
2132 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2133 return TRUE;
2135 return FALSE;
2138 /***********************************************************************
2139 * ColorDlgProc (COMMDLG.8)
2141 LRESULT ColorDlgProc(HWND hDlg, UINT message,
2142 WPARAM16 wParam, LONG lParam)
2144 int res;
2145 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2146 if (message!=WM_INITDIALOG)
2148 if (!lpp)
2149 return FALSE;
2150 res=0;
2151 if (CC_HookCallChk(lpp->lpcc))
2152 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2153 if (res)
2154 return res;
2157 /* FIXME: SetRGB message
2158 if (message && message==msetrgb)
2159 return HandleSetRGB(hDlg,lParam);
2162 switch (message)
2164 case WM_INITDIALOG:
2165 return CC_WMInitDialog(hDlg,wParam,lParam);
2166 case WM_NCDESTROY:
2167 DeleteDC(lpp->hdcMem);
2168 DeleteObject(lpp->hbmMem);
2169 free(lpp);
2170 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2171 break;
2172 case WM_COMMAND:
2173 if (CC_WMCommand(hDlg, wParam, lParam))
2174 return TRUE;
2175 break;
2176 case WM_PAINT:
2177 CC_WMPaint(hDlg, wParam, lParam);
2178 break;
2179 case WM_LBUTTONDBLCLK:
2180 if (CC_MouseCheckResultWindow(hDlg,lParam))
2181 return TRUE;
2182 break;
2183 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2184 break;
2185 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2186 break;
2187 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2188 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2189 return TRUE;
2190 break;
2192 return FALSE ;
2197 /***********************************************************************
2198 * ChooseFont (COMMDLG.15)
2200 BOOL ChooseFont(LPCHOOSEFONT lpChFont)
2202 HINSTANCE16 hInst;
2203 HANDLE16 hDlgTmpl, hResInfo;
2204 BOOL bRet;
2206 dprintf_commdlg(stddeb,"ChooseFont\n");
2207 if (!lpChFont) return FALSE;
2208 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE) hDlgTmpl = lpChFont->hInstance;
2209 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2211 if (!(hResInfo = FindResource16(lpChFont->hInstance,
2212 lpChFont->lpTemplateName, RT_DIALOG)))
2214 CommDlgLastError = CDERR_FINDRESFAILURE;
2215 return FALSE;
2217 hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo );
2219 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_FONT );
2220 if (!hDlgTmpl)
2222 CommDlgLastError = CDERR_LOADRESFAILURE;
2223 return FALSE;
2225 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2226 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpChFont->hwndOwner,
2227 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2228 (DWORD)lpChFont);
2229 if (!(lpChFont->Flags & CF_ENABLETEMPLATEHANDLE))
2231 if (lpChFont->Flags & CF_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
2232 else SYSRES_FreeResource( hDlgTmpl );
2234 return bRet;
2238 #define TEXT_EXTRAS 4
2239 #define TEXT_COLORS 16
2241 static const COLORREF textcolors[TEXT_COLORS]=
2243 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2244 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2245 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2246 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2249 /***********************************************************************
2250 * CFn_HookCallChk [internal]
2252 static BOOL CFn_HookCallChk(LPCHOOSEFONT lpcf)
2254 if (lpcf)
2255 if(lpcf->Flags & CF_ENABLEHOOK)
2256 if (lpcf->lpfnHook)
2257 return TRUE;
2258 return FALSE;
2262 /***********************************************************************
2263 * FontFamilyEnumProc (COMMDLG.19)
2265 INT16 FontFamilyEnumProc( SEGPTR logfont, SEGPTR metrics,
2266 UINT16 nFontType, LPARAM lParam )
2268 int i;
2269 WORD w;
2270 HWND hwnd=LOWORD(lParam);
2271 HWND hDlg=GetParent16(hwnd);
2272 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2273 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
2275 dprintf_commdlg(stddeb,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2276 lplf->lfFaceName,nFontType);
2278 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2279 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2280 return 1;
2281 if (lpcf->Flags & CF_ANSIONLY)
2282 if (lplf->lfCharSet != ANSI_CHARSET)
2283 return 1;
2284 if (lpcf->Flags & CF_TTONLY)
2285 if (!(nFontType & 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2286 return 1;
2288 i=SendMessage16(hwnd,CB_ADDSTRING,0,
2289 (LPARAM)logfont + ((char *)lplf->lfFaceName - (char *)lplf));
2290 if (i!=CB_ERR)
2292 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2293 SendMessage16(hwnd, CB_SETITEMDATA,i,MAKELONG(nFontType,w));
2294 return 1 ; /* store some important font information */
2296 else
2297 return 0;
2300 /*************************************************************************
2301 * SetFontStylesToCombo2 [internal]
2303 * Fill font style information into combobox (without using font.c directly)
2305 static int SetFontStylesToCombo2(HWND hwnd, HDC16 hdc, LPLOGFONT16 lplf,
2306 LPTEXTMETRIC16 lptm)
2308 #define FSTYLES 4
2309 struct FONTSTYLE
2310 { int italic;
2311 int weight;
2312 char stname[20]; };
2313 static struct FONTSTYLE fontstyles[FSTYLES]={
2314 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
2315 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
2316 HFONT16 hf;
2317 int i,j;
2319 for (i=0;i<FSTYLES;i++)
2321 lplf->lfItalic=fontstyles[i].italic;
2322 lplf->lfWeight=fontstyles[i].weight;
2323 hf=CreateFontIndirect16(lplf);
2324 hf=SelectObject(hdc,hf);
2325 GetTextMetrics16(hdc,lptm);
2326 hf=SelectObject(hdc,hf);
2327 DeleteObject(hf);
2329 if (lptm->tmWeight==fontstyles[i].weight &&
2330 lptm->tmItalic==fontstyles[i].italic) /* font successful created ? */
2332 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
2333 j=SendMessage16(hwnd,CB_ADDSTRING,0,(LPARAM)SEGPTR_GET(str) );
2334 SEGPTR_FREE(str);
2335 if (j==CB_ERR) return 1;
2336 j=SendMessage16(hwnd, CB_SETITEMDATA, j,
2337 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
2338 if (j==CB_ERR) return 1;
2341 return 0;
2344 /*************************************************************************
2345 * SetFontSizesToCombo3 [internal]
2347 static int SetFontSizesToCombo3(HWND hwnd, LPLOGFONT16 lplf, LPCHOOSEFONT lpcf)
2349 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2350 int h,i,j;
2351 char *buffer;
2353 if (!(buffer = SEGPTR_ALLOC(20))) return 1;
2354 for (i=0;sizes[i] && !lplf->lfHeight;i++)
2356 h=lplf->lfHeight ? lplf->lfHeight : sizes[i];
2358 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2359 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
2361 sprintf(buffer,"%2d",h);
2362 j=SendMessage16(hwnd,CB_FINDSTRING,-1,(LPARAM)SEGPTR_GET(buffer));
2363 if (j==CB_ERR)
2365 j=SendMessage16(hwnd,CB_ADDSTRING,0,(LPARAM)SEGPTR_GET(buffer));
2366 if (j!=CB_ERR) j = SendMessage16(hwnd, CB_SETITEMDATA, j, h);
2367 if (j==CB_ERR)
2369 SEGPTR_FREE(buffer);
2370 return 1;
2375 SEGPTR_FREE(buffer);
2376 return 0;
2380 /***********************************************************************
2381 * FontStyleEnumProc (COMMDLG.18)
2383 INT16 FontStyleEnumProc( SEGPTR logfont, SEGPTR metrics,
2384 UINT16 nFontType, LPARAM lParam )
2386 HWND hcmb2=LOWORD(lParam);
2387 HWND hcmb3=HIWORD(lParam);
2388 HWND hDlg=GetParent16(hcmb3);
2389 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2390 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
2391 TEXTMETRIC16 *lptm = (TEXTMETRIC16 *)PTR_SEG_TO_LIN(metrics);
2392 int i;
2394 dprintf_commdlg(stddeb,"FontStyleEnumProc: (nFontType=%d)\n",nFontType);
2395 dprintf_commdlg(stddeb," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d ch=%d op=%d cp=%d q=%d pf=%xh\n",
2396 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,lplf->lfEscapement,lplf->lfOrientation,
2397 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,lplf->lfStrikeOut,lplf->lfCharSet,
2398 lplf->lfOutPrecision,lplf->lfClipPrecision,lplf->lfQuality,lplf->lfPitchAndFamily);
2400 if (SetFontSizesToCombo3(hcmb3, lplf ,lpcf))
2401 return 0;
2403 if (!SendMessage16(hcmb2,CB_GETCOUNT,0,0))
2405 HDC32 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2406 i=SetFontStylesToCombo2(hcmb2,hdc,lplf,lptm);
2407 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2408 ReleaseDC32(hDlg,hdc);
2409 if (i)
2410 return 0;
2412 return 1 ;
2416 /***********************************************************************
2417 * CFn_WMInitDialog [internal]
2419 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
2421 HDC32 hdc;
2422 int i,j,res,init=0;
2423 long l;
2424 LPLOGFONT16 lpxx;
2425 HCURSOR16 hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
2426 LPCHOOSEFONT lpcf;
2428 SetWindowLong32A(hDlg, DWL_USER, lParam);
2429 lpcf=(LPCHOOSEFONT)lParam;
2430 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2431 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
2433 if (lpcf->lStructSize != sizeof(CHOOSEFONT))
2435 dprintf_commdlg(stddeb,"WM_INITDIALOG: structure size failure !!!\n");
2436 EndDialog (hDlg, 0);
2437 return FALSE;
2439 if (!hBitmapTT)
2440 hBitmapTT = LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE));
2442 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
2443 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
2444 if (!(lpcf->Flags & CF_APPLY))
2445 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
2446 if (lpcf->Flags & CF_EFFECTS)
2448 for (res=1,i=0;res && i<TEXT_COLORS;i++)
2450 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2451 char *name = SEGPTR_ALLOC(20);
2452 strcpy( name, "[color name]" );
2453 j=SendDlgItemMessage16(hDlg,cmb4,CB_ADDSTRING,0,(LPARAM)SEGPTR_GET(name));
2454 SEGPTR_FREE(name);
2455 SendDlgItemMessage16(hDlg,cmb4, CB_SETITEMDATA,j,textcolors[j]);
2456 /* look for a fitting value in color combobox */
2457 if (textcolors[j]==lpcf->rgbColors)
2458 SendDlgItemMessage16(hDlg,cmb4, CB_SETCURSEL,j,0);
2461 else
2463 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
2464 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
2465 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
2466 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
2467 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
2469 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2470 if (hdc)
2472 if (!EnumFontFamilies (hdc, NULL,FontFamilyEnumProc,(LPARAM)GetDlgItem(hDlg,cmb1)))
2473 dprintf_commdlg(stddeb,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2474 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
2476 /* look for fitting font name in combobox1 */
2477 j=SendDlgItemMessage16(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
2478 if (j!=CB_ERR)
2480 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL,j,0);
2481 SendMessage16(hDlg,WM_COMMAND,cmb1,MAKELONG(GetDlgItem(hDlg,cmb1),CBN_SELCHANGE));
2482 init=1;
2483 /* look for fitting font style in combobox2 */
2484 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
2485 for (i=0;i<TEXT_EXTRAS;i++)
2487 if (l==SendDlgItemMessage16(hDlg,cmb2, CB_GETITEMDATA,i,0))
2488 SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL,i,0);
2491 /* look for fitting font size in combobox3 */
2492 j=SendDlgItemMessage16(hDlg,cmb3,CB_GETCOUNT,0,0);
2493 for (i=0;i<j;i++)
2495 if (lpxx->lfHeight==(int)SendDlgItemMessage16(hDlg,cmb3, CB_GETITEMDATA,i,0))
2496 SendDlgItemMessage16(hDlg,cmb3,CB_SETCURSEL,i,0);
2499 if (!init)
2501 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL,0,0);
2502 SendMessage16(hDlg,WM_COMMAND,cmb1,MAKELONG(GetDlgItem(hDlg,cmb1),CBN_SELCHANGE));
2505 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
2507 j=SendDlgItemMessage16(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
2508 if (j!=CB_ERR)
2510 j=SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL,j,0);
2511 SendMessage16(hDlg,WM_COMMAND,cmb2,MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
2515 else
2517 dprintf_commdlg(stddeb,"WM_INITDIALOG: HDC failure !!!\n");
2518 EndDialog (hDlg, 0);
2519 return FALSE;
2522 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2523 ReleaseDC32(hDlg,hdc);
2524 res=TRUE;
2525 if (CFn_HookCallChk(lpcf))
2526 res=CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2527 SetCursor(hcursor);
2528 return res;
2532 /***********************************************************************
2533 * CFn_WMMeasureItem [internal]
2535 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
2537 BITMAP16 bm;
2538 LPMEASUREITEMSTRUCT16 lpmi=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT16)lParam);
2539 if (!hBitmapTT)
2540 hBitmapTT = LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE));
2541 GetObject16( hBitmapTT, sizeof(bm), &bm );
2542 lpmi->itemHeight=bm.bmHeight;
2543 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2544 return 0;
2548 /***********************************************************************
2549 * CFn_WMDrawItem [internal]
2551 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
2553 HBRUSH16 hBrush;
2554 char *buffer;
2555 BITMAP16 bm;
2556 COLORREF cr;
2557 RECT16 rect;
2558 #if 0
2559 HDC16 hMemDC;
2560 int nFontType;
2561 HBITMAP16 hBitmap; /* for later TT usage */
2562 #endif
2563 LPDRAWITEMSTRUCT16 lpdi = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
2565 if (lpdi->itemID == 0xFFFF) /* got no items */
2566 DrawFocusRect16(lpdi->hDC, &lpdi->rcItem);
2567 else
2569 if (lpdi->CtlType == ODT_COMBOBOX)
2571 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
2572 SelectObject(lpdi->hDC, hBrush);
2573 FillRect16(lpdi->hDC, &lpdi->rcItem, hBrush);
2575 else
2576 return TRUE; /* this should never happen */
2578 rect=lpdi->rcItem;
2579 buffer = SEGPTR_ALLOC(40);
2580 switch (lpdi->CtlID)
2582 case cmb1: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2583 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2584 (LPARAM)SEGPTR_GET(buffer));
2585 GetObject16( hBitmapTT, sizeof(bm), &bm );
2586 TextOut16(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
2587 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2588 #if 0
2589 nFontType = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
2590 /* FIXME: draw bitmap if truetype usage */
2591 if (nFontType&TRUETYPE_FONTTYPE)
2593 hMemDC = CreateCompatibleDC(lpdi->hDC);
2594 hBitmap = SelectObject(hMemDC, hBitmapTT);
2595 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
2596 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
2597 SelectObject(hMemDC, hBitmap);
2598 DeleteDC(hMemDC);
2600 #endif
2601 break;
2602 case cmb2:
2603 case cmb3: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2604 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2605 (LPARAM)SEGPTR_GET(buffer));
2606 TextOut16(lpdi->hDC, lpdi->rcItem.left,
2607 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2608 break;
2610 case cmb4: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2611 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2612 (LPARAM)SEGPTR_GET(buffer));
2613 TextOut16(lpdi->hDC, lpdi->rcItem.left + 25+5,
2614 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2615 cr = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
2616 hBrush = CreateSolidBrush(cr);
2617 if (hBrush)
2619 hBrush = SelectObject (lpdi->hDC, hBrush) ;
2620 rect.right=rect.left+25;
2621 rect.top++;
2622 rect.left+=5;
2623 rect.bottom--;
2624 Rectangle(lpdi->hDC,rect.left,rect.top,rect.right,rect.bottom);
2625 DeleteObject (SelectObject (lpdi->hDC, hBrush)) ;
2627 rect=lpdi->rcItem;
2628 rect.left+=25+5;
2629 break;
2631 default: return TRUE; /* this should never happen */
2633 SEGPTR_FREE(buffer);
2634 if (lpdi->itemState ==ODS_SELECTED)
2635 InvertRect16(lpdi->hDC, &rect);
2637 return TRUE;
2640 /***********************************************************************
2641 * CFn_WMCtlColor [internal]
2643 LRESULT CFn_WMCtlColor(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
2645 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2647 if (lpcf->Flags & CF_EFFECTS)
2648 if (HIWORD(lParam)==CTLCOLOR_STATIC && GetDlgCtrlID(LOWORD(lParam))==stc6)
2650 SetTextColor(wParam,lpcf->rgbColors);
2651 return GetStockObject(WHITE_BRUSH);
2653 return 0;
2656 /***********************************************************************
2657 * CFn_WMCommand [internal]
2659 LRESULT CFn_WMCommand(HWND hDlg, WPARAM16 wParam, LPARAM lParam)
2661 HFONT16 hFont;
2662 int i,j;
2663 long l;
2664 HDC16 hdc;
2665 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2666 LPLOGFONT16 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2668 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam);
2669 switch (wParam)
2671 case cmb1:if (HIWORD(lParam)==CBN_SELCHANGE)
2673 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2674 if (hdc)
2676 SendDlgItemMessage16(hDlg,cmb2,CB_RESETCONTENT,0,0);
2677 SendDlgItemMessage16(hDlg,cmb3,CB_RESETCONTENT,0,0);
2678 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL,0,0);
2679 if (i!=CB_ERR)
2681 HCURSOR16 hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
2682 char *str = SEGPTR_ALLOC(256);
2683 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT,i,
2684 (LPARAM)SEGPTR_GET(str));
2685 dprintf_commdlg(stddeb,"WM_COMMAND/cmb1 =>%s\n",str);
2686 EnumFontFamilies(hdc,str,FontStyleEnumProc,
2687 MAKELONG(GetDlgItem(hDlg,cmb2),GetDlgItem(hDlg,cmb3)));
2688 SetCursor(hcursor);
2689 SEGPTR_FREE(str);
2691 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2692 ReleaseDC32(hDlg,hdc);
2694 else
2696 dprintf_commdlg(stddeb,"WM_COMMAND: HDC failure !!!\n");
2697 EndDialog (hDlg, 0);
2698 return TRUE;
2701 case chx1:
2702 case chx2:
2703 case cmb2:
2704 case cmb3:if (HIWORD(lParam)==CBN_SELCHANGE || HIWORD(lParam)== BN_CLICKED )
2706 char *str = SEGPTR_ALLOC(256);
2707 dprintf_commdlg(stddeb,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
2708 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL,0,0);
2709 if (i==CB_ERR)
2710 i=GetDlgItemText32A( hDlg, cmb1, str, 256 );
2711 else
2713 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT,i,
2714 (LPARAM)SEGPTR_GET(str));
2715 l=SendDlgItemMessage16(hDlg,cmb1,CB_GETITEMDATA,i,0);
2716 j=HIWORD(l);
2717 lpcf->nFontType = LOWORD(l);
2718 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2719 /* same value reported to the EnumFonts
2720 call back with the extra FONTTYPE_... bits added */
2721 lpxx->lfPitchAndFamily=j&0xff;
2722 lpxx->lfCharSet=j>>8;
2724 strcpy(lpxx->lfFaceName,str);
2725 SEGPTR_FREE(str);
2726 i=SendDlgItemMessage16(hDlg,cmb2,CB_GETCURSEL,0,0);
2727 if (i!=CB_ERR)
2729 l=SendDlgItemMessage16(hDlg,cmb2,CB_GETITEMDATA,i,0);
2730 if (0!=(lpxx->lfItalic=HIWORD(l)))
2731 lpcf->nFontType |= ITALIC_FONTTYPE;
2732 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
2733 lpcf->nFontType |= BOLD_FONTTYPE;
2735 i=SendDlgItemMessage16(hDlg,cmb3,CB_GETCURSEL,0,0);
2736 if (i!=CB_ERR)
2737 lpxx->lfHeight=-LOWORD(SendDlgItemMessage16(hDlg,cmb3,CB_GETITEMDATA,i,0));
2738 else
2739 lpxx->lfHeight=0;
2740 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
2741 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
2742 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
2743 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
2744 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
2745 lpxx->lfQuality=DEFAULT_QUALITY;
2746 lpcf->iPointSize= -10*lpxx->lfHeight;
2748 hFont=CreateFontIndirect16(lpxx);
2749 if (hFont)
2750 SendDlgItemMessage16(hDlg,stc6,WM_SETFONT,hFont,TRUE);
2751 /* FIXME: Delete old font ...? */
2753 break;
2755 case cmb4:i=SendDlgItemMessage16(hDlg,cmb4,CB_GETCURSEL,0,0);
2756 if (i!=CB_ERR)
2758 lpcf->rgbColors=textcolors[i];
2759 InvalidateRect32( GetDlgItem(hDlg,stc6), NULL, 0 );
2761 break;
2763 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
2764 if (lpcf->hwndOwner)
2765 SendMessage16(lpcf->hwndOwner,i,0,(LPARAM)lpcf);
2766 if (CFn_HookCallChk(lpcf))
2767 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);
2768 break;
2770 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2771 ( (lpcf->Flags & CF_LIMITSIZE) &&
2772 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
2773 (-lpxx->lfHeight <= lpcf->nSizeMax)))
2774 EndDialog(hDlg, TRUE);
2775 else
2777 char buffer[80];
2778 sprintf(buffer,"Select a font size between %d and %d points.",
2779 lpcf->nSizeMin,lpcf->nSizeMax);
2780 MessageBox(hDlg,buffer,NULL,MB_OK);
2782 return(TRUE);
2783 case IDCANCEL:EndDialog(hDlg, FALSE);
2784 return(TRUE);
2786 return(FALSE);
2790 /***********************************************************************
2791 * FormatCharDlgProc (COMMDLG.16)
2792 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2793 2. some CF_.. flags are not supported
2794 3. some TType extensions
2796 LRESULT FormatCharDlgProc(HWND hDlg, UINT message, WPARAM16 wParam, LPARAM lParam)
2798 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2799 if (message!=WM_INITDIALOG)
2801 int res=0;
2802 if (!lpcf)
2803 return FALSE;
2804 if (CFn_HookCallChk(lpcf))
2805 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
2806 if (res)
2807 return res;
2809 else
2810 return CFn_WMInitDialog(hDlg,wParam,lParam);
2811 switch (message)
2813 case WM_MEASUREITEM:
2814 return CFn_WMMeasureItem(hDlg,wParam,lParam);
2815 case WM_DRAWITEM:
2816 return CFn_WMDrawItem(hDlg,wParam,lParam);
2817 case WM_CTLCOLOR:
2818 return CFn_WMCtlColor(hDlg,wParam,lParam);
2819 case WM_COMMAND:
2820 return CFn_WMCommand(hDlg,wParam,lParam);
2821 case WM_CHOOSEFONT_GETLOGFONT:
2822 dprintf_commdlg(stddeb,
2823 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
2824 /* FIXME: current logfont back to caller */
2825 break;
2827 return FALSE;