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
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER
));
42 if (!hFolder2
) hFolder2
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER2
));
43 if (!hFloppy
) hFloppy
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_FLOPPY
));
44 if (!hHDisk
) hHDisk
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_HDISK
));
45 if (!hCDRom
) hCDRom
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_CDROM
));
46 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
47 hHDisk
== 0 || hCDRom
== 0)
49 fprintf(stderr
, "FileDlg_Init // Error loading bitmaps !");
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
= FindResource16(lpofn
->hInstance
,
72 lpofn
->lpTemplateName
, RT_DIALOG
)))
74 CommDlgLastError
= CDERR_FINDRESFAILURE
;
77 hDlgTmpl
= LoadResource16( lpofn
->hInstance
, hResInfo
);
79 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_OPEN_FILE
);
82 CommDlgLastError
= CDERR_LOADRESFAILURE
;
86 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
87 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpofn
->hwndOwner
,
88 (DLGPROC16
)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
91 if (!(lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
))
93 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
94 else SYSRES_FreeResource( hDlgTmpl
);
97 dprintf_commdlg(stddeb
,"GetOpenFileName // return lpstrFile='%s' !\n",
98 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
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
= FindResource16(lpofn
->hInstance
,
119 lpofn
->lpTemplateName
, RT_DIALOG
)))
121 CommDlgLastError
= CDERR_FINDRESFAILURE
;
124 hDlgTmpl
= LoadResource16( lpofn
->hInstance
, hResInfo
);
126 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE
);
128 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
129 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpofn
->hwndOwner
,
130 (DLGPROC16
)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
132 if (!(lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
))
134 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
135 else SYSRES_FreeResource( hDlgTmpl
);
138 dprintf_commdlg(stddeb
, "GetSaveFileName // return lpstrFile='%s' !\n",
139 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
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
,int savedlg
)
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
));
226 if (savedlg
) /* use _gray_ text in FileSaveDlg */
227 if (!lpdis
->itemState
)
228 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_GRAYTEXT
) );
230 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_WINDOWTEXT
) );
231 /* inversion of gray would be bad readable */
233 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
235 if (lpdis
->itemState
!= 0) {
236 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
241 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
) {
242 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
243 SelectObject(lpdis
->hDC
, hBrush
);
244 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
245 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
246 (LPARAM
)MAKE_SEGPTR(str
));
249 GetObject16( hBitmap
, sizeof(bm
), &bm
);
250 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
251 lpdis
->rcItem
.top
, str
, strlen(str
));
252 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
253 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
254 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
255 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
256 SelectObject(hMemDC
, hPrevBitmap
);
258 if (lpdis
->itemState
!= 0) {
259 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
263 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
) {
264 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
265 SelectObject(lpdis
->hDC
, hBrush
);
266 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
267 SendMessage16(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
268 (LPARAM
)MAKE_SEGPTR(str
));
269 switch(DRIVE_GetType( str
[2] - 'a' ))
271 case TYPE_FLOPPY
: hBitmap
= hFloppy
; break;
272 case TYPE_CDROM
: hBitmap
= hCDRom
; break;
275 default: hBitmap
= hHDisk
; break;
277 GetObject16( hBitmap
, sizeof(bm
), &bm
);
278 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
279 lpdis
->rcItem
.top
, str
, strlen(str
));
280 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
281 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
282 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
283 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
284 SelectObject(hMemDC
, hPrevBitmap
);
286 if (lpdis
->itemState
!= 0) {
287 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
294 /***********************************************************************
295 * FILEDLG_WMMeasureItem [internal]
297 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
300 LPMEASUREITEMSTRUCT16 lpmeasure
;
302 GetObject16( hFolder2
, sizeof(bm
), &bm
);
303 lpmeasure
= (LPMEASUREITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
304 lpmeasure
->itemHeight
= bm
.bmHeight
;
308 /***********************************************************************
309 * FILEDLG_HookCallChk [internal]
311 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn
)
314 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
320 /***********************************************************************
321 * FILEDLG_WMInitDialog [internal]
324 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
328 LPOPENFILENAME lpofn
;
331 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
332 lpofn
= (LPOPENFILENAME
)lParam
;
333 if (lpofn
->lpstrTitle
) SetWindowText16( hWnd
, lpofn
->lpstrTitle
);
334 /* read custom filter information */
335 if (lpofn
->lpstrCustomFilter
)
337 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
);
338 dprintf_commdlg(stddeb
,"lpstrCustomFilter = %p\n", pstr
);
342 strncpy(tmpstr
, pstr
, 511); tmpstr
[511]=0;
343 dprintf_commdlg(stddeb
,"lpstrCustomFilter // add tmpstr='%s' ", tmpstr
);
344 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
347 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
348 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
352 /* read filter information */
353 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
357 strncpy(tmpstr
, pstr
, 511); tmpstr
[511]=0;
358 dprintf_commdlg(stddeb
,"lpstrFilter // add tmpstr='%s' ", tmpstr
);
359 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
362 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
363 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
366 /* set default filter */
367 if (lpofn
->nFilterIndex
== 0 && lpofn
->lpstrCustomFilter
== (SEGPTR
)NULL
)
368 lpofn
->nFilterIndex
= 1;
369 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETCURSEL
, lpofn
->nFilterIndex
- 1, 0);
370 strncpy(tmpstr
, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
371 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lpofn
->nFilterIndex
- 1),511);
373 dprintf_commdlg(stddeb
,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
374 lpofn
->nFilterIndex
, tmpstr
);
375 SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
378 DlgDirListComboBox16(hWnd
, (LPSTR
)MAKE_SEGPTR(tmpstr
), cmb2
, 0, 0xC000);
379 /* read initial directory */
380 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
)
382 strncpy(tmpstr
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
), 510);
384 if (strlen(tmpstr
) > 0 && tmpstr
[strlen(tmpstr
)-1] != '\\'
385 && tmpstr
[strlen(tmpstr
)-1] != ':')
390 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
391 fprintf(stderr
, "FileDlg: couldn't read initial directory %s!\n", tmpstr
);
392 /* select current drive in combo 2 */
393 n
= DRIVE_GetCurrentDrive();
394 SendDlgItemMessage16(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
395 if (!(lpofn
->Flags
& OFN_SHOWHELP
))
396 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
397 if (lpofn
->Flags
& OFN_HIDEREADONLY
)
398 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
399 if (FILEDLG_HookCallChk(lpofn
))
400 return (BOOL
)CallWindowProc16(lpofn
->lpfnHook
,
401 hWnd
, WM_INITDIALOG
, wParam
,(LPARAM
)MAKE_SEGPTR(lpofn
));
406 /***********************************************************************
407 * FILEDLG_WMCommand [internal]
409 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
412 LPOPENFILENAME lpofn
;
414 char tmpstr
[512], tmpstr2
[512];
416 UINT control
,notification
;
418 /* Notifications are packaged differently in Win32 */
420 control
= LOWORD(wParam
);
421 notification
= HIWORD(wParam
);
424 notification
= HIWORD(lParam
);
427 lpofn
= (LPOPENFILENAME
)GetWindowLong32A(hWnd
, DWL_USER
);
430 case lst1
: /* file list */
431 FILEDLG_StripEditControl(hWnd
);
432 if (notification
== LBN_DBLCLK
)
434 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL
, 0, 0);
435 if (lRet
== LB_ERR
) return TRUE
;
436 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT
, lRet
,
437 (LPARAM
)MAKE_SEGPTR(tmpstr
));
438 SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
440 if (FILEDLG_HookCallChk(lpofn
))
441 CallWindowProc16(lpofn
->lpfnHook
, hWnd
,
442 RegisterWindowMessage32A( LBSELCHSTRING
),
443 control
, MAKELONG(lRet
,CD_LBSELCHANGE
));
444 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
446 case lst2
: /* directory list */
447 FILEDLG_StripEditControl(hWnd
);
448 if (notification
== LBN_DBLCLK
)
450 lRet
= SendDlgItemMessage16(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
451 if (lRet
== LB_ERR
) return TRUE
;
452 SendDlgItemMessage16(hWnd
, lst2
, LB_GETTEXT
, lRet
,
453 (LPARAM
)MAKE_SEGPTR(tmpstr
));
454 if (tmpstr
[0] == '[')
456 tmpstr
[strlen(tmpstr
) - 1] = 0;
457 strcpy(tmpstr
,tmpstr
+1);
459 strcat(tmpstr
, "\\");
463 case cmb1
: /* file type drop list */
464 if (notification
== CBN_SELCHANGE
)
470 case cmb2
: /* disk drop list */
471 FILEDLG_StripEditControl(hWnd
);
472 lRet
= SendDlgItemMessage16(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
473 if (lRet
== LB_ERR
) return 0;
474 SendDlgItemMessage16(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
, (LPARAM
)MAKE_SEGPTR(tmpstr
));
475 sprintf(tmpstr
, "%c:", tmpstr
[2]);
477 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
480 pstr
= (LPSTR
)SendDlgItemMessage16(hWnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
481 dprintf_commdlg(stddeb
,"Selected filter : %s\n", pstr
);
482 SetDlgItemText32A( hWnd
, edt1
, pstr
);
483 FILEDLG_ScanDir(hWnd
, tmpstr
);
491 ofn2
=*lpofn
; /* for later restoring */
492 GetDlgItemText32A( hWnd
, edt1
, tmpstr
, sizeof(tmpstr
) );
493 pstr
= strrchr(tmpstr
, '\\');
495 pstr
= strrchr(tmpstr
, ':');
496 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
498 /* edit control contains wildcards */
501 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
506 strcpy(tmpstr2
, tmpstr
);
509 dprintf_commdlg(stddeb
,"commdlg: %s, %s\n", tmpstr
, tmpstr2
);
510 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
511 FILEDLG_ScanDir(hWnd
, tmpstr
);
514 /* no wildcards, we might have a directory or a filename */
515 /* try appending a wildcard and reading the directory */
516 pstr2
= tmpstr
+ strlen(tmpstr
);
517 if (pstr
== NULL
|| *(pstr
+1) != 0)
518 strcat(tmpstr
, "\\");
519 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
520 if (lRet
== LB_ERR
) return TRUE
;
521 lpofn
->nFilterIndex
= lRet
+ 1;
522 dprintf_commdlg(stddeb
,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn
->nFilterIndex
);
524 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
525 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
526 lRet
), sizeof(tmpstr2
));
527 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
528 /* if ScanDir succeeds, we have changed the directory */
529 if (FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
530 /* if not, this must be a filename */
534 /* strip off the pathname */
536 SetDlgItemText32A( hWnd
, edt1
, pstr
+ 1 );
537 lstrcpyn32A(tmpstr2
, pstr
+1, sizeof(tmpstr2
) );
538 /* Should we MessageBox() if this fails? */
539 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
540 strcpy(tmpstr
, tmpstr2
);
542 else SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
544 ShowWindow(hWnd
, SW_HIDE
); /* this should not be necessary ?! (%%%) */
547 int drive
= DRIVE_GetCurrentDrive();
548 tmpstr2
[0] = 'A'+ drive
;
551 strncpy(tmpstr2
+ 3, DRIVE_GetDosCwd(drive
), 507); tmpstr2
[510]=0;
552 if (strlen(tmpstr2
) > 3)
553 strcat(tmpstr2
, "\\");
554 strncat(tmpstr2
, tmpstr
, 511-strlen(tmpstr2
)); tmpstr2
[511]=0;
555 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), tmpstr2
);
557 lpofn
->nFileOffset
= 0;
558 lpofn
->nFileExtension
= 0;
559 while(tmpstr2
[lpofn
->nFileExtension
] != '.' && tmpstr2
[lpofn
->nFileExtension
] != '\0')
560 lpofn
->nFileExtension
++;
561 if (lpofn
->nFileExtension
== '\0')
562 lpofn
->nFileExtension
= 0;
564 lpofn
->nFileExtension
++;
565 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
)
567 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL
, 0, 0);
568 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT
, lRet
,
569 (LPARAM
)MAKE_SEGPTR(tmpstr
));
570 dprintf_commdlg(stddeb
,"strcpy'ing '%s'\n",tmpstr
); fflush(stdout
);
571 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
), tmpstr
);
573 if (FILEDLG_HookCallChk(lpofn
))
575 lRet
= (BOOL
)CallWindowProc16(lpofn
->lpfnHook
,
576 hWnd
, RegisterWindowMessage32A( FILEOKSTRING
),
577 0, (LPARAM
)MAKE_SEGPTR(lpofn
));
580 *lpofn
=ofn2
; /* restore old state */
582 ShowWindow(hWnd
, SW_SHOW
); /* only if above (%%%) SW_HIDE used */
587 EndDialog(hWnd
, TRUE
);
590 EndDialog(hWnd
, FALSE
);
597 /***********************************************************************
598 * FileOpenDlgProc (COMMDLG.6)
600 LRESULT
FileOpenDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
602 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)GetWindowLong32A(hWnd
, DWL_USER
);
604 if (wMsg
!=WM_INITDIALOG
)
605 if (FILEDLG_HookCallChk(lpofn
))
607 LRESULT lRet
=(BOOL
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
609 return lRet
; /* else continue message processing */
614 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
616 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
618 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
);
620 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
623 SetBkColor((HDC
)wParam
, 0x00C0C0C0);
624 switch (HIWORD(lParam
))
627 SetTextColor((HDC
)wParam
, 0x00000000);
629 case CTLCOLOR_STATIC
:
630 SetTextColor((HDC
)wParam
, 0x00000000);
640 /***********************************************************************
641 * FileSaveDlgProc (COMMDLG.7)
643 LRESULT
FileSaveDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
645 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)GetWindowLong32A(hWnd
, DWL_USER
);
647 if (wMsg
!=WM_INITDIALOG
)
648 if (FILEDLG_HookCallChk(lpofn
))
650 LRESULT lRet
=(BOOL
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
652 return lRet
; /* else continue message processing */
656 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
659 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
662 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
);
665 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
670 SetBkColor((HDC)wParam, 0x00C0C0C0);
671 switch (HIWORD(lParam))
674 SetTextColor((HDC)wParam, 0x00000000);
676 case CTLCOLOR_STATIC:
677 SetTextColor((HDC)wParam, 0x00000000);
687 /***********************************************************************
688 * FindTextDlg (COMMDLG.11)
690 BOOL
FindText(LPFINDREPLACE lpFind
)
692 HANDLE hInst
, hDlgTmpl
;
697 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
698 * For now, only the standard dialog works.
701 * FIXME : We should do error checking on the lpFind structure here
702 * and make CommDlgExtendedError() return the error condition.
704 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT
);
705 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
706 if (!(ptr
= GlobalLock16( hDlgTmpl
))) return -1;
707 bRet
= CreateDialogIndirectParam16( hInst
, ptr
, lpFind
->hwndOwner
,
708 (DLGPROC16
)MODULE_GetWndProcEntry16("FindTextDlgProc"),
710 GlobalUnlock16( hDlgTmpl
);
711 SYSRES_FreeResource( hDlgTmpl
);
716 /***********************************************************************
717 * ReplaceTextDlg (COMMDLG.12)
719 BOOL
ReplaceText(LPFINDREPLACE lpFind
)
721 HANDLE hInst
, hDlgTmpl
;
726 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
727 * For now, only the standard dialog works.
730 * FIXME : We should do error checking on the lpFind structure here
731 * and make CommDlgExtendedError() return the error condition.
733 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT
);
734 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
735 if (!(ptr
= GlobalLock16( hDlgTmpl
))) return -1;
736 bRet
= CreateDialogIndirectParam16( hInst
, ptr
, lpFind
->hwndOwner
,
737 (DLGPROC16
)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
739 GlobalUnlock16( hDlgTmpl
);
740 SYSRES_FreeResource( hDlgTmpl
);
745 /***********************************************************************
746 * FINDDLG_WMInitDialog [internal]
748 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
752 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
753 lpfr
= (LPFINDREPLACE
)lParam
;
754 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
756 * FIXME : If the initial FindWhat string is empty, we should disable the
757 * FindNext (IDOK) button. Only after typing some text, the button should be
760 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
761 CheckRadioButton(hWnd
, rad1
, rad2
, (lpfr
->Flags
& FR_DOWN
) ? rad2
: rad1
);
762 if (lpfr
->Flags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
763 EnableWindow(GetDlgItem(hWnd
, rad1
), FALSE
);
764 EnableWindow(GetDlgItem(hWnd
, rad2
), FALSE
);
766 if (lpfr
->Flags
& FR_HIDEUPDOWN
) {
767 ShowWindow(GetDlgItem(hWnd
, rad1
), SW_HIDE
);
768 ShowWindow(GetDlgItem(hWnd
, rad2
), SW_HIDE
);
769 ShowWindow(GetDlgItem(hWnd
, grp1
), SW_HIDE
);
771 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
772 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
773 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
774 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
775 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
776 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
777 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
778 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
779 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
780 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
781 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
782 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
783 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
785 ShowWindow(hWnd
, SW_SHOWNORMAL
);
790 /***********************************************************************
791 * FINDDLG_WMCommand [internal]
793 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
796 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
797 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
799 lpfr
= (LPFINDREPLACE
)GetWindowLong32A(hWnd
, DWL_USER
);
802 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
803 if (IsDlgButtonChecked(hWnd
, rad2
))
804 lpfr
->Flags
|= FR_DOWN
;
805 else lpfr
->Flags
&= ~FR_DOWN
;
806 if (IsDlgButtonChecked(hWnd
, chx1
))
807 lpfr
->Flags
|= FR_WHOLEWORD
;
808 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
809 if (IsDlgButtonChecked(hWnd
, chx2
))
810 lpfr
->Flags
|= FR_MATCHCASE
;
811 else lpfr
->Flags
&= ~FR_MATCHCASE
;
812 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
813 lpfr
->Flags
|= FR_FINDNEXT
;
814 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
817 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
818 lpfr
->Flags
|= FR_DIALOGTERM
;
819 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
823 /* FIXME : should lpfr structure be passed as an argument ??? */
824 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
831 /***********************************************************************
832 * FindTextDlgProc (COMMDLG.13)
834 LRESULT
FindTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
838 return FINDDLG_WMInitDialog(hWnd
, wParam
, lParam
);
840 return FINDDLG_WMCommand(hWnd
, wParam
, lParam
);
846 /***********************************************************************
847 * REPLACEDLG_WMInitDialog [internal]
849 static LRESULT
REPLACEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
853 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
854 lpfr
= (LPFINDREPLACE
)lParam
;
855 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
857 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
858 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
861 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
862 SetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
);
863 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
864 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
865 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
866 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
867 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
868 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
869 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
870 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
871 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
872 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
873 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
874 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
875 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
877 ShowWindow(hWnd
, SW_SHOWNORMAL
);
882 /***********************************************************************
883 * REPLACEDLG_WMCommand [internal]
885 static LRESULT
REPLACEDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
888 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
889 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
891 lpfr
= (LPFINDREPLACE
)GetWindowLong32A(hWnd
, DWL_USER
);
894 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
895 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
896 if (IsDlgButtonChecked(hWnd
, chx1
))
897 lpfr
->Flags
|= FR_WHOLEWORD
;
898 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
899 if (IsDlgButtonChecked(hWnd
, chx2
))
900 lpfr
->Flags
|= FR_MATCHCASE
;
901 else lpfr
->Flags
&= ~FR_MATCHCASE
;
902 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
903 lpfr
->Flags
|= FR_FINDNEXT
;
904 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
907 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
908 lpfr
->Flags
|= FR_DIALOGTERM
;
909 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
913 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
914 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
915 if (IsDlgButtonChecked(hWnd
, chx1
))
916 lpfr
->Flags
|= FR_WHOLEWORD
;
917 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
918 if (IsDlgButtonChecked(hWnd
, chx2
))
919 lpfr
->Flags
|= FR_MATCHCASE
;
920 else lpfr
->Flags
&= ~FR_MATCHCASE
;
921 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
922 lpfr
->Flags
|= FR_REPLACE
;
923 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
926 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
927 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
928 if (IsDlgButtonChecked(hWnd
, chx1
))
929 lpfr
->Flags
|= FR_WHOLEWORD
;
930 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
931 if (IsDlgButtonChecked(hWnd
, chx2
))
932 lpfr
->Flags
|= FR_MATCHCASE
;
933 else lpfr
->Flags
&= ~FR_MATCHCASE
;
934 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
935 lpfr
->Flags
|= FR_REPLACEALL
;
936 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0, (LPARAM
)MAKE_SEGPTR(lpfr
));
939 /* FIXME : should lpfr structure be passed as an argument ??? */
940 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
947 /***********************************************************************
948 * ReplaceTextDlgProc (COMMDLG.14)
950 LRESULT
ReplaceTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
954 return REPLACEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
956 return REPLACEDLG_WMCommand(hWnd
, wParam
, lParam
);
962 /***********************************************************************
963 * PrintDlg (COMMDLG.20)
965 BOOL
PrintDlg(LPPRINTDLG lpPrint
)
967 HANDLE hInst
, hDlgTmpl
;
970 dprintf_commdlg(stddeb
,"PrintDlg(%p) // Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
972 if (lpPrint
->Flags
& PD_RETURNDEFAULT
)
973 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
976 if (lpPrint
->Flags
& PD_PRINTSETUP
)
977 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP
);
979 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT
);
981 hInst
= WIN_GetWindowInstance( lpPrint
->hwndOwner
);
982 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpPrint
->hwndOwner
,
983 (DLGPROC16
)((lpPrint
->Flags
& PD_PRINTSETUP
) ?
984 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
985 MODULE_GetWndProcEntry16("PrintDlgProc")),
987 SYSRES_FreeResource( hDlgTmpl
);
992 /***********************************************************************
993 * PrintDlgProc (COMMDLG.21)
995 LRESULT
PrintDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
1000 dprintf_commdlg(stddeb
,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1001 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1007 EndDialog(hWnd
, TRUE
);
1010 EndDialog(hWnd
, FALSE
);
1019 /***********************************************************************
1020 * PrintSetupDlgProc (COMMDLG.22)
1022 LRESULT
PrintSetupDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
1027 dprintf_commdlg(stddeb
,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1028 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1033 EndDialog(hWnd
, TRUE
);
1036 EndDialog(hWnd
, FALSE
);
1045 /***********************************************************************
1046 * CommDlgExtendedError (COMMDLG.26)
1048 DWORD
CommDlgExtendedError(void)
1050 return CommDlgLastError
;
1054 /***********************************************************************
1055 * GetFileTitle (COMMDLG.27)
1057 short GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT cbBuf
)
1060 dprintf_commdlg(stddeb
,"GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
1061 if (lpFile
== NULL
|| lpTitle
== NULL
)
1063 len
= strlen(lpFile
);
1066 if (strpbrk(lpFile
, "*[]"))
1069 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
1071 for (i
= len
; i
>= 0; i
--)
1072 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
1077 dprintf_commdlg(stddeb
,"\n---> '%s' ", &lpFile
[i
]);
1079 len
= strlen(lpFile
+i
)+1;
1083 strncpy(lpTitle
, &lpFile
[i
], len
);
1088 /* ------------------------ Choose Color Dialog --------------------------- */
1090 /***********************************************************************
1091 * ChooseColor (COMMDLG.5)
1093 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
1096 HANDLE hDlgTmpl
, hResInfo
;
1099 dprintf_commdlg(stddeb
,"ChooseColor\n");
1100 if (!lpChCol
) return FALSE
;
1101 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpChCol
->hInstance
;
1102 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1104 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
1105 lpChCol
->lpTemplateName
, RT_DIALOG
)))
1107 CommDlgLastError
= CDERR_FINDRESFAILURE
;
1110 hDlgTmpl
= LoadResource16( lpChCol
->hInstance
, hResInfo
);
1112 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR
);
1115 CommDlgLastError
= CDERR_LOADRESFAILURE
;
1118 hInst
= WIN_GetWindowInstance( lpChCol
->hwndOwner
);
1119 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpChCol
->hwndOwner
,
1120 (DLGPROC16
)MODULE_GetWndProcEntry16("ColorDlgProc"),
1122 if (!(lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
))
1124 if (lpChCol
->Flags
& CC_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
1125 else SYSRES_FreeResource( hDlgTmpl
);
1131 static const COLORREF predefcolors
[6][8]=
1133 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
1134 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
1135 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
1136 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
1138 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
1139 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
1140 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
1141 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
1143 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
1144 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
1145 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
1146 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
1151 LPCHOOSECOLOR lpcc
; /* points to public known data structure */
1152 int nextuserdef
; /* next free place in user defined color array */
1153 HDC hdcMem
; /* color graph used for BitBlt() */
1154 HBITMAP hbmMem
; /* color graph bitmap */
1155 RECT16 fullsize
; /* original dialog window size */
1156 UINT msetrgb
; /* # of SETRGBSTRING message (today not used) */
1157 RECT16 old3angle
; /* last position of l-marker */
1158 RECT16 oldcross
; /* last position of color/satuation marker */
1159 BOOL updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1162 int l
; /* for temporary storing of hue,sat,lum */
1165 /***********************************************************************
1166 * CC_HSLtoRGB [internal]
1168 static int CC_HSLtoRGB(char c
,int hue
,int sat
,int lum
)
1175 case 'R':if (hue
>80) hue
-=80; else hue
+=160; break;
1176 case 'G':if (hue
>160) hue
-=160; else hue
+=80; break;
1181 maxrgb
=(256*MIN(120,lum
))/120; /* 0 .. 256 */
1187 res
=(hue
-80)* maxrgb
; /* 0...10240 */
1188 res
/=40; /* 0...256 */
1195 res
=(240-hue
)* maxrgb
;
1198 res
=res
-maxrgb
/2; /* -128...128 */
1201 res
=maxrgb
/2 + (sat
*res
) /240; /* 0..256 */
1204 if (lum
>120 && res
<256)
1205 res
+=((lum
-120) * (256-res
))/120;
1207 return MIN(res
,255);
1210 /***********************************************************************
1211 * CC_RGBtoHSL [internal]
1213 static int CC_RGBtoHSL(char c
,int r
,int g
,int b
)
1215 WORD maxi
,mini
,mmsum
,mmdif
,result
=0;
1229 case 'L':mmsum
*=120; /* 0...61200=(255+255)*120 */
1230 result
=mmsum
/255; /* 0...240 */
1233 case 'S':if (!mmsum
)
1236 if (!mini
|| maxi
==255)
1240 result
=mmdif
*240; /* 0...61200=255*240 */
1241 result
/= (mmsum
>255 ? mmsum
=510-mmsum
: mmsum
); /* 0..255 */
1245 case 'H':if (!mmdif
)
1251 iresult
=40*(g
-b
); /* -10200 ... 10200 */
1252 iresult
/=(int)mmdif
; /* -40 .. 40 */
1254 iresult
+=240; /* 0..40 and 200..240 */
1260 iresult
/=(int)mmdif
;
1261 iresult
+=80; /* 40 .. 120 */
1267 iresult
/=(int)mmdif
;
1268 iresult
+=160; /* 120 .. 200 */
1274 return result
; /* is this integer arithmetic precise enough ? */
1279 /***********************************************************************
1280 * CC_MouseCheckPredefColorArray [internal]
1282 static int CC_MouseCheckPredefColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1283 LPARAM lParam
,COLORREF
*cr
)
1286 POINT16 point
= MAKEPOINT16(lParam
);
1290 ClientToScreen16(hDlg
,&point
);
1291 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1292 GetWindowRect16(hwnd
,&rect
);
1293 if (PtInRect16(&rect
,point
))
1295 dx
=(rect
.right
-rect
.left
)/cols
;
1296 dy
=(rect
.bottom
-rect
.top
)/rows
;
1297 ScreenToClient16(hwnd
,&point
);
1299 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1303 *cr
=predefcolors
[y
][x
];
1304 /* FIXME: Draw_a_Focus_Rect() */
1311 /***********************************************************************
1312 * CC_MouseCheckUserColorArray [internal]
1314 static int CC_MouseCheckUserColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1315 LPARAM lParam
,COLORREF
*cr
,COLORREF
*crarr
)
1318 POINT16 point
= MAKEPOINT16(lParam
);
1322 ClientToScreen16(hDlg
,&point
);
1323 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1324 GetWindowRect16(hwnd
,&rect
);
1325 if (PtInRect16(&rect
,point
))
1327 dx
=(rect
.right
-rect
.left
)/cols
;
1328 dy
=(rect
.bottom
-rect
.top
)/rows
;
1329 ScreenToClient16(hwnd
,&point
);
1331 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1335 *cr
=crarr
[x
+cols
*y
];
1336 /* FIXME: Draw_a_Focus_Rect() */
1346 /* 240 ^...... ^^ 240
1353 /***********************************************************************
1354 * CC_MouseCheckColorGraph [internal]
1356 static int CC_MouseCheckColorGraph(HWND hDlg
,int dlgitem
,int *hori
,int *vert
,LPARAM lParam
)
1359 POINT16 point
= MAKEPOINT16(lParam
);
1363 ClientToScreen16(hDlg
,&point
);
1364 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1365 GetWindowRect16(hwnd
,&rect
);
1366 if (PtInRect16(&rect
,point
))
1368 GetClientRect16(hwnd
,&rect
);
1369 ScreenToClient16(hwnd
,&point
);
1371 x
=(long)point
.x
*MAXHORI
;
1373 y
=(long)(rect
.bottom
-point
.y
)*MAXVERT
;
1385 /***********************************************************************
1386 * CC_MouseCheckResultWindow [internal]
1388 static int CC_MouseCheckResultWindow(HWND hDlg
,LPARAM lParam
)
1391 POINT16 point
= MAKEPOINT16(lParam
);
1394 ClientToScreen16(hDlg
,&point
);
1395 hwnd
=GetDlgItem(hDlg
,0x2c5);
1396 GetWindowRect16(hwnd
,&rect
);
1397 if (PtInRect16(&rect
,point
))
1399 PostMessage(hDlg
,WM_COMMAND
,0x2c9,0);
1405 /***********************************************************************
1406 * CC_CheckDigitsInEdit [internal]
1408 static int CC_CheckDigitsInEdit(HWND hwnd
,int maxval
)
1410 int i
,k
,m
,result
,value
;
1413 GetWindowText32A(hwnd
,buffer
,sizeof(buffer
));
1418 if (buffer
[i
]<'0' || buffer
[i
]>'9')
1420 for (k
=i
+1;k
<=m
;k
++) /* delete bad character */
1422 buffer
[i
]=buffer
[k
];
1430 if (value
>maxval
) /* build a new string */
1432 sprintf(buffer
,"%d",maxval
);
1437 editpos
=SendMessage16(hwnd
,EM_GETSEL
,0,0);
1438 SetWindowText32A(hwnd
,buffer
);
1439 SendMessage16(hwnd
,EM_SETSEL
,0,editpos
);
1446 /***********************************************************************
1447 * CC_PaintSelectedColor [internal]
1449 static void CC_PaintSelectedColor(HWND hDlg
,COLORREF cr
)
1454 HWND hwnd
=GetDlgItem(hDlg
,0x2c5);
1455 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1458 GetClientRect16 (hwnd
, &rect
) ;
1459 hBrush
= CreateSolidBrush(cr
);
1462 hBrush
= SelectObject (hdc
, hBrush
) ;
1463 Rectangle (hdc
, rect
.left
,rect
.top
,rect
.right
/2,rect
.bottom
);
1464 DeleteObject (SelectObject (hdc
,hBrush
)) ;
1465 hBrush
=CreateSolidBrush(GetNearestColor(hdc
,cr
));
1468 hBrush
= SelectObject (hdc
, hBrush
) ;
1469 Rectangle (hdc
, rect
.right
/2-1,rect
.top
,rect
.right
,rect
.bottom
);
1470 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1473 ReleaseDC(hwnd
,hdc
);
1477 /***********************************************************************
1478 * CC_PaintTriangle [internal]
1480 static void CC_PaintTriangle(HWND hDlg
,int y
)
1484 int w
=GetDialogBaseUnits();
1489 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
1490 struct CCPRIVATE
*lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1492 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1494 GetClientRect16(hwnd
,&rect
);
1498 points
[0].y
=rect
.top
;
1499 points
[0].x
=rect
.right
; /* | /| */
1500 ClientToScreen16(hwnd
,points
); /* | / | */
1501 ScreenToClient16(hDlg
,points
); /* |< | */
1502 oben
=points
[0].y
; /* | \ | */
1504 temp
=(long)height
*(long)y
;
1505 points
[0].y
=oben
+height
-temp
/(long)MAXVERT
;
1506 points
[1].y
=points
[0].y
+w
;
1507 points
[2].y
=points
[0].y
-w
;
1508 points
[2].x
=points
[1].x
=points
[0].x
+ w
;
1510 if (lpp
->old3angle
.left
)
1511 FillRect16(hDC
,&lpp
->old3angle
,GetStockObject(WHITE_BRUSH
));
1512 lpp
->old3angle
.left
=points
[0].x
;
1513 lpp
->old3angle
.right
=points
[1].x
+1;
1514 lpp
->old3angle
.top
=points
[2].y
-1;
1515 lpp
->old3angle
.bottom
=points
[1].y
+1;
1516 Polygon16(hDC
,points
,3);
1517 ReleaseDC(hDlg
,hDC
);
1522 /***********************************************************************
1523 * CC_PaintCross [internal]
1525 static void CC_PaintCross(HWND hDlg
,int x
,int y
)
1528 int w
=GetDialogBaseUnits();
1529 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1530 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1535 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1537 GetClientRect16(hwnd
,&rect
);
1539 SelectClipRgn(hDC
,CreateRectRgnIndirect16(&rect
));
1540 hPen
=CreatePen(PS_SOLID
,2,0);
1541 hPen
=SelectObject(hDC
,hPen
);
1542 point
.x
=((long)rect
.right
*(long)x
)/(long)MAXHORI
;
1543 point
.y
=rect
.bottom
-((long)rect
.bottom
*(long)y
)/(long)MAXVERT
;
1544 if (lpp
->oldcross
.left
!=lpp
->oldcross
.right
)
1545 BitBlt(hDC
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,
1546 lpp
->oldcross
.right
-lpp
->oldcross
.left
,
1547 lpp
->oldcross
.bottom
-lpp
->oldcross
.top
,
1548 lpp
->hdcMem
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,SRCCOPY
);
1549 lpp
->oldcross
.left
=point
.x
-w
-1;
1550 lpp
->oldcross
.right
=point
.x
+w
+1;
1551 lpp
->oldcross
.top
=point
.y
-w
-1;
1552 lpp
->oldcross
.bottom
=point
.y
+w
+1;
1554 MoveTo(hDC
,point
.x
-w
,point
.y
);
1555 LineTo(hDC
,point
.x
+w
,point
.y
);
1556 MoveTo(hDC
,point
.x
,point
.y
-w
);
1557 LineTo(hDC
,point
.x
,point
.y
+w
);
1558 DeleteObject(SelectObject(hDC
,hPen
));
1559 ReleaseDC(hwnd
,hDC
);
1568 /***********************************************************************
1569 * CC_PrepareColorGraph [internal]
1571 static void CC_PrepareColorGraph(HWND hDlg
)
1573 int sdif
,hdif
,xdif
,ydif
,r
,g
,b
,hue
,sat
;
1574 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1575 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1579 HCURSOR hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
1581 GetClientRect16(hwnd
,&client
);
1583 lpp
->hdcMem
= CreateCompatibleDC(hdc
);
1584 lpp
->hbmMem
= CreateCompatibleBitmap(hdc
,client
.right
,client
.bottom
);
1585 SelectObject(lpp
->hdcMem
,lpp
->hbmMem
);
1587 xdif
=client
.right
/XSTEPS
;
1588 ydif
=client
.bottom
/YSTEPS
+1;
1591 for(rect
.left
=hue
=0;hue
<239+hdif
;hue
+=hdif
)
1593 rect
.right
=rect
.left
+xdif
;
1594 rect
.bottom
=client
.bottom
;
1595 for(sat
=0;sat
<240+sdif
;sat
+=sdif
)
1597 rect
.top
=rect
.bottom
-ydif
;
1598 r
=CC_HSLtoRGB('R',hue
,sat
,120);
1599 g
=CC_HSLtoRGB('G',hue
,sat
,120);
1600 b
=CC_HSLtoRGB('B',hue
,sat
,120);
1601 hbrush
=CreateSolidBrush(RGB(r
,g
,b
));
1602 FillRect16(lpp
->hdcMem
,&rect
,hbrush
);
1603 DeleteObject(hbrush
);
1604 rect
.bottom
=rect
.top
;
1606 rect
.left
=rect
.right
;
1608 ReleaseDC(hwnd
,hdc
);
1612 /***********************************************************************
1613 * CC_PaintColorGraph [internal]
1615 static void CC_PaintColorGraph(HWND hDlg
)
1617 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1618 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1621 if (IsWindowVisible(hwnd
)) /* if full size */
1624 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
1627 GetClientRect16(hwnd
,&rect
);
1629 BitBlt(hDC
,0,0,rect
.right
,rect
.bottom
,lpp
->hdcMem
,0,0,SRCCOPY
);
1631 fprintf(stderr
,"choose color: hdcMem is not defined\n");
1632 ReleaseDC(hwnd
,hDC
);
1635 /***********************************************************************
1636 * CC_PaintLumBar [internal]
1638 static void CC_PaintLumBar(HWND hDlg
,int hue
,int sat
)
1640 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
1642 int lum
,ldif
,ydif
,r
,g
,b
;
1646 if (IsWindowVisible(hwnd
))
1649 GetClientRect16(hwnd
,&client
);
1653 ydif
=client
.bottom
/YSTEPS
+1;
1654 for(lum
=0;lum
<240+ldif
;lum
+=ldif
)
1656 rect
.top
=MAX(0,rect
.bottom
-ydif
);
1657 r
=CC_HSLtoRGB('R',hue
,sat
,lum
);
1658 g
=CC_HSLtoRGB('G',hue
,sat
,lum
);
1659 b
=CC_HSLtoRGB('B',hue
,sat
,lum
);
1660 hbrush
=CreateSolidBrush(RGB(r
,g
,b
));
1661 FillRect16(hDC
,&rect
,hbrush
);
1662 DeleteObject(hbrush
);
1663 rect
.bottom
=rect
.top
;
1665 GetClientRect16(hwnd
,&rect
);
1666 FrameRect16(hDC
,&rect
,GetStockObject(BLACK_BRUSH
));
1667 ReleaseDC(hwnd
,hDC
);
1671 /***********************************************************************
1672 * CC_EditSetRGB [internal]
1674 static void CC_EditSetRGB(HWND hDlg
,COLORREF cr
)
1677 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1678 int r
=GetRValue(cr
);
1679 int g
=GetGValue(cr
);
1680 int b
=GetBValue(cr
);
1681 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1684 sprintf(buffer
,"%d",r
);
1685 SetWindowText32A(GetDlgItem(hDlg
,0x2c2),buffer
);
1686 sprintf(buffer
,"%d",g
);
1687 SetWindowText32A(GetDlgItem(hDlg
,0x2c3),buffer
);
1688 sprintf(buffer
,"%d",b
);
1689 SetWindowText32A(GetDlgItem(hDlg
,0x2c4),buffer
);
1690 lpp
->updating
=FALSE
;
1694 /***********************************************************************
1695 * CC_EditSetHSL [internal]
1697 static void CC_EditSetHSL(HWND hDlg
,int h
,int s
,int l
)
1700 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1702 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1705 sprintf(buffer
,"%d",h
);
1706 SetWindowText32A(GetDlgItem(hDlg
,0x2bf),buffer
);
1707 sprintf(buffer
,"%d",s
);
1708 SetWindowText32A(GetDlgItem(hDlg
,0x2c0),buffer
);
1709 sprintf(buffer
,"%d",l
);
1710 SetWindowText32A(GetDlgItem(hDlg
,0x2c1),buffer
);
1711 lpp
->updating
=FALSE
;
1713 CC_PaintLumBar(hDlg
,h
,s
);
1716 /***********************************************************************
1717 * CC_SwitchToFullSize [internal]
1719 static void CC_SwitchToFullSize(HWND hDlg
,COLORREF result
,LPRECT16 lprect
)
1722 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1724 EnableWindow(GetDlgItem(hDlg
,0x2cf),FALSE
);
1725 CC_PrepareColorGraph(hDlg
);
1726 for (i
=0x2bf;i
<0x2c5;i
++)
1727 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
1728 for (i
=0x2d3;i
<0x2d9;i
++)
1729 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
1730 EnableWindow(GetDlgItem(hDlg
,0x2c9),TRUE
);
1731 EnableWindow(GetDlgItem(hDlg
,0x2c8),TRUE
);
1734 SetWindowPos(hDlg
,NULL
,0,0,lprect
->right
-lprect
->left
,
1735 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
1737 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_SHOW
);
1738 ShowWindow(GetDlgItem(hDlg
,0x2be),SW_SHOW
);
1739 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_SHOW
);
1741 CC_EditSetRGB(hDlg
,result
);
1742 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1745 /***********************************************************************
1746 * CC_PaintPredefColorArray [internal]
1748 static void CC_PaintPredefColorArray(HWND hDlg
,int rows
,int cols
)
1750 HWND hwnd
=GetDlgItem(hDlg
,0x2d0);
1756 GetClientRect16(hwnd
,&rect
);
1758 dy
=rect
.bottom
/rows
;
1762 GetClientRect16 (hwnd
, &rect
) ;
1764 for (j
=0;j
<rows
;j
++)
1766 for (i
=0;i
<cols
;i
++)
1768 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
1771 hBrush
= SelectObject (hdc
, hBrush
) ;
1772 Rectangle (hdc
, rect
.left
, rect
.top
,
1773 rect
.left
+dx
-DISTANCE
,rect
.top
+dy
-DISTANCE
);
1774 rect
.left
=rect
.left
+dx
;
1775 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1778 rect
.top
=rect
.top
+dy
;
1781 ReleaseDC(hwnd
,hdc
);
1782 /* FIXME: draw_a_focus_rect */
1784 /***********************************************************************
1785 * CC_PaintUserColorArray [internal]
1787 static void CC_PaintUserColorArray(HWND hDlg
,int rows
,int cols
,COLORREF
* lpcr
)
1789 HWND hwnd
=GetDlgItem(hDlg
,0x2d1);
1795 GetClientRect16(hwnd
,&rect
);
1798 dy
=rect
.bottom
/rows
;
1804 for (j
=0;j
<rows
;j
++)
1806 for (i
=0;i
<cols
;i
++)
1808 hBrush
= CreateSolidBrush(lpcr
[i
+j
*cols
]);
1811 hBrush
= SelectObject (hdc
, hBrush
) ;
1812 Rectangle (hdc
, rect
.left
, rect
.top
,
1813 rect
.left
+dx
-DISTANCE
,rect
.top
+dy
-DISTANCE
);
1814 rect
.left
=rect
.left
+dx
;
1815 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1818 rect
.top
=rect
.top
+dy
;
1821 ReleaseDC(hwnd
,hdc
);
1823 /* FIXME: draw_a_focus_rect */
1828 /***********************************************************************
1829 * CC_HookCallChk [internal]
1831 static BOOL
CC_HookCallChk(LPCHOOSECOLOR lpcc
)
1834 if(lpcc
->Flags
& CC_ENABLEHOOK
)
1840 /***********************************************************************
1841 * CC_WMInitDialog [internal]
1843 static LONG
CC_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1849 struct CCPRIVATE
* lpp
;
1851 dprintf_commdlg(stddeb
,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1852 lpp
=calloc(1,sizeof(struct CCPRIVATE
));
1853 lpp
->lpcc
=(LPCHOOSECOLOR
)lParam
;
1854 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLOR
))
1856 EndDialog (hDlg
, 0) ;
1859 SetWindowLong32A(hDlg
, DWL_USER
, (LONG
)lpp
);
1861 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
1862 ShowWindow(GetDlgItem(hDlg
,0x40e),SW_HIDE
);
1863 lpp
->msetrgb
=RegisterWindowMessage32A( SETRGBSTRING
);
1865 cpos
=MAKELONG(5,7); /* init */
1866 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
1870 if (predefcolors
[i
][j
]==lpp
->lpcc
->rgbResult
)
1877 /* FIXME: Draw_a_focus_rect & set_init_values */
1879 GetWindowRect16(hDlg
,&lpp
->fullsize
);
1880 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1882 hwnd
=GetDlgItem(hDlg
,0x2cf);
1883 EnableWindow(hwnd
,FALSE
);
1885 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1888 res
=rect
.bottom
-rect
.top
;
1889 hwnd
=GetDlgItem(hDlg
,0x2c6); /* cut at left border */
1891 ClientToScreen16(hwnd
,&point
);
1892 ScreenToClient16(hDlg
,&point
);
1893 GetClientRect16(hDlg
,&rect
);
1894 point
.x
+=GetSystemMetrics(SM_CXDLGFRAME
);
1895 SetWindowPos(hDlg
,NULL
,0,0,point
.x
,res
,SWP_NOMOVE
|SWP_NOZORDER
);
1897 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_HIDE
);
1898 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_HIDE
);
1901 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,NULL
);
1903 for (i
=0x2bf;i
<0x2c5;i
++)
1904 SendMessage16(GetDlgItem(hDlg
,i
),EM_LIMITTEXT
,3,0); /* max 3 digits: xyz */
1905 if (CC_HookCallChk(lpp
->lpcc
))
1906 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1910 /***********************************************************************
1911 * CC_WMCommand [internal]
1913 static LRESULT
CC_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1919 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1920 dprintf_commdlg(stddeb
,"CC_WMCommand wParam=%x lParam=%lx\n",wParam
,lParam
);
1923 case 0x2c2: /* edit notify RGB */
1926 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1928 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),255);
1929 r
=GetRValue(lpp
->lpcc
->rgbResult
);
1930 g
=GetGValue(lpp
->lpcc
->rgbResult
);
1931 b
=GetBValue(lpp
->lpcc
->rgbResult
);
1935 case 0x2c2:if ((xx
=(i
!=r
))) r
=i
;break;
1936 case 0x2c3:if ((xx
=(i
!=g
))) g
=i
;break;
1937 case 0x2c4:if ((xx
=(i
!=b
))) b
=i
;break;
1939 if (xx
) /* something has changed */
1941 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1942 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1943 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
1944 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
1945 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
1946 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1947 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1948 CC_PaintTriangle(hDlg
,lpp
->l
);
1953 case 0x2bf: /* edit notify HSL */
1956 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1958 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),wParam
==0x2bf?239:240);
1962 case 0x2bf:if ((xx
=(i
!=lpp
->h
))) lpp
->h
=i
;break;
1963 case 0x2c0:if ((xx
=(i
!=lpp
->s
))) lpp
->s
=i
;break;
1964 case 0x2c1:if ((xx
=(i
!=lpp
->l
))) lpp
->l
=i
;break;
1966 if (xx
) /* something has changed */
1968 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
1969 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
1970 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
1971 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1972 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1973 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
1974 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1975 CC_PaintTriangle(hDlg
,lpp
->l
);
1981 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,&lpp
->fullsize
);
1982 InvalidateRect32( hDlg
, NULL
, TRUE
);
1983 SetFocus(GetDlgItem(hDlg
,0x2bf));
1986 case 0x2c8: /* add colors ... column by column */
1987 cr
=PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
);
1988 cr
[(lpp
->nextuserdef
%2)*8 + lpp
->nextuserdef
/2]=lpp
->lpcc
->rgbResult
;
1989 if (++lpp
->nextuserdef
==16)
1991 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
1994 case 0x2c9: /* resulting color */
1996 lpp
->lpcc
->rgbResult
=GetNearestColor(hdc
,lpp
->lpcc
->rgbResult
);
1997 ReleaseDC(hDlg
,hdc
);
1998 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
1999 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2000 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2001 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2002 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2003 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2004 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2005 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2006 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2007 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2008 CC_PaintTriangle(hDlg
,lpp
->l
);
2011 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2012 i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2013 if (lpp
->lpcc
->hwndOwner
)
2014 SendMessage16(lpp
->lpcc
->hwndOwner
,i
,0,(LPARAM
)lpp
->lpcc
);
2015 if (CC_HookCallChk(lpp
->lpcc
))
2016 CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,
2017 WM_COMMAND
,psh15
,(LPARAM
)lpp
->lpcc
);
2021 cokmsg
=RegisterWindowMessage32A( COLOROKSTRING
);
2022 if (lpp
->lpcc
->hwndOwner
)
2023 if (SendMessage16(lpp
->lpcc
->hwndOwner
,cokmsg
,0,(LPARAM
)lpp
->lpcc
))
2024 break; /* do NOT close */
2026 EndDialog (hDlg
, 1) ;
2030 EndDialog (hDlg
, 0) ;
2037 /***********************************************************************
2038 * CC_WMPaint [internal]
2040 static LRESULT
CC_WMPaint(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2042 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2043 /* we have to paint dialog children except text and buttons */
2045 CC_PaintPredefColorArray(hDlg
,6,8);
2046 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2047 CC_PaintColorGraph(hDlg
);
2048 CC_PaintLumBar(hDlg
,lpp
->h
,lpp
->s
);
2049 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2050 CC_PaintTriangle(hDlg
,lpp
->l
);
2051 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2053 /* special necessary for Wine */
2054 ValidateRect32(GetDlgItem(hDlg
,0x2d0),NULL
);
2055 ValidateRect32(GetDlgItem(hDlg
,0x2d1),NULL
);
2056 ValidateRect32(GetDlgItem(hDlg
,0x2c6),NULL
);
2057 ValidateRect32(GetDlgItem(hDlg
,0x2be),NULL
);
2058 ValidateRect32(GetDlgItem(hDlg
,0x2c5),NULL
);
2059 /* hope we can remove it later -->FIXME */
2064 /***********************************************************************
2065 * CC_WMLButtonDown [internal]
2067 static LRESULT
CC_WMLButtonDown(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2069 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2072 if (CC_MouseCheckPredefColorArray(hDlg
,0x2d0,6,8,lParam
,&lpp
->lpcc
->rgbResult
))
2075 if (CC_MouseCheckUserColorArray(hDlg
,0x2d1,2,8,lParam
,&lpp
->lpcc
->rgbResult
,
2076 PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
)))
2079 if (CC_MouseCheckColorGraph(hDlg
,0x2c6,&lpp
->h
,&lpp
->s
,lParam
))
2082 if (CC_MouseCheckColorGraph(hDlg
,0x2be,NULL
,&lpp
->l
,lParam
))
2086 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
2087 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
2088 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
2089 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2093 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2094 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2095 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2096 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2097 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2098 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2102 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2103 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2104 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2105 CC_PaintTriangle(hDlg
,lpp
->l
);
2106 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2112 /***********************************************************************
2113 * ColorDlgProc (COMMDLG.8)
2115 LRESULT
ColorDlgProc(HWND hDlg
, UINT message
,
2116 UINT wParam
, LONG lParam
)
2119 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2120 if (message
!=WM_INITDIALOG
)
2125 if (CC_HookCallChk(lpp
->lpcc
))
2126 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2131 /* FIXME: SetRGB message
2132 if (message && message==msetrgb)
2133 return HandleSetRGB(hDlg,lParam);
2139 return CC_WMInitDialog(hDlg
,wParam
,lParam
);
2141 DeleteDC(lpp
->hdcMem
);
2142 DeleteObject(lpp
->hbmMem
);
2144 SetWindowLong32A(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
2147 if (CC_WMCommand(hDlg
, wParam
, lParam
))
2151 CC_WMPaint(hDlg
, wParam
, lParam
);
2153 case WM_LBUTTONDBLCLK
:
2154 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
2157 case WM_MOUSEMOVE
: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2159 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
2161 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
2162 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
2171 /***********************************************************************
2172 * ChooseFont (COMMDLG.15)
2174 BOOL
ChooseFont(LPCHOOSEFONT lpChFont
)
2177 HANDLE hDlgTmpl
, hResInfo
;
2180 dprintf_commdlg(stddeb
,"ChooseFont\n");
2181 if (!lpChFont
) return FALSE
;
2182 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpChFont
->hInstance
;
2183 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
2185 if (!(hResInfo
= FindResource16(lpChFont
->hInstance
,
2186 lpChFont
->lpTemplateName
, RT_DIALOG
)))
2188 CommDlgLastError
= CDERR_FINDRESFAILURE
;
2191 hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
);
2193 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_FONT
);
2196 CommDlgLastError
= CDERR_LOADRESFAILURE
;
2199 hInst
= WIN_GetWindowInstance( lpChFont
->hwndOwner
);
2200 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpChFont
->hwndOwner
,
2201 (DLGPROC16
)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2203 if (!(lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
))
2205 if (lpChFont
->Flags
& CF_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
2206 else SYSRES_FreeResource( hDlgTmpl
);
2212 #define TEXT_EXTRAS 4
2213 #define TEXT_COLORS 16
2215 static const COLORREF textcolors
[TEXT_COLORS
]=
2217 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
2218 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
2219 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
2220 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
2223 /***********************************************************************
2224 * CFn_HookCallChk [internal]
2226 static BOOL
CFn_HookCallChk(LPCHOOSEFONT lpcf
)
2229 if(lpcf
->Flags
& CF_ENABLEHOOK
)
2236 /***********************************************************************
2237 * FontFamilyEnumProc (COMMDLG.19)
2239 int FontFamilyEnumProc(LPLOGFONT16 lplf
, LPTEXTMETRIC16 lptm
, int nFontType
, LPARAM lParam
)
2243 HWND hwnd
=LOWORD(lParam
);
2244 HWND hDlg
=GetParent(hwnd
);
2245 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2247 dprintf_commdlg(stddeb
,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2248 lplf
->lfFaceName
,nFontType
);
2250 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
2251 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
2253 if (lpcf
->Flags
& CF_ANSIONLY
)
2254 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
2256 if (lpcf
->Flags
& CF_TTONLY
)
2257 if (!(nFontType
& 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2260 i
=SendMessage16(hwnd
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR(lplf
->lfFaceName
));
2263 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
2264 SendMessage16(hwnd
, CB_SETITEMDATA
,i
,MAKELONG(nFontType
,w
));
2265 return 1 ; /* store some important font information */
2271 /*************************************************************************
2272 * SetFontStylesToCombo2 [internal]
2274 * Fill font style information into combobox (without using font.c directly)
2276 static int SetFontStylesToCombo2(HWND hwnd
, HDC hdc
, LPLOGFONT16 lplf
,LPTEXTMETRIC16 lptm
)
2283 static struct FONTSTYLE fontstyles
[FSTYLES
]={
2284 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
2285 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
2289 for (i
=0;i
<FSTYLES
;i
++)
2291 lplf
->lfItalic
=fontstyles
[i
].italic
;
2292 lplf
->lfWeight
=fontstyles
[i
].weight
;
2293 hf
=CreateFontIndirect16(lplf
);
2294 hf
=SelectObject(hdc
,hf
);
2295 GetTextMetrics16(hdc
,lptm
);
2296 hf
=SelectObject(hdc
,hf
);
2299 if (lptm
->tmWeight
==fontstyles
[i
].weight
&&
2300 lptm
->tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
2302 j
=SendMessage16(hwnd
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR(fontstyles
[i
].stname
));
2303 if (j
==CB_ERR
) return 1;
2304 j
=SendMessage16(hwnd
, CB_SETITEMDATA
, j
,
2305 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
2306 if (j
==CB_ERR
) return 1;
2312 /*************************************************************************
2313 * SetFontSizesToCombo3 [internal]
2315 static int SetFontSizesToCombo3(HWND hwnd
, LPLOGFONT16 lplf
, LPCHOOSEFONT lpcf
)
2317 int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2321 for (i
=0;sizes
[i
] && !lplf
->lfHeight
;i
++)
2323 h
=lplf
->lfHeight
? lplf
->lfHeight
: sizes
[i
];
2325 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2326 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
2328 sprintf(buffer
,"%2d",h
);
2329 j
=SendMessage16(hwnd
,CB_FINDSTRING
,-1,(LPARAM
)MAKE_SEGPTR(buffer
));
2332 j
=SendMessage16(hwnd
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR(buffer
));
2333 if (j
==CB_ERR
) return 1;
2334 j
=SendMessage16(hwnd
, CB_SETITEMDATA
, j
, h
);
2335 if (j
==CB_ERR
) return 1;
2343 /***********************************************************************
2344 * FontStyleEnumProc (COMMDLG.18)
2346 int FontStyleEnumProc(LPLOGFONT16 lplf
,LPTEXTMETRIC16 lptm
, int nFontType
, LPARAM lParam
)
2348 HWND hcmb2
=LOWORD(lParam
);
2349 HWND hcmb3
=HIWORD(lParam
);
2350 HWND hDlg
=GetParent(hcmb3
);
2351 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2354 dprintf_commdlg(stddeb
,"FontStyleEnumProc: (nFontType=%d)\n",nFontType
);
2355 dprintf_commdlg(stddeb
," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d ch=%d op=%d cp=%d q=%d pf=%xh\n",
2356 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,lplf
->lfEscapement
,lplf
->lfOrientation
,
2357 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,lplf
->lfStrikeOut
,lplf
->lfCharSet
,
2358 lplf
->lfOutPrecision
,lplf
->lfClipPrecision
,lplf
->lfQuality
,lplf
->lfPitchAndFamily
);
2360 if (SetFontSizesToCombo3(hcmb3
, lplf
,lpcf
))
2363 if (!SendMessage16(hcmb2
,CB_GETCOUNT
,0,0))
2365 HDC hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
2366 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
,lptm
);
2367 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2368 ReleaseDC(hDlg
,hdc
);
2376 /***********************************************************************
2377 * CFn_WMInitDialog [internal]
2379 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2384 FARPROC16 enumCallback
= MODULE_GetWndProcEntry16("FontFamilyEnumProc");
2386 HCURSOR hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
2389 SetWindowLong32A(hDlg
, DWL_USER
, lParam
);
2390 lpcf
=(LPCHOOSEFONT
)lParam
;
2391 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2392 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
2394 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONT
))
2396 dprintf_commdlg(stddeb
,"WM_INITDIALOG: structure size failure !!!\n");
2397 EndDialog (hDlg
, 0);
2401 hBitmapTT
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2403 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
2404 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
2405 if (!(lpcf
->Flags
& CF_APPLY
))
2406 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
2407 if (lpcf
->Flags
& CF_EFFECTS
)
2409 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
2411 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2412 j
=SendDlgItemMessage16(hDlg
,cmb4
,CB_ADDSTRING
,0,(LPARAM
)MAKE_SEGPTR("[color name]"));
2413 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETITEMDATA
,j
,textcolors
[j
]);
2414 /* look for a fitting value in color combobox */
2415 if (textcolors
[j
]==lpcf
->rgbColors
)
2416 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
2421 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
2422 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
2423 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
2424 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
2425 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
2427 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
2430 if (!EnumFontFamilies (hdc
, NULL
,enumCallback
,(LPARAM
)GetDlgItem(hDlg
,cmb1
)))
2431 dprintf_commdlg(stddeb
,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2432 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
2434 /* look for fitting font name in combobox1 */
2435 j
=SendDlgItemMessage16(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
2438 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL
,j
,0);
2439 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
2441 /* look for fitting font style in combobox2 */
2442 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
2443 for (i
=0;i
<TEXT_EXTRAS
;i
++)
2445 if (l
==SendDlgItemMessage16(hDlg
,cmb2
, CB_GETITEMDATA
,i
,0))
2446 SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL
,i
,0);
2449 /* look for fitting font size in combobox3 */
2450 j
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCOUNT
,0,0);
2453 if (lpxx
->lfHeight
==(int)SendDlgItemMessage16(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
2454 SendDlgItemMessage16(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
2459 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
2460 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
2463 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
2465 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
2468 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
2469 SendMessage16(hDlg
,WM_COMMAND
,cmb2
,MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
2475 dprintf_commdlg(stddeb
,"WM_INITDIALOG: HDC failure !!!\n");
2476 EndDialog (hDlg
, 0);
2480 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2481 ReleaseDC(hDlg
,hdc
);
2483 if (CFn_HookCallChk(lpcf
))
2484 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
2490 /***********************************************************************
2491 * CFn_WMMeasureItem [internal]
2493 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2496 LPMEASUREITEMSTRUCT16 lpmi
=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT16
)lParam
);
2498 hBitmapTT
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2499 GetObject16( hBitmapTT
, sizeof(bm
), &bm
);
2500 lpmi
->itemHeight
=bm
.bmHeight
;
2501 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2506 /***********************************************************************
2507 * CFn_WMDrawItem [internal]
2509 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2519 HBITMAP hBitmap
; /* for later TT usage */
2521 LPDRAWITEMSTRUCT16 lpdi
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
2523 if (lpdi
->itemID
== 0xFFFF) /* got no items */
2524 DrawFocusRect16(lpdi
->hDC
, &lpdi
->rcItem
);
2527 if (lpdi
->CtlType
== ODT_COMBOBOX
)
2529 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
2530 SelectObject(lpdi
->hDC
, hBrush
);
2531 FillRect16(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
2534 return TRUE
; /* this should never happen */
2537 switch (lpdi
->CtlID
)
2539 case cmb1
: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2540 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2541 (LPARAM
)MAKE_SEGPTR(buffer
));
2542 GetObject16( hBitmapTT
, sizeof(bm
), &bm
);
2543 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
2544 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2546 nFontType
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
2547 /* FIXME: draw bitmap if truetype usage */
2548 if (nFontType
&TRUETYPE_FONTTYPE
)
2550 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
2551 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
2552 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
2553 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
2554 SelectObject(hMemDC
, hBitmap
);
2560 case cmb3
: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2561 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2562 (LPARAM
)MAKE_SEGPTR(buffer
));
2563 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
,
2564 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2567 case cmb4
: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2568 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2569 (LPARAM
)MAKE_SEGPTR(buffer
));
2570 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
2571 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2572 cr
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
2573 hBrush
= CreateSolidBrush(cr
);
2576 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
2577 rect
.right
=rect
.left
+25;
2581 Rectangle(lpdi
->hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
2582 DeleteObject (SelectObject (lpdi
->hDC
, hBrush
)) ;
2588 default: return TRUE
; /* this should never happen */
2590 if (lpdi
->itemState
==ODS_SELECTED
)
2591 InvertRect16(lpdi
->hDC
, &rect
);
2596 /***********************************************************************
2597 * CFn_WMCtlColor [internal]
2599 LRESULT
CFn_WMCtlColor(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2601 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2603 if (lpcf
->Flags
& CF_EFFECTS
)
2604 if (HIWORD(lParam
)==CTLCOLOR_STATIC
&& GetDlgCtrlID(LOWORD(lParam
))==stc6
)
2606 SetTextColor(wParam
,lpcf
->rgbColors
);
2607 return GetStockObject(WHITE_BRUSH
);
2612 /***********************************************************************
2613 * CFn_WMCommand [internal]
2615 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
2618 FARPROC16 enumCallback
;
2619 HFONT hFont
/*,hFontOld*/;
2623 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2624 LPLOGFONT16 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2626 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam
);
2629 case cmb1
:if (HIWORD(lParam
)==CBN_SELCHANGE
)
2631 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC(hDlg
);
2634 SendDlgItemMessage16(hDlg
,cmb2
,CB_RESETCONTENT
,0,0);
2635 SendDlgItemMessage16(hDlg
,cmb3
,CB_RESETCONTENT
,0,0);
2636 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
2639 HCURSOR hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
2640 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT
,i
,(LPARAM
)MAKE_SEGPTR(buffer
));
2641 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb1 =>%s\n",buffer
);
2642 enumCallback
= MODULE_GetWndProcEntry16("FontStyleEnumProc");
2643 EnumFontFamilies(hdc
,buffer
,enumCallback
,
2644 MAKELONG(GetDlgItem(hDlg
,cmb2
),GetDlgItem(hDlg
,cmb3
)));
2647 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2648 ReleaseDC(hDlg
,hdc
);
2652 dprintf_commdlg(stddeb
,"WM_COMMAND: HDC failure !!!\n");
2653 EndDialog (hDlg
, 0);
2660 case cmb3
:if (HIWORD(lParam
)==CBN_SELCHANGE
|| HIWORD(lParam
)== BN_CLICKED
)
2662 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
2663 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
2665 i
=GetDlgItemText32A( hDlg
, cmb1
, buffer
, sizeof(buffer
) );
2668 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT
,i
,(LPARAM
)MAKE_SEGPTR(buffer
));
2669 l
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
2671 lpcf
->nFontType
= LOWORD(l
);
2672 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2673 /* same value reported to the EnumFonts
2674 call back with the extra FONTTYPE_... bits added */
2675 lpxx
->lfPitchAndFamily
=j
&0xff;
2676 lpxx
->lfCharSet
=j
>>8;
2678 strcpy(lpxx
->lfFaceName
,buffer
);
2679 i
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETCURSEL
,0,0);
2682 l
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETITEMDATA
,i
,0);
2683 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
2684 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
2685 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
2686 lpcf
->nFontType
|= BOLD_FONTTYPE
;
2688 i
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCURSEL
,0,0);
2690 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessage16(hDlg
,cmb3
,CB_GETITEMDATA
,i
,0));
2693 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
2694 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
2695 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
2696 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
2697 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
2698 lpxx
->lfQuality
=DEFAULT_QUALITY
;
2699 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
2701 hFont
=CreateFontIndirect16(lpxx
);
2703 SendDlgItemMessage16(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
2704 /* FIXME: Delete old font ...? */
2708 case cmb4
:i
=SendDlgItemMessage16(hDlg
,cmb4
,CB_GETCURSEL
,0,0);
2711 lpcf
->rgbColors
=textcolors
[i
];
2712 InvalidateRect32( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
2716 case psh15
:i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2717 if (lpcf
->hwndOwner
)
2718 SendMessage16(lpcf
->hwndOwner
,i
,0,(LPARAM
)lpcf
);
2719 if (CFn_HookCallChk(lpcf
))
2720 CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_COMMAND
,psh15
,(LPARAM
)lpcf
);
2723 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2724 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
2725 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
2726 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
2727 EndDialog(hDlg
, TRUE
);
2730 sprintf(buffer
,"Select a font size among %d and %d points.",lpcf
->nSizeMin
,lpcf
->nSizeMax
);
2731 MessageBox(hDlg
,buffer
,NULL
,MB_OK
);
2734 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
2741 /***********************************************************************
2742 * FormatCharDlgProc (COMMDLG.16)
2743 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2744 2. some CF_.. flags are not supported
2745 3. some TType extensions
2747 LRESULT
FormatCharDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2749 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2750 if (message
!=WM_INITDIALOG
)
2755 if (CFn_HookCallChk(lpcf
))
2756 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2761 return CFn_WMInitDialog(hDlg
,wParam
,lParam
);
2764 case WM_MEASUREITEM
:
2765 return CFn_WMMeasureItem(hDlg
,wParam
,lParam
);
2767 return CFn_WMDrawItem(hDlg
,wParam
,lParam
);
2769 return CFn_WMCtlColor(hDlg
,wParam
,lParam
);
2771 return CFn_WMCommand(hDlg
,wParam
,lParam
);
2772 case WM_CHOOSEFONT_GETLOGFONT
:
2773 dprintf_commdlg(stddeb
,
2774 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam
);
2775 /* FIXME: current logfont back to caller */