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
)
171 char *str
= SEGPTR_ALLOC(512);
172 if (!str
) return TRUE
;
174 lstrcpyn32A( str
, newPath
, 512 );
176 GetDlgItemText32A( hWnd
, edt1
, str
+ len
, 512 - len
);
177 if (DlgDirList(hWnd
, SEGPTR_GET(str
), lst1
, 0, 0x0000))
179 strcpy( str
, "*.*" );
180 DlgDirList(hWnd
, SEGPTR_GET(str
), lst2
, stc1
, 0x8010 );
187 /***********************************************************************
188 * FILEDLG_GetFileType [internal]
191 static LPSTR
FILEDLG_GetFileType(LPSTR cfptr
, LPSTR fptr
, WORD index
)
196 for ( ;(n
= strlen(cfptr
)) != 0; i
++)
201 cfptr
+= strlen(cfptr
) + 1;
204 for ( ;(n
= strlen(fptr
)) != 0; i
++)
209 fptr
+= strlen(fptr
) + 1;
214 /***********************************************************************
215 * FILEDLG_WMDrawItem [internal]
217 static LONG
FILEDLG_WMDrawItem(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
,int savedlg
)
219 LPDRAWITEMSTRUCT16 lpdis
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
222 HBITMAP16 hBitmap
, hPrevBitmap
;
226 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
228 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
229 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
230 SelectObject(lpdis
->hDC
, hBrush
);
231 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
232 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT16
, lpdis
->itemID
,
233 (LPARAM
)SEGPTR_GET(str
));
235 if (savedlg
) /* use _gray_ text in FileSaveDlg */
236 if (!lpdis
->itemState
)
237 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_GRAYTEXT
) );
239 SetTextColor(lpdis
->hDC
,GetSysColor(COLOR_WINDOWTEXT
) );
240 /* inversion of gray would be bad readable */
242 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
244 if (lpdis
->itemState
!= 0) {
245 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
251 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
253 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
254 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
255 SelectObject(lpdis
->hDC
, hBrush
);
256 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
257 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT16
, lpdis
->itemID
,
258 (LPARAM
)SEGPTR_GET(str
));
261 GetObject16( hBitmap
, sizeof(bm
), &bm
);
262 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
263 lpdis
->rcItem
.top
, str
, strlen(str
));
264 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
265 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
266 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
267 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
268 SelectObject(hMemDC
, hPrevBitmap
);
270 if (lpdis
->itemState
!= 0) InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
274 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
276 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
277 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
278 SelectObject(lpdis
->hDC
, hBrush
);
279 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
280 SendMessage16(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
281 (LPARAM
)SEGPTR_GET(str
));
282 switch(DRIVE_GetType( str
[2] - 'a' ))
284 case TYPE_FLOPPY
: hBitmap
= hFloppy
; break;
285 case TYPE_CDROM
: hBitmap
= hCDRom
; break;
288 default: hBitmap
= hHDisk
; break;
290 GetObject16( hBitmap
, sizeof(bm
), &bm
);
291 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
292 lpdis
->rcItem
.top
, str
, strlen(str
));
293 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
294 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
295 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
296 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
297 SelectObject(hMemDC
, hPrevBitmap
);
299 if (lpdis
->itemState
!= 0) InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
306 /***********************************************************************
307 * FILEDLG_WMMeasureItem [internal]
309 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
312 LPMEASUREITEMSTRUCT16 lpmeasure
;
314 GetObject16( hFolder2
, sizeof(bm
), &bm
);
315 lpmeasure
= (LPMEASUREITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
316 lpmeasure
->itemHeight
= bm
.bmHeight
;
320 /***********************************************************************
321 * FILEDLG_HookCallChk [internal]
323 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn
)
326 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
332 /***********************************************************************
333 * FILEDLG_WMInitDialog [internal]
336 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
339 LPOPENFILENAME lpofn
;
342 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
343 lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(lParam
);
344 if (lpofn
->lpstrTitle
) SetWindowText16( hWnd
, lpofn
->lpstrTitle
);
345 /* read custom filter information */
346 if (lpofn
->lpstrCustomFilter
)
348 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
);
350 dprintf_commdlg(stddeb
,"lpstrCustomFilter = %p\n", pstr
);
353 dprintf_commdlg(stddeb
,"lpstrCustomFilter // add str='%s' ",pstr
);
354 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING
, 0,
355 (LPARAM
)lpofn
->lpstrCustomFilter
+ n
);
356 n
+= strlen(pstr
) + 1;
357 pstr
+= strlen(pstr
) + 1;
358 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
359 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
360 n
+= strlen(pstr
) + 1;
361 pstr
+= strlen(pstr
) + 1;
364 /* read filter information */
365 if (lpofn
->lpstrFilter
) {
366 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
369 dprintf_commdlg(stddeb
,"lpstrFilter // add str='%s' ", pstr
);
370 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING
, 0,
371 (LPARAM
)lpofn
->lpstrFilter
+ n
);
372 n
+= strlen(pstr
) + 1;
373 pstr
+= strlen(pstr
) + 1;
374 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
375 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
376 n
+= strlen(pstr
) + 1;
377 pstr
+= strlen(pstr
) + 1;
380 /* set default filter */
381 if (lpofn
->nFilterIndex
== 0 && lpofn
->lpstrCustomFilter
== (SEGPTR
)NULL
)
382 lpofn
->nFilterIndex
= 1;
383 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETCURSEL
, lpofn
->nFilterIndex
- 1, 0);
384 strncpy(tmpstr
, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
385 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lpofn
->nFilterIndex
- 1),511);
387 dprintf_commdlg(stddeb
,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
388 lpofn
->nFilterIndex
, tmpstr
);
389 SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
391 pstr
= SEGPTR_ALLOC(1);
393 DlgDirListComboBox16(hWnd
, SEGPTR_GET(pstr
), cmb2
, 0, 0xC000);
395 /* read initial directory */
396 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
)
398 strncpy(tmpstr
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
), 510);
400 if (strlen(tmpstr
) > 0 && tmpstr
[strlen(tmpstr
)-1] != '\\'
401 && tmpstr
[strlen(tmpstr
)-1] != ':')
406 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
407 fprintf(stderr
, "FileDlg: couldn't read initial directory %s!\n", tmpstr
);
408 /* select current drive in combo 2 */
409 n
= DRIVE_GetCurrentDrive();
410 SendDlgItemMessage16(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
411 if (!(lpofn
->Flags
& OFN_SHOWHELP
))
412 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
413 if (lpofn
->Flags
& OFN_HIDEREADONLY
)
414 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
415 if (FILEDLG_HookCallChk(lpofn
))
416 return (BOOL
)CallWindowProc16(lpofn
->lpfnHook
,
417 hWnd
, WM_INITDIALOG
, wParam
, lParam
);
422 /***********************************************************************
423 * FILEDLG_WMCommand [internal]
425 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
428 LPOPENFILENAME lpofn
;
430 char tmpstr
[512], tmpstr2
[512];
432 UINT control
,notification
;
434 /* Notifications are packaged differently in Win32 */
436 notification
= HIWORD(lParam
);
438 lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
441 case lst1
: /* file list */
442 FILEDLG_StripEditControl(hWnd
);
443 if (notification
== LBN_DBLCLK
)
445 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
446 if (lRet
== LB_ERR
) return TRUE
;
447 if ((pstr
= SEGPTR_ALLOC(512)))
449 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT16
, lRet
,
450 (LPARAM
)SEGPTR_GET(pstr
));
451 SetDlgItemText32A( hWnd
, edt1
, pstr
);
454 if (FILEDLG_HookCallChk(lpofn
))
455 CallWindowProc16(lpofn
->lpfnHook
, hWnd
,
456 RegisterWindowMessage32A( LBSELCHSTRING
),
457 control
, MAKELONG(lRet
,CD_LBSELCHANGE
));
458 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
460 case lst2
: /* directory list */
461 FILEDLG_StripEditControl(hWnd
);
462 if (notification
== LBN_DBLCLK
)
464 lRet
= SendDlgItemMessage16(hWnd
, lst2
, LB_GETCURSEL16
, 0, 0);
465 if (lRet
== LB_ERR
) return TRUE
;
466 pstr
= SEGPTR_ALLOC(512);
467 SendDlgItemMessage16(hWnd
, lst2
, LB_GETTEXT16
, lRet
,
468 (LPARAM
)SEGPTR_GET(pstr
));
469 strcpy( tmpstr
, pstr
);
471 if (tmpstr
[0] == '[')
473 tmpstr
[strlen(tmpstr
) - 1] = 0;
474 strcpy(tmpstr
,tmpstr
+1);
476 strcat(tmpstr
, "\\");
480 case cmb1
: /* file type drop list */
481 if (notification
== CBN_SELCHANGE
)
487 case cmb2
: /* disk drop list */
488 FILEDLG_StripEditControl(hWnd
);
489 lRet
= SendDlgItemMessage16(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
490 if (lRet
== LB_ERR
) return 0;
491 pstr
= SEGPTR_ALLOC(512);
492 SendDlgItemMessage16(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
,
493 (LPARAM
)SEGPTR_GET(pstr
));
494 sprintf(tmpstr
, "%c:", pstr
[2]);
497 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
500 pstr
= (LPSTR
)SendDlgItemMessage16(hWnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
501 dprintf_commdlg(stddeb
,"Selected filter : %s\n", pstr
);
502 SetDlgItemText32A( hWnd
, edt1
, pstr
);
503 FILEDLG_ScanDir(hWnd
, tmpstr
);
511 ofn2
=*lpofn
; /* for later restoring */
512 GetDlgItemText32A( hWnd
, edt1
, tmpstr
, sizeof(tmpstr
) );
513 pstr
= strrchr(tmpstr
, '\\');
515 pstr
= strrchr(tmpstr
, ':');
516 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
518 /* edit control contains wildcards */
521 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
526 strcpy(tmpstr2
, tmpstr
);
529 dprintf_commdlg(stddeb
,"commdlg: %s, %s\n", tmpstr
, tmpstr2
);
530 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
531 FILEDLG_ScanDir(hWnd
, tmpstr
);
534 /* no wildcards, we might have a directory or a filename */
535 /* try appending a wildcard and reading the directory */
536 pstr2
= tmpstr
+ strlen(tmpstr
);
537 if (pstr
== NULL
|| *(pstr
+1) != 0)
538 strcat(tmpstr
, "\\");
539 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
540 if (lRet
== LB_ERR
) return TRUE
;
541 lpofn
->nFilterIndex
= lRet
+ 1;
542 dprintf_commdlg(stddeb
,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn
->nFilterIndex
);
544 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
545 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
546 lRet
), sizeof(tmpstr2
));
547 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
548 /* if ScanDir succeeds, we have changed the directory */
549 if (FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
550 /* if not, this must be a filename */
554 /* strip off the pathname */
556 SetDlgItemText32A( hWnd
, edt1
, pstr
+ 1 );
557 lstrcpyn32A(tmpstr2
, pstr
+1, sizeof(tmpstr2
) );
558 /* Should we MessageBox() if this fails? */
559 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
560 strcpy(tmpstr
, tmpstr2
);
562 else SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
564 ShowWindow(hWnd
, SW_HIDE
); /* this should not be necessary ?! (%%%) */
567 int drive
= DRIVE_GetCurrentDrive();
568 tmpstr2
[0] = 'A'+ drive
;
571 strncpy(tmpstr2
+ 3, DRIVE_GetDosCwd(drive
), 507); tmpstr2
[510]=0;
572 if (strlen(tmpstr2
) > 3)
573 strcat(tmpstr2
, "\\");
574 strncat(tmpstr2
, tmpstr
, 511-strlen(tmpstr2
)); tmpstr2
[511]=0;
575 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), tmpstr2
);
577 lpofn
->nFileOffset
= 0;
578 lpofn
->nFileExtension
= 0;
579 while(tmpstr2
[lpofn
->nFileExtension
] != '.' && tmpstr2
[lpofn
->nFileExtension
] != '\0')
580 lpofn
->nFileExtension
++;
581 if (lpofn
->nFileExtension
== '\0')
582 lpofn
->nFileExtension
= 0;
584 lpofn
->nFileExtension
++;
585 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
)
587 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
588 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT16
, lRet
,
589 lpofn
->lpstrFileTitle
);
591 if (FILEDLG_HookCallChk(lpofn
))
593 lRet
= (BOOL
)CallWindowProc16(lpofn
->lpfnHook
,
594 hWnd
, RegisterWindowMessage32A( FILEOKSTRING
), 0, lParam
);
597 *lpofn
=ofn2
; /* restore old state */
599 ShowWindow(hWnd
, SW_SHOW
); /* only if above (%%%) SW_HIDE used */
604 EndDialog(hWnd
, TRUE
);
607 EndDialog(hWnd
, FALSE
);
614 /***********************************************************************
615 * FileOpenDlgProc (COMMDLG.6)
617 LRESULT
FileOpenDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
619 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
621 if (wMsg
!=WM_INITDIALOG
)
622 if (FILEDLG_HookCallChk(lpofn
))
624 LRESULT lRet
=(BOOL
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
626 return lRet
; /* else continue message processing */
631 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
633 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
635 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
);
637 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
640 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
641 switch (HIWORD(lParam
))
644 SetTextColor((HDC16
)wParam
, 0x00000000);
646 case CTLCOLOR_STATIC
:
647 SetTextColor((HDC16
)wParam
, 0x00000000);
657 /***********************************************************************
658 * FileSaveDlgProc (COMMDLG.7)
660 LRESULT
FileSaveDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
662 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
664 if (wMsg
!=WM_INITDIALOG
)
665 if (FILEDLG_HookCallChk(lpofn
))
667 LRESULT lRet
=(BOOL
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
669 return lRet
; /* else continue message processing */
673 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
676 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
679 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
);
682 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
687 SetBkColor((HDC16)wParam, 0x00C0C0C0);
688 switch (HIWORD(lParam))
691 SetTextColor((HDC16)wParam, 0x00000000);
693 case CTLCOLOR_STATIC:
694 SetTextColor((HDC16)wParam, 0x00000000);
704 /***********************************************************************
705 * FindTextDlg (COMMDLG.11)
707 BOOL
FindText( SEGPTR find
)
709 HANDLE16 hInst
, hDlgTmpl
;
712 LPFINDREPLACE lpFind
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(find
);
715 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
716 * For now, only the standard dialog works.
719 * FIXME : We should do error checking on the lpFind structure here
720 * and make CommDlgExtendedError() return the error condition.
722 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT
);
723 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
724 if (!(ptr
= GlobalLock16( hDlgTmpl
))) return -1;
725 bRet
= CreateDialogIndirectParam16( hInst
, ptr
, lpFind
->hwndOwner
,
726 (DLGPROC16
)MODULE_GetWndProcEntry16("FindTextDlgProc"),
728 GlobalUnlock16( hDlgTmpl
);
729 SYSRES_FreeResource( hDlgTmpl
);
734 /***********************************************************************
735 * ReplaceTextDlg (COMMDLG.12)
737 BOOL
ReplaceText( SEGPTR find
)
739 HANDLE16 hInst
, hDlgTmpl
;
742 LPFINDREPLACE lpFind
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(find
);
745 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
746 * For now, only the standard dialog works.
749 * FIXME : We should do error checking on the lpFind structure here
750 * and make CommDlgExtendedError() return the error condition.
752 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT
);
753 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
754 if (!(ptr
= GlobalLock16( hDlgTmpl
))) return -1;
755 bRet
= CreateDialogIndirectParam16( hInst
, ptr
, lpFind
->hwndOwner
,
756 (DLGPROC16
)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
758 GlobalUnlock16( hDlgTmpl
);
759 SYSRES_FreeResource( hDlgTmpl
);
764 /***********************************************************************
765 * FINDDLG_WMInitDialog [internal]
767 static LRESULT
FINDDLG_WMInitDialog(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
771 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
772 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(lParam
);
773 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
775 * FIXME : If the initial FindWhat string is empty, we should disable the
776 * FindNext (IDOK) button. Only after typing some text, the button should be
779 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
780 CheckRadioButton(hWnd
, rad1
, rad2
, (lpfr
->Flags
& FR_DOWN
) ? rad2
: rad1
);
781 if (lpfr
->Flags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
782 EnableWindow(GetDlgItem(hWnd
, rad1
), FALSE
);
783 EnableWindow(GetDlgItem(hWnd
, rad2
), FALSE
);
785 if (lpfr
->Flags
& FR_HIDEUPDOWN
) {
786 ShowWindow(GetDlgItem(hWnd
, rad1
), SW_HIDE
);
787 ShowWindow(GetDlgItem(hWnd
, rad2
), SW_HIDE
);
788 ShowWindow(GetDlgItem(hWnd
, grp1
), SW_HIDE
);
790 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
791 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
792 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
793 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
794 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
795 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
796 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
797 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
798 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
799 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
800 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
801 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
802 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
804 ShowWindow(hWnd
, SW_SHOWNORMAL
);
809 /***********************************************************************
810 * FINDDLG_WMCommand [internal]
812 static LRESULT
FINDDLG_WMCommand(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
815 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
816 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
818 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
821 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
822 if (IsDlgButtonChecked(hWnd
, rad2
))
823 lpfr
->Flags
|= FR_DOWN
;
824 else lpfr
->Flags
&= ~FR_DOWN
;
825 if (IsDlgButtonChecked(hWnd
, chx1
))
826 lpfr
->Flags
|= FR_WHOLEWORD
;
827 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
828 if (IsDlgButtonChecked(hWnd
, chx2
))
829 lpfr
->Flags
|= FR_MATCHCASE
;
830 else lpfr
->Flags
&= ~FR_MATCHCASE
;
831 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
832 lpfr
->Flags
|= FR_FINDNEXT
;
833 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
834 GetWindowLong32A(hWnd
, DWL_USER
) );
837 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
838 lpfr
->Flags
|= FR_DIALOGTERM
;
839 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
840 GetWindowLong32A(hWnd
, DWL_USER
) );
844 /* FIXME : should lpfr structure be passed as an argument ??? */
845 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
852 /***********************************************************************
853 * FindTextDlgProc (COMMDLG.13)
855 LRESULT
FindTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
859 return FINDDLG_WMInitDialog(hWnd
, wParam
, lParam
);
861 return FINDDLG_WMCommand(hWnd
, wParam
, lParam
);
867 /***********************************************************************
868 * REPLACEDLG_WMInitDialog [internal]
870 static LRESULT
REPLACEDLG_WMInitDialog(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
874 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
875 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(lParam
);
876 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
878 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
879 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
882 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
883 SetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
);
884 CheckDlgButton(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
885 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
886 EnableWindow(GetDlgItem(hWnd
, chx1
), FALSE
);
887 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
888 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
889 CheckDlgButton(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
890 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
891 EnableWindow(GetDlgItem(hWnd
, chx2
), FALSE
);
892 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
893 ShowWindow(GetDlgItem(hWnd
, chx2
), SW_HIDE
);
894 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
895 EnableWindow(GetDlgItem(hWnd
, pshHelp
), FALSE
);
896 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
898 ShowWindow(hWnd
, SW_SHOWNORMAL
);
903 /***********************************************************************
904 * REPLACEDLG_WMCommand [internal]
906 static LRESULT
REPLACEDLG_WMCommand(HWND hWnd
, WPARAM16 wParam
, LPARAM lParam
)
909 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
910 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
912 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
915 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
916 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
917 if (IsDlgButtonChecked(hWnd
, chx1
))
918 lpfr
->Flags
|= FR_WHOLEWORD
;
919 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
920 if (IsDlgButtonChecked(hWnd
, chx2
))
921 lpfr
->Flags
|= FR_MATCHCASE
;
922 else lpfr
->Flags
&= ~FR_MATCHCASE
;
923 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
924 lpfr
->Flags
|= FR_FINDNEXT
;
925 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
926 GetWindowLong32A(hWnd
, DWL_USER
) );
929 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
930 lpfr
->Flags
|= FR_DIALOGTERM
;
931 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
932 GetWindowLong32A(hWnd
, DWL_USER
) );
936 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
937 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
938 if (IsDlgButtonChecked(hWnd
, chx1
))
939 lpfr
->Flags
|= FR_WHOLEWORD
;
940 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
941 if (IsDlgButtonChecked(hWnd
, chx2
))
942 lpfr
->Flags
|= FR_MATCHCASE
;
943 else lpfr
->Flags
&= ~FR_MATCHCASE
;
944 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
945 lpfr
->Flags
|= FR_REPLACE
;
946 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
947 GetWindowLong32A(hWnd
, DWL_USER
) );
950 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
951 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
952 if (IsDlgButtonChecked(hWnd
, chx1
))
953 lpfr
->Flags
|= FR_WHOLEWORD
;
954 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
955 if (IsDlgButtonChecked(hWnd
, chx2
))
956 lpfr
->Flags
|= FR_MATCHCASE
;
957 else lpfr
->Flags
&= ~FR_MATCHCASE
;
958 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
959 lpfr
->Flags
|= FR_REPLACEALL
;
960 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
961 GetWindowLong32A(hWnd
, DWL_USER
) );
964 /* FIXME : should lpfr structure be passed as an argument ??? */
965 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
972 /***********************************************************************
973 * ReplaceTextDlgProc (COMMDLG.14)
975 LRESULT
ReplaceTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
979 return REPLACEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
981 return REPLACEDLG_WMCommand(hWnd
, wParam
, lParam
);
987 /***********************************************************************
988 * PrintDlg (COMMDLG.20)
990 BOOL
PrintDlg( SEGPTR printdlg
)
992 HANDLE16 hInst
, hDlgTmpl
;
994 LPPRINTDLG lpPrint
= (LPPRINTDLG
)PTR_SEG_TO_LIN(printdlg
);
996 dprintf_commdlg(stddeb
,"PrintDlg(%p) // Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
998 if (lpPrint
->Flags
& PD_RETURNDEFAULT
)
999 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1002 if (lpPrint
->Flags
& PD_PRINTSETUP
)
1003 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP
);
1005 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT
);
1007 hInst
= WIN_GetWindowInstance( lpPrint
->hwndOwner
);
1008 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpPrint
->hwndOwner
,
1009 (DLGPROC16
)((lpPrint
->Flags
& PD_PRINTSETUP
) ?
1010 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1011 MODULE_GetWndProcEntry16("PrintDlgProc")),
1013 SYSRES_FreeResource( hDlgTmpl
);
1018 /***********************************************************************
1019 * PrintDlgProc (COMMDLG.21)
1021 LRESULT
PrintDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
1026 dprintf_commdlg(stddeb
,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1027 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1033 EndDialog(hWnd
, TRUE
);
1036 EndDialog(hWnd
, FALSE
);
1045 /***********************************************************************
1046 * PrintSetupDlgProc (COMMDLG.22)
1048 LRESULT
PrintSetupDlgProc(HWND hWnd
, UINT wMsg
, WPARAM16 wParam
, LPARAM lParam
)
1053 dprintf_commdlg(stddeb
,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1054 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1059 EndDialog(hWnd
, TRUE
);
1062 EndDialog(hWnd
, FALSE
);
1071 /***********************************************************************
1072 * CommDlgExtendedError (COMMDLG.26)
1074 DWORD
CommDlgExtendedError(void)
1076 return CommDlgLastError
;
1080 /***********************************************************************
1081 * GetFileTitle (COMMDLG.27)
1083 short GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT cbBuf
)
1086 dprintf_commdlg(stddeb
,"GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
1087 if (lpFile
== NULL
|| lpTitle
== NULL
)
1089 len
= strlen(lpFile
);
1092 if (strpbrk(lpFile
, "*[]"))
1095 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
1097 for (i
= len
; i
>= 0; i
--)
1098 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
1103 dprintf_commdlg(stddeb
,"\n---> '%s' ", &lpFile
[i
]);
1105 len
= strlen(lpFile
+i
)+1;
1109 strncpy(lpTitle
, &lpFile
[i
], len
);
1114 /* ------------------------ Choose Color Dialog --------------------------- */
1116 /***********************************************************************
1117 * ChooseColor (COMMDLG.5)
1119 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
1122 HANDLE16 hDlgTmpl
, hResInfo
;
1125 dprintf_commdlg(stddeb
,"ChooseColor\n");
1126 if (!lpChCol
) return FALSE
;
1127 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpChCol
->hInstance
;
1128 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1130 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
1131 lpChCol
->lpTemplateName
, RT_DIALOG
)))
1133 CommDlgLastError
= CDERR_FINDRESFAILURE
;
1136 hDlgTmpl
= LoadResource16( lpChCol
->hInstance
, hResInfo
);
1138 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR
);
1141 CommDlgLastError
= CDERR_LOADRESFAILURE
;
1144 hInst
= WIN_GetWindowInstance( lpChCol
->hwndOwner
);
1145 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpChCol
->hwndOwner
,
1146 (DLGPROC16
)MODULE_GetWndProcEntry16("ColorDlgProc"),
1148 if (!(lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
))
1150 if (lpChCol
->Flags
& CC_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
1151 else SYSRES_FreeResource( hDlgTmpl
);
1157 static const COLORREF predefcolors
[6][8]=
1159 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
1160 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
1161 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
1162 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
1164 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
1165 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
1166 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
1167 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
1169 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
1170 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
1171 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
1172 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
1177 LPCHOOSECOLOR lpcc
; /* points to public known data structure */
1178 int nextuserdef
; /* next free place in user defined color array */
1179 HDC16 hdcMem
; /* color graph used for BitBlt() */
1180 HBITMAP16 hbmMem
; /* color graph bitmap */
1181 RECT16 fullsize
; /* original dialog window size */
1182 UINT msetrgb
; /* # of SETRGBSTRING message (today not used) */
1183 RECT16 old3angle
; /* last position of l-marker */
1184 RECT16 oldcross
; /* last position of color/satuation marker */
1185 BOOL updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1188 int l
; /* for temporary storing of hue,sat,lum */
1191 /***********************************************************************
1192 * CC_HSLtoRGB [internal]
1194 static int CC_HSLtoRGB(char c
,int hue
,int sat
,int lum
)
1201 case 'R':if (hue
>80) hue
-=80; else hue
+=160; break;
1202 case 'G':if (hue
>160) hue
-=160; else hue
+=80; break;
1207 maxrgb
=(256*MIN(120,lum
))/120; /* 0 .. 256 */
1213 res
=(hue
-80)* maxrgb
; /* 0...10240 */
1214 res
/=40; /* 0...256 */
1221 res
=(240-hue
)* maxrgb
;
1224 res
=res
-maxrgb
/2; /* -128...128 */
1227 res
=maxrgb
/2 + (sat
*res
) /240; /* 0..256 */
1230 if (lum
>120 && res
<256)
1231 res
+=((lum
-120) * (256-res
))/120;
1233 return MIN(res
,255);
1236 /***********************************************************************
1237 * CC_RGBtoHSL [internal]
1239 static int CC_RGBtoHSL(char c
,int r
,int g
,int b
)
1241 WORD maxi
,mini
,mmsum
,mmdif
,result
=0;
1255 case 'L':mmsum
*=120; /* 0...61200=(255+255)*120 */
1256 result
=mmsum
/255; /* 0...240 */
1259 case 'S':if (!mmsum
)
1262 if (!mini
|| maxi
==255)
1266 result
=mmdif
*240; /* 0...61200=255*240 */
1267 result
/= (mmsum
>255 ? mmsum
=510-mmsum
: mmsum
); /* 0..255 */
1271 case 'H':if (!mmdif
)
1277 iresult
=40*(g
-b
); /* -10200 ... 10200 */
1278 iresult
/=(int)mmdif
; /* -40 .. 40 */
1280 iresult
+=240; /* 0..40 and 200..240 */
1286 iresult
/=(int)mmdif
;
1287 iresult
+=80; /* 40 .. 120 */
1293 iresult
/=(int)mmdif
;
1294 iresult
+=160; /* 120 .. 200 */
1300 return result
; /* is this integer arithmetic precise enough ? */
1305 /***********************************************************************
1306 * CC_MouseCheckPredefColorArray [internal]
1308 static int CC_MouseCheckPredefColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1309 LPARAM lParam
,COLORREF
*cr
)
1312 POINT16 point
= MAKEPOINT16(lParam
);
1316 ClientToScreen16(hDlg
,&point
);
1317 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1318 GetWindowRect16(hwnd
,&rect
);
1319 if (PtInRect16(&rect
,point
))
1321 dx
=(rect
.right
-rect
.left
)/cols
;
1322 dy
=(rect
.bottom
-rect
.top
)/rows
;
1323 ScreenToClient16(hwnd
,&point
);
1325 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1329 *cr
=predefcolors
[y
][x
];
1330 /* FIXME: Draw_a_Focus_Rect() */
1337 /***********************************************************************
1338 * CC_MouseCheckUserColorArray [internal]
1340 static int CC_MouseCheckUserColorArray(HWND hDlg
,int dlgitem
,int rows
,int cols
,
1341 LPARAM lParam
,COLORREF
*cr
,COLORREF
*crarr
)
1344 POINT16 point
= MAKEPOINT16(lParam
);
1348 ClientToScreen16(hDlg
,&point
);
1349 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1350 GetWindowRect16(hwnd
,&rect
);
1351 if (PtInRect16(&rect
,point
))
1353 dx
=(rect
.right
-rect
.left
)/cols
;
1354 dy
=(rect
.bottom
-rect
.top
)/rows
;
1355 ScreenToClient16(hwnd
,&point
);
1357 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1361 *cr
=crarr
[x
+cols
*y
];
1362 /* FIXME: Draw_a_Focus_Rect() */
1372 /* 240 ^...... ^^ 240
1379 /***********************************************************************
1380 * CC_MouseCheckColorGraph [internal]
1382 static int CC_MouseCheckColorGraph(HWND hDlg
,int dlgitem
,int *hori
,int *vert
,LPARAM lParam
)
1385 POINT16 point
= MAKEPOINT16(lParam
);
1389 ClientToScreen16(hDlg
,&point
);
1390 hwnd
=GetDlgItem(hDlg
,dlgitem
);
1391 GetWindowRect16(hwnd
,&rect
);
1392 if (PtInRect16(&rect
,point
))
1394 GetClientRect16(hwnd
,&rect
);
1395 ScreenToClient16(hwnd
,&point
);
1397 x
=(long)point
.x
*MAXHORI
;
1399 y
=(long)(rect
.bottom
-point
.y
)*MAXVERT
;
1411 /***********************************************************************
1412 * CC_MouseCheckResultWindow [internal]
1414 static int CC_MouseCheckResultWindow(HWND hDlg
,LPARAM lParam
)
1417 POINT16 point
= MAKEPOINT16(lParam
);
1420 ClientToScreen16(hDlg
,&point
);
1421 hwnd
=GetDlgItem(hDlg
,0x2c5);
1422 GetWindowRect16(hwnd
,&rect
);
1423 if (PtInRect16(&rect
,point
))
1425 PostMessage(hDlg
,WM_COMMAND
,0x2c9,0);
1431 /***********************************************************************
1432 * CC_CheckDigitsInEdit [internal]
1434 static int CC_CheckDigitsInEdit(HWND hwnd
,int maxval
)
1436 int i
,k
,m
,result
,value
;
1439 GetWindowText32A(hwnd
,buffer
,sizeof(buffer
));
1444 if (buffer
[i
]<'0' || buffer
[i
]>'9')
1446 for (k
=i
+1;k
<=m
;k
++) /* delete bad character */
1448 buffer
[i
]=buffer
[k
];
1456 if (value
>maxval
) /* build a new string */
1458 sprintf(buffer
,"%d",maxval
);
1463 editpos
=SendMessage16(hwnd
,EM_GETSEL
,0,0);
1464 SetWindowText32A(hwnd
,buffer
);
1465 SendMessage16(hwnd
,EM_SETSEL
,0,editpos
);
1472 /***********************************************************************
1473 * CC_PaintSelectedColor [internal]
1475 static void CC_PaintSelectedColor(HWND hDlg
,COLORREF cr
)
1480 HWND hwnd
=GetDlgItem(hDlg
,0x2c5);
1481 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1484 GetClientRect16 (hwnd
, &rect
) ;
1485 hBrush
= CreateSolidBrush(cr
);
1488 hBrush
= SelectObject (hdc
, hBrush
) ;
1489 Rectangle (hdc
, rect
.left
,rect
.top
,rect
.right
/2,rect
.bottom
);
1490 DeleteObject (SelectObject (hdc
,hBrush
)) ;
1491 hBrush
=CreateSolidBrush(GetNearestColor(hdc
,cr
));
1494 hBrush
= SelectObject (hdc
, hBrush
) ;
1495 Rectangle (hdc
, rect
.right
/2-1,rect
.top
,rect
.right
,rect
.bottom
);
1496 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1499 ReleaseDC32(hwnd
,hdc
);
1503 /***********************************************************************
1504 * CC_PaintTriangle [internal]
1506 static void CC_PaintTriangle(HWND hDlg
,int y
)
1510 int w
=GetDialogBaseUnits();
1515 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
1516 struct CCPRIVATE
*lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1518 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1520 GetClientRect16(hwnd
,&rect
);
1524 points
[0].y
=rect
.top
;
1525 points
[0].x
=rect
.right
; /* | /| */
1526 ClientToScreen16(hwnd
,points
); /* | / | */
1527 ScreenToClient16(hDlg
,points
); /* |< | */
1528 oben
=points
[0].y
; /* | \ | */
1530 temp
=(long)height
*(long)y
;
1531 points
[0].y
=oben
+height
-temp
/(long)MAXVERT
;
1532 points
[1].y
=points
[0].y
+w
;
1533 points
[2].y
=points
[0].y
-w
;
1534 points
[2].x
=points
[1].x
=points
[0].x
+ w
;
1536 if (lpp
->old3angle
.left
)
1537 FillRect16(hDC
,&lpp
->old3angle
,GetStockObject(WHITE_BRUSH
));
1538 lpp
->old3angle
.left
=points
[0].x
;
1539 lpp
->old3angle
.right
=points
[1].x
+1;
1540 lpp
->old3angle
.top
=points
[2].y
-1;
1541 lpp
->old3angle
.bottom
=points
[1].y
+1;
1542 Polygon16(hDC
,points
,3);
1543 ReleaseDC32(hDlg
,hDC
);
1548 /***********************************************************************
1549 * CC_PaintCross [internal]
1551 static void CC_PaintCross(HWND hDlg
,int x
,int y
)
1554 int w
=GetDialogBaseUnits();
1555 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1556 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1561 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1563 GetClientRect16(hwnd
,&rect
);
1565 SelectClipRgn(hDC
,CreateRectRgnIndirect16(&rect
));
1566 hPen
=CreatePen(PS_SOLID
,2,0);
1567 hPen
=SelectObject(hDC
,hPen
);
1568 point
.x
=((long)rect
.right
*(long)x
)/(long)MAXHORI
;
1569 point
.y
=rect
.bottom
-((long)rect
.bottom
*(long)y
)/(long)MAXVERT
;
1570 if (lpp
->oldcross
.left
!=lpp
->oldcross
.right
)
1571 BitBlt(hDC
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,
1572 lpp
->oldcross
.right
-lpp
->oldcross
.left
,
1573 lpp
->oldcross
.bottom
-lpp
->oldcross
.top
,
1574 lpp
->hdcMem
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,SRCCOPY
);
1575 lpp
->oldcross
.left
=point
.x
-w
-1;
1576 lpp
->oldcross
.right
=point
.x
+w
+1;
1577 lpp
->oldcross
.top
=point
.y
-w
-1;
1578 lpp
->oldcross
.bottom
=point
.y
+w
+1;
1580 MoveTo(hDC
,point
.x
-w
,point
.y
);
1581 LineTo(hDC
,point
.x
+w
,point
.y
);
1582 MoveTo(hDC
,point
.x
,point
.y
-w
);
1583 LineTo(hDC
,point
.x
,point
.y
+w
);
1584 DeleteObject(SelectObject(hDC
,hPen
));
1585 ReleaseDC32(hwnd
,hDC
);
1594 /***********************************************************************
1595 * CC_PrepareColorGraph [internal]
1597 static void CC_PrepareColorGraph(HWND hDlg
)
1599 int sdif
,hdif
,xdif
,ydif
,r
,g
,b
,hue
,sat
;
1600 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1601 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1605 HCURSOR16 hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
1607 GetClientRect16(hwnd
,&client
);
1609 lpp
->hdcMem
= CreateCompatibleDC(hdc
);
1610 lpp
->hbmMem
= CreateCompatibleBitmap(hdc
,client
.right
,client
.bottom
);
1611 SelectObject(lpp
->hdcMem
,lpp
->hbmMem
);
1613 xdif
=client
.right
/XSTEPS
;
1614 ydif
=client
.bottom
/YSTEPS
+1;
1617 for(rect
.left
=hue
=0;hue
<239+hdif
;hue
+=hdif
)
1619 rect
.right
=rect
.left
+xdif
;
1620 rect
.bottom
=client
.bottom
;
1621 for(sat
=0;sat
<240+sdif
;sat
+=sdif
)
1623 rect
.top
=rect
.bottom
-ydif
;
1624 r
=CC_HSLtoRGB('R',hue
,sat
,120);
1625 g
=CC_HSLtoRGB('G',hue
,sat
,120);
1626 b
=CC_HSLtoRGB('B',hue
,sat
,120);
1627 hbrush
=CreateSolidBrush(RGB(r
,g
,b
));
1628 FillRect16(lpp
->hdcMem
,&rect
,hbrush
);
1629 DeleteObject(hbrush
);
1630 rect
.bottom
=rect
.top
;
1632 rect
.left
=rect
.right
;
1634 ReleaseDC32(hwnd
,hdc
);
1638 /***********************************************************************
1639 * CC_PaintColorGraph [internal]
1641 static void CC_PaintColorGraph(HWND hDlg
)
1643 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
1644 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1647 if (IsWindowVisible(hwnd
)) /* if full size */
1650 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
1653 GetClientRect16(hwnd
,&rect
);
1655 BitBlt(hDC
,0,0,rect
.right
,rect
.bottom
,lpp
->hdcMem
,0,0,SRCCOPY
);
1657 fprintf(stderr
,"choose color: hdcMem is not defined\n");
1658 ReleaseDC32(hwnd
,hDC
);
1661 /***********************************************************************
1662 * CC_PaintLumBar [internal]
1664 static void CC_PaintLumBar(HWND hDlg
,int hue
,int sat
)
1666 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
1668 int lum
,ldif
,ydif
,r
,g
,b
;
1672 if (IsWindowVisible(hwnd
))
1675 GetClientRect16(hwnd
,&client
);
1679 ydif
=client
.bottom
/YSTEPS
+1;
1680 for(lum
=0;lum
<240+ldif
;lum
+=ldif
)
1682 rect
.top
=MAX(0,rect
.bottom
-ydif
);
1683 r
=CC_HSLtoRGB('R',hue
,sat
,lum
);
1684 g
=CC_HSLtoRGB('G',hue
,sat
,lum
);
1685 b
=CC_HSLtoRGB('B',hue
,sat
,lum
);
1686 hbrush
=CreateSolidBrush(RGB(r
,g
,b
));
1687 FillRect16(hDC
,&rect
,hbrush
);
1688 DeleteObject(hbrush
);
1689 rect
.bottom
=rect
.top
;
1691 GetClientRect16(hwnd
,&rect
);
1692 FrameRect16(hDC
,&rect
,GetStockObject(BLACK_BRUSH
));
1693 ReleaseDC32(hwnd
,hDC
);
1697 /***********************************************************************
1698 * CC_EditSetRGB [internal]
1700 static void CC_EditSetRGB(HWND hDlg
,COLORREF cr
)
1703 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1704 int r
=GetRValue(cr
);
1705 int g
=GetGValue(cr
);
1706 int b
=GetBValue(cr
);
1707 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1710 sprintf(buffer
,"%d",r
);
1711 SetWindowText32A(GetDlgItem(hDlg
,0x2c2),buffer
);
1712 sprintf(buffer
,"%d",g
);
1713 SetWindowText32A(GetDlgItem(hDlg
,0x2c3),buffer
);
1714 sprintf(buffer
,"%d",b
);
1715 SetWindowText32A(GetDlgItem(hDlg
,0x2c4),buffer
);
1716 lpp
->updating
=FALSE
;
1720 /***********************************************************************
1721 * CC_EditSetHSL [internal]
1723 static void CC_EditSetHSL(HWND hDlg
,int h
,int s
,int l
)
1726 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1728 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
1731 sprintf(buffer
,"%d",h
);
1732 SetWindowText32A(GetDlgItem(hDlg
,0x2bf),buffer
);
1733 sprintf(buffer
,"%d",s
);
1734 SetWindowText32A(GetDlgItem(hDlg
,0x2c0),buffer
);
1735 sprintf(buffer
,"%d",l
);
1736 SetWindowText32A(GetDlgItem(hDlg
,0x2c1),buffer
);
1737 lpp
->updating
=FALSE
;
1739 CC_PaintLumBar(hDlg
,h
,s
);
1742 /***********************************************************************
1743 * CC_SwitchToFullSize [internal]
1745 static void CC_SwitchToFullSize(HWND hDlg
,COLORREF result
,LPRECT16 lprect
)
1748 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1750 EnableWindow(GetDlgItem(hDlg
,0x2cf),FALSE
);
1751 CC_PrepareColorGraph(hDlg
);
1752 for (i
=0x2bf;i
<0x2c5;i
++)
1753 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
1754 for (i
=0x2d3;i
<0x2d9;i
++)
1755 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
1756 EnableWindow(GetDlgItem(hDlg
,0x2c9),TRUE
);
1757 EnableWindow(GetDlgItem(hDlg
,0x2c8),TRUE
);
1760 SetWindowPos(hDlg
,NULL
,0,0,lprect
->right
-lprect
->left
,
1761 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
1763 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_SHOW
);
1764 ShowWindow(GetDlgItem(hDlg
,0x2be),SW_SHOW
);
1765 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_SHOW
);
1767 CC_EditSetRGB(hDlg
,result
);
1768 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1771 /***********************************************************************
1772 * CC_PaintPredefColorArray [internal]
1774 static void CC_PaintPredefColorArray(HWND hDlg
,int rows
,int cols
)
1776 HWND hwnd
=GetDlgItem(hDlg
,0x2d0);
1782 GetClientRect16(hwnd
,&rect
);
1784 dy
=rect
.bottom
/rows
;
1788 GetClientRect16 (hwnd
, &rect
) ;
1790 for (j
=0;j
<rows
;j
++)
1792 for (i
=0;i
<cols
;i
++)
1794 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
1797 hBrush
= SelectObject (hdc
, hBrush
) ;
1798 Rectangle (hdc
, rect
.left
, rect
.top
,
1799 rect
.left
+dx
-DISTANCE
,rect
.top
+dy
-DISTANCE
);
1800 rect
.left
=rect
.left
+dx
;
1801 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1804 rect
.top
=rect
.top
+dy
;
1807 ReleaseDC32(hwnd
,hdc
);
1808 /* FIXME: draw_a_focus_rect */
1810 /***********************************************************************
1811 * CC_PaintUserColorArray [internal]
1813 static void CC_PaintUserColorArray(HWND hDlg
,int rows
,int cols
,COLORREF
* lpcr
)
1815 HWND hwnd
=GetDlgItem(hDlg
,0x2d1);
1821 GetClientRect16(hwnd
,&rect
);
1824 dy
=rect
.bottom
/rows
;
1830 for (j
=0;j
<rows
;j
++)
1832 for (i
=0;i
<cols
;i
++)
1834 hBrush
= CreateSolidBrush(lpcr
[i
+j
*cols
]);
1837 hBrush
= SelectObject (hdc
, hBrush
) ;
1838 Rectangle (hdc
, rect
.left
, rect
.top
,
1839 rect
.left
+dx
-DISTANCE
,rect
.top
+dy
-DISTANCE
);
1840 rect
.left
=rect
.left
+dx
;
1841 DeleteObject (SelectObject (hdc
, hBrush
)) ;
1844 rect
.top
=rect
.top
+dy
;
1847 ReleaseDC32(hwnd
,hdc
);
1849 /* FIXME: draw_a_focus_rect */
1854 /***********************************************************************
1855 * CC_HookCallChk [internal]
1857 static BOOL
CC_HookCallChk(LPCHOOSECOLOR lpcc
)
1860 if(lpcc
->Flags
& CC_ENABLEHOOK
)
1866 /***********************************************************************
1867 * CC_WMInitDialog [internal]
1869 static LONG
CC_WMInitDialog(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
1875 struct CCPRIVATE
* lpp
;
1877 dprintf_commdlg(stddeb
,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1878 lpp
=calloc(1,sizeof(struct CCPRIVATE
));
1879 lpp
->lpcc
=(LPCHOOSECOLOR
)lParam
;
1880 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLOR
))
1882 EndDialog (hDlg
, 0) ;
1885 SetWindowLong32A(hDlg
, DWL_USER
, (LONG
)lpp
);
1887 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
1888 ShowWindow(GetDlgItem(hDlg
,0x40e),SW_HIDE
);
1889 lpp
->msetrgb
=RegisterWindowMessage32A( SETRGBSTRING
);
1891 cpos
=MAKELONG(5,7); /* init */
1892 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
1896 if (predefcolors
[i
][j
]==lpp
->lpcc
->rgbResult
)
1903 /* FIXME: Draw_a_focus_rect & set_init_values */
1905 GetWindowRect16(hDlg
,&lpp
->fullsize
);
1906 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1908 hwnd
=GetDlgItem(hDlg
,0x2cf);
1909 EnableWindow(hwnd
,FALSE
);
1911 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1914 res
=rect
.bottom
-rect
.top
;
1915 hwnd
=GetDlgItem(hDlg
,0x2c6); /* cut at left border */
1917 ClientToScreen16(hwnd
,&point
);
1918 ScreenToClient16(hDlg
,&point
);
1919 GetClientRect16(hDlg
,&rect
);
1920 point
.x
+=GetSystemMetrics(SM_CXDLGFRAME
);
1921 SetWindowPos(hDlg
,NULL
,0,0,point
.x
,res
,SWP_NOMOVE
|SWP_NOZORDER
);
1923 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_HIDE
);
1924 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_HIDE
);
1927 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,NULL
);
1929 for (i
=0x2bf;i
<0x2c5;i
++)
1930 SendMessage16(GetDlgItem(hDlg
,i
),EM_LIMITTEXT
,3,0); /* max 3 digits: xyz */
1931 if (CC_HookCallChk(lpp
->lpcc
))
1932 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1936 /***********************************************************************
1937 * CC_WMCommand [internal]
1939 static LRESULT
CC_WMCommand(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
1945 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1946 dprintf_commdlg(stddeb
,"CC_WMCommand wParam=%x lParam=%lx\n",wParam
,lParam
);
1949 case 0x2c2: /* edit notify RGB */
1952 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1954 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),255);
1955 r
=GetRValue(lpp
->lpcc
->rgbResult
);
1956 g
=GetGValue(lpp
->lpcc
->rgbResult
);
1957 b
=GetBValue(lpp
->lpcc
->rgbResult
);
1961 case 0x2c2:if ((xx
=(i
!=r
))) r
=i
;break;
1962 case 0x2c3:if ((xx
=(i
!=g
))) g
=i
;break;
1963 case 0x2c4:if ((xx
=(i
!=b
))) b
=i
;break;
1965 if (xx
) /* something has changed */
1967 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1968 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1969 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
1970 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
1971 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
1972 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1973 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1974 CC_PaintTriangle(hDlg
,lpp
->l
);
1979 case 0x2bf: /* edit notify HSL */
1982 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1984 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),wParam
==0x2bf?239:240);
1988 case 0x2bf:if ((xx
=(i
!=lpp
->h
))) lpp
->h
=i
;break;
1989 case 0x2c0:if ((xx
=(i
!=lpp
->s
))) lpp
->s
=i
;break;
1990 case 0x2c1:if ((xx
=(i
!=lpp
->l
))) lpp
->l
=i
;break;
1992 if (xx
) /* something has changed */
1994 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
1995 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
1996 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
1997 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1998 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1999 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2000 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2001 CC_PaintTriangle(hDlg
,lpp
->l
);
2007 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,&lpp
->fullsize
);
2008 InvalidateRect32( hDlg
, NULL
, TRUE
);
2009 SetFocus32(GetDlgItem(hDlg
,0x2bf));
2012 case 0x2c8: /* add colors ... column by column */
2013 cr
=PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
);
2014 cr
[(lpp
->nextuserdef
%2)*8 + lpp
->nextuserdef
/2]=lpp
->lpcc
->rgbResult
;
2015 if (++lpp
->nextuserdef
==16)
2017 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2020 case 0x2c9: /* resulting color */
2022 lpp
->lpcc
->rgbResult
=GetNearestColor(hdc
,lpp
->lpcc
->rgbResult
);
2023 ReleaseDC32(hDlg
,hdc
);
2024 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2025 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2026 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2027 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2028 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2029 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2030 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2031 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2032 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2033 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2034 CC_PaintTriangle(hDlg
,lpp
->l
);
2037 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2038 i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2039 if (lpp
->lpcc
->hwndOwner
)
2040 SendMessage16(lpp
->lpcc
->hwndOwner
,i
,0,(LPARAM
)lpp
->lpcc
);
2041 if (CC_HookCallChk(lpp
->lpcc
))
2042 CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,
2043 WM_COMMAND
,psh15
,(LPARAM
)lpp
->lpcc
);
2047 cokmsg
=RegisterWindowMessage32A( COLOROKSTRING
);
2048 if (lpp
->lpcc
->hwndOwner
)
2049 if (SendMessage16(lpp
->lpcc
->hwndOwner
,cokmsg
,0,(LPARAM
)lpp
->lpcc
))
2050 break; /* do NOT close */
2052 EndDialog (hDlg
, 1) ;
2056 EndDialog (hDlg
, 0) ;
2063 /***********************************************************************
2064 * CC_WMPaint [internal]
2066 static LRESULT
CC_WMPaint(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2068 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2069 /* we have to paint dialog children except text and buttons */
2071 CC_PaintPredefColorArray(hDlg
,6,8);
2072 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2073 CC_PaintColorGraph(hDlg
);
2074 CC_PaintLumBar(hDlg
,lpp
->h
,lpp
->s
);
2075 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2076 CC_PaintTriangle(hDlg
,lpp
->l
);
2077 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2079 /* special necessary for Wine */
2080 ValidateRect32(GetDlgItem(hDlg
,0x2d0),NULL
);
2081 ValidateRect32(GetDlgItem(hDlg
,0x2d1),NULL
);
2082 ValidateRect32(GetDlgItem(hDlg
,0x2c6),NULL
);
2083 ValidateRect32(GetDlgItem(hDlg
,0x2be),NULL
);
2084 ValidateRect32(GetDlgItem(hDlg
,0x2c5),NULL
);
2085 /* hope we can remove it later -->FIXME */
2090 /***********************************************************************
2091 * CC_WMLButtonDown [internal]
2093 static LRESULT
CC_WMLButtonDown(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2095 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2098 if (CC_MouseCheckPredefColorArray(hDlg
,0x2d0,6,8,lParam
,&lpp
->lpcc
->rgbResult
))
2101 if (CC_MouseCheckUserColorArray(hDlg
,0x2d1,2,8,lParam
,&lpp
->lpcc
->rgbResult
,
2102 PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
)))
2105 if (CC_MouseCheckColorGraph(hDlg
,0x2c6,&lpp
->h
,&lpp
->s
,lParam
))
2108 if (CC_MouseCheckColorGraph(hDlg
,0x2be,NULL
,&lpp
->l
,lParam
))
2112 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
2113 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
2114 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
2115 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2119 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2120 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2121 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2122 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2123 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2124 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2128 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2129 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2130 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2131 CC_PaintTriangle(hDlg
,lpp
->l
);
2132 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2138 /***********************************************************************
2139 * ColorDlgProc (COMMDLG.8)
2141 LRESULT
ColorDlgProc(HWND hDlg
, UINT message
,
2142 WPARAM16 wParam
, LONG lParam
)
2145 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2146 if (message
!=WM_INITDIALOG
)
2151 if (CC_HookCallChk(lpp
->lpcc
))
2152 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2157 /* FIXME: SetRGB message
2158 if (message && message==msetrgb)
2159 return HandleSetRGB(hDlg,lParam);
2165 return CC_WMInitDialog(hDlg
,wParam
,lParam
);
2167 DeleteDC(lpp
->hdcMem
);
2168 DeleteObject(lpp
->hbmMem
);
2170 SetWindowLong32A(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
2173 if (CC_WMCommand(hDlg
, wParam
, lParam
))
2177 CC_WMPaint(hDlg
, wParam
, lParam
);
2179 case WM_LBUTTONDBLCLK
:
2180 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
2183 case WM_MOUSEMOVE
: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2185 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
2187 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
2188 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
2197 /***********************************************************************
2198 * ChooseFont (COMMDLG.15)
2200 BOOL
ChooseFont(LPCHOOSEFONT lpChFont
)
2203 HANDLE16 hDlgTmpl
, hResInfo
;
2206 dprintf_commdlg(stddeb
,"ChooseFont\n");
2207 if (!lpChFont
) return FALSE
;
2208 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpChFont
->hInstance
;
2209 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
2211 if (!(hResInfo
= FindResource16(lpChFont
->hInstance
,
2212 lpChFont
->lpTemplateName
, RT_DIALOG
)))
2214 CommDlgLastError
= CDERR_FINDRESFAILURE
;
2217 hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
);
2219 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_FONT
);
2222 CommDlgLastError
= CDERR_LOADRESFAILURE
;
2225 hInst
= WIN_GetWindowInstance( lpChFont
->hwndOwner
);
2226 bRet
= DialogBoxIndirectParam16( hInst
, hDlgTmpl
, lpChFont
->hwndOwner
,
2227 (DLGPROC16
)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2229 if (!(lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
))
2231 if (lpChFont
->Flags
& CF_ENABLETEMPLATE
) FreeResource16( hDlgTmpl
);
2232 else SYSRES_FreeResource( hDlgTmpl
);
2238 #define TEXT_EXTRAS 4
2239 #define TEXT_COLORS 16
2241 static const COLORREF textcolors
[TEXT_COLORS
]=
2243 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
2244 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
2245 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
2246 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
2249 /***********************************************************************
2250 * CFn_HookCallChk [internal]
2252 static BOOL
CFn_HookCallChk(LPCHOOSEFONT lpcf
)
2255 if(lpcf
->Flags
& CF_ENABLEHOOK
)
2262 /***********************************************************************
2263 * FontFamilyEnumProc (COMMDLG.19)
2265 INT16
FontFamilyEnumProc( SEGPTR logfont
, SEGPTR metrics
,
2266 UINT16 nFontType
, LPARAM lParam
)
2270 HWND hwnd
=LOWORD(lParam
);
2271 HWND hDlg
=GetParent16(hwnd
);
2272 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2273 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN( logfont
);
2275 dprintf_commdlg(stddeb
,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2276 lplf
->lfFaceName
,nFontType
);
2278 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
2279 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
2281 if (lpcf
->Flags
& CF_ANSIONLY
)
2282 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
2284 if (lpcf
->Flags
& CF_TTONLY
)
2285 if (!(nFontType
& 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2288 i
=SendMessage16(hwnd
,CB_ADDSTRING
,0,
2289 (LPARAM
)logfont
+ ((char *)lplf
->lfFaceName
- (char *)lplf
));
2292 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
2293 SendMessage16(hwnd
, CB_SETITEMDATA
,i
,MAKELONG(nFontType
,w
));
2294 return 1 ; /* store some important font information */
2300 /*************************************************************************
2301 * SetFontStylesToCombo2 [internal]
2303 * Fill font style information into combobox (without using font.c directly)
2305 static int SetFontStylesToCombo2(HWND hwnd
, HDC16 hdc
, LPLOGFONT16 lplf
,
2306 LPTEXTMETRIC16 lptm
)
2313 static struct FONTSTYLE fontstyles
[FSTYLES
]={
2314 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
2315 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
2319 for (i
=0;i
<FSTYLES
;i
++)
2321 lplf
->lfItalic
=fontstyles
[i
].italic
;
2322 lplf
->lfWeight
=fontstyles
[i
].weight
;
2323 hf
=CreateFontIndirect16(lplf
);
2324 hf
=SelectObject(hdc
,hf
);
2325 GetTextMetrics16(hdc
,lptm
);
2326 hf
=SelectObject(hdc
,hf
);
2329 if (lptm
->tmWeight
==fontstyles
[i
].weight
&&
2330 lptm
->tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
2332 char *str
= SEGPTR_STRDUP(fontstyles
[i
].stname
);
2333 j
=SendMessage16(hwnd
,CB_ADDSTRING
,0,(LPARAM
)SEGPTR_GET(str
) );
2335 if (j
==CB_ERR
) return 1;
2336 j
=SendMessage16(hwnd
, CB_SETITEMDATA
, j
,
2337 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
2338 if (j
==CB_ERR
) return 1;
2344 /*************************************************************************
2345 * SetFontSizesToCombo3 [internal]
2347 static int SetFontSizesToCombo3(HWND hwnd
, LPLOGFONT16 lplf
, LPCHOOSEFONT lpcf
)
2349 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2353 if (!(buffer
= SEGPTR_ALLOC(20))) return 1;
2354 for (i
=0;sizes
[i
] && !lplf
->lfHeight
;i
++)
2356 h
=lplf
->lfHeight
? lplf
->lfHeight
: sizes
[i
];
2358 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2359 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
2361 sprintf(buffer
,"%2d",h
);
2362 j
=SendMessage16(hwnd
,CB_FINDSTRING
,-1,(LPARAM
)SEGPTR_GET(buffer
));
2365 j
=SendMessage16(hwnd
,CB_ADDSTRING
,0,(LPARAM
)SEGPTR_GET(buffer
));
2366 if (j
!=CB_ERR
) j
= SendMessage16(hwnd
, CB_SETITEMDATA
, j
, h
);
2369 SEGPTR_FREE(buffer
);
2375 SEGPTR_FREE(buffer
);
2380 /***********************************************************************
2381 * FontStyleEnumProc (COMMDLG.18)
2383 INT16
FontStyleEnumProc( SEGPTR logfont
, SEGPTR metrics
,
2384 UINT16 nFontType
, LPARAM lParam
)
2386 HWND hcmb2
=LOWORD(lParam
);
2387 HWND hcmb3
=HIWORD(lParam
);
2388 HWND hDlg
=GetParent16(hcmb3
);
2389 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2390 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN(logfont
);
2391 TEXTMETRIC16
*lptm
= (TEXTMETRIC16
*)PTR_SEG_TO_LIN(metrics
);
2394 dprintf_commdlg(stddeb
,"FontStyleEnumProc: (nFontType=%d)\n",nFontType
);
2395 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",
2396 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,lplf
->lfEscapement
,lplf
->lfOrientation
,
2397 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,lplf
->lfStrikeOut
,lplf
->lfCharSet
,
2398 lplf
->lfOutPrecision
,lplf
->lfClipPrecision
,lplf
->lfQuality
,lplf
->lfPitchAndFamily
);
2400 if (SetFontSizesToCombo3(hcmb3
, lplf
,lpcf
))
2403 if (!SendMessage16(hcmb2
,CB_GETCOUNT
,0,0))
2405 HDC32 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2406 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
,lptm
);
2407 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2408 ReleaseDC32(hDlg
,hdc
);
2416 /***********************************************************************
2417 * CFn_WMInitDialog [internal]
2419 LRESULT
CFn_WMInitDialog(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2425 HCURSOR16 hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
2428 SetWindowLong32A(hDlg
, DWL_USER
, lParam
);
2429 lpcf
=(LPCHOOSEFONT
)lParam
;
2430 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2431 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
2433 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONT
))
2435 dprintf_commdlg(stddeb
,"WM_INITDIALOG: structure size failure !!!\n");
2436 EndDialog (hDlg
, 0);
2440 hBitmapTT
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2442 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow(lpcf
->hwndOwner
))
2443 ShowWindow(GetDlgItem(hDlg
,pshHelp
),SW_HIDE
);
2444 if (!(lpcf
->Flags
& CF_APPLY
))
2445 ShowWindow(GetDlgItem(hDlg
,psh3
),SW_HIDE
);
2446 if (lpcf
->Flags
& CF_EFFECTS
)
2448 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
2450 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2451 char *name
= SEGPTR_ALLOC(20);
2452 strcpy( name
, "[color name]" );
2453 j
=SendDlgItemMessage16(hDlg
,cmb4
,CB_ADDSTRING
,0,(LPARAM
)SEGPTR_GET(name
));
2455 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETITEMDATA
,j
,textcolors
[j
]);
2456 /* look for a fitting value in color combobox */
2457 if (textcolors
[j
]==lpcf
->rgbColors
)
2458 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETCURSEL
,j
,0);
2463 ShowWindow(GetDlgItem(hDlg
,cmb4
),SW_HIDE
);
2464 ShowWindow(GetDlgItem(hDlg
,chx1
),SW_HIDE
);
2465 ShowWindow(GetDlgItem(hDlg
,chx2
),SW_HIDE
);
2466 ShowWindow(GetDlgItem(hDlg
,grp1
),SW_HIDE
);
2467 ShowWindow(GetDlgItem(hDlg
,stc4
),SW_HIDE
);
2469 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2472 if (!EnumFontFamilies (hdc
, NULL
,FontFamilyEnumProc
,(LPARAM
)GetDlgItem(hDlg
,cmb1
)))
2473 dprintf_commdlg(stddeb
,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2474 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
2476 /* look for fitting font name in combobox1 */
2477 j
=SendDlgItemMessage16(hDlg
,cmb1
,CB_FINDSTRING
,-1,(LONG
)lpxx
->lfFaceName
);
2480 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL
,j
,0);
2481 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
2483 /* look for fitting font style in combobox2 */
2484 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
2485 for (i
=0;i
<TEXT_EXTRAS
;i
++)
2487 if (l
==SendDlgItemMessage16(hDlg
,cmb2
, CB_GETITEMDATA
,i
,0))
2488 SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL
,i
,0);
2491 /* look for fitting font size in combobox3 */
2492 j
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCOUNT
,0,0);
2495 if (lpxx
->lfHeight
==(int)SendDlgItemMessage16(hDlg
,cmb3
, CB_GETITEMDATA
,i
,0))
2496 SendDlgItemMessage16(hDlg
,cmb3
,CB_SETCURSEL
,i
,0);
2501 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL
,0,0);
2502 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,MAKELONG(GetDlgItem(hDlg
,cmb1
),CBN_SELCHANGE
));
2505 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
2507 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_FINDSTRING
,-1,(LONG
)lpcf
->lpszStyle
);
2510 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL
,j
,0);
2511 SendMessage16(hDlg
,WM_COMMAND
,cmb2
,MAKELONG(GetDlgItem(hDlg
,cmb2
),CBN_SELCHANGE
));
2517 dprintf_commdlg(stddeb
,"WM_INITDIALOG: HDC failure !!!\n");
2518 EndDialog (hDlg
, 0);
2522 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2523 ReleaseDC32(hDlg
,hdc
);
2525 if (CFn_HookCallChk(lpcf
))
2526 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
2532 /***********************************************************************
2533 * CFn_WMMeasureItem [internal]
2535 LRESULT
CFn_WMMeasureItem(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2538 LPMEASUREITEMSTRUCT16 lpmi
=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT16
)lParam
);
2540 hBitmapTT
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2541 GetObject16( hBitmapTT
, sizeof(bm
), &bm
);
2542 lpmi
->itemHeight
=bm
.bmHeight
;
2543 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2548 /***********************************************************************
2549 * CFn_WMDrawItem [internal]
2551 LRESULT
CFn_WMDrawItem(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2561 HBITMAP16 hBitmap
; /* for later TT usage */
2563 LPDRAWITEMSTRUCT16 lpdi
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
2565 if (lpdi
->itemID
== 0xFFFF) /* got no items */
2566 DrawFocusRect16(lpdi
->hDC
, &lpdi
->rcItem
);
2569 if (lpdi
->CtlType
== ODT_COMBOBOX
)
2571 hBrush
= SelectObject(lpdi
->hDC
, GetStockObject(LTGRAY_BRUSH
));
2572 SelectObject(lpdi
->hDC
, hBrush
);
2573 FillRect16(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
2576 return TRUE
; /* this should never happen */
2579 buffer
= SEGPTR_ALLOC(40);
2580 switch (lpdi
->CtlID
)
2582 case cmb1
: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2583 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2584 (LPARAM
)SEGPTR_GET(buffer
));
2585 GetObject16( hBitmapTT
, sizeof(bm
), &bm
);
2586 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
2587 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2589 nFontType
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
2590 /* FIXME: draw bitmap if truetype usage */
2591 if (nFontType
&TRUETYPE_FONTTYPE
)
2593 hMemDC
= CreateCompatibleDC(lpdi
->hDC
);
2594 hBitmap
= SelectObject(hMemDC
, hBitmapTT
);
2595 BitBlt(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
2596 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
2597 SelectObject(hMemDC
, hBitmap
);
2603 case cmb3
: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2604 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2605 (LPARAM
)SEGPTR_GET(buffer
));
2606 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
,
2607 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2610 case cmb4
: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2611 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT
, lpdi
->itemID
,
2612 (LPARAM
)SEGPTR_GET(buffer
));
2613 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
2614 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2615 cr
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA
, lpdi
->itemID
,0L);
2616 hBrush
= CreateSolidBrush(cr
);
2619 hBrush
= SelectObject (lpdi
->hDC
, hBrush
) ;
2620 rect
.right
=rect
.left
+25;
2624 Rectangle(lpdi
->hDC
,rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
2625 DeleteObject (SelectObject (lpdi
->hDC
, hBrush
)) ;
2631 default: return TRUE
; /* this should never happen */
2633 SEGPTR_FREE(buffer
);
2634 if (lpdi
->itemState
==ODS_SELECTED
)
2635 InvertRect16(lpdi
->hDC
, &rect
);
2640 /***********************************************************************
2641 * CFn_WMCtlColor [internal]
2643 LRESULT
CFn_WMCtlColor(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2645 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2647 if (lpcf
->Flags
& CF_EFFECTS
)
2648 if (HIWORD(lParam
)==CTLCOLOR_STATIC
&& GetDlgCtrlID(LOWORD(lParam
))==stc6
)
2650 SetTextColor(wParam
,lpcf
->rgbColors
);
2651 return GetStockObject(WHITE_BRUSH
);
2656 /***********************************************************************
2657 * CFn_WMCommand [internal]
2659 LRESULT
CFn_WMCommand(HWND hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2665 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2666 LPLOGFONT16 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2668 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam
);
2671 case cmb1
:if (HIWORD(lParam
)==CBN_SELCHANGE
)
2673 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2676 SendDlgItemMessage16(hDlg
,cmb2
,CB_RESETCONTENT
,0,0);
2677 SendDlgItemMessage16(hDlg
,cmb3
,CB_RESETCONTENT
,0,0);
2678 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
2681 HCURSOR16 hcursor
=SetCursor(LoadCursor16(0,IDC_WAIT
));
2682 char *str
= SEGPTR_ALLOC(256);
2683 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
2684 (LPARAM
)SEGPTR_GET(str
));
2685 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb1 =>%s\n",str
);
2686 EnumFontFamilies(hdc
,str
,FontStyleEnumProc
,
2687 MAKELONG(GetDlgItem(hDlg
,cmb2
),GetDlgItem(hDlg
,cmb3
)));
2691 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2692 ReleaseDC32(hDlg
,hdc
);
2696 dprintf_commdlg(stddeb
,"WM_COMMAND: HDC failure !!!\n");
2697 EndDialog (hDlg
, 0);
2704 case cmb3
:if (HIWORD(lParam
)==CBN_SELCHANGE
|| HIWORD(lParam
)== BN_CLICKED
)
2706 char *str
= SEGPTR_ALLOC(256);
2707 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
2708 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL
,0,0);
2710 i
=GetDlgItemText32A( hDlg
, cmb1
, str
, 256 );
2713 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT
,i
,
2714 (LPARAM
)SEGPTR_GET(str
));
2715 l
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETITEMDATA
,i
,0);
2717 lpcf
->nFontType
= LOWORD(l
);
2718 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2719 /* same value reported to the EnumFonts
2720 call back with the extra FONTTYPE_... bits added */
2721 lpxx
->lfPitchAndFamily
=j
&0xff;
2722 lpxx
->lfCharSet
=j
>>8;
2724 strcpy(lpxx
->lfFaceName
,str
);
2726 i
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETCURSEL
,0,0);
2729 l
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETITEMDATA
,i
,0);
2730 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
2731 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
2732 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
2733 lpcf
->nFontType
|= BOLD_FONTTYPE
;
2735 i
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCURSEL
,0,0);
2737 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessage16(hDlg
,cmb3
,CB_GETITEMDATA
,i
,0));
2740 lpxx
->lfStrikeOut
=IsDlgButtonChecked(hDlg
,chx1
);
2741 lpxx
->lfUnderline
=IsDlgButtonChecked(hDlg
,chx2
);
2742 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
2743 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
2744 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
2745 lpxx
->lfQuality
=DEFAULT_QUALITY
;
2746 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
2748 hFont
=CreateFontIndirect16(lpxx
);
2750 SendDlgItemMessage16(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
2751 /* FIXME: Delete old font ...? */
2755 case cmb4
:i
=SendDlgItemMessage16(hDlg
,cmb4
,CB_GETCURSEL
,0,0);
2758 lpcf
->rgbColors
=textcolors
[i
];
2759 InvalidateRect32( GetDlgItem(hDlg
,stc6
), NULL
, 0 );
2763 case psh15
:i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2764 if (lpcf
->hwndOwner
)
2765 SendMessage16(lpcf
->hwndOwner
,i
,0,(LPARAM
)lpcf
);
2766 if (CFn_HookCallChk(lpcf
))
2767 CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_COMMAND
,psh15
,(LPARAM
)lpcf
);
2770 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2771 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
2772 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
2773 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
2774 EndDialog(hDlg
, TRUE
);
2778 sprintf(buffer
,"Select a font size between %d and %d points.",
2779 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
2780 MessageBox(hDlg
,buffer
,NULL
,MB_OK
);
2783 case IDCANCEL
:EndDialog(hDlg
, FALSE
);
2790 /***********************************************************************
2791 * FormatCharDlgProc (COMMDLG.16)
2792 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2793 2. some CF_.. flags are not supported
2794 3. some TType extensions
2796 LRESULT
FormatCharDlgProc(HWND hDlg
, UINT message
, WPARAM16 wParam
, LPARAM lParam
)
2798 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2799 if (message
!=WM_INITDIALOG
)
2804 if (CFn_HookCallChk(lpcf
))
2805 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2810 return CFn_WMInitDialog(hDlg
,wParam
,lParam
);
2813 case WM_MEASUREITEM
:
2814 return CFn_WMMeasureItem(hDlg
,wParam
,lParam
);
2816 return CFn_WMDrawItem(hDlg
,wParam
,lParam
);
2818 return CFn_WMCtlColor(hDlg
,wParam
,lParam
);
2820 return CFn_WMCommand(hDlg
,wParam
,lParam
);
2821 case WM_CHOOSEFONT_GETLOGFONT
:
2822 dprintf_commdlg(stddeb
,
2823 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam
);
2824 /* FIXME: current logfont back to caller */