Release 980601
[wine.git] / misc / commdlg.c
blob1e3cfec84dd83d088d6353856b7f1732b8075bc8
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
8 #include <stdlib.h>
9 #include <string.h>
10 #include "win.h"
11 #include "heap.h"
12 #include "message.h"
13 #include "commdlg.h"
14 #include "dialog.h"
15 #include "dlgs.h"
16 #include "module.h"
17 #include "resource.h"
18 #include "drive.h"
19 #include "debug.h"
20 #include "font.h"
21 #include "winproc.h"
23 static DWORD CommDlgLastError = 0;
25 static HBITMAP16 hFolder = 0;
26 static HBITMAP16 hFolder2 = 0;
27 static HBITMAP16 hFloppy = 0;
28 static HBITMAP16 hHDisk = 0;
29 static HBITMAP16 hCDRom = 0;
30 static HBITMAP16 hBitmapTT = 0;
31 static const char defaultfilter[]=" \0\0";
33 /***********************************************************************
34 * FileDlg_Init [internal]
36 static BOOL32 FileDlg_Init()
38 static BOOL32 initialized = 0;
40 if (!initialized) {
41 if (!hFolder) hFolder = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER));
42 if (!hFolder2) hFolder2 = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER2));
43 if (!hFloppy) hFloppy = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FLOPPY));
44 if (!hHDisk) hHDisk = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_HDISK));
45 if (!hCDRom) hCDRom = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CDROM));
46 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
47 hHDisk == 0 || hCDRom == 0)
49 WARN(commdlg, "Error loading bitmaps !\nprin");
50 return FALSE;
52 initialized = TRUE;
54 return TRUE;
57 /***********************************************************************
58 * GetOpenFileName (COMMDLG.1)
60 BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
62 HINSTANCE32 hInst;
63 HANDLE32 hDlgTmpl = 0, hResInfo;
64 BOOL32 bRet = FALSE, win32Format = FALSE;
65 HWND32 hwndDialog;
66 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
67 LPCVOID template;
68 char defaultopen[]="Open File";
69 char *str=0,*str1=0;
71 if (!lpofn || !FileDlg_Init()) return FALSE;
73 if (lpofn->Flags & OFN_WINE32) {
74 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
76 if (!(template = LockResource32( lpofn->hInstance )))
78 CommDlgLastError = CDERR_LOADRESFAILURE;
79 return FALSE;
82 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
84 if (!(hResInfo = FindResource32A(lpofn->hInstance,
85 PTR_SEG_TO_LIN(lpofn->lpTemplateName), RT_DIALOG32A)))
87 CommDlgLastError = CDERR_FINDRESFAILURE;
88 return FALSE;
90 if (!(hDlgTmpl = LoadResource32( lpofn->hInstance, hResInfo )) ||
91 !(template = LockResource32( hDlgTmpl )))
93 CommDlgLastError = CDERR_LOADRESFAILURE;
94 return FALSE;
96 } else {
97 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
99 win32Format = TRUE;
100 } else {
101 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
103 if (!(template = LockResource16( lpofn->hInstance )))
105 CommDlgLastError = CDERR_LOADRESFAILURE;
106 return FALSE;
109 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
111 if (!(hResInfo = FindResource16(lpofn->hInstance,
112 lpofn->lpTemplateName,
113 RT_DIALOG16)))
115 CommDlgLastError = CDERR_FINDRESFAILURE;
116 return FALSE;
118 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
119 !(template = LockResource16( hDlgTmpl )))
121 CommDlgLastError = CDERR_LOADRESFAILURE;
122 return FALSE;
124 } else {
125 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
126 win32Format = TRUE;
130 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
132 if (!(lpofn->lpstrFilter))
134 str = SEGPTR_ALLOC(sizeof(defaultfilter));
135 TRACE(commdlg,"Alloc %p default for Filetype in GetOpenFileName\n",str);
136 memcpy(str,defaultfilter,sizeof(defaultfilter));
137 lpofn->lpstrFilter=SEGPTR_GET(str);
140 if (!(lpofn->lpstrTitle))
142 str1 = SEGPTR_ALLOC(strlen(defaultopen)+1);
143 TRACE(commdlg,"Alloc %p default for Title in GetOpenFileName\n",str1);
144 strcpy(str1,defaultopen);
145 lpofn->lpstrTitle=SEGPTR_GET(str1);
148 /* FIXME: doesn't handle win32 format correctly yet */
149 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
150 lpofn->hwndOwner,
151 (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
152 ofn, WIN_PROC_16 );
153 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
155 if (str1)
157 TRACE(commdlg,"Freeing %p default for Title in GetOpenFileName\n",str1);
158 SEGPTR_FREE(str1);
159 lpofn->lpstrTitle=0;
162 if (str)
164 TRACE(commdlg,"Freeing %p default for Filetype in GetOpenFileName\n",str);
165 SEGPTR_FREE(str);
166 lpofn->lpstrFilter=0;
169 if (hDlgTmpl) {
170 if (lpofn->Flags & OFN_WINE32)
171 FreeResource32( hDlgTmpl );
172 else
173 FreeResource16( hDlgTmpl );
176 TRACE(commdlg,"return lpstrFile='%s' !\n",
177 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
178 return bRet;
182 /***********************************************************************
183 * GetSaveFileName (COMMDLG.2)
185 BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
187 HINSTANCE32 hInst;
188 HANDLE32 hDlgTmpl = 0;
189 BOOL32 bRet = FALSE, win32Format = FALSE;
190 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
191 LPCVOID template;
192 HWND32 hwndDialog;
193 char defaultsave[]="Save as";
194 char *str =0,*str1=0;
196 if (!lpofn || !FileDlg_Init()) return FALSE;
198 if (lpofn->Flags & OFN_WINE32) {
199 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
201 if (!(template = LockResource32( lpofn->hInstance )))
203 CommDlgLastError = CDERR_LOADRESFAILURE;
204 return FALSE;
207 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
209 HANDLE32 hResInfo;
210 if (!(hResInfo = FindResource32A(lpofn->hInstance,
211 PTR_SEG_TO_LIN(lpofn->lpTemplateName),
212 RT_DIALOG32A)))
214 CommDlgLastError = CDERR_FINDRESFAILURE;
215 return FALSE;
217 if (!(hDlgTmpl = LoadResource32(lpofn->hInstance,hResInfo)) ||
218 !(template = LockResource32(hDlgTmpl)))
220 CommDlgLastError = CDERR_LOADRESFAILURE;
221 return FALSE;
223 win32Format= TRUE;
224 } else {
225 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
226 win32Format = TRUE;
228 } else {
229 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
231 if (!(template = LockResource16( lpofn->hInstance )))
233 CommDlgLastError = CDERR_LOADRESFAILURE;
234 return FALSE;
237 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
239 HANDLE16 hResInfo;
240 if (!(hResInfo = FindResource16(lpofn->hInstance,
241 lpofn->lpTemplateName,
242 RT_DIALOG16)))
244 CommDlgLastError = CDERR_FINDRESFAILURE;
245 return FALSE;
247 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
248 !(template = LockResource16( hDlgTmpl )))
250 CommDlgLastError = CDERR_LOADRESFAILURE;
251 return FALSE;
253 } else {
254 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
255 win32Format = TRUE;
259 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
261 if (!(lpofn->lpstrFilter))
263 str = SEGPTR_ALLOC(sizeof(defaultfilter));
264 TRACE(commdlg,"Alloc default for Filetype in GetSaveFileName\n");
265 memcpy(str,defaultfilter,sizeof(defaultfilter));
266 lpofn->lpstrFilter=SEGPTR_GET(str);
269 if (!(lpofn->lpstrTitle))
271 str1 = SEGPTR_ALLOC(sizeof(defaultsave)+1);
272 TRACE(commdlg,"Alloc default for Title in GetSaveFileName\n");
273 strcpy(str1,defaultsave);
274 lpofn->lpstrTitle=SEGPTR_GET(str1);
277 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
278 lpofn->hwndOwner,
279 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
280 ofn, WIN_PROC_16 );
281 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
283 if (str1)
285 TRACE(commdlg,"Freeing %p default for Title in GetSaveFileName\n",str1);
286 SEGPTR_FREE(str1);
287 lpofn->lpstrTitle=0;
290 if (str)
292 TRACE(commdlg,"Freeing %p default for Filetype in GetSaveFileName\n",str);
293 SEGPTR_FREE(str);
294 lpofn->lpstrFilter=0;
297 if (hDlgTmpl) {
298 if (lpofn->Flags & OFN_WINE32)
299 FreeResource32( hDlgTmpl );
300 else
301 FreeResource16( hDlgTmpl );
304 TRACE(commdlg, "return lpstrFile='%s' !\n",
305 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
306 return bRet;
309 /***********************************************************************
310 * FILEDLG_StripEditControl [internal]
311 * Strip pathnames off the contents of the edit control.
313 static void FILEDLG_StripEditControl(HWND16 hwnd)
315 char temp[512], *cp;
317 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
318 cp = strrchr(temp, '\\');
319 if (cp != NULL) {
320 strcpy(temp, cp+1);
322 cp = strrchr(temp, ':');
323 if (cp != NULL) {
324 strcpy(temp, cp+1);
326 /* FIXME: shouldn't we do something with the result here? ;-) */
329 /***********************************************************************
330 * FILEDLG_ScanDir [internal]
332 static BOOL32 FILEDLG_ScanDir(HWND16 hWnd, LPSTR newPath)
334 int len;
335 char str[512];
337 lstrcpyn32A( str, newPath, 512 );
338 len = strlen(str);
339 GetDlgItemText32A( hWnd, edt1, str + len, sizeof(str) - len );
340 if (!DlgDirList32A( hWnd, str, lst1, 0, 0x0000 )) return FALSE;
341 strcpy( str, "*.*" );
342 return DlgDirList32A( hWnd, str, lst2, stc1, 0x8010 );
345 /***********************************************************************
346 * FILEDLG_GetFileType [internal]
349 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
351 int n, i;
352 i = 0;
353 if (cfptr)
354 for ( ;(n = strlen(cfptr)) != 0; i++)
356 cfptr += n + 1;
357 if (i == index)
358 return cfptr;
359 cfptr += strlen(cfptr) + 1;
361 if (fptr)
362 for ( ;(n = strlen(fptr)) != 0; i++)
364 fptr += n + 1;
365 if (i == index)
366 return fptr;
367 fptr += strlen(fptr) + 1;
369 return "*.*"; /* FIXME */
372 /***********************************************************************
373 * FILEDLG_WMDrawItem [internal]
375 static LONG FILEDLG_WMDrawItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam,int savedlg)
377 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
378 char *str;
379 HBRUSH32 hBrush;
380 HBITMAP16 hBitmap, hPrevBitmap;
381 BITMAP16 bm;
382 HDC32 hMemDC;
384 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
386 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
387 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
388 SelectObject32(lpdis->hDC, hBrush);
389 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
390 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
391 (LPARAM)SEGPTR_GET(str));
393 if (savedlg) /* use _gray_ text in FileSaveDlg */
394 if (!lpdis->itemState)
395 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_GRAYTEXT) );
396 else
397 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_WINDOWTEXT) );
398 /* inversion of gray would be bad readable */
400 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
401 str, strlen(str));
402 if (lpdis->itemState != 0) {
403 InvertRect16(lpdis->hDC, &lpdis->rcItem);
405 SEGPTR_FREE(str);
406 return TRUE;
409 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
411 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
412 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
413 SelectObject32(lpdis->hDC, hBrush);
414 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
415 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
416 (LPARAM)SEGPTR_GET(str));
418 hBitmap = hFolder;
419 GetObject16( hBitmap, sizeof(bm), &bm );
420 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
421 lpdis->rcItem.top, str, strlen(str));
422 hMemDC = CreateCompatibleDC32(lpdis->hDC);
423 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
424 BitBlt32(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
425 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
426 SelectObject32(hMemDC, hPrevBitmap);
427 DeleteDC32(hMemDC);
428 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
429 SEGPTR_FREE(str);
430 return TRUE;
432 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
434 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
435 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
436 SelectObject32(lpdis->hDC, hBrush);
437 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
438 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT16, lpdis->itemID,
439 (LPARAM)SEGPTR_GET(str));
440 switch(DRIVE_GetType( str[2] - 'a' ))
442 case TYPE_FLOPPY: hBitmap = hFloppy; break;
443 case TYPE_CDROM: hBitmap = hCDRom; break;
444 case TYPE_HD:
445 case TYPE_NETWORK:
446 default: hBitmap = hHDisk; break;
448 GetObject16( hBitmap, sizeof(bm), &bm );
449 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
450 lpdis->rcItem.top, str, strlen(str));
451 hMemDC = CreateCompatibleDC32(lpdis->hDC);
452 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
453 BitBlt32( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
454 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
455 SelectObject32(hMemDC, hPrevBitmap);
456 DeleteDC32(hMemDC);
457 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
458 SEGPTR_FREE(str);
459 return TRUE;
461 return FALSE;
464 /***********************************************************************
465 * FILEDLG_WMMeasureItem [internal]
467 static LONG FILEDLG_WMMeasureItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
469 BITMAP16 bm;
470 LPMEASUREITEMSTRUCT16 lpmeasure;
472 GetObject16( hFolder2, sizeof(bm), &bm );
473 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
474 lpmeasure->itemHeight = bm.bmHeight;
475 return TRUE;
478 /***********************************************************************
479 * FILEDLG_HookCallChk [internal]
481 static int FILEDLG_HookCallChk(LPOPENFILENAME16 lpofn)
483 if (lpofn)
484 if (lpofn->Flags & OFN_ENABLEHOOK)
485 if (lpofn->lpfnHook)
486 return 1;
487 return 0;
490 /***********************************************************************
491 * FILEDLG_CallWindowProc [internal]
493 * Adapt the structures back for win32 calls so the callee can read lpCustData
495 static BOOL32 FILEDLG_CallWindowProc(LPOPENFILENAME16 lpofn,HWND32 hwnd,
496 UINT32 wMsg,WPARAM32 wParam,LPARAM lParam
499 BOOL32 needstruct;
501 needstruct = (PTR_SEG_TO_LIN(lParam) == lpofn);
503 if (!(lpofn->Flags & OFN_WINE32))
504 return (BOOL32)CallWindowProc16(
505 lpofn->lpfnHook,hwnd,(UINT16)wMsg,(WPARAM16)wParam,lParam
507 /* |OFN_WINE32 */
508 if (lpofn->Flags & OFN_UNICODE) {
509 if (needstruct) {
510 OPENFILENAME32W ofnw;
512 /* FIXME: probably needs more converted */
513 ofnw.lCustData = lpofn->lCustData;
514 return (BOOL32)CallWindowProc32W(
515 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofnw
517 } else
518 return (BOOL32)CallWindowProc32W(
519 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
522 /* ! |OFN_UNICODE */
523 if (needstruct) {
524 OPENFILENAME32A ofna;
526 /* FIXME: probably needs more converted */
527 ofna.lCustData = lpofn->lCustData;
528 return (BOOL32)CallWindowProc32A(
529 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofna
531 } else
532 return (BOOL32)CallWindowProc32A(
533 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
538 /***********************************************************************
539 * FILEDLG_WMInitDialog [internal]
542 static LONG FILEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
544 int i, n;
545 LPOPENFILENAME16 lpofn;
546 char tmpstr[512];
547 LPSTR pstr, old_pstr;
548 SetWindowLong32A(hWnd, DWL_USER, lParam);
549 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(lParam);
550 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
551 /* read custom filter information */
552 if (lpofn->lpstrCustomFilter)
554 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
555 n = 0;
556 TRACE(commdlg,"lpstrCustomFilter = %p\n", pstr);
557 while(*pstr)
559 old_pstr = pstr;
560 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
561 (LPARAM)lpofn->lpstrCustomFilter + n );
562 n += strlen(pstr) + 1;
563 pstr += strlen(pstr) + 1;
564 TRACE(commdlg,"add str='%s' "
565 "associated to '%s'\n", old_pstr, pstr);
566 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
567 n += strlen(pstr) + 1;
568 pstr += strlen(pstr) + 1;
571 /* read filter information */
572 if (lpofn->lpstrFilter) {
573 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
574 n = 0;
575 while(*pstr) {
576 old_pstr = pstr;
577 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
578 (LPARAM)lpofn->lpstrFilter + n );
579 n += strlen(pstr) + 1;
580 pstr += strlen(pstr) + 1;
581 TRACE(commdlg,"add str='%s' "
582 "associated to '%s'\n", old_pstr, pstr);
583 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
584 n += strlen(pstr) + 1;
585 pstr += strlen(pstr) + 1;
588 /* set default filter */
589 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
590 lpofn->nFilterIndex = 1;
591 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL16, lpofn->nFilterIndex - 1, 0);
592 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
593 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
594 tmpstr[511]=0;
595 TRACE(commdlg,"nFilterIndex = %ld, SetText of edt1 to '%s'\n",
596 lpofn->nFilterIndex, tmpstr);
597 SetDlgItemText32A( hWnd, edt1, tmpstr );
598 /* get drive list */
599 *tmpstr = 0;
600 DlgDirListComboBox32A(hWnd, tmpstr, cmb2, 0, 0xC000);
601 /* read initial directory */
602 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
604 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
605 tmpstr[510]=0;
606 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
607 && tmpstr[strlen(tmpstr)-1] != ':')
608 strcat(tmpstr,"\\");
610 else
611 *tmpstr = 0;
612 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
613 *tmpstr = 0;
614 if (!FILEDLG_ScanDir(hWnd, tmpstr))
615 WARN(commdlg, "Couldn't read initial directory %s!\n",tmpstr);
617 /* select current drive in combo 2, omit missing drives */
618 for(i=0, n=-1; i<=DRIVE_GetCurrentDrive(); i++)
619 if (DRIVE_IsValid(i)) n++;
620 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL16, n, 0);
621 if (!(lpofn->Flags & OFN_SHOWHELP))
622 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
623 if (lpofn->Flags & OFN_HIDEREADONLY)
624 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
625 if (FILEDLG_HookCallChk(lpofn))
626 return (BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,WM_INITDIALOG,wParam,lParam );
627 else
628 return TRUE;
631 /***********************************************************************
632 * FILEDLG_WMCommand [internal]
634 BOOL32 in_update=FALSE;
636 static LRESULT FILEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
638 LONG lRet;
639 LPOPENFILENAME16 lpofn;
640 OPENFILENAME16 ofn2;
641 char tmpstr[512], tmpstr2[512];
642 LPSTR pstr, pstr2;
643 UINT16 control,notification;
645 /* Notifications are packaged differently in Win32 */
646 control = wParam;
647 notification = HIWORD(lParam);
649 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
650 switch (control)
652 case lst1: /* file list */
653 FILEDLG_StripEditControl(hWnd);
654 if (notification == LBN_DBLCLK)
655 goto almost_ok;
656 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
657 if (lRet == LB_ERR) return TRUE;
658 if ((pstr = SEGPTR_ALLOC(512)))
660 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
661 (LPARAM)SEGPTR_GET(pstr));
662 SetDlgItemText32A( hWnd, edt1, pstr );
663 SEGPTR_FREE(pstr);
665 if (FILEDLG_HookCallChk(lpofn))
666 FILEDLG_CallWindowProc(lpofn,hWnd,
667 RegisterWindowMessage32A( LBSELCHSTRING ),
668 control, MAKELONG(lRet,CD_LBSELCHANGE));
669 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
670 return TRUE;
671 case lst2: /* directory list */
672 FILEDLG_StripEditControl(hWnd);
673 if (notification == LBN_DBLCLK)
675 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
676 if (lRet == LB_ERR) return TRUE;
677 pstr = SEGPTR_ALLOC(512);
678 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
679 (LPARAM)SEGPTR_GET(pstr));
680 strcpy( tmpstr, pstr );
681 SEGPTR_FREE(pstr);
682 if (tmpstr[0] == '[')
684 tmpstr[strlen(tmpstr) - 1] = 0;
685 strcpy(tmpstr,tmpstr+1);
687 strcat(tmpstr, "\\");
688 goto reset_scan;
690 return TRUE;
691 case cmb1: /* file type drop list */
692 if (notification == CBN_SELCHANGE)
694 *tmpstr = 0;
695 goto reset_scan;
697 return TRUE;
698 case chx1:
699 return TRUE;
700 case pshHelp:
701 return TRUE;
702 case cmb2: /* disk drop list */
703 FILEDLG_StripEditControl(hWnd);
704 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL16, 0, 0L);
705 if (lRet == LB_ERR) return 0;
706 pstr = SEGPTR_ALLOC(512);
707 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT16, lRet,
708 (LPARAM)SEGPTR_GET(pstr));
709 sprintf(tmpstr, "%c:", pstr[2]);
710 SEGPTR_FREE(pstr);
711 reset_scan:
712 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
713 if (lRet == LB_ERR)
714 return TRUE;
715 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA16, lRet, 0);
716 TRACE(commdlg,"Selected filter : %s\n", pstr);
717 SetDlgItemText32A( hWnd, edt1, pstr );
718 FILEDLG_ScanDir(hWnd, tmpstr);
719 in_update=TRUE;
720 case IDOK:
721 almost_ok:
722 ofn2=*lpofn; /* for later restoring */
723 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
724 pstr = strrchr(tmpstr, '\\');
725 if (pstr == NULL)
726 pstr = strrchr(tmpstr, ':');
727 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
729 /* edit control contains wildcards */
730 if (pstr != NULL)
732 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
733 *(pstr+1) = 0;
735 else
737 strcpy(tmpstr2, tmpstr);
738 *tmpstr=0;
740 TRACE(commdlg,"tmpstr=%s, tmpstr2=%s\n", tmpstr, tmpstr2);
741 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
742 FILEDLG_ScanDir(hWnd, tmpstr);
743 return TRUE;
745 /* no wildcards, we might have a directory or a filename */
746 /* try appending a wildcard and reading the directory */
747 pstr2 = tmpstr + strlen(tmpstr);
748 if (pstr == NULL || *(pstr+1) != 0)
749 strcat(tmpstr, "\\");
750 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
751 if (lRet == LB_ERR) return TRUE;
752 lpofn->nFilterIndex = lRet + 1;
753 TRACE(commdlg,"lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
754 lstrcpyn32A(tmpstr2,
755 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
756 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
757 lRet), sizeof(tmpstr2));
758 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
759 if (!in_update)
760 /* if ScanDir succeeds, we have changed the directory */
761 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
762 /* if not, this must be a filename */
763 *pstr2 = 0;
764 if (pstr != NULL)
766 /* strip off the pathname */
767 *pstr = 0;
768 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
769 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
770 /* Should we MessageBox() if this fails? */
771 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
772 strcpy(tmpstr, tmpstr2);
774 else SetDlgItemText32A( hWnd, edt1, tmpstr );
775 #if 0
776 ShowWindow16(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
777 #endif
779 int drive = DRIVE_GetCurrentDrive();
780 tmpstr2[0] = 'A'+ drive;
781 tmpstr2[1] = ':';
782 tmpstr2[2] = '\\';
783 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
784 if (strlen(tmpstr2) > 3)
785 strcat(tmpstr2, "\\");
786 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
787 if (lpofn->lpstrFile)
788 lstrcpyn32A(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2,lpofn->nMaxFile);
790 lpofn->nFileOffset = strrchr(tmpstr2,'\\') - tmpstr2 +1;
791 lpofn->nFileExtension = 0;
792 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
793 lpofn->nFileExtension++;
794 if (lpofn->nFileExtension == '\0')
795 lpofn->nFileExtension = 0;
796 else
797 lpofn->nFileExtension++;
799 if(in_update)
801 if (FILEDLG_HookCallChk(lpofn))
802 FILEDLG_CallWindowProc(lpofn,hWnd,
803 RegisterWindowMessage32A( LBSELCHSTRING ),
804 control, MAKELONG(lRet,CD_LBSELCHANGE));
806 in_update = FALSE;
807 return TRUE;
809 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
811 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
812 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
813 lpofn->lpstrFileTitle );
815 if (FILEDLG_HookCallChk(lpofn))
817 lRet= (BOOL16)FILEDLG_CallWindowProc(lpofn,
818 hWnd, RegisterWindowMessage32A( FILEOKSTRING ), 0, lParam );
819 if (lRet)
821 *lpofn=ofn2; /* restore old state */
822 #if 0
823 ShowWindow16(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
824 #endif
825 break;
828 EndDialog32(hWnd, TRUE);
829 return TRUE;
830 case IDCANCEL:
831 EndDialog32(hWnd, FALSE);
832 return TRUE;
834 return FALSE;
838 /***********************************************************************
839 * FileOpenDlgProc (COMMDLG.6)
841 LRESULT WINAPI FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
842 LPARAM lParam)
844 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
846 if (wMsg!=WM_INITDIALOG)
847 if (FILEDLG_HookCallChk(lpofn))
849 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
850 if (lRet)
851 return lRet; /* else continue message processing */
853 switch (wMsg)
855 case WM_INITDIALOG:
856 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
857 case WM_MEASUREITEM:
858 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
859 case WM_DRAWITEM:
860 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
861 case WM_COMMAND:
862 return FILEDLG_WMCommand(hWnd, wParam, lParam);
863 #if 0
864 case WM_CTLCOLOR:
865 SetBkColor((HDC16)wParam, 0x00C0C0C0);
866 switch (HIWORD(lParam))
868 case CTLCOLOR_BTN:
869 SetTextColor((HDC16)wParam, 0x00000000);
870 return hGRAYBrush;
871 case CTLCOLOR_STATIC:
872 SetTextColor((HDC16)wParam, 0x00000000);
873 return hGRAYBrush;
875 break;
876 #endif
878 return FALSE;
882 /***********************************************************************
883 * FileSaveDlgProc (COMMDLG.7)
885 LRESULT WINAPI FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
886 LPARAM lParam)
888 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
890 if (wMsg!=WM_INITDIALOG)
891 if (FILEDLG_HookCallChk(lpofn))
893 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
894 if (lRet)
895 return lRet; /* else continue message processing */
897 switch (wMsg) {
898 case WM_INITDIALOG:
899 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
901 case WM_MEASUREITEM:
902 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
904 case WM_DRAWITEM:
905 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
907 case WM_COMMAND:
908 return FILEDLG_WMCommand(hWnd, wParam, lParam);
912 case WM_CTLCOLOR:
913 SetBkColor((HDC16)wParam, 0x00C0C0C0);
914 switch (HIWORD(lParam))
916 case CTLCOLOR_BTN:
917 SetTextColor((HDC16)wParam, 0x00000000);
918 return hGRAYBrush;
919 case CTLCOLOR_STATIC:
920 SetTextColor((HDC16)wParam, 0x00000000);
921 return hGRAYBrush;
923 return FALSE;
926 return FALSE;
930 /***********************************************************************
931 * FindText16 (COMMDLG.11)
933 HWND16 WINAPI FindText16( SEGPTR find )
935 HANDLE16 hInst;
936 LPCVOID ptr;
937 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
940 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
941 * For now, only the standard dialog works.
943 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
944 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
945 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
946 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
947 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
948 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
949 find, WIN_PROC_16 );
952 /***********************************************************************
953 * FindText32A (COMMDLG.6)
955 HWND32 WINAPI FindText32A( LPFINDREPLACE32A lpFind )
957 HANDLE16 hInst;
958 LPCVOID ptr;
961 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
962 * For now, only the standard dialog works.
964 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
965 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
966 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
967 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
968 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
969 (DLGPROC16)FindTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
972 /***********************************************************************
973 * FindText32W (COMMDLG.7)
975 HWND32 WINAPI FindText32W( LPFINDREPLACE32W lpFind )
977 HANDLE16 hInst;
978 LPCVOID ptr;
981 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
982 * For now, only the standard dialog works.
984 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
985 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
986 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
987 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
988 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
989 (DLGPROC16)FindTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
992 /***********************************************************************
993 * ReplaceText16 (COMMDLG.12)
995 HWND16 WINAPI ReplaceText16( SEGPTR find )
997 HANDLE16 hInst;
998 LPCVOID ptr;
999 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
1002 * FIXME : We should do error checking on the lpFind structure here
1003 * and make CommDlgExtendedError() return the error condition.
1005 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1006 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1007 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1008 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1009 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1010 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
1011 find, WIN_PROC_16 );
1014 /***********************************************************************
1015 * ReplaceText32A (COMDLG32.19)
1017 HWND32 WINAPI ReplaceText32A( LPFINDREPLACE32A lpFind )
1019 HANDLE16 hInst;
1020 LPCVOID ptr;
1023 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1024 * For now, only the standard dialog works.
1026 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1027 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1028 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1029 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1030 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1031 (DLGPROC16)ReplaceTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
1034 /***********************************************************************
1035 * ReplaceText32W (COMDLG32.20)
1037 HWND32 WINAPI ReplaceText32W( LPFINDREPLACE32W lpFind )
1039 HANDLE16 hInst;
1040 LPCVOID ptr;
1043 * FIXME : We should do error checking on the lpFind structure here
1044 * and make CommDlgExtendedError() return the error condition.
1046 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1047 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1048 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1049 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1050 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1051 (DLGPROC16)ReplaceTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
1055 /***********************************************************************
1056 * FINDDLG_WMInitDialog [internal]
1058 static LRESULT FINDDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam, LPDWORD lpFlags,
1059 LPSTR lpstrFindWhat, BOOL32 fUnicode)
1061 SetWindowLong32A(hWnd, DWL_USER, lParam);
1062 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1064 * FIXME : If the initial FindWhat string is empty, we should disable the
1065 * FindNext (IDOK) button. Only after typing some text, the button should be
1066 * enabled.
1068 if (fUnicode) SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1069 else SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1070 CheckRadioButton32(hWnd, rad1, rad2, (*lpFlags & FR_DOWN) ? rad2 : rad1);
1071 if (*lpFlags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
1072 EnableWindow32(GetDlgItem32(hWnd, rad1), FALSE);
1073 EnableWindow32(GetDlgItem32(hWnd, rad2), FALSE);
1075 if (*lpFlags & FR_HIDEUPDOWN) {
1076 ShowWindow32(GetDlgItem32(hWnd, rad1), SW_HIDE);
1077 ShowWindow32(GetDlgItem32(hWnd, rad2), SW_HIDE);
1078 ShowWindow32(GetDlgItem32(hWnd, grp1), SW_HIDE);
1080 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1081 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1082 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1083 if (*lpFlags & FR_HIDEWHOLEWORD)
1084 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1085 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1086 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1087 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1088 if (*lpFlags & FR_HIDEMATCHCASE)
1089 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1090 if (!(*lpFlags & FR_SHOWHELP)) {
1091 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1092 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1094 ShowWindow32(hWnd, SW_SHOWNORMAL);
1095 return TRUE;
1099 /***********************************************************************
1100 * FINDDLG_WMCommand [internal]
1102 static LRESULT FINDDLG_WMCommand(HWND32 hWnd, WPARAM32 wParam,
1103 HWND32 hwndOwner, LPDWORD lpFlags,
1104 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1105 BOOL32 fUnicode)
1107 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1108 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1110 switch (wParam) {
1111 case IDOK:
1112 if (fUnicode)
1113 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1114 else GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1115 if (IsDlgButtonChecked32(hWnd, rad2))
1116 *lpFlags |= FR_DOWN;
1117 else *lpFlags &= ~FR_DOWN;
1118 if (IsDlgButtonChecked32(hWnd, chx1))
1119 *lpFlags |= FR_WHOLEWORD;
1120 else *lpFlags &= ~FR_WHOLEWORD;
1121 if (IsDlgButtonChecked32(hWnd, chx2))
1122 *lpFlags |= FR_MATCHCASE;
1123 else *lpFlags &= ~FR_MATCHCASE;
1124 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1125 *lpFlags |= FR_FINDNEXT;
1126 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1127 GetWindowLong32A(hWnd, DWL_USER) );
1128 return TRUE;
1129 case IDCANCEL:
1130 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1131 *lpFlags |= FR_DIALOGTERM;
1132 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1133 GetWindowLong32A(hWnd, DWL_USER) );
1134 DestroyWindow32(hWnd);
1135 return TRUE;
1136 case pshHelp:
1137 /* FIXME : should lpfr structure be passed as an argument ??? */
1138 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1139 return TRUE;
1141 return FALSE;
1145 /***********************************************************************
1146 * FindTextDlgProc16 (COMMDLG.13)
1148 LRESULT WINAPI FindTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1149 LPARAM lParam)
1151 LPFINDREPLACE16 lpfr;
1152 switch (wMsg) {
1153 case WM_INITDIALOG:
1154 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1155 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1156 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat), FALSE);
1157 case WM_COMMAND:
1158 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1159 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1160 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1161 lpfr->wFindWhatLen, FALSE);
1163 return FALSE;
1166 /***********************************************************************
1167 * FindTextDlgProc32A
1169 LRESULT WINAPI FindTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1170 LPARAM lParam)
1172 LPFINDREPLACE32A lpfr;
1173 switch (wMsg) {
1174 case WM_INITDIALOG:
1175 lpfr=(LPFINDREPLACE32A)lParam;
1176 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1177 lpfr->lpstrFindWhat, FALSE);
1178 case WM_COMMAND:
1179 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1180 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1181 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1182 FALSE);
1184 return FALSE;
1187 /***********************************************************************
1188 * FindTextDlgProc32W
1190 LRESULT WINAPI FindTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1191 LPARAM lParam)
1193 LPFINDREPLACE32W lpfr;
1194 switch (wMsg) {
1195 case WM_INITDIALOG:
1196 lpfr=(LPFINDREPLACE32W)lParam;
1197 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1198 (LPSTR)lpfr->lpstrFindWhat, TRUE);
1199 case WM_COMMAND:
1200 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1201 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1202 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1203 TRUE);
1205 return FALSE;
1209 /***********************************************************************
1210 * REPLACEDLG_WMInitDialog [internal]
1212 static LRESULT REPLACEDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam,
1213 LPDWORD lpFlags, LPSTR lpstrFindWhat,
1214 LPSTR lpstrReplaceWith, BOOL32 fUnicode)
1216 SetWindowLong32A(hWnd, DWL_USER, lParam);
1217 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1219 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
1220 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
1221 * enabled.
1223 if (fUnicode)
1225 SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1226 SetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith);
1227 } else
1229 SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1230 SetDlgItemText32A(hWnd, edt2, lpstrReplaceWith);
1232 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1233 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1234 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1235 if (*lpFlags & FR_HIDEWHOLEWORD)
1236 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1237 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1238 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1239 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1240 if (*lpFlags & FR_HIDEMATCHCASE)
1241 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1242 if (!(*lpFlags & FR_SHOWHELP)) {
1243 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1244 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1246 ShowWindow32(hWnd, SW_SHOWNORMAL);
1247 return TRUE;
1251 /***********************************************************************
1252 * REPLACEDLG_WMCommand [internal]
1254 static LRESULT REPLACEDLG_WMCommand(HWND32 hWnd, WPARAM16 wParam,
1255 HWND32 hwndOwner, LPDWORD lpFlags,
1256 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1257 LPSTR lpstrReplaceWith, WORD wReplaceWithLen,
1258 BOOL32 fUnicode)
1260 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1261 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1263 switch (wParam) {
1264 case IDOK:
1265 if (fUnicode)
1267 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1268 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1269 } else
1271 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1272 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1274 if (IsDlgButtonChecked32(hWnd, chx1))
1275 *lpFlags |= FR_WHOLEWORD;
1276 else *lpFlags &= ~FR_WHOLEWORD;
1277 if (IsDlgButtonChecked32(hWnd, chx2))
1278 *lpFlags |= FR_MATCHCASE;
1279 else *lpFlags &= ~FR_MATCHCASE;
1280 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1281 *lpFlags |= FR_FINDNEXT;
1282 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1283 GetWindowLong32A(hWnd, DWL_USER) );
1284 return TRUE;
1285 case IDCANCEL:
1286 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1287 *lpFlags |= FR_DIALOGTERM;
1288 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1289 GetWindowLong32A(hWnd, DWL_USER) );
1290 DestroyWindow32(hWnd);
1291 return TRUE;
1292 case psh1:
1293 if (fUnicode)
1295 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1296 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1297 } else
1299 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1300 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1302 if (IsDlgButtonChecked32(hWnd, chx1))
1303 *lpFlags |= FR_WHOLEWORD;
1304 else *lpFlags &= ~FR_WHOLEWORD;
1305 if (IsDlgButtonChecked32(hWnd, chx2))
1306 *lpFlags |= FR_MATCHCASE;
1307 else *lpFlags &= ~FR_MATCHCASE;
1308 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
1309 *lpFlags |= FR_REPLACE;
1310 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1311 GetWindowLong32A(hWnd, DWL_USER) );
1312 return TRUE;
1313 case psh2:
1314 if (fUnicode)
1316 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1317 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1318 } else
1320 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1321 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1323 if (IsDlgButtonChecked32(hWnd, chx1))
1324 *lpFlags |= FR_WHOLEWORD;
1325 else *lpFlags &= ~FR_WHOLEWORD;
1326 if (IsDlgButtonChecked32(hWnd, chx2))
1327 *lpFlags |= FR_MATCHCASE;
1328 else *lpFlags &= ~FR_MATCHCASE;
1329 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
1330 *lpFlags |= FR_REPLACEALL;
1331 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1332 GetWindowLong32A(hWnd, DWL_USER) );
1333 return TRUE;
1334 case pshHelp:
1335 /* FIXME : should lpfr structure be passed as an argument ??? */
1336 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1337 return TRUE;
1339 return FALSE;
1343 /***********************************************************************
1344 * ReplaceTextDlgProc16 (COMMDLG.14)
1346 LRESULT WINAPI ReplaceTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1347 LPARAM lParam)
1349 LPFINDREPLACE16 lpfr;
1350 switch (wMsg) {
1351 case WM_INITDIALOG:
1352 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1353 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1354 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1355 PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith), FALSE);
1356 case WM_COMMAND:
1357 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1358 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1359 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1360 lpfr->wFindWhatLen, PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith),
1361 lpfr->wReplaceWithLen, FALSE);
1363 return FALSE;
1366 /***********************************************************************
1367 * ReplaceTextDlgProc32A
1369 LRESULT WINAPI ReplaceTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1370 LPARAM lParam)
1372 LPFINDREPLACE32A lpfr;
1373 switch (wMsg) {
1374 case WM_INITDIALOG:
1375 lpfr=(LPFINDREPLACE32A)lParam;
1376 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1377 lpfr->lpstrFindWhat, lpfr->lpstrReplaceWith, FALSE);
1378 case WM_COMMAND:
1379 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1380 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1381 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1382 lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, FALSE);
1384 return FALSE;
1387 /***********************************************************************
1388 * ReplaceTextDlgProc32W
1390 LRESULT WINAPI ReplaceTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1391 LPARAM lParam)
1393 LPFINDREPLACE32W lpfr;
1394 switch (wMsg) {
1395 case WM_INITDIALOG:
1396 lpfr=(LPFINDREPLACE32W)lParam;
1397 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1398 (LPSTR)lpfr->lpstrFindWhat, (LPSTR)lpfr->lpstrReplaceWith,
1399 TRUE);
1400 case WM_COMMAND:
1401 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1402 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1403 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1404 (LPSTR)lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, TRUE);
1406 return FALSE;
1410 /***********************************************************************
1411 * PrintDlg16 (COMMDLG.20)
1413 BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
1415 HANDLE16 hInst;
1416 BOOL16 bRet = FALSE;
1417 LPCVOID template;
1418 HWND32 hwndDialog;
1419 LPPRINTDLG16 lpPrint = (LPPRINTDLG16)PTR_SEG_TO_LIN(printdlg);
1421 TRACE(commdlg,"(%p) -- Flags=%08lX\n", lpPrint, lpPrint->Flags );
1423 if (lpPrint->Flags & PD_RETURNDEFAULT)
1424 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1425 return TRUE;
1427 if (lpPrint->Flags & PD_PRINTSETUP)
1428 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
1429 else
1430 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
1432 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1433 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
1434 lpPrint->hwndOwner,
1435 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
1436 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1437 MODULE_GetWndProcEntry16("PrintDlgProc")),
1438 printdlg, WIN_PROC_16 );
1439 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
1440 return bRet;
1444 /***********************************************************************
1445 * PrintDlg32A (COMDLG32.17)
1447 BOOL32 WINAPI PrintDlg32A( LPPRINTDLG32A printdlg )
1449 FIXME(commdlg, "empty stub\n" );
1450 return FALSE;
1454 /***********************************************************************
1455 * PrintDlg32W (COMDLG32.18)
1457 BOOL32 WINAPI PrintDlg32W( LPPRINTDLG32W printdlg )
1459 FIXME(commdlg, "empty stub\n" );
1460 return FALSE;
1464 /***********************************************************************
1465 * PrintDlgProc (COMMDLG.21)
1467 LRESULT WINAPI PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1468 LPARAM lParam)
1470 switch (wMsg)
1472 case WM_INITDIALOG:
1473 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1474 ShowWindow16(hWnd, SW_SHOWNORMAL);
1475 return (TRUE);
1476 case WM_COMMAND:
1477 switch (wParam)
1479 case IDOK:
1480 EndDialog32(hWnd, TRUE);
1481 return(TRUE);
1482 case IDCANCEL:
1483 EndDialog32(hWnd, FALSE);
1484 return(TRUE);
1486 return(FALSE);
1488 return FALSE;
1492 /***********************************************************************
1493 * PrintSetupDlgProc (COMMDLG.22)
1495 LRESULT WINAPI PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1496 LPARAM lParam)
1498 switch (wMsg)
1500 case WM_INITDIALOG:
1501 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1502 ShowWindow16(hWnd, SW_SHOWNORMAL);
1503 return (TRUE);
1504 case WM_COMMAND:
1505 switch (wParam) {
1506 case IDOK:
1507 EndDialog32(hWnd, TRUE);
1508 return(TRUE);
1509 case IDCANCEL:
1510 EndDialog32(hWnd, FALSE);
1511 return(TRUE);
1513 return(FALSE);
1515 return FALSE;
1519 /***********************************************************************
1520 * CommDlgExtendedError (COMMDLG.26)
1522 DWORD WINAPI CommDlgExtendedError(void)
1524 return CommDlgLastError;
1527 /***********************************************************************
1528 * GetFileTitleA (COMDLG32.8)
1530 short WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
1532 int i, len;
1533 TRACE(commdlg,"(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1534 if (lpFile == NULL || lpTitle == NULL)
1535 return -1;
1536 len = strlen(lpFile);
1537 if (len == 0)
1538 return -1;
1539 if (strpbrk(lpFile, "*[]"))
1540 return -1;
1541 len--;
1542 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1543 return -1;
1544 for (i = len; i >= 0; i--)
1545 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1547 i++;
1548 break;
1550 TRACE(commdlg,"---> '%s' \n", &lpFile[i]);
1552 len = strlen(lpFile+i)+1;
1553 if (cbBuf < len)
1554 return len;
1556 strncpy(lpTitle, &lpFile[i], len);
1557 return 0;
1561 /***********************************************************************
1562 * GetFileTitleA (COMDLG32.8)
1564 short WINAPI GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf)
1566 LPSTR file = HEAP_strdupWtoA(GetProcessHeap(),0,lpFile);
1567 LPSTR title = HeapAlloc(GetProcessHeap(),0,cbBuf);
1568 short ret;
1570 ret = GetFileTitle32A(file,title,cbBuf);
1572 lstrcpynAtoW(lpTitle,title,cbBuf);
1573 HeapFree(GetProcessHeap(),0,file);
1574 HeapFree(GetProcessHeap(),0,title);
1575 return ret;
1577 /***********************************************************************
1578 * GetFileTitle (COMMDLG.27)
1580 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
1582 return GetFileTitle32A(lpFile,lpTitle,cbBuf);
1586 /* ------------------------ Choose Color Dialog --------------------------- */
1588 /***********************************************************************
1589 * ChooseColor (COMMDLG.5)
1591 BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol)
1593 HINSTANCE16 hInst;
1594 HANDLE16 hDlgTmpl = 0;
1595 BOOL16 bRet = FALSE, win32Format = FALSE;
1596 LPCVOID template;
1597 HWND32 hwndDialog;
1599 TRACE(commdlg,"ChooseColor\n");
1600 if (!lpChCol) return FALSE;
1602 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1604 if (!(template = LockResource16( lpChCol->hInstance )))
1606 CommDlgLastError = CDERR_LOADRESFAILURE;
1607 return FALSE;
1610 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1612 HANDLE16 hResInfo;
1613 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1614 lpChCol->lpTemplateName,
1615 RT_DIALOG16)))
1617 CommDlgLastError = CDERR_FINDRESFAILURE;
1618 return FALSE;
1620 if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
1621 !(template = LockResource16( hDlgTmpl )))
1623 CommDlgLastError = CDERR_LOADRESFAILURE;
1624 return FALSE;
1627 else
1629 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR );
1630 win32Format = TRUE;
1633 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1634 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
1635 lpChCol->hwndOwner,
1636 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1637 (DWORD)lpChCol, WIN_PROC_16 );
1638 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
1639 if (hDlgTmpl) FreeResource16( hDlgTmpl );
1640 return bRet;
1644 static const COLORREF predefcolors[6][8]=
1646 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1647 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1648 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1649 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1651 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1652 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1653 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1654 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1656 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1657 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1658 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1659 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1662 struct CCPRIVATE
1664 LPCHOOSECOLOR16 lpcc; /* points to public known data structure */
1665 int nextuserdef; /* next free place in user defined color array */
1666 HDC16 hdcMem; /* color graph used for BitBlt() */
1667 HBITMAP16 hbmMem; /* color graph bitmap */
1668 RECT16 fullsize; /* original dialog window size */
1669 UINT16 msetrgb; /* # of SETRGBSTRING message (today not used) */
1670 RECT16 old3angle; /* last position of l-marker */
1671 RECT16 oldcross; /* last position of color/satuation marker */
1672 BOOL32 updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1673 int h;
1674 int s;
1675 int l; /* for temporary storing of hue,sat,lum */
1678 /***********************************************************************
1679 * CC_HSLtoRGB [internal]
1681 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1683 int res=0,maxrgb;
1685 /* hue */
1686 switch(c)
1688 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1689 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1690 case 'B':break;
1693 /* l below 120 */
1694 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1695 if (hue< 80)
1696 res=0;
1697 else
1698 if (hue< 120)
1700 res=(hue-80)* maxrgb; /* 0...10240 */
1701 res/=40; /* 0...256 */
1703 else
1704 if (hue< 200)
1705 res=maxrgb;
1706 else
1708 res=(240-hue)* maxrgb;
1709 res/=40;
1711 res=res-maxrgb/2; /* -128...128 */
1713 /* saturation */
1714 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1716 /* lum above 120 */
1717 if (lum>120 && res<256)
1718 res+=((lum-120) * (256-res))/120;
1720 return MIN(res,255);
1723 /***********************************************************************
1724 * CC_RGBtoHSL [internal]
1726 static int CC_RGBtoHSL(char c,int r,int g,int b)
1728 WORD maxi,mini,mmsum,mmdif,result=0;
1729 int iresult=0;
1731 maxi=MAX(r,b);
1732 maxi=MAX(maxi,g);
1733 mini=MIN(r,b);
1734 mini=MIN(mini,g);
1736 mmsum=maxi+mini;
1737 mmdif=maxi-mini;
1739 switch(c)
1741 /* lum */
1742 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1743 result=mmsum/255; /* 0...240 */
1744 break;
1745 /* saturation */
1746 case 'S':if (!mmsum)
1747 result=0;
1748 else
1749 if (!mini || maxi==255)
1750 result=240;
1751 else
1753 result=mmdif*240; /* 0...61200=255*240 */
1754 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1756 break;
1757 /* hue */
1758 case 'H':if (!mmdif)
1759 result=160;
1760 else
1762 if (maxi==r)
1764 iresult=40*(g-b); /* -10200 ... 10200 */
1765 iresult/=(int)mmdif; /* -40 .. 40 */
1766 if (iresult<0)
1767 iresult+=240; /* 0..40 and 200..240 */
1769 else
1770 if (maxi==g)
1772 iresult=40*(b-r);
1773 iresult/=(int)mmdif;
1774 iresult+=80; /* 40 .. 120 */
1776 else
1777 if (maxi==b)
1779 iresult=40*(r-g);
1780 iresult/=(int)mmdif;
1781 iresult+=160; /* 120 .. 200 */
1783 result=iresult;
1785 break;
1787 return result; /* is this integer arithmetic precise enough ? */
1790 #define DISTANCE 4
1792 /***********************************************************************
1793 * CC_MouseCheckPredefColorArray [internal]
1795 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1796 LPARAM lParam,COLORREF *cr)
1798 HWND16 hwnd;
1799 POINT16 point = MAKEPOINT16(lParam);
1800 RECT16 rect;
1801 int dx,dy,x,y;
1803 ClientToScreen16(hDlg,&point);
1804 hwnd=GetDlgItem32(hDlg,dlgitem);
1805 GetWindowRect16(hwnd,&rect);
1806 if (PtInRect16(&rect,point))
1808 dx=(rect.right-rect.left)/cols;
1809 dy=(rect.bottom-rect.top)/rows;
1810 ScreenToClient16(hwnd,&point);
1812 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1814 x=point.x/dx;
1815 y=point.y/dy;
1816 *cr=predefcolors[y][x];
1817 /* FIXME: Draw_a_Focus_Rect() */
1818 return 1;
1821 return 0;
1824 /***********************************************************************
1825 * CC_MouseCheckUserColorArray [internal]
1827 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1828 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1830 HWND16 hwnd;
1831 POINT16 point = MAKEPOINT16(lParam);
1832 RECT16 rect;
1833 int dx,dy,x,y;
1835 ClientToScreen16(hDlg,&point);
1836 hwnd=GetDlgItem32(hDlg,dlgitem);
1837 GetWindowRect16(hwnd,&rect);
1838 if (PtInRect16(&rect,point))
1840 dx=(rect.right-rect.left)/cols;
1841 dy=(rect.bottom-rect.top)/rows;
1842 ScreenToClient16(hwnd,&point);
1844 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1846 x=point.x/dx;
1847 y=point.y/dy;
1848 *cr=crarr[x+cols*y];
1849 /* FIXME: Draw_a_Focus_Rect() */
1850 return 1;
1853 return 0;
1856 #define MAXVERT 240
1857 #define MAXHORI 239
1859 /* 240 ^...... ^^ 240
1860 | . ||
1861 SAT | . || LUM
1862 | . ||
1863 +-----> 239 ----
1866 /***********************************************************************
1867 * CC_MouseCheckColorGraph [internal]
1869 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1871 HWND32 hwnd;
1872 POINT16 point = MAKEPOINT16(lParam);
1873 RECT16 rect;
1874 long x,y;
1876 ClientToScreen16(hDlg,&point);
1877 hwnd=GetDlgItem32(hDlg,dlgitem);
1878 GetWindowRect16(hwnd,&rect);
1879 if (PtInRect16(&rect,point))
1881 GetClientRect16(hwnd,&rect);
1882 ScreenToClient16(hwnd,&point);
1884 x=(long)point.x*MAXHORI;
1885 x/=rect.right;
1886 y=(long)(rect.bottom-point.y)*MAXVERT;
1887 y/=rect.bottom;
1889 if (hori)
1890 *hori=x;
1891 if (vert)
1892 *vert=y;
1893 return 1;
1895 else
1896 return 0;
1898 /***********************************************************************
1899 * CC_MouseCheckResultWindow [internal]
1901 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
1903 HWND16 hwnd;
1904 POINT16 point = MAKEPOINT16(lParam);
1905 RECT16 rect;
1907 ClientToScreen16(hDlg,&point);
1908 hwnd=GetDlgItem32(hDlg,0x2c5);
1909 GetWindowRect16(hwnd,&rect);
1910 if (PtInRect16(&rect,point))
1912 PostMessage16(hDlg,WM_COMMAND,0x2c9,0);
1913 return 1;
1915 return 0;
1918 /***********************************************************************
1919 * CC_CheckDigitsInEdit [internal]
1921 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
1923 int i,k,m,result,value;
1924 long editpos;
1925 char buffer[30];
1926 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1927 m=strlen(buffer);
1928 result=0;
1930 for (i=0;i<m;i++)
1931 if (buffer[i]<'0' || buffer[i]>'9')
1933 for (k=i+1;k<=m;k++) /* delete bad character */
1935 buffer[i]=buffer[k];
1936 m--;
1938 buffer[m]=0;
1939 result=1;
1942 value=atoi(buffer);
1943 if (value>maxval) /* build a new string */
1945 sprintf(buffer,"%d",maxval);
1946 result=2;
1948 if (result)
1950 editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
1951 SetWindowText32A(hwnd,buffer);
1952 SendMessage16(hwnd,EM_SETSEL16,0,editpos);
1954 return value;
1959 /***********************************************************************
1960 * CC_PaintSelectedColor [internal]
1962 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
1964 RECT16 rect;
1965 HDC32 hdc;
1966 HBRUSH32 hBrush;
1967 HWND32 hwnd=GetDlgItem32(hDlg,0x2c5);
1968 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1970 hdc=GetDC32(hwnd);
1971 GetClientRect16 (hwnd, &rect) ;
1972 hBrush = CreateSolidBrush32(cr);
1973 if (hBrush)
1975 hBrush = SelectObject32 (hdc, hBrush) ;
1976 Rectangle32(hdc, rect.left,rect.top,rect.right/2,rect.bottom);
1977 DeleteObject32 (SelectObject32 (hdc,hBrush)) ;
1978 hBrush=CreateSolidBrush32(GetNearestColor32(hdc,cr));
1979 if (hBrush)
1981 hBrush= SelectObject32 (hdc, hBrush) ;
1982 Rectangle32( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
1983 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
1986 ReleaseDC32(hwnd,hdc);
1990 /***********************************************************************
1991 * CC_PaintTriangle [internal]
1993 static void CC_PaintTriangle(HWND16 hDlg,int y)
1995 HDC32 hDC;
1996 long temp;
1997 int w=GetDialogBaseUnits();
1998 POINT16 points[3];
1999 int height;
2000 int oben;
2001 RECT16 rect;
2002 HWND16 hwnd=GetDlgItem32(hDlg,0x2be);
2003 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2005 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2007 GetClientRect16(hwnd,&rect);
2008 height=rect.bottom;
2009 hDC=GetDC32(hDlg);
2011 points[0].y=rect.top;
2012 points[0].x=rect.right; /* | /| */
2013 ClientToScreen16(hwnd,points); /* | / | */
2014 ScreenToClient16(hDlg,points); /* |< | */
2015 oben=points[0].y; /* | \ | */
2016 /* | \| */
2017 temp=(long)height*(long)y;
2018 points[0].y=oben+height -temp/(long)MAXVERT;
2019 points[1].y=points[0].y+w;
2020 points[2].y=points[0].y-w;
2021 points[2].x=points[1].x=points[0].x + w;
2023 if (lpp->old3angle.left)
2024 FillRect16(hDC,&lpp->old3angle,GetStockObject32(WHITE_BRUSH));
2025 lpp->old3angle.left =points[0].x;
2026 lpp->old3angle.right =points[1].x+1;
2027 lpp->old3angle.top =points[2].y-1;
2028 lpp->old3angle.bottom=points[1].y+1;
2029 Polygon16(hDC,points,3);
2030 ReleaseDC32(hDlg,hDC);
2035 /***********************************************************************
2036 * CC_PaintCross [internal]
2038 static void CC_PaintCross(HWND16 hDlg,int x,int y)
2040 HDC32 hDC;
2041 int w=GetDialogBaseUnits();
2042 HWND16 hwnd=GetDlgItem32(hDlg,0x2c6);
2043 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2044 RECT16 rect;
2045 POINT16 point;
2046 HPEN32 hPen;
2048 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2050 GetClientRect16(hwnd,&rect);
2051 hDC=GetDC32(hwnd);
2052 SelectClipRgn32(hDC,CreateRectRgnIndirect16(&rect));
2053 hPen=CreatePen32(PS_SOLID,2,0);
2054 hPen=SelectObject32(hDC,hPen);
2055 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
2056 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
2057 if (lpp->oldcross.left!=lpp->oldcross.right)
2058 BitBlt32(hDC,lpp->oldcross.left,lpp->oldcross.top,
2059 lpp->oldcross.right-lpp->oldcross.left,
2060 lpp->oldcross.bottom-lpp->oldcross.top,
2061 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
2062 lpp->oldcross.left =point.x-w-1;
2063 lpp->oldcross.right =point.x+w+1;
2064 lpp->oldcross.top =point.y-w-1;
2065 lpp->oldcross.bottom=point.y+w+1;
2067 MoveTo(hDC,point.x-w,point.y);
2068 LineTo32(hDC,point.x+w,point.y);
2069 MoveTo(hDC,point.x,point.y-w);
2070 LineTo32(hDC,point.x,point.y+w);
2071 DeleteObject32(SelectObject32(hDC,hPen));
2072 ReleaseDC32(hwnd,hDC);
2077 #define XSTEPS 48
2078 #define YSTEPS 24
2081 /***********************************************************************
2082 * CC_PrepareColorGraph [internal]
2084 static void CC_PrepareColorGraph(HWND16 hDlg)
2086 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
2087 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2088 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2089 HBRUSH32 hbrush;
2090 HDC32 hdc ;
2091 RECT16 rect,client;
2092 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT16));
2094 GetClientRect16(hwnd,&client);
2095 hdc=GetDC32(hwnd);
2096 lpp->hdcMem = CreateCompatibleDC32(hdc);
2097 lpp->hbmMem = CreateCompatibleBitmap32(hdc,client.right,client.bottom);
2098 SelectObject32(lpp->hdcMem,lpp->hbmMem);
2100 xdif=client.right /XSTEPS;
2101 ydif=client.bottom/YSTEPS+1;
2102 hdif=239/XSTEPS;
2103 sdif=240/YSTEPS;
2104 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
2106 rect.right=rect.left+xdif;
2107 rect.bottom=client.bottom;
2108 for(sat=0;sat<240+sdif;sat+=sdif)
2110 rect.top=rect.bottom-ydif;
2111 r=CC_HSLtoRGB('R',hue,sat,120);
2112 g=CC_HSLtoRGB('G',hue,sat,120);
2113 b=CC_HSLtoRGB('B',hue,sat,120);
2114 hbrush=CreateSolidBrush32(RGB(r,g,b));
2115 FillRect16(lpp->hdcMem,&rect,hbrush);
2116 DeleteObject32(hbrush);
2117 rect.bottom=rect.top;
2119 rect.left=rect.right;
2121 ReleaseDC32(hwnd,hdc);
2122 SetCursor16(hcursor);
2125 /***********************************************************************
2126 * CC_PaintColorGraph [internal]
2128 static void CC_PaintColorGraph(HWND16 hDlg)
2130 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2131 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2132 HDC32 hDC;
2133 RECT16 rect;
2134 if (IsWindowVisible32(hwnd)) /* if full size */
2136 if (!lpp->hdcMem)
2137 CC_PrepareColorGraph(hDlg); /* should not be necessary */
2139 hDC=GetDC32(hwnd);
2140 GetClientRect16(hwnd,&rect);
2141 if (lpp->hdcMem)
2142 BitBlt32(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
2143 else
2144 WARN(commdlg,"choose color: hdcMem is not defined\n");
2145 ReleaseDC32(hwnd,hDC);
2148 /***********************************************************************
2149 * CC_PaintLumBar [internal]
2151 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
2153 HWND32 hwnd=GetDlgItem32(hDlg,0x2be);
2154 RECT16 rect,client;
2155 int lum,ldif,ydif,r,g,b;
2156 HBRUSH32 hbrush;
2157 HDC32 hDC;
2159 if (IsWindowVisible32(hwnd))
2161 hDC=GetDC32(hwnd);
2162 GetClientRect16(hwnd,&client);
2163 rect=client;
2165 ldif=240/YSTEPS;
2166 ydif=client.bottom/YSTEPS+1;
2167 for(lum=0;lum<240+ldif;lum+=ldif)
2169 rect.top=MAX(0,rect.bottom-ydif);
2170 r=CC_HSLtoRGB('R',hue,sat,lum);
2171 g=CC_HSLtoRGB('G',hue,sat,lum);
2172 b=CC_HSLtoRGB('B',hue,sat,lum);
2173 hbrush=CreateSolidBrush32(RGB(r,g,b));
2174 FillRect16(hDC,&rect,hbrush);
2175 DeleteObject32(hbrush);
2176 rect.bottom=rect.top;
2178 GetClientRect16(hwnd,&rect);
2179 FrameRect16(hDC,&rect,GetStockObject32(BLACK_BRUSH));
2180 ReleaseDC32(hwnd,hDC);
2184 /***********************************************************************
2185 * CC_EditSetRGB [internal]
2187 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
2189 char buffer[10];
2190 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2191 int r=GetRValue(cr);
2192 int g=GetGValue(cr);
2193 int b=GetBValue(cr);
2194 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2196 lpp->updating=TRUE;
2197 sprintf(buffer,"%d",r);
2198 SetWindowText32A(GetDlgItem32(hDlg,0x2c2),buffer);
2199 sprintf(buffer,"%d",g);
2200 SetWindowText32A(GetDlgItem32(hDlg,0x2c3),buffer);
2201 sprintf(buffer,"%d",b);
2202 SetWindowText32A(GetDlgItem32(hDlg,0x2c4),buffer);
2203 lpp->updating=FALSE;
2207 /***********************************************************************
2208 * CC_EditSetHSL [internal]
2210 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
2212 char buffer[10];
2213 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2214 lpp->updating=TRUE;
2215 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2217 lpp->updating=TRUE;
2218 sprintf(buffer,"%d",h);
2219 SetWindowText32A(GetDlgItem32(hDlg,0x2bf),buffer);
2220 sprintf(buffer,"%d",s);
2221 SetWindowText32A(GetDlgItem32(hDlg,0x2c0),buffer);
2222 sprintf(buffer,"%d",l);
2223 SetWindowText32A(GetDlgItem32(hDlg,0x2c1),buffer);
2224 lpp->updating=FALSE;
2226 CC_PaintLumBar(hDlg,h,s);
2229 /***********************************************************************
2230 * CC_SwitchToFullSize [internal]
2232 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
2234 int i;
2235 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2237 EnableWindow32(GetDlgItem32(hDlg,0x2cf),FALSE);
2238 CC_PrepareColorGraph(hDlg);
2239 for (i=0x2bf;i<0x2c5;i++)
2240 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2241 for (i=0x2d3;i<0x2d9;i++)
2242 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2243 EnableWindow32(GetDlgItem32(hDlg,0x2c9),TRUE);
2244 EnableWindow32(GetDlgItem32(hDlg,0x2c8),TRUE);
2246 if (lprect)
2247 SetWindowPos32(hDlg,NULL,0,0,lprect->right-lprect->left,
2248 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
2250 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_SHOW);
2251 ShowWindow32(GetDlgItem32(hDlg,0x2be),SW_SHOW);
2252 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_SHOW);
2254 CC_EditSetRGB(hDlg,result);
2255 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2258 /***********************************************************************
2259 * CC_PaintPredefColorArray [internal]
2261 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
2263 HWND32 hwnd=GetDlgItem32(hDlg,0x2d0);
2264 RECT16 rect;
2265 HDC32 hdc;
2266 HBRUSH32 hBrush;
2267 int dx,dy,i,j,k;
2269 GetClientRect16(hwnd,&rect);
2270 dx=rect.right/cols;
2271 dy=rect.bottom/rows;
2272 k=rect.left;
2274 hdc=GetDC32(hwnd);
2275 GetClientRect16 (hwnd, &rect) ;
2277 for (j=0;j<rows;j++)
2279 for (i=0;i<cols;i++)
2281 hBrush = CreateSolidBrush32(predefcolors[j][i]);
2282 if (hBrush)
2284 hBrush = SelectObject32 (hdc, hBrush) ;
2285 Rectangle32(hdc, rect.left, rect.top,
2286 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2287 rect.left=rect.left+dx;
2288 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2291 rect.top=rect.top+dy;
2292 rect.left=k;
2294 ReleaseDC32(hwnd,hdc);
2295 /* FIXME: draw_a_focus_rect */
2297 /***********************************************************************
2298 * CC_PaintUserColorArray [internal]
2300 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
2302 HWND32 hwnd=GetDlgItem32(hDlg,0x2d1);
2303 RECT16 rect;
2304 HDC32 hdc;
2305 HBRUSH32 hBrush;
2306 int dx,dy,i,j,k;
2308 GetClientRect16(hwnd,&rect);
2310 dx=rect.right/cols;
2311 dy=rect.bottom/rows;
2312 k=rect.left;
2314 hdc=GetDC32(hwnd);
2315 if (hdc)
2317 for (j=0;j<rows;j++)
2319 for (i=0;i<cols;i++)
2321 hBrush = CreateSolidBrush32(lpcr[i+j*cols]);
2322 if (hBrush)
2324 hBrush = SelectObject32 (hdc, hBrush) ;
2325 Rectangle32( hdc, rect.left, rect.top,
2326 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2327 rect.left=rect.left+dx;
2328 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2331 rect.top=rect.top+dy;
2332 rect.left=k;
2334 ReleaseDC32(hwnd,hdc);
2336 /* FIXME: draw_a_focus_rect */
2341 /***********************************************************************
2342 * CC_HookCallChk [internal]
2344 static BOOL32 CC_HookCallChk(LPCHOOSECOLOR16 lpcc)
2346 if (lpcc)
2347 if(lpcc->Flags & CC_ENABLEHOOK)
2348 if (lpcc->lpfnHook)
2349 return TRUE;
2350 return FALSE;
2353 /***********************************************************************
2354 * CC_WMInitDialog [internal]
2356 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2358 int i,res;
2359 HWND16 hwnd;
2360 RECT16 rect;
2361 POINT16 point;
2362 struct CCPRIVATE * lpp;
2364 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
2365 lpp=calloc(1,sizeof(struct CCPRIVATE));
2366 lpp->lpcc=(LPCHOOSECOLOR16)lParam;
2367 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR16))
2369 EndDialog32 (hDlg, 0) ;
2370 return FALSE;
2372 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
2374 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
2375 ShowWindow32(GetDlgItem32(hDlg,0x40e),SW_HIDE);
2376 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
2377 #if 0
2378 cpos=MAKELONG(5,7); /* init */
2379 if (lpp->lpcc->Flags & CC_RGBINIT)
2381 for (i=0;i<6;i++)
2382 for (j=0;j<8;j++)
2383 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
2385 cpos=MAKELONG(i,j);
2386 goto found;
2389 found:
2390 /* FIXME: Draw_a_focus_rect & set_init_values */
2391 #endif
2392 GetWindowRect16(hDlg,&lpp->fullsize);
2393 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2395 hwnd=GetDlgItem32(hDlg,0x2cf);
2396 EnableWindow32(hwnd,FALSE);
2398 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2400 rect=lpp->fullsize;
2401 res=rect.bottom-rect.top;
2402 hwnd=GetDlgItem32(hDlg,0x2c6); /* cut at left border */
2403 point.x=point.y=0;
2404 ClientToScreen16(hwnd,&point);
2405 ScreenToClient16(hDlg,&point);
2406 GetClientRect16(hDlg,&rect);
2407 point.x+=GetSystemMetrics32(SM_CXDLGFRAME);
2408 SetWindowPos32(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
2410 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_HIDE);
2411 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_HIDE);
2413 else
2414 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
2415 res=TRUE;
2416 for (i=0x2bf;i<0x2c5;i++)
2417 SendMessage16(GetDlgItem32(hDlg,i),EM_LIMITTEXT16,3,0); /* max 3 digits: xyz */
2418 if (CC_HookCallChk(lpp->lpcc))
2419 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2420 return res;
2423 /***********************************************************************
2424 * CC_WMCommand [internal]
2426 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2428 int r,g,b,i,xx;
2429 UINT16 cokmsg;
2430 HDC32 hdc;
2431 COLORREF *cr;
2432 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2433 TRACE(commdlg,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
2434 switch (wParam)
2436 case 0x2c2: /* edit notify RGB */
2437 case 0x2c3:
2438 case 0x2c4:
2439 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2441 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
2442 r=GetRValue(lpp->lpcc->rgbResult);
2443 g=GetGValue(lpp->lpcc->rgbResult);
2444 b=GetBValue(lpp->lpcc->rgbResult);
2445 xx=0;
2446 switch (wParam)
2448 case 0x2c2:if ((xx=(i!=r))) r=i;break;
2449 case 0x2c3:if ((xx=(i!=g))) g=i;break;
2450 case 0x2c4:if ((xx=(i!=b))) b=i;break;
2452 if (xx) /* something has changed */
2454 lpp->lpcc->rgbResult=RGB(r,g,b);
2455 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2456 lpp->h=CC_RGBtoHSL('H',r,g,b);
2457 lpp->s=CC_RGBtoHSL('S',r,g,b);
2458 lpp->l=CC_RGBtoHSL('L',r,g,b);
2459 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2460 CC_PaintCross(hDlg,lpp->h,lpp->s);
2461 CC_PaintTriangle(hDlg,lpp->l);
2464 break;
2466 case 0x2bf: /* edit notify HSL */
2467 case 0x2c0:
2468 case 0x2c1:
2469 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2471 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
2472 xx=0;
2473 switch (wParam)
2475 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
2476 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
2477 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
2479 if (xx) /* something has changed */
2481 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2482 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2483 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2484 lpp->lpcc->rgbResult=RGB(r,g,b);
2485 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2486 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2487 CC_PaintCross(hDlg,lpp->h,lpp->s);
2488 CC_PaintTriangle(hDlg,lpp->l);
2491 break;
2493 case 0x2cf:
2494 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
2495 InvalidateRect32( hDlg, NULL, TRUE );
2496 SetFocus32(GetDlgItem32(hDlg,0x2bf));
2497 break;
2499 case 0x2c8: /* add colors ... column by column */
2500 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
2501 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
2502 if (++lpp->nextuserdef==16)
2503 lpp->nextuserdef=0;
2504 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2505 break;
2507 case 0x2c9: /* resulting color */
2508 hdc=GetDC32(hDlg);
2509 lpp->lpcc->rgbResult=GetNearestColor32(hdc,lpp->lpcc->rgbResult);
2510 ReleaseDC32(hDlg,hdc);
2511 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2512 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2513 r=GetRValue(lpp->lpcc->rgbResult);
2514 g=GetGValue(lpp->lpcc->rgbResult);
2515 b=GetBValue(lpp->lpcc->rgbResult);
2516 lpp->h=CC_RGBtoHSL('H',r,g,b);
2517 lpp->s=CC_RGBtoHSL('S',r,g,b);
2518 lpp->l=CC_RGBtoHSL('L',r,g,b);
2519 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2520 CC_PaintCross(hDlg,lpp->h,lpp->s);
2521 CC_PaintTriangle(hDlg,lpp->l);
2522 break;
2524 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2525 i=RegisterWindowMessage32A( HELPMSGSTRING );
2526 if (lpp->lpcc->hwndOwner)
2527 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2528 if (CC_HookCallChk(lpp->lpcc))
2529 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2530 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2531 break;
2533 case IDOK :
2534 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2535 if (lpp->lpcc->hwndOwner)
2536 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2537 break; /* do NOT close */
2539 EndDialog32 (hDlg, 1) ;
2540 return TRUE ;
2542 case IDCANCEL :
2543 EndDialog32 (hDlg, 0) ;
2544 return TRUE ;
2547 return FALSE;
2550 /***********************************************************************
2551 * CC_WMPaint [internal]
2553 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2555 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2556 /* we have to paint dialog children except text and buttons */
2558 CC_PaintPredefColorArray(hDlg,6,8);
2559 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2560 CC_PaintColorGraph(hDlg);
2561 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2562 CC_PaintCross(hDlg,lpp->h,lpp->s);
2563 CC_PaintTriangle(hDlg,lpp->l);
2564 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2566 /* special necessary for Wine */
2567 ValidateRect32(GetDlgItem32(hDlg,0x2d0),NULL);
2568 ValidateRect32(GetDlgItem32(hDlg,0x2d1),NULL);
2569 ValidateRect32(GetDlgItem32(hDlg,0x2c6),NULL);
2570 ValidateRect32(GetDlgItem32(hDlg,0x2be),NULL);
2571 ValidateRect32(GetDlgItem32(hDlg,0x2c5),NULL);
2572 /* hope we can remove it later -->FIXME */
2573 return 0;
2577 /***********************************************************************
2578 * CC_WMLButtonDown [internal]
2580 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2582 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2583 int r,g,b,i;
2584 i=0;
2585 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2586 i=1;
2587 else
2588 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2589 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2590 i=1;
2591 else
2592 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2593 i=2;
2594 else
2595 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2596 i=2;
2597 if (i==2)
2599 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2600 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2601 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2602 lpp->lpcc->rgbResult=RGB(r,g,b);
2604 if (i==1)
2606 r=GetRValue(lpp->lpcc->rgbResult);
2607 g=GetGValue(lpp->lpcc->rgbResult);
2608 b=GetBValue(lpp->lpcc->rgbResult);
2609 lpp->h=CC_RGBtoHSL('H',r,g,b);
2610 lpp->s=CC_RGBtoHSL('S',r,g,b);
2611 lpp->l=CC_RGBtoHSL('L',r,g,b);
2613 if (i)
2615 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2616 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2617 CC_PaintCross(hDlg,lpp->h,lpp->s);
2618 CC_PaintTriangle(hDlg,lpp->l);
2619 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2620 return TRUE;
2622 return FALSE;
2625 /***********************************************************************
2626 * ColorDlgProc (COMMDLG.8)
2628 LRESULT WINAPI ColorDlgProc(HWND16 hDlg, UINT16 message,
2629 WPARAM16 wParam, LONG lParam)
2631 int res;
2632 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2633 if (message!=WM_INITDIALOG)
2635 if (!lpp)
2636 return FALSE;
2637 res=0;
2638 if (CC_HookCallChk(lpp->lpcc))
2639 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2640 if (res)
2641 return res;
2644 /* FIXME: SetRGB message
2645 if (message && message==msetrgb)
2646 return HandleSetRGB(hDlg,lParam);
2649 switch (message)
2651 case WM_INITDIALOG:
2652 return CC_WMInitDialog(hDlg,wParam,lParam);
2653 case WM_NCDESTROY:
2654 DeleteDC32(lpp->hdcMem);
2655 DeleteObject32(lpp->hbmMem);
2656 free(lpp);
2657 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2658 break;
2659 case WM_COMMAND:
2660 if (CC_WMCommand(hDlg, wParam, lParam))
2661 return TRUE;
2662 break;
2663 case WM_PAINT:
2664 CC_WMPaint(hDlg, wParam, lParam);
2665 break;
2666 case WM_LBUTTONDBLCLK:
2667 if (CC_MouseCheckResultWindow(hDlg,lParam))
2668 return TRUE;
2669 break;
2670 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2671 break;
2672 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2673 break;
2674 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2675 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2676 return TRUE;
2677 break;
2679 return FALSE ;
2682 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONT32A chf32a)
2684 chf32a->lStructSize=sizeof(CHOOSEFONT32A);
2685 chf32a->hwndOwner=chf16->hwndOwner;
2686 chf32a->hDC=chf16->hDC;
2687 chf32a->iPointSize=chf16->iPointSize;
2688 chf32a->Flags=chf16->Flags;
2689 chf32a->rgbColors=chf16->rgbColors;
2690 chf32a->lCustData=chf16->lCustData;
2691 chf32a->lpfnHook=NULL;
2692 chf32a->lpTemplateName=PTR_SEG_TO_LIN(chf16->lpTemplateName);
2693 chf32a->hInstance=chf16->hInstance;
2694 chf32a->lpszStyle=PTR_SEG_TO_LIN(chf16->lpszStyle);
2695 chf32a->nFontType=chf16->nFontType;
2696 chf32a->nSizeMax=chf16->nSizeMax;
2697 chf32a->nSizeMin=chf16->nSizeMin;
2698 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16->lpLogFont), chf32a->lpLogFont);
2702 /***********************************************************************
2703 * ChooseFont16 (COMMDLG.15)
2705 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
2707 HINSTANCE16 hInst;
2708 HANDLE16 hDlgTmpl = 0;
2709 BOOL16 bRet = FALSE, win32Format = FALSE;
2710 LPCVOID template;
2711 HWND32 hwndDialog;
2712 CHOOSEFONT32A cf32a;
2713 LOGFONT32A lf32a;
2714 SEGPTR lpTemplateName;
2716 cf32a.lpLogFont=&lf32a;
2717 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
2719 TRACE(commdlg,"ChooseFont\n");
2720 if (!lpChFont) return FALSE;
2722 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
2724 if (!(template = LockResource16( lpChFont->hInstance )))
2726 CommDlgLastError = CDERR_LOADRESFAILURE;
2727 return FALSE;
2730 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2732 HANDLE16 hResInfo;
2733 if (!(hResInfo = FindResource16( lpChFont->hInstance,
2734 lpChFont->lpTemplateName,
2735 RT_DIALOG16)))
2737 CommDlgLastError = CDERR_FINDRESFAILURE;
2738 return FALSE;
2740 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
2741 !(template = LockResource16( hDlgTmpl )))
2743 CommDlgLastError = CDERR_LOADRESFAILURE;
2744 return FALSE;
2747 else
2749 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2750 win32Format = TRUE;
2753 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2755 /* lpTemplateName is not used in the dialog */
2756 lpTemplateName=lpChFont->lpTemplateName;
2757 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
2759 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
2760 lpChFont->hwndOwner,
2761 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2762 (DWORD)lpChFont, WIN_PROC_16 );
2763 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2764 if (hDlgTmpl) FreeResource16( hDlgTmpl );
2765 lpChFont->lpTemplateName=lpTemplateName;
2766 FONT_LogFont32ATo16(cf32a.lpLogFont,
2767 (LPLOGFONT16)(PTR_SEG_TO_LIN(lpChFont->lpLogFont)));
2768 return bRet;
2772 /***********************************************************************
2773 * ChooseFont32A (COMDLG32.3)
2775 BOOL32 WINAPI ChooseFont32A(LPCHOOSEFONT32A lpChFont)
2777 BOOL32 bRet=FALSE;
2778 HWND32 hwndDialog;
2779 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2780 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2781 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2782 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2783 hwndDialog = DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2784 (DLGPROC16)FormatCharDlgProc32A, (LPARAM)lpChFont, WIN_PROC_32A );
2785 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2786 return bRet;
2789 /***********************************************************************
2790 * ChooseFont32W (COMDLG32.4)
2792 BOOL32 WINAPI ChooseFont32W(LPCHOOSEFONT32W lpChFont)
2794 BOOL32 bRet=FALSE;
2795 HWND32 hwndDialog;
2796 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2797 CHOOSEFONT32A cf32a;
2798 LOGFONT32A lf32a;
2799 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2800 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2801 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2802 memcpy(&cf32a, lpChFont, sizeof(cf32a));
2803 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONT32A));
2804 lstrcpynWtoA(lf32a.lfFaceName, lpChFont->lpLogFont->lfFaceName, LF_FACESIZE);
2805 cf32a.lpLogFont=&lf32a;
2806 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
2807 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
2808 hwndDialog=DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2809 (DLGPROC16)FormatCharDlgProc32W, (LPARAM)lpChFont, WIN_PROC_32W );
2810 if (hwndDialog)bRet=DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2811 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
2812 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
2813 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONT32A));
2814 lstrcpynAtoW(lpChFont->lpLogFont->lfFaceName, lf32a.lfFaceName, LF_FACESIZE);
2815 return bRet;
2819 #define TEXT_EXTRAS 4
2820 #define TEXT_COLORS 16
2822 static const COLORREF textcolors[TEXT_COLORS]=
2824 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2825 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2826 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2827 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2830 /***********************************************************************
2831 * CFn_HookCallChk [internal]
2833 static BOOL32 CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
2835 if (lpcf)
2836 if(lpcf->Flags & CF_ENABLEHOOK)
2837 if (lpcf->lpfnHook)
2838 return TRUE;
2839 return FALSE;
2842 /***********************************************************************
2843 * CFn_HookCallChk32 [internal]
2845 static BOOL32 CFn_HookCallChk32(LPCHOOSEFONT32A lpcf)
2847 if (lpcf)
2848 if(lpcf->Flags & CF_ENABLEHOOK)
2849 if (lpcf->lpfnHook)
2850 return TRUE;
2851 return FALSE;
2855 /*************************************************************************
2856 * AddFontFamily [internal]
2858 static INT32 AddFontFamily(LPLOGFONT32A lplf, UINT32 nFontType,
2859 LPCHOOSEFONT32A lpcf, HWND32 hwnd)
2861 int i;
2862 WORD w;
2864 TRACE(commdlg,"font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
2866 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2867 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2868 return 1;
2869 if (lpcf->Flags & CF_ANSIONLY)
2870 if (lplf->lfCharSet != ANSI_CHARSET)
2871 return 1;
2872 if (lpcf->Flags & CF_TTONLY)
2873 if (!(nFontType & TRUETYPE_FONTTYPE))
2874 return 1;
2876 i=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)lplf->lfFaceName);
2877 if (i!=CB_ERR)
2879 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2880 SendMessage32A(hwnd, CB_SETITEMDATA32, i, MAKELONG(nFontType,w));
2881 return 1 ; /* store some important font information */
2883 else
2884 return 0;
2887 typedef struct
2889 HWND32 hWnd1;
2890 HWND32 hWnd2;
2891 LPCHOOSEFONT32A lpcf32a;
2892 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
2894 /*************************************************************************
2895 * FontFamilyEnumProc32 [internal]
2897 INT32 WINAPI FontFamilyEnumProc32(LPENUMLOGFONT32A lpEnumLogFont,
2898 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam)
2900 LPCFn_ENUMSTRUCT e;
2901 e=(LPCFn_ENUMSTRUCT)lParam;
2902 return AddFontFamily(&lpEnumLogFont->elfLogFont, nFontType, e->lpcf32a, e->hWnd1);
2905 /***********************************************************************
2906 * FontFamilyEnumProc16 (COMMDLG.19)
2908 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
2909 UINT16 nFontType, LPARAM lParam )
2911 HWND16 hwnd=LOWORD(lParam);
2912 HWND16 hDlg=GetParent16(hwnd);
2913 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
2914 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
2915 LOGFONT32A lf32a;
2916 FONT_LogFont16To32A(lplf, &lf32a);
2917 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
2918 hwnd);
2921 /*************************************************************************
2922 * SetFontStylesToCombo2 [internal]
2924 * Fill font style information into combobox (without using font.c directly)
2926 static int SetFontStylesToCombo2(HWND32 hwnd, HDC32 hdc, LPLOGFONT32A lplf)
2928 #define FSTYLES 4
2929 struct FONTSTYLE
2930 { int italic;
2931 int weight;
2932 char stname[20]; };
2933 static struct FONTSTYLE fontstyles[FSTYLES]={
2934 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
2935 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
2936 HFONT16 hf;
2937 TEXTMETRIC16 tm;
2938 int i,j;
2940 for (i=0;i<FSTYLES;i++)
2942 lplf->lfItalic=fontstyles[i].italic;
2943 lplf->lfWeight=fontstyles[i].weight;
2944 hf=CreateFontIndirect32A(lplf);
2945 hf=SelectObject32(hdc,hf);
2946 GetTextMetrics16(hdc,&tm);
2947 hf=SelectObject32(hdc,hf);
2948 DeleteObject32(hf);
2950 if (tm.tmWeight==fontstyles[i].weight &&
2951 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
2953 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
2954 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
2955 SEGPTR_FREE(str);
2956 if (j==CB_ERR) return 1;
2957 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
2958 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
2959 if (j==CB_ERR) return 1;
2962 return 0;
2965 /*************************************************************************
2966 * AddFontSizeToCombo3 [internal]
2968 static int AddFontSizeToCombo3(HWND32 hwnd, UINT32 h, LPCHOOSEFONT32A lpcf)
2970 int j;
2971 char buffer[20];
2973 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2974 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
2976 sprintf(buffer, "%2d", h);
2977 j=SendMessage32A(hwnd, CB_FINDSTRINGEXACT32, -1, (LPARAM)buffer);
2978 if (j==CB_ERR)
2980 j=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)buffer);
2981 if (j!=CB_ERR) j = SendMessage32A(hwnd, CB_SETITEMDATA32, j, h);
2982 if (j==CB_ERR) return 1;
2985 return 0;
2988 /*************************************************************************
2989 * SetFontSizesToCombo3 [internal]
2991 static int SetFontSizesToCombo3(HWND32 hwnd, LPCHOOSEFONT32A lpcf)
2993 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2994 int i;
2996 for (i=0; sizes[i]; i++)
2997 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
2998 return 0;
3001 /***********************************************************************
3002 * AddFontStyle [internal]
3004 INT32 AddFontStyle(LPLOGFONT32A lplf, UINT32 nFontType,
3005 LPCHOOSEFONT32A lpcf, HWND32 hcmb2, HWND32 hcmb3, HWND32 hDlg)
3007 int i;
3009 TRACE(commdlg,"(nFontType=%d)\n",nFontType);
3010 TRACE(commdlg," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
3011 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
3012 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
3013 lplf->lfEscapement,lplf->lfOrientation,
3014 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
3015 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
3016 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
3017 if (nFontType & RASTER_FONTTYPE)
3019 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
3020 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
3022 if (!SendMessage32A(hcmb2, CB_GETCOUNT32, 0, 0))
3024 HDC32 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3025 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
3026 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3027 ReleaseDC32(hDlg,hdc);
3028 if (i)
3029 return 0;
3031 return 1 ;
3035 /***********************************************************************
3036 * FontStyleEnumProc16 (COMMDLG.18)
3038 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
3039 UINT16 nFontType, LPARAM lParam )
3041 HWND16 hcmb2=LOWORD(lParam);
3042 HWND16 hcmb3=HIWORD(lParam);
3043 HWND16 hDlg=GetParent16(hcmb3);
3044 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3045 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
3046 LOGFONT32A lf32a;
3047 FONT_LogFont16To32A(lplf, &lf32a);
3048 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
3049 hcmb2, hcmb3, hDlg);
3052 /***********************************************************************
3053 * FontStyleEnumProc32 [internal]
3055 INT32 WINAPI FontStyleEnumProc32( LPENUMLOGFONT32A lpFont,
3056 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam )
3058 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
3059 HWND32 hcmb2=s->hWnd1;
3060 HWND32 hcmb3=s->hWnd2;
3061 HWND32 hDlg=GetParent32(hcmb3);
3062 return AddFontStyle(&lpFont->elfLogFont, nFontType, s->lpcf32a, hcmb2,
3063 hcmb3, hDlg);
3066 /***********************************************************************
3067 * CFn_WMInitDialog [internal]
3069 LRESULT CFn_WMInitDialog(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3070 LPCHOOSEFONT32A lpcf)
3072 HDC32 hdc;
3073 int i,j,res,init=0;
3074 long l;
3075 LPLOGFONT32A lpxx;
3076 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3078 SetWindowLong32A(hDlg, DWL_USER, lParam);
3079 lpxx=lpcf->lpLogFont;
3080 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
3082 if (lpcf->lStructSize != sizeof(CHOOSEFONT32A))
3084 ERR(commdlg,"structure size failure !!!\n");
3085 EndDialog32 (hDlg, 0);
3086 return FALSE;
3088 if (!hBitmapTT)
3089 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3091 /* This font will be deleted by WM_COMMAND */
3092 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,
3093 CreateFont32A(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
3095 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow32(lpcf->hwndOwner))
3096 ShowWindow32(GetDlgItem32(hDlg,pshHelp),SW_HIDE);
3097 if (!(lpcf->Flags & CF_APPLY))
3098 ShowWindow32(GetDlgItem32(hDlg,psh3),SW_HIDE);
3099 if (lpcf->Flags & CF_EFFECTS)
3101 for (res=1,i=0;res && i<TEXT_COLORS;i++)
3103 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
3104 char name[20];
3105 strcpy( name, "[color name]" );
3106 j=SendDlgItemMessage32A(hDlg, cmb4, CB_ADDSTRING32, 0, (LPARAM)name);
3107 SendDlgItemMessage32A(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
3108 /* look for a fitting value in color combobox */
3109 if (textcolors[j]==lpcf->rgbColors)
3110 SendDlgItemMessage32A(hDlg,cmb4, CB_SETCURSEL32,j,0);
3113 else
3115 ShowWindow32(GetDlgItem32(hDlg,cmb4),SW_HIDE);
3116 ShowWindow32(GetDlgItem32(hDlg,chx1),SW_HIDE);
3117 ShowWindow32(GetDlgItem32(hDlg,chx2),SW_HIDE);
3118 ShowWindow32(GetDlgItem32(hDlg,grp1),SW_HIDE);
3119 ShowWindow32(GetDlgItem32(hDlg,stc4),SW_HIDE);
3121 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3122 if (hdc)
3124 CFn_ENUMSTRUCT s;
3125 s.hWnd1=GetDlgItem32(hDlg,cmb1);
3126 s.lpcf32a=lpcf;
3127 if (!EnumFontFamilies32A(hdc, NULL, FontFamilyEnumProc32, (LPARAM)&s))
3128 TRACE(commdlg,"EnumFontFamilies returns 0\n");
3129 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
3131 /* look for fitting font name in combobox1 */
3132 j=SendDlgItemMessage32A(hDlg,cmb1,CB_FINDSTRING32,-1,(LONG)lpxx->lfFaceName);
3133 if (j!=CB_ERR)
3135 SendDlgItemMessage32A(hDlg, cmb1, CB_SETCURSEL32, j, 0);
3136 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3137 GetDlgItem32(hDlg,cmb1));
3138 init=1;
3139 /* look for fitting font style in combobox2 */
3140 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
3141 for (i=0;i<TEXT_EXTRAS;i++)
3143 if (l==SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0))
3144 SendDlgItemMessage32A(hDlg, cmb2, CB_SETCURSEL32, i, 0);
3147 /* look for fitting font size in combobox3 */
3148 j=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCOUNT32, 0, 0);
3149 for (i=0;i<j;i++)
3151 if (lpxx->lfHeight==(int)SendDlgItemMessage32A(hDlg,cmb3, CB_GETITEMDATA32,i,0))
3152 SendDlgItemMessage32A(hDlg,cmb3,CB_SETCURSEL32,i,0);
3156 if (!init)
3158 SendDlgItemMessage32A(hDlg,cmb1,CB_SETCURSEL32,0,0);
3159 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3160 GetDlgItem32(hDlg,cmb1));
3162 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
3164 j=SendDlgItemMessage32A(hDlg,cmb2,CB_FINDSTRING32,-1,(LONG)lpcf->lpszStyle);
3165 if (j!=CB_ERR)
3167 j=SendDlgItemMessage32A(hDlg,cmb2,CB_SETCURSEL32,j,0);
3168 SendMessage32A(hDlg,WM_COMMAND,cmb2,
3169 MAKELONG(GetDlgItem32(hDlg,cmb2),CBN_SELCHANGE));
3173 else
3175 WARN(commdlg,"HDC failure !!!\n");
3176 EndDialog32 (hDlg, 0);
3177 return FALSE;
3180 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3181 ReleaseDC32(hDlg,hdc);
3182 SetCursor32(hcursor);
3183 return TRUE;
3187 /***********************************************************************
3188 * CFn_WMMeasureItem [internal]
3190 LRESULT CFn_WMMeasureItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3192 BITMAP32 bm;
3193 LPMEASUREITEMSTRUCT32 lpmi=(LPMEASUREITEMSTRUCT32)lParam;
3194 if (!hBitmapTT)
3195 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3196 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3197 lpmi->itemHeight=bm.bmHeight;
3198 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
3199 return 0;
3203 /***********************************************************************
3204 * CFn_WMDrawItem [internal]
3206 LRESULT CFn_WMDrawItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3208 HBRUSH32 hBrush;
3209 char buffer[40];
3210 BITMAP32 bm;
3211 COLORREF cr, oldText=0, oldBk=0;
3212 RECT32 rect;
3213 #if 0
3214 HDC32 hMemDC;
3215 int nFontType;
3216 HBITMAP32 hBitmap; /* for later TT usage */
3217 #endif
3218 LPDRAWITEMSTRUCT32 lpdi = (LPDRAWITEMSTRUCT32)lParam;
3220 if (lpdi->itemID == 0xFFFF) /* got no items */
3221 DrawFocusRect32(lpdi->hDC, &lpdi->rcItem);
3222 else
3224 if (lpdi->CtlType == ODT_COMBOBOX)
3226 if (lpdi->itemState ==ODS_SELECTED)
3228 hBrush=GetSysColorBrush32(COLOR_HIGHLIGHT);
3229 oldText=SetTextColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHTTEXT));
3230 oldBk=SetBkColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHT));
3231 } else
3233 hBrush = SelectObject32(lpdi->hDC, GetStockObject32(LTGRAY_BRUSH));
3234 SelectObject32(lpdi->hDC, hBrush);
3236 FillRect32(lpdi->hDC, &lpdi->rcItem, hBrush);
3238 else
3239 return TRUE; /* this should never happen */
3241 rect=lpdi->rcItem;
3242 switch (lpdi->CtlID)
3244 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
3245 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3246 (LPARAM)buffer);
3247 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3248 TextOut32A(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
3249 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3250 #if 0
3251 nFontType = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3252 /* FIXME: draw bitmap if truetype usage */
3253 if (nFontType&TRUETYPE_FONTTYPE)
3255 hMemDC = CreateCompatibleDC32(lpdi->hDC);
3256 hBitmap = SelectObject32(hMemDC, hBitmapTT);
3257 BitBlt32(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
3258 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
3259 SelectObject32(hMemDC, hBitmap);
3260 DeleteDC32(hMemDC);
3262 #endif
3263 break;
3264 case cmb2:
3265 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
3266 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3267 (LPARAM)buffer);
3268 TextOut32A(lpdi->hDC, lpdi->rcItem.left,
3269 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3270 break;
3272 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
3273 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3274 (LPARAM)buffer);
3275 TextOut32A(lpdi->hDC, lpdi->rcItem.left + 25+5,
3276 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3277 cr = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3278 hBrush = CreateSolidBrush32(cr);
3279 if (hBrush)
3281 hBrush = SelectObject32 (lpdi->hDC, hBrush) ;
3282 rect.right=rect.left+25;
3283 rect.top++;
3284 rect.left+=5;
3285 rect.bottom--;
3286 Rectangle32( lpdi->hDC, rect.left, rect.top,
3287 rect.right, rect.bottom );
3288 DeleteObject32( SelectObject32 (lpdi->hDC, hBrush)) ;
3290 rect=lpdi->rcItem;
3291 rect.left+=25+5;
3292 break;
3294 default: return TRUE; /* this should never happen */
3296 if (lpdi->itemState == ODS_SELECTED)
3298 SetTextColor32(lpdi->hDC, oldText);
3299 SetBkColor32(lpdi->hDC, oldBk);
3302 return TRUE;
3305 /***********************************************************************
3306 * CFn_WMCtlColor [internal]
3308 LRESULT CFn_WMCtlColorStatic(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3309 LPCHOOSEFONT32A lpcf)
3311 if (lpcf->Flags & CF_EFFECTS)
3312 if (GetDlgCtrlID32(lParam)==stc6)
3314 SetTextColor32((HDC32)wParam, lpcf->rgbColors);
3315 return GetStockObject32(WHITE_BRUSH);
3317 return 0;
3320 /***********************************************************************
3321 * CFn_WMCommand [internal]
3323 LRESULT CFn_WMCommand(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3324 LPCHOOSEFONT32A lpcf)
3326 HFONT32 hFont;
3327 int i,j;
3328 long l;
3329 HDC32 hdc;
3330 LPLOGFONT32A lpxx=lpcf->lpLogFont;
3332 TRACE(commdlg,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
3333 switch (LOWORD(wParam))
3335 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
3337 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3338 if (hdc)
3340 SendDlgItemMessage32A(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
3341 SendDlgItemMessage32A(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
3342 i=SendDlgItemMessage32A(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
3343 if (i!=CB_ERR)
3345 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3346 CFn_ENUMSTRUCT s;
3347 char str[256];
3348 SendDlgItemMessage32A(hDlg, cmb1, CB_GETLBTEXT32, i,
3349 (LPARAM)str);
3350 TRACE(commdlg,"WM_COMMAND/cmb1 =>%s\n",str);
3351 s.hWnd1=GetDlgItem32(hDlg, cmb2);
3352 s.hWnd2=GetDlgItem32(hDlg, cmb3);
3353 s.lpcf32a=lpcf;
3354 EnumFontFamilies32A(hdc, str, FontStyleEnumProc32, (LPARAM)&s);
3355 SetCursor32(hcursor);
3357 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3358 ReleaseDC32(hDlg,hdc);
3360 else
3362 WARN(commdlg,"HDC failure !!!\n");
3363 EndDialog32 (hDlg, 0);
3364 return TRUE;
3367 case chx1:
3368 case chx2:
3369 case cmb2:
3370 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
3372 char str[256];
3373 TRACE(commdlg,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
3374 i=SendDlgItemMessage32A(hDlg,cmb1,CB_GETCURSEL32,0,0);
3375 if (i==CB_ERR)
3376 i=GetDlgItemText32A( hDlg, cmb1, str, 256 );
3377 else
3379 SendDlgItemMessage32A(hDlg,cmb1,CB_GETLBTEXT32,i,
3380 (LPARAM)str);
3381 l=SendDlgItemMessage32A(hDlg,cmb1,CB_GETITEMDATA32,i,0);
3382 j=HIWORD(l);
3383 lpcf->nFontType = LOWORD(l);
3384 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
3385 /* same value reported to the EnumFonts
3386 call back with the extra FONTTYPE_... bits added */
3387 lpxx->lfPitchAndFamily=j&0xff;
3388 lpxx->lfCharSet=j>>8;
3390 strcpy(lpxx->lfFaceName,str);
3391 i=SendDlgItemMessage32A(hDlg, cmb2, CB_GETCURSEL32, 0, 0);
3392 if (i!=CB_ERR)
3394 l=SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0);
3395 if (0!=(lpxx->lfItalic=HIWORD(l)))
3396 lpcf->nFontType |= ITALIC_FONTTYPE;
3397 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
3398 lpcf->nFontType |= BOLD_FONTTYPE;
3400 i=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCURSEL32, 0, 0);
3401 if (i!=CB_ERR)
3402 lpxx->lfHeight=-LOWORD(SendDlgItemMessage32A(hDlg, cmb3, CB_GETITEMDATA32, i, 0));
3403 else
3404 lpxx->lfHeight=0;
3405 lpxx->lfStrikeOut=IsDlgButtonChecked32(hDlg,chx1);
3406 lpxx->lfUnderline=IsDlgButtonChecked32(hDlg,chx2);
3407 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
3408 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
3409 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
3410 lpxx->lfQuality=DEFAULT_QUALITY;
3411 lpcf->iPointSize= -10*lpxx->lfHeight;
3413 hFont=CreateFontIndirect32A(lpxx);
3414 if (hFont)
3416 HFONT32 oldFont=SendDlgItemMessage32A(hDlg, stc6,
3417 WM_GETFONT, 0, 0);
3418 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,hFont,TRUE);
3419 DeleteObject32(oldFont);
3422 break;
3424 case cmb4:i=SendDlgItemMessage32A(hDlg, cmb4, CB_GETCURSEL32, 0, 0);
3425 if (i!=CB_ERR)
3427 lpcf->rgbColors=textcolors[i];
3428 InvalidateRect32( GetDlgItem32(hDlg,stc6), NULL, 0 );
3430 break;
3432 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
3433 if (lpcf->hwndOwner)
3434 SendMessage32A(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLong32A(hDlg, DWL_USER));
3435 /* if (CFn_HookCallChk(lpcf))
3436 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
3437 break;
3439 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
3440 ( (lpcf->Flags & CF_LIMITSIZE) &&
3441 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
3442 (-lpxx->lfHeight <= lpcf->nSizeMax)))
3443 EndDialog32(hDlg, TRUE);
3444 else
3446 char buffer[80];
3447 sprintf(buffer,"Select a font size between %d and %d points.",
3448 lpcf->nSizeMin,lpcf->nSizeMax);
3449 MessageBox32A(hDlg, buffer, NULL, MB_OK);
3451 return(TRUE);
3452 case IDCANCEL:EndDialog32(hDlg, FALSE);
3453 return(TRUE);
3455 return(FALSE);
3458 static LRESULT CFn_WMDestroy(HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
3460 DeleteObject32(SendDlgItemMessage32A(hwnd, stc6, WM_GETFONT, 0, 0));
3461 return TRUE;
3465 /***********************************************************************
3466 * FormatCharDlgProc16 (COMMDLG.16)
3467 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
3468 2. some CF_.. flags are not supported
3469 3. some TType extensions
3471 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
3472 LPARAM lParam)
3474 LPCHOOSEFONT16 lpcf;
3475 LPCHOOSEFONT32A lpcf32a;
3476 UINT32 uMsg32;
3477 WPARAM32 wParam32;
3478 LRESULT res=0;
3479 if (message!=WM_INITDIALOG)
3481 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3482 if (!lpcf)
3483 return FALSE;
3484 if (CFn_HookCallChk(lpcf))
3485 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
3486 if (res)
3487 return res;
3489 else
3491 lpcf=(LPCHOOSEFONT16)lParam;
3492 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3493 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3495 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3496 return FALSE;
3498 if (CFn_HookCallChk(lpcf))
3499 return CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3501 WINPROC_MapMsg16To32A(message, wParam, &uMsg32, &wParam32, &lParam);
3502 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3503 switch (uMsg32)
3505 case WM_MEASUREITEM:
3506 res=CFn_WMMeasureItem(hDlg, wParam32, lParam);
3507 break;
3508 case WM_DRAWITEM:
3509 res=CFn_WMDrawItem(hDlg, wParam32, lParam);
3510 break;
3511 case WM_CTLCOLORSTATIC:
3512 res=CFn_WMCtlColorStatic(hDlg, wParam32, lParam, lpcf32a);
3513 break;
3514 case WM_COMMAND:
3515 res=CFn_WMCommand(hDlg, wParam32, lParam, lpcf32a);
3516 break;
3517 case WM_DESTROY:
3518 res=CFn_WMDestroy(hDlg, wParam32, lParam);
3519 break;
3520 case WM_CHOOSEFONT_GETLOGFONT:
3521 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3522 lParam);
3523 FIXME(commdlg, "current logfont back to caller\n");
3524 break;
3526 WINPROC_UnmapMsg16To32A(uMsg32, wParam32, lParam, res);
3527 return res;
3530 /***********************************************************************
3531 * FormatCharDlgProc32A [internal]
3533 LRESULT WINAPI FormatCharDlgProc32A(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3534 LPARAM lParam)
3536 LPCHOOSEFONT32A lpcf;
3537 LRESULT res=FALSE;
3538 if (uMsg!=WM_INITDIALOG)
3540 lpcf=(LPCHOOSEFONT32A)GetWindowLong32A(hDlg, DWL_USER);
3541 if (!lpcf)
3542 return FALSE;
3543 if (CFn_HookCallChk32(lpcf))
3544 res=CallWindowProc32A(lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
3545 if (res)
3546 return res;
3548 else
3550 lpcf=(LPCHOOSEFONT32A)lParam;
3551 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
3553 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3554 return FALSE;
3556 if (CFn_HookCallChk32(lpcf))
3557 return CallWindowProc32A(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3559 switch (uMsg)
3561 case WM_MEASUREITEM:
3562 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3563 case WM_DRAWITEM:
3564 return CFn_WMDrawItem(hDlg, wParam, lParam);
3565 case WM_CTLCOLORSTATIC:
3566 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
3567 case WM_COMMAND:
3568 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
3569 case WM_DESTROY:
3570 return CFn_WMDestroy(hDlg, wParam, lParam);
3571 case WM_CHOOSEFONT_GETLOGFONT:
3572 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3573 lParam);
3574 FIXME(commdlg, "current logfont back to caller\n");
3575 break;
3577 return res;
3580 /***********************************************************************
3581 * FormatCharDlgProc32W [internal]
3583 LRESULT WINAPI FormatCharDlgProc32W(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3584 LPARAM lParam)
3586 LPCHOOSEFONT32W lpcf32w;
3587 LPCHOOSEFONT32A lpcf32a;
3588 LRESULT res=FALSE;
3589 if (uMsg!=WM_INITDIALOG)
3591 lpcf32w=(LPCHOOSEFONT32W)GetWindowLong32A(hDlg, DWL_USER);
3592 if (!lpcf32w)
3593 return FALSE;
3594 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3595 res=CallWindowProc32W(lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
3596 if (res)
3597 return res;
3599 else
3601 lpcf32w=(LPCHOOSEFONT32W)lParam;
3602 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3603 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3605 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3606 return FALSE;
3608 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3609 return CallWindowProc32W(lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3611 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3612 switch (uMsg)
3614 case WM_MEASUREITEM:
3615 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3616 case WM_DRAWITEM:
3617 return CFn_WMDrawItem(hDlg, wParam, lParam);
3618 case WM_CTLCOLORSTATIC:
3619 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
3620 case WM_COMMAND:
3621 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
3622 case WM_DESTROY:
3623 return CFn_WMDestroy(hDlg, wParam, lParam);
3624 case WM_CHOOSEFONT_GETLOGFONT:
3625 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3626 lParam);
3627 FIXME(commdlg, "current logfont back to caller\n");
3628 break;
3630 return res;
3634 static BOOL32 Commdlg_GetFileName32A( BOOL16 (*dofunction)(),
3635 LPOPENFILENAME32A ofn )
3637 BOOL16 ret;
3638 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3640 memset(ofn16,'\0',sizeof(*ofn16));
3641 ofn16->lStructSize = sizeof(*ofn16);
3642 ofn16->hwndOwner = ofn->hwndOwner;
3643 /* FIXME: OPENFILENAME16 got only 16 bit for HINSTANCE... */
3644 ofn16->hInstance = 0;
3645 if (ofn->lpstrFilter) {
3646 LPSTR s,x;
3648 /* filter is a list... title\0ext\0......\0\0 */
3649 s = (LPSTR)ofn->lpstrFilter;
3650 while (*s)
3651 s = s+strlen(s)+1;
3652 s++;
3653 x = (LPSTR)SEGPTR_ALLOC(s-ofn->lpstrFilter);
3654 memcpy(x,ofn->lpstrFilter,s-ofn->lpstrFilter);
3655 ofn16->lpstrFilter = SEGPTR_GET(x);
3657 if (ofn->lpstrCustomFilter) {
3658 LPSTR s,x;
3660 /* filter is a list... title\0ext\0......\0\0 */
3661 s = (LPSTR)ofn->lpstrCustomFilter;
3662 while (*s)
3663 s = s+strlen(s)+1;
3664 x = SEGPTR_ALLOC(s-ofn->lpstrCustomFilter);
3665 s++;
3666 memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);
3667 ofn16->lpstrCustomFilter = SEGPTR_GET(x);
3669 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3670 ofn16->nFilterIndex = ofn->nFilterIndex;
3671 if (ofn->nMaxFile)
3672 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3673 ofn16->nMaxFile = ofn->nMaxFile;
3674 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3675 if (ofn16->nMaxFileTitle)
3676 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3677 if (ofn->lpstrInitialDir)
3678 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrInitialDir));
3679 if (ofn->lpstrTitle)
3680 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrTitle));
3681 ofn16->Flags = ofn->Flags|OFN_WINE32;
3682 ofn16->nFileOffset = ofn->nFileOffset;
3683 ofn16->nFileExtension = ofn->nFileExtension;
3684 if (ofn->lpstrDefExt)
3685 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrDefExt));
3686 ofn16->lCustData = ofn->lCustData;
3687 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3689 if (ofn->lpTemplateName)
3690 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpTemplateName));
3692 ret = dofunction(SEGPTR_GET(ofn16));
3694 ofn->nFileOffset = ofn16->nFileOffset;
3695 ofn->nFileExtension = ofn16->nFileExtension;
3696 if (ofn16->lpstrFilter)
3697 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3698 if (ofn16->lpTemplateName)
3699 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3700 if (ofn16->lpstrDefExt)
3701 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3702 if (ofn16->lpstrTitle)
3703 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3704 if (ofn16->lpstrInitialDir)
3705 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3706 if (ofn16->lpstrCustomFilter)
3707 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3709 if (ofn16->lpstrFile)
3711 strcpy(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3712 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3715 if (ofn16->lpstrFileTitle)
3717 strcpy(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3718 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3720 SEGPTR_FREE(ofn16);
3721 return ret;
3724 static BOOL32 Commdlg_GetFileName32W( BOOL16 (*dofunction)(),
3725 LPOPENFILENAME32W ofn )
3727 BOOL16 ret;
3728 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3730 memset(ofn16,'\0',sizeof(*ofn16));
3731 ofn16->lStructSize = sizeof(*ofn16);
3732 ofn16->hwndOwner = ofn->hwndOwner;
3733 /* FIXME: OPENFILENAME16 got only 16 bit for HINSTANCE... */
3734 ofn16->hInstance = 0;
3735 if (ofn->lpstrFilter) {
3736 LPWSTR s;
3737 LPSTR x,y;
3738 int n;
3740 /* filter is a list... title\0ext\0......\0\0 */
3741 s = (LPWSTR)ofn->lpstrFilter;
3742 while (*s)
3743 s = s+lstrlen32W(s)+1;
3744 s++;
3745 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
3746 x = y = (LPSTR)SEGPTR_ALLOC(n);
3747 s = (LPWSTR)ofn->lpstrFilter;
3748 while (*s) {
3749 lstrcpyWtoA(x,s);
3750 x+=lstrlen32A(x)+1;
3751 s+=lstrlen32W(s)+1;
3753 *x=0;
3754 ofn16->lpstrFilter = SEGPTR_GET(y);
3756 if (ofn->lpstrCustomFilter) {
3757 LPWSTR s;
3758 LPSTR x,y;
3759 int n;
3761 /* filter is a list... title\0ext\0......\0\0 */
3762 s = (LPWSTR)ofn->lpstrCustomFilter;
3763 while (*s)
3764 s = s+lstrlen32W(s)+1;
3765 s++;
3766 n = s - ofn->lpstrCustomFilter;
3767 x = y = (LPSTR)SEGPTR_ALLOC(n);
3768 s = (LPWSTR)ofn->lpstrCustomFilter;
3769 while (*s) {
3770 lstrcpyWtoA(x,s);
3771 x+=lstrlen32A(x)+1;
3772 s+=lstrlen32W(s)+1;
3774 *x=0;
3775 ofn16->lpstrCustomFilter = SEGPTR_GET(y);
3777 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3778 ofn16->nFilterIndex = ofn->nFilterIndex;
3779 if (ofn->nMaxFile)
3780 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3781 ofn16->nMaxFile = ofn->nMaxFile;
3782 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3783 if (ofn->nMaxFileTitle)
3784 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3785 if (ofn->lpstrInitialDir)
3786 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrInitialDir));
3787 if (ofn->lpstrTitle)
3788 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrTitle));
3789 ofn16->Flags = ofn->Flags|OFN_WINE32|OFN_UNICODE;
3790 ofn16->nFileOffset = ofn->nFileOffset;
3791 ofn16->nFileExtension = ofn->nFileExtension;
3792 if (ofn->lpstrDefExt)
3793 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrDefExt));
3794 ofn16->lCustData = ofn->lCustData;
3795 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3796 if (ofn->lpTemplateName)
3797 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpTemplateName));
3798 ret = dofunction(SEGPTR_GET(ofn16));
3800 ofn->nFileOffset = ofn16->nFileOffset;
3801 ofn->nFileExtension = ofn16->nFileExtension;
3802 if (ofn16->lpstrFilter)
3803 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3804 if (ofn16->lpTemplateName)
3805 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3806 if (ofn16->lpstrDefExt)
3807 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3808 if (ofn16->lpstrTitle)
3809 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3810 if (ofn16->lpstrInitialDir)
3811 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3812 if (ofn16->lpstrCustomFilter)
3813 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3815 if (ofn16->lpstrFile) {
3816 lstrcpyAtoW(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3817 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3820 if (ofn16->lpstrFileTitle) {
3821 lstrcpyAtoW(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3822 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3824 SEGPTR_FREE(ofn16);
3825 return ret;
3828 /***********************************************************************
3829 * GetOpenFileName32A (COMDLG32.10)
3831 BOOL32 WINAPI GetOpenFileName32A( LPOPENFILENAME32A ofn )
3833 BOOL16 (WINAPI * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3834 return Commdlg_GetFileName32A(dofunction,ofn);
3837 /***********************************************************************
3838 * GetOpenFileName32W (COMDLG32.11)
3840 BOOL32 WINAPI GetOpenFileName32W( LPOPENFILENAME32W ofn )
3842 BOOL16 (WINAPI * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3843 return Commdlg_GetFileName32W(dofunction,ofn);
3846 /***********************************************************************
3847 * GetSaveFileName32A (COMDLG32.12)
3849 BOOL32 WINAPI GetSaveFileName32A( LPOPENFILENAME32A ofn )
3851 BOOL16 (WINAPI * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3852 return Commdlg_GetFileName32A(dofunction,ofn);
3855 /***********************************************************************
3856 * GetSaveFileName32W (COMDLG32.13)
3858 BOOL32 WINAPI GetSaveFileName32W( LPOPENFILENAME32W ofn )
3860 BOOL16 (WINAPI * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3861 return Commdlg_GetFileName32W(dofunction,ofn);
3864 /***********************************************************************
3865 * ChooseColorA (COMDLG32.1)
3867 BOOL32 WINAPI ChooseColor32A(LPCHOOSECOLOR32A lpChCol )
3870 BOOL16 ret;
3871 char *str = NULL;
3872 COLORREF* ccref=SEGPTR_ALLOC(64);
3873 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3875 memset(lpcc16,'\0',sizeof(*lpcc16));
3876 lpcc16->lStructSize=sizeof(*lpcc16);
3877 lpcc16->hwndOwner=lpChCol->hwndOwner;
3878 lpcc16->hInstance=0; /* FIXME:MODULE_HANDLEtoHMODULE16(lpChCol->hInstance)*/
3879 lpcc16->rgbResult=lpChCol->rgbResult;
3880 memcpy(ccref,lpChCol->lpCustColors,64);
3881 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3882 lpcc16->Flags=lpChCol->Flags;
3883 lpcc16->lCustData=lpChCol->lCustData;
3884 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3885 if (lpChCol->lpTemplateName)
3886 str = SEGPTR_STRDUP(lpChCol->lpTemplateName );
3887 lpcc16->lpTemplateName=SEGPTR_GET(str);
3889 ret = ChooseColor16(lpcc16);
3890 if(str)
3891 SEGPTR_FREE(str);
3892 memcpy(lpChCol->lpCustColors,ccref,64);
3893 SEGPTR_FREE(ccref);
3894 SEGPTR_FREE(lpcc16);
3895 return (BOOL32)ret;
3898 /***********************************************************************
3899 * ChooseColorW (COMDLG32.2)
3901 BOOL32 WINAPI ChooseColor32W(LPCHOOSECOLOR32W lpChCol )
3904 BOOL16 ret;
3905 char *str = NULL;
3906 COLORREF* ccref=SEGPTR_ALLOC(64);
3907 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3909 memset(lpcc16,'\0',sizeof(*lpcc16));
3910 lpcc16->lStructSize=sizeof(*lpcc16);
3911 lpcc16->hwndOwner=lpChCol->hwndOwner;
3912 lpcc16->hInstance=0; /*FIXME:MODULE_HANDLEtoHMODULE16(lpChCol->hInstance)*/
3913 lpcc16->rgbResult=lpChCol->rgbResult;
3914 memcpy(ccref,lpChCol->lpCustColors,64);
3915 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3916 lpcc16->Flags=lpChCol->Flags;
3917 lpcc16->lCustData=lpChCol->lCustData;
3918 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3919 if (lpChCol->lpTemplateName)
3920 str = SEGPTR_STRDUP_WtoA(lpChCol->lpTemplateName );
3921 lpcc16->lpTemplateName=SEGPTR_GET(str);
3923 ret = ChooseColor16(lpcc16);
3924 if(str)
3925 SEGPTR_FREE(str);
3926 memcpy(lpChCol->lpCustColors,ccref,64);
3927 SEGPTR_FREE(ccref);
3928 SEGPTR_FREE(lpcc16);
3929 return (BOOL32)ret;