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 GetDlgItemText32A( hwnd
, edt1
, temp
, sizeof(temp
) );
152 cp
= strrchr(temp
, '\\');
156 cp
= strrchr(temp
, ':');
160 /* FIXME: shouldn't we do something with the result here? ;-) */
163 /***********************************************************************
164 * FILEDLG_ScanDir [internal]
166 static BOOL
FILEDLG_ScanDir(HWND hWnd
, LPSTR newPath
)
168 char str
[512],str2
[512];
170 strncpy(str
,newPath
,511); str
[511]=0;
171 GetDlgItemText32A( hWnd
, edt1
, str2
, sizeof(str2
) );
172 strncat(str
,str2
,511-strlen(str
)); str
[511]=0;
173 if (!DlgDirList(hWnd
, MAKE_SEGPTR(str
), lst1
, 0, 0x0000)) return FALSE
;
174 strcpy( str
, "*.*" );
175 DlgDirList(hWnd
, MAKE_SEGPTR(str
), lst2
, stc1
, 0x8010);
179 /***********************************************************************
180 * FILEDLG_GetFileType [internal]
183 static LPSTR
FILEDLG_GetFileType(LPSTR cfptr
, LPSTR fptr
, WORD index
)
188 for ( ;(n
= strlen(cfptr
)) != 0; i
++)
193 cfptr
+= strlen(cfptr
) + 1;
196 for ( ;(n
= strlen(fptr
)) != 0; i
++)
201 fptr
+= strlen(fptr
) + 1;
206 /***********************************************************************
207 * FILEDLG_WMDrawItem [internal]
209 static LONG
FILEDLG_WMDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
211 LPDRAWITEMSTRUCT16 lpdis
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
214 HBITMAP hBitmap
, hPrevBitmap
;
219 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
) {
220 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
221 SelectObject(lpdis
->hDC
, hBrush
);
222 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
223 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
224 (LPARAM
)MAKE_SEGPTR(str
));
225 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
227 if (lpdis
->itemState
!= 0) {
228 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
233 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
) {
234 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
235 SelectObject(lpdis
->hDC
, hBrush
);
236 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
237 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
238 (LPARAM
)MAKE_SEGPTR(str
));
241 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
242 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
243 lpdis
->rcItem
.top
, str
, strlen(str
));
244 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
245 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
246 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
247 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
248 SelectObject(hMemDC
, hPrevBitmap
);
250 if (lpdis
->itemState
!= 0) {
251 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
255 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
) {
256 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
257 SelectObject(lpdis
->hDC
, hBrush
);
258 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
259 SendMessage16(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
260 (LPARAM
)MAKE_SEGPTR(str
));
261 switch(DRIVE_GetType( str
[2] - 'a' ))
263 case TYPE_FLOPPY
: hBitmap
= hFloppy
; break;
264 case TYPE_CDROM
: hBitmap
= hCDRom
; break;
267 default: hBitmap
= hHDisk
; break;
269 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
270 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
271 lpdis
->rcItem
.top
, str
, strlen(str
));
272 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
273 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
274 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
275 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
276 SelectObject(hMemDC
, hPrevBitmap
);
278 if (lpdis
->itemState
!= 0) {
279 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
286 /***********************************************************************
287 * FILEDLG_WMMeasureItem [internal]
289 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
292 LPMEASUREITEMSTRUCT lpmeasure
;
294 GetObject(hFolder2
, sizeof(BITMAP
), (LPSTR
)&bm
);
295 lpmeasure
= (LPMEASUREITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
296 lpmeasure
->itemHeight
= bm
.bmHeight
;
300 /***********************************************************************
301 * FILEDLG_HookCallChk [internal]
303 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn
)
306 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
312 /***********************************************************************
313 * FILEDLG_WMInitDialog [internal]
316 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
320 LPOPENFILENAME lpofn
;
323 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
324 lpofn
= (LPOPENFILENAME
)lParam
;
325 if (lpofn
->lpstrTitle
) SetWindowText16( hWnd
, lpofn
->lpstrTitle
);
326 /* read custom filter information */
327 if (lpofn
->lpstrCustomFilter
)
329 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
);
330 dprintf_commdlg(stddeb
,"lpstrCustomFilter = %p\n", pstr
);
334 strncpy(tmpstr
, pstr
, 511); tmpstr
[511]=0;
335 dprintf_commdlg(stddeb
,"lpstrCustomFilter // add tmpstr='%s' ", tmpstr
);
336 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
339 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
340 SendDlgItemMessage16(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
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
354 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
355 SendDlgItemMessage16(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 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETCURSEL
, lpofn
->nFilterIndex
- 1, 0);
362 strncpy(tmpstr
, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
363 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lpofn
->nFilterIndex
- 1),511);
365 dprintf_commdlg(stddeb
,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
366 lpofn
->nFilterIndex
, tmpstr
);
367 SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
370 DlgDirListComboBox16(hWnd
, tmpstr
, cmb2
, 0, 0xC000);
371 /* read initial directory */
372 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
)
374 strncpy(tmpstr
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
), 510);
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 SendDlgItemMessage16(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
387 if (!(lpofn
->Flags
& OFN_SHOWHELP
))
388 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
389 if (lpofn
->Flags
& OFN_HIDEREADONLY
)
390 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
391 if (FILEDLG_HookCallChk(lpofn
))
392 return (BOOL
)CallWindowProc16(lpofn
->lpfnHook
,
393 hWnd
, WM_INITDIALOG
, wParam
,(LPARAM
)MAKE_SEGPTR(lpofn
));
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
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL
, 0, 0);
427 if (lRet
== LB_ERR
) return TRUE
;
428 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT
, lRet
,
429 (LPARAM
)MAKE_SEGPTR(tmpstr
));
430 SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
432 if (FILEDLG_HookCallChk(lpofn
))
433 CallWindowProc16(lpofn
->lpfnHook
, hWnd
,
434 RegisterWindowMessage32A( LBSELCHSTRING
),
435 control
, MAKELONG(lRet
,CD_LBSELCHANGE
));
436 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
438 case lst2
: /* directory list */
439 FILEDLG_StripEditControl(hWnd
);
440 if (notification
== LBN_DBLCLK
)
442 lRet
= SendDlgItemMessage16(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
443 if (lRet
== LB_ERR
) return TRUE
;
444 SendDlgItemMessage16(hWnd
, lst2
, LB_GETTEXT
, lRet
,
445 (LPARAM
)MAKE_SEGPTR(tmpstr
));
446 if (tmpstr
[0] == '[')
448 tmpstr
[strlen(tmpstr
) - 1] = 0;
449 strcpy(tmpstr
,tmpstr
+1);
451 strcat(tmpstr
, "\\");
455 case cmb1
: /* file type drop list */
456 if (notification
== CBN_SELCHANGE
)
462 case cmb2
: /* disk drop list */
463 FILEDLG_StripEditControl(hWnd
);
464 lRet
= SendDlgItemMessage16(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
465 if (lRet
== LB_ERR
) return 0;
466 SendDlgItemMessage16(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
, (LPARAM
)MAKE_SEGPTR(tmpstr
));
467 sprintf(tmpstr
, "%c:", tmpstr
[2]);
469 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
472 pstr
= (LPSTR
)SendDlgItemMessage16(hWnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
473 dprintf_commdlg(stddeb
,"Selected filter : %s\n", pstr
);
474 SetDlgItemText32A( hWnd
, edt1
, pstr
);
475 FILEDLG_ScanDir(hWnd
, tmpstr
);
483 ofn2
=*lpofn
; /* for later restoring */
484 GetDlgItemText32A( hWnd
, edt1
, tmpstr
, sizeof(tmpstr
) );
485 pstr
= strrchr(tmpstr
, '\\');
487 pstr
= strrchr(tmpstr
, ':');
488 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
490 /* edit control contains wildcards */
493 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
498 strcpy(tmpstr2
, tmpstr
);
501 dprintf_commdlg(stddeb
,"commdlg: %s, %s\n", tmpstr
, tmpstr2
);
502 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
503 FILEDLG_ScanDir(hWnd
, tmpstr
);
506 /* no wildcards, we might have a directory or a filename */
507 /* try appending a wildcard and reading the directory */
508 pstr2
= tmpstr
+ strlen(tmpstr
);
509 if (pstr
== NULL
|| *(pstr
+1) != 0)
510 strcat(tmpstr
, "\\");
511 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
512 if (lRet
== LB_ERR
) return TRUE
;
513 lpofn
->nFilterIndex
= lRet
+ 1;
514 dprintf_commdlg(stddeb
,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn
->nFilterIndex
);
516 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
517 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
518 lRet
), sizeof(tmpstr2
));
519 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
520 /* if ScanDir succeeds, we have changed the directory */
521 if (FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
522 /* if not, this must be a filename */
526 /* strip off the pathname */
528 SetDlgItemText32A( hWnd
, edt1
, pstr
+ 1 );
529 lstrcpyn(tmpstr2
, pstr
+1, sizeof(tmpstr2
) );
530 /* Should we MessageBox() if this fails? */
531 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
532 strcpy(tmpstr
, tmpstr2
);
534 else SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
536 ShowWindow(hWnd
, SW_HIDE
); /* this should not be necessary ?! (%%%) */
539 int drive
= DRIVE_GetCurrentDrive();
540 tmpstr2
[0] = 'A'+ drive
;
543 strncpy(tmpstr2
+ 3, DRIVE_GetDosCwd(drive
), 507); tmpstr2
[510]=0;
544 if (strlen(tmpstr2
) > 3)
545 strcat(tmpstr2
, "\\");
546 strncat(tmpstr2
, tmpstr
, 511-strlen(tmpstr2
)); tmpstr2
[511]=0;
547 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), tmpstr2
);
549 lpofn
->nFileOffset
= 0;
550 lpofn
->nFileExtension
= 0;
551 while(tmpstr2
[lpofn
->nFileExtension
] != '.' && tmpstr2
[lpofn
->nFileExtension
] != '\0')
552 lpofn
->nFileExtension
++;
553 if (lpofn
->nFileExtension
== '\0')
554 lpofn
->nFileExtension
= 0;
556 lpofn
->nFileExtension
++;
557 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
)
559 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL
, 0, 0);
560 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT
, lRet
,
561 (LPARAM
)MAKE_SEGPTR(tmpstr
));
562 dprintf_commdlg(stddeb
,"strcpy'ing '%s'\n",tmpstr
); fflush(stdout
);
563 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
), tmpstr
);
565 if (FILEDLG_HookCallChk(lpofn
))
567 lRet
= (BOOL
)CallWindowProc16(lpofn
->lpfnHook
,
568 hWnd
, RegisterWindowMessage32A( FILEOKSTRING
),
569 0, (LPARAM
)MAKE_SEGPTR(lpofn
));
572 *lpofn
=ofn2
; /* restore old state */
574 ShowWindow(hWnd
, SW_SHOW
); /* only if above (%%%) SW_HIDE used */
579 EndDialog(hWnd
, TRUE
);
582 EndDialog(hWnd
, FALSE
);
589 /***********************************************************************
590 * FileOpenDlgProc (COMMDLG.6)
592 LRESULT
FileOpenDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
594 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)GetWindowLong(hWnd
, DWL_USER
);
596 if (wMsg
!=WM_INITDIALOG
)
597 if (FILEDLG_HookCallChk(lpofn
))
599 LRESULT lRet
=(BOOL
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
601 return lRet
; /* else continue message processing */
606 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
608 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
610 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
);
612 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
615 SetBkColor((HDC
)wParam
, 0x00C0C0C0);
616 switch (HIWORD(lParam
))
619 SetTextColor((HDC
)wParam
, 0x00000000);
621 case CTLCOLOR_STATIC
:
622 SetTextColor((HDC
)wParam
, 0x00000000);
632 /***********************************************************************
633 * FileSaveDlgProc (COMMDLG.7)
635 LRESULT
FileSaveDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
637 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)GetWindowLong(hWnd
, DWL_USER
);
639 if (wMsg
!=WM_INITDIALOG
)
640 if (FILEDLG_HookCallChk(lpofn
))
642 LRESULT lRet
=(BOOL
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
644 return lRet
; /* else continue message processing */
648 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
651 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
654 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
);
657 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
662 SetBkColor((HDC)wParam, 0x00C0C0C0);
663 switch (HIWORD(lParam))
666 SetTextColor((HDC)wParam, 0x00000000);
668 case CTLCOLOR_STATIC:
669 SetTextColor((HDC)wParam, 0x00000000);
679 /***********************************************************************
680 * ChooseColor (COMMDLG.5)
682 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
684 HANDLE hInst
, hDlgTmpl
;
687 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR
);
688 hInst
= WIN_GetWindowInstance( lpChCol
->hwndOwner
);
689 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpChCol
->hwndOwner
,
690 MODULE_GetWndProcEntry16("ColorDlgProc"),
692 SYSRES_FreeResource( hDlgTmpl
);
697 /***********************************************************************
698 * FindTextDlg (COMMDLG.11)
700 BOOL
FindText(LPFINDREPLACE lpFind
)
702 HANDLE hInst
, hDlgTmpl
;
707 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
708 * For now, only the standard dialog works.
711 * FIXME : We should do error checking on the lpFind structure here
712 * and make CommDlgExtendedError() return the error condition.
714 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT
);
715 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
716 if (!(ptr
= (SEGPTR
)WIN16_GlobalLock16( hDlgTmpl
))) return -1;
717 bRet
= CreateDialogIndirectParam( hInst
, ptr
, lpFind
->hwndOwner
,
718 MODULE_GetWndProcEntry16("FindTextDlgProc"),
720 GlobalUnlock16( hDlgTmpl
);
721 SYSRES_FreeResource( hDlgTmpl
);
726 /***********************************************************************
727 * ReplaceTextDlg (COMMDLG.12)
729 BOOL
ReplaceText(LPFINDREPLACE lpFind
)
731 HANDLE hInst
, hDlgTmpl
;
736 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
737 * For now, only the standard dialog works.
740 * FIXME : We should do error checking on the lpFind structure here
741 * and make CommDlgExtendedError() return the error condition.
743 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT
);
744 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
745 if (!(ptr
= (SEGPTR
)WIN16_GlobalLock16( hDlgTmpl
))) return -1;
746 bRet
= CreateDialogIndirectParam( hInst
, ptr
, lpFind
->hwndOwner
,
747 MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
749 GlobalUnlock16( hDlgTmpl
);
750 SYSRES_FreeResource( hDlgTmpl
);
755 /***********************************************************************
756 * FINDDLG_WMInitDialog [internal]
758 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
762 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
763 lpfr
= (LPFINDREPLACE
)lParam
;
764 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
766 * FIXME : If the initial FindWhat string is empty, we should disable the
767 * FindNext (IDOK) button. Only after typing some text, the button should be
770 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
771 CheckRadioButton(hWnd
, rad1
, rad2
, (lpfr
->Flags
& FR_DOWN
) ? rad2
: rad1
);
772 if (lpfr
->Flags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
773 EnableWindow(GetDlgItem(hWnd
, rad1
), FALSE
);
774 EnableWindow(GetDlgItem(hWnd
, rad2
), FALSE
);
776 if (lpfr
->Flags
& FR_HIDEUPDOWN
) {
777 ShowWindow(GetDlgItem(hWnd
, rad1
), SW_HIDE
);
778 ShowWindow(GetDlgItem(hWnd
, rad2
), SW_HIDE
);
779 ShowWindow(GetDlgItem(hWnd
, grp1
), SW_HIDE
);
781 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
782 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
783 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
784 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
785 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
786 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
787 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
788 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
789 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
790 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
791 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
792 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
793 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
795 ShowWindow(hWnd
, SW_SHOWNORMAL
);
800 /***********************************************************************
801 * FINDDLG_WMCommand [internal]
803 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
806 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
807 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
809 lpfr
= (LPFINDREPLACE
)GetWindowLong(hWnd
, DWL_USER
);
812 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
813 if (IsDlgButtonChecked(hWnd
, rad2
))
814 lpfr
->Flags
|= FR_DOWN
;
815 else lpfr
->Flags
&= ~FR_DOWN
;
816 if (IsDlgButtonChecked(hWnd
, chx1
))
817 lpfr
->Flags
|= FR_WHOLEWORD
;
818 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
819 if (IsDlgButtonChecked(hWnd
, chx2
))
820 lpfr
->Flags
|= FR_MATCHCASE
;
821 else lpfr
->Flags
&= ~FR_MATCHCASE
;
822 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
823 lpfr
->Flags
|= FR_FINDNEXT
;
824 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
827 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
828 lpfr
->Flags
|= FR_DIALOGTERM
;
829 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
833 /* FIXME : should lpfr structure be passed as an argument ??? */
834 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
841 /***********************************************************************
842 * FindTextDlgProc (COMMDLG.13)
844 LRESULT
FindTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
848 return FINDDLG_WMInitDialog(hWnd
, wParam
, lParam
);
850 return FINDDLG_WMCommand(hWnd
, wParam
, lParam
);
856 /***********************************************************************
857 * REPLACEDLG_WMInitDialog [internal]
859 static LRESULT
REPLACEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
863 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
864 lpfr
= (LPFINDREPLACE
)lParam
;
865 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
867 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
868 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
871 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
872 SetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
);
873 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
874 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
875 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
876 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
877 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
878 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
879 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
880 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
881 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
882 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
883 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
884 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
885 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
887 ShowWindow(hWnd
, SW_SHOWNORMAL
);
892 /***********************************************************************
893 * REPLACEDLG_WMCommand [internal]
895 static LRESULT
REPLACEDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
898 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
899 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
901 lpfr
= (LPFINDREPLACE
)GetWindowLong(hWnd
, DWL_USER
);
904 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
905 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
906 if (IsDlgButtonChecked(hWnd
, chx1
))
907 lpfr
->Flags
|= FR_WHOLEWORD
;
908 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
909 if (IsDlgButtonChecked(hWnd
, chx2
))
910 lpfr
->Flags
|= FR_MATCHCASE
;
911 else lpfr
->Flags
&= ~FR_MATCHCASE
;
912 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
913 lpfr
->Flags
|= FR_FINDNEXT
;
914 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
917 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
918 lpfr
->Flags
|= FR_DIALOGTERM
;
919 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
923 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
924 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
925 if (IsDlgButtonChecked(hWnd
, chx1
))
926 lpfr
->Flags
|= FR_WHOLEWORD
;
927 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
928 if (IsDlgButtonChecked(hWnd
, chx2
))
929 lpfr
->Flags
|= FR_MATCHCASE
;
930 else lpfr
->Flags
&= ~FR_MATCHCASE
;
931 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
932 lpfr
->Flags
|= FR_REPLACE
;
933 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
936 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
937 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
938 if (IsDlgButtonChecked(hWnd
, chx1
))
939 lpfr
->Flags
|= FR_WHOLEWORD
;
940 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
941 if (IsDlgButtonChecked(hWnd
, chx2
))
942 lpfr
->Flags
|= FR_MATCHCASE
;
943 else lpfr
->Flags
&= ~FR_MATCHCASE
;
944 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
945 lpfr
->Flags
|= FR_REPLACEALL
;
946 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
949 /* FIXME : should lpfr structure be passed as an argument ??? */
950 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
957 /***********************************************************************
958 * ReplaceTextDlgProc (COMMDLG.14)
960 LRESULT
ReplaceTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
964 return REPLACEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
966 return REPLACEDLG_WMCommand(hWnd
, wParam
, lParam
);
972 /***********************************************************************
973 * PrintDlg (COMMDLG.20)
975 BOOL
PrintDlg(LPPRINTDLG lpPrint
)
977 HANDLE hInst
, hDlgTmpl
;
980 dprintf_commdlg(stddeb
,"PrintDlg(%p) // Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
982 if (lpPrint
->Flags
& PD_RETURNDEFAULT
)
983 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
986 if (lpPrint
->Flags
& PD_PRINTSETUP
)
987 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP
);
989 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT
);
991 hInst
= WIN_GetWindowInstance( lpPrint
->hwndOwner
);
992 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpPrint
->hwndOwner
,
993 (lpPrint
->Flags
& PD_PRINTSETUP
) ?
994 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
995 MODULE_GetWndProcEntry16("PrintDlgProc"),
997 SYSRES_FreeResource( hDlgTmpl
);
1002 /***********************************************************************
1003 * PrintDlgProc (COMMDLG.21)
1005 LRESULT
PrintDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
1010 dprintf_commdlg(stddeb
,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1011 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1017 EndDialog(hWnd
, TRUE
);
1020 EndDialog(hWnd
, FALSE
);
1029 /***********************************************************************
1030 * PrintSetupDlgProc (COMMDLG.22)
1032 LRESULT
PrintSetupDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
1037 dprintf_commdlg(stddeb
,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1038 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1043 EndDialog(hWnd
, TRUE
);
1046 EndDialog(hWnd
, FALSE
);
1055 /***********************************************************************
1056 * CommDlgExtendedError (COMMDLG.26)
1058 DWORD
CommDlgExtendedError(void)
1060 return CommDlgLastError
;
1064 /***********************************************************************
1065 * GetFileTitle (COMMDLG.27)
1067 short GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT cbBuf
)
1070 dprintf_commdlg(stddeb
,"GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
1071 if (lpFile
== NULL
|| lpTitle
== NULL
)
1073 len
= strlen(lpFile
);
1076 if (strpbrk(lpFile
, "*[]"))
1079 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
1081 for (i
= len
; i
>= 0; i
--)
1082 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
1087 dprintf_commdlg(stddeb
,"\n---> '%s' ", &lpFile
[i
]);
1089 len
= strlen(lpFile
+i
)+1;
1093 strncpy(lpTitle
, &lpFile
[i
], len
);
1098 /* --------------------------- Choose Color Dialog ------------------------------ */
1100 static const COLORREF predefcolors
[6][8]=
1102 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
1103 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
1104 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
1105 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
1107 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
1108 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
1109 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
1110 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
1112 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
1113 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
1114 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
1115 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
1120 LPCHOOSECOLOR lpcc
; /* points to public known data structure */
1121 int nextuserdef
; /* next free place in user defined color array */
1122 HDC hdcMem
; /* color graph used for BitBlt() */
1123 HBITMAP hbmMem
; /* color graph bitmap */
1124 RECT16 fullsize
; /* original dialog window size */
1125 UINT msetrgb
; /* # of SETRGBSTRING message (today not used) */
1126 RECT16 old3angle
; /* last position of l-marker */
1127 RECT16 oldcross
; /* last position of color/satuation marker */
1128 BOOL updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1131 int l
; /* for temporary storing of hue,sat,lum */
1134 /***********************************************************************
1135 * CC_HSLtoRGB [internal]
1137 static int CC_HSLtoRGB(char c
,int hue
,int sat
,int lum
)
1144 case 'R':if (hue
>80) hue
-=80; else hue
+=160; break;
1145 case 'G':if (hue
>160) hue
-=160; else hue
+=80; break;
1150 maxrgb
=(256*MIN(120,lum
))/120; /* 0 .. 256 */
1156 res
=(hue
-80)* maxrgb
; /* 0...10240 */
1157 res
/=40; /* 0...256 */
1164 res
=(240-hue
)* maxrgb
;
1167 res
=res
-maxrgb
/2; /* -128...128 */
1170 res
=maxrgb
/2 + (sat
*res
) /240; /* 0..256 */
1173 if (lum
>120 && res
<256)
1174 res
+=((lum
-120) * (256-res
))/120;
1176 return MIN(res
,255);
1179 /***********************************************************************
1180 * CC_RGBtoHSL [internal]
1182 static int CC_RGBtoHSL(char c
,int r
,int g
,int b
)
1184 WORD maxi
,mini
,mmsum
,mmdif
,result
=0;
1198 case 'L':mmsum
*=120; /* 0...61200=(255+255)*120 */
1199 result
=mmsum
/255; /* 0...240 */
1202 case 'S':if (!mmsum
)
1205 if (!mini
|| maxi
==255)
1209 result
=mmdif
*240; /* 0...61200=255*240 */
1210 result
/= (mmsum
>255 ? mmsum
=510-mmsum
: mmsum
); /* 0..255 */
1214 case 'H':if (!mmdif
)
1220 iresult
=40*(g
-b
); /* -10200 ... 10200 */
1221 iresult
/=(int)mmdif
; /* -40 .. 40 */
1223 iresult
+=240; /* 0..40 and 200..240 */
1229 iresult
/=(int)mmdif
;
1230 iresult
+=80; /* 40 .. 120 */
1236 iresult
/=(int)mmdif
;
1237 iresult
+=160; /* 120 .. 200 */
1243 return result
; /* is this integer arithmetic precise enough ? */
1248 /***********************************************************************
1249 * CC_MouseCheckPredefColorArray [internal]
1251 static int CC_MouseCheckPredefColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1252 LPARAM lParam
,COLORREF
*cr
)
1255 POINT16 point
= MAKEPOINT16(lParam
);
1259 ClientToScreen16(hDlg
,&point
);
1260 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1261 GetWindowRect16(hwnd
,&rect
);
1262 if (PtInRect16(&rect
,point
))
1264 dx
=(rect
.right
-rect
.left
)/cols
;
1265 dy
=(rect
.bottom
-rect
.top
)/rows
;
1266 ScreenToClient16(hwnd
,&point
);
1268 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1272 *cr
=predefcolors
[y
][x
];
1273 /* FIXME: Draw_a_Focus_Rect() */
1280 /***********************************************************************
1281 * CC_MouseCheckUserColorArray [internal]
1283 static int CC_MouseCheckUserColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1284 LPARAM lParam
,COLORREF
*cr
,COLORREF
*crarr
)
1287 POINT16 point
= MAKEPOINT16(lParam
);
1291 ClientToScreen16(hDlg
,&point
);
1292 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1293 GetWindowRect16(hwnd
,&rect
);
1294 if (PtInRect16(&rect
,point
))
1296 dx
=(rect
.right
-rect
.left
)/cols
;
1297 dy
=(rect
.bottom
-rect
.top
)/rows
;
1298 ScreenToClient16(hwnd
,&point
);
1300 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1304 *cr
=crarr
[x
+cols
*y
];
1305 /* FIXME: Draw_a_Focus_Rect() */
1315 /* 240 ^...... ^^ 240
1322 /***********************************************************************
1323 * CC_MouseCheckColorGraph [internal]
1325 static int CC_MouseCheckColorGraph(HWND hDlg
,int dlgitem
,int *hori
,int *vert
,LPARAM lParam
)
1328 POINT16 point
= MAKEPOINT16(lParam
);
1332 ClientToScreen16(hDlg
,&point
);
1333 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1334 GetWindowRect16(hwnd
,&rect
);
1335 if (PtInRect16(&rect
,point
))
1337 GetClientRect16(hwnd
,&rect
);
1338 ScreenToClient16(hwnd
,&point
);
1340 x
=(long)point
.x
*MAXHORI
;
1342 y
=(long)(rect
.bottom
-point
.y
)*MAXVERT
;
1354 /***********************************************************************
1355 * CC_MouseCheckResultWindow [internal]
1357 static int CC_MouseCheckResultWindow(HWND hDlg
,LPARAM lParam
)
1360 POINT16 point
= MAKEPOINT16(lParam
);
1363 ClientToScreen16(hDlg
,&point
);
1364 hwnd
=GetDlgItem(hDlg
,0x2c5);
1365 GetWindowRect16(hwnd
,&rect
);
1366 if (PtInRect16(&rect
,point
))
1368 PostMessage(hDlg
,WM_COMMAND
,0x2c9,0);
1374 /***********************************************************************
1375 * CC_CheckDigitsInEdit [internal]
1377 static int CC_CheckDigitsInEdit(HWND hwnd
,int maxval
)
1379 int i
,k
,m
,result
,value
;
1382 GetWindowText32A(hwnd
,buffer
,sizeof(buffer
));
1387 if (buffer
[i
]<'0' || buffer
[i
]>'9')
1389 for (k
=i
+1;k
<=m
;k
++) /* delete bad character */
1391 buffer
[i
]=buffer
[k
];
1399 if (value
>maxval
) /* build a new string */
1401 sprintf(buffer
,"%d",maxval
);
1406 editpos
=SendMessage16(hwnd
,EM_GETSEL
,0,0);
1407 SetWindowText32A(hwnd
,buffer
);
1408 SendMessage16(hwnd
,EM_SETSEL
,0,editpos
);
1415 /***********************************************************************
1416 * CC_PaintSelectedColor [internal]
1418 static void CC_PaintSelectedColor(HWND hDlg
,COLORREF cr
)
1423 HWND hwnd
=GetDlgItem(hDlg
,0x2c5);
1424 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1427 GetClientRect16 (hwnd
, &rect
) ;
1428 hBrush
= CreateSolidBrush(cr
);
1431 hBrush
= SelectObject (hdc
, hBrush
) ;
1432 Rectangle (hdc
, rect
.left
,rect
.top
,rect
.right
/2,rect
.bottom
);
1433 DeleteObject (SelectObject (hdc
,hBrush
)) ;
1434 hBrush
=CreateSolidBrush(GetNearestColor(hdc
,cr
));
1437 hBrush
= SelectObject (hdc
, hBrush
) ;
1438 Rectangle (hdc
, rect
.right
/2-1,rect
.top
,rect
.right
,rect
.bottom
);
1439 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1442 ReleaseDC(hwnd
,hdc
);
1446 /***********************************************************************
1447 * CC_PaintTriangle [internal]
1449 static void CC_PaintTriangle(HWND hDlg
,int y
)
1453 int w
=GetDialogBaseUnits();
1458 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
1459 struct CCPRIVATE
*lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1461 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1463 GetClientRect16(hwnd
,&rect
);
1467 points
[0].y
=rect
.top
;
1468 points
[0].x
=rect
.right
; /* | /| */
1469 ClientToScreen16(hwnd
,points
); /* | / | */
1470 ScreenToClient16(hDlg
,points
); /* |< | */
1471 oben
=points
[0].y
; /* | \ | */
1473 temp
=(long)height
*(long)y
;
1474 points
[0].y
=oben
+height
-temp
/(long)MAXVERT
;
1475 points
[1].y
=points
[0].y
+w
;
1476 points
[2].y
=points
[0].y
-w
;
1477 points
[2].x
=points
[1].x
=points
[0].x
+ w
;
1479 if (lpp
->old3angle
.left
)
1480 FillRect16(hDC
,&lpp
->old3angle
,GetStockObject(WHITE_BRUSH
));
1481 lpp
->old3angle
.left
=points
[0].x
;
1482 lpp
->old3angle
.right
=points
[1].x
+1;
1483 lpp
->old3angle
.top
=points
[2].y
-1;
1484 lpp
->old3angle
.bottom
=points
[1].y
+1;
1485 Polygon16(hDC
,points
,3);
1486 ReleaseDC(hDlg
,hDC
);
1491 /***********************************************************************
1492 * CC_PaintCross [internal]
1494 static void CC_PaintCross(HWND hDlg
,int x
,int y
)
1497 int w
=GetDialogBaseUnits();
1498 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1499 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1504 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1506 GetClientRect16(hwnd
,&rect
);
1508 SelectClipRgn(hDC
,CreateRectRgnIndirect16(&rect
));
1509 hPen
=CreatePen(PS_SOLID
,2,0);
1510 hPen
=SelectObject(hDC
,hPen
);
1511 point
.x
=((long)rect
.right
*(long)x
)/(long)MAXHORI
;
1512 point
.y
=rect
.bottom
-((long)rect
.bottom
*(long)y
)/(long)MAXVERT
;
1513 if (lpp
->oldcross
.left
!=lpp
->oldcross
.right
)
1514 BitBlt(hDC
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,
1515 lpp
->oldcross
.right
-lpp
->oldcross
.left
,
1516 lpp
->oldcross
.bottom
-lpp
->oldcross
.top
,
1517 lpp
->hdcMem
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,SRCCOPY
);
1518 lpp
->oldcross
.left
=point
.x
-w
-1;
1519 lpp
->oldcross
.right
=point
.x
+w
+1;
1520 lpp
->oldcross
.top
=point
.y
-w
-1;
1521 lpp
->oldcross
.bottom
=point
.y
+w
+1;
1523 MoveTo(hDC
,point
.x
-w
,point
.y
);
1524 LineTo(hDC
,point
.x
+w
,point
.y
);
1525 MoveTo(hDC
,point
.x
,point
.y
-w
);
1526 LineTo(hDC
,point
.x
,point
.y
+w
);
1527 DeleteObject(SelectObject(hDC
,hPen
));
1528 ReleaseDC(hwnd
,hDC
);
1537 /***********************************************************************
1538 * CC_PrepareColorGraph [internal]
1540 static void CC_PrepareColorGraph(HWND hDlg
)
1542 int sdif
,hdif
,xdif
,ydif
,r
,g
,b
,hue
,sat
;
1543 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1544 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1548 HCURSOR hcursor
=SetCursor(LoadCursor(0,IDC_WAIT
));
1550 GetClientRect16(hwnd
,&client
);
1552 lpp
->hdcMem
= CreateCompatibleDC(hdc
);
1553 lpp
->hbmMem
= CreateCompatibleBitmap(hdc
,client
.right
,client
.bottom
);
1554 SelectObject(lpp
->hdcMem
,lpp
->hbmMem
);
1556 xdif
=client
.right
/XSTEPS
;
1557 ydif
=client
.bottom
/YSTEPS
+1;
1560 for(rect
.left
=hue
=0;hue
<239+hdif
;hue
+=hdif
)
1562 rect
.right
=rect
.left
+xdif
;
1563 rect
.bottom
=client
.bottom
;
1564 for(sat
=0;sat
<240+sdif
;sat
+=sdif
)
1566 rect
.top
=rect
.bottom
-ydif
;
1567 r
=CC_HSLtoRGB('R',hue
,sat
,120);
1568 g
=CC_HSLtoRGB('G',hue
,sat
,120);
1569 b
=CC_HSLtoRGB('B',hue
,sat
,120);
1570 hbrush
=CreateSolidBrush(RGB(r
,g
,b
));
1571 FillRect16(lpp
->hdcMem
,&rect
,hbrush
);
1572 DeleteObject(hbrush
);
1573 rect
.bottom
=rect
.top
;
1575 rect
.left
=rect
.right
;
1577 ReleaseDC(hwnd
,hdc
);
1581 /***********************************************************************
1582 * CC_PaintColorGraph [internal]
1584 static void CC_PaintColorGraph(HWND hDlg
)
1586 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1587 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1590 if (IsWindowVisible(hwnd
)) /* if full size */
1593 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
1596 GetClientRect16(hwnd
,&rect
);
1598 BitBlt(hDC
,0,0,rect
.right
,rect
.bottom
,lpp
->hdcMem
,0,0,SRCCOPY
);
1600 fprintf(stderr
,"choose color: hdcMem is not defined\n");
1601 ReleaseDC(hwnd
,hDC
);
1604 /***********************************************************************
1605 * CC_PaintLumBar [internal]
1607 static void CC_PaintLumBar(HWND hDlg
,int hue
,int sat
)
1609 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
1611 int lum
,ldif
,ydif
,r
,g
,b
;
1615 if (IsWindowVisible(hwnd
))
1618 GetClientRect16(hwnd
,&client
);
1622 ydif
=client
.bottom
/YSTEPS
+1;
1623 for(lum
=0;lum
<240+ldif
;lum
+=ldif
)
1625 rect
.top
=MAX(0,rect
.bottom
-ydif
);
1626 r
=CC_HSLtoRGB('R',hue
,sat
,lum
);
1627 g
=CC_HSLtoRGB('G',hue
,sat
,lum
);
1628 b
=CC_HSLtoRGB('B',hue
,sat
,lum
);
1629 hbrush
=CreateSolidBrush(RGB(r
,g
,b
));
1630 FillRect16(hDC
,&rect
,hbrush
);
1631 DeleteObject(hbrush
);
1632 rect
.bottom
=rect
.top
;
1634 GetClientRect16(hwnd
,&rect
);
1635 FrameRect16(hDC
,&rect
,GetStockObject(BLACK_BRUSH
));
1636 ReleaseDC(hwnd
,hDC
);
1640 /***********************************************************************
1641 * CC_EditSetRGB [internal]
1643 static void CC_EditSetRGB(HWND hDlg
,COLORREF cr
)
1646 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1647 int r
=GetRValue(cr
);
1648 int g
=GetGValue(cr
);
1649 int b
=GetBValue(cr
);
1650 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1653 sprintf(buffer
,"%d",r
);
1654 SetWindowText32A(GetDlgItem(hDlg
,0x2c2),buffer
);
1655 sprintf(buffer
,"%d",g
);
1656 SetWindowText32A(GetDlgItem(hDlg
,0x2c3),buffer
);
1657 sprintf(buffer
,"%d",b
);
1658 SetWindowText32A(GetDlgItem(hDlg
,0x2c4),buffer
);
1659 lpp
->updating
=FALSE
;
1663 /***********************************************************************
1664 * CC_EditSetHSL [internal]
1666 static void CC_EditSetHSL(HWND hDlg
,int h
,int s
,int l
)
1669 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1671 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1674 sprintf(buffer
,"%d",h
);
1675 SetWindowText32A(GetDlgItem(hDlg
,0x2bf),buffer
);
1676 sprintf(buffer
,"%d",s
);
1677 SetWindowText32A(GetDlgItem(hDlg
,0x2c0),buffer
);
1678 sprintf(buffer
,"%d",l
);
1679 SetWindowText32A(GetDlgItem(hDlg
,0x2c1),buffer
);
1680 lpp
->updating
=FALSE
;
1682 CC_PaintLumBar(hDlg
,h
,s
);
1685 /***********************************************************************
1686 * CC_SwitchToFullSize [internal]
1688 static void CC_SwitchToFullSize(HWND hDlg
,COLORREF result
,LPRECT16 lprect
)
1691 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1693 EnableWindow(GetDlgItem(hDlg
,0x2cf),FALSE
);
1694 CC_PrepareColorGraph(hDlg
);
1695 for (i
=0x2bf;i
<0x2c5;i
++)
1696 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
1697 for (i
=0x2d3;i
<0x2d9;i
++)
1698 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
1699 EnableWindow(GetDlgItem(hDlg
,0x2c9),TRUE
);
1700 EnableWindow(GetDlgItem(hDlg
,0x2c8),TRUE
);
1703 SetWindowPos(hDlg
,NULL
,0,0,lprect
->right
-lprect
->left
,
1704 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
1706 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_SHOW
);
1707 ShowWindow(GetDlgItem(hDlg
,0x2be),SW_SHOW
);
1708 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_SHOW
);
1710 CC_EditSetRGB(hDlg
,result
);
1711 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1714 /***********************************************************************
1715 * CC_PaintPredefColorArray [internal]
1717 static void CC_PaintPredefColorArray(HWND hDlg
,int rows
,int cols
)
1719 HWND hwnd
=GetDlgItem(hDlg
,0x2d0);
1725 GetClientRect16(hwnd
,&rect
);
1727 dy
=rect
.bottom
/rows
;
1731 GetClientRect16 (hwnd
, &rect
) ;
1733 for (j
=0;j
<rows
;j
++)
1735 for (i
=0;i
<cols
;i
++)
1737 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
1740 hBrush
= SelectObject (hdc
, hBrush
) ;
1741 Rectangle (hdc
, rect
.left
, rect
.top
,
1742 rect
.left
+dx
-DISTANCE
,rect
.top
+dy
-DISTANCE
);
1743 rect
.left
=rect
.left
+dx
;
1744 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1747 rect
.top
=rect
.top
+dy
;
1750 ReleaseDC(hwnd
,hdc
);
1751 /* FIXME: draw_a_focus_rect */
1753 /***********************************************************************
1754 * CC_PaintUserColorArray [internal]
1756 static void CC_PaintUserColorArray(HWND hDlg
,int rows
,int cols
,COLORREF
* lpcr
)
1758 HWND hwnd
=GetDlgItem(hDlg
,0x2d1);
1764 GetClientRect16(hwnd
,&rect
);
1767 dy
=rect
.bottom
/rows
;
1773 for (j
=0;j
<rows
;j
++)
1775 for (i
=0;i
<cols
;i
++)
1777 hBrush
= CreateSolidBrush(lpcr
[i
+j
*cols
]);
1780 hBrush
= SelectObject (hdc
, hBrush
) ;
1781 Rectangle (hdc
, rect
.left
, rect
.top
,
1782 rect
.left
+dx
-DISTANCE
,rect
.top
+dy
-DISTANCE
);
1783 rect
.left
=rect
.left
+dx
;
1784 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1787 rect
.top
=rect
.top
+dy
;
1790 ReleaseDC(hwnd
,hdc
);
1792 /* FIXME: draw_a_focus_rect */
1797 /***********************************************************************
1798 * CC_HookCallChk [internal]
1800 static BOOL
CC_HookCallChk(LPCHOOSECOLOR lpcc
)
1803 if(lpcc
->Flags
& CC_ENABLEHOOK
)
1809 /***********************************************************************
1810 * CC_WMInitDialog [internal]
1812 static LONG
CC_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1818 struct CCPRIVATE
* lpp
;
1820 dprintf_commdlg(stddeb
,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1821 lpp
=calloc(1,sizeof(struct CCPRIVATE
));
1822 lpp
->lpcc
=(LPCHOOSECOLOR
)lParam
;
1823 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLOR
))
1825 EndDialog (hDlg
, 0) ;
1828 SetWindowLong32A(hDlg
, DWL_USER
, (LONG
)lpp
);
1830 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
1831 ShowWindow(GetDlgItem(hDlg
,0x40e),SW_HIDE
);
1832 lpp
->msetrgb
=RegisterWindowMessage32A( SETRGBSTRING
);
1834 cpos
=MAKELONG(5,7); /* init */
1835 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
1839 if (predefcolors
[i
][j
]==lpp
->lpcc
->rgbResult
)
1846 /* FIXME: Draw_a_focus_rect & set_init_values */
1848 GetWindowRect16(hDlg
,&lpp
->fullsize
);
1849 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1851 hwnd
=GetDlgItem(hDlg
,0x2cf);
1852 EnableWindow(hwnd
,FALSE
);
1854 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1857 res
=rect
.bottom
-rect
.top
;
1858 hwnd
=GetDlgItem(hDlg
,0x2c6); /* cut at left border */
1860 ClientToScreen16(hwnd
,&point
);
1861 ScreenToClient16(hDlg
,&point
);
1862 GetClientRect16(hDlg
,&rect
);
1863 point
.x
+=GetSystemMetrics(SM_CXDLGFRAME
);
1864 SetWindowPos(hDlg
,NULL
,0,0,point
.x
,res
,SWP_NOMOVE
|SWP_NOZORDER
);
1866 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_HIDE
);
1867 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_HIDE
);
1870 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,NULL
);
1872 for (i
=0x2bf;i
<0x2c5;i
++)
1873 SendMessage16(GetDlgItem(hDlg
,i
),EM_LIMITTEXT
,3,0); /* max 3 digits: xyz */
1874 if (CC_HookCallChk(lpp
->lpcc
))
1875 res
=CallWindowProc16((FARPROC
)lpp
->lpcc
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1879 /***********************************************************************
1880 * CC_WMCommand [internal]
1882 static LRESULT
CC_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1888 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
1889 dprintf_commdlg(stddeb
,"CC_WMCommand wParam=%x lParam=%lx\n",wParam
,lParam
);
1892 case 0x2c2: /* edit notify RGB */
1895 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1897 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),255);
1898 r
=GetRValue(lpp
->lpcc
->rgbResult
);
1899 g
=GetGValue(lpp
->lpcc
->rgbResult
);
1900 b
=GetBValue(lpp
->lpcc
->rgbResult
);
1904 case 0x2c2:if ((xx
=(i
!=r
))) r
=i
;break;
1905 case 0x2c3:if ((xx
=(i
!=g
))) g
=i
;break;
1906 case 0x2c4:if ((xx
=(i
!=b
))) b
=i
;break;
1908 if (xx
) /* something has changed */
1910 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1911 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1912 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
1913 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
1914 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
1915 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1916 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1917 CC_PaintTriangle(hDlg
,lpp
->l
);
1922 case 0x2bf: /* edit notify HSL */
1925 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1927 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),wParam
==0x2bf?239:240);
1931 case 0x2bf:if ((xx
=(i
!=lpp
->h
))) lpp
->h
=i
;break;
1932 case 0x2c0:if ((xx
=(i
!=lpp
->s
))) lpp
->s
=i
;break;
1933 case 0x2c1:if ((xx
=(i
!=lpp
->l
))) lpp
->l
=i
;break;
1935 if (xx
) /* something has changed */
1937 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
1938 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
1939 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
1940 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1941 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1942 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
1943 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1944 CC_PaintTriangle(hDlg
,lpp
->l
);
1950 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,&lpp
->fullsize
);
1951 InvalidateRect32( hDlg
, NULL
, TRUE
);
1952 SetFocus(GetDlgItem(hDlg
,0x2bf));
1955 case 0x2c8: /* add colors ... column by column */
1956 cr
=PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
);
1957 cr
[(lpp
->nextuserdef
%2)*8 + lpp
->nextuserdef
/2]=lpp
->lpcc
->rgbResult
;
1958 if (++lpp
->nextuserdef
==16)
1960 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
1963 case 0x2c9: /* resulting color */
1965 lpp
->lpcc
->rgbResult
=GetNearestColor(hdc
,lpp
->lpcc
->rgbResult
);
1966 ReleaseDC(hDlg
,hdc
);
1967 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
1968 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1969 r
=GetRValue(lpp
->lpcc
->rgbResult
);
1970 g
=GetGValue(lpp
->lpcc
->rgbResult
);
1971 b
=GetBValue(lpp
->lpcc
->rgbResult
);
1972 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
1973 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
1974 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
1975 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1976 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1977 CC_PaintTriangle(hDlg
,lpp
->l
);
1980 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1981 i
=RegisterWindowMessage32A( HELPMSGSTRING
);
1982 if (lpp
->lpcc
->hwndOwner
)
1983 SendMessage16(lpp
->lpcc
->hwndOwner
,i
,0,(LPARAM
)lpp
->lpcc
);
1984 if (CC_HookCallChk(lpp
->lpcc
))
1985 CallWindowProc16((FARPROC
)lpp
->lpcc
->lpfnHook
,hDlg
,
1986 WM_COMMAND
,psh15
,(LPARAM
)lpp
->lpcc
);
1990 cokmsg
=RegisterWindowMessage32A( COLOROKSTRING
);
1991 if (lpp
->lpcc
->hwndOwner
)
1992 if (SendMessage16(lpp
->lpcc
->hwndOwner
,cokmsg
,0,(LPARAM
)lpp
->lpcc
))
1993 break; /* do NOT close */
1995 EndDialog (hDlg
, 1) ;
1999 EndDialog (hDlg
, 0) ;
2006 /***********************************************************************
2007 * CC_WMPaint [internal]
2009 static LRESULT
CC_WMPaint(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2011 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
2012 /* we have to paint dialog children except text and buttons */
2014 CC_PaintPredefColorArray(hDlg
,6,8);
2015 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2016 CC_PaintColorGraph(hDlg
);
2017 CC_PaintLumBar(hDlg
,lpp
->h
,lpp
->s
);
2018 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2019 CC_PaintTriangle(hDlg
,lpp
->l
);
2020 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2022 /* special necessary for Wine */
2023 ValidateRect32(GetDlgItem(hDlg
,0x2d0),NULL
);
2024 ValidateRect32(GetDlgItem(hDlg
,0x2d1),NULL
);
2025 ValidateRect32(GetDlgItem(hDlg
,0x2c6),NULL
);
2026 ValidateRect32(GetDlgItem(hDlg
,0x2be),NULL
);
2027 ValidateRect32(GetDlgItem(hDlg
,0x2c5),NULL
);
2028 /* hope we can remove it later -->FIXME */
2033 /***********************************************************************
2034 * CC_WMLButtonDown [internal]
2036 static LRESULT
CC_WMLButtonDown(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2038 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
2041 if (CC_MouseCheckPredefColorArray(hDlg
,0x2d0,6,8,lParam
,&lpp
->lpcc
->rgbResult
))
2044 if (CC_MouseCheckUserColorArray(hDlg
,0x2d1,2,8,lParam
,&lpp
->lpcc
->rgbResult
,
2045 PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
)))
2048 if (CC_MouseCheckColorGraph(hDlg
,0x2c6,&lpp
->h
,&lpp
->s
,lParam
))
2051 if (CC_MouseCheckColorGraph(hDlg
,0x2be,NULL
,&lpp
->l
,lParam
))
2055 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
2056 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
2057 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
2058 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2062 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2063 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2064 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2065 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2066 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2067 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2071 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2072 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2073 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2074 CC_PaintTriangle(hDlg
,lpp
->l
);
2075 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2081 /***********************************************************************
2082 * ColorDlgProc (COMMDLG.8)
2084 LRESULT
ColorDlgProc(HWND hDlg
, UINT message
,
2085 UINT wParam
, LONG lParam
)
2088 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong(hDlg
, DWL_USER
);
2089 if (message
!=WM_INITDIALOG
)
2094 if (CC_HookCallChk(lpp
->lpcc
))
2095 res
=CallWindowProc16((FARPROC
)lpp
->lpcc
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2100 /* FIXME: SetRGB message
2101 if (message && message==msetrgb)
2102 return HandleSetRGB(hDlg,lParam);
2108 return CC_WMInitDialog(hDlg
,wParam
,lParam
);
2110 DeleteDC(lpp
->hdcMem
);
2111 DeleteObject(lpp
->hbmMem
);
2113 SetWindowLong32A(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
2116 if (CC_WMCommand(hDlg
, wParam
, lParam
))
2120 CC_WMPaint(hDlg
, wParam
, lParam
);
2122 case WM_LBUTTONDBLCLK
:
2123 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
2126 case WM_MOUSEMOVE
: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2128 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
2130 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
2131 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
2140 /***********************************************************************
2141 * ChooseFont (COMMDLG.15)
2143 BOOL
ChooseFont(LPCHOOSEFONT lpChFont
)
2145 HANDLE hInst
, hDlgTmpl
;
2147 dprintf_commdlg(stddeb
,"ChooseFont\n");
2148 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_FONT
);
2149 hInst
= WIN_GetWindowInstance( lpChFont
->hwndOwner
);
2150 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpChFont
->hwndOwner
,
2151 MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2153 SYSRES_FreeResource( hDlgTmpl
);
2158 #define TEXT_EXTRAS 4
2159 #define TEXT_COLORS 16
2161 static const COLORREF textcolors
[TEXT_COLORS
]=
2163 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
2164 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
2165 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
2166 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
2169 /***********************************************************************
2170 * CFn_HookCallChk [internal]
2172 static BOOL
CFn_HookCallChk(LPCHOOSEFONT lpcf
)
2175 if(lpcf
->Flags
& CF_ENABLEHOOK
)
2182 /***********************************************************************
2183 * FontFamilyEnumProc (COMMDLG.19)
2185 int FontFamilyEnumProc(LPLOGFONT lplf
,LPTEXTMETRIC lptm
, int nFontType
, LPARAM lParam
)
2189 HWND hwnd
=LOWORD(lParam
);
2190 HWND hDlg
=GetParent(hwnd
);
2191 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong(hDlg
, DWL_USER
);
2193 dprintf_commdlg(stddeb
,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2194 lplf
->lfFaceName
,nFontType
);
2196 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
2197 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
2199 if (lpcf
->Flags
& CF_ANSIONLY
)
2200 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
2202 if (lpcf
->Flags
& CF_TTONLY
)
2203 if (!(nFontType
& 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2206 i
=SendMessage16(hwnd
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR(lplf
->lfFaceName
));
2209 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
2210 SendMessage16(hwnd
, CB_SETITEMDATA
,i
,MAKELONG(nFontType
,w
));
2211 return 1 ; /* store some important font information */
2217 /*************************************************************************
2218 * SetFontStylesToCombo2 [internal]
2220 * Fill font style information into combobox (without using font.c directly)
2222 static int SetFontStylesToCombo2(HWND hwnd
, HDC hdc
, LPLOGFONT lplf
,LPTEXTMETRIC lptm
)
2229 static struct FONTSTYLE fontstyles
[FSTYLES
]={
2230 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
2231 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
2235 for (i
=0;i
<FSTYLES
;i
++)
2237 lplf
->lfItalic
=fontstyles
[i
].italic
;
2238 lplf
->lfWeight
=fontstyles
[i
].weight
;
2239 hf
=CreateFontIndirect(lplf
);
2240 hf
=SelectObject(hdc
,hf
);
2241 GetTextMetrics(hdc
,lptm
);
2242 hf
=SelectObject(hdc
,hf
);
2245 if (lptm
->tmWeight
==fontstyles
[i
].weight
&&
2246 lptm
->tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
2248 j
=SendMessage16(hwnd
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR(fontstyles
[i
].stname
));
2249 if (j
==CB_ERR
) return 1;
2250 j
=SendMessage16(hwnd
, CB_SETITEMDATA
, j
,
2251 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
2252 if (j
==CB_ERR
) return 1;
2258 /*************************************************************************
2259 * SetFontSizesToCombo3 [internal]
2261 static int SetFontSizesToCombo3(HWND hwnd
, LPLOGFONT lplf
, LPCHOOSEFONT lpcf
)
2263 int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2267 for (i
=0;sizes
[i
] && !lplf
->lfHeight
;i
++)
2269 h
=lplf
->lfHeight
? lplf
->lfHeight
: sizes
[i
];
2271 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2272 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
2274 sprintf(buffer
,"%2d",h
);
2275 j
=SendMessage16(hwnd
,CB_FINDSTRING
,-1,(LPARAM
)MAKE_SEGPTR(buffer
));
2278 j
=SendMessage16(hwnd
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR(buffer
));
2279 if (j
==CB_ERR
) return 1;
2280 j
=SendMessage16(hwnd
, CB_SETITEMDATA
, j
, h
);
2281 if (j
==CB_ERR
) return 1;
2289 /***********************************************************************
2290 * FontStyleEnumProc (COMMDLG.18)
2292 int FontStyleEnumProc(LPLOGFONT lplf
,LPTEXTMETRIC lptm
, int nFontType
, LPARAM lParam
)
2294 HWND hcmb2
=LOWORD(lParam
);
2295 HWND hcmb3
=HIWORD(lParam
);
2296 HWND hDlg
=GetParent(hcmb3
);
2297 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong(hDlg
, DWL_USER
);
2300 dprintf_commdlg(stddeb
,"FontStyleEnumProc: (nFontType=%d)\n",nFontType
);
2301 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",
2302 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,lplf
->lfEscapement
,lplf
->lfOrientation
,
2303 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,lplf
->lfStrikeOut
,lplf
->lfCharSet
,
2304 lplf
->lfOutPrecision
,lplf
->lfClipPrecision
,lplf
->lfQuality
,lplf
->lfPitchAndFamily
);
2306 if (SetFontSizesToCombo3(hcmb3
, lplf
,lpcf
))
2309 if (!SendMessage16(hcmb2
,CB_GETCOUNT
,0,0))
2311 HDC hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
2312 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
,lptm
);
2313 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2314 ReleaseDC(hDlg
,hdc
);
2322 /***********************************************************************
2323 * CFn_WMInitDialog [internal]
2325 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2330 FARPROC enumCallback
= MODULE_GetWndProcEntry16("FontFamilyEnumProc");
2332 HCURSOR hcursor
=SetCursor(LoadCursor(0,IDC_WAIT
));
2335 SetWindowLong32A(hDlg
, DWL_USER
, lParam
);
2336 lpcf
=(LPCHOOSEFONT
)lParam
;
2337 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2338 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
2340 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONT
))
2342 dprintf_commdlg(stddeb
,"WM_INITDIALOG: structure size failure !!!\n");
2343 EndDialog (hDlg
, 0);
2347 hBitmapTT
= LoadBitmap(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2349 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
2350 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
2351 if (!(lpcf
->Flags
& CF_APPLY
))
2352 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
2353 if (lpcf
->Flags
& CF_EFFECTS
)
2355 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
2357 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2358 j
=SendDlgItemMessage16(hDlg
,cmb4
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR("[color name]"));
2359 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETITEMDATA
,j
,textcolors
[j
]);
2360 /* look for a fitting value in color combobox */
2361 if (textcolors
[j
]==lpcf
->rgbColors
)
2362 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
2367 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
2368 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
2369 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
2370 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
2371 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
2373 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
2376 if (!EnumFontFamilies (hdc
, NULL
,enumCallback
,(LPARAM
)GetDlgItem(hDlg
,cmb1
)))
2377 dprintf_commdlg(stddeb
,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2378 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
2380 /* look for fitting font name in combobox1 */
2381 j
=SendDlgItemMessage16(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
2384 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL
,j
,0);
2385 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
2387 /* look for fitting font style in combobox2 */
2388 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
2389 for (i
=0;i
<TEXT_EXTRAS
;i
++)
2391 if (l
==SendDlgItemMessage16(hDlg
,cmb2
, CB_GETITEMDATA
,i
,0))
2392 SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL
,i
,0);
2395 /* look for fitting font size in combobox3 */
2396 j
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCOUNT
,0,0);
2399 if (lpxx
->lfHeight
==(int)SendDlgItemMessage16(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
2400 SendDlgItemMessage16(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
2405 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
2406 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
2409 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
2411 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
2414 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
2415 SendMessage16(hDlg
,WM_COMMAND
,cmb2
,MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
2421 dprintf_commdlg(stddeb
,"WM_INITDIALOG: HDC failure !!!\n");
2422 EndDialog (hDlg
, 0);
2426 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2427 ReleaseDC(hDlg
,hdc
);
2429 if (CFn_HookCallChk(lpcf
))
2430 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
2436 /***********************************************************************
2437 * CFn_WMMeasureItem [internal]
2439 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2442 LPMEASUREITEMSTRUCT lpmi
=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT
)lParam
);
2444 hBitmapTT
= LoadBitmap(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2445 GetObject(hBitmapTT
, sizeof(BITMAP
), (LPSTR
)&bm
);
2446 lpmi
->itemHeight
=bm
.bmHeight
;
2447 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2452 /***********************************************************************
2453 * CFn_WMDrawItem [internal]
2455 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2465 HBITMAP hBitmap
; /* for later TT usage */
2467 LPDRAWITEMSTRUCT16 lpdi
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
2469 if (lpdi
->itemID
== 0xFFFF) /* got no items */
2470 DrawFocusRect16(lpdi
->hDC
, &lpdi
->rcItem
);
2473 if (lpdi
->CtlType
== ODT_COMBOBOX
)
2475 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
2476 SelectObject(lpdi
->hDC
, hBrush
);
2477 FillRect16(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
2480 return TRUE
; /* this should never happen */
2483 switch (lpdi
->CtlID
)
2485 case cmb1
: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2486 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2487 (LPARAM
)MAKE_SEGPTR(buffer
));
2488 GetObject(hBitmapTT
, sizeof(BITMAP
), (LPSTR
)&bm
);
2489 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
2490 lpdi
->rcItem
.top
, buffer
, lstrlen(buffer
));
2492 nFontType
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
2493 /* FIXME: draw bitmap if truetype usage */
2494 if (nFontType
&TRUETYPE_FONTTYPE
)
2496 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
2497 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
2498 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
2499 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
2500 SelectObject(hMemDC
, hBitmap
);
2506 case cmb3
: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2507 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2508 (LPARAM
)MAKE_SEGPTR(buffer
));
2509 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
,
2510 lpdi
->rcItem
.top
, buffer
, lstrlen(buffer
));
2513 case cmb4
: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2514 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2515 (LPARAM
)MAKE_SEGPTR(buffer
));
2516 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
2517 lpdi
->rcItem
.top
, buffer
, lstrlen(buffer
));
2518 cr
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
2519 hBrush
= CreateSolidBrush(cr
);
2522 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
2523 rect
.right
=rect
.left
+25;
2527 Rectangle(lpdi
->hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
2528 DeleteObject (SelectObject (lpdi
->hDC
, hBrush
)) ;
2534 default: return TRUE
; /* this should never happen */
2536 if (lpdi
->itemState
==ODS_SELECTED
)
2537 InvertRect16(lpdi
->hDC
, &rect
);
2542 /***********************************************************************
2543 * CFn_WMCtlColor [internal]
2545 LRESULT
CFn_WMCtlColor(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2547 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong(hDlg
, DWL_USER
);
2549 if (lpcf
->Flags
& CF_EFFECTS
)
2550 if (HIWORD(lParam
)==CTLCOLOR_STATIC
&& GetDlgCtrlID(LOWORD(lParam
))==stc6
)
2552 SetTextColor(wParam
,lpcf
->rgbColors
);
2553 return GetStockObject(WHITE_BRUSH
);
2558 /***********************************************************************
2559 * CFn_WMCommand [internal]
2561 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2564 FARPROC enumCallback
;
2565 HFONT hFont
/*,hFontOld*/;
2569 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong(hDlg
, DWL_USER
);
2570 LPLOGFONT lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2572 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam
);
2575 case cmb1
:if (HIWORD(lParam
)==CBN_SELCHANGE
)
2577 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
2580 SendDlgItemMessage16(hDlg
,cmb2
,CB_RESETCONTENT
,0,0);
2581 SendDlgItemMessage16(hDlg
,cmb3
,CB_RESETCONTENT
,0,0);
2582 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
2585 HCURSOR hcursor
=SetCursor(LoadCursor(0,IDC_WAIT
));
2586 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT
,i
,(LPARAM
)MAKE_SEGPTR(buffer
));
2587 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb1 =>%s\n",buffer
);
2588 enumCallback
= MODULE_GetWndProcEntry16("FontStyleEnumProc");
2589 EnumFontFamilies(hdc
,buffer
,enumCallback
,
2590 MAKELONG(GetDlgItem(hDlg
,cmb2
),GetDlgItem(hDlg
,cmb3
)));
2593 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2594 ReleaseDC(hDlg
,hdc
);
2598 dprintf_commdlg(stddeb
,"WM_COMMAND: HDC failure !!!\n");
2599 EndDialog (hDlg
, 0);
2606 case cmb3
:if (HIWORD(lParam
)==CBN_SELCHANGE
|| HIWORD(lParam
)== BN_CLICKED
)
2608 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
2609 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
2611 i
=GetDlgItemText32A( hDlg
, cmb1
, buffer
, sizeof(buffer
) );
2614 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT
,i
,(LPARAM
)MAKE_SEGPTR(buffer
));
2615 l
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
2617 lpcf
->nFontType
= LOWORD(l
);
2618 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2619 /* same value reported to the EnumFonts
2620 call back with the extra FONTTYPE_... bits added */
2621 lpxx
->lfPitchAndFamily
=j
&0xff;
2622 lpxx
->lfCharSet
=j
>>8;
2624 strcpy(lpxx
->lfFaceName
,buffer
);
2625 i
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETCURSEL
,0,0);
2628 l
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETITEMDATA
,i
,0);
2629 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
2630 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
2631 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
2632 lpcf
->nFontType
|= BOLD_FONTTYPE
;
2634 i
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCURSEL
,0,0);
2636 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessage16(hDlg
,cmb3
,CB_GETITEMDATA
,i
,0));
2639 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
2640 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
2641 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
2642 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
2643 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
2644 lpxx
->lfQuality
=DEFAULT_QUALITY
;
2646 hFont
=CreateFontIndirect(lpxx
);
2648 SendDlgItemMessage16(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
2649 /* FIXME: Delete old font ...? */
2653 case cmb4
:i
=SendDlgItemMessage16(hDlg
,cmb4
,CB_GETCURSEL
,0,0);
2656 lpcf
->rgbColors
=textcolors
[i
];
2657 InvalidateRect32( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
2661 case psh15
:i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2662 if (lpcf
->hwndOwner
)
2663 SendMessage16(lpcf
->hwndOwner
,i
,0,(LPARAM
)lpcf
);
2664 if (CFn_HookCallChk(lpcf
))
2665 CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_COMMAND
,psh15
,(LPARAM
)lpcf
);
2668 case IDOK
:EndDialog(hDlg
, TRUE
);
2670 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
2677 /***********************************************************************
2678 * FormatCharDlgProc (COMMDLG.16)
2679 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2680 2. some CF_.. flags are not supported
2681 3. some TType extensions
2683 LRESULT
FormatCharDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2685 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong(hDlg
, DWL_USER
);
2686 if (message
!=WM_INITDIALOG
)
2691 if (CFn_HookCallChk(lpcf
))
2692 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2697 return CFn_WMInitDialog(hDlg
,wParam
,lParam
);
2700 case WM_MEASUREITEM
:
2701 return CFn_WMMeasureItem(hDlg
,wParam
,lParam
);
2703 return CFn_WMDrawItem(hDlg
,wParam
,lParam
);
2705 return CFn_WMCtlColor(hDlg
,wParam
,lParam
);
2707 return CFn_WMCommand(hDlg
,wParam
,lParam
);
2708 case WM_CHOOSEFONT_GETLOGFONT
:
2709 dprintf_commdlg(stddeb
,
2710 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam
);
2711 /* FIXME: current logfont back to caller */