Release 960717
[wine/multimedia.git] / misc / commdlg.c
blobdda9e254111d7f78a2127cb6fab85441dd38b91a
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 "user.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 "stackframe.h"
21 #include "stddebug.h"
22 #include "debug.h"
24 static DWORD CommDlgLastError = 0;
26 static HBITMAP hFolder = 0;
27 static HBITMAP hFolder2 = 0;
28 static HBITMAP hFloppy = 0;
29 static HBITMAP hHDisk = 0;
30 static HBITMAP hCDRom = 0;
31 static HBITMAP hBitmapTT = 0;
33 /***********************************************************************
34 * FileDlg_Init [internal]
36 static BOOL FileDlg_Init()
38 static BOOL initialized = 0;
40 if (!initialized) {
41 if (!hFolder) hFolder = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER));
42 if (!hFolder2) hFolder2 = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER2));
43 if (!hFloppy) hFloppy = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FLOPPY));
44 if (!hHDisk) hHDisk = LoadBitmap16(0, MAKEINTRESOURCE(OBM_HDISK));
45 if (!hCDRom) hCDRom = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CDROM));
46 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
47 hHDisk == 0 || hCDRom == 0)
49 fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
50 return FALSE;
52 initialized = TRUE;
54 return TRUE;
57 /***********************************************************************
58 * GetOpenFileName (COMMDLG.1)
60 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
62 HINSTANCE hInst;
63 HANDLE hDlgTmpl, hResInfo;
64 BOOL bRet;
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 (DWORD)lpofn );
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(LPOPENFILENAME lpofn)
108 HINSTANCE hInst;
109 HANDLE hDlgTmpl, hResInfo;
110 BOOL bRet;
112 if (!lpofn || !FileDlg_Init()) return FALSE;
114 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) hDlgTmpl = lpofn->hInstance;
115 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
117 hInst = lpofn->hInstance;
118 if (!(hResInfo = FindResource16(lpofn->hInstance,
119 lpofn->lpTemplateName, RT_DIALOG )))
121 CommDlgLastError = CDERR_FINDRESFAILURE;
122 return FALSE;
124 hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo );
126 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE );
128 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
129 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpofn->hwndOwner,
130 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
131 (DWORD)lpofn);
132 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
134 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
135 else SYSRES_FreeResource( hDlgTmpl );
138 dprintf_commdlg(stddeb, "GetSaveFileName // return lpstrFile='%s' !\n",
139 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
140 return bRet;
143 /***********************************************************************
144 * FILEDLG_StripEditControl [internal]
145 * Strip pathnames off the contents of the edit control.
147 static void FILEDLG_StripEditControl(HWND hwnd)
149 char temp[512], *cp;
151 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
152 cp = strrchr(temp, '\\');
153 if (cp != NULL) {
154 strcpy(temp, cp+1);
156 cp = strrchr(temp, ':');
157 if (cp != NULL) {
158 strcpy(temp, cp+1);
160 /* FIXME: shouldn't we do something with the result here? ;-) */
163 /***********************************************************************
164 * FILEDLG_ScanDir [internal]
166 static BOOL FILEDLG_ScanDir(HWND hWnd, LPSTR newPath)
168 char str[512],str2[512];
170 strncpy(str,newPath,511); str[511]=0;
171 GetDlgItemText32A( hWnd, edt1, str2, sizeof(str2) );
172 strncat(str,str2,511-strlen(str)); str[511]=0;
173 if (!DlgDirList(hWnd, MAKE_SEGPTR(str), lst1, 0, 0x0000)) return FALSE;
174 strcpy( str, "*.*" );
175 DlgDirList(hWnd, MAKE_SEGPTR(str), lst2, stc1, 0x8010);
176 return TRUE;
179 /***********************************************************************
180 * FILEDLG_GetFileType [internal]
183 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
185 int n, i;
186 i = 0;
187 if (cfptr)
188 for ( ;(n = strlen(cfptr)) != 0; i++)
190 cfptr += n + 1;
191 if (i == index)
192 return cfptr;
193 cfptr += strlen(cfptr) + 1;
195 if (fptr)
196 for ( ;(n = strlen(fptr)) != 0; i++)
198 fptr += n + 1;
199 if (i == index)
200 return fptr;
201 fptr += strlen(fptr) + 1;
203 return NULL;
206 /***********************************************************************
207 * FILEDLG_WMDrawItem [internal]
209 static LONG FILEDLG_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam,int savedlg)
211 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
212 char str[512];
213 HBRUSH hBrush;
214 HBITMAP hBitmap, hPrevBitmap;
215 BITMAP16 bm;
216 HDC hMemDC;
218 str[0]=0;
219 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
220 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
221 SelectObject(lpdis->hDC, hBrush);
222 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
223 SendMessage16(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
224 (LPARAM)MAKE_SEGPTR(str));
226 if (savedlg) /* use _gray_ text in FileSaveDlg */
227 if (!lpdis->itemState)
228 SetTextColor(lpdis->hDC,GetSysColor(COLOR_GRAYTEXT) );
229 else
230 SetTextColor(lpdis->hDC,GetSysColor(COLOR_WINDOWTEXT) );
231 /* inversion of gray would be bad readable */
233 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
234 str, strlen(str));
235 if (lpdis->itemState != 0) {
236 InvertRect16(lpdis->hDC, &lpdis->rcItem);
238 return TRUE;
241 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2) {
242 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
243 SelectObject(lpdis->hDC, hBrush);
244 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
245 SendMessage16(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
246 (LPARAM)MAKE_SEGPTR(str));
248 hBitmap = hFolder;
249 GetObject16( hBitmap, sizeof(bm), &bm );
250 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
251 lpdis->rcItem.top, str, strlen(str));
252 hMemDC = CreateCompatibleDC(lpdis->hDC);
253 hPrevBitmap = SelectObject(hMemDC, hBitmap);
254 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
255 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
256 SelectObject(hMemDC, hPrevBitmap);
257 DeleteDC(hMemDC);
258 if (lpdis->itemState != 0) {
259 InvertRect16(lpdis->hDC, &lpdis->rcItem);
261 return TRUE;
263 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2) {
264 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
265 SelectObject(lpdis->hDC, hBrush);
266 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
267 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
268 (LPARAM)MAKE_SEGPTR(str));
269 switch(DRIVE_GetType( str[2] - 'a' ))
271 case TYPE_FLOPPY: hBitmap = hFloppy; break;
272 case TYPE_CDROM: hBitmap = hCDRom; break;
273 case TYPE_HD:
274 case TYPE_NETWORK:
275 default: hBitmap = hHDisk; break;
277 GetObject16( hBitmap, sizeof(bm), &bm );
278 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
279 lpdis->rcItem.top, str, strlen(str));
280 hMemDC = CreateCompatibleDC(lpdis->hDC);
281 hPrevBitmap = SelectObject(hMemDC, hBitmap);
282 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
283 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
284 SelectObject(hMemDC, hPrevBitmap);
285 DeleteDC(hMemDC);
286 if (lpdis->itemState != 0) {
287 InvertRect16(lpdis->hDC, &lpdis->rcItem);
289 return TRUE;
291 return FALSE;
294 /***********************************************************************
295 * FILEDLG_WMMeasureItem [internal]
297 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
299 BITMAP16 bm;
300 LPMEASUREITEMSTRUCT16 lpmeasure;
302 GetObject16( hFolder2, sizeof(bm), &bm );
303 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
304 lpmeasure->itemHeight = bm.bmHeight;
305 return TRUE;
308 /***********************************************************************
309 * FILEDLG_HookCallChk [internal]
311 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn)
313 if (lpofn)
314 if (lpofn->Flags & OFN_ENABLEHOOK)
315 if (lpofn->lpfnHook)
316 return 1;
317 return 0;
320 /***********************************************************************
321 * FILEDLG_WMInitDialog [internal]
324 static LONG FILEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
326 int n;
327 int i;
328 LPOPENFILENAME lpofn;
329 char tmpstr[512];
330 LPSTR pstr;
331 SetWindowLong32A(hWnd, DWL_USER, lParam);
332 lpofn = (LPOPENFILENAME)lParam;
333 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
334 /* read custom filter information */
335 if (lpofn->lpstrCustomFilter)
337 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
338 dprintf_commdlg(stddeb,"lpstrCustomFilter = %p\n", pstr);
339 while(*pstr)
341 n = strlen(pstr);
342 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
343 dprintf_commdlg(stddeb,"lpstrCustomFilter // add tmpstr='%s' ", tmpstr);
344 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
345 pstr += n + 1;
346 n = strlen(pstr);
347 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
348 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
349 pstr += n + 1;
352 /* read filter information */
353 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
354 while(*pstr)
356 n = strlen(pstr);
357 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
358 dprintf_commdlg(stddeb,"lpstrFilter // add tmpstr='%s' ", tmpstr);
359 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
360 pstr += n + 1;
361 n = strlen(pstr);
362 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
363 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
364 pstr += n + 1;
366 /* set default filter */
367 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
368 lpofn->nFilterIndex = 1;
369 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL, lpofn->nFilterIndex - 1, 0);
370 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
371 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
372 tmpstr[511]=0;
373 dprintf_commdlg(stddeb,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
374 lpofn->nFilterIndex, tmpstr);
375 SetDlgItemText32A( hWnd, edt1, tmpstr );
376 /* get drive list */
377 *tmpstr = 0;
378 DlgDirListComboBox16(hWnd, (LPSTR)MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
379 /* read initial directory */
380 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
382 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
383 tmpstr[510]=0;
384 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
385 && tmpstr[strlen(tmpstr)-1] != ':')
386 strcat(tmpstr,"\\");
388 else
389 *tmpstr = 0;
390 if (!FILEDLG_ScanDir(hWnd, tmpstr))
391 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
392 /* select current drive in combo 2 */
393 n = DRIVE_GetCurrentDrive();
394 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL, n, 0);
395 if (!(lpofn->Flags & OFN_SHOWHELP))
396 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
397 if (lpofn->Flags & OFN_HIDEREADONLY)
398 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
399 if (FILEDLG_HookCallChk(lpofn))
400 return (BOOL)CallWindowProc16(lpofn->lpfnHook,
401 hWnd, WM_INITDIALOG, wParam,(LPARAM)MAKE_SEGPTR(lpofn));
402 else
403 return TRUE;
406 /***********************************************************************
407 * FILEDLG_WMCommand [internal]
409 static LRESULT FILEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
411 LONG lRet;
412 LPOPENFILENAME lpofn;
413 OPENFILENAME ofn2;
414 char tmpstr[512], tmpstr2[512];
415 LPSTR pstr, pstr2;
416 UINT control,notification;
418 /* Notifications are packaged differently in Win32 */
419 #ifdef WINELIB32
420 control = LOWORD(wParam);
421 notification = HIWORD(wParam);
422 #else
423 control = wParam;
424 notification = HIWORD(lParam);
425 #endif
427 lpofn = (LPOPENFILENAME)GetWindowLong32A(hWnd, DWL_USER);
428 switch (control)
430 case lst1: /* file list */
431 FILEDLG_StripEditControl(hWnd);
432 if (notification == LBN_DBLCLK)
433 goto almost_ok;
434 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL, 0, 0);
435 if (lRet == LB_ERR) return TRUE;
436 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT, lRet,
437 (LPARAM)MAKE_SEGPTR(tmpstr));
438 SetDlgItemText32A( hWnd, edt1, tmpstr );
440 if (FILEDLG_HookCallChk(lpofn))
441 CallWindowProc16(lpofn->lpfnHook, hWnd,
442 RegisterWindowMessage32A( LBSELCHSTRING ),
443 control, MAKELONG(lRet,CD_LBSELCHANGE));
444 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
445 return TRUE;
446 case lst2: /* directory list */
447 FILEDLG_StripEditControl(hWnd);
448 if (notification == LBN_DBLCLK)
450 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL, 0, 0);
451 if (lRet == LB_ERR) return TRUE;
452 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT, lRet,
453 (LPARAM)MAKE_SEGPTR(tmpstr));
454 if (tmpstr[0] == '[')
456 tmpstr[strlen(tmpstr) - 1] = 0;
457 strcpy(tmpstr,tmpstr+1);
459 strcat(tmpstr, "\\");
460 goto reset_scan;
462 return TRUE;
463 case cmb1: /* file type drop list */
464 if (notification == CBN_SELCHANGE)
466 *tmpstr = 0;
467 goto reset_scan;
469 return TRUE;
470 case cmb2: /* disk drop list */
471 FILEDLG_StripEditControl(hWnd);
472 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
473 if (lRet == LB_ERR) return 0;
474 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT, lRet, (LPARAM)MAKE_SEGPTR(tmpstr));
475 sprintf(tmpstr, "%c:", tmpstr[2]);
476 reset_scan:
477 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL, 0, 0);
478 if (lRet == LB_ERR)
479 return TRUE;
480 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA, lRet, 0);
481 dprintf_commdlg(stddeb,"Selected filter : %s\n", pstr);
482 SetDlgItemText32A( hWnd, edt1, pstr );
483 FILEDLG_ScanDir(hWnd, tmpstr);
484 return TRUE;
485 case chx1:
486 return TRUE;
487 case pshHelp:
488 return TRUE;
489 case IDOK:
490 almost_ok:
491 ofn2=*lpofn; /* for later restoring */
492 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
493 pstr = strrchr(tmpstr, '\\');
494 if (pstr == NULL)
495 pstr = strrchr(tmpstr, ':');
496 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
498 /* edit control contains wildcards */
499 if (pstr != NULL)
501 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
502 *(pstr+1) = 0;
504 else
506 strcpy(tmpstr2, tmpstr);
507 *tmpstr=0;
509 dprintf_commdlg(stddeb,"commdlg: %s, %s\n", tmpstr, tmpstr2);
510 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
511 FILEDLG_ScanDir(hWnd, tmpstr);
512 return TRUE;
514 /* no wildcards, we might have a directory or a filename */
515 /* try appending a wildcard and reading the directory */
516 pstr2 = tmpstr + strlen(tmpstr);
517 if (pstr == NULL || *(pstr+1) != 0)
518 strcat(tmpstr, "\\");
519 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL, 0, 0);
520 if (lRet == LB_ERR) return TRUE;
521 lpofn->nFilterIndex = lRet + 1;
522 dprintf_commdlg(stddeb,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
523 lstrcpyn32A(tmpstr2,
524 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
525 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
526 lRet), sizeof(tmpstr2));
527 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
528 /* if ScanDir succeeds, we have changed the directory */
529 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
530 /* if not, this must be a filename */
531 *pstr2 = 0;
532 if (pstr != NULL)
534 /* strip off the pathname */
535 *pstr = 0;
536 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
537 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
538 /* Should we MessageBox() if this fails? */
539 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
540 strcpy(tmpstr, tmpstr2);
542 else SetDlgItemText32A( hWnd, edt1, tmpstr );
543 #if 0
544 ShowWindow(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
545 #endif
547 int drive = DRIVE_GetCurrentDrive();
548 tmpstr2[0] = 'A'+ drive;
549 tmpstr2[1] = ':';
550 tmpstr2[2] = '\\';
551 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
552 if (strlen(tmpstr2) > 3)
553 strcat(tmpstr2, "\\");
554 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
555 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
557 lpofn->nFileOffset = 0;
558 lpofn->nFileExtension = 0;
559 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
560 lpofn->nFileExtension++;
561 if (lpofn->nFileExtension == '\0')
562 lpofn->nFileExtension = 0;
563 else
564 lpofn->nFileExtension++;
565 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
567 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL, 0, 0);
568 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT, lRet,
569 (LPARAM)MAKE_SEGPTR(tmpstr));
570 dprintf_commdlg(stddeb,"strcpy'ing '%s'\n",tmpstr); fflush(stdout);
571 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
573 if (FILEDLG_HookCallChk(lpofn))
575 lRet= (BOOL)CallWindowProc16(lpofn->lpfnHook,
576 hWnd, RegisterWindowMessage32A( FILEOKSTRING ),
577 0, (LPARAM)MAKE_SEGPTR(lpofn));
578 if (lRet)
580 *lpofn=ofn2; /* restore old state */
581 #if 0
582 ShowWindow(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
583 #endif
584 break;
587 EndDialog(hWnd, TRUE);
588 return TRUE;
589 case IDCANCEL:
590 EndDialog(hWnd, FALSE);
591 return TRUE;
593 return FALSE;
597 /***********************************************************************
598 * FileOpenDlgProc (COMMDLG.6)
600 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
602 LPOPENFILENAME lpofn = (LPOPENFILENAME)GetWindowLong32A(hWnd, DWL_USER);
604 if (wMsg!=WM_INITDIALOG)
605 if (FILEDLG_HookCallChk(lpofn))
607 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
608 if (lRet)
609 return lRet; /* else continue message processing */
611 switch (wMsg)
613 case WM_INITDIALOG:
614 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
615 case WM_MEASUREITEM:
616 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
617 case WM_DRAWITEM:
618 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
619 case WM_COMMAND:
620 return FILEDLG_WMCommand(hWnd, wParam, lParam);
621 #if 0
622 case WM_CTLCOLOR:
623 SetBkColor((HDC)wParam, 0x00C0C0C0);
624 switch (HIWORD(lParam))
626 case CTLCOLOR_BTN:
627 SetTextColor((HDC)wParam, 0x00000000);
628 return hGRAYBrush;
629 case CTLCOLOR_STATIC:
630 SetTextColor((HDC)wParam, 0x00000000);
631 return hGRAYBrush;
633 break;
634 #endif
636 return FALSE;
640 /***********************************************************************
641 * FileSaveDlgProc (COMMDLG.7)
643 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
645 LPOPENFILENAME lpofn = (LPOPENFILENAME)GetWindowLong32A(hWnd, DWL_USER);
647 if (wMsg!=WM_INITDIALOG)
648 if (FILEDLG_HookCallChk(lpofn))
650 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
651 if (lRet)
652 return lRet; /* else continue message processing */
654 switch (wMsg) {
655 case WM_INITDIALOG:
656 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
658 case WM_MEASUREITEM:
659 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
661 case WM_DRAWITEM:
662 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
664 case WM_COMMAND:
665 return FILEDLG_WMCommand(hWnd, wParam, lParam);
669 case WM_CTLCOLOR:
670 SetBkColor((HDC)wParam, 0x00C0C0C0);
671 switch (HIWORD(lParam))
673 case CTLCOLOR_BTN:
674 SetTextColor((HDC)wParam, 0x00000000);
675 return hGRAYBrush;
676 case CTLCOLOR_STATIC:
677 SetTextColor((HDC)wParam, 0x00000000);
678 return hGRAYBrush;
680 return FALSE;
683 return FALSE;
687 /***********************************************************************
688 * FindTextDlg (COMMDLG.11)
690 BOOL FindText(LPFINDREPLACE lpFind)
692 HANDLE hInst, hDlgTmpl;
693 BOOL bRet;
694 LPCVOID ptr;
697 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
698 * For now, only the standard dialog works.
701 * FIXME : We should do error checking on the lpFind structure here
702 * and make CommDlgExtendedError() return the error condition.
704 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT );
705 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
706 if (!(ptr = GlobalLock16( hDlgTmpl ))) return -1;
707 bRet = CreateDialogIndirectParam16( hInst, ptr, lpFind->hwndOwner,
708 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
709 (DWORD)lpFind );
710 GlobalUnlock16( hDlgTmpl );
711 SYSRES_FreeResource( hDlgTmpl );
712 return bRet;
716 /***********************************************************************
717 * ReplaceTextDlg (COMMDLG.12)
719 BOOL ReplaceText(LPFINDREPLACE lpFind)
721 HANDLE hInst, hDlgTmpl;
722 BOOL bRet;
723 LPCVOID ptr;
726 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
727 * For now, only the standard dialog works.
730 * FIXME : We should do error checking on the lpFind structure here
731 * and make CommDlgExtendedError() return the error condition.
733 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT );
734 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
735 if (!(ptr = GlobalLock16( hDlgTmpl ))) return -1;
736 bRet = CreateDialogIndirectParam16( hInst, ptr, lpFind->hwndOwner,
737 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
738 (DWORD)lpFind );
739 GlobalUnlock16( hDlgTmpl );
740 SYSRES_FreeResource( hDlgTmpl );
741 return bRet;
745 /***********************************************************************
746 * FINDDLG_WMInitDialog [internal]
748 static LRESULT FINDDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
750 LPFINDREPLACE lpfr;
752 SetWindowLong32A(hWnd, DWL_USER, lParam);
753 lpfr = (LPFINDREPLACE)lParam;
754 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
756 * FIXME : If the initial FindWhat string is empty, we should disable the
757 * FindNext (IDOK) button. Only after typing some text, the button should be
758 * enabled.
760 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
761 CheckRadioButton(hWnd, rad1, rad2, (lpfr->Flags & FR_DOWN) ? rad2 : rad1);
762 if (lpfr->Flags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
763 EnableWindow(GetDlgItem(hWnd, rad1), FALSE);
764 EnableWindow(GetDlgItem(hWnd, rad2), FALSE);
766 if (lpfr->Flags & FR_HIDEUPDOWN) {
767 ShowWindow(GetDlgItem(hWnd, rad1), SW_HIDE);
768 ShowWindow(GetDlgItem(hWnd, rad2), SW_HIDE);
769 ShowWindow(GetDlgItem(hWnd, grp1), SW_HIDE);
771 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
772 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
773 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
774 if (lpfr->Flags & FR_HIDEWHOLEWORD)
775 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
776 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
777 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
778 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
779 if (lpfr->Flags & FR_HIDEMATCHCASE)
780 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
781 if (!(lpfr->Flags & FR_SHOWHELP)) {
782 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
783 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
785 ShowWindow(hWnd, SW_SHOWNORMAL);
786 return TRUE;
790 /***********************************************************************
791 * FINDDLG_WMCommand [internal]
793 static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
795 LPFINDREPLACE lpfr;
796 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
797 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
799 lpfr = (LPFINDREPLACE)GetWindowLong32A(hWnd, DWL_USER);
800 switch (wParam) {
801 case IDOK:
802 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
803 if (IsDlgButtonChecked(hWnd, rad2))
804 lpfr->Flags |= FR_DOWN;
805 else lpfr->Flags &= ~FR_DOWN;
806 if (IsDlgButtonChecked(hWnd, chx1))
807 lpfr->Flags |= FR_WHOLEWORD;
808 else lpfr->Flags &= ~FR_WHOLEWORD;
809 if (IsDlgButtonChecked(hWnd, chx2))
810 lpfr->Flags |= FR_MATCHCASE;
811 else lpfr->Flags &= ~FR_MATCHCASE;
812 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
813 lpfr->Flags |= FR_FINDNEXT;
814 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
815 return TRUE;
816 case IDCANCEL:
817 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
818 lpfr->Flags |= FR_DIALOGTERM;
819 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
820 DestroyWindow(hWnd);
821 return TRUE;
822 case pshHelp:
823 /* FIXME : should lpfr structure be passed as an argument ??? */
824 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
825 return TRUE;
827 return FALSE;
831 /***********************************************************************
832 * FindTextDlgProc (COMMDLG.13)
834 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
836 switch (wMsg) {
837 case WM_INITDIALOG:
838 return FINDDLG_WMInitDialog(hWnd, wParam, lParam);
839 case WM_COMMAND:
840 return FINDDLG_WMCommand(hWnd, wParam, lParam);
842 return FALSE;
846 /***********************************************************************
847 * REPLACEDLG_WMInitDialog [internal]
849 static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
851 LPFINDREPLACE lpfr;
853 SetWindowLong32A(hWnd, DWL_USER, lParam);
854 lpfr = (LPFINDREPLACE)lParam;
855 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
857 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
858 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
859 * enabled.
861 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
862 SetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith);
863 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
864 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
865 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
866 if (lpfr->Flags & FR_HIDEWHOLEWORD)
867 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
868 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
869 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
870 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
871 if (lpfr->Flags & FR_HIDEMATCHCASE)
872 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
873 if (!(lpfr->Flags & FR_SHOWHELP)) {
874 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
875 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
877 ShowWindow(hWnd, SW_SHOWNORMAL);
878 return TRUE;
882 /***********************************************************************
883 * REPLACEDLG_WMCommand [internal]
885 static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
887 LPFINDREPLACE lpfr;
888 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
889 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
891 lpfr = (LPFINDREPLACE)GetWindowLong32A(hWnd, DWL_USER);
892 switch (wParam) {
893 case IDOK:
894 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
895 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
896 if (IsDlgButtonChecked(hWnd, chx1))
897 lpfr->Flags |= FR_WHOLEWORD;
898 else lpfr->Flags &= ~FR_WHOLEWORD;
899 if (IsDlgButtonChecked(hWnd, chx2))
900 lpfr->Flags |= FR_MATCHCASE;
901 else lpfr->Flags &= ~FR_MATCHCASE;
902 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
903 lpfr->Flags |= FR_FINDNEXT;
904 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
905 return TRUE;
906 case IDCANCEL:
907 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
908 lpfr->Flags |= FR_DIALOGTERM;
909 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
910 DestroyWindow(hWnd);
911 return TRUE;
912 case psh1:
913 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
914 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
915 if (IsDlgButtonChecked(hWnd, chx1))
916 lpfr->Flags |= FR_WHOLEWORD;
917 else lpfr->Flags &= ~FR_WHOLEWORD;
918 if (IsDlgButtonChecked(hWnd, chx2))
919 lpfr->Flags |= FR_MATCHCASE;
920 else lpfr->Flags &= ~FR_MATCHCASE;
921 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
922 lpfr->Flags |= FR_REPLACE;
923 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
924 return TRUE;
925 case psh2:
926 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
927 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
928 if (IsDlgButtonChecked(hWnd, chx1))
929 lpfr->Flags |= FR_WHOLEWORD;
930 else lpfr->Flags &= ~FR_WHOLEWORD;
931 if (IsDlgButtonChecked(hWnd, chx2))
932 lpfr->Flags |= FR_MATCHCASE;
933 else lpfr->Flags &= ~FR_MATCHCASE;
934 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
935 lpfr->Flags |= FR_REPLACEALL;
936 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
937 return TRUE;
938 case pshHelp:
939 /* FIXME : should lpfr structure be passed as an argument ??? */
940 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
941 return TRUE;
943 return FALSE;
947 /***********************************************************************
948 * ReplaceTextDlgProc (COMMDLG.14)
950 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
952 switch (wMsg) {
953 case WM_INITDIALOG:
954 return REPLACEDLG_WMInitDialog(hWnd, wParam, lParam);
955 case WM_COMMAND:
956 return REPLACEDLG_WMCommand(hWnd, wParam, lParam);
958 return FALSE;
962 /***********************************************************************
963 * PrintDlg (COMMDLG.20)
965 BOOL PrintDlg(LPPRINTDLG lpPrint)
967 HANDLE hInst, hDlgTmpl;
968 BOOL bRet;
970 dprintf_commdlg(stddeb,"PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
972 if (lpPrint->Flags & PD_RETURNDEFAULT)
973 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
974 return TRUE;
976 if (lpPrint->Flags & PD_PRINTSETUP)
977 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP );
978 else
979 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT );
981 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
982 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpPrint->hwndOwner,
983 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
984 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
985 MODULE_GetWndProcEntry16("PrintDlgProc")),
986 (DWORD)lpPrint );
987 SYSRES_FreeResource( hDlgTmpl );
988 return bRet;
992 /***********************************************************************
993 * PrintDlgProc (COMMDLG.21)
995 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
997 switch (wMsg)
999 case WM_INITDIALOG:
1000 dprintf_commdlg(stddeb,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1001 ShowWindow(hWnd, SW_SHOWNORMAL);
1002 return (TRUE);
1003 case WM_COMMAND:
1004 switch (wParam)
1006 case IDOK:
1007 EndDialog(hWnd, TRUE);
1008 return(TRUE);
1009 case IDCANCEL:
1010 EndDialog(hWnd, FALSE);
1011 return(TRUE);
1013 return(FALSE);
1015 return FALSE;
1019 /***********************************************************************
1020 * PrintSetupDlgProc (COMMDLG.22)
1022 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
1024 switch (wMsg)
1026 case WM_INITDIALOG:
1027 dprintf_commdlg(stddeb,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1028 ShowWindow(hWnd, SW_SHOWNORMAL);
1029 return (TRUE);
1030 case WM_COMMAND:
1031 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 * CommDlgExtendedError (COMMDLG.26)
1048 DWORD CommDlgExtendedError(void)
1050 return CommDlgLastError;
1054 /***********************************************************************
1055 * GetFileTitle (COMMDLG.27)
1057 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
1059 int i, len;
1060 dprintf_commdlg(stddeb,"GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1061 if (lpFile == NULL || lpTitle == NULL)
1062 return -1;
1063 len = strlen(lpFile);
1064 if (len == 0)
1065 return -1;
1066 if (strpbrk(lpFile, "*[]"))
1067 return -1;
1068 len--;
1069 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1070 return -1;
1071 for (i = len; i >= 0; i--)
1072 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1074 i++;
1075 break;
1077 dprintf_commdlg(stddeb,"\n---> '%s' ", &lpFile[i]);
1079 len = strlen(lpFile+i)+1;
1080 if (cbBuf < len)
1081 return len;
1083 strncpy(lpTitle, &lpFile[i], len);
1084 return 0;
1088 /* ------------------------ Choose Color Dialog --------------------------- */
1090 /***********************************************************************
1091 * ChooseColor (COMMDLG.5)
1093 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
1095 HINSTANCE hInst;
1096 HANDLE hDlgTmpl, hResInfo;
1097 BOOL bRet;
1099 dprintf_commdlg(stddeb,"ChooseColor\n");
1100 if (!lpChCol) return FALSE;
1101 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE) hDlgTmpl = lpChCol->hInstance;
1102 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1104 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1105 lpChCol->lpTemplateName, RT_DIALOG)))
1107 CommDlgLastError = CDERR_FINDRESFAILURE;
1108 return FALSE;
1110 hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo );
1112 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR );
1113 if (!hDlgTmpl)
1115 CommDlgLastError = CDERR_LOADRESFAILURE;
1116 return FALSE;
1118 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1119 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpChCol->hwndOwner,
1120 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1121 (DWORD)lpChCol );
1122 if (!(lpChCol->Flags & CC_ENABLETEMPLATEHANDLE))
1124 if (lpChCol->Flags & CC_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
1125 else SYSRES_FreeResource( hDlgTmpl );
1127 return bRet;
1131 static const COLORREF predefcolors[6][8]=
1133 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1134 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1135 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1136 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1138 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1139 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1140 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1141 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1143 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1144 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1145 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1146 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1149 struct CCPRIVATE
1151 LPCHOOSECOLOR lpcc; /* points to public known data structure */
1152 int nextuserdef; /* next free place in user defined color array */
1153 HDC hdcMem; /* color graph used for BitBlt() */
1154 HBITMAP hbmMem; /* color graph bitmap */
1155 RECT16 fullsize; /* original dialog window size */
1156 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
1157 RECT16 old3angle; /* last position of l-marker */
1158 RECT16 oldcross; /* last position of color/satuation marker */
1159 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1160 int h;
1161 int s;
1162 int l; /* for temporary storing of hue,sat,lum */
1165 /***********************************************************************
1166 * CC_HSLtoRGB [internal]
1168 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1170 int res=0,maxrgb;
1172 /* hue */
1173 switch(c)
1175 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1176 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1177 case 'B':break;
1180 /* l below 120 */
1181 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1182 if (hue< 80)
1183 res=0;
1184 else
1185 if (hue< 120)
1187 res=(hue-80)* maxrgb; /* 0...10240 */
1188 res/=40; /* 0...256 */
1190 else
1191 if (hue< 200)
1192 res=maxrgb;
1193 else
1195 res=(240-hue)* maxrgb;
1196 res/=40;
1198 res=res-maxrgb/2; /* -128...128 */
1200 /* saturation */
1201 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1203 /* lum above 120 */
1204 if (lum>120 && res<256)
1205 res+=((lum-120) * (256-res))/120;
1207 return MIN(res,255);
1210 /***********************************************************************
1211 * CC_RGBtoHSL [internal]
1213 static int CC_RGBtoHSL(char c,int r,int g,int b)
1215 WORD maxi,mini,mmsum,mmdif,result=0;
1216 int iresult=0;
1218 maxi=MAX(r,b);
1219 maxi=MAX(maxi,g);
1220 mini=MIN(r,b);
1221 mini=MIN(mini,g);
1223 mmsum=maxi+mini;
1224 mmdif=maxi-mini;
1226 switch(c)
1228 /* lum */
1229 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1230 result=mmsum/255; /* 0...240 */
1231 break;
1232 /* saturation */
1233 case 'S':if (!mmsum)
1234 result=0;
1235 else
1236 if (!mini || maxi==255)
1237 result=240;
1238 else
1240 result=mmdif*240; /* 0...61200=255*240 */
1241 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1243 break;
1244 /* hue */
1245 case 'H':if (!mmdif)
1246 result=160;
1247 else
1249 if (maxi==r)
1251 iresult=40*(g-b); /* -10200 ... 10200 */
1252 iresult/=(int)mmdif; /* -40 .. 40 */
1253 if (iresult<0)
1254 iresult+=240; /* 0..40 and 200..240 */
1256 else
1257 if (maxi==g)
1259 iresult=40*(b-r);
1260 iresult/=(int)mmdif;
1261 iresult+=80; /* 40 .. 120 */
1263 else
1264 if (maxi==b)
1266 iresult=40*(r-g);
1267 iresult/=(int)mmdif;
1268 iresult+=160; /* 120 .. 200 */
1270 result=iresult;
1272 break;
1274 return result; /* is this integer arithmetic precise enough ? */
1277 #define DISTANCE 4
1279 /***********************************************************************
1280 * CC_MouseCheckPredefColorArray [internal]
1282 static int CC_MouseCheckPredefColorArray(HWND hDlg,int dlgitem,int rows,int cols,
1283 LPARAM lParam,COLORREF *cr)
1285 HWND hwnd;
1286 POINT16 point = MAKEPOINT16(lParam);
1287 RECT16 rect;
1288 int dx,dy,x,y;
1290 ClientToScreen16(hDlg,&point);
1291 hwnd=GetDlgItem(hDlg,dlgitem);
1292 GetWindowRect16(hwnd,&rect);
1293 if (PtInRect16(&rect,point))
1295 dx=(rect.right-rect.left)/cols;
1296 dy=(rect.bottom-rect.top)/rows;
1297 ScreenToClient16(hwnd,&point);
1299 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1301 x=point.x/dx;
1302 y=point.y/dy;
1303 *cr=predefcolors[y][x];
1304 /* FIXME: Draw_a_Focus_Rect() */
1305 return 1;
1308 return 0;
1311 /***********************************************************************
1312 * CC_MouseCheckUserColorArray [internal]
1314 static int CC_MouseCheckUserColorArray(HWND hDlg,int dlgitem,int rows,int cols,
1315 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1317 HWND hwnd;
1318 POINT16 point = MAKEPOINT16(lParam);
1319 RECT16 rect;
1320 int dx,dy,x,y;
1322 ClientToScreen16(hDlg,&point);
1323 hwnd=GetDlgItem(hDlg,dlgitem);
1324 GetWindowRect16(hwnd,&rect);
1325 if (PtInRect16(&rect,point))
1327 dx=(rect.right-rect.left)/cols;
1328 dy=(rect.bottom-rect.top)/rows;
1329 ScreenToClient16(hwnd,&point);
1331 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1333 x=point.x/dx;
1334 y=point.y/dy;
1335 *cr=crarr[x+cols*y];
1336 /* FIXME: Draw_a_Focus_Rect() */
1337 return 1;
1340 return 0;
1343 #define MAXVERT 240
1344 #define MAXHORI 239
1346 /* 240 ^...... ^^ 240
1347 | . ||
1348 SAT | . || LUM
1349 | . ||
1350 +-----> 239 ----
1353 /***********************************************************************
1354 * CC_MouseCheckColorGraph [internal]
1356 static int CC_MouseCheckColorGraph(HWND hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1358 HWND hwnd;
1359 POINT16 point = MAKEPOINT16(lParam);
1360 RECT16 rect;
1361 long x,y;
1363 ClientToScreen16(hDlg,&point);
1364 hwnd=GetDlgItem(hDlg,dlgitem);
1365 GetWindowRect16(hwnd,&rect);
1366 if (PtInRect16(&rect,point))
1368 GetClientRect16(hwnd,&rect);
1369 ScreenToClient16(hwnd,&point);
1371 x=(long)point.x*MAXHORI;
1372 x/=rect.right;
1373 y=(long)(rect.bottom-point.y)*MAXVERT;
1374 y/=rect.bottom;
1376 if (hori)
1377 *hori=x;
1378 if (vert)
1379 *vert=y;
1380 return 1;
1382 else
1383 return 0;
1385 /***********************************************************************
1386 * CC_MouseCheckResultWindow [internal]
1388 static int CC_MouseCheckResultWindow(HWND hDlg,LPARAM lParam)
1390 HWND hwnd;
1391 POINT16 point = MAKEPOINT16(lParam);
1392 RECT16 rect;
1394 ClientToScreen16(hDlg,&point);
1395 hwnd=GetDlgItem(hDlg,0x2c5);
1396 GetWindowRect16(hwnd,&rect);
1397 if (PtInRect16(&rect,point))
1399 PostMessage(hDlg,WM_COMMAND,0x2c9,0);
1400 return 1;
1402 return 0;
1405 /***********************************************************************
1406 * CC_CheckDigitsInEdit [internal]
1408 static int CC_CheckDigitsInEdit(HWND hwnd,int maxval)
1410 int i,k,m,result,value;
1411 long editpos;
1412 char buffer[30];
1413 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1414 m=strlen(buffer);
1415 result=0;
1417 for (i=0;i<m;i++)
1418 if (buffer[i]<'0' || buffer[i]>'9')
1420 for (k=i+1;k<=m;k++) /* delete bad character */
1422 buffer[i]=buffer[k];
1423 m--;
1425 buffer[m]=0;
1426 result=1;
1429 value=atoi(buffer);
1430 if (value>maxval) /* build a new string */
1432 sprintf(buffer,"%d",maxval);
1433 result=2;
1435 if (result)
1437 editpos=SendMessage16(hwnd,EM_GETSEL,0,0);
1438 SetWindowText32A(hwnd,buffer);
1439 SendMessage16(hwnd,EM_SETSEL,0,editpos);
1441 return value;
1446 /***********************************************************************
1447 * CC_PaintSelectedColor [internal]
1449 static void CC_PaintSelectedColor(HWND hDlg,COLORREF cr)
1451 RECT16 rect;
1452 HDC hdc;
1453 HBRUSH hBrush;
1454 HWND hwnd=GetDlgItem(hDlg,0x2c5);
1455 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1457 hdc=GetDC(hwnd);
1458 GetClientRect16 (hwnd, &rect) ;
1459 hBrush = CreateSolidBrush(cr);
1460 if (hBrush)
1462 hBrush = SelectObject (hdc, hBrush) ;
1463 Rectangle (hdc, rect.left,rect.top,rect.right/2,rect.bottom);
1464 DeleteObject (SelectObject (hdc,hBrush)) ;
1465 hBrush=CreateSolidBrush(GetNearestColor(hdc,cr));
1466 if (hBrush)
1468 hBrush= SelectObject (hdc, hBrush) ;
1469 Rectangle (hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
1470 DeleteObject (SelectObject (hdc, hBrush)) ;
1473 ReleaseDC(hwnd,hdc);
1477 /***********************************************************************
1478 * CC_PaintTriangle [internal]
1480 static void CC_PaintTriangle(HWND hDlg,int y)
1482 HDC hDC;
1483 long temp;
1484 int w=GetDialogBaseUnits();
1485 POINT16 points[3];
1486 int height;
1487 int oben;
1488 RECT16 rect;
1489 HWND hwnd=GetDlgItem(hDlg,0x2be);
1490 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1492 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1494 GetClientRect16(hwnd,&rect);
1495 height=rect.bottom;
1496 hDC=GetDC(hDlg);
1498 points[0].y=rect.top;
1499 points[0].x=rect.right; /* | /| */
1500 ClientToScreen16(hwnd,points); /* | / | */
1501 ScreenToClient16(hDlg,points); /* |< | */
1502 oben=points[0].y; /* | \ | */
1503 /* | \| */
1504 temp=(long)height*(long)y;
1505 points[0].y=oben+height -temp/(long)MAXVERT;
1506 points[1].y=points[0].y+w;
1507 points[2].y=points[0].y-w;
1508 points[2].x=points[1].x=points[0].x + w;
1510 if (lpp->old3angle.left)
1511 FillRect16(hDC,&lpp->old3angle,GetStockObject(WHITE_BRUSH));
1512 lpp->old3angle.left =points[0].x;
1513 lpp->old3angle.right =points[1].x+1;
1514 lpp->old3angle.top =points[2].y-1;
1515 lpp->old3angle.bottom=points[1].y+1;
1516 Polygon16(hDC,points,3);
1517 ReleaseDC(hDlg,hDC);
1522 /***********************************************************************
1523 * CC_PaintCross [internal]
1525 static void CC_PaintCross(HWND hDlg,int x,int y)
1527 HDC hDC;
1528 int w=GetDialogBaseUnits();
1529 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1530 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1531 RECT16 rect;
1532 POINT16 point;
1533 HPEN16 hPen;
1535 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1537 GetClientRect16(hwnd,&rect);
1538 hDC=GetDC(hwnd);
1539 SelectClipRgn(hDC,CreateRectRgnIndirect16(&rect));
1540 hPen=CreatePen(PS_SOLID,2,0);
1541 hPen=SelectObject(hDC,hPen);
1542 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
1543 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
1544 if (lpp->oldcross.left!=lpp->oldcross.right)
1545 BitBlt(hDC,lpp->oldcross.left,lpp->oldcross.top,
1546 lpp->oldcross.right-lpp->oldcross.left,
1547 lpp->oldcross.bottom-lpp->oldcross.top,
1548 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
1549 lpp->oldcross.left =point.x-w-1;
1550 lpp->oldcross.right =point.x+w+1;
1551 lpp->oldcross.top =point.y-w-1;
1552 lpp->oldcross.bottom=point.y+w+1;
1554 MoveTo(hDC,point.x-w,point.y);
1555 LineTo(hDC,point.x+w,point.y);
1556 MoveTo(hDC,point.x,point.y-w);
1557 LineTo(hDC,point.x,point.y+w);
1558 DeleteObject(SelectObject(hDC,hPen));
1559 ReleaseDC(hwnd,hDC);
1564 #define XSTEPS 48
1565 #define YSTEPS 24
1568 /***********************************************************************
1569 * CC_PrepareColorGraph [internal]
1571 static void CC_PrepareColorGraph(HWND hDlg)
1573 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
1574 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1575 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1576 HBRUSH hbrush;
1577 HDC hdc ;
1578 RECT16 rect,client;
1579 HCURSOR hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
1581 GetClientRect16(hwnd,&client);
1582 hdc=GetDC(hwnd);
1583 lpp->hdcMem = CreateCompatibleDC(hdc);
1584 lpp->hbmMem = CreateCompatibleBitmap(hdc,client.right,client.bottom);
1585 SelectObject(lpp->hdcMem,lpp->hbmMem);
1587 xdif=client.right /XSTEPS;
1588 ydif=client.bottom/YSTEPS+1;
1589 hdif=239/XSTEPS;
1590 sdif=240/YSTEPS;
1591 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
1593 rect.right=rect.left+xdif;
1594 rect.bottom=client.bottom;
1595 for(sat=0;sat<240+sdif;sat+=sdif)
1597 rect.top=rect.bottom-ydif;
1598 r=CC_HSLtoRGB('R',hue,sat,120);
1599 g=CC_HSLtoRGB('G',hue,sat,120);
1600 b=CC_HSLtoRGB('B',hue,sat,120);
1601 hbrush=CreateSolidBrush(RGB(r,g,b));
1602 FillRect16(lpp->hdcMem,&rect,hbrush);
1603 DeleteObject(hbrush);
1604 rect.bottom=rect.top;
1606 rect.left=rect.right;
1608 ReleaseDC(hwnd,hdc);
1609 SetCursor(hcursor);
1612 /***********************************************************************
1613 * CC_PaintColorGraph [internal]
1615 static void CC_PaintColorGraph(HWND hDlg)
1617 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1618 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1619 HDC hDC;
1620 RECT16 rect;
1621 if (IsWindowVisible(hwnd)) /* if full size */
1623 if (!lpp->hdcMem)
1624 CC_PrepareColorGraph(hDlg); /* should not be necessary */
1626 hDC=GetDC(hwnd);
1627 GetClientRect16(hwnd,&rect);
1628 if (lpp->hdcMem)
1629 BitBlt(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
1630 else
1631 fprintf(stderr,"choose color: hdcMem is not defined\n");
1632 ReleaseDC(hwnd,hDC);
1635 /***********************************************************************
1636 * CC_PaintLumBar [internal]
1638 static void CC_PaintLumBar(HWND hDlg,int hue,int sat)
1640 HWND hwnd=GetDlgItem(hDlg,0x2be);
1641 RECT16 rect,client;
1642 int lum,ldif,ydif,r,g,b;
1643 HBRUSH hbrush;
1644 HDC hDC;
1646 if (IsWindowVisible(hwnd))
1648 hDC=GetDC(hwnd);
1649 GetClientRect16(hwnd,&client);
1650 rect=client;
1652 ldif=240/YSTEPS;
1653 ydif=client.bottom/YSTEPS+1;
1654 for(lum=0;lum<240+ldif;lum+=ldif)
1656 rect.top=MAX(0,rect.bottom-ydif);
1657 r=CC_HSLtoRGB('R',hue,sat,lum);
1658 g=CC_HSLtoRGB('G',hue,sat,lum);
1659 b=CC_HSLtoRGB('B',hue,sat,lum);
1660 hbrush=CreateSolidBrush(RGB(r,g,b));
1661 FillRect16(hDC,&rect,hbrush);
1662 DeleteObject(hbrush);
1663 rect.bottom=rect.top;
1665 GetClientRect16(hwnd,&rect);
1666 FrameRect16(hDC,&rect,GetStockObject(BLACK_BRUSH));
1667 ReleaseDC(hwnd,hDC);
1671 /***********************************************************************
1672 * CC_EditSetRGB [internal]
1674 static void CC_EditSetRGB(HWND hDlg,COLORREF cr)
1676 char buffer[10];
1677 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1678 int r=GetRValue(cr);
1679 int g=GetGValue(cr);
1680 int b=GetBValue(cr);
1681 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1683 lpp->updating=TRUE;
1684 sprintf(buffer,"%d",r);
1685 SetWindowText32A(GetDlgItem(hDlg,0x2c2),buffer);
1686 sprintf(buffer,"%d",g);
1687 SetWindowText32A(GetDlgItem(hDlg,0x2c3),buffer);
1688 sprintf(buffer,"%d",b);
1689 SetWindowText32A(GetDlgItem(hDlg,0x2c4),buffer);
1690 lpp->updating=FALSE;
1694 /***********************************************************************
1695 * CC_EditSetHSL [internal]
1697 static void CC_EditSetHSL(HWND hDlg,int h,int s,int l)
1699 char buffer[10];
1700 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1701 lpp->updating=TRUE;
1702 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1704 lpp->updating=TRUE;
1705 sprintf(buffer,"%d",h);
1706 SetWindowText32A(GetDlgItem(hDlg,0x2bf),buffer);
1707 sprintf(buffer,"%d",s);
1708 SetWindowText32A(GetDlgItem(hDlg,0x2c0),buffer);
1709 sprintf(buffer,"%d",l);
1710 SetWindowText32A(GetDlgItem(hDlg,0x2c1),buffer);
1711 lpp->updating=FALSE;
1713 CC_PaintLumBar(hDlg,h,s);
1716 /***********************************************************************
1717 * CC_SwitchToFullSize [internal]
1719 static void CC_SwitchToFullSize(HWND hDlg,COLORREF result,LPRECT16 lprect)
1721 int i;
1722 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1724 EnableWindow(GetDlgItem(hDlg,0x2cf),FALSE);
1725 CC_PrepareColorGraph(hDlg);
1726 for (i=0x2bf;i<0x2c5;i++)
1727 EnableWindow(GetDlgItem(hDlg,i),TRUE);
1728 for (i=0x2d3;i<0x2d9;i++)
1729 EnableWindow(GetDlgItem(hDlg,i),TRUE);
1730 EnableWindow(GetDlgItem(hDlg,0x2c9),TRUE);
1731 EnableWindow(GetDlgItem(hDlg,0x2c8),TRUE);
1733 if (lprect)
1734 SetWindowPos(hDlg,NULL,0,0,lprect->right-lprect->left,
1735 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
1737 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_SHOW);
1738 ShowWindow(GetDlgItem(hDlg,0x2be),SW_SHOW);
1739 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_SHOW);
1741 CC_EditSetRGB(hDlg,result);
1742 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1745 /***********************************************************************
1746 * CC_PaintPredefColorArray [internal]
1748 static void CC_PaintPredefColorArray(HWND hDlg,int rows,int cols)
1750 HWND hwnd=GetDlgItem(hDlg,0x2d0);
1751 RECT16 rect;
1752 HDC hdc;
1753 HBRUSH hBrush;
1754 int dx,dy,i,j,k;
1756 GetClientRect16(hwnd,&rect);
1757 dx=rect.right/cols;
1758 dy=rect.bottom/rows;
1759 k=rect.left;
1761 hdc=GetDC(hwnd);
1762 GetClientRect16 (hwnd, &rect) ;
1764 for (j=0;j<rows;j++)
1766 for (i=0;i<cols;i++)
1768 hBrush = CreateSolidBrush(predefcolors[j][i]);
1769 if (hBrush)
1771 hBrush = SelectObject (hdc, hBrush) ;
1772 Rectangle (hdc, rect.left, rect.top,
1773 rect.left+dx-DISTANCE,rect.top+dy-DISTANCE);
1774 rect.left=rect.left+dx;
1775 DeleteObject (SelectObject (hdc, hBrush)) ;
1778 rect.top=rect.top+dy;
1779 rect.left=k;
1781 ReleaseDC(hwnd,hdc);
1782 /* FIXME: draw_a_focus_rect */
1784 /***********************************************************************
1785 * CC_PaintUserColorArray [internal]
1787 static void CC_PaintUserColorArray(HWND hDlg,int rows,int cols,COLORREF* lpcr)
1789 HWND hwnd=GetDlgItem(hDlg,0x2d1);
1790 RECT16 rect;
1791 HDC hdc;
1792 HBRUSH hBrush;
1793 int dx,dy,i,j,k;
1795 GetClientRect16(hwnd,&rect);
1797 dx=rect.right/cols;
1798 dy=rect.bottom/rows;
1799 k=rect.left;
1801 hdc=GetDC(hwnd);
1802 if (hdc)
1804 for (j=0;j<rows;j++)
1806 for (i=0;i<cols;i++)
1808 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
1809 if (hBrush)
1811 hBrush = SelectObject (hdc, hBrush) ;
1812 Rectangle (hdc, rect.left, rect.top,
1813 rect.left+dx-DISTANCE,rect.top+dy-DISTANCE);
1814 rect.left=rect.left+dx;
1815 DeleteObject (SelectObject (hdc, hBrush)) ;
1818 rect.top=rect.top+dy;
1819 rect.left=k;
1821 ReleaseDC(hwnd,hdc);
1823 /* FIXME: draw_a_focus_rect */
1828 /***********************************************************************
1829 * CC_HookCallChk [internal]
1831 static BOOL CC_HookCallChk(LPCHOOSECOLOR lpcc)
1833 if (lpcc)
1834 if(lpcc->Flags & CC_ENABLEHOOK)
1835 if (lpcc->lpfnHook)
1836 return TRUE;
1837 return FALSE;
1840 /***********************************************************************
1841 * CC_WMInitDialog [internal]
1843 static LONG CC_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam)
1845 int i,res;
1846 HWND hwnd;
1847 RECT16 rect;
1848 POINT16 point;
1849 struct CCPRIVATE * lpp;
1851 dprintf_commdlg(stddeb,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1852 lpp=calloc(1,sizeof(struct CCPRIVATE));
1853 lpp->lpcc=(LPCHOOSECOLOR)lParam;
1854 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR))
1856 EndDialog (hDlg, 0) ;
1857 return FALSE;
1859 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
1861 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
1862 ShowWindow(GetDlgItem(hDlg,0x40e),SW_HIDE);
1863 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
1864 #if 0
1865 cpos=MAKELONG(5,7); /* init */
1866 if (lpp->lpcc->Flags & CC_RGBINIT)
1868 for (i=0;i<6;i++)
1869 for (j=0;j<8;j++)
1870 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
1872 cpos=MAKELONG(i,j);
1873 goto found;
1876 found:
1877 /* FIXME: Draw_a_focus_rect & set_init_values */
1878 #endif
1879 GetWindowRect16(hDlg,&lpp->fullsize);
1880 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1882 hwnd=GetDlgItem(hDlg,0x2cf);
1883 EnableWindow(hwnd,FALSE);
1885 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1887 rect=lpp->fullsize;
1888 res=rect.bottom-rect.top;
1889 hwnd=GetDlgItem(hDlg,0x2c6); /* cut at left border */
1890 point.x=point.y=0;
1891 ClientToScreen16(hwnd,&point);
1892 ScreenToClient16(hDlg,&point);
1893 GetClientRect16(hDlg,&rect);
1894 point.x+=GetSystemMetrics(SM_CXDLGFRAME);
1895 SetWindowPos(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
1897 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_HIDE);
1898 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_HIDE);
1900 else
1901 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
1902 res=TRUE;
1903 for (i=0x2bf;i<0x2c5;i++)
1904 SendMessage16(GetDlgItem(hDlg,i),EM_LIMITTEXT,3,0); /* max 3 digits: xyz */
1905 if (CC_HookCallChk(lpp->lpcc))
1906 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1907 return res;
1910 /***********************************************************************
1911 * CC_WMCommand [internal]
1913 static LRESULT CC_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
1915 int r,g,b,i,xx;
1916 UINT cokmsg;
1917 HDC hdc;
1918 COLORREF *cr;
1919 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1920 dprintf_commdlg(stddeb,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
1921 switch (wParam)
1923 case 0x2c2: /* edit notify RGB */
1924 case 0x2c3:
1925 case 0x2c4:
1926 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1928 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
1929 r=GetRValue(lpp->lpcc->rgbResult);
1930 g=GetGValue(lpp->lpcc->rgbResult);
1931 b=GetBValue(lpp->lpcc->rgbResult);
1932 xx=0;
1933 switch (wParam)
1935 case 0x2c2:if ((xx=(i!=r))) r=i;break;
1936 case 0x2c3:if ((xx=(i!=g))) g=i;break;
1937 case 0x2c4:if ((xx=(i!=b))) b=i;break;
1939 if (xx) /* something has changed */
1941 lpp->lpcc->rgbResult=RGB(r,g,b);
1942 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1943 lpp->h=CC_RGBtoHSL('H',r,g,b);
1944 lpp->s=CC_RGBtoHSL('S',r,g,b);
1945 lpp->l=CC_RGBtoHSL('L',r,g,b);
1946 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1947 CC_PaintCross(hDlg,lpp->h,lpp->s);
1948 CC_PaintTriangle(hDlg,lpp->l);
1951 break;
1953 case 0x2bf: /* edit notify HSL */
1954 case 0x2c0:
1955 case 0x2c1:
1956 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1958 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
1959 xx=0;
1960 switch (wParam)
1962 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
1963 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
1964 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
1966 if (xx) /* something has changed */
1968 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
1969 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
1970 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
1971 lpp->lpcc->rgbResult=RGB(r,g,b);
1972 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1973 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
1974 CC_PaintCross(hDlg,lpp->h,lpp->s);
1975 CC_PaintTriangle(hDlg,lpp->l);
1978 break;
1980 case 0x2cf:
1981 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
1982 InvalidateRect32( hDlg, NULL, TRUE );
1983 SetFocus(GetDlgItem(hDlg,0x2bf));
1984 break;
1986 case 0x2c8: /* add colors ... column by column */
1987 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
1988 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
1989 if (++lpp->nextuserdef==16)
1990 lpp->nextuserdef=0;
1991 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
1992 break;
1994 case 0x2c9: /* resulting color */
1995 hdc=GetDC(hDlg);
1996 lpp->lpcc->rgbResult=GetNearestColor(hdc,lpp->lpcc->rgbResult);
1997 ReleaseDC(hDlg,hdc);
1998 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
1999 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2000 r=GetRValue(lpp->lpcc->rgbResult);
2001 g=GetGValue(lpp->lpcc->rgbResult);
2002 b=GetBValue(lpp->lpcc->rgbResult);
2003 lpp->h=CC_RGBtoHSL('H',r,g,b);
2004 lpp->s=CC_RGBtoHSL('S',r,g,b);
2005 lpp->l=CC_RGBtoHSL('L',r,g,b);
2006 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2007 CC_PaintCross(hDlg,lpp->h,lpp->s);
2008 CC_PaintTriangle(hDlg,lpp->l);
2009 break;
2011 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2012 i=RegisterWindowMessage32A( HELPMSGSTRING );
2013 if (lpp->lpcc->hwndOwner)
2014 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2015 if (CC_HookCallChk(lpp->lpcc))
2016 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2017 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2018 break;
2020 case IDOK :
2021 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2022 if (lpp->lpcc->hwndOwner)
2023 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2024 break; /* do NOT close */
2026 EndDialog (hDlg, 1) ;
2027 return TRUE ;
2029 case IDCANCEL :
2030 EndDialog (hDlg, 0) ;
2031 return TRUE ;
2034 return FALSE;
2037 /***********************************************************************
2038 * CC_WMPaint [internal]
2040 static LRESULT CC_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam)
2042 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2043 /* we have to paint dialog children except text and buttons */
2045 CC_PaintPredefColorArray(hDlg,6,8);
2046 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2047 CC_PaintColorGraph(hDlg);
2048 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2049 CC_PaintCross(hDlg,lpp->h,lpp->s);
2050 CC_PaintTriangle(hDlg,lpp->l);
2051 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2053 /* special necessary for Wine */
2054 ValidateRect32(GetDlgItem(hDlg,0x2d0),NULL);
2055 ValidateRect32(GetDlgItem(hDlg,0x2d1),NULL);
2056 ValidateRect32(GetDlgItem(hDlg,0x2c6),NULL);
2057 ValidateRect32(GetDlgItem(hDlg,0x2be),NULL);
2058 ValidateRect32(GetDlgItem(hDlg,0x2c5),NULL);
2059 /* hope we can remove it later -->FIXME */
2060 return 0;
2064 /***********************************************************************
2065 * CC_WMLButtonDown [internal]
2067 static LRESULT CC_WMLButtonDown(HWND hDlg, WPARAM wParam, LPARAM lParam)
2069 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2070 int r,g,b,i;
2071 i=0;
2072 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2073 i=1;
2074 else
2075 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2076 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2077 i=1;
2078 else
2079 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2080 i=2;
2081 else
2082 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2083 i=2;
2084 if (i==2)
2086 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2087 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2088 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2089 lpp->lpcc->rgbResult=RGB(r,g,b);
2091 if (i==1)
2093 r=GetRValue(lpp->lpcc->rgbResult);
2094 g=GetGValue(lpp->lpcc->rgbResult);
2095 b=GetBValue(lpp->lpcc->rgbResult);
2096 lpp->h=CC_RGBtoHSL('H',r,g,b);
2097 lpp->s=CC_RGBtoHSL('S',r,g,b);
2098 lpp->l=CC_RGBtoHSL('L',r,g,b);
2100 if (i)
2102 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2103 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2104 CC_PaintCross(hDlg,lpp->h,lpp->s);
2105 CC_PaintTriangle(hDlg,lpp->l);
2106 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2107 return TRUE;
2109 return FALSE;
2112 /***********************************************************************
2113 * ColorDlgProc (COMMDLG.8)
2115 LRESULT ColorDlgProc(HWND hDlg, UINT message,
2116 UINT wParam, LONG lParam)
2118 int res;
2119 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2120 if (message!=WM_INITDIALOG)
2122 if (!lpp)
2123 return FALSE;
2124 res=0;
2125 if (CC_HookCallChk(lpp->lpcc))
2126 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2127 if (res)
2128 return res;
2131 /* FIXME: SetRGB message
2132 if (message && message==msetrgb)
2133 return HandleSetRGB(hDlg,lParam);
2136 switch (message)
2138 case WM_INITDIALOG:
2139 return CC_WMInitDialog(hDlg,wParam,lParam);
2140 case WM_NCDESTROY:
2141 DeleteDC(lpp->hdcMem);
2142 DeleteObject(lpp->hbmMem);
2143 free(lpp);
2144 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2145 break;
2146 case WM_COMMAND:
2147 if (CC_WMCommand(hDlg, wParam, lParam))
2148 return TRUE;
2149 break;
2150 case WM_PAINT:
2151 CC_WMPaint(hDlg, wParam, lParam);
2152 break;
2153 case WM_LBUTTONDBLCLK:
2154 if (CC_MouseCheckResultWindow(hDlg,lParam))
2155 return TRUE;
2156 break;
2157 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2158 break;
2159 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2160 break;
2161 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2162 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2163 return TRUE;
2164 break;
2166 return FALSE ;
2171 /***********************************************************************
2172 * ChooseFont (COMMDLG.15)
2174 BOOL ChooseFont(LPCHOOSEFONT lpChFont)
2176 HINSTANCE hInst;
2177 HANDLE hDlgTmpl, hResInfo;
2178 BOOL bRet;
2180 dprintf_commdlg(stddeb,"ChooseFont\n");
2181 if (!lpChFont) return FALSE;
2182 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE) hDlgTmpl = lpChFont->hInstance;
2183 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2185 if (!(hResInfo = FindResource16(lpChFont->hInstance,
2186 lpChFont->lpTemplateName, RT_DIALOG)))
2188 CommDlgLastError = CDERR_FINDRESFAILURE;
2189 return FALSE;
2191 hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo );
2193 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_FONT );
2194 if (!hDlgTmpl)
2196 CommDlgLastError = CDERR_LOADRESFAILURE;
2197 return FALSE;
2199 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2200 bRet = DialogBoxIndirectParam16( hInst, hDlgTmpl, lpChFont->hwndOwner,
2201 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2202 (DWORD)lpChFont );
2203 if (!(lpChFont->Flags & CF_ENABLETEMPLATEHANDLE))
2205 if (lpChFont->Flags & CF_ENABLETEMPLATE) FreeResource16( hDlgTmpl );
2206 else SYSRES_FreeResource( hDlgTmpl );
2208 return bRet;
2212 #define TEXT_EXTRAS 4
2213 #define TEXT_COLORS 16
2215 static const COLORREF textcolors[TEXT_COLORS]=
2217 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2218 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2219 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2220 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2223 /***********************************************************************
2224 * CFn_HookCallChk [internal]
2226 static BOOL CFn_HookCallChk(LPCHOOSEFONT lpcf)
2228 if (lpcf)
2229 if(lpcf->Flags & CF_ENABLEHOOK)
2230 if (lpcf->lpfnHook)
2231 return TRUE;
2232 return FALSE;
2236 /***********************************************************************
2237 * FontFamilyEnumProc (COMMDLG.19)
2239 int FontFamilyEnumProc(LPLOGFONT16 lplf, LPTEXTMETRIC16 lptm, int nFontType, LPARAM lParam)
2241 int i;
2242 WORD w;
2243 HWND hwnd=LOWORD(lParam);
2244 HWND hDlg=GetParent(hwnd);
2245 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2247 dprintf_commdlg(stddeb,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2248 lplf->lfFaceName,nFontType);
2250 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2251 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2252 return 1;
2253 if (lpcf->Flags & CF_ANSIONLY)
2254 if (lplf->lfCharSet != ANSI_CHARSET)
2255 return 1;
2256 if (lpcf->Flags & CF_TTONLY)
2257 if (!(nFontType & 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2258 return 1;
2260 i=SendMessage16(hwnd,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(lplf->lfFaceName));
2261 if (i!=CB_ERR)
2263 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2264 SendMessage16(hwnd, CB_SETITEMDATA,i,MAKELONG(nFontType,w));
2265 return 1 ; /* store some important font information */
2267 else
2268 return 0;
2271 /*************************************************************************
2272 * SetFontStylesToCombo2 [internal]
2274 * Fill font style information into combobox (without using font.c directly)
2276 static int SetFontStylesToCombo2(HWND hwnd, HDC hdc, LPLOGFONT16 lplf ,LPTEXTMETRIC16 lptm)
2278 #define FSTYLES 4
2279 struct FONTSTYLE
2280 { int italic;
2281 int weight;
2282 char stname[20]; };
2283 static struct FONTSTYLE fontstyles[FSTYLES]={
2284 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
2285 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
2286 HFONT hf;
2287 int i,j;
2289 for (i=0;i<FSTYLES;i++)
2291 lplf->lfItalic=fontstyles[i].italic;
2292 lplf->lfWeight=fontstyles[i].weight;
2293 hf=CreateFontIndirect16(lplf);
2294 hf=SelectObject(hdc,hf);
2295 GetTextMetrics16(hdc,lptm);
2296 hf=SelectObject(hdc,hf);
2297 DeleteObject(hf);
2299 if (lptm->tmWeight==fontstyles[i].weight &&
2300 lptm->tmItalic==fontstyles[i].italic) /* font successful created ? */
2302 j=SendMessage16(hwnd,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(fontstyles[i].stname));
2303 if (j==CB_ERR) return 1;
2304 j=SendMessage16(hwnd, CB_SETITEMDATA, j,
2305 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
2306 if (j==CB_ERR) return 1;
2309 return 0;
2312 /*************************************************************************
2313 * SetFontSizesToCombo3 [internal]
2315 static int SetFontSizesToCombo3(HWND hwnd, LPLOGFONT16 lplf, LPCHOOSEFONT lpcf)
2317 int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2318 int h,i,j;
2319 char buffer[20];
2321 for (i=0;sizes[i] && !lplf->lfHeight;i++)
2323 h=lplf->lfHeight ? lplf->lfHeight : sizes[i];
2325 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2326 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
2328 sprintf(buffer,"%2d",h);
2329 j=SendMessage16(hwnd,CB_FINDSTRING,-1,(LPARAM)MAKE_SEGPTR(buffer));
2330 if (j==CB_ERR)
2332 j=SendMessage16(hwnd,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2333 if (j==CB_ERR) return 1;
2334 j=SendMessage16(hwnd, CB_SETITEMDATA, j, h);
2335 if (j==CB_ERR) return 1;
2339 return 0;
2343 /***********************************************************************
2344 * FontStyleEnumProc (COMMDLG.18)
2346 int FontStyleEnumProc(LPLOGFONT16 lplf ,LPTEXTMETRIC16 lptm, int nFontType, LPARAM lParam)
2348 HWND hcmb2=LOWORD(lParam);
2349 HWND hcmb3=HIWORD(lParam);
2350 HWND hDlg=GetParent(hcmb3);
2351 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2352 int i;
2354 dprintf_commdlg(stddeb,"FontStyleEnumProc: (nFontType=%d)\n",nFontType);
2355 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",
2356 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,lplf->lfEscapement,lplf->lfOrientation,
2357 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,lplf->lfStrikeOut,lplf->lfCharSet,
2358 lplf->lfOutPrecision,lplf->lfClipPrecision,lplf->lfQuality,lplf->lfPitchAndFamily);
2360 if (SetFontSizesToCombo3(hcmb3, lplf ,lpcf))
2361 return 0;
2363 if (!SendMessage16(hcmb2,CB_GETCOUNT,0,0))
2365 HDC hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
2366 i=SetFontStylesToCombo2(hcmb2,hdc,lplf,lptm);
2367 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2368 ReleaseDC(hDlg,hdc);
2369 if (i)
2370 return 0;
2372 return 1 ;
2376 /***********************************************************************
2377 * CFn_WMInitDialog [internal]
2379 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam)
2381 HDC hdc;
2382 int i,j,res,init=0;
2383 long l;
2384 FARPROC16 enumCallback = MODULE_GetWndProcEntry16("FontFamilyEnumProc");
2385 LPLOGFONT16 lpxx;
2386 HCURSOR hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
2387 LPCHOOSEFONT lpcf;
2389 SetWindowLong32A(hDlg, DWL_USER, lParam);
2390 lpcf=(LPCHOOSEFONT)lParam;
2391 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2392 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
2394 if (lpcf->lStructSize != sizeof(CHOOSEFONT))
2396 dprintf_commdlg(stddeb,"WM_INITDIALOG: structure size failure !!!\n");
2397 EndDialog (hDlg, 0);
2398 return FALSE;
2400 if (!hBitmapTT)
2401 hBitmapTT = LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE));
2403 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
2404 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
2405 if (!(lpcf->Flags & CF_APPLY))
2406 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
2407 if (lpcf->Flags & CF_EFFECTS)
2409 for (res=1,i=0;res && i<TEXT_COLORS;i++)
2411 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2412 j=SendDlgItemMessage16(hDlg,cmb4,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR("[color name]"));
2413 SendDlgItemMessage16(hDlg,cmb4, CB_SETITEMDATA,j,textcolors[j]);
2414 /* look for a fitting value in color combobox */
2415 if (textcolors[j]==lpcf->rgbColors)
2416 SendDlgItemMessage16(hDlg,cmb4, CB_SETCURSEL,j,0);
2419 else
2421 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
2422 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
2423 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
2424 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
2425 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
2427 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
2428 if (hdc)
2430 if (!EnumFontFamilies (hdc, NULL,enumCallback,(LPARAM)GetDlgItem(hDlg,cmb1)))
2431 dprintf_commdlg(stddeb,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2432 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
2434 /* look for fitting font name in combobox1 */
2435 j=SendDlgItemMessage16(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
2436 if (j!=CB_ERR)
2438 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL,j,0);
2439 SendMessage16(hDlg,WM_COMMAND,cmb1,MAKELONG(GetDlgItem(hDlg,cmb1),CBN_SELCHANGE));
2440 init=1;
2441 /* look for fitting font style in combobox2 */
2442 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
2443 for (i=0;i<TEXT_EXTRAS;i++)
2445 if (l==SendDlgItemMessage16(hDlg,cmb2, CB_GETITEMDATA,i,0))
2446 SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL,i,0);
2449 /* look for fitting font size in combobox3 */
2450 j=SendDlgItemMessage16(hDlg,cmb3,CB_GETCOUNT,0,0);
2451 for (i=0;i<j;i++)
2453 if (lpxx->lfHeight==(int)SendDlgItemMessage16(hDlg,cmb3, CB_GETITEMDATA,i,0))
2454 SendDlgItemMessage16(hDlg,cmb3,CB_SETCURSEL,i,0);
2457 if (!init)
2459 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL,0,0);
2460 SendMessage16(hDlg,WM_COMMAND,cmb1,MAKELONG(GetDlgItem(hDlg,cmb1),CBN_SELCHANGE));
2463 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
2465 j=SendDlgItemMessage16(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
2466 if (j!=CB_ERR)
2468 j=SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL,j,0);
2469 SendMessage16(hDlg,WM_COMMAND,cmb2,MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
2473 else
2475 dprintf_commdlg(stddeb,"WM_INITDIALOG: HDC failure !!!\n");
2476 EndDialog (hDlg, 0);
2477 return FALSE;
2480 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2481 ReleaseDC(hDlg,hdc);
2482 res=TRUE;
2483 if (CFn_HookCallChk(lpcf))
2484 res=CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2485 SetCursor(hcursor);
2486 return res;
2490 /***********************************************************************
2491 * CFn_WMMeasureItem [internal]
2493 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
2495 BITMAP16 bm;
2496 LPMEASUREITEMSTRUCT16 lpmi=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT16)lParam);
2497 if (!hBitmapTT)
2498 hBitmapTT = LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE));
2499 GetObject16( hBitmapTT, sizeof(bm), &bm );
2500 lpmi->itemHeight=bm.bmHeight;
2501 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2502 return 0;
2506 /***********************************************************************
2507 * CFn_WMDrawItem [internal]
2509 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
2511 HBRUSH hBrush;
2512 char buffer[40];
2513 BITMAP16 bm;
2514 COLORREF cr;
2515 RECT16 rect;
2516 #if 0
2517 HDC hMemDC;
2518 int nFontType;
2519 HBITMAP hBitmap; /* for later TT usage */
2520 #endif
2521 LPDRAWITEMSTRUCT16 lpdi = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
2523 if (lpdi->itemID == 0xFFFF) /* got no items */
2524 DrawFocusRect16(lpdi->hDC, &lpdi->rcItem);
2525 else
2527 if (lpdi->CtlType == ODT_COMBOBOX)
2529 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
2530 SelectObject(lpdi->hDC, hBrush);
2531 FillRect16(lpdi->hDC, &lpdi->rcItem, hBrush);
2533 else
2534 return TRUE; /* this should never happen */
2536 rect=lpdi->rcItem;
2537 switch (lpdi->CtlID)
2539 case cmb1: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2540 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2541 (LPARAM)MAKE_SEGPTR(buffer));
2542 GetObject16( hBitmapTT, sizeof(bm), &bm );
2543 TextOut16(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
2544 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2545 #if 0
2546 nFontType = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
2547 /* FIXME: draw bitmap if truetype usage */
2548 if (nFontType&TRUETYPE_FONTTYPE)
2550 hMemDC = CreateCompatibleDC(lpdi->hDC);
2551 hBitmap = SelectObject(hMemDC, hBitmapTT);
2552 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
2553 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
2554 SelectObject(hMemDC, hBitmap);
2555 DeleteDC(hMemDC);
2557 #endif
2558 break;
2559 case cmb2:
2560 case cmb3: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2561 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2562 (LPARAM)MAKE_SEGPTR(buffer));
2563 TextOut16(lpdi->hDC, lpdi->rcItem.left,
2564 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2565 break;
2567 case cmb4: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2568 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2569 (LPARAM)MAKE_SEGPTR(buffer));
2570 TextOut16(lpdi->hDC, lpdi->rcItem.left + 25+5,
2571 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2572 cr = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
2573 hBrush = CreateSolidBrush(cr);
2574 if (hBrush)
2576 hBrush = SelectObject (lpdi->hDC, hBrush) ;
2577 rect.right=rect.left+25;
2578 rect.top++;
2579 rect.left+=5;
2580 rect.bottom--;
2581 Rectangle(lpdi->hDC,rect.left,rect.top,rect.right,rect.bottom);
2582 DeleteObject (SelectObject (lpdi->hDC, hBrush)) ;
2584 rect=lpdi->rcItem;
2585 rect.left+=25+5;
2586 break;
2588 default: return TRUE; /* this should never happen */
2590 if (lpdi->itemState ==ODS_SELECTED)
2591 InvertRect16(lpdi->hDC, &rect);
2593 return TRUE;
2596 /***********************************************************************
2597 * CFn_WMCtlColor [internal]
2599 LRESULT CFn_WMCtlColor(HWND hDlg, WPARAM wParam, LPARAM lParam)
2601 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2603 if (lpcf->Flags & CF_EFFECTS)
2604 if (HIWORD(lParam)==CTLCOLOR_STATIC && GetDlgCtrlID(LOWORD(lParam))==stc6)
2606 SetTextColor(wParam,lpcf->rgbColors);
2607 return GetStockObject(WHITE_BRUSH);
2609 return 0;
2612 /***********************************************************************
2613 * CFn_WMCommand [internal]
2615 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
2617 char buffer[200];
2618 FARPROC16 enumCallback;
2619 HFONT hFont/*,hFontOld*/;
2620 int i,j;
2621 long l;
2622 HDC hdc;
2623 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2624 LPLOGFONT16 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2626 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam);
2627 switch (wParam)
2629 case cmb1:if (HIWORD(lParam)==CBN_SELCHANGE)
2631 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
2632 if (hdc)
2634 SendDlgItemMessage16(hDlg,cmb2,CB_RESETCONTENT,0,0);
2635 SendDlgItemMessage16(hDlg,cmb3,CB_RESETCONTENT,0,0);
2636 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL,0,0);
2637 if (i!=CB_ERR)
2639 HCURSOR hcursor=SetCursor(LoadCursor16(0,IDC_WAIT));
2640 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT,i,(LPARAM)MAKE_SEGPTR(buffer));
2641 dprintf_commdlg(stddeb,"WM_COMMAND/cmb1 =>%s\n",buffer);
2642 enumCallback = MODULE_GetWndProcEntry16("FontStyleEnumProc");
2643 EnumFontFamilies(hdc,buffer,enumCallback,
2644 MAKELONG(GetDlgItem(hDlg,cmb2),GetDlgItem(hDlg,cmb3)));
2645 SetCursor(hcursor);
2647 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2648 ReleaseDC(hDlg,hdc);
2650 else
2652 dprintf_commdlg(stddeb,"WM_COMMAND: HDC failure !!!\n");
2653 EndDialog (hDlg, 0);
2654 return TRUE;
2657 case chx1:
2658 case chx2:
2659 case cmb2:
2660 case cmb3:if (HIWORD(lParam)==CBN_SELCHANGE || HIWORD(lParam)== BN_CLICKED )
2662 dprintf_commdlg(stddeb,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
2663 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL,0,0);
2664 if (i==CB_ERR)
2665 i=GetDlgItemText32A( hDlg, cmb1, buffer, sizeof(buffer) );
2666 else
2668 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT,i,(LPARAM)MAKE_SEGPTR(buffer));
2669 l=SendDlgItemMessage16(hDlg,cmb1,CB_GETITEMDATA,i,0);
2670 j=HIWORD(l);
2671 lpcf->nFontType = LOWORD(l);
2672 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2673 /* same value reported to the EnumFonts
2674 call back with the extra FONTTYPE_... bits added */
2675 lpxx->lfPitchAndFamily=j&0xff;
2676 lpxx->lfCharSet=j>>8;
2678 strcpy(lpxx->lfFaceName,buffer);
2679 i=SendDlgItemMessage16(hDlg,cmb2,CB_GETCURSEL,0,0);
2680 if (i!=CB_ERR)
2682 l=SendDlgItemMessage16(hDlg,cmb2,CB_GETITEMDATA,i,0);
2683 if (0!=(lpxx->lfItalic=HIWORD(l)))
2684 lpcf->nFontType |= ITALIC_FONTTYPE;
2685 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
2686 lpcf->nFontType |= BOLD_FONTTYPE;
2688 i=SendDlgItemMessage16(hDlg,cmb3,CB_GETCURSEL,0,0);
2689 if (i!=CB_ERR)
2690 lpxx->lfHeight=-LOWORD(SendDlgItemMessage16(hDlg,cmb3,CB_GETITEMDATA,i,0));
2691 else
2692 lpxx->lfHeight=0;
2693 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
2694 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
2695 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
2696 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
2697 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
2698 lpxx->lfQuality=DEFAULT_QUALITY;
2699 lpcf->iPointSize= -10*lpxx->lfHeight;
2701 hFont=CreateFontIndirect16(lpxx);
2702 if (hFont)
2703 SendDlgItemMessage16(hDlg,stc6,WM_SETFONT,hFont,TRUE);
2704 /* FIXME: Delete old font ...? */
2706 break;
2708 case cmb4:i=SendDlgItemMessage16(hDlg,cmb4,CB_GETCURSEL,0,0);
2709 if (i!=CB_ERR)
2711 lpcf->rgbColors=textcolors[i];
2712 InvalidateRect32( GetDlgItem(hDlg,stc6), NULL, 0 );
2714 break;
2716 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
2717 if (lpcf->hwndOwner)
2718 SendMessage16(lpcf->hwndOwner,i,0,(LPARAM)lpcf);
2719 if (CFn_HookCallChk(lpcf))
2720 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);
2721 break;
2723 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2724 ( (lpcf->Flags & CF_LIMITSIZE) &&
2725 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
2726 (-lpxx->lfHeight <= lpcf->nSizeMax)))
2727 EndDialog(hDlg, TRUE);
2728 else
2730 sprintf(buffer,"Select a font size among %d and %d points.",lpcf->nSizeMin,lpcf->nSizeMax);
2731 MessageBox(hDlg,buffer,NULL,MB_OK);
2733 return(TRUE);
2734 case IDCANCEL:EndDialog(hDlg, FALSE);
2735 return(TRUE);
2737 return(FALSE);
2741 /***********************************************************************
2742 * FormatCharDlgProc (COMMDLG.16)
2743 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2744 2. some CF_.. flags are not supported
2745 3. some TType extensions
2747 LRESULT FormatCharDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2749 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2750 if (message!=WM_INITDIALOG)
2752 int res=0;
2753 if (!lpcf)
2754 return FALSE;
2755 if (CFn_HookCallChk(lpcf))
2756 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
2757 if (res)
2758 return res;
2760 else
2761 return CFn_WMInitDialog(hDlg,wParam,lParam);
2762 switch (message)
2764 case WM_MEASUREITEM:
2765 return CFn_WMMeasureItem(hDlg,wParam,lParam);
2766 case WM_DRAWITEM:
2767 return CFn_WMDrawItem(hDlg,wParam,lParam);
2768 case WM_CTLCOLOR:
2769 return CFn_WMCtlColor(hDlg,wParam,lParam);
2770 case WM_COMMAND:
2771 return CFn_WMCommand(hDlg,wParam,lParam);
2772 case WM_CHOOSEFONT_GETLOGFONT:
2773 dprintf_commdlg(stddeb,
2774 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
2775 /* FIXME: current logfont back to caller */
2776 break;
2778 return FALSE;