Release 960516
[wine.git] / misc / commdlg.c
blob84143c5a143fd53d41be1611bcccc80abbb6559f
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 SendDlgItemMessage(hwnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(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);
162 /***********************************************************************
163 * FILEDLG_ScanDir [internal]
165 static BOOL FILEDLG_ScanDir(HWND hWnd, LPSTR newPath)
167 char str[512],str2[512];
169 strncpy(str,newPath,511); str[511]=0;
170 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(str2));
171 strncat(str,str2,511-strlen(str)); str[511]=0;
172 if (!DlgDirList(hWnd, MAKE_SEGPTR(str), lst1, 0, 0x0000)) return FALSE;
173 strcpy( str, "*.*" );
174 DlgDirList(hWnd, MAKE_SEGPTR(str), lst2, stc1, 0x8010);
175 return TRUE;
178 /***********************************************************************
179 * FILEDLG_GetFileType [internal]
182 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
184 int n, i;
185 i = 0;
186 if (cfptr)
187 for ( ;(n = strlen(cfptr)) != 0; i++)
189 cfptr += n + 1;
190 if (i == index)
191 return cfptr;
192 cfptr += strlen(cfptr) + 1;
194 if (fptr)
195 for ( ;(n = strlen(fptr)) != 0; i++)
197 fptr += n + 1;
198 if (i == index)
199 return fptr;
200 fptr += strlen(fptr) + 1;
202 return NULL;
205 /***********************************************************************
206 * FILEDLG_WMDrawItem [internal]
208 static LONG FILEDLG_WMDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
210 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
211 char str[512];
212 HBRUSH hBrush;
213 HBITMAP hBitmap, hPrevBitmap;
214 BITMAP bm;
215 HDC hMemDC;
217 str[0]=0;
218 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
219 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
220 SelectObject(lpdis->hDC, hBrush);
221 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
222 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
223 (LPARAM)MAKE_SEGPTR(str));
224 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
225 str, strlen(str));
226 if (lpdis->itemState != 0) {
227 InvertRect16(lpdis->hDC, &lpdis->rcItem);
229 return TRUE;
232 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2) {
233 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
234 SelectObject(lpdis->hDC, hBrush);
235 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
236 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
237 (LPARAM)MAKE_SEGPTR(str));
239 hBitmap = hFolder;
240 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
241 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
242 lpdis->rcItem.top, str, strlen(str));
243 hMemDC = CreateCompatibleDC(lpdis->hDC);
244 hPrevBitmap = SelectObject(hMemDC, hBitmap);
245 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
246 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
247 SelectObject(hMemDC, hPrevBitmap);
248 DeleteDC(hMemDC);
249 if (lpdis->itemState != 0) {
250 InvertRect16(lpdis->hDC, &lpdis->rcItem);
252 return TRUE;
254 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2) {
255 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
256 SelectObject(lpdis->hDC, hBrush);
257 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
258 SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
259 (LPARAM)MAKE_SEGPTR(str));
260 switch(DRIVE_GetType( str[2] - 'a' ))
262 case TYPE_FLOPPY: hBitmap = hFloppy; break;
263 case TYPE_CDROM: hBitmap = hCDRom; break;
264 case TYPE_HD:
265 case TYPE_NETWORK:
266 default: hBitmap = hHDisk; break;
268 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
269 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
270 lpdis->rcItem.top, str, strlen(str));
271 hMemDC = CreateCompatibleDC(lpdis->hDC);
272 hPrevBitmap = SelectObject(hMemDC, hBitmap);
273 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
274 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
275 SelectObject(hMemDC, hPrevBitmap);
276 DeleteDC(hMemDC);
277 if (lpdis->itemState != 0) {
278 InvertRect16(lpdis->hDC, &lpdis->rcItem);
280 return TRUE;
282 return FALSE;
285 /***********************************************************************
286 * FILEDLG_WMMeasureItem [internal]
288 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
290 BITMAP bm;
291 LPMEASUREITEMSTRUCT lpmeasure;
293 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
294 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
295 lpmeasure->itemHeight = bm.bmHeight;
296 return TRUE;
299 /***********************************************************************
300 * FILEDLG_HookCallChk [internal]
302 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn)
304 if (lpofn)
305 if (lpofn->Flags & OFN_ENABLEHOOK)
306 if (lpofn->lpfnHook)
307 return 1;
308 return 0;
311 /***********************************************************************
312 * FILEDLG_WMInitDialog [internal]
315 static LONG FILEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
317 int n;
318 int i;
319 LPOPENFILENAME lpofn;
320 char tmpstr[512];
321 LPSTR pstr;
322 SetWindowLong(hWnd, DWL_USER, lParam);
323 lpofn = (LPOPENFILENAME)lParam;
324 if (lpofn->lpstrTitle)
325 SendMessage( hWnd, WM_SETTEXT, 0, (LPARAM)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 = SendDlgItemMessage(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 SendDlgItemMessage(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 = SendDlgItemMessage(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 SendDlgItemMessage(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 SendDlgItemMessage(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 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
368 /* get drive list */
369 *tmpstr = 0;
370 DlgDirListComboBox(hWnd, MAKE_SEGPTR(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 SendDlgItemMessage(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 = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
427 if (lRet == LB_ERR) return TRUE;
428 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
429 (LPARAM)MAKE_SEGPTR(tmpstr));
430 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(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 = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
443 if (lRet == LB_ERR) return TRUE;
444 SendDlgItemMessage(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 = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
465 if (lRet == LB_ERR) return 0;
466 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, (LPARAM)MAKE_SEGPTR(tmpstr));
467 sprintf(tmpstr, "%c:", tmpstr[2]);
468 reset_scan:
469 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
470 if (lRet == LB_ERR)
471 return TRUE;
472 pstr = (LPSTR)SendDlgItemMessage(hWnd, cmb1, CB_GETITEMDATA, lRet, 0);
473 dprintf_commdlg(stddeb,"Selected filter : %s\n", pstr);
474 strncpy(tmpstr2, pstr, 511); tmpstr2[511]=0;
475 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
476 FILEDLG_ScanDir(hWnd, tmpstr);
477 return TRUE;
478 case chx1:
479 return TRUE;
480 case pshHelp:
481 return TRUE;
482 case IDOK:
483 almost_ok:
484 ofn2=*lpofn; /* for later restoring */
485 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(tmpstr));
486 pstr = strrchr(tmpstr, '\\');
487 if (pstr == NULL)
488 pstr = strrchr(tmpstr, ':');
489 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
491 /* edit control contains wildcards */
492 if (pstr != NULL)
494 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
495 *(pstr+1) = 0;
497 else
499 strcpy(tmpstr2, tmpstr);
500 *tmpstr=0;
502 dprintf_commdlg(stddeb,"commdlg: %s, %s\n", tmpstr, tmpstr2);
503 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
504 FILEDLG_ScanDir(hWnd, tmpstr);
505 return TRUE;
507 /* no wildcards, we might have a directory or a filename */
508 /* try appending a wildcard and reading the directory */
509 pstr2 = tmpstr + strlen(tmpstr);
510 if (pstr == NULL || *(pstr+1) != 0)
511 strcat(tmpstr, "\\");
512 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
513 if (lRet == LB_ERR) return TRUE;
514 lpofn->nFilterIndex = lRet + 1;
515 dprintf_commdlg(stddeb,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
516 strncpy(tmpstr2,
517 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
518 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
519 lRet), 511);
520 tmpstr2[511]=0;
521 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
522 /* if ScanDir succeeds, we have changed the directory */
523 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
524 /* if not, this must be a filename */
525 *pstr2 = 0;
526 if (pstr != NULL)
528 /* strip off the pathname */
529 *pstr = 0;
530 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
531 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
532 /* Should we MessageBox() if this fails? */
533 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
534 strcpy(tmpstr, tmpstr2);
536 else
537 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
538 #if 0
539 ShowWindow(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
540 #endif
542 int drive = DRIVE_GetCurrentDrive();
543 tmpstr2[0] = 'A'+ drive;
544 tmpstr2[1] = ':';
545 tmpstr2[2] = '\\';
546 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
547 if (strlen(tmpstr2) > 3)
548 strcat(tmpstr2, "\\");
549 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
550 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
552 lpofn->nFileOffset = 0;
553 lpofn->nFileExtension = 0;
554 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
555 lpofn->nFileExtension++;
556 if (lpofn->nFileExtension == '\0')
557 lpofn->nFileExtension = 0;
558 else
559 lpofn->nFileExtension++;
560 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
562 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
563 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
564 (LPARAM)MAKE_SEGPTR(tmpstr));
565 dprintf_commdlg(stddeb,"strcpy'ing '%s'\n",tmpstr); fflush(stdout);
566 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
568 if (FILEDLG_HookCallChk(lpofn))
570 lRet= (BOOL)CallWindowProc16(lpofn->lpfnHook,
571 hWnd, RegisterWindowMessage32A( FILEOKSTRING ),
572 0, (LPARAM)MAKE_SEGPTR(lpofn));
573 if (lRet)
575 *lpofn=ofn2; /* restore old state */
576 #if 0
577 ShowWindow(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
578 #endif
579 break;
582 EndDialog(hWnd, TRUE);
583 return TRUE;
584 case IDCANCEL:
585 EndDialog(hWnd, FALSE);
586 return TRUE;
588 return FALSE;
592 /***********************************************************************
593 * FileOpenDlgProc (COMMDLG.6)
595 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
597 LPOPENFILENAME lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
599 if (wMsg!=WM_INITDIALOG)
600 if (FILEDLG_HookCallChk(lpofn))
602 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
603 if (lRet)
604 return lRet; /* else continue message processing */
606 switch (wMsg)
608 case WM_INITDIALOG:
609 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
610 case WM_MEASUREITEM:
611 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
612 case WM_DRAWITEM:
613 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
614 case WM_COMMAND:
615 return FILEDLG_WMCommand(hWnd, wParam, lParam);
616 #if 0
617 case WM_CTLCOLOR:
618 SetBkColor((HDC)wParam, 0x00C0C0C0);
619 switch (HIWORD(lParam))
621 case CTLCOLOR_BTN:
622 SetTextColor((HDC)wParam, 0x00000000);
623 return hGRAYBrush;
624 case CTLCOLOR_STATIC:
625 SetTextColor((HDC)wParam, 0x00000000);
626 return hGRAYBrush;
628 break;
629 #endif
631 return FALSE;
635 /***********************************************************************
636 * FileSaveDlgProc (COMMDLG.7)
638 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
640 LPOPENFILENAME lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
642 if (wMsg!=WM_INITDIALOG)
643 if (FILEDLG_HookCallChk(lpofn))
645 LRESULT lRet=(BOOL)CallWindowProc16(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
646 if (lRet)
647 return lRet; /* else continue message processing */
649 switch (wMsg) {
650 case WM_INITDIALOG:
651 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
653 case WM_MEASUREITEM:
654 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
656 case WM_DRAWITEM:
657 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
659 case WM_COMMAND:
660 return FILEDLG_WMCommand(hWnd, wParam, lParam);
664 case WM_CTLCOLOR:
665 SetBkColor((HDC)wParam, 0x00C0C0C0);
666 switch (HIWORD(lParam))
668 case CTLCOLOR_BTN:
669 SetTextColor((HDC)wParam, 0x00000000);
670 return hGRAYBrush;
671 case CTLCOLOR_STATIC:
672 SetTextColor((HDC)wParam, 0x00000000);
673 return hGRAYBrush;
675 return FALSE;
678 return FALSE;
682 /***********************************************************************
683 * ChooseColor (COMMDLG.5)
685 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
687 HANDLE hInst, hDlgTmpl;
688 BOOL bRet;
690 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR );
691 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
692 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
693 MODULE_GetWndProcEntry16("ColorDlgProc"),
694 (DWORD)lpChCol );
695 SYSRES_FreeResource( hDlgTmpl );
696 return bRet;
700 /***********************************************************************
701 * FindTextDlg (COMMDLG.11)
703 BOOL FindText(LPFINDREPLACE lpFind)
705 HANDLE hInst, hDlgTmpl;
706 BOOL bRet;
707 SEGPTR ptr;
710 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
711 * For now, only the standard dialog works.
714 * FIXME : We should do error checking on the lpFind structure here
715 * and make CommDlgExtendedError() return the error condition.
717 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT );
718 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
719 if (!(ptr = (SEGPTR)WIN16_GlobalLock16( hDlgTmpl ))) return -1;
720 bRet = CreateDialogIndirectParam( hInst, ptr, lpFind->hwndOwner,
721 MODULE_GetWndProcEntry16("FindTextDlgProc"),
722 (DWORD)lpFind );
723 GlobalUnlock16( hDlgTmpl );
724 SYSRES_FreeResource( hDlgTmpl );
725 return bRet;
729 /***********************************************************************
730 * ReplaceTextDlg (COMMDLG.12)
732 BOOL ReplaceText(LPFINDREPLACE lpFind)
734 HANDLE hInst, hDlgTmpl;
735 BOOL bRet;
736 SEGPTR ptr;
739 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
740 * For now, only the standard dialog works.
743 * FIXME : We should do error checking on the lpFind structure here
744 * and make CommDlgExtendedError() return the error condition.
746 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT );
747 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
748 if (!(ptr = (SEGPTR)WIN16_GlobalLock16( hDlgTmpl ))) return -1;
749 bRet = CreateDialogIndirectParam( hInst, ptr, lpFind->hwndOwner,
750 MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
751 (DWORD)lpFind );
752 GlobalUnlock16( hDlgTmpl );
753 SYSRES_FreeResource( hDlgTmpl );
754 return bRet;
758 /***********************************************************************
759 * FINDDLG_WMInitDialog [internal]
761 static LRESULT FINDDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
763 LPFINDREPLACE lpfr;
765 SetWindowLong(hWnd, DWL_USER, lParam);
766 lpfr = (LPFINDREPLACE)lParam;
767 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
769 * FIXME : If the initial FindWhat string is empty, we should disable the
770 * FindNext (IDOK) button. Only after typing some text, the button should be
771 * enabled.
773 SetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat);
774 CheckRadioButton(hWnd, rad1, rad2, (lpfr->Flags & FR_DOWN) ? rad2 : rad1);
775 if (lpfr->Flags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
776 EnableWindow(GetDlgItem(hWnd, rad1), FALSE);
777 EnableWindow(GetDlgItem(hWnd, rad2), FALSE);
779 if (lpfr->Flags & FR_HIDEUPDOWN) {
780 ShowWindow(GetDlgItem(hWnd, rad1), SW_HIDE);
781 ShowWindow(GetDlgItem(hWnd, rad2), SW_HIDE);
782 ShowWindow(GetDlgItem(hWnd, grp1), SW_HIDE);
784 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
785 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
786 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
787 if (lpfr->Flags & FR_HIDEWHOLEWORD)
788 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
789 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
790 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
791 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
792 if (lpfr->Flags & FR_HIDEMATCHCASE)
793 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
794 if (!(lpfr->Flags & FR_SHOWHELP)) {
795 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
796 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
798 ShowWindow(hWnd, SW_SHOWNORMAL);
799 return TRUE;
803 /***********************************************************************
804 * FINDDLG_WMCommand [internal]
806 static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
808 LPFINDREPLACE lpfr;
809 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
810 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
812 lpfr = (LPFINDREPLACE)GetWindowLong(hWnd, DWL_USER);
813 switch (wParam) {
814 case IDOK:
815 GetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
816 if (IsDlgButtonChecked(hWnd, rad2))
817 lpfr->Flags |= FR_DOWN;
818 else lpfr->Flags &= ~FR_DOWN;
819 if (IsDlgButtonChecked(hWnd, chx1))
820 lpfr->Flags |= FR_WHOLEWORD;
821 else lpfr->Flags &= ~FR_WHOLEWORD;
822 if (IsDlgButtonChecked(hWnd, chx2))
823 lpfr->Flags |= FR_MATCHCASE;
824 else lpfr->Flags &= ~FR_MATCHCASE;
825 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
826 lpfr->Flags |= FR_FINDNEXT;
827 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
828 return TRUE;
829 case IDCANCEL:
830 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
831 lpfr->Flags |= FR_DIALOGTERM;
832 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
833 DestroyWindow(hWnd);
834 return TRUE;
835 case pshHelp:
836 /* FIXME : should lpfr structure be passed as an argument ??? */
837 SendMessage(lpfr->hwndOwner, uHelpMessage, 0, 0);
838 return TRUE;
840 return FALSE;
844 /***********************************************************************
845 * FindTextDlgProc (COMMDLG.13)
847 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
849 switch (wMsg) {
850 case WM_INITDIALOG:
851 return FINDDLG_WMInitDialog(hWnd, wParam, lParam);
852 case WM_COMMAND:
853 return FINDDLG_WMCommand(hWnd, wParam, lParam);
855 return FALSE;
859 /***********************************************************************
860 * REPLACEDLG_WMInitDialog [internal]
862 static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
864 LPFINDREPLACE lpfr;
866 SetWindowLong(hWnd, DWL_USER, lParam);
867 lpfr = (LPFINDREPLACE)lParam;
868 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
870 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
871 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
872 * enabled.
874 SetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat);
875 SetDlgItemText(hWnd, edt2, lpfr->lpstrReplaceWith);
876 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
877 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
878 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
879 if (lpfr->Flags & FR_HIDEWHOLEWORD)
880 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
881 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
882 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
883 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
884 if (lpfr->Flags & FR_HIDEMATCHCASE)
885 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
886 if (!(lpfr->Flags & FR_SHOWHELP)) {
887 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
888 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
890 ShowWindow(hWnd, SW_SHOWNORMAL);
891 return TRUE;
895 /***********************************************************************
896 * REPLACEDLG_WMCommand [internal]
898 static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
900 LPFINDREPLACE lpfr;
901 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
902 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
904 lpfr = (LPFINDREPLACE)GetWindowLong(hWnd, DWL_USER);
905 switch (wParam) {
906 case IDOK:
907 GetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
908 GetDlgItemText(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
909 if (IsDlgButtonChecked(hWnd, chx1))
910 lpfr->Flags |= FR_WHOLEWORD;
911 else lpfr->Flags &= ~FR_WHOLEWORD;
912 if (IsDlgButtonChecked(hWnd, chx2))
913 lpfr->Flags |= FR_MATCHCASE;
914 else lpfr->Flags &= ~FR_MATCHCASE;
915 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
916 lpfr->Flags |= FR_FINDNEXT;
917 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
918 return TRUE;
919 case IDCANCEL:
920 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
921 lpfr->Flags |= FR_DIALOGTERM;
922 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
923 DestroyWindow(hWnd);
924 return TRUE;
925 case psh1:
926 GetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
927 GetDlgItemText(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_REPLACEALL | FR_DIALOGTERM);
935 lpfr->Flags |= FR_REPLACE;
936 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
937 return TRUE;
938 case psh2:
939 GetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
940 GetDlgItemText(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
941 if (IsDlgButtonChecked(hWnd, chx1))
942 lpfr->Flags |= FR_WHOLEWORD;
943 else lpfr->Flags &= ~FR_WHOLEWORD;
944 if (IsDlgButtonChecked(hWnd, chx2))
945 lpfr->Flags |= FR_MATCHCASE;
946 else lpfr->Flags &= ~FR_MATCHCASE;
947 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
948 lpfr->Flags |= FR_REPLACEALL;
949 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
950 return TRUE;
951 case pshHelp:
952 /* FIXME : should lpfr structure be passed as an argument ??? */
953 SendMessage(lpfr->hwndOwner, uHelpMessage, 0, 0);
954 return TRUE;
956 return FALSE;
960 /***********************************************************************
961 * ReplaceTextDlgProc (COMMDLG.14)
963 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
965 switch (wMsg) {
966 case WM_INITDIALOG:
967 return REPLACEDLG_WMInitDialog(hWnd, wParam, lParam);
968 case WM_COMMAND:
969 return REPLACEDLG_WMCommand(hWnd, wParam, lParam);
971 return FALSE;
975 /***********************************************************************
976 * PrintDlg (COMMDLG.20)
978 BOOL PrintDlg(LPPRINTDLG lpPrint)
980 HANDLE hInst, hDlgTmpl;
981 BOOL bRet;
983 dprintf_commdlg(stddeb,"PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
985 if (lpPrint->Flags & PD_RETURNDEFAULT)
986 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
987 return TRUE;
989 if (lpPrint->Flags & PD_PRINTSETUP)
990 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP );
991 else
992 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT );
994 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
995 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
996 (lpPrint->Flags & PD_PRINTSETUP) ?
997 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
998 MODULE_GetWndProcEntry16("PrintDlgProc"),
999 (DWORD)lpPrint );
1000 SYSRES_FreeResource( hDlgTmpl );
1001 return bRet;
1005 /***********************************************************************
1006 * PrintDlgProc (COMMDLG.21)
1008 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
1010 switch (wMsg)
1012 case WM_INITDIALOG:
1013 dprintf_commdlg(stddeb,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1014 ShowWindow(hWnd, SW_SHOWNORMAL);
1015 return (TRUE);
1016 case WM_COMMAND:
1017 switch (wParam)
1019 case IDOK:
1020 EndDialog(hWnd, TRUE);
1021 return(TRUE);
1022 case IDCANCEL:
1023 EndDialog(hWnd, FALSE);
1024 return(TRUE);
1026 return(FALSE);
1028 return FALSE;
1032 /***********************************************************************
1033 * PrintSetupDlgProc (COMMDLG.22)
1035 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
1037 switch (wMsg)
1039 case WM_INITDIALOG:
1040 dprintf_commdlg(stddeb,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1041 ShowWindow(hWnd, SW_SHOWNORMAL);
1042 return (TRUE);
1043 case WM_COMMAND:
1044 switch (wParam) {
1045 case IDOK:
1046 EndDialog(hWnd, TRUE);
1047 return(TRUE);
1048 case IDCANCEL:
1049 EndDialog(hWnd, FALSE);
1050 return(TRUE);
1052 return(FALSE);
1054 return FALSE;
1058 /***********************************************************************
1059 * CommDlgExtendedError (COMMDLG.26)
1061 DWORD CommDlgExtendedError(void)
1063 return CommDlgLastError;
1067 /***********************************************************************
1068 * GetFileTitle (COMMDLG.27)
1070 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
1072 int i, len;
1073 dprintf_commdlg(stddeb,"GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1074 if (lpFile == NULL || lpTitle == NULL)
1075 return -1;
1076 len = strlen(lpFile);
1077 if (len == 0)
1078 return -1;
1079 if (strpbrk(lpFile, "*[]"))
1080 return -1;
1081 len--;
1082 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1083 return -1;
1084 for (i = len; i >= 0; i--)
1085 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1087 i++;
1088 break;
1090 dprintf_commdlg(stddeb,"\n---> '%s' ", &lpFile[i]);
1092 len = strlen(lpFile+i)+1;
1093 if (cbBuf < len)
1094 return len;
1096 strncpy(lpTitle, &lpFile[i], len);
1097 return 0;
1101 /* --------------------------- Choose Color Dialog ------------------------------ */
1103 static const COLORREF predefcolors[6][8]=
1105 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1106 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1107 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1108 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1110 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1111 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1112 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1113 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1115 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1116 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1117 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1118 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1121 struct CCPRIVATE
1123 LPCHOOSECOLOR lpcc; /* points to public known data structure */
1124 int nextuserdef; /* next free place in user defined color array */
1125 HDC hdcMem; /* color graph used for BitBlt() */
1126 HBITMAP hbmMem; /* color graph bitmap */
1127 RECT16 fullsize; /* original dialog window size */
1128 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
1129 RECT16 old3angle; /* last position of l-marker */
1130 RECT16 oldcross; /* last position of color/satuation marker */
1131 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1132 int h;
1133 int s;
1134 int l; /* for temporary storing of hue,sat,lum */
1137 /***********************************************************************
1138 * CC_HSLtoRGB [internal]
1140 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1142 int res=0,maxrgb;
1144 /* hue */
1145 switch(c)
1147 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1148 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1149 case 'B':break;
1152 /* l below 120 */
1153 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1154 if (hue< 80)
1155 res=0;
1156 else
1157 if (hue< 120)
1159 res=(hue-80)* maxrgb; /* 0...10240 */
1160 res/=40; /* 0...256 */
1162 else
1163 if (hue< 200)
1164 res=maxrgb;
1165 else
1167 res=(240-hue)* maxrgb;
1168 res/=40;
1170 res=res-maxrgb/2; /* -128...128 */
1172 /* saturation */
1173 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1175 /* lum above 120 */
1176 if (lum>120 && res<256)
1177 res+=((lum-120) * (256-res))/120;
1179 return MIN(res,255);
1182 /***********************************************************************
1183 * CC_RGBtoHSL [internal]
1185 static int CC_RGBtoHSL(char c,int r,int g,int b)
1187 WORD maxi,mini,mmsum,mmdif,result=0;
1188 int iresult=0;
1190 maxi=MAX(r,b);
1191 maxi=MAX(maxi,g);
1192 mini=MIN(r,b);
1193 mini=MIN(mini,g);
1195 mmsum=maxi+mini;
1196 mmdif=maxi-mini;
1198 switch(c)
1200 /* lum */
1201 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1202 result=mmsum/255; /* 0...240 */
1203 break;
1204 /* saturation */
1205 case 'S':if (!mmsum)
1206 result=0;
1207 else
1208 if (!mini || maxi==255)
1209 result=240;
1210 else
1212 result=mmdif*240; /* 0...61200=255*240 */
1213 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1215 break;
1216 /* hue */
1217 case 'H':if (!mmdif)
1218 result=160;
1219 else
1221 if (maxi==r)
1223 iresult=40*(g-b); /* -10200 ... 10200 */
1224 iresult/=(int)mmdif; /* -40 .. 40 */
1225 if (iresult<0)
1226 iresult+=240; /* 0..40 and 200..240 */
1228 else
1229 if (maxi==g)
1231 iresult=40*(b-r);
1232 iresult/=(int)mmdif;
1233 iresult+=80; /* 40 .. 120 */
1235 else
1236 if (maxi==b)
1238 iresult=40*(r-g);
1239 iresult/=(int)mmdif;
1240 iresult+=160; /* 120 .. 200 */
1242 result=iresult;
1244 break;
1246 return result; /* is this integer arithmetic precise enough ? */
1249 #define DISTANCE 4
1251 /***********************************************************************
1252 * CC_MouseCheckPredefColorArray [internal]
1254 static int CC_MouseCheckPredefColorArray(HWND hDlg,int dlgitem,int rows,int cols,
1255 LPARAM lParam,COLORREF *cr)
1257 HWND hwnd;
1258 POINT16 point = MAKEPOINT16(lParam);
1259 RECT16 rect;
1260 int dx,dy,x,y;
1262 ClientToScreen16(hDlg,&point);
1263 hwnd=GetDlgItem(hDlg,dlgitem);
1264 GetWindowRect16(hwnd,&rect);
1265 if (PtInRect16(&rect,point))
1267 dx=(rect.right-rect.left)/cols;
1268 dy=(rect.bottom-rect.top)/rows;
1269 ScreenToClient16(hwnd,&point);
1271 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1273 x=point.x/dx;
1274 y=point.y/dy;
1275 *cr=predefcolors[y][x];
1276 /* FIXME: Draw_a_Focus_Rect() */
1277 return 1;
1280 return 0;
1283 /***********************************************************************
1284 * CC_MouseCheckUserColorArray [internal]
1286 static int CC_MouseCheckUserColorArray(HWND hDlg,int dlgitem,int rows,int cols,
1287 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1289 HWND hwnd;
1290 POINT16 point = MAKEPOINT16(lParam);
1291 RECT16 rect;
1292 int dx,dy,x,y;
1294 ClientToScreen16(hDlg,&point);
1295 hwnd=GetDlgItem(hDlg,dlgitem);
1296 GetWindowRect16(hwnd,&rect);
1297 if (PtInRect16(&rect,point))
1299 dx=(rect.right-rect.left)/cols;
1300 dy=(rect.bottom-rect.top)/rows;
1301 ScreenToClient16(hwnd,&point);
1303 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1305 x=point.x/dx;
1306 y=point.y/dy;
1307 *cr=crarr[x+cols*y];
1308 /* FIXME: Draw_a_Focus_Rect() */
1309 return 1;
1312 return 0;
1315 #define MAXVERT 240
1316 #define MAXHORI 239
1318 /* 240 ^...... ^^ 240
1319 | . ||
1320 SAT | . || LUM
1321 | . ||
1322 +-----> 239 ----
1325 /***********************************************************************
1326 * CC_MouseCheckColorGraph [internal]
1328 static int CC_MouseCheckColorGraph(HWND hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1330 HWND hwnd;
1331 POINT16 point = MAKEPOINT16(lParam);
1332 RECT16 rect;
1333 long x,y;
1335 ClientToScreen16(hDlg,&point);
1336 hwnd=GetDlgItem(hDlg,dlgitem);
1337 GetWindowRect16(hwnd,&rect);
1338 if (PtInRect16(&rect,point))
1340 GetClientRect16(hwnd,&rect);
1341 ScreenToClient16(hwnd,&point);
1343 x=(long)point.x*MAXHORI;
1344 x/=rect.right;
1345 y=(long)(rect.bottom-point.y)*MAXVERT;
1346 y/=rect.bottom;
1348 if (hori)
1349 *hori=x;
1350 if (vert)
1351 *vert=y;
1352 return 1;
1354 else
1355 return 0;
1357 /***********************************************************************
1358 * CC_MouseCheckResultWindow [internal]
1360 static int CC_MouseCheckResultWindow(HWND hDlg,LPARAM lParam)
1362 HWND hwnd;
1363 POINT16 point = MAKEPOINT16(lParam);
1364 RECT16 rect;
1366 ClientToScreen16(hDlg,&point);
1367 hwnd=GetDlgItem(hDlg,0x2c5);
1368 GetWindowRect16(hwnd,&rect);
1369 if (PtInRect16(&rect,point))
1371 PostMessage(hDlg,WM_COMMAND,0x2c9,0);
1372 return 1;
1374 return 0;
1377 /***********************************************************************
1378 * CC_CheckDigitsInEdit [internal]
1380 static int CC_CheckDigitsInEdit(HWND hwnd,int maxval)
1382 int i,k,m,result,value;
1383 long editpos;
1384 char buffer[30];
1385 GetWindowText(hwnd,buffer,30-1);
1386 m=lstrlen(buffer);
1387 result=0;
1389 for (i=0;i<m;i++)
1390 if (buffer[i]<'0' || buffer[i]>'9')
1392 for (k=i+1;k<=m;k++) /* delete bad character */
1394 buffer[i]=buffer[k];
1395 m--;
1397 buffer[m]=0;
1398 result=1;
1401 value=atoi(buffer);
1402 if (value>maxval) /* build a new string */
1404 sprintf(buffer,"%d",maxval);
1405 result=2;
1407 if (result)
1409 editpos=SendMessage(hwnd,EM_GETSEL,0,0);
1410 SetWindowText(hwnd,buffer);
1411 SendMessage(hwnd,EM_SETSEL,0,editpos);
1413 return value;
1418 /***********************************************************************
1419 * CC_PaintSelectedColor [internal]
1421 static void CC_PaintSelectedColor(HWND hDlg,COLORREF cr)
1423 RECT16 rect;
1424 HDC hdc;
1425 HBRUSH hBrush;
1426 HWND hwnd=GetDlgItem(hDlg,0x2c5);
1427 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1429 hdc=GetDC(hwnd);
1430 GetClientRect16 (hwnd, &rect) ;
1431 hBrush = CreateSolidBrush(cr);
1432 if (hBrush)
1434 hBrush = SelectObject (hdc, hBrush) ;
1435 Rectangle (hdc, rect.left,rect.top,rect.right/2,rect.bottom);
1436 DeleteObject (SelectObject (hdc,hBrush)) ;
1437 hBrush=CreateSolidBrush(GetNearestColor(hdc,cr));
1438 if (hBrush)
1440 hBrush= SelectObject (hdc, hBrush) ;
1441 Rectangle (hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
1442 DeleteObject (SelectObject (hdc, hBrush)) ;
1445 ReleaseDC(hwnd,hdc);
1449 /***********************************************************************
1450 * CC_PaintTriangle [internal]
1452 static void CC_PaintTriangle(HWND hDlg,int y)
1454 HDC hDC;
1455 long temp;
1456 int w=GetDialogBaseUnits();
1457 POINT16 points[3];
1458 int height;
1459 int oben;
1460 RECT16 rect;
1461 HWND hwnd=GetDlgItem(hDlg,0x2be);
1462 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1464 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1466 GetClientRect16(hwnd,&rect);
1467 height=rect.bottom;
1468 hDC=GetDC(hDlg);
1470 points[0].y=rect.top;
1471 points[0].x=rect.right; /* | /| */
1472 ClientToScreen16(hwnd,points); /* | / | */
1473 ScreenToClient16(hDlg,points); /* |< | */
1474 oben=points[0].y; /* | \ | */
1475 /* | \| */
1476 temp=(long)height*(long)y;
1477 points[0].y=oben+height -temp/(long)MAXVERT;
1478 points[1].y=points[0].y+w;
1479 points[2].y=points[0].y-w;
1480 points[2].x=points[1].x=points[0].x + w;
1482 if (lpp->old3angle.left)
1483 FillRect16(hDC,&lpp->old3angle,GetStockObject(WHITE_BRUSH));
1484 lpp->old3angle.left =points[0].x;
1485 lpp->old3angle.right =points[1].x+1;
1486 lpp->old3angle.top =points[2].y-1;
1487 lpp->old3angle.bottom=points[1].y+1;
1488 Polygon16(hDC,points,3);
1489 ReleaseDC(hDlg,hDC);
1494 /***********************************************************************
1495 * CC_PaintCross [internal]
1497 static void CC_PaintCross(HWND hDlg,int x,int y)
1499 HDC hDC;
1500 int w=GetDialogBaseUnits();
1501 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1502 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1503 RECT16 rect;
1504 POINT16 point;
1505 HPEN16 hPen;
1507 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1509 GetClientRect16(hwnd,&rect);
1510 hDC=GetDC(hwnd);
1511 SelectClipRgn(hDC,CreateRectRgnIndirect16(&rect));
1512 hPen=CreatePen(PS_SOLID,2,0);
1513 hPen=SelectObject(hDC,hPen);
1514 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
1515 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
1516 if (lpp->oldcross.left!=lpp->oldcross.right)
1517 BitBlt(hDC,lpp->oldcross.left,lpp->oldcross.top,
1518 lpp->oldcross.right-lpp->oldcross.left,
1519 lpp->oldcross.bottom-lpp->oldcross.top,
1520 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
1521 lpp->oldcross.left =point.x-w-1;
1522 lpp->oldcross.right =point.x+w+1;
1523 lpp->oldcross.top =point.y-w-1;
1524 lpp->oldcross.bottom=point.y+w+1;
1526 MoveTo(hDC,point.x-w,point.y);
1527 LineTo(hDC,point.x+w,point.y);
1528 MoveTo(hDC,point.x,point.y-w);
1529 LineTo(hDC,point.x,point.y+w);
1530 DeleteObject(SelectObject(hDC,hPen));
1531 ReleaseDC(hwnd,hDC);
1536 #define XSTEPS 48
1537 #define YSTEPS 24
1540 /***********************************************************************
1541 * CC_PrepareColorGraph [internal]
1543 static void CC_PrepareColorGraph(HWND hDlg)
1545 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
1546 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1547 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1548 HBRUSH hbrush;
1549 HDC hdc ;
1550 RECT16 rect,client;
1551 HCURSOR hcursor=SetCursor(LoadCursor(0,IDC_WAIT));
1553 GetClientRect16(hwnd,&client);
1554 hdc=GetDC(hwnd);
1555 lpp->hdcMem = CreateCompatibleDC(hdc);
1556 lpp->hbmMem = CreateCompatibleBitmap(hdc,client.right,client.bottom);
1557 SelectObject(lpp->hdcMem,lpp->hbmMem);
1559 xdif=client.right /XSTEPS;
1560 ydif=client.bottom/YSTEPS+1;
1561 hdif=239/XSTEPS;
1562 sdif=240/YSTEPS;
1563 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
1565 rect.right=rect.left+xdif;
1566 rect.bottom=client.bottom;
1567 for(sat=0;sat<240+sdif;sat+=sdif)
1569 rect.top=rect.bottom-ydif;
1570 r=CC_HSLtoRGB('R',hue,sat,120);
1571 g=CC_HSLtoRGB('G',hue,sat,120);
1572 b=CC_HSLtoRGB('B',hue,sat,120);
1573 hbrush=CreateSolidBrush(RGB(r,g,b));
1574 FillRect16(lpp->hdcMem,&rect,hbrush);
1575 DeleteObject(hbrush);
1576 rect.bottom=rect.top;
1578 rect.left=rect.right;
1580 ReleaseDC(hwnd,hdc);
1581 SetCursor(hcursor);
1584 /***********************************************************************
1585 * CC_PaintColorGraph [internal]
1587 static void CC_PaintColorGraph(HWND hDlg)
1589 HWND hwnd=GetDlgItem(hDlg,0x2c6);
1590 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1591 HDC hDC;
1592 RECT16 rect;
1593 if (IsWindowVisible(hwnd)) /* if full size */
1595 if (!lpp->hdcMem)
1596 CC_PrepareColorGraph(hDlg); /* should not be necessary */
1598 hDC=GetDC(hwnd);
1599 GetClientRect16(hwnd,&rect);
1600 if (lpp->hdcMem)
1601 BitBlt(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
1602 else
1603 fprintf(stderr,"choose color: hdcMem is not defined\n");
1604 ReleaseDC(hwnd,hDC);
1607 /***********************************************************************
1608 * CC_PaintLumBar [internal]
1610 static void CC_PaintLumBar(HWND hDlg,int hue,int sat)
1612 HWND hwnd=GetDlgItem(hDlg,0x2be);
1613 RECT16 rect,client;
1614 int lum,ldif,ydif,r,g,b;
1615 HBRUSH hbrush;
1616 HDC hDC;
1618 if (IsWindowVisible(hwnd))
1620 hDC=GetDC(hwnd);
1621 GetClientRect16(hwnd,&client);
1622 rect=client;
1624 ldif=240/YSTEPS;
1625 ydif=client.bottom/YSTEPS+1;
1626 for(lum=0;lum<240+ldif;lum+=ldif)
1628 rect.top=MAX(0,rect.bottom-ydif);
1629 r=CC_HSLtoRGB('R',hue,sat,lum);
1630 g=CC_HSLtoRGB('G',hue,sat,lum);
1631 b=CC_HSLtoRGB('B',hue,sat,lum);
1632 hbrush=CreateSolidBrush(RGB(r,g,b));
1633 FillRect16(hDC,&rect,hbrush);
1634 DeleteObject(hbrush);
1635 rect.bottom=rect.top;
1637 GetClientRect16(hwnd,&rect);
1638 FrameRect16(hDC,&rect,GetStockObject(BLACK_BRUSH));
1639 ReleaseDC(hwnd,hDC);
1643 /***********************************************************************
1644 * CC_EditSetRGB [internal]
1646 static void CC_EditSetRGB(HWND hDlg,COLORREF cr)
1648 char buffer[10];
1649 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1650 int r=GetRValue(cr);
1651 int g=GetGValue(cr);
1652 int b=GetBValue(cr);
1653 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1655 lpp->updating=TRUE;
1656 sprintf(buffer,"%d",r);
1657 SetWindowText(GetDlgItem(hDlg,0x2c2),buffer);
1658 sprintf(buffer,"%d",g);
1659 SetWindowText(GetDlgItem(hDlg,0x2c3),buffer);
1660 sprintf(buffer,"%d",b);
1661 SetWindowText(GetDlgItem(hDlg,0x2c4),buffer);
1662 lpp->updating=FALSE;
1666 /***********************************************************************
1667 * CC_EditSetHSL [internal]
1669 static void CC_EditSetHSL(HWND hDlg,int h,int s,int l)
1671 char buffer[10];
1672 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1673 lpp->updating=TRUE;
1674 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
1676 lpp->updating=TRUE;
1677 sprintf(buffer,"%d",h);
1678 SetWindowText(GetDlgItem(hDlg,0x2bf),buffer);
1679 sprintf(buffer,"%d",s);
1680 SetWindowText(GetDlgItem(hDlg,0x2c0),buffer);
1681 sprintf(buffer,"%d",l);
1682 SetWindowText(GetDlgItem(hDlg,0x2c1),buffer);
1683 lpp->updating=FALSE;
1685 CC_PaintLumBar(hDlg,h,s);
1688 /***********************************************************************
1689 * CC_SwitchToFullSize [internal]
1691 static void CC_SwitchToFullSize(HWND hDlg,COLORREF result,LPRECT16 lprect)
1693 int i;
1694 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1696 EnableWindow(GetDlgItem(hDlg,0x2cf),FALSE);
1697 CC_PrepareColorGraph(hDlg);
1698 for (i=0x2bf;i<0x2c5;i++)
1699 EnableWindow(GetDlgItem(hDlg,i),TRUE);
1700 for (i=0x2d3;i<0x2d9;i++)
1701 EnableWindow(GetDlgItem(hDlg,i),TRUE);
1702 EnableWindow(GetDlgItem(hDlg,0x2c9),TRUE);
1703 EnableWindow(GetDlgItem(hDlg,0x2c8),TRUE);
1705 if (lprect)
1706 SetWindowPos(hDlg,NULL,0,0,lprect->right-lprect->left,
1707 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
1709 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_SHOW);
1710 ShowWindow(GetDlgItem(hDlg,0x2be),SW_SHOW);
1711 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_SHOW);
1713 CC_EditSetRGB(hDlg,result);
1714 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1717 /***********************************************************************
1718 * CC_PaintPredefColorArray [internal]
1720 static void CC_PaintPredefColorArray(HWND hDlg,int rows,int cols)
1722 HWND hwnd=GetDlgItem(hDlg,0x2d0);
1723 RECT16 rect;
1724 HDC hdc;
1725 HBRUSH hBrush;
1726 int dx,dy,i,j,k;
1728 GetClientRect16(hwnd,&rect);
1729 dx=rect.right/cols;
1730 dy=rect.bottom/rows;
1731 k=rect.left;
1733 hdc=GetDC(hwnd);
1734 GetClientRect16 (hwnd, &rect) ;
1736 for (j=0;j<rows;j++)
1738 for (i=0;i<cols;i++)
1740 hBrush = CreateSolidBrush(predefcolors[j][i]);
1741 if (hBrush)
1743 hBrush = SelectObject (hdc, hBrush) ;
1744 Rectangle (hdc, rect.left, rect.top,
1745 rect.left+dx-DISTANCE,rect.top+dy-DISTANCE);
1746 rect.left=rect.left+dx;
1747 DeleteObject (SelectObject (hdc, hBrush)) ;
1750 rect.top=rect.top+dy;
1751 rect.left=k;
1753 ReleaseDC(hwnd,hdc);
1754 /* FIXME: draw_a_focus_rect */
1756 /***********************************************************************
1757 * CC_PaintUserColorArray [internal]
1759 static void CC_PaintUserColorArray(HWND hDlg,int rows,int cols,COLORREF* lpcr)
1761 HWND hwnd=GetDlgItem(hDlg,0x2d1);
1762 RECT16 rect;
1763 HDC hdc;
1764 HBRUSH hBrush;
1765 int dx,dy,i,j,k;
1767 GetClientRect16(hwnd,&rect);
1769 dx=rect.right/cols;
1770 dy=rect.bottom/rows;
1771 k=rect.left;
1773 hdc=GetDC(hwnd);
1774 if (hdc)
1776 for (j=0;j<rows;j++)
1778 for (i=0;i<cols;i++)
1780 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
1781 if (hBrush)
1783 hBrush = SelectObject (hdc, hBrush) ;
1784 Rectangle (hdc, rect.left, rect.top,
1785 rect.left+dx-DISTANCE,rect.top+dy-DISTANCE);
1786 rect.left=rect.left+dx;
1787 DeleteObject (SelectObject (hdc, hBrush)) ;
1790 rect.top=rect.top+dy;
1791 rect.left=k;
1793 ReleaseDC(hwnd,hdc);
1795 /* FIXME: draw_a_focus_rect */
1800 /***********************************************************************
1801 * CC_HookCallChk [internal]
1803 static BOOL CC_HookCallChk(LPCHOOSECOLOR lpcc)
1805 if (lpcc)
1806 if(lpcc->Flags & CC_ENABLEHOOK)
1807 if (lpcc->lpfnHook)
1808 return TRUE;
1809 return FALSE;
1812 /***********************************************************************
1813 * CC_WMInitDialog [internal]
1815 static LONG CC_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam)
1817 int i,res;
1818 HWND hwnd;
1819 RECT16 rect;
1820 POINT16 point;
1821 struct CCPRIVATE * lpp;
1823 dprintf_commdlg(stddeb,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1824 lpp=calloc(1,sizeof(struct CCPRIVATE));
1825 lpp->lpcc=(LPCHOOSECOLOR)lParam;
1826 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR))
1828 EndDialog (hDlg, 0) ;
1829 return FALSE;
1831 SetWindowLong(hDlg, DWL_USER, (LONG)lpp);
1833 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
1834 ShowWindow(GetDlgItem(hDlg,0x40e),SW_HIDE);
1835 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
1836 #if 0
1837 cpos=MAKELONG(5,7); /* init */
1838 if (lpp->lpcc->Flags & CC_RGBINIT)
1840 for (i=0;i<6;i++)
1841 for (j=0;j<8;j++)
1842 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
1844 cpos=MAKELONG(i,j);
1845 goto found;
1848 found:
1849 /* FIXME: Draw_a_focus_rect & set_init_values */
1850 #endif
1851 GetWindowRect16(hDlg,&lpp->fullsize);
1852 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1854 hwnd=GetDlgItem(hDlg,0x2cf);
1855 EnableWindow(hwnd,FALSE);
1857 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
1859 rect=lpp->fullsize;
1860 res=rect.bottom-rect.top;
1861 hwnd=GetDlgItem(hDlg,0x2c6); /* cut at left border */
1862 point.x=point.y=0;
1863 ClientToScreen16(hwnd,&point);
1864 ScreenToClient16(hDlg,&point);
1865 GetClientRect16(hDlg,&rect);
1866 point.x+=GetSystemMetrics(SM_CXDLGFRAME);
1867 SetWindowPos(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
1869 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_HIDE);
1870 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_HIDE);
1872 else
1873 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
1874 res=TRUE;
1875 for (i=0x2bf;i<0x2c5;i++)
1876 SendMessage(GetDlgItem(hDlg,i),EM_LIMITTEXT,3,0); /* max 3 digits: xyz */
1877 if (CC_HookCallChk(lpp->lpcc))
1878 res=CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
1879 return res;
1882 /***********************************************************************
1883 * CC_WMCommand [internal]
1885 static LRESULT CC_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
1887 int r,g,b,i,xx;
1888 UINT cokmsg;
1889 HDC hdc;
1890 COLORREF *cr;
1891 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
1892 dprintf_commdlg(stddeb,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
1893 switch (wParam)
1895 case 0x2c2: /* edit notify RGB */
1896 case 0x2c3:
1897 case 0x2c4:
1898 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1900 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
1901 r=GetRValue(lpp->lpcc->rgbResult);
1902 g=GetGValue(lpp->lpcc->rgbResult);
1903 b=GetBValue(lpp->lpcc->rgbResult);
1904 xx=0;
1905 switch (wParam)
1907 case 0x2c2:if ((xx=(i!=r))) r=i;break;
1908 case 0x2c3:if ((xx=(i!=g))) g=i;break;
1909 case 0x2c4:if ((xx=(i!=b))) b=i;break;
1911 if (xx) /* something has changed */
1913 lpp->lpcc->rgbResult=RGB(r,g,b);
1914 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1915 lpp->h=CC_RGBtoHSL('H',r,g,b);
1916 lpp->s=CC_RGBtoHSL('S',r,g,b);
1917 lpp->l=CC_RGBtoHSL('L',r,g,b);
1918 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1919 CC_PaintCross(hDlg,lpp->h,lpp->s);
1920 CC_PaintTriangle(hDlg,lpp->l);
1923 break;
1925 case 0x2bf: /* edit notify HSL */
1926 case 0x2c0:
1927 case 0x2c1:
1928 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
1930 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
1931 xx=0;
1932 switch (wParam)
1934 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
1935 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
1936 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
1938 if (xx) /* something has changed */
1940 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
1941 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
1942 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
1943 lpp->lpcc->rgbResult=RGB(r,g,b);
1944 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1945 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
1946 CC_PaintCross(hDlg,lpp->h,lpp->s);
1947 CC_PaintTriangle(hDlg,lpp->l);
1950 break;
1952 case 0x2cf:
1953 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
1954 InvalidateRect32( hDlg, NULL, TRUE );
1955 SetFocus(GetDlgItem(hDlg,0x2bf));
1956 break;
1958 case 0x2c8: /* add colors ... column by column */
1959 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
1960 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
1961 if (++lpp->nextuserdef==16)
1962 lpp->nextuserdef=0;
1963 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
1964 break;
1966 case 0x2c9: /* resulting color */
1967 hdc=GetDC(hDlg);
1968 lpp->lpcc->rgbResult=GetNearestColor(hdc,lpp->lpcc->rgbResult);
1969 ReleaseDC(hDlg,hdc);
1970 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
1971 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1972 r=GetRValue(lpp->lpcc->rgbResult);
1973 g=GetGValue(lpp->lpcc->rgbResult);
1974 b=GetBValue(lpp->lpcc->rgbResult);
1975 lpp->h=CC_RGBtoHSL('H',r,g,b);
1976 lpp->s=CC_RGBtoHSL('S',r,g,b);
1977 lpp->l=CC_RGBtoHSL('L',r,g,b);
1978 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1979 CC_PaintCross(hDlg,lpp->h,lpp->s);
1980 CC_PaintTriangle(hDlg,lpp->l);
1981 break;
1983 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1984 i=RegisterWindowMessage32A( HELPMSGSTRING );
1985 if (lpp->lpcc->hwndOwner)
1986 SendMessage(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
1987 if (CC_HookCallChk(lpp->lpcc))
1988 CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,
1989 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
1990 break;
1992 case IDOK :
1993 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
1994 if (lpp->lpcc->hwndOwner)
1995 if (SendMessage(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
1996 break; /* do NOT close */
1998 EndDialog (hDlg, 1) ;
1999 return TRUE ;
2001 case IDCANCEL :
2002 EndDialog (hDlg, 0) ;
2003 return TRUE ;
2006 return FALSE;
2009 /***********************************************************************
2010 * CC_WMPaint [internal]
2012 static LRESULT CC_WMPaint(HWND hDlg, WPARAM wParam, LPARAM lParam)
2014 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
2015 /* we have to paint dialog children except text and buttons */
2017 CC_PaintPredefColorArray(hDlg,6,8);
2018 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2019 CC_PaintColorGraph(hDlg);
2020 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2021 CC_PaintCross(hDlg,lpp->h,lpp->s);
2022 CC_PaintTriangle(hDlg,lpp->l);
2023 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2025 /* special necessary for Wine */
2026 ValidateRect32(GetDlgItem(hDlg,0x2d0),NULL);
2027 ValidateRect32(GetDlgItem(hDlg,0x2d1),NULL);
2028 ValidateRect32(GetDlgItem(hDlg,0x2c6),NULL);
2029 ValidateRect32(GetDlgItem(hDlg,0x2be),NULL);
2030 ValidateRect32(GetDlgItem(hDlg,0x2c5),NULL);
2031 /* hope we can remove it later -->FIXME */
2032 return 0;
2036 /***********************************************************************
2037 * CC_WMLButtonDown [internal]
2039 static LRESULT CC_WMLButtonDown(HWND hDlg, WPARAM wParam, LPARAM lParam)
2041 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
2042 int r,g,b,i;
2043 i=0;
2044 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2045 i=1;
2046 else
2047 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2048 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2049 i=1;
2050 else
2051 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2052 i=2;
2053 else
2054 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2055 i=2;
2056 if (i==2)
2058 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2059 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2060 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2061 lpp->lpcc->rgbResult=RGB(r,g,b);
2063 if (i==1)
2065 r=GetRValue(lpp->lpcc->rgbResult);
2066 g=GetGValue(lpp->lpcc->rgbResult);
2067 b=GetBValue(lpp->lpcc->rgbResult);
2068 lpp->h=CC_RGBtoHSL('H',r,g,b);
2069 lpp->s=CC_RGBtoHSL('S',r,g,b);
2070 lpp->l=CC_RGBtoHSL('L',r,g,b);
2072 if (i)
2074 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2075 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2076 CC_PaintCross(hDlg,lpp->h,lpp->s);
2077 CC_PaintTriangle(hDlg,lpp->l);
2078 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2079 return TRUE;
2081 return FALSE;
2084 /***********************************************************************
2085 * ColorDlgProc (COMMDLG.8)
2087 LRESULT ColorDlgProc(HWND hDlg, UINT message,
2088 UINT wParam, LONG lParam)
2090 int res;
2091 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong(hDlg, DWL_USER);
2092 if (message!=WM_INITDIALOG)
2094 if (!lpp)
2095 return FALSE;
2096 res=0;
2097 if (CC_HookCallChk(lpp->lpcc))
2098 res=CallWindowProc16((FARPROC)lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2099 if (res)
2100 return res;
2103 /* FIXME: SetRGB message
2104 if (message && message==msetrgb)
2105 return HandleSetRGB(hDlg,lParam);
2108 switch (message)
2110 case WM_INITDIALOG:
2111 return CC_WMInitDialog(hDlg,wParam,lParam);
2112 case WM_NCDESTROY:
2113 DeleteDC(lpp->hdcMem);
2114 DeleteObject(lpp->hbmMem);
2115 free(lpp);
2116 SetWindowLong(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2117 break;
2118 case WM_COMMAND:
2119 if (CC_WMCommand(hDlg, wParam, lParam))
2120 return TRUE;
2121 break;
2122 case WM_PAINT:
2123 CC_WMPaint(hDlg, wParam, lParam);
2124 break;
2125 case WM_LBUTTONDBLCLK:
2126 if (CC_MouseCheckResultWindow(hDlg,lParam))
2127 return TRUE;
2128 break;
2129 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2130 break;
2131 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2132 break;
2133 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2134 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2135 return TRUE;
2136 break;
2138 return FALSE ;
2143 /***********************************************************************
2144 * ChooseFont (COMMDLG.15)
2146 BOOL ChooseFont(LPCHOOSEFONT lpChFont)
2148 HANDLE hInst, hDlgTmpl;
2149 BOOL bRet;
2150 dprintf_commdlg(stddeb,"ChoseFont\n");
2151 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_FONT );
2152 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2153 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChFont->hwndOwner,
2154 MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2155 (DWORD)lpChFont );
2156 SYSRES_FreeResource( hDlgTmpl );
2157 return bRet;
2161 #define TEXT_EXTRAS 4
2162 #define TEXT_COLORS 16
2164 static const COLORREF textcolors[TEXT_COLORS]=
2166 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2167 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2168 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2169 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2172 /***********************************************************************
2173 * CFn_HookCallChk [internal]
2175 static BOOL CFn_HookCallChk(LPCHOOSEFONT lpcf)
2177 if (lpcf)
2178 if(lpcf->Flags & CF_ENABLEHOOK)
2179 if (lpcf->lpfnHook)
2180 return TRUE;
2181 return FALSE;
2184 /***********************************************************************
2185 * FontFamilyEnumProc (COMMDLG.19)
2187 int FontFamilyEnumProc(LPLOGFONT lplf ,LPTEXTMETRIC lptm, int nFontType, LPARAM lParam)
2189 int i;
2190 WORD w;
2191 HWND hwnd=LOWORD(lParam);
2193 dprintf_commdlg(stddeb,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2194 lplf->lfFaceName,nFontType);
2195 i=SendMessage(hwnd,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(lplf->lfFaceName));
2196 if (i!=CB_ERR)
2198 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2199 SendMessage(hwnd, CB_SETITEMDATA,i,MAKELONG(nFontType,w));
2200 return 1 ;
2202 else
2203 return 0;
2206 /***********************************************************************
2207 * FontStyleEnumProc (COMMDLG.18)
2209 int FontStyleEnumProc(LPLOGFONT lplf ,LPTEXTMETRIC lptm, int nFontType, LPARAM lParam)
2211 int j;
2212 char buffer[20];
2213 /* HWND hcmb2=LOWORD(lParam);*/
2214 HWND hcmb3=HIWORD(lParam);
2215 LPLOGFONT lf=lplf;
2217 dprintf_commdlg(stddeb,"FontStyleEnumProc: (nFontType=%d)\n",nFontType);
2218 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",
2219 lf->lfFaceName,lf->lfHeight,lf->lfWidth,lf->lfEscapement,lf->lfOrientation,
2220 lf->lfWeight,lf->lfItalic,lf->lfUnderline,lf->lfStrikeOut,lf->lfCharSet,
2221 lf->lfOutPrecision,lf->lfClipPrecision,lf->lfQuality,lf->lfPitchAndFamily);
2223 #if 1 /* VERSION A: use some predefined height values */
2224 /* FIXME: if (!(nFontType & RASTER_FONTTYPE))......... */
2226 int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2227 int i;
2228 if (!SendMessage(hcmb3,CB_GETCOUNT,0,0))
2230 i=0;
2231 while (sizes[i])
2233 sprintf(buffer,"%d",sizes[i]);
2234 j=SendMessage(hcmb3,CB_INSERTSTRING,-1,(LPARAM)MAKE_SEGPTR(buffer));
2235 SendMessage(hcmb3, CB_SETITEMDATA, j, MAKELONG(sizes[i],0));
2236 i++;
2240 return 0;
2241 #endif
2243 #if 0 /* VERSION B: use only lplf->lfHeight values */
2245 if (lplf->lfHeight)
2247 sprintf(buffer,"%3d",lplf->lfHeight);
2248 j=SendMessage(hcmb3,CB_FINDSTRING,-1,(LPARAM)MAKE_SEGPTR(buffer));
2249 if (j==CB_ERR)
2251 j=SendMessage(hcmb3,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2252 SendMessage(hcmb3, CB_SETITEMDATA, j, MAKELONG(lplf->lfHeight,lplf->lfWidth));
2256 return 1 ;
2257 #endif
2262 /***********************************************************************
2263 * CFn_WMInitDialog [internal]
2265 LRESULT CFn_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam)
2267 HDC hdc;
2268 int i,j,res,init=0;
2269 long l;
2270 char buffer[32];
2271 FARPROC enumCallback = MODULE_GetWndProcEntry16("FontFamilyEnumProc");
2272 LPLOGFONT lpxx;
2273 HCURSOR hcursor=SetCursor(LoadCursor(0,IDC_WAIT));
2274 LPCHOOSEFONT lpcf;
2276 SetWindowLong(hDlg, DWL_USER, lParam);
2277 lpcf=(LPCHOOSEFONT)lParam;
2278 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2279 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
2281 if (lpcf->lStructSize != sizeof(CHOOSEFONT))
2283 dprintf_commdlg(stddeb,"WM_INITDIALOG: structure size failure !!!\n");
2284 EndDialog (hDlg, 0);
2285 return FALSE;
2287 if (!hBitmapTT)
2288 hBitmapTT = LoadBitmap(0, MAKEINTRESOURCE(OBM_TRTYPE));
2290 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow(lpcf->hwndOwner))
2291 ShowWindow(GetDlgItem(hDlg,pshHelp),SW_HIDE);
2292 if (!(lpcf->Flags & CF_APPLY))
2293 ShowWindow(GetDlgItem(hDlg,psh3),SW_HIDE);
2294 if (lpcf->Flags & CF_EFFECTS)
2296 for (res=1,i=0;res && i<TEXT_COLORS;i++)
2298 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2299 j=SendDlgItemMessage(hDlg,cmb4,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR("[color name]"));
2300 SendDlgItemMessage(hDlg,cmb4, CB_SETITEMDATA,j,textcolors[j]);
2301 /* look for a fitting value in color combobox */
2302 if (textcolors[j]==lpcf->rgbColors)
2303 SendDlgItemMessage(hDlg,cmb4, CB_SETCURSEL,j,0);
2306 else
2308 ShowWindow(GetDlgItem(hDlg,cmb4),SW_HIDE);
2309 ShowWindow(GetDlgItem(hDlg,chx1),SW_HIDE);
2310 ShowWindow(GetDlgItem(hDlg,chx2),SW_HIDE);
2311 ShowWindow(GetDlgItem(hDlg,grp1),SW_HIDE);
2312 ShowWindow(GetDlgItem(hDlg,stc4),SW_HIDE);
2315 /* perhaps this stuff should be moved to FontStyleEnumProc() ?? */
2316 strcpy(buffer,"Regular"); /* LoadString(hInst,.... ,buffer,LF_FACESIZE);*/
2317 j=SendDlgItemMessage(hDlg,cmb2,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2318 SendDlgItemMessage(hDlg,cmb2, CB_SETITEMDATA, j, MAKELONG(FW_NORMAL,0));
2319 strcpy(buffer,"Bold"); /* LoadString(hInst,.... ,buffer,LF_FACESIZE);*/
2320 j=SendDlgItemMessage(hDlg,cmb2,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2321 SendDlgItemMessage(hDlg,cmb2, CB_SETITEMDATA, j, MAKELONG(FW_BOLD,0));
2322 strcpy(buffer,"Italic"); /* LoadString(hInst,.... ,buffer,LF_FACESIZE);*/
2323 j=SendDlgItemMessage(hDlg,cmb2,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2324 SendDlgItemMessage(hDlg,cmb2, CB_SETITEMDATA, j, MAKELONG(FW_NORMAL,1));
2325 strcpy(buffer,"Bold Italic"); /* LoadString(hInst,.... ,buffer,LF_FACESIZE);*/
2326 j=SendDlgItemMessage(hDlg,cmb2,CB_ADDSTRING,0,(LPARAM)MAKE_SEGPTR(buffer));
2327 SendDlgItemMessage(hDlg,cmb2, CB_SETITEMDATA, j, MAKELONG(FW_BOLD,1));
2329 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
2330 if (hdc)
2332 if (!EnumFontFamilies (hdc, NULL,enumCallback,(LPARAM)GetDlgItem(hDlg,cmb1)))
2333 dprintf_commdlg(stddeb,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2334 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
2336 /* look for fitting font name in combobox1 */
2337 j=SendDlgItemMessage(hDlg,cmb1,CB_FINDSTRING,-1,(LONG)lpxx->lfFaceName);
2338 if (j!=CB_ERR)
2340 SendDlgItemMessage(hDlg,cmb1,CB_SETCURSEL,j,0);
2341 SendMessage(hDlg,WM_COMMAND,cmb1,MAKELONG(GetDlgItem(hDlg,cmb1),CBN_SELCHANGE));
2342 init=1;
2343 /* look for fitting font style in combobox2 */
2344 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
2345 for (i=0;i<TEXT_EXTRAS;i++)
2347 if (l==SendDlgItemMessage(hDlg,cmb2, CB_GETITEMDATA,i,0))
2348 SendDlgItemMessage(hDlg,cmb2,CB_SETCURSEL,i,0);
2351 /* look for fitting font size in combobox3 */
2352 j=SendDlgItemMessage(hDlg,cmb3,CB_GETCOUNT,0,0);
2353 for (i=0;i<j;i++)
2355 if (lpxx->lfHeight==(int)SendDlgItemMessage(hDlg,cmb3, CB_GETITEMDATA,i,0))
2356 SendDlgItemMessage(hDlg,cmb3,CB_SETCURSEL,i,0);
2359 if (!init)
2361 SendDlgItemMessage(hDlg,cmb1,CB_SETCURSEL,0,0);
2362 SendMessage(hDlg,WM_COMMAND,cmb1,MAKELONG(GetDlgItem(hDlg,cmb1),CBN_SELCHANGE));
2365 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
2367 j=SendDlgItemMessage(hDlg,cmb2,CB_FINDSTRING,-1,(LONG)lpcf->lpszStyle);
2368 if (j!=CB_ERR)
2370 j=SendDlgItemMessage(hDlg,cmb2,CB_SETCURSEL,j,0);
2371 SendMessage(hDlg,WM_COMMAND,cmb2,MAKELONG(GetDlgItem(hDlg,cmb2),CBN_SELCHANGE));
2375 else
2377 dprintf_commdlg(stddeb,"WM_INITDIALOG: HDC failure !!!\n");
2378 EndDialog (hDlg, 0);
2379 return FALSE;
2382 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2383 ReleaseDC(hDlg,hdc);
2384 res=TRUE;
2385 if (CFn_HookCallChk(lpcf))
2386 res=CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2387 SetCursor(hcursor);
2388 return res;
2392 /***********************************************************************
2393 * CFn_WMMeasureItem [internal]
2395 LRESULT CFn_WMMeasureItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
2397 BITMAP bm;
2398 LPMEASUREITEMSTRUCT lpmi=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT)lParam);
2399 if (!hBitmapTT)
2400 hBitmapTT = LoadBitmap(0, MAKEINTRESOURCE(OBM_TRTYPE));
2401 GetObject(hBitmapTT, sizeof(BITMAP), (LPSTR)&bm);
2402 lpmi->itemHeight=bm.bmHeight;
2403 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2404 return 0;
2408 /***********************************************************************
2409 * CFn_WMDrawItem [internal]
2411 LRESULT CFn_WMDrawItem(HWND hDlg, WPARAM wParam, LPARAM lParam)
2413 HBRUSH hBrush;
2414 char buffer[40];
2415 BITMAP bm;
2416 COLORREF cr;
2417 RECT16 rect;
2418 #if 0
2419 HDC hMemDC;
2420 int nFontType;
2421 HBITMAP hBitmap; /* for later TT usage */
2422 #endif
2423 LPDRAWITEMSTRUCT16 lpdi = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
2425 if (lpdi->itemID == 0xFFFF) /* got no items */
2426 DrawFocusRect16(lpdi->hDC, &lpdi->rcItem);
2427 else
2429 if (lpdi->CtlType == ODT_COMBOBOX)
2431 hBrush = SelectObject(lpdi->hDC, GetStockObject(LTGRAY_BRUSH));
2432 SelectObject(lpdi->hDC, hBrush);
2433 FillRect16(lpdi->hDC, &lpdi->rcItem, hBrush);
2435 else
2436 return TRUE; /* this should never happen */
2438 rect=lpdi->rcItem;
2439 switch (lpdi->CtlID)
2441 case cmb1: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2442 SendMessage(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2443 (LPARAM)MAKE_SEGPTR(buffer));
2444 GetObject(hBitmapTT, sizeof(BITMAP), (LPSTR)&bm);
2445 TextOut16(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
2446 lpdi->rcItem.top, buffer, lstrlen(buffer));
2447 #if 0
2448 nFontType = SendMessage(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
2449 /* FIXME: draw bitmap if truetype usage */
2450 if (nFontType&TRUETYPE_FONTTYPE)
2452 hMemDC = CreateCompatibleDC(lpdi->hDC);
2453 hBitmap = SelectObject(hMemDC, hBitmapTT);
2454 BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
2455 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
2456 SelectObject(hMemDC, hBitmap);
2457 DeleteDC(hMemDC);
2459 #endif
2460 break;
2461 case cmb2:
2462 case cmb3: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2463 SendMessage(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2464 (LPARAM)MAKE_SEGPTR(buffer));
2465 TextOut16(lpdi->hDC, lpdi->rcItem.left,
2466 lpdi->rcItem.top, buffer, lstrlen(buffer));
2467 break;
2469 case cmb4: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2470 SendMessage(lpdi->hwndItem, CB_GETLBTEXT, lpdi->itemID,
2471 (LPARAM)MAKE_SEGPTR(buffer));
2472 TextOut16(lpdi->hDC, lpdi->rcItem.left + 25+5,
2473 lpdi->rcItem.top, buffer, lstrlen(buffer));
2474 cr = SendMessage(lpdi->hwndItem, CB_GETITEMDATA, lpdi->itemID,0L);
2475 hBrush = CreateSolidBrush(cr);
2476 if (hBrush)
2478 hBrush = SelectObject (lpdi->hDC, hBrush) ;
2479 rect.right=rect.left+25;
2480 rect.top++;
2481 rect.left+=5;
2482 rect.bottom--;
2483 Rectangle(lpdi->hDC,rect.left,rect.top,rect.right,rect.bottom);
2484 DeleteObject (SelectObject (lpdi->hDC, hBrush)) ;
2486 rect=lpdi->rcItem;
2487 rect.left+=25+5;
2488 break;
2490 default: return TRUE; /* this should never happen */
2492 if (lpdi->itemState ==ODS_SELECTED)
2493 InvertRect16(lpdi->hDC, &rect);
2495 return TRUE;
2498 /***********************************************************************
2499 * CFn_WMCtlColor [internal]
2501 LRESULT CFn_WMCtlColor(HWND hDlg, WPARAM wParam, LPARAM lParam)
2503 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong(hDlg, DWL_USER);
2505 if (lpcf->Flags & CF_EFFECTS)
2506 if (HIWORD(lParam)==CTLCOLOR_STATIC && GetDlgCtrlID(LOWORD(lParam))==stc6)
2508 SetTextColor(wParam,lpcf->rgbColors);
2509 return GetStockObject(WHITE_BRUSH);
2511 return 0;
2514 /***********************************************************************
2515 * CFn_WMCommand [internal]
2517 LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam)
2519 char buffer[200];
2520 FARPROC enumCallback;
2521 HFONT hFont/*,hFontOld*/;
2522 int i,j;
2523 long l;
2524 HDC hdc;
2525 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong(hDlg, DWL_USER);
2526 LPLOGFONT lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2528 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam);
2529 switch (wParam)
2531 case cmb1:if (HIWORD(lParam)==CBN_SELCHANGE)
2533 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC(hDlg);
2534 if (hdc)
2536 /* only if cmb2 is refilled in FontStyleEnumProc():
2537 SendDlgItemMessage(hDlg,cmb2,CB_RESETCONTENT,0,0);
2539 SendDlgItemMessage(hDlg,cmb3,CB_RESETCONTENT,0,0);
2540 i=SendDlgItemMessage(hDlg,cmb1,CB_GETCURSEL,0,0);
2541 if (i!=CB_ERR)
2543 HCURSOR hcursor=SetCursor(LoadCursor(0,IDC_WAIT));
2544 SendDlgItemMessage(hDlg,cmb1,CB_GETLBTEXT,i,(LPARAM)MAKE_SEGPTR(buffer));
2545 dprintf_commdlg(stddeb,"WM_COMMAND/cmb1 =>%s\n",buffer);
2546 enumCallback = MODULE_GetWndProcEntry16("FontStyleEnumProc");
2547 EnumFontFamilies(hdc,buffer,enumCallback,
2548 MAKELONG(GetDlgItem(hDlg,cmb2),GetDlgItem(hDlg,cmb3)));
2549 SetCursor(hcursor);
2551 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2552 ReleaseDC(hDlg,hdc);
2554 else
2556 dprintf_commdlg(stddeb,"WM_COMMAND: HDC failure !!!\n");
2557 EndDialog (hDlg, 0);
2558 return TRUE;
2561 case chx1:
2562 case chx2:
2563 case cmb2:
2564 case cmb3:if (HIWORD(lParam)==CBN_SELCHANGE || HIWORD(lParam)== BN_CLICKED )
2566 dprintf_commdlg(stddeb,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
2567 i=SendDlgItemMessage(hDlg,cmb1,CB_GETCURSEL,0,0);
2568 if (i==CB_ERR)
2569 i=SendDlgItemMessage(hDlg,cmb1,WM_GETTEXT,20,(LPARAM)MAKE_SEGPTR(buffer));
2570 else
2572 SendDlgItemMessage(hDlg,cmb1,CB_GETLBTEXT,i,(LPARAM)MAKE_SEGPTR(buffer));
2573 l=SendDlgItemMessage(hDlg,cmb1,CB_GETITEMDATA,i,0);
2574 j=HIWORD(l);
2575 lpcf->nFontType = LOWORD(l);
2576 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2577 /* same value reported to the EnumFonts
2578 call back with the extra FONTTYPE_... bits added */
2579 lpxx->lfPitchAndFamily=j&0xff;
2580 lpxx->lfCharSet=j>>8;
2582 strcpy(lpxx->lfFaceName,buffer);
2583 i=SendDlgItemMessage(hDlg,cmb2,CB_GETCURSEL,0,0);
2584 if (i!=CB_ERR)
2586 l=SendDlgItemMessage(hDlg,cmb2,CB_GETITEMDATA,i,0);
2587 if (0!=(lpxx->lfItalic=HIWORD(l)))
2588 lpcf->nFontType |= ITALIC_FONTTYPE;
2589 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
2590 lpcf->nFontType |= BOLD_FONTTYPE;
2592 i=SendDlgItemMessage(hDlg,cmb3,CB_GETCURSEL,0,0);
2593 if (i!=CB_ERR)
2595 l=SendDlgItemMessage(hDlg,cmb3,CB_GETITEMDATA,i,0);
2596 lpxx->lfHeight=-LOWORD(l);
2597 lpxx->lfWidth = 0; /* FYI: lfWidth is in HIWORD(l); */
2599 lpxx->lfStrikeOut=IsDlgButtonChecked(hDlg,chx1);
2600 lpxx->lfUnderline=IsDlgButtonChecked(hDlg,chx2);
2601 lpxx->lfOrientation=lpxx->lfEscapement=0;
2602 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
2603 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
2604 lpxx->lfQuality=DEFAULT_QUALITY;
2606 hFont=CreateFontIndirect(lpxx);
2607 if (hFont)
2608 SendDlgItemMessage(hDlg,stc6,WM_SETFONT,hFont,TRUE);
2609 /* FIXME: Delete old font ...? */
2611 break;
2613 case cmb4:i=SendDlgItemMessage(hDlg,cmb4,CB_GETCURSEL,0,0);
2614 if (i!=CB_ERR)
2616 lpcf->rgbColors=textcolors[i];
2617 InvalidateRect32( GetDlgItem(hDlg,stc6), NULL, 0 );
2619 break;
2621 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
2622 if (lpcf->hwndOwner)
2623 SendMessage(lpcf->hwndOwner,i,0,(LPARAM)lpcf);
2624 if (CFn_HookCallChk(lpcf))
2625 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);
2626 break;
2628 case IDOK:EndDialog(hDlg, TRUE);
2629 return(TRUE);
2630 case IDCANCEL:EndDialog(hDlg, FALSE);
2631 return(TRUE);
2633 return(FALSE);
2637 /***********************************************************************
2638 * FormatCharDlgProc (COMMDLG.16)
2639 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2640 2. some CF_.. flags are not supported
2641 3. some TType extensions
2643 LRESULT FormatCharDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
2645 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong(hDlg, DWL_USER);
2646 if (message!=WM_INITDIALOG)
2648 int res=0;
2649 if (!lpcf)
2650 return FALSE;
2651 if (CFn_HookCallChk(lpcf))
2652 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
2653 if (res)
2654 return res;
2656 else
2657 return CFn_WMInitDialog(hDlg,wParam,lParam);
2658 switch (message)
2660 case WM_MEASUREITEM:
2661 return CFn_WMMeasureItem(hDlg,wParam,lParam);
2662 case WM_DRAWITEM:
2663 return CFn_WMDrawItem(hDlg,wParam,lParam);
2664 case WM_CTLCOLOR:
2665 return CFn_WMCtlColor(hDlg,wParam,lParam);
2666 case WM_COMMAND:
2667 return CFn_WMCommand(hDlg,wParam,lParam);
2668 case WM_CHOOSEFONT_GETLOGFONT:
2669 /* FIXME: current logfont back to caller */
2670 break;
2672 return FALSE;