Closing a dialog using the menu bar ("x" or "-" button or windows
[wine/multimedia.git] / misc / commdlg.c
blobfa1d6e55bc6fc7a09b6aa3e13727f4f473a23c66
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "win.h"
12 #include "heap.h"
13 #include "message.h"
14 #include "commdlg.h"
15 #include "dialog.h"
16 #include "dlgs.h"
17 #include "module.h"
18 #include "resource.h"
19 #include "drive.h"
20 #include "debug.h"
21 #include "font.h"
22 #include "winproc.h"
24 static DWORD CommDlgLastError = 0;
26 static HBITMAP16 hFolder = 0;
27 static HBITMAP16 hFolder2 = 0;
28 static HBITMAP16 hFloppy = 0;
29 static HBITMAP16 hHDisk = 0;
30 static HBITMAP16 hCDRom = 0;
31 static HBITMAP16 hBitmapTT = 0;
32 static const char defaultfilter[]=" \0\0";
34 /***********************************************************************
35 * FileDlg_Init [internal]
37 static BOOL32 FileDlg_Init()
39 static BOOL32 initialized = 0;
41 if (!initialized) {
42 if (!hFolder) hFolder = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER));
43 if (!hFolder2) hFolder2 = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER2));
44 if (!hFloppy) hFloppy = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FLOPPY));
45 if (!hHDisk) hHDisk = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_HDISK));
46 if (!hCDRom) hCDRom = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CDROM));
47 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
48 hHDisk == 0 || hCDRom == 0)
50 WARN(commdlg, "Error loading bitmaps !\nprin");
51 return FALSE;
53 initialized = TRUE;
55 return TRUE;
58 /***********************************************************************
59 * GetOpenFileName (COMMDLG.1)
61 BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
63 HINSTANCE32 hInst;
64 HANDLE32 hDlgTmpl = 0, hResInfo;
65 BOOL32 bRet = FALSE, win32Format = FALSE;
66 HWND32 hwndDialog;
67 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
68 LPCVOID template;
69 char defaultopen[]="Open File";
70 char *str=0,*str1=0;
72 if (!lpofn || !FileDlg_Init()) return FALSE;
74 if (lpofn->Flags & OFN_WINE32) {
75 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
77 if (!(template = LockResource32( MapHModuleSL(lpofn->hInstance ))))
79 CommDlgLastError = CDERR_LOADRESFAILURE;
80 return FALSE;
83 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
85 if (!(hResInfo = FindResource32A(MapHModuleSL(lpofn->hInstance),
86 PTR_SEG_TO_LIN(lpofn->lpTemplateName), RT_DIALOG32A)))
88 CommDlgLastError = CDERR_FINDRESFAILURE;
89 return FALSE;
91 if (!(hDlgTmpl = LoadResource32( MapHModuleSL(lpofn->hInstance),
92 hResInfo )) ||
93 !(template = LockResource32( hDlgTmpl )))
95 CommDlgLastError = CDERR_LOADRESFAILURE;
96 return FALSE;
98 } else {
99 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
101 win32Format = TRUE;
102 } else {
103 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
105 if (!(template = LockResource16( lpofn->hInstance )))
107 CommDlgLastError = CDERR_LOADRESFAILURE;
108 return FALSE;
111 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
113 if (!(hResInfo = FindResource16(lpofn->hInstance,
114 lpofn->lpTemplateName,
115 RT_DIALOG16)))
117 CommDlgLastError = CDERR_FINDRESFAILURE;
118 return FALSE;
120 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
121 !(template = LockResource16( hDlgTmpl )))
123 CommDlgLastError = CDERR_LOADRESFAILURE;
124 return FALSE;
126 } else {
127 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
128 win32Format = TRUE;
132 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
134 if (!(lpofn->lpstrFilter))
136 str = SEGPTR_ALLOC(sizeof(defaultfilter));
137 TRACE(commdlg,"Alloc %p default for Filetype in GetOpenFileName\n",str);
138 memcpy(str,defaultfilter,sizeof(defaultfilter));
139 lpofn->lpstrFilter=SEGPTR_GET(str);
142 if (!(lpofn->lpstrTitle))
144 str1 = SEGPTR_ALLOC(strlen(defaultopen)+1);
145 TRACE(commdlg,"Alloc %p default for Title in GetOpenFileName\n",str1);
146 strcpy(str1,defaultopen);
147 lpofn->lpstrTitle=SEGPTR_GET(str1);
150 /* FIXME: doesn't handle win32 format correctly yet */
151 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
152 lpofn->hwndOwner,
153 (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
154 ofn, WIN_PROC_16 );
155 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
157 if (str1)
159 TRACE(commdlg,"Freeing %p default for Title in GetOpenFileName\n",str1);
160 SEGPTR_FREE(str1);
161 lpofn->lpstrTitle=0;
164 if (str)
166 TRACE(commdlg,"Freeing %p default for Filetype in GetOpenFileName\n",str);
167 SEGPTR_FREE(str);
168 lpofn->lpstrFilter=0;
171 if (hDlgTmpl) {
172 if (lpofn->Flags & OFN_WINE32)
173 FreeResource32( hDlgTmpl );
174 else
175 FreeResource16( hDlgTmpl );
178 TRACE(commdlg,"return lpstrFile='%s' !\n",
179 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
180 return bRet;
184 /***********************************************************************
185 * GetSaveFileName (COMMDLG.2)
187 BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
189 HINSTANCE32 hInst;
190 HANDLE32 hDlgTmpl = 0;
191 BOOL32 bRet = FALSE, win32Format = FALSE;
192 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
193 LPCVOID template;
194 HWND32 hwndDialog;
195 char defaultsave[]="Save as";
196 char *str =0,*str1=0;
198 if (!lpofn || !FileDlg_Init()) return FALSE;
200 if (lpofn->Flags & OFN_WINE32) {
201 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
203 if (!(template = LockResource32( MapHModuleSL(lpofn->hInstance ))))
205 CommDlgLastError = CDERR_LOADRESFAILURE;
206 return FALSE;
209 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
211 HANDLE32 hResInfo;
212 if (!(hResInfo = FindResource32A(MapHModuleSL(lpofn->hInstance),
213 PTR_SEG_TO_LIN(lpofn->lpTemplateName),
214 RT_DIALOG32A)))
216 CommDlgLastError = CDERR_FINDRESFAILURE;
217 return FALSE;
219 if (!(hDlgTmpl = LoadResource32(MapHModuleSL(lpofn->hInstance),
220 hResInfo)) ||
221 !(template = LockResource32(hDlgTmpl)))
223 CommDlgLastError = CDERR_LOADRESFAILURE;
224 return FALSE;
226 win32Format= TRUE;
227 } else {
228 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
229 win32Format = TRUE;
231 } else {
232 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
234 if (!(template = LockResource16( lpofn->hInstance )))
236 CommDlgLastError = CDERR_LOADRESFAILURE;
237 return FALSE;
240 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
242 HANDLE16 hResInfo;
243 if (!(hResInfo = FindResource16(lpofn->hInstance,
244 lpofn->lpTemplateName,
245 RT_DIALOG16)))
247 CommDlgLastError = CDERR_FINDRESFAILURE;
248 return FALSE;
250 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
251 !(template = LockResource16( hDlgTmpl )))
253 CommDlgLastError = CDERR_LOADRESFAILURE;
254 return FALSE;
256 } else {
257 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
258 win32Format = TRUE;
262 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
264 if (!(lpofn->lpstrFilter))
266 str = SEGPTR_ALLOC(sizeof(defaultfilter));
267 TRACE(commdlg,"Alloc default for Filetype in GetSaveFileName\n");
268 memcpy(str,defaultfilter,sizeof(defaultfilter));
269 lpofn->lpstrFilter=SEGPTR_GET(str);
272 if (!(lpofn->lpstrTitle))
274 str1 = SEGPTR_ALLOC(sizeof(defaultsave)+1);
275 TRACE(commdlg,"Alloc default for Title in GetSaveFileName\n");
276 strcpy(str1,defaultsave);
277 lpofn->lpstrTitle=SEGPTR_GET(str1);
280 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
281 lpofn->hwndOwner,
282 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
283 ofn, WIN_PROC_16 );
284 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
286 if (str1)
288 TRACE(commdlg,"Freeing %p default for Title in GetSaveFileName\n",str1);
289 SEGPTR_FREE(str1);
290 lpofn->lpstrTitle=0;
293 if (str)
295 TRACE(commdlg,"Freeing %p default for Filetype in GetSaveFileName\n",str);
296 SEGPTR_FREE(str);
297 lpofn->lpstrFilter=0;
300 if (hDlgTmpl) {
301 if (lpofn->Flags & OFN_WINE32)
302 FreeResource32( hDlgTmpl );
303 else
304 FreeResource16( hDlgTmpl );
307 TRACE(commdlg, "return lpstrFile='%s' !\n",
308 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
309 return bRet;
312 /***********************************************************************
313 * FILEDLG_StripEditControl [internal]
314 * Strip pathnames off the contents of the edit control.
316 static void FILEDLG_StripEditControl(HWND16 hwnd)
318 char temp[512], *cp;
320 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
321 cp = strrchr(temp, '\\');
322 if (cp != NULL) {
323 strcpy(temp, cp+1);
325 cp = strrchr(temp, ':');
326 if (cp != NULL) {
327 strcpy(temp, cp+1);
329 /* FIXME: shouldn't we do something with the result here? ;-) */
332 /***********************************************************************
333 * FILEDLG_ScanDir [internal]
335 static BOOL32 FILEDLG_ScanDir(HWND16 hWnd, LPSTR newPath)
337 char buffer[512];
338 char* str = buffer;
339 int drive;
340 HWND32 hlb;
342 lstrcpyn32A(buffer, newPath, sizeof(buffer));
344 if (str[0] && (str[1] == ':')) {
345 drive = toupper(str[0]) - 'A';
346 str += 2;
347 if (!DRIVE_SetCurrentDrive(drive))
348 return FALSE;
349 } else {
350 drive = DRIVE_GetCurrentDrive();
353 if (str[0] && !DRIVE_Chdir(drive, str)) {
354 return FALSE;
357 GetDlgItemText32A(hWnd, edt1, buffer, sizeof(buffer));
358 if ((hlb = GetDlgItem32(hWnd, lst1)) != 0) {
359 char* scptr; /* ptr on semi-colon */
360 char* filter = buffer;
362 TRACE(commdlg, "Using filter %s\n", filter);
363 SendMessage32A(hlb, LB_RESETCONTENT32, 0, 0);
364 while (filter) {
365 scptr = strchr(filter, ';');
366 if (scptr) *scptr = 0;
367 TRACE(commdlg, "Using file spec %s\n", filter);
368 if (SendMessage32A(hlb, LB_DIR32, 0, (LPARAM)filter) == LB_ERR)
369 return FALSE;
370 if (scptr) *scptr = ';';
371 filter = (scptr) ? (scptr + 1) : 0;
375 strcpy(buffer, "*.*");
376 return DlgDirList32A(hWnd, buffer, lst2, stc1, 0x8010);
379 /***********************************************************************
380 * FILEDLG_GetFileType [internal]
383 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
385 int n, i;
386 i = 0;
387 if (cfptr)
388 for ( ;(n = strlen(cfptr)) != 0; i++)
390 cfptr += n + 1;
391 if (i == index)
392 return cfptr;
393 cfptr += strlen(cfptr) + 1;
395 if (fptr)
396 for ( ;(n = strlen(fptr)) != 0; i++)
398 fptr += n + 1;
399 if (i == index)
400 return fptr;
401 fptr += strlen(fptr) + 1;
403 return "*.*"; /* FIXME */
406 /***********************************************************************
407 * FILEDLG_WMDrawItem [internal]
409 static LONG FILEDLG_WMDrawItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam,int savedlg)
411 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
412 char *str;
413 HBRUSH32 hBrush;
414 HBITMAP16 hBitmap, hPrevBitmap;
415 BITMAP16 bm;
416 HDC32 hMemDC;
418 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
420 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
421 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
422 SelectObject32(lpdis->hDC, hBrush);
423 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
424 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
425 (LPARAM)SEGPTR_GET(str));
427 if (savedlg) /* use _gray_ text in FileSaveDlg */
428 if (!lpdis->itemState)
429 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_GRAYTEXT) );
430 else
431 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_WINDOWTEXT) );
432 /* inversion of gray would be bad readable */
434 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
435 str, strlen(str));
436 if (lpdis->itemState != 0) {
437 InvertRect16(lpdis->hDC, &lpdis->rcItem);
439 SEGPTR_FREE(str);
440 return TRUE;
443 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
445 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
446 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
447 SelectObject32(lpdis->hDC, hBrush);
448 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
449 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
450 (LPARAM)SEGPTR_GET(str));
452 hBitmap = hFolder;
453 GetObject16( hBitmap, sizeof(bm), &bm );
454 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
455 lpdis->rcItem.top, str, strlen(str));
456 hMemDC = CreateCompatibleDC32(lpdis->hDC);
457 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
458 BitBlt32(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
459 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
460 SelectObject32(hMemDC, hPrevBitmap);
461 DeleteDC32(hMemDC);
462 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
463 SEGPTR_FREE(str);
464 return TRUE;
466 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
468 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
469 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
470 SelectObject32(lpdis->hDC, hBrush);
471 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
472 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT16, lpdis->itemID,
473 (LPARAM)SEGPTR_GET(str));
474 switch(DRIVE_GetType( str[2] - 'a' ))
476 case TYPE_FLOPPY: hBitmap = hFloppy; break;
477 case TYPE_CDROM: hBitmap = hCDRom; break;
478 case TYPE_HD:
479 case TYPE_NETWORK:
480 default: hBitmap = hHDisk; break;
482 GetObject16( hBitmap, sizeof(bm), &bm );
483 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
484 lpdis->rcItem.top, str, strlen(str));
485 hMemDC = CreateCompatibleDC32(lpdis->hDC);
486 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
487 BitBlt32( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
488 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
489 SelectObject32(hMemDC, hPrevBitmap);
490 DeleteDC32(hMemDC);
491 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
492 SEGPTR_FREE(str);
493 return TRUE;
495 return FALSE;
498 /***********************************************************************
499 * FILEDLG_WMMeasureItem [internal]
501 static LONG FILEDLG_WMMeasureItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
503 BITMAP16 bm;
504 LPMEASUREITEMSTRUCT16 lpmeasure;
506 GetObject16( hFolder2, sizeof(bm), &bm );
507 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
508 lpmeasure->itemHeight = bm.bmHeight;
509 return TRUE;
512 /***********************************************************************
513 * FILEDLG_HookCallChk [internal]
515 static int FILEDLG_HookCallChk(LPOPENFILENAME16 lpofn)
517 if (lpofn)
518 if (lpofn->Flags & OFN_ENABLEHOOK)
519 if (lpofn->lpfnHook)
520 return 1;
521 return 0;
524 /***********************************************************************
525 * FILEDLG_CallWindowProc [internal]
527 * Adapt the structures back for win32 calls so the callee can read lpCustData
529 static BOOL32 FILEDLG_CallWindowProc(LPOPENFILENAME16 lpofn,HWND32 hwnd,
530 UINT32 wMsg,WPARAM32 wParam,LPARAM lParam
533 BOOL32 needstruct;
535 needstruct = (PTR_SEG_TO_LIN(lParam) == lpofn);
537 if (!(lpofn->Flags & OFN_WINE32))
538 return (BOOL32)CallWindowProc16(
539 lpofn->lpfnHook,hwnd,(UINT16)wMsg,(WPARAM16)wParam,lParam
541 /* |OFN_WINE32 */
542 if (lpofn->Flags & OFN_UNICODE) {
543 if (needstruct) {
544 OPENFILENAME32W ofnw;
546 /* FIXME: probably needs more converted */
547 ofnw.lCustData = lpofn->lCustData;
548 return (BOOL32)CallWindowProc32W(
549 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofnw
551 } else
552 return (BOOL32)CallWindowProc32W(
553 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
556 /* ! |OFN_UNICODE */
557 if (needstruct) {
558 OPENFILENAME32A ofna;
560 /* FIXME: probably needs more converted */
561 ofna.lCustData = lpofn->lCustData;
562 return (BOOL32)CallWindowProc32A(
563 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofna
565 } else
566 return (BOOL32)CallWindowProc32A(
567 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
572 /***********************************************************************
573 * FILEDLG_WMInitDialog [internal]
576 static LONG FILEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
578 int i, n;
579 LPOPENFILENAME16 lpofn;
580 char tmpstr[512];
581 LPSTR pstr, old_pstr;
582 SetWindowLong32A(hWnd, DWL_USER, lParam);
583 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(lParam);
584 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
585 /* read custom filter information */
586 if (lpofn->lpstrCustomFilter)
588 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
589 n = 0;
590 TRACE(commdlg,"lpstrCustomFilter = %p\n", pstr);
591 while(*pstr)
593 old_pstr = pstr;
594 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
595 (LPARAM)lpofn->lpstrCustomFilter + n );
596 n += strlen(pstr) + 1;
597 pstr += strlen(pstr) + 1;
598 TRACE(commdlg,"add str='%s' "
599 "associated to '%s'\n", old_pstr, pstr);
600 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
601 n += strlen(pstr) + 1;
602 pstr += strlen(pstr) + 1;
605 /* read filter information */
606 if (lpofn->lpstrFilter) {
607 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
608 n = 0;
609 while(*pstr) {
610 old_pstr = pstr;
611 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
612 (LPARAM)lpofn->lpstrFilter + n );
613 n += strlen(pstr) + 1;
614 pstr += strlen(pstr) + 1;
615 TRACE(commdlg,"add str='%s' "
616 "associated to '%s'\n", old_pstr, pstr);
617 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
618 n += strlen(pstr) + 1;
619 pstr += strlen(pstr) + 1;
622 /* set default filter */
623 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
624 lpofn->nFilterIndex = 1;
625 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL16, lpofn->nFilterIndex - 1, 0);
626 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
627 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
628 tmpstr[511]=0;
629 TRACE(commdlg,"nFilterIndex = %ld, SetText of edt1 to '%s'\n",
630 lpofn->nFilterIndex, tmpstr);
631 SetDlgItemText32A( hWnd, edt1, tmpstr );
632 /* get drive list */
633 *tmpstr = 0;
634 DlgDirListComboBox32A(hWnd, tmpstr, cmb2, 0, 0xC000);
635 /* read initial directory */
636 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
638 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
639 tmpstr[510]=0;
640 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
641 && tmpstr[strlen(tmpstr)-1] != ':')
642 strcat(tmpstr,"\\");
644 else
645 *tmpstr = 0;
646 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
647 *tmpstr = 0;
648 if (!FILEDLG_ScanDir(hWnd, tmpstr))
649 WARN(commdlg, "Couldn't read initial directory %s!\n",tmpstr);
651 /* select current drive in combo 2, omit missing drives */
652 for(i=0, n=-1; i<=DRIVE_GetCurrentDrive(); i++)
653 if (DRIVE_IsValid(i)) n++;
654 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL16, n, 0);
655 if (!(lpofn->Flags & OFN_SHOWHELP))
656 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
657 if (lpofn->Flags & OFN_HIDEREADONLY)
658 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
659 if (FILEDLG_HookCallChk(lpofn))
660 return (BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,WM_INITDIALOG,wParam,lParam );
661 else
662 return TRUE;
665 /***********************************************************************
666 * FILEDLG_WMCommand [internal]
668 BOOL32 in_update=FALSE;
670 static LRESULT FILEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
672 LONG lRet;
673 LPOPENFILENAME16 lpofn;
674 OPENFILENAME16 ofn2;
675 char tmpstr[512], tmpstr2[512];
676 LPSTR pstr, pstr2;
677 UINT16 control,notification;
679 /* Notifications are packaged differently in Win32 */
680 control = wParam;
681 notification = HIWORD(lParam);
683 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
684 switch (control)
686 case lst1: /* file list */
687 FILEDLG_StripEditControl(hWnd);
688 if (notification == LBN_DBLCLK)
689 goto almost_ok;
690 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
691 if (lRet == LB_ERR) return TRUE;
692 if ((pstr = SEGPTR_ALLOC(512)))
694 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
695 (LPARAM)SEGPTR_GET(pstr));
696 SetDlgItemText32A( hWnd, edt1, pstr );
697 SEGPTR_FREE(pstr);
699 if (FILEDLG_HookCallChk(lpofn))
700 FILEDLG_CallWindowProc(lpofn,hWnd,
701 RegisterWindowMessage32A( LBSELCHSTRING ),
702 control, MAKELONG(lRet,CD_LBSELCHANGE));
703 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
704 return TRUE;
705 case lst2: /* directory list */
706 FILEDLG_StripEditControl(hWnd);
707 if (notification == LBN_DBLCLK)
709 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
710 if (lRet == LB_ERR) return TRUE;
711 pstr = SEGPTR_ALLOC(512);
712 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
713 (LPARAM)SEGPTR_GET(pstr));
714 strcpy( tmpstr, pstr );
715 SEGPTR_FREE(pstr);
716 if (tmpstr[0] == '[')
718 tmpstr[strlen(tmpstr) - 1] = 0;
719 strcpy(tmpstr,tmpstr+1);
721 strcat(tmpstr, "\\");
722 goto reset_scan;
724 return TRUE;
725 case cmb1: /* file type drop list */
726 if (notification == CBN_SELCHANGE)
728 *tmpstr = 0;
729 goto reset_scan;
731 return TRUE;
732 case chx1:
733 return TRUE;
734 case pshHelp:
735 return TRUE;
736 case cmb2: /* disk drop list */
737 FILEDLG_StripEditControl(hWnd);
738 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL16, 0, 0L);
739 if (lRet == LB_ERR) return 0;
740 pstr = SEGPTR_ALLOC(512);
741 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT16, lRet,
742 (LPARAM)SEGPTR_GET(pstr));
743 sprintf(tmpstr, "%c:", pstr[2]);
744 SEGPTR_FREE(pstr);
745 reset_scan:
746 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
747 if (lRet == LB_ERR)
748 return TRUE;
749 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA16, lRet, 0);
750 TRACE(commdlg,"Selected filter : %s\n", pstr);
751 SetDlgItemText32A( hWnd, edt1, pstr );
752 FILEDLG_ScanDir(hWnd, tmpstr);
753 in_update=TRUE;
754 case IDOK:
755 almost_ok:
756 ofn2=*lpofn; /* for later restoring */
757 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
758 pstr = strrchr(tmpstr, '\\');
759 if (pstr == NULL)
760 pstr = strrchr(tmpstr, ':');
761 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
763 /* edit control contains wildcards */
764 if (pstr != NULL)
766 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
767 *(pstr+1) = 0;
769 else
771 strcpy(tmpstr2, tmpstr);
772 *tmpstr=0;
774 TRACE(commdlg,"tmpstr=%s, tmpstr2=%s\n", tmpstr, tmpstr2);
775 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
776 FILEDLG_ScanDir(hWnd, tmpstr);
777 return TRUE;
779 /* no wildcards, we might have a directory or a filename */
780 /* try appending a wildcard and reading the directory */
781 pstr2 = tmpstr + strlen(tmpstr);
782 if (pstr == NULL || *(pstr+1) != 0)
783 strcat(tmpstr, "\\");
784 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
785 if (lRet == LB_ERR) return TRUE;
786 lpofn->nFilterIndex = lRet + 1;
787 TRACE(commdlg,"lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
788 lstrcpyn32A(tmpstr2,
789 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
790 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
791 lRet), sizeof(tmpstr2));
792 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
793 if (!in_update)
794 /* if ScanDir succeeds, we have changed the directory */
795 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
796 /* if not, this must be a filename */
797 *pstr2 = 0;
798 if (pstr != NULL)
800 /* strip off the pathname */
801 *pstr = 0;
802 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
803 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
804 /* Should we MessageBox() if this fails? */
805 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
806 strcpy(tmpstr, tmpstr2);
808 else SetDlgItemText32A( hWnd, edt1, tmpstr );
809 #if 0
810 ShowWindow16(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
811 #endif
813 int drive = DRIVE_GetCurrentDrive();
814 tmpstr2[0] = 'A'+ drive;
815 tmpstr2[1] = ':';
816 tmpstr2[2] = '\\';
817 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
818 if (strlen(tmpstr2) > 3)
819 strcat(tmpstr2, "\\");
820 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
821 if (lpofn->lpstrFile)
822 lstrcpyn32A(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2,lpofn->nMaxFile);
824 lpofn->nFileOffset = strrchr(tmpstr2,'\\') - tmpstr2 +1;
825 lpofn->nFileExtension = 0;
826 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
827 lpofn->nFileExtension++;
828 if (lpofn->nFileExtension == '\0')
829 lpofn->nFileExtension = 0;
830 else
831 lpofn->nFileExtension++;
833 if(in_update)
835 if (FILEDLG_HookCallChk(lpofn))
836 FILEDLG_CallWindowProc(lpofn,hWnd,
837 RegisterWindowMessage32A( LBSELCHSTRING ),
838 control, MAKELONG(lRet,CD_LBSELCHANGE));
840 in_update = FALSE;
841 return TRUE;
843 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
845 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
846 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
847 lpofn->lpstrFileTitle );
849 if (FILEDLG_HookCallChk(lpofn))
851 lRet= (BOOL16)FILEDLG_CallWindowProc(lpofn,
852 hWnd, RegisterWindowMessage32A( FILEOKSTRING ), 0, lParam );
853 if (lRet)
855 *lpofn=ofn2; /* restore old state */
856 #if 0
857 ShowWindow16(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
858 #endif
859 break;
862 EndDialog32(hWnd, TRUE);
863 return TRUE;
864 case IDCANCEL:
865 EndDialog32(hWnd, FALSE);
866 return TRUE;
868 return FALSE;
872 /***********************************************************************
873 * FileOpenDlgProc (COMMDLG.6)
875 LRESULT WINAPI FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
876 LPARAM lParam)
878 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
880 if (wMsg!=WM_INITDIALOG)
881 if (FILEDLG_HookCallChk(lpofn))
883 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
884 if (lRet)
885 return lRet; /* else continue message processing */
887 switch (wMsg)
889 case WM_INITDIALOG:
890 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
891 case WM_MEASUREITEM:
892 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
893 case WM_DRAWITEM:
894 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
895 case WM_COMMAND:
896 return FILEDLG_WMCommand(hWnd, wParam, lParam);
897 #if 0
898 case WM_CTLCOLOR:
899 SetBkColor((HDC16)wParam, 0x00C0C0C0);
900 switch (HIWORD(lParam))
902 case CTLCOLOR_BTN:
903 SetTextColor((HDC16)wParam, 0x00000000);
904 return hGRAYBrush;
905 case CTLCOLOR_STATIC:
906 SetTextColor((HDC16)wParam, 0x00000000);
907 return hGRAYBrush;
909 break;
910 #endif
912 return FALSE;
916 /***********************************************************************
917 * FileSaveDlgProc (COMMDLG.7)
919 LRESULT WINAPI FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
920 LPARAM lParam)
922 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
924 if (wMsg!=WM_INITDIALOG)
925 if (FILEDLG_HookCallChk(lpofn))
927 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
928 if (lRet)
929 return lRet; /* else continue message processing */
931 switch (wMsg) {
932 case WM_INITDIALOG:
933 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
935 case WM_MEASUREITEM:
936 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
938 case WM_DRAWITEM:
939 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
941 case WM_COMMAND:
942 return FILEDLG_WMCommand(hWnd, wParam, lParam);
946 case WM_CTLCOLOR:
947 SetBkColor((HDC16)wParam, 0x00C0C0C0);
948 switch (HIWORD(lParam))
950 case CTLCOLOR_BTN:
951 SetTextColor((HDC16)wParam, 0x00000000);
952 return hGRAYBrush;
953 case CTLCOLOR_STATIC:
954 SetTextColor((HDC16)wParam, 0x00000000);
955 return hGRAYBrush;
957 return FALSE;
960 return FALSE;
964 /***********************************************************************
965 * FindText16 (COMMDLG.11)
967 HWND16 WINAPI FindText16( SEGPTR find )
969 HANDLE16 hInst;
970 LPCVOID ptr;
971 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
974 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
975 * For now, only the standard dialog works.
977 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
978 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
979 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
980 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
981 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
982 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
983 find, WIN_PROC_16 );
986 /***********************************************************************
987 * FindText32A (COMMDLG.6)
989 HWND32 WINAPI FindText32A( LPFINDREPLACE32A lpFind )
991 HANDLE16 hInst;
992 LPCVOID ptr;
995 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
996 * For now, only the standard dialog works.
998 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
999 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1000 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
1001 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1002 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1003 (DLGPROC16)FindTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
1006 /***********************************************************************
1007 * FindText32W (COMMDLG.7)
1009 HWND32 WINAPI FindText32W( LPFINDREPLACE32W lpFind )
1011 HANDLE16 hInst;
1012 LPCVOID ptr;
1015 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1016 * For now, only the standard dialog works.
1018 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1019 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1020 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
1021 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1022 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1023 (DLGPROC16)FindTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
1026 /***********************************************************************
1027 * ReplaceText16 (COMMDLG.12)
1029 HWND16 WINAPI ReplaceText16( SEGPTR find )
1031 HANDLE16 hInst;
1032 LPCVOID ptr;
1033 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
1036 * FIXME : We should do error checking on the lpFind structure here
1037 * and make CommDlgExtendedError() return the error condition.
1039 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1040 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1041 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1042 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1043 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1044 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
1045 find, WIN_PROC_16 );
1048 /***********************************************************************
1049 * ReplaceText32A (COMDLG32.19)
1051 HWND32 WINAPI ReplaceText32A( LPFINDREPLACE32A lpFind )
1053 HANDLE16 hInst;
1054 LPCVOID ptr;
1057 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1058 * For now, only the standard dialog works.
1060 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1061 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1062 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1063 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1064 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1065 (DLGPROC16)ReplaceTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
1068 /***********************************************************************
1069 * ReplaceText32W (COMDLG32.20)
1071 HWND32 WINAPI ReplaceText32W( LPFINDREPLACE32W lpFind )
1073 HANDLE16 hInst;
1074 LPCVOID ptr;
1077 * FIXME : We should do error checking on the lpFind structure here
1078 * and make CommDlgExtendedError() return the error condition.
1080 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1081 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1082 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1083 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1084 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1085 (DLGPROC16)ReplaceTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
1089 /***********************************************************************
1090 * FINDDLG_WMInitDialog [internal]
1092 static LRESULT FINDDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam, LPDWORD lpFlags,
1093 LPSTR lpstrFindWhat, BOOL32 fUnicode)
1095 SetWindowLong32A(hWnd, DWL_USER, lParam);
1096 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1098 * FIXME : If the initial FindWhat string is empty, we should disable the
1099 * FindNext (IDOK) button. Only after typing some text, the button should be
1100 * enabled.
1102 if (fUnicode) SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1103 else SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1104 CheckRadioButton32(hWnd, rad1, rad2, (*lpFlags & FR_DOWN) ? rad2 : rad1);
1105 if (*lpFlags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
1106 EnableWindow32(GetDlgItem32(hWnd, rad1), FALSE);
1107 EnableWindow32(GetDlgItem32(hWnd, rad2), FALSE);
1109 if (*lpFlags & FR_HIDEUPDOWN) {
1110 ShowWindow32(GetDlgItem32(hWnd, rad1), SW_HIDE);
1111 ShowWindow32(GetDlgItem32(hWnd, rad2), SW_HIDE);
1112 ShowWindow32(GetDlgItem32(hWnd, grp1), SW_HIDE);
1114 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1115 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1116 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1117 if (*lpFlags & FR_HIDEWHOLEWORD)
1118 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1119 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1120 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1121 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1122 if (*lpFlags & FR_HIDEMATCHCASE)
1123 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1124 if (!(*lpFlags & FR_SHOWHELP)) {
1125 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1126 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1128 ShowWindow32(hWnd, SW_SHOWNORMAL);
1129 return TRUE;
1133 /***********************************************************************
1134 * FINDDLG_WMCommand [internal]
1136 static LRESULT FINDDLG_WMCommand(HWND32 hWnd, WPARAM32 wParam,
1137 HWND32 hwndOwner, LPDWORD lpFlags,
1138 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1139 BOOL32 fUnicode)
1141 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1142 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1144 switch (wParam) {
1145 case IDOK:
1146 if (fUnicode)
1147 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1148 else GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1149 if (IsDlgButtonChecked32(hWnd, rad2))
1150 *lpFlags |= FR_DOWN;
1151 else *lpFlags &= ~FR_DOWN;
1152 if (IsDlgButtonChecked32(hWnd, chx1))
1153 *lpFlags |= FR_WHOLEWORD;
1154 else *lpFlags &= ~FR_WHOLEWORD;
1155 if (IsDlgButtonChecked32(hWnd, chx2))
1156 *lpFlags |= FR_MATCHCASE;
1157 else *lpFlags &= ~FR_MATCHCASE;
1158 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1159 *lpFlags |= FR_FINDNEXT;
1160 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1161 GetWindowLong32A(hWnd, DWL_USER) );
1162 return TRUE;
1163 case IDCANCEL:
1164 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1165 *lpFlags |= FR_DIALOGTERM;
1166 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1167 GetWindowLong32A(hWnd, DWL_USER) );
1168 DestroyWindow32(hWnd);
1169 return TRUE;
1170 case pshHelp:
1171 /* FIXME : should lpfr structure be passed as an argument ??? */
1172 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1173 return TRUE;
1175 return FALSE;
1179 /***********************************************************************
1180 * FindTextDlgProc16 (COMMDLG.13)
1182 LRESULT WINAPI FindTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1183 LPARAM lParam)
1185 LPFINDREPLACE16 lpfr;
1186 switch (wMsg) {
1187 case WM_INITDIALOG:
1188 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1189 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1190 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat), FALSE);
1191 case WM_COMMAND:
1192 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1193 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1194 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1195 lpfr->wFindWhatLen, FALSE);
1197 return FALSE;
1200 /***********************************************************************
1201 * FindTextDlgProc32A
1203 LRESULT WINAPI FindTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1204 LPARAM lParam)
1206 LPFINDREPLACE32A lpfr;
1207 switch (wMsg) {
1208 case WM_INITDIALOG:
1209 lpfr=(LPFINDREPLACE32A)lParam;
1210 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1211 lpfr->lpstrFindWhat, FALSE);
1212 case WM_COMMAND:
1213 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1214 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1215 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1216 FALSE);
1218 return FALSE;
1221 /***********************************************************************
1222 * FindTextDlgProc32W
1224 LRESULT WINAPI FindTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1225 LPARAM lParam)
1227 LPFINDREPLACE32W lpfr;
1228 switch (wMsg) {
1229 case WM_INITDIALOG:
1230 lpfr=(LPFINDREPLACE32W)lParam;
1231 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1232 (LPSTR)lpfr->lpstrFindWhat, TRUE);
1233 case WM_COMMAND:
1234 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1235 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1236 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1237 TRUE);
1239 return FALSE;
1243 /***********************************************************************
1244 * REPLACEDLG_WMInitDialog [internal]
1246 static LRESULT REPLACEDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam,
1247 LPDWORD lpFlags, LPSTR lpstrFindWhat,
1248 LPSTR lpstrReplaceWith, BOOL32 fUnicode)
1250 SetWindowLong32A(hWnd, DWL_USER, lParam);
1251 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1253 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
1254 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
1255 * enabled.
1257 if (fUnicode)
1259 SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1260 SetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith);
1261 } else
1263 SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1264 SetDlgItemText32A(hWnd, edt2, lpstrReplaceWith);
1266 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1267 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1268 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1269 if (*lpFlags & FR_HIDEWHOLEWORD)
1270 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1271 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1272 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1273 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1274 if (*lpFlags & FR_HIDEMATCHCASE)
1275 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1276 if (!(*lpFlags & FR_SHOWHELP)) {
1277 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1278 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1280 ShowWindow32(hWnd, SW_SHOWNORMAL);
1281 return TRUE;
1285 /***********************************************************************
1286 * REPLACEDLG_WMCommand [internal]
1288 static LRESULT REPLACEDLG_WMCommand(HWND32 hWnd, WPARAM16 wParam,
1289 HWND32 hwndOwner, LPDWORD lpFlags,
1290 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1291 LPSTR lpstrReplaceWith, WORD wReplaceWithLen,
1292 BOOL32 fUnicode)
1294 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1295 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1297 switch (wParam) {
1298 case IDOK:
1299 if (fUnicode)
1301 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1302 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1303 } else
1305 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1306 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1308 if (IsDlgButtonChecked32(hWnd, chx1))
1309 *lpFlags |= FR_WHOLEWORD;
1310 else *lpFlags &= ~FR_WHOLEWORD;
1311 if (IsDlgButtonChecked32(hWnd, chx2))
1312 *lpFlags |= FR_MATCHCASE;
1313 else *lpFlags &= ~FR_MATCHCASE;
1314 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1315 *lpFlags |= FR_FINDNEXT;
1316 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1317 GetWindowLong32A(hWnd, DWL_USER) );
1318 return TRUE;
1319 case IDCANCEL:
1320 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1321 *lpFlags |= FR_DIALOGTERM;
1322 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1323 GetWindowLong32A(hWnd, DWL_USER) );
1324 DestroyWindow32(hWnd);
1325 return TRUE;
1326 case psh1:
1327 if (fUnicode)
1329 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1330 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1331 } else
1333 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1334 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1336 if (IsDlgButtonChecked32(hWnd, chx1))
1337 *lpFlags |= FR_WHOLEWORD;
1338 else *lpFlags &= ~FR_WHOLEWORD;
1339 if (IsDlgButtonChecked32(hWnd, chx2))
1340 *lpFlags |= FR_MATCHCASE;
1341 else *lpFlags &= ~FR_MATCHCASE;
1342 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
1343 *lpFlags |= FR_REPLACE;
1344 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1345 GetWindowLong32A(hWnd, DWL_USER) );
1346 return TRUE;
1347 case psh2:
1348 if (fUnicode)
1350 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1351 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1352 } else
1354 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1355 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1357 if (IsDlgButtonChecked32(hWnd, chx1))
1358 *lpFlags |= FR_WHOLEWORD;
1359 else *lpFlags &= ~FR_WHOLEWORD;
1360 if (IsDlgButtonChecked32(hWnd, chx2))
1361 *lpFlags |= FR_MATCHCASE;
1362 else *lpFlags &= ~FR_MATCHCASE;
1363 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
1364 *lpFlags |= FR_REPLACEALL;
1365 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1366 GetWindowLong32A(hWnd, DWL_USER) );
1367 return TRUE;
1368 case pshHelp:
1369 /* FIXME : should lpfr structure be passed as an argument ??? */
1370 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1371 return TRUE;
1373 return FALSE;
1377 /***********************************************************************
1378 * ReplaceTextDlgProc16 (COMMDLG.14)
1380 LRESULT WINAPI ReplaceTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1381 LPARAM lParam)
1383 LPFINDREPLACE16 lpfr;
1384 switch (wMsg) {
1385 case WM_INITDIALOG:
1386 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1387 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1388 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1389 PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith), FALSE);
1390 case WM_COMMAND:
1391 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1392 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1393 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1394 lpfr->wFindWhatLen, PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith),
1395 lpfr->wReplaceWithLen, FALSE);
1397 return FALSE;
1400 /***********************************************************************
1401 * ReplaceTextDlgProc32A
1403 LRESULT WINAPI ReplaceTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1404 LPARAM lParam)
1406 LPFINDREPLACE32A lpfr;
1407 switch (wMsg) {
1408 case WM_INITDIALOG:
1409 lpfr=(LPFINDREPLACE32A)lParam;
1410 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1411 lpfr->lpstrFindWhat, lpfr->lpstrReplaceWith, FALSE);
1412 case WM_COMMAND:
1413 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1414 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1415 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1416 lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, FALSE);
1418 return FALSE;
1421 /***********************************************************************
1422 * ReplaceTextDlgProc32W
1424 LRESULT WINAPI ReplaceTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1425 LPARAM lParam)
1427 LPFINDREPLACE32W lpfr;
1428 switch (wMsg) {
1429 case WM_INITDIALOG:
1430 lpfr=(LPFINDREPLACE32W)lParam;
1431 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1432 (LPSTR)lpfr->lpstrFindWhat, (LPSTR)lpfr->lpstrReplaceWith,
1433 TRUE);
1434 case WM_COMMAND:
1435 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1436 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1437 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1438 (LPSTR)lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, TRUE);
1440 return FALSE;
1444 /***********************************************************************
1445 * PrintDlg16 (COMMDLG.20)
1447 BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
1449 HANDLE16 hInst;
1450 BOOL16 bRet = FALSE;
1451 LPCVOID template;
1452 HWND32 hwndDialog;
1453 LPPRINTDLG16 lpPrint = (LPPRINTDLG16)PTR_SEG_TO_LIN(printdlg);
1455 TRACE(commdlg,"(%p) -- Flags=%08lX\n", lpPrint, lpPrint->Flags );
1457 if (lpPrint->Flags & PD_RETURNDEFAULT)
1458 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1459 return TRUE;
1461 if (lpPrint->Flags & PD_PRINTSETUP)
1462 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
1463 else
1464 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
1466 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1467 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
1468 lpPrint->hwndOwner,
1469 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
1470 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1471 MODULE_GetWndProcEntry16("PrintDlgProc")),
1472 printdlg, WIN_PROC_16 );
1473 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
1474 return bRet;
1478 /***********************************************************************
1479 * PrintDlg32A (COMDLG32.17)
1481 BOOL32 WINAPI PrintDlg32A( LPPRINTDLG32A printdlg )
1483 FIXME(commdlg, "(%p): stub\n",printdlg);
1484 /* Altough returning FALSE is theoricaly the right thing
1485 * most programs check for a printer at startup, and if
1486 * none is found popup PrintDlg32A(), if it fails the program
1487 * terminates; by returning TRUE the programs can still run
1488 * as long as no printer related stuff is used
1490 return TRUE;
1494 /***********************************************************************
1495 * PrintDlg32W (COMDLG32.18)
1497 BOOL32 WINAPI PrintDlg32W( LPPRINTDLG32W printdlg )
1499 FIXME(commdlg, "empty stub\n" );
1500 return FALSE;
1504 /***********************************************************************
1505 * PrintDlgProc (COMMDLG.21)
1507 LRESULT WINAPI PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1508 LPARAM lParam)
1510 switch (wMsg)
1512 case WM_INITDIALOG:
1513 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1514 ShowWindow16(hWnd, SW_SHOWNORMAL);
1515 return (TRUE);
1516 case WM_COMMAND:
1517 switch (wParam)
1519 case IDOK:
1520 EndDialog32(hWnd, TRUE);
1521 return(TRUE);
1522 case IDCANCEL:
1523 EndDialog32(hWnd, FALSE);
1524 return(TRUE);
1526 return(FALSE);
1528 return FALSE;
1532 /***********************************************************************
1533 * PrintSetupDlgProc (COMMDLG.22)
1535 LRESULT WINAPI PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1536 LPARAM lParam)
1538 switch (wMsg)
1540 case WM_INITDIALOG:
1541 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1542 ShowWindow16(hWnd, SW_SHOWNORMAL);
1543 return (TRUE);
1544 case WM_COMMAND:
1545 switch (wParam) {
1546 case IDOK:
1547 EndDialog32(hWnd, TRUE);
1548 return(TRUE);
1549 case IDCANCEL:
1550 EndDialog32(hWnd, FALSE);
1551 return(TRUE);
1553 return(FALSE);
1555 return FALSE;
1559 /***********************************************************************
1560 * CommDlgExtendedError (COMMDLG.26)
1562 DWORD WINAPI CommDlgExtendedError(void)
1564 return CommDlgLastError;
1567 /***********************************************************************
1568 * GetFileTitleA (COMDLG32.8)
1570 short WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
1572 int i, len;
1573 TRACE(commdlg,"(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1574 if (lpFile == NULL || lpTitle == NULL)
1575 return -1;
1576 len = strlen(lpFile);
1577 if (len == 0)
1578 return -1;
1579 if (strpbrk(lpFile, "*[]"))
1580 return -1;
1581 len--;
1582 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1583 return -1;
1584 for (i = len; i >= 0; i--)
1585 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1587 i++;
1588 break;
1590 TRACE(commdlg,"---> '%s' \n", &lpFile[i]);
1592 len = strlen(lpFile+i)+1;
1593 if (cbBuf < len)
1594 return len;
1596 strncpy(lpTitle, &lpFile[i], len);
1597 return 0;
1601 /***********************************************************************
1602 * GetFileTitleA (COMDLG32.8)
1604 short WINAPI GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf)
1606 LPSTR file = HEAP_strdupWtoA(GetProcessHeap(),0,lpFile);
1607 LPSTR title = HeapAlloc(GetProcessHeap(),0,cbBuf);
1608 short ret;
1610 ret = GetFileTitle32A(file,title,cbBuf);
1612 lstrcpynAtoW(lpTitle,title,cbBuf);
1613 HeapFree(GetProcessHeap(),0,file);
1614 HeapFree(GetProcessHeap(),0,title);
1615 return ret;
1617 /***********************************************************************
1618 * GetFileTitle (COMMDLG.27)
1620 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
1622 return GetFileTitle32A(lpFile,lpTitle,cbBuf);
1626 /* ------------------------ Choose Color Dialog --------------------------- */
1628 /***********************************************************************
1629 * ChooseColor (COMMDLG.5)
1631 BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol)
1633 HINSTANCE16 hInst;
1634 HANDLE16 hDlgTmpl = 0;
1635 BOOL16 bRet = FALSE, win32Format = FALSE;
1636 LPCVOID template;
1637 HWND32 hwndDialog;
1639 TRACE(commdlg,"ChooseColor\n");
1640 if (!lpChCol) return FALSE;
1642 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1644 if (!(template = LockResource16( lpChCol->hInstance )))
1646 CommDlgLastError = CDERR_LOADRESFAILURE;
1647 return FALSE;
1650 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1652 HANDLE16 hResInfo;
1653 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1654 lpChCol->lpTemplateName,
1655 RT_DIALOG16)))
1657 CommDlgLastError = CDERR_FINDRESFAILURE;
1658 return FALSE;
1660 if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
1661 !(template = LockResource16( hDlgTmpl )))
1663 CommDlgLastError = CDERR_LOADRESFAILURE;
1664 return FALSE;
1667 else
1669 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR );
1670 win32Format = TRUE;
1673 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1674 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
1675 lpChCol->hwndOwner,
1676 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1677 (DWORD)lpChCol, WIN_PROC_16 );
1678 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
1679 if (hDlgTmpl) FreeResource16( hDlgTmpl );
1680 return bRet;
1684 static const COLORREF predefcolors[6][8]=
1686 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1687 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1688 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1689 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1691 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1692 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1693 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1694 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1696 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1697 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1698 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1699 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1702 struct CCPRIVATE
1704 LPCHOOSECOLOR16 lpcc; /* points to public known data structure */
1705 int nextuserdef; /* next free place in user defined color array */
1706 HDC16 hdcMem; /* color graph used for BitBlt() */
1707 HBITMAP16 hbmMem; /* color graph bitmap */
1708 RECT16 fullsize; /* original dialog window size */
1709 UINT16 msetrgb; /* # of SETRGBSTRING message (today not used) */
1710 RECT16 old3angle; /* last position of l-marker */
1711 RECT16 oldcross; /* last position of color/satuation marker */
1712 BOOL32 updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1713 int h;
1714 int s;
1715 int l; /* for temporary storing of hue,sat,lum */
1718 /***********************************************************************
1719 * CC_HSLtoRGB [internal]
1721 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1723 int res=0,maxrgb;
1725 /* hue */
1726 switch(c)
1728 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1729 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1730 case 'B':break;
1733 /* l below 120 */
1734 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1735 if (hue< 80)
1736 res=0;
1737 else
1738 if (hue< 120)
1740 res=(hue-80)* maxrgb; /* 0...10240 */
1741 res/=40; /* 0...256 */
1743 else
1744 if (hue< 200)
1745 res=maxrgb;
1746 else
1748 res=(240-hue)* maxrgb;
1749 res/=40;
1751 res=res-maxrgb/2; /* -128...128 */
1753 /* saturation */
1754 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1756 /* lum above 120 */
1757 if (lum>120 && res<256)
1758 res+=((lum-120) * (256-res))/120;
1760 return MIN(res,255);
1763 /***********************************************************************
1764 * CC_RGBtoHSL [internal]
1766 static int CC_RGBtoHSL(char c,int r,int g,int b)
1768 WORD maxi,mini,mmsum,mmdif,result=0;
1769 int iresult=0;
1771 maxi=MAX(r,b);
1772 maxi=MAX(maxi,g);
1773 mini=MIN(r,b);
1774 mini=MIN(mini,g);
1776 mmsum=maxi+mini;
1777 mmdif=maxi-mini;
1779 switch(c)
1781 /* lum */
1782 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1783 result=mmsum/255; /* 0...240 */
1784 break;
1785 /* saturation */
1786 case 'S':if (!mmsum)
1787 result=0;
1788 else
1789 if (!mini || maxi==255)
1790 result=240;
1791 else
1793 result=mmdif*240; /* 0...61200=255*240 */
1794 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1796 break;
1797 /* hue */
1798 case 'H':if (!mmdif)
1799 result=160;
1800 else
1802 if (maxi==r)
1804 iresult=40*(g-b); /* -10200 ... 10200 */
1805 iresult/=(int)mmdif; /* -40 .. 40 */
1806 if (iresult<0)
1807 iresult+=240; /* 0..40 and 200..240 */
1809 else
1810 if (maxi==g)
1812 iresult=40*(b-r);
1813 iresult/=(int)mmdif;
1814 iresult+=80; /* 40 .. 120 */
1816 else
1817 if (maxi==b)
1819 iresult=40*(r-g);
1820 iresult/=(int)mmdif;
1821 iresult+=160; /* 120 .. 200 */
1823 result=iresult;
1825 break;
1827 return result; /* is this integer arithmetic precise enough ? */
1830 #define DISTANCE 4
1832 /***********************************************************************
1833 * CC_MouseCheckPredefColorArray [internal]
1835 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1836 LPARAM lParam,COLORREF *cr)
1838 HWND16 hwnd;
1839 POINT16 point = MAKEPOINT16(lParam);
1840 RECT16 rect;
1841 int dx,dy,x,y;
1843 ClientToScreen16(hDlg,&point);
1844 hwnd=GetDlgItem32(hDlg,dlgitem);
1845 GetWindowRect16(hwnd,&rect);
1846 if (PtInRect16(&rect,point))
1848 dx=(rect.right-rect.left)/cols;
1849 dy=(rect.bottom-rect.top)/rows;
1850 ScreenToClient16(hwnd,&point);
1852 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1854 x=point.x/dx;
1855 y=point.y/dy;
1856 *cr=predefcolors[y][x];
1857 /* FIXME: Draw_a_Focus_Rect() */
1858 return 1;
1861 return 0;
1864 /***********************************************************************
1865 * CC_MouseCheckUserColorArray [internal]
1867 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1868 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1870 HWND16 hwnd;
1871 POINT16 point = MAKEPOINT16(lParam);
1872 RECT16 rect;
1873 int dx,dy,x,y;
1875 ClientToScreen16(hDlg,&point);
1876 hwnd=GetDlgItem32(hDlg,dlgitem);
1877 GetWindowRect16(hwnd,&rect);
1878 if (PtInRect16(&rect,point))
1880 dx=(rect.right-rect.left)/cols;
1881 dy=(rect.bottom-rect.top)/rows;
1882 ScreenToClient16(hwnd,&point);
1884 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1886 x=point.x/dx;
1887 y=point.y/dy;
1888 *cr=crarr[x+cols*y];
1889 /* FIXME: Draw_a_Focus_Rect() */
1890 return 1;
1893 return 0;
1896 #define MAXVERT 240
1897 #define MAXHORI 239
1899 /* 240 ^...... ^^ 240
1900 | . ||
1901 SAT | . || LUM
1902 | . ||
1903 +-----> 239 ----
1906 /***********************************************************************
1907 * CC_MouseCheckColorGraph [internal]
1909 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1911 HWND32 hwnd;
1912 POINT16 point = MAKEPOINT16(lParam);
1913 RECT16 rect;
1914 long x,y;
1916 ClientToScreen16(hDlg,&point);
1917 hwnd=GetDlgItem32(hDlg,dlgitem);
1918 GetWindowRect16(hwnd,&rect);
1919 if (PtInRect16(&rect,point))
1921 GetClientRect16(hwnd,&rect);
1922 ScreenToClient16(hwnd,&point);
1924 x=(long)point.x*MAXHORI;
1925 x/=rect.right;
1926 y=(long)(rect.bottom-point.y)*MAXVERT;
1927 y/=rect.bottom;
1929 if (hori)
1930 *hori=x;
1931 if (vert)
1932 *vert=y;
1933 return 1;
1935 else
1936 return 0;
1938 /***********************************************************************
1939 * CC_MouseCheckResultWindow [internal]
1941 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
1943 HWND16 hwnd;
1944 POINT16 point = MAKEPOINT16(lParam);
1945 RECT16 rect;
1947 ClientToScreen16(hDlg,&point);
1948 hwnd=GetDlgItem32(hDlg,0x2c5);
1949 GetWindowRect16(hwnd,&rect);
1950 if (PtInRect16(&rect,point))
1952 PostMessage16(hDlg,WM_COMMAND,0x2c9,0);
1953 return 1;
1955 return 0;
1958 /***********************************************************************
1959 * CC_CheckDigitsInEdit [internal]
1961 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
1963 int i,k,m,result,value;
1964 long editpos;
1965 char buffer[30];
1966 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1967 m=strlen(buffer);
1968 result=0;
1970 for (i=0;i<m;i++)
1971 if (buffer[i]<'0' || buffer[i]>'9')
1973 for (k=i+1;k<=m;k++) /* delete bad character */
1975 buffer[i]=buffer[k];
1976 m--;
1978 buffer[m]=0;
1979 result=1;
1982 value=atoi(buffer);
1983 if (value>maxval) /* build a new string */
1985 sprintf(buffer,"%d",maxval);
1986 result=2;
1988 if (result)
1990 editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
1991 SetWindowText32A(hwnd,buffer);
1992 SendMessage16(hwnd,EM_SETSEL16,0,editpos);
1994 return value;
1999 /***********************************************************************
2000 * CC_PaintSelectedColor [internal]
2002 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
2004 RECT16 rect;
2005 HDC32 hdc;
2006 HBRUSH32 hBrush;
2007 HWND32 hwnd=GetDlgItem32(hDlg,0x2c5);
2008 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2010 hdc=GetDC32(hwnd);
2011 GetClientRect16 (hwnd, &rect) ;
2012 hBrush = CreateSolidBrush32(cr);
2013 if (hBrush)
2015 hBrush = SelectObject32 (hdc, hBrush) ;
2016 Rectangle32(hdc, rect.left,rect.top,rect.right/2,rect.bottom);
2017 DeleteObject32 (SelectObject32 (hdc,hBrush)) ;
2018 hBrush=CreateSolidBrush32(GetNearestColor32(hdc,cr));
2019 if (hBrush)
2021 hBrush= SelectObject32 (hdc, hBrush) ;
2022 Rectangle32( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
2023 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2026 ReleaseDC32(hwnd,hdc);
2030 /***********************************************************************
2031 * CC_PaintTriangle [internal]
2033 static void CC_PaintTriangle(HWND16 hDlg,int y)
2035 HDC32 hDC;
2036 long temp;
2037 int w=GetDialogBaseUnits();
2038 POINT16 points[3];
2039 int height;
2040 int oben;
2041 RECT16 rect;
2042 HWND16 hwnd=GetDlgItem32(hDlg,0x2be);
2043 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2045 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2047 GetClientRect16(hwnd,&rect);
2048 height=rect.bottom;
2049 hDC=GetDC32(hDlg);
2051 points[0].y=rect.top;
2052 points[0].x=rect.right; /* | /| */
2053 ClientToScreen16(hwnd,points); /* | / | */
2054 ScreenToClient16(hDlg,points); /* |< | */
2055 oben=points[0].y; /* | \ | */
2056 /* | \| */
2057 temp=(long)height*(long)y;
2058 points[0].y=oben+height -temp/(long)MAXVERT;
2059 points[1].y=points[0].y+w;
2060 points[2].y=points[0].y-w;
2061 points[2].x=points[1].x=points[0].x + w;
2063 if (lpp->old3angle.left)
2064 FillRect16(hDC,&lpp->old3angle,GetStockObject32(WHITE_BRUSH));
2065 lpp->old3angle.left =points[0].x;
2066 lpp->old3angle.right =points[1].x+1;
2067 lpp->old3angle.top =points[2].y-1;
2068 lpp->old3angle.bottom=points[1].y+1;
2069 Polygon16(hDC,points,3);
2070 ReleaseDC32(hDlg,hDC);
2075 /***********************************************************************
2076 * CC_PaintCross [internal]
2078 static void CC_PaintCross(HWND16 hDlg,int x,int y)
2080 HDC32 hDC;
2081 int w=GetDialogBaseUnits();
2082 HWND16 hwnd=GetDlgItem32(hDlg,0x2c6);
2083 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2084 RECT16 rect;
2085 POINT16 point;
2086 HPEN32 hPen;
2088 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2090 GetClientRect16(hwnd,&rect);
2091 hDC=GetDC32(hwnd);
2092 SelectClipRgn32(hDC,CreateRectRgnIndirect16(&rect));
2093 hPen=CreatePen32(PS_SOLID,2,0);
2094 hPen=SelectObject32(hDC,hPen);
2095 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
2096 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
2097 if (lpp->oldcross.left!=lpp->oldcross.right)
2098 BitBlt32(hDC,lpp->oldcross.left,lpp->oldcross.top,
2099 lpp->oldcross.right-lpp->oldcross.left,
2100 lpp->oldcross.bottom-lpp->oldcross.top,
2101 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
2102 lpp->oldcross.left =point.x-w-1;
2103 lpp->oldcross.right =point.x+w+1;
2104 lpp->oldcross.top =point.y-w-1;
2105 lpp->oldcross.bottom=point.y+w+1;
2107 MoveTo(hDC,point.x-w,point.y);
2108 LineTo32(hDC,point.x+w,point.y);
2109 MoveTo(hDC,point.x,point.y-w);
2110 LineTo32(hDC,point.x,point.y+w);
2111 DeleteObject32(SelectObject32(hDC,hPen));
2112 ReleaseDC32(hwnd,hDC);
2117 #define XSTEPS 48
2118 #define YSTEPS 24
2121 /***********************************************************************
2122 * CC_PrepareColorGraph [internal]
2124 static void CC_PrepareColorGraph(HWND16 hDlg)
2126 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
2127 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2128 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2129 HBRUSH32 hbrush;
2130 HDC32 hdc ;
2131 RECT16 rect,client;
2132 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT16));
2134 GetClientRect16(hwnd,&client);
2135 hdc=GetDC32(hwnd);
2136 lpp->hdcMem = CreateCompatibleDC32(hdc);
2137 lpp->hbmMem = CreateCompatibleBitmap32(hdc,client.right,client.bottom);
2138 SelectObject32(lpp->hdcMem,lpp->hbmMem);
2140 xdif=client.right /XSTEPS;
2141 ydif=client.bottom/YSTEPS+1;
2142 hdif=239/XSTEPS;
2143 sdif=240/YSTEPS;
2144 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
2146 rect.right=rect.left+xdif;
2147 rect.bottom=client.bottom;
2148 for(sat=0;sat<240+sdif;sat+=sdif)
2150 rect.top=rect.bottom-ydif;
2151 r=CC_HSLtoRGB('R',hue,sat,120);
2152 g=CC_HSLtoRGB('G',hue,sat,120);
2153 b=CC_HSLtoRGB('B',hue,sat,120);
2154 hbrush=CreateSolidBrush32(RGB(r,g,b));
2155 FillRect16(lpp->hdcMem,&rect,hbrush);
2156 DeleteObject32(hbrush);
2157 rect.bottom=rect.top;
2159 rect.left=rect.right;
2161 ReleaseDC32(hwnd,hdc);
2162 SetCursor16(hcursor);
2165 /***********************************************************************
2166 * CC_PaintColorGraph [internal]
2168 static void CC_PaintColorGraph(HWND16 hDlg)
2170 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2171 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2172 HDC32 hDC;
2173 RECT16 rect;
2174 if (IsWindowVisible32(hwnd)) /* if full size */
2176 if (!lpp->hdcMem)
2177 CC_PrepareColorGraph(hDlg); /* should not be necessary */
2179 hDC=GetDC32(hwnd);
2180 GetClientRect16(hwnd,&rect);
2181 if (lpp->hdcMem)
2182 BitBlt32(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
2183 else
2184 WARN(commdlg,"choose color: hdcMem is not defined\n");
2185 ReleaseDC32(hwnd,hDC);
2188 /***********************************************************************
2189 * CC_PaintLumBar [internal]
2191 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
2193 HWND32 hwnd=GetDlgItem32(hDlg,0x2be);
2194 RECT16 rect,client;
2195 int lum,ldif,ydif,r,g,b;
2196 HBRUSH32 hbrush;
2197 HDC32 hDC;
2199 if (IsWindowVisible32(hwnd))
2201 hDC=GetDC32(hwnd);
2202 GetClientRect16(hwnd,&client);
2203 rect=client;
2205 ldif=240/YSTEPS;
2206 ydif=client.bottom/YSTEPS+1;
2207 for(lum=0;lum<240+ldif;lum+=ldif)
2209 rect.top=MAX(0,rect.bottom-ydif);
2210 r=CC_HSLtoRGB('R',hue,sat,lum);
2211 g=CC_HSLtoRGB('G',hue,sat,lum);
2212 b=CC_HSLtoRGB('B',hue,sat,lum);
2213 hbrush=CreateSolidBrush32(RGB(r,g,b));
2214 FillRect16(hDC,&rect,hbrush);
2215 DeleteObject32(hbrush);
2216 rect.bottom=rect.top;
2218 GetClientRect16(hwnd,&rect);
2219 FrameRect16(hDC,&rect,GetStockObject32(BLACK_BRUSH));
2220 ReleaseDC32(hwnd,hDC);
2224 /***********************************************************************
2225 * CC_EditSetRGB [internal]
2227 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
2229 char buffer[10];
2230 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2231 int r=GetRValue(cr);
2232 int g=GetGValue(cr);
2233 int b=GetBValue(cr);
2234 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2236 lpp->updating=TRUE;
2237 sprintf(buffer,"%d",r);
2238 SetWindowText32A(GetDlgItem32(hDlg,0x2c2),buffer);
2239 sprintf(buffer,"%d",g);
2240 SetWindowText32A(GetDlgItem32(hDlg,0x2c3),buffer);
2241 sprintf(buffer,"%d",b);
2242 SetWindowText32A(GetDlgItem32(hDlg,0x2c4),buffer);
2243 lpp->updating=FALSE;
2247 /***********************************************************************
2248 * CC_EditSetHSL [internal]
2250 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
2252 char buffer[10];
2253 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2254 lpp->updating=TRUE;
2255 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2257 lpp->updating=TRUE;
2258 sprintf(buffer,"%d",h);
2259 SetWindowText32A(GetDlgItem32(hDlg,0x2bf),buffer);
2260 sprintf(buffer,"%d",s);
2261 SetWindowText32A(GetDlgItem32(hDlg,0x2c0),buffer);
2262 sprintf(buffer,"%d",l);
2263 SetWindowText32A(GetDlgItem32(hDlg,0x2c1),buffer);
2264 lpp->updating=FALSE;
2266 CC_PaintLumBar(hDlg,h,s);
2269 /***********************************************************************
2270 * CC_SwitchToFullSize [internal]
2272 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
2274 int i;
2275 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2277 EnableWindow32(GetDlgItem32(hDlg,0x2cf),FALSE);
2278 CC_PrepareColorGraph(hDlg);
2279 for (i=0x2bf;i<0x2c5;i++)
2280 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2281 for (i=0x2d3;i<0x2d9;i++)
2282 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2283 EnableWindow32(GetDlgItem32(hDlg,0x2c9),TRUE);
2284 EnableWindow32(GetDlgItem32(hDlg,0x2c8),TRUE);
2286 if (lprect)
2287 SetWindowPos32(hDlg,NULL,0,0,lprect->right-lprect->left,
2288 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
2290 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_SHOW);
2291 ShowWindow32(GetDlgItem32(hDlg,0x2be),SW_SHOW);
2292 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_SHOW);
2294 CC_EditSetRGB(hDlg,result);
2295 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2298 /***********************************************************************
2299 * CC_PaintPredefColorArray [internal]
2301 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
2303 HWND32 hwnd=GetDlgItem32(hDlg,0x2d0);
2304 RECT16 rect;
2305 HDC32 hdc;
2306 HBRUSH32 hBrush;
2307 int dx,dy,i,j,k;
2309 GetClientRect16(hwnd,&rect);
2310 dx=rect.right/cols;
2311 dy=rect.bottom/rows;
2312 k=rect.left;
2314 hdc=GetDC32(hwnd);
2315 GetClientRect16 (hwnd, &rect) ;
2317 for (j=0;j<rows;j++)
2319 for (i=0;i<cols;i++)
2321 hBrush = CreateSolidBrush32(predefcolors[j][i]);
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);
2335 /* FIXME: draw_a_focus_rect */
2337 /***********************************************************************
2338 * CC_PaintUserColorArray [internal]
2340 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
2342 HWND32 hwnd=GetDlgItem32(hDlg,0x2d1);
2343 RECT16 rect;
2344 HDC32 hdc;
2345 HBRUSH32 hBrush;
2346 int dx,dy,i,j,k;
2348 GetClientRect16(hwnd,&rect);
2350 dx=rect.right/cols;
2351 dy=rect.bottom/rows;
2352 k=rect.left;
2354 hdc=GetDC32(hwnd);
2355 if (hdc)
2357 for (j=0;j<rows;j++)
2359 for (i=0;i<cols;i++)
2361 hBrush = CreateSolidBrush32(lpcr[i+j*cols]);
2362 if (hBrush)
2364 hBrush = SelectObject32 (hdc, hBrush) ;
2365 Rectangle32( hdc, rect.left, rect.top,
2366 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2367 rect.left=rect.left+dx;
2368 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2371 rect.top=rect.top+dy;
2372 rect.left=k;
2374 ReleaseDC32(hwnd,hdc);
2376 /* FIXME: draw_a_focus_rect */
2381 /***********************************************************************
2382 * CC_HookCallChk [internal]
2384 static BOOL32 CC_HookCallChk(LPCHOOSECOLOR16 lpcc)
2386 if (lpcc)
2387 if(lpcc->Flags & CC_ENABLEHOOK)
2388 if (lpcc->lpfnHook)
2389 return TRUE;
2390 return FALSE;
2393 /***********************************************************************
2394 * CC_WMInitDialog [internal]
2396 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2398 int i,res;
2399 HWND16 hwnd;
2400 RECT16 rect;
2401 POINT16 point;
2402 struct CCPRIVATE * lpp;
2404 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
2405 lpp=calloc(1,sizeof(struct CCPRIVATE));
2406 lpp->lpcc=(LPCHOOSECOLOR16)lParam;
2407 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR16))
2409 EndDialog32 (hDlg, 0) ;
2410 return FALSE;
2412 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
2414 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
2415 ShowWindow32(GetDlgItem32(hDlg,0x40e),SW_HIDE);
2416 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
2417 #if 0
2418 cpos=MAKELONG(5,7); /* init */
2419 if (lpp->lpcc->Flags & CC_RGBINIT)
2421 for (i=0;i<6;i++)
2422 for (j=0;j<8;j++)
2423 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
2425 cpos=MAKELONG(i,j);
2426 goto found;
2429 found:
2430 /* FIXME: Draw_a_focus_rect & set_init_values */
2431 #endif
2432 GetWindowRect16(hDlg,&lpp->fullsize);
2433 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2435 hwnd=GetDlgItem32(hDlg,0x2cf);
2436 EnableWindow32(hwnd,FALSE);
2438 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2440 rect=lpp->fullsize;
2441 res=rect.bottom-rect.top;
2442 hwnd=GetDlgItem32(hDlg,0x2c6); /* cut at left border */
2443 point.x=point.y=0;
2444 ClientToScreen16(hwnd,&point);
2445 ScreenToClient16(hDlg,&point);
2446 GetClientRect16(hDlg,&rect);
2447 point.x+=GetSystemMetrics32(SM_CXDLGFRAME);
2448 SetWindowPos32(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
2450 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_HIDE);
2451 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_HIDE);
2453 else
2454 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
2455 res=TRUE;
2456 for (i=0x2bf;i<0x2c5;i++)
2457 SendMessage16(GetDlgItem32(hDlg,i),EM_LIMITTEXT16,3,0); /* max 3 digits: xyz */
2458 if (CC_HookCallChk(lpp->lpcc))
2459 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2460 return res;
2463 /***********************************************************************
2464 * CC_WMCommand [internal]
2466 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2468 int r,g,b,i,xx;
2469 UINT16 cokmsg;
2470 HDC32 hdc;
2471 COLORREF *cr;
2472 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2473 TRACE(commdlg,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
2474 switch (wParam)
2476 case 0x2c2: /* edit notify RGB */
2477 case 0x2c3:
2478 case 0x2c4:
2479 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2481 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
2482 r=GetRValue(lpp->lpcc->rgbResult);
2483 g=GetGValue(lpp->lpcc->rgbResult);
2484 b=GetBValue(lpp->lpcc->rgbResult);
2485 xx=0;
2486 switch (wParam)
2488 case 0x2c2:if ((xx=(i!=r))) r=i;break;
2489 case 0x2c3:if ((xx=(i!=g))) g=i;break;
2490 case 0x2c4:if ((xx=(i!=b))) b=i;break;
2492 if (xx) /* something has changed */
2494 lpp->lpcc->rgbResult=RGB(r,g,b);
2495 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2496 lpp->h=CC_RGBtoHSL('H',r,g,b);
2497 lpp->s=CC_RGBtoHSL('S',r,g,b);
2498 lpp->l=CC_RGBtoHSL('L',r,g,b);
2499 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2500 CC_PaintCross(hDlg,lpp->h,lpp->s);
2501 CC_PaintTriangle(hDlg,lpp->l);
2504 break;
2506 case 0x2bf: /* edit notify HSL */
2507 case 0x2c0:
2508 case 0x2c1:
2509 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2511 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
2512 xx=0;
2513 switch (wParam)
2515 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
2516 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
2517 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
2519 if (xx) /* something has changed */
2521 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2522 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2523 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2524 lpp->lpcc->rgbResult=RGB(r,g,b);
2525 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2526 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2527 CC_PaintCross(hDlg,lpp->h,lpp->s);
2528 CC_PaintTriangle(hDlg,lpp->l);
2531 break;
2533 case 0x2cf:
2534 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
2535 InvalidateRect32( hDlg, NULL, TRUE );
2536 SetFocus32(GetDlgItem32(hDlg,0x2bf));
2537 break;
2539 case 0x2c8: /* add colors ... column by column */
2540 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
2541 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
2542 if (++lpp->nextuserdef==16)
2543 lpp->nextuserdef=0;
2544 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2545 break;
2547 case 0x2c9: /* resulting color */
2548 hdc=GetDC32(hDlg);
2549 lpp->lpcc->rgbResult=GetNearestColor32(hdc,lpp->lpcc->rgbResult);
2550 ReleaseDC32(hDlg,hdc);
2551 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2552 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2553 r=GetRValue(lpp->lpcc->rgbResult);
2554 g=GetGValue(lpp->lpcc->rgbResult);
2555 b=GetBValue(lpp->lpcc->rgbResult);
2556 lpp->h=CC_RGBtoHSL('H',r,g,b);
2557 lpp->s=CC_RGBtoHSL('S',r,g,b);
2558 lpp->l=CC_RGBtoHSL('L',r,g,b);
2559 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2560 CC_PaintCross(hDlg,lpp->h,lpp->s);
2561 CC_PaintTriangle(hDlg,lpp->l);
2562 break;
2564 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2565 i=RegisterWindowMessage32A( HELPMSGSTRING );
2566 if (lpp->lpcc->hwndOwner)
2567 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2568 if (CC_HookCallChk(lpp->lpcc))
2569 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2570 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2571 break;
2573 case IDOK :
2574 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2575 if (lpp->lpcc->hwndOwner)
2576 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2577 break; /* do NOT close */
2579 EndDialog32 (hDlg, 1) ;
2580 return TRUE ;
2582 case IDCANCEL :
2583 EndDialog32 (hDlg, 0) ;
2584 return TRUE ;
2587 return FALSE;
2590 /***********************************************************************
2591 * CC_WMPaint [internal]
2593 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2595 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2596 /* we have to paint dialog children except text and buttons */
2598 CC_PaintPredefColorArray(hDlg,6,8);
2599 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2600 CC_PaintColorGraph(hDlg);
2601 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2602 CC_PaintCross(hDlg,lpp->h,lpp->s);
2603 CC_PaintTriangle(hDlg,lpp->l);
2604 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2606 /* special necessary for Wine */
2607 ValidateRect32(GetDlgItem32(hDlg,0x2d0),NULL);
2608 ValidateRect32(GetDlgItem32(hDlg,0x2d1),NULL);
2609 ValidateRect32(GetDlgItem32(hDlg,0x2c6),NULL);
2610 ValidateRect32(GetDlgItem32(hDlg,0x2be),NULL);
2611 ValidateRect32(GetDlgItem32(hDlg,0x2c5),NULL);
2612 /* hope we can remove it later -->FIXME */
2613 return 0;
2617 /***********************************************************************
2618 * CC_WMLButtonDown [internal]
2620 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2622 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2623 int r,g,b,i;
2624 i=0;
2625 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2626 i=1;
2627 else
2628 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2629 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2630 i=1;
2631 else
2632 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2633 i=2;
2634 else
2635 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2636 i=2;
2637 if (i==2)
2639 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2640 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2641 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2642 lpp->lpcc->rgbResult=RGB(r,g,b);
2644 if (i==1)
2646 r=GetRValue(lpp->lpcc->rgbResult);
2647 g=GetGValue(lpp->lpcc->rgbResult);
2648 b=GetBValue(lpp->lpcc->rgbResult);
2649 lpp->h=CC_RGBtoHSL('H',r,g,b);
2650 lpp->s=CC_RGBtoHSL('S',r,g,b);
2651 lpp->l=CC_RGBtoHSL('L',r,g,b);
2653 if (i)
2655 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2656 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2657 CC_PaintCross(hDlg,lpp->h,lpp->s);
2658 CC_PaintTriangle(hDlg,lpp->l);
2659 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2660 return TRUE;
2662 return FALSE;
2665 /***********************************************************************
2666 * ColorDlgProc (COMMDLG.8)
2668 LRESULT WINAPI ColorDlgProc(HWND16 hDlg, UINT16 message,
2669 WPARAM16 wParam, LONG lParam)
2671 int res;
2672 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2673 if (message!=WM_INITDIALOG)
2675 if (!lpp)
2676 return FALSE;
2677 res=0;
2678 if (CC_HookCallChk(lpp->lpcc))
2679 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2680 if (res)
2681 return res;
2684 /* FIXME: SetRGB message
2685 if (message && message==msetrgb)
2686 return HandleSetRGB(hDlg,lParam);
2689 switch (message)
2691 case WM_INITDIALOG:
2692 return CC_WMInitDialog(hDlg,wParam,lParam);
2693 case WM_NCDESTROY:
2694 DeleteDC32(lpp->hdcMem);
2695 DeleteObject32(lpp->hbmMem);
2696 free(lpp);
2697 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2698 break;
2699 case WM_COMMAND:
2700 if (CC_WMCommand(hDlg, wParam, lParam))
2701 return TRUE;
2702 break;
2703 case WM_PAINT:
2704 CC_WMPaint(hDlg, wParam, lParam);
2705 break;
2706 case WM_LBUTTONDBLCLK:
2707 if (CC_MouseCheckResultWindow(hDlg,lParam))
2708 return TRUE;
2709 break;
2710 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2711 break;
2712 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2713 break;
2714 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2715 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2716 return TRUE;
2717 break;
2719 return FALSE ;
2722 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONT32A chf32a)
2724 chf32a->lStructSize=sizeof(CHOOSEFONT32A);
2725 chf32a->hwndOwner=chf16->hwndOwner;
2726 chf32a->hDC=chf16->hDC;
2727 chf32a->iPointSize=chf16->iPointSize;
2728 chf32a->Flags=chf16->Flags;
2729 chf32a->rgbColors=chf16->rgbColors;
2730 chf32a->lCustData=chf16->lCustData;
2731 chf32a->lpfnHook=NULL;
2732 chf32a->lpTemplateName=PTR_SEG_TO_LIN(chf16->lpTemplateName);
2733 chf32a->hInstance=chf16->hInstance;
2734 chf32a->lpszStyle=PTR_SEG_TO_LIN(chf16->lpszStyle);
2735 chf32a->nFontType=chf16->nFontType;
2736 chf32a->nSizeMax=chf16->nSizeMax;
2737 chf32a->nSizeMin=chf16->nSizeMin;
2738 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16->lpLogFont), chf32a->lpLogFont);
2742 /***********************************************************************
2743 * ChooseFont16 (COMMDLG.15)
2745 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
2747 HINSTANCE16 hInst;
2748 HANDLE16 hDlgTmpl = 0;
2749 BOOL16 bRet = FALSE, win32Format = FALSE;
2750 LPCVOID template;
2751 HWND32 hwndDialog;
2752 CHOOSEFONT32A cf32a;
2753 LOGFONT32A lf32a;
2754 SEGPTR lpTemplateName;
2756 cf32a.lpLogFont=&lf32a;
2757 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
2759 TRACE(commdlg,"ChooseFont\n");
2760 if (!lpChFont) return FALSE;
2762 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
2764 if (!(template = LockResource16( lpChFont->hInstance )))
2766 CommDlgLastError = CDERR_LOADRESFAILURE;
2767 return FALSE;
2770 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2772 HANDLE16 hResInfo;
2773 if (!(hResInfo = FindResource16( lpChFont->hInstance,
2774 lpChFont->lpTemplateName,
2775 RT_DIALOG16)))
2777 CommDlgLastError = CDERR_FINDRESFAILURE;
2778 return FALSE;
2780 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
2781 !(template = LockResource16( hDlgTmpl )))
2783 CommDlgLastError = CDERR_LOADRESFAILURE;
2784 return FALSE;
2787 else
2789 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2790 win32Format = TRUE;
2793 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2795 /* lpTemplateName is not used in the dialog */
2796 lpTemplateName=lpChFont->lpTemplateName;
2797 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
2799 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
2800 lpChFont->hwndOwner,
2801 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2802 (DWORD)lpChFont, WIN_PROC_16 );
2803 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2804 if (hDlgTmpl) FreeResource16( hDlgTmpl );
2805 lpChFont->lpTemplateName=lpTemplateName;
2806 FONT_LogFont32ATo16(cf32a.lpLogFont,
2807 (LPLOGFONT16)(PTR_SEG_TO_LIN(lpChFont->lpLogFont)));
2808 return bRet;
2812 /***********************************************************************
2813 * ChooseFont32A (COMDLG32.3)
2815 BOOL32 WINAPI ChooseFont32A(LPCHOOSEFONT32A lpChFont)
2817 BOOL32 bRet=FALSE;
2818 HWND32 hwndDialog;
2819 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2820 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2821 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2822 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2823 hwndDialog = DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2824 (DLGPROC16)FormatCharDlgProc32A, (LPARAM)lpChFont, WIN_PROC_32A );
2825 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2826 return bRet;
2829 /***********************************************************************
2830 * ChooseFont32W (COMDLG32.4)
2832 BOOL32 WINAPI ChooseFont32W(LPCHOOSEFONT32W lpChFont)
2834 BOOL32 bRet=FALSE;
2835 HWND32 hwndDialog;
2836 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2837 CHOOSEFONT32A cf32a;
2838 LOGFONT32A lf32a;
2839 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2840 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2841 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2842 memcpy(&cf32a, lpChFont, sizeof(cf32a));
2843 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONT32A));
2844 lstrcpynWtoA(lf32a.lfFaceName, lpChFont->lpLogFont->lfFaceName, LF_FACESIZE);
2845 cf32a.lpLogFont=&lf32a;
2846 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
2847 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
2848 hwndDialog=DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2849 (DLGPROC16)FormatCharDlgProc32W, (LPARAM)lpChFont, WIN_PROC_32W );
2850 if (hwndDialog)bRet=DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2851 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
2852 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
2853 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONT32A));
2854 lstrcpynAtoW(lpChFont->lpLogFont->lfFaceName, lf32a.lfFaceName, LF_FACESIZE);
2855 return bRet;
2859 #define TEXT_EXTRAS 4
2860 #define TEXT_COLORS 16
2862 static const COLORREF textcolors[TEXT_COLORS]=
2864 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2865 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2866 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2867 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2870 /***********************************************************************
2871 * CFn_HookCallChk [internal]
2873 static BOOL32 CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
2875 if (lpcf)
2876 if(lpcf->Flags & CF_ENABLEHOOK)
2877 if (lpcf->lpfnHook)
2878 return TRUE;
2879 return FALSE;
2882 /***********************************************************************
2883 * CFn_HookCallChk32 [internal]
2885 static BOOL32 CFn_HookCallChk32(LPCHOOSEFONT32A lpcf)
2887 if (lpcf)
2888 if(lpcf->Flags & CF_ENABLEHOOK)
2889 if (lpcf->lpfnHook)
2890 return TRUE;
2891 return FALSE;
2895 /*************************************************************************
2896 * AddFontFamily [internal]
2898 static INT32 AddFontFamily(LPLOGFONT32A lplf, UINT32 nFontType,
2899 LPCHOOSEFONT32A lpcf, HWND32 hwnd)
2901 int i;
2902 WORD w;
2904 TRACE(commdlg,"font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
2906 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2907 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2908 return 1;
2909 if (lpcf->Flags & CF_ANSIONLY)
2910 if (lplf->lfCharSet != ANSI_CHARSET)
2911 return 1;
2912 if (lpcf->Flags & CF_TTONLY)
2913 if (!(nFontType & TRUETYPE_FONTTYPE))
2914 return 1;
2916 i=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)lplf->lfFaceName);
2917 if (i!=CB_ERR)
2919 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2920 SendMessage32A(hwnd, CB_SETITEMDATA32, i, MAKELONG(nFontType,w));
2921 return 1 ; /* store some important font information */
2923 else
2924 return 0;
2927 typedef struct
2929 HWND32 hWnd1;
2930 HWND32 hWnd2;
2931 LPCHOOSEFONT32A lpcf32a;
2932 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
2934 /*************************************************************************
2935 * FontFamilyEnumProc32 [internal]
2937 INT32 WINAPI FontFamilyEnumProc32(LPENUMLOGFONT32A lpEnumLogFont,
2938 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam)
2940 LPCFn_ENUMSTRUCT e;
2941 e=(LPCFn_ENUMSTRUCT)lParam;
2942 return AddFontFamily(&lpEnumLogFont->elfLogFont, nFontType, e->lpcf32a, e->hWnd1);
2945 /***********************************************************************
2946 * FontFamilyEnumProc16 (COMMDLG.19)
2948 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
2949 UINT16 nFontType, LPARAM lParam )
2951 HWND16 hwnd=LOWORD(lParam);
2952 HWND16 hDlg=GetParent16(hwnd);
2953 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
2954 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
2955 LOGFONT32A lf32a;
2956 FONT_LogFont16To32A(lplf, &lf32a);
2957 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
2958 hwnd);
2961 /*************************************************************************
2962 * SetFontStylesToCombo2 [internal]
2964 * Fill font style information into combobox (without using font.c directly)
2966 static int SetFontStylesToCombo2(HWND32 hwnd, HDC32 hdc, LPLOGFONT32A lplf)
2968 #define FSTYLES 4
2969 struct FONTSTYLE
2970 { int italic;
2971 int weight;
2972 char stname[20]; };
2973 static struct FONTSTYLE fontstyles[FSTYLES]={
2974 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
2975 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
2976 HFONT16 hf;
2977 TEXTMETRIC16 tm;
2978 int i,j;
2980 for (i=0;i<FSTYLES;i++)
2982 lplf->lfItalic=fontstyles[i].italic;
2983 lplf->lfWeight=fontstyles[i].weight;
2984 hf=CreateFontIndirect32A(lplf);
2985 hf=SelectObject32(hdc,hf);
2986 GetTextMetrics16(hdc,&tm);
2987 hf=SelectObject32(hdc,hf);
2988 DeleteObject32(hf);
2990 if (tm.tmWeight==fontstyles[i].weight &&
2991 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
2993 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
2994 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
2995 SEGPTR_FREE(str);
2996 if (j==CB_ERR) return 1;
2997 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
2998 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
2999 if (j==CB_ERR) return 1;
3002 return 0;
3005 /*************************************************************************
3006 * AddFontSizeToCombo3 [internal]
3008 static int AddFontSizeToCombo3(HWND32 hwnd, UINT32 h, LPCHOOSEFONT32A lpcf)
3010 int j;
3011 char buffer[20];
3013 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
3014 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
3016 sprintf(buffer, "%2d", h);
3017 j=SendMessage32A(hwnd, CB_FINDSTRINGEXACT32, -1, (LPARAM)buffer);
3018 if (j==CB_ERR)
3020 j=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)buffer);
3021 if (j!=CB_ERR) j = SendMessage32A(hwnd, CB_SETITEMDATA32, j, h);
3022 if (j==CB_ERR) return 1;
3025 return 0;
3028 /*************************************************************************
3029 * SetFontSizesToCombo3 [internal]
3031 static int SetFontSizesToCombo3(HWND32 hwnd, LPCHOOSEFONT32A lpcf)
3033 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
3034 int i;
3036 for (i=0; sizes[i]; i++)
3037 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
3038 return 0;
3041 /***********************************************************************
3042 * AddFontStyle [internal]
3044 INT32 AddFontStyle(LPLOGFONT32A lplf, UINT32 nFontType,
3045 LPCHOOSEFONT32A lpcf, HWND32 hcmb2, HWND32 hcmb3, HWND32 hDlg)
3047 int i;
3049 TRACE(commdlg,"(nFontType=%d)\n",nFontType);
3050 TRACE(commdlg," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
3051 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
3052 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
3053 lplf->lfEscapement,lplf->lfOrientation,
3054 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
3055 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
3056 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
3057 if (nFontType & RASTER_FONTTYPE)
3059 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
3060 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
3062 if (!SendMessage32A(hcmb2, CB_GETCOUNT32, 0, 0))
3064 HDC32 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3065 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
3066 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3067 ReleaseDC32(hDlg,hdc);
3068 if (i)
3069 return 0;
3071 return 1 ;
3075 /***********************************************************************
3076 * FontStyleEnumProc16 (COMMDLG.18)
3078 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
3079 UINT16 nFontType, LPARAM lParam )
3081 HWND16 hcmb2=LOWORD(lParam);
3082 HWND16 hcmb3=HIWORD(lParam);
3083 HWND16 hDlg=GetParent16(hcmb3);
3084 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3085 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
3086 LOGFONT32A lf32a;
3087 FONT_LogFont16To32A(lplf, &lf32a);
3088 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
3089 hcmb2, hcmb3, hDlg);
3092 /***********************************************************************
3093 * FontStyleEnumProc32 [internal]
3095 INT32 WINAPI FontStyleEnumProc32( LPENUMLOGFONT32A lpFont,
3096 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam )
3098 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
3099 HWND32 hcmb2=s->hWnd1;
3100 HWND32 hcmb3=s->hWnd2;
3101 HWND32 hDlg=GetParent32(hcmb3);
3102 return AddFontStyle(&lpFont->elfLogFont, nFontType, s->lpcf32a, hcmb2,
3103 hcmb3, hDlg);
3106 /***********************************************************************
3107 * CFn_WMInitDialog [internal]
3109 LRESULT CFn_WMInitDialog(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3110 LPCHOOSEFONT32A lpcf)
3112 HDC32 hdc;
3113 int i,j,res,init=0;
3114 long l;
3115 LPLOGFONT32A lpxx;
3116 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3118 SetWindowLong32A(hDlg, DWL_USER, lParam);
3119 lpxx=lpcf->lpLogFont;
3120 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
3122 if (lpcf->lStructSize != sizeof(CHOOSEFONT32A))
3124 ERR(commdlg,"structure size failure !!!\n");
3125 EndDialog32 (hDlg, 0);
3126 return FALSE;
3128 if (!hBitmapTT)
3129 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3131 /* This font will be deleted by WM_COMMAND */
3132 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,
3133 CreateFont32A(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
3135 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow32(lpcf->hwndOwner))
3136 ShowWindow32(GetDlgItem32(hDlg,pshHelp),SW_HIDE);
3137 if (!(lpcf->Flags & CF_APPLY))
3138 ShowWindow32(GetDlgItem32(hDlg,psh3),SW_HIDE);
3139 if (lpcf->Flags & CF_EFFECTS)
3141 for (res=1,i=0;res && i<TEXT_COLORS;i++)
3143 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
3144 char name[20];
3145 strcpy( name, "[color name]" );
3146 j=SendDlgItemMessage32A(hDlg, cmb4, CB_ADDSTRING32, 0, (LPARAM)name);
3147 SendDlgItemMessage32A(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
3148 /* look for a fitting value in color combobox */
3149 if (textcolors[j]==lpcf->rgbColors)
3150 SendDlgItemMessage32A(hDlg,cmb4, CB_SETCURSEL32,j,0);
3153 else
3155 ShowWindow32(GetDlgItem32(hDlg,cmb4),SW_HIDE);
3156 ShowWindow32(GetDlgItem32(hDlg,chx1),SW_HIDE);
3157 ShowWindow32(GetDlgItem32(hDlg,chx2),SW_HIDE);
3158 ShowWindow32(GetDlgItem32(hDlg,grp1),SW_HIDE);
3159 ShowWindow32(GetDlgItem32(hDlg,stc4),SW_HIDE);
3161 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3162 if (hdc)
3164 CFn_ENUMSTRUCT s;
3165 s.hWnd1=GetDlgItem32(hDlg,cmb1);
3166 s.lpcf32a=lpcf;
3167 if (!EnumFontFamilies32A(hdc, NULL, FontFamilyEnumProc32, (LPARAM)&s))
3168 TRACE(commdlg,"EnumFontFamilies returns 0\n");
3169 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
3171 /* look for fitting font name in combobox1 */
3172 j=SendDlgItemMessage32A(hDlg,cmb1,CB_FINDSTRING32,-1,(LONG)lpxx->lfFaceName);
3173 if (j!=CB_ERR)
3175 SendDlgItemMessage32A(hDlg, cmb1, CB_SETCURSEL32, j, 0);
3176 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3177 GetDlgItem32(hDlg,cmb1));
3178 init=1;
3179 /* look for fitting font style in combobox2 */
3180 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
3181 for (i=0;i<TEXT_EXTRAS;i++)
3183 if (l==SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0))
3184 SendDlgItemMessage32A(hDlg, cmb2, CB_SETCURSEL32, i, 0);
3187 /* look for fitting font size in combobox3 */
3188 j=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCOUNT32, 0, 0);
3189 for (i=0;i<j;i++)
3191 if (lpxx->lfHeight==(int)SendDlgItemMessage32A(hDlg,cmb3, CB_GETITEMDATA32,i,0))
3192 SendDlgItemMessage32A(hDlg,cmb3,CB_SETCURSEL32,i,0);
3196 if (!init)
3198 SendDlgItemMessage32A(hDlg,cmb1,CB_SETCURSEL32,0,0);
3199 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3200 GetDlgItem32(hDlg,cmb1));
3202 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
3204 j=SendDlgItemMessage32A(hDlg,cmb2,CB_FINDSTRING32,-1,(LONG)lpcf->lpszStyle);
3205 if (j!=CB_ERR)
3207 j=SendDlgItemMessage32A(hDlg,cmb2,CB_SETCURSEL32,j,0);
3208 SendMessage32A(hDlg,WM_COMMAND,cmb2,
3209 MAKELONG(GetDlgItem32(hDlg,cmb2),CBN_SELCHANGE));
3213 else
3215 WARN(commdlg,"HDC failure !!!\n");
3216 EndDialog32 (hDlg, 0);
3217 return FALSE;
3220 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3221 ReleaseDC32(hDlg,hdc);
3222 SetCursor32(hcursor);
3223 return TRUE;
3227 /***********************************************************************
3228 * CFn_WMMeasureItem [internal]
3230 LRESULT CFn_WMMeasureItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3232 BITMAP32 bm;
3233 LPMEASUREITEMSTRUCT32 lpmi=(LPMEASUREITEMSTRUCT32)lParam;
3234 if (!hBitmapTT)
3235 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3236 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3237 lpmi->itemHeight=bm.bmHeight;
3238 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
3239 return 0;
3243 /***********************************************************************
3244 * CFn_WMDrawItem [internal]
3246 LRESULT CFn_WMDrawItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3248 HBRUSH32 hBrush;
3249 char buffer[40];
3250 BITMAP32 bm;
3251 COLORREF cr, oldText=0, oldBk=0;
3252 RECT32 rect;
3253 #if 0
3254 HDC32 hMemDC;
3255 int nFontType;
3256 HBITMAP32 hBitmap; /* for later TT usage */
3257 #endif
3258 LPDRAWITEMSTRUCT32 lpdi = (LPDRAWITEMSTRUCT32)lParam;
3260 if (lpdi->itemID == 0xFFFF) /* got no items */
3261 DrawFocusRect32(lpdi->hDC, &lpdi->rcItem);
3262 else
3264 if (lpdi->CtlType == ODT_COMBOBOX)
3266 if (lpdi->itemState ==ODS_SELECTED)
3268 hBrush=GetSysColorBrush32(COLOR_HIGHLIGHT);
3269 oldText=SetTextColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHTTEXT));
3270 oldBk=SetBkColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHT));
3271 } else
3273 hBrush = SelectObject32(lpdi->hDC, GetStockObject32(LTGRAY_BRUSH));
3274 SelectObject32(lpdi->hDC, hBrush);
3276 FillRect32(lpdi->hDC, &lpdi->rcItem, hBrush);
3278 else
3279 return TRUE; /* this should never happen */
3281 rect=lpdi->rcItem;
3282 switch (lpdi->CtlID)
3284 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
3285 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3286 (LPARAM)buffer);
3287 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3288 TextOut32A(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
3289 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3290 #if 0
3291 nFontType = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3292 /* FIXME: draw bitmap if truetype usage */
3293 if (nFontType&TRUETYPE_FONTTYPE)
3295 hMemDC = CreateCompatibleDC32(lpdi->hDC);
3296 hBitmap = SelectObject32(hMemDC, hBitmapTT);
3297 BitBlt32(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
3298 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
3299 SelectObject32(hMemDC, hBitmap);
3300 DeleteDC32(hMemDC);
3302 #endif
3303 break;
3304 case cmb2:
3305 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
3306 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3307 (LPARAM)buffer);
3308 TextOut32A(lpdi->hDC, lpdi->rcItem.left,
3309 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3310 break;
3312 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
3313 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3314 (LPARAM)buffer);
3315 TextOut32A(lpdi->hDC, lpdi->rcItem.left + 25+5,
3316 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3317 cr = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3318 hBrush = CreateSolidBrush32(cr);
3319 if (hBrush)
3321 hBrush = SelectObject32 (lpdi->hDC, hBrush) ;
3322 rect.right=rect.left+25;
3323 rect.top++;
3324 rect.left+=5;
3325 rect.bottom--;
3326 Rectangle32( lpdi->hDC, rect.left, rect.top,
3327 rect.right, rect.bottom );
3328 DeleteObject32( SelectObject32 (lpdi->hDC, hBrush)) ;
3330 rect=lpdi->rcItem;
3331 rect.left+=25+5;
3332 break;
3334 default: return TRUE; /* this should never happen */
3336 if (lpdi->itemState == ODS_SELECTED)
3338 SetTextColor32(lpdi->hDC, oldText);
3339 SetBkColor32(lpdi->hDC, oldBk);
3342 return TRUE;
3345 /***********************************************************************
3346 * CFn_WMCtlColor [internal]
3348 LRESULT CFn_WMCtlColorStatic(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3349 LPCHOOSEFONT32A lpcf)
3351 if (lpcf->Flags & CF_EFFECTS)
3352 if (GetDlgCtrlID32(lParam)==stc6)
3354 SetTextColor32((HDC32)wParam, lpcf->rgbColors);
3355 return GetStockObject32(WHITE_BRUSH);
3357 return 0;
3360 /***********************************************************************
3361 * CFn_WMCommand [internal]
3363 LRESULT CFn_WMCommand(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3364 LPCHOOSEFONT32A lpcf)
3366 HFONT32 hFont;
3367 int i,j;
3368 long l;
3369 HDC32 hdc;
3370 LPLOGFONT32A lpxx=lpcf->lpLogFont;
3372 TRACE(commdlg,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
3373 switch (LOWORD(wParam))
3375 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
3377 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3378 if (hdc)
3380 SendDlgItemMessage32A(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
3381 SendDlgItemMessage32A(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
3382 i=SendDlgItemMessage32A(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
3383 if (i!=CB_ERR)
3385 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3386 CFn_ENUMSTRUCT s;
3387 char str[256];
3388 SendDlgItemMessage32A(hDlg, cmb1, CB_GETLBTEXT32, i,
3389 (LPARAM)str);
3390 TRACE(commdlg,"WM_COMMAND/cmb1 =>%s\n",str);
3391 s.hWnd1=GetDlgItem32(hDlg, cmb2);
3392 s.hWnd2=GetDlgItem32(hDlg, cmb3);
3393 s.lpcf32a=lpcf;
3394 EnumFontFamilies32A(hdc, str, FontStyleEnumProc32, (LPARAM)&s);
3395 SetCursor32(hcursor);
3397 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3398 ReleaseDC32(hDlg,hdc);
3400 else
3402 WARN(commdlg,"HDC failure !!!\n");
3403 EndDialog32 (hDlg, 0);
3404 return TRUE;
3407 case chx1:
3408 case chx2:
3409 case cmb2:
3410 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
3412 char str[256];
3413 TRACE(commdlg,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
3414 i=SendDlgItemMessage32A(hDlg,cmb1,CB_GETCURSEL32,0,0);
3415 if (i==CB_ERR)
3416 i=GetDlgItemText32A( hDlg, cmb1, str, 256 );
3417 else
3419 SendDlgItemMessage32A(hDlg,cmb1,CB_GETLBTEXT32,i,
3420 (LPARAM)str);
3421 l=SendDlgItemMessage32A(hDlg,cmb1,CB_GETITEMDATA32,i,0);
3422 j=HIWORD(l);
3423 lpcf->nFontType = LOWORD(l);
3424 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
3425 /* same value reported to the EnumFonts
3426 call back with the extra FONTTYPE_... bits added */
3427 lpxx->lfPitchAndFamily=j&0xff;
3428 lpxx->lfCharSet=j>>8;
3430 strcpy(lpxx->lfFaceName,str);
3431 i=SendDlgItemMessage32A(hDlg, cmb2, CB_GETCURSEL32, 0, 0);
3432 if (i!=CB_ERR)
3434 l=SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0);
3435 if (0!=(lpxx->lfItalic=HIWORD(l)))
3436 lpcf->nFontType |= ITALIC_FONTTYPE;
3437 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
3438 lpcf->nFontType |= BOLD_FONTTYPE;
3440 i=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCURSEL32, 0, 0);
3441 if (i!=CB_ERR)
3442 lpxx->lfHeight=-LOWORD(SendDlgItemMessage32A(hDlg, cmb3, CB_GETITEMDATA32, i, 0));
3443 else
3444 lpxx->lfHeight=0;
3445 lpxx->lfStrikeOut=IsDlgButtonChecked32(hDlg,chx1);
3446 lpxx->lfUnderline=IsDlgButtonChecked32(hDlg,chx2);
3447 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
3448 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
3449 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
3450 lpxx->lfQuality=DEFAULT_QUALITY;
3451 lpcf->iPointSize= -10*lpxx->lfHeight;
3453 hFont=CreateFontIndirect32A(lpxx);
3454 if (hFont)
3456 HFONT32 oldFont=SendDlgItemMessage32A(hDlg, stc6,
3457 WM_GETFONT, 0, 0);
3458 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,hFont,TRUE);
3459 DeleteObject32(oldFont);
3462 break;
3464 case cmb4:i=SendDlgItemMessage32A(hDlg, cmb4, CB_GETCURSEL32, 0, 0);
3465 if (i!=CB_ERR)
3467 lpcf->rgbColors=textcolors[i];
3468 InvalidateRect32( GetDlgItem32(hDlg,stc6), NULL, 0 );
3470 break;
3472 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
3473 if (lpcf->hwndOwner)
3474 SendMessage32A(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLong32A(hDlg, DWL_USER));
3475 /* if (CFn_HookCallChk(lpcf))
3476 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
3477 break;
3479 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
3480 ( (lpcf->Flags & CF_LIMITSIZE) &&
3481 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
3482 (-lpxx->lfHeight <= lpcf->nSizeMax)))
3483 EndDialog32(hDlg, TRUE);
3484 else
3486 char buffer[80];
3487 sprintf(buffer,"Select a font size between %d and %d points.",
3488 lpcf->nSizeMin,lpcf->nSizeMax);
3489 MessageBox32A(hDlg, buffer, NULL, MB_OK);
3491 return(TRUE);
3492 case IDCANCEL:EndDialog32(hDlg, FALSE);
3493 return(TRUE);
3495 return(FALSE);
3498 static LRESULT CFn_WMDestroy(HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
3500 DeleteObject32(SendDlgItemMessage32A(hwnd, stc6, WM_GETFONT, 0, 0));
3501 return TRUE;
3505 /***********************************************************************
3506 * FormatCharDlgProc16 (COMMDLG.16)
3507 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
3508 2. some CF_.. flags are not supported
3509 3. some TType extensions
3511 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
3512 LPARAM lParam)
3514 LPCHOOSEFONT16 lpcf;
3515 LPCHOOSEFONT32A lpcf32a;
3516 UINT32 uMsg32;
3517 WPARAM32 wParam32;
3518 LRESULT res=0;
3519 if (message!=WM_INITDIALOG)
3521 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3522 if (!lpcf)
3523 return FALSE;
3524 if (CFn_HookCallChk(lpcf))
3525 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
3526 if (res)
3527 return res;
3529 else
3531 lpcf=(LPCHOOSEFONT16)lParam;
3532 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3533 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3535 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3536 return FALSE;
3538 if (CFn_HookCallChk(lpcf))
3539 return CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3541 WINPROC_MapMsg16To32A(message, wParam, &uMsg32, &wParam32, &lParam);
3542 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3543 switch (uMsg32)
3545 case WM_MEASUREITEM:
3546 res=CFn_WMMeasureItem(hDlg, wParam32, lParam);
3547 break;
3548 case WM_DRAWITEM:
3549 res=CFn_WMDrawItem(hDlg, wParam32, lParam);
3550 break;
3551 case WM_CTLCOLORSTATIC:
3552 res=CFn_WMCtlColorStatic(hDlg, wParam32, lParam, lpcf32a);
3553 break;
3554 case WM_COMMAND:
3555 res=CFn_WMCommand(hDlg, wParam32, lParam, lpcf32a);
3556 break;
3557 case WM_DESTROY:
3558 res=CFn_WMDestroy(hDlg, wParam32, lParam);
3559 break;
3560 case WM_CHOOSEFONT_GETLOGFONT:
3561 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3562 lParam);
3563 FIXME(commdlg, "current logfont back to caller\n");
3564 break;
3566 WINPROC_UnmapMsg16To32A(uMsg32, wParam32, lParam, res);
3567 return res;
3570 /***********************************************************************
3571 * FormatCharDlgProc32A [internal]
3573 LRESULT WINAPI FormatCharDlgProc32A(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3574 LPARAM lParam)
3576 LPCHOOSEFONT32A lpcf;
3577 LRESULT res=FALSE;
3578 if (uMsg!=WM_INITDIALOG)
3580 lpcf=(LPCHOOSEFONT32A)GetWindowLong32A(hDlg, DWL_USER);
3581 if (!lpcf)
3582 return FALSE;
3583 if (CFn_HookCallChk32(lpcf))
3584 res=CallWindowProc32A(lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
3585 if (res)
3586 return res;
3588 else
3590 lpcf=(LPCHOOSEFONT32A)lParam;
3591 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
3593 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3594 return FALSE;
3596 if (CFn_HookCallChk32(lpcf))
3597 return CallWindowProc32A(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3599 switch (uMsg)
3601 case WM_MEASUREITEM:
3602 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3603 case WM_DRAWITEM:
3604 return CFn_WMDrawItem(hDlg, wParam, lParam);
3605 case WM_CTLCOLORSTATIC:
3606 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
3607 case WM_COMMAND:
3608 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
3609 case WM_DESTROY:
3610 return CFn_WMDestroy(hDlg, wParam, lParam);
3611 case WM_CHOOSEFONT_GETLOGFONT:
3612 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3613 lParam);
3614 FIXME(commdlg, "current logfont back to caller\n");
3615 break;
3617 return res;
3620 /***********************************************************************
3621 * FormatCharDlgProc32W [internal]
3623 LRESULT WINAPI FormatCharDlgProc32W(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3624 LPARAM lParam)
3626 LPCHOOSEFONT32W lpcf32w;
3627 LPCHOOSEFONT32A lpcf32a;
3628 LRESULT res=FALSE;
3629 if (uMsg!=WM_INITDIALOG)
3631 lpcf32w=(LPCHOOSEFONT32W)GetWindowLong32A(hDlg, DWL_USER);
3632 if (!lpcf32w)
3633 return FALSE;
3634 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3635 res=CallWindowProc32W(lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
3636 if (res)
3637 return res;
3639 else
3641 lpcf32w=(LPCHOOSEFONT32W)lParam;
3642 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3643 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3645 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3646 return FALSE;
3648 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3649 return CallWindowProc32W(lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3651 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3652 switch (uMsg)
3654 case WM_MEASUREITEM:
3655 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3656 case WM_DRAWITEM:
3657 return CFn_WMDrawItem(hDlg, wParam, lParam);
3658 case WM_CTLCOLORSTATIC:
3659 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
3660 case WM_COMMAND:
3661 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
3662 case WM_DESTROY:
3663 return CFn_WMDestroy(hDlg, wParam, lParam);
3664 case WM_CHOOSEFONT_GETLOGFONT:
3665 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3666 lParam);
3667 FIXME(commdlg, "current logfont back to caller\n");
3668 break;
3670 return res;
3674 static BOOL32 Commdlg_GetFileName32A( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
3675 LPOPENFILENAME32A ofn )
3677 BOOL16 ret;
3678 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3680 memset(ofn16,'\0',sizeof(*ofn16));
3681 ofn16->lStructSize = sizeof(*ofn16);
3682 ofn16->hwndOwner = ofn->hwndOwner;
3683 ofn16->hInstance = MapHModuleLS(ofn->hInstance);
3684 if (ofn->lpstrFilter) {
3685 LPSTR s,x;
3687 /* filter is a list... title\0ext\0......\0\0 */
3688 s = (LPSTR)ofn->lpstrFilter;
3689 while (*s)
3690 s = s+strlen(s)+1;
3691 s++;
3692 x = (LPSTR)SEGPTR_ALLOC(s-ofn->lpstrFilter);
3693 memcpy(x,ofn->lpstrFilter,s-ofn->lpstrFilter);
3694 ofn16->lpstrFilter = SEGPTR_GET(x);
3696 if (ofn->lpstrCustomFilter) {
3697 LPSTR s,x;
3699 /* filter is a list... title\0ext\0......\0\0 */
3700 s = (LPSTR)ofn->lpstrCustomFilter;
3701 while (*s)
3702 s = s+strlen(s)+1;
3703 s++;
3704 x = SEGPTR_ALLOC(s-ofn->lpstrCustomFilter);
3705 memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);
3706 ofn16->lpstrCustomFilter = SEGPTR_GET(x);
3708 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3709 ofn16->nFilterIndex = ofn->nFilterIndex;
3710 if (ofn->nMaxFile)
3711 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3712 ofn16->nMaxFile = ofn->nMaxFile;
3713 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3714 if (ofn16->nMaxFileTitle)
3715 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3716 if (ofn->lpstrInitialDir)
3717 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrInitialDir));
3718 if (ofn->lpstrTitle)
3719 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrTitle));
3720 ofn16->Flags = ofn->Flags|OFN_WINE32;
3721 ofn16->nFileOffset = ofn->nFileOffset;
3722 ofn16->nFileExtension = ofn->nFileExtension;
3723 if (ofn->lpstrDefExt)
3724 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrDefExt));
3725 ofn16->lCustData = ofn->lCustData;
3726 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3728 if (ofn->lpTemplateName)
3729 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpTemplateName));
3731 ret = dofunction(SEGPTR_GET(ofn16));
3733 ofn->nFileOffset = ofn16->nFileOffset;
3734 ofn->nFileExtension = ofn16->nFileExtension;
3735 if (ofn16->lpstrFilter)
3736 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3737 if (ofn16->lpTemplateName)
3738 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3739 if (ofn16->lpstrDefExt)
3740 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3741 if (ofn16->lpstrTitle)
3742 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3743 if (ofn16->lpstrInitialDir)
3744 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3745 if (ofn16->lpstrCustomFilter)
3746 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3748 if (ofn16->lpstrFile)
3750 strcpy(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3751 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3754 if (ofn16->lpstrFileTitle)
3756 strcpy(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3757 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3759 SEGPTR_FREE(ofn16);
3760 return ret;
3763 static BOOL32 Commdlg_GetFileName32W( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
3764 LPOPENFILENAME32W ofn )
3766 BOOL16 ret;
3767 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3769 memset(ofn16,'\0',sizeof(*ofn16));
3770 ofn16->lStructSize = sizeof(*ofn16);
3771 ofn16->hwndOwner = ofn->hwndOwner;
3772 ofn16->hInstance = MapHModuleLS(ofn->hInstance);
3773 if (ofn->lpstrFilter) {
3774 LPWSTR s;
3775 LPSTR x,y;
3776 int n;
3778 /* filter is a list... title\0ext\0......\0\0 */
3779 s = (LPWSTR)ofn->lpstrFilter;
3780 while (*s)
3781 s = s+lstrlen32W(s)+1;
3782 s++;
3783 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
3784 x = y = (LPSTR)SEGPTR_ALLOC(n);
3785 s = (LPWSTR)ofn->lpstrFilter;
3786 while (*s) {
3787 lstrcpyWtoA(x,s);
3788 x+=lstrlen32A(x)+1;
3789 s+=lstrlen32W(s)+1;
3791 *x=0;
3792 ofn16->lpstrFilter = SEGPTR_GET(y);
3794 if (ofn->lpstrCustomFilter) {
3795 LPWSTR s;
3796 LPSTR x,y;
3797 int n;
3799 /* filter is a list... title\0ext\0......\0\0 */
3800 s = (LPWSTR)ofn->lpstrCustomFilter;
3801 while (*s)
3802 s = s+lstrlen32W(s)+1;
3803 s++;
3804 n = s - ofn->lpstrCustomFilter;
3805 x = y = (LPSTR)SEGPTR_ALLOC(n);
3806 s = (LPWSTR)ofn->lpstrCustomFilter;
3807 while (*s) {
3808 lstrcpyWtoA(x,s);
3809 x+=lstrlen32A(x)+1;
3810 s+=lstrlen32W(s)+1;
3812 *x=0;
3813 ofn16->lpstrCustomFilter = SEGPTR_GET(y);
3815 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3816 ofn16->nFilterIndex = ofn->nFilterIndex;
3817 if (ofn->nMaxFile)
3818 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3819 ofn16->nMaxFile = ofn->nMaxFile;
3820 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3821 if (ofn->nMaxFileTitle)
3822 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3823 if (ofn->lpstrInitialDir)
3824 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrInitialDir));
3825 if (ofn->lpstrTitle)
3826 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrTitle));
3827 ofn16->Flags = ofn->Flags|OFN_WINE32|OFN_UNICODE;
3828 ofn16->nFileOffset = ofn->nFileOffset;
3829 ofn16->nFileExtension = ofn->nFileExtension;
3830 if (ofn->lpstrDefExt)
3831 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrDefExt));
3832 ofn16->lCustData = ofn->lCustData;
3833 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3834 if (ofn->lpTemplateName)
3835 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpTemplateName));
3836 ret = dofunction(SEGPTR_GET(ofn16));
3838 ofn->nFileOffset = ofn16->nFileOffset;
3839 ofn->nFileExtension = ofn16->nFileExtension;
3840 if (ofn16->lpstrFilter)
3841 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3842 if (ofn16->lpTemplateName)
3843 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3844 if (ofn16->lpstrDefExt)
3845 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3846 if (ofn16->lpstrTitle)
3847 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3848 if (ofn16->lpstrInitialDir)
3849 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3850 if (ofn16->lpstrCustomFilter)
3851 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3853 if (ofn16->lpstrFile) {
3854 lstrcpyAtoW(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3855 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3858 if (ofn16->lpstrFileTitle) {
3859 lstrcpyAtoW(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3860 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3862 SEGPTR_FREE(ofn16);
3863 return ret;
3866 /***********************************************************************
3867 * GetOpenFileName32A (COMDLG32.10)
3869 BOOL32 WINAPI GetOpenFileName32A( LPOPENFILENAME32A ofn )
3871 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3872 return Commdlg_GetFileName32A(dofunction,ofn);
3875 /***********************************************************************
3876 * GetOpenFileName32W (COMDLG32.11)
3878 BOOL32 WINAPI GetOpenFileName32W( LPOPENFILENAME32W ofn )
3880 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3881 return Commdlg_GetFileName32W(dofunction,ofn);
3884 /***********************************************************************
3885 * GetSaveFileName32A (COMDLG32.12)
3887 BOOL32 WINAPI GetSaveFileName32A( LPOPENFILENAME32A ofn )
3889 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3890 return Commdlg_GetFileName32A(dofunction,ofn);
3893 /***********************************************************************
3894 * GetSaveFileName32W (COMDLG32.13)
3896 BOOL32 WINAPI GetSaveFileName32W( LPOPENFILENAME32W ofn )
3898 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3899 return Commdlg_GetFileName32W(dofunction,ofn);
3902 /***********************************************************************
3903 * ChooseColorA (COMDLG32.1)
3905 BOOL32 WINAPI ChooseColor32A(LPCHOOSECOLOR32A lpChCol )
3908 BOOL16 ret;
3909 char *str = NULL;
3910 COLORREF* ccref=SEGPTR_ALLOC(64);
3911 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3913 memset(lpcc16,'\0',sizeof(*lpcc16));
3914 lpcc16->lStructSize=sizeof(*lpcc16);
3915 lpcc16->hwndOwner=lpChCol->hwndOwner;
3916 lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
3917 lpcc16->rgbResult=lpChCol->rgbResult;
3918 memcpy(ccref,lpChCol->lpCustColors,64);
3919 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3920 lpcc16->Flags=lpChCol->Flags;
3921 lpcc16->lCustData=lpChCol->lCustData;
3922 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3923 if (lpChCol->lpTemplateName)
3924 str = SEGPTR_STRDUP(lpChCol->lpTemplateName );
3925 lpcc16->lpTemplateName=SEGPTR_GET(str);
3927 ret = ChooseColor16(lpcc16);
3928 if(str)
3929 SEGPTR_FREE(str);
3930 memcpy(lpChCol->lpCustColors,ccref,64);
3931 SEGPTR_FREE(ccref);
3932 SEGPTR_FREE(lpcc16);
3933 return (BOOL32)ret;
3936 /***********************************************************************
3937 * ChooseColorW (COMDLG32.2)
3939 BOOL32 WINAPI ChooseColor32W(LPCHOOSECOLOR32W lpChCol )
3942 BOOL16 ret;
3943 char *str = NULL;
3944 COLORREF* ccref=SEGPTR_ALLOC(64);
3945 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3947 memset(lpcc16,'\0',sizeof(*lpcc16));
3948 lpcc16->lStructSize=sizeof(*lpcc16);
3949 lpcc16->hwndOwner=lpChCol->hwndOwner;
3950 lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
3951 lpcc16->rgbResult=lpChCol->rgbResult;
3952 memcpy(ccref,lpChCol->lpCustColors,64);
3953 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3954 lpcc16->Flags=lpChCol->Flags;
3955 lpcc16->lCustData=lpChCol->lCustData;
3956 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3957 if (lpChCol->lpTemplateName)
3958 str = SEGPTR_STRDUP_WtoA(lpChCol->lpTemplateName );
3959 lpcc16->lpTemplateName=SEGPTR_GET(str);
3961 ret = ChooseColor16(lpcc16);
3962 if(str)
3963 SEGPTR_FREE(str);
3964 memcpy(lpChCol->lpCustColors,ccref,64);
3965 SEGPTR_FREE(ccref);
3966 SEGPTR_FREE(lpcc16);
3967 return (BOOL32)ret;
3970 /***********************************************************************
3971 * PageSetupDlgA (COMDLG32.15)
3973 BOOL32 WINAPI PageSetupDlg32A(LPPAGESETUPDLG32A setupdlg) {
3974 FIXME(commdlg,"(%p), stub!\n",setupdlg);
3975 return FALSE;