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 BOOL32
FileDlg_Init()
37 static BOOL32 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 BOOL16
GetOpenFileName( SEGPTR ofn
)
62 HANDLE16 hDlgTmpl
= 0, hResInfo
;
63 BOOL32 bRet
= FALSE
, win32Format
= FALSE
;
65 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(ofn
);
68 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
70 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
72 if (!(template = LockResource16( lpofn
->hInstance
)))
74 CommDlgLastError
= CDERR_LOADRESFAILURE
;
78 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
80 if (!(hResInfo
= FindResource16(lpofn
->hInstance
,
81 lpofn
->lpTemplateName
, RT_DIALOG
)))
83 CommDlgLastError
= CDERR_FINDRESFAILURE
;
86 if (!(hDlgTmpl
= LoadResource16( lpofn
->hInstance
, hResInfo
)) ||
87 !(template = LockResource16( hDlgTmpl
)))
89 CommDlgLastError
= CDERR_LOADRESFAILURE
;
95 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE
);
99 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
100 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
102 (DLGPROC16
)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
104 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpofn
->hwndOwner
);
106 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
108 dprintf_commdlg(stddeb
,"GetOpenFileName // return lpstrFile='%s' !\n",
109 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
114 /***********************************************************************
115 * GetSaveFileName (COMMDLG.2)
117 BOOL16
GetSaveFileName( SEGPTR ofn
)
120 HANDLE16 hDlgTmpl
= 0;
121 BOOL32 bRet
= FALSE
, win32Format
= FALSE
;
122 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(ofn
);
126 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
128 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
130 if (!(template = LockResource16( lpofn
->hInstance
)))
132 CommDlgLastError
= CDERR_LOADRESFAILURE
;
136 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
139 if (!(hResInfo
= FindResource16(lpofn
->hInstance
,
140 lpofn
->lpTemplateName
, RT_DIALOG
)))
142 CommDlgLastError
= CDERR_FINDRESFAILURE
;
145 if (!(hDlgTmpl
= LoadResource16( lpofn
->hInstance
, hResInfo
)) ||
146 !(template = LockResource16( hDlgTmpl
)))
148 CommDlgLastError
= CDERR_LOADRESFAILURE
;
154 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE
);
158 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
160 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
162 (DLGPROC16
)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
164 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpofn
->hwndOwner
);
166 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
168 dprintf_commdlg(stddeb
, "GetSaveFileName // return lpstrFile='%s' !\n",
169 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
173 /***********************************************************************
174 * FILEDLG_StripEditControl [internal]
175 * Strip pathnames off the contents of the edit control.
177 static void FILEDLG_StripEditControl(HWND16 hwnd
)
181 GetDlgItemText32A( hwnd
, edt1
, temp
, sizeof(temp
) );
182 cp
= strrchr(temp
, '\\');
186 cp
= strrchr(temp
, ':');
190 /* FIXME: shouldn't we do something with the result here? ;-) */
193 /***********************************************************************
194 * FILEDLG_ScanDir [internal]
196 static BOOL32
FILEDLG_ScanDir(HWND16 hWnd
, LPSTR newPath
)
201 lstrcpyn32A( str
, newPath
, 512 );
203 GetDlgItemText32A( hWnd
, edt1
, str
+ len
, sizeof(str
) - len
);
204 if (!DlgDirList32A( hWnd
, str
, lst1
, 0, 0x0000 )) return FALSE
;
205 return DlgDirList32A( hWnd
, "*.*", lst2
, stc1
, 0x8010 );
208 /***********************************************************************
209 * FILEDLG_GetFileType [internal]
212 static LPSTR
FILEDLG_GetFileType(LPSTR cfptr
, LPSTR fptr
, WORD index
)
217 for ( ;(n
= strlen(cfptr
)) != 0; i
++)
222 cfptr
+= strlen(cfptr
) + 1;
225 for ( ;(n
= strlen(fptr
)) != 0; i
++)
230 fptr
+= strlen(fptr
) + 1;
235 /***********************************************************************
236 * FILEDLG_WMDrawItem [internal]
238 static LONG
FILEDLG_WMDrawItem(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
,int savedlg
)
240 LPDRAWITEMSTRUCT16 lpdis
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
243 HBITMAP16 hBitmap
, hPrevBitmap
;
247 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
249 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
250 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
251 SelectObject32(lpdis
->hDC
, hBrush
);
252 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
253 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT16
, lpdis
->itemID
,
254 (LPARAM
)SEGPTR_GET(str
));
256 if (savedlg
) /* use _gray_ text in FileSaveDlg */
257 if (!lpdis
->itemState
)
258 SetTextColor32(lpdis
->hDC
,GetSysColor32(COLOR_GRAYTEXT
) );
260 SetTextColor32(lpdis
->hDC
,GetSysColor32(COLOR_WINDOWTEXT
) );
261 /* inversion of gray would be bad readable */
263 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
265 if (lpdis
->itemState
!= 0) {
266 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
272 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
274 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
275 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
276 SelectObject32(lpdis
->hDC
, hBrush
);
277 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
278 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT16
, lpdis
->itemID
,
279 (LPARAM
)SEGPTR_GET(str
));
282 GetObject16( hBitmap
, sizeof(bm
), &bm
);
283 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
284 lpdis
->rcItem
.top
, str
, strlen(str
));
285 hMemDC
= CreateCompatibleDC32(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
);
295 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
297 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
298 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
299 SelectObject32(lpdis
->hDC
, hBrush
);
300 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
301 SendMessage16(lpdis
->hwndItem
, CB_GETLBTEXT16
, lpdis
->itemID
,
302 (LPARAM
)SEGPTR_GET(str
));
303 switch(DRIVE_GetType( str
[2] - 'a' ))
305 case TYPE_FLOPPY
: hBitmap
= hFloppy
; break;
306 case TYPE_CDROM
: hBitmap
= hCDRom
; break;
309 default: hBitmap
= hHDisk
; break;
311 GetObject16( hBitmap
, sizeof(bm
), &bm
);
312 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
313 lpdis
->rcItem
.top
, str
, strlen(str
));
314 hMemDC
= CreateCompatibleDC32(lpdis
->hDC
);
315 hPrevBitmap
= SelectObject32(hMemDC
, hBitmap
);
316 BitBlt32( lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
317 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
318 SelectObject32(hMemDC
, hPrevBitmap
);
320 if (lpdis
->itemState
!= 0) InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
327 /***********************************************************************
328 * FILEDLG_WMMeasureItem [internal]
330 static LONG
FILEDLG_WMMeasureItem(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
333 LPMEASUREITEMSTRUCT16 lpmeasure
;
335 GetObject16( hFolder2
, sizeof(bm
), &bm
);
336 lpmeasure
= (LPMEASUREITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
337 lpmeasure
->itemHeight
= bm
.bmHeight
;
341 /***********************************************************************
342 * FILEDLG_HookCallChk [internal]
344 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn
)
347 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
353 /***********************************************************************
354 * FILEDLG_WMInitDialog [internal]
357 static LONG
FILEDLG_WMInitDialog(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
360 LPOPENFILENAME lpofn
;
363 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
364 lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(lParam
);
365 if (lpofn
->lpstrTitle
) SetWindowText16( hWnd
, lpofn
->lpstrTitle
);
366 /* read custom filter information */
367 if (lpofn
->lpstrCustomFilter
)
369 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
);
371 dprintf_commdlg(stddeb
,"lpstrCustomFilter = %p\n", pstr
);
374 dprintf_commdlg(stddeb
,"lpstrCustomFilter // add str='%s' ",pstr
);
375 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING16
, 0,
376 (LPARAM
)lpofn
->lpstrCustomFilter
+ n
);
377 n
+= strlen(pstr
) + 1;
378 pstr
+= strlen(pstr
) + 1;
379 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
380 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA16
, i
, (LPARAM
)pstr
);
381 n
+= strlen(pstr
) + 1;
382 pstr
+= strlen(pstr
) + 1;
385 /* read filter information */
386 if (lpofn
->lpstrFilter
) {
387 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
390 dprintf_commdlg(stddeb
,"lpstrFilter // add str='%s' ", pstr
);
391 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING16
, 0,
392 (LPARAM
)lpofn
->lpstrFilter
+ n
);
393 n
+= strlen(pstr
) + 1;
394 pstr
+= strlen(pstr
) + 1;
395 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
396 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA16
, i
, (LPARAM
)pstr
);
397 n
+= strlen(pstr
) + 1;
398 pstr
+= strlen(pstr
) + 1;
401 /* set default filter */
402 if (lpofn
->nFilterIndex
== 0 && lpofn
->lpstrCustomFilter
== (SEGPTR
)NULL
)
403 lpofn
->nFilterIndex
= 1;
404 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETCURSEL16
, lpofn
->nFilterIndex
- 1, 0);
405 strncpy(tmpstr
, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
406 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lpofn
->nFilterIndex
- 1),511);
408 dprintf_commdlg(stddeb
,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
409 lpofn
->nFilterIndex
, tmpstr
);
410 SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
412 DlgDirListComboBox32A(hWnd
, "", cmb2
, 0, 0xC000);
413 /* read initial directory */
414 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
)
416 strncpy(tmpstr
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
), 510);
418 if (strlen(tmpstr
) > 0 && tmpstr
[strlen(tmpstr
)-1] != '\\'
419 && tmpstr
[strlen(tmpstr
)-1] != ':')
424 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
425 fprintf(stderr
, "FileDlg: couldn't read initial directory %s!\n", tmpstr
);
426 /* select current drive in combo 2 */
427 n
= DRIVE_GetCurrentDrive();
428 SendDlgItemMessage16(hWnd
, cmb2
, CB_SETCURSEL16
, n
, 0);
429 if (!(lpofn
->Flags
& OFN_SHOWHELP
))
430 ShowWindow32(GetDlgItem32(hWnd
, pshHelp
), SW_HIDE
);
431 if (lpofn
->Flags
& OFN_HIDEREADONLY
)
432 ShowWindow32(GetDlgItem32(hWnd
, chx1
), SW_HIDE
);
433 if (FILEDLG_HookCallChk(lpofn
))
434 return (BOOL16
)CallWindowProc16(lpofn
->lpfnHook
,
435 hWnd
, WM_INITDIALOG
, wParam
, lParam
);
440 /***********************************************************************
441 * FILEDLG_WMCommand [internal]
443 static LRESULT
FILEDLG_WMCommand(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
446 LPOPENFILENAME lpofn
;
448 char tmpstr
[512], tmpstr2
[512];
450 UINT16 control
,notification
;
452 /* Notifications are packaged differently in Win32 */
454 notification
= HIWORD(lParam
);
456 lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
459 case lst1
: /* file list */
460 FILEDLG_StripEditControl(hWnd
);
461 if (notification
== LBN_DBLCLK
)
463 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
464 if (lRet
== LB_ERR
) return TRUE
;
465 if ((pstr
= SEGPTR_ALLOC(512)))
467 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT16
, lRet
,
468 (LPARAM
)SEGPTR_GET(pstr
));
469 SetDlgItemText32A( hWnd
, edt1
, pstr
);
472 if (FILEDLG_HookCallChk(lpofn
))
473 CallWindowProc16(lpofn
->lpfnHook
, hWnd
,
474 RegisterWindowMessage32A( LBSELCHSTRING
),
475 control
, MAKELONG(lRet
,CD_LBSELCHANGE
));
476 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
478 case lst2
: /* directory list */
479 FILEDLG_StripEditControl(hWnd
);
480 if (notification
== LBN_DBLCLK
)
482 lRet
= SendDlgItemMessage16(hWnd
, lst2
, LB_GETCURSEL16
, 0, 0);
483 if (lRet
== LB_ERR
) return TRUE
;
484 pstr
= SEGPTR_ALLOC(512);
485 SendDlgItemMessage16(hWnd
, lst2
, LB_GETTEXT16
, lRet
,
486 (LPARAM
)SEGPTR_GET(pstr
));
487 strcpy( tmpstr
, pstr
);
489 if (tmpstr
[0] == '[')
491 tmpstr
[strlen(tmpstr
) - 1] = 0;
492 strcpy(tmpstr
,tmpstr
+1);
494 strcat(tmpstr
, "\\");
498 case cmb1
: /* file type drop list */
499 if (notification
== CBN_SELCHANGE
)
505 case cmb2
: /* disk drop list */
506 FILEDLG_StripEditControl(hWnd
);
507 lRet
= SendDlgItemMessage16(hWnd
, cmb2
, CB_GETCURSEL16
, 0, 0L);
508 if (lRet
== LB_ERR
) return 0;
509 pstr
= SEGPTR_ALLOC(512);
510 SendDlgItemMessage16(hWnd
, cmb2
, CB_GETLBTEXT16
, lRet
,
511 (LPARAM
)SEGPTR_GET(pstr
));
512 sprintf(tmpstr
, "%c:", pstr
[2]);
515 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL16
, 0, 0);
518 pstr
= (LPSTR
)SendDlgItemMessage16(hWnd
, cmb1
, CB_GETITEMDATA16
, lRet
, 0);
519 dprintf_commdlg(stddeb
,"Selected filter : %s\n", pstr
);
520 SetDlgItemText32A( hWnd
, edt1
, pstr
);
521 FILEDLG_ScanDir(hWnd
, tmpstr
);
529 ofn2
=*lpofn
; /* for later restoring */
530 GetDlgItemText32A( hWnd
, edt1
, tmpstr
, sizeof(tmpstr
) );
531 pstr
= strrchr(tmpstr
, '\\');
533 pstr
= strrchr(tmpstr
, ':');
534 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
536 /* edit control contains wildcards */
539 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
544 strcpy(tmpstr2
, tmpstr
);
547 dprintf_commdlg(stddeb
,"commdlg: %s, %s\n", tmpstr
, tmpstr2
);
548 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
549 FILEDLG_ScanDir(hWnd
, tmpstr
);
552 /* no wildcards, we might have a directory or a filename */
553 /* try appending a wildcard and reading the directory */
554 pstr2
= tmpstr
+ strlen(tmpstr
);
555 if (pstr
== NULL
|| *(pstr
+1) != 0)
556 strcat(tmpstr
, "\\");
557 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL16
, 0, 0);
558 if (lRet
== LB_ERR
) return TRUE
;
559 lpofn
->nFilterIndex
= lRet
+ 1;
560 dprintf_commdlg(stddeb
,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn
->nFilterIndex
);
562 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
563 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
564 lRet
), sizeof(tmpstr2
));
565 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
566 /* if ScanDir succeeds, we have changed the directory */
567 if (FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
568 /* if not, this must be a filename */
572 /* strip off the pathname */
574 SetDlgItemText32A( hWnd
, edt1
, pstr
+ 1 );
575 lstrcpyn32A(tmpstr2
, pstr
+1, sizeof(tmpstr2
) );
576 /* Should we MessageBox() if this fails? */
577 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
578 strcpy(tmpstr
, tmpstr2
);
580 else SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
582 ShowWindow16(hWnd
, SW_HIDE
); /* this should not be necessary ?! (%%%) */
585 int drive
= DRIVE_GetCurrentDrive();
586 tmpstr2
[0] = 'A'+ drive
;
589 strncpy(tmpstr2
+ 3, DRIVE_GetDosCwd(drive
), 507); tmpstr2
[510]=0;
590 if (strlen(tmpstr2
) > 3)
591 strcat(tmpstr2
, "\\");
592 strncat(tmpstr2
, tmpstr
, 511-strlen(tmpstr2
)); tmpstr2
[511]=0;
593 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), tmpstr2
);
595 lpofn
->nFileOffset
= 0;
596 lpofn
->nFileExtension
= 0;
597 while(tmpstr2
[lpofn
->nFileExtension
] != '.' && tmpstr2
[lpofn
->nFileExtension
] != '\0')
598 lpofn
->nFileExtension
++;
599 if (lpofn
->nFileExtension
== '\0')
600 lpofn
->nFileExtension
= 0;
602 lpofn
->nFileExtension
++;
603 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
)
605 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
606 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT16
, lRet
,
607 lpofn
->lpstrFileTitle
);
609 if (FILEDLG_HookCallChk(lpofn
))
611 lRet
= (BOOL16
)CallWindowProc16(lpofn
->lpfnHook
,
612 hWnd
, RegisterWindowMessage32A( FILEOKSTRING
), 0, lParam
);
615 *lpofn
=ofn2
; /* restore old state */
617 ShowWindow16(hWnd
, SW_SHOW
); /* only if above (%%%) SW_HIDE used */
622 EndDialog32(hWnd
, TRUE
);
625 EndDialog32(hWnd
, FALSE
);
632 /***********************************************************************
633 * FileOpenDlgProc (COMMDLG.6)
635 LRESULT
FileOpenDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
, LPARAM lParam
)
637 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
639 if (wMsg
!=WM_INITDIALOG
)
640 if (FILEDLG_HookCallChk(lpofn
))
642 LRESULT lRet
=(BOOL16
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
644 return lRet
; /* else continue message processing */
649 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
651 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
653 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
);
655 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
658 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
659 switch (HIWORD(lParam
))
662 SetTextColor((HDC16
)wParam
, 0x00000000);
664 case CTLCOLOR_STATIC
:
665 SetTextColor((HDC16
)wParam
, 0x00000000);
675 /***********************************************************************
676 * FileSaveDlgProc (COMMDLG.7)
678 LRESULT
FileSaveDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
, LPARAM lParam
)
680 LPOPENFILENAME lpofn
= (LPOPENFILENAME
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
682 if (wMsg
!=WM_INITDIALOG
)
683 if (FILEDLG_HookCallChk(lpofn
))
685 LRESULT lRet
=(BOOL16
)CallWindowProc16(lpofn
->lpfnHook
, hWnd
, wMsg
, wParam
, lParam
);
687 return lRet
; /* else continue message processing */
691 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
694 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
697 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
);
700 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
705 SetBkColor((HDC16)wParam, 0x00C0C0C0);
706 switch (HIWORD(lParam))
709 SetTextColor((HDC16)wParam, 0x00000000);
711 case CTLCOLOR_STATIC:
712 SetTextColor((HDC16)wParam, 0x00000000);
722 /***********************************************************************
723 * FindTextDlg (COMMDLG.11)
725 HWND16
FindText( SEGPTR find
)
729 LPFINDREPLACE lpFind
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(find
);
732 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
733 * For now, only the standard dialog works.
736 * FIXME : We should do error checking on the lpFind structure here
737 * and make CommDlgExtendedError() return the error condition.
739 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT
);
740 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
741 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
742 (DLGPROC16
)MODULE_GetWndProcEntry16("FindTextDlgProc"),
747 /***********************************************************************
748 * ReplaceText (COMMDLG.12)
750 HWND16
ReplaceText( SEGPTR find
)
754 LPFINDREPLACE lpFind
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(find
);
757 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
758 * For now, only the standard dialog works.
761 * FIXME : We should do error checking on the lpFind structure here
762 * and make CommDlgExtendedError() return the error condition.
764 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT
);
765 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
766 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
767 (DLGPROC16
)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
772 /***********************************************************************
773 * FINDDLG_WMInitDialog [internal]
775 static LRESULT
FINDDLG_WMInitDialog(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
779 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
780 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(lParam
);
781 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
783 * FIXME : If the initial FindWhat string is empty, we should disable the
784 * FindNext (IDOK) button. Only after typing some text, the button should be
787 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
788 CheckRadioButton32(hWnd
, rad1
, rad2
, (lpfr
->Flags
& FR_DOWN
) ? rad2
: rad1
);
789 if (lpfr
->Flags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
790 EnableWindow32(GetDlgItem32(hWnd
, rad1
), FALSE
);
791 EnableWindow32(GetDlgItem32(hWnd
, rad2
), FALSE
);
793 if (lpfr
->Flags
& FR_HIDEUPDOWN
) {
794 ShowWindow32(GetDlgItem32(hWnd
, rad1
), SW_HIDE
);
795 ShowWindow32(GetDlgItem32(hWnd
, rad2
), SW_HIDE
);
796 ShowWindow32(GetDlgItem32(hWnd
, grp1
), SW_HIDE
);
798 CheckDlgButton32(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
799 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
800 EnableWindow32(GetDlgItem32(hWnd
, chx1
), FALSE
);
801 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
802 ShowWindow32(GetDlgItem32(hWnd
, chx1
), SW_HIDE
);
803 CheckDlgButton32(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
804 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
805 EnableWindow32(GetDlgItem32(hWnd
, chx2
), FALSE
);
806 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
807 ShowWindow32(GetDlgItem32(hWnd
, chx2
), SW_HIDE
);
808 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
809 EnableWindow32(GetDlgItem32(hWnd
, pshHelp
), FALSE
);
810 ShowWindow32(GetDlgItem32(hWnd
, pshHelp
), SW_HIDE
);
812 ShowWindow32(hWnd
, SW_SHOWNORMAL
);
817 /***********************************************************************
818 * FINDDLG_WMCommand [internal]
820 static LRESULT
FINDDLG_WMCommand(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
823 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
824 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
826 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
829 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
830 if (IsDlgButtonChecked32(hWnd
, rad2
))
831 lpfr
->Flags
|= FR_DOWN
;
832 else lpfr
->Flags
&= ~FR_DOWN
;
833 if (IsDlgButtonChecked32(hWnd
, chx1
))
834 lpfr
->Flags
|= FR_WHOLEWORD
;
835 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
836 if (IsDlgButtonChecked32(hWnd
, chx2
))
837 lpfr
->Flags
|= FR_MATCHCASE
;
838 else lpfr
->Flags
&= ~FR_MATCHCASE
;
839 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
840 lpfr
->Flags
|= FR_FINDNEXT
;
841 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
842 GetWindowLong32A(hWnd
, DWL_USER
) );
845 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
846 lpfr
->Flags
|= FR_DIALOGTERM
;
847 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
848 GetWindowLong32A(hWnd
, DWL_USER
) );
849 DestroyWindow16(hWnd
);
852 /* FIXME : should lpfr structure be passed as an argument ??? */
853 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
860 /***********************************************************************
861 * FindTextDlgProc (COMMDLG.13)
863 LRESULT
FindTextDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
, LPARAM lParam
)
867 return FINDDLG_WMInitDialog(hWnd
, wParam
, lParam
);
869 return FINDDLG_WMCommand(hWnd
, wParam
, lParam
);
875 /***********************************************************************
876 * REPLACEDLG_WMInitDialog [internal]
878 static LRESULT
REPLACEDLG_WMInitDialog(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
882 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
883 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(lParam
);
884 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
886 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
887 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
890 SetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
);
891 SetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
);
892 CheckDlgButton32(hWnd
, chx1
, (lpfr
->Flags
& FR_WHOLEWORD
) ? 1 : 0);
893 if (lpfr
->Flags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
894 EnableWindow32(GetDlgItem32(hWnd
, chx1
), FALSE
);
895 if (lpfr
->Flags
& FR_HIDEWHOLEWORD
)
896 ShowWindow32(GetDlgItem32(hWnd
, chx1
), SW_HIDE
);
897 CheckDlgButton32(hWnd
, chx2
, (lpfr
->Flags
& FR_MATCHCASE
) ? 1 : 0);
898 if (lpfr
->Flags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
899 EnableWindow32(GetDlgItem32(hWnd
, chx2
), FALSE
);
900 if (lpfr
->Flags
& FR_HIDEMATCHCASE
)
901 ShowWindow32(GetDlgItem32(hWnd
, chx2
), SW_HIDE
);
902 if (!(lpfr
->Flags
& FR_SHOWHELP
)) {
903 EnableWindow32(GetDlgItem32(hWnd
, pshHelp
), FALSE
);
904 ShowWindow32(GetDlgItem32(hWnd
, pshHelp
), SW_HIDE
);
906 ShowWindow32(hWnd
, SW_SHOWNORMAL
);
911 /***********************************************************************
912 * REPLACEDLG_WMCommand [internal]
914 static LRESULT
REPLACEDLG_WMCommand(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
917 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
918 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
920 lpfr
= (LPFINDREPLACE
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
923 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
924 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
925 if (IsDlgButtonChecked32(hWnd
, chx1
))
926 lpfr
->Flags
|= FR_WHOLEWORD
;
927 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
928 if (IsDlgButtonChecked32(hWnd
, chx2
))
929 lpfr
->Flags
|= FR_MATCHCASE
;
930 else lpfr
->Flags
&= ~FR_MATCHCASE
;
931 lpfr
->Flags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
932 lpfr
->Flags
|= FR_FINDNEXT
;
933 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
934 GetWindowLong32A(hWnd
, DWL_USER
) );
937 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
938 lpfr
->Flags
|= FR_DIALOGTERM
;
939 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
940 GetWindowLong32A(hWnd
, DWL_USER
) );
941 DestroyWindow16(hWnd
);
944 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
945 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
946 if (IsDlgButtonChecked32(hWnd
, chx1
))
947 lpfr
->Flags
|= FR_WHOLEWORD
;
948 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
949 if (IsDlgButtonChecked32(hWnd
, chx2
))
950 lpfr
->Flags
|= FR_MATCHCASE
;
951 else lpfr
->Flags
&= ~FR_MATCHCASE
;
952 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
953 lpfr
->Flags
|= FR_REPLACE
;
954 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
955 GetWindowLong32A(hWnd
, DWL_USER
) );
958 GetDlgItemText16(hWnd
, edt1
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
);
959 GetDlgItemText16(hWnd
, edt2
, lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
);
960 if (IsDlgButtonChecked32(hWnd
, chx1
))
961 lpfr
->Flags
|= FR_WHOLEWORD
;
962 else lpfr
->Flags
&= ~FR_WHOLEWORD
;
963 if (IsDlgButtonChecked32(hWnd
, chx2
))
964 lpfr
->Flags
|= FR_MATCHCASE
;
965 else lpfr
->Flags
&= ~FR_MATCHCASE
;
966 lpfr
->Flags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
967 lpfr
->Flags
|= FR_REPLACEALL
;
968 SendMessage16(lpfr
->hwndOwner
, uFindReplaceMessage
, 0,
969 GetWindowLong32A(hWnd
, DWL_USER
) );
972 /* FIXME : should lpfr structure be passed as an argument ??? */
973 SendMessage16(lpfr
->hwndOwner
, uHelpMessage
, 0, 0);
980 /***********************************************************************
981 * ReplaceTextDlgProc (COMMDLG.14)
983 LRESULT
ReplaceTextDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
, LPARAM lParam
)
987 return REPLACEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
989 return REPLACEDLG_WMCommand(hWnd
, wParam
, lParam
);
995 /***********************************************************************
996 * PrintDlg (COMMDLG.20)
998 BOOL16
PrintDlg( SEGPTR printdlg
)
1001 BOOL16 bRet
= FALSE
;
1004 LPPRINTDLG lpPrint
= (LPPRINTDLG
)PTR_SEG_TO_LIN(printdlg
);
1006 dprintf_commdlg(stddeb
,"PrintDlg(%p) // Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
1008 if (lpPrint
->Flags
& PD_RETURNDEFAULT
)
1009 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1012 if (lpPrint
->Flags
& PD_PRINTSETUP
)
1013 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP
);
1015 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT
);
1017 hInst
= WIN_GetWindowInstance( lpPrint
->hwndOwner
);
1018 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, TRUE
,
1020 (DLGPROC16
)((lpPrint
->Flags
& PD_PRINTSETUP
) ?
1021 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1022 MODULE_GetWndProcEntry16("PrintDlgProc")),
1023 printdlg
, WIN_PROC_16
);
1024 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpPrint
->hwndOwner
);
1029 /***********************************************************************
1030 * PrintDlgProc (COMMDLG.21)
1032 LRESULT
PrintDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
, LPARAM lParam
)
1037 dprintf_commdlg(stddeb
,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1038 ShowWindow16(hWnd
, SW_SHOWNORMAL
);
1044 EndDialog32(hWnd
, TRUE
);
1047 EndDialog32(hWnd
, FALSE
);
1056 /***********************************************************************
1057 * PrintSetupDlgProc (COMMDLG.22)
1059 LRESULT
PrintSetupDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
, LPARAM lParam
)
1064 dprintf_commdlg(stddeb
,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1065 ShowWindow16(hWnd
, SW_SHOWNORMAL
);
1070 EndDialog32(hWnd
, TRUE
);
1073 EndDialog32(hWnd
, FALSE
);
1082 /***********************************************************************
1083 * CommDlgExtendedError (COMMDLG.26)
1085 DWORD
CommDlgExtendedError(void)
1087 return CommDlgLastError
;
1091 /***********************************************************************
1092 * GetFileTitle (COMMDLG.27)
1094 short GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT16 cbBuf
)
1097 dprintf_commdlg(stddeb
,"GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
1098 if (lpFile
== NULL
|| lpTitle
== NULL
)
1100 len
= strlen(lpFile
);
1103 if (strpbrk(lpFile
, "*[]"))
1106 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
1108 for (i
= len
; i
>= 0; i
--)
1109 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
1114 dprintf_commdlg(stddeb
,"\n---> '%s' ", &lpFile
[i
]);
1116 len
= strlen(lpFile
+i
)+1;
1120 strncpy(lpTitle
, &lpFile
[i
], len
);
1125 /* ------------------------ Choose Color Dialog --------------------------- */
1127 /***********************************************************************
1128 * ChooseColor (COMMDLG.5)
1130 BOOL16
ChooseColor(LPCHOOSECOLOR lpChCol
)
1133 HANDLE16 hDlgTmpl
= 0;
1134 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
1138 dprintf_commdlg(stddeb
,"ChooseColor\n");
1139 if (!lpChCol
) return FALSE
;
1141 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1143 if (!(template = LockResource16( lpChCol
->hInstance
)))
1145 CommDlgLastError
= CDERR_LOADRESFAILURE
;
1149 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1152 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
1153 lpChCol
->lpTemplateName
, RT_DIALOG
)))
1155 CommDlgLastError
= CDERR_FINDRESFAILURE
;
1158 if (!(hDlgTmpl
= LoadResource16( lpChCol
->hInstance
, hResInfo
)) ||
1159 !(template = LockResource16( hDlgTmpl
)))
1161 CommDlgLastError
= CDERR_LOADRESFAILURE
;
1167 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR
);
1171 hInst
= WIN_GetWindowInstance( lpChCol
->hwndOwner
);
1172 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
1174 (DLGPROC16
)MODULE_GetWndProcEntry16("ColorDlgProc"),
1175 (DWORD
)lpChCol
, WIN_PROC_16
);
1176 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpChCol
->hwndOwner
);
1177 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
1182 static const COLORREF predefcolors
[6][8]=
1184 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
1185 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
1186 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
1187 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
1189 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
1190 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
1191 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
1192 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
1194 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
1195 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
1196 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
1197 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
1202 LPCHOOSECOLOR lpcc
; /* points to public known data structure */
1203 int nextuserdef
; /* next free place in user defined color array */
1204 HDC16 hdcMem
; /* color graph used for BitBlt() */
1205 HBITMAP16 hbmMem
; /* color graph bitmap */
1206 RECT16 fullsize
; /* original dialog window size */
1207 UINT16 msetrgb
; /* # of SETRGBSTRING message (today not used) */
1208 RECT16 old3angle
; /* last position of l-marker */
1209 RECT16 oldcross
; /* last position of color/satuation marker */
1210 BOOL32 updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1213 int l
; /* for temporary storing of hue,sat,lum */
1216 /***********************************************************************
1217 * CC_HSLtoRGB [internal]
1219 static int CC_HSLtoRGB(char c
,int hue
,int sat
,int lum
)
1226 case 'R':if (hue
>80) hue
-=80; else hue
+=160; break;
1227 case 'G':if (hue
>160) hue
-=160; else hue
+=80; break;
1232 maxrgb
=(256*MIN(120,lum
))/120; /* 0 .. 256 */
1238 res
=(hue
-80)* maxrgb
; /* 0...10240 */
1239 res
/=40; /* 0...256 */
1246 res
=(240-hue
)* maxrgb
;
1249 res
=res
-maxrgb
/2; /* -128...128 */
1252 res
=maxrgb
/2 + (sat
*res
) /240; /* 0..256 */
1255 if (lum
>120 && res
<256)
1256 res
+=((lum
-120) * (256-res
))/120;
1258 return MIN(res
,255);
1261 /***********************************************************************
1262 * CC_RGBtoHSL [internal]
1264 static int CC_RGBtoHSL(char c
,int r
,int g
,int b
)
1266 WORD maxi
,mini
,mmsum
,mmdif
,result
=0;
1280 case 'L':mmsum
*=120; /* 0...61200=(255+255)*120 */
1281 result
=mmsum
/255; /* 0...240 */
1284 case 'S':if (!mmsum
)
1287 if (!mini
|| maxi
==255)
1291 result
=mmdif
*240; /* 0...61200=255*240 */
1292 result
/= (mmsum
>255 ? mmsum
=510-mmsum
: mmsum
); /* 0..255 */
1296 case 'H':if (!mmdif
)
1302 iresult
=40*(g
-b
); /* -10200 ... 10200 */
1303 iresult
/=(int)mmdif
; /* -40 .. 40 */
1305 iresult
+=240; /* 0..40 and 200..240 */
1311 iresult
/=(int)mmdif
;
1312 iresult
+=80; /* 40 .. 120 */
1318 iresult
/=(int)mmdif
;
1319 iresult
+=160; /* 120 .. 200 */
1325 return result
; /* is this integer arithmetic precise enough ? */
1330 /***********************************************************************
1331 * CC_MouseCheckPredefColorArray [internal]
1333 static int CC_MouseCheckPredefColorArray(HWND16 hDlg
,int dlgitem
,int rows
,int cols
,
1334 LPARAM lParam
,COLORREF
*cr
)
1337 POINT16 point
= MAKEPOINT16(lParam
);
1341 ClientToScreen16(hDlg
,&point
);
1342 hwnd
=GetDlgItem32(hDlg
,dlgitem
);
1343 GetWindowRect16(hwnd
,&rect
);
1344 if (PtInRect16(&rect
,point
))
1346 dx
=(rect
.right
-rect
.left
)/cols
;
1347 dy
=(rect
.bottom
-rect
.top
)/rows
;
1348 ScreenToClient16(hwnd
,&point
);
1350 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1354 *cr
=predefcolors
[y
][x
];
1355 /* FIXME: Draw_a_Focus_Rect() */
1362 /***********************************************************************
1363 * CC_MouseCheckUserColorArray [internal]
1365 static int CC_MouseCheckUserColorArray(HWND16 hDlg
,int dlgitem
,int rows
,int cols
,
1366 LPARAM lParam
,COLORREF
*cr
,COLORREF
*crarr
)
1369 POINT16 point
= MAKEPOINT16(lParam
);
1373 ClientToScreen16(hDlg
,&point
);
1374 hwnd
=GetDlgItem32(hDlg
,dlgitem
);
1375 GetWindowRect16(hwnd
,&rect
);
1376 if (PtInRect16(&rect
,point
))
1378 dx
=(rect
.right
-rect
.left
)/cols
;
1379 dy
=(rect
.bottom
-rect
.top
)/rows
;
1380 ScreenToClient16(hwnd
,&point
);
1382 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1386 *cr
=crarr
[x
+cols
*y
];
1387 /* FIXME: Draw_a_Focus_Rect() */
1397 /* 240 ^...... ^^ 240
1404 /***********************************************************************
1405 * CC_MouseCheckColorGraph [internal]
1407 static int CC_MouseCheckColorGraph(HWND16 hDlg
,int dlgitem
,int *hori
,int *vert
,LPARAM lParam
)
1410 POINT16 point
= MAKEPOINT16(lParam
);
1414 ClientToScreen16(hDlg
,&point
);
1415 hwnd
=GetDlgItem32(hDlg
,dlgitem
);
1416 GetWindowRect16(hwnd
,&rect
);
1417 if (PtInRect16(&rect
,point
))
1419 GetClientRect16(hwnd
,&rect
);
1420 ScreenToClient16(hwnd
,&point
);
1422 x
=(long)point
.x
*MAXHORI
;
1424 y
=(long)(rect
.bottom
-point
.y
)*MAXVERT
;
1436 /***********************************************************************
1437 * CC_MouseCheckResultWindow [internal]
1439 static int CC_MouseCheckResultWindow(HWND16 hDlg
,LPARAM lParam
)
1442 POINT16 point
= MAKEPOINT16(lParam
);
1445 ClientToScreen16(hDlg
,&point
);
1446 hwnd
=GetDlgItem32(hDlg
,0x2c5);
1447 GetWindowRect16(hwnd
,&rect
);
1448 if (PtInRect16(&rect
,point
))
1450 PostMessage16(hDlg
,WM_COMMAND
,0x2c9,0);
1456 /***********************************************************************
1457 * CC_CheckDigitsInEdit [internal]
1459 static int CC_CheckDigitsInEdit(HWND16 hwnd
,int maxval
)
1461 int i
,k
,m
,result
,value
;
1464 GetWindowText32A(hwnd
,buffer
,sizeof(buffer
));
1469 if (buffer
[i
]<'0' || buffer
[i
]>'9')
1471 for (k
=i
+1;k
<=m
;k
++) /* delete bad character */
1473 buffer
[i
]=buffer
[k
];
1481 if (value
>maxval
) /* build a new string */
1483 sprintf(buffer
,"%d",maxval
);
1488 editpos
=SendMessage16(hwnd
,EM_GETSEL16
,0,0);
1489 SetWindowText32A(hwnd
,buffer
);
1490 SendMessage16(hwnd
,EM_SETSEL16
,0,editpos
);
1497 /***********************************************************************
1498 * CC_PaintSelectedColor [internal]
1500 static void CC_PaintSelectedColor(HWND16 hDlg
,COLORREF cr
)
1505 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2c5);
1506 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
1509 GetClientRect16 (hwnd
, &rect
) ;
1510 hBrush
= CreateSolidBrush32(cr
);
1513 hBrush
= SelectObject32 (hdc
, hBrush
) ;
1514 Rectangle32(hdc
, rect
.left
,rect
.top
,rect
.right
/2,rect
.bottom
);
1515 DeleteObject32 (SelectObject32 (hdc
,hBrush
)) ;
1516 hBrush
=CreateSolidBrush32(GetNearestColor32(hdc
,cr
));
1519 hBrush
= SelectObject32 (hdc
, hBrush
) ;
1520 Rectangle32( hdc
, rect
.right
/2-1,rect
.top
,rect
.right
,rect
.bottom
);
1521 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
1524 ReleaseDC32(hwnd
,hdc
);
1528 /***********************************************************************
1529 * CC_PaintTriangle [internal]
1531 static void CC_PaintTriangle(HWND16 hDlg
,int y
)
1535 int w
=GetDialogBaseUnits();
1540 HWND16 hwnd
=GetDlgItem32(hDlg
,0x2be);
1541 struct CCPRIVATE
*lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1543 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
1545 GetClientRect16(hwnd
,&rect
);
1549 points
[0].y
=rect
.top
;
1550 points
[0].x
=rect
.right
; /* | /| */
1551 ClientToScreen16(hwnd
,points
); /* | / | */
1552 ScreenToClient16(hDlg
,points
); /* |< | */
1553 oben
=points
[0].y
; /* | \ | */
1555 temp
=(long)height
*(long)y
;
1556 points
[0].y
=oben
+height
-temp
/(long)MAXVERT
;
1557 points
[1].y
=points
[0].y
+w
;
1558 points
[2].y
=points
[0].y
-w
;
1559 points
[2].x
=points
[1].x
=points
[0].x
+ w
;
1561 if (lpp
->old3angle
.left
)
1562 FillRect16(hDC
,&lpp
->old3angle
,GetStockObject32(WHITE_BRUSH
));
1563 lpp
->old3angle
.left
=points
[0].x
;
1564 lpp
->old3angle
.right
=points
[1].x
+1;
1565 lpp
->old3angle
.top
=points
[2].y
-1;
1566 lpp
->old3angle
.bottom
=points
[1].y
+1;
1567 Polygon16(hDC
,points
,3);
1568 ReleaseDC32(hDlg
,hDC
);
1573 /***********************************************************************
1574 * CC_PaintCross [internal]
1576 static void CC_PaintCross(HWND16 hDlg
,int x
,int y
)
1579 int w
=GetDialogBaseUnits();
1580 HWND16 hwnd
=GetDlgItem32(hDlg
,0x2c6);
1581 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1586 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
1588 GetClientRect16(hwnd
,&rect
);
1590 SelectClipRgn32(hDC
,CreateRectRgnIndirect16(&rect
));
1591 hPen
=CreatePen32(PS_SOLID
,2,0);
1592 hPen
=SelectObject32(hDC
,hPen
);
1593 point
.x
=((long)rect
.right
*(long)x
)/(long)MAXHORI
;
1594 point
.y
=rect
.bottom
-((long)rect
.bottom
*(long)y
)/(long)MAXVERT
;
1595 if (lpp
->oldcross
.left
!=lpp
->oldcross
.right
)
1596 BitBlt32(hDC
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,
1597 lpp
->oldcross
.right
-lpp
->oldcross
.left
,
1598 lpp
->oldcross
.bottom
-lpp
->oldcross
.top
,
1599 lpp
->hdcMem
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,SRCCOPY
);
1600 lpp
->oldcross
.left
=point
.x
-w
-1;
1601 lpp
->oldcross
.right
=point
.x
+w
+1;
1602 lpp
->oldcross
.top
=point
.y
-w
-1;
1603 lpp
->oldcross
.bottom
=point
.y
+w
+1;
1605 MoveTo(hDC
,point
.x
-w
,point
.y
);
1606 LineTo32(hDC
,point
.x
+w
,point
.y
);
1607 MoveTo(hDC
,point
.x
,point
.y
-w
);
1608 LineTo32(hDC
,point
.x
,point
.y
+w
);
1609 DeleteObject32(SelectObject32(hDC
,hPen
));
1610 ReleaseDC32(hwnd
,hDC
);
1619 /***********************************************************************
1620 * CC_PrepareColorGraph [internal]
1622 static void CC_PrepareColorGraph(HWND16 hDlg
)
1624 int sdif
,hdif
,xdif
,ydif
,r
,g
,b
,hue
,sat
;
1625 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2c6);
1626 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1630 HCURSOR16 hcursor
=SetCursor16(LoadCursor16(0,IDC_WAIT
));
1632 GetClientRect16(hwnd
,&client
);
1634 lpp
->hdcMem
= CreateCompatibleDC32(hdc
);
1635 lpp
->hbmMem
= CreateCompatibleBitmap32(hdc
,client
.right
,client
.bottom
);
1636 SelectObject32(lpp
->hdcMem
,lpp
->hbmMem
);
1638 xdif
=client
.right
/XSTEPS
;
1639 ydif
=client
.bottom
/YSTEPS
+1;
1642 for(rect
.left
=hue
=0;hue
<239+hdif
;hue
+=hdif
)
1644 rect
.right
=rect
.left
+xdif
;
1645 rect
.bottom
=client
.bottom
;
1646 for(sat
=0;sat
<240+sdif
;sat
+=sdif
)
1648 rect
.top
=rect
.bottom
-ydif
;
1649 r
=CC_HSLtoRGB('R',hue
,sat
,120);
1650 g
=CC_HSLtoRGB('G',hue
,sat
,120);
1651 b
=CC_HSLtoRGB('B',hue
,sat
,120);
1652 hbrush
=CreateSolidBrush32(RGB(r
,g
,b
));
1653 FillRect16(lpp
->hdcMem
,&rect
,hbrush
);
1654 DeleteObject32(hbrush
);
1655 rect
.bottom
=rect
.top
;
1657 rect
.left
=rect
.right
;
1659 ReleaseDC32(hwnd
,hdc
);
1660 SetCursor16(hcursor
);
1663 /***********************************************************************
1664 * CC_PaintColorGraph [internal]
1666 static void CC_PaintColorGraph(HWND16 hDlg
)
1668 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2c6);
1669 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1672 if (IsWindowVisible32(hwnd
)) /* if full size */
1675 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
1678 GetClientRect16(hwnd
,&rect
);
1680 BitBlt32(hDC
,0,0,rect
.right
,rect
.bottom
,lpp
->hdcMem
,0,0,SRCCOPY
);
1682 fprintf(stderr
,"choose color: hdcMem is not defined\n");
1683 ReleaseDC32(hwnd
,hDC
);
1686 /***********************************************************************
1687 * CC_PaintLumBar [internal]
1689 static void CC_PaintLumBar(HWND16 hDlg
,int hue
,int sat
)
1691 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2be);
1693 int lum
,ldif
,ydif
,r
,g
,b
;
1697 if (IsWindowVisible32(hwnd
))
1700 GetClientRect16(hwnd
,&client
);
1704 ydif
=client
.bottom
/YSTEPS
+1;
1705 for(lum
=0;lum
<240+ldif
;lum
+=ldif
)
1707 rect
.top
=MAX(0,rect
.bottom
-ydif
);
1708 r
=CC_HSLtoRGB('R',hue
,sat
,lum
);
1709 g
=CC_HSLtoRGB('G',hue
,sat
,lum
);
1710 b
=CC_HSLtoRGB('B',hue
,sat
,lum
);
1711 hbrush
=CreateSolidBrush32(RGB(r
,g
,b
));
1712 FillRect16(hDC
,&rect
,hbrush
);
1713 DeleteObject32(hbrush
);
1714 rect
.bottom
=rect
.top
;
1716 GetClientRect16(hwnd
,&rect
);
1717 FrameRect16(hDC
,&rect
,GetStockObject32(BLACK_BRUSH
));
1718 ReleaseDC32(hwnd
,hDC
);
1722 /***********************************************************************
1723 * CC_EditSetRGB [internal]
1725 static void CC_EditSetRGB(HWND16 hDlg
,COLORREF cr
)
1728 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1729 int r
=GetRValue(cr
);
1730 int g
=GetGValue(cr
);
1731 int b
=GetBValue(cr
);
1732 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
1735 sprintf(buffer
,"%d",r
);
1736 SetWindowText32A(GetDlgItem32(hDlg
,0x2c2),buffer
);
1737 sprintf(buffer
,"%d",g
);
1738 SetWindowText32A(GetDlgItem32(hDlg
,0x2c3),buffer
);
1739 sprintf(buffer
,"%d",b
);
1740 SetWindowText32A(GetDlgItem32(hDlg
,0x2c4),buffer
);
1741 lpp
->updating
=FALSE
;
1745 /***********************************************************************
1746 * CC_EditSetHSL [internal]
1748 static void CC_EditSetHSL(HWND16 hDlg
,int h
,int s
,int l
)
1751 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1753 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
1756 sprintf(buffer
,"%d",h
);
1757 SetWindowText32A(GetDlgItem32(hDlg
,0x2bf),buffer
);
1758 sprintf(buffer
,"%d",s
);
1759 SetWindowText32A(GetDlgItem32(hDlg
,0x2c0),buffer
);
1760 sprintf(buffer
,"%d",l
);
1761 SetWindowText32A(GetDlgItem32(hDlg
,0x2c1),buffer
);
1762 lpp
->updating
=FALSE
;
1764 CC_PaintLumBar(hDlg
,h
,s
);
1767 /***********************************************************************
1768 * CC_SwitchToFullSize [internal]
1770 static void CC_SwitchToFullSize(HWND16 hDlg
,COLORREF result
,LPRECT16 lprect
)
1773 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1775 EnableWindow32(GetDlgItem32(hDlg
,0x2cf),FALSE
);
1776 CC_PrepareColorGraph(hDlg
);
1777 for (i
=0x2bf;i
<0x2c5;i
++)
1778 EnableWindow32(GetDlgItem32(hDlg
,i
),TRUE
);
1779 for (i
=0x2d3;i
<0x2d9;i
++)
1780 EnableWindow32(GetDlgItem32(hDlg
,i
),TRUE
);
1781 EnableWindow32(GetDlgItem32(hDlg
,0x2c9),TRUE
);
1782 EnableWindow32(GetDlgItem32(hDlg
,0x2c8),TRUE
);
1785 SetWindowPos32(hDlg
,NULL
,0,0,lprect
->right
-lprect
->left
,
1786 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
1788 ShowWindow32(GetDlgItem32(hDlg
,0x2c6),SW_SHOW
);
1789 ShowWindow32(GetDlgItem32(hDlg
,0x2be),SW_SHOW
);
1790 ShowWindow32(GetDlgItem32(hDlg
,0x2c5),SW_SHOW
);
1792 CC_EditSetRGB(hDlg
,result
);
1793 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1796 /***********************************************************************
1797 * CC_PaintPredefColorArray [internal]
1799 static void CC_PaintPredefColorArray(HWND16 hDlg
,int rows
,int cols
)
1801 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2d0);
1807 GetClientRect16(hwnd
,&rect
);
1809 dy
=rect
.bottom
/rows
;
1813 GetClientRect16 (hwnd
, &rect
) ;
1815 for (j
=0;j
<rows
;j
++)
1817 for (i
=0;i
<cols
;i
++)
1819 hBrush
= CreateSolidBrush32(predefcolors
[j
][i
]);
1822 hBrush
= SelectObject32 (hdc
, hBrush
) ;
1823 Rectangle32(hdc
, rect
.left
, rect
.top
,
1824 rect
.left
+dx
-DISTANCE
, rect
.top
+dy
-DISTANCE
);
1825 rect
.left
=rect
.left
+dx
;
1826 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
1829 rect
.top
=rect
.top
+dy
;
1832 ReleaseDC32(hwnd
,hdc
);
1833 /* FIXME: draw_a_focus_rect */
1835 /***********************************************************************
1836 * CC_PaintUserColorArray [internal]
1838 static void CC_PaintUserColorArray(HWND16 hDlg
,int rows
,int cols
,COLORREF
* lpcr
)
1840 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2d1);
1846 GetClientRect16(hwnd
,&rect
);
1849 dy
=rect
.bottom
/rows
;
1855 for (j
=0;j
<rows
;j
++)
1857 for (i
=0;i
<cols
;i
++)
1859 hBrush
= CreateSolidBrush32(lpcr
[i
+j
*cols
]);
1862 hBrush
= SelectObject32 (hdc
, hBrush
) ;
1863 Rectangle32( hdc
, rect
.left
, rect
.top
,
1864 rect
.left
+dx
-DISTANCE
, rect
.top
+dy
-DISTANCE
);
1865 rect
.left
=rect
.left
+dx
;
1866 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
1869 rect
.top
=rect
.top
+dy
;
1872 ReleaseDC32(hwnd
,hdc
);
1874 /* FIXME: draw_a_focus_rect */
1879 /***********************************************************************
1880 * CC_HookCallChk [internal]
1882 static BOOL32
CC_HookCallChk(LPCHOOSECOLOR lpcc
)
1885 if(lpcc
->Flags
& CC_ENABLEHOOK
)
1891 /***********************************************************************
1892 * CC_WMInitDialog [internal]
1894 static LONG
CC_WMInitDialog(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
1900 struct CCPRIVATE
* lpp
;
1902 dprintf_commdlg(stddeb
,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
1903 lpp
=calloc(1,sizeof(struct CCPRIVATE
));
1904 lpp
->lpcc
=(LPCHOOSECOLOR
)lParam
;
1905 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLOR
))
1907 EndDialog32 (hDlg
, 0) ;
1910 SetWindowLong32A(hDlg
, DWL_USER
, (LONG
)lpp
);
1912 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
1913 ShowWindow32(GetDlgItem32(hDlg
,0x40e),SW_HIDE
);
1914 lpp
->msetrgb
=RegisterWindowMessage32A( SETRGBSTRING
);
1916 cpos
=MAKELONG(5,7); /* init */
1917 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
1921 if (predefcolors
[i
][j
]==lpp
->lpcc
->rgbResult
)
1928 /* FIXME: Draw_a_focus_rect & set_init_values */
1930 GetWindowRect16(hDlg
,&lpp
->fullsize
);
1931 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1933 hwnd
=GetDlgItem32(hDlg
,0x2cf);
1934 EnableWindow32(hwnd
,FALSE
);
1936 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
1939 res
=rect
.bottom
-rect
.top
;
1940 hwnd
=GetDlgItem32(hDlg
,0x2c6); /* cut at left border */
1942 ClientToScreen16(hwnd
,&point
);
1943 ScreenToClient16(hDlg
,&point
);
1944 GetClientRect16(hDlg
,&rect
);
1945 point
.x
+=GetSystemMetrics32(SM_CXDLGFRAME
);
1946 SetWindowPos32(hDlg
,NULL
,0,0,point
.x
,res
,SWP_NOMOVE
|SWP_NOZORDER
);
1948 ShowWindow32(GetDlgItem32(hDlg
,0x2c6),SW_HIDE
);
1949 ShowWindow32(GetDlgItem32(hDlg
,0x2c5),SW_HIDE
);
1952 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,NULL
);
1954 for (i
=0x2bf;i
<0x2c5;i
++)
1955 SendMessage16(GetDlgItem32(hDlg
,i
),EM_LIMITTEXT16
,3,0); /* max 3 digits: xyz */
1956 if (CC_HookCallChk(lpp
->lpcc
))
1957 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
1961 /***********************************************************************
1962 * CC_WMCommand [internal]
1964 static LRESULT
CC_WMCommand(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
1970 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
1971 dprintf_commdlg(stddeb
,"CC_WMCommand wParam=%x lParam=%lx\n",wParam
,lParam
);
1974 case 0x2c2: /* edit notify RGB */
1977 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
1979 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),255);
1980 r
=GetRValue(lpp
->lpcc
->rgbResult
);
1981 g
=GetGValue(lpp
->lpcc
->rgbResult
);
1982 b
=GetBValue(lpp
->lpcc
->rgbResult
);
1986 case 0x2c2:if ((xx
=(i
!=r
))) r
=i
;break;
1987 case 0x2c3:if ((xx
=(i
!=g
))) g
=i
;break;
1988 case 0x2c4:if ((xx
=(i
!=b
))) b
=i
;break;
1990 if (xx
) /* something has changed */
1992 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1993 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1994 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
1995 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
1996 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
1997 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1998 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1999 CC_PaintTriangle(hDlg
,lpp
->l
);
2004 case 0x2bf: /* edit notify HSL */
2007 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
2009 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),wParam
==0x2bf?239:240);
2013 case 0x2bf:if ((xx
=(i
!=lpp
->h
))) lpp
->h
=i
;break;
2014 case 0x2c0:if ((xx
=(i
!=lpp
->s
))) lpp
->s
=i
;break;
2015 case 0x2c1:if ((xx
=(i
!=lpp
->l
))) lpp
->l
=i
;break;
2017 if (xx
) /* something has changed */
2019 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
2020 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
2021 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
2022 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2023 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2024 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2025 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2026 CC_PaintTriangle(hDlg
,lpp
->l
);
2032 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,&lpp
->fullsize
);
2033 InvalidateRect32( hDlg
, NULL
, TRUE
);
2034 SetFocus32(GetDlgItem32(hDlg
,0x2bf));
2037 case 0x2c8: /* add colors ... column by column */
2038 cr
=PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
);
2039 cr
[(lpp
->nextuserdef
%2)*8 + lpp
->nextuserdef
/2]=lpp
->lpcc
->rgbResult
;
2040 if (++lpp
->nextuserdef
==16)
2042 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2045 case 0x2c9: /* resulting color */
2047 lpp
->lpcc
->rgbResult
=GetNearestColor32(hdc
,lpp
->lpcc
->rgbResult
);
2048 ReleaseDC32(hDlg
,hdc
);
2049 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2050 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2051 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2052 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2053 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2054 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2055 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2056 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2057 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2058 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2059 CC_PaintTriangle(hDlg
,lpp
->l
);
2062 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2063 i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2064 if (lpp
->lpcc
->hwndOwner
)
2065 SendMessage16(lpp
->lpcc
->hwndOwner
,i
,0,(LPARAM
)lpp
->lpcc
);
2066 if (CC_HookCallChk(lpp
->lpcc
))
2067 CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,
2068 WM_COMMAND
,psh15
,(LPARAM
)lpp
->lpcc
);
2072 cokmsg
=RegisterWindowMessage32A( COLOROKSTRING
);
2073 if (lpp
->lpcc
->hwndOwner
)
2074 if (SendMessage16(lpp
->lpcc
->hwndOwner
,cokmsg
,0,(LPARAM
)lpp
->lpcc
))
2075 break; /* do NOT close */
2077 EndDialog32 (hDlg
, 1) ;
2081 EndDialog32 (hDlg
, 0) ;
2088 /***********************************************************************
2089 * CC_WMPaint [internal]
2091 static LRESULT
CC_WMPaint(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2093 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2094 /* we have to paint dialog children except text and buttons */
2096 CC_PaintPredefColorArray(hDlg
,6,8);
2097 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2098 CC_PaintColorGraph(hDlg
);
2099 CC_PaintLumBar(hDlg
,lpp
->h
,lpp
->s
);
2100 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2101 CC_PaintTriangle(hDlg
,lpp
->l
);
2102 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2104 /* special necessary for Wine */
2105 ValidateRect32(GetDlgItem32(hDlg
,0x2d0),NULL
);
2106 ValidateRect32(GetDlgItem32(hDlg
,0x2d1),NULL
);
2107 ValidateRect32(GetDlgItem32(hDlg
,0x2c6),NULL
);
2108 ValidateRect32(GetDlgItem32(hDlg
,0x2be),NULL
);
2109 ValidateRect32(GetDlgItem32(hDlg
,0x2c5),NULL
);
2110 /* hope we can remove it later -->FIXME */
2115 /***********************************************************************
2116 * CC_WMLButtonDown [internal]
2118 static LRESULT
CC_WMLButtonDown(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2120 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2123 if (CC_MouseCheckPredefColorArray(hDlg
,0x2d0,6,8,lParam
,&lpp
->lpcc
->rgbResult
))
2126 if (CC_MouseCheckUserColorArray(hDlg
,0x2d1,2,8,lParam
,&lpp
->lpcc
->rgbResult
,
2127 PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
)))
2130 if (CC_MouseCheckColorGraph(hDlg
,0x2c6,&lpp
->h
,&lpp
->s
,lParam
))
2133 if (CC_MouseCheckColorGraph(hDlg
,0x2be,NULL
,&lpp
->l
,lParam
))
2137 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
2138 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
2139 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
2140 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2144 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2145 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2146 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2147 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2148 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2149 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2153 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2154 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2155 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2156 CC_PaintTriangle(hDlg
,lpp
->l
);
2157 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2163 /***********************************************************************
2164 * ColorDlgProc (COMMDLG.8)
2166 LRESULT
ColorDlgProc(HWND16 hDlg
, UINT16 message
,
2167 WPARAM16 wParam
, LONG lParam
)
2170 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2171 if (message
!=WM_INITDIALOG
)
2176 if (CC_HookCallChk(lpp
->lpcc
))
2177 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2182 /* FIXME: SetRGB message
2183 if (message && message==msetrgb)
2184 return HandleSetRGB(hDlg,lParam);
2190 return CC_WMInitDialog(hDlg
,wParam
,lParam
);
2192 DeleteDC32(lpp
->hdcMem
);
2193 DeleteObject32(lpp
->hbmMem
);
2195 SetWindowLong32A(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
2198 if (CC_WMCommand(hDlg
, wParam
, lParam
))
2202 CC_WMPaint(hDlg
, wParam
, lParam
);
2204 case WM_LBUTTONDBLCLK
:
2205 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
2208 case WM_MOUSEMOVE
: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2210 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
2212 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
2213 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
2222 /***********************************************************************
2223 * ChooseFont (COMMDLG.15)
2225 BOOL16
ChooseFont(LPCHOOSEFONT lpChFont
)
2228 HANDLE16 hDlgTmpl
= 0;
2229 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
2233 dprintf_commdlg(stddeb
,"ChooseFont\n");
2234 if (!lpChFont
) return FALSE
;
2236 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
)
2238 if (!(template = LockResource16( lpChFont
->hInstance
)))
2240 CommDlgLastError
= CDERR_LOADRESFAILURE
;
2244 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
2247 if (!(hResInfo
= FindResource16( lpChFont
->hInstance
,
2248 lpChFont
->lpTemplateName
, RT_DIALOG
)))
2250 CommDlgLastError
= CDERR_FINDRESFAILURE
;
2253 if (!(hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
)) ||
2254 !(template = LockResource16( hDlgTmpl
)))
2256 CommDlgLastError
= CDERR_LOADRESFAILURE
;
2262 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT
);
2266 hInst
= WIN_GetWindowInstance( lpChFont
->hwndOwner
);
2268 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
2269 lpChFont
->hwndOwner
,
2270 (DLGPROC16
)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2271 (DWORD
)lpChFont
, WIN_PROC_16
);
2272 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
2273 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
2278 #define TEXT_EXTRAS 4
2279 #define TEXT_COLORS 16
2281 static const COLORREF textcolors
[TEXT_COLORS
]=
2283 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
2284 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
2285 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
2286 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
2289 /***********************************************************************
2290 * CFn_HookCallChk [internal]
2292 static BOOL32
CFn_HookCallChk(LPCHOOSEFONT lpcf
)
2295 if(lpcf
->Flags
& CF_ENABLEHOOK
)
2302 /***********************************************************************
2303 * FontFamilyEnumProc (COMMDLG.19)
2305 INT16
FontFamilyEnumProc( SEGPTR logfont
, SEGPTR metrics
,
2306 UINT16 nFontType
, LPARAM lParam
)
2310 HWND16 hwnd
=LOWORD(lParam
);
2311 HWND16 hDlg
=GetParent16(hwnd
);
2312 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2313 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN( logfont
);
2315 dprintf_commdlg(stddeb
,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2316 lplf
->lfFaceName
,nFontType
);
2318 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
2319 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
2321 if (lpcf
->Flags
& CF_ANSIONLY
)
2322 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
2324 if (lpcf
->Flags
& CF_TTONLY
)
2325 if (!(nFontType
& 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2328 i
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,
2329 (LPARAM
)logfont
+ ((char *)lplf
->lfFaceName
- (char *)lplf
));
2332 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
2333 SendMessage16(hwnd
, CB_SETITEMDATA16
,i
,MAKELONG(nFontType
,w
));
2334 return 1 ; /* store some important font information */
2340 /*************************************************************************
2341 * SetFontStylesToCombo2 [internal]
2343 * Fill font style information into combobox (without using font.c directly)
2345 static int SetFontStylesToCombo2(HWND16 hwnd
, HDC16 hdc
, LPLOGFONT16 lplf
,
2346 LPTEXTMETRIC16 lptm
)
2353 static struct FONTSTYLE fontstyles
[FSTYLES
]={
2354 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
2355 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
2359 for (i
=0;i
<FSTYLES
;i
++)
2361 lplf
->lfItalic
=fontstyles
[i
].italic
;
2362 lplf
->lfWeight
=fontstyles
[i
].weight
;
2363 hf
=CreateFontIndirect16(lplf
);
2364 hf
=SelectObject32(hdc
,hf
);
2365 GetTextMetrics16(hdc
,lptm
);
2366 hf
=SelectObject32(hdc
,hf
);
2369 if (lptm
->tmWeight
==fontstyles
[i
].weight
&&
2370 lptm
->tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
2372 char *str
= SEGPTR_STRDUP(fontstyles
[i
].stname
);
2373 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(str
) );
2375 if (j
==CB_ERR
) return 1;
2376 j
=SendMessage16(hwnd
, CB_SETITEMDATA16
, j
,
2377 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
2378 if (j
==CB_ERR
) return 1;
2384 /*************************************************************************
2385 * SetFontSizesToCombo3 [internal]
2387 static int SetFontSizesToCombo3(HWND16 hwnd
, LPLOGFONT16 lplf
, LPCHOOSEFONT lpcf
)
2389 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2393 if (!(buffer
= SEGPTR_ALLOC(20))) return 1;
2394 for (i
=0;sizes
[i
] && !lplf
->lfHeight
;i
++)
2396 h
=lplf
->lfHeight
? lplf
->lfHeight
: sizes
[i
];
2398 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2399 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
2401 sprintf(buffer
,"%2d",h
);
2402 j
=SendMessage16(hwnd
,CB_FINDSTRING16
,-1,(LPARAM
)SEGPTR_GET(buffer
));
2405 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(buffer
));
2406 if (j
!=CB_ERR
) j
= SendMessage16(hwnd
, CB_SETITEMDATA16
, j
, h
);
2409 SEGPTR_FREE(buffer
);
2415 SEGPTR_FREE(buffer
);
2420 /***********************************************************************
2421 * FontStyleEnumProc (COMMDLG.18)
2423 INT16
FontStyleEnumProc( SEGPTR logfont
, SEGPTR metrics
,
2424 UINT16 nFontType
, LPARAM lParam
)
2426 HWND16 hcmb2
=LOWORD(lParam
);
2427 HWND16 hcmb3
=HIWORD(lParam
);
2428 HWND16 hDlg
=GetParent16(hcmb3
);
2429 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2430 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN(logfont
);
2431 TEXTMETRIC16
*lptm
= (TEXTMETRIC16
*)PTR_SEG_TO_LIN(metrics
);
2434 dprintf_commdlg(stddeb
,"FontStyleEnumProc: (nFontType=%d)\n",nFontType
);
2435 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",
2436 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,lplf
->lfEscapement
,lplf
->lfOrientation
,
2437 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,lplf
->lfStrikeOut
,lplf
->lfCharSet
,
2438 lplf
->lfOutPrecision
,lplf
->lfClipPrecision
,lplf
->lfQuality
,lplf
->lfPitchAndFamily
);
2440 if (SetFontSizesToCombo3(hcmb3
, lplf
,lpcf
))
2443 if (!SendMessage16(hcmb2
,CB_GETCOUNT16
,0,0))
2445 HDC32 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2446 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
,lptm
);
2447 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2448 ReleaseDC32(hDlg
,hdc
);
2456 /***********************************************************************
2457 * CFn_WMInitDialog [internal]
2459 LRESULT
CFn_WMInitDialog(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2465 HCURSOR16 hcursor
=SetCursor16(LoadCursor16(0,IDC_WAIT
));
2468 SetWindowLong32A(hDlg
, DWL_USER
, lParam
);
2469 lpcf
=(LPCHOOSEFONT
)lParam
;
2470 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2471 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
2473 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONT
))
2475 dprintf_commdlg(stddeb
,"WM_INITDIALOG: structure size failure !!!\n");
2476 EndDialog32 (hDlg
, 0);
2480 hBitmapTT
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2482 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow32(lpcf
->hwndOwner
))
2483 ShowWindow32(GetDlgItem32(hDlg
,pshHelp
),SW_HIDE
);
2484 if (!(lpcf
->Flags
& CF_APPLY
))
2485 ShowWindow32(GetDlgItem32(hDlg
,psh3
),SW_HIDE
);
2486 if (lpcf
->Flags
& CF_EFFECTS
)
2488 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
2490 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2491 char *name
= SEGPTR_ALLOC(20);
2492 strcpy( name
, "[color name]" );
2493 j
=SendDlgItemMessage16(hDlg
,cmb4
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(name
));
2495 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETITEMDATA16
,j
,textcolors
[j
]);
2496 /* look for a fitting value in color combobox */
2497 if (textcolors
[j
]==lpcf
->rgbColors
)
2498 SendDlgItemMessage16(hDlg
,cmb4
, CB_SETCURSEL16
,j
,0);
2503 ShowWindow32(GetDlgItem32(hDlg
,cmb4
),SW_HIDE
);
2504 ShowWindow32(GetDlgItem32(hDlg
,chx1
),SW_HIDE
);
2505 ShowWindow32(GetDlgItem32(hDlg
,chx2
),SW_HIDE
);
2506 ShowWindow32(GetDlgItem32(hDlg
,grp1
),SW_HIDE
);
2507 ShowWindow32(GetDlgItem32(hDlg
,stc4
),SW_HIDE
);
2509 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2512 if (!EnumFontFamilies16(hdc
, NULL
,FontFamilyEnumProc
,
2513 (LPARAM
)GetDlgItem32(hDlg
,cmb1
)))
2514 dprintf_commdlg(stddeb
,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2515 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
2517 /* look for fitting font name in combobox1 */
2518 j
=SendDlgItemMessage16(hDlg
,cmb1
,CB_FINDSTRING16
,-1,(LONG
)lpxx
->lfFaceName
);
2521 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL16
,j
,0);
2522 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,
2523 MAKELONG(GetDlgItem32(hDlg
,cmb1
),CBN_SELCHANGE
));
2525 /* look for fitting font style in combobox2 */
2526 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
2527 for (i
=0;i
<TEXT_EXTRAS
;i
++)
2529 if (l
==SendDlgItemMessage16(hDlg
,cmb2
, CB_GETITEMDATA16
,i
,0))
2530 SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL16
,i
,0);
2533 /* look for fitting font size in combobox3 */
2534 j
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCOUNT16
,0,0);
2537 if (lpxx
->lfHeight
==(int)SendDlgItemMessage16(hDlg
,cmb3
, CB_GETITEMDATA16
,i
,0))
2538 SendDlgItemMessage16(hDlg
,cmb3
,CB_SETCURSEL16
,i
,0);
2543 SendDlgItemMessage16(hDlg
,cmb1
,CB_SETCURSEL16
,0,0);
2544 SendMessage16(hDlg
,WM_COMMAND
,cmb1
,
2545 MAKELONG(GetDlgItem32(hDlg
,cmb1
),CBN_SELCHANGE
));
2548 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
2550 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_FINDSTRING16
,-1,(LONG
)lpcf
->lpszStyle
);
2553 j
=SendDlgItemMessage16(hDlg
,cmb2
,CB_SETCURSEL16
,j
,0);
2554 SendMessage16(hDlg
,WM_COMMAND
,cmb2
,
2555 MAKELONG(GetDlgItem32(hDlg
,cmb2
),CBN_SELCHANGE
));
2561 dprintf_commdlg(stddeb
,"WM_INITDIALOG: HDC failure !!!\n");
2562 EndDialog32 (hDlg
, 0);
2566 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2567 ReleaseDC32(hDlg
,hdc
);
2569 if (CFn_HookCallChk(lpcf
))
2570 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
2571 SetCursor16(hcursor
);
2576 /***********************************************************************
2577 * CFn_WMMeasureItem [internal]
2579 LRESULT
CFn_WMMeasureItem(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2582 LPMEASUREITEMSTRUCT16 lpmi
=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT16
)lParam
);
2584 hBitmapTT
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE
));
2585 GetObject16( hBitmapTT
, sizeof(bm
), &bm
);
2586 lpmi
->itemHeight
=bm
.bmHeight
;
2587 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2592 /***********************************************************************
2593 * CFn_WMDrawItem [internal]
2595 LRESULT
CFn_WMDrawItem(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2605 HBITMAP16 hBitmap
; /* for later TT usage */
2607 LPDRAWITEMSTRUCT16 lpdi
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
2609 if (lpdi
->itemID
== 0xFFFF) /* got no items */
2610 DrawFocusRect16(lpdi
->hDC
, &lpdi
->rcItem
);
2613 if (lpdi
->CtlType
== ODT_COMBOBOX
)
2615 hBrush
= SelectObject32(lpdi
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
2616 SelectObject32(lpdi
->hDC
, hBrush
);
2617 FillRect16(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
2620 return TRUE
; /* this should never happen */
2623 buffer
= SEGPTR_ALLOC(40);
2624 switch (lpdi
->CtlID
)
2626 case cmb1
: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2627 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT16
, lpdi
->itemID
,
2628 (LPARAM
)SEGPTR_GET(buffer
));
2629 GetObject16( hBitmapTT
, sizeof(bm
), &bm
);
2630 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
2631 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2633 nFontType
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA16
, lpdi
->itemID
,0L);
2634 /* FIXME: draw bitmap if truetype usage */
2635 if (nFontType
&TRUETYPE_FONTTYPE
)
2637 hMemDC
= CreateCompatibleDC32(lpdi
->hDC
);
2638 hBitmap
= SelectObject32(hMemDC
, hBitmapTT
);
2639 BitBlt32(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
2640 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
2641 SelectObject32(hMemDC
, hBitmap
);
2647 case cmb3
: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2648 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT16
, lpdi
->itemID
,
2649 (LPARAM
)SEGPTR_GET(buffer
));
2650 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
,
2651 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2654 case cmb4
: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2655 SendMessage16(lpdi
->hwndItem
, CB_GETLBTEXT16
, lpdi
->itemID
,
2656 (LPARAM
)SEGPTR_GET(buffer
));
2657 TextOut16(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
2658 lpdi
->rcItem
.top
, buffer
, lstrlen16(buffer
));
2659 cr
= SendMessage16(lpdi
->hwndItem
, CB_GETITEMDATA16
, lpdi
->itemID
,0L);
2660 hBrush
= CreateSolidBrush32(cr
);
2663 hBrush
= SelectObject32 (lpdi
->hDC
, hBrush
) ;
2664 rect
.right
=rect
.left
+25;
2668 Rectangle32( lpdi
->hDC
, rect
.left
, rect
.top
,
2669 rect
.right
, rect
.bottom
);
2670 DeleteObject32( SelectObject32 (lpdi
->hDC
, hBrush
)) ;
2676 default: return TRUE
; /* this should never happen */
2678 SEGPTR_FREE(buffer
);
2679 if (lpdi
->itemState
==ODS_SELECTED
)
2680 InvertRect16(lpdi
->hDC
, &rect
);
2685 /***********************************************************************
2686 * CFn_WMCtlColor [internal]
2688 LRESULT
CFn_WMCtlColor(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2690 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2692 if (lpcf
->Flags
& CF_EFFECTS
)
2693 if (HIWORD(lParam
)==CTLCOLOR_STATIC
&& GetDlgCtrlID32(LOWORD(lParam
))==stc6
)
2695 SetTextColor32(wParam
,lpcf
->rgbColors
);
2696 return GetStockObject32(WHITE_BRUSH
);
2701 /***********************************************************************
2702 * CFn_WMCommand [internal]
2704 LRESULT
CFn_WMCommand(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2710 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2711 LPLOGFONT16 lpxx
=PTR_SEG_TO_LIN(lpcf
->lpLogFont
);
2713 dprintf_commdlg(stddeb
,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam
);
2716 case cmb1
:if (HIWORD(lParam
)==CBN_SELCHANGE
)
2718 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
2721 SendDlgItemMessage16(hDlg
,cmb2
,CB_RESETCONTENT16
,0,0);
2722 SendDlgItemMessage16(hDlg
,cmb3
,CB_RESETCONTENT16
,0,0);
2723 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL16
,0,0);
2726 HCURSOR16 hcursor
=SetCursor16(LoadCursor16(0,IDC_WAIT
));
2727 char *str
= SEGPTR_ALLOC(256);
2728 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT16
,i
,
2729 (LPARAM
)SEGPTR_GET(str
));
2730 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb1 =>%s\n",str
);
2731 EnumFontFamilies16(hdc
,str
,FontStyleEnumProc
,
2732 MAKELONG(GetDlgItem32(hDlg
,cmb2
),GetDlgItem32(hDlg
,cmb3
)));
2733 SetCursor16(hcursor
);
2736 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
2737 ReleaseDC32(hDlg
,hdc
);
2741 dprintf_commdlg(stddeb
,"WM_COMMAND: HDC failure !!!\n");
2742 EndDialog32 (hDlg
, 0);
2749 case cmb3
:if (HIWORD(lParam
)==CBN_SELCHANGE
|| HIWORD(lParam
)== BN_CLICKED
)
2751 char *str
= SEGPTR_ALLOC(256);
2752 dprintf_commdlg(stddeb
,"WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
2753 i
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETCURSEL16
,0,0);
2755 i
=GetDlgItemText32A( hDlg
, cmb1
, str
, 256 );
2758 SendDlgItemMessage16(hDlg
,cmb1
,CB_GETLBTEXT16
,i
,
2759 (LPARAM
)SEGPTR_GET(str
));
2760 l
=SendDlgItemMessage16(hDlg
,cmb1
,CB_GETITEMDATA16
,i
,0);
2762 lpcf
->nFontType
= LOWORD(l
);
2763 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2764 /* same value reported to the EnumFonts
2765 call back with the extra FONTTYPE_... bits added */
2766 lpxx
->lfPitchAndFamily
=j
&0xff;
2767 lpxx
->lfCharSet
=j
>>8;
2769 strcpy(lpxx
->lfFaceName
,str
);
2771 i
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETCURSEL16
,0,0);
2774 l
=SendDlgItemMessage16(hDlg
,cmb2
,CB_GETITEMDATA16
,i
,0);
2775 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
2776 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
2777 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
2778 lpcf
->nFontType
|= BOLD_FONTTYPE
;
2780 i
=SendDlgItemMessage16(hDlg
,cmb3
,CB_GETCURSEL16
,0,0);
2782 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessage16(hDlg
,cmb3
,CB_GETITEMDATA16
,i
,0));
2785 lpxx
->lfStrikeOut
=IsDlgButtonChecked32(hDlg
,chx1
);
2786 lpxx
->lfUnderline
=IsDlgButtonChecked32(hDlg
,chx2
);
2787 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
2788 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
2789 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
2790 lpxx
->lfQuality
=DEFAULT_QUALITY
;
2791 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
2793 hFont
=CreateFontIndirect16(lpxx
);
2795 SendDlgItemMessage16(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
2796 /* FIXME: Delete old font ...? */
2800 case cmb4
:i
=SendDlgItemMessage16(hDlg
,cmb4
,CB_GETCURSEL16
,0,0);
2803 lpcf
->rgbColors
=textcolors
[i
];
2804 InvalidateRect32( GetDlgItem32(hDlg
,stc6
), NULL
, 0 );
2808 case psh15
:i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2809 if (lpcf
->hwndOwner
)
2810 SendMessage16(lpcf
->hwndOwner
,i
,0,(LPARAM
)lpcf
);
2811 if (CFn_HookCallChk(lpcf
))
2812 CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_COMMAND
,psh15
,(LPARAM
)lpcf
);
2815 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
2816 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
2817 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
2818 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
2819 EndDialog32(hDlg
, TRUE
);
2823 sprintf(buffer
,"Select a font size between %d and %d points.",
2824 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
2825 MessageBox16(hDlg
,buffer
,NULL
,MB_OK
);
2828 case IDCANCEL
:EndDialog32(hDlg
, FALSE
);
2835 /***********************************************************************
2836 * FormatCharDlgProc (COMMDLG.16)
2837 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
2838 2. some CF_.. flags are not supported
2839 3. some TType extensions
2841 LRESULT
FormatCharDlgProc(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
2843 LPCHOOSEFONT lpcf
=(LPCHOOSEFONT
)GetWindowLong32A(hDlg
, DWL_USER
);
2844 if (message
!=WM_INITDIALOG
)
2849 if (CFn_HookCallChk(lpcf
))
2850 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2855 return CFn_WMInitDialog(hDlg
,wParam
,lParam
);
2858 case WM_MEASUREITEM
:
2859 return CFn_WMMeasureItem(hDlg
,wParam
,lParam
);
2861 return CFn_WMDrawItem(hDlg
,wParam
,lParam
);
2863 return CFn_WMCtlColor(hDlg
,wParam
,lParam
);
2865 return CFn_WMCommand(hDlg
,wParam
,lParam
);
2866 case WM_CHOOSEFONT_GETLOGFONT
:
2867 dprintf_commdlg(stddeb
,
2868 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam
);
2869 /* FIXME: current logfont back to caller */