Release 970215
[wine/multimedia.git] / misc / commdlg.c
blob7ebe94ce64f06a14669e73133561e3b109287ce9
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 "dialog.h"
16 #include "dlgs.h"
17 #include "module.h"
18 #include "resource.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 = 0, hResInfo;
63 BOOL32 bRet = FALSE, win32Format = FALSE;
64 HWND32 hwndDialog;
65 LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(ofn);
66 LPCVOID template;
68 if (!lpofn || !FileDlg_Init()) return FALSE;
70 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
72 if (!(template = LockResource16( lpofn->hInstance )))
74 CommDlgLastError = CDERR_LOADRESFAILURE;
75 return FALSE;
78 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
80 if (!(hResInfo = FindResource16(lpofn->hInstance,
81 lpofn->lpTemplateName, RT_DIALOG)))
83 CommDlgLastError = CDERR_FINDRESFAILURE;
84 return FALSE;
86 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
87 !(template = LockResource16( hDlgTmpl )))
89 CommDlgLastError = CDERR_LOADRESFAILURE;
90 return FALSE;
93 else
95 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
96 win32Format = TRUE;
99 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
100 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
101 lpofn->hwndOwner,
102 (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
103 ofn, WIN_PROC_16 );
104 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
106 if (hDlgTmpl) FreeResource16( hDlgTmpl );
108 dprintf_commdlg(stddeb,"GetOpenFileName // return lpstrFile='%s' !\n",
109 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
110 return bRet;
114 /***********************************************************************
115 * GetSaveFileName (COMMDLG.2)
117 BOOL GetSaveFileName( SEGPTR ofn)
119 HINSTANCE16 hInst;
120 HANDLE16 hDlgTmpl = 0;
121 BOOL32 bRet = FALSE, win32Format = FALSE;
122 LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(ofn);
123 LPCVOID template;
124 HWND32 hwndDialog;
126 if (!lpofn || !FileDlg_Init()) return FALSE;
128 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
130 if (!(template = LockResource16( lpofn->hInstance )))
132 CommDlgLastError = CDERR_LOADRESFAILURE;
133 return FALSE;
136 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
138 HANDLE16 hResInfo;
139 if (!(hResInfo = FindResource16(lpofn->hInstance,
140 lpofn->lpTemplateName, RT_DIALOG)))
142 CommDlgLastError = CDERR_FINDRESFAILURE;
143 return FALSE;
145 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
146 !(template = LockResource16( hDlgTmpl )))
148 CommDlgLastError = CDERR_LOADRESFAILURE;
149 return FALSE;
152 else
154 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
155 win32Format = TRUE;
158 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
160 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
161 lpofn->hwndOwner,
162 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
163 ofn, WIN_PROC_16 );
164 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
166 if (hDlgTmpl) FreeResource16( hDlgTmpl );
168 dprintf_commdlg(stddeb, "GetSaveFileName // return lpstrFile='%s' !\n",
169 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
170 return bRet;
173 /***********************************************************************
174 * FILEDLG_StripEditControl [internal]
175 * Strip pathnames off the contents of the edit control.
177 static void FILEDLG_StripEditControl(HWND16 hwnd)
179 char temp[512], *cp;
181 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
182 cp = strrchr(temp, '\\');
183 if (cp != NULL) {
184 strcpy(temp, cp+1);
186 cp = strrchr(temp, ':');
187 if (cp != NULL) {
188 strcpy(temp, cp+1);
190 /* FIXME: shouldn't we do something with the result here? ;-) */
193 /***********************************************************************
194 * FILEDLG_ScanDir [internal]
196 static BOOL FILEDLG_ScanDir(HWND16 hWnd, LPSTR newPath)
198 int len;
199 char str[512];
201 lstrcpyn32A( str, newPath, 512 );
202 len = strlen(str);
203 GetDlgItemText32A( hWnd, edt1, str + len, sizeof(str) - len );
204 if (!DlgDirList32A( hWnd, str, lst1, 0, 0x0000 )) return FALSE;
205 return DlgDirList32A( hWnd, "*.*", lst2, stc1, 0x8010 );
208 /***********************************************************************
209 * FILEDLG_GetFileType [internal]
212 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
214 int n, i;
215 i = 0;
216 if (cfptr)
217 for ( ;(n = strlen(cfptr)) != 0; i++)
219 cfptr += n + 1;
220 if (i == index)
221 return cfptr;
222 cfptr += strlen(cfptr) + 1;
224 if (fptr)
225 for ( ;(n = strlen(fptr)) != 0; i++)
227 fptr += n + 1;
228 if (i == index)
229 return fptr;
230 fptr += strlen(fptr) + 1;
232 return NULL;
235 /***********************************************************************
236 * FILEDLG_WMDrawItem [internal]
238 static LONG FILEDLG_WMDrawItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam,int savedlg)
240 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
241 char *str;
242 HBRUSH32 hBrush;
243 HBITMAP16 hBitmap, hPrevBitmap;
244 BITMAP16 bm;
245 HDC32 hMemDC;
247 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
249 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
250 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
251 SelectObject32(lpdis->hDC, hBrush);
252 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
253 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
254 (LPARAM)SEGPTR_GET(str));
256 if (savedlg) /* use _gray_ text in FileSaveDlg */
257 if (!lpdis->itemState)
258 SetTextColor(lpdis->hDC,GetSysColor32(COLOR_GRAYTEXT) );
259 else
260 SetTextColor(lpdis->hDC,GetSysColor32(COLOR_WINDOWTEXT) );
261 /* inversion of gray would be bad readable */
263 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
264 str, strlen(str));
265 if (lpdis->itemState != 0) {
266 InvertRect16(lpdis->hDC, &lpdis->rcItem);
268 SEGPTR_FREE(str);
269 return TRUE;
272 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
274 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
275 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
276 SelectObject32(lpdis->hDC, hBrush);
277 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
278 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
279 (LPARAM)SEGPTR_GET(str));
281 hBitmap = hFolder;
282 GetObject16( hBitmap, sizeof(bm), &bm );
283 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
284 lpdis->rcItem.top, str, strlen(str));
285 hMemDC = CreateCompatibleDC32(lpdis->hDC);
286 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
287 BitBlt32(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
288 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
289 SelectObject32(hMemDC, hPrevBitmap);
290 DeleteDC32(hMemDC);
291 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
292 SEGPTR_FREE(str);
293 return TRUE;
295 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
297 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
298 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
299 SelectObject32(lpdis->hDC, hBrush);
300 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
301 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT16, lpdis->itemID,
302 (LPARAM)SEGPTR_GET(str));
303 switch(DRIVE_GetType( str[2] - 'a' ))
305 case TYPE_FLOPPY: hBitmap = hFloppy; break;
306 case TYPE_CDROM: hBitmap = hCDRom; break;
307 case TYPE_HD:
308 case TYPE_NETWORK:
309 default: hBitmap = hHDisk; break;
311 GetObject16( hBitmap, sizeof(bm), &bm );
312 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
313 lpdis->rcItem.top, str, strlen(str));
314 hMemDC = CreateCompatibleDC32(lpdis->hDC);
315 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
316 BitBlt32( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
317 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
318 SelectObject32(hMemDC, hPrevBitmap);
319 DeleteDC32(hMemDC);
320 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
321 SEGPTR_FREE(str);
322 return TRUE;
324 return FALSE;
327 /***********************************************************************
328 * FILEDLG_WMMeasureItem [internal]
330 static LONG FILEDLG_WMMeasureItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
332 BITMAP16 bm;
333 LPMEASUREITEMSTRUCT16 lpmeasure;
335 GetObject16( hFolder2, sizeof(bm), &bm );
336 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
337 lpmeasure->itemHeight = bm.bmHeight;
338 return TRUE;
341 /***********************************************************************
342 * FILEDLG_HookCallChk [internal]
344 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn)
346 if (lpofn)
347 if (lpofn->Flags & OFN_ENABLEHOOK)
348 if (lpofn->lpfnHook)
349 return 1;
350 return 0;
353 /***********************************************************************
354 * FILEDLG_WMInitDialog [internal]
357 static LONG FILEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
359 int i, n;
360 LPOPENFILENAME lpofn;
361 char tmpstr[512];
362 LPSTR pstr;
363 SetWindowLong32A(hWnd, DWL_USER, lParam);
364 lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(lParam);
365 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
366 /* read custom filter information */
367 if (lpofn->lpstrCustomFilter)
369 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
370 n = 0;
371 dprintf_commdlg(stddeb,"lpstrCustomFilter = %p\n", pstr);
372 while(*pstr)
374 dprintf_commdlg(stddeb,"lpstrCustomFilter // add str='%s' ",pstr);
375 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
376 (LPARAM)lpofn->lpstrCustomFilter + n );
377 n += strlen(pstr) + 1;
378 pstr += strlen(pstr) + 1;
379 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
380 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
381 n += strlen(pstr) + 1;
382 pstr += strlen(pstr) + 1;
385 /* read filter information */
386 if (lpofn->lpstrFilter) {
387 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
388 n = 0;
389 while(*pstr) {
390 dprintf_commdlg(stddeb,"lpstrFilter // add str='%s' ", pstr);
391 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
392 (LPARAM)lpofn->lpstrFilter + n );
393 n += strlen(pstr) + 1;
394 pstr += strlen(pstr) + 1;
395 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
396 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
397 n += strlen(pstr) + 1;
398 pstr += strlen(pstr) + 1;
401 /* set default filter */
402 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
403 lpofn->nFilterIndex = 1;
404 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL16, lpofn->nFilterIndex - 1, 0);
405 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
406 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
407 tmpstr[511]=0;
408 dprintf_commdlg(stddeb,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
409 lpofn->nFilterIndex, tmpstr);
410 SetDlgItemText32A( hWnd, edt1, tmpstr );
411 /* get drive list */
412 DlgDirListComboBox32A(hWnd, "", cmb2, 0, 0xC000);
413 /* read initial directory */
414 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
416 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
417 tmpstr[510]=0;
418 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
419 && tmpstr[strlen(tmpstr)-1] != ':')
420 strcat(tmpstr,"\\");
422 else
423 *tmpstr = 0;
424 if (!FILEDLG_ScanDir(hWnd, tmpstr))
425 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
426 /* select current drive in combo 2 */
427 n = DRIVE_GetCurrentDrive();
428 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL16, n, 0);
429 if (!(lpofn->Flags & OFN_SHOWHELP))
430 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
431 if (lpofn->Flags & OFN_HIDEREADONLY)
432 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
433 if (FILEDLG_HookCallChk(lpofn))
434 return (BOOL)CallWindowProc16(lpofn->lpfnHook,
435 hWnd, WM_INITDIALOG, wParam, lParam );
436 else
437 return TRUE;
440 /***********************************************************************
441 * FILEDLG_WMCommand [internal]
443 static LRESULT FILEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
445 LONG lRet;
446 LPOPENFILENAME lpofn;
447 OPENFILENAME ofn2;
448 char tmpstr[512], tmpstr2[512];
449 LPSTR pstr, pstr2;
450 UINT control,notification;
452 /* Notifications are packaged differently in Win32 */
453 control = wParam;
454 notification = HIWORD(lParam);
456 lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
457 switch (control)
459 case lst1: /* file list */
460 FILEDLG_StripEditControl(hWnd);
461 if (notification == LBN_DBLCLK)
462 goto almost_ok;
463 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
464 if (lRet == LB_ERR) return TRUE;
465 if ((pstr = SEGPTR_ALLOC(512)))
467 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
468 (LPARAM)SEGPTR_GET(pstr));
469 SetDlgItemText32A( hWnd, edt1, pstr );
470 SEGPTR_FREE(pstr);
472 if (FILEDLG_HookCallChk(lpofn))
473 CallWindowProc16(lpofn->lpfnHook, hWnd,
474 RegisterWindowMessage32A( LBSELCHSTRING ),
475 control, MAKELONG(lRet,CD_LBSELCHANGE));
476 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
477 return TRUE;
478 case lst2: /* directory list */
479 FILEDLG_StripEditControl(hWnd);
480 if (notification == LBN_DBLCLK)
482 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
483 if (lRet == LB_ERR) return TRUE;
484 pstr = SEGPTR_ALLOC(512);
485 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
486 (LPARAM)SEGPTR_GET(pstr));
487 strcpy( tmpstr, pstr );
488 SEGPTR_FREE(pstr);
489 if (tmpstr[0] == '[')
491 tmpstr[strlen(tmpstr) - 1] = 0;
492 strcpy(tmpstr,tmpstr+1);
494 strcat(tmpstr, "\\");
495 goto reset_scan;
497 return TRUE;
498 case cmb1: /* file type drop list */
499 if (notification == CBN_SELCHANGE)
501 *tmpstr = 0;
502 goto reset_scan;
504 return TRUE;
505 case cmb2: /* disk drop list */
506 FILEDLG_StripEditControl(hWnd);
507 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL16, 0, 0L);
508 if (lRet == LB_ERR) return 0;
509 pstr = SEGPTR_ALLOC(512);
510 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT16, lRet,
511 (LPARAM)SEGPTR_GET(pstr));
512 sprintf(tmpstr, "%c:", pstr[2]);
513 SEGPTR_FREE(pstr);
514 reset_scan:
515 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
516 if (lRet == LB_ERR)
517 return TRUE;
518 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA16, lRet, 0);
519 dprintf_commdlg(stddeb,"Selected filter : %s\n", pstr);
520 SetDlgItemText32A( hWnd, edt1, pstr );
521 FILEDLG_ScanDir(hWnd, tmpstr);
522 return TRUE;
523 case chx1:
524 return TRUE;
525 case pshHelp:
526 return TRUE;
527 case IDOK:
528 almost_ok:
529 ofn2=*lpofn; /* for later restoring */
530 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
531 pstr = strrchr(tmpstr, '\\');
532 if (pstr == NULL)
533 pstr = strrchr(tmpstr, ':');
534 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
536 /* edit control contains wildcards */
537 if (pstr != NULL)
539 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
540 *(pstr+1) = 0;
542 else
544 strcpy(tmpstr2, tmpstr);
545 *tmpstr=0;
547 dprintf_commdlg(stddeb,"commdlg: %s, %s\n", tmpstr, tmpstr2);
548 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
549 FILEDLG_ScanDir(hWnd, tmpstr);
550 return TRUE;
552 /* no wildcards, we might have a directory or a filename */
553 /* try appending a wildcard and reading the directory */
554 pstr2 = tmpstr + strlen(tmpstr);
555 if (pstr == NULL || *(pstr+1) != 0)
556 strcat(tmpstr, "\\");
557 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
558 if (lRet == LB_ERR) return TRUE;
559 lpofn->nFilterIndex = lRet + 1;
560 dprintf_commdlg(stddeb,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
561 lstrcpyn32A(tmpstr2,
562 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
563 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
564 lRet), sizeof(tmpstr2));
565 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
566 /* if ScanDir succeeds, we have changed the directory */
567 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
568 /* if not, this must be a filename */
569 *pstr2 = 0;
570 if (pstr != NULL)
572 /* strip off the pathname */
573 *pstr = 0;
574 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
575 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
576 /* Should we MessageBox() if this fails? */
577 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
578 strcpy(tmpstr, tmpstr2);
580 else SetDlgItemText32A( hWnd, edt1, tmpstr );
581 #if 0
582 ShowWindow16(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
583 #endif
585 int drive = DRIVE_GetCurrentDrive();
586 tmpstr2[0] = 'A'+ drive;
587 tmpstr2[1] = ':';
588 tmpstr2[2] = '\\';
589 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
590 if (strlen(tmpstr2) > 3)
591 strcat(tmpstr2, "\\");
592 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
593 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
595 lpofn->nFileOffset = 0;
596 lpofn->nFileExtension = 0;
597 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
598 lpofn->nFileExtension++;
599 if (lpofn->nFileExtension == '\0')
600 lpofn->nFileExtension = 0;
601 else
602 lpofn->nFileExtension++;
603 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
605 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
606 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
607 lpofn->lpstrFileTitle );
609 if (FILEDLG_HookCallChk(lpofn))
611 lRet= (BOOL)CallWindowProc16(lpofn->lpfnHook,
612 hWnd, RegisterWindowMessage32A( FILEOKSTRING ), 0, lParam );
613 if (lRet)
615 *lpofn=ofn2; /* restore old state */
616 #if 0
617 ShowWindow16(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
618 #endif
619 break;
622 EndDialog32(hWnd, TRUE);
623 return TRUE;
624 case IDCANCEL:
625 EndDialog32(hWnd, FALSE);
626 return TRUE;
628 return FALSE;
632 /***********************************************************************
633 * FileOpenDlgProc (COMMDLG.6)
635 LRESULT FileOpenDlgProc(HWND16 hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
637 LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
639 if (wMsg!=WM_INITDIALOG)
640 if (FILEDLG_HookCallChk(lpofn))
642 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
643 if (lRet)
644 return lRet; /* else continue message processing */
646 switch (wMsg)
648 case WM_INITDIALOG:
649 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
650 case WM_MEASUREITEM:
651 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
652 case WM_DRAWITEM:
653 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
654 case WM_COMMAND:
655 return FILEDLG_WMCommand(hWnd, wParam, lParam);
656 #if 0
657 case WM_CTLCOLOR:
658 SetBkColor((HDC16)wParam, 0x00C0C0C0);
659 switch (HIWORD(lParam))
661 case CTLCOLOR_BTN:
662 SetTextColor((HDC16)wParam, 0x00000000);
663 return hGRAYBrush;
664 case CTLCOLOR_STATIC:
665 SetTextColor((HDC16)wParam, 0x00000000);
666 return hGRAYBrush;
668 break;
669 #endif
671 return FALSE;
675 /***********************************************************************
676 * FileSaveDlgProc (COMMDLG.7)
678 LRESULT FileSaveDlgProc(HWND16 hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
680 LPOPENFILENAME lpofn = (LPOPENFILENAME)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
682 if (wMsg!=WM_INITDIALOG)
683 if (FILEDLG_HookCallChk(lpofn))
685 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
686 if (lRet)
687 return lRet; /* else continue message processing */
689 switch (wMsg) {
690 case WM_INITDIALOG:
691 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
693 case WM_MEASUREITEM:
694 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
696 case WM_DRAWITEM:
697 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
699 case WM_COMMAND:
700 return FILEDLG_WMCommand(hWnd, wParam, lParam);
704 case WM_CTLCOLOR:
705 SetBkColor((HDC16)wParam, 0x00C0C0C0);
706 switch (HIWORD(lParam))
708 case CTLCOLOR_BTN:
709 SetTextColor((HDC16)wParam, 0x00000000);
710 return hGRAYBrush;
711 case CTLCOLOR_STATIC:
712 SetTextColor((HDC16)wParam, 0x00000000);
713 return hGRAYBrush;
715 return FALSE;
718 return FALSE;
722 /***********************************************************************
723 * FindTextDlg (COMMDLG.11)
725 HWND16 FindText( SEGPTR find )
727 HANDLE16 hInst;
728 LPCVOID ptr;
729 LPFINDREPLACE lpFind = (LPFINDREPLACE)PTR_SEG_TO_LIN(find);
732 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
733 * For now, only the standard dialog works.
736 * FIXME : We should do error checking on the lpFind structure here
737 * and make CommDlgExtendedError() return the error condition.
739 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
740 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
741 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
742 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
743 find, WIN_PROC_16 );
747 /***********************************************************************
748 * ReplaceText (COMMDLG.12)
750 HWND16 ReplaceText( SEGPTR find )
752 HANDLE16 hInst;
753 LPCVOID ptr;
754 LPFINDREPLACE lpFind = (LPFINDREPLACE)PTR_SEG_TO_LIN(find);
757 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
758 * For now, only the standard dialog works.
761 * FIXME : We should do error checking on the lpFind structure here
762 * and make CommDlgExtendedError() return the error condition.
764 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
765 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
766 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
767 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
768 find, WIN_PROC_16 );
772 /***********************************************************************
773 * FINDDLG_WMInitDialog [internal]
775 static LRESULT FINDDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
777 LPFINDREPLACE lpfr;
779 SetWindowLong32A(hWnd, DWL_USER, lParam);
780 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(lParam);
781 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
783 * FIXME : If the initial FindWhat string is empty, we should disable the
784 * FindNext (IDOK) button. Only after typing some text, the button should be
785 * enabled.
787 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
788 CheckRadioButton32(hWnd, rad1, rad2, (lpfr->Flags & FR_DOWN) ? rad2 : rad1);
789 if (lpfr->Flags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
790 EnableWindow32(GetDlgItem32(hWnd, rad1), FALSE);
791 EnableWindow32(GetDlgItem32(hWnd, rad2), FALSE);
793 if (lpfr->Flags & FR_HIDEUPDOWN) {
794 ShowWindow32(GetDlgItem32(hWnd, rad1), SW_HIDE);
795 ShowWindow32(GetDlgItem32(hWnd, rad2), SW_HIDE);
796 ShowWindow32(GetDlgItem32(hWnd, grp1), SW_HIDE);
798 CheckDlgButton32(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
799 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
800 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
801 if (lpfr->Flags & FR_HIDEWHOLEWORD)
802 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
803 CheckDlgButton32(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
804 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
805 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
806 if (lpfr->Flags & FR_HIDEMATCHCASE)
807 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
808 if (!(lpfr->Flags & FR_SHOWHELP)) {
809 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
810 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
812 ShowWindow32(hWnd, SW_SHOWNORMAL);
813 return TRUE;
817 /***********************************************************************
818 * FINDDLG_WMCommand [internal]
820 static LRESULT FINDDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
822 LPFINDREPLACE lpfr;
823 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
824 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
826 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
827 switch (wParam) {
828 case IDOK:
829 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
830 if (IsDlgButtonChecked32(hWnd, rad2))
831 lpfr->Flags |= FR_DOWN;
832 else lpfr->Flags &= ~FR_DOWN;
833 if (IsDlgButtonChecked32(hWnd, chx1))
834 lpfr->Flags |= FR_WHOLEWORD;
835 else lpfr->Flags &= ~FR_WHOLEWORD;
836 if (IsDlgButtonChecked32(hWnd, chx2))
837 lpfr->Flags |= FR_MATCHCASE;
838 else lpfr->Flags &= ~FR_MATCHCASE;
839 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
840 lpfr->Flags |= FR_FINDNEXT;
841 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
842 GetWindowLong32A(hWnd, DWL_USER) );
843 return TRUE;
844 case IDCANCEL:
845 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
846 lpfr->Flags |= FR_DIALOGTERM;
847 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
848 GetWindowLong32A(hWnd, DWL_USER) );
849 DestroyWindow16(hWnd);
850 return TRUE;
851 case pshHelp:
852 /* FIXME : should lpfr structure be passed as an argument ??? */
853 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
854 return TRUE;
856 return FALSE;
860 /***********************************************************************
861 * FindTextDlgProc (COMMDLG.13)
863 LRESULT FindTextDlgProc(HWND16 hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
865 switch (wMsg) {
866 case WM_INITDIALOG:
867 return FINDDLG_WMInitDialog(hWnd, wParam, lParam);
868 case WM_COMMAND:
869 return FINDDLG_WMCommand(hWnd, wParam, lParam);
871 return FALSE;
875 /***********************************************************************
876 * REPLACEDLG_WMInitDialog [internal]
878 static LRESULT REPLACEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
880 LPFINDREPLACE lpfr;
882 SetWindowLong32A(hWnd, DWL_USER, lParam);
883 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(lParam);
884 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
886 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
887 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
888 * enabled.
890 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
891 SetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith);
892 CheckDlgButton32(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
893 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
894 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
895 if (lpfr->Flags & FR_HIDEWHOLEWORD)
896 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
897 CheckDlgButton32(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
898 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
899 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
900 if (lpfr->Flags & FR_HIDEMATCHCASE)
901 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
902 if (!(lpfr->Flags & FR_SHOWHELP)) {
903 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
904 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
906 ShowWindow32(hWnd, SW_SHOWNORMAL);
907 return TRUE;
911 /***********************************************************************
912 * REPLACEDLG_WMCommand [internal]
914 static LRESULT REPLACEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
916 LPFINDREPLACE lpfr;
917 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
918 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
920 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
921 switch (wParam) {
922 case IDOK:
923 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
924 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
925 if (IsDlgButtonChecked32(hWnd, chx1))
926 lpfr->Flags |= FR_WHOLEWORD;
927 else lpfr->Flags &= ~FR_WHOLEWORD;
928 if (IsDlgButtonChecked32(hWnd, chx2))
929 lpfr->Flags |= FR_MATCHCASE;
930 else lpfr->Flags &= ~FR_MATCHCASE;
931 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
932 lpfr->Flags |= FR_FINDNEXT;
933 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
934 GetWindowLong32A(hWnd, DWL_USER) );
935 return TRUE;
936 case IDCANCEL:
937 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
938 lpfr->Flags |= FR_DIALOGTERM;
939 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
940 GetWindowLong32A(hWnd, DWL_USER) );
941 DestroyWindow16(hWnd);
942 return TRUE;
943 case psh1:
944 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
945 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
946 if (IsDlgButtonChecked32(hWnd, chx1))
947 lpfr->Flags |= FR_WHOLEWORD;
948 else lpfr->Flags &= ~FR_WHOLEWORD;
949 if (IsDlgButtonChecked32(hWnd, chx2))
950 lpfr->Flags |= FR_MATCHCASE;
951 else lpfr->Flags &= ~FR_MATCHCASE;
952 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
953 lpfr->Flags |= FR_REPLACE;
954 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
955 GetWindowLong32A(hWnd, DWL_USER) );
956 return TRUE;
957 case psh2:
958 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
959 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
960 if (IsDlgButtonChecked32(hWnd, chx1))
961 lpfr->Flags |= FR_WHOLEWORD;
962 else lpfr->Flags &= ~FR_WHOLEWORD;
963 if (IsDlgButtonChecked32(hWnd, chx2))
964 lpfr->Flags |= FR_MATCHCASE;
965 else lpfr->Flags &= ~FR_MATCHCASE;
966 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
967 lpfr->Flags |= FR_REPLACEALL;
968 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
969 GetWindowLong32A(hWnd, DWL_USER) );
970 return TRUE;
971 case pshHelp:
972 /* FIXME : should lpfr structure be passed as an argument ??? */
973 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
974 return TRUE;
976 return FALSE;
980 /***********************************************************************
981 * ReplaceTextDlgProc (COMMDLG.14)
983 LRESULT ReplaceTextDlgProc(HWND16 hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
985 switch (wMsg) {
986 case WM_INITDIALOG:
987 return REPLACEDLG_WMInitDialog(hWnd, wParam, lParam);
988 case WM_COMMAND:
989 return REPLACEDLG_WMCommand(hWnd, wParam, lParam);
991 return FALSE;
995 /***********************************************************************
996 * PrintDlg (COMMDLG.20)
998 BOOL PrintDlg( SEGPTR printdlg )
1000 HANDLE16 hInst;
1001 BOOL bRet = FALSE;
1002 LPCVOID template;
1003 HWND32 hwndDialog;
1004 LPPRINTDLG lpPrint = (LPPRINTDLG)PTR_SEG_TO_LIN(printdlg);
1006 dprintf_commdlg(stddeb,"PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
1008 if (lpPrint->Flags & PD_RETURNDEFAULT)
1009 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1010 return TRUE;
1012 if (lpPrint->Flags & PD_PRINTSETUP)
1013 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
1014 else
1015 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
1017 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1018 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
1019 lpPrint->hwndOwner,
1020 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
1021 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1022 MODULE_GetWndProcEntry16("PrintDlgProc")),
1023 printdlg, WIN_PROC_16 );
1024 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
1025 return bRet;
1029 /***********************************************************************
1030 * PrintDlgProc (COMMDLG.21)
1032 LRESULT PrintDlgProc(HWND16 hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
1034 switch (wMsg)
1036 case WM_INITDIALOG:
1037 dprintf_commdlg(stddeb,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1038 ShowWindow16(hWnd, SW_SHOWNORMAL);
1039 return (TRUE);
1040 case WM_COMMAND:
1041 switch (wParam)
1043 case IDOK:
1044 EndDialog32(hWnd, TRUE);
1045 return(TRUE);
1046 case IDCANCEL:
1047 EndDialog32(hWnd, FALSE);
1048 return(TRUE);
1050 return(FALSE);
1052 return FALSE;
1056 /***********************************************************************
1057 * PrintSetupDlgProc (COMMDLG.22)
1059 LRESULT PrintSetupDlgProc(HWND16 hWnd, UINT wMsg, WPARAM16 wParam, LPARAM lParam)
1061 switch (wMsg)
1063 case WM_INITDIALOG:
1064 dprintf_commdlg(stddeb,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1065 ShowWindow16(hWnd, SW_SHOWNORMAL);
1066 return (TRUE);
1067 case WM_COMMAND:
1068 switch (wParam) {
1069 case IDOK:
1070 EndDialog32(hWnd, TRUE);
1071 return(TRUE);
1072 case IDCANCEL:
1073 EndDialog32(hWnd, FALSE);
1074 return(TRUE);
1076 return(FALSE);
1078 return FALSE;
1082 /***********************************************************************
1083 * CommDlgExtendedError (COMMDLG.26)
1085 DWORD CommDlgExtendedError(void)
1087 return CommDlgLastError;
1091 /***********************************************************************
1092 * GetFileTitle (COMMDLG.27)
1094 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
1096 int i, len;
1097 dprintf_commdlg(stddeb,"GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1098 if (lpFile == NULL || lpTitle == NULL)
1099 return -1;
1100 len = strlen(lpFile);
1101 if (len == 0)
1102 return -1;
1103 if (strpbrk(lpFile, "*[]"))
1104 return -1;
1105 len--;
1106 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1107 return -1;
1108 for (i = len; i >= 0; i--)
1109 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1111 i++;
1112 break;
1114 dprintf_commdlg(stddeb,"\n---> '%s' ", &lpFile[i]);
1116 len = strlen(lpFile+i)+1;
1117 if (cbBuf < len)
1118 return len;
1120 strncpy(lpTitle, &lpFile[i], len);
1121 return 0;
1125 /* ------------------------ Choose Color Dialog --------------------------- */
1127 /***********************************************************************
1128 * ChooseColor (COMMDLG.5)
1130 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
1132 HINSTANCE16 hInst;
1133 HANDLE16 hDlgTmpl = 0;
1134 BOOL bRet = FALSE, win32Format = FALSE;
1135 LPCVOID template;
1136 HWND32 hwndDialog;
1138 dprintf_commdlg(stddeb,"ChooseColor\n");
1139 if (!lpChCol) return FALSE;
1141 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1143 if (!(template = LockResource16( lpChCol->hInstance )))
1145 CommDlgLastError = CDERR_LOADRESFAILURE;
1146 return FALSE;
1149 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1151 HANDLE16 hResInfo;
1152 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1153 lpChCol->lpTemplateName, RT_DIALOG)))
1155 CommDlgLastError = CDERR_FINDRESFAILURE;
1156 return FALSE;
1158 if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
1159 !(template = LockResource16( hDlgTmpl )))
1161 CommDlgLastError = CDERR_LOADRESFAILURE;
1162 return FALSE;
1165 else
1167 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR );
1168 win32Format = TRUE;
1171 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1172 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
1173 lpChCol->hwndOwner,
1174 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1175 (DWORD)lpChCol, WIN_PROC_16 );
1176 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
1177 if (hDlgTmpl) FreeResource16( hDlgTmpl );
1178 return bRet;
1182 static const COLORREF predefcolors[6][8]=
1184 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1185 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1186 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1187 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1189 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1190 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1191 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1192 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1194 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1195 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1196 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1197 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1200 struct CCPRIVATE
1202 LPCHOOSECOLOR lpcc; /* points to public known data structure */
1203 int nextuserdef; /* next free place in user defined color array */
1204 HDC16 hdcMem; /* color graph used for BitBlt() */
1205 HBITMAP16 hbmMem; /* color graph bitmap */
1206 RECT16 fullsize; /* original dialog window size */
1207 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
1208 RECT16 old3angle; /* last position of l-marker */
1209 RECT16 oldcross; /* last position of color/satuation marker */
1210 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1211 int h;
1212 int s;
1213 int l; /* for temporary storing of hue,sat,lum */
1216 /***********************************************************************
1217 * CC_HSLtoRGB [internal]
1219 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1221 int res=0,maxrgb;
1223 /* hue */
1224 switch(c)
1226 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1227 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1228 case 'B':break;
1231 /* l below 120 */
1232 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1233 if (hue< 80)
1234 res=0;
1235 else
1236 if (hue< 120)
1238 res=(hue-80)* maxrgb; /* 0...10240 */
1239 res/=40; /* 0...256 */
1241 else
1242 if (hue< 200)
1243 res=maxrgb;
1244 else
1246 res=(240-hue)* maxrgb;
1247 res/=40;
1249 res=res-maxrgb/2; /* -128...128 */
1251 /* saturation */
1252 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1254 /* lum above 120 */
1255 if (lum>120 && res<256)
1256 res+=((lum-120) * (256-res))/120;
1258 return MIN(res,255);
1261 /***********************************************************************
1262 * CC_RGBtoHSL [internal]
1264 static int CC_RGBtoHSL(char c,int r,int g,int b)
1266 WORD maxi,mini,mmsum,mmdif,result=0;
1267 int iresult=0;
1269 maxi=MAX(r,b);
1270 maxi=MAX(maxi,g);
1271 mini=MIN(r,b);
1272 mini=MIN(mini,g);
1274 mmsum=maxi+mini;
1275 mmdif=maxi-mini;
1277 switch(c)
1279 /* lum */
1280 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1281 result=mmsum/255; /* 0...240 */
1282 break;
1283 /* saturation */
1284 case 'S':if (!mmsum)
1285 result=0;
1286 else
1287 if (!mini || maxi==255)
1288 result=240;
1289 else
1291 result=mmdif*240; /* 0...61200=255*240 */
1292 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1294 break;
1295 /* hue */
1296 case 'H':if (!mmdif)
1297 result=160;
1298 else
1300 if (maxi==r)
1302 iresult=40*(g-b); /* -10200 ... 10200 */
1303 iresult/=(int)mmdif; /* -40 .. 40 */
1304 if (iresult<0)
1305 iresult+=240; /* 0..40 and 200..240 */
1307 else
1308 if (maxi==g)
1310 iresult=40*(b-r);
1311 iresult/=(int)mmdif;
1312 iresult+=80; /* 40 .. 120 */
1314 else
1315 if (maxi==b)
1317 iresult=40*(r-g);
1318 iresult/=(int)mmdif;
1319 iresult+=160; /* 120 .. 200 */
1321 result=iresult;
1323 break;
1325 return result; /* is this integer arithmetic precise enough ? */
1328 #define DISTANCE 4
1330 /***********************************************************************
1331 * CC_MouseCheckPredefColorArray [internal]
1333 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1334 LPARAM lParam,COLORREF *cr)
1336 HWND16 hwnd;
1337 POINT16 point = MAKEPOINT16(lParam);
1338 RECT16 rect;
1339 int dx,dy,x,y;
1341 ClientToScreen16(hDlg,&point);
1342 hwnd=GetDlgItem32(hDlg,dlgitem);
1343 GetWindowRect16(hwnd,&rect);
1344 if (PtInRect16(&rect,point))
1346 dx=(rect.right-rect.left)/cols;
1347 dy=(rect.bottom-rect.top)/rows;
1348 ScreenToClient16(hwnd,&point);
1350 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1352 x=point.x/dx;
1353 y=point.y/dy;
1354 *cr=predefcolors[y][x];
1355 /* FIXME: Draw_a_Focus_Rect() */
1356 return 1;
1359 return 0;
1362 /***********************************************************************
1363 * CC_MouseCheckUserColorArray [internal]
1365 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1366 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1368 HWND16 hwnd;
1369 POINT16 point = MAKEPOINT16(lParam);
1370 RECT16 rect;
1371 int dx,dy,x,y;
1373 ClientToScreen16(hDlg,&point);
1374 hwnd=GetDlgItem32(hDlg,dlgitem);
1375 GetWindowRect16(hwnd,&rect);
1376 if (PtInRect16(&rect,point))
1378 dx=(rect.right-rect.left)/cols;
1379 dy=(rect.bottom-rect.top)/rows;
1380 ScreenToClient16(hwnd,&point);
1382 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1384 x=point.x/dx;
1385 y=point.y/dy;
1386 *cr=crarr[x+cols*y];
1387 /* FIXME: Draw_a_Focus_Rect() */
1388 return 1;
1391 return 0;
1394 #define MAXVERT 240
1395 #define MAXHORI 239
1397 /* 240 ^...... ^^ 240
1398 | . ||
1399 SAT | . || LUM
1400 | . ||
1401 +-----> 239 ----
1404 /***********************************************************************
1405 * CC_MouseCheckColorGraph [internal]
1407 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1409 HWND32 hwnd;
1410 POINT16 point = MAKEPOINT16(lParam);
1411 RECT16 rect;
1412 long x,y;
1414 ClientToScreen16(hDlg,&point);
1415 hwnd=GetDlgItem32(hDlg,dlgitem);
1416 GetWindowRect16(hwnd,&rect);
1417 if (PtInRect16(&rect,point))
1419 GetClientRect16(hwnd,&rect);
1420 ScreenToClient16(hwnd,&point);
1422 x=(long)point.x*MAXHORI;
1423 x/=rect.right;
1424 y=(long)(rect.bottom-point.y)*MAXVERT;
1425 y/=rect.bottom;
1427 if (hori)
1428 *hori=x;
1429 if (vert)
1430 *vert=y;
1431 return 1;
1433 else
1434 return 0;
1436 /***********************************************************************
1437 * CC_MouseCheckResultWindow [internal]
1439 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
1441 HWND16 hwnd;
1442 POINT16 point = MAKEPOINT16(lParam);
1443 RECT16 rect;
1445 ClientToScreen16(hDlg,&point);
1446 hwnd=GetDlgItem32(hDlg,0x2c5);
1447 GetWindowRect16(hwnd,&rect);
1448 if (PtInRect16(&rect,point))
1450 PostMessage(hDlg,WM_COMMAND,0x2c9,0);
1451 return 1;
1453 return 0;
1456 /***********************************************************************
1457 * CC_CheckDigitsInEdit [internal]
1459 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
1461 int i,k,m,result,value;
1462 long editpos;
1463 char buffer[30];
1464 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1465 m=strlen(buffer);
1466 result=0;
1468 for (i=0;i<m;i++)
1469 if (buffer[i]<'0' || buffer[i]>'9')
1471 for (k=i+1;k<=m;k++) /* delete bad character */
1473 buffer[i]=buffer[k];
1474 m--;
1476 buffer[m]=0;
1477 result=1;
1480 value=atoi(buffer);
1481 if (value>maxval) /* build a new string */
1483 sprintf(buffer,"%d",maxval);
1484 result=2;
1486 if (result)
1488 editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
1489 SetWindowText32A(hwnd,buffer);
1490 SendMessage16(hwnd,EM_SETSEL16,0,editpos);
1492 return value;
1497 /***********************************************************************
1498 * CC_PaintSelectedColor [internal]
1500 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
1502 RECT16 rect;
1503 HDC32 hdc;
1504 HBRUSH32 hBrush;
1505 HWND32 hwnd=GetDlgItem32(hDlg,0x2c5);
1506 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1508 hdc=GetDC32(hwnd);
1509 GetClientRect16 (hwnd, &rect) ;
1510 hBrush = CreateSolidBrush32(cr);
1511 if (hBrush)
1513 hBrush = SelectObject32 (hdc, hBrush) ;
1514 Rectangle32(hdc, rect.left,rect.top,rect.right/2,rect.bottom);
1515 DeleteObject32 (SelectObject32 (hdc,hBrush)) ;
1516 hBrush=CreateSolidBrush32(GetNearestColor32(hdc,cr));
1517 if (hBrush)
1519 hBrush= SelectObject32 (hdc, hBrush) ;
1520 Rectangle32( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
1521 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
1524 ReleaseDC32(hwnd,hdc);
1528 /***********************************************************************
1529 * CC_PaintTriangle [internal]
1531 static void CC_PaintTriangle(HWND16 hDlg,int y)
1533 HDC32 hDC;
1534 long temp;
1535 int w=GetDialogBaseUnits();
1536 POINT16 points[3];
1537 int height;
1538 int oben;
1539 RECT16 rect;
1540 HWND16 hwnd=GetDlgItem32(hDlg,0x2be);
1541 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1543 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1545 GetClientRect16(hwnd,&rect);
1546 height=rect.bottom;
1547 hDC=GetDC32(hDlg);
1549 points[0].y=rect.top;
1550 points[0].x=rect.right; /* | /| */
1551 ClientToScreen16(hwnd,points); /* | / | */
1552 ScreenToClient16(hDlg,points); /* |< | */
1553 oben=points[0].y; /* | \ | */
1554 /* | \| */
1555 temp=(long)height*(long)y;
1556 points[0].y=oben+height -temp/(long)MAXVERT;
1557 points[1].y=points[0].y+w;
1558 points[2].y=points[0].y-w;
1559 points[2].x=points[1].x=points[0].x + w;
1561 if (lpp->old3angle.left)
1562 FillRect16(hDC,&lpp->old3angle,GetStockObject32(WHITE_BRUSH));
1563 lpp->old3angle.left =points[0].x;
1564 lpp->old3angle.right =points[1].x+1;
1565 lpp->old3angle.top =points[2].y-1;
1566 lpp->old3angle.bottom=points[1].y+1;
1567 Polygon16(hDC,points,3);
1568 ReleaseDC32(hDlg,hDC);
1573 /***********************************************************************
1574 * CC_PaintCross [internal]
1576 static void CC_PaintCross(HWND16 hDlg,int x,int y)
1578 HDC32 hDC;
1579 int w=GetDialogBaseUnits();
1580 HWND16 hwnd=GetDlgItem32(hDlg,0x2c6);
1581 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1582 RECT16 rect;
1583 POINT16 point;
1584 HPEN32 hPen;
1586 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1588 GetClientRect16(hwnd,&rect);
1589 hDC=GetDC32(hwnd);
1590 SelectClipRgn32(hDC,CreateRectRgnIndirect16(&rect));
1591 hPen=CreatePen32(PS_SOLID,2,0);
1592 hPen=SelectObject32(hDC,hPen);
1593 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
1594 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
1595 if (lpp->oldcross.left!=lpp->oldcross.right)
1596 BitBlt32(hDC,lpp->oldcross.left,lpp->oldcross.top,
1597 lpp->oldcross.right-lpp->oldcross.left,
1598 lpp->oldcross.bottom-lpp->oldcross.top,
1599 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
1600 lpp->oldcross.left =point.x-w-1;
1601 lpp->oldcross.right =point.x+w+1;
1602 lpp->oldcross.top =point.y-w-1;
1603 lpp->oldcross.bottom=point.y+w+1;
1605 MoveTo(hDC,point.x-w,point.y);
1606 LineTo32(hDC,point.x+w,point.y);
1607 MoveTo(hDC,point.x,point.y-w);
1608 LineTo32(hDC,point.x,point.y+w);
1609 DeleteObject32(SelectObject32(hDC,hPen));
1610 ReleaseDC32(hwnd,hDC);
1615 #define XSTEPS 48
1616 #define YSTEPS 24
1619 /***********************************************************************
1620 * CC_PrepareColorGraph [internal]
1622 static void CC_PrepareColorGraph(HWND16 hDlg)
1624 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
1625 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
1626 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1627 HBRUSH32 hbrush;
1628 HDC32 hdc ;
1629 RECT16 rect,client;
1630 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT));
1632 GetClientRect16(hwnd,&client);
1633 hdc=GetDC32(hwnd);
1634 lpp->hdcMem = CreateCompatibleDC32(hdc);
1635 lpp->hbmMem = CreateCompatibleBitmap(hdc,client.right,client.bottom);
1636 SelectObject32(lpp->hdcMem,lpp->hbmMem);
1638 xdif=client.right /XSTEPS;
1639 ydif=client.bottom/YSTEPS+1;
1640 hdif=239/XSTEPS;
1641 sdif=240/YSTEPS;
1642 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
1644 rect.right=rect.left+xdif;
1645 rect.bottom=client.bottom;
1646 for(sat=0;sat<240+sdif;sat+=sdif)
1648 rect.top=rect.bottom-ydif;
1649 r=CC_HSLtoRGB('R',hue,sat,120);
1650 g=CC_HSLtoRGB('G',hue,sat,120);
1651 b=CC_HSLtoRGB('B',hue,sat,120);
1652 hbrush=CreateSolidBrush32(RGB(r,g,b));
1653 FillRect16(lpp->hdcMem,&rect,hbrush);
1654 DeleteObject32(hbrush);
1655 rect.bottom=rect.top;
1657 rect.left=rect.right;
1659 ReleaseDC32(hwnd,hdc);
1660 SetCursor16(hcursor);
1663 /***********************************************************************
1664 * CC_PaintColorGraph [internal]
1666 static void CC_PaintColorGraph(HWND16 hDlg)
1668 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
1669 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1670 HDC32 hDC;
1671 RECT16 rect;
1672 if (IsWindowVisible32(hwnd)) /* if full size */
1674 if (!lpp->hdcMem)
1675 CC_PrepareColorGraph(hDlg); /* should not be necessary */
1677 hDC=GetDC32(hwnd);
1678 GetClientRect16(hwnd,&rect);
1679 if (lpp->hdcMem)
1680 BitBlt32(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
1681 else
1682 fprintf(stderr,"choose color: hdcMem is not defined\n");
1683 ReleaseDC32(hwnd,hDC);
1686 /***********************************************************************
1687 * CC_PaintLumBar [internal]
1689 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
1691 HWND32 hwnd=GetDlgItem32(hDlg,0x2be);
1692 RECT16 rect,client;
1693 int lum,ldif,ydif,r,g,b;
1694 HBRUSH32 hbrush;
1695 HDC32 hDC;
1697 if (IsWindowVisible32(hwnd))
1699 hDC=GetDC32(hwnd);
1700 GetClientRect16(hwnd,&client);
1701 rect=client;
1703 ldif=240/YSTEPS;
1704 ydif=client.bottom/YSTEPS+1;
1705 for(lum=0;lum<240+ldif;lum+=ldif)
1707 rect.top=MAX(0,rect.bottom-ydif);
1708 r=CC_HSLtoRGB('R',hue,sat,lum);
1709 g=CC_HSLtoRGB('G',hue,sat,lum);
1710 b=CC_HSLtoRGB('B',hue,sat,lum);
1711 hbrush=CreateSolidBrush32(RGB(r,g,b));
1712 FillRect16(hDC,&rect,hbrush);
1713 DeleteObject32(hbrush);
1714 rect.bottom=rect.top;
1716 GetClientRect16(hwnd,&rect);
1717 FrameRect16(hDC,&rect,GetStockObject32(BLACK_BRUSH));
1718 ReleaseDC32(hwnd,hDC);
1722 /***********************************************************************
1723 * CC_EditSetRGB [internal]
1725 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
1727 char buffer[10];
1728 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1729 int r=GetRValue(cr);
1730 int g=GetGValue(cr);
1731 int b=GetBValue(cr);
1732 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1734 lpp->updating=TRUE;
1735 sprintf(buffer,"%d",r);
1736 SetWindowText32A(GetDlgItem32(hDlg,0x2c2),buffer);
1737 sprintf(buffer,"%d",g);
1738 SetWindowText32A(GetDlgItem32(hDlg,0x2c3),buffer);
1739 sprintf(buffer,"%d",b);
1740 SetWindowText32A(GetDlgItem32(hDlg,0x2c4),buffer);
1741 lpp->updating=FALSE;
1745 /***********************************************************************
1746 * CC_EditSetHSL [internal]
1748 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
1750 char buffer[10];
1751 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1752 lpp->updating=TRUE;
1753 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1755 lpp->updating=TRUE;
1756 sprintf(buffer,"%d",h);
1757 SetWindowText32A(GetDlgItem32(hDlg,0x2bf),buffer);
1758 sprintf(buffer,"%d",s);
1759 SetWindowText32A(GetDlgItem32(hDlg,0x2c0),buffer);
1760 sprintf(buffer,"%d",l);
1761 SetWindowText32A(GetDlgItem32(hDlg,0x2c1),buffer);
1762 lpp->updating=FALSE;
1764 CC_PaintLumBar(hDlg,h,s);
1767 /***********************************************************************
1768 * CC_SwitchToFullSize [internal]
1770 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
1772 int i;
1773 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1775 EnableWindow32(GetDlgItem32(hDlg,0x2cf),FALSE);
1776 CC_PrepareColorGraph(hDlg);
1777 for (i=0x2bf;i<0x2c5;i++)
1778 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
1779 for (i=0x2d3;i<0x2d9;i++)
1780 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
1781 EnableWindow32(GetDlgItem32(hDlg,0x2c9),TRUE);
1782 EnableWindow32(GetDlgItem32(hDlg,0x2c8),TRUE);
1784 if (lprect)
1785 SetWindowPos32(hDlg,NULL,0,0,lprect->right-lprect->left,
1786 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
1788 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_SHOW);
1789 ShowWindow32(GetDlgItem32(hDlg,0x2be),SW_SHOW);
1790 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_SHOW);
1792 CC_EditSetRGB(hDlg,result);
1793 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1796 /***********************************************************************
1797 * CC_PaintPredefColorArray [internal]
1799 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
1801 HWND32 hwnd=GetDlgItem32(hDlg,0x2d0);
1802 RECT16 rect;
1803 HDC32 hdc;
1804 HBRUSH32 hBrush;
1805 int dx,dy,i,j,k;
1807 GetClientRect16(hwnd,&rect);
1808 dx=rect.right/cols;
1809 dy=rect.bottom/rows;
1810 k=rect.left;
1812 hdc=GetDC32(hwnd);
1813 GetClientRect16 (hwnd, &rect) ;
1815 for (j=0;j<rows;j++)
1817 for (i=0;i<cols;i++)
1819 hBrush = CreateSolidBrush32(predefcolors[j][i]);
1820 if (hBrush)
1822 hBrush = SelectObject32 (hdc, hBrush) ;
1823 Rectangle32(hdc, rect.left, rect.top,
1824 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
1825 rect.left=rect.left+dx;
1826 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
1829 rect.top=rect.top+dy;
1830 rect.left=k;
1832 ReleaseDC32(hwnd,hdc);
1833 /* FIXME: draw_a_focus_rect */
1835 /***********************************************************************
1836 * CC_PaintUserColorArray [internal]
1838 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
1840 HWND32 hwnd=GetDlgItem32(hDlg,0x2d1);
1841 RECT16 rect;
1842 HDC32 hdc;
1843 HBRUSH32 hBrush;
1844 int dx,dy,i,j,k;
1846 GetClientRect16(hwnd,&rect);
1848 dx=rect.right/cols;
1849 dy=rect.bottom/rows;
1850 k=rect.left;
1852 hdc=GetDC32(hwnd);
1853 if (hdc)
1855 for (j=0;j<rows;j++)
1857 for (i=0;i<cols;i++)
1859 hBrush = CreateSolidBrush32(lpcr[i+j*cols]);
1860 if (hBrush)
1862 hBrush = SelectObject32 (hdc, hBrush) ;
1863 Rectangle32( hdc, rect.left, rect.top,
1864 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
1865 rect.left=rect.left+dx;
1866 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
1869 rect.top=rect.top+dy;
1870 rect.left=k;
1872 ReleaseDC32(hwnd,hdc);
1874 /* FIXME: draw_a_focus_rect */
1879 /***********************************************************************
1880 * CC_HookCallChk [internal]
1882 static BOOL CC_HookCallChk(LPCHOOSECOLOR lpcc)
1884 if (lpcc)
1885 if(lpcc->Flags & CC_ENABLEHOOK)
1886 if (lpcc->lpfnHook)
1887 return TRUE;
1888 return FALSE;
1891 /***********************************************************************
1892 * CC_WMInitDialog [internal]
1894 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
1896 int i,res;
1897 HWND16 hwnd;
1898 RECT16 rect;
1899 POINT16 point;
1900 struct CCPRIVATE * lpp;
1902 dprintf_commdlg(stddeb,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1903 lpp=calloc(1,sizeof(struct CCPRIVATE));
1904 lpp->lpcc=(LPCHOOSECOLOR)lParam;
1905 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR))
1907 EndDialog32 (hDlg, 0) ;
1908 return FALSE;
1910 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
1912 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
1913 ShowWindow32(GetDlgItem32(hDlg,0x40e),SW_HIDE);
1914 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
1915 #if 0
1916 cpos=MAKELONG(5,7); /* init */
1917 if (lpp->lpcc->Flags & CC_RGBINIT)
1919 for (i=0;i<6;i++)
1920 for (j=0;j<8;j++)
1921 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
1923 cpos=MAKELONG(i,j);
1924 goto found;
1927 found:
1928 /* FIXME: Draw_a_focus_rect & set_init_values */
1929 #endif
1930 GetWindowRect16(hDlg,&lpp->fullsize);
1931 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1933 hwnd=GetDlgItem32(hDlg,0x2cf);
1934 EnableWindow32(hwnd,FALSE);
1936 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1938 rect=lpp->fullsize;
1939 res=rect.bottom-rect.top;
1940 hwnd=GetDlgItem32(hDlg,0x2c6); /* cut at left border */
1941 point.x=point.y=0;
1942 ClientToScreen16(hwnd,&point);
1943 ScreenToClient16(hDlg,&point);
1944 GetClientRect16(hDlg,&rect);
1945 point.x+=GetSystemMetrics32(SM_CXDLGFRAME);
1946 SetWindowPos32(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
1948 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_HIDE);
1949 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_HIDE);
1951 else
1952 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
1953 res=TRUE;
1954 for (i=0x2bf;i<0x2c5;i++)
1955 SendMessage16(GetDlgItem32(hDlg,i),EM_LIMITTEXT16,3,0); /* max 3 digits: xyz */
1956 if (CC_HookCallChk(lpp->lpcc))
1957 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1958 return res;
1961 /***********************************************************************
1962 * CC_WMCommand [internal]
1964 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
1966 int r,g,b,i,xx;
1967 UINT cokmsg;
1968 HDC32 hdc;
1969 COLORREF *cr;
1970 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1971 dprintf_commdlg(stddeb,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
1972 switch (wParam)
1974 case 0x2c2: /* edit notify RGB */
1975 case 0x2c3:
1976 case 0x2c4:
1977 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1979 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
1980 r=GetRValue(lpp->lpcc->rgbResult);
1981 g=GetGValue(lpp->lpcc->rgbResult);
1982 b=GetBValue(lpp->lpcc->rgbResult);
1983 xx=0;
1984 switch (wParam)
1986 case 0x2c2:if ((xx=(i!=r))) r=i;break;
1987 case 0x2c3:if ((xx=(i!=g))) g=i;break;
1988 case 0x2c4:if ((xx=(i!=b))) b=i;break;
1990 if (xx) /* something has changed */
1992 lpp->lpcc->rgbResult=RGB(r,g,b);
1993 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1994 lpp->h=CC_RGBtoHSL('H',r,g,b);
1995 lpp->s=CC_RGBtoHSL('S',r,g,b);
1996 lpp->l=CC_RGBtoHSL('L',r,g,b);
1997 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1998 CC_PaintCross(hDlg,lpp->h,lpp->s);
1999 CC_PaintTriangle(hDlg,lpp->l);
2002 break;
2004 case 0x2bf: /* edit notify HSL */
2005 case 0x2c0:
2006 case 0x2c1:
2007 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2009 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
2010 xx=0;
2011 switch (wParam)
2013 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
2014 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
2015 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
2017 if (xx) /* something has changed */
2019 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2020 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2021 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2022 lpp->lpcc->rgbResult=RGB(r,g,b);
2023 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2024 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2025 CC_PaintCross(hDlg,lpp->h,lpp->s);
2026 CC_PaintTriangle(hDlg,lpp->l);
2029 break;
2031 case 0x2cf:
2032 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
2033 InvalidateRect32( hDlg, NULL, TRUE );
2034 SetFocus32(GetDlgItem32(hDlg,0x2bf));
2035 break;
2037 case 0x2c8: /* add colors ... column by column */
2038 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
2039 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
2040 if (++lpp->nextuserdef==16)
2041 lpp->nextuserdef=0;
2042 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2043 break;
2045 case 0x2c9: /* resulting color */
2046 hdc=GetDC32(hDlg);
2047 lpp->lpcc->rgbResult=GetNearestColor32(hdc,lpp->lpcc->rgbResult);
2048 ReleaseDC32(hDlg,hdc);
2049 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2050 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2051 r=GetRValue(lpp->lpcc->rgbResult);
2052 g=GetGValue(lpp->lpcc->rgbResult);
2053 b=GetBValue(lpp->lpcc->rgbResult);
2054 lpp->h=CC_RGBtoHSL('H',r,g,b);
2055 lpp->s=CC_RGBtoHSL('S',r,g,b);
2056 lpp->l=CC_RGBtoHSL('L',r,g,b);
2057 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2058 CC_PaintCross(hDlg,lpp->h,lpp->s);
2059 CC_PaintTriangle(hDlg,lpp->l);
2060 break;
2062 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2063 i=RegisterWindowMessage32A( HELPMSGSTRING );
2064 if (lpp->lpcc->hwndOwner)
2065 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2066 if (CC_HookCallChk(lpp->lpcc))
2067 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2068 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2069 break;
2071 case IDOK :
2072 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2073 if (lpp->lpcc->hwndOwner)
2074 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2075 break; /* do NOT close */
2077 EndDialog32 (hDlg, 1) ;
2078 return TRUE ;
2080 case IDCANCEL :
2081 EndDialog32 (hDlg, 0) ;
2082 return TRUE ;
2085 return FALSE;
2088 /***********************************************************************
2089 * CC_WMPaint [internal]
2091 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2093 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2094 /* we have to paint dialog children except text and buttons */
2096 CC_PaintPredefColorArray(hDlg,6,8);
2097 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2098 CC_PaintColorGraph(hDlg);
2099 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2100 CC_PaintCross(hDlg,lpp->h,lpp->s);
2101 CC_PaintTriangle(hDlg,lpp->l);
2102 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2104 /* special necessary for Wine */
2105 ValidateRect32(GetDlgItem32(hDlg,0x2d0),NULL);
2106 ValidateRect32(GetDlgItem32(hDlg,0x2d1),NULL);
2107 ValidateRect32(GetDlgItem32(hDlg,0x2c6),NULL);
2108 ValidateRect32(GetDlgItem32(hDlg,0x2be),NULL);
2109 ValidateRect32(GetDlgItem32(hDlg,0x2c5),NULL);
2110 /* hope we can remove it later -->FIXME */
2111 return 0;
2115 /***********************************************************************
2116 * CC_WMLButtonDown [internal]
2118 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2120 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2121 int r,g,b,i;
2122 i=0;
2123 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2124 i=1;
2125 else
2126 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2127 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2128 i=1;
2129 else
2130 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2131 i=2;
2132 else
2133 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2134 i=2;
2135 if (i==2)
2137 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2138 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2139 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2140 lpp->lpcc->rgbResult=RGB(r,g,b);
2142 if (i==1)
2144 r=GetRValue(lpp->lpcc->rgbResult);
2145 g=GetGValue(lpp->lpcc->rgbResult);
2146 b=GetBValue(lpp->lpcc->rgbResult);
2147 lpp->h=CC_RGBtoHSL('H',r,g,b);
2148 lpp->s=CC_RGBtoHSL('S',r,g,b);
2149 lpp->l=CC_RGBtoHSL('L',r,g,b);
2151 if (i)
2153 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2154 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2155 CC_PaintCross(hDlg,lpp->h,lpp->s);
2156 CC_PaintTriangle(hDlg,lpp->l);
2157 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2158 return TRUE;
2160 return FALSE;
2163 /***********************************************************************
2164 * ColorDlgProc (COMMDLG.8)
2166 LRESULT ColorDlgProc(HWND16 hDlg, UINT message,
2167 WPARAM16 wParam, LONG lParam)
2169 int res;
2170 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2171 if (message!=WM_INITDIALOG)
2173 if (!lpp)
2174 return FALSE;
2175 res=0;
2176 if (CC_HookCallChk(lpp->lpcc))
2177 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2178 if (res)
2179 return res;
2182 /* FIXME: SetRGB message
2183 if (message && message==msetrgb)
2184 return HandleSetRGB(hDlg,lParam);
2187 switch (message)
2189 case WM_INITDIALOG:
2190 return CC_WMInitDialog(hDlg,wParam,lParam);
2191 case WM_NCDESTROY:
2192 DeleteDC32(lpp->hdcMem);
2193 DeleteObject32(lpp->hbmMem);
2194 free(lpp);
2195 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2196 break;
2197 case WM_COMMAND:
2198 if (CC_WMCommand(hDlg, wParam, lParam))
2199 return TRUE;
2200 break;
2201 case WM_PAINT:
2202 CC_WMPaint(hDlg, wParam, lParam);
2203 break;
2204 case WM_LBUTTONDBLCLK:
2205 if (CC_MouseCheckResultWindow(hDlg,lParam))
2206 return TRUE;
2207 break;
2208 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2209 break;
2210 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2211 break;
2212 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2213 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2214 return TRUE;
2215 break;
2217 return FALSE ;
2222 /***********************************************************************
2223 * ChooseFont (COMMDLG.15)
2225 BOOL ChooseFont(LPCHOOSEFONT lpChFont)
2227 HINSTANCE16 hInst;
2228 HANDLE16 hDlgTmpl = 0;
2229 BOOL bRet = FALSE, win32Format = FALSE;
2230 LPCVOID template;
2231 HWND32 hwndDialog;
2233 dprintf_commdlg(stddeb,"ChooseFont\n");
2234 if (!lpChFont) return FALSE;
2236 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
2238 if (!(template = LockResource16( lpChFont->hInstance )))
2240 CommDlgLastError = CDERR_LOADRESFAILURE;
2241 return FALSE;
2244 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2246 HANDLE16 hResInfo;
2247 if (!(hResInfo = FindResource16( lpChFont->hInstance,
2248 lpChFont->lpTemplateName, RT_DIALOG)))
2250 CommDlgLastError = CDERR_FINDRESFAILURE;
2251 return FALSE;
2253 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
2254 !(template = LockResource16( hDlgTmpl )))
2256 CommDlgLastError = CDERR_LOADRESFAILURE;
2257 return FALSE;
2260 else
2262 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2263 win32Format = TRUE;
2266 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2268 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
2269 lpChFont->hwndOwner,
2270 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2271 (DWORD)lpChFont, WIN_PROC_16 );
2272 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2273 if (hDlgTmpl) FreeResource16( hDlgTmpl );
2274 return bRet;
2278 #define TEXT_EXTRAS 4
2279 #define TEXT_COLORS 16
2281 static const COLORREF textcolors[TEXT_COLORS]=
2283 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2284 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2285 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2286 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2289 /***********************************************************************
2290 * CFn_HookCallChk [internal]
2292 static BOOL CFn_HookCallChk(LPCHOOSEFONT lpcf)
2294 if (lpcf)
2295 if(lpcf->Flags & CF_ENABLEHOOK)
2296 if (lpcf->lpfnHook)
2297 return TRUE;
2298 return FALSE;
2302 /***********************************************************************
2303 * FontFamilyEnumProc (COMMDLG.19)
2305 INT16 FontFamilyEnumProc( SEGPTR logfont, SEGPTR metrics,
2306 UINT16 nFontType, LPARAM lParam )
2308 int i;
2309 WORD w;
2310 HWND16 hwnd=LOWORD(lParam);
2311 HWND16 hDlg=GetParent16(hwnd);
2312 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2313 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
2315 dprintf_commdlg(stddeb,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2316 lplf->lfFaceName,nFontType);
2318 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2319 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2320 return 1;
2321 if (lpcf->Flags & CF_ANSIONLY)
2322 if (lplf->lfCharSet != ANSI_CHARSET)
2323 return 1;
2324 if (lpcf->Flags & CF_TTONLY)
2325 if (!(nFontType & 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2326 return 1;
2328 i=SendMessage16(hwnd,CB_ADDSTRING16,0,
2329 (LPARAM)logfont + ((char *)lplf->lfFaceName - (char *)lplf));
2330 if (i!=CB_ERR)
2332 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2333 SendMessage16(hwnd, CB_SETITEMDATA16,i,MAKELONG(nFontType,w));
2334 return 1 ; /* store some important font information */
2336 else
2337 return 0;
2340 /*************************************************************************
2341 * SetFontStylesToCombo2 [internal]
2343 * Fill font style information into combobox (without using font.c directly)
2345 static int SetFontStylesToCombo2(HWND16 hwnd, HDC16 hdc, LPLOGFONT16 lplf,
2346 LPTEXTMETRIC16 lptm)
2348 #define FSTYLES 4
2349 struct FONTSTYLE
2350 { int italic;
2351 int weight;
2352 char stname[20]; };
2353 static struct FONTSTYLE fontstyles[FSTYLES]={
2354 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
2355 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
2356 HFONT16 hf;
2357 int i,j;
2359 for (i=0;i<FSTYLES;i++)
2361 lplf->lfItalic=fontstyles[i].italic;
2362 lplf->lfWeight=fontstyles[i].weight;
2363 hf=CreateFontIndirect16(lplf);
2364 hf=SelectObject32(hdc,hf);
2365 GetTextMetrics16(hdc,lptm);
2366 hf=SelectObject32(hdc,hf);
2367 DeleteObject32(hf);
2369 if (lptm->tmWeight==fontstyles[i].weight &&
2370 lptm->tmItalic==fontstyles[i].italic) /* font successful created ? */
2372 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
2373 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
2374 SEGPTR_FREE(str);
2375 if (j==CB_ERR) return 1;
2376 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
2377 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
2378 if (j==CB_ERR) return 1;
2381 return 0;
2384 /*************************************************************************
2385 * SetFontSizesToCombo3 [internal]
2387 static int SetFontSizesToCombo3(HWND16 hwnd, LPLOGFONT16 lplf, LPCHOOSEFONT lpcf)
2389 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2390 int h,i,j;
2391 char *buffer;
2393 if (!(buffer = SEGPTR_ALLOC(20))) return 1;
2394 for (i=0;sizes[i] && !lplf->lfHeight;i++)
2396 h=lplf->lfHeight ? lplf->lfHeight : sizes[i];
2398 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2399 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
2401 sprintf(buffer,"%2d",h);
2402 j=SendMessage16(hwnd,CB_FINDSTRING16,-1,(LPARAM)SEGPTR_GET(buffer));
2403 if (j==CB_ERR)
2405 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(buffer));
2406 if (j!=CB_ERR) j = SendMessage16(hwnd, CB_SETITEMDATA16, j, h);
2407 if (j==CB_ERR)
2409 SEGPTR_FREE(buffer);
2410 return 1;
2415 SEGPTR_FREE(buffer);
2416 return 0;
2420 /***********************************************************************
2421 * FontStyleEnumProc (COMMDLG.18)
2423 INT16 FontStyleEnumProc( SEGPTR logfont, SEGPTR metrics,
2424 UINT16 nFontType, LPARAM lParam )
2426 HWND16 hcmb2=LOWORD(lParam);
2427 HWND16 hcmb3=HIWORD(lParam);
2428 HWND16 hDlg=GetParent16(hcmb3);
2429 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2430 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
2431 TEXTMETRIC16 *lptm = (TEXTMETRIC16 *)PTR_SEG_TO_LIN(metrics);
2432 int i;
2434 dprintf_commdlg(stddeb,"FontStyleEnumProc: (nFontType=%d)\n",nFontType);
2435 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",
2436 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,lplf->lfEscapement,lplf->lfOrientation,
2437 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,lplf->lfStrikeOut,lplf->lfCharSet,
2438 lplf->lfOutPrecision,lplf->lfClipPrecision,lplf->lfQuality,lplf->lfPitchAndFamily);
2440 if (SetFontSizesToCombo3(hcmb3, lplf ,lpcf))
2441 return 0;
2443 if (!SendMessage16(hcmb2,CB_GETCOUNT16,0,0))
2445 HDC32 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2446 i=SetFontStylesToCombo2(hcmb2,hdc,lplf,lptm);
2447 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2448 ReleaseDC32(hDlg,hdc);
2449 if (i)
2450 return 0;
2452 return 1 ;
2456 /***********************************************************************
2457 * CFn_WMInitDialog [internal]
2459 LRESULT CFn_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2461 HDC32 hdc;
2462 int i,j,res,init=0;
2463 long l;
2464 LPLOGFONT16 lpxx;
2465 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT));
2466 LPCHOOSEFONT lpcf;
2468 SetWindowLong32A(hDlg, DWL_USER, lParam);
2469 lpcf=(LPCHOOSEFONT)lParam;
2470 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2471 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
2473 if (lpcf->lStructSize != sizeof(CHOOSEFONT))
2475 dprintf_commdlg(stddeb,"WM_INITDIALOG: structure size failure !!!\n");
2476 EndDialog32 (hDlg, 0);
2477 return FALSE;
2479 if (!hBitmapTT)
2480 hBitmapTT = LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE));
2482 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
2483 ShowWindow32(GetDlgItem32(hDlg,pshHelp),SW_HIDE);
2484 if (!(lpcf->Flags & CF_APPLY))
2485 ShowWindow32(GetDlgItem32(hDlg,psh3),SW_HIDE);
2486 if (lpcf->Flags & CF_EFFECTS)
2488 for (res=1,i=0;res && i<TEXT_COLORS;i++)
2490 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2491 char *name = SEGPTR_ALLOC(20);
2492 strcpy( name, "[color name]" );
2493 j=SendDlgItemMessage16(hDlg,cmb4,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(name));
2494 SEGPTR_FREE(name);
2495 SendDlgItemMessage16(hDlg,cmb4, CB_SETITEMDATA16,j,textcolors[j]);
2496 /* look for a fitting value in color combobox */
2497 if (textcolors[j]==lpcf->rgbColors)
2498 SendDlgItemMessage16(hDlg,cmb4, CB_SETCURSEL16,j,0);
2501 else
2503 ShowWindow32(GetDlgItem32(hDlg,cmb4),SW_HIDE);
2504 ShowWindow32(GetDlgItem32(hDlg,chx1),SW_HIDE);
2505 ShowWindow32(GetDlgItem32(hDlg,chx2),SW_HIDE);
2506 ShowWindow32(GetDlgItem32(hDlg,grp1),SW_HIDE);
2507 ShowWindow32(GetDlgItem32(hDlg,stc4),SW_HIDE);
2509 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2510 if (hdc)
2512 if (!EnumFontFamilies16(hdc, NULL,FontFamilyEnumProc,
2513 (LPARAM)GetDlgItem32(hDlg,cmb1)))
2514 dprintf_commdlg(stddeb,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2515 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
2517 /* look for fitting font name in combobox1 */
2518 j=SendDlgItemMessage16(hDlg,cmb1,CB_FINDSTRING16,-1,(LONG)lpxx->lfFaceName);
2519 if (j!=CB_ERR)
2521 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL16,j,0);
2522 SendMessage16(hDlg,WM_COMMAND,cmb1,
2523 MAKELONG(GetDlgItem32(hDlg,cmb1),CBN_SELCHANGE));
2524 init=1;
2525 /* look for fitting font style in combobox2 */
2526 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
2527 for (i=0;i<TEXT_EXTRAS;i++)
2529 if (l==SendDlgItemMessage16(hDlg,cmb2, CB_GETITEMDATA16,i,0))
2530 SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL16,i,0);
2533 /* look for fitting font size in combobox3 */
2534 j=SendDlgItemMessage16(hDlg,cmb3,CB_GETCOUNT16,0,0);
2535 for (i=0;i<j;i++)
2537 if (lpxx->lfHeight==(int)SendDlgItemMessage16(hDlg,cmb3, CB_GETITEMDATA16,i,0))
2538 SendDlgItemMessage16(hDlg,cmb3,CB_SETCURSEL16,i,0);
2541 if (!init)
2543 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL16,0,0);
2544 SendMessage16(hDlg,WM_COMMAND,cmb1,
2545 MAKELONG(GetDlgItem32(hDlg,cmb1),CBN_SELCHANGE));
2548 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
2550 j=SendDlgItemMessage16(hDlg,cmb2,CB_FINDSTRING16,-1,(LONG)lpcf->lpszStyle);
2551 if (j!=CB_ERR)
2553 j=SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL16,j,0);
2554 SendMessage16(hDlg,WM_COMMAND,cmb2,
2555 MAKELONG(GetDlgItem32(hDlg,cmb2),CBN_SELCHANGE));
2559 else
2561 dprintf_commdlg(stddeb,"WM_INITDIALOG: HDC failure !!!\n");
2562 EndDialog32 (hDlg, 0);
2563 return FALSE;
2566 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2567 ReleaseDC32(hDlg,hdc);
2568 res=TRUE;
2569 if (CFn_HookCallChk(lpcf))
2570 res=CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2571 SetCursor16(hcursor);
2572 return res;
2576 /***********************************************************************
2577 * CFn_WMMeasureItem [internal]
2579 LRESULT CFn_WMMeasureItem(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2581 BITMAP16 bm;
2582 LPMEASUREITEMSTRUCT16 lpmi=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT16)lParam);
2583 if (!hBitmapTT)
2584 hBitmapTT = LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE));
2585 GetObject16( hBitmapTT, sizeof(bm), &bm );
2586 lpmi->itemHeight=bm.bmHeight;
2587 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2588 return 0;
2592 /***********************************************************************
2593 * CFn_WMDrawItem [internal]
2595 LRESULT CFn_WMDrawItem(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2597 HBRUSH16 hBrush;
2598 char *buffer;
2599 BITMAP16 bm;
2600 COLORREF cr;
2601 RECT16 rect;
2602 #if 0
2603 HDC16 hMemDC;
2604 int nFontType;
2605 HBITMAP16 hBitmap; /* for later TT usage */
2606 #endif
2607 LPDRAWITEMSTRUCT16 lpdi = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
2609 if (lpdi->itemID == 0xFFFF) /* got no items */
2610 DrawFocusRect16(lpdi->hDC, &lpdi->rcItem);
2611 else
2613 if (lpdi->CtlType == ODT_COMBOBOX)
2615 hBrush = SelectObject32(lpdi->hDC, GetStockObject32(LTGRAY_BRUSH));
2616 SelectObject32(lpdi->hDC, hBrush);
2617 FillRect16(lpdi->hDC, &lpdi->rcItem, hBrush);
2619 else
2620 return TRUE; /* this should never happen */
2622 rect=lpdi->rcItem;
2623 buffer = SEGPTR_ALLOC(40);
2624 switch (lpdi->CtlID)
2626 case cmb1: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2627 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT16, lpdi->itemID,
2628 (LPARAM)SEGPTR_GET(buffer));
2629 GetObject16( hBitmapTT, sizeof(bm), &bm );
2630 TextOut16(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
2631 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2632 #if 0
2633 nFontType = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA16, lpdi->itemID,0L);
2634 /* FIXME: draw bitmap if truetype usage */
2635 if (nFontType&TRUETYPE_FONTTYPE)
2637 hMemDC = CreateCompatibleDC32(lpdi->hDC);
2638 hBitmap = SelectObject32(hMemDC, hBitmapTT);
2639 BitBlt32(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
2640 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
2641 SelectObject32(hMemDC, hBitmap);
2642 DeleteDC32(hMemDC);
2644 #endif
2645 break;
2646 case cmb2:
2647 case cmb3: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2648 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT16, lpdi->itemID,
2649 (LPARAM)SEGPTR_GET(buffer));
2650 TextOut16(lpdi->hDC, lpdi->rcItem.left,
2651 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2652 break;
2654 case cmb4: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2655 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT16, lpdi->itemID,
2656 (LPARAM)SEGPTR_GET(buffer));
2657 TextOut16(lpdi->hDC, lpdi->rcItem.left + 25+5,
2658 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2659 cr = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA16, lpdi->itemID,0L);
2660 hBrush = CreateSolidBrush32(cr);
2661 if (hBrush)
2663 hBrush = SelectObject32 (lpdi->hDC, hBrush) ;
2664 rect.right=rect.left+25;
2665 rect.top++;
2666 rect.left+=5;
2667 rect.bottom--;
2668 Rectangle32( lpdi->hDC, rect.left, rect.top,
2669 rect.right, rect.bottom );
2670 DeleteObject32( SelectObject32 (lpdi->hDC, hBrush)) ;
2672 rect=lpdi->rcItem;
2673 rect.left+=25+5;
2674 break;
2676 default: return TRUE; /* this should never happen */
2678 SEGPTR_FREE(buffer);
2679 if (lpdi->itemState ==ODS_SELECTED)
2680 InvertRect16(lpdi->hDC, &rect);
2682 return TRUE;
2685 /***********************************************************************
2686 * CFn_WMCtlColor [internal]
2688 LRESULT CFn_WMCtlColor(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2690 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2692 if (lpcf->Flags & CF_EFFECTS)
2693 if (HIWORD(lParam)==CTLCOLOR_STATIC && GetDlgCtrlID32(LOWORD(lParam))==stc6)
2695 SetTextColor(wParam,lpcf->rgbColors);
2696 return GetStockObject32(WHITE_BRUSH);
2698 return 0;
2701 /***********************************************************************
2702 * CFn_WMCommand [internal]
2704 LRESULT CFn_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2706 HFONT16 hFont;
2707 int i,j;
2708 long l;
2709 HDC16 hdc;
2710 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2711 LPLOGFONT16 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2713 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam);
2714 switch (wParam)
2716 case cmb1:if (HIWORD(lParam)==CBN_SELCHANGE)
2718 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2719 if (hdc)
2721 SendDlgItemMessage16(hDlg,cmb2,CB_RESETCONTENT16,0,0);
2722 SendDlgItemMessage16(hDlg,cmb3,CB_RESETCONTENT16,0,0);
2723 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL16,0,0);
2724 if (i!=CB_ERR)
2726 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT));
2727 char *str = SEGPTR_ALLOC(256);
2728 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT16,i,
2729 (LPARAM)SEGPTR_GET(str));
2730 dprintf_commdlg(stddeb,"WM_COMMAND/cmb1 =>%s\n",str);
2731 EnumFontFamilies16(hdc,str,FontStyleEnumProc,
2732 MAKELONG(GetDlgItem32(hDlg,cmb2),GetDlgItem32(hDlg,cmb3)));
2733 SetCursor16(hcursor);
2734 SEGPTR_FREE(str);
2736 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2737 ReleaseDC32(hDlg,hdc);
2739 else
2741 dprintf_commdlg(stddeb,"WM_COMMAND: HDC failure !!!\n");
2742 EndDialog32 (hDlg, 0);
2743 return TRUE;
2746 case chx1:
2747 case chx2:
2748 case cmb2:
2749 case cmb3:if (HIWORD(lParam)==CBN_SELCHANGE || HIWORD(lParam)== BN_CLICKED )
2751 char *str = SEGPTR_ALLOC(256);
2752 dprintf_commdlg(stddeb,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
2753 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL16,0,0);
2754 if (i==CB_ERR)
2755 i=GetDlgItemText32A( hDlg, cmb1, str, 256 );
2756 else
2758 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT16,i,
2759 (LPARAM)SEGPTR_GET(str));
2760 l=SendDlgItemMessage16(hDlg,cmb1,CB_GETITEMDATA16,i,0);
2761 j=HIWORD(l);
2762 lpcf->nFontType = LOWORD(l);
2763 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2764 /* same value reported to the EnumFonts
2765 call back with the extra FONTTYPE_... bits added */
2766 lpxx->lfPitchAndFamily=j&0xff;
2767 lpxx->lfCharSet=j>>8;
2769 strcpy(lpxx->lfFaceName,str);
2770 SEGPTR_FREE(str);
2771 i=SendDlgItemMessage16(hDlg,cmb2,CB_GETCURSEL16,0,0);
2772 if (i!=CB_ERR)
2774 l=SendDlgItemMessage16(hDlg,cmb2,CB_GETITEMDATA16,i,0);
2775 if (0!=(lpxx->lfItalic=HIWORD(l)))
2776 lpcf->nFontType |= ITALIC_FONTTYPE;
2777 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
2778 lpcf->nFontType |= BOLD_FONTTYPE;
2780 i=SendDlgItemMessage16(hDlg,cmb3,CB_GETCURSEL16,0,0);
2781 if (i!=CB_ERR)
2782 lpxx->lfHeight=-LOWORD(SendDlgItemMessage16(hDlg,cmb3,CB_GETITEMDATA16,i,0));
2783 else
2784 lpxx->lfHeight=0;
2785 lpxx->lfStrikeOut=IsDlgButtonChecked32(hDlg,chx1);
2786 lpxx->lfUnderline=IsDlgButtonChecked32(hDlg,chx2);
2787 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
2788 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
2789 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
2790 lpxx->lfQuality=DEFAULT_QUALITY;
2791 lpcf->iPointSize= -10*lpxx->lfHeight;
2793 hFont=CreateFontIndirect16(lpxx);
2794 if (hFont)
2795 SendDlgItemMessage16(hDlg,stc6,WM_SETFONT,hFont,TRUE);
2796 /* FIXME: Delete old font ...? */
2798 break;
2800 case cmb4:i=SendDlgItemMessage16(hDlg,cmb4,CB_GETCURSEL16,0,0);
2801 if (i!=CB_ERR)
2803 lpcf->rgbColors=textcolors[i];
2804 InvalidateRect32( GetDlgItem32(hDlg,stc6), NULL, 0 );
2806 break;
2808 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
2809 if (lpcf->hwndOwner)
2810 SendMessage16(lpcf->hwndOwner,i,0,(LPARAM)lpcf);
2811 if (CFn_HookCallChk(lpcf))
2812 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);
2813 break;
2815 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2816 ( (lpcf->Flags & CF_LIMITSIZE) &&
2817 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
2818 (-lpxx->lfHeight <= lpcf->nSizeMax)))
2819 EndDialog32(hDlg, TRUE);
2820 else
2822 char buffer[80];
2823 sprintf(buffer,"Select a font size between %d and %d points.",
2824 lpcf->nSizeMin,lpcf->nSizeMax);
2825 MessageBox16(hDlg,buffer,NULL,MB_OK);
2827 return(TRUE);
2828 case IDCANCEL:EndDialog32(hDlg, FALSE);
2829 return(TRUE);
2831 return(FALSE);
2835 /***********************************************************************
2836 * FormatCharDlgProc (COMMDLG.16)
2837 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2838 2. some CF_.. flags are not supported
2839 3. some TType extensions
2841 LRESULT FormatCharDlgProc(HWND16 hDlg, UINT message, WPARAM16 wParam, LPARAM lParam)
2843 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2844 if (message!=WM_INITDIALOG)
2846 int res=0;
2847 if (!lpcf)
2848 return FALSE;
2849 if (CFn_HookCallChk(lpcf))
2850 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
2851 if (res)
2852 return res;
2854 else
2855 return CFn_WMInitDialog(hDlg,wParam,lParam);
2856 switch (message)
2858 case WM_MEASUREITEM:
2859 return CFn_WMMeasureItem(hDlg,wParam,lParam);
2860 case WM_DRAWITEM:
2861 return CFn_WMDrawItem(hDlg,wParam,lParam);
2862 case WM_CTLCOLOR:
2863 return CFn_WMCtlColor(hDlg,wParam,lParam);
2864 case WM_COMMAND:
2865 return CFn_WMCommand(hDlg,wParam,lParam);
2866 case WM_CHOOSEFONT_GETLOGFONT:
2867 dprintf_commdlg(stddeb,
2868 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
2869 /* FIXME: current logfont back to caller */
2870 break;
2872 return FALSE;