4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
20 #include "stackframe.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;
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 !");
57 /***********************************************************************
58 * GetOpenFileName (COMMDLG.1)
60 BOOL
GetOpenFileName(LPOPENFILENAME lpofn
)
63 HANDLE hDlgTmpl
, hResInfo
;
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
;
77 hDlgTmpl
= LoadResource( lpofn
->hInstance
, hResInfo
);
79 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_OPEN_FILE
);
82 CommDlgLastError
= CDERR_LOADRESFAILURE
;
86 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
87 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpofn
->hwndOwner
,
88 MODULE_GetWndProcEntry16("FileOpenDlgProc"),
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
));
103 /***********************************************************************
104 * GetSaveFileName (COMMDLG.2)
106 BOOL
GetSaveFileName(LPOPENFILENAME lpofn
)
109 HANDLE hDlgTmpl
, hResInfo
;
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
;
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"),
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
));
143 /***********************************************************************
144 * FILEDLG_StripEditControl [internal]
145 * Strip pathnames off the contents of the edit control.
147 static void FILEDLG_StripEditControl(HWND hwnd
)
151 SendDlgItemMessage(hwnd
, edt1
, WM_GETTEXT
, 511, (LPARAM
)MAKE_SEGPTR(temp
));
152 cp
= strrchr(temp
, '\\');
156 cp
= strrchr(temp
, ':');
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);
178 /***********************************************************************
179 * FILEDLG_GetFileType [internal]
182 static LPSTR
FILEDLG_GetFileType(LPSTR cfptr
, LPSTR fptr
, WORD index
)
187 for ( ;(n
= strlen(cfptr
)) != 0; i
++)
192 cfptr
+= strlen(cfptr
) + 1;
195 for ( ;(n
= strlen(fptr
)) != 0; i
++)
200 fptr
+= strlen(fptr
) + 1;
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
);
213 HBITMAP hBitmap
, hPrevBitmap
;
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
,
226 if (lpdis
->itemState
!= 0) {
227 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
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
));
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
);
249 if (lpdis
->itemState
!= 0) {
250 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
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;
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
);
277 if (lpdis
->itemState
!= 0) {
278 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
285 /***********************************************************************
286 * FILEDLG_WMMeasureItem [internal]
288 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
291 LPMEASUREITEMSTRUCT lpmeasure
;
293 GetObject(hFolder2
, sizeof(BITMAP
), (LPSTR
)&bm
);
294 lpmeasure
= (LPMEASUREITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
295 lpmeasure
->itemHeight
= bm
.bmHeight
;
299 /***********************************************************************
300 * FILEDLG_HookCallChk [internal]
302 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn
)
305 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
311 /***********************************************************************
312 * FILEDLG_WMInitDialog [internal]
315 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
319 LPOPENFILENAME lpofn
;
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
);
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
));
339 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
340 SendDlgItemMessage(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
344 /* read filter information */
345 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
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
));
354 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
355 SendDlgItemMessage(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
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);
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
));
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);
376 if (strlen(tmpstr
) > 0 && tmpstr
[strlen(tmpstr
)-1] != '\\'
377 && tmpstr
[strlen(tmpstr
)-1] != ':')
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
));
398 /***********************************************************************
399 * FILEDLG_WMCommand [internal]
401 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
404 LPOPENFILENAME lpofn
;
406 char tmpstr
[512], tmpstr2
[512];
408 UINT control
,notification
;
410 /* Notifications are packaged differently in Win32 */
412 control
= LOWORD(wParam
);
413 notification
= HIWORD(wParam
);
416 notification
= HIWORD(lParam
);
419 lpofn
= (LPOPENFILENAME
)GetWindowLong(hWnd
, DWL_USER
);
422 case lst1
: /* file list */
423 FILEDLG_StripEditControl(hWnd
);
424 if (notification
== LBN_DBLCLK
)
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 */
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
, "\\");
455 case cmb1
: /* file type drop list */
456 if (notification
== CBN_SELCHANGE
)
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]);
469 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
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
);
484 ofn2
=*lpofn
; /* for later restoring */
485 SendDlgItemMessage(hWnd
, edt1
, WM_GETTEXT
, 511, (LPARAM
)MAKE_SEGPTR(tmpstr
));
486 pstr
= strrchr(tmpstr
, '\\');
488 pstr
= strrchr(tmpstr
, ':');
489 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
491 /* edit control contains wildcards */
494 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
499 strcpy(tmpstr2
, tmpstr
);
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
);
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
);
517 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
518 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
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 */
528 /* strip off the pathname */
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
);
537 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
539 ShowWindow(hWnd
, SW_HIDE
); /* this should not be necessary ?! (%%%) */
542 int drive
= DRIVE_GetCurrentDrive();
543 tmpstr2
[0] = 'A'+ drive
;
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;
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
));
575 *lpofn
=ofn2
; /* restore old state */
577 ShowWindow(hWnd
, SW_SHOW
); /* only if above (%%%) SW_HIDE used */
582 EndDialog(hWnd
, TRUE
);
585 EndDialog(hWnd
, 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
);
604 return lRet
; /* else continue message processing */
609 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
611 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
613 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
);
615 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
618 SetBkColor((HDC
)wParam
, 0x00C0C0C0);
619 switch (HIWORD(lParam
))
622 SetTextColor((HDC
)wParam
, 0x00000000);
624 case CTLCOLOR_STATIC
:
625 SetTextColor((HDC
)wParam
, 0x00000000);
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
);
647 return lRet
; /* else continue message processing */
651 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
654 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
657 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
);
660 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
665 SetBkColor((HDC)wParam, 0x00C0C0C0);
666 switch (HIWORD(lParam))
669 SetTextColor((HDC)wParam, 0x00000000);
671 case CTLCOLOR_STATIC:
672 SetTextColor((HDC)wParam, 0x00000000);
682 /***********************************************************************
683 * ChooseColor (COMMDLG.5)
685 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
687 HANDLE hInst
, hDlgTmpl
;
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"),
695 SYSRES_FreeResource( hDlgTmpl
);
700 /***********************************************************************
701 * FindTextDlg (COMMDLG.11)
703 BOOL
FindText(LPFINDREPLACE lpFind
)
705 HANDLE hInst
, hDlgTmpl
;
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"),
723 GlobalUnlock16( hDlgTmpl
);
724 SYSRES_FreeResource( hDlgTmpl
);
729 /***********************************************************************
730 * ReplaceTextDlg (COMMDLG.12)
732 BOOL
ReplaceText(LPFINDREPLACE lpFind
)
734 HANDLE hInst
, hDlgTmpl
;
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"),
752 GlobalUnlock16( hDlgTmpl
);
753 SYSRES_FreeResource( hDlgTmpl
);
758 /***********************************************************************
759 * FINDDLG_WMInitDialog [internal]
761 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
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
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
);
803 /***********************************************************************
804 * FINDDLG_WMCommand [internal]
806 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
809 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
810 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
812 lpfr
= (LPFINDREPLACE
)GetWindowLong(hWnd
, DWL_USER
);
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
));
830 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
831 lpfr
->Flags
|= FR_DIALOGTERM
;
832 SendMessage(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
836 /* FIXME : should lpfr structure be passed as an argument ??? */
837 SendMessage(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
844 /***********************************************************************
845 * FindTextDlgProc (COMMDLG.13)
847 LRESULT
FindTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
851 return FINDDLG_WMInitDialog(hWnd
, wParam
, lParam
);
853 return FINDDLG_WMCommand(hWnd
, wParam
, lParam
);
859 /***********************************************************************
860 * REPLACEDLG_WMInitDialog [internal]
862 static LRESULT
REPLACEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
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
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
);
895 /***********************************************************************
896 * REPLACEDLG_WMCommand [internal]
898 static LRESULT
REPLACEDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
901 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
902 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
904 lpfr
= (LPFINDREPLACE
)GetWindowLong(hWnd
, DWL_USER
);
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
));
920 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
921 lpfr
->Flags
|= FR_DIALOGTERM
;
922 SendMessage(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
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
));
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
));
952 /* FIXME : should lpfr structure be passed as an argument ??? */
953 SendMessage(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
960 /***********************************************************************
961 * ReplaceTextDlgProc (COMMDLG.14)
963 LRESULT
ReplaceTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
967 return REPLACEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
969 return REPLACEDLG_WMCommand(hWnd
, wParam
, lParam
);
975 /***********************************************************************
976 * PrintDlg (COMMDLG.20)
978 BOOL
PrintDlg(LPPRINTDLG lpPrint
)
980 HANDLE hInst
, hDlgTmpl
;
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 */
989 if (lpPrint
->Flags
& PD_PRINTSETUP
)
990 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP
);
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"),
1000 SYSRES_FreeResource( hDlgTmpl
);
1005 /***********************************************************************
1006 * PrintDlgProc (COMMDLG.21)
1008 LRESULT
PrintDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
1013 dprintf_commdlg(stddeb
,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1014 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1020 EndDialog(hWnd
, TRUE
);
1023 EndDialog(hWnd
, FALSE
);
1032 /***********************************************************************
1033 * PrintSetupDlgProc (COMMDLG.22)
1035 LRESULT
PrintSetupDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
1040 dprintf_commdlg(stddeb
,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1041 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1046 EndDialog(hWnd
, TRUE
);
1049 EndDialog(hWnd
, 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
)
1073 dprintf_commdlg(stddeb
,"GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
1074 if (lpFile
== NULL
|| lpTitle
== NULL
)
1076 len
= strlen(lpFile
);
1079 if (strpbrk(lpFile
, "*[]"))
1082 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
1084 for (i
= len
; i
>= 0; i
--)
1085 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
1090 dprintf_commdlg(stddeb
,"\n---> '%s' ", &lpFile
[i
]);
1092 len
= strlen(lpFile
+i
)+1;
1096 strncpy(lpTitle
, &lpFile
[i
], len
);
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
},
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 */
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
)
1147 case 'R':if (hue
>80) hue
-=80; else hue
+=160; break;
1148 case 'G':if (hue
>160) hue
-=160; else hue
+=80; break;
1153 maxrgb
=(256*MIN(120,lum
))/120; /* 0 .. 256 */
1159 res
=(hue
-80)* maxrgb
; /* 0...10240 */
1160 res
/=40; /* 0...256 */
1167 res
=(240-hue
)* maxrgb
;
1170 res
=res
-maxrgb
/2; /* -128...128 */
1173 res
=maxrgb
/2 + (sat
*res
) /240; /* 0..256 */
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;
1201 case 'L':mmsum
*=120; /* 0...61200=(255+255)*120 */
1202 result
=mmsum
/255; /* 0...240 */
1205 case 'S':if (!mmsum
)
1208 if (!mini
|| maxi
==255)
1212 result
=mmdif
*240; /* 0...61200=255*240 */
1213 result
/= (mmsum
>255 ? mmsum
=510-mmsum
: mmsum
); /* 0..255 */
1217 case 'H':if (!mmdif
)
1223 iresult
=40*(g
-b
); /* -10200 ... 10200 */
1224 iresult
/=(int)mmdif
; /* -40 .. 40 */
1226 iresult
+=240; /* 0..40 and 200..240 */
1232 iresult
/=(int)mmdif
;
1233 iresult
+=80; /* 40 .. 120 */
1239 iresult
/=(int)mmdif
;
1240 iresult
+=160; /* 120 .. 200 */
1246 return result
; /* is this integer arithmetic precise enough ? */
1251 /***********************************************************************
1252 * CC_MouseCheckPredefColorArray [internal]
1254 static int CC_MouseCheckPredefColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1255 LPARAM lParam
,COLORREF
*cr
)
1258 POINT16 point
= MAKEPOINT16(lParam
);
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
))
1275 *cr
=predefcolors
[y
][x
];
1276 /* FIXME: Draw_a_Focus_Rect() */
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
)
1290 POINT16 point
= MAKEPOINT16(lParam
);
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
))
1307 *cr
=crarr
[x
+cols
*y
];
1308 /* FIXME: Draw_a_Focus_Rect() */
1318 /* 240 ^...... ^^ 240
1325 /***********************************************************************
1326 * CC_MouseCheckColorGraph [internal]
1328 static int CC_MouseCheckColorGraph(HWND hDlg
,int dlgitem
,int *hori
,int *vert
,LPARAM lParam
)
1331 POINT16 point
= MAKEPOINT16(lParam
);
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
;
1345 y
=(long)(rect
.bottom
-point
.y
)*MAXVERT
;
1357 /***********************************************************************
1358 * CC_MouseCheckResultWindow [internal]
1360 static int CC_MouseCheckResultWindow(HWND hDlg
,LPARAM lParam
)
1363 POINT16 point
= MAKEPOINT16(lParam
);
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);
1377 /***********************************************************************
1378 * CC_CheckDigitsInEdit [internal]
1380 static int CC_CheckDigitsInEdit(HWND hwnd
,int maxval
)
1382 int i
,k
,m
,result
,value
;
1385 GetWindowText(hwnd
,buffer
,30-1);
1390 if (buffer
[i
]<'0' || buffer
[i
]>'9')
1392 for (k
=i
+1;k
<=m
;k
++) /* delete bad character */
1394 buffer
[i
]=buffer
[k
];
1402 if (value
>maxval
) /* build a new string */
1404 sprintf(buffer
,"%d",maxval
);
1409 editpos
=SendMessage(hwnd
,EM_GETSEL
,0,0);
1410 SetWindowText(hwnd
,buffer
);
1411 SendMessage(hwnd
,EM_SETSEL
,0,editpos
);
1418 /***********************************************************************
1419 * CC_PaintSelectedColor [internal]
1421 static void CC_PaintSelectedColor(HWND hDlg
,COLORREF cr
)
1426 HWND hwnd
=GetDlgItem(hDlg
,0x2c5);
1427 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1430 GetClientRect16 (hwnd
, &rect
) ;
1431 hBrush
= CreateSolidBrush(cr
);
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
));
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
)
1456 int w
=GetDialogBaseUnits();
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
);
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
; /* | \ | */
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
)
1500 int w
=GetDialogBaseUnits();
1501 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1502 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1507 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1509 GetClientRect16(hwnd
,&rect
);
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
);
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
);
1551 HCURSOR hcursor
=SetCursor(LoadCursor(0,IDC_WAIT
));
1553 GetClientRect16(hwnd
,&client
);
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;
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
);
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
);
1593 if (IsWindowVisible(hwnd
)) /* if full size */
1596 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
1599 GetClientRect16(hwnd
,&rect
);
1601 BitBlt(hDC
,0,0,rect
.right
,rect
.bottom
,lpp
->hdcMem
,0,0,SRCCOPY
);
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);
1614 int lum
,ldif
,ydif
,r
,g
,b
;
1618 if (IsWindowVisible(hwnd
))
1621 GetClientRect16(hwnd
,&client
);
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
)
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 */
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
)
1672 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1674 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
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
)
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
);
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);
1728 GetClientRect16(hwnd
,&rect
);
1730 dy
=rect
.bottom
/rows
;
1734 GetClientRect16 (hwnd
, &rect
) ;
1736 for (j
=0;j
<rows
;j
++)
1738 for (i
=0;i
<cols
;i
++)
1740 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
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
;
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);
1767 GetClientRect16(hwnd
,&rect
);
1770 dy
=rect
.bottom
/rows
;
1776 for (j
=0;j
<rows
;j
++)
1778 for (i
=0;i
<cols
;i
++)
1780 hBrush
= CreateSolidBrush(lpcr
[i
+j
*cols
]);
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
;
1793 ReleaseDC(hwnd
,hdc
);
1795 /* FIXME: draw_a_focus_rect */
1800 /***********************************************************************
1801 * CC_HookCallChk [internal]
1803 static BOOL
CC_HookCallChk(LPCHOOSECOLOR lpcc
)
1806 if(lpcc
->Flags
& CC_ENABLEHOOK
)
1812 /***********************************************************************
1813 * CC_WMInitDialog [internal]
1815 static LONG
CC_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
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) ;
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
);
1837 cpos
=MAKELONG(5,7); /* init */
1838 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
1842 if (predefcolors
[i
][j
]==lpp
->lpcc
->rgbResult
)
1849 /* FIXME: Draw_a_focus_rect & set_init_values */
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
)
1860 res
=rect
.bottom
-rect
.top
;
1861 hwnd
=GetDlgItem(hDlg
,0x2c6); /* cut at left border */
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
);
1873 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,NULL
);
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
);
1882 /***********************************************************************
1883 * CC_WMCommand [internal]
1885 static LRESULT
CC_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1891 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1892 dprintf_commdlg(stddeb
,"CC_WMCommand wParam=%x lParam=%lx\n",wParam
,lParam
);
1895 case 0x2c2: /* edit notify RGB */
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
);
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
);
1925 case 0x2bf: /* edit notify HSL */
1928 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1930 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),wParam
==0x2bf?239:240);
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
);
1953 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,&lpp
->fullsize
);
1954 InvalidateRect32( hDlg
, NULL
, TRUE
);
1955 SetFocus(GetDlgItem(hDlg
,0x2bf));
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)
1963 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
1966 case 0x2c9: /* resulting color */
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
);
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
);
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) ;
2002 EndDialog (hDlg
, 0) ;
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 */
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
);
2044 if (CC_MouseCheckPredefColorArray(hDlg
,0x2d0,6,8,lParam
,&lpp
->lpcc
->rgbResult
))
2047 if (CC_MouseCheckUserColorArray(hDlg
,0x2d1,2,8,lParam
,&lpp
->lpcc
->rgbResult
,
2048 PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
)))
2051 if (CC_MouseCheckColorGraph(hDlg
,0x2c6,&lpp
->h
,&lpp
->s
,lParam
))
2054 if (CC_MouseCheckColorGraph(hDlg
,0x2be,NULL
,&lpp
->l
,lParam
))
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
);
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
);
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
);
2084 /***********************************************************************
2085 * ColorDlgProc (COMMDLG.8)
2087 LRESULT
ColorDlgProc(HWND hDlg
, UINT message
,
2088 UINT wParam
, LONG lParam
)
2091 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
2092 if (message
!=WM_INITDIALOG
)
2097 if (CC_HookCallChk(lpp
->lpcc
))
2098 res
=CallWindowProc16((FARPROC
)lpp
->lpcc
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2103 /* FIXME: SetRGB message
2104 if (message && message==msetrgb)
2105 return HandleSetRGB(hDlg,lParam);
2111 return CC_WMInitDialog(hDlg
,wParam
,lParam
);
2113 DeleteDC(lpp
->hdcMem
);
2114 DeleteObject(lpp
->hbmMem
);
2116 SetWindowLong(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
2119 if (CC_WMCommand(hDlg
, wParam
, lParam
))
2123 CC_WMPaint(hDlg
, wParam
, lParam
);
2125 case WM_LBUTTONDBLCLK
:
2126 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
2129 case WM_MOUSEMOVE
: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2131 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
2133 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
2134 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
2143 /***********************************************************************
2144 * ChooseFont (COMMDLG.15)
2146 BOOL
ChooseFont(LPCHOOSEFONT lpChFont
)
2148 HANDLE hInst
, hDlgTmpl
;
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"),
2156 SYSRES_FreeResource( hDlgTmpl
);
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
)
2178 if(lpcf
->Flags
& CF_ENABLEHOOK
)
2184 /***********************************************************************
2185 * FontFamilyEnumProc (COMMDLG.19)
2187 int FontFamilyEnumProc(LPLOGFONT lplf
,LPTEXTMETRIC lptm
, int nFontType
, LPARAM lParam
)
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
));
2198 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
2199 SendMessage(hwnd
, CB_SETITEMDATA
,i
,MAKELONG(nFontType
,w
));
2206 /***********************************************************************
2207 * FontStyleEnumProc (COMMDLG.18)
2209 int FontStyleEnumProc(LPLOGFONT lplf
,LPTEXTMETRIC lptm
, int nFontType
, LPARAM lParam
)
2213 /* HWND hcmb2=LOWORD(lParam);*/
2214 HWND hcmb3
=HIWORD(lParam
);
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};
2228 if (!SendMessage(hcmb3
,CB_GETCOUNT
,0,0))
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));
2243 #if 0 /* VERSION B: use only lplf->lfHeight values */
2247 sprintf(buffer
,"%3d",lplf
->lfHeight
);
2248 j
=SendMessage(hcmb3
,CB_FINDSTRING
,-1,(LPARAM
)MAKE_SEGPTR(buffer
));
2251 j
=SendMessage(hcmb3
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR(buffer
));
2252 SendMessage(hcmb3
, CB_SETITEMDATA
, j
, MAKELONG(lplf
->lfHeight
,lplf
->lfWidth
));
2262 /***********************************************************************
2263 * CFn_WMInitDialog [internal]
2265 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2271 FARPROC enumCallback
= MODULE_GetWndProcEntry16("FontFamilyEnumProc");
2273 HCURSOR hcursor
=SetCursor(LoadCursor(0,IDC_WAIT
));
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);
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);
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
);
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
);
2340 SendDlgItemMessage(hDlg
,cmb1
,CB_SETCURSEL
,j
,0);
2341 SendMessage(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
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);
2355 if (lpxx
->lfHeight
==(int)SendDlgItemMessage(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
2356 SendDlgItemMessage(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
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
);
2370 j
=SendDlgItemMessage(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
2371 SendMessage(hDlg
,WM_COMMAND
,cmb2
,MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
2377 dprintf_commdlg(stddeb
,"WM_INITDIALOG: HDC failure !!!\n");
2378 EndDialog (hDlg
, 0);
2382 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2383 ReleaseDC(hDlg
,hdc
);
2385 if (CFn_HookCallChk(lpcf
))
2386 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
2392 /***********************************************************************
2393 * CFn_WMMeasureItem [internal]
2395 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2398 LPMEASUREITEMSTRUCT lpmi
=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT
)lParam
);
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 .*/
2408 /***********************************************************************
2409 * CFn_WMDrawItem [internal]
2411 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2421 HBITMAP hBitmap
; /* for later TT usage */
2423 LPDRAWITEMSTRUCT16 lpdi
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
2425 if (lpdi
->itemID
== 0xFFFF) /* got no items */
2426 DrawFocusRect16(lpdi
->hDC
, &lpdi
->rcItem
);
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
);
2436 return TRUE
; /* this should never happen */
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
));
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
);
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
));
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
);
2478 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
2479 rect
.right
=rect
.left
+25;
2483 Rectangle(lpdi
->hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
2484 DeleteObject (SelectObject (lpdi
->hDC
, hBrush
)) ;
2490 default: return TRUE
; /* this should never happen */
2492 if (lpdi
->itemState
==ODS_SELECTED
)
2493 InvertRect16(lpdi
->hDC
, &rect
);
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
);
2514 /***********************************************************************
2515 * CFn_WMCommand [internal]
2517 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2520 FARPROC enumCallback
;
2521 HFONT hFont
/*,hFontOld*/;
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
);
2531 case cmb1
:if (HIWORD(lParam
)==CBN_SELCHANGE
)
2533 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
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);
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
)));
2551 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2552 ReleaseDC(hDlg
,hdc
);
2556 dprintf_commdlg(stddeb
,"WM_COMMAND: HDC failure !!!\n");
2557 EndDialog (hDlg
, 0);
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);
2569 i
=SendDlgItemMessage(hDlg
,cmb1
,WM_GETTEXT
,20,(LPARAM
)MAKE_SEGPTR(buffer
));
2572 SendDlgItemMessage(hDlg
,cmb1
,CB_GETLBTEXT
,i
,(LPARAM
)MAKE_SEGPTR(buffer
));
2573 l
=SendDlgItemMessage(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
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);
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);
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
);
2608 SendDlgItemMessage(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
2609 /* FIXME: Delete old font ...? */
2613 case cmb4
:i
=SendDlgItemMessage(hDlg
,cmb4
,CB_GETCURSEL
,0,0);
2616 lpcf
->rgbColors
=textcolors
[i
];
2617 InvalidateRect32( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
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
);
2628 case IDOK
:EndDialog(hDlg
, TRUE
);
2630 case IDCANCEL
:EndDialog(hDlg
, 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
)
2651 if (CFn_HookCallChk(lpcf
))
2652 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2657 return CFn_WMInitDialog(hDlg
,wParam
,lParam
);
2660 case WM_MEASUREITEM
:
2661 return CFn_WMMeasureItem(hDlg
,wParam
,lParam
);
2663 return CFn_WMDrawItem(hDlg
,wParam
,lParam
);
2665 return CFn_WMCtlColor(hDlg
,wParam
,lParam
);
2667 return CFn_WMCommand(hDlg
,wParam
,lParam
);
2668 case WM_CHOOSEFONT_GETLOGFONT
:
2669 /* FIXME: current logfont back to caller */