4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
11 #include "wine/winbase16.h"
25 static DWORD CommDlgLastError
= 0;
27 static HBITMAP16 hFolder
= 0;
28 static HBITMAP16 hFolder2
= 0;
29 static HBITMAP16 hFloppy
= 0;
30 static HBITMAP16 hHDisk
= 0;
31 static HBITMAP16 hCDRom
= 0;
32 static HBITMAP16 hBitmapTT
= 0;
33 static const char defaultfilter
[]=" \0\0";
35 /***********************************************************************
36 * FileDlg_Init [internal]
38 static BOOL32
FileDlg_Init(void)
40 static BOOL32 initialized
= 0;
43 if (!hFolder
) hFolder
= LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER
));
44 if (!hFolder2
) hFolder2
= LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER2
));
45 if (!hFloppy
) hFloppy
= LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FLOPPY
));
46 if (!hHDisk
) hHDisk
= LoadBitmap16(0, MAKEINTRESOURCE16(OBM_HDISK
));
47 if (!hCDRom
) hCDRom
= LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CDROM
));
48 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
49 hHDisk
== 0 || hCDRom
== 0)
51 WARN(commdlg
, "Error loading bitmaps !\nprin");
59 /***********************************************************************
60 * GetOpenFileName (COMMDLG.1)
62 BOOL16 WINAPI
GetOpenFileName16( SEGPTR ofn
)
65 HANDLE32 hDlgTmpl
= 0, hResInfo
;
66 BOOL32 bRet
= FALSE
, win32Format
= FALSE
;
68 LPOPENFILENAME16 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(ofn
);
70 char defaultopen
[]="Open File";
73 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
75 if (lpofn
->Flags
& OFN_WINE32
) {
76 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
78 if (!(template = LockResource32( MapHModuleSL(lpofn
->hInstance
))))
80 CommDlgLastError
= CDERR_LOADRESFAILURE
;
84 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
86 if (!(hResInfo
= FindResource32A(MapHModuleSL(lpofn
->hInstance
),
87 PTR_SEG_TO_LIN(lpofn
->lpTemplateName
), RT_DIALOG32A
)))
89 CommDlgLastError
= CDERR_FINDRESFAILURE
;
92 if (!(hDlgTmpl
= LoadResource32( MapHModuleSL(lpofn
->hInstance
),
94 !(template = LockResource32( hDlgTmpl
)))
96 CommDlgLastError
= CDERR_LOADRESFAILURE
;
100 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE
);
104 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
106 if (!(template = LockResource16( lpofn
->hInstance
)))
108 CommDlgLastError
= CDERR_LOADRESFAILURE
;
112 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
114 if (!(hResInfo
= FindResource16(lpofn
->hInstance
,
115 lpofn
->lpTemplateName
,
118 CommDlgLastError
= CDERR_FINDRESFAILURE
;
121 if (!(hDlgTmpl
= LoadResource16( lpofn
->hInstance
, hResInfo
)) ||
122 !(template = LockResource16( hDlgTmpl
)))
124 CommDlgLastError
= CDERR_LOADRESFAILURE
;
128 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE
);
133 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
135 if (!(lpofn
->lpstrFilter
))
137 str
= SEGPTR_ALLOC(sizeof(defaultfilter
));
138 TRACE(commdlg
,"Alloc %p default for Filetype in GetOpenFileName\n",str
);
139 memcpy(str
,defaultfilter
,sizeof(defaultfilter
));
140 lpofn
->lpstrFilter
=SEGPTR_GET(str
);
143 if (!(lpofn
->lpstrTitle
))
145 str1
= SEGPTR_ALLOC(strlen(defaultopen
)+1);
146 TRACE(commdlg
,"Alloc %p default for Title in GetOpenFileName\n",str1
);
147 strcpy(str1
,defaultopen
);
148 lpofn
->lpstrTitle
=SEGPTR_GET(str1
);
151 /* FIXME: doesn't handle win32 format correctly yet */
152 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
154 (DLGPROC16
)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
156 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpofn
->hwndOwner
);
160 TRACE(commdlg
,"Freeing %p default for Title in GetOpenFileName\n",str1
);
167 TRACE(commdlg
,"Freeing %p default for Filetype in GetOpenFileName\n",str
);
169 lpofn
->lpstrFilter
=0;
173 if (lpofn
->Flags
& OFN_WINE32
)
174 FreeResource32( hDlgTmpl
);
176 FreeResource16( hDlgTmpl
);
179 TRACE(commdlg
,"return lpstrFile='%s' !\n",
180 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
185 /***********************************************************************
186 * GetSaveFileName (COMMDLG.2)
188 BOOL16 WINAPI
GetSaveFileName16( SEGPTR ofn
)
191 HANDLE32 hDlgTmpl
= 0;
192 BOOL32 bRet
= FALSE
, win32Format
= FALSE
;
193 LPOPENFILENAME16 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(ofn
);
196 char defaultsave
[]="Save as";
197 char *str
=0,*str1
=0;
199 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
201 if (lpofn
->Flags
& OFN_WINE32
) {
202 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
204 if (!(template = LockResource32( MapHModuleSL(lpofn
->hInstance
))))
206 CommDlgLastError
= CDERR_LOADRESFAILURE
;
210 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
213 if (!(hResInfo
= FindResource32A(MapHModuleSL(lpofn
->hInstance
),
214 PTR_SEG_TO_LIN(lpofn
->lpTemplateName
),
217 CommDlgLastError
= CDERR_FINDRESFAILURE
;
220 if (!(hDlgTmpl
= LoadResource32(MapHModuleSL(lpofn
->hInstance
),
222 !(template = LockResource32(hDlgTmpl
)))
224 CommDlgLastError
= CDERR_LOADRESFAILURE
;
229 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE
);
233 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
)
235 if (!(template = LockResource16( lpofn
->hInstance
)))
237 CommDlgLastError
= CDERR_LOADRESFAILURE
;
241 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
244 if (!(hResInfo
= FindResource16(lpofn
->hInstance
,
245 lpofn
->lpTemplateName
,
248 CommDlgLastError
= CDERR_FINDRESFAILURE
;
251 if (!(hDlgTmpl
= LoadResource16( lpofn
->hInstance
, hResInfo
)) ||
252 !(template = LockResource16( hDlgTmpl
)))
254 CommDlgLastError
= CDERR_LOADRESFAILURE
;
258 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE
);
263 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
265 if (!(lpofn
->lpstrFilter
))
267 str
= SEGPTR_ALLOC(sizeof(defaultfilter
));
268 TRACE(commdlg
,"Alloc default for Filetype in GetSaveFileName\n");
269 memcpy(str
,defaultfilter
,sizeof(defaultfilter
));
270 lpofn
->lpstrFilter
=SEGPTR_GET(str
);
273 if (!(lpofn
->lpstrTitle
))
275 str1
= SEGPTR_ALLOC(sizeof(defaultsave
)+1);
276 TRACE(commdlg
,"Alloc default for Title in GetSaveFileName\n");
277 strcpy(str1
,defaultsave
);
278 lpofn
->lpstrTitle
=SEGPTR_GET(str1
);
281 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
283 (DLGPROC16
)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
285 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpofn
->hwndOwner
);
289 TRACE(commdlg
,"Freeing %p default for Title in GetSaveFileName\n",str1
);
296 TRACE(commdlg
,"Freeing %p default for Filetype in GetSaveFileName\n",str
);
298 lpofn
->lpstrFilter
=0;
302 if (lpofn
->Flags
& OFN_WINE32
)
303 FreeResource32( hDlgTmpl
);
305 FreeResource16( hDlgTmpl
);
308 TRACE(commdlg
, "return lpstrFile='%s' !\n",
309 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
313 /***********************************************************************
314 * FILEDLG_StripEditControl [internal]
315 * Strip pathnames off the contents of the edit control.
317 static void FILEDLG_StripEditControl(HWND16 hwnd
)
321 GetDlgItemText32A( hwnd
, edt1
, temp
, sizeof(temp
) );
322 cp
= strrchr(temp
, '\\');
326 cp
= strrchr(temp
, ':');
330 /* FIXME: shouldn't we do something with the result here? ;-) */
333 /***********************************************************************
334 * FILEDLG_ScanDir [internal]
336 static BOOL32
FILEDLG_ScanDir(HWND16 hWnd
, LPSTR newPath
)
343 lstrcpyn32A(buffer
, newPath
, sizeof(buffer
));
345 if (str
[0] && (str
[1] == ':')) {
346 drive
= toupper(str
[0]) - 'A';
348 if (!DRIVE_SetCurrentDrive(drive
))
351 drive
= DRIVE_GetCurrentDrive();
354 if (str
[0] && !DRIVE_Chdir(drive
, str
)) {
358 GetDlgItemText32A(hWnd
, edt1
, buffer
, sizeof(buffer
));
359 if ((hlb
= GetDlgItem32(hWnd
, lst1
)) != 0) {
360 char* scptr
; /* ptr on semi-colon */
361 char* filter
= buffer
;
363 TRACE(commdlg
, "Using filter %s\n", filter
);
364 SendMessage32A(hlb
, LB_RESETCONTENT32
, 0, 0);
366 scptr
= strchr(filter
, ';');
367 if (scptr
) *scptr
= 0;
368 TRACE(commdlg
, "Using file spec %s\n", filter
);
369 if (SendMessage32A(hlb
, LB_DIR32
, 0, (LPARAM
)filter
) == LB_ERR
)
371 if (scptr
) *scptr
= ';';
372 filter
= (scptr
) ? (scptr
+ 1) : 0;
376 strcpy(buffer
, "*.*");
377 return DlgDirList32A(hWnd
, buffer
, lst2
, stc1
, 0x8010);
380 /***********************************************************************
381 * FILEDLG_GetFileType [internal]
384 static LPSTR
FILEDLG_GetFileType(LPSTR cfptr
, LPSTR fptr
, WORD index
)
389 for ( ;(n
= strlen(cfptr
)) != 0; i
++)
394 cfptr
+= strlen(cfptr
) + 1;
397 for ( ;(n
= strlen(fptr
)) != 0; i
++)
402 fptr
+= strlen(fptr
) + 1;
404 return "*.*"; /* FIXME */
407 /***********************************************************************
408 * FILEDLG_WMDrawItem [internal]
410 static LONG
FILEDLG_WMDrawItem(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
,int savedlg
)
412 LPDRAWITEMSTRUCT16 lpdis
= (LPDRAWITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
415 HBITMAP16 hBitmap
, hPrevBitmap
;
419 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
)
421 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
422 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
423 SelectObject32(lpdis
->hDC
, hBrush
);
424 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
425 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT16
, lpdis
->itemID
,
426 (LPARAM
)SEGPTR_GET(str
));
428 if (savedlg
) /* use _gray_ text in FileSaveDlg */
430 if (!lpdis
->itemState
)
431 SetTextColor32(lpdis
->hDC
,GetSysColor32(COLOR_GRAYTEXT
) );
433 SetTextColor32(lpdis
->hDC
,GetSysColor32(COLOR_WINDOWTEXT
) );
434 /* inversion of gray would be bad readable */
437 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
439 if (lpdis
->itemState
!= 0) {
440 InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
446 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
)
448 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
449 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
450 SelectObject32(lpdis
->hDC
, hBrush
);
451 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
452 SendMessage16(lpdis
->hwndItem
, LB_GETTEXT16
, lpdis
->itemID
,
453 (LPARAM
)SEGPTR_GET(str
));
456 GetObject16( hBitmap
, sizeof(bm
), &bm
);
457 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
458 lpdis
->rcItem
.top
, str
, strlen(str
));
459 hMemDC
= CreateCompatibleDC32(lpdis
->hDC
);
460 hPrevBitmap
= SelectObject32(hMemDC
, hBitmap
);
461 BitBlt32(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
462 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
463 SelectObject32(hMemDC
, hPrevBitmap
);
465 if (lpdis
->itemState
!= 0) InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
469 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
)
471 if (!(str
= SEGPTR_ALLOC(512))) return FALSE
;
472 hBrush
= SelectObject32(lpdis
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
473 SelectObject32(lpdis
->hDC
, hBrush
);
474 FillRect16(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
475 SendMessage16(lpdis
->hwndItem
, CB_GETLBTEXT16
, lpdis
->itemID
,
476 (LPARAM
)SEGPTR_GET(str
));
477 switch(DRIVE_GetType( str
[2] - 'a' ))
479 case TYPE_FLOPPY
: hBitmap
= hFloppy
; break;
480 case TYPE_CDROM
: hBitmap
= hCDRom
; break;
483 default: hBitmap
= hHDisk
; break;
485 GetObject16( hBitmap
, sizeof(bm
), &bm
);
486 TextOut16(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
487 lpdis
->rcItem
.top
, str
, strlen(str
));
488 hMemDC
= CreateCompatibleDC32(lpdis
->hDC
);
489 hPrevBitmap
= SelectObject32(hMemDC
, hBitmap
);
490 BitBlt32( lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
491 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
492 SelectObject32(hMemDC
, hPrevBitmap
);
494 if (lpdis
->itemState
!= 0) InvertRect16(lpdis
->hDC
, &lpdis
->rcItem
);
501 /***********************************************************************
502 * FILEDLG_WMMeasureItem [internal]
504 static LONG
FILEDLG_WMMeasureItem(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
507 LPMEASUREITEMSTRUCT16 lpmeasure
;
509 GetObject16( hFolder2
, sizeof(bm
), &bm
);
510 lpmeasure
= (LPMEASUREITEMSTRUCT16
)PTR_SEG_TO_LIN(lParam
);
511 lpmeasure
->itemHeight
= bm
.bmHeight
;
515 /***********************************************************************
516 * FILEDLG_HookCallChk [internal]
518 static int FILEDLG_HookCallChk(LPOPENFILENAME16 lpofn
)
521 if (lpofn
->Flags
& OFN_ENABLEHOOK
)
527 /***********************************************************************
528 * FILEDLG_CallWindowProc [internal]
530 * Adapt the structures back for win32 calls so the callee can read lpCustData
532 static BOOL32
FILEDLG_CallWindowProc(LPOPENFILENAME16 lpofn
,HWND32 hwnd
,
533 UINT32 wMsg
,WPARAM32 wParam
,LPARAM lParam
537 BOOL32 result
= FALSE
;
538 WINDOWPROCTYPE ProcType
; /* Type of Hook Function to be called. */
540 /* TRUE if lParam points to the OPENFILENAME16 Structure */
541 needstruct
= (PTR_SEG_TO_LIN(lParam
) == lpofn
);
543 ProcType
= (lpofn
->Flags
& OFN_WINE32
)
544 ? (lpofn
->Flags
& OFN_UNICODE
) /* 32-Bit call to GetOpenFileName */
545 ? WIN_PROC_32W
: WIN_PROC_32A
546 : WIN_PROC_16
; /* 16-Bit call to GetOpenFileName */
548 if (!(lpofn
->Flags
& OFN_WINE32
))
549 /* Call to 16-Bit Hooking function... No Problem at all. */
550 return (BOOL32
)CallWindowProc16(
551 lpofn
->lpfnHook
,hwnd
,(UINT16
)wMsg
,(WPARAM16
)wParam
,lParam
556 /* Parameter lParam points to lpofn... Convert Structure Data... */
557 if (lpofn
->Flags
& OFN_UNICODE
)
559 OPENFILENAME32W ofnw
;
561 /* FIXME: probably needs more converted */
562 ofnw
.lCustData
= lpofn
->lCustData
;
563 return (BOOL32
)CallWindowProc32W(
564 (WNDPROC32
)lpofn
->lpfnHook
,hwnd
,wMsg
,wParam
,(LPARAM
)&ofnw
567 else /* ! |OFN_UNICODE */
569 OPENFILENAME32A ofna
;
571 /* FIXME: probably needs more converted */
572 ofna
.lCustData
= lpofn
->lCustData
;
573 return (BOOL32
)CallWindowProc32A(
574 (WNDPROC32
)lpofn
->lpfnHook
,hwnd
,wMsg
,wParam
,(LPARAM
)&ofna
578 else /* ! needstruct */
580 HWINDOWPROC hWindowProc
=NULL
;
582 if (WINPROC_SetProc(&hWindowProc
, lpofn
->lpfnHook
, ProcType
, WIN_PROC_WINDOW
))
584 /* Call Window Procedure converting 16-Bit Type Parameters to 32-Bit Type Parameters */
585 result
= CallWindowProc16( (WNDPROC16
)hWindowProc
,
586 hwnd
, wMsg
, wParam
, lParam
);
588 result
= LOWORD(result
);
590 WINPROC_FreeProc( hWindowProc
, WIN_PROC_WINDOW
);
599 /***********************************************************************
600 * FILEDLG_WMInitDialog [internal]
603 static LONG
FILEDLG_WMInitDialog(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
606 LPOPENFILENAME16 lpofn
;
608 LPSTR pstr
, old_pstr
;
609 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
610 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(lParam
);
611 if (lpofn
->lpstrTitle
) SetWindowText16( hWnd
, lpofn
->lpstrTitle
);
612 /* read custom filter information */
613 if (lpofn
->lpstrCustomFilter
)
615 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
);
617 TRACE(commdlg
,"lpstrCustomFilter = %p\n", pstr
);
621 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING16
, 0,
622 (LPARAM
)lpofn
->lpstrCustomFilter
+ n
);
623 n
+= strlen(pstr
) + 1;
624 pstr
+= strlen(pstr
) + 1;
625 TRACE(commdlg
,"add str='%s' "
626 "associated to '%s'\n", old_pstr
, pstr
);
627 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA16
, i
, (LPARAM
)pstr
);
628 n
+= strlen(pstr
) + 1;
629 pstr
+= strlen(pstr
) + 1;
632 /* read filter information */
633 if (lpofn
->lpstrFilter
) {
634 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
638 i
= SendDlgItemMessage16(hWnd
, cmb1
, CB_ADDSTRING16
, 0,
639 (LPARAM
)lpofn
->lpstrFilter
+ n
);
640 n
+= strlen(pstr
) + 1;
641 pstr
+= strlen(pstr
) + 1;
642 TRACE(commdlg
,"add str='%s' "
643 "associated to '%s'\n", old_pstr
, pstr
);
644 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETITEMDATA16
, i
, (LPARAM
)pstr
);
645 n
+= strlen(pstr
) + 1;
646 pstr
+= strlen(pstr
) + 1;
649 /* set default filter */
650 if (lpofn
->nFilterIndex
== 0 && lpofn
->lpstrCustomFilter
== (SEGPTR
)NULL
)
651 lpofn
->nFilterIndex
= 1;
652 SendDlgItemMessage16(hWnd
, cmb1
, CB_SETCURSEL16
, lpofn
->nFilterIndex
- 1, 0);
653 strncpy(tmpstr
, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
654 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lpofn
->nFilterIndex
- 1),511);
656 TRACE(commdlg
,"nFilterIndex = %ld, SetText of edt1 to '%s'\n",
657 lpofn
->nFilterIndex
, tmpstr
);
658 SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
661 DlgDirListComboBox32A(hWnd
, tmpstr
, cmb2
, 0, 0xC000);
662 /* read initial directory */
663 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
)
665 strncpy(tmpstr
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
), 510);
667 if (strlen(tmpstr
) > 0 && tmpstr
[strlen(tmpstr
)-1] != '\\'
668 && tmpstr
[strlen(tmpstr
)-1] != ':')
673 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) {
675 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
676 WARN(commdlg
, "Couldn't read initial directory %s!\n",tmpstr
);
678 /* select current drive in combo 2, omit missing drives */
679 for(i
=0, n
=-1; i
<=DRIVE_GetCurrentDrive(); i
++)
680 if (DRIVE_IsValid(i
)) n
++;
681 SendDlgItemMessage16(hWnd
, cmb2
, CB_SETCURSEL16
, n
, 0);
682 if (!(lpofn
->Flags
& OFN_SHOWHELP
))
683 ShowWindow32(GetDlgItem32(hWnd
, pshHelp
), SW_HIDE
);
684 if (lpofn
->Flags
& OFN_HIDEREADONLY
)
685 ShowWindow32(GetDlgItem32(hWnd
, chx1
), SW_HIDE
);
686 if (FILEDLG_HookCallChk(lpofn
))
687 return (BOOL16
)FILEDLG_CallWindowProc(lpofn
,hWnd
,WM_INITDIALOG
,wParam
,lParam
);
692 /***********************************************************************
693 * FILEDLG_WMCommand [internal]
695 BOOL32 in_update
=FALSE
;
697 static LRESULT
FILEDLG_WMCommand(HWND16 hWnd
, WPARAM16 wParam
, LPARAM lParam
)
700 LPOPENFILENAME16 lpofn
;
702 char tmpstr
[512], tmpstr2
[512];
704 UINT16 control
,notification
;
706 /* Notifications are packaged differently in Win32 */
708 notification
= HIWORD(lParam
);
710 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
713 case lst1
: /* file list */
714 FILEDLG_StripEditControl(hWnd
);
715 if (notification
== LBN_DBLCLK
)
717 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
718 if (lRet
== LB_ERR
) return TRUE
;
719 if ((pstr
= SEGPTR_ALLOC(512)))
721 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT16
, lRet
,
722 (LPARAM
)SEGPTR_GET(pstr
));
723 SetDlgItemText32A( hWnd
, edt1
, pstr
);
726 if (FILEDLG_HookCallChk(lpofn
))
727 FILEDLG_CallWindowProc(lpofn
,hWnd
,
728 RegisterWindowMessage32A( LBSELCHSTRING
),
729 control
, MAKELONG(lRet
,CD_LBSELCHANGE
));
730 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
732 case lst2
: /* directory list */
733 FILEDLG_StripEditControl(hWnd
);
734 if (notification
== LBN_DBLCLK
)
736 lRet
= SendDlgItemMessage16(hWnd
, lst2
, LB_GETCURSEL16
, 0, 0);
737 if (lRet
== LB_ERR
) return TRUE
;
738 pstr
= SEGPTR_ALLOC(512);
739 SendDlgItemMessage16(hWnd
, lst2
, LB_GETTEXT16
, lRet
,
740 (LPARAM
)SEGPTR_GET(pstr
));
741 strcpy( tmpstr
, pstr
);
743 if (tmpstr
[0] == '[')
745 tmpstr
[strlen(tmpstr
) - 1] = 0;
746 strcpy(tmpstr
,tmpstr
+1);
748 strcat(tmpstr
, "\\");
752 case cmb1
: /* file type drop list */
753 if (notification
== CBN_SELCHANGE
)
763 case cmb2
: /* disk drop list */
764 FILEDLG_StripEditControl(hWnd
);
765 lRet
= SendDlgItemMessage16(hWnd
, cmb2
, CB_GETCURSEL16
, 0, 0L);
766 if (lRet
== LB_ERR
) return 0;
767 pstr
= SEGPTR_ALLOC(512);
768 SendDlgItemMessage16(hWnd
, cmb2
, CB_GETLBTEXT16
, lRet
,
769 (LPARAM
)SEGPTR_GET(pstr
));
770 sprintf(tmpstr
, "%c:", pstr
[2]);
773 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL16
, 0, 0);
776 pstr
= (LPSTR
)SendDlgItemMessage16(hWnd
, cmb1
, CB_GETITEMDATA16
, lRet
, 0);
777 TRACE(commdlg
,"Selected filter : %s\n", pstr
);
778 SetDlgItemText32A( hWnd
, edt1
, pstr
);
779 FILEDLG_ScanDir(hWnd
, tmpstr
);
783 ofn2
=*lpofn
; /* for later restoring */
784 GetDlgItemText32A( hWnd
, edt1
, tmpstr
, sizeof(tmpstr
) );
785 pstr
= strrchr(tmpstr
, '\\');
787 pstr
= strrchr(tmpstr
, ':');
788 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
790 /* edit control contains wildcards */
793 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
798 strcpy(tmpstr2
, tmpstr
);
801 TRACE(commdlg
,"tmpstr=%s, tmpstr2=%s\n", tmpstr
, tmpstr2
);
802 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
803 FILEDLG_ScanDir(hWnd
, tmpstr
);
806 /* no wildcards, we might have a directory or a filename */
807 /* try appending a wildcard and reading the directory */
808 pstr2
= tmpstr
+ strlen(tmpstr
);
809 if (pstr
== NULL
|| *(pstr
+1) != 0)
810 strcat(tmpstr
, "\\");
811 lRet
= SendDlgItemMessage16(hWnd
, cmb1
, CB_GETCURSEL16
, 0, 0);
812 if (lRet
== LB_ERR
) return TRUE
;
813 lpofn
->nFilterIndex
= lRet
+ 1;
814 TRACE(commdlg
,"lpofn->nFilterIndex=%ld\n", lpofn
->nFilterIndex
);
816 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
817 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
818 lRet
), sizeof(tmpstr2
));
819 SetDlgItemText32A( hWnd
, edt1
, tmpstr2
);
821 /* if ScanDir succeeds, we have changed the directory */
822 if (FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
823 /* if not, this must be a filename */
827 /* strip off the pathname */
829 SetDlgItemText32A( hWnd
, edt1
, pstr
+ 1 );
830 lstrcpyn32A(tmpstr2
, pstr
+1, sizeof(tmpstr2
) );
831 /* Should we MessageBox() if this fails? */
832 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
833 strcpy(tmpstr
, tmpstr2
);
835 else SetDlgItemText32A( hWnd
, edt1
, tmpstr
);
837 ShowWindow16(hWnd
, SW_HIDE
); /* this should not be necessary ?! (%%%) */
840 int drive
= DRIVE_GetCurrentDrive();
841 tmpstr2
[0] = 'A'+ drive
;
844 strncpy(tmpstr2
+ 3, DRIVE_GetDosCwd(drive
), 507); tmpstr2
[510]=0;
845 if (strlen(tmpstr2
) > 3)
846 strcat(tmpstr2
, "\\");
847 strncat(tmpstr2
, tmpstr
, 511-strlen(tmpstr2
)); tmpstr2
[511]=0;
848 if (lpofn
->lpstrFile
)
849 lstrcpyn32A(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), tmpstr2
,lpofn
->nMaxFile
);
851 lpofn
->nFileOffset
= strrchr(tmpstr2
,'\\') - tmpstr2
+1;
852 lpofn
->nFileExtension
= 0;
853 while(tmpstr2
[lpofn
->nFileExtension
] != '.' && tmpstr2
[lpofn
->nFileExtension
] != '\0')
854 lpofn
->nFileExtension
++;
855 if (tmpstr2
[lpofn
->nFileExtension
] == '\0')
856 lpofn
->nFileExtension
= 0;
858 lpofn
->nFileExtension
++;
862 if (FILEDLG_HookCallChk(lpofn
))
863 FILEDLG_CallWindowProc(lpofn
,hWnd
,
864 RegisterWindowMessage32A( LBSELCHSTRING
),
865 control
, MAKELONG(lRet
,CD_LBSELCHANGE
));
870 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
)
872 lRet
= SendDlgItemMessage16(hWnd
, lst1
, LB_GETCURSEL16
, 0, 0);
873 SendDlgItemMessage16(hWnd
, lst1
, LB_GETTEXT16
, lRet
,
874 lpofn
->lpstrFileTitle
);
876 if (FILEDLG_HookCallChk(lpofn
))
878 lRet
= (BOOL16
)FILEDLG_CallWindowProc(lpofn
,
879 hWnd
, RegisterWindowMessage32A( FILEOKSTRING
), 0, lParam
);
882 *lpofn
=ofn2
; /* restore old state */
884 ShowWindow16(hWnd
, SW_SHOW
); /* only if above (%%%) SW_HIDE used */
889 EndDialog32(hWnd
, TRUE
);
892 EndDialog32(hWnd
, FALSE
);
899 /***********************************************************************
900 * FileOpenDlgProc (COMMDLG.6)
902 LRESULT WINAPI
FileOpenDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
905 LPOPENFILENAME16 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
907 if (wMsg
!=WM_INITDIALOG
)
908 if (FILEDLG_HookCallChk(lpofn
))
910 LRESULT lRet
=(BOOL16
)FILEDLG_CallWindowProc(lpofn
,hWnd
,wMsg
,wParam
,lParam
);
912 return lRet
; /* else continue message processing */
917 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
919 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
921 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, FALSE
);
923 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
926 SetBkColor((HDC16
)wParam
, 0x00C0C0C0);
927 switch (HIWORD(lParam
))
930 SetTextColor((HDC16
)wParam
, 0x00000000);
932 case CTLCOLOR_STATIC
:
933 SetTextColor((HDC16
)wParam
, 0x00000000);
943 /***********************************************************************
944 * FileSaveDlgProc (COMMDLG.7)
946 LRESULT WINAPI
FileSaveDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
949 LPOPENFILENAME16 lpofn
= (LPOPENFILENAME16
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
951 if (wMsg
!=WM_INITDIALOG
)
952 if (FILEDLG_HookCallChk(lpofn
))
954 LRESULT lRet
=(BOOL16
)FILEDLG_CallWindowProc(lpofn
,hWnd
,wMsg
,wParam
,lParam
);
956 return lRet
; /* else continue message processing */
960 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
963 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
966 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
, TRUE
);
969 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
974 SetBkColor((HDC16)wParam, 0x00C0C0C0);
975 switch (HIWORD(lParam))
978 SetTextColor((HDC16)wParam, 0x00000000);
980 case CTLCOLOR_STATIC:
981 SetTextColor((HDC16)wParam, 0x00000000);
991 /***********************************************************************
992 * FindText16 (COMMDLG.11)
994 HWND16 WINAPI
FindText16( SEGPTR find
)
998 LPFINDREPLACE16 lpFind
= (LPFINDREPLACE16
)PTR_SEG_TO_LIN(find
);
1001 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1002 * For now, only the standard dialog works.
1004 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
1005 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
1006 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT
);
1007 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
1008 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
1009 (DLGPROC16
)MODULE_GetWndProcEntry16("FindTextDlgProc"),
1010 find
, WIN_PROC_16
);
1013 /***********************************************************************
1014 * FindText32A (COMMDLG.6)
1016 HWND32 WINAPI
FindText32A( LPFINDREPLACE32A lpFind
)
1022 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1023 * For now, only the standard dialog works.
1025 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
1026 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
1027 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT
);
1028 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
1029 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
1030 (DLGPROC16
)FindTextDlgProc32A
, (LPARAM
)lpFind
, WIN_PROC_32A
);
1033 /***********************************************************************
1034 * FindText32W (COMMDLG.7)
1036 HWND32 WINAPI
FindText32W( LPFINDREPLACE32W lpFind
)
1042 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1043 * For now, only the standard dialog works.
1045 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
1046 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
1047 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT
);
1048 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
1049 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
1050 (DLGPROC16
)FindTextDlgProc32W
, (LPARAM
)lpFind
, WIN_PROC_32W
);
1053 /***********************************************************************
1054 * ReplaceText16 (COMMDLG.12)
1056 HWND16 WINAPI
ReplaceText16( SEGPTR find
)
1060 LPFINDREPLACE16 lpFind
= (LPFINDREPLACE16
)PTR_SEG_TO_LIN(find
);
1063 * FIXME : We should do error checking on the lpFind structure here
1064 * and make CommDlgExtendedError() return the error condition.
1066 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
1067 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
1068 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT
);
1069 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
1070 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
1071 (DLGPROC16
)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
1072 find
, WIN_PROC_16
);
1075 /***********************************************************************
1076 * ReplaceText32A (COMDLG32.19)
1078 HWND32 WINAPI
ReplaceText32A( LPFINDREPLACE32A lpFind
)
1084 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1085 * For now, only the standard dialog works.
1087 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
1088 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
1089 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT
);
1090 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
1091 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
1092 (DLGPROC16
)ReplaceTextDlgProc32A
, (LPARAM
)lpFind
, WIN_PROC_32A
);
1095 /***********************************************************************
1096 * ReplaceText32W (COMDLG32.20)
1098 HWND32 WINAPI
ReplaceText32W( LPFINDREPLACE32W lpFind
)
1104 * FIXME : We should do error checking on the lpFind structure here
1105 * and make CommDlgExtendedError() return the error condition.
1107 if (lpFind
->Flags
& (FR_ENABLETEMPLATE
| FR_ENABLETEMPLATEHANDLE
|
1108 FR_ENABLEHOOK
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
1109 ptr
= SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT
);
1110 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
1111 return DIALOG_CreateIndirect( hInst
, ptr
, TRUE
, lpFind
->hwndOwner
,
1112 (DLGPROC16
)ReplaceTextDlgProc32W
, (LPARAM
)lpFind
, WIN_PROC_32W
);
1116 /***********************************************************************
1117 * FINDDLG_WMInitDialog [internal]
1119 static LRESULT
FINDDLG_WMInitDialog(HWND32 hWnd
, LPARAM lParam
, LPDWORD lpFlags
,
1120 LPSTR lpstrFindWhat
, BOOL32 fUnicode
)
1122 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
1123 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
1125 * FIXME : If the initial FindWhat string is empty, we should disable the
1126 * FindNext (IDOK) button. Only after typing some text, the button should be
1129 if (fUnicode
) SetDlgItemText32W(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
);
1130 else SetDlgItemText32A(hWnd
, edt1
, lpstrFindWhat
);
1131 CheckRadioButton32(hWnd
, rad1
, rad2
, (*lpFlags
& FR_DOWN
) ? rad2
: rad1
);
1132 if (*lpFlags
& (FR_HIDEUPDOWN
| FR_NOUPDOWN
)) {
1133 EnableWindow32(GetDlgItem32(hWnd
, rad1
), FALSE
);
1134 EnableWindow32(GetDlgItem32(hWnd
, rad2
), FALSE
);
1136 if (*lpFlags
& FR_HIDEUPDOWN
) {
1137 ShowWindow32(GetDlgItem32(hWnd
, rad1
), SW_HIDE
);
1138 ShowWindow32(GetDlgItem32(hWnd
, rad2
), SW_HIDE
);
1139 ShowWindow32(GetDlgItem32(hWnd
, grp1
), SW_HIDE
);
1141 CheckDlgButton32(hWnd
, chx1
, (*lpFlags
& FR_WHOLEWORD
) ? 1 : 0);
1142 if (*lpFlags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
1143 EnableWindow32(GetDlgItem32(hWnd
, chx1
), FALSE
);
1144 if (*lpFlags
& FR_HIDEWHOLEWORD
)
1145 ShowWindow32(GetDlgItem32(hWnd
, chx1
), SW_HIDE
);
1146 CheckDlgButton32(hWnd
, chx2
, (*lpFlags
& FR_MATCHCASE
) ? 1 : 0);
1147 if (*lpFlags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
1148 EnableWindow32(GetDlgItem32(hWnd
, chx2
), FALSE
);
1149 if (*lpFlags
& FR_HIDEMATCHCASE
)
1150 ShowWindow32(GetDlgItem32(hWnd
, chx2
), SW_HIDE
);
1151 if (!(*lpFlags
& FR_SHOWHELP
)) {
1152 EnableWindow32(GetDlgItem32(hWnd
, pshHelp
), FALSE
);
1153 ShowWindow32(GetDlgItem32(hWnd
, pshHelp
), SW_HIDE
);
1155 ShowWindow32(hWnd
, SW_SHOWNORMAL
);
1160 /***********************************************************************
1161 * FINDDLG_WMCommand [internal]
1163 static LRESULT
FINDDLG_WMCommand(HWND32 hWnd
, WPARAM32 wParam
,
1164 HWND32 hwndOwner
, LPDWORD lpFlags
,
1165 LPSTR lpstrFindWhat
, WORD wFindWhatLen
,
1168 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
1169 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
1174 GetDlgItemText32W(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
1175 else GetDlgItemText32A(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
1176 if (IsDlgButtonChecked32(hWnd
, rad2
))
1177 *lpFlags
|= FR_DOWN
;
1178 else *lpFlags
&= ~FR_DOWN
;
1179 if (IsDlgButtonChecked32(hWnd
, chx1
))
1180 *lpFlags
|= FR_WHOLEWORD
;
1181 else *lpFlags
&= ~FR_WHOLEWORD
;
1182 if (IsDlgButtonChecked32(hWnd
, chx2
))
1183 *lpFlags
|= FR_MATCHCASE
;
1184 else *lpFlags
&= ~FR_MATCHCASE
;
1185 *lpFlags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
1186 *lpFlags
|= FR_FINDNEXT
;
1187 SendMessage32A(hwndOwner
, uFindReplaceMessage
, 0,
1188 GetWindowLong32A(hWnd
, DWL_USER
) );
1191 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
1192 *lpFlags
|= FR_DIALOGTERM
;
1193 SendMessage32A(hwndOwner
, uFindReplaceMessage
, 0,
1194 GetWindowLong32A(hWnd
, DWL_USER
) );
1195 DestroyWindow32(hWnd
);
1198 /* FIXME : should lpfr structure be passed as an argument ??? */
1199 SendMessage32A(hwndOwner
, uHelpMessage
, 0, 0);
1206 /***********************************************************************
1207 * FindTextDlgProc16 (COMMDLG.13)
1209 LRESULT WINAPI
FindTextDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
1212 LPFINDREPLACE16 lpfr
;
1215 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(lParam
);
1216 return FINDDLG_WMInitDialog(hWnd
, lParam
, &(lpfr
->Flags
),
1217 PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
), FALSE
);
1219 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
1220 return FINDDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
1221 &lpfr
->Flags
, PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
1222 lpfr
->wFindWhatLen
, FALSE
);
1227 /***********************************************************************
1228 * FindTextDlgProc32A
1230 LRESULT WINAPI
FindTextDlgProc32A(HWND32 hWnd
, UINT32 wMsg
, WPARAM32 wParam
,
1233 LPFINDREPLACE32A lpfr
;
1236 lpfr
=(LPFINDREPLACE32A
)lParam
;
1237 return FINDDLG_WMInitDialog(hWnd
, lParam
, &(lpfr
->Flags
),
1238 lpfr
->lpstrFindWhat
, FALSE
);
1240 lpfr
=(LPFINDREPLACE32A
)GetWindowLong32A(hWnd
, DWL_USER
);
1241 return FINDDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
1242 &lpfr
->Flags
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
,
1248 /***********************************************************************
1249 * FindTextDlgProc32W
1251 LRESULT WINAPI
FindTextDlgProc32W(HWND32 hWnd
, UINT32 wMsg
, WPARAM32 wParam
,
1254 LPFINDREPLACE32W lpfr
;
1257 lpfr
=(LPFINDREPLACE32W
)lParam
;
1258 return FINDDLG_WMInitDialog(hWnd
, lParam
, &(lpfr
->Flags
),
1259 (LPSTR
)lpfr
->lpstrFindWhat
, TRUE
);
1261 lpfr
=(LPFINDREPLACE32W
)GetWindowLong32A(hWnd
, DWL_USER
);
1262 return FINDDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
1263 &lpfr
->Flags
, (LPSTR
)lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
,
1270 /***********************************************************************
1271 * REPLACEDLG_WMInitDialog [internal]
1273 static LRESULT
REPLACEDLG_WMInitDialog(HWND32 hWnd
, LPARAM lParam
,
1274 LPDWORD lpFlags
, LPSTR lpstrFindWhat
,
1275 LPSTR lpstrReplaceWith
, BOOL32 fUnicode
)
1277 SetWindowLong32A(hWnd
, DWL_USER
, lParam
);
1278 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
1280 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
1281 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
1286 SetDlgItemText32W(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
);
1287 SetDlgItemText32W(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
);
1290 SetDlgItemText32A(hWnd
, edt1
, lpstrFindWhat
);
1291 SetDlgItemText32A(hWnd
, edt2
, lpstrReplaceWith
);
1293 CheckDlgButton32(hWnd
, chx1
, (*lpFlags
& FR_WHOLEWORD
) ? 1 : 0);
1294 if (*lpFlags
& (FR_HIDEWHOLEWORD
| FR_NOWHOLEWORD
))
1295 EnableWindow32(GetDlgItem32(hWnd
, chx1
), FALSE
);
1296 if (*lpFlags
& FR_HIDEWHOLEWORD
)
1297 ShowWindow32(GetDlgItem32(hWnd
, chx1
), SW_HIDE
);
1298 CheckDlgButton32(hWnd
, chx2
, (*lpFlags
& FR_MATCHCASE
) ? 1 : 0);
1299 if (*lpFlags
& (FR_HIDEMATCHCASE
| FR_NOMATCHCASE
))
1300 EnableWindow32(GetDlgItem32(hWnd
, chx2
), FALSE
);
1301 if (*lpFlags
& FR_HIDEMATCHCASE
)
1302 ShowWindow32(GetDlgItem32(hWnd
, chx2
), SW_HIDE
);
1303 if (!(*lpFlags
& FR_SHOWHELP
)) {
1304 EnableWindow32(GetDlgItem32(hWnd
, pshHelp
), FALSE
);
1305 ShowWindow32(GetDlgItem32(hWnd
, pshHelp
), SW_HIDE
);
1307 ShowWindow32(hWnd
, SW_SHOWNORMAL
);
1312 /***********************************************************************
1313 * REPLACEDLG_WMCommand [internal]
1315 static LRESULT
REPLACEDLG_WMCommand(HWND32 hWnd
, WPARAM16 wParam
,
1316 HWND32 hwndOwner
, LPDWORD lpFlags
,
1317 LPSTR lpstrFindWhat
, WORD wFindWhatLen
,
1318 LPSTR lpstrReplaceWith
, WORD wReplaceWithLen
,
1321 int uFindReplaceMessage
= RegisterWindowMessage32A( FINDMSGSTRING
);
1322 int uHelpMessage
= RegisterWindowMessage32A( HELPMSGSTRING
);
1328 GetDlgItemText32W(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
1329 GetDlgItemText32W(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
1332 GetDlgItemText32A(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
1333 GetDlgItemText32A(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
1335 if (IsDlgButtonChecked32(hWnd
, chx1
))
1336 *lpFlags
|= FR_WHOLEWORD
;
1337 else *lpFlags
&= ~FR_WHOLEWORD
;
1338 if (IsDlgButtonChecked32(hWnd
, chx2
))
1339 *lpFlags
|= FR_MATCHCASE
;
1340 else *lpFlags
&= ~FR_MATCHCASE
;
1341 *lpFlags
&= ~(FR_REPLACE
| FR_REPLACEALL
| FR_DIALOGTERM
);
1342 *lpFlags
|= FR_FINDNEXT
;
1343 SendMessage32A(hwndOwner
, uFindReplaceMessage
, 0,
1344 GetWindowLong32A(hWnd
, DWL_USER
) );
1347 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_REPLACEALL
);
1348 *lpFlags
|= FR_DIALOGTERM
;
1349 SendMessage32A(hwndOwner
, uFindReplaceMessage
, 0,
1350 GetWindowLong32A(hWnd
, DWL_USER
) );
1351 DestroyWindow32(hWnd
);
1356 GetDlgItemText32W(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
1357 GetDlgItemText32W(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
1360 GetDlgItemText32A(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
1361 GetDlgItemText32A(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
1363 if (IsDlgButtonChecked32(hWnd
, chx1
))
1364 *lpFlags
|= FR_WHOLEWORD
;
1365 else *lpFlags
&= ~FR_WHOLEWORD
;
1366 if (IsDlgButtonChecked32(hWnd
, chx2
))
1367 *lpFlags
|= FR_MATCHCASE
;
1368 else *lpFlags
&= ~FR_MATCHCASE
;
1369 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACEALL
| FR_DIALOGTERM
);
1370 *lpFlags
|= FR_REPLACE
;
1371 SendMessage32A(hwndOwner
, uFindReplaceMessage
, 0,
1372 GetWindowLong32A(hWnd
, DWL_USER
) );
1377 GetDlgItemText32W(hWnd
, edt1
, (LPWSTR
)lpstrFindWhat
, wFindWhatLen
/2);
1378 GetDlgItemText32W(hWnd
, edt2
, (LPWSTR
)lpstrReplaceWith
, wReplaceWithLen
/2);
1381 GetDlgItemText32A(hWnd
, edt1
, lpstrFindWhat
, wFindWhatLen
);
1382 GetDlgItemText32A(hWnd
, edt2
, lpstrReplaceWith
, wReplaceWithLen
);
1384 if (IsDlgButtonChecked32(hWnd
, chx1
))
1385 *lpFlags
|= FR_WHOLEWORD
;
1386 else *lpFlags
&= ~FR_WHOLEWORD
;
1387 if (IsDlgButtonChecked32(hWnd
, chx2
))
1388 *lpFlags
|= FR_MATCHCASE
;
1389 else *lpFlags
&= ~FR_MATCHCASE
;
1390 *lpFlags
&= ~(FR_FINDNEXT
| FR_REPLACE
| FR_DIALOGTERM
);
1391 *lpFlags
|= FR_REPLACEALL
;
1392 SendMessage32A(hwndOwner
, uFindReplaceMessage
, 0,
1393 GetWindowLong32A(hWnd
, DWL_USER
) );
1396 /* FIXME : should lpfr structure be passed as an argument ??? */
1397 SendMessage32A(hwndOwner
, uHelpMessage
, 0, 0);
1404 /***********************************************************************
1405 * ReplaceTextDlgProc16 (COMMDLG.14)
1407 LRESULT WINAPI
ReplaceTextDlgProc16(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
1410 LPFINDREPLACE16 lpfr
;
1413 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(lParam
);
1414 return REPLACEDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
,
1415 PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
1416 PTR_SEG_TO_LIN(lpfr
->lpstrReplaceWith
), FALSE
);
1418 lpfr
=(LPFINDREPLACE16
)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd
, DWL_USER
));
1419 return REPLACEDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
1420 &lpfr
->Flags
, PTR_SEG_TO_LIN(lpfr
->lpstrFindWhat
),
1421 lpfr
->wFindWhatLen
, PTR_SEG_TO_LIN(lpfr
->lpstrReplaceWith
),
1422 lpfr
->wReplaceWithLen
, FALSE
);
1427 /***********************************************************************
1428 * ReplaceTextDlgProc32A
1430 LRESULT WINAPI
ReplaceTextDlgProc32A(HWND32 hWnd
, UINT32 wMsg
, WPARAM32 wParam
,
1433 LPFINDREPLACE32A lpfr
;
1436 lpfr
=(LPFINDREPLACE32A
)lParam
;
1437 return REPLACEDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
,
1438 lpfr
->lpstrFindWhat
, lpfr
->lpstrReplaceWith
, FALSE
);
1440 lpfr
=(LPFINDREPLACE32A
)GetWindowLong32A(hWnd
, DWL_USER
);
1441 return REPLACEDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
1442 &lpfr
->Flags
, lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
,
1443 lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
, FALSE
);
1448 /***********************************************************************
1449 * ReplaceTextDlgProc32W
1451 LRESULT WINAPI
ReplaceTextDlgProc32W(HWND32 hWnd
, UINT32 wMsg
, WPARAM32 wParam
,
1454 LPFINDREPLACE32W lpfr
;
1457 lpfr
=(LPFINDREPLACE32W
)lParam
;
1458 return REPLACEDLG_WMInitDialog(hWnd
, lParam
, &lpfr
->Flags
,
1459 (LPSTR
)lpfr
->lpstrFindWhat
, (LPSTR
)lpfr
->lpstrReplaceWith
,
1462 lpfr
=(LPFINDREPLACE32W
)GetWindowLong32A(hWnd
, DWL_USER
);
1463 return REPLACEDLG_WMCommand(hWnd
, wParam
, lpfr
->hwndOwner
,
1464 &lpfr
->Flags
, (LPSTR
)lpfr
->lpstrFindWhat
, lpfr
->wFindWhatLen
,
1465 (LPSTR
)lpfr
->lpstrReplaceWith
, lpfr
->wReplaceWithLen
, TRUE
);
1471 /***********************************************************************
1472 * PrintDlg16 (COMMDLG.20)
1474 BOOL16 WINAPI
PrintDlg16( SEGPTR printdlg
)
1477 BOOL16 bRet
= FALSE
;
1480 LPPRINTDLG16 lpPrint
= (LPPRINTDLG16
)PTR_SEG_TO_LIN(printdlg
);
1482 TRACE(commdlg
,"(%p) -- Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
1484 if (lpPrint
->Flags
& PD_RETURNDEFAULT
)
1485 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1488 if (lpPrint
->Flags
& PD_PRINTSETUP
)
1489 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP
);
1491 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT
);
1493 hInst
= WIN_GetWindowInstance( lpPrint
->hwndOwner
);
1494 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, TRUE
,
1496 (DLGPROC16
)((lpPrint
->Flags
& PD_PRINTSETUP
) ?
1497 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1498 MODULE_GetWndProcEntry16("PrintDlgProc")),
1499 printdlg
, WIN_PROC_16
);
1500 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpPrint
->hwndOwner
);
1505 /***********************************************************************
1506 * PrintDlg32A (COMDLG32.17)
1508 BOOL32 WINAPI
PrintDlg32A( LPPRINTDLG32A printdlg
)
1510 FIXME(commdlg
, "(%p): stub\n",printdlg
);
1511 /* Altough returning FALSE is theoricaly the right thing
1512 * most programs check for a printer at startup, and if
1513 * none is found popup PrintDlg32A(), if it fails the program
1514 * terminates; by returning TRUE the programs can still run
1515 * as long as no printer related stuff is used
1521 /***********************************************************************
1522 * PrintDlg32W (COMDLG32.18)
1524 BOOL32 WINAPI
PrintDlg32W( LPPRINTDLG32W printdlg
)
1526 FIXME(commdlg
, "empty stub\n" );
1531 /***********************************************************************
1532 * PrintDlgProc (COMMDLG.21)
1534 LRESULT WINAPI
PrintDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
1540 TRACE(commdlg
,"WM_INITDIALOG lParam=%08lX\n", lParam
);
1541 ShowWindow16(hWnd
, SW_SHOWNORMAL
);
1547 EndDialog32(hWnd
, TRUE
);
1550 EndDialog32(hWnd
, FALSE
);
1559 /***********************************************************************
1560 * PrintSetupDlgProc (COMMDLG.22)
1562 LRESULT WINAPI
PrintSetupDlgProc(HWND16 hWnd
, UINT16 wMsg
, WPARAM16 wParam
,
1568 TRACE(commdlg
,"WM_INITDIALOG lParam=%08lX\n", lParam
);
1569 ShowWindow16(hWnd
, SW_SHOWNORMAL
);
1574 EndDialog32(hWnd
, TRUE
);
1577 EndDialog32(hWnd
, FALSE
);
1586 /***********************************************************************
1587 * CommDlgExtendedError (COMMDLG.26)
1589 DWORD WINAPI
CommDlgExtendedError(void)
1591 return CommDlgLastError
;
1594 /***********************************************************************
1595 * GetFileTitleA (COMDLG32.8)
1597 short WINAPI
GetFileTitle32A(LPCSTR lpFile
, LPSTR lpTitle
, UINT32 cbBuf
)
1600 TRACE(commdlg
,"(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
1601 if (lpFile
== NULL
|| lpTitle
== NULL
)
1603 len
= strlen(lpFile
);
1606 if (strpbrk(lpFile
, "*[]"))
1609 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
1611 for (i
= len
; i
>= 0; i
--)
1612 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
1619 TRACE(commdlg
,"---> '%s' \n", &lpFile
[i
]);
1621 len
= strlen(lpFile
+i
)+1;
1625 strncpy(lpTitle
, &lpFile
[i
], len
);
1630 /***********************************************************************
1631 * GetFileTitleA (COMDLG32.8)
1633 short WINAPI
GetFileTitle32W(LPCWSTR lpFile
, LPWSTR lpTitle
, UINT32 cbBuf
)
1635 LPSTR file
= HEAP_strdupWtoA(GetProcessHeap(),0,lpFile
);
1636 LPSTR title
= HeapAlloc(GetProcessHeap(),0,cbBuf
);
1639 ret
= GetFileTitle32A(file
,title
,cbBuf
);
1641 lstrcpynAtoW(lpTitle
,title
,cbBuf
);
1642 HeapFree(GetProcessHeap(),0,file
);
1643 HeapFree(GetProcessHeap(),0,title
);
1646 /***********************************************************************
1647 * GetFileTitle (COMMDLG.27)
1649 short WINAPI
GetFileTitle16(LPCSTR lpFile
, LPSTR lpTitle
, UINT16 cbBuf
)
1651 return GetFileTitle32A(lpFile
,lpTitle
,cbBuf
);
1655 /* ------------------------ Choose Color Dialog --------------------------- */
1657 /***********************************************************************
1658 * ChooseColor (COMMDLG.5)
1660 BOOL16 WINAPI
ChooseColor16(LPCHOOSECOLOR16 lpChCol
)
1663 HANDLE16 hDlgTmpl
= 0;
1664 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
1668 TRACE(commdlg
,"ChooseColor\n");
1669 if (!lpChCol
) return FALSE
;
1671 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1673 if (!(template = LockResource16( lpChCol
->hInstance
)))
1675 CommDlgLastError
= CDERR_LOADRESFAILURE
;
1679 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1682 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
1683 lpChCol
->lpTemplateName
,
1686 CommDlgLastError
= CDERR_FINDRESFAILURE
;
1689 if (!(hDlgTmpl
= LoadResource16( lpChCol
->hInstance
, hResInfo
)) ||
1690 !(template = LockResource16( hDlgTmpl
)))
1692 CommDlgLastError
= CDERR_LOADRESFAILURE
;
1698 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR
);
1702 hInst
= WIN_GetWindowInstance( lpChCol
->hwndOwner
);
1703 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
1705 (DLGPROC16
)MODULE_GetWndProcEntry16("ColorDlgProc"),
1706 (DWORD
)lpChCol
, WIN_PROC_16
);
1707 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpChCol
->hwndOwner
);
1708 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
1714 static const COLORREF predefcolors
[6][8]=
1716 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
1717 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
1718 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
1719 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
1721 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
1722 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
1723 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
1724 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
1726 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
1727 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
1728 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
1729 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
1734 LPCHOOSECOLOR16 lpcc
; /* points to public known data structure */
1735 int nextuserdef
; /* next free place in user defined color array */
1736 HDC16 hdcMem
; /* color graph used for BitBlt() */
1737 HBITMAP16 hbmMem
; /* color graph bitmap */
1738 RECT16 fullsize
; /* original dialog window size */
1739 UINT16 msetrgb
; /* # of SETRGBSTRING message (today not used) */
1740 RECT16 old3angle
; /* last position of l-marker */
1741 RECT16 oldcross
; /* last position of color/satuation marker */
1742 BOOL32 updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1745 int l
; /* for temporary storing of hue,sat,lum */
1748 /***********************************************************************
1749 * CC_HSLtoRGB [internal]
1751 static int CC_HSLtoRGB(char c
,int hue
,int sat
,int lum
)
1758 case 'R':if (hue
>80) hue
-=80; else hue
+=160; break;
1759 case 'G':if (hue
>160) hue
-=160; else hue
+=80; break;
1764 maxrgb
=(256*MIN(120,lum
))/120; /* 0 .. 256 */
1770 res
=(hue
-80)* maxrgb
; /* 0...10240 */
1771 res
/=40; /* 0...256 */
1778 res
=(240-hue
)* maxrgb
;
1781 res
=res
-maxrgb
/2; /* -128...128 */
1784 res
=maxrgb
/2 + (sat
*res
) /240; /* 0..256 */
1787 if (lum
>120 && res
<256)
1788 res
+=((lum
-120) * (256-res
))/120;
1790 return MIN(res
,255);
1793 /***********************************************************************
1794 * CC_RGBtoHSL [internal]
1796 static int CC_RGBtoHSL(char c
,int r
,int g
,int b
)
1798 WORD maxi
,mini
,mmsum
,mmdif
,result
=0;
1812 case 'L':mmsum
*=120; /* 0...61200=(255+255)*120 */
1813 result
=mmsum
/255; /* 0...240 */
1816 case 'S':if (!mmsum
)
1819 if (!mini
|| maxi
==255)
1823 result
=mmdif
*240; /* 0...61200=255*240 */
1824 result
/= (mmsum
>255 ? mmsum
=510-mmsum
: mmsum
); /* 0..255 */
1828 case 'H':if (!mmdif
)
1834 iresult
=40*(g
-b
); /* -10200 ... 10200 */
1835 iresult
/=(int)mmdif
; /* -40 .. 40 */
1837 iresult
+=240; /* 0..40 and 200..240 */
1843 iresult
/=(int)mmdif
;
1844 iresult
+=80; /* 40 .. 120 */
1850 iresult
/=(int)mmdif
;
1851 iresult
+=160; /* 120 .. 200 */
1857 return result
; /* is this integer arithmetic precise enough ? */
1862 /***********************************************************************
1863 * CC_MouseCheckPredefColorArray [internal]
1865 static int CC_MouseCheckPredefColorArray(HWND16 hDlg
,int dlgitem
,int rows
,int cols
,
1866 LPARAM lParam
,COLORREF
*cr
)
1869 POINT16 point
= MAKEPOINT16(lParam
);
1873 ClientToScreen16(hDlg
,&point
);
1874 hwnd
=GetDlgItem32(hDlg
,dlgitem
);
1875 GetWindowRect16(hwnd
,&rect
);
1876 if (PtInRect16(&rect
,point
))
1878 dx
=(rect
.right
-rect
.left
)/cols
;
1879 dy
=(rect
.bottom
-rect
.top
)/rows
;
1880 ScreenToClient16(hwnd
,&point
);
1882 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1886 *cr
=predefcolors
[y
][x
];
1887 /* FIXME: Draw_a_Focus_Rect() */
1894 /***********************************************************************
1895 * CC_MouseCheckUserColorArray [internal]
1897 static int CC_MouseCheckUserColorArray(HWND16 hDlg
,int dlgitem
,int rows
,int cols
,
1898 LPARAM lParam
,COLORREF
*cr
,COLORREF
*crarr
)
1901 POINT16 point
= MAKEPOINT16(lParam
);
1905 ClientToScreen16(hDlg
,&point
);
1906 hwnd
=GetDlgItem32(hDlg
,dlgitem
);
1907 GetWindowRect16(hwnd
,&rect
);
1908 if (PtInRect16(&rect
,point
))
1910 dx
=(rect
.right
-rect
.left
)/cols
;
1911 dy
=(rect
.bottom
-rect
.top
)/rows
;
1912 ScreenToClient16(hwnd
,&point
);
1914 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
1918 *cr
=crarr
[x
+cols
*y
];
1919 /* FIXME: Draw_a_Focus_Rect() */
1929 /* 240 ^...... ^^ 240
1936 /***********************************************************************
1937 * CC_MouseCheckColorGraph [internal]
1939 static int CC_MouseCheckColorGraph(HWND16 hDlg
,int dlgitem
,int *hori
,int *vert
,LPARAM lParam
)
1942 POINT16 point
= MAKEPOINT16(lParam
);
1946 ClientToScreen16(hDlg
,&point
);
1947 hwnd
=GetDlgItem32(hDlg
,dlgitem
);
1948 GetWindowRect16(hwnd
,&rect
);
1949 if (PtInRect16(&rect
,point
))
1951 GetClientRect16(hwnd
,&rect
);
1952 ScreenToClient16(hwnd
,&point
);
1954 x
=(long)point
.x
*MAXHORI
;
1956 y
=(long)(rect
.bottom
-point
.y
)*MAXVERT
;
1968 /***********************************************************************
1969 * CC_MouseCheckResultWindow [internal]
1971 static int CC_MouseCheckResultWindow(HWND16 hDlg
,LPARAM lParam
)
1974 POINT16 point
= MAKEPOINT16(lParam
);
1977 ClientToScreen16(hDlg
,&point
);
1978 hwnd
=GetDlgItem32(hDlg
,0x2c5);
1979 GetWindowRect16(hwnd
,&rect
);
1980 if (PtInRect16(&rect
,point
))
1982 PostMessage16(hDlg
,WM_COMMAND
,0x2c9,0);
1988 /***********************************************************************
1989 * CC_CheckDigitsInEdit [internal]
1991 static int CC_CheckDigitsInEdit(HWND16 hwnd
,int maxval
)
1993 int i
,k
,m
,result
,value
;
1996 GetWindowText32A(hwnd
,buffer
,sizeof(buffer
));
2001 if (buffer
[i
]<'0' || buffer
[i
]>'9')
2003 for (k
=i
+1;k
<=m
;k
++) /* delete bad character */
2005 buffer
[i
]=buffer
[k
];
2013 if (value
>maxval
) /* build a new string */
2015 sprintf(buffer
,"%d",maxval
);
2020 editpos
=SendMessage16(hwnd
,EM_GETSEL16
,0,0);
2021 SetWindowText32A(hwnd
,buffer
);
2022 SendMessage16(hwnd
,EM_SETSEL16
,0,editpos
);
2029 /***********************************************************************
2030 * CC_PaintSelectedColor [internal]
2032 static void CC_PaintSelectedColor(HWND16 hDlg
,COLORREF cr
)
2037 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2c5);
2038 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
2041 GetClientRect16 (hwnd
, &rect
) ;
2042 hBrush
= CreateSolidBrush32(cr
);
2045 hBrush
= SelectObject32 (hdc
, hBrush
) ;
2046 Rectangle32(hdc
, rect
.left
,rect
.top
,rect
.right
/2,rect
.bottom
);
2047 DeleteObject32 (SelectObject32 (hdc
,hBrush
)) ;
2048 hBrush
=CreateSolidBrush32(GetNearestColor32(hdc
,cr
));
2051 hBrush
= SelectObject32 (hdc
, hBrush
) ;
2052 Rectangle32( hdc
, rect
.right
/2-1,rect
.top
,rect
.right
,rect
.bottom
);
2053 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
2056 ReleaseDC32(hwnd
,hdc
);
2060 /***********************************************************************
2061 * CC_PaintTriangle [internal]
2063 static void CC_PaintTriangle(HWND16 hDlg
,int y
)
2067 int w
=GetDialogBaseUnits();
2072 HWND16 hwnd
=GetDlgItem32(hDlg
,0x2be);
2073 struct CCPRIVATE
*lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2075 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
2077 GetClientRect16(hwnd
,&rect
);
2081 points
[0].y
=rect
.top
;
2082 points
[0].x
=rect
.right
; /* | /| */
2083 ClientToScreen16(hwnd
,points
); /* | / | */
2084 ScreenToClient16(hDlg
,points
); /* |< | */
2085 oben
=points
[0].y
; /* | \ | */
2087 temp
=(long)height
*(long)y
;
2088 points
[0].y
=oben
+height
-temp
/(long)MAXVERT
;
2089 points
[1].y
=points
[0].y
+w
;
2090 points
[2].y
=points
[0].y
-w
;
2091 points
[2].x
=points
[1].x
=points
[0].x
+ w
;
2093 if (lpp
->old3angle
.left
)
2094 FillRect16(hDC
,&lpp
->old3angle
,GetStockObject32(WHITE_BRUSH
));
2095 lpp
->old3angle
.left
=points
[0].x
;
2096 lpp
->old3angle
.right
=points
[1].x
+1;
2097 lpp
->old3angle
.top
=points
[2].y
-1;
2098 lpp
->old3angle
.bottom
=points
[1].y
+1;
2099 Polygon16(hDC
,points
,3);
2100 ReleaseDC32(hDlg
,hDC
);
2105 /***********************************************************************
2106 * CC_PaintCross [internal]
2108 static void CC_PaintCross(HWND16 hDlg
,int x
,int y
)
2111 int w
=GetDialogBaseUnits();
2112 HWND16 hwnd
=GetDlgItem32(hDlg
,0x2c6);
2113 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2118 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
2120 GetClientRect16(hwnd
,&rect
);
2122 SelectClipRgn32(hDC
,CreateRectRgnIndirect16(&rect
));
2123 hPen
=CreatePen32(PS_SOLID
,2,0);
2124 hPen
=SelectObject32(hDC
,hPen
);
2125 point
.x
=((long)rect
.right
*(long)x
)/(long)MAXHORI
;
2126 point
.y
=rect
.bottom
-((long)rect
.bottom
*(long)y
)/(long)MAXVERT
;
2127 if (lpp
->oldcross
.left
!=lpp
->oldcross
.right
)
2128 BitBlt32(hDC
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,
2129 lpp
->oldcross
.right
-lpp
->oldcross
.left
,
2130 lpp
->oldcross
.bottom
-lpp
->oldcross
.top
,
2131 lpp
->hdcMem
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,SRCCOPY
);
2132 lpp
->oldcross
.left
=point
.x
-w
-1;
2133 lpp
->oldcross
.right
=point
.x
+w
+1;
2134 lpp
->oldcross
.top
=point
.y
-w
-1;
2135 lpp
->oldcross
.bottom
=point
.y
+w
+1;
2137 MoveTo(hDC
,point
.x
-w
,point
.y
);
2138 LineTo32(hDC
,point
.x
+w
,point
.y
);
2139 MoveTo(hDC
,point
.x
,point
.y
-w
);
2140 LineTo32(hDC
,point
.x
,point
.y
+w
);
2141 DeleteObject32(SelectObject32(hDC
,hPen
));
2142 ReleaseDC32(hwnd
,hDC
);
2151 /***********************************************************************
2152 * CC_PrepareColorGraph [internal]
2154 static void CC_PrepareColorGraph(HWND16 hDlg
)
2156 int sdif
,hdif
,xdif
,ydif
,r
,g
,b
,hue
,sat
;
2157 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2c6);
2158 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2162 HCURSOR16 hcursor
=SetCursor16(LoadCursor16(0,IDC_WAIT16
));
2164 GetClientRect16(hwnd
,&client
);
2166 lpp
->hdcMem
= CreateCompatibleDC32(hdc
);
2167 lpp
->hbmMem
= CreateCompatibleBitmap32(hdc
,client
.right
,client
.bottom
);
2168 SelectObject32(lpp
->hdcMem
,lpp
->hbmMem
);
2170 xdif
=client
.right
/XSTEPS
;
2171 ydif
=client
.bottom
/YSTEPS
+1;
2174 for(rect
.left
=hue
=0;hue
<239+hdif
;hue
+=hdif
)
2176 rect
.right
=rect
.left
+xdif
;
2177 rect
.bottom
=client
.bottom
;
2178 for(sat
=0;sat
<240+sdif
;sat
+=sdif
)
2180 rect
.top
=rect
.bottom
-ydif
;
2181 r
=CC_HSLtoRGB('R',hue
,sat
,120);
2182 g
=CC_HSLtoRGB('G',hue
,sat
,120);
2183 b
=CC_HSLtoRGB('B',hue
,sat
,120);
2184 hbrush
=CreateSolidBrush32(RGB(r
,g
,b
));
2185 FillRect16(lpp
->hdcMem
,&rect
,hbrush
);
2186 DeleteObject32(hbrush
);
2187 rect
.bottom
=rect
.top
;
2189 rect
.left
=rect
.right
;
2191 ReleaseDC32(hwnd
,hdc
);
2192 SetCursor16(hcursor
);
2195 /***********************************************************************
2196 * CC_PaintColorGraph [internal]
2198 static void CC_PaintColorGraph(HWND16 hDlg
)
2200 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2c6);
2201 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2204 if (IsWindowVisible32(hwnd
)) /* if full size */
2207 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
2210 GetClientRect16(hwnd
,&rect
);
2212 BitBlt32(hDC
,0,0,rect
.right
,rect
.bottom
,lpp
->hdcMem
,0,0,SRCCOPY
);
2214 WARN(commdlg
,"choose color: hdcMem is not defined\n");
2215 ReleaseDC32(hwnd
,hDC
);
2218 /***********************************************************************
2219 * CC_PaintLumBar [internal]
2221 static void CC_PaintLumBar(HWND16 hDlg
,int hue
,int sat
)
2223 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2be);
2225 int lum
,ldif
,ydif
,r
,g
,b
;
2229 if (IsWindowVisible32(hwnd
))
2232 GetClientRect16(hwnd
,&client
);
2236 ydif
=client
.bottom
/YSTEPS
+1;
2237 for(lum
=0;lum
<240+ldif
;lum
+=ldif
)
2239 rect
.top
=MAX(0,rect
.bottom
-ydif
);
2240 r
=CC_HSLtoRGB('R',hue
,sat
,lum
);
2241 g
=CC_HSLtoRGB('G',hue
,sat
,lum
);
2242 b
=CC_HSLtoRGB('B',hue
,sat
,lum
);
2243 hbrush
=CreateSolidBrush32(RGB(r
,g
,b
));
2244 FillRect16(hDC
,&rect
,hbrush
);
2245 DeleteObject32(hbrush
);
2246 rect
.bottom
=rect
.top
;
2248 GetClientRect16(hwnd
,&rect
);
2249 FrameRect16(hDC
,&rect
,GetStockObject32(BLACK_BRUSH
));
2250 ReleaseDC32(hwnd
,hDC
);
2254 /***********************************************************************
2255 * CC_EditSetRGB [internal]
2257 static void CC_EditSetRGB(HWND16 hDlg
,COLORREF cr
)
2260 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2261 int r
=GetRValue(cr
);
2262 int g
=GetGValue(cr
);
2263 int b
=GetBValue(cr
);
2264 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
2267 sprintf(buffer
,"%d",r
);
2268 SetWindowText32A(GetDlgItem32(hDlg
,0x2c2),buffer
);
2269 sprintf(buffer
,"%d",g
);
2270 SetWindowText32A(GetDlgItem32(hDlg
,0x2c3),buffer
);
2271 sprintf(buffer
,"%d",b
);
2272 SetWindowText32A(GetDlgItem32(hDlg
,0x2c4),buffer
);
2273 lpp
->updating
=FALSE
;
2277 /***********************************************************************
2278 * CC_EditSetHSL [internal]
2280 static void CC_EditSetHSL(HWND16 hDlg
,int h
,int s
,int l
)
2283 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2285 if (IsWindowVisible32(GetDlgItem32(hDlg
,0x2c6))) /* if full size */
2288 sprintf(buffer
,"%d",h
);
2289 SetWindowText32A(GetDlgItem32(hDlg
,0x2bf),buffer
);
2290 sprintf(buffer
,"%d",s
);
2291 SetWindowText32A(GetDlgItem32(hDlg
,0x2c0),buffer
);
2292 sprintf(buffer
,"%d",l
);
2293 SetWindowText32A(GetDlgItem32(hDlg
,0x2c1),buffer
);
2294 lpp
->updating
=FALSE
;
2296 CC_PaintLumBar(hDlg
,h
,s
);
2299 /***********************************************************************
2300 * CC_SwitchToFullSize [internal]
2302 static void CC_SwitchToFullSize(HWND16 hDlg
,COLORREF result
,LPRECT16 lprect
)
2305 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2307 EnableWindow32(GetDlgItem32(hDlg
,0x2cf),FALSE
);
2308 CC_PrepareColorGraph(hDlg
);
2309 for (i
=0x2bf;i
<0x2c5;i
++)
2310 EnableWindow32(GetDlgItem32(hDlg
,i
),TRUE
);
2311 for (i
=0x2d3;i
<0x2d9;i
++)
2312 EnableWindow32(GetDlgItem32(hDlg
,i
),TRUE
);
2313 EnableWindow32(GetDlgItem32(hDlg
,0x2c9),TRUE
);
2314 EnableWindow32(GetDlgItem32(hDlg
,0x2c8),TRUE
);
2317 SetWindowPos32(hDlg
,0,0,0,lprect
->right
-lprect
->left
,
2318 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
2320 ShowWindow32(GetDlgItem32(hDlg
,0x2c6),SW_SHOW
);
2321 ShowWindow32(GetDlgItem32(hDlg
,0x2be),SW_SHOW
);
2322 ShowWindow32(GetDlgItem32(hDlg
,0x2c5),SW_SHOW
);
2324 CC_EditSetRGB(hDlg
,result
);
2325 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2328 /***********************************************************************
2329 * CC_PaintPredefColorArray [internal]
2331 static void CC_PaintPredefColorArray(HWND16 hDlg
,int rows
,int cols
)
2333 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2d0);
2339 GetClientRect16(hwnd
,&rect
);
2341 dy
=rect
.bottom
/rows
;
2345 GetClientRect16 (hwnd
, &rect
) ;
2347 for (j
=0;j
<rows
;j
++)
2349 for (i
=0;i
<cols
;i
++)
2351 hBrush
= CreateSolidBrush32(predefcolors
[j
][i
]);
2354 hBrush
= SelectObject32 (hdc
, hBrush
) ;
2355 Rectangle32(hdc
, rect
.left
, rect
.top
,
2356 rect
.left
+dx
-DISTANCE
, rect
.top
+dy
-DISTANCE
);
2357 rect
.left
=rect
.left
+dx
;
2358 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
2361 rect
.top
=rect
.top
+dy
;
2364 ReleaseDC32(hwnd
,hdc
);
2365 /* FIXME: draw_a_focus_rect */
2367 /***********************************************************************
2368 * CC_PaintUserColorArray [internal]
2370 static void CC_PaintUserColorArray(HWND16 hDlg
,int rows
,int cols
,COLORREF
* lpcr
)
2372 HWND32 hwnd
=GetDlgItem32(hDlg
,0x2d1);
2378 GetClientRect16(hwnd
,&rect
);
2381 dy
=rect
.bottom
/rows
;
2387 for (j
=0;j
<rows
;j
++)
2389 for (i
=0;i
<cols
;i
++)
2391 hBrush
= CreateSolidBrush32(lpcr
[i
+j
*cols
]);
2394 hBrush
= SelectObject32 (hdc
, hBrush
) ;
2395 Rectangle32( hdc
, rect
.left
, rect
.top
,
2396 rect
.left
+dx
-DISTANCE
, rect
.top
+dy
-DISTANCE
);
2397 rect
.left
=rect
.left
+dx
;
2398 DeleteObject32( SelectObject32 (hdc
, hBrush
)) ;
2401 rect
.top
=rect
.top
+dy
;
2404 ReleaseDC32(hwnd
,hdc
);
2406 /* FIXME: draw_a_focus_rect */
2411 /***********************************************************************
2412 * CC_HookCallChk [internal]
2414 static BOOL32
CC_HookCallChk(LPCHOOSECOLOR16 lpcc
)
2417 if(lpcc
->Flags
& CC_ENABLEHOOK
)
2423 /***********************************************************************
2424 * CC_WMInitDialog [internal]
2426 static LONG
CC_WMInitDialog(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2433 struct CCPRIVATE
* lpp
;
2435 TRACE(commdlg
,"WM_INITDIALOG lParam=%08lX\n", lParam
);
2436 lpp
=calloc(1,sizeof(struct CCPRIVATE
));
2437 lpp
->lpcc
=(LPCHOOSECOLOR16
)lParam
;
2439 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLOR16
))
2441 EndDialog32 (hDlg
, 0) ;
2444 SetWindowLong32A(hDlg
, DWL_USER
, (LONG
)lpp
);
2446 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
2447 ShowWindow32(GetDlgItem32(hDlg
,0x40e),SW_HIDE
);
2448 lpp
->msetrgb
=RegisterWindowMessage32A( SETRGBSTRING
);
2451 cpos
=MAKELONG(5,7); /* init */
2452 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
2456 if (predefcolors
[i
][j
]==lpp
->lpcc
->rgbResult
)
2463 /* FIXME: Draw_a_focus_rect & set_init_values */
2466 GetWindowRect16(hDlg
,&lpp
->fullsize
);
2467 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
2469 hwnd
=GetDlgItem32(hDlg
,0x2cf);
2470 EnableWindow32(hwnd
,FALSE
);
2472 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
2475 res
=rect
.bottom
-rect
.top
;
2476 hwnd
=GetDlgItem32(hDlg
,0x2c6); /* cut at left border */
2478 ClientToScreen16(hwnd
,&point
);
2479 ScreenToClient16(hDlg
,&point
);
2480 GetClientRect16(hDlg
,&rect
);
2481 point
.x
+=GetSystemMetrics32(SM_CXDLGFRAME
);
2482 SetWindowPos32(hDlg
,0,0,0,point
.x
,res
,SWP_NOMOVE
|SWP_NOZORDER
);
2484 ShowWindow32(GetDlgItem32(hDlg
,0x2c6),SW_HIDE
);
2485 ShowWindow32(GetDlgItem32(hDlg
,0x2c5),SW_HIDE
);
2488 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,NULL
);
2490 for (i
=0x2bf;i
<0x2c5;i
++)
2491 SendMessage16(GetDlgItem32(hDlg
,i
),EM_LIMITTEXT16
,3,0); /* max 3 digits: xyz */
2492 if (CC_HookCallChk(lpp
->lpcc
))
2493 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
2496 /* Set the initial values of the color chooser dialog */
2497 r
= GetRValue(lpp
->lpcc
->rgbResult
);
2498 g
= GetGValue(lpp
->lpcc
->rgbResult
);
2499 b
= GetBValue(lpp
->lpcc
->rgbResult
);
2501 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2502 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2503 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2504 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2506 /* Doing it the long way becaus CC_EditSetRGB/HSL doesn'nt seem to work */
2507 SetDlgItemInt32(hDlg
, 703, lpp
->h
, TRUE
);
2508 SetDlgItemInt32(hDlg
, 704, lpp
->s
, TRUE
);
2509 SetDlgItemInt32(hDlg
, 705, lpp
->l
, TRUE
);
2510 SetDlgItemInt32(hDlg
, 706, r
, TRUE
);
2511 SetDlgItemInt32(hDlg
, 707, g
, TRUE
);
2512 SetDlgItemInt32(hDlg
, 708, b
, TRUE
);
2514 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2515 CC_PaintTriangle(hDlg
,lpp
->l
);
2520 /***********************************************************************
2521 * CC_WMCommand [internal]
2523 static LRESULT
CC_WMCommand(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2529 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2530 TRACE(commdlg
,"CC_WMCommand wParam=%x lParam=%lx\n",wParam
,lParam
);
2533 case 0x2c2: /* edit notify RGB */
2536 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
2538 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),255);
2539 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2540 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2541 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2545 case 0x2c2:if ((xx
=(i
!=r
))) r
=i
;break;
2546 case 0x2c3:if ((xx
=(i
!=g
))) g
=i
;break;
2547 case 0x2c4:if ((xx
=(i
!=b
))) b
=i
;break;
2549 if (xx
) /* something has changed */
2551 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2552 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2553 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2554 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2555 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2556 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2557 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2558 CC_PaintTriangle(hDlg
,lpp
->l
);
2563 case 0x2bf: /* edit notify HSL */
2566 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
2568 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),wParam
==0x2bf?239:240);
2572 case 0x2bf:if ((xx
=(i
!=lpp
->h
))) lpp
->h
=i
;break;
2573 case 0x2c0:if ((xx
=(i
!=lpp
->s
))) lpp
->s
=i
;break;
2574 case 0x2c1:if ((xx
=(i
!=lpp
->l
))) lpp
->l
=i
;break;
2576 if (xx
) /* something has changed */
2578 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
2579 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
2580 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
2581 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2582 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2583 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2584 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2585 CC_PaintTriangle(hDlg
,lpp
->l
);
2591 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,&lpp
->fullsize
);
2592 InvalidateRect32( hDlg
, NULL
, TRUE
);
2593 SetFocus32(GetDlgItem32(hDlg
,0x2bf));
2596 case 0x2c8: /* add colors ... column by column */
2597 cr
=PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
);
2598 cr
[(lpp
->nextuserdef
%2)*8 + lpp
->nextuserdef
/2]=lpp
->lpcc
->rgbResult
;
2599 if (++lpp
->nextuserdef
==16)
2601 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2604 case 0x2c9: /* resulting color */
2606 lpp
->lpcc
->rgbResult
=GetNearestColor32(hdc
,lpp
->lpcc
->rgbResult
);
2607 ReleaseDC32(hDlg
,hdc
);
2608 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2609 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2610 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2611 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2612 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2613 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2614 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2615 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2616 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2617 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2618 CC_PaintTriangle(hDlg
,lpp
->l
);
2621 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2622 i
=RegisterWindowMessage32A( HELPMSGSTRING
);
2623 if (lpp
->lpcc
->hwndOwner
)
2624 SendMessage16(lpp
->lpcc
->hwndOwner
,i
,0,(LPARAM
)lpp
->lpcc
);
2625 if (CC_HookCallChk(lpp
->lpcc
))
2626 CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,
2627 WM_COMMAND
,psh15
,(LPARAM
)lpp
->lpcc
);
2631 cokmsg
=RegisterWindowMessage32A( COLOROKSTRING
);
2632 if (lpp
->lpcc
->hwndOwner
)
2633 if (SendMessage16(lpp
->lpcc
->hwndOwner
,cokmsg
,0,(LPARAM
)lpp
->lpcc
))
2634 break; /* do NOT close */
2636 EndDialog32 (hDlg
, 1) ;
2640 EndDialog32 (hDlg
, 0) ;
2647 /***********************************************************************
2648 * CC_WMPaint [internal]
2650 static LRESULT
CC_WMPaint(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2654 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2656 hdc
=BeginPaint32(hDlg
,&ps
);
2657 EndPaint32(hDlg
,&ps
);
2658 /* we have to paint dialog children except text and buttons */
2660 CC_PaintPredefColorArray(hDlg
,6,8);
2661 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
2662 CC_PaintColorGraph(hDlg
);
2663 CC_PaintLumBar(hDlg
,lpp
->h
,lpp
->s
);
2664 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2665 CC_PaintTriangle(hDlg
,lpp
->l
);
2666 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2668 /* special necessary for Wine */
2669 ValidateRect32(GetDlgItem32(hDlg
,0x2d0),NULL
);
2670 ValidateRect32(GetDlgItem32(hDlg
,0x2d1),NULL
);
2671 ValidateRect32(GetDlgItem32(hDlg
,0x2c6),NULL
);
2672 ValidateRect32(GetDlgItem32(hDlg
,0x2be),NULL
);
2673 ValidateRect32(GetDlgItem32(hDlg
,0x2c5),NULL
);
2674 /* hope we can remove it later -->FIXME */
2679 /***********************************************************************
2680 * CC_WMLButtonDown [internal]
2682 static LRESULT
CC_WMLButtonDown(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
2684 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2687 if (CC_MouseCheckPredefColorArray(hDlg
,0x2d0,6,8,lParam
,&lpp
->lpcc
->rgbResult
))
2690 if (CC_MouseCheckUserColorArray(hDlg
,0x2d1,2,8,lParam
,&lpp
->lpcc
->rgbResult
,
2691 PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
)))
2694 if (CC_MouseCheckColorGraph(hDlg
,0x2c6,&lpp
->h
,&lpp
->s
,lParam
))
2697 if (CC_MouseCheckColorGraph(hDlg
,0x2be,NULL
,&lpp
->l
,lParam
))
2701 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
2702 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
2703 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
2704 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
2708 r
=GetRValue(lpp
->lpcc
->rgbResult
);
2709 g
=GetGValue(lpp
->lpcc
->rgbResult
);
2710 b
=GetBValue(lpp
->lpcc
->rgbResult
);
2711 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
2712 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
2713 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
2717 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
2718 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
2719 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
2720 CC_PaintTriangle(hDlg
,lpp
->l
);
2721 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
2727 /***********************************************************************
2728 * ColorDlgProc (COMMDLG.8)
2730 LRESULT WINAPI
ColorDlgProc(HWND16 hDlg
, UINT16 message
,
2731 WPARAM16 wParam
, LONG lParam
)
2734 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLong32A(hDlg
, DWL_USER
);
2735 if (message
!=WM_INITDIALOG
)
2740 if (CC_HookCallChk(lpp
->lpcc
))
2741 res
=CallWindowProc16(lpp
->lpcc
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
2746 /* FIXME: SetRGB message
2747 if (message && message==msetrgb)
2748 return HandleSetRGB(hDlg,lParam);
2754 return CC_WMInitDialog(hDlg
,wParam
,lParam
);
2756 DeleteDC32(lpp
->hdcMem
);
2757 DeleteObject32(lpp
->hbmMem
);
2759 SetWindowLong32A(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
2762 if (CC_WMCommand(hDlg
, wParam
, lParam
))
2766 if (CC_WMPaint(hDlg
, wParam
, lParam
))
2769 case WM_LBUTTONDBLCLK
:
2770 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
2773 case WM_MOUSEMOVE
: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2775 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
2777 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
2778 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
2785 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16
, LPCHOOSEFONT32A chf32a
)
2787 chf32a
->lStructSize
=sizeof(CHOOSEFONT32A
);
2788 chf32a
->hwndOwner
=chf16
->hwndOwner
;
2789 chf32a
->hDC
=chf16
->hDC
;
2790 chf32a
->iPointSize
=chf16
->iPointSize
;
2791 chf32a
->Flags
=chf16
->Flags
;
2792 chf32a
->rgbColors
=chf16
->rgbColors
;
2793 chf32a
->lCustData
=chf16
->lCustData
;
2794 chf32a
->lpfnHook
=NULL
;
2795 chf32a
->lpTemplateName
=PTR_SEG_TO_LIN(chf16
->lpTemplateName
);
2796 chf32a
->hInstance
=chf16
->hInstance
;
2797 chf32a
->lpszStyle
=PTR_SEG_TO_LIN(chf16
->lpszStyle
);
2798 chf32a
->nFontType
=chf16
->nFontType
;
2799 chf32a
->nSizeMax
=chf16
->nSizeMax
;
2800 chf32a
->nSizeMin
=chf16
->nSizeMin
;
2801 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16
->lpLogFont
), chf32a
->lpLogFont
);
2805 /***********************************************************************
2806 * ChooseFont16 (COMMDLG.15)
2808 BOOL16 WINAPI
ChooseFont16(LPCHOOSEFONT16 lpChFont
)
2811 HANDLE16 hDlgTmpl
= 0;
2812 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
2815 CHOOSEFONT32A cf32a
;
2817 SEGPTR lpTemplateName
;
2819 cf32a
.lpLogFont
=&lf32a
;
2820 CFn_CHOOSEFONT16to32A(lpChFont
, &cf32a
);
2822 TRACE(commdlg
,"ChooseFont\n");
2823 if (!lpChFont
) return FALSE
;
2825 if (lpChFont
->Flags
& CF_ENABLETEMPLATEHANDLE
)
2827 if (!(template = LockResource16( lpChFont
->hInstance
)))
2829 CommDlgLastError
= CDERR_LOADRESFAILURE
;
2833 else if (lpChFont
->Flags
& CF_ENABLETEMPLATE
)
2836 if (!(hResInfo
= FindResource16( lpChFont
->hInstance
,
2837 lpChFont
->lpTemplateName
,
2840 CommDlgLastError
= CDERR_FINDRESFAILURE
;
2843 if (!(hDlgTmpl
= LoadResource16( lpChFont
->hInstance
, hResInfo
)) ||
2844 !(template = LockResource16( hDlgTmpl
)))
2846 CommDlgLastError
= CDERR_LOADRESFAILURE
;
2852 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT
);
2856 hInst
= WIN_GetWindowInstance( lpChFont
->hwndOwner
);
2858 /* lpTemplateName is not used in the dialog */
2859 lpTemplateName
=lpChFont
->lpTemplateName
;
2860 lpChFont
->lpTemplateName
=(SEGPTR
)&cf32a
;
2862 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
2863 lpChFont
->hwndOwner
,
2864 (DLGPROC16
)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2865 (DWORD
)lpChFont
, WIN_PROC_16
);
2866 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
2867 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
2868 lpChFont
->lpTemplateName
=lpTemplateName
;
2869 FONT_LogFont32ATo16(cf32a
.lpLogFont
,
2870 (LPLOGFONT16
)(PTR_SEG_TO_LIN(lpChFont
->lpLogFont
)));
2875 /***********************************************************************
2876 * ChooseFont32A (COMDLG32.3)
2878 BOOL32 WINAPI
ChooseFont32A(LPCHOOSEFONT32A lpChFont
)
2882 HINSTANCE32 hInst
=WIN_GetWindowInstance( lpChFont
->hwndOwner
);
2883 LPCVOID
template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT
);
2884 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
2885 CF_ENABLETEMPLATEHANDLE
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
2886 hwndDialog
= DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
2887 (DLGPROC16
)FormatCharDlgProc32A
, (LPARAM
)lpChFont
, WIN_PROC_32A
);
2888 if (hwndDialog
) bRet
= DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
2892 /***********************************************************************
2893 * ChooseFont32W (COMDLG32.4)
2895 BOOL32 WINAPI
ChooseFont32W(LPCHOOSEFONT32W lpChFont
)
2899 HINSTANCE32 hInst
=WIN_GetWindowInstance( lpChFont
->hwndOwner
);
2900 CHOOSEFONT32A cf32a
;
2902 LPCVOID
template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT
);
2903 if (lpChFont
->Flags
& (CF_SELECTSCRIPT
| CF_NOVERTFONTS
| CF_ENABLETEMPLATE
|
2904 CF_ENABLETEMPLATEHANDLE
)) FIXME(commdlg
, ": unimplemented flag (ignored)\n");
2905 memcpy(&cf32a
, lpChFont
, sizeof(cf32a
));
2906 memcpy(&lf32a
, lpChFont
->lpLogFont
, sizeof(LOGFONT32A
));
2907 lstrcpynWtoA(lf32a
.lfFaceName
, lpChFont
->lpLogFont
->lfFaceName
, LF_FACESIZE
);
2908 cf32a
.lpLogFont
=&lf32a
;
2909 cf32a
.lpszStyle
=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont
->lpszStyle
);
2910 lpChFont
->lpTemplateName
=(LPWSTR
)&cf32a
;
2911 hwndDialog
=DIALOG_CreateIndirect(hInst
, template, TRUE
, lpChFont
->hwndOwner
,
2912 (DLGPROC16
)FormatCharDlgProc32W
, (LPARAM
)lpChFont
, WIN_PROC_32W
);
2913 if (hwndDialog
)bRet
=DIALOG_DoDialogBox(hwndDialog
, lpChFont
->hwndOwner
);
2914 HeapFree(GetProcessHeap(), 0, cf32a
.lpszStyle
);
2915 lpChFont
->lpTemplateName
=(LPWSTR
)cf32a
.lpTemplateName
;
2916 memcpy(lpChFont
->lpLogFont
, &lf32a
, sizeof(CHOOSEFONT32A
));
2917 lstrcpynAtoW(lpChFont
->lpLogFont
->lfFaceName
, lf32a
.lfFaceName
, LF_FACESIZE
);
2922 #define TEXT_EXTRAS 4
2923 #define TEXT_COLORS 16
2925 static const COLORREF textcolors
[TEXT_COLORS
]=
2927 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
2928 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
2929 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
2930 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
2933 /***********************************************************************
2934 * CFn_HookCallChk [internal]
2936 static BOOL32
CFn_HookCallChk(LPCHOOSEFONT16 lpcf
)
2939 if(lpcf
->Flags
& CF_ENABLEHOOK
)
2945 /***********************************************************************
2946 * CFn_HookCallChk32 [internal]
2948 static BOOL32
CFn_HookCallChk32(LPCHOOSEFONT32A lpcf
)
2951 if(lpcf
->Flags
& CF_ENABLEHOOK
)
2958 /*************************************************************************
2959 * AddFontFamily [internal]
2961 static INT32
AddFontFamily(LPLOGFONT32A lplf
, UINT32 nFontType
,
2962 LPCHOOSEFONT32A lpcf
, HWND32 hwnd
)
2967 TRACE(commdlg
,"font=%s (nFontType=%d)\n", lplf
->lfFaceName
,nFontType
);
2969 if (lpcf
->Flags
& CF_FIXEDPITCHONLY
)
2970 if (!(lplf
->lfPitchAndFamily
& FIXED_PITCH
))
2972 if (lpcf
->Flags
& CF_ANSIONLY
)
2973 if (lplf
->lfCharSet
!= ANSI_CHARSET
)
2975 if (lpcf
->Flags
& CF_TTONLY
)
2976 if (!(nFontType
& TRUETYPE_FONTTYPE
))
2979 i
=SendMessage32A(hwnd
, CB_ADDSTRING32
, 0, (LPARAM
)lplf
->lfFaceName
);
2982 w
=(lplf
->lfCharSet
<< 8) | lplf
->lfPitchAndFamily
;
2983 SendMessage32A(hwnd
, CB_SETITEMDATA32
, i
, MAKELONG(nFontType
,w
));
2984 return 1 ; /* store some important font information */
2994 LPCHOOSEFONT32A lpcf32a
;
2995 } CFn_ENUMSTRUCT
, *LPCFn_ENUMSTRUCT
;
2997 /*************************************************************************
2998 * FontFamilyEnumProc32 [internal]
3000 INT32 WINAPI
FontFamilyEnumProc32(LPENUMLOGFONT32A lpEnumLogFont
,
3001 LPNEWTEXTMETRIC32A metrics
, UINT32 nFontType
, LPARAM lParam
)
3004 e
=(LPCFn_ENUMSTRUCT
)lParam
;
3005 return AddFontFamily(&lpEnumLogFont
->elfLogFont
, nFontType
, e
->lpcf32a
, e
->hWnd1
);
3008 /***********************************************************************
3009 * FontFamilyEnumProc16 (COMMDLG.19)
3011 INT16 WINAPI
FontFamilyEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
3012 UINT16 nFontType
, LPARAM lParam
)
3014 HWND16 hwnd
=LOWORD(lParam
);
3015 HWND16 hDlg
=GetParent16(hwnd
);
3016 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLong32A(hDlg
, DWL_USER
);
3017 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN( logfont
);
3019 FONT_LogFont16To32A(lplf
, &lf32a
);
3020 return AddFontFamily(&lf32a
, nFontType
, (LPCHOOSEFONT32A
)lpcf
->lpTemplateName
,
3024 /*************************************************************************
3025 * SetFontStylesToCombo2 [internal]
3027 * Fill font style information into combobox (without using font.c directly)
3029 static int SetFontStylesToCombo2(HWND32 hwnd
, HDC32 hdc
, LPLOGFONT32A lplf
)
3036 static struct FONTSTYLE fontstyles
[FSTYLES
]={
3037 { 0,FW_NORMAL
,"Regular"},{0,FW_BOLD
,"Bold"},
3038 { 1,FW_NORMAL
,"Italic"}, {1,FW_BOLD
,"Bold Italic"}};
3043 for (i
=0;i
<FSTYLES
;i
++)
3045 lplf
->lfItalic
=fontstyles
[i
].italic
;
3046 lplf
->lfWeight
=fontstyles
[i
].weight
;
3047 hf
=CreateFontIndirect32A(lplf
);
3048 hf
=SelectObject32(hdc
,hf
);
3049 GetTextMetrics16(hdc
,&tm
);
3050 hf
=SelectObject32(hdc
,hf
);
3053 if (tm
.tmWeight
==fontstyles
[i
].weight
&&
3054 tm
.tmItalic
==fontstyles
[i
].italic
) /* font successful created ? */
3056 char *str
= SEGPTR_STRDUP(fontstyles
[i
].stname
);
3057 j
=SendMessage16(hwnd
,CB_ADDSTRING16
,0,(LPARAM
)SEGPTR_GET(str
) );
3059 if (j
==CB_ERR
) return 1;
3060 j
=SendMessage16(hwnd
, CB_SETITEMDATA16
, j
,
3061 MAKELONG(fontstyles
[i
].weight
,fontstyles
[i
].italic
));
3062 if (j
==CB_ERR
) return 1;
3068 /*************************************************************************
3069 * AddFontSizeToCombo3 [internal]
3071 static int AddFontSizeToCombo3(HWND32 hwnd
, UINT32 h
, LPCHOOSEFONT32A lpcf
)
3076 if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
3077 ((lpcf
->Flags
& CF_LIMITSIZE
) && (h
>= lpcf
->nSizeMin
) && (h
<= lpcf
->nSizeMax
)))
3079 sprintf(buffer
, "%2d", h
);
3080 j
=SendMessage32A(hwnd
, CB_FINDSTRINGEXACT32
, -1, (LPARAM
)buffer
);
3083 j
=SendMessage32A(hwnd
, CB_ADDSTRING32
, 0, (LPARAM
)buffer
);
3084 if (j
!=CB_ERR
) j
= SendMessage32A(hwnd
, CB_SETITEMDATA32
, j
, h
);
3085 if (j
==CB_ERR
) return 1;
3091 /*************************************************************************
3092 * SetFontSizesToCombo3 [internal]
3094 static int SetFontSizesToCombo3(HWND32 hwnd
, LPCHOOSEFONT32A lpcf
)
3096 static const int sizes
[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
3099 for (i
=0; sizes
[i
]; i
++)
3100 if (AddFontSizeToCombo3(hwnd
, sizes
[i
], lpcf
)) return 1;
3104 /***********************************************************************
3105 * AddFontStyle [internal]
3107 INT32
AddFontStyle(LPLOGFONT32A lplf
, UINT32 nFontType
,
3108 LPCHOOSEFONT32A lpcf
, HWND32 hcmb2
, HWND32 hcmb3
, HWND32 hDlg
)
3112 TRACE(commdlg
,"(nFontType=%d)\n",nFontType
);
3113 TRACE(commdlg
," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
3114 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
3115 lplf
->lfFaceName
,lplf
->lfHeight
,lplf
->lfWidth
,
3116 lplf
->lfEscapement
,lplf
->lfOrientation
,
3117 lplf
->lfWeight
,lplf
->lfItalic
,lplf
->lfUnderline
,
3118 lplf
->lfStrikeOut
,lplf
->lfCharSet
, lplf
->lfOutPrecision
,
3119 lplf
->lfClipPrecision
,lplf
->lfQuality
, lplf
->lfPitchAndFamily
);
3120 if (nFontType
& RASTER_FONTTYPE
)
3122 if (AddFontSizeToCombo3(hcmb3
, lplf
->lfHeight
, lpcf
)) return 0;
3123 } else if (SetFontSizesToCombo3(hcmb3
, lpcf
)) return 0;
3125 if (!SendMessage32A(hcmb2
, CB_GETCOUNT32
, 0, 0))
3127 HDC32 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
3128 i
=SetFontStylesToCombo2(hcmb2
,hdc
,lplf
);
3129 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
3130 ReleaseDC32(hDlg
,hdc
);
3138 /***********************************************************************
3139 * FontStyleEnumProc16 (COMMDLG.18)
3141 INT16 WINAPI
FontStyleEnumProc16( SEGPTR logfont
, SEGPTR metrics
,
3142 UINT16 nFontType
, LPARAM lParam
)
3144 HWND16 hcmb2
=LOWORD(lParam
);
3145 HWND16 hcmb3
=HIWORD(lParam
);
3146 HWND16 hDlg
=GetParent16(hcmb3
);
3147 LPCHOOSEFONT16 lpcf
=(LPCHOOSEFONT16
)GetWindowLong32A(hDlg
, DWL_USER
);
3148 LOGFONT16
*lplf
= (LOGFONT16
*)PTR_SEG_TO_LIN(logfont
);
3150 FONT_LogFont16To32A(lplf
, &lf32a
);
3151 return AddFontStyle(&lf32a
, nFontType
, (LPCHOOSEFONT32A
)lpcf
->lpTemplateName
,
3152 hcmb2
, hcmb3
, hDlg
);
3155 /***********************************************************************
3156 * FontStyleEnumProc32 [internal]
3158 INT32 WINAPI
FontStyleEnumProc32( LPENUMLOGFONT32A lpFont
,
3159 LPNEWTEXTMETRIC32A metrics
, UINT32 nFontType
, LPARAM lParam
)
3161 LPCFn_ENUMSTRUCT s
=(LPCFn_ENUMSTRUCT
)lParam
;
3162 HWND32 hcmb2
=s
->hWnd1
;
3163 HWND32 hcmb3
=s
->hWnd2
;
3164 HWND32 hDlg
=GetParent32(hcmb3
);
3165 return AddFontStyle(&lpFont
->elfLogFont
, nFontType
, s
->lpcf32a
, hcmb2
,
3169 /***********************************************************************
3170 * CFn_WMInitDialog [internal]
3172 LRESULT
CFn_WMInitDialog(HWND32 hDlg
, WPARAM32 wParam
, LPARAM lParam
,
3173 LPCHOOSEFONT32A lpcf
)
3179 HCURSOR32 hcursor
=SetCursor32(LoadCursor32A(0,IDC_WAIT32A
));
3181 SetWindowLong32A(hDlg
, DWL_USER
, lParam
);
3182 lpxx
=lpcf
->lpLogFont
;
3183 TRACE(commdlg
,"WM_INITDIALOG lParam=%08lX\n", lParam
);
3185 if (lpcf
->lStructSize
!= sizeof(CHOOSEFONT32A
))
3187 ERR(commdlg
,"structure size failure !!!\n");
3188 EndDialog32 (hDlg
, 0);
3192 hBitmapTT
= LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE
));
3194 /* This font will be deleted by WM_COMMAND */
3195 SendDlgItemMessage32A(hDlg
,stc6
,WM_SETFONT
,
3196 CreateFont32A(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL
),FALSE
);
3198 if (!(lpcf
->Flags
& CF_SHOWHELP
) || !IsWindow32(lpcf
->hwndOwner
))
3199 ShowWindow32(GetDlgItem32(hDlg
,pshHelp
),SW_HIDE
);
3200 if (!(lpcf
->Flags
& CF_APPLY
))
3201 ShowWindow32(GetDlgItem32(hDlg
,psh3
),SW_HIDE
);
3202 if (lpcf
->Flags
& CF_EFFECTS
)
3204 for (res
=1,i
=0;res
&& i
<TEXT_COLORS
;i
++)
3206 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
3208 strcpy( name
, "[color name]" );
3209 j
=SendDlgItemMessage32A(hDlg
, cmb4
, CB_ADDSTRING32
, 0, (LPARAM
)name
);
3210 SendDlgItemMessage32A(hDlg
, cmb4
, CB_SETITEMDATA16
, j
, textcolors
[j
]);
3211 /* look for a fitting value in color combobox */
3212 if (textcolors
[j
]==lpcf
->rgbColors
)
3213 SendDlgItemMessage32A(hDlg
,cmb4
, CB_SETCURSEL32
,j
,0);
3218 ShowWindow32(GetDlgItem32(hDlg
,cmb4
),SW_HIDE
);
3219 ShowWindow32(GetDlgItem32(hDlg
,chx1
),SW_HIDE
);
3220 ShowWindow32(GetDlgItem32(hDlg
,chx2
),SW_HIDE
);
3221 ShowWindow32(GetDlgItem32(hDlg
,grp1
),SW_HIDE
);
3222 ShowWindow32(GetDlgItem32(hDlg
,stc4
),SW_HIDE
);
3224 hdc
= (lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
3228 s
.hWnd1
=GetDlgItem32(hDlg
,cmb1
);
3230 if (!EnumFontFamilies32A(hdc
, NULL
, FontFamilyEnumProc32
, (LPARAM
)&s
))
3231 TRACE(commdlg
,"EnumFontFamilies returns 0\n");
3232 if (lpcf
->Flags
& CF_INITTOLOGFONTSTRUCT
)
3234 /* look for fitting font name in combobox1 */
3235 j
=SendDlgItemMessage32A(hDlg
,cmb1
,CB_FINDSTRING32
,-1,(LONG
)lpxx
->lfFaceName
);
3238 SendDlgItemMessage32A(hDlg
, cmb1
, CB_SETCURSEL32
, j
, 0);
3239 SendMessage32A(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
3240 GetDlgItem32(hDlg
,cmb1
));
3242 /* look for fitting font style in combobox2 */
3243 l
=MAKELONG(lpxx
->lfWeight
> FW_MEDIUM
? FW_BOLD
:FW_NORMAL
,lpxx
->lfItalic
!=0);
3244 for (i
=0;i
<TEXT_EXTRAS
;i
++)
3246 if (l
==SendDlgItemMessage32A(hDlg
, cmb2
, CB_GETITEMDATA32
, i
, 0))
3247 SendDlgItemMessage32A(hDlg
, cmb2
, CB_SETCURSEL32
, i
, 0);
3250 /* look for fitting font size in combobox3 */
3251 j
=SendDlgItemMessage32A(hDlg
, cmb3
, CB_GETCOUNT32
, 0, 0);
3254 if (lpxx
->lfHeight
==(int)SendDlgItemMessage32A(hDlg
,cmb3
, CB_GETITEMDATA32
,i
,0))
3255 SendDlgItemMessage32A(hDlg
,cmb3
,CB_SETCURSEL32
,i
,0);
3261 SendDlgItemMessage32A(hDlg
,cmb1
,CB_SETCURSEL32
,0,0);
3262 SendMessage32A(hDlg
, WM_COMMAND
, MAKEWPARAM(cmb1
, CBN_SELCHANGE
),
3263 GetDlgItem32(hDlg
,cmb1
));
3265 if (lpcf
->Flags
& CF_USESTYLE
&& lpcf
->lpszStyle
)
3267 j
=SendDlgItemMessage32A(hDlg
,cmb2
,CB_FINDSTRING32
,-1,(LONG
)lpcf
->lpszStyle
);
3270 j
=SendDlgItemMessage32A(hDlg
,cmb2
,CB_SETCURSEL32
,j
,0);
3271 SendMessage32A(hDlg
,WM_COMMAND
,cmb2
,
3272 MAKELONG(GetDlgItem32(hDlg
,cmb2
),CBN_SELCHANGE
));
3278 WARN(commdlg
,"HDC failure !!!\n");
3279 EndDialog32 (hDlg
, 0);
3283 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
3284 ReleaseDC32(hDlg
,hdc
);
3285 SetCursor32(hcursor
);
3290 /***********************************************************************
3291 * CFn_WMMeasureItem [internal]
3293 LRESULT
CFn_WMMeasureItem(HWND32 hDlg
, WPARAM32 wParam
, LPARAM lParam
)
3296 LPMEASUREITEMSTRUCT32 lpmi
=(LPMEASUREITEMSTRUCT32
)lParam
;
3298 hBitmapTT
= LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE
));
3299 GetObject32A( hBitmapTT
, sizeof(bm
), &bm
);
3300 lpmi
->itemHeight
=bm
.bmHeight
;
3301 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
3306 /***********************************************************************
3307 * CFn_WMDrawItem [internal]
3309 LRESULT
CFn_WMDrawItem(HWND32 hDlg
, WPARAM32 wParam
, LPARAM lParam
)
3314 COLORREF cr
, oldText
=0, oldBk
=0;
3319 HBITMAP32 hBitmap
; /* for later TT usage */
3321 LPDRAWITEMSTRUCT32 lpdi
= (LPDRAWITEMSTRUCT32
)lParam
;
3323 if (lpdi
->itemID
== 0xFFFF) /* got no items */
3324 DrawFocusRect32(lpdi
->hDC
, &lpdi
->rcItem
);
3327 if (lpdi
->CtlType
== ODT_COMBOBOX
)
3329 if (lpdi
->itemState
==ODS_SELECTED
)
3331 hBrush
=GetSysColorBrush32(COLOR_HIGHLIGHT
);
3332 oldText
=SetTextColor32(lpdi
->hDC
, GetSysColor32(COLOR_HIGHLIGHTTEXT
));
3333 oldBk
=SetBkColor32(lpdi
->hDC
, GetSysColor32(COLOR_HIGHLIGHT
));
3336 hBrush
= SelectObject32(lpdi
->hDC
, GetStockObject32(LTGRAY_BRUSH
));
3337 SelectObject32(lpdi
->hDC
, hBrush
);
3339 FillRect32(lpdi
->hDC
, &lpdi
->rcItem
, hBrush
);
3342 return TRUE
; /* this should never happen */
3345 switch (lpdi
->CtlID
)
3347 case cmb1
: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
3348 SendMessage32A(lpdi
->hwndItem
, CB_GETLBTEXT32
, lpdi
->itemID
,
3350 GetObject32A( hBitmapTT
, sizeof(bm
), &bm
);
3351 TextOut32A(lpdi
->hDC
, lpdi
->rcItem
.left
+ bm
.bmWidth
+ 10,
3352 lpdi
->rcItem
.top
, buffer
, lstrlen32A(buffer
));
3354 nFontType
= SendMessage32A(lpdi
->hwndItem
, CB_GETITEMDATA32
, lpdi
->itemID
,0L);
3355 /* FIXME: draw bitmap if truetype usage */
3356 if (nFontType
&TRUETYPE_FONTTYPE
)
3358 hMemDC
= CreateCompatibleDC32(lpdi
->hDC
);
3359 hBitmap
= SelectObject32(hMemDC
, hBitmapTT
);
3360 BitBlt32(lpdi
->hDC
, lpdi
->rcItem
.left
, lpdi
->rcItem
.top
,
3361 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
3362 SelectObject32(hMemDC
, hBitmap
);
3368 case cmb3
: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
3369 SendMessage32A(lpdi
->hwndItem
, CB_GETLBTEXT32
, lpdi
->itemID
,
3371 TextOut32A(lpdi
->hDC
, lpdi
->rcItem
.left
,
3372 lpdi
->rcItem
.top
, buffer
, lstrlen32A(buffer
));
3375 case cmb4
: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
3376 SendMessage32A(lpdi
->hwndItem
, CB_GETLBTEXT32
, lpdi
->itemID
,
3378 TextOut32A(lpdi
->hDC
, lpdi
->rcItem
.left
+ 25+5,
3379 lpdi
->rcItem
.top
, buffer
, lstrlen32A(buffer
));
3380 cr
= SendMessage32A(lpdi
->hwndItem
, CB_GETITEMDATA32
, lpdi
->itemID
,0L);
3381 hBrush
= CreateSolidBrush32(cr
);
3384 hBrush
= SelectObject32 (lpdi
->hDC
, hBrush
) ;
3385 rect
.right
=rect
.left
+25;
3389 Rectangle32( lpdi
->hDC
, rect
.left
, rect
.top
,
3390 rect
.right
, rect
.bottom
);
3391 DeleteObject32( SelectObject32 (lpdi
->hDC
, hBrush
)) ;
3397 default: return TRUE
; /* this should never happen */
3399 if (lpdi
->itemState
== ODS_SELECTED
)
3401 SetTextColor32(lpdi
->hDC
, oldText
);
3402 SetBkColor32(lpdi
->hDC
, oldBk
);
3408 /***********************************************************************
3409 * CFn_WMCtlColor [internal]
3411 LRESULT
CFn_WMCtlColorStatic(HWND32 hDlg
, WPARAM32 wParam
, LPARAM lParam
,
3412 LPCHOOSEFONT32A lpcf
)
3414 if (lpcf
->Flags
& CF_EFFECTS
)
3415 if (GetDlgCtrlID32(lParam
)==stc6
)
3417 SetTextColor32((HDC32
)wParam
, lpcf
->rgbColors
);
3418 return GetStockObject32(WHITE_BRUSH
);
3423 /***********************************************************************
3424 * CFn_WMCommand [internal]
3426 LRESULT
CFn_WMCommand(HWND32 hDlg
, WPARAM32 wParam
, LPARAM lParam
,
3427 LPCHOOSEFONT32A lpcf
)
3433 LPLOGFONT32A lpxx
=lpcf
->lpLogFont
;
3435 TRACE(commdlg
,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG
)wParam
, lParam
);
3436 switch (LOWORD(wParam
))
3438 case cmb1
:if (HIWORD(wParam
)==CBN_SELCHANGE
)
3440 hdc
=(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
) ? lpcf
->hDC
: GetDC32(hDlg
);
3443 SendDlgItemMessage32A(hDlg
, cmb2
, CB_RESETCONTENT16
, 0, 0);
3444 SendDlgItemMessage32A(hDlg
, cmb3
, CB_RESETCONTENT16
, 0, 0);
3445 i
=SendDlgItemMessage32A(hDlg
, cmb1
, CB_GETCURSEL16
, 0, 0);
3448 HCURSOR32 hcursor
=SetCursor32(LoadCursor32A(0,IDC_WAIT32A
));
3451 SendDlgItemMessage32A(hDlg
, cmb1
, CB_GETLBTEXT32
, i
,
3453 TRACE(commdlg
,"WM_COMMAND/cmb1 =>%s\n",str
);
3454 s
.hWnd1
=GetDlgItem32(hDlg
, cmb2
);
3455 s
.hWnd2
=GetDlgItem32(hDlg
, cmb3
);
3457 EnumFontFamilies32A(hdc
, str
, FontStyleEnumProc32
, (LPARAM
)&s
);
3458 SetCursor32(hcursor
);
3460 if (!(lpcf
->Flags
& CF_PRINTERFONTS
&& lpcf
->hDC
))
3461 ReleaseDC32(hDlg
,hdc
);
3465 WARN(commdlg
,"HDC failure !!!\n");
3466 EndDialog32 (hDlg
, 0);
3473 case cmb3
:if (HIWORD(wParam
)==CBN_SELCHANGE
|| HIWORD(wParam
)== BN_CLICKED
)
3476 TRACE(commdlg
,"WM_COMMAND/cmb2,3 =%08lX\n", lParam
);
3477 i
=SendDlgItemMessage32A(hDlg
,cmb1
,CB_GETCURSEL32
,0,0);
3479 i
=GetDlgItemText32A( hDlg
, cmb1
, str
, 256 );
3482 SendDlgItemMessage32A(hDlg
,cmb1
,CB_GETLBTEXT32
,i
,
3484 l
=SendDlgItemMessage32A(hDlg
,cmb1
,CB_GETITEMDATA32
,i
,0);
3486 lpcf
->nFontType
= LOWORD(l
);
3487 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
3488 /* same value reported to the EnumFonts
3489 call back with the extra FONTTYPE_... bits added */
3490 lpxx
->lfPitchAndFamily
=j
&0xff;
3491 lpxx
->lfCharSet
=j
>>8;
3493 strcpy(lpxx
->lfFaceName
,str
);
3494 i
=SendDlgItemMessage32A(hDlg
, cmb2
, CB_GETCURSEL32
, 0, 0);
3497 l
=SendDlgItemMessage32A(hDlg
, cmb2
, CB_GETITEMDATA32
, i
, 0);
3498 if (0!=(lpxx
->lfItalic
=HIWORD(l
)))
3499 lpcf
->nFontType
|= ITALIC_FONTTYPE
;
3500 if ((lpxx
->lfWeight
=LOWORD(l
)) > FW_MEDIUM
)
3501 lpcf
->nFontType
|= BOLD_FONTTYPE
;
3503 i
=SendDlgItemMessage32A(hDlg
, cmb3
, CB_GETCURSEL32
, 0, 0);
3505 lpxx
->lfHeight
=-LOWORD(SendDlgItemMessage32A(hDlg
, cmb3
, CB_GETITEMDATA32
, i
, 0));
3508 lpxx
->lfStrikeOut
=IsDlgButtonChecked32(hDlg
,chx1
);
3509 lpxx
->lfUnderline
=IsDlgButtonChecked32(hDlg
,chx2
);
3510 lpxx
->lfWidth
=lpxx
->lfOrientation
=lpxx
->lfEscapement
=0;
3511 lpxx
->lfOutPrecision
=OUT_DEFAULT_PRECIS
;
3512 lpxx
->lfClipPrecision
=CLIP_DEFAULT_PRECIS
;
3513 lpxx
->lfQuality
=DEFAULT_QUALITY
;
3514 lpcf
->iPointSize
= -10*lpxx
->lfHeight
;
3516 hFont
=CreateFontIndirect32A(lpxx
);
3519 HFONT32 oldFont
=SendDlgItemMessage32A(hDlg
, stc6
,
3521 SendDlgItemMessage32A(hDlg
,stc6
,WM_SETFONT
,hFont
,TRUE
);
3522 DeleteObject32(oldFont
);
3527 case cmb4
:i
=SendDlgItemMessage32A(hDlg
, cmb4
, CB_GETCURSEL32
, 0, 0);
3530 lpcf
->rgbColors
=textcolors
[i
];
3531 InvalidateRect32( GetDlgItem32(hDlg
,stc6
), NULL
, 0 );
3535 case psh15
:i
=RegisterWindowMessage32A( HELPMSGSTRING
);
3536 if (lpcf
->hwndOwner
)
3537 SendMessage32A(lpcf
->hwndOwner
, i
, 0, (LPARAM
)GetWindowLong32A(hDlg
, DWL_USER
));
3538 /* if (CFn_HookCallChk(lpcf))
3539 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
3542 case IDOK
:if ( (!(lpcf
->Flags
& CF_LIMITSIZE
)) ||
3543 ( (lpcf
->Flags
& CF_LIMITSIZE
) &&
3544 (-lpxx
->lfHeight
>= lpcf
->nSizeMin
) &&
3545 (-lpxx
->lfHeight
<= lpcf
->nSizeMax
)))
3546 EndDialog32(hDlg
, TRUE
);
3550 sprintf(buffer
,"Select a font size between %d and %d points.",
3551 lpcf
->nSizeMin
,lpcf
->nSizeMax
);
3552 MessageBox32A(hDlg
, buffer
, NULL
, MB_OK
);
3555 case IDCANCEL
:EndDialog32(hDlg
, FALSE
);
3561 static LRESULT
CFn_WMDestroy(HWND32 hwnd
, WPARAM32 wParam
, LPARAM lParam
)
3563 DeleteObject32(SendDlgItemMessage32A(hwnd
, stc6
, WM_GETFONT
, 0, 0));
3568 /***********************************************************************
3569 * FormatCharDlgProc16 (COMMDLG.16)
3570 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
3571 2. some CF_.. flags are not supported
3572 3. some TType extensions
3574 LRESULT WINAPI
FormatCharDlgProc16(HWND16 hDlg
, UINT16 message
, WPARAM16 wParam
,
3577 LPCHOOSEFONT16 lpcf
;
3578 LPCHOOSEFONT32A lpcf32a
;
3582 if (message
!=WM_INITDIALOG
)
3584 lpcf
=(LPCHOOSEFONT16
)GetWindowLong32A(hDlg
, DWL_USER
);
3587 if (CFn_HookCallChk(lpcf
))
3588 res
=CallWindowProc16(lpcf
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
3594 lpcf
=(LPCHOOSEFONT16
)lParam
;
3595 lpcf32a
=(LPCHOOSEFONT32A
)lpcf
->lpTemplateName
;
3596 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
3598 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
3601 if (CFn_HookCallChk(lpcf
))
3602 return CallWindowProc16(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
3604 WINPROC_MapMsg16To32A(message
, wParam
, &uMsg32
, &wParam32
, &lParam
);
3605 lpcf32a
=(LPCHOOSEFONT32A
)lpcf
->lpTemplateName
;
3608 case WM_MEASUREITEM
:
3609 res
=CFn_WMMeasureItem(hDlg
, wParam32
, lParam
);
3612 res
=CFn_WMDrawItem(hDlg
, wParam32
, lParam
);
3614 case WM_CTLCOLORSTATIC
:
3615 res
=CFn_WMCtlColorStatic(hDlg
, wParam32
, lParam
, lpcf32a
);
3618 res
=CFn_WMCommand(hDlg
, wParam32
, lParam
, lpcf32a
);
3621 res
=CFn_WMDestroy(hDlg
, wParam32
, lParam
);
3623 case WM_CHOOSEFONT_GETLOGFONT
:
3624 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3626 FIXME(commdlg
, "current logfont back to caller\n");
3629 WINPROC_UnmapMsg16To32A(hDlg
,uMsg32
, wParam32
, lParam
, res
);
3633 /***********************************************************************
3634 * FormatCharDlgProc32A [internal]
3636 LRESULT WINAPI
FormatCharDlgProc32A(HWND32 hDlg
, UINT32 uMsg
, WPARAM32 wParam
,
3639 LPCHOOSEFONT32A lpcf
;
3641 if (uMsg
!=WM_INITDIALOG
)
3643 lpcf
=(LPCHOOSEFONT32A
)GetWindowLong32A(hDlg
, DWL_USER
);
3646 if (CFn_HookCallChk32(lpcf
))
3647 res
=CallWindowProc32A(lpcf
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
3653 lpcf
=(LPCHOOSEFONT32A
)lParam
;
3654 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf
))
3656 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
3659 if (CFn_HookCallChk32(lpcf
))
3660 return CallWindowProc32A(lpcf
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
3664 case WM_MEASUREITEM
:
3665 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
3667 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
3668 case WM_CTLCOLORSTATIC
:
3669 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf
);
3671 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf
);
3673 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
3674 case WM_CHOOSEFONT_GETLOGFONT
:
3675 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3677 FIXME(commdlg
, "current logfont back to caller\n");
3683 /***********************************************************************
3684 * FormatCharDlgProc32W [internal]
3686 LRESULT WINAPI
FormatCharDlgProc32W(HWND32 hDlg
, UINT32 uMsg
, WPARAM32 wParam
,
3689 LPCHOOSEFONT32W lpcf32w
;
3690 LPCHOOSEFONT32A lpcf32a
;
3692 if (uMsg
!=WM_INITDIALOG
)
3694 lpcf32w
=(LPCHOOSEFONT32W
)GetWindowLong32A(hDlg
, DWL_USER
);
3697 if (CFn_HookCallChk32((LPCHOOSEFONT32A
)lpcf32w
))
3698 res
=CallWindowProc32W(lpcf32w
->lpfnHook
, hDlg
, uMsg
, wParam
, lParam
);
3704 lpcf32w
=(LPCHOOSEFONT32W
)lParam
;
3705 lpcf32a
=(LPCHOOSEFONT32A
)lpcf32w
->lpTemplateName
;
3706 if (!CFn_WMInitDialog(hDlg
, wParam
, lParam
, lpcf32a
))
3708 TRACE(commdlg
, "CFn_WMInitDialog returned FALSE\n");
3711 if (CFn_HookCallChk32((LPCHOOSEFONT32A
)lpcf32w
))
3712 return CallWindowProc32W(lpcf32w
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
3714 lpcf32a
=(LPCHOOSEFONT32A
)lpcf32w
->lpTemplateName
;
3717 case WM_MEASUREITEM
:
3718 return CFn_WMMeasureItem(hDlg
, wParam
, lParam
);
3720 return CFn_WMDrawItem(hDlg
, wParam
, lParam
);
3721 case WM_CTLCOLORSTATIC
:
3722 return CFn_WMCtlColorStatic(hDlg
, wParam
, lParam
, lpcf32a
);
3724 return CFn_WMCommand(hDlg
, wParam
, lParam
, lpcf32a
);
3726 return CFn_WMDestroy(hDlg
, wParam
, lParam
);
3727 case WM_CHOOSEFONT_GETLOGFONT
:
3728 TRACE(commdlg
,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3730 FIXME(commdlg
, "current logfont back to caller\n");
3737 static BOOL32
Commdlg_GetFileName32A( BOOL16 (CALLBACK
*dofunction
)(SEGPTR x
),
3738 LPOPENFILENAME32A ofn
)
3741 LPOPENFILENAME16 ofn16
= SEGPTR_ALLOC(sizeof(OPENFILENAME16
));
3743 memset(ofn16
,'\0',sizeof(*ofn16
));
3744 ofn16
->lStructSize
= sizeof(*ofn16
);
3745 ofn16
->hwndOwner
= ofn
->hwndOwner
;
3746 ofn16
->hInstance
= MapHModuleLS(ofn
->hInstance
);
3747 if (ofn
->lpstrFilter
) {
3750 /* filter is a list... title\0ext\0......\0\0 */
3751 s
= (LPSTR
)ofn
->lpstrFilter
;
3755 x
= (LPSTR
)SEGPTR_ALLOC(s
-ofn
->lpstrFilter
);
3756 memcpy(x
,ofn
->lpstrFilter
,s
-ofn
->lpstrFilter
);
3757 ofn16
->lpstrFilter
= SEGPTR_GET(x
);
3759 if (ofn
->lpstrCustomFilter
) {
3762 /* filter is a list... title\0ext\0......\0\0 */
3763 s
= (LPSTR
)ofn
->lpstrCustomFilter
;
3767 x
= SEGPTR_ALLOC(s
-ofn
->lpstrCustomFilter
);
3768 memcpy(x
,ofn
->lpstrCustomFilter
,s
-ofn
->lpstrCustomFilter
);
3769 ofn16
->lpstrCustomFilter
= SEGPTR_GET(x
);
3771 ofn16
->nMaxCustFilter
= ofn
->nMaxCustFilter
;
3772 ofn16
->nFilterIndex
= ofn
->nFilterIndex
;
3774 ofn16
->lpstrFile
= SEGPTR_GET(SEGPTR_ALLOC(ofn
->nMaxFile
));
3775 ofn16
->nMaxFile
= ofn
->nMaxFile
;
3776 ofn16
->nMaxFileTitle
= ofn
->nMaxFileTitle
;
3777 if (ofn16
->nMaxFileTitle
)
3778 ofn16
->lpstrFileTitle
= SEGPTR_GET(SEGPTR_ALLOC(ofn
->nMaxFileTitle
));
3779 if (ofn
->lpstrInitialDir
)
3780 ofn16
->lpstrInitialDir
= SEGPTR_GET(SEGPTR_STRDUP(ofn
->lpstrInitialDir
));
3781 if (ofn
->lpstrTitle
)
3782 ofn16
->lpstrTitle
= SEGPTR_GET(SEGPTR_STRDUP(ofn
->lpstrTitle
));
3783 ofn16
->Flags
= ofn
->Flags
|OFN_WINE32
;
3784 ofn16
->nFileOffset
= ofn
->nFileOffset
;
3785 ofn16
->nFileExtension
= ofn
->nFileExtension
;
3786 if (ofn
->lpstrDefExt
)
3787 ofn16
->lpstrDefExt
= SEGPTR_GET(SEGPTR_STRDUP(ofn
->lpstrDefExt
));
3788 ofn16
->lCustData
= ofn
->lCustData
;
3789 ofn16
->lpfnHook
= (WNDPROC16
)ofn
->lpfnHook
;
3791 if (ofn
->lpTemplateName
)
3792 ofn16
->lpTemplateName
= SEGPTR_GET(SEGPTR_STRDUP(ofn
->lpTemplateName
));
3794 ret
= dofunction(SEGPTR_GET(ofn16
));
3796 ofn
->nFileOffset
= ofn16
->nFileOffset
;
3797 ofn
->nFileExtension
= ofn16
->nFileExtension
;
3798 if (ofn16
->lpstrFilter
)
3799 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrFilter
));
3800 if (ofn16
->lpTemplateName
)
3801 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpTemplateName
));
3802 if (ofn16
->lpstrDefExt
)
3803 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrDefExt
));
3804 if (ofn16
->lpstrTitle
)
3805 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrTitle
));
3806 if (ofn16
->lpstrInitialDir
)
3807 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrInitialDir
));
3808 if (ofn16
->lpstrCustomFilter
)
3809 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrCustomFilter
));
3811 if (ofn16
->lpstrFile
)
3813 strcpy(ofn
->lpstrFile
,PTR_SEG_TO_LIN(ofn16
->lpstrFile
));
3814 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrFile
));
3817 if (ofn16
->lpstrFileTitle
)
3819 strcpy(ofn
->lpstrFileTitle
,PTR_SEG_TO_LIN(ofn16
->lpstrFileTitle
));
3820 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrFileTitle
));
3826 static BOOL32
Commdlg_GetFileName32W( BOOL16 (CALLBACK
*dofunction
)(SEGPTR x
),
3827 LPOPENFILENAME32W ofn
)
3830 LPOPENFILENAME16 ofn16
= SEGPTR_ALLOC(sizeof(OPENFILENAME16
));
3832 memset(ofn16
,'\0',sizeof(*ofn16
));
3833 ofn16
->lStructSize
= sizeof(*ofn16
);
3834 ofn16
->hwndOwner
= ofn
->hwndOwner
;
3835 ofn16
->hInstance
= MapHModuleLS(ofn
->hInstance
);
3836 if (ofn
->lpstrFilter
) {
3841 /* filter is a list... title\0ext\0......\0\0 */
3842 s
= (LPWSTR
)ofn
->lpstrFilter
;
3844 s
= s
+lstrlen32W(s
)+1;
3846 n
= s
- ofn
->lpstrFilter
; /* already divides by 2. ptr magic */
3847 x
= y
= (LPSTR
)SEGPTR_ALLOC(n
);
3848 s
= (LPWSTR
)ofn
->lpstrFilter
;
3855 ofn16
->lpstrFilter
= SEGPTR_GET(y
);
3857 if (ofn
->lpstrCustomFilter
) {
3862 /* filter is a list... title\0ext\0......\0\0 */
3863 s
= (LPWSTR
)ofn
->lpstrCustomFilter
;
3865 s
= s
+lstrlen32W(s
)+1;
3867 n
= s
- ofn
->lpstrCustomFilter
;
3868 x
= y
= (LPSTR
)SEGPTR_ALLOC(n
);
3869 s
= (LPWSTR
)ofn
->lpstrCustomFilter
;
3876 ofn16
->lpstrCustomFilter
= SEGPTR_GET(y
);
3878 ofn16
->nMaxCustFilter
= ofn
->nMaxCustFilter
;
3879 ofn16
->nFilterIndex
= ofn
->nFilterIndex
;
3881 ofn16
->lpstrFile
= SEGPTR_GET(SEGPTR_ALLOC(ofn
->nMaxFile
));
3882 ofn16
->nMaxFile
= ofn
->nMaxFile
;
3883 ofn16
->nMaxFileTitle
= ofn
->nMaxFileTitle
;
3884 if (ofn
->nMaxFileTitle
)
3885 ofn16
->lpstrFileTitle
= SEGPTR_GET(SEGPTR_ALLOC(ofn
->nMaxFileTitle
));
3886 if (ofn
->lpstrInitialDir
)
3887 ofn16
->lpstrInitialDir
= SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn
->lpstrInitialDir
));
3888 if (ofn
->lpstrTitle
)
3889 ofn16
->lpstrTitle
= SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn
->lpstrTitle
));
3890 ofn16
->Flags
= ofn
->Flags
|OFN_WINE32
|OFN_UNICODE
;
3891 ofn16
->nFileOffset
= ofn
->nFileOffset
;
3892 ofn16
->nFileExtension
= ofn
->nFileExtension
;
3893 if (ofn
->lpstrDefExt
)
3894 ofn16
->lpstrDefExt
= SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn
->lpstrDefExt
));
3895 ofn16
->lCustData
= ofn
->lCustData
;
3896 ofn16
->lpfnHook
= (WNDPROC16
)ofn
->lpfnHook
;
3897 if (ofn
->lpTemplateName
)
3898 ofn16
->lpTemplateName
= SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn
->lpTemplateName
));
3899 ret
= dofunction(SEGPTR_GET(ofn16
));
3901 ofn
->nFileOffset
= ofn16
->nFileOffset
;
3902 ofn
->nFileExtension
= ofn16
->nFileExtension
;
3903 if (ofn16
->lpstrFilter
)
3904 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrFilter
));
3905 if (ofn16
->lpTemplateName
)
3906 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpTemplateName
));
3907 if (ofn16
->lpstrDefExt
)
3908 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrDefExt
));
3909 if (ofn16
->lpstrTitle
)
3910 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrTitle
));
3911 if (ofn16
->lpstrInitialDir
)
3912 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrInitialDir
));
3913 if (ofn16
->lpstrCustomFilter
)
3914 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrCustomFilter
));
3916 if (ofn16
->lpstrFile
) {
3917 lstrcpyAtoW(ofn
->lpstrFile
,PTR_SEG_TO_LIN(ofn16
->lpstrFile
));
3918 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrFile
));
3921 if (ofn16
->lpstrFileTitle
) {
3922 lstrcpyAtoW(ofn
->lpstrFileTitle
,PTR_SEG_TO_LIN(ofn16
->lpstrFileTitle
));
3923 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16
->lpstrFileTitle
));
3929 /***********************************************************************
3930 * GetOpenFileName32A (COMDLG32.10)
3932 BOOL32 WINAPI
GetOpenFileName32A( LPOPENFILENAME32A ofn
)
3934 BOOL16 (CALLBACK
* dofunction
)(SEGPTR ofn16
) = GetOpenFileName16
;
3935 return Commdlg_GetFileName32A(dofunction
,ofn
);
3938 /***********************************************************************
3939 * GetOpenFileName32W (COMDLG32.11)
3941 BOOL32 WINAPI
GetOpenFileName32W( LPOPENFILENAME32W ofn
)
3943 BOOL16 (CALLBACK
* dofunction
)(SEGPTR ofn16
) = GetOpenFileName16
;
3944 return Commdlg_GetFileName32W(dofunction
,ofn
);
3947 /***********************************************************************
3948 * GetSaveFileName32A (COMDLG32.12)
3950 BOOL32 WINAPI
GetSaveFileName32A( LPOPENFILENAME32A ofn
)
3952 BOOL16 (CALLBACK
* dofunction
)(SEGPTR ofn16
) = GetSaveFileName16
;
3953 return Commdlg_GetFileName32A(dofunction
,ofn
);
3956 /***********************************************************************
3957 * GetSaveFileName32W (COMDLG32.13)
3959 BOOL32 WINAPI
GetSaveFileName32W( LPOPENFILENAME32W ofn
)
3961 BOOL16 (CALLBACK
* dofunction
)(SEGPTR ofn16
) = GetSaveFileName16
;
3962 return Commdlg_GetFileName32W(dofunction
,ofn
);
3965 /***********************************************************************
3966 * ChooseColorA (COMDLG32.1)
3968 BOOL32 WINAPI
ChooseColor32A(LPCHOOSECOLOR32A lpChCol
)
3973 COLORREF
* ccref
=SEGPTR_ALLOC(64);
3974 LPCHOOSECOLOR16 lpcc16
=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16
));
3976 memset(lpcc16
,'\0',sizeof(*lpcc16
));
3977 lpcc16
->lStructSize
=sizeof(*lpcc16
);
3978 lpcc16
->hwndOwner
=lpChCol
->hwndOwner
;
3979 lpcc16
->hInstance
=MapHModuleLS(lpChCol
->hInstance
);
3980 lpcc16
->rgbResult
=lpChCol
->rgbResult
;
3981 memcpy(ccref
,lpChCol
->lpCustColors
,64);
3982 lpcc16
->lpCustColors
=(COLORREF
*)SEGPTR_GET(ccref
);
3983 lpcc16
->Flags
=lpChCol
->Flags
;
3984 lpcc16
->lCustData
=lpChCol
->lCustData
;
3985 lpcc16
->lpfnHook
=(WNDPROC16
)lpChCol
->lpfnHook
;
3986 if (lpChCol
->lpTemplateName
)
3987 str
= SEGPTR_STRDUP(lpChCol
->lpTemplateName
);
3988 lpcc16
->lpTemplateName
=SEGPTR_GET(str
);
3990 ret
= ChooseColor16(lpcc16
);
3993 lpChCol
->rgbResult
= lpcc16
->rgbResult
;
3997 memcpy(lpChCol
->lpCustColors
,ccref
,64);
3999 SEGPTR_FREE(lpcc16
);
4003 /***********************************************************************
4004 * ChooseColorW (COMDLG32.2)
4006 BOOL32 WINAPI
ChooseColor32W(LPCHOOSECOLOR32W lpChCol
)
4011 COLORREF
* ccref
=SEGPTR_ALLOC(64);
4012 LPCHOOSECOLOR16 lpcc16
=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16
));
4014 memset(lpcc16
,'\0',sizeof(*lpcc16
));
4015 lpcc16
->lStructSize
=sizeof(*lpcc16
);
4016 lpcc16
->hwndOwner
=lpChCol
->hwndOwner
;
4017 lpcc16
->hInstance
=MapHModuleLS(lpChCol
->hInstance
);
4018 lpcc16
->rgbResult
=lpChCol
->rgbResult
;
4019 memcpy(ccref
,lpChCol
->lpCustColors
,64);
4020 lpcc16
->lpCustColors
=(COLORREF
*)SEGPTR_GET(ccref
);
4021 lpcc16
->Flags
=lpChCol
->Flags
;
4022 lpcc16
->lCustData
=lpChCol
->lCustData
;
4023 lpcc16
->lpfnHook
=(WNDPROC16
)lpChCol
->lpfnHook
;
4024 if (lpChCol
->lpTemplateName
)
4025 str
= SEGPTR_STRDUP_WtoA(lpChCol
->lpTemplateName
);
4026 lpcc16
->lpTemplateName
=SEGPTR_GET(str
);
4028 ret
= ChooseColor16(lpcc16
);
4031 lpChCol
->rgbResult
= lpcc16
->rgbResult
;
4035 memcpy(lpChCol
->lpCustColors
,ccref
,64);
4037 SEGPTR_FREE(lpcc16
);
4041 /***********************************************************************
4042 * PageSetupDlgA (COMDLG32.15)
4044 BOOL32 WINAPI
PageSetupDlg32A(LPPAGESETUPDLG32A setupdlg
) {
4045 FIXME(commdlg
,"(%p), stub!\n",setupdlg
);