4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
23 static DWORD CommDlgLastError
= 0;
25 static HBITMAP16 hFolder
= 0;
26 static HBITMAP16 hFolder2
= 0;
27 static HBITMAP16 hFloppy
= 0;
28 static HBITMAP16 hHDisk
= 0;
29 static HBITMAP16 hCDRom
= 0;
30 static HBITMAP16 hBitmapTT
= 0;
32 /***********************************************************************
33 * FileDlg_Init [internal]
35 static BOOL
FileDlg_Init()
37 static BOOL initialized
= 0;
40 if (!hFolder
) hFolder
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER
));
41 if (!hFolder2
) hFolder2
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER2
));
42 if (!hFloppy
) hFloppy
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_FLOPPY
));
43 if (!hHDisk
) hHDisk
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_HDISK
));
44 if (!hCDRom
) hCDRom
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_CDROM
));
45 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
46 hHDisk
== 0 || hCDRom
== 0)
48 fprintf(stderr
, "FileDlg_Init // Error loading bitmaps !");
56 /***********************************************************************
57 * GetOpenFileName (COMMDLG.1)
59 BOOL
GetOpenFileName( SEGPTR ofn
)
62 HANDLE16 hDlgTmpl
, hResInfo
;
64 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(ofn
);
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( SEGPTR ofn
)
109 HANDLE16 hDlgTmpl
, hResInfo
;
111 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(ofn
);
113 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
115 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpofn
->hInstance
;
116 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
118 hInst
= lpofn
->hInstance
;
119 if (!(hResInfo
= FindResource16(lpofn
->hInstance
,
120 lpofn
->lpTemplateName
, RT_DIALOG
)))
122 CommDlgLastError
= CDERR_FINDRESFAILURE
;
125 hDlgTmpl
= LoadResource16( lpofn
->hInstance
, hResInfo
);
127 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE
);
129 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
130 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpofn
->hwndOwner
,
131 (DLGPROC16
)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
133 if (!(lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
))
135 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
136 else SYSRES_FreeResource( hDlgTmpl
);
139 dprintf_commdlg(stddeb
, "GetSaveFileName // return lpstrFile='%s' !\n",
140 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
144 /***********************************************************************
145 * FILEDLG_StripEditControl [internal]
146 * Strip pathnames off the contents of the edit control.
148 static void FILEDLG_StripEditControl(HWND hwnd
)
152 GetDlgItemText32A( hwnd
, edt1
, temp
, sizeof(temp
) );
153 cp
= strrchr(temp
, '\\');
157 cp
= strrchr(temp
, ':');
161 /* FIXME: shouldn't we do something with the result here? ;-) */
164 /***********************************************************************
165 * FILEDLG_ScanDir [internal]
167 static BOOL
FILEDLG_ScanDir(HWND hWnd
, LPSTR newPath
)
172 lstrcpyn32A( str
, newPath
, 512 );
174 GetDlgItemText32A( hWnd
, edt1
, str
+ len
, sizeof(str
) - len
);
175 if (!DlgDirList32A( hWnd
, str
, lst1
, 0, 0x0000 )) return FALSE
;
176 return DlgDirList32A( hWnd
, "*.*", 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
, WPARAM16 wParam
, LPARAM lParam
,int savedlg
)
211 LPDRAWITEMSTRUCT16 lpdis
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
214 HBITMAP16 hBitmap
, hPrevBitmap
;
218 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
220 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
221 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
222 SelectObject32(lpdis
->hDC
, hBrush
);
223 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
224 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT16
, lpdis
->itemID
,
225 (LPARAM
)SEGPTR_GET(str
));
227 if (savedlg
) /* use _gray_ text in FileSaveDlg */
228 if (!lpdis
->itemState
)
229 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_GRAYTEXT
) );
231 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_WINDOWTEXT
) );
232 /* inversion of gray would be bad readable */
234 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
236 if (lpdis
->itemState
!= 0) {
237 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
243 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
245 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
246 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
247 SelectObject32(lpdis
->hDC
, hBrush
);
248 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
249 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT16
, lpdis
->itemID
,
250 (LPARAM
)SEGPTR_GET(str
));
253 GetObject16( hBitmap
, sizeof(bm
), &bm
);
254 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
255 lpdis
->rcItem
.top
, str
, strlen(str
));
256 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
257 hPrevBitmap
= SelectObject32(hMemDC
, hBitmap
);
258 BitBlt32(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
259 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
260 SelectObject32(hMemDC
, hPrevBitmap
);
262 if (lpdis
->itemState
!= 0) InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
266 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
268 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
269 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
270 SelectObject32(lpdis
->hDC
, hBrush
);
271 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
272 SendMessage16(lpdis
->hwndItem
, CB_GETLBTEXT16
, lpdis
->itemID
,
273 (LPARAM
)SEGPTR_GET(str
));
274 switch(DRIVE_GetType( str
[2] - 'a' ))
276 case TYPE_FLOPPY
: hBitmap
= hFloppy
; break;
277 case TYPE_CDROM
: hBitmap
= hCDRom
; break;
280 default: hBitmap
= hHDisk
; break;
282 GetObject16( hBitmap
, sizeof(bm
), &bm
);
283 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
284 lpdis
->rcItem
.top
, str
, strlen(str
));
285 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
286 hPrevBitmap
= SelectObject32(hMemDC
, hBitmap
);
287 BitBlt32( lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
288 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
289 SelectObject32(hMemDC
, hPrevBitmap
);
291 if (lpdis
->itemState
!= 0) InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
298 /***********************************************************************
299 * FILEDLG_WMMeasureItem [internal]
301 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
304 LPMEASUREITEMSTRUCT16 lpmeasure
;
306 GetObject16( hFolder2
, sizeof(bm
), &bm
);
307 lpmeasure
= (LPMEASUREITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
308 lpmeasure
->itemHeight
= bm
.bmHeight
;
312 /***********************************************************************
313 * FILEDLG_HookCallChk [internal]
315 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn
)
318 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
324 /***********************************************************************
325 * FILEDLG_WMInitDialog [internal]
328 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
331 LPOPENFILENAME lpofn
;
334 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
335 lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(lParam
);
336 if (lpofn
->lpstrTitle
) SetWindowText16( hWnd
, lpofn
->lpstrTitle
);
337 /* read custom filter information */
338 if (lpofn
->lpstrCustomFilter
)
340 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
);
342 dprintf_commdlg(stddeb
,"lpstrCustomFilter = %p\n", pstr
);
345 dprintf_commdlg(stddeb
,"lpstrCustomFilter // add str='%s' ",pstr
);
346 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING16
, 0,
347 (LPARAM
)lpofn
->lpstrCustomFilter
+ n
);
348 n
+= strlen(pstr
) + 1;
349 pstr
+= strlen(pstr
) + 1;
350 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
351 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA16
, i
, (LPARAM
)pstr
);
352 n
+= strlen(pstr
) + 1;
353 pstr
+= strlen(pstr
) + 1;
356 /* read filter information */
357 if (lpofn
->lpstrFilter
) {
358 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
361 dprintf_commdlg(stddeb
,"lpstrFilter // add str='%s' ", pstr
);
362 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING16
, 0,
363 (LPARAM
)lpofn
->lpstrFilter
+ n
);
364 n
+= strlen(pstr
) + 1;
365 pstr
+= strlen(pstr
) + 1;
366 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
367 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA16
, i
, (LPARAM
)pstr
);
368 n
+= strlen(pstr
) + 1;
369 pstr
+= strlen(pstr
) + 1;
372 /* set default filter */
373 if (lpofn
->nFilterIndex
== 0 && lpofn
->lpstrCustomFilter
== (SEGPTR
)NULL
)
374 lpofn
->nFilterIndex
= 1;
375 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETCURSEL16
, lpofn
->nFilterIndex
- 1, 0);
376 strncpy(tmpstr
, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
377 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lpofn
->nFilterIndex
- 1),511);
379 dprintf_commdlg(stddeb
,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
380 lpofn
->nFilterIndex
, tmpstr
);
381 SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
383 DlgDirListComboBox32A(hWnd
, "", cmb2
, 0, 0xC000);
384 /* read initial directory */
385 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
)
387 strncpy(tmpstr
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
), 510);
389 if (strlen(tmpstr
) > 0 && tmpstr
[strlen(tmpstr
)-1] != '\\'
390 && tmpstr
[strlen(tmpstr
)-1] != ':')
395 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
396 fprintf(stderr
, "FileDlg: couldn't read initial directory %s!\n", tmpstr
);
397 /* select current drive in combo 2 */
398 n
= DRIVE_GetCurrentDrive();
399 SendDlgItemMessage16(hWnd
, cmb2
, CB_SETCURSEL16
, n
, 0);
400 if (!(lpofn
->Flags
& OFN_SHOWHELP
))
401 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
402 if (lpofn
->Flags
& OFN_HIDEREADONLY
)
403 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
404 if (FILEDLG_HookCallChk(lpofn
))
405 return (BOOL
)CallWindowProc16(lpofn
->lpfnHook
,
406 hWnd
, WM_INITDIALOG
, wParam
, lParam
);
411 /***********************************************************************
412 * FILEDLG_WMCommand [internal]
414 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
417 LPOPENFILENAME lpofn
;
419 char tmpstr
[512], tmpstr2
[512];
421 UINT control
,notification
;
423 /* Notifications are packaged differently in Win32 */
425 notification
= HIWORD(lParam
);
427 lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
430 case lst1
: /* file list */
431 FILEDLG_StripEditControl(hWnd
);
432 if (notification
== LBN_DBLCLK
)
434 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
435 if (lRet
== LB_ERR
) return TRUE
;
436 if ((pstr
= SEGPTR_ALLOC(512)))
438 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT16
, lRet
,
439 (LPARAM
)SEGPTR_GET(pstr
));
440 SetDlgItemText32A( hWnd
, edt1
, pstr
);
443 if (FILEDLG_HookCallChk(lpofn
))
444 CallWindowProc16(lpofn
->lpfnHook
, hWnd
,
445 RegisterWindowMessage32A( LBSELCHSTRING
),
446 control
, MAKELONG(lRet
,CD_LBSELCHANGE
));
447 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
449 case lst2
: /* directory list */
450 FILEDLG_StripEditControl(hWnd
);
451 if (notification
== LBN_DBLCLK
)
453 lRet
= SendDlgItemMessage16(hWnd
, lst2
, LB_GETCURSEL16
, 0, 0);
454 if (lRet
== LB_ERR
) return TRUE
;
455 pstr
= SEGPTR_ALLOC(512);
456 SendDlgItemMessage16(hWnd
, lst2
, LB_GETTEXT16
, lRet
,
457 (LPARAM
)SEGPTR_GET(pstr
));
458 strcpy( tmpstr
, pstr
);
460 if (tmpstr
[0] == '[')
462 tmpstr
[strlen(tmpstr
) - 1] = 0;
463 strcpy(tmpstr
,tmpstr
+1);
465 strcat(tmpstr
, "\\");
469 case cmb1
: /* file type drop list */
470 if (notification
== CBN_SELCHANGE
)
476 case cmb2
: /* disk drop list */
477 FILEDLG_StripEditControl(hWnd
);
478 lRet
= SendDlgItemMessage16(hWnd
, cmb2
, CB_GETCURSEL16
, 0, 0L);
479 if (lRet
== LB_ERR
) return 0;
480 pstr
= SEGPTR_ALLOC(512);
481 SendDlgItemMessage16(hWnd
, cmb2
, CB_GETLBTEXT16
, lRet
,
482 (LPARAM
)SEGPTR_GET(pstr
));
483 sprintf(tmpstr
, "%c:", pstr
[2]);
486 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL16
, 0, 0);
489 pstr
= (LPSTR
)SendDlgItemMessage16(hWnd
, cmb1
, CB_GETITEMDATA16
, lRet
, 0);
490 dprintf_commdlg(stddeb
,"Selected filter : %s\n", pstr
);
491 SetDlgItemText32A( hWnd
, edt1
, pstr
);
492 FILEDLG_ScanDir(hWnd
, tmpstr
);
500 ofn2
=*lpofn
; /* for later restoring */
501 GetDlgItemText32A( hWnd
, edt1
, tmpstr
, sizeof(tmpstr
) );
502 pstr
= strrchr(tmpstr
, '\\');
504 pstr
= strrchr(tmpstr
, ':');
505 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
507 /* edit control contains wildcards */
510 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
515 strcpy(tmpstr2
, tmpstr
);
518 dprintf_commdlg(stddeb
,"commdlg: %s, %s\n", tmpstr
, tmpstr2
);
519 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
520 FILEDLG_ScanDir(hWnd
, tmpstr
);
523 /* no wildcards, we might have a directory or a filename */
524 /* try appending a wildcard and reading the directory */
525 pstr2
= tmpstr
+ strlen(tmpstr
);
526 if (pstr
== NULL
|| *(pstr
+1) != 0)
527 strcat(tmpstr
, "\\");
528 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL16
, 0, 0);
529 if (lRet
== LB_ERR
) return TRUE
;
530 lpofn
->nFilterIndex
= lRet
+ 1;
531 dprintf_commdlg(stddeb
,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn
->nFilterIndex
);
533 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
534 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
535 lRet
), sizeof(tmpstr2
));
536 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
537 /* if ScanDir succeeds, we have changed the directory */
538 if (FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
539 /* if not, this must be a filename */
543 /* strip off the pathname */
545 SetDlgItemText32A( hWnd
, edt1
, pstr
+ 1 );
546 lstrcpyn32A(tmpstr2
, pstr
+1, sizeof(tmpstr2
) );
547 /* Should we MessageBox() if this fails? */
548 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
549 strcpy(tmpstr
, tmpstr2
);
551 else SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
553 ShowWindow(hWnd
, SW_HIDE
); /* this should not be necessary ?! (%%%) */
556 int drive
= DRIVE_GetCurrentDrive();
557 tmpstr2
[0] = 'A'+ drive
;
560 strncpy(tmpstr2
+ 3, DRIVE_GetDosCwd(drive
), 507); tmpstr2
[510]=0;
561 if (strlen(tmpstr2
) > 3)
562 strcat(tmpstr2
, "\\");
563 strncat(tmpstr2
, tmpstr
, 511-strlen(tmpstr2
)); tmpstr2
[511]=0;
564 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), tmpstr2
);
566 lpofn
->nFileOffset
= 0;
567 lpofn
->nFileExtension
= 0;
568 while(tmpstr2
[lpofn
->nFileExtension
] != '.' && tmpstr2
[lpofn
->nFileExtension
] != '\0')
569 lpofn
->nFileExtension
++;
570 if (lpofn
->nFileExtension
== '\0')
571 lpofn
->nFileExtension
= 0;
573 lpofn
->nFileExtension
++;
574 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
)
576 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
577 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT16
, lRet
,
578 lpofn
->lpstrFileTitle
);
580 if (FILEDLG_HookCallChk(lpofn
))
582 lRet
= (BOOL
)CallWindowProc16(lpofn
->lpfnHook
,
583 hWnd
, RegisterWindowMessage32A( FILEOKSTRING
), 0, lParam
);
586 *lpofn
=ofn2
; /* restore old state */
588 ShowWindow(hWnd
, SW_SHOW
); /* only if above (%%%) SW_HIDE used */
593 EndDialog(hWnd
, TRUE
);
596 EndDialog(hWnd
, FALSE
);
603 /***********************************************************************
604 * FileOpenDlgProc (COMMDLG.6)
606 LRESULT
FileOpenDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
608 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
610 if (wMsg
!=WM_INITDIALOG
)
611 if (FILEDLG_HookCallChk(lpofn
))
613 LRESULT lRet
=(BOOL
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
615 return lRet
; /* else continue message processing */
620 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
622 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
624 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
);
626 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
629 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
630 switch (HIWORD(lParam
))
633 SetTextColor((HDC16
)wParam
, 0x00000000);
635 case CTLCOLOR_STATIC
:
636 SetTextColor((HDC16
)wParam
, 0x00000000);
646 /***********************************************************************
647 * FileSaveDlgProc (COMMDLG.7)
649 LRESULT
FileSaveDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
651 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
653 if (wMsg
!=WM_INITDIALOG
)
654 if (FILEDLG_HookCallChk(lpofn
))
656 LRESULT lRet
=(BOOL
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
658 return lRet
; /* else continue message processing */
662 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
665 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
668 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
);
671 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
676 SetBkColor((HDC16)wParam, 0x00C0C0C0);
677 switch (HIWORD(lParam))
680 SetTextColor((HDC16)wParam, 0x00000000);
682 case CTLCOLOR_STATIC:
683 SetTextColor((HDC16)wParam, 0x00000000);
693 /***********************************************************************
694 * FindTextDlg (COMMDLG.11)
696 BOOL
FindText( SEGPTR find
)
698 HANDLE16 hInst
, hDlgTmpl
;
701 LPFINDREPLACE lpFind
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(find
);
704 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
705 * For now, only the standard dialog works.
708 * FIXME : We should do error checking on the lpFind structure here
709 * and make CommDlgExtendedError() return the error condition.
711 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT
);
712 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
713 if (!(ptr
= GlobalLock16( hDlgTmpl
))) return -1;
714 bRet
= CreateDialogIndirectParam16( hInst
, ptr
, lpFind
->hwndOwner
,
715 (DLGPROC16
)MODULE_GetWndProcEntry16("FindTextDlgProc"),
717 GlobalUnlock16( hDlgTmpl
);
718 SYSRES_FreeResource( hDlgTmpl
);
723 /***********************************************************************
724 * ReplaceTextDlg (COMMDLG.12)
726 BOOL
ReplaceText( SEGPTR find
)
728 HANDLE16 hInst
, hDlgTmpl
;
731 LPFINDREPLACE lpFind
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(find
);
734 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
735 * For now, only the standard dialog works.
738 * FIXME : We should do error checking on the lpFind structure here
739 * and make CommDlgExtendedError() return the error condition.
741 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT
);
742 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
743 if (!(ptr
= GlobalLock16( hDlgTmpl
))) return -1;
744 bRet
= CreateDialogIndirectParam16( hInst
, ptr
, lpFind
->hwndOwner
,
745 (DLGPROC16
)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
747 GlobalUnlock16( hDlgTmpl
);
748 SYSRES_FreeResource( hDlgTmpl
);
753 /***********************************************************************
754 * FINDDLG_WMInitDialog [internal]
756 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
760 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
761 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(lParam
);
762 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
764 * FIXME : If the initial FindWhat string is empty, we should disable the
765 * FindNext (IDOK) button. Only after typing some text, the button should be
768 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
769 CheckRadioButton(hWnd
, rad1
, rad2
, (lpfr
->Flags
& FR_DOWN
) ? rad2
: rad1
);
770 if (lpfr
->Flags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
771 EnableWindow(GetDlgItem(hWnd
, rad1
), FALSE
);
772 EnableWindow(GetDlgItem(hWnd
, rad2
), FALSE
);
774 if (lpfr
->Flags
& FR_HIDEUPDOWN
) {
775 ShowWindow(GetDlgItem(hWnd
, rad1
), SW_HIDE
);
776 ShowWindow(GetDlgItem(hWnd
, rad2
), SW_HIDE
);
777 ShowWindow(GetDlgItem(hWnd
, grp1
), SW_HIDE
);
779 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
780 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
781 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
782 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
783 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
784 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
785 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
786 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
787 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
788 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
789 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
790 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
791 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
793 ShowWindow(hWnd
, SW_SHOWNORMAL
);
798 /***********************************************************************
799 * FINDDLG_WMCommand [internal]
801 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
804 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
805 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
807 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
810 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
811 if (IsDlgButtonChecked(hWnd
, rad2
))
812 lpfr
->Flags
|= FR_DOWN
;
813 else lpfr
->Flags
&= ~FR_DOWN
;
814 if (IsDlgButtonChecked(hWnd
, chx1
))
815 lpfr
->Flags
|= FR_WHOLEWORD
;
816 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
817 if (IsDlgButtonChecked(hWnd
, chx2
))
818 lpfr
->Flags
|= FR_MATCHCASE
;
819 else lpfr
->Flags
&= ~FR_MATCHCASE
;
820 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
821 lpfr
->Flags
|= FR_FINDNEXT
;
822 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
823 GetWindowLong32A(hWnd
, DWL_USER
) );
826 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
827 lpfr
->Flags
|= FR_DIALOGTERM
;
828 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
829 GetWindowLong32A(hWnd
, DWL_USER
) );
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
, WPARAM16 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
, WPARAM16 wParam
, LPARAM lParam
)
863 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
864 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(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
, WPARAM16 wParam
, LPARAM lParam
)
898 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
899 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
901 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(GetWindowLong32A(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,
915 GetWindowLong32A(hWnd
, DWL_USER
) );
918 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
919 lpfr
->Flags
|= FR_DIALOGTERM
;
920 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
921 GetWindowLong32A(hWnd
, DWL_USER
) );
925 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
926 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
927 if (IsDlgButtonChecked(hWnd
, chx1
))
928 lpfr
->Flags
|= FR_WHOLEWORD
;
929 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
930 if (IsDlgButtonChecked(hWnd
, chx2
))
931 lpfr
->Flags
|= FR_MATCHCASE
;
932 else lpfr
->Flags
&= ~FR_MATCHCASE
;
933 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
934 lpfr
->Flags
|= FR_REPLACE
;
935 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
936 GetWindowLong32A(hWnd
, DWL_USER
) );
939 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
940 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
941 if (IsDlgButtonChecked(hWnd
, chx1
))
942 lpfr
->Flags
|= FR_WHOLEWORD
;
943 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
944 if (IsDlgButtonChecked(hWnd
, chx2
))
945 lpfr
->Flags
|= FR_MATCHCASE
;
946 else lpfr
->Flags
&= ~FR_MATCHCASE
;
947 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
948 lpfr
->Flags
|= FR_REPLACEALL
;
949 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
950 GetWindowLong32A(hWnd
, DWL_USER
) );
953 /* FIXME : should lpfr structure be passed as an argument ??? */
954 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
961 /***********************************************************************
962 * ReplaceTextDlgProc (COMMDLG.14)
964 LRESULT
ReplaceTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
968 return REPLACEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
970 return REPLACEDLG_WMCommand(hWnd
, wParam
, lParam
);
976 /***********************************************************************
977 * PrintDlg (COMMDLG.20)
979 BOOL
PrintDlg( SEGPTR printdlg
)
981 HANDLE16 hInst
, hDlgTmpl
;
983 LPPRINTDLG lpPrint
= (LPPRINTDLG
)PTR_SEG_TO_LIN(printdlg
);
985 dprintf_commdlg(stddeb
,"PrintDlg(%p) // Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
987 if (lpPrint
->Flags
& PD_RETURNDEFAULT
)
988 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
991 if (lpPrint
->Flags
& PD_PRINTSETUP
)
992 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP
);
994 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT
);
996 hInst
= WIN_GetWindowInstance( lpPrint
->hwndOwner
);
997 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpPrint
->hwndOwner
,
998 (DLGPROC16
)((lpPrint
->Flags
& PD_PRINTSETUP
) ?
999 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1000 MODULE_GetWndProcEntry16("PrintDlgProc")),
1002 SYSRES_FreeResource( hDlgTmpl
);
1007 /***********************************************************************
1008 * PrintDlgProc (COMMDLG.21)
1010 LRESULT
PrintDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
1015 dprintf_commdlg(stddeb
,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1016 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1022 EndDialog(hWnd
, TRUE
);
1025 EndDialog(hWnd
, FALSE
);
1034 /***********************************************************************
1035 * PrintSetupDlgProc (COMMDLG.22)
1037 LRESULT
PrintSetupDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
1042 dprintf_commdlg(stddeb
,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1043 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1048 EndDialog(hWnd
, TRUE
);
1051 EndDialog(hWnd
, FALSE
);
1060 /***********************************************************************
1061 * CommDlgExtendedError (COMMDLG.26)
1063 DWORD
CommDlgExtendedError(void)
1065 return CommDlgLastError
;
1069 /***********************************************************************
1070 * GetFileTitle (COMMDLG.27)
1072 short GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT cbBuf
)
1075 dprintf_commdlg(stddeb
,"GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
1076 if (lpFile
== NULL
|| lpTitle
== NULL
)
1078 len
= strlen(lpFile
);
1081 if (strpbrk(lpFile
, "*[]"))
1084 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
1086 for (i
= len
; i
>= 0; i
--)
1087 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
1092 dprintf_commdlg(stddeb
,"\n---> '%s' ", &lpFile
[i
]);
1094 len
= strlen(lpFile
+i
)+1;
1098 strncpy(lpTitle
, &lpFile
[i
], len
);
1103 /* ------------------------ Choose Color Dialog --------------------------- */
1105 /***********************************************************************
1106 * ChooseColor (COMMDLG.5)
1108 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
1111 HANDLE16 hDlgTmpl
, hResInfo
;
1114 dprintf_commdlg(stddeb
,"ChooseColor\n");
1115 if (!lpChCol
) return FALSE
;
1116 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpChCol
->hInstance
;
1117 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1119 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
1120 lpChCol
->lpTemplateName
, RT_DIALOG
)))
1122 CommDlgLastError
= CDERR_FINDRESFAILURE
;
1125 hDlgTmpl
= LoadResource16( lpChCol
->hInstance
, hResInfo
);
1127 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR
);
1130 CommDlgLastError
= CDERR_LOADRESFAILURE
;
1133 hInst
= WIN_GetWindowInstance( lpChCol
->hwndOwner
);
1134 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpChCol
->hwndOwner
,
1135 (DLGPROC16
)MODULE_GetWndProcEntry16("ColorDlgProc"),
1137 if (!(lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
))
1139 if (lpChCol
->Flags
& CC_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
1140 else SYSRES_FreeResource( hDlgTmpl
);
1146 static const COLORREF predefcolors
[6][8]=
1148 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
1149 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
1150 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
1151 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
1153 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
1154 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
1155 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
1156 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
1158 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
1159 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
1160 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
1161 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
1166 LPCHOOSECOLOR lpcc
; /* points to public known data structure */
1167 int nextuserdef
; /* next free place in user defined color array */
1168 HDC16 hdcMem
; /* color graph used for BitBlt() */
1169 HBITMAP16 hbmMem
; /* color graph bitmap */
1170 RECT16 fullsize
; /* original dialog window size */
1171 UINT msetrgb
; /* # of SETRGBSTRING message (today not used) */
1172 RECT16 old3angle
; /* last position of l-marker */
1173 RECT16 oldcross
; /* last position of color/satuation marker */
1174 BOOL updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1177 int l
; /* for temporary storing of hue,sat,lum */
1180 /***********************************************************************
1181 * CC_HSLtoRGB [internal]
1183 static int CC_HSLtoRGB(char c
,int hue
,int sat
,int lum
)
1190 case 'R':if (hue
>80) hue
-=80; else hue
+=160; break;
1191 case 'G':if (hue
>160) hue
-=160; else hue
+=80; break;
1196 maxrgb
=(256*MIN(120,lum
))/120; /* 0 .. 256 */
1202 res
=(hue
-80)* maxrgb
; /* 0...10240 */
1203 res
/=40; /* 0...256 */
1210 res
=(240-hue
)* maxrgb
;
1213 res
=res
-maxrgb
/2; /* -128...128 */
1216 res
=maxrgb
/2 + (sat
*res
) /240; /* 0..256 */
1219 if (lum
>120 && res
<256)
1220 res
+=((lum
-120) * (256-res
))/120;
1222 return MIN(res
,255);
1225 /***********************************************************************
1226 * CC_RGBtoHSL [internal]
1228 static int CC_RGBtoHSL(char c
,int r
,int g
,int b
)
1230 WORD maxi
,mini
,mmsum
,mmdif
,result
=0;
1244 case 'L':mmsum
*=120; /* 0...61200=(255+255)*120 */
1245 result
=mmsum
/255; /* 0...240 */
1248 case 'S':if (!mmsum
)
1251 if (!mini
|| maxi
==255)
1255 result
=mmdif
*240; /* 0...61200=255*240 */
1256 result
/= (mmsum
>255 ? mmsum
=510-mmsum
: mmsum
); /* 0..255 */
1260 case 'H':if (!mmdif
)
1266 iresult
=40*(g
-b
); /* -10200 ... 10200 */
1267 iresult
/=(int)mmdif
; /* -40 .. 40 */
1269 iresult
+=240; /* 0..40 and 200..240 */
1275 iresult
/=(int)mmdif
;
1276 iresult
+=80; /* 40 .. 120 */
1282 iresult
/=(int)mmdif
;
1283 iresult
+=160; /* 120 .. 200 */
1289 return result
; /* is this integer arithmetic precise enough ? */
1294 /***********************************************************************
1295 * CC_MouseCheckPredefColorArray [internal]
1297 static int CC_MouseCheckPredefColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1298 LPARAM lParam
,COLORREF
*cr
)
1301 POINT16 point
= MAKEPOINT16(lParam
);
1305 ClientToScreen16(hDlg
,&point
);
1306 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1307 GetWindowRect16(hwnd
,&rect
);
1308 if (PtInRect16(&rect
,point
))
1310 dx
=(rect
.right
-rect
.left
)/cols
;
1311 dy
=(rect
.bottom
-rect
.top
)/rows
;
1312 ScreenToClient16(hwnd
,&point
);
1314 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1318 *cr
=predefcolors
[y
][x
];
1319 /* FIXME: Draw_a_Focus_Rect() */
1326 /***********************************************************************
1327 * CC_MouseCheckUserColorArray [internal]
1329 static int CC_MouseCheckUserColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1330 LPARAM lParam
,COLORREF
*cr
,COLORREF
*crarr
)
1333 POINT16 point
= MAKEPOINT16(lParam
);
1337 ClientToScreen16(hDlg
,&point
);
1338 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1339 GetWindowRect16(hwnd
,&rect
);
1340 if (PtInRect16(&rect
,point
))
1342 dx
=(rect
.right
-rect
.left
)/cols
;
1343 dy
=(rect
.bottom
-rect
.top
)/rows
;
1344 ScreenToClient16(hwnd
,&point
);
1346 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1350 *cr
=crarr
[x
+cols
*y
];
1351 /* FIXME: Draw_a_Focus_Rect() */
1361 /* 240 ^...... ^^ 240
1368 /***********************************************************************
1369 * CC_MouseCheckColorGraph [internal]
1371 static int CC_MouseCheckColorGraph(HWND hDlg
,int dlgitem
,int *hori
,int *vert
,LPARAM lParam
)
1374 POINT16 point
= MAKEPOINT16(lParam
);
1378 ClientToScreen16(hDlg
,&point
);
1379 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1380 GetWindowRect16(hwnd
,&rect
);
1381 if (PtInRect16(&rect
,point
))
1383 GetClientRect16(hwnd
,&rect
);
1384 ScreenToClient16(hwnd
,&point
);
1386 x
=(long)point
.x
*MAXHORI
;
1388 y
=(long)(rect
.bottom
-point
.y
)*MAXVERT
;
1400 /***********************************************************************
1401 * CC_MouseCheckResultWindow [internal]
1403 static int CC_MouseCheckResultWindow(HWND hDlg
,LPARAM lParam
)
1406 POINT16 point
= MAKEPOINT16(lParam
);
1409 ClientToScreen16(hDlg
,&point
);
1410 hwnd
=GetDlgItem(hDlg
,0x2c5);
1411 GetWindowRect16(hwnd
,&rect
);
1412 if (PtInRect16(&rect
,point
))
1414 PostMessage(hDlg
,WM_COMMAND
,0x2c9,0);
1420 /***********************************************************************
1421 * CC_CheckDigitsInEdit [internal]
1423 static int CC_CheckDigitsInEdit(HWND hwnd
,int maxval
)
1425 int i
,k
,m
,result
,value
;
1428 GetWindowText32A(hwnd
,buffer
,sizeof(buffer
));
1433 if (buffer
[i
]<'0' || buffer
[i
]>'9')
1435 for (k
=i
+1;k
<=m
;k
++) /* delete bad character */
1437 buffer
[i
]=buffer
[k
];
1445 if (value
>maxval
) /* build a new string */
1447 sprintf(buffer
,"%d",maxval
);
1452 editpos
=SendMessage16(hwnd
,EM_GETSEL
,0,0);
1453 SetWindowText32A(hwnd
,buffer
);
1454 SendMessage16(hwnd
,EM_SETSEL
,0,editpos
);
1461 /***********************************************************************
1462 * CC_PaintSelectedColor [internal]
1464 static void CC_PaintSelectedColor(HWND hDlg
,COLORREF cr
)
1469 HWND hwnd
=GetDlgItem(hDlg
,0x2c5);
1470 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1473 GetClientRect16 (hwnd
, &rect
) ;
1474 hBrush
= CreateSolidBrush32(cr
);
1477 hBrush
= SelectObject32 (hdc
, hBrush
) ;
1478 Rectangle32(hdc
, rect
.left
,rect
.top
,rect
.right
/2,rect
.bottom
);
1479 DeleteObject32 (SelectObject32 (hdc
,hBrush
)) ;
1480 hBrush
=CreateSolidBrush32(GetNearestColor(hdc
,cr
));
1483 hBrush
= SelectObject32 (hdc
, hBrush
) ;
1484 Rectangle32( hdc
, rect
.right
/2-1,rect
.top
,rect
.right
,rect
.bottom
);
1485 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
1488 ReleaseDC32(hwnd
,hdc
);
1492 /***********************************************************************
1493 * CC_PaintTriangle [internal]
1495 static void CC_PaintTriangle(HWND hDlg
,int y
)
1499 int w
=GetDialogBaseUnits();
1504 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
1505 struct CCPRIVATE
*lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1507 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1509 GetClientRect16(hwnd
,&rect
);
1513 points
[0].y
=rect
.top
;
1514 points
[0].x
=rect
.right
; /* | /| */
1515 ClientToScreen16(hwnd
,points
); /* | / | */
1516 ScreenToClient16(hDlg
,points
); /* |< | */
1517 oben
=points
[0].y
; /* | \ | */
1519 temp
=(long)height
*(long)y
;
1520 points
[0].y
=oben
+height
-temp
/(long)MAXVERT
;
1521 points
[1].y
=points
[0].y
+w
;
1522 points
[2].y
=points
[0].y
-w
;
1523 points
[2].x
=points
[1].x
=points
[0].x
+ w
;
1525 if (lpp
->old3angle
.left
)
1526 FillRect16(hDC
,&lpp
->old3angle
,GetStockObject32(WHITE_BRUSH
));
1527 lpp
->old3angle
.left
=points
[0].x
;
1528 lpp
->old3angle
.right
=points
[1].x
+1;
1529 lpp
->old3angle
.top
=points
[2].y
-1;
1530 lpp
->old3angle
.bottom
=points
[1].y
+1;
1531 Polygon16(hDC
,points
,3);
1532 ReleaseDC32(hDlg
,hDC
);
1537 /***********************************************************************
1538 * CC_PaintCross [internal]
1540 static void CC_PaintCross(HWND hDlg
,int x
,int y
)
1543 int w
=GetDialogBaseUnits();
1544 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1545 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1550 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1552 GetClientRect16(hwnd
,&rect
);
1554 SelectClipRgn32(hDC
,CreateRectRgnIndirect16(&rect
));
1555 hPen
=CreatePen32(PS_SOLID
,2,0);
1556 hPen
=SelectObject32(hDC
,hPen
);
1557 point
.x
=((long)rect
.right
*(long)x
)/(long)MAXHORI
;
1558 point
.y
=rect
.bottom
-((long)rect
.bottom
*(long)y
)/(long)MAXVERT
;
1559 if (lpp
->oldcross
.left
!=lpp
->oldcross
.right
)
1560 BitBlt32(hDC
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,
1561 lpp
->oldcross
.right
-lpp
->oldcross
.left
,
1562 lpp
->oldcross
.bottom
-lpp
->oldcross
.top
,
1563 lpp
->hdcMem
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,SRCCOPY
);
1564 lpp
->oldcross
.left
=point
.x
-w
-1;
1565 lpp
->oldcross
.right
=point
.x
+w
+1;
1566 lpp
->oldcross
.top
=point
.y
-w
-1;
1567 lpp
->oldcross
.bottom
=point
.y
+w
+1;
1569 MoveTo(hDC
,point
.x
-w
,point
.y
);
1570 LineTo32(hDC
,point
.x
+w
,point
.y
);
1571 MoveTo(hDC
,point
.x
,point
.y
-w
);
1572 LineTo32(hDC
,point
.x
,point
.y
+w
);
1573 DeleteObject32(SelectObject32(hDC
,hPen
));
1574 ReleaseDC32(hwnd
,hDC
);
1583 /***********************************************************************
1584 * CC_PrepareColorGraph [internal]
1586 static void CC_PrepareColorGraph(HWND hDlg
)
1588 int sdif
,hdif
,xdif
,ydif
,r
,g
,b
,hue
,sat
;
1589 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1590 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1594 HCURSOR16 hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
1596 GetClientRect16(hwnd
,&client
);
1598 lpp
->hdcMem
= CreateCompatibleDC(hdc
);
1599 lpp
->hbmMem
= CreateCompatibleBitmap(hdc
,client
.right
,client
.bottom
);
1600 SelectObject32(lpp
->hdcMem
,lpp
->hbmMem
);
1602 xdif
=client
.right
/XSTEPS
;
1603 ydif
=client
.bottom
/YSTEPS
+1;
1606 for(rect
.left
=hue
=0;hue
<239+hdif
;hue
+=hdif
)
1608 rect
.right
=rect
.left
+xdif
;
1609 rect
.bottom
=client
.bottom
;
1610 for(sat
=0;sat
<240+sdif
;sat
+=sdif
)
1612 rect
.top
=rect
.bottom
-ydif
;
1613 r
=CC_HSLtoRGB('R',hue
,sat
,120);
1614 g
=CC_HSLtoRGB('G',hue
,sat
,120);
1615 b
=CC_HSLtoRGB('B',hue
,sat
,120);
1616 hbrush
=CreateSolidBrush32(RGB(r
,g
,b
));
1617 FillRect16(lpp
->hdcMem
,&rect
,hbrush
);
1618 DeleteObject32(hbrush
);
1619 rect
.bottom
=rect
.top
;
1621 rect
.left
=rect
.right
;
1623 ReleaseDC32(hwnd
,hdc
);
1627 /***********************************************************************
1628 * CC_PaintColorGraph [internal]
1630 static void CC_PaintColorGraph(HWND hDlg
)
1632 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1633 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1636 if (IsWindowVisible(hwnd
)) /* if full size */
1639 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
1642 GetClientRect16(hwnd
,&rect
);
1644 BitBlt32(hDC
,0,0,rect
.right
,rect
.bottom
,lpp
->hdcMem
,0,0,SRCCOPY
);
1646 fprintf(stderr
,"choose color: hdcMem is not defined\n");
1647 ReleaseDC32(hwnd
,hDC
);
1650 /***********************************************************************
1651 * CC_PaintLumBar [internal]
1653 static void CC_PaintLumBar(HWND hDlg
,int hue
,int sat
)
1655 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
1657 int lum
,ldif
,ydif
,r
,g
,b
;
1661 if (IsWindowVisible(hwnd
))
1664 GetClientRect16(hwnd
,&client
);
1668 ydif
=client
.bottom
/YSTEPS
+1;
1669 for(lum
=0;lum
<240+ldif
;lum
+=ldif
)
1671 rect
.top
=MAX(0,rect
.bottom
-ydif
);
1672 r
=CC_HSLtoRGB('R',hue
,sat
,lum
);
1673 g
=CC_HSLtoRGB('G',hue
,sat
,lum
);
1674 b
=CC_HSLtoRGB('B',hue
,sat
,lum
);
1675 hbrush
=CreateSolidBrush32(RGB(r
,g
,b
));
1676 FillRect16(hDC
,&rect
,hbrush
);
1677 DeleteObject32(hbrush
);
1678 rect
.bottom
=rect
.top
;
1680 GetClientRect16(hwnd
,&rect
);
1681 FrameRect16(hDC
,&rect
,GetStockObject32(BLACK_BRUSH
));
1682 ReleaseDC32(hwnd
,hDC
);
1686 /***********************************************************************
1687 * CC_EditSetRGB [internal]
1689 static void CC_EditSetRGB(HWND hDlg
,COLORREF cr
)
1692 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1693 int r
=GetRValue(cr
);
1694 int g
=GetGValue(cr
);
1695 int b
=GetBValue(cr
);
1696 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1699 sprintf(buffer
,"%d",r
);
1700 SetWindowText32A(GetDlgItem(hDlg
,0x2c2),buffer
);
1701 sprintf(buffer
,"%d",g
);
1702 SetWindowText32A(GetDlgItem(hDlg
,0x2c3),buffer
);
1703 sprintf(buffer
,"%d",b
);
1704 SetWindowText32A(GetDlgItem(hDlg
,0x2c4),buffer
);
1705 lpp
->updating
=FALSE
;
1709 /***********************************************************************
1710 * CC_EditSetHSL [internal]
1712 static void CC_EditSetHSL(HWND hDlg
,int h
,int s
,int l
)
1715 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1717 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1720 sprintf(buffer
,"%d",h
);
1721 SetWindowText32A(GetDlgItem(hDlg
,0x2bf),buffer
);
1722 sprintf(buffer
,"%d",s
);
1723 SetWindowText32A(GetDlgItem(hDlg
,0x2c0),buffer
);
1724 sprintf(buffer
,"%d",l
);
1725 SetWindowText32A(GetDlgItem(hDlg
,0x2c1),buffer
);
1726 lpp
->updating
=FALSE
;
1728 CC_PaintLumBar(hDlg
,h
,s
);
1731 /***********************************************************************
1732 * CC_SwitchToFullSize [internal]
1734 static void CC_SwitchToFullSize(HWND hDlg
,COLORREF result
,LPRECT16 lprect
)
1737 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1739 EnableWindow(GetDlgItem(hDlg
,0x2cf),FALSE
);
1740 CC_PrepareColorGraph(hDlg
);
1741 for (i
=0x2bf;i
<0x2c5;i
++)
1742 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
1743 for (i
=0x2d3;i
<0x2d9;i
++)
1744 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
1745 EnableWindow(GetDlgItem(hDlg
,0x2c9),TRUE
);
1746 EnableWindow(GetDlgItem(hDlg
,0x2c8),TRUE
);
1749 SetWindowPos(hDlg
,NULL
,0,0,lprect
->right
-lprect
->left
,
1750 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
1752 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_SHOW
);
1753 ShowWindow(GetDlgItem(hDlg
,0x2be),SW_SHOW
);
1754 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_SHOW
);
1756 CC_EditSetRGB(hDlg
,result
);
1757 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1760 /***********************************************************************
1761 * CC_PaintPredefColorArray [internal]
1763 static void CC_PaintPredefColorArray(HWND hDlg
,int rows
,int cols
)
1765 HWND hwnd
=GetDlgItem(hDlg
,0x2d0);
1771 GetClientRect16(hwnd
,&rect
);
1773 dy
=rect
.bottom
/rows
;
1777 GetClientRect16 (hwnd
, &rect
) ;
1779 for (j
=0;j
<rows
;j
++)
1781 for (i
=0;i
<cols
;i
++)
1783 hBrush
= CreateSolidBrush32(predefcolors
[j
][i
]);
1786 hBrush
= SelectObject32 (hdc
, hBrush
) ;
1787 Rectangle32(hdc
, rect
.left
, rect
.top
,
1788 rect
.left
+dx
-DISTANCE
, rect
.top
+dy
-DISTANCE
);
1789 rect
.left
=rect
.left
+dx
;
1790 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
1793 rect
.top
=rect
.top
+dy
;
1796 ReleaseDC32(hwnd
,hdc
);
1797 /* FIXME: draw_a_focus_rect */
1799 /***********************************************************************
1800 * CC_PaintUserColorArray [internal]
1802 static void CC_PaintUserColorArray(HWND hDlg
,int rows
,int cols
,COLORREF
* lpcr
)
1804 HWND hwnd
=GetDlgItem(hDlg
,0x2d1);
1810 GetClientRect16(hwnd
,&rect
);
1813 dy
=rect
.bottom
/rows
;
1819 for (j
=0;j
<rows
;j
++)
1821 for (i
=0;i
<cols
;i
++)
1823 hBrush
= CreateSolidBrush32(lpcr
[i
+j
*cols
]);
1826 hBrush
= SelectObject32 (hdc
, hBrush
) ;
1827 Rectangle32( hdc
, rect
.left
, rect
.top
,
1828 rect
.left
+dx
-DISTANCE
, rect
.top
+dy
-DISTANCE
);
1829 rect
.left
=rect
.left
+dx
;
1830 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
1833 rect
.top
=rect
.top
+dy
;
1836 ReleaseDC32(hwnd
,hdc
);
1838 /* FIXME: draw_a_focus_rect */
1843 /***********************************************************************
1844 * CC_HookCallChk [internal]
1846 static BOOL
CC_HookCallChk(LPCHOOSECOLOR lpcc
)
1849 if(lpcc
->Flags
& CC_ENABLEHOOK
)
1855 /***********************************************************************
1856 * CC_WMInitDialog [internal]
1858 static LONG
CC_WMInitDialog(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
1864 struct CCPRIVATE
* lpp
;
1866 dprintf_commdlg(stddeb
,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1867 lpp
=calloc(1,sizeof(struct CCPRIVATE
));
1868 lpp
->lpcc
=(LPCHOOSECOLOR
)lParam
;
1869 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLOR
))
1871 EndDialog (hDlg
, 0) ;
1874 SetWindowLong32A(hDlg
, DWL_USER
, (LONG
)lpp
);
1876 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
1877 ShowWindow(GetDlgItem(hDlg
,0x40e),SW_HIDE
);
1878 lpp
->msetrgb
=RegisterWindowMessage32A( SETRGBSTRING
);
1880 cpos
=MAKELONG(5,7); /* init */
1881 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
1885 if (predefcolors
[i
][j
]==lpp
->lpcc
->rgbResult
)
1892 /* FIXME: Draw_a_focus_rect & set_init_values */
1894 GetWindowRect16(hDlg
,&lpp
->fullsize
);
1895 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1897 hwnd
=GetDlgItem(hDlg
,0x2cf);
1898 EnableWindow(hwnd
,FALSE
);
1900 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1903 res
=rect
.bottom
-rect
.top
;
1904 hwnd
=GetDlgItem(hDlg
,0x2c6); /* cut at left border */
1906 ClientToScreen16(hwnd
,&point
);
1907 ScreenToClient16(hDlg
,&point
);
1908 GetClientRect16(hDlg
,&rect
);
1909 point
.x
+=GetSystemMetrics(SM_CXDLGFRAME
);
1910 SetWindowPos(hDlg
,NULL
,0,0,point
.x
,res
,SWP_NOMOVE
|SWP_NOZORDER
);
1912 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_HIDE
);
1913 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_HIDE
);
1916 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,NULL
);
1918 for (i
=0x2bf;i
<0x2c5;i
++)
1919 SendMessage16(GetDlgItem(hDlg
,i
),EM_LIMITTEXT
,3,0); /* max 3 digits: xyz */
1920 if (CC_HookCallChk(lpp
->lpcc
))
1921 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1925 /***********************************************************************
1926 * CC_WMCommand [internal]
1928 static LRESULT
CC_WMCommand(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
1934 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1935 dprintf_commdlg(stddeb
,"CC_WMCommand wParam=%x lParam=%lx\n",wParam
,lParam
);
1938 case 0x2c2: /* edit notify RGB */
1941 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1943 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),255);
1944 r
=GetRValue(lpp
->lpcc
->rgbResult
);
1945 g
=GetGValue(lpp
->lpcc
->rgbResult
);
1946 b
=GetBValue(lpp
->lpcc
->rgbResult
);
1950 case 0x2c2:if ((xx
=(i
!=r
))) r
=i
;break;
1951 case 0x2c3:if ((xx
=(i
!=g
))) g
=i
;break;
1952 case 0x2c4:if ((xx
=(i
!=b
))) b
=i
;break;
1954 if (xx
) /* something has changed */
1956 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1957 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1958 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
1959 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
1960 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
1961 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1962 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1963 CC_PaintTriangle(hDlg
,lpp
->l
);
1968 case 0x2bf: /* edit notify HSL */
1971 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1973 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),wParam
==0x2bf?239:240);
1977 case 0x2bf:if ((xx
=(i
!=lpp
->h
))) lpp
->h
=i
;break;
1978 case 0x2c0:if ((xx
=(i
!=lpp
->s
))) lpp
->s
=i
;break;
1979 case 0x2c1:if ((xx
=(i
!=lpp
->l
))) lpp
->l
=i
;break;
1981 if (xx
) /* something has changed */
1983 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
1984 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
1985 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
1986 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1987 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1988 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
1989 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1990 CC_PaintTriangle(hDlg
,lpp
->l
);
1996 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,&lpp
->fullsize
);
1997 InvalidateRect32( hDlg
, NULL
, TRUE
);
1998 SetFocus32(GetDlgItem(hDlg
,0x2bf));
2001 case 0x2c8: /* add colors ... column by column */
2002 cr
=PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
);
2003 cr
[(lpp
->nextuserdef
%2)*8 + lpp
->nextuserdef
/2]=lpp
->lpcc
->rgbResult
;
2004 if (++lpp
->nextuserdef
==16)
2006 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2009 case 0x2c9: /* resulting color */
2011 lpp
->lpcc
->rgbResult
=GetNearestColor(hdc
,lpp
->lpcc
->rgbResult
);
2012 ReleaseDC32(hDlg
,hdc
);
2013 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2014 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2015 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2016 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2017 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2018 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2019 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2020 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2021 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2022 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2023 CC_PaintTriangle(hDlg
,lpp
->l
);
2026 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2027 i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2028 if (lpp
->lpcc
->hwndOwner
)
2029 SendMessage16(lpp
->lpcc
->hwndOwner
,i
,0,(LPARAM
)lpp
->lpcc
);
2030 if (CC_HookCallChk(lpp
->lpcc
))
2031 CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,
2032 WM_COMMAND
,psh15
,(LPARAM
)lpp
->lpcc
);
2036 cokmsg
=RegisterWindowMessage32A( COLOROKSTRING
);
2037 if (lpp
->lpcc
->hwndOwner
)
2038 if (SendMessage16(lpp
->lpcc
->hwndOwner
,cokmsg
,0,(LPARAM
)lpp
->lpcc
))
2039 break; /* do NOT close */
2041 EndDialog (hDlg
, 1) ;
2045 EndDialog (hDlg
, 0) ;
2052 /***********************************************************************
2053 * CC_WMPaint [internal]
2055 static LRESULT
CC_WMPaint(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2057 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2058 /* we have to paint dialog children except text and buttons */
2060 CC_PaintPredefColorArray(hDlg
,6,8);
2061 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2062 CC_PaintColorGraph(hDlg
);
2063 CC_PaintLumBar(hDlg
,lpp
->h
,lpp
->s
);
2064 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2065 CC_PaintTriangle(hDlg
,lpp
->l
);
2066 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2068 /* special necessary for Wine */
2069 ValidateRect32(GetDlgItem(hDlg
,0x2d0),NULL
);
2070 ValidateRect32(GetDlgItem(hDlg
,0x2d1),NULL
);
2071 ValidateRect32(GetDlgItem(hDlg
,0x2c6),NULL
);
2072 ValidateRect32(GetDlgItem(hDlg
,0x2be),NULL
);
2073 ValidateRect32(GetDlgItem(hDlg
,0x2c5),NULL
);
2074 /* hope we can remove it later -->FIXME */
2079 /***********************************************************************
2080 * CC_WMLButtonDown [internal]
2082 static LRESULT
CC_WMLButtonDown(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2084 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2087 if (CC_MouseCheckPredefColorArray(hDlg
,0x2d0,6,8,lParam
,&lpp
->lpcc
->rgbResult
))
2090 if (CC_MouseCheckUserColorArray(hDlg
,0x2d1,2,8,lParam
,&lpp
->lpcc
->rgbResult
,
2091 PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
)))
2094 if (CC_MouseCheckColorGraph(hDlg
,0x2c6,&lpp
->h
,&lpp
->s
,lParam
))
2097 if (CC_MouseCheckColorGraph(hDlg
,0x2be,NULL
,&lpp
->l
,lParam
))
2101 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
2102 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
2103 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
2104 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2108 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2109 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2110 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2111 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2112 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2113 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2117 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2118 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2119 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2120 CC_PaintTriangle(hDlg
,lpp
->l
);
2121 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2127 /***********************************************************************
2128 * ColorDlgProc (COMMDLG.8)
2130 LRESULT
ColorDlgProc(HWND hDlg
, UINT message
,
2131 WPARAM16 wParam
, LONG lParam
)
2134 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2135 if (message
!=WM_INITDIALOG
)
2140 if (CC_HookCallChk(lpp
->lpcc
))
2141 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2146 /* FIXME: SetRGB message
2147 if (message && message==msetrgb)
2148 return HandleSetRGB(hDlg,lParam);
2154 return CC_WMInitDialog(hDlg
,wParam
,lParam
);
2156 DeleteDC(lpp
->hdcMem
);
2157 DeleteObject32(lpp
->hbmMem
);
2159 SetWindowLong32A(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
2162 if (CC_WMCommand(hDlg
, wParam
, lParam
))
2166 CC_WMPaint(hDlg
, wParam
, lParam
);
2168 case WM_LBUTTONDBLCLK
:
2169 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
2172 case WM_MOUSEMOVE
: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2174 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
2176 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
2177 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
2186 /***********************************************************************
2187 * ChooseFont (COMMDLG.15)
2189 BOOL
ChooseFont(LPCHOOSEFONT lpChFont
)
2192 HANDLE16 hDlgTmpl
, hResInfo
;
2195 dprintf_commdlg(stddeb
,"ChooseFont\n");
2196 if (!lpChFont
) return FALSE
;
2197 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpChFont
->hInstance
;
2198 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
2200 if (!(hResInfo
= FindResource16(lpChFont
->hInstance
,
2201 lpChFont
->lpTemplateName
, RT_DIALOG
)))
2203 CommDlgLastError
= CDERR_FINDRESFAILURE
;
2206 hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
);
2208 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_FONT
);
2211 CommDlgLastError
= CDERR_LOADRESFAILURE
;
2214 hInst
= WIN_GetWindowInstance( lpChFont
->hwndOwner
);
2215 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpChFont
->hwndOwner
,
2216 (DLGPROC16
)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2218 if (!(lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
))
2220 if (lpChFont
->Flags
& CF_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
2221 else SYSRES_FreeResource( hDlgTmpl
);
2227 #define TEXT_EXTRAS 4
2228 #define TEXT_COLORS 16
2230 static const COLORREF textcolors
[TEXT_COLORS
]=
2232 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
2233 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
2234 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
2235 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
2238 /***********************************************************************
2239 * CFn_HookCallChk [internal]
2241 static BOOL
CFn_HookCallChk(LPCHOOSEFONT lpcf
)
2244 if(lpcf
->Flags
& CF_ENABLEHOOK
)
2251 /***********************************************************************
2252 * FontFamilyEnumProc (COMMDLG.19)
2254 INT16
FontFamilyEnumProc( SEGPTR logfont
, SEGPTR metrics
,
2255 UINT16 nFontType
, LPARAM lParam
)
2259 HWND hwnd
=LOWORD(lParam
);
2260 HWND hDlg
=GetParent16(hwnd
);
2261 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2262 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN( logfont
);
2264 dprintf_commdlg(stddeb
,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2265 lplf
->lfFaceName
,nFontType
);
2267 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
2268 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
2270 if (lpcf
->Flags
& CF_ANSIONLY
)
2271 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
2273 if (lpcf
->Flags
& CF_TTONLY
)
2274 if (!(nFontType
& 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2277 i
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,
2278 (LPARAM
)logfont
+ ((char *)lplf
->lfFaceName
- (char *)lplf
));
2281 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
2282 SendMessage16(hwnd
, CB_SETITEMDATA16
,i
,MAKELONG(nFontType
,w
));
2283 return 1 ; /* store some important font information */
2289 /*************************************************************************
2290 * SetFontStylesToCombo2 [internal]
2292 * Fill font style information into combobox (without using font.c directly)
2294 static int SetFontStylesToCombo2(HWND hwnd
, HDC16 hdc
, LPLOGFONT16 lplf
,
2295 LPTEXTMETRIC16 lptm
)
2302 static struct FONTSTYLE fontstyles
[FSTYLES
]={
2303 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
2304 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
2308 for (i
=0;i
<FSTYLES
;i
++)
2310 lplf
->lfItalic
=fontstyles
[i
].italic
;
2311 lplf
->lfWeight
=fontstyles
[i
].weight
;
2312 hf
=CreateFontIndirect16(lplf
);
2313 hf
=SelectObject32(hdc
,hf
);
2314 GetTextMetrics16(hdc
,lptm
);
2315 hf
=SelectObject32(hdc
,hf
);
2318 if (lptm
->tmWeight
==fontstyles
[i
].weight
&&
2319 lptm
->tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
2321 char *str
= SEGPTR_STRDUP(fontstyles
[i
].stname
);
2322 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(str
) );
2324 if (j
==CB_ERR
) return 1;
2325 j
=SendMessage16(hwnd
, CB_SETITEMDATA16
, j
,
2326 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
2327 if (j
==CB_ERR
) return 1;
2333 /*************************************************************************
2334 * SetFontSizesToCombo3 [internal]
2336 static int SetFontSizesToCombo3(HWND hwnd
, LPLOGFONT16 lplf
, LPCHOOSEFONT lpcf
)
2338 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2342 if (!(buffer
= SEGPTR_ALLOC(20))) return 1;
2343 for (i
=0;sizes
[i
] && !lplf
->lfHeight
;i
++)
2345 h
=lplf
->lfHeight
? lplf
->lfHeight
: sizes
[i
];
2347 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2348 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
2350 sprintf(buffer
,"%2d",h
);
2351 j
=SendMessage16(hwnd
,CB_FINDSTRING16
,-1,(LPARAM
)SEGPTR_GET(buffer
));
2354 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(buffer
));
2355 if (j
!=CB_ERR
) j
= SendMessage16(hwnd
, CB_SETITEMDATA16
, j
, h
);
2358 SEGPTR_FREE(buffer
);
2364 SEGPTR_FREE(buffer
);
2369 /***********************************************************************
2370 * FontStyleEnumProc (COMMDLG.18)
2372 INT16
FontStyleEnumProc( SEGPTR logfont
, SEGPTR metrics
,
2373 UINT16 nFontType
, LPARAM lParam
)
2375 HWND hcmb2
=LOWORD(lParam
);
2376 HWND hcmb3
=HIWORD(lParam
);
2377 HWND hDlg
=GetParent16(hcmb3
);
2378 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2379 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN(logfont
);
2380 TEXTMETRIC16
*lptm
= (TEXTMETRIC16
*)PTR_SEG_TO_LIN(metrics
);
2383 dprintf_commdlg(stddeb
,"FontStyleEnumProc: (nFontType=%d)\n",nFontType
);
2384 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",
2385 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,lplf
->lfEscapement
,lplf
->lfOrientation
,
2386 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,lplf
->lfStrikeOut
,lplf
->lfCharSet
,
2387 lplf
->lfOutPrecision
,lplf
->lfClipPrecision
,lplf
->lfQuality
,lplf
->lfPitchAndFamily
);
2389 if (SetFontSizesToCombo3(hcmb3
, lplf
,lpcf
))
2392 if (!SendMessage16(hcmb2
,CB_GETCOUNT16
,0,0))
2394 HDC32 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2395 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
,lptm
);
2396 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2397 ReleaseDC32(hDlg
,hdc
);
2405 /***********************************************************************
2406 * CFn_WMInitDialog [internal]
2408 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2414 HCURSOR16 hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
2417 SetWindowLong32A(hDlg
, DWL_USER
, lParam
);
2418 lpcf
=(LPCHOOSEFONT
)lParam
;
2419 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2420 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
2422 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONT
))
2424 dprintf_commdlg(stddeb
,"WM_INITDIALOG: structure size failure !!!\n");
2425 EndDialog (hDlg
, 0);
2429 hBitmapTT
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2431 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
2432 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
2433 if (!(lpcf
->Flags
& CF_APPLY
))
2434 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
2435 if (lpcf
->Flags
& CF_EFFECTS
)
2437 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
2439 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2440 char *name
= SEGPTR_ALLOC(20);
2441 strcpy( name
, "[color name]" );
2442 j
=SendDlgItemMessage16(hDlg
,cmb4
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(name
));
2444 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETITEMDATA16
,j
,textcolors
[j
]);
2445 /* look for a fitting value in color combobox */
2446 if (textcolors
[j
]==lpcf
->rgbColors
)
2447 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETCURSEL16
,j
,0);
2452 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
2453 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
2454 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
2455 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
2456 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
2458 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2461 if (!EnumFontFamilies16(hdc
, NULL
,FontFamilyEnumProc
,(LPARAM
)GetDlgItem(hDlg
,cmb1
)))
2462 dprintf_commdlg(stddeb
,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2463 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
2465 /* look for fitting font name in combobox1 */
2466 j
=SendDlgItemMessage16(hDlg
,cmb1
,CB_FINDSTRING16
,-1,(LONG
)lpxx
->lfFaceName
);
2469 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL16
,j
,0);
2470 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
2472 /* look for fitting font style in combobox2 */
2473 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
2474 for (i
=0;i
<TEXT_EXTRAS
;i
++)
2476 if (l
==SendDlgItemMessage16(hDlg
,cmb2
, CB_GETITEMDATA16
,i
,0))
2477 SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL16
,i
,0);
2480 /* look for fitting font size in combobox3 */
2481 j
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCOUNT16
,0,0);
2484 if (lpxx
->lfHeight
==(int)SendDlgItemMessage16(hDlg
,cmb3
, CB_GETITEMDATA16
,i
,0))
2485 SendDlgItemMessage16(hDlg
,cmb3
,CB_SETCURSEL16
,i
,0);
2490 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL16
,0,0);
2491 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
2494 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
2496 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_FINDSTRING16
,-1,(LONG
)lpcf
->lpszStyle
);
2499 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL16
,j
,0);
2500 SendMessage16(hDlg
,WM_COMMAND
,cmb2
,MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
2506 dprintf_commdlg(stddeb
,"WM_INITDIALOG: HDC failure !!!\n");
2507 EndDialog (hDlg
, 0);
2511 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2512 ReleaseDC32(hDlg
,hdc
);
2514 if (CFn_HookCallChk(lpcf
))
2515 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
2521 /***********************************************************************
2522 * CFn_WMMeasureItem [internal]
2524 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2527 LPMEASUREITEMSTRUCT16 lpmi
=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT16
)lParam
);
2529 hBitmapTT
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2530 GetObject16( hBitmapTT
, sizeof(bm
), &bm
);
2531 lpmi
->itemHeight
=bm
.bmHeight
;
2532 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2537 /***********************************************************************
2538 * CFn_WMDrawItem [internal]
2540 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2550 HBITMAP16 hBitmap
; /* for later TT usage */
2552 LPDRAWITEMSTRUCT16 lpdi
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
2554 if (lpdi
->itemID
== 0xFFFF) /* got no items */
2555 DrawFocusRect16(lpdi
->hDC
, &lpdi
->rcItem
);
2558 if (lpdi
->CtlType
== ODT_COMBOBOX
)
2560 hBrush
= SelectObject32(lpdi
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
2561 SelectObject32(lpdi
->hDC
, hBrush
);
2562 FillRect16(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
2565 return TRUE
; /* this should never happen */
2568 buffer
= SEGPTR_ALLOC(40);
2569 switch (lpdi
->CtlID
)
2571 case cmb1
: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2572 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT16
, lpdi
->itemID
,
2573 (LPARAM
)SEGPTR_GET(buffer
));
2574 GetObject16( hBitmapTT
, sizeof(bm
), &bm
);
2575 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
2576 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2578 nFontType
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA16
, lpdi
->itemID
,0L);
2579 /* FIXME: draw bitmap if truetype usage */
2580 if (nFontType
&TRUETYPE_FONTTYPE
)
2582 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
2583 hBitmap
= SelectObject32(hMemDC
, hBitmapTT
);
2584 BitBlt32(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
2585 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
2586 SelectObject32(hMemDC
, hBitmap
);
2592 case cmb3
: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2593 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT16
, lpdi
->itemID
,
2594 (LPARAM
)SEGPTR_GET(buffer
));
2595 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
,
2596 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2599 case cmb4
: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2600 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT16
, lpdi
->itemID
,
2601 (LPARAM
)SEGPTR_GET(buffer
));
2602 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
2603 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2604 cr
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA16
, lpdi
->itemID
,0L);
2605 hBrush
= CreateSolidBrush32(cr
);
2608 hBrush
= SelectObject32 (lpdi
->hDC
, hBrush
) ;
2609 rect
.right
=rect
.left
+25;
2613 Rectangle32( lpdi
->hDC
, rect
.left
, rect
.top
,
2614 rect
.right
, rect
.bottom
);
2615 DeleteObject32( SelectObject32 (lpdi
->hDC
, hBrush
)) ;
2621 default: return TRUE
; /* this should never happen */
2623 SEGPTR_FREE(buffer
);
2624 if (lpdi
->itemState
==ODS_SELECTED
)
2625 InvertRect16(lpdi
->hDC
, &rect
);
2630 /***********************************************************************
2631 * CFn_WMCtlColor [internal]
2633 LRESULT
CFn_WMCtlColor(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2635 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2637 if (lpcf
->Flags
& CF_EFFECTS
)
2638 if (HIWORD(lParam
)==CTLCOLOR_STATIC
&& GetDlgCtrlID(LOWORD(lParam
))==stc6
)
2640 SetTextColor(wParam
,lpcf
->rgbColors
);
2641 return GetStockObject32(WHITE_BRUSH
);
2646 /***********************************************************************
2647 * CFn_WMCommand [internal]
2649 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2655 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2656 LPLOGFONT16 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2658 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam
);
2661 case cmb1
:if (HIWORD(lParam
)==CBN_SELCHANGE
)
2663 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2666 SendDlgItemMessage16(hDlg
,cmb2
,CB_RESETCONTENT16
,0,0);
2667 SendDlgItemMessage16(hDlg
,cmb3
,CB_RESETCONTENT16
,0,0);
2668 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL16
,0,0);
2671 HCURSOR16 hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
2672 char *str
= SEGPTR_ALLOC(256);
2673 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT16
,i
,
2674 (LPARAM
)SEGPTR_GET(str
));
2675 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb1 =>%s\n",str
);
2676 EnumFontFamilies16(hdc
,str
,FontStyleEnumProc
,
2677 MAKELONG(GetDlgItem(hDlg
,cmb2
),GetDlgItem(hDlg
,cmb3
)));
2681 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2682 ReleaseDC32(hDlg
,hdc
);
2686 dprintf_commdlg(stddeb
,"WM_COMMAND: HDC failure !!!\n");
2687 EndDialog (hDlg
, 0);
2694 case cmb3
:if (HIWORD(lParam
)==CBN_SELCHANGE
|| HIWORD(lParam
)== BN_CLICKED
)
2696 char *str
= SEGPTR_ALLOC(256);
2697 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
2698 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL16
,0,0);
2700 i
=GetDlgItemText32A( hDlg
, cmb1
, str
, 256 );
2703 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT16
,i
,
2704 (LPARAM
)SEGPTR_GET(str
));
2705 l
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETITEMDATA16
,i
,0);
2707 lpcf
->nFontType
= LOWORD(l
);
2708 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2709 /* same value reported to the EnumFonts
2710 call back with the extra FONTTYPE_... bits added */
2711 lpxx
->lfPitchAndFamily
=j
&0xff;
2712 lpxx
->lfCharSet
=j
>>8;
2714 strcpy(lpxx
->lfFaceName
,str
);
2716 i
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETCURSEL16
,0,0);
2719 l
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETITEMDATA16
,i
,0);
2720 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
2721 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
2722 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
2723 lpcf
->nFontType
|= BOLD_FONTTYPE
;
2725 i
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCURSEL16
,0,0);
2727 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessage16(hDlg
,cmb3
,CB_GETITEMDATA16
,i
,0));
2730 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
2731 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
2732 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
2733 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
2734 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
2735 lpxx
->lfQuality
=DEFAULT_QUALITY
;
2736 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
2738 hFont
=CreateFontIndirect16(lpxx
);
2740 SendDlgItemMessage16(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
2741 /* FIXME: Delete old font ...? */
2745 case cmb4
:i
=SendDlgItemMessage16(hDlg
,cmb4
,CB_GETCURSEL16
,0,0);
2748 lpcf
->rgbColors
=textcolors
[i
];
2749 InvalidateRect32( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
2753 case psh15
:i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2754 if (lpcf
->hwndOwner
)
2755 SendMessage16(lpcf
->hwndOwner
,i
,0,(LPARAM
)lpcf
);
2756 if (CFn_HookCallChk(lpcf
))
2757 CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_COMMAND
,psh15
,(LPARAM
)lpcf
);
2760 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2761 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
2762 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
2763 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
2764 EndDialog(hDlg
, TRUE
);
2768 sprintf(buffer
,"Select a font size between %d and %d points.",
2769 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
2770 MessageBox(hDlg
,buffer
,NULL
,MB_OK
);
2773 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
2780 /***********************************************************************
2781 * FormatCharDlgProc (COMMDLG.16)
2782 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2783 2. some CF_.. flags are not supported
2784 3. some TType extensions
2786 LRESULT
FormatCharDlgProc(HWND hDlg
, UINT message
, WPARAM16 wParam
, LPARAM lParam
)
2788 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2789 if (message
!=WM_INITDIALOG
)
2794 if (CFn_HookCallChk(lpcf
))
2795 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2800 return CFn_WMInitDialog(hDlg
,wParam
,lParam
);
2803 case WM_MEASUREITEM
:
2804 return CFn_WMMeasureItem(hDlg
,wParam
,lParam
);
2806 return CFn_WMDrawItem(hDlg
,wParam
,lParam
);
2808 return CFn_WMCtlColor(hDlg
,wParam
,lParam
);
2810 return CFn_WMCommand(hDlg
,wParam
,lParam
);
2811 case WM_CHOOSEFONT_GETLOGFONT
:
2812 dprintf_commdlg(stddeb
,
2813 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam
);
2814 /* FIXME: current logfont back to caller */