Optimized include/*.h: (recursively) include all headers needed by
[wine/testsucceed.git] / misc / commdlg.c
blob41f589ece83ad109389e69f6bc089d6173610125
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 "wine/winbase16.h"
12 #include "win.h"
13 #include "heap.h"
14 #include "message.h"
15 #include "commdlg.h"
16 #include "resource.h"
17 #include "dialog.h"
18 #include "dlgs.h"
19 #include "module.h"
20 #include "drive.h"
21 #include "debug.h"
22 #include "font.h"
23 #include "winproc.h"
25 static DWORD CommDlgLastError = 0;
27 static HBITMAP16 hFolder = 0;
28 static HBITMAP16 hFolder2 = 0;
29 static HBITMAP16 hFloppy = 0;
30 static HBITMAP16 hHDisk = 0;
31 static HBITMAP16 hCDRom = 0;
32 static HBITMAP16 hBitmapTT = 0;
33 static const char defaultfilter[]=" \0\0";
35 /***********************************************************************
36 * FileDlg_Init [internal]
38 static BOOL32 FileDlg_Init(void)
40 static BOOL32 initialized = 0;
42 if (!initialized) {
43 if (!hFolder) hFolder = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER));
44 if (!hFolder2) hFolder2 = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER2));
45 if (!hFloppy) hFloppy = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FLOPPY));
46 if (!hHDisk) hHDisk = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_HDISK));
47 if (!hCDRom) hCDRom = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CDROM));
48 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
49 hHDisk == 0 || hCDRom == 0)
51 WARN(commdlg, "Error loading bitmaps !\nprin");
52 return FALSE;
54 initialized = TRUE;
56 return TRUE;
59 /***********************************************************************
60 * GetOpenFileName (COMMDLG.1)
62 BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
64 HINSTANCE32 hInst;
65 HANDLE32 hDlgTmpl = 0, hResInfo;
66 BOOL32 bRet = FALSE, win32Format = FALSE;
67 HWND32 hwndDialog;
68 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
69 LPCVOID template;
70 char defaultopen[]="Open File";
71 char *str=0,*str1=0;
73 if (!lpofn || !FileDlg_Init()) return FALSE;
75 if (lpofn->Flags & OFN_WINE32) {
76 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
78 if (!(template = LockResource32( MapHModuleSL(lpofn->hInstance ))))
80 CommDlgLastError = CDERR_LOADRESFAILURE;
81 return FALSE;
84 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
86 if (!(hResInfo = FindResource32A(MapHModuleSL(lpofn->hInstance),
87 PTR_SEG_TO_LIN(lpofn->lpTemplateName), RT_DIALOG32A)))
89 CommDlgLastError = CDERR_FINDRESFAILURE;
90 return FALSE;
92 if (!(hDlgTmpl = LoadResource32( MapHModuleSL(lpofn->hInstance),
93 hResInfo )) ||
94 !(template = LockResource32( hDlgTmpl )))
96 CommDlgLastError = CDERR_LOADRESFAILURE;
97 return FALSE;
99 } else {
100 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
102 win32Format = TRUE;
103 } else {
104 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
106 if (!(template = LockResource16( lpofn->hInstance )))
108 CommDlgLastError = CDERR_LOADRESFAILURE;
109 return FALSE;
112 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
114 if (!(hResInfo = FindResource16(lpofn->hInstance,
115 lpofn->lpTemplateName,
116 RT_DIALOG16)))
118 CommDlgLastError = CDERR_FINDRESFAILURE;
119 return FALSE;
121 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
122 !(template = LockResource16( hDlgTmpl )))
124 CommDlgLastError = CDERR_LOADRESFAILURE;
125 return FALSE;
127 } else {
128 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
129 win32Format = TRUE;
133 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
135 if (!(lpofn->lpstrFilter))
137 str = SEGPTR_ALLOC(sizeof(defaultfilter));
138 TRACE(commdlg,"Alloc %p default for Filetype in GetOpenFileName\n",str);
139 memcpy(str,defaultfilter,sizeof(defaultfilter));
140 lpofn->lpstrFilter=SEGPTR_GET(str);
143 if (!(lpofn->lpstrTitle))
145 str1 = SEGPTR_ALLOC(strlen(defaultopen)+1);
146 TRACE(commdlg,"Alloc %p default for Title in GetOpenFileName\n",str1);
147 strcpy(str1,defaultopen);
148 lpofn->lpstrTitle=SEGPTR_GET(str1);
151 /* FIXME: doesn't handle win32 format correctly yet */
152 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
153 lpofn->hwndOwner,
154 (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
155 ofn, WIN_PROC_16 );
156 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
158 if (str1)
160 TRACE(commdlg,"Freeing %p default for Title in GetOpenFileName\n",str1);
161 SEGPTR_FREE(str1);
162 lpofn->lpstrTitle=0;
165 if (str)
167 TRACE(commdlg,"Freeing %p default for Filetype in GetOpenFileName\n",str);
168 SEGPTR_FREE(str);
169 lpofn->lpstrFilter=0;
172 if (hDlgTmpl) {
173 if (lpofn->Flags & OFN_WINE32)
174 FreeResource32( hDlgTmpl );
175 else
176 FreeResource16( hDlgTmpl );
179 TRACE(commdlg,"return lpstrFile='%s' !\n",
180 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
181 return bRet;
185 /***********************************************************************
186 * GetSaveFileName (COMMDLG.2)
188 BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
190 HINSTANCE32 hInst;
191 HANDLE32 hDlgTmpl = 0;
192 BOOL32 bRet = FALSE, win32Format = FALSE;
193 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
194 LPCVOID template;
195 HWND32 hwndDialog;
196 char defaultsave[]="Save as";
197 char *str =0,*str1=0;
199 if (!lpofn || !FileDlg_Init()) return FALSE;
201 if (lpofn->Flags & OFN_WINE32) {
202 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
204 if (!(template = LockResource32( MapHModuleSL(lpofn->hInstance ))))
206 CommDlgLastError = CDERR_LOADRESFAILURE;
207 return FALSE;
210 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
212 HANDLE32 hResInfo;
213 if (!(hResInfo = FindResource32A(MapHModuleSL(lpofn->hInstance),
214 PTR_SEG_TO_LIN(lpofn->lpTemplateName),
215 RT_DIALOG32A)))
217 CommDlgLastError = CDERR_FINDRESFAILURE;
218 return FALSE;
220 if (!(hDlgTmpl = LoadResource32(MapHModuleSL(lpofn->hInstance),
221 hResInfo)) ||
222 !(template = LockResource32(hDlgTmpl)))
224 CommDlgLastError = CDERR_LOADRESFAILURE;
225 return FALSE;
227 win32Format= TRUE;
228 } else {
229 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
230 win32Format = TRUE;
232 } else {
233 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
235 if (!(template = LockResource16( lpofn->hInstance )))
237 CommDlgLastError = CDERR_LOADRESFAILURE;
238 return FALSE;
241 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
243 HANDLE16 hResInfo;
244 if (!(hResInfo = FindResource16(lpofn->hInstance,
245 lpofn->lpTemplateName,
246 RT_DIALOG16)))
248 CommDlgLastError = CDERR_FINDRESFAILURE;
249 return FALSE;
251 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
252 !(template = LockResource16( hDlgTmpl )))
254 CommDlgLastError = CDERR_LOADRESFAILURE;
255 return FALSE;
257 } else {
258 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
259 win32Format = TRUE;
263 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
265 if (!(lpofn->lpstrFilter))
267 str = SEGPTR_ALLOC(sizeof(defaultfilter));
268 TRACE(commdlg,"Alloc default for Filetype in GetSaveFileName\n");
269 memcpy(str,defaultfilter,sizeof(defaultfilter));
270 lpofn->lpstrFilter=SEGPTR_GET(str);
273 if (!(lpofn->lpstrTitle))
275 str1 = SEGPTR_ALLOC(sizeof(defaultsave)+1);
276 TRACE(commdlg,"Alloc default for Title in GetSaveFileName\n");
277 strcpy(str1,defaultsave);
278 lpofn->lpstrTitle=SEGPTR_GET(str1);
281 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
282 lpofn->hwndOwner,
283 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
284 ofn, WIN_PROC_16 );
285 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
287 if (str1)
289 TRACE(commdlg,"Freeing %p default for Title in GetSaveFileName\n",str1);
290 SEGPTR_FREE(str1);
291 lpofn->lpstrTitle=0;
294 if (str)
296 TRACE(commdlg,"Freeing %p default for Filetype in GetSaveFileName\n",str);
297 SEGPTR_FREE(str);
298 lpofn->lpstrFilter=0;
301 if (hDlgTmpl) {
302 if (lpofn->Flags & OFN_WINE32)
303 FreeResource32( hDlgTmpl );
304 else
305 FreeResource16( hDlgTmpl );
308 TRACE(commdlg, "return lpstrFile='%s' !\n",
309 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
310 return bRet;
313 /***********************************************************************
314 * FILEDLG_StripEditControl [internal]
315 * Strip pathnames off the contents of the edit control.
317 static void FILEDLG_StripEditControl(HWND16 hwnd)
319 char temp[512], *cp;
321 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
322 cp = strrchr(temp, '\\');
323 if (cp != NULL) {
324 strcpy(temp, cp+1);
326 cp = strrchr(temp, ':');
327 if (cp != NULL) {
328 strcpy(temp, cp+1);
330 /* FIXME: shouldn't we do something with the result here? ;-) */
333 /***********************************************************************
334 * FILEDLG_ScanDir [internal]
336 static BOOL32 FILEDLG_ScanDir(HWND16 hWnd, LPSTR newPath)
338 char buffer[512];
339 char* str = buffer;
340 int drive;
341 HWND32 hlb;
343 lstrcpyn32A(buffer, newPath, sizeof(buffer));
345 if (str[0] && (str[1] == ':')) {
346 drive = toupper(str[0]) - 'A';
347 str += 2;
348 if (!DRIVE_SetCurrentDrive(drive))
349 return FALSE;
350 } else {
351 drive = DRIVE_GetCurrentDrive();
354 if (str[0] && !DRIVE_Chdir(drive, str)) {
355 return FALSE;
358 GetDlgItemText32A(hWnd, edt1, buffer, sizeof(buffer));
359 if ((hlb = GetDlgItem32(hWnd, lst1)) != 0) {
360 char* scptr; /* ptr on semi-colon */
361 char* filter = buffer;
363 TRACE(commdlg, "Using filter %s\n", filter);
364 SendMessage32A(hlb, LB_RESETCONTENT32, 0, 0);
365 while (filter) {
366 scptr = strchr(filter, ';');
367 if (scptr) *scptr = 0;
368 TRACE(commdlg, "Using file spec %s\n", filter);
369 if (SendMessage32A(hlb, LB_DIR32, 0, (LPARAM)filter) == LB_ERR)
370 return FALSE;
371 if (scptr) *scptr = ';';
372 filter = (scptr) ? (scptr + 1) : 0;
376 strcpy(buffer, "*.*");
377 return DlgDirList32A(hWnd, buffer, lst2, stc1, 0x8010);
380 /***********************************************************************
381 * FILEDLG_GetFileType [internal]
384 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
386 int n, i;
387 i = 0;
388 if (cfptr)
389 for ( ;(n = strlen(cfptr)) != 0; i++)
391 cfptr += n + 1;
392 if (i == index)
393 return cfptr;
394 cfptr += strlen(cfptr) + 1;
396 if (fptr)
397 for ( ;(n = strlen(fptr)) != 0; i++)
399 fptr += n + 1;
400 if (i == index)
401 return fptr;
402 fptr += strlen(fptr) + 1;
404 return "*.*"; /* FIXME */
407 /***********************************************************************
408 * FILEDLG_WMDrawItem [internal]
410 static LONG FILEDLG_WMDrawItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam,int savedlg)
412 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
413 char *str;
414 HBRUSH32 hBrush;
415 HBITMAP16 hBitmap, hPrevBitmap;
416 BITMAP16 bm;
417 HDC32 hMemDC;
419 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
421 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
422 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
423 SelectObject32(lpdis->hDC, hBrush);
424 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
425 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
426 (LPARAM)SEGPTR_GET(str));
428 if (savedlg) /* use _gray_ text in FileSaveDlg */
430 if (!lpdis->itemState)
431 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_GRAYTEXT) );
432 else
433 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_WINDOWTEXT) );
434 /* inversion of gray would be bad readable */
437 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
438 str, strlen(str));
439 if (lpdis->itemState != 0) {
440 InvertRect16(lpdis->hDC, &lpdis->rcItem);
442 SEGPTR_FREE(str);
443 return TRUE;
446 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
448 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
449 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
450 SelectObject32(lpdis->hDC, hBrush);
451 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
452 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
453 (LPARAM)SEGPTR_GET(str));
455 hBitmap = hFolder;
456 GetObject16( hBitmap, sizeof(bm), &bm );
457 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
458 lpdis->rcItem.top, str, strlen(str));
459 hMemDC = CreateCompatibleDC32(lpdis->hDC);
460 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
461 BitBlt32(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
462 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
463 SelectObject32(hMemDC, hPrevBitmap);
464 DeleteDC32(hMemDC);
465 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
466 SEGPTR_FREE(str);
467 return TRUE;
469 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
471 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
472 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
473 SelectObject32(lpdis->hDC, hBrush);
474 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
475 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT16, lpdis->itemID,
476 (LPARAM)SEGPTR_GET(str));
477 switch(DRIVE_GetType( str[2] - 'a' ))
479 case TYPE_FLOPPY: hBitmap = hFloppy; break;
480 case TYPE_CDROM: hBitmap = hCDRom; break;
481 case TYPE_HD:
482 case TYPE_NETWORK:
483 default: hBitmap = hHDisk; break;
485 GetObject16( hBitmap, sizeof(bm), &bm );
486 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
487 lpdis->rcItem.top, str, strlen(str));
488 hMemDC = CreateCompatibleDC32(lpdis->hDC);
489 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
490 BitBlt32( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
491 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
492 SelectObject32(hMemDC, hPrevBitmap);
493 DeleteDC32(hMemDC);
494 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
495 SEGPTR_FREE(str);
496 return TRUE;
498 return FALSE;
501 /***********************************************************************
502 * FILEDLG_WMMeasureItem [internal]
504 static LONG FILEDLG_WMMeasureItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
506 BITMAP16 bm;
507 LPMEASUREITEMSTRUCT16 lpmeasure;
509 GetObject16( hFolder2, sizeof(bm), &bm );
510 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
511 lpmeasure->itemHeight = bm.bmHeight;
512 return TRUE;
515 /***********************************************************************
516 * FILEDLG_HookCallChk [internal]
518 static int FILEDLG_HookCallChk(LPOPENFILENAME16 lpofn)
520 if (lpofn)
521 if (lpofn->Flags & OFN_ENABLEHOOK)
522 if (lpofn->lpfnHook)
523 return 1;
524 return 0;
527 /***********************************************************************
528 * FILEDLG_CallWindowProc [internal]
530 * Adapt the structures back for win32 calls so the callee can read lpCustData
532 static BOOL32 FILEDLG_CallWindowProc(LPOPENFILENAME16 lpofn,HWND32 hwnd,
533 UINT32 wMsg,WPARAM32 wParam,LPARAM lParam
536 BOOL32 needstruct;
537 BOOL32 result = FALSE;
538 WINDOWPROCTYPE ProcType; /* Type of Hook Function to be called. */
540 /* TRUE if lParam points to the OPENFILENAME16 Structure */
541 needstruct = (PTR_SEG_TO_LIN(lParam) == lpofn);
543 ProcType = (lpofn->Flags & OFN_WINE32)
544 ? (lpofn->Flags & OFN_UNICODE) /* 32-Bit call to GetOpenFileName */
545 ? WIN_PROC_32W : WIN_PROC_32A
546 : WIN_PROC_16; /* 16-Bit call to GetOpenFileName */
548 if (!(lpofn->Flags & OFN_WINE32))
549 /* Call to 16-Bit Hooking function... No Problem at all. */
550 return (BOOL32)CallWindowProc16(
551 lpofn->lpfnHook,hwnd,(UINT16)wMsg,(WPARAM16)wParam,lParam
553 /* |OFN_WINE32 */
554 if (needstruct)
556 /* Parameter lParam points to lpofn... Convert Structure Data... */
557 if (lpofn->Flags & OFN_UNICODE)
559 OPENFILENAME32W ofnw;
561 /* FIXME: probably needs more converted */
562 ofnw.lCustData = lpofn->lCustData;
563 return (BOOL32)CallWindowProc32W(
564 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofnw
567 else /* ! |OFN_UNICODE */
569 OPENFILENAME32A ofna;
571 /* FIXME: probably needs more converted */
572 ofna.lCustData = lpofn->lCustData;
573 return (BOOL32)CallWindowProc32A(
574 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofna
578 else /* ! needstruct */
580 HWINDOWPROC hWindowProc=NULL;
582 if (WINPROC_SetProc(&hWindowProc, lpofn->lpfnHook, ProcType, WIN_PROC_WINDOW))
584 /* Call Window Procedure converting 16-Bit Type Parameters to 32-Bit Type Parameters */
585 result = CallWindowProc16( (WNDPROC16)hWindowProc,
586 hwnd, wMsg, wParam, lParam );
588 result = LOWORD(result);
590 WINPROC_FreeProc( hWindowProc, WIN_PROC_WINDOW );
593 return result;
599 /***********************************************************************
600 * FILEDLG_WMInitDialog [internal]
603 static LONG FILEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
605 int i, n;
606 LPOPENFILENAME16 lpofn;
607 char tmpstr[512];
608 LPSTR pstr, old_pstr;
609 SetWindowLong32A(hWnd, DWL_USER, lParam);
610 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(lParam);
611 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
612 /* read custom filter information */
613 if (lpofn->lpstrCustomFilter)
615 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
616 n = 0;
617 TRACE(commdlg,"lpstrCustomFilter = %p\n", pstr);
618 while(*pstr)
620 old_pstr = pstr;
621 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
622 (LPARAM)lpofn->lpstrCustomFilter + n );
623 n += strlen(pstr) + 1;
624 pstr += strlen(pstr) + 1;
625 TRACE(commdlg,"add str='%s' "
626 "associated to '%s'\n", old_pstr, pstr);
627 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
628 n += strlen(pstr) + 1;
629 pstr += strlen(pstr) + 1;
632 /* read filter information */
633 if (lpofn->lpstrFilter) {
634 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
635 n = 0;
636 while(*pstr) {
637 old_pstr = pstr;
638 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
639 (LPARAM)lpofn->lpstrFilter + n );
640 n += strlen(pstr) + 1;
641 pstr += strlen(pstr) + 1;
642 TRACE(commdlg,"add str='%s' "
643 "associated to '%s'\n", old_pstr, pstr);
644 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
645 n += strlen(pstr) + 1;
646 pstr += strlen(pstr) + 1;
649 /* set default filter */
650 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
651 lpofn->nFilterIndex = 1;
652 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL16, lpofn->nFilterIndex - 1, 0);
653 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
654 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
655 tmpstr[511]=0;
656 TRACE(commdlg,"nFilterIndex = %ld, SetText of edt1 to '%s'\n",
657 lpofn->nFilterIndex, tmpstr);
658 SetDlgItemText32A( hWnd, edt1, tmpstr );
659 /* get drive list */
660 *tmpstr = 0;
661 DlgDirListComboBox32A(hWnd, tmpstr, cmb2, 0, 0xC000);
662 /* read initial directory */
663 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
665 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
666 tmpstr[510]=0;
667 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
668 && tmpstr[strlen(tmpstr)-1] != ':')
669 strcat(tmpstr,"\\");
671 else
672 *tmpstr = 0;
673 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
674 *tmpstr = 0;
675 if (!FILEDLG_ScanDir(hWnd, tmpstr))
676 WARN(commdlg, "Couldn't read initial directory %s!\n",tmpstr);
678 /* select current drive in combo 2, omit missing drives */
679 for(i=0, n=-1; i<=DRIVE_GetCurrentDrive(); i++)
680 if (DRIVE_IsValid(i)) n++;
681 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL16, n, 0);
682 if (!(lpofn->Flags & OFN_SHOWHELP))
683 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
684 if (lpofn->Flags & OFN_HIDEREADONLY)
685 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
686 if (FILEDLG_HookCallChk(lpofn))
687 return (BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,WM_INITDIALOG,wParam,lParam );
688 else
689 return TRUE;
692 /***********************************************************************
693 * FILEDLG_WMCommand [internal]
695 BOOL32 in_update=FALSE;
697 static LRESULT FILEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
699 LONG lRet;
700 LPOPENFILENAME16 lpofn;
701 OPENFILENAME16 ofn2;
702 char tmpstr[512], tmpstr2[512];
703 LPSTR pstr, pstr2;
704 UINT16 control,notification;
706 /* Notifications are packaged differently in Win32 */
707 control = wParam;
708 notification = HIWORD(lParam);
710 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
711 switch (control)
713 case lst1: /* file list */
714 FILEDLG_StripEditControl(hWnd);
715 if (notification == LBN_DBLCLK)
716 goto almost_ok;
717 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
718 if (lRet == LB_ERR) return TRUE;
719 if ((pstr = SEGPTR_ALLOC(512)))
721 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
722 (LPARAM)SEGPTR_GET(pstr));
723 SetDlgItemText32A( hWnd, edt1, pstr );
724 SEGPTR_FREE(pstr);
726 if (FILEDLG_HookCallChk(lpofn))
727 FILEDLG_CallWindowProc(lpofn,hWnd,
728 RegisterWindowMessage32A( LBSELCHSTRING ),
729 control, MAKELONG(lRet,CD_LBSELCHANGE));
730 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
731 return TRUE;
732 case lst2: /* directory list */
733 FILEDLG_StripEditControl(hWnd);
734 if (notification == LBN_DBLCLK)
736 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
737 if (lRet == LB_ERR) return TRUE;
738 pstr = SEGPTR_ALLOC(512);
739 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
740 (LPARAM)SEGPTR_GET(pstr));
741 strcpy( tmpstr, pstr );
742 SEGPTR_FREE(pstr);
743 if (tmpstr[0] == '[')
745 tmpstr[strlen(tmpstr) - 1] = 0;
746 strcpy(tmpstr,tmpstr+1);
748 strcat(tmpstr, "\\");
749 goto reset_scan;
751 return TRUE;
752 case cmb1: /* file type drop list */
753 if (notification == CBN_SELCHANGE)
755 *tmpstr = 0;
756 goto reset_scan;
758 return TRUE;
759 case chx1:
760 return TRUE;
761 case pshHelp:
762 return TRUE;
763 case cmb2: /* disk drop list */
764 FILEDLG_StripEditControl(hWnd);
765 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL16, 0, 0L);
766 if (lRet == LB_ERR) return 0;
767 pstr = SEGPTR_ALLOC(512);
768 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT16, lRet,
769 (LPARAM)SEGPTR_GET(pstr));
770 sprintf(tmpstr, "%c:", pstr[2]);
771 SEGPTR_FREE(pstr);
772 reset_scan:
773 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
774 if (lRet == LB_ERR)
775 return TRUE;
776 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA16, lRet, 0);
777 TRACE(commdlg,"Selected filter : %s\n", pstr);
778 SetDlgItemText32A( hWnd, edt1, pstr );
779 FILEDLG_ScanDir(hWnd, tmpstr);
780 in_update=TRUE;
781 case IDOK:
782 almost_ok:
783 ofn2=*lpofn; /* for later restoring */
784 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
785 pstr = strrchr(tmpstr, '\\');
786 if (pstr == NULL)
787 pstr = strrchr(tmpstr, ':');
788 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
790 /* edit control contains wildcards */
791 if (pstr != NULL)
793 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
794 *(pstr+1) = 0;
796 else
798 strcpy(tmpstr2, tmpstr);
799 *tmpstr=0;
801 TRACE(commdlg,"tmpstr=%s, tmpstr2=%s\n", tmpstr, tmpstr2);
802 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
803 FILEDLG_ScanDir(hWnd, tmpstr);
804 return TRUE;
806 /* no wildcards, we might have a directory or a filename */
807 /* try appending a wildcard and reading the directory */
808 pstr2 = tmpstr + strlen(tmpstr);
809 if (pstr == NULL || *(pstr+1) != 0)
810 strcat(tmpstr, "\\");
811 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
812 if (lRet == LB_ERR) return TRUE;
813 lpofn->nFilterIndex = lRet + 1;
814 TRACE(commdlg,"lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
815 lstrcpyn32A(tmpstr2,
816 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
817 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
818 lRet), sizeof(tmpstr2));
819 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
820 if (!in_update)
821 /* if ScanDir succeeds, we have changed the directory */
822 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
823 /* if not, this must be a filename */
824 *pstr2 = 0;
825 if (pstr != NULL)
827 /* strip off the pathname */
828 *pstr = 0;
829 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
830 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
831 /* Should we MessageBox() if this fails? */
832 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
833 strcpy(tmpstr, tmpstr2);
835 else SetDlgItemText32A( hWnd, edt1, tmpstr );
836 #if 0
837 ShowWindow16(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
838 #endif
840 int drive = DRIVE_GetCurrentDrive();
841 tmpstr2[0] = 'A'+ drive;
842 tmpstr2[1] = ':';
843 tmpstr2[2] = '\\';
844 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
845 if (strlen(tmpstr2) > 3)
846 strcat(tmpstr2, "\\");
847 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
848 if (lpofn->lpstrFile)
849 lstrcpyn32A(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2,lpofn->nMaxFile);
851 lpofn->nFileOffset = strrchr(tmpstr2,'\\') - tmpstr2 +1;
852 lpofn->nFileExtension = 0;
853 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
854 lpofn->nFileExtension++;
855 if (tmpstr2[lpofn->nFileExtension] == '\0')
856 lpofn->nFileExtension = 0;
857 else
858 lpofn->nFileExtension++;
860 if(in_update)
862 if (FILEDLG_HookCallChk(lpofn))
863 FILEDLG_CallWindowProc(lpofn,hWnd,
864 RegisterWindowMessage32A( LBSELCHSTRING ),
865 control, MAKELONG(lRet,CD_LBSELCHANGE));
867 in_update = FALSE;
868 return TRUE;
870 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
872 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
873 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
874 lpofn->lpstrFileTitle );
876 if (FILEDLG_HookCallChk(lpofn))
878 lRet= (BOOL16)FILEDLG_CallWindowProc(lpofn,
879 hWnd, RegisterWindowMessage32A( FILEOKSTRING ), 0, lParam );
880 if (lRet)
882 *lpofn=ofn2; /* restore old state */
883 #if 0
884 ShowWindow16(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
885 #endif
886 break;
889 EndDialog32(hWnd, TRUE);
890 return TRUE;
891 case IDCANCEL:
892 EndDialog32(hWnd, FALSE);
893 return TRUE;
895 return FALSE;
899 /***********************************************************************
900 * FileOpenDlgProc (COMMDLG.6)
902 LRESULT WINAPI FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
903 LPARAM lParam)
905 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
907 if (wMsg!=WM_INITDIALOG)
908 if (FILEDLG_HookCallChk(lpofn))
910 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
911 if (lRet)
912 return lRet; /* else continue message processing */
914 switch (wMsg)
916 case WM_INITDIALOG:
917 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
918 case WM_MEASUREITEM:
919 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
920 case WM_DRAWITEM:
921 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
922 case WM_COMMAND:
923 return FILEDLG_WMCommand(hWnd, wParam, lParam);
924 #if 0
925 case WM_CTLCOLOR:
926 SetBkColor((HDC16)wParam, 0x00C0C0C0);
927 switch (HIWORD(lParam))
929 case CTLCOLOR_BTN:
930 SetTextColor((HDC16)wParam, 0x00000000);
931 return hGRAYBrush;
932 case CTLCOLOR_STATIC:
933 SetTextColor((HDC16)wParam, 0x00000000);
934 return hGRAYBrush;
936 break;
937 #endif
939 return FALSE;
943 /***********************************************************************
944 * FileSaveDlgProc (COMMDLG.7)
946 LRESULT WINAPI FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
947 LPARAM lParam)
949 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
951 if (wMsg!=WM_INITDIALOG)
952 if (FILEDLG_HookCallChk(lpofn))
954 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
955 if (lRet)
956 return lRet; /* else continue message processing */
958 switch (wMsg) {
959 case WM_INITDIALOG:
960 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
962 case WM_MEASUREITEM:
963 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
965 case WM_DRAWITEM:
966 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
968 case WM_COMMAND:
969 return FILEDLG_WMCommand(hWnd, wParam, lParam);
973 case WM_CTLCOLOR:
974 SetBkColor((HDC16)wParam, 0x00C0C0C0);
975 switch (HIWORD(lParam))
977 case CTLCOLOR_BTN:
978 SetTextColor((HDC16)wParam, 0x00000000);
979 return hGRAYBrush;
980 case CTLCOLOR_STATIC:
981 SetTextColor((HDC16)wParam, 0x00000000);
982 return hGRAYBrush;
984 return FALSE;
987 return FALSE;
991 /***********************************************************************
992 * FindText16 (COMMDLG.11)
994 HWND16 WINAPI FindText16( SEGPTR find )
996 HANDLE16 hInst;
997 LPCVOID ptr;
998 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
1001 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1002 * For now, only the standard dialog works.
1004 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1005 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1006 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
1007 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1008 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1009 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
1010 find, WIN_PROC_16 );
1013 /***********************************************************************
1014 * FindText32A (COMMDLG.6)
1016 HWND32 WINAPI FindText32A( LPFINDREPLACE32A lpFind )
1018 HANDLE16 hInst;
1019 LPCVOID ptr;
1022 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1023 * For now, only the standard dialog works.
1025 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1026 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1027 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
1028 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1029 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1030 (DLGPROC16)FindTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
1033 /***********************************************************************
1034 * FindText32W (COMMDLG.7)
1036 HWND32 WINAPI FindText32W( LPFINDREPLACE32W lpFind )
1038 HANDLE16 hInst;
1039 LPCVOID ptr;
1042 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1043 * For now, only the standard dialog works.
1045 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1046 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1047 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
1048 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1049 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1050 (DLGPROC16)FindTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
1053 /***********************************************************************
1054 * ReplaceText16 (COMMDLG.12)
1056 HWND16 WINAPI ReplaceText16( SEGPTR find )
1058 HANDLE16 hInst;
1059 LPCVOID ptr;
1060 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
1063 * FIXME : We should do error checking on the lpFind structure here
1064 * and make CommDlgExtendedError() return the error condition.
1066 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1067 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1068 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1069 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1070 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1071 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
1072 find, WIN_PROC_16 );
1075 /***********************************************************************
1076 * ReplaceText32A (COMDLG32.19)
1078 HWND32 WINAPI ReplaceText32A( LPFINDREPLACE32A lpFind )
1080 HANDLE16 hInst;
1081 LPCVOID ptr;
1084 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1085 * For now, only the standard dialog works.
1087 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1088 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1089 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1090 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1091 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1092 (DLGPROC16)ReplaceTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
1095 /***********************************************************************
1096 * ReplaceText32W (COMDLG32.20)
1098 HWND32 WINAPI ReplaceText32W( LPFINDREPLACE32W lpFind )
1100 HANDLE16 hInst;
1101 LPCVOID ptr;
1104 * FIXME : We should do error checking on the lpFind structure here
1105 * and make CommDlgExtendedError() return the error condition.
1107 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1108 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1109 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1110 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1111 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1112 (DLGPROC16)ReplaceTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
1116 /***********************************************************************
1117 * FINDDLG_WMInitDialog [internal]
1119 static LRESULT FINDDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam, LPDWORD lpFlags,
1120 LPSTR lpstrFindWhat, BOOL32 fUnicode)
1122 SetWindowLong32A(hWnd, DWL_USER, lParam);
1123 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1125 * FIXME : If the initial FindWhat string is empty, we should disable the
1126 * FindNext (IDOK) button. Only after typing some text, the button should be
1127 * enabled.
1129 if (fUnicode) SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1130 else SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1131 CheckRadioButton32(hWnd, rad1, rad2, (*lpFlags & FR_DOWN) ? rad2 : rad1);
1132 if (*lpFlags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
1133 EnableWindow32(GetDlgItem32(hWnd, rad1), FALSE);
1134 EnableWindow32(GetDlgItem32(hWnd, rad2), FALSE);
1136 if (*lpFlags & FR_HIDEUPDOWN) {
1137 ShowWindow32(GetDlgItem32(hWnd, rad1), SW_HIDE);
1138 ShowWindow32(GetDlgItem32(hWnd, rad2), SW_HIDE);
1139 ShowWindow32(GetDlgItem32(hWnd, grp1), SW_HIDE);
1141 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1142 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1143 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1144 if (*lpFlags & FR_HIDEWHOLEWORD)
1145 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1146 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1147 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1148 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1149 if (*lpFlags & FR_HIDEMATCHCASE)
1150 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1151 if (!(*lpFlags & FR_SHOWHELP)) {
1152 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1153 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1155 ShowWindow32(hWnd, SW_SHOWNORMAL);
1156 return TRUE;
1160 /***********************************************************************
1161 * FINDDLG_WMCommand [internal]
1163 static LRESULT FINDDLG_WMCommand(HWND32 hWnd, WPARAM32 wParam,
1164 HWND32 hwndOwner, LPDWORD lpFlags,
1165 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1166 BOOL32 fUnicode)
1168 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1169 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1171 switch (wParam) {
1172 case IDOK:
1173 if (fUnicode)
1174 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1175 else GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1176 if (IsDlgButtonChecked32(hWnd, rad2))
1177 *lpFlags |= FR_DOWN;
1178 else *lpFlags &= ~FR_DOWN;
1179 if (IsDlgButtonChecked32(hWnd, chx1))
1180 *lpFlags |= FR_WHOLEWORD;
1181 else *lpFlags &= ~FR_WHOLEWORD;
1182 if (IsDlgButtonChecked32(hWnd, chx2))
1183 *lpFlags |= FR_MATCHCASE;
1184 else *lpFlags &= ~FR_MATCHCASE;
1185 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1186 *lpFlags |= FR_FINDNEXT;
1187 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1188 GetWindowLong32A(hWnd, DWL_USER) );
1189 return TRUE;
1190 case IDCANCEL:
1191 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1192 *lpFlags |= FR_DIALOGTERM;
1193 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1194 GetWindowLong32A(hWnd, DWL_USER) );
1195 DestroyWindow32(hWnd);
1196 return TRUE;
1197 case pshHelp:
1198 /* FIXME : should lpfr structure be passed as an argument ??? */
1199 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1200 return TRUE;
1202 return FALSE;
1206 /***********************************************************************
1207 * FindTextDlgProc16 (COMMDLG.13)
1209 LRESULT WINAPI FindTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1210 LPARAM lParam)
1212 LPFINDREPLACE16 lpfr;
1213 switch (wMsg) {
1214 case WM_INITDIALOG:
1215 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1216 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1217 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat), FALSE);
1218 case WM_COMMAND:
1219 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1220 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1221 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1222 lpfr->wFindWhatLen, FALSE);
1224 return FALSE;
1227 /***********************************************************************
1228 * FindTextDlgProc32A
1230 LRESULT WINAPI FindTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1231 LPARAM lParam)
1233 LPFINDREPLACE32A lpfr;
1234 switch (wMsg) {
1235 case WM_INITDIALOG:
1236 lpfr=(LPFINDREPLACE32A)lParam;
1237 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1238 lpfr->lpstrFindWhat, FALSE);
1239 case WM_COMMAND:
1240 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1241 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1242 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1243 FALSE);
1245 return FALSE;
1248 /***********************************************************************
1249 * FindTextDlgProc32W
1251 LRESULT WINAPI FindTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1252 LPARAM lParam)
1254 LPFINDREPLACE32W lpfr;
1255 switch (wMsg) {
1256 case WM_INITDIALOG:
1257 lpfr=(LPFINDREPLACE32W)lParam;
1258 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1259 (LPSTR)lpfr->lpstrFindWhat, TRUE);
1260 case WM_COMMAND:
1261 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1262 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1263 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1264 TRUE);
1266 return FALSE;
1270 /***********************************************************************
1271 * REPLACEDLG_WMInitDialog [internal]
1273 static LRESULT REPLACEDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam,
1274 LPDWORD lpFlags, LPSTR lpstrFindWhat,
1275 LPSTR lpstrReplaceWith, BOOL32 fUnicode)
1277 SetWindowLong32A(hWnd, DWL_USER, lParam);
1278 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1280 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
1281 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
1282 * enabled.
1284 if (fUnicode)
1286 SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1287 SetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith);
1288 } else
1290 SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1291 SetDlgItemText32A(hWnd, edt2, lpstrReplaceWith);
1293 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1294 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1295 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1296 if (*lpFlags & FR_HIDEWHOLEWORD)
1297 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1298 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1299 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1300 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1301 if (*lpFlags & FR_HIDEMATCHCASE)
1302 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1303 if (!(*lpFlags & FR_SHOWHELP)) {
1304 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1305 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1307 ShowWindow32(hWnd, SW_SHOWNORMAL);
1308 return TRUE;
1312 /***********************************************************************
1313 * REPLACEDLG_WMCommand [internal]
1315 static LRESULT REPLACEDLG_WMCommand(HWND32 hWnd, WPARAM16 wParam,
1316 HWND32 hwndOwner, LPDWORD lpFlags,
1317 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1318 LPSTR lpstrReplaceWith, WORD wReplaceWithLen,
1319 BOOL32 fUnicode)
1321 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1322 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1324 switch (wParam) {
1325 case IDOK:
1326 if (fUnicode)
1328 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1329 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1330 } else
1332 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1333 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1335 if (IsDlgButtonChecked32(hWnd, chx1))
1336 *lpFlags |= FR_WHOLEWORD;
1337 else *lpFlags &= ~FR_WHOLEWORD;
1338 if (IsDlgButtonChecked32(hWnd, chx2))
1339 *lpFlags |= FR_MATCHCASE;
1340 else *lpFlags &= ~FR_MATCHCASE;
1341 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1342 *lpFlags |= FR_FINDNEXT;
1343 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1344 GetWindowLong32A(hWnd, DWL_USER) );
1345 return TRUE;
1346 case IDCANCEL:
1347 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1348 *lpFlags |= FR_DIALOGTERM;
1349 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1350 GetWindowLong32A(hWnd, DWL_USER) );
1351 DestroyWindow32(hWnd);
1352 return TRUE;
1353 case psh1:
1354 if (fUnicode)
1356 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1357 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1358 } else
1360 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1361 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1363 if (IsDlgButtonChecked32(hWnd, chx1))
1364 *lpFlags |= FR_WHOLEWORD;
1365 else *lpFlags &= ~FR_WHOLEWORD;
1366 if (IsDlgButtonChecked32(hWnd, chx2))
1367 *lpFlags |= FR_MATCHCASE;
1368 else *lpFlags &= ~FR_MATCHCASE;
1369 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
1370 *lpFlags |= FR_REPLACE;
1371 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1372 GetWindowLong32A(hWnd, DWL_USER) );
1373 return TRUE;
1374 case psh2:
1375 if (fUnicode)
1377 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1378 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1379 } else
1381 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1382 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1384 if (IsDlgButtonChecked32(hWnd, chx1))
1385 *lpFlags |= FR_WHOLEWORD;
1386 else *lpFlags &= ~FR_WHOLEWORD;
1387 if (IsDlgButtonChecked32(hWnd, chx2))
1388 *lpFlags |= FR_MATCHCASE;
1389 else *lpFlags &= ~FR_MATCHCASE;
1390 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
1391 *lpFlags |= FR_REPLACEALL;
1392 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1393 GetWindowLong32A(hWnd, DWL_USER) );
1394 return TRUE;
1395 case pshHelp:
1396 /* FIXME : should lpfr structure be passed as an argument ??? */
1397 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1398 return TRUE;
1400 return FALSE;
1404 /***********************************************************************
1405 * ReplaceTextDlgProc16 (COMMDLG.14)
1407 LRESULT WINAPI ReplaceTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1408 LPARAM lParam)
1410 LPFINDREPLACE16 lpfr;
1411 switch (wMsg) {
1412 case WM_INITDIALOG:
1413 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1414 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1415 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1416 PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith), FALSE);
1417 case WM_COMMAND:
1418 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1419 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1420 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1421 lpfr->wFindWhatLen, PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith),
1422 lpfr->wReplaceWithLen, FALSE);
1424 return FALSE;
1427 /***********************************************************************
1428 * ReplaceTextDlgProc32A
1430 LRESULT WINAPI ReplaceTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1431 LPARAM lParam)
1433 LPFINDREPLACE32A lpfr;
1434 switch (wMsg) {
1435 case WM_INITDIALOG:
1436 lpfr=(LPFINDREPLACE32A)lParam;
1437 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1438 lpfr->lpstrFindWhat, lpfr->lpstrReplaceWith, FALSE);
1439 case WM_COMMAND:
1440 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1441 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1442 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1443 lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, FALSE);
1445 return FALSE;
1448 /***********************************************************************
1449 * ReplaceTextDlgProc32W
1451 LRESULT WINAPI ReplaceTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1452 LPARAM lParam)
1454 LPFINDREPLACE32W lpfr;
1455 switch (wMsg) {
1456 case WM_INITDIALOG:
1457 lpfr=(LPFINDREPLACE32W)lParam;
1458 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1459 (LPSTR)lpfr->lpstrFindWhat, (LPSTR)lpfr->lpstrReplaceWith,
1460 TRUE);
1461 case WM_COMMAND:
1462 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1463 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1464 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1465 (LPSTR)lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, TRUE);
1467 return FALSE;
1471 /***********************************************************************
1472 * PrintDlg16 (COMMDLG.20)
1474 BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
1476 HANDLE16 hInst;
1477 BOOL16 bRet = FALSE;
1478 LPCVOID template;
1479 HWND32 hwndDialog;
1480 LPPRINTDLG16 lpPrint = (LPPRINTDLG16)PTR_SEG_TO_LIN(printdlg);
1482 TRACE(commdlg,"(%p) -- Flags=%08lX\n", lpPrint, lpPrint->Flags );
1484 if (lpPrint->Flags & PD_RETURNDEFAULT)
1485 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1486 return TRUE;
1488 if (lpPrint->Flags & PD_PRINTSETUP)
1489 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
1490 else
1491 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
1493 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1494 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
1495 lpPrint->hwndOwner,
1496 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
1497 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1498 MODULE_GetWndProcEntry16("PrintDlgProc")),
1499 printdlg, WIN_PROC_16 );
1500 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
1501 return bRet;
1505 /***********************************************************************
1506 * PrintDlg32A (COMDLG32.17)
1508 BOOL32 WINAPI PrintDlg32A( LPPRINTDLG32A printdlg )
1510 FIXME(commdlg, "(%p): stub\n",printdlg);
1511 /* Altough returning FALSE is theoricaly the right thing
1512 * most programs check for a printer at startup, and if
1513 * none is found popup PrintDlg32A(), if it fails the program
1514 * terminates; by returning TRUE the programs can still run
1515 * as long as no printer related stuff is used
1517 return TRUE;
1521 /***********************************************************************
1522 * PrintDlg32W (COMDLG32.18)
1524 BOOL32 WINAPI PrintDlg32W( LPPRINTDLG32W printdlg )
1526 FIXME(commdlg, "empty stub\n" );
1527 return FALSE;
1531 /***********************************************************************
1532 * PrintDlgProc (COMMDLG.21)
1534 LRESULT WINAPI PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1535 LPARAM lParam)
1537 switch (wMsg)
1539 case WM_INITDIALOG:
1540 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1541 ShowWindow16(hWnd, SW_SHOWNORMAL);
1542 return (TRUE);
1543 case WM_COMMAND:
1544 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 * PrintSetupDlgProc (COMMDLG.22)
1562 LRESULT WINAPI PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1563 LPARAM lParam)
1565 switch (wMsg)
1567 case WM_INITDIALOG:
1568 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1569 ShowWindow16(hWnd, SW_SHOWNORMAL);
1570 return (TRUE);
1571 case WM_COMMAND:
1572 switch (wParam) {
1573 case IDOK:
1574 EndDialog32(hWnd, TRUE);
1575 return(TRUE);
1576 case IDCANCEL:
1577 EndDialog32(hWnd, FALSE);
1578 return(TRUE);
1580 return(FALSE);
1582 return FALSE;
1586 /***********************************************************************
1587 * CommDlgExtendedError (COMMDLG.26)
1589 DWORD WINAPI CommDlgExtendedError(void)
1591 return CommDlgLastError;
1594 /***********************************************************************
1595 * GetFileTitleA (COMDLG32.8)
1597 short WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
1599 int i, len;
1600 TRACE(commdlg,"(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1601 if (lpFile == NULL || lpTitle == NULL)
1602 return -1;
1603 len = strlen(lpFile);
1604 if (len == 0)
1605 return -1;
1606 if (strpbrk(lpFile, "*[]"))
1607 return -1;
1608 len--;
1609 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1610 return -1;
1611 for (i = len; i >= 0; i--)
1612 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1614 i++;
1615 break;
1617 if (i == -1)
1618 i++;
1619 TRACE(commdlg,"---> '%s' \n", &lpFile[i]);
1621 len = strlen(lpFile+i)+1;
1622 if (cbBuf < len)
1623 return len;
1625 strncpy(lpTitle, &lpFile[i], len);
1626 return 0;
1630 /***********************************************************************
1631 * GetFileTitleA (COMDLG32.8)
1633 short WINAPI GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf)
1635 LPSTR file = HEAP_strdupWtoA(GetProcessHeap(),0,lpFile);
1636 LPSTR title = HeapAlloc(GetProcessHeap(),0,cbBuf);
1637 short ret;
1639 ret = GetFileTitle32A(file,title,cbBuf);
1641 lstrcpynAtoW(lpTitle,title,cbBuf);
1642 HeapFree(GetProcessHeap(),0,file);
1643 HeapFree(GetProcessHeap(),0,title);
1644 return ret;
1646 /***********************************************************************
1647 * GetFileTitle (COMMDLG.27)
1649 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
1651 return GetFileTitle32A(lpFile,lpTitle,cbBuf);
1655 /* ------------------------ Choose Color Dialog --------------------------- */
1657 /***********************************************************************
1658 * ChooseColor (COMMDLG.5)
1660 BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol)
1662 HINSTANCE16 hInst;
1663 HANDLE16 hDlgTmpl = 0;
1664 BOOL16 bRet = FALSE, win32Format = FALSE;
1665 LPCVOID template;
1666 HWND32 hwndDialog;
1668 TRACE(commdlg,"ChooseColor\n");
1669 if (!lpChCol) return FALSE;
1671 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1673 if (!(template = LockResource16( lpChCol->hInstance )))
1675 CommDlgLastError = CDERR_LOADRESFAILURE;
1676 return FALSE;
1679 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1681 HANDLE16 hResInfo;
1682 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1683 lpChCol->lpTemplateName,
1684 RT_DIALOG16)))
1686 CommDlgLastError = CDERR_FINDRESFAILURE;
1687 return FALSE;
1689 if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
1690 !(template = LockResource16( hDlgTmpl )))
1692 CommDlgLastError = CDERR_LOADRESFAILURE;
1693 return FALSE;
1696 else
1698 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR );
1699 win32Format = TRUE;
1702 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1703 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
1704 lpChCol->hwndOwner,
1705 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1706 (DWORD)lpChCol, WIN_PROC_16 );
1707 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
1708 if (hDlgTmpl) FreeResource16( hDlgTmpl );
1709 return bRet;
1713 static const COLORREF predefcolors[6][8]=
1715 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1716 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1717 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1718 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1720 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1721 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1722 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1723 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1725 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1726 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1727 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1728 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1731 struct CCPRIVATE
1733 LPCHOOSECOLOR16 lpcc; /* points to public known data structure */
1734 int nextuserdef; /* next free place in user defined color array */
1735 HDC16 hdcMem; /* color graph used for BitBlt() */
1736 HBITMAP16 hbmMem; /* color graph bitmap */
1737 RECT16 fullsize; /* original dialog window size */
1738 UINT16 msetrgb; /* # of SETRGBSTRING message (today not used) */
1739 RECT16 old3angle; /* last position of l-marker */
1740 RECT16 oldcross; /* last position of color/satuation marker */
1741 BOOL32 updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1742 int h;
1743 int s;
1744 int l; /* for temporary storing of hue,sat,lum */
1747 /***********************************************************************
1748 * CC_HSLtoRGB [internal]
1750 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1752 int res=0,maxrgb;
1754 /* hue */
1755 switch(c)
1757 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1758 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1759 case 'B':break;
1762 /* l below 120 */
1763 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1764 if (hue< 80)
1765 res=0;
1766 else
1767 if (hue< 120)
1769 res=(hue-80)* maxrgb; /* 0...10240 */
1770 res/=40; /* 0...256 */
1772 else
1773 if (hue< 200)
1774 res=maxrgb;
1775 else
1777 res=(240-hue)* maxrgb;
1778 res/=40;
1780 res=res-maxrgb/2; /* -128...128 */
1782 /* saturation */
1783 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1785 /* lum above 120 */
1786 if (lum>120 && res<256)
1787 res+=((lum-120) * (256-res))/120;
1789 return MIN(res,255);
1792 /***********************************************************************
1793 * CC_RGBtoHSL [internal]
1795 static int CC_RGBtoHSL(char c,int r,int g,int b)
1797 WORD maxi,mini,mmsum,mmdif,result=0;
1798 int iresult=0;
1800 maxi=MAX(r,b);
1801 maxi=MAX(maxi,g);
1802 mini=MIN(r,b);
1803 mini=MIN(mini,g);
1805 mmsum=maxi+mini;
1806 mmdif=maxi-mini;
1808 switch(c)
1810 /* lum */
1811 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1812 result=mmsum/255; /* 0...240 */
1813 break;
1814 /* saturation */
1815 case 'S':if (!mmsum)
1816 result=0;
1817 else
1818 if (!mini || maxi==255)
1819 result=240;
1820 else
1822 result=mmdif*240; /* 0...61200=255*240 */
1823 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1825 break;
1826 /* hue */
1827 case 'H':if (!mmdif)
1828 result=160;
1829 else
1831 if (maxi==r)
1833 iresult=40*(g-b); /* -10200 ... 10200 */
1834 iresult/=(int)mmdif; /* -40 .. 40 */
1835 if (iresult<0)
1836 iresult+=240; /* 0..40 and 200..240 */
1838 else
1839 if (maxi==g)
1841 iresult=40*(b-r);
1842 iresult/=(int)mmdif;
1843 iresult+=80; /* 40 .. 120 */
1845 else
1846 if (maxi==b)
1848 iresult=40*(r-g);
1849 iresult/=(int)mmdif;
1850 iresult+=160; /* 120 .. 200 */
1852 result=iresult;
1854 break;
1856 return result; /* is this integer arithmetic precise enough ? */
1859 #define DISTANCE 4
1861 /***********************************************************************
1862 * CC_MouseCheckPredefColorArray [internal]
1864 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1865 LPARAM lParam,COLORREF *cr)
1867 HWND16 hwnd;
1868 POINT16 point = MAKEPOINT16(lParam);
1869 RECT16 rect;
1870 int dx,dy,x,y;
1872 ClientToScreen16(hDlg,&point);
1873 hwnd=GetDlgItem32(hDlg,dlgitem);
1874 GetWindowRect16(hwnd,&rect);
1875 if (PtInRect16(&rect,point))
1877 dx=(rect.right-rect.left)/cols;
1878 dy=(rect.bottom-rect.top)/rows;
1879 ScreenToClient16(hwnd,&point);
1881 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1883 x=point.x/dx;
1884 y=point.y/dy;
1885 *cr=predefcolors[y][x];
1886 /* FIXME: Draw_a_Focus_Rect() */
1887 return 1;
1890 return 0;
1893 /***********************************************************************
1894 * CC_MouseCheckUserColorArray [internal]
1896 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1897 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1899 HWND16 hwnd;
1900 POINT16 point = MAKEPOINT16(lParam);
1901 RECT16 rect;
1902 int dx,dy,x,y;
1904 ClientToScreen16(hDlg,&point);
1905 hwnd=GetDlgItem32(hDlg,dlgitem);
1906 GetWindowRect16(hwnd,&rect);
1907 if (PtInRect16(&rect,point))
1909 dx=(rect.right-rect.left)/cols;
1910 dy=(rect.bottom-rect.top)/rows;
1911 ScreenToClient16(hwnd,&point);
1913 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1915 x=point.x/dx;
1916 y=point.y/dy;
1917 *cr=crarr[x+cols*y];
1918 /* FIXME: Draw_a_Focus_Rect() */
1919 return 1;
1922 return 0;
1925 #define MAXVERT 240
1926 #define MAXHORI 239
1928 /* 240 ^...... ^^ 240
1929 | . ||
1930 SAT | . || LUM
1931 | . ||
1932 +-----> 239 ----
1935 /***********************************************************************
1936 * CC_MouseCheckColorGraph [internal]
1938 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1940 HWND32 hwnd;
1941 POINT16 point = MAKEPOINT16(lParam);
1942 RECT16 rect;
1943 long x,y;
1945 ClientToScreen16(hDlg,&point);
1946 hwnd=GetDlgItem32(hDlg,dlgitem);
1947 GetWindowRect16(hwnd,&rect);
1948 if (PtInRect16(&rect,point))
1950 GetClientRect16(hwnd,&rect);
1951 ScreenToClient16(hwnd,&point);
1953 x=(long)point.x*MAXHORI;
1954 x/=rect.right;
1955 y=(long)(rect.bottom-point.y)*MAXVERT;
1956 y/=rect.bottom;
1958 if (hori)
1959 *hori=x;
1960 if (vert)
1961 *vert=y;
1962 return 1;
1964 else
1965 return 0;
1967 /***********************************************************************
1968 * CC_MouseCheckResultWindow [internal]
1970 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
1972 HWND16 hwnd;
1973 POINT16 point = MAKEPOINT16(lParam);
1974 RECT16 rect;
1976 ClientToScreen16(hDlg,&point);
1977 hwnd=GetDlgItem32(hDlg,0x2c5);
1978 GetWindowRect16(hwnd,&rect);
1979 if (PtInRect16(&rect,point))
1981 PostMessage16(hDlg,WM_COMMAND,0x2c9,0);
1982 return 1;
1984 return 0;
1987 /***********************************************************************
1988 * CC_CheckDigitsInEdit [internal]
1990 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
1992 int i,k,m,result,value;
1993 long editpos;
1994 char buffer[30];
1995 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1996 m=strlen(buffer);
1997 result=0;
1999 for (i=0;i<m;i++)
2000 if (buffer[i]<'0' || buffer[i]>'9')
2002 for (k=i+1;k<=m;k++) /* delete bad character */
2004 buffer[i]=buffer[k];
2005 m--;
2007 buffer[m]=0;
2008 result=1;
2011 value=atoi(buffer);
2012 if (value>maxval) /* build a new string */
2014 sprintf(buffer,"%d",maxval);
2015 result=2;
2017 if (result)
2019 editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
2020 SetWindowText32A(hwnd,buffer);
2021 SendMessage16(hwnd,EM_SETSEL16,0,editpos);
2023 return value;
2028 /***********************************************************************
2029 * CC_PaintSelectedColor [internal]
2031 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
2033 RECT16 rect;
2034 HDC32 hdc;
2035 HBRUSH32 hBrush;
2036 HWND32 hwnd=GetDlgItem32(hDlg,0x2c5);
2037 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2039 hdc=GetDC32(hwnd);
2040 GetClientRect16 (hwnd, &rect) ;
2041 hBrush = CreateSolidBrush32(cr);
2042 if (hBrush)
2044 hBrush = SelectObject32 (hdc, hBrush) ;
2045 Rectangle32(hdc, rect.left,rect.top,rect.right/2,rect.bottom);
2046 DeleteObject32 (SelectObject32 (hdc,hBrush)) ;
2047 hBrush=CreateSolidBrush32(GetNearestColor32(hdc,cr));
2048 if (hBrush)
2050 hBrush= SelectObject32 (hdc, hBrush) ;
2051 Rectangle32( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
2052 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2055 ReleaseDC32(hwnd,hdc);
2059 /***********************************************************************
2060 * CC_PaintTriangle [internal]
2062 static void CC_PaintTriangle(HWND16 hDlg,int y)
2064 HDC32 hDC;
2065 long temp;
2066 int w=GetDialogBaseUnits();
2067 POINT16 points[3];
2068 int height;
2069 int oben;
2070 RECT16 rect;
2071 HWND16 hwnd=GetDlgItem32(hDlg,0x2be);
2072 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2074 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2076 GetClientRect16(hwnd,&rect);
2077 height=rect.bottom;
2078 hDC=GetDC32(hDlg);
2080 points[0].y=rect.top;
2081 points[0].x=rect.right; /* | /| */
2082 ClientToScreen16(hwnd,points); /* | / | */
2083 ScreenToClient16(hDlg,points); /* |< | */
2084 oben=points[0].y; /* | \ | */
2085 /* | \| */
2086 temp=(long)height*(long)y;
2087 points[0].y=oben+height -temp/(long)MAXVERT;
2088 points[1].y=points[0].y+w;
2089 points[2].y=points[0].y-w;
2090 points[2].x=points[1].x=points[0].x + w;
2092 if (lpp->old3angle.left)
2093 FillRect16(hDC,&lpp->old3angle,GetStockObject32(WHITE_BRUSH));
2094 lpp->old3angle.left =points[0].x;
2095 lpp->old3angle.right =points[1].x+1;
2096 lpp->old3angle.top =points[2].y-1;
2097 lpp->old3angle.bottom=points[1].y+1;
2098 Polygon16(hDC,points,3);
2099 ReleaseDC32(hDlg,hDC);
2104 /***********************************************************************
2105 * CC_PaintCross [internal]
2107 static void CC_PaintCross(HWND16 hDlg,int x,int y)
2109 HDC32 hDC;
2110 int w=GetDialogBaseUnits();
2111 HWND16 hwnd=GetDlgItem32(hDlg,0x2c6);
2112 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2113 RECT16 rect;
2114 POINT16 point;
2115 HPEN32 hPen;
2117 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2119 GetClientRect16(hwnd,&rect);
2120 hDC=GetDC32(hwnd);
2121 SelectClipRgn32(hDC,CreateRectRgnIndirect16(&rect));
2122 hPen=CreatePen32(PS_SOLID,2,0);
2123 hPen=SelectObject32(hDC,hPen);
2124 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
2125 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
2126 if (lpp->oldcross.left!=lpp->oldcross.right)
2127 BitBlt32(hDC,lpp->oldcross.left,lpp->oldcross.top,
2128 lpp->oldcross.right-lpp->oldcross.left,
2129 lpp->oldcross.bottom-lpp->oldcross.top,
2130 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
2131 lpp->oldcross.left =point.x-w-1;
2132 lpp->oldcross.right =point.x+w+1;
2133 lpp->oldcross.top =point.y-w-1;
2134 lpp->oldcross.bottom=point.y+w+1;
2136 MoveTo(hDC,point.x-w,point.y);
2137 LineTo32(hDC,point.x+w,point.y);
2138 MoveTo(hDC,point.x,point.y-w);
2139 LineTo32(hDC,point.x,point.y+w);
2140 DeleteObject32(SelectObject32(hDC,hPen));
2141 ReleaseDC32(hwnd,hDC);
2146 #define XSTEPS 48
2147 #define YSTEPS 24
2150 /***********************************************************************
2151 * CC_PrepareColorGraph [internal]
2153 static void CC_PrepareColorGraph(HWND16 hDlg)
2155 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
2156 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2157 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2158 HBRUSH32 hbrush;
2159 HDC32 hdc ;
2160 RECT16 rect,client;
2161 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT16));
2163 GetClientRect16(hwnd,&client);
2164 hdc=GetDC32(hwnd);
2165 lpp->hdcMem = CreateCompatibleDC32(hdc);
2166 lpp->hbmMem = CreateCompatibleBitmap32(hdc,client.right,client.bottom);
2167 SelectObject32(lpp->hdcMem,lpp->hbmMem);
2169 xdif=client.right /XSTEPS;
2170 ydif=client.bottom/YSTEPS+1;
2171 hdif=239/XSTEPS;
2172 sdif=240/YSTEPS;
2173 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
2175 rect.right=rect.left+xdif;
2176 rect.bottom=client.bottom;
2177 for(sat=0;sat<240+sdif;sat+=sdif)
2179 rect.top=rect.bottom-ydif;
2180 r=CC_HSLtoRGB('R',hue,sat,120);
2181 g=CC_HSLtoRGB('G',hue,sat,120);
2182 b=CC_HSLtoRGB('B',hue,sat,120);
2183 hbrush=CreateSolidBrush32(RGB(r,g,b));
2184 FillRect16(lpp->hdcMem,&rect,hbrush);
2185 DeleteObject32(hbrush);
2186 rect.bottom=rect.top;
2188 rect.left=rect.right;
2190 ReleaseDC32(hwnd,hdc);
2191 SetCursor16(hcursor);
2194 /***********************************************************************
2195 * CC_PaintColorGraph [internal]
2197 static void CC_PaintColorGraph(HWND16 hDlg)
2199 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2200 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2201 HDC32 hDC;
2202 RECT16 rect;
2203 if (IsWindowVisible32(hwnd)) /* if full size */
2205 if (!lpp->hdcMem)
2206 CC_PrepareColorGraph(hDlg); /* should not be necessary */
2208 hDC=GetDC32(hwnd);
2209 GetClientRect16(hwnd,&rect);
2210 if (lpp->hdcMem)
2211 BitBlt32(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
2212 else
2213 WARN(commdlg,"choose color: hdcMem is not defined\n");
2214 ReleaseDC32(hwnd,hDC);
2217 /***********************************************************************
2218 * CC_PaintLumBar [internal]
2220 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
2222 HWND32 hwnd=GetDlgItem32(hDlg,0x2be);
2223 RECT16 rect,client;
2224 int lum,ldif,ydif,r,g,b;
2225 HBRUSH32 hbrush;
2226 HDC32 hDC;
2228 if (IsWindowVisible32(hwnd))
2230 hDC=GetDC32(hwnd);
2231 GetClientRect16(hwnd,&client);
2232 rect=client;
2234 ldif=240/YSTEPS;
2235 ydif=client.bottom/YSTEPS+1;
2236 for(lum=0;lum<240+ldif;lum+=ldif)
2238 rect.top=MAX(0,rect.bottom-ydif);
2239 r=CC_HSLtoRGB('R',hue,sat,lum);
2240 g=CC_HSLtoRGB('G',hue,sat,lum);
2241 b=CC_HSLtoRGB('B',hue,sat,lum);
2242 hbrush=CreateSolidBrush32(RGB(r,g,b));
2243 FillRect16(hDC,&rect,hbrush);
2244 DeleteObject32(hbrush);
2245 rect.bottom=rect.top;
2247 GetClientRect16(hwnd,&rect);
2248 FrameRect16(hDC,&rect,GetStockObject32(BLACK_BRUSH));
2249 ReleaseDC32(hwnd,hDC);
2253 /***********************************************************************
2254 * CC_EditSetRGB [internal]
2256 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
2258 char buffer[10];
2259 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2260 int r=GetRValue(cr);
2261 int g=GetGValue(cr);
2262 int b=GetBValue(cr);
2263 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2265 lpp->updating=TRUE;
2266 sprintf(buffer,"%d",r);
2267 SetWindowText32A(GetDlgItem32(hDlg,0x2c2),buffer);
2268 sprintf(buffer,"%d",g);
2269 SetWindowText32A(GetDlgItem32(hDlg,0x2c3),buffer);
2270 sprintf(buffer,"%d",b);
2271 SetWindowText32A(GetDlgItem32(hDlg,0x2c4),buffer);
2272 lpp->updating=FALSE;
2276 /***********************************************************************
2277 * CC_EditSetHSL [internal]
2279 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
2281 char buffer[10];
2282 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2283 lpp->updating=TRUE;
2284 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2286 lpp->updating=TRUE;
2287 sprintf(buffer,"%d",h);
2288 SetWindowText32A(GetDlgItem32(hDlg,0x2bf),buffer);
2289 sprintf(buffer,"%d",s);
2290 SetWindowText32A(GetDlgItem32(hDlg,0x2c0),buffer);
2291 sprintf(buffer,"%d",l);
2292 SetWindowText32A(GetDlgItem32(hDlg,0x2c1),buffer);
2293 lpp->updating=FALSE;
2295 CC_PaintLumBar(hDlg,h,s);
2298 /***********************************************************************
2299 * CC_SwitchToFullSize [internal]
2301 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
2303 int i;
2304 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2306 EnableWindow32(GetDlgItem32(hDlg,0x2cf),FALSE);
2307 CC_PrepareColorGraph(hDlg);
2308 for (i=0x2bf;i<0x2c5;i++)
2309 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2310 for (i=0x2d3;i<0x2d9;i++)
2311 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2312 EnableWindow32(GetDlgItem32(hDlg,0x2c9),TRUE);
2313 EnableWindow32(GetDlgItem32(hDlg,0x2c8),TRUE);
2315 if (lprect)
2316 SetWindowPos32(hDlg,0,0,0,lprect->right-lprect->left,
2317 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
2319 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_SHOW);
2320 ShowWindow32(GetDlgItem32(hDlg,0x2be),SW_SHOW);
2321 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_SHOW);
2323 CC_EditSetRGB(hDlg,result);
2324 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2327 /***********************************************************************
2328 * CC_PaintPredefColorArray [internal]
2330 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
2332 HWND32 hwnd=GetDlgItem32(hDlg,0x2d0);
2333 RECT16 rect;
2334 HDC32 hdc;
2335 HBRUSH32 hBrush;
2336 int dx,dy,i,j,k;
2338 GetClientRect16(hwnd,&rect);
2339 dx=rect.right/cols;
2340 dy=rect.bottom/rows;
2341 k=rect.left;
2343 hdc=GetDC32(hwnd);
2344 GetClientRect16 (hwnd, &rect) ;
2346 for (j=0;j<rows;j++)
2348 for (i=0;i<cols;i++)
2350 hBrush = CreateSolidBrush32(predefcolors[j][i]);
2351 if (hBrush)
2353 hBrush = SelectObject32 (hdc, hBrush) ;
2354 Rectangle32(hdc, rect.left, rect.top,
2355 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2356 rect.left=rect.left+dx;
2357 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2360 rect.top=rect.top+dy;
2361 rect.left=k;
2363 ReleaseDC32(hwnd,hdc);
2364 /* FIXME: draw_a_focus_rect */
2366 /***********************************************************************
2367 * CC_PaintUserColorArray [internal]
2369 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
2371 HWND32 hwnd=GetDlgItem32(hDlg,0x2d1);
2372 RECT16 rect;
2373 HDC32 hdc;
2374 HBRUSH32 hBrush;
2375 int dx,dy,i,j,k;
2377 GetClientRect16(hwnd,&rect);
2379 dx=rect.right/cols;
2380 dy=rect.bottom/rows;
2381 k=rect.left;
2383 hdc=GetDC32(hwnd);
2384 if (hdc)
2386 for (j=0;j<rows;j++)
2388 for (i=0;i<cols;i++)
2390 hBrush = CreateSolidBrush32(lpcr[i+j*cols]);
2391 if (hBrush)
2393 hBrush = SelectObject32 (hdc, hBrush) ;
2394 Rectangle32( hdc, rect.left, rect.top,
2395 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2396 rect.left=rect.left+dx;
2397 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2400 rect.top=rect.top+dy;
2401 rect.left=k;
2403 ReleaseDC32(hwnd,hdc);
2405 /* FIXME: draw_a_focus_rect */
2410 /***********************************************************************
2411 * CC_HookCallChk [internal]
2413 static BOOL32 CC_HookCallChk(LPCHOOSECOLOR16 lpcc)
2415 if (lpcc)
2416 if(lpcc->Flags & CC_ENABLEHOOK)
2417 if (lpcc->lpfnHook)
2418 return TRUE;
2419 return FALSE;
2422 /***********************************************************************
2423 * CC_WMInitDialog [internal]
2425 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2427 int i,res;
2428 HWND16 hwnd;
2429 RECT16 rect;
2430 POINT16 point;
2431 struct CCPRIVATE * lpp;
2433 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
2434 lpp=calloc(1,sizeof(struct CCPRIVATE));
2435 lpp->lpcc=(LPCHOOSECOLOR16)lParam;
2436 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR16))
2438 EndDialog32 (hDlg, 0) ;
2439 return FALSE;
2441 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
2443 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
2444 ShowWindow32(GetDlgItem32(hDlg,0x40e),SW_HIDE);
2445 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
2446 #if 0
2447 cpos=MAKELONG(5,7); /* init */
2448 if (lpp->lpcc->Flags & CC_RGBINIT)
2450 for (i=0;i<6;i++)
2451 for (j=0;j<8;j++)
2452 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
2454 cpos=MAKELONG(i,j);
2455 goto found;
2458 found:
2459 /* FIXME: Draw_a_focus_rect & set_init_values */
2460 #endif
2461 GetWindowRect16(hDlg,&lpp->fullsize);
2462 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2464 hwnd=GetDlgItem32(hDlg,0x2cf);
2465 EnableWindow32(hwnd,FALSE);
2467 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2469 rect=lpp->fullsize;
2470 res=rect.bottom-rect.top;
2471 hwnd=GetDlgItem32(hDlg,0x2c6); /* cut at left border */
2472 point.x=point.y=0;
2473 ClientToScreen16(hwnd,&point);
2474 ScreenToClient16(hDlg,&point);
2475 GetClientRect16(hDlg,&rect);
2476 point.x+=GetSystemMetrics32(SM_CXDLGFRAME);
2477 SetWindowPos32(hDlg,0,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
2479 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_HIDE);
2480 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_HIDE);
2482 else
2483 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
2484 res=TRUE;
2485 for (i=0x2bf;i<0x2c5;i++)
2486 SendMessage16(GetDlgItem32(hDlg,i),EM_LIMITTEXT16,3,0); /* max 3 digits: xyz */
2487 if (CC_HookCallChk(lpp->lpcc))
2488 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2489 return res;
2492 /***********************************************************************
2493 * CC_WMCommand [internal]
2495 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2497 int r,g,b,i,xx;
2498 UINT16 cokmsg;
2499 HDC32 hdc;
2500 COLORREF *cr;
2501 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2502 TRACE(commdlg,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
2503 switch (wParam)
2505 case 0x2c2: /* edit notify RGB */
2506 case 0x2c3:
2507 case 0x2c4:
2508 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2510 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
2511 r=GetRValue(lpp->lpcc->rgbResult);
2512 g=GetGValue(lpp->lpcc->rgbResult);
2513 b=GetBValue(lpp->lpcc->rgbResult);
2514 xx=0;
2515 switch (wParam)
2517 case 0x2c2:if ((xx=(i!=r))) r=i;break;
2518 case 0x2c3:if ((xx=(i!=g))) g=i;break;
2519 case 0x2c4:if ((xx=(i!=b))) b=i;break;
2521 if (xx) /* something has changed */
2523 lpp->lpcc->rgbResult=RGB(r,g,b);
2524 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2525 lpp->h=CC_RGBtoHSL('H',r,g,b);
2526 lpp->s=CC_RGBtoHSL('S',r,g,b);
2527 lpp->l=CC_RGBtoHSL('L',r,g,b);
2528 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2529 CC_PaintCross(hDlg,lpp->h,lpp->s);
2530 CC_PaintTriangle(hDlg,lpp->l);
2533 break;
2535 case 0x2bf: /* edit notify HSL */
2536 case 0x2c0:
2537 case 0x2c1:
2538 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2540 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
2541 xx=0;
2542 switch (wParam)
2544 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
2545 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
2546 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
2548 if (xx) /* something has changed */
2550 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2551 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2552 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2553 lpp->lpcc->rgbResult=RGB(r,g,b);
2554 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2555 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2556 CC_PaintCross(hDlg,lpp->h,lpp->s);
2557 CC_PaintTriangle(hDlg,lpp->l);
2560 break;
2562 case 0x2cf:
2563 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
2564 InvalidateRect32( hDlg, NULL, TRUE );
2565 SetFocus32(GetDlgItem32(hDlg,0x2bf));
2566 break;
2568 case 0x2c8: /* add colors ... column by column */
2569 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
2570 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
2571 if (++lpp->nextuserdef==16)
2572 lpp->nextuserdef=0;
2573 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2574 break;
2576 case 0x2c9: /* resulting color */
2577 hdc=GetDC32(hDlg);
2578 lpp->lpcc->rgbResult=GetNearestColor32(hdc,lpp->lpcc->rgbResult);
2579 ReleaseDC32(hDlg,hdc);
2580 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2581 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2582 r=GetRValue(lpp->lpcc->rgbResult);
2583 g=GetGValue(lpp->lpcc->rgbResult);
2584 b=GetBValue(lpp->lpcc->rgbResult);
2585 lpp->h=CC_RGBtoHSL('H',r,g,b);
2586 lpp->s=CC_RGBtoHSL('S',r,g,b);
2587 lpp->l=CC_RGBtoHSL('L',r,g,b);
2588 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2589 CC_PaintCross(hDlg,lpp->h,lpp->s);
2590 CC_PaintTriangle(hDlg,lpp->l);
2591 break;
2593 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2594 i=RegisterWindowMessage32A( HELPMSGSTRING );
2595 if (lpp->lpcc->hwndOwner)
2596 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2597 if (CC_HookCallChk(lpp->lpcc))
2598 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2599 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2600 break;
2602 case IDOK :
2603 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2604 if (lpp->lpcc->hwndOwner)
2605 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2606 break; /* do NOT close */
2608 EndDialog32 (hDlg, 1) ;
2609 return TRUE ;
2611 case IDCANCEL :
2612 EndDialog32 (hDlg, 0) ;
2613 return TRUE ;
2616 return FALSE;
2619 /***********************************************************************
2620 * CC_WMPaint [internal]
2622 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2624 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2625 /* we have to paint dialog children except text and buttons */
2627 CC_PaintPredefColorArray(hDlg,6,8);
2628 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2629 CC_PaintColorGraph(hDlg);
2630 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2631 CC_PaintCross(hDlg,lpp->h,lpp->s);
2632 CC_PaintTriangle(hDlg,lpp->l);
2633 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2635 /* special necessary for Wine */
2636 ValidateRect32(GetDlgItem32(hDlg,0x2d0),NULL);
2637 ValidateRect32(GetDlgItem32(hDlg,0x2d1),NULL);
2638 ValidateRect32(GetDlgItem32(hDlg,0x2c6),NULL);
2639 ValidateRect32(GetDlgItem32(hDlg,0x2be),NULL);
2640 ValidateRect32(GetDlgItem32(hDlg,0x2c5),NULL);
2641 /* hope we can remove it later -->FIXME */
2642 return 0;
2646 /***********************************************************************
2647 * CC_WMLButtonDown [internal]
2649 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2651 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2652 int r,g,b,i;
2653 i=0;
2654 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2655 i=1;
2656 else
2657 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2658 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2659 i=1;
2660 else
2661 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2662 i=2;
2663 else
2664 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2665 i=2;
2666 if (i==2)
2668 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2669 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2670 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2671 lpp->lpcc->rgbResult=RGB(r,g,b);
2673 if (i==1)
2675 r=GetRValue(lpp->lpcc->rgbResult);
2676 g=GetGValue(lpp->lpcc->rgbResult);
2677 b=GetBValue(lpp->lpcc->rgbResult);
2678 lpp->h=CC_RGBtoHSL('H',r,g,b);
2679 lpp->s=CC_RGBtoHSL('S',r,g,b);
2680 lpp->l=CC_RGBtoHSL('L',r,g,b);
2682 if (i)
2684 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2685 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2686 CC_PaintCross(hDlg,lpp->h,lpp->s);
2687 CC_PaintTriangle(hDlg,lpp->l);
2688 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2689 return TRUE;
2691 return FALSE;
2694 /***********************************************************************
2695 * ColorDlgProc (COMMDLG.8)
2697 LRESULT WINAPI ColorDlgProc(HWND16 hDlg, UINT16 message,
2698 WPARAM16 wParam, LONG lParam)
2700 int res;
2701 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2702 if (message!=WM_INITDIALOG)
2704 if (!lpp)
2705 return FALSE;
2706 res=0;
2707 if (CC_HookCallChk(lpp->lpcc))
2708 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2709 if (res)
2710 return res;
2713 /* FIXME: SetRGB message
2714 if (message && message==msetrgb)
2715 return HandleSetRGB(hDlg,lParam);
2718 switch (message)
2720 case WM_INITDIALOG:
2721 return CC_WMInitDialog(hDlg,wParam,lParam);
2722 case WM_NCDESTROY:
2723 DeleteDC32(lpp->hdcMem);
2724 DeleteObject32(lpp->hbmMem);
2725 free(lpp);
2726 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2727 break;
2728 case WM_COMMAND:
2729 if (CC_WMCommand(hDlg, wParam, lParam))
2730 return TRUE;
2731 break;
2732 case WM_PAINT:
2733 CC_WMPaint(hDlg, wParam, lParam);
2734 break;
2735 case WM_LBUTTONDBLCLK:
2736 if (CC_MouseCheckResultWindow(hDlg,lParam))
2737 return TRUE;
2738 break;
2739 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2740 break;
2741 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2742 break;
2743 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2744 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2745 return TRUE;
2746 break;
2748 return FALSE ;
2751 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONT32A chf32a)
2753 chf32a->lStructSize=sizeof(CHOOSEFONT32A);
2754 chf32a->hwndOwner=chf16->hwndOwner;
2755 chf32a->hDC=chf16->hDC;
2756 chf32a->iPointSize=chf16->iPointSize;
2757 chf32a->Flags=chf16->Flags;
2758 chf32a->rgbColors=chf16->rgbColors;
2759 chf32a->lCustData=chf16->lCustData;
2760 chf32a->lpfnHook=NULL;
2761 chf32a->lpTemplateName=PTR_SEG_TO_LIN(chf16->lpTemplateName);
2762 chf32a->hInstance=chf16->hInstance;
2763 chf32a->lpszStyle=PTR_SEG_TO_LIN(chf16->lpszStyle);
2764 chf32a->nFontType=chf16->nFontType;
2765 chf32a->nSizeMax=chf16->nSizeMax;
2766 chf32a->nSizeMin=chf16->nSizeMin;
2767 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16->lpLogFont), chf32a->lpLogFont);
2771 /***********************************************************************
2772 * ChooseFont16 (COMMDLG.15)
2774 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
2776 HINSTANCE16 hInst;
2777 HANDLE16 hDlgTmpl = 0;
2778 BOOL16 bRet = FALSE, win32Format = FALSE;
2779 LPCVOID template;
2780 HWND32 hwndDialog;
2781 CHOOSEFONT32A cf32a;
2782 LOGFONT32A lf32a;
2783 SEGPTR lpTemplateName;
2785 cf32a.lpLogFont=&lf32a;
2786 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
2788 TRACE(commdlg,"ChooseFont\n");
2789 if (!lpChFont) return FALSE;
2791 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
2793 if (!(template = LockResource16( lpChFont->hInstance )))
2795 CommDlgLastError = CDERR_LOADRESFAILURE;
2796 return FALSE;
2799 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2801 HANDLE16 hResInfo;
2802 if (!(hResInfo = FindResource16( lpChFont->hInstance,
2803 lpChFont->lpTemplateName,
2804 RT_DIALOG16)))
2806 CommDlgLastError = CDERR_FINDRESFAILURE;
2807 return FALSE;
2809 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
2810 !(template = LockResource16( hDlgTmpl )))
2812 CommDlgLastError = CDERR_LOADRESFAILURE;
2813 return FALSE;
2816 else
2818 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2819 win32Format = TRUE;
2822 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2824 /* lpTemplateName is not used in the dialog */
2825 lpTemplateName=lpChFont->lpTemplateName;
2826 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
2828 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
2829 lpChFont->hwndOwner,
2830 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2831 (DWORD)lpChFont, WIN_PROC_16 );
2832 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2833 if (hDlgTmpl) FreeResource16( hDlgTmpl );
2834 lpChFont->lpTemplateName=lpTemplateName;
2835 FONT_LogFont32ATo16(cf32a.lpLogFont,
2836 (LPLOGFONT16)(PTR_SEG_TO_LIN(lpChFont->lpLogFont)));
2837 return bRet;
2841 /***********************************************************************
2842 * ChooseFont32A (COMDLG32.3)
2844 BOOL32 WINAPI ChooseFont32A(LPCHOOSEFONT32A lpChFont)
2846 BOOL32 bRet=FALSE;
2847 HWND32 hwndDialog;
2848 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2849 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2850 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2851 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2852 hwndDialog = DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2853 (DLGPROC16)FormatCharDlgProc32A, (LPARAM)lpChFont, WIN_PROC_32A );
2854 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2855 return bRet;
2858 /***********************************************************************
2859 * ChooseFont32W (COMDLG32.4)
2861 BOOL32 WINAPI ChooseFont32W(LPCHOOSEFONT32W lpChFont)
2863 BOOL32 bRet=FALSE;
2864 HWND32 hwndDialog;
2865 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2866 CHOOSEFONT32A cf32a;
2867 LOGFONT32A lf32a;
2868 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2869 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2870 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2871 memcpy(&cf32a, lpChFont, sizeof(cf32a));
2872 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONT32A));
2873 lstrcpynWtoA(lf32a.lfFaceName, lpChFont->lpLogFont->lfFaceName, LF_FACESIZE);
2874 cf32a.lpLogFont=&lf32a;
2875 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
2876 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
2877 hwndDialog=DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2878 (DLGPROC16)FormatCharDlgProc32W, (LPARAM)lpChFont, WIN_PROC_32W );
2879 if (hwndDialog)bRet=DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2880 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
2881 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
2882 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONT32A));
2883 lstrcpynAtoW(lpChFont->lpLogFont->lfFaceName, lf32a.lfFaceName, LF_FACESIZE);
2884 return bRet;
2888 #define TEXT_EXTRAS 4
2889 #define TEXT_COLORS 16
2891 static const COLORREF textcolors[TEXT_COLORS]=
2893 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2894 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2895 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2896 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2899 /***********************************************************************
2900 * CFn_HookCallChk [internal]
2902 static BOOL32 CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
2904 if (lpcf)
2905 if(lpcf->Flags & CF_ENABLEHOOK)
2906 if (lpcf->lpfnHook)
2907 return TRUE;
2908 return FALSE;
2911 /***********************************************************************
2912 * CFn_HookCallChk32 [internal]
2914 static BOOL32 CFn_HookCallChk32(LPCHOOSEFONT32A lpcf)
2916 if (lpcf)
2917 if(lpcf->Flags & CF_ENABLEHOOK)
2918 if (lpcf->lpfnHook)
2919 return TRUE;
2920 return FALSE;
2924 /*************************************************************************
2925 * AddFontFamily [internal]
2927 static INT32 AddFontFamily(LPLOGFONT32A lplf, UINT32 nFontType,
2928 LPCHOOSEFONT32A lpcf, HWND32 hwnd)
2930 int i;
2931 WORD w;
2933 TRACE(commdlg,"font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
2935 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2936 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2937 return 1;
2938 if (lpcf->Flags & CF_ANSIONLY)
2939 if (lplf->lfCharSet != ANSI_CHARSET)
2940 return 1;
2941 if (lpcf->Flags & CF_TTONLY)
2942 if (!(nFontType & TRUETYPE_FONTTYPE))
2943 return 1;
2945 i=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)lplf->lfFaceName);
2946 if (i!=CB_ERR)
2948 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2949 SendMessage32A(hwnd, CB_SETITEMDATA32, i, MAKELONG(nFontType,w));
2950 return 1 ; /* store some important font information */
2952 else
2953 return 0;
2956 typedef struct
2958 HWND32 hWnd1;
2959 HWND32 hWnd2;
2960 LPCHOOSEFONT32A lpcf32a;
2961 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
2963 /*************************************************************************
2964 * FontFamilyEnumProc32 [internal]
2966 INT32 WINAPI FontFamilyEnumProc32(LPENUMLOGFONT32A lpEnumLogFont,
2967 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam)
2969 LPCFn_ENUMSTRUCT e;
2970 e=(LPCFn_ENUMSTRUCT)lParam;
2971 return AddFontFamily(&lpEnumLogFont->elfLogFont, nFontType, e->lpcf32a, e->hWnd1);
2974 /***********************************************************************
2975 * FontFamilyEnumProc16 (COMMDLG.19)
2977 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
2978 UINT16 nFontType, LPARAM lParam )
2980 HWND16 hwnd=LOWORD(lParam);
2981 HWND16 hDlg=GetParent16(hwnd);
2982 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
2983 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
2984 LOGFONT32A lf32a;
2985 FONT_LogFont16To32A(lplf, &lf32a);
2986 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
2987 hwnd);
2990 /*************************************************************************
2991 * SetFontStylesToCombo2 [internal]
2993 * Fill font style information into combobox (without using font.c directly)
2995 static int SetFontStylesToCombo2(HWND32 hwnd, HDC32 hdc, LPLOGFONT32A lplf)
2997 #define FSTYLES 4
2998 struct FONTSTYLE
2999 { int italic;
3000 int weight;
3001 char stname[20]; };
3002 static struct FONTSTYLE fontstyles[FSTYLES]={
3003 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
3004 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
3005 HFONT16 hf;
3006 TEXTMETRIC16 tm;
3007 int i,j;
3009 for (i=0;i<FSTYLES;i++)
3011 lplf->lfItalic=fontstyles[i].italic;
3012 lplf->lfWeight=fontstyles[i].weight;
3013 hf=CreateFontIndirect32A(lplf);
3014 hf=SelectObject32(hdc,hf);
3015 GetTextMetrics16(hdc,&tm);
3016 hf=SelectObject32(hdc,hf);
3017 DeleteObject32(hf);
3019 if (tm.tmWeight==fontstyles[i].weight &&
3020 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
3022 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
3023 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
3024 SEGPTR_FREE(str);
3025 if (j==CB_ERR) return 1;
3026 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
3027 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
3028 if (j==CB_ERR) return 1;
3031 return 0;
3034 /*************************************************************************
3035 * AddFontSizeToCombo3 [internal]
3037 static int AddFontSizeToCombo3(HWND32 hwnd, UINT32 h, LPCHOOSEFONT32A lpcf)
3039 int j;
3040 char buffer[20];
3042 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
3043 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
3045 sprintf(buffer, "%2d", h);
3046 j=SendMessage32A(hwnd, CB_FINDSTRINGEXACT32, -1, (LPARAM)buffer);
3047 if (j==CB_ERR)
3049 j=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)buffer);
3050 if (j!=CB_ERR) j = SendMessage32A(hwnd, CB_SETITEMDATA32, j, h);
3051 if (j==CB_ERR) return 1;
3054 return 0;
3057 /*************************************************************************
3058 * SetFontSizesToCombo3 [internal]
3060 static int SetFontSizesToCombo3(HWND32 hwnd, LPCHOOSEFONT32A lpcf)
3062 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
3063 int i;
3065 for (i=0; sizes[i]; i++)
3066 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
3067 return 0;
3070 /***********************************************************************
3071 * AddFontStyle [internal]
3073 INT32 AddFontStyle(LPLOGFONT32A lplf, UINT32 nFontType,
3074 LPCHOOSEFONT32A lpcf, HWND32 hcmb2, HWND32 hcmb3, HWND32 hDlg)
3076 int i;
3078 TRACE(commdlg,"(nFontType=%d)\n",nFontType);
3079 TRACE(commdlg," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
3080 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
3081 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
3082 lplf->lfEscapement,lplf->lfOrientation,
3083 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
3084 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
3085 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
3086 if (nFontType & RASTER_FONTTYPE)
3088 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
3089 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
3091 if (!SendMessage32A(hcmb2, CB_GETCOUNT32, 0, 0))
3093 HDC32 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3094 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
3095 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3096 ReleaseDC32(hDlg,hdc);
3097 if (i)
3098 return 0;
3100 return 1 ;
3104 /***********************************************************************
3105 * FontStyleEnumProc16 (COMMDLG.18)
3107 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
3108 UINT16 nFontType, LPARAM lParam )
3110 HWND16 hcmb2=LOWORD(lParam);
3111 HWND16 hcmb3=HIWORD(lParam);
3112 HWND16 hDlg=GetParent16(hcmb3);
3113 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3114 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
3115 LOGFONT32A lf32a;
3116 FONT_LogFont16To32A(lplf, &lf32a);
3117 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
3118 hcmb2, hcmb3, hDlg);
3121 /***********************************************************************
3122 * FontStyleEnumProc32 [internal]
3124 INT32 WINAPI FontStyleEnumProc32( LPENUMLOGFONT32A lpFont,
3125 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam )
3127 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
3128 HWND32 hcmb2=s->hWnd1;
3129 HWND32 hcmb3=s->hWnd2;
3130 HWND32 hDlg=GetParent32(hcmb3);
3131 return AddFontStyle(&lpFont->elfLogFont, nFontType, s->lpcf32a, hcmb2,
3132 hcmb3, hDlg);
3135 /***********************************************************************
3136 * CFn_WMInitDialog [internal]
3138 LRESULT CFn_WMInitDialog(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3139 LPCHOOSEFONT32A lpcf)
3141 HDC32 hdc;
3142 int i,j,res,init=0;
3143 long l;
3144 LPLOGFONT32A lpxx;
3145 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3147 SetWindowLong32A(hDlg, DWL_USER, lParam);
3148 lpxx=lpcf->lpLogFont;
3149 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
3151 if (lpcf->lStructSize != sizeof(CHOOSEFONT32A))
3153 ERR(commdlg,"structure size failure !!!\n");
3154 EndDialog32 (hDlg, 0);
3155 return FALSE;
3157 if (!hBitmapTT)
3158 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3160 /* This font will be deleted by WM_COMMAND */
3161 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,
3162 CreateFont32A(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
3164 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow32(lpcf->hwndOwner))
3165 ShowWindow32(GetDlgItem32(hDlg,pshHelp),SW_HIDE);
3166 if (!(lpcf->Flags & CF_APPLY))
3167 ShowWindow32(GetDlgItem32(hDlg,psh3),SW_HIDE);
3168 if (lpcf->Flags & CF_EFFECTS)
3170 for (res=1,i=0;res && i<TEXT_COLORS;i++)
3172 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
3173 char name[20];
3174 strcpy( name, "[color name]" );
3175 j=SendDlgItemMessage32A(hDlg, cmb4, CB_ADDSTRING32, 0, (LPARAM)name);
3176 SendDlgItemMessage32A(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
3177 /* look for a fitting value in color combobox */
3178 if (textcolors[j]==lpcf->rgbColors)
3179 SendDlgItemMessage32A(hDlg,cmb4, CB_SETCURSEL32,j,0);
3182 else
3184 ShowWindow32(GetDlgItem32(hDlg,cmb4),SW_HIDE);
3185 ShowWindow32(GetDlgItem32(hDlg,chx1),SW_HIDE);
3186 ShowWindow32(GetDlgItem32(hDlg,chx2),SW_HIDE);
3187 ShowWindow32(GetDlgItem32(hDlg,grp1),SW_HIDE);
3188 ShowWindow32(GetDlgItem32(hDlg,stc4),SW_HIDE);
3190 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3191 if (hdc)
3193 CFn_ENUMSTRUCT s;
3194 s.hWnd1=GetDlgItem32(hDlg,cmb1);
3195 s.lpcf32a=lpcf;
3196 if (!EnumFontFamilies32A(hdc, NULL, FontFamilyEnumProc32, (LPARAM)&s))
3197 TRACE(commdlg,"EnumFontFamilies returns 0\n");
3198 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
3200 /* look for fitting font name in combobox1 */
3201 j=SendDlgItemMessage32A(hDlg,cmb1,CB_FINDSTRING32,-1,(LONG)lpxx->lfFaceName);
3202 if (j!=CB_ERR)
3204 SendDlgItemMessage32A(hDlg, cmb1, CB_SETCURSEL32, j, 0);
3205 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3206 GetDlgItem32(hDlg,cmb1));
3207 init=1;
3208 /* look for fitting font style in combobox2 */
3209 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
3210 for (i=0;i<TEXT_EXTRAS;i++)
3212 if (l==SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0))
3213 SendDlgItemMessage32A(hDlg, cmb2, CB_SETCURSEL32, i, 0);
3216 /* look for fitting font size in combobox3 */
3217 j=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCOUNT32, 0, 0);
3218 for (i=0;i<j;i++)
3220 if (lpxx->lfHeight==(int)SendDlgItemMessage32A(hDlg,cmb3, CB_GETITEMDATA32,i,0))
3221 SendDlgItemMessage32A(hDlg,cmb3,CB_SETCURSEL32,i,0);
3225 if (!init)
3227 SendDlgItemMessage32A(hDlg,cmb1,CB_SETCURSEL32,0,0);
3228 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3229 GetDlgItem32(hDlg,cmb1));
3231 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
3233 j=SendDlgItemMessage32A(hDlg,cmb2,CB_FINDSTRING32,-1,(LONG)lpcf->lpszStyle);
3234 if (j!=CB_ERR)
3236 j=SendDlgItemMessage32A(hDlg,cmb2,CB_SETCURSEL32,j,0);
3237 SendMessage32A(hDlg,WM_COMMAND,cmb2,
3238 MAKELONG(GetDlgItem32(hDlg,cmb2),CBN_SELCHANGE));
3242 else
3244 WARN(commdlg,"HDC failure !!!\n");
3245 EndDialog32 (hDlg, 0);
3246 return FALSE;
3249 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3250 ReleaseDC32(hDlg,hdc);
3251 SetCursor32(hcursor);
3252 return TRUE;
3256 /***********************************************************************
3257 * CFn_WMMeasureItem [internal]
3259 LRESULT CFn_WMMeasureItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3261 BITMAP32 bm;
3262 LPMEASUREITEMSTRUCT32 lpmi=(LPMEASUREITEMSTRUCT32)lParam;
3263 if (!hBitmapTT)
3264 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3265 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3266 lpmi->itemHeight=bm.bmHeight;
3267 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
3268 return 0;
3272 /***********************************************************************
3273 * CFn_WMDrawItem [internal]
3275 LRESULT CFn_WMDrawItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3277 HBRUSH32 hBrush;
3278 char buffer[40];
3279 BITMAP32 bm;
3280 COLORREF cr, oldText=0, oldBk=0;
3281 RECT32 rect;
3282 #if 0
3283 HDC32 hMemDC;
3284 int nFontType;
3285 HBITMAP32 hBitmap; /* for later TT usage */
3286 #endif
3287 LPDRAWITEMSTRUCT32 lpdi = (LPDRAWITEMSTRUCT32)lParam;
3289 if (lpdi->itemID == 0xFFFF) /* got no items */
3290 DrawFocusRect32(lpdi->hDC, &lpdi->rcItem);
3291 else
3293 if (lpdi->CtlType == ODT_COMBOBOX)
3295 if (lpdi->itemState ==ODS_SELECTED)
3297 hBrush=GetSysColorBrush32(COLOR_HIGHLIGHT);
3298 oldText=SetTextColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHTTEXT));
3299 oldBk=SetBkColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHT));
3300 } else
3302 hBrush = SelectObject32(lpdi->hDC, GetStockObject32(LTGRAY_BRUSH));
3303 SelectObject32(lpdi->hDC, hBrush);
3305 FillRect32(lpdi->hDC, &lpdi->rcItem, hBrush);
3307 else
3308 return TRUE; /* this should never happen */
3310 rect=lpdi->rcItem;
3311 switch (lpdi->CtlID)
3313 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
3314 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3315 (LPARAM)buffer);
3316 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3317 TextOut32A(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
3318 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3319 #if 0
3320 nFontType = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3321 /* FIXME: draw bitmap if truetype usage */
3322 if (nFontType&TRUETYPE_FONTTYPE)
3324 hMemDC = CreateCompatibleDC32(lpdi->hDC);
3325 hBitmap = SelectObject32(hMemDC, hBitmapTT);
3326 BitBlt32(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
3327 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
3328 SelectObject32(hMemDC, hBitmap);
3329 DeleteDC32(hMemDC);
3331 #endif
3332 break;
3333 case cmb2:
3334 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
3335 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3336 (LPARAM)buffer);
3337 TextOut32A(lpdi->hDC, lpdi->rcItem.left,
3338 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3339 break;
3341 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
3342 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3343 (LPARAM)buffer);
3344 TextOut32A(lpdi->hDC, lpdi->rcItem.left + 25+5,
3345 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3346 cr = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3347 hBrush = CreateSolidBrush32(cr);
3348 if (hBrush)
3350 hBrush = SelectObject32 (lpdi->hDC, hBrush) ;
3351 rect.right=rect.left+25;
3352 rect.top++;
3353 rect.left+=5;
3354 rect.bottom--;
3355 Rectangle32( lpdi->hDC, rect.left, rect.top,
3356 rect.right, rect.bottom );
3357 DeleteObject32( SelectObject32 (lpdi->hDC, hBrush)) ;
3359 rect=lpdi->rcItem;
3360 rect.left+=25+5;
3361 break;
3363 default: return TRUE; /* this should never happen */
3365 if (lpdi->itemState == ODS_SELECTED)
3367 SetTextColor32(lpdi->hDC, oldText);
3368 SetBkColor32(lpdi->hDC, oldBk);
3371 return TRUE;
3374 /***********************************************************************
3375 * CFn_WMCtlColor [internal]
3377 LRESULT CFn_WMCtlColorStatic(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3378 LPCHOOSEFONT32A lpcf)
3380 if (lpcf->Flags & CF_EFFECTS)
3381 if (GetDlgCtrlID32(lParam)==stc6)
3383 SetTextColor32((HDC32)wParam, lpcf->rgbColors);
3384 return GetStockObject32(WHITE_BRUSH);
3386 return 0;
3389 /***********************************************************************
3390 * CFn_WMCommand [internal]
3392 LRESULT CFn_WMCommand(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3393 LPCHOOSEFONT32A lpcf)
3395 HFONT32 hFont;
3396 int i,j;
3397 long l;
3398 HDC32 hdc;
3399 LPLOGFONT32A lpxx=lpcf->lpLogFont;
3401 TRACE(commdlg,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
3402 switch (LOWORD(wParam))
3404 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
3406 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3407 if (hdc)
3409 SendDlgItemMessage32A(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
3410 SendDlgItemMessage32A(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
3411 i=SendDlgItemMessage32A(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
3412 if (i!=CB_ERR)
3414 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3415 CFn_ENUMSTRUCT s;
3416 char str[256];
3417 SendDlgItemMessage32A(hDlg, cmb1, CB_GETLBTEXT32, i,
3418 (LPARAM)str);
3419 TRACE(commdlg,"WM_COMMAND/cmb1 =>%s\n",str);
3420 s.hWnd1=GetDlgItem32(hDlg, cmb2);
3421 s.hWnd2=GetDlgItem32(hDlg, cmb3);
3422 s.lpcf32a=lpcf;
3423 EnumFontFamilies32A(hdc, str, FontStyleEnumProc32, (LPARAM)&s);
3424 SetCursor32(hcursor);
3426 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3427 ReleaseDC32(hDlg,hdc);
3429 else
3431 WARN(commdlg,"HDC failure !!!\n");
3432 EndDialog32 (hDlg, 0);
3433 return TRUE;
3436 case chx1:
3437 case chx2:
3438 case cmb2:
3439 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
3441 char str[256];
3442 TRACE(commdlg,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
3443 i=SendDlgItemMessage32A(hDlg,cmb1,CB_GETCURSEL32,0,0);
3444 if (i==CB_ERR)
3445 i=GetDlgItemText32A( hDlg, cmb1, str, 256 );
3446 else
3448 SendDlgItemMessage32A(hDlg,cmb1,CB_GETLBTEXT32,i,
3449 (LPARAM)str);
3450 l=SendDlgItemMessage32A(hDlg,cmb1,CB_GETITEMDATA32,i,0);
3451 j=HIWORD(l);
3452 lpcf->nFontType = LOWORD(l);
3453 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
3454 /* same value reported to the EnumFonts
3455 call back with the extra FONTTYPE_... bits added */
3456 lpxx->lfPitchAndFamily=j&0xff;
3457 lpxx->lfCharSet=j>>8;
3459 strcpy(lpxx->lfFaceName,str);
3460 i=SendDlgItemMessage32A(hDlg, cmb2, CB_GETCURSEL32, 0, 0);
3461 if (i!=CB_ERR)
3463 l=SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0);
3464 if (0!=(lpxx->lfItalic=HIWORD(l)))
3465 lpcf->nFontType |= ITALIC_FONTTYPE;
3466 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
3467 lpcf->nFontType |= BOLD_FONTTYPE;
3469 i=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCURSEL32, 0, 0);
3470 if (i!=CB_ERR)
3471 lpxx->lfHeight=-LOWORD(SendDlgItemMessage32A(hDlg, cmb3, CB_GETITEMDATA32, i, 0));
3472 else
3473 lpxx->lfHeight=0;
3474 lpxx->lfStrikeOut=IsDlgButtonChecked32(hDlg,chx1);
3475 lpxx->lfUnderline=IsDlgButtonChecked32(hDlg,chx2);
3476 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
3477 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
3478 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
3479 lpxx->lfQuality=DEFAULT_QUALITY;
3480 lpcf->iPointSize= -10*lpxx->lfHeight;
3482 hFont=CreateFontIndirect32A(lpxx);
3483 if (hFont)
3485 HFONT32 oldFont=SendDlgItemMessage32A(hDlg, stc6,
3486 WM_GETFONT, 0, 0);
3487 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,hFont,TRUE);
3488 DeleteObject32(oldFont);
3491 break;
3493 case cmb4:i=SendDlgItemMessage32A(hDlg, cmb4, CB_GETCURSEL32, 0, 0);
3494 if (i!=CB_ERR)
3496 lpcf->rgbColors=textcolors[i];
3497 InvalidateRect32( GetDlgItem32(hDlg,stc6), NULL, 0 );
3499 break;
3501 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
3502 if (lpcf->hwndOwner)
3503 SendMessage32A(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLong32A(hDlg, DWL_USER));
3504 /* if (CFn_HookCallChk(lpcf))
3505 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
3506 break;
3508 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
3509 ( (lpcf->Flags & CF_LIMITSIZE) &&
3510 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
3511 (-lpxx->lfHeight <= lpcf->nSizeMax)))
3512 EndDialog32(hDlg, TRUE);
3513 else
3515 char buffer[80];
3516 sprintf(buffer,"Select a font size between %d and %d points.",
3517 lpcf->nSizeMin,lpcf->nSizeMax);
3518 MessageBox32A(hDlg, buffer, NULL, MB_OK);
3520 return(TRUE);
3521 case IDCANCEL:EndDialog32(hDlg, FALSE);
3522 return(TRUE);
3524 return(FALSE);
3527 static LRESULT CFn_WMDestroy(HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
3529 DeleteObject32(SendDlgItemMessage32A(hwnd, stc6, WM_GETFONT, 0, 0));
3530 return TRUE;
3534 /***********************************************************************
3535 * FormatCharDlgProc16 (COMMDLG.16)
3536 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
3537 2. some CF_.. flags are not supported
3538 3. some TType extensions
3540 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
3541 LPARAM lParam)
3543 LPCHOOSEFONT16 lpcf;
3544 LPCHOOSEFONT32A lpcf32a;
3545 UINT32 uMsg32;
3546 WPARAM32 wParam32;
3547 LRESULT res=0;
3548 if (message!=WM_INITDIALOG)
3550 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3551 if (!lpcf)
3552 return FALSE;
3553 if (CFn_HookCallChk(lpcf))
3554 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
3555 if (res)
3556 return res;
3558 else
3560 lpcf=(LPCHOOSEFONT16)lParam;
3561 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3562 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3564 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3565 return FALSE;
3567 if (CFn_HookCallChk(lpcf))
3568 return CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3570 WINPROC_MapMsg16To32A(message, wParam, &uMsg32, &wParam32, &lParam);
3571 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3572 switch (uMsg32)
3574 case WM_MEASUREITEM:
3575 res=CFn_WMMeasureItem(hDlg, wParam32, lParam);
3576 break;
3577 case WM_DRAWITEM:
3578 res=CFn_WMDrawItem(hDlg, wParam32, lParam);
3579 break;
3580 case WM_CTLCOLORSTATIC:
3581 res=CFn_WMCtlColorStatic(hDlg, wParam32, lParam, lpcf32a);
3582 break;
3583 case WM_COMMAND:
3584 res=CFn_WMCommand(hDlg, wParam32, lParam, lpcf32a);
3585 break;
3586 case WM_DESTROY:
3587 res=CFn_WMDestroy(hDlg, wParam32, lParam);
3588 break;
3589 case WM_CHOOSEFONT_GETLOGFONT:
3590 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3591 lParam);
3592 FIXME(commdlg, "current logfont back to caller\n");
3593 break;
3595 WINPROC_UnmapMsg16To32A(hDlg,uMsg32, wParam32, lParam, res);
3596 return res;
3599 /***********************************************************************
3600 * FormatCharDlgProc32A [internal]
3602 LRESULT WINAPI FormatCharDlgProc32A(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3603 LPARAM lParam)
3605 LPCHOOSEFONT32A lpcf;
3606 LRESULT res=FALSE;
3607 if (uMsg!=WM_INITDIALOG)
3609 lpcf=(LPCHOOSEFONT32A)GetWindowLong32A(hDlg, DWL_USER);
3610 if (!lpcf)
3611 return FALSE;
3612 if (CFn_HookCallChk32(lpcf))
3613 res=CallWindowProc32A(lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
3614 if (res)
3615 return res;
3617 else
3619 lpcf=(LPCHOOSEFONT32A)lParam;
3620 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
3622 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3623 return FALSE;
3625 if (CFn_HookCallChk32(lpcf))
3626 return CallWindowProc32A(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3628 switch (uMsg)
3630 case WM_MEASUREITEM:
3631 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3632 case WM_DRAWITEM:
3633 return CFn_WMDrawItem(hDlg, wParam, lParam);
3634 case WM_CTLCOLORSTATIC:
3635 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
3636 case WM_COMMAND:
3637 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
3638 case WM_DESTROY:
3639 return CFn_WMDestroy(hDlg, wParam, lParam);
3640 case WM_CHOOSEFONT_GETLOGFONT:
3641 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3642 lParam);
3643 FIXME(commdlg, "current logfont back to caller\n");
3644 break;
3646 return res;
3649 /***********************************************************************
3650 * FormatCharDlgProc32W [internal]
3652 LRESULT WINAPI FormatCharDlgProc32W(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3653 LPARAM lParam)
3655 LPCHOOSEFONT32W lpcf32w;
3656 LPCHOOSEFONT32A lpcf32a;
3657 LRESULT res=FALSE;
3658 if (uMsg!=WM_INITDIALOG)
3660 lpcf32w=(LPCHOOSEFONT32W)GetWindowLong32A(hDlg, DWL_USER);
3661 if (!lpcf32w)
3662 return FALSE;
3663 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3664 res=CallWindowProc32W(lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
3665 if (res)
3666 return res;
3668 else
3670 lpcf32w=(LPCHOOSEFONT32W)lParam;
3671 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3672 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3674 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3675 return FALSE;
3677 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3678 return CallWindowProc32W(lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3680 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3681 switch (uMsg)
3683 case WM_MEASUREITEM:
3684 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3685 case WM_DRAWITEM:
3686 return CFn_WMDrawItem(hDlg, wParam, lParam);
3687 case WM_CTLCOLORSTATIC:
3688 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
3689 case WM_COMMAND:
3690 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
3691 case WM_DESTROY:
3692 return CFn_WMDestroy(hDlg, wParam, lParam);
3693 case WM_CHOOSEFONT_GETLOGFONT:
3694 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3695 lParam);
3696 FIXME(commdlg, "current logfont back to caller\n");
3697 break;
3699 return res;
3703 static BOOL32 Commdlg_GetFileName32A( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
3704 LPOPENFILENAME32A ofn )
3706 BOOL16 ret;
3707 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3709 memset(ofn16,'\0',sizeof(*ofn16));
3710 ofn16->lStructSize = sizeof(*ofn16);
3711 ofn16->hwndOwner = ofn->hwndOwner;
3712 ofn16->hInstance = MapHModuleLS(ofn->hInstance);
3713 if (ofn->lpstrFilter) {
3714 LPSTR s,x;
3716 /* filter is a list... title\0ext\0......\0\0 */
3717 s = (LPSTR)ofn->lpstrFilter;
3718 while (*s)
3719 s = s+strlen(s)+1;
3720 s++;
3721 x = (LPSTR)SEGPTR_ALLOC(s-ofn->lpstrFilter);
3722 memcpy(x,ofn->lpstrFilter,s-ofn->lpstrFilter);
3723 ofn16->lpstrFilter = SEGPTR_GET(x);
3725 if (ofn->lpstrCustomFilter) {
3726 LPSTR s,x;
3728 /* filter is a list... title\0ext\0......\0\0 */
3729 s = (LPSTR)ofn->lpstrCustomFilter;
3730 while (*s)
3731 s = s+strlen(s)+1;
3732 s++;
3733 x = SEGPTR_ALLOC(s-ofn->lpstrCustomFilter);
3734 memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);
3735 ofn16->lpstrCustomFilter = SEGPTR_GET(x);
3737 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3738 ofn16->nFilterIndex = ofn->nFilterIndex;
3739 if (ofn->nMaxFile)
3740 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3741 ofn16->nMaxFile = ofn->nMaxFile;
3742 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3743 if (ofn16->nMaxFileTitle)
3744 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3745 if (ofn->lpstrInitialDir)
3746 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrInitialDir));
3747 if (ofn->lpstrTitle)
3748 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrTitle));
3749 ofn16->Flags = ofn->Flags|OFN_WINE32;
3750 ofn16->nFileOffset = ofn->nFileOffset;
3751 ofn16->nFileExtension = ofn->nFileExtension;
3752 if (ofn->lpstrDefExt)
3753 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrDefExt));
3754 ofn16->lCustData = ofn->lCustData;
3755 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3757 if (ofn->lpTemplateName)
3758 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpTemplateName));
3760 ret = dofunction(SEGPTR_GET(ofn16));
3762 ofn->nFileOffset = ofn16->nFileOffset;
3763 ofn->nFileExtension = ofn16->nFileExtension;
3764 if (ofn16->lpstrFilter)
3765 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3766 if (ofn16->lpTemplateName)
3767 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3768 if (ofn16->lpstrDefExt)
3769 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3770 if (ofn16->lpstrTitle)
3771 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3772 if (ofn16->lpstrInitialDir)
3773 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3774 if (ofn16->lpstrCustomFilter)
3775 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3777 if (ofn16->lpstrFile)
3779 strcpy(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3780 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3783 if (ofn16->lpstrFileTitle)
3785 strcpy(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3786 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3788 SEGPTR_FREE(ofn16);
3789 return ret;
3792 static BOOL32 Commdlg_GetFileName32W( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
3793 LPOPENFILENAME32W ofn )
3795 BOOL16 ret;
3796 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3798 memset(ofn16,'\0',sizeof(*ofn16));
3799 ofn16->lStructSize = sizeof(*ofn16);
3800 ofn16->hwndOwner = ofn->hwndOwner;
3801 ofn16->hInstance = MapHModuleLS(ofn->hInstance);
3802 if (ofn->lpstrFilter) {
3803 LPWSTR s;
3804 LPSTR x,y;
3805 int n;
3807 /* filter is a list... title\0ext\0......\0\0 */
3808 s = (LPWSTR)ofn->lpstrFilter;
3809 while (*s)
3810 s = s+lstrlen32W(s)+1;
3811 s++;
3812 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
3813 x = y = (LPSTR)SEGPTR_ALLOC(n);
3814 s = (LPWSTR)ofn->lpstrFilter;
3815 while (*s) {
3816 lstrcpyWtoA(x,s);
3817 x+=lstrlen32A(x)+1;
3818 s+=lstrlen32W(s)+1;
3820 *x=0;
3821 ofn16->lpstrFilter = SEGPTR_GET(y);
3823 if (ofn->lpstrCustomFilter) {
3824 LPWSTR s;
3825 LPSTR x,y;
3826 int n;
3828 /* filter is a list... title\0ext\0......\0\0 */
3829 s = (LPWSTR)ofn->lpstrCustomFilter;
3830 while (*s)
3831 s = s+lstrlen32W(s)+1;
3832 s++;
3833 n = s - ofn->lpstrCustomFilter;
3834 x = y = (LPSTR)SEGPTR_ALLOC(n);
3835 s = (LPWSTR)ofn->lpstrCustomFilter;
3836 while (*s) {
3837 lstrcpyWtoA(x,s);
3838 x+=lstrlen32A(x)+1;
3839 s+=lstrlen32W(s)+1;
3841 *x=0;
3842 ofn16->lpstrCustomFilter = SEGPTR_GET(y);
3844 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3845 ofn16->nFilterIndex = ofn->nFilterIndex;
3846 if (ofn->nMaxFile)
3847 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3848 ofn16->nMaxFile = ofn->nMaxFile;
3849 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3850 if (ofn->nMaxFileTitle)
3851 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3852 if (ofn->lpstrInitialDir)
3853 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrInitialDir));
3854 if (ofn->lpstrTitle)
3855 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrTitle));
3856 ofn16->Flags = ofn->Flags|OFN_WINE32|OFN_UNICODE;
3857 ofn16->nFileOffset = ofn->nFileOffset;
3858 ofn16->nFileExtension = ofn->nFileExtension;
3859 if (ofn->lpstrDefExt)
3860 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrDefExt));
3861 ofn16->lCustData = ofn->lCustData;
3862 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3863 if (ofn->lpTemplateName)
3864 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpTemplateName));
3865 ret = dofunction(SEGPTR_GET(ofn16));
3867 ofn->nFileOffset = ofn16->nFileOffset;
3868 ofn->nFileExtension = ofn16->nFileExtension;
3869 if (ofn16->lpstrFilter)
3870 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3871 if (ofn16->lpTemplateName)
3872 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3873 if (ofn16->lpstrDefExt)
3874 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3875 if (ofn16->lpstrTitle)
3876 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3877 if (ofn16->lpstrInitialDir)
3878 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3879 if (ofn16->lpstrCustomFilter)
3880 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3882 if (ofn16->lpstrFile) {
3883 lstrcpyAtoW(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3884 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3887 if (ofn16->lpstrFileTitle) {
3888 lstrcpyAtoW(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3889 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3891 SEGPTR_FREE(ofn16);
3892 return ret;
3895 /***********************************************************************
3896 * GetOpenFileName32A (COMDLG32.10)
3898 BOOL32 WINAPI GetOpenFileName32A( LPOPENFILENAME32A ofn )
3900 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3901 return Commdlg_GetFileName32A(dofunction,ofn);
3904 /***********************************************************************
3905 * GetOpenFileName32W (COMDLG32.11)
3907 BOOL32 WINAPI GetOpenFileName32W( LPOPENFILENAME32W ofn )
3909 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3910 return Commdlg_GetFileName32W(dofunction,ofn);
3913 /***********************************************************************
3914 * GetSaveFileName32A (COMDLG32.12)
3916 BOOL32 WINAPI GetSaveFileName32A( LPOPENFILENAME32A ofn )
3918 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3919 return Commdlg_GetFileName32A(dofunction,ofn);
3922 /***********************************************************************
3923 * GetSaveFileName32W (COMDLG32.13)
3925 BOOL32 WINAPI GetSaveFileName32W( LPOPENFILENAME32W ofn )
3927 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3928 return Commdlg_GetFileName32W(dofunction,ofn);
3931 /***********************************************************************
3932 * ChooseColorA (COMDLG32.1)
3934 BOOL32 WINAPI ChooseColor32A(LPCHOOSECOLOR32A lpChCol )
3937 BOOL16 ret;
3938 char *str = NULL;
3939 COLORREF* ccref=SEGPTR_ALLOC(64);
3940 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3942 memset(lpcc16,'\0',sizeof(*lpcc16));
3943 lpcc16->lStructSize=sizeof(*lpcc16);
3944 lpcc16->hwndOwner=lpChCol->hwndOwner;
3945 lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
3946 lpcc16->rgbResult=lpChCol->rgbResult;
3947 memcpy(ccref,lpChCol->lpCustColors,64);
3948 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3949 lpcc16->Flags=lpChCol->Flags;
3950 lpcc16->lCustData=lpChCol->lCustData;
3951 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3952 if (lpChCol->lpTemplateName)
3953 str = SEGPTR_STRDUP(lpChCol->lpTemplateName );
3954 lpcc16->lpTemplateName=SEGPTR_GET(str);
3956 ret = ChooseColor16(lpcc16);
3957 if(str)
3958 SEGPTR_FREE(str);
3959 memcpy(lpChCol->lpCustColors,ccref,64);
3960 SEGPTR_FREE(ccref);
3961 SEGPTR_FREE(lpcc16);
3962 return (BOOL32)ret;
3965 /***********************************************************************
3966 * ChooseColorW (COMDLG32.2)
3968 BOOL32 WINAPI ChooseColor32W(LPCHOOSECOLOR32W lpChCol )
3971 BOOL16 ret;
3972 char *str = NULL;
3973 COLORREF* ccref=SEGPTR_ALLOC(64);
3974 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3976 memset(lpcc16,'\0',sizeof(*lpcc16));
3977 lpcc16->lStructSize=sizeof(*lpcc16);
3978 lpcc16->hwndOwner=lpChCol->hwndOwner;
3979 lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
3980 lpcc16->rgbResult=lpChCol->rgbResult;
3981 memcpy(ccref,lpChCol->lpCustColors,64);
3982 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3983 lpcc16->Flags=lpChCol->Flags;
3984 lpcc16->lCustData=lpChCol->lCustData;
3985 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3986 if (lpChCol->lpTemplateName)
3987 str = SEGPTR_STRDUP_WtoA(lpChCol->lpTemplateName );
3988 lpcc16->lpTemplateName=SEGPTR_GET(str);
3990 ret = ChooseColor16(lpcc16);
3991 if(str)
3992 SEGPTR_FREE(str);
3993 memcpy(lpChCol->lpCustColors,ccref,64);
3994 SEGPTR_FREE(ccref);
3995 SEGPTR_FREE(lpcc16);
3996 return (BOOL32)ret;
3999 /***********************************************************************
4000 * PageSetupDlgA (COMDLG32.15)
4002 BOOL32 WINAPI PageSetupDlg32A(LPPAGESETUPDLG32A setupdlg) {
4003 FIXME(commdlg,"(%p), stub!\n",setupdlg);
4004 return FALSE;