Release 960521
[wine/multimedia.git] / misc / commdlg.c
bloba0569f74d53d0d7070b6b9f1f462461dbebd2ac0
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 = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER));
42 if (!hFolder2) hFolder2 = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2));
43 if (!hFloppy) hFloppy = LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY));
44 if (!hHDisk) hHDisk = LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK));
45 if (!hCDRom) hCDRom = LoadBitmap(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 = FindResource( lpofn->hInstance,
72 lpofn->lpTemplateName, RT_DIALOG)))
74 CommDlgLastError = CDERR_FINDRESFAILURE;
75 return FALSE;
77 hDlgTmpl = LoadResource( 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 = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
88 MODULE_GetWndProcEntry16("FileOpenDlgProc"),
89 (DWORD)lpofn );
91 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
93 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( 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 = FindResource( lpofn->hInstance,
119 lpofn->lpTemplateName, RT_DIALOG )))
121 CommDlgLastError = CDERR_FINDRESFAILURE;
122 return FALSE;
124 hDlgTmpl = LoadResource( lpofn->hInstance, hResInfo );
126 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE );
128 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
129 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
130 MODULE_GetWndProcEntry16("FileSaveDlgProc"),
131 (DWORD)lpofn);
132 if (!(lpofn->Flags & OFN_ENABLETEMPLATEHANDLE))
134 if (lpofn->Flags & OFN_ENABLETEMPLATE) FreeResource( 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)
211 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
212 char str[512];
213 HBRUSH hBrush;
214 HBITMAP hBitmap, hPrevBitmap;
215 BITMAP 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));
225 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
226 str, strlen(str));
227 if (lpdis->itemState != 0) {
228 InvertRect16(lpdis->hDC, &lpdis->rcItem);
230 return TRUE;
233 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2) {
234 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
235 SelectObject(lpdis->hDC, hBrush);
236 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
237 SendMessage16(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
238 (LPARAM)MAKE_SEGPTR(str));
240 hBitmap = hFolder;
241 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
242 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
243 lpdis->rcItem.top, str, strlen(str));
244 hMemDC = CreateCompatibleDC(lpdis->hDC);
245 hPrevBitmap = SelectObject(hMemDC, hBitmap);
246 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
247 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
248 SelectObject(hMemDC, hPrevBitmap);
249 DeleteDC(hMemDC);
250 if (lpdis->itemState != 0) {
251 InvertRect16(lpdis->hDC, &lpdis->rcItem);
253 return TRUE;
255 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2) {
256 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
257 SelectObject(lpdis->hDC, hBrush);
258 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
259 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
260 (LPARAM)MAKE_SEGPTR(str));
261 switch(DRIVE_GetType( str[2] - 'a' ))
263 case TYPE_FLOPPY: hBitmap = hFloppy; break;
264 case TYPE_CDROM: hBitmap = hCDRom; break;
265 case TYPE_HD:
266 case TYPE_NETWORK:
267 default: hBitmap = hHDisk; break;
269 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
270 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
271 lpdis->rcItem.top, str, strlen(str));
272 hMemDC = CreateCompatibleDC(lpdis->hDC);
273 hPrevBitmap = SelectObject(hMemDC, hBitmap);
274 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
275 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
276 SelectObject(hMemDC, hPrevBitmap);
277 DeleteDC(hMemDC);
278 if (lpdis->itemState != 0) {
279 InvertRect16(lpdis->hDC, &lpdis->rcItem);
281 return TRUE;
283 return FALSE;
286 /***********************************************************************
287 * FILEDLG_WMMeasureItem [internal]
289 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
291 BITMAP bm;
292 LPMEASUREITEMSTRUCT lpmeasure;
294 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
295 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
296 lpmeasure->itemHeight = bm.bmHeight;
297 return TRUE;
300 /***********************************************************************
301 * FILEDLG_HookCallChk [internal]
303 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn)
305 if (lpofn)
306 if (lpofn->Flags & OFN_ENABLEHOOK)
307 if (lpofn->lpfnHook)
308 return 1;
309 return 0;
312 /***********************************************************************
313 * FILEDLG_WMInitDialog [internal]
316 static LONG FILEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
318 int n;
319 int i;
320 LPOPENFILENAME lpofn;
321 char tmpstr[512];
322 LPSTR pstr;
323 SetWindowLong32A(hWnd, DWL_USER, lParam);
324 lpofn = (LPOPENFILENAME)lParam;
325 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
326 /* read custom filter information */
327 if (lpofn->lpstrCustomFilter)
329 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
330 dprintf_commdlg(stddeb,"lpstrCustomFilter = %p\n", pstr);
331 while(*pstr)
333 n = strlen(pstr);
334 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
335 dprintf_commdlg(stddeb,"lpstrCustomFilter // add tmpstr='%s' ", tmpstr);
336 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
337 pstr += n + 1;
338 n = strlen(pstr);
339 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
340 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
341 pstr += n + 1;
344 /* read filter information */
345 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
346 while(*pstr)
348 n = strlen(pstr);
349 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
350 dprintf_commdlg(stddeb,"lpstrFilter // add tmpstr='%s' ", tmpstr);
351 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
352 pstr += n + 1;
353 n = strlen(pstr);
354 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
355 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
356 pstr += n + 1;
358 /* set default filter */
359 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
360 lpofn->nFilterIndex = 1;
361 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL, lpofn->nFilterIndex - 1, 0);
362 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
363 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
364 tmpstr[511]=0;
365 dprintf_commdlg(stddeb,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
366 lpofn->nFilterIndex, tmpstr);
367 SetDlgItemText32A( hWnd, edt1, tmpstr );
368 /* get drive list */
369 *tmpstr = 0;
370 DlgDirListComboBox16(hWnd, tmpstr, cmb2, 0, 0xC000);
371 /* read initial directory */
372 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
374 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
375 tmpstr[510]=0;
376 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
377 && tmpstr[strlen(tmpstr)-1] != ':')
378 strcat(tmpstr,"\\");
380 else
381 *tmpstr = 0;
382 if (!FILEDLG_ScanDir(hWnd, tmpstr))
383 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
384 /* select current drive in combo 2 */
385 n = DRIVE_GetCurrentDrive();
386 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL, n, 0);
387 if (!(lpofn->Flags & OFN_SHOWHELP))
388 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
389 if (lpofn->Flags & OFN_HIDEREADONLY)
390 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
391 if (FILEDLG_HookCallChk(lpofn))
392 return (BOOL)CallWindowProc16(lpofn->lpfnHook,
393 hWnd, WM_INITDIALOG, wParam,(LPARAM)MAKE_SEGPTR(lpofn));
394 else
395 return TRUE;
398 /***********************************************************************
399 * FILEDLG_WMCommand [internal]
401 static LRESULT FILEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
403 LONG lRet;
404 LPOPENFILENAME lpofn;
405 OPENFILENAME ofn2;
406 char tmpstr[512], tmpstr2[512];
407 LPSTR pstr, pstr2;
408 UINT control,notification;
410 /* Notifications are packaged differently in Win32 */
411 #ifdef WINELIB32
412 control = LOWORD(wParam);
413 notification = HIWORD(wParam);
414 #else
415 control = wParam;
416 notification = HIWORD(lParam);
417 #endif
419 lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
420 switch (control)
422 case lst1: /* file list */
423 FILEDLG_StripEditControl(hWnd);
424 if (notification == LBN_DBLCLK)
425 goto almost_ok;
426 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL, 0, 0);
427 if (lRet == LB_ERR) return TRUE;
428 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT, lRet,
429 (LPARAM)MAKE_SEGPTR(tmpstr));
430 SetDlgItemText32A( hWnd, edt1, tmpstr );
432 if (FILEDLG_HookCallChk(lpofn))
433 CallWindowProc16(lpofn->lpfnHook, hWnd,
434 RegisterWindowMessage32A( LBSELCHSTRING ),
435 control, MAKELONG(lRet,CD_LBSELCHANGE));
436 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
437 return TRUE;
438 case lst2: /* directory list */
439 FILEDLG_StripEditControl(hWnd);
440 if (notification == LBN_DBLCLK)
442 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL, 0, 0);
443 if (lRet == LB_ERR) return TRUE;
444 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT, lRet,
445 (LPARAM)MAKE_SEGPTR(tmpstr));
446 if (tmpstr[0] == '[')
448 tmpstr[strlen(tmpstr) - 1] = 0;
449 strcpy(tmpstr,tmpstr+1);
451 strcat(tmpstr, "\\");
452 goto reset_scan;
454 return TRUE;
455 case cmb1: /* file type drop list */
456 if (notification == CBN_SELCHANGE)
458 *tmpstr = 0;
459 goto reset_scan;
461 return TRUE;
462 case cmb2: /* disk drop list */
463 FILEDLG_StripEditControl(hWnd);
464 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
465 if (lRet == LB_ERR) return 0;
466 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT, lRet, (LPARAM)MAKE_SEGPTR(tmpstr));
467 sprintf(tmpstr, "%c:", tmpstr[2]);
468 reset_scan:
469 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL, 0, 0);
470 if (lRet == LB_ERR)
471 return TRUE;
472 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA, lRet, 0);
473 dprintf_commdlg(stddeb,"Selected filter : %s\n", pstr);
474 SetDlgItemText32A( hWnd, edt1, pstr );
475 FILEDLG_ScanDir(hWnd, tmpstr);
476 return TRUE;
477 case chx1:
478 return TRUE;
479 case pshHelp:
480 return TRUE;
481 case IDOK:
482 almost_ok:
483 ofn2=*lpofn; /* for later restoring */
484 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
485 pstr = strrchr(tmpstr, '\\');
486 if (pstr == NULL)
487 pstr = strrchr(tmpstr, ':');
488 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
490 /* edit control contains wildcards */
491 if (pstr != NULL)
493 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
494 *(pstr+1) = 0;
496 else
498 strcpy(tmpstr2, tmpstr);
499 *tmpstr=0;
501 dprintf_commdlg(stddeb,"commdlg: %s, %s\n", tmpstr, tmpstr2);
502 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
503 FILEDLG_ScanDir(hWnd, tmpstr);
504 return TRUE;
506 /* no wildcards, we might have a directory or a filename */
507 /* try appending a wildcard and reading the directory */
508 pstr2 = tmpstr + strlen(tmpstr);
509 if (pstr == NULL || *(pstr+1) != 0)
510 strcat(tmpstr, "\\");
511 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL, 0, 0);
512 if (lRet == LB_ERR) return TRUE;
513 lpofn->nFilterIndex = lRet + 1;
514 dprintf_commdlg(stddeb,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
515 lstrcpyn(tmpstr2,
516 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
517 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
518 lRet), sizeof(tmpstr2));
519 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
520 /* if ScanDir succeeds, we have changed the directory */
521 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
522 /* if not, this must be a filename */
523 *pstr2 = 0;
524 if (pstr != NULL)
526 /* strip off the pathname */
527 *pstr = 0;
528 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
529 lstrcpyn(tmpstr2, pstr+1, sizeof(tmpstr2) );
530 /* Should we MessageBox() if this fails? */
531 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
532 strcpy(tmpstr, tmpstr2);
534 else SetDlgItemText32A( hWnd, edt1, tmpstr );
535 #if 0
536 ShowWindow(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
537 #endif
539 int drive = DRIVE_GetCurrentDrive();
540 tmpstr2[0] = 'A'+ drive;
541 tmpstr2[1] = ':';
542 tmpstr2[2] = '\\';
543 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
544 if (strlen(tmpstr2) > 3)
545 strcat(tmpstr2, "\\");
546 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
547 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
549 lpofn->nFileOffset = 0;
550 lpofn->nFileExtension = 0;
551 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
552 lpofn->nFileExtension++;
553 if (lpofn->nFileExtension == '\0')
554 lpofn->nFileExtension = 0;
555 else
556 lpofn->nFileExtension++;
557 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
559 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL, 0, 0);
560 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT, lRet,
561 (LPARAM)MAKE_SEGPTR(tmpstr));
562 dprintf_commdlg(stddeb,"strcpy'ing '%s'\n",tmpstr); fflush(stdout);
563 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
565 if (FILEDLG_HookCallChk(lpofn))
567 lRet= (BOOL)CallWindowProc16(lpofn->lpfnHook,
568 hWnd, RegisterWindowMessage32A( FILEOKSTRING ),
569 0, (LPARAM)MAKE_SEGPTR(lpofn));
570 if (lRet)
572 *lpofn=ofn2; /* restore old state */
573 #if 0
574 ShowWindow(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
575 #endif
576 break;
579 EndDialog(hWnd, TRUE);
580 return TRUE;
581 case IDCANCEL:
582 EndDialog(hWnd, FALSE);
583 return TRUE;
585 return FALSE;
589 /***********************************************************************
590 * FileOpenDlgProc (COMMDLG.6)
592 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
594 LPOPENFILENAME lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
596 if (wMsg!=WM_INITDIALOG)
597 if (FILEDLG_HookCallChk(lpofn))
599 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
600 if (lRet)
601 return lRet; /* else continue message processing */
603 switch (wMsg)
605 case WM_INITDIALOG:
606 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
607 case WM_MEASUREITEM:
608 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
609 case WM_DRAWITEM:
610 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
611 case WM_COMMAND:
612 return FILEDLG_WMCommand(hWnd, wParam, lParam);
613 #if 0
614 case WM_CTLCOLOR:
615 SetBkColor((HDC)wParam, 0x00C0C0C0);
616 switch (HIWORD(lParam))
618 case CTLCOLOR_BTN:
619 SetTextColor((HDC)wParam, 0x00000000);
620 return hGRAYBrush;
621 case CTLCOLOR_STATIC:
622 SetTextColor((HDC)wParam, 0x00000000);
623 return hGRAYBrush;
625 break;
626 #endif
628 return FALSE;
632 /***********************************************************************
633 * FileSaveDlgProc (COMMDLG.7)
635 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
637 LPOPENFILENAME lpofn = (LPOPENFILENAME)GetWindowLong(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) {
647 case WM_INITDIALOG:
648 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
650 case WM_MEASUREITEM:
651 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
653 case WM_DRAWITEM:
654 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
656 case WM_COMMAND:
657 return FILEDLG_WMCommand(hWnd, wParam, lParam);
661 case WM_CTLCOLOR:
662 SetBkColor((HDC)wParam, 0x00C0C0C0);
663 switch (HIWORD(lParam))
665 case CTLCOLOR_BTN:
666 SetTextColor((HDC)wParam, 0x00000000);
667 return hGRAYBrush;
668 case CTLCOLOR_STATIC:
669 SetTextColor((HDC)wParam, 0x00000000);
670 return hGRAYBrush;
672 return FALSE;
675 return FALSE;
679 /***********************************************************************
680 * ChooseColor (COMMDLG.5)
682 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
684 HANDLE hInst, hDlgTmpl;
685 BOOL bRet;
687 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR );
688 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
689 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
690 MODULE_GetWndProcEntry16("ColorDlgProc"),
691 (DWORD)lpChCol );
692 SYSRES_FreeResource( hDlgTmpl );
693 return bRet;
697 /***********************************************************************
698 * FindTextDlg (COMMDLG.11)
700 BOOL FindText(LPFINDREPLACE lpFind)
702 HANDLE hInst, hDlgTmpl;
703 BOOL bRet;
704 SEGPTR ptr;
707 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
708 * For now, only the standard dialog works.
711 * FIXME : We should do error checking on the lpFind structure here
712 * and make CommDlgExtendedError() return the error condition.
714 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT );
715 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
716 if (!(ptr = (SEGPTR)WIN16_GlobalLock16( hDlgTmpl ))) return -1;
717 bRet = CreateDialogIndirectParam( hInst, ptr, lpFind->hwndOwner,
718 MODULE_GetWndProcEntry16("FindTextDlgProc"),
719 (DWORD)lpFind );
720 GlobalUnlock16( hDlgTmpl );
721 SYSRES_FreeResource( hDlgTmpl );
722 return bRet;
726 /***********************************************************************
727 * ReplaceTextDlg (COMMDLG.12)
729 BOOL ReplaceText(LPFINDREPLACE lpFind)
731 HANDLE hInst, hDlgTmpl;
732 BOOL bRet;
733 SEGPTR ptr;
736 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
737 * For now, only the standard dialog works.
740 * FIXME : We should do error checking on the lpFind structure here
741 * and make CommDlgExtendedError() return the error condition.
743 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT );
744 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
745 if (!(ptr = (SEGPTR)WIN16_GlobalLock16( hDlgTmpl ))) return -1;
746 bRet = CreateDialogIndirectParam( hInst, ptr, lpFind->hwndOwner,
747 MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
748 (DWORD)lpFind );
749 GlobalUnlock16( hDlgTmpl );
750 SYSRES_FreeResource( hDlgTmpl );
751 return bRet;
755 /***********************************************************************
756 * FINDDLG_WMInitDialog [internal]
758 static LRESULT FINDDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
760 LPFINDREPLACE lpfr;
762 SetWindowLong32A(hWnd, DWL_USER, lParam);
763 lpfr = (LPFINDREPLACE)lParam;
764 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
766 * FIXME : If the initial FindWhat string is empty, we should disable the
767 * FindNext (IDOK) button. Only after typing some text, the button should be
768 * enabled.
770 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
771 CheckRadioButton(hWnd, rad1, rad2, (lpfr->Flags & FR_DOWN) ? rad2 : rad1);
772 if (lpfr->Flags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
773 EnableWindow(GetDlgItem(hWnd, rad1), FALSE);
774 EnableWindow(GetDlgItem(hWnd, rad2), FALSE);
776 if (lpfr->Flags & FR_HIDEUPDOWN) {
777 ShowWindow(GetDlgItem(hWnd, rad1), SW_HIDE);
778 ShowWindow(GetDlgItem(hWnd, rad2), SW_HIDE);
779 ShowWindow(GetDlgItem(hWnd, grp1), SW_HIDE);
781 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
782 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
783 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
784 if (lpfr->Flags & FR_HIDEWHOLEWORD)
785 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
786 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
787 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
788 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
789 if (lpfr->Flags & FR_HIDEMATCHCASE)
790 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
791 if (!(lpfr->Flags & FR_SHOWHELP)) {
792 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
793 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
795 ShowWindow(hWnd, SW_SHOWNORMAL);
796 return TRUE;
800 /***********************************************************************
801 * FINDDLG_WMCommand [internal]
803 static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
805 LPFINDREPLACE lpfr;
806 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
807 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
809 lpfr = (LPFINDREPLACE)GetWindowLong(hWnd, DWL_USER);
810 switch (wParam) {
811 case IDOK:
812 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
813 if (IsDlgButtonChecked(hWnd, rad2))
814 lpfr->Flags |= FR_DOWN;
815 else lpfr->Flags &= ~FR_DOWN;
816 if (IsDlgButtonChecked(hWnd, chx1))
817 lpfr->Flags |= FR_WHOLEWORD;
818 else lpfr->Flags &= ~FR_WHOLEWORD;
819 if (IsDlgButtonChecked(hWnd, chx2))
820 lpfr->Flags |= FR_MATCHCASE;
821 else lpfr->Flags &= ~FR_MATCHCASE;
822 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
823 lpfr->Flags |= FR_FINDNEXT;
824 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
825 return TRUE;
826 case IDCANCEL:
827 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
828 lpfr->Flags |= FR_DIALOGTERM;
829 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
830 DestroyWindow(hWnd);
831 return TRUE;
832 case pshHelp:
833 /* FIXME : should lpfr structure be passed as an argument ??? */
834 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
835 return TRUE;
837 return FALSE;
841 /***********************************************************************
842 * FindTextDlgProc (COMMDLG.13)
844 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
846 switch (wMsg) {
847 case WM_INITDIALOG:
848 return FINDDLG_WMInitDialog(hWnd, wParam, lParam);
849 case WM_COMMAND:
850 return FINDDLG_WMCommand(hWnd, wParam, lParam);
852 return FALSE;
856 /***********************************************************************
857 * REPLACEDLG_WMInitDialog [internal]
859 static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
861 LPFINDREPLACE lpfr;
863 SetWindowLong32A(hWnd, DWL_USER, lParam);
864 lpfr = (LPFINDREPLACE)lParam;
865 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
867 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
868 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
869 * enabled.
871 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
872 SetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith);
873 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
874 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
875 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
876 if (lpfr->Flags & FR_HIDEWHOLEWORD)
877 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
878 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
879 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
880 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
881 if (lpfr->Flags & FR_HIDEMATCHCASE)
882 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
883 if (!(lpfr->Flags & FR_SHOWHELP)) {
884 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
885 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
887 ShowWindow(hWnd, SW_SHOWNORMAL);
888 return TRUE;
892 /***********************************************************************
893 * REPLACEDLG_WMCommand [internal]
895 static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
897 LPFINDREPLACE lpfr;
898 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
899 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
901 lpfr = (LPFINDREPLACE)GetWindowLong(hWnd, DWL_USER);
902 switch (wParam) {
903 case IDOK:
904 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
905 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
906 if (IsDlgButtonChecked(hWnd, chx1))
907 lpfr->Flags |= FR_WHOLEWORD;
908 else lpfr->Flags &= ~FR_WHOLEWORD;
909 if (IsDlgButtonChecked(hWnd, chx2))
910 lpfr->Flags |= FR_MATCHCASE;
911 else lpfr->Flags &= ~FR_MATCHCASE;
912 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
913 lpfr->Flags |= FR_FINDNEXT;
914 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
915 return TRUE;
916 case IDCANCEL:
917 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
918 lpfr->Flags |= FR_DIALOGTERM;
919 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
920 DestroyWindow(hWnd);
921 return TRUE;
922 case psh1:
923 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
924 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
925 if (IsDlgButtonChecked(hWnd, chx1))
926 lpfr->Flags |= FR_WHOLEWORD;
927 else lpfr->Flags &= ~FR_WHOLEWORD;
928 if (IsDlgButtonChecked(hWnd, chx2))
929 lpfr->Flags |= FR_MATCHCASE;
930 else lpfr->Flags &= ~FR_MATCHCASE;
931 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
932 lpfr->Flags |= FR_REPLACE;
933 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
934 return TRUE;
935 case psh2:
936 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
937 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
938 if (IsDlgButtonChecked(hWnd, chx1))
939 lpfr->Flags |= FR_WHOLEWORD;
940 else lpfr->Flags &= ~FR_WHOLEWORD;
941 if (IsDlgButtonChecked(hWnd, chx2))
942 lpfr->Flags |= FR_MATCHCASE;
943 else lpfr->Flags &= ~FR_MATCHCASE;
944 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
945 lpfr->Flags |= FR_REPLACEALL;
946 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
947 return TRUE;
948 case pshHelp:
949 /* FIXME : should lpfr structure be passed as an argument ??? */
950 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
951 return TRUE;
953 return FALSE;
957 /***********************************************************************
958 * ReplaceTextDlgProc (COMMDLG.14)
960 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
962 switch (wMsg) {
963 case WM_INITDIALOG:
964 return REPLACEDLG_WMInitDialog(hWnd, wParam, lParam);
965 case WM_COMMAND:
966 return REPLACEDLG_WMCommand(hWnd, wParam, lParam);
968 return FALSE;
972 /***********************************************************************
973 * PrintDlg (COMMDLG.20)
975 BOOL PrintDlg(LPPRINTDLG lpPrint)
977 HANDLE hInst, hDlgTmpl;
978 BOOL bRet;
980 dprintf_commdlg(stddeb,"PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
982 if (lpPrint->Flags & PD_RETURNDEFAULT)
983 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
984 return TRUE;
986 if (lpPrint->Flags & PD_PRINTSETUP)
987 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP );
988 else
989 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT );
991 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
992 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
993 (lpPrint->Flags & PD_PRINTSETUP) ?
994 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
995 MODULE_GetWndProcEntry16("PrintDlgProc"),
996 (DWORD)lpPrint );
997 SYSRES_FreeResource( hDlgTmpl );
998 return bRet;
1002 /***********************************************************************
1003 * PrintDlgProc (COMMDLG.21)
1005 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
1007 switch (wMsg)
1009 case WM_INITDIALOG:
1010 dprintf_commdlg(stddeb,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1011 ShowWindow(hWnd, SW_SHOWNORMAL);
1012 return (TRUE);
1013 case WM_COMMAND:
1014 switch (wParam)
1016 case IDOK:
1017 EndDialog(hWnd, TRUE);
1018 return(TRUE);
1019 case IDCANCEL:
1020 EndDialog(hWnd, FALSE);
1021 return(TRUE);
1023 return(FALSE);
1025 return FALSE;
1029 /***********************************************************************
1030 * PrintSetupDlgProc (COMMDLG.22)
1032 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
1034 switch (wMsg)
1036 case WM_INITDIALOG:
1037 dprintf_commdlg(stddeb,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1038 ShowWindow(hWnd, SW_SHOWNORMAL);
1039 return (TRUE);
1040 case WM_COMMAND:
1041 switch (wParam) {
1042 case IDOK:
1043 EndDialog(hWnd, TRUE);
1044 return(TRUE);
1045 case IDCANCEL:
1046 EndDialog(hWnd, FALSE);
1047 return(TRUE);
1049 return(FALSE);
1051 return FALSE;
1055 /***********************************************************************
1056 * CommDlgExtendedError (COMMDLG.26)
1058 DWORD CommDlgExtendedError(void)
1060 return CommDlgLastError;
1064 /***********************************************************************
1065 * GetFileTitle (COMMDLG.27)
1067 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
1069 int i, len;
1070 dprintf_commdlg(stddeb,"GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1071 if (lpFile == NULL || lpTitle == NULL)
1072 return -1;
1073 len = strlen(lpFile);
1074 if (len == 0)
1075 return -1;
1076 if (strpbrk(lpFile, "*[]"))
1077 return -1;
1078 len--;
1079 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1080 return -1;
1081 for (i = len; i >= 0; i--)
1082 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1084 i++;
1085 break;
1087 dprintf_commdlg(stddeb,"\n---> '%s' ", &lpFile[i]);
1089 len = strlen(lpFile+i)+1;
1090 if (cbBuf < len)
1091 return len;
1093 strncpy(lpTitle, &lpFile[i], len);
1094 return 0;
1098 /* --------------------------- Choose Color Dialog ------------------------------ */
1100 static const COLORREF predefcolors[6][8]=
1102 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1103 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1104 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1105 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1107 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1108 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1109 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1110 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1112 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1113 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1114 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1115 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1118 struct CCPRIVATE
1120 LPCHOOSECOLOR lpcc; /* points to public known data structure */
1121 int nextuserdef; /* next free place in user defined color array */
1122 HDC hdcMem; /* color graph used for BitBlt() */
1123 HBITMAP hbmMem; /* color graph bitmap */
1124 RECT16 fullsize; /* original dialog window size */
1125 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
1126 RECT16 old3angle; /* last position of l-marker */
1127 RECT16 oldcross; /* last position of color/satuation marker */
1128 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1129 int h;
1130 int s;
1131 int l; /* for temporary storing of hue,sat,lum */
1134 /***********************************************************************
1135 * CC_HSLtoRGB [internal]
1137 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1139 int res=0,maxrgb;
1141 /* hue */
1142 switch(c)
1144 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1145 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1146 case 'B':break;
1149 /* l below 120 */
1150 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1151 if (hue< 80)
1152 res=0;
1153 else
1154 if (hue< 120)
1156 res=(hue-80)* maxrgb; /* 0...10240 */
1157 res/=40; /* 0...256 */
1159 else
1160 if (hue< 200)
1161 res=maxrgb;
1162 else
1164 res=(240-hue)* maxrgb;
1165 res/=40;
1167 res=res-maxrgb/2; /* -128...128 */
1169 /* saturation */
1170 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1172 /* lum above 120 */
1173 if (lum>120 && res<256)
1174 res+=((lum-120) * (256-res))/120;
1176 return MIN(res,255);
1179 /***********************************************************************
1180 * CC_RGBtoHSL [internal]
1182 static int CC_RGBtoHSL(char c,int r,int g,int b)
1184 WORD maxi,mini,mmsum,mmdif,result=0;
1185 int iresult=0;
1187 maxi=MAX(r,b);
1188 maxi=MAX(maxi,g);
1189 mini=MIN(r,b);
1190 mini=MIN(mini,g);
1192 mmsum=maxi+mini;
1193 mmdif=maxi-mini;
1195 switch(c)
1197 /* lum */
1198 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1199 result=mmsum/255; /* 0...240 */
1200 break;
1201 /* saturation */
1202 case 'S':if (!mmsum)
1203 result=0;
1204 else
1205 if (!mini || maxi==255)
1206 result=240;
1207 else
1209 result=mmdif*240; /* 0...61200=255*240 */
1210 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1212 break;
1213 /* hue */
1214 case 'H':if (!mmdif)
1215 result=160;
1216 else
1218 if (maxi==r)
1220 iresult=40*(g-b); /* -10200 ... 10200 */
1221 iresult/=(int)mmdif; /* -40 .. 40 */
1222 if (iresult<0)
1223 iresult+=240; /* 0..40 and 200..240 */
1225 else
1226 if (maxi==g)
1228 iresult=40*(b-r);
1229 iresult/=(int)mmdif;
1230 iresult+=80; /* 40 .. 120 */
1232 else
1233 if (maxi==b)
1235 iresult=40*(r-g);
1236 iresult/=(int)mmdif;
1237 iresult+=160; /* 120 .. 200 */
1239 result=iresult;
1241 break;
1243 return result; /* is this integer arithmetic precise enough ? */
1246 #define DISTANCE 4
1248 /***********************************************************************
1249 * CC_MouseCheckPredefColorArray [internal]
1251 static int CC_MouseCheckPredefColorArray(HWND hDlg,int dlgitem,int rows,int cols,
1252 LPARAM lParam,COLORREF *cr)
1254 HWND hwnd;
1255 POINT16 point = MAKEPOINT16(lParam);
1256 RECT16 rect;
1257 int dx,dy,x,y;
1259 ClientToScreen16(hDlg,&point);
1260 hwnd=GetDlgItem(hDlg,dlgitem);
1261 GetWindowRect16(hwnd,&rect);
1262 if (PtInRect16(&rect,point))
1264 dx=(rect.right-rect.left)/cols;
1265 dy=(rect.bottom-rect.top)/rows;
1266 ScreenToClient16(hwnd,&point);
1268 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1270 x=point.x/dx;
1271 y=point.y/dy;
1272 *cr=predefcolors[y][x];
1273 /* FIXME: Draw_a_Focus_Rect() */
1274 return 1;
1277 return 0;
1280 /***********************************************************************
1281 * CC_MouseCheckUserColorArray [internal]
1283 static int CC_MouseCheckUserColorArray(HWND hDlg,int dlgitem,int rows,int cols,
1284 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1286 HWND hwnd;
1287 POINT16 point = MAKEPOINT16(lParam);
1288 RECT16 rect;
1289 int dx,dy,x,y;
1291 ClientToScreen16(hDlg,&point);
1292 hwnd=GetDlgItem(hDlg,dlgitem);
1293 GetWindowRect16(hwnd,&rect);
1294 if (PtInRect16(&rect,point))
1296 dx=(rect.right-rect.left)/cols;
1297 dy=(rect.bottom-rect.top)/rows;
1298 ScreenToClient16(hwnd,&point);
1300 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1302 x=point.x/dx;
1303 y=point.y/dy;
1304 *cr=crarr[x+cols*y];
1305 /* FIXME: Draw_a_Focus_Rect() */
1306 return 1;
1309 return 0;
1312 #define MAXVERT 240
1313 #define MAXHORI 239
1315 /* 240 ^...... ^^ 240
1316 | . ||
1317 SAT | . || LUM
1318 | . ||
1319 +-----> 239 ----
1322 /***********************************************************************
1323 * CC_MouseCheckColorGraph [internal]
1325 static int CC_MouseCheckColorGraph(HWND hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1327 HWND hwnd;
1328 POINT16 point = MAKEPOINT16(lParam);
1329 RECT16 rect;
1330 long x,y;
1332 ClientToScreen16(hDlg,&point);
1333 hwnd=GetDlgItem(hDlg,dlgitem);
1334 GetWindowRect16(hwnd,&rect);
1335 if (PtInRect16(&rect,point))
1337 GetClientRect16(hwnd,&rect);
1338 ScreenToClient16(hwnd,&point);
1340 x=(long)point.x*MAXHORI;
1341 x/=rect.right;
1342 y=(long)(rect.bottom-point.y)*MAXVERT;
1343 y/=rect.bottom;
1345 if (hori)
1346 *hori=x;
1347 if (vert)
1348 *vert=y;
1349 return 1;
1351 else
1352 return 0;
1354 /***********************************************************************
1355 * CC_MouseCheckResultWindow [internal]
1357 static int CC_MouseCheckResultWindow(HWND hDlg,LPARAM lParam)
1359 HWND hwnd;
1360 POINT16 point = MAKEPOINT16(lParam);
1361 RECT16 rect;
1363 ClientToScreen16(hDlg,&point);
1364 hwnd=GetDlgItem(hDlg,0x2c5);
1365 GetWindowRect16(hwnd,&rect);
1366 if (PtInRect16(&rect,point))
1368 PostMessage(hDlg,WM_COMMAND,0x2c9,0);
1369 return 1;
1371 return 0;
1374 /***********************************************************************
1375 * CC_CheckDigitsInEdit [internal]
1377 static int CC_CheckDigitsInEdit(HWND hwnd,int maxval)
1379 int i,k,m,result,value;
1380 long editpos;
1381 char buffer[30];
1382 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1383 m=lstrlen(buffer);
1384 result=0;
1386 for (i=0;i<m;i++)
1387 if (buffer[i]<'0' || buffer[i]>'9')
1389 for (k=i+1;k<=m;k++) /* delete bad character */
1391 buffer[i]=buffer[k];
1392 m--;
1394 buffer[m]=0;
1395 result=1;
1398 value=atoi(buffer);
1399 if (value>maxval) /* build a new string */
1401 sprintf(buffer,"%d",maxval);
1402 result=2;
1404 if (result)
1406 editpos=SendMessage16(hwnd,EM_GETSEL,0,0);
1407 SetWindowText32A(hwnd,buffer);
1408 SendMessage16(hwnd,EM_SETSEL,0,editpos);
1410 return value;
1415 /***********************************************************************
1416 * CC_PaintSelectedColor [internal]
1418 static void CC_PaintSelectedColor(HWND hDlg,COLORREF cr)
1420 RECT16 rect;
1421 HDC hdc;
1422 HBRUSH hBrush;
1423 HWND hwnd=GetDlgItem(hDlg,0x2c5);
1424 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1426 hdc=GetDC(hwnd);
1427 GetClientRect16 (hwnd, &rect) ;
1428 hBrush = CreateSolidBrush(cr);
1429 if (hBrush)
1431 hBrush = SelectObject (hdc, hBrush) ;
1432 Rectangle (hdc, rect.left,rect.top,rect.right/2,rect.bottom);
1433 DeleteObject (SelectObject (hdc,hBrush)) ;
1434 hBrush=CreateSolidBrush(GetNearestColor(hdc,cr));
1435 if (hBrush)
1437 hBrush= SelectObject (hdc, hBrush) ;
1438 Rectangle (hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
1439 DeleteObject (SelectObject (hdc, hBrush)) ;
1442 ReleaseDC(hwnd,hdc);
1446 /***********************************************************************
1447 * CC_PaintTriangle [internal]
1449 static void CC_PaintTriangle(HWND hDlg,int y)
1451 HDC hDC;
1452 long temp;
1453 int w=GetDialogBaseUnits();
1454 POINT16 points[3];
1455 int height;
1456 int oben;
1457 RECT16 rect;
1458 HWND hwnd=GetDlgItem(hDlg,0x2be);
1459 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1461 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1463 GetClientRect16(hwnd,&rect);
1464 height=rect.bottom;
1465 hDC=GetDC(hDlg);
1467 points[0].y=rect.top;
1468 points[0].x=rect.right; /* | /| */
1469 ClientToScreen16(hwnd,points); /* | / | */
1470 ScreenToClient16(hDlg,points); /* |< | */
1471 oben=points[0].y; /* | \ | */
1472 /* | \| */
1473 temp=(long)height*(long)y;
1474 points[0].y=oben+height -temp/(long)MAXVERT;
1475 points[1].y=points[0].y+w;
1476 points[2].y=points[0].y-w;
1477 points[2].x=points[1].x=points[0].x + w;
1479 if (lpp->old3angle.left)
1480 FillRect16(hDC,&lpp->old3angle,GetStockObject(WHITE_BRUSH));
1481 lpp->old3angle.left =points[0].x;
1482 lpp->old3angle.right =points[1].x+1;
1483 lpp->old3angle.top =points[2].y-1;
1484 lpp->old3angle.bottom=points[1].y+1;
1485 Polygon16(hDC,points,3);
1486 ReleaseDC(hDlg,hDC);
1491 /***********************************************************************
1492 * CC_PaintCross [internal]
1494 static void CC_PaintCross(HWND hDlg,int x,int y)
1496 HDC hDC;
1497 int w=GetDialogBaseUnits();
1498 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1499 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1500 RECT16 rect;
1501 POINT16 point;
1502 HPEN16 hPen;
1504 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1506 GetClientRect16(hwnd,&rect);
1507 hDC=GetDC(hwnd);
1508 SelectClipRgn(hDC,CreateRectRgnIndirect16(&rect));
1509 hPen=CreatePen(PS_SOLID,2,0);
1510 hPen=SelectObject(hDC,hPen);
1511 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
1512 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
1513 if (lpp->oldcross.left!=lpp->oldcross.right)
1514 BitBlt(hDC,lpp->oldcross.left,lpp->oldcross.top,
1515 lpp->oldcross.right-lpp->oldcross.left,
1516 lpp->oldcross.bottom-lpp->oldcross.top,
1517 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
1518 lpp->oldcross.left =point.x-w-1;
1519 lpp->oldcross.right =point.x+w+1;
1520 lpp->oldcross.top =point.y-w-1;
1521 lpp->oldcross.bottom=point.y+w+1;
1523 MoveTo(hDC,point.x-w,point.y);
1524 LineTo(hDC,point.x+w,point.y);
1525 MoveTo(hDC,point.x,point.y-w);
1526 LineTo(hDC,point.x,point.y+w);
1527 DeleteObject(SelectObject(hDC,hPen));
1528 ReleaseDC(hwnd,hDC);
1533 #define XSTEPS 48
1534 #define YSTEPS 24
1537 /***********************************************************************
1538 * CC_PrepareColorGraph [internal]
1540 static void CC_PrepareColorGraph(HWND hDlg)
1542 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
1543 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1544 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1545 HBRUSH hbrush;
1546 HDC hdc ;
1547 RECT16 rect,client;
1548 HCURSOR hcursor=SetCursor(LoadCursor(0,IDC_WAIT));
1550 GetClientRect16(hwnd,&client);
1551 hdc=GetDC(hwnd);
1552 lpp->hdcMem = CreateCompatibleDC(hdc);
1553 lpp->hbmMem = CreateCompatibleBitmap(hdc,client.right,client.bottom);
1554 SelectObject(lpp->hdcMem,lpp->hbmMem);
1556 xdif=client.right /XSTEPS;
1557 ydif=client.bottom/YSTEPS+1;
1558 hdif=239/XSTEPS;
1559 sdif=240/YSTEPS;
1560 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
1562 rect.right=rect.left+xdif;
1563 rect.bottom=client.bottom;
1564 for(sat=0;sat<240+sdif;sat+=sdif)
1566 rect.top=rect.bottom-ydif;
1567 r=CC_HSLtoRGB('R',hue,sat,120);
1568 g=CC_HSLtoRGB('G',hue,sat,120);
1569 b=CC_HSLtoRGB('B',hue,sat,120);
1570 hbrush=CreateSolidBrush(RGB(r,g,b));
1571 FillRect16(lpp->hdcMem,&rect,hbrush);
1572 DeleteObject(hbrush);
1573 rect.bottom=rect.top;
1575 rect.left=rect.right;
1577 ReleaseDC(hwnd,hdc);
1578 SetCursor(hcursor);
1581 /***********************************************************************
1582 * CC_PaintColorGraph [internal]
1584 static void CC_PaintColorGraph(HWND hDlg)
1586 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1587 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1588 HDC hDC;
1589 RECT16 rect;
1590 if (IsWindowVisible(hwnd)) /* if full size */
1592 if (!lpp->hdcMem)
1593 CC_PrepareColorGraph(hDlg); /* should not be necessary */
1595 hDC=GetDC(hwnd);
1596 GetClientRect16(hwnd,&rect);
1597 if (lpp->hdcMem)
1598 BitBlt(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
1599 else
1600 fprintf(stderr,"choose color: hdcMem is not defined\n");
1601 ReleaseDC(hwnd,hDC);
1604 /***********************************************************************
1605 * CC_PaintLumBar [internal]
1607 static void CC_PaintLumBar(HWND hDlg,int hue,int sat)
1609 HWND hwnd=GetDlgItem(hDlg,0x2be);
1610 RECT16 rect,client;
1611 int lum,ldif,ydif,r,g,b;
1612 HBRUSH hbrush;
1613 HDC hDC;
1615 if (IsWindowVisible(hwnd))
1617 hDC=GetDC(hwnd);
1618 GetClientRect16(hwnd,&client);
1619 rect=client;
1621 ldif=240/YSTEPS;
1622 ydif=client.bottom/YSTEPS+1;
1623 for(lum=0;lum<240+ldif;lum+=ldif)
1625 rect.top=MAX(0,rect.bottom-ydif);
1626 r=CC_HSLtoRGB('R',hue,sat,lum);
1627 g=CC_HSLtoRGB('G',hue,sat,lum);
1628 b=CC_HSLtoRGB('B',hue,sat,lum);
1629 hbrush=CreateSolidBrush(RGB(r,g,b));
1630 FillRect16(hDC,&rect,hbrush);
1631 DeleteObject(hbrush);
1632 rect.bottom=rect.top;
1634 GetClientRect16(hwnd,&rect);
1635 FrameRect16(hDC,&rect,GetStockObject(BLACK_BRUSH));
1636 ReleaseDC(hwnd,hDC);
1640 /***********************************************************************
1641 * CC_EditSetRGB [internal]
1643 static void CC_EditSetRGB(HWND hDlg,COLORREF cr)
1645 char buffer[10];
1646 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1647 int r=GetRValue(cr);
1648 int g=GetGValue(cr);
1649 int b=GetBValue(cr);
1650 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1652 lpp->updating=TRUE;
1653 sprintf(buffer,"%d",r);
1654 SetWindowText32A(GetDlgItem(hDlg,0x2c2),buffer);
1655 sprintf(buffer,"%d",g);
1656 SetWindowText32A(GetDlgItem(hDlg,0x2c3),buffer);
1657 sprintf(buffer,"%d",b);
1658 SetWindowText32A(GetDlgItem(hDlg,0x2c4),buffer);
1659 lpp->updating=FALSE;
1663 /***********************************************************************
1664 * CC_EditSetHSL [internal]
1666 static void CC_EditSetHSL(HWND hDlg,int h,int s,int l)
1668 char buffer[10];
1669 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1670 lpp->updating=TRUE;
1671 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1673 lpp->updating=TRUE;
1674 sprintf(buffer,"%d",h);
1675 SetWindowText32A(GetDlgItem(hDlg,0x2bf),buffer);
1676 sprintf(buffer,"%d",s);
1677 SetWindowText32A(GetDlgItem(hDlg,0x2c0),buffer);
1678 sprintf(buffer,"%d",l);
1679 SetWindowText32A(GetDlgItem(hDlg,0x2c1),buffer);
1680 lpp->updating=FALSE;
1682 CC_PaintLumBar(hDlg,h,s);
1685 /***********************************************************************
1686 * CC_SwitchToFullSize [internal]
1688 static void CC_SwitchToFullSize(HWND hDlg,COLORREF result,LPRECT16 lprect)
1690 int i;
1691 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1693 EnableWindow(GetDlgItem(hDlg,0x2cf),FALSE);
1694 CC_PrepareColorGraph(hDlg);
1695 for (i=0x2bf;i<0x2c5;i++)
1696 EnableWindow(GetDlgItem(hDlg,i),TRUE);
1697 for (i=0x2d3;i<0x2d9;i++)
1698 EnableWindow(GetDlgItem(hDlg,i),TRUE);
1699 EnableWindow(GetDlgItem(hDlg,0x2c9),TRUE);
1700 EnableWindow(GetDlgItem(hDlg,0x2c8),TRUE);
1702 if (lprect)
1703 SetWindowPos(hDlg,NULL,0,0,lprect->right-lprect->left,
1704 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
1706 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_SHOW);
1707 ShowWindow(GetDlgItem(hDlg,0x2be),SW_SHOW);
1708 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_SHOW);
1710 CC_EditSetRGB(hDlg,result);
1711 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1714 /***********************************************************************
1715 * CC_PaintPredefColorArray [internal]
1717 static void CC_PaintPredefColorArray(HWND hDlg,int rows,int cols)
1719 HWND hwnd=GetDlgItem(hDlg,0x2d0);
1720 RECT16 rect;
1721 HDC hdc;
1722 HBRUSH hBrush;
1723 int dx,dy,i,j,k;
1725 GetClientRect16(hwnd,&rect);
1726 dx=rect.right/cols;
1727 dy=rect.bottom/rows;
1728 k=rect.left;
1730 hdc=GetDC(hwnd);
1731 GetClientRect16 (hwnd, &rect) ;
1733 for (j=0;j<rows;j++)
1735 for (i=0;i<cols;i++)
1737 hBrush = CreateSolidBrush(predefcolors[j][i]);
1738 if (hBrush)
1740 hBrush = SelectObject (hdc, hBrush) ;
1741 Rectangle (hdc, rect.left, rect.top,
1742 rect.left+dx-DISTANCE,rect.top+dy-DISTANCE);
1743 rect.left=rect.left+dx;
1744 DeleteObject (SelectObject (hdc, hBrush)) ;
1747 rect.top=rect.top+dy;
1748 rect.left=k;
1750 ReleaseDC(hwnd,hdc);
1751 /* FIXME: draw_a_focus_rect */
1753 /***********************************************************************
1754 * CC_PaintUserColorArray [internal]
1756 static void CC_PaintUserColorArray(HWND hDlg,int rows,int cols,COLORREF* lpcr)
1758 HWND hwnd=GetDlgItem(hDlg,0x2d1);
1759 RECT16 rect;
1760 HDC hdc;
1761 HBRUSH hBrush;
1762 int dx,dy,i,j,k;
1764 GetClientRect16(hwnd,&rect);
1766 dx=rect.right/cols;
1767 dy=rect.bottom/rows;
1768 k=rect.left;
1770 hdc=GetDC(hwnd);
1771 if (hdc)
1773 for (j=0;j<rows;j++)
1775 for (i=0;i<cols;i++)
1777 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
1778 if (hBrush)
1780 hBrush = SelectObject (hdc, hBrush) ;
1781 Rectangle (hdc, rect.left, rect.top,
1782 rect.left+dx-DISTANCE,rect.top+dy-DISTANCE);
1783 rect.left=rect.left+dx;
1784 DeleteObject (SelectObject (hdc, hBrush)) ;
1787 rect.top=rect.top+dy;
1788 rect.left=k;
1790 ReleaseDC(hwnd,hdc);
1792 /* FIXME: draw_a_focus_rect */
1797 /***********************************************************************
1798 * CC_HookCallChk [internal]
1800 static BOOL CC_HookCallChk(LPCHOOSECOLOR lpcc)
1802 if (lpcc)
1803 if(lpcc->Flags & CC_ENABLEHOOK)
1804 if (lpcc->lpfnHook)
1805 return TRUE;
1806 return FALSE;
1809 /***********************************************************************
1810 * CC_WMInitDialog [internal]
1812 static LONG CC_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam)
1814 int i,res;
1815 HWND hwnd;
1816 RECT16 rect;
1817 POINT16 point;
1818 struct CCPRIVATE * lpp;
1820 dprintf_commdlg(stddeb,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1821 lpp=calloc(1,sizeof(struct CCPRIVATE));
1822 lpp->lpcc=(LPCHOOSECOLOR)lParam;
1823 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR))
1825 EndDialog (hDlg, 0) ;
1826 return FALSE;
1828 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
1830 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
1831 ShowWindow(GetDlgItem(hDlg,0x40e),SW_HIDE);
1832 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
1833 #if 0
1834 cpos=MAKELONG(5,7); /* init */
1835 if (lpp->lpcc->Flags & CC_RGBINIT)
1837 for (i=0;i<6;i++)
1838 for (j=0;j<8;j++)
1839 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
1841 cpos=MAKELONG(i,j);
1842 goto found;
1845 found:
1846 /* FIXME: Draw_a_focus_rect & set_init_values */
1847 #endif
1848 GetWindowRect16(hDlg,&lpp->fullsize);
1849 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1851 hwnd=GetDlgItem(hDlg,0x2cf);
1852 EnableWindow(hwnd,FALSE);
1854 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1856 rect=lpp->fullsize;
1857 res=rect.bottom-rect.top;
1858 hwnd=GetDlgItem(hDlg,0x2c6); /* cut at left border */
1859 point.x=point.y=0;
1860 ClientToScreen16(hwnd,&point);
1861 ScreenToClient16(hDlg,&point);
1862 GetClientRect16(hDlg,&rect);
1863 point.x+=GetSystemMetrics(SM_CXDLGFRAME);
1864 SetWindowPos(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
1866 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_HIDE);
1867 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_HIDE);
1869 else
1870 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
1871 res=TRUE;
1872 for (i=0x2bf;i<0x2c5;i++)
1873 SendMessage16(GetDlgItem(hDlg,i),EM_LIMITTEXT,3,0); /* max 3 digits: xyz */
1874 if (CC_HookCallChk(lpp->lpcc))
1875 res=CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1876 return res;
1879 /***********************************************************************
1880 * CC_WMCommand [internal]
1882 static LRESULT CC_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
1884 int r,g,b,i,xx;
1885 UINT cokmsg;
1886 HDC hdc;
1887 COLORREF *cr;
1888 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1889 dprintf_commdlg(stddeb,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
1890 switch (wParam)
1892 case 0x2c2: /* edit notify RGB */
1893 case 0x2c3:
1894 case 0x2c4:
1895 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1897 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
1898 r=GetRValue(lpp->lpcc->rgbResult);
1899 g=GetGValue(lpp->lpcc->rgbResult);
1900 b=GetBValue(lpp->lpcc->rgbResult);
1901 xx=0;
1902 switch (wParam)
1904 case 0x2c2:if ((xx=(i!=r))) r=i;break;
1905 case 0x2c3:if ((xx=(i!=g))) g=i;break;
1906 case 0x2c4:if ((xx=(i!=b))) b=i;break;
1908 if (xx) /* something has changed */
1910 lpp->lpcc->rgbResult=RGB(r,g,b);
1911 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1912 lpp->h=CC_RGBtoHSL('H',r,g,b);
1913 lpp->s=CC_RGBtoHSL('S',r,g,b);
1914 lpp->l=CC_RGBtoHSL('L',r,g,b);
1915 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1916 CC_PaintCross(hDlg,lpp->h,lpp->s);
1917 CC_PaintTriangle(hDlg,lpp->l);
1920 break;
1922 case 0x2bf: /* edit notify HSL */
1923 case 0x2c0:
1924 case 0x2c1:
1925 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1927 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
1928 xx=0;
1929 switch (wParam)
1931 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
1932 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
1933 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
1935 if (xx) /* something has changed */
1937 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
1938 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
1939 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
1940 lpp->lpcc->rgbResult=RGB(r,g,b);
1941 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1942 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
1943 CC_PaintCross(hDlg,lpp->h,lpp->s);
1944 CC_PaintTriangle(hDlg,lpp->l);
1947 break;
1949 case 0x2cf:
1950 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
1951 InvalidateRect32( hDlg, NULL, TRUE );
1952 SetFocus(GetDlgItem(hDlg,0x2bf));
1953 break;
1955 case 0x2c8: /* add colors ... column by column */
1956 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
1957 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
1958 if (++lpp->nextuserdef==16)
1959 lpp->nextuserdef=0;
1960 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
1961 break;
1963 case 0x2c9: /* resulting color */
1964 hdc=GetDC(hDlg);
1965 lpp->lpcc->rgbResult=GetNearestColor(hdc,lpp->lpcc->rgbResult);
1966 ReleaseDC(hDlg,hdc);
1967 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
1968 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1969 r=GetRValue(lpp->lpcc->rgbResult);
1970 g=GetGValue(lpp->lpcc->rgbResult);
1971 b=GetBValue(lpp->lpcc->rgbResult);
1972 lpp->h=CC_RGBtoHSL('H',r,g,b);
1973 lpp->s=CC_RGBtoHSL('S',r,g,b);
1974 lpp->l=CC_RGBtoHSL('L',r,g,b);
1975 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1976 CC_PaintCross(hDlg,lpp->h,lpp->s);
1977 CC_PaintTriangle(hDlg,lpp->l);
1978 break;
1980 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1981 i=RegisterWindowMessage32A( HELPMSGSTRING );
1982 if (lpp->lpcc->hwndOwner)
1983 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
1984 if (CC_HookCallChk(lpp->lpcc))
1985 CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,
1986 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
1987 break;
1989 case IDOK :
1990 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
1991 if (lpp->lpcc->hwndOwner)
1992 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
1993 break; /* do NOT close */
1995 EndDialog (hDlg, 1) ;
1996 return TRUE ;
1998 case IDCANCEL :
1999 EndDialog (hDlg, 0) ;
2000 return TRUE ;
2003 return FALSE;
2006 /***********************************************************************
2007 * CC_WMPaint [internal]
2009 static LRESULT CC_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam)
2011 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
2012 /* we have to paint dialog children except text and buttons */
2014 CC_PaintPredefColorArray(hDlg,6,8);
2015 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2016 CC_PaintColorGraph(hDlg);
2017 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2018 CC_PaintCross(hDlg,lpp->h,lpp->s);
2019 CC_PaintTriangle(hDlg,lpp->l);
2020 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2022 /* special necessary for Wine */
2023 ValidateRect32(GetDlgItem(hDlg,0x2d0),NULL);
2024 ValidateRect32(GetDlgItem(hDlg,0x2d1),NULL);
2025 ValidateRect32(GetDlgItem(hDlg,0x2c6),NULL);
2026 ValidateRect32(GetDlgItem(hDlg,0x2be),NULL);
2027 ValidateRect32(GetDlgItem(hDlg,0x2c5),NULL);
2028 /* hope we can remove it later -->FIXME */
2029 return 0;
2033 /***********************************************************************
2034 * CC_WMLButtonDown [internal]
2036 static LRESULT CC_WMLButtonDown(HWND hDlg, WPARAM wParam, LPARAM lParam)
2038 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
2039 int r,g,b,i;
2040 i=0;
2041 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2042 i=1;
2043 else
2044 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2045 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2046 i=1;
2047 else
2048 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2049 i=2;
2050 else
2051 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2052 i=2;
2053 if (i==2)
2055 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2056 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2057 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2058 lpp->lpcc->rgbResult=RGB(r,g,b);
2060 if (i==1)
2062 r=GetRValue(lpp->lpcc->rgbResult);
2063 g=GetGValue(lpp->lpcc->rgbResult);
2064 b=GetBValue(lpp->lpcc->rgbResult);
2065 lpp->h=CC_RGBtoHSL('H',r,g,b);
2066 lpp->s=CC_RGBtoHSL('S',r,g,b);
2067 lpp->l=CC_RGBtoHSL('L',r,g,b);
2069 if (i)
2071 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2072 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2073 CC_PaintCross(hDlg,lpp->h,lpp->s);
2074 CC_PaintTriangle(hDlg,lpp->l);
2075 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2076 return TRUE;
2078 return FALSE;
2081 /***********************************************************************
2082 * ColorDlgProc (COMMDLG.8)
2084 LRESULT ColorDlgProc(HWND hDlg, UINT message,
2085 UINT wParam, LONG lParam)
2087 int res;
2088 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
2089 if (message!=WM_INITDIALOG)
2091 if (!lpp)
2092 return FALSE;
2093 res=0;
2094 if (CC_HookCallChk(lpp->lpcc))
2095 res=CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2096 if (res)
2097 return res;
2100 /* FIXME: SetRGB message
2101 if (message && message==msetrgb)
2102 return HandleSetRGB(hDlg,lParam);
2105 switch (message)
2107 case WM_INITDIALOG:
2108 return CC_WMInitDialog(hDlg,wParam,lParam);
2109 case WM_NCDESTROY:
2110 DeleteDC(lpp->hdcMem);
2111 DeleteObject(lpp->hbmMem);
2112 free(lpp);
2113 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2114 break;
2115 case WM_COMMAND:
2116 if (CC_WMCommand(hDlg, wParam, lParam))
2117 return TRUE;
2118 break;
2119 case WM_PAINT:
2120 CC_WMPaint(hDlg, wParam, lParam);
2121 break;
2122 case WM_LBUTTONDBLCLK:
2123 if (CC_MouseCheckResultWindow(hDlg,lParam))
2124 return TRUE;
2125 break;
2126 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2127 break;
2128 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2129 break;
2130 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2131 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2132 return TRUE;
2133 break;
2135 return FALSE ;
2140 /***********************************************************************
2141 * ChooseFont (COMMDLG.15)
2143 BOOL ChooseFont(LPCHOOSEFONT lpChFont)
2145 HANDLE hInst, hDlgTmpl;
2146 BOOL bRet;
2147 dprintf_commdlg(stddeb,"ChoseFont\n");
2148 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_FONT );
2149 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2150 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChFont->hwndOwner,
2151 MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2152 (DWORD)lpChFont );
2153 SYSRES_FreeResource( hDlgTmpl );
2154 return bRet;
2158 #define TEXT_EXTRAS 4
2159 #define TEXT_COLORS 16
2161 static const COLORREF textcolors[TEXT_COLORS]=
2163 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2164 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2165 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2166 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2169 /***********************************************************************
2170 * CFn_HookCallChk [internal]
2172 static BOOL CFn_HookCallChk(LPCHOOSEFONT lpcf)
2174 if (lpcf)
2175 if(lpcf->Flags & CF_ENABLEHOOK)
2176 if (lpcf->lpfnHook)
2177 return TRUE;
2178 return FALSE;
2181 /***********************************************************************
2182 * FontFamilyEnumProc (COMMDLG.19)
2184 int FontFamilyEnumProc(LPLOGFONT lplf ,LPTEXTMETRIC lptm, int nFontType, LPARAM lParam)
2186 int i;
2187 WORD w;
2188 HWND hwnd=LOWORD(lParam);
2190 dprintf_commdlg(stddeb,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2191 lplf->lfFaceName,nFontType);
2192 i=SendMessage16(hwnd,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(lplf->lfFaceName));
2193 if (i!=CB_ERR)
2195 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2196 SendMessage16(hwnd, CB_SETITEMDATA,i,MAKELONG(nFontType,w));
2197 return 1 ;
2199 else
2200 return 0;
2203 /***********************************************************************
2204 * FontStyleEnumProc (COMMDLG.18)
2206 int FontStyleEnumProc(LPLOGFONT lplf ,LPTEXTMETRIC lptm, int nFontType, LPARAM lParam)
2208 int j;
2209 char buffer[20];
2210 /* HWND hcmb2=LOWORD(lParam);*/
2211 HWND hcmb3=HIWORD(lParam);
2212 LPLOGFONT lf=lplf;
2214 dprintf_commdlg(stddeb,"FontStyleEnumProc: (nFontType=%d)\n",nFontType);
2215 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",
2216 lf->lfFaceName,lf->lfHeight,lf->lfWidth,lf->lfEscapement,lf->lfOrientation,
2217 lf->lfWeight,lf->lfItalic,lf->lfUnderline,lf->lfStrikeOut,lf->lfCharSet,
2218 lf->lfOutPrecision,lf->lfClipPrecision,lf->lfQuality,lf->lfPitchAndFamily);
2220 #if 1 /* VERSION A: use some predefined height values */
2221 /* FIXME: if (!(nFontType & RASTER_FONTTYPE))......... */
2223 int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2224 int i;
2225 if (!SendMessage16(hcmb3,CB_GETCOUNT,0,0))
2227 i=0;
2228 while (sizes[i])
2230 sprintf(buffer,"%d",sizes[i]);
2231 j=SendMessage16(hcmb3,CB_INSERTSTRING,-1,(LPARAM)MAKE_SEGPTR(buffer));
2232 SendMessage16(hcmb3, CB_SETITEMDATA, j, MAKELONG(sizes[i],0));
2233 i++;
2237 return 0;
2238 #endif
2240 #if 0 /* VERSION B: use only lplf->lfHeight values */
2242 if (lplf->lfHeight)
2244 sprintf(buffer,"%3d",lplf->lfHeight);
2245 j=SendMessage16(hcmb3,CB_FINDSTRING,-1,(LPARAM)MAKE_SEGPTR(buffer));
2246 if (j==CB_ERR)
2248 j=SendMessage16(hcmb3,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2249 SendMessage16(hcmb3, CB_SETITEMDATA, j, MAKELONG(lplf->lfHeight,lplf->lfWidth));
2253 return 1 ;
2254 #endif
2259 /***********************************************************************
2260 * CFn_WMInitDialog [internal]
2262 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam)
2264 HDC hdc;
2265 int i,j,res,init=0;
2266 long l;
2267 char buffer[32];
2268 FARPROC enumCallback = MODULE_GetWndProcEntry16("FontFamilyEnumProc");
2269 LPLOGFONT lpxx;
2270 HCURSOR hcursor=SetCursor(LoadCursor(0,IDC_WAIT));
2271 LPCHOOSEFONT lpcf;
2273 SetWindowLong32A(hDlg, DWL_USER, lParam);
2274 lpcf=(LPCHOOSEFONT)lParam;
2275 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2276 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
2278 if (lpcf->lStructSize != sizeof(CHOOSEFONT))
2280 dprintf_commdlg(stddeb,"WM_INITDIALOG: structure size failure !!!\n");
2281 EndDialog (hDlg, 0);
2282 return FALSE;
2284 if (!hBitmapTT)
2285 hBitmapTT = LoadBitmap(0, MAKEINTRESOURCE(OBM_TRTYPE));
2287 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
2288 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
2289 if (!(lpcf->Flags & CF_APPLY))
2290 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
2291 if (lpcf->Flags & CF_EFFECTS)
2293 for (res=1,i=0;res && i<TEXT_COLORS;i++)
2295 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2296 j=SendDlgItemMessage16(hDlg,cmb4,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR("[color name]"));
2297 SendDlgItemMessage16(hDlg,cmb4, CB_SETITEMDATA,j,textcolors[j]);
2298 /* look for a fitting value in color combobox */
2299 if (textcolors[j]==lpcf->rgbColors)
2300 SendDlgItemMessage16(hDlg,cmb4, CB_SETCURSEL,j,0);
2303 else
2305 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
2306 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
2307 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
2308 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
2309 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
2312 /* perhaps this stuff should be moved to FontStyleEnumProc() ?? */
2313 strcpy(buffer,"Regular"); /* LoadString(hInst,.... ,buffer,LF_FACESIZE);*/
2314 j=SendDlgItemMessage16(hDlg,cmb2,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2315 SendDlgItemMessage16(hDlg,cmb2, CB_SETITEMDATA, j, MAKELONG(FW_NORMAL,0));
2316 strcpy(buffer,"Bold"); /* LoadString(hInst,.... ,buffer,LF_FACESIZE);*/
2317 j=SendDlgItemMessage16(hDlg,cmb2,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2318 SendDlgItemMessage16(hDlg,cmb2, CB_SETITEMDATA, j, MAKELONG(FW_BOLD,0));
2319 strcpy(buffer,"Italic"); /* LoadString(hInst,.... ,buffer,LF_FACESIZE);*/
2320 j=SendDlgItemMessage16(hDlg,cmb2,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2321 SendDlgItemMessage16(hDlg,cmb2, CB_SETITEMDATA, j, MAKELONG(FW_NORMAL,1));
2322 strcpy(buffer,"Bold Italic"); /* LoadString(hInst,.... ,buffer,LF_FACESIZE);*/
2323 j=SendDlgItemMessage16(hDlg,cmb2,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2324 SendDlgItemMessage16(hDlg,cmb2, CB_SETITEMDATA, j, MAKELONG(FW_BOLD,1));
2326 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
2327 if (hdc)
2329 if (!EnumFontFamilies (hdc, NULL,enumCallback,(LPARAM)GetDlgItem(hDlg,cmb1)))
2330 dprintf_commdlg(stddeb,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2331 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
2333 /* look for fitting font name in combobox1 */
2334 j=SendDlgItemMessage16(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
2335 if (j!=CB_ERR)
2337 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL,j,0);
2338 SendMessage16(hDlg,WM_COMMAND,cmb1,MAKELONG(GetDlgItem(hDlg,cmb1),CBN_SELCHANGE));
2339 init=1;
2340 /* look for fitting font style in combobox2 */
2341 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
2342 for (i=0;i<TEXT_EXTRAS;i++)
2344 if (l==SendDlgItemMessage16(hDlg,cmb2, CB_GETITEMDATA,i,0))
2345 SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL,i,0);
2348 /* look for fitting font size in combobox3 */
2349 j=SendDlgItemMessage16(hDlg,cmb3,CB_GETCOUNT,0,0);
2350 for (i=0;i<j;i++)
2352 if (lpxx->lfHeight==(int)SendDlgItemMessage16(hDlg,cmb3, CB_GETITEMDATA,i,0))
2353 SendDlgItemMessage16(hDlg,cmb3,CB_SETCURSEL,i,0);
2356 if (!init)
2358 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL,0,0);
2359 SendMessage16(hDlg,WM_COMMAND,cmb1,MAKELONG(GetDlgItem(hDlg,cmb1),CBN_SELCHANGE));
2362 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
2364 j=SendDlgItemMessage16(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
2365 if (j!=CB_ERR)
2367 j=SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL,j,0);
2368 SendMessage16(hDlg,WM_COMMAND,cmb2,MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
2372 else
2374 dprintf_commdlg(stddeb,"WM_INITDIALOG: HDC failure !!!\n");
2375 EndDialog (hDlg, 0);
2376 return FALSE;
2379 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2380 ReleaseDC(hDlg,hdc);
2381 res=TRUE;
2382 if (CFn_HookCallChk(lpcf))
2383 res=CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2384 SetCursor(hcursor);
2385 return res;
2389 /***********************************************************************
2390 * CFn_WMMeasureItem [internal]
2392 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
2394 BITMAP bm;
2395 LPMEASUREITEMSTRUCT lpmi=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT)lParam);
2396 if (!hBitmapTT)
2397 hBitmapTT = LoadBitmap(0, MAKEINTRESOURCE(OBM_TRTYPE));
2398 GetObject(hBitmapTT, sizeof(BITMAP), (LPSTR)&bm);
2399 lpmi->itemHeight=bm.bmHeight;
2400 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2401 return 0;
2405 /***********************************************************************
2406 * CFn_WMDrawItem [internal]
2408 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
2410 HBRUSH hBrush;
2411 char buffer[40];
2412 BITMAP bm;
2413 COLORREF cr;
2414 RECT16 rect;
2415 #if 0
2416 HDC hMemDC;
2417 int nFontType;
2418 HBITMAP hBitmap; /* for later TT usage */
2419 #endif
2420 LPDRAWITEMSTRUCT16 lpdi = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
2422 if (lpdi->itemID == 0xFFFF) /* got no items */
2423 DrawFocusRect16(lpdi->hDC, &lpdi->rcItem);
2424 else
2426 if (lpdi->CtlType == ODT_COMBOBOX)
2428 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
2429 SelectObject(lpdi->hDC, hBrush);
2430 FillRect16(lpdi->hDC, &lpdi->rcItem, hBrush);
2432 else
2433 return TRUE; /* this should never happen */
2435 rect=lpdi->rcItem;
2436 switch (lpdi->CtlID)
2438 case cmb1: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2439 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2440 (LPARAM)MAKE_SEGPTR(buffer));
2441 GetObject(hBitmapTT, sizeof(BITMAP), (LPSTR)&bm);
2442 TextOut16(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
2443 lpdi->rcItem.top, buffer, lstrlen(buffer));
2444 #if 0
2445 nFontType = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
2446 /* FIXME: draw bitmap if truetype usage */
2447 if (nFontType&TRUETYPE_FONTTYPE)
2449 hMemDC = CreateCompatibleDC(lpdi->hDC);
2450 hBitmap = SelectObject(hMemDC, hBitmapTT);
2451 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
2452 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
2453 SelectObject(hMemDC, hBitmap);
2454 DeleteDC(hMemDC);
2456 #endif
2457 break;
2458 case cmb2:
2459 case cmb3: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2460 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2461 (LPARAM)MAKE_SEGPTR(buffer));
2462 TextOut16(lpdi->hDC, lpdi->rcItem.left,
2463 lpdi->rcItem.top, buffer, lstrlen(buffer));
2464 break;
2466 case cmb4: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2467 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2468 (LPARAM)MAKE_SEGPTR(buffer));
2469 TextOut16(lpdi->hDC, lpdi->rcItem.left + 25+5,
2470 lpdi->rcItem.top, buffer, lstrlen(buffer));
2471 cr = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
2472 hBrush = CreateSolidBrush(cr);
2473 if (hBrush)
2475 hBrush = SelectObject (lpdi->hDC, hBrush) ;
2476 rect.right=rect.left+25;
2477 rect.top++;
2478 rect.left+=5;
2479 rect.bottom--;
2480 Rectangle(lpdi->hDC,rect.left,rect.top,rect.right,rect.bottom);
2481 DeleteObject (SelectObject (lpdi->hDC, hBrush)) ;
2483 rect=lpdi->rcItem;
2484 rect.left+=25+5;
2485 break;
2487 default: return TRUE; /* this should never happen */
2489 if (lpdi->itemState ==ODS_SELECTED)
2490 InvertRect16(lpdi->hDC, &rect);
2492 return TRUE;
2495 /***********************************************************************
2496 * CFn_WMCtlColor [internal]
2498 LRESULT CFn_WMCtlColor(HWND hDlg, WPARAM wParam, LPARAM lParam)
2500 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong(hDlg, DWL_USER);
2502 if (lpcf->Flags & CF_EFFECTS)
2503 if (HIWORD(lParam)==CTLCOLOR_STATIC && GetDlgCtrlID(LOWORD(lParam))==stc6)
2505 SetTextColor(wParam,lpcf->rgbColors);
2506 return GetStockObject(WHITE_BRUSH);
2508 return 0;
2511 /***********************************************************************
2512 * CFn_WMCommand [internal]
2514 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
2516 char buffer[200];
2517 FARPROC enumCallback;
2518 HFONT hFont/*,hFontOld*/;
2519 int i,j;
2520 long l;
2521 HDC hdc;
2522 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong(hDlg, DWL_USER);
2523 LPLOGFONT lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2525 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam);
2526 switch (wParam)
2528 case cmb1:if (HIWORD(lParam)==CBN_SELCHANGE)
2530 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
2531 if (hdc)
2533 /* only if cmb2 is refilled in FontStyleEnumProc():
2534 SendDlgItemMessage(hDlg,cmb2,CB_RESETCONTENT,0,0);
2536 SendDlgItemMessage16(hDlg,cmb3,CB_RESETCONTENT,0,0);
2537 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL,0,0);
2538 if (i!=CB_ERR)
2540 HCURSOR hcursor=SetCursor(LoadCursor(0,IDC_WAIT));
2541 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT,i,(LPARAM)MAKE_SEGPTR(buffer));
2542 dprintf_commdlg(stddeb,"WM_COMMAND/cmb1 =>%s\n",buffer);
2543 enumCallback = MODULE_GetWndProcEntry16("FontStyleEnumProc");
2544 EnumFontFamilies(hdc,buffer,enumCallback,
2545 MAKELONG(GetDlgItem(hDlg,cmb2),GetDlgItem(hDlg,cmb3)));
2546 SetCursor(hcursor);
2548 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2549 ReleaseDC(hDlg,hdc);
2551 else
2553 dprintf_commdlg(stddeb,"WM_COMMAND: HDC failure !!!\n");
2554 EndDialog (hDlg, 0);
2555 return TRUE;
2558 case chx1:
2559 case chx2:
2560 case cmb2:
2561 case cmb3:if (HIWORD(lParam)==CBN_SELCHANGE || HIWORD(lParam)== BN_CLICKED )
2563 dprintf_commdlg(stddeb,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
2564 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL,0,0);
2565 if (i==CB_ERR)
2566 i=GetDlgItemText32A( hDlg, cmb1, buffer, sizeof(buffer) );
2567 else
2569 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT,i,(LPARAM)MAKE_SEGPTR(buffer));
2570 l=SendDlgItemMessage16(hDlg,cmb1,CB_GETITEMDATA,i,0);
2571 j=HIWORD(l);
2572 lpcf->nFontType = LOWORD(l);
2573 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2574 /* same value reported to the EnumFonts
2575 call back with the extra FONTTYPE_... bits added */
2576 lpxx->lfPitchAndFamily=j&0xff;
2577 lpxx->lfCharSet=j>>8;
2579 strcpy(lpxx->lfFaceName,buffer);
2580 i=SendDlgItemMessage16(hDlg,cmb2,CB_GETCURSEL,0,0);
2581 if (i!=CB_ERR)
2583 l=SendDlgItemMessage16(hDlg,cmb2,CB_GETITEMDATA,i,0);
2584 if (0!=(lpxx->lfItalic=HIWORD(l)))
2585 lpcf->nFontType |= ITALIC_FONTTYPE;
2586 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
2587 lpcf->nFontType |= BOLD_FONTTYPE;
2589 i=SendDlgItemMessage16(hDlg,cmb3,CB_GETCURSEL,0,0);
2590 if (i!=CB_ERR)
2592 l=SendDlgItemMessage16(hDlg,cmb3,CB_GETITEMDATA,i,0);
2593 lpxx->lfHeight=-LOWORD(l);
2594 lpxx->lfWidth = 0; /* FYI: lfWidth is in HIWORD(l); */
2596 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
2597 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
2598 lpxx->lfOrientation=lpxx->lfEscapement=0;
2599 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
2600 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
2601 lpxx->lfQuality=DEFAULT_QUALITY;
2603 hFont=CreateFontIndirect(lpxx);
2604 if (hFont)
2605 SendDlgItemMessage16(hDlg,stc6,WM_SETFONT,hFont,TRUE);
2606 /* FIXME: Delete old font ...? */
2608 break;
2610 case cmb4:i=SendDlgItemMessage16(hDlg,cmb4,CB_GETCURSEL,0,0);
2611 if (i!=CB_ERR)
2613 lpcf->rgbColors=textcolors[i];
2614 InvalidateRect32( GetDlgItem(hDlg,stc6), NULL, 0 );
2616 break;
2618 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
2619 if (lpcf->hwndOwner)
2620 SendMessage16(lpcf->hwndOwner,i,0,(LPARAM)lpcf);
2621 if (CFn_HookCallChk(lpcf))
2622 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);
2623 break;
2625 case IDOK:EndDialog(hDlg, TRUE);
2626 return(TRUE);
2627 case IDCANCEL:EndDialog(hDlg, FALSE);
2628 return(TRUE);
2630 return(FALSE);
2634 /***********************************************************************
2635 * FormatCharDlgProc (COMMDLG.16)
2636 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2637 2. some CF_.. flags are not supported
2638 3. some TType extensions
2640 LRESULT FormatCharDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2642 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong(hDlg, DWL_USER);
2643 if (message!=WM_INITDIALOG)
2645 int res=0;
2646 if (!lpcf)
2647 return FALSE;
2648 if (CFn_HookCallChk(lpcf))
2649 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
2650 if (res)
2651 return res;
2653 else
2654 return CFn_WMInitDialog(hDlg,wParam,lParam);
2655 switch (message)
2657 case WM_MEASUREITEM:
2658 return CFn_WMMeasureItem(hDlg,wParam,lParam);
2659 case WM_DRAWITEM:
2660 return CFn_WMDrawItem(hDlg,wParam,lParam);
2661 case WM_CTLCOLOR:
2662 return CFn_WMCtlColor(hDlg,wParam,lParam);
2663 case WM_COMMAND:
2664 return CFn_WMCommand(hDlg,wParam,lParam);
2665 case WM_CHOOSEFONT_GETLOGFONT:
2666 /* FIXME: current logfont back to caller */
2667 break;
2669 return FALSE;