Release 980726
[wine/multimedia.git] / misc / commdlg.c
blobdb21377f688894e28ee778099608427a07723113
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
8 #include <stdlib.h>
9 #include <string.h>
10 #include "win.h"
11 #include "heap.h"
12 #include "message.h"
13 #include "commdlg.h"
14 #include "dialog.h"
15 #include "dlgs.h"
16 #include "module.h"
17 #include "resource.h"
18 #include "drive.h"
19 #include "debug.h"
20 #include "font.h"
21 #include "winproc.h"
23 static DWORD CommDlgLastError = 0;
25 static HBITMAP16 hFolder = 0;
26 static HBITMAP16 hFolder2 = 0;
27 static HBITMAP16 hFloppy = 0;
28 static HBITMAP16 hHDisk = 0;
29 static HBITMAP16 hCDRom = 0;
30 static HBITMAP16 hBitmapTT = 0;
31 static const char defaultfilter[]=" \0\0";
33 /***********************************************************************
34 * FileDlg_Init [internal]
36 static BOOL32 FileDlg_Init()
38 static BOOL32 initialized = 0;
40 if (!initialized) {
41 if (!hFolder) hFolder = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER));
42 if (!hFolder2) hFolder2 = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER2));
43 if (!hFloppy) hFloppy = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FLOPPY));
44 if (!hHDisk) hHDisk = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_HDISK));
45 if (!hCDRom) hCDRom = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CDROM));
46 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
47 hHDisk == 0 || hCDRom == 0)
49 WARN(commdlg, "Error loading bitmaps !\nprin");
50 return FALSE;
52 initialized = TRUE;
54 return TRUE;
57 /***********************************************************************
58 * GetOpenFileName (COMMDLG.1)
60 BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
62 HINSTANCE32 hInst;
63 HANDLE32 hDlgTmpl = 0, hResInfo;
64 BOOL32 bRet = FALSE, win32Format = FALSE;
65 HWND32 hwndDialog;
66 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
67 LPCVOID template;
68 char defaultopen[]="Open File";
69 char *str=0,*str1=0;
71 if (!lpofn || !FileDlg_Init()) return FALSE;
73 if (lpofn->Flags & OFN_WINE32) {
74 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
76 if (!(template = LockResource32( lpofn->hInstance )))
78 CommDlgLastError = CDERR_LOADRESFAILURE;
79 return FALSE;
82 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
84 if (!(hResInfo = FindResource32A(lpofn->hInstance,
85 PTR_SEG_TO_LIN(lpofn->lpTemplateName), RT_DIALOG32A)))
87 CommDlgLastError = CDERR_FINDRESFAILURE;
88 return FALSE;
90 if (!(hDlgTmpl = LoadResource32( lpofn->hInstance, hResInfo )) ||
91 !(template = LockResource32( hDlgTmpl )))
93 CommDlgLastError = CDERR_LOADRESFAILURE;
94 return FALSE;
96 } else {
97 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
99 win32Format = TRUE;
100 } else {
101 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
103 if (!(template = LockResource16( lpofn->hInstance )))
105 CommDlgLastError = CDERR_LOADRESFAILURE;
106 return FALSE;
109 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
111 if (!(hResInfo = FindResource16(lpofn->hInstance,
112 lpofn->lpTemplateName,
113 RT_DIALOG16)))
115 CommDlgLastError = CDERR_FINDRESFAILURE;
116 return FALSE;
118 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
119 !(template = LockResource16( hDlgTmpl )))
121 CommDlgLastError = CDERR_LOADRESFAILURE;
122 return FALSE;
124 } else {
125 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
126 win32Format = TRUE;
130 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
132 if (!(lpofn->lpstrFilter))
134 str = SEGPTR_ALLOC(sizeof(defaultfilter));
135 TRACE(commdlg,"Alloc %p default for Filetype in GetOpenFileName\n",str);
136 memcpy(str,defaultfilter,sizeof(defaultfilter));
137 lpofn->lpstrFilter=SEGPTR_GET(str);
140 if (!(lpofn->lpstrTitle))
142 str1 = SEGPTR_ALLOC(strlen(defaultopen)+1);
143 TRACE(commdlg,"Alloc %p default for Title in GetOpenFileName\n",str1);
144 strcpy(str1,defaultopen);
145 lpofn->lpstrTitle=SEGPTR_GET(str1);
148 /* FIXME: doesn't handle win32 format correctly yet */
149 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
150 lpofn->hwndOwner,
151 (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
152 ofn, WIN_PROC_16 );
153 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
155 if (str1)
157 TRACE(commdlg,"Freeing %p default for Title in GetOpenFileName\n",str1);
158 SEGPTR_FREE(str1);
159 lpofn->lpstrTitle=0;
162 if (str)
164 TRACE(commdlg,"Freeing %p default for Filetype in GetOpenFileName\n",str);
165 SEGPTR_FREE(str);
166 lpofn->lpstrFilter=0;
169 if (hDlgTmpl) {
170 if (lpofn->Flags & OFN_WINE32)
171 FreeResource32( hDlgTmpl );
172 else
173 FreeResource16( hDlgTmpl );
176 TRACE(commdlg,"return lpstrFile='%s' !\n",
177 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
178 return bRet;
182 /***********************************************************************
183 * GetSaveFileName (COMMDLG.2)
185 BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
187 HINSTANCE32 hInst;
188 HANDLE32 hDlgTmpl = 0;
189 BOOL32 bRet = FALSE, win32Format = FALSE;
190 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
191 LPCVOID template;
192 HWND32 hwndDialog;
193 char defaultsave[]="Save as";
194 char *str =0,*str1=0;
196 if (!lpofn || !FileDlg_Init()) return FALSE;
198 if (lpofn->Flags & OFN_WINE32) {
199 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
201 if (!(template = LockResource32( lpofn->hInstance )))
203 CommDlgLastError = CDERR_LOADRESFAILURE;
204 return FALSE;
207 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
209 HANDLE32 hResInfo;
210 if (!(hResInfo = FindResource32A(lpofn->hInstance,
211 PTR_SEG_TO_LIN(lpofn->lpTemplateName),
212 RT_DIALOG32A)))
214 CommDlgLastError = CDERR_FINDRESFAILURE;
215 return FALSE;
217 if (!(hDlgTmpl = LoadResource32(lpofn->hInstance,hResInfo)) ||
218 !(template = LockResource32(hDlgTmpl)))
220 CommDlgLastError = CDERR_LOADRESFAILURE;
221 return FALSE;
223 win32Format= TRUE;
224 } else {
225 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
226 win32Format = TRUE;
228 } else {
229 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
231 if (!(template = LockResource16( lpofn->hInstance )))
233 CommDlgLastError = CDERR_LOADRESFAILURE;
234 return FALSE;
237 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
239 HANDLE16 hResInfo;
240 if (!(hResInfo = FindResource16(lpofn->hInstance,
241 lpofn->lpTemplateName,
242 RT_DIALOG16)))
244 CommDlgLastError = CDERR_FINDRESFAILURE;
245 return FALSE;
247 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
248 !(template = LockResource16( hDlgTmpl )))
250 CommDlgLastError = CDERR_LOADRESFAILURE;
251 return FALSE;
253 } else {
254 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
255 win32Format = TRUE;
259 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
261 if (!(lpofn->lpstrFilter))
263 str = SEGPTR_ALLOC(sizeof(defaultfilter));
264 TRACE(commdlg,"Alloc default for Filetype in GetSaveFileName\n");
265 memcpy(str,defaultfilter,sizeof(defaultfilter));
266 lpofn->lpstrFilter=SEGPTR_GET(str);
269 if (!(lpofn->lpstrTitle))
271 str1 = SEGPTR_ALLOC(sizeof(defaultsave)+1);
272 TRACE(commdlg,"Alloc default for Title in GetSaveFileName\n");
273 strcpy(str1,defaultsave);
274 lpofn->lpstrTitle=SEGPTR_GET(str1);
277 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
278 lpofn->hwndOwner,
279 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
280 ofn, WIN_PROC_16 );
281 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
283 if (str1)
285 TRACE(commdlg,"Freeing %p default for Title in GetSaveFileName\n",str1);
286 SEGPTR_FREE(str1);
287 lpofn->lpstrTitle=0;
290 if (str)
292 TRACE(commdlg,"Freeing %p default for Filetype in GetSaveFileName\n",str);
293 SEGPTR_FREE(str);
294 lpofn->lpstrFilter=0;
297 if (hDlgTmpl) {
298 if (lpofn->Flags & OFN_WINE32)
299 FreeResource32( hDlgTmpl );
300 else
301 FreeResource16( hDlgTmpl );
304 TRACE(commdlg, "return lpstrFile='%s' !\n",
305 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
306 return bRet;
309 /***********************************************************************
310 * FILEDLG_StripEditControl [internal]
311 * Strip pathnames off the contents of the edit control.
313 static void FILEDLG_StripEditControl(HWND16 hwnd)
315 char temp[512], *cp;
317 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
318 cp = strrchr(temp, '\\');
319 if (cp != NULL) {
320 strcpy(temp, cp+1);
322 cp = strrchr(temp, ':');
323 if (cp != NULL) {
324 strcpy(temp, cp+1);
326 /* FIXME: shouldn't we do something with the result here? ;-) */
329 /***********************************************************************
330 * FILEDLG_ScanDir [internal]
332 static BOOL32 FILEDLG_ScanDir(HWND16 hWnd, LPSTR newPath)
334 int len;
335 char str[512];
337 lstrcpyn32A( str, newPath, 512 );
338 len = strlen(str);
339 GetDlgItemText32A( hWnd, edt1, str + len, sizeof(str) - len );
340 if (!DlgDirList32A( hWnd, str, lst1, 0, 0x0000 )) return FALSE;
341 strcpy( str, "*.*" );
342 return DlgDirList32A( hWnd, str, lst2, stc1, 0x8010 );
345 /***********************************************************************
346 * FILEDLG_GetFileType [internal]
349 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
351 int n, i;
352 i = 0;
353 if (cfptr)
354 for ( ;(n = strlen(cfptr)) != 0; i++)
356 cfptr += n + 1;
357 if (i == index)
358 return cfptr;
359 cfptr += strlen(cfptr) + 1;
361 if (fptr)
362 for ( ;(n = strlen(fptr)) != 0; i++)
364 fptr += n + 1;
365 if (i == index)
366 return fptr;
367 fptr += strlen(fptr) + 1;
369 return "*.*"; /* FIXME */
372 /***********************************************************************
373 * FILEDLG_WMDrawItem [internal]
375 static LONG FILEDLG_WMDrawItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam,int savedlg)
377 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
378 char *str;
379 HBRUSH32 hBrush;
380 HBITMAP16 hBitmap, hPrevBitmap;
381 BITMAP16 bm;
382 HDC32 hMemDC;
384 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
386 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
387 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
388 SelectObject32(lpdis->hDC, hBrush);
389 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
390 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
391 (LPARAM)SEGPTR_GET(str));
393 if (savedlg) /* use _gray_ text in FileSaveDlg */
394 if (!lpdis->itemState)
395 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_GRAYTEXT) );
396 else
397 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_WINDOWTEXT) );
398 /* inversion of gray would be bad readable */
400 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
401 str, strlen(str));
402 if (lpdis->itemState != 0) {
403 InvertRect16(lpdis->hDC, &lpdis->rcItem);
405 SEGPTR_FREE(str);
406 return TRUE;
409 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
411 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
412 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
413 SelectObject32(lpdis->hDC, hBrush);
414 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
415 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
416 (LPARAM)SEGPTR_GET(str));
418 hBitmap = hFolder;
419 GetObject16( hBitmap, sizeof(bm), &bm );
420 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
421 lpdis->rcItem.top, str, strlen(str));
422 hMemDC = CreateCompatibleDC32(lpdis->hDC);
423 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
424 BitBlt32(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
425 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
426 SelectObject32(hMemDC, hPrevBitmap);
427 DeleteDC32(hMemDC);
428 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
429 SEGPTR_FREE(str);
430 return TRUE;
432 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
434 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
435 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
436 SelectObject32(lpdis->hDC, hBrush);
437 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
438 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT16, lpdis->itemID,
439 (LPARAM)SEGPTR_GET(str));
440 switch(DRIVE_GetType( str[2] - 'a' ))
442 case TYPE_FLOPPY: hBitmap = hFloppy; break;
443 case TYPE_CDROM: hBitmap = hCDRom; break;
444 case TYPE_HD:
445 case TYPE_NETWORK:
446 default: hBitmap = hHDisk; break;
448 GetObject16( hBitmap, sizeof(bm), &bm );
449 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
450 lpdis->rcItem.top, str, strlen(str));
451 hMemDC = CreateCompatibleDC32(lpdis->hDC);
452 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
453 BitBlt32( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
454 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
455 SelectObject32(hMemDC, hPrevBitmap);
456 DeleteDC32(hMemDC);
457 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
458 SEGPTR_FREE(str);
459 return TRUE;
461 return FALSE;
464 /***********************************************************************
465 * FILEDLG_WMMeasureItem [internal]
467 static LONG FILEDLG_WMMeasureItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
469 BITMAP16 bm;
470 LPMEASUREITEMSTRUCT16 lpmeasure;
472 GetObject16( hFolder2, sizeof(bm), &bm );
473 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
474 lpmeasure->itemHeight = bm.bmHeight;
475 return TRUE;
478 /***********************************************************************
479 * FILEDLG_HookCallChk [internal]
481 static int FILEDLG_HookCallChk(LPOPENFILENAME16 lpofn)
483 if (lpofn)
484 if (lpofn->Flags & OFN_ENABLEHOOK)
485 if (lpofn->lpfnHook)
486 return 1;
487 return 0;
490 /***********************************************************************
491 * FILEDLG_CallWindowProc [internal]
493 * Adapt the structures back for win32 calls so the callee can read lpCustData
495 static BOOL32 FILEDLG_CallWindowProc(LPOPENFILENAME16 lpofn,HWND32 hwnd,
496 UINT32 wMsg,WPARAM32 wParam,LPARAM lParam
499 BOOL32 needstruct;
501 needstruct = (PTR_SEG_TO_LIN(lParam) == lpofn);
503 if (!(lpofn->Flags & OFN_WINE32))
504 return (BOOL32)CallWindowProc16(
505 lpofn->lpfnHook,hwnd,(UINT16)wMsg,(WPARAM16)wParam,lParam
507 /* |OFN_WINE32 */
508 if (lpofn->Flags & OFN_UNICODE) {
509 if (needstruct) {
510 OPENFILENAME32W ofnw;
512 /* FIXME: probably needs more converted */
513 ofnw.lCustData = lpofn->lCustData;
514 return (BOOL32)CallWindowProc32W(
515 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofnw
517 } else
518 return (BOOL32)CallWindowProc32W(
519 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
522 /* ! |OFN_UNICODE */
523 if (needstruct) {
524 OPENFILENAME32A ofna;
526 /* FIXME: probably needs more converted */
527 ofna.lCustData = lpofn->lCustData;
528 return (BOOL32)CallWindowProc32A(
529 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofna
531 } else
532 return (BOOL32)CallWindowProc32A(
533 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
538 /***********************************************************************
539 * FILEDLG_WMInitDialog [internal]
542 static LONG FILEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
544 int i, n;
545 LPOPENFILENAME16 lpofn;
546 char tmpstr[512];
547 LPSTR pstr, old_pstr;
548 SetWindowLong32A(hWnd, DWL_USER, lParam);
549 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(lParam);
550 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
551 /* read custom filter information */
552 if (lpofn->lpstrCustomFilter)
554 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
555 n = 0;
556 TRACE(commdlg,"lpstrCustomFilter = %p\n", pstr);
557 while(*pstr)
559 old_pstr = pstr;
560 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
561 (LPARAM)lpofn->lpstrCustomFilter + n );
562 n += strlen(pstr) + 1;
563 pstr += strlen(pstr) + 1;
564 TRACE(commdlg,"add str='%s' "
565 "associated to '%s'\n", old_pstr, pstr);
566 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
567 n += strlen(pstr) + 1;
568 pstr += strlen(pstr) + 1;
571 /* read filter information */
572 if (lpofn->lpstrFilter) {
573 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
574 n = 0;
575 while(*pstr) {
576 old_pstr = pstr;
577 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
578 (LPARAM)lpofn->lpstrFilter + n );
579 n += strlen(pstr) + 1;
580 pstr += strlen(pstr) + 1;
581 TRACE(commdlg,"add str='%s' "
582 "associated to '%s'\n", old_pstr, pstr);
583 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
584 n += strlen(pstr) + 1;
585 pstr += strlen(pstr) + 1;
588 /* set default filter */
589 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
590 lpofn->nFilterIndex = 1;
591 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL16, lpofn->nFilterIndex - 1, 0);
592 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
593 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
594 tmpstr[511]=0;
595 TRACE(commdlg,"nFilterIndex = %ld, SetText of edt1 to '%s'\n",
596 lpofn->nFilterIndex, tmpstr);
597 SetDlgItemText32A( hWnd, edt1, tmpstr );
598 /* get drive list */
599 *tmpstr = 0;
600 DlgDirListComboBox32A(hWnd, tmpstr, cmb2, 0, 0xC000);
601 /* read initial directory */
602 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
604 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
605 tmpstr[510]=0;
606 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
607 && tmpstr[strlen(tmpstr)-1] != ':')
608 strcat(tmpstr,"\\");
610 else
611 *tmpstr = 0;
612 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
613 *tmpstr = 0;
614 if (!FILEDLG_ScanDir(hWnd, tmpstr))
615 WARN(commdlg, "Couldn't read initial directory %s!\n",tmpstr);
617 /* select current drive in combo 2, omit missing drives */
618 for(i=0, n=-1; i<=DRIVE_GetCurrentDrive(); i++)
619 if (DRIVE_IsValid(i)) n++;
620 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL16, n, 0);
621 if (!(lpofn->Flags & OFN_SHOWHELP))
622 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
623 if (lpofn->Flags & OFN_HIDEREADONLY)
624 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
625 if (FILEDLG_HookCallChk(lpofn))
626 return (BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,WM_INITDIALOG,wParam,lParam );
627 else
628 return TRUE;
631 /***********************************************************************
632 * FILEDLG_WMCommand [internal]
634 BOOL32 in_update=FALSE;
636 static LRESULT FILEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
638 LONG lRet;
639 LPOPENFILENAME16 lpofn;
640 OPENFILENAME16 ofn2;
641 char tmpstr[512], tmpstr2[512];
642 LPSTR pstr, pstr2;
643 UINT16 control,notification;
645 /* Notifications are packaged differently in Win32 */
646 control = wParam;
647 notification = HIWORD(lParam);
649 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
650 switch (control)
652 case lst1: /* file list */
653 FILEDLG_StripEditControl(hWnd);
654 if (notification == LBN_DBLCLK)
655 goto almost_ok;
656 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
657 if (lRet == LB_ERR) return TRUE;
658 if ((pstr = SEGPTR_ALLOC(512)))
660 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
661 (LPARAM)SEGPTR_GET(pstr));
662 SetDlgItemText32A( hWnd, edt1, pstr );
663 SEGPTR_FREE(pstr);
665 if (FILEDLG_HookCallChk(lpofn))
666 FILEDLG_CallWindowProc(lpofn,hWnd,
667 RegisterWindowMessage32A( LBSELCHSTRING ),
668 control, MAKELONG(lRet,CD_LBSELCHANGE));
669 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
670 return TRUE;
671 case lst2: /* directory list */
672 FILEDLG_StripEditControl(hWnd);
673 if (notification == LBN_DBLCLK)
675 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
676 if (lRet == LB_ERR) return TRUE;
677 pstr = SEGPTR_ALLOC(512);
678 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
679 (LPARAM)SEGPTR_GET(pstr));
680 strcpy( tmpstr, pstr );
681 SEGPTR_FREE(pstr);
682 if (tmpstr[0] == '[')
684 tmpstr[strlen(tmpstr) - 1] = 0;
685 strcpy(tmpstr,tmpstr+1);
687 strcat(tmpstr, "\\");
688 goto reset_scan;
690 return TRUE;
691 case cmb1: /* file type drop list */
692 if (notification == CBN_SELCHANGE)
694 *tmpstr = 0;
695 goto reset_scan;
697 return TRUE;
698 case chx1:
699 return TRUE;
700 case pshHelp:
701 return TRUE;
702 case cmb2: /* disk drop list */
703 FILEDLG_StripEditControl(hWnd);
704 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL16, 0, 0L);
705 if (lRet == LB_ERR) return 0;
706 pstr = SEGPTR_ALLOC(512);
707 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT16, lRet,
708 (LPARAM)SEGPTR_GET(pstr));
709 sprintf(tmpstr, "%c:", pstr[2]);
710 SEGPTR_FREE(pstr);
711 reset_scan:
712 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
713 if (lRet == LB_ERR)
714 return TRUE;
715 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA16, lRet, 0);
716 TRACE(commdlg,"Selected filter : %s\n", pstr);
717 SetDlgItemText32A( hWnd, edt1, pstr );
718 FILEDLG_ScanDir(hWnd, tmpstr);
719 in_update=TRUE;
720 case IDOK:
721 almost_ok:
722 ofn2=*lpofn; /* for later restoring */
723 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
724 pstr = strrchr(tmpstr, '\\');
725 if (pstr == NULL)
726 pstr = strrchr(tmpstr, ':');
727 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
729 /* edit control contains wildcards */
730 if (pstr != NULL)
732 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
733 *(pstr+1) = 0;
735 else
737 strcpy(tmpstr2, tmpstr);
738 *tmpstr=0;
740 TRACE(commdlg,"tmpstr=%s, tmpstr2=%s\n", tmpstr, tmpstr2);
741 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
742 FILEDLG_ScanDir(hWnd, tmpstr);
743 return TRUE;
745 /* no wildcards, we might have a directory or a filename */
746 /* try appending a wildcard and reading the directory */
747 pstr2 = tmpstr + strlen(tmpstr);
748 if (pstr == NULL || *(pstr+1) != 0)
749 strcat(tmpstr, "\\");
750 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
751 if (lRet == LB_ERR) return TRUE;
752 lpofn->nFilterIndex = lRet + 1;
753 TRACE(commdlg,"lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
754 lstrcpyn32A(tmpstr2,
755 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
756 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
757 lRet), sizeof(tmpstr2));
758 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
759 if (!in_update)
760 /* if ScanDir succeeds, we have changed the directory */
761 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
762 /* if not, this must be a filename */
763 *pstr2 = 0;
764 if (pstr != NULL)
766 /* strip off the pathname */
767 *pstr = 0;
768 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
769 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
770 /* Should we MessageBox() if this fails? */
771 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
772 strcpy(tmpstr, tmpstr2);
774 else SetDlgItemText32A( hWnd, edt1, tmpstr );
775 #if 0
776 ShowWindow16(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
777 #endif
779 int drive = DRIVE_GetCurrentDrive();
780 tmpstr2[0] = 'A'+ drive;
781 tmpstr2[1] = ':';
782 tmpstr2[2] = '\\';
783 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
784 if (strlen(tmpstr2) > 3)
785 strcat(tmpstr2, "\\");
786 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
787 if (lpofn->lpstrFile)
788 lstrcpyn32A(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2,lpofn->nMaxFile);
790 lpofn->nFileOffset = strrchr(tmpstr2,'\\') - tmpstr2 +1;
791 lpofn->nFileExtension = 0;
792 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
793 lpofn->nFileExtension++;
794 if (lpofn->nFileExtension == '\0')
795 lpofn->nFileExtension = 0;
796 else
797 lpofn->nFileExtension++;
799 if(in_update)
801 if (FILEDLG_HookCallChk(lpofn))
802 FILEDLG_CallWindowProc(lpofn,hWnd,
803 RegisterWindowMessage32A( LBSELCHSTRING ),
804 control, MAKELONG(lRet,CD_LBSELCHANGE));
806 in_update = FALSE;
807 return TRUE;
809 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
811 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
812 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
813 lpofn->lpstrFileTitle );
815 if (FILEDLG_HookCallChk(lpofn))
817 lRet= (BOOL16)FILEDLG_CallWindowProc(lpofn,
818 hWnd, RegisterWindowMessage32A( FILEOKSTRING ), 0, lParam );
819 if (lRet)
821 *lpofn=ofn2; /* restore old state */
822 #if 0
823 ShowWindow16(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
824 #endif
825 break;
828 EndDialog32(hWnd, TRUE);
829 return TRUE;
830 case IDCANCEL:
831 EndDialog32(hWnd, FALSE);
832 return TRUE;
834 return FALSE;
838 /***********************************************************************
839 * FileOpenDlgProc (COMMDLG.6)
841 LRESULT WINAPI FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
842 LPARAM lParam)
844 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
846 if (wMsg!=WM_INITDIALOG)
847 if (FILEDLG_HookCallChk(lpofn))
849 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
850 if (lRet)
851 return lRet; /* else continue message processing */
853 switch (wMsg)
855 case WM_INITDIALOG:
856 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
857 case WM_MEASUREITEM:
858 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
859 case WM_DRAWITEM:
860 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
861 case WM_COMMAND:
862 return FILEDLG_WMCommand(hWnd, wParam, lParam);
863 #if 0
864 case WM_CTLCOLOR:
865 SetBkColor((HDC16)wParam, 0x00C0C0C0);
866 switch (HIWORD(lParam))
868 case CTLCOLOR_BTN:
869 SetTextColor((HDC16)wParam, 0x00000000);
870 return hGRAYBrush;
871 case CTLCOLOR_STATIC:
872 SetTextColor((HDC16)wParam, 0x00000000);
873 return hGRAYBrush;
875 break;
876 #endif
878 return FALSE;
882 /***********************************************************************
883 * FileSaveDlgProc (COMMDLG.7)
885 LRESULT WINAPI FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
886 LPARAM lParam)
888 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
890 if (wMsg!=WM_INITDIALOG)
891 if (FILEDLG_HookCallChk(lpofn))
893 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
894 if (lRet)
895 return lRet; /* else continue message processing */
897 switch (wMsg) {
898 case WM_INITDIALOG:
899 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
901 case WM_MEASUREITEM:
902 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
904 case WM_DRAWITEM:
905 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
907 case WM_COMMAND:
908 return FILEDLG_WMCommand(hWnd, wParam, lParam);
912 case WM_CTLCOLOR:
913 SetBkColor((HDC16)wParam, 0x00C0C0C0);
914 switch (HIWORD(lParam))
916 case CTLCOLOR_BTN:
917 SetTextColor((HDC16)wParam, 0x00000000);
918 return hGRAYBrush;
919 case CTLCOLOR_STATIC:
920 SetTextColor((HDC16)wParam, 0x00000000);
921 return hGRAYBrush;
923 return FALSE;
926 return FALSE;
930 /***********************************************************************
931 * FindText16 (COMMDLG.11)
933 HWND16 WINAPI FindText16( SEGPTR find )
935 HANDLE16 hInst;
936 LPCVOID ptr;
937 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
940 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
941 * For now, only the standard dialog works.
943 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
944 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
945 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
946 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
947 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
948 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
949 find, WIN_PROC_16 );
952 /***********************************************************************
953 * FindText32A (COMMDLG.6)
955 HWND32 WINAPI FindText32A( LPFINDREPLACE32A lpFind )
957 HANDLE16 hInst;
958 LPCVOID ptr;
961 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
962 * For now, only the standard dialog works.
964 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
965 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
966 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
967 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
968 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
969 (DLGPROC16)FindTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
972 /***********************************************************************
973 * FindText32W (COMMDLG.7)
975 HWND32 WINAPI FindText32W( LPFINDREPLACE32W lpFind )
977 HANDLE16 hInst;
978 LPCVOID ptr;
981 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
982 * For now, only the standard dialog works.
984 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
985 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
986 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
987 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
988 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
989 (DLGPROC16)FindTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
992 /***********************************************************************
993 * ReplaceText16 (COMMDLG.12)
995 HWND16 WINAPI ReplaceText16( SEGPTR find )
997 HANDLE16 hInst;
998 LPCVOID ptr;
999 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
1002 * FIXME : We should do error checking on the lpFind structure here
1003 * and make CommDlgExtendedError() return the error condition.
1005 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1006 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1007 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1008 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1009 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1010 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
1011 find, WIN_PROC_16 );
1014 /***********************************************************************
1015 * ReplaceText32A (COMDLG32.19)
1017 HWND32 WINAPI ReplaceText32A( LPFINDREPLACE32A lpFind )
1019 HANDLE16 hInst;
1020 LPCVOID ptr;
1023 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1024 * For now, only the standard dialog works.
1026 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1027 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1028 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1029 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1030 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1031 (DLGPROC16)ReplaceTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
1034 /***********************************************************************
1035 * ReplaceText32W (COMDLG32.20)
1037 HWND32 WINAPI ReplaceText32W( LPFINDREPLACE32W lpFind )
1039 HANDLE16 hInst;
1040 LPCVOID ptr;
1043 * FIXME : We should do error checking on the lpFind structure here
1044 * and make CommDlgExtendedError() return the error condition.
1046 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1047 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1048 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1049 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1050 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1051 (DLGPROC16)ReplaceTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
1055 /***********************************************************************
1056 * FINDDLG_WMInitDialog [internal]
1058 static LRESULT FINDDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam, LPDWORD lpFlags,
1059 LPSTR lpstrFindWhat, BOOL32 fUnicode)
1061 SetWindowLong32A(hWnd, DWL_USER, lParam);
1062 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1064 * FIXME : If the initial FindWhat string is empty, we should disable the
1065 * FindNext (IDOK) button. Only after typing some text, the button should be
1066 * enabled.
1068 if (fUnicode) SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1069 else SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1070 CheckRadioButton32(hWnd, rad1, rad2, (*lpFlags & FR_DOWN) ? rad2 : rad1);
1071 if (*lpFlags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
1072 EnableWindow32(GetDlgItem32(hWnd, rad1), FALSE);
1073 EnableWindow32(GetDlgItem32(hWnd, rad2), FALSE);
1075 if (*lpFlags & FR_HIDEUPDOWN) {
1076 ShowWindow32(GetDlgItem32(hWnd, rad1), SW_HIDE);
1077 ShowWindow32(GetDlgItem32(hWnd, rad2), SW_HIDE);
1078 ShowWindow32(GetDlgItem32(hWnd, grp1), SW_HIDE);
1080 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1081 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1082 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1083 if (*lpFlags & FR_HIDEWHOLEWORD)
1084 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1085 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1086 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1087 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1088 if (*lpFlags & FR_HIDEMATCHCASE)
1089 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1090 if (!(*lpFlags & FR_SHOWHELP)) {
1091 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1092 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1094 ShowWindow32(hWnd, SW_SHOWNORMAL);
1095 return TRUE;
1099 /***********************************************************************
1100 * FINDDLG_WMCommand [internal]
1102 static LRESULT FINDDLG_WMCommand(HWND32 hWnd, WPARAM32 wParam,
1103 HWND32 hwndOwner, LPDWORD lpFlags,
1104 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1105 BOOL32 fUnicode)
1107 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1108 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1110 switch (wParam) {
1111 case IDOK:
1112 if (fUnicode)
1113 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1114 else GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1115 if (IsDlgButtonChecked32(hWnd, rad2))
1116 *lpFlags |= FR_DOWN;
1117 else *lpFlags &= ~FR_DOWN;
1118 if (IsDlgButtonChecked32(hWnd, chx1))
1119 *lpFlags |= FR_WHOLEWORD;
1120 else *lpFlags &= ~FR_WHOLEWORD;
1121 if (IsDlgButtonChecked32(hWnd, chx2))
1122 *lpFlags |= FR_MATCHCASE;
1123 else *lpFlags &= ~FR_MATCHCASE;
1124 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1125 *lpFlags |= FR_FINDNEXT;
1126 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1127 GetWindowLong32A(hWnd, DWL_USER) );
1128 return TRUE;
1129 case IDCANCEL:
1130 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1131 *lpFlags |= FR_DIALOGTERM;
1132 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1133 GetWindowLong32A(hWnd, DWL_USER) );
1134 DestroyWindow32(hWnd);
1135 return TRUE;
1136 case pshHelp:
1137 /* FIXME : should lpfr structure be passed as an argument ??? */
1138 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1139 return TRUE;
1141 return FALSE;
1145 /***********************************************************************
1146 * FindTextDlgProc16 (COMMDLG.13)
1148 LRESULT WINAPI FindTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1149 LPARAM lParam)
1151 LPFINDREPLACE16 lpfr;
1152 switch (wMsg) {
1153 case WM_INITDIALOG:
1154 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1155 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1156 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat), FALSE);
1157 case WM_COMMAND:
1158 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1159 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1160 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1161 lpfr->wFindWhatLen, FALSE);
1163 return FALSE;
1166 /***********************************************************************
1167 * FindTextDlgProc32A
1169 LRESULT WINAPI FindTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1170 LPARAM lParam)
1172 LPFINDREPLACE32A lpfr;
1173 switch (wMsg) {
1174 case WM_INITDIALOG:
1175 lpfr=(LPFINDREPLACE32A)lParam;
1176 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1177 lpfr->lpstrFindWhat, FALSE);
1178 case WM_COMMAND:
1179 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1180 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1181 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1182 FALSE);
1184 return FALSE;
1187 /***********************************************************************
1188 * FindTextDlgProc32W
1190 LRESULT WINAPI FindTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1191 LPARAM lParam)
1193 LPFINDREPLACE32W lpfr;
1194 switch (wMsg) {
1195 case WM_INITDIALOG:
1196 lpfr=(LPFINDREPLACE32W)lParam;
1197 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1198 (LPSTR)lpfr->lpstrFindWhat, TRUE);
1199 case WM_COMMAND:
1200 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1201 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1202 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1203 TRUE);
1205 return FALSE;
1209 /***********************************************************************
1210 * REPLACEDLG_WMInitDialog [internal]
1212 static LRESULT REPLACEDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam,
1213 LPDWORD lpFlags, LPSTR lpstrFindWhat,
1214 LPSTR lpstrReplaceWith, BOOL32 fUnicode)
1216 SetWindowLong32A(hWnd, DWL_USER, lParam);
1217 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1219 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
1220 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
1221 * enabled.
1223 if (fUnicode)
1225 SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1226 SetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith);
1227 } else
1229 SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1230 SetDlgItemText32A(hWnd, edt2, lpstrReplaceWith);
1232 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1233 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1234 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1235 if (*lpFlags & FR_HIDEWHOLEWORD)
1236 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1237 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1238 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1239 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1240 if (*lpFlags & FR_HIDEMATCHCASE)
1241 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1242 if (!(*lpFlags & FR_SHOWHELP)) {
1243 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1244 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1246 ShowWindow32(hWnd, SW_SHOWNORMAL);
1247 return TRUE;
1251 /***********************************************************************
1252 * REPLACEDLG_WMCommand [internal]
1254 static LRESULT REPLACEDLG_WMCommand(HWND32 hWnd, WPARAM16 wParam,
1255 HWND32 hwndOwner, LPDWORD lpFlags,
1256 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1257 LPSTR lpstrReplaceWith, WORD wReplaceWithLen,
1258 BOOL32 fUnicode)
1260 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1261 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1263 switch (wParam) {
1264 case IDOK:
1265 if (fUnicode)
1267 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1268 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1269 } else
1271 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1272 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1274 if (IsDlgButtonChecked32(hWnd, chx1))
1275 *lpFlags |= FR_WHOLEWORD;
1276 else *lpFlags &= ~FR_WHOLEWORD;
1277 if (IsDlgButtonChecked32(hWnd, chx2))
1278 *lpFlags |= FR_MATCHCASE;
1279 else *lpFlags &= ~FR_MATCHCASE;
1280 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1281 *lpFlags |= FR_FINDNEXT;
1282 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1283 GetWindowLong32A(hWnd, DWL_USER) );
1284 return TRUE;
1285 case IDCANCEL:
1286 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1287 *lpFlags |= FR_DIALOGTERM;
1288 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1289 GetWindowLong32A(hWnd, DWL_USER) );
1290 DestroyWindow32(hWnd);
1291 return TRUE;
1292 case psh1:
1293 if (fUnicode)
1295 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1296 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1297 } else
1299 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1300 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1302 if (IsDlgButtonChecked32(hWnd, chx1))
1303 *lpFlags |= FR_WHOLEWORD;
1304 else *lpFlags &= ~FR_WHOLEWORD;
1305 if (IsDlgButtonChecked32(hWnd, chx2))
1306 *lpFlags |= FR_MATCHCASE;
1307 else *lpFlags &= ~FR_MATCHCASE;
1308 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
1309 *lpFlags |= FR_REPLACE;
1310 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1311 GetWindowLong32A(hWnd, DWL_USER) );
1312 return TRUE;
1313 case psh2:
1314 if (fUnicode)
1316 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1317 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1318 } else
1320 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1321 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1323 if (IsDlgButtonChecked32(hWnd, chx1))
1324 *lpFlags |= FR_WHOLEWORD;
1325 else *lpFlags &= ~FR_WHOLEWORD;
1326 if (IsDlgButtonChecked32(hWnd, chx2))
1327 *lpFlags |= FR_MATCHCASE;
1328 else *lpFlags &= ~FR_MATCHCASE;
1329 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
1330 *lpFlags |= FR_REPLACEALL;
1331 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1332 GetWindowLong32A(hWnd, DWL_USER) );
1333 return TRUE;
1334 case pshHelp:
1335 /* FIXME : should lpfr structure be passed as an argument ??? */
1336 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1337 return TRUE;
1339 return FALSE;
1343 /***********************************************************************
1344 * ReplaceTextDlgProc16 (COMMDLG.14)
1346 LRESULT WINAPI ReplaceTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1347 LPARAM lParam)
1349 LPFINDREPLACE16 lpfr;
1350 switch (wMsg) {
1351 case WM_INITDIALOG:
1352 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1353 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1354 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1355 PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith), FALSE);
1356 case WM_COMMAND:
1357 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1358 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1359 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1360 lpfr->wFindWhatLen, PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith),
1361 lpfr->wReplaceWithLen, FALSE);
1363 return FALSE;
1366 /***********************************************************************
1367 * ReplaceTextDlgProc32A
1369 LRESULT WINAPI ReplaceTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1370 LPARAM lParam)
1372 LPFINDREPLACE32A lpfr;
1373 switch (wMsg) {
1374 case WM_INITDIALOG:
1375 lpfr=(LPFINDREPLACE32A)lParam;
1376 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1377 lpfr->lpstrFindWhat, lpfr->lpstrReplaceWith, FALSE);
1378 case WM_COMMAND:
1379 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1380 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1381 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1382 lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, FALSE);
1384 return FALSE;
1387 /***********************************************************************
1388 * ReplaceTextDlgProc32W
1390 LRESULT WINAPI ReplaceTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1391 LPARAM lParam)
1393 LPFINDREPLACE32W lpfr;
1394 switch (wMsg) {
1395 case WM_INITDIALOG:
1396 lpfr=(LPFINDREPLACE32W)lParam;
1397 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1398 (LPSTR)lpfr->lpstrFindWhat, (LPSTR)lpfr->lpstrReplaceWith,
1399 TRUE);
1400 case WM_COMMAND:
1401 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1402 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1403 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1404 (LPSTR)lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, TRUE);
1406 return FALSE;
1410 /***********************************************************************
1411 * PrintDlg16 (COMMDLG.20)
1413 BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
1415 HANDLE16 hInst;
1416 BOOL16 bRet = FALSE;
1417 LPCVOID template;
1418 HWND32 hwndDialog;
1419 LPPRINTDLG16 lpPrint = (LPPRINTDLG16)PTR_SEG_TO_LIN(printdlg);
1421 TRACE(commdlg,"(%p) -- Flags=%08lX\n", lpPrint, lpPrint->Flags );
1423 if (lpPrint->Flags & PD_RETURNDEFAULT)
1424 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1425 return TRUE;
1427 if (lpPrint->Flags & PD_PRINTSETUP)
1428 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
1429 else
1430 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
1432 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1433 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
1434 lpPrint->hwndOwner,
1435 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
1436 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1437 MODULE_GetWndProcEntry16("PrintDlgProc")),
1438 printdlg, WIN_PROC_16 );
1439 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
1440 return bRet;
1444 /***********************************************************************
1445 * PrintDlg32A (COMDLG32.17)
1447 BOOL32 WINAPI PrintDlg32A( LPPRINTDLG32A printdlg )
1449 FIXME(commdlg, "empty stub\n" );
1450 /* Altough returning FALSE is theoricaly the right thing
1451 * most programs check for a printer at startup, and if
1452 * none is found popup PrintDlg32A(), if it fails the program
1453 * terminates; by returning TRUE the programs can still run
1454 * as long as no printer related stuff is used
1456 return TRUE;
1460 /***********************************************************************
1461 * PrintDlg32W (COMDLG32.18)
1463 BOOL32 WINAPI PrintDlg32W( LPPRINTDLG32W printdlg )
1465 FIXME(commdlg, "empty stub\n" );
1466 return FALSE;
1470 /***********************************************************************
1471 * PrintDlgProc (COMMDLG.21)
1473 LRESULT WINAPI PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1474 LPARAM lParam)
1476 switch (wMsg)
1478 case WM_INITDIALOG:
1479 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1480 ShowWindow16(hWnd, SW_SHOWNORMAL);
1481 return (TRUE);
1482 case WM_COMMAND:
1483 switch (wParam)
1485 case IDOK:
1486 EndDialog32(hWnd, TRUE);
1487 return(TRUE);
1488 case IDCANCEL:
1489 EndDialog32(hWnd, FALSE);
1490 return(TRUE);
1492 return(FALSE);
1494 return FALSE;
1498 /***********************************************************************
1499 * PrintSetupDlgProc (COMMDLG.22)
1501 LRESULT WINAPI PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1502 LPARAM lParam)
1504 switch (wMsg)
1506 case WM_INITDIALOG:
1507 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1508 ShowWindow16(hWnd, SW_SHOWNORMAL);
1509 return (TRUE);
1510 case WM_COMMAND:
1511 switch (wParam) {
1512 case IDOK:
1513 EndDialog32(hWnd, TRUE);
1514 return(TRUE);
1515 case IDCANCEL:
1516 EndDialog32(hWnd, FALSE);
1517 return(TRUE);
1519 return(FALSE);
1521 return FALSE;
1525 /***********************************************************************
1526 * CommDlgExtendedError (COMMDLG.26)
1528 DWORD WINAPI CommDlgExtendedError(void)
1530 return CommDlgLastError;
1533 /***********************************************************************
1534 * GetFileTitleA (COMDLG32.8)
1536 short WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
1538 int i, len;
1539 TRACE(commdlg,"(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1540 if (lpFile == NULL || lpTitle == NULL)
1541 return -1;
1542 len = strlen(lpFile);
1543 if (len == 0)
1544 return -1;
1545 if (strpbrk(lpFile, "*[]"))
1546 return -1;
1547 len--;
1548 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1549 return -1;
1550 for (i = len; i >= 0; i--)
1551 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1553 i++;
1554 break;
1556 TRACE(commdlg,"---> '%s' \n", &lpFile[i]);
1558 len = strlen(lpFile+i)+1;
1559 if (cbBuf < len)
1560 return len;
1562 strncpy(lpTitle, &lpFile[i], len);
1563 return 0;
1567 /***********************************************************************
1568 * GetFileTitleA (COMDLG32.8)
1570 short WINAPI GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf)
1572 LPSTR file = HEAP_strdupWtoA(GetProcessHeap(),0,lpFile);
1573 LPSTR title = HeapAlloc(GetProcessHeap(),0,cbBuf);
1574 short ret;
1576 ret = GetFileTitle32A(file,title,cbBuf);
1578 lstrcpynAtoW(lpTitle,title,cbBuf);
1579 HeapFree(GetProcessHeap(),0,file);
1580 HeapFree(GetProcessHeap(),0,title);
1581 return ret;
1583 /***********************************************************************
1584 * GetFileTitle (COMMDLG.27)
1586 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
1588 return GetFileTitle32A(lpFile,lpTitle,cbBuf);
1592 /* ------------------------ Choose Color Dialog --------------------------- */
1594 /***********************************************************************
1595 * ChooseColor (COMMDLG.5)
1597 BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol)
1599 HINSTANCE16 hInst;
1600 HANDLE16 hDlgTmpl = 0;
1601 BOOL16 bRet = FALSE, win32Format = FALSE;
1602 LPCVOID template;
1603 HWND32 hwndDialog;
1605 TRACE(commdlg,"ChooseColor\n");
1606 if (!lpChCol) return FALSE;
1608 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1610 if (!(template = LockResource16( lpChCol->hInstance )))
1612 CommDlgLastError = CDERR_LOADRESFAILURE;
1613 return FALSE;
1616 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1618 HANDLE16 hResInfo;
1619 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1620 lpChCol->lpTemplateName,
1621 RT_DIALOG16)))
1623 CommDlgLastError = CDERR_FINDRESFAILURE;
1624 return FALSE;
1626 if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
1627 !(template = LockResource16( hDlgTmpl )))
1629 CommDlgLastError = CDERR_LOADRESFAILURE;
1630 return FALSE;
1633 else
1635 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR );
1636 win32Format = TRUE;
1639 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1640 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
1641 lpChCol->hwndOwner,
1642 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1643 (DWORD)lpChCol, WIN_PROC_16 );
1644 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
1645 if (hDlgTmpl) FreeResource16( hDlgTmpl );
1646 return bRet;
1650 static const COLORREF predefcolors[6][8]=
1652 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1653 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1654 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1655 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1657 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1658 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1659 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1660 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1662 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1663 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1664 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1665 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1668 struct CCPRIVATE
1670 LPCHOOSECOLOR16 lpcc; /* points to public known data structure */
1671 int nextuserdef; /* next free place in user defined color array */
1672 HDC16 hdcMem; /* color graph used for BitBlt() */
1673 HBITMAP16 hbmMem; /* color graph bitmap */
1674 RECT16 fullsize; /* original dialog window size */
1675 UINT16 msetrgb; /* # of SETRGBSTRING message (today not used) */
1676 RECT16 old3angle; /* last position of l-marker */
1677 RECT16 oldcross; /* last position of color/satuation marker */
1678 BOOL32 updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1679 int h;
1680 int s;
1681 int l; /* for temporary storing of hue,sat,lum */
1684 /***********************************************************************
1685 * CC_HSLtoRGB [internal]
1687 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1689 int res=0,maxrgb;
1691 /* hue */
1692 switch(c)
1694 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1695 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1696 case 'B':break;
1699 /* l below 120 */
1700 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1701 if (hue< 80)
1702 res=0;
1703 else
1704 if (hue< 120)
1706 res=(hue-80)* maxrgb; /* 0...10240 */
1707 res/=40; /* 0...256 */
1709 else
1710 if (hue< 200)
1711 res=maxrgb;
1712 else
1714 res=(240-hue)* maxrgb;
1715 res/=40;
1717 res=res-maxrgb/2; /* -128...128 */
1719 /* saturation */
1720 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1722 /* lum above 120 */
1723 if (lum>120 && res<256)
1724 res+=((lum-120) * (256-res))/120;
1726 return MIN(res,255);
1729 /***********************************************************************
1730 * CC_RGBtoHSL [internal]
1732 static int CC_RGBtoHSL(char c,int r,int g,int b)
1734 WORD maxi,mini,mmsum,mmdif,result=0;
1735 int iresult=0;
1737 maxi=MAX(r,b);
1738 maxi=MAX(maxi,g);
1739 mini=MIN(r,b);
1740 mini=MIN(mini,g);
1742 mmsum=maxi+mini;
1743 mmdif=maxi-mini;
1745 switch(c)
1747 /* lum */
1748 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1749 result=mmsum/255; /* 0...240 */
1750 break;
1751 /* saturation */
1752 case 'S':if (!mmsum)
1753 result=0;
1754 else
1755 if (!mini || maxi==255)
1756 result=240;
1757 else
1759 result=mmdif*240; /* 0...61200=255*240 */
1760 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1762 break;
1763 /* hue */
1764 case 'H':if (!mmdif)
1765 result=160;
1766 else
1768 if (maxi==r)
1770 iresult=40*(g-b); /* -10200 ... 10200 */
1771 iresult/=(int)mmdif; /* -40 .. 40 */
1772 if (iresult<0)
1773 iresult+=240; /* 0..40 and 200..240 */
1775 else
1776 if (maxi==g)
1778 iresult=40*(b-r);
1779 iresult/=(int)mmdif;
1780 iresult+=80; /* 40 .. 120 */
1782 else
1783 if (maxi==b)
1785 iresult=40*(r-g);
1786 iresult/=(int)mmdif;
1787 iresult+=160; /* 120 .. 200 */
1789 result=iresult;
1791 break;
1793 return result; /* is this integer arithmetic precise enough ? */
1796 #define DISTANCE 4
1798 /***********************************************************************
1799 * CC_MouseCheckPredefColorArray [internal]
1801 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1802 LPARAM lParam,COLORREF *cr)
1804 HWND16 hwnd;
1805 POINT16 point = MAKEPOINT16(lParam);
1806 RECT16 rect;
1807 int dx,dy,x,y;
1809 ClientToScreen16(hDlg,&point);
1810 hwnd=GetDlgItem32(hDlg,dlgitem);
1811 GetWindowRect16(hwnd,&rect);
1812 if (PtInRect16(&rect,point))
1814 dx=(rect.right-rect.left)/cols;
1815 dy=(rect.bottom-rect.top)/rows;
1816 ScreenToClient16(hwnd,&point);
1818 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1820 x=point.x/dx;
1821 y=point.y/dy;
1822 *cr=predefcolors[y][x];
1823 /* FIXME: Draw_a_Focus_Rect() */
1824 return 1;
1827 return 0;
1830 /***********************************************************************
1831 * CC_MouseCheckUserColorArray [internal]
1833 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1834 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1836 HWND16 hwnd;
1837 POINT16 point = MAKEPOINT16(lParam);
1838 RECT16 rect;
1839 int dx,dy,x,y;
1841 ClientToScreen16(hDlg,&point);
1842 hwnd=GetDlgItem32(hDlg,dlgitem);
1843 GetWindowRect16(hwnd,&rect);
1844 if (PtInRect16(&rect,point))
1846 dx=(rect.right-rect.left)/cols;
1847 dy=(rect.bottom-rect.top)/rows;
1848 ScreenToClient16(hwnd,&point);
1850 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1852 x=point.x/dx;
1853 y=point.y/dy;
1854 *cr=crarr[x+cols*y];
1855 /* FIXME: Draw_a_Focus_Rect() */
1856 return 1;
1859 return 0;
1862 #define MAXVERT 240
1863 #define MAXHORI 239
1865 /* 240 ^...... ^^ 240
1866 | . ||
1867 SAT | . || LUM
1868 | . ||
1869 +-----> 239 ----
1872 /***********************************************************************
1873 * CC_MouseCheckColorGraph [internal]
1875 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1877 HWND32 hwnd;
1878 POINT16 point = MAKEPOINT16(lParam);
1879 RECT16 rect;
1880 long x,y;
1882 ClientToScreen16(hDlg,&point);
1883 hwnd=GetDlgItem32(hDlg,dlgitem);
1884 GetWindowRect16(hwnd,&rect);
1885 if (PtInRect16(&rect,point))
1887 GetClientRect16(hwnd,&rect);
1888 ScreenToClient16(hwnd,&point);
1890 x=(long)point.x*MAXHORI;
1891 x/=rect.right;
1892 y=(long)(rect.bottom-point.y)*MAXVERT;
1893 y/=rect.bottom;
1895 if (hori)
1896 *hori=x;
1897 if (vert)
1898 *vert=y;
1899 return 1;
1901 else
1902 return 0;
1904 /***********************************************************************
1905 * CC_MouseCheckResultWindow [internal]
1907 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
1909 HWND16 hwnd;
1910 POINT16 point = MAKEPOINT16(lParam);
1911 RECT16 rect;
1913 ClientToScreen16(hDlg,&point);
1914 hwnd=GetDlgItem32(hDlg,0x2c5);
1915 GetWindowRect16(hwnd,&rect);
1916 if (PtInRect16(&rect,point))
1918 PostMessage16(hDlg,WM_COMMAND,0x2c9,0);
1919 return 1;
1921 return 0;
1924 /***********************************************************************
1925 * CC_CheckDigitsInEdit [internal]
1927 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
1929 int i,k,m,result,value;
1930 long editpos;
1931 char buffer[30];
1932 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1933 m=strlen(buffer);
1934 result=0;
1936 for (i=0;i<m;i++)
1937 if (buffer[i]<'0' || buffer[i]>'9')
1939 for (k=i+1;k<=m;k++) /* delete bad character */
1941 buffer[i]=buffer[k];
1942 m--;
1944 buffer[m]=0;
1945 result=1;
1948 value=atoi(buffer);
1949 if (value>maxval) /* build a new string */
1951 sprintf(buffer,"%d",maxval);
1952 result=2;
1954 if (result)
1956 editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
1957 SetWindowText32A(hwnd,buffer);
1958 SendMessage16(hwnd,EM_SETSEL16,0,editpos);
1960 return value;
1965 /***********************************************************************
1966 * CC_PaintSelectedColor [internal]
1968 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
1970 RECT16 rect;
1971 HDC32 hdc;
1972 HBRUSH32 hBrush;
1973 HWND32 hwnd=GetDlgItem32(hDlg,0x2c5);
1974 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1976 hdc=GetDC32(hwnd);
1977 GetClientRect16 (hwnd, &rect) ;
1978 hBrush = CreateSolidBrush32(cr);
1979 if (hBrush)
1981 hBrush = SelectObject32 (hdc, hBrush) ;
1982 Rectangle32(hdc, rect.left,rect.top,rect.right/2,rect.bottom);
1983 DeleteObject32 (SelectObject32 (hdc,hBrush)) ;
1984 hBrush=CreateSolidBrush32(GetNearestColor32(hdc,cr));
1985 if (hBrush)
1987 hBrush= SelectObject32 (hdc, hBrush) ;
1988 Rectangle32( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
1989 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
1992 ReleaseDC32(hwnd,hdc);
1996 /***********************************************************************
1997 * CC_PaintTriangle [internal]
1999 static void CC_PaintTriangle(HWND16 hDlg,int y)
2001 HDC32 hDC;
2002 long temp;
2003 int w=GetDialogBaseUnits();
2004 POINT16 points[3];
2005 int height;
2006 int oben;
2007 RECT16 rect;
2008 HWND16 hwnd=GetDlgItem32(hDlg,0x2be);
2009 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2011 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2013 GetClientRect16(hwnd,&rect);
2014 height=rect.bottom;
2015 hDC=GetDC32(hDlg);
2017 points[0].y=rect.top;
2018 points[0].x=rect.right; /* | /| */
2019 ClientToScreen16(hwnd,points); /* | / | */
2020 ScreenToClient16(hDlg,points); /* |< | */
2021 oben=points[0].y; /* | \ | */
2022 /* | \| */
2023 temp=(long)height*(long)y;
2024 points[0].y=oben+height -temp/(long)MAXVERT;
2025 points[1].y=points[0].y+w;
2026 points[2].y=points[0].y-w;
2027 points[2].x=points[1].x=points[0].x + w;
2029 if (lpp->old3angle.left)
2030 FillRect16(hDC,&lpp->old3angle,GetStockObject32(WHITE_BRUSH));
2031 lpp->old3angle.left =points[0].x;
2032 lpp->old3angle.right =points[1].x+1;
2033 lpp->old3angle.top =points[2].y-1;
2034 lpp->old3angle.bottom=points[1].y+1;
2035 Polygon16(hDC,points,3);
2036 ReleaseDC32(hDlg,hDC);
2041 /***********************************************************************
2042 * CC_PaintCross [internal]
2044 static void CC_PaintCross(HWND16 hDlg,int x,int y)
2046 HDC32 hDC;
2047 int w=GetDialogBaseUnits();
2048 HWND16 hwnd=GetDlgItem32(hDlg,0x2c6);
2049 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2050 RECT16 rect;
2051 POINT16 point;
2052 HPEN32 hPen;
2054 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2056 GetClientRect16(hwnd,&rect);
2057 hDC=GetDC32(hwnd);
2058 SelectClipRgn32(hDC,CreateRectRgnIndirect16(&rect));
2059 hPen=CreatePen32(PS_SOLID,2,0);
2060 hPen=SelectObject32(hDC,hPen);
2061 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
2062 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
2063 if (lpp->oldcross.left!=lpp->oldcross.right)
2064 BitBlt32(hDC,lpp->oldcross.left,lpp->oldcross.top,
2065 lpp->oldcross.right-lpp->oldcross.left,
2066 lpp->oldcross.bottom-lpp->oldcross.top,
2067 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
2068 lpp->oldcross.left =point.x-w-1;
2069 lpp->oldcross.right =point.x+w+1;
2070 lpp->oldcross.top =point.y-w-1;
2071 lpp->oldcross.bottom=point.y+w+1;
2073 MoveTo(hDC,point.x-w,point.y);
2074 LineTo32(hDC,point.x+w,point.y);
2075 MoveTo(hDC,point.x,point.y-w);
2076 LineTo32(hDC,point.x,point.y+w);
2077 DeleteObject32(SelectObject32(hDC,hPen));
2078 ReleaseDC32(hwnd,hDC);
2083 #define XSTEPS 48
2084 #define YSTEPS 24
2087 /***********************************************************************
2088 * CC_PrepareColorGraph [internal]
2090 static void CC_PrepareColorGraph(HWND16 hDlg)
2092 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
2093 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2094 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2095 HBRUSH32 hbrush;
2096 HDC32 hdc ;
2097 RECT16 rect,client;
2098 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT16));
2100 GetClientRect16(hwnd,&client);
2101 hdc=GetDC32(hwnd);
2102 lpp->hdcMem = CreateCompatibleDC32(hdc);
2103 lpp->hbmMem = CreateCompatibleBitmap32(hdc,client.right,client.bottom);
2104 SelectObject32(lpp->hdcMem,lpp->hbmMem);
2106 xdif=client.right /XSTEPS;
2107 ydif=client.bottom/YSTEPS+1;
2108 hdif=239/XSTEPS;
2109 sdif=240/YSTEPS;
2110 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
2112 rect.right=rect.left+xdif;
2113 rect.bottom=client.bottom;
2114 for(sat=0;sat<240+sdif;sat+=sdif)
2116 rect.top=rect.bottom-ydif;
2117 r=CC_HSLtoRGB('R',hue,sat,120);
2118 g=CC_HSLtoRGB('G',hue,sat,120);
2119 b=CC_HSLtoRGB('B',hue,sat,120);
2120 hbrush=CreateSolidBrush32(RGB(r,g,b));
2121 FillRect16(lpp->hdcMem,&rect,hbrush);
2122 DeleteObject32(hbrush);
2123 rect.bottom=rect.top;
2125 rect.left=rect.right;
2127 ReleaseDC32(hwnd,hdc);
2128 SetCursor16(hcursor);
2131 /***********************************************************************
2132 * CC_PaintColorGraph [internal]
2134 static void CC_PaintColorGraph(HWND16 hDlg)
2136 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2137 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2138 HDC32 hDC;
2139 RECT16 rect;
2140 if (IsWindowVisible32(hwnd)) /* if full size */
2142 if (!lpp->hdcMem)
2143 CC_PrepareColorGraph(hDlg); /* should not be necessary */
2145 hDC=GetDC32(hwnd);
2146 GetClientRect16(hwnd,&rect);
2147 if (lpp->hdcMem)
2148 BitBlt32(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
2149 else
2150 WARN(commdlg,"choose color: hdcMem is not defined\n");
2151 ReleaseDC32(hwnd,hDC);
2154 /***********************************************************************
2155 * CC_PaintLumBar [internal]
2157 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
2159 HWND32 hwnd=GetDlgItem32(hDlg,0x2be);
2160 RECT16 rect,client;
2161 int lum,ldif,ydif,r,g,b;
2162 HBRUSH32 hbrush;
2163 HDC32 hDC;
2165 if (IsWindowVisible32(hwnd))
2167 hDC=GetDC32(hwnd);
2168 GetClientRect16(hwnd,&client);
2169 rect=client;
2171 ldif=240/YSTEPS;
2172 ydif=client.bottom/YSTEPS+1;
2173 for(lum=0;lum<240+ldif;lum+=ldif)
2175 rect.top=MAX(0,rect.bottom-ydif);
2176 r=CC_HSLtoRGB('R',hue,sat,lum);
2177 g=CC_HSLtoRGB('G',hue,sat,lum);
2178 b=CC_HSLtoRGB('B',hue,sat,lum);
2179 hbrush=CreateSolidBrush32(RGB(r,g,b));
2180 FillRect16(hDC,&rect,hbrush);
2181 DeleteObject32(hbrush);
2182 rect.bottom=rect.top;
2184 GetClientRect16(hwnd,&rect);
2185 FrameRect16(hDC,&rect,GetStockObject32(BLACK_BRUSH));
2186 ReleaseDC32(hwnd,hDC);
2190 /***********************************************************************
2191 * CC_EditSetRGB [internal]
2193 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
2195 char buffer[10];
2196 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2197 int r=GetRValue(cr);
2198 int g=GetGValue(cr);
2199 int b=GetBValue(cr);
2200 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2202 lpp->updating=TRUE;
2203 sprintf(buffer,"%d",r);
2204 SetWindowText32A(GetDlgItem32(hDlg,0x2c2),buffer);
2205 sprintf(buffer,"%d",g);
2206 SetWindowText32A(GetDlgItem32(hDlg,0x2c3),buffer);
2207 sprintf(buffer,"%d",b);
2208 SetWindowText32A(GetDlgItem32(hDlg,0x2c4),buffer);
2209 lpp->updating=FALSE;
2213 /***********************************************************************
2214 * CC_EditSetHSL [internal]
2216 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
2218 char buffer[10];
2219 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2220 lpp->updating=TRUE;
2221 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2223 lpp->updating=TRUE;
2224 sprintf(buffer,"%d",h);
2225 SetWindowText32A(GetDlgItem32(hDlg,0x2bf),buffer);
2226 sprintf(buffer,"%d",s);
2227 SetWindowText32A(GetDlgItem32(hDlg,0x2c0),buffer);
2228 sprintf(buffer,"%d",l);
2229 SetWindowText32A(GetDlgItem32(hDlg,0x2c1),buffer);
2230 lpp->updating=FALSE;
2232 CC_PaintLumBar(hDlg,h,s);
2235 /***********************************************************************
2236 * CC_SwitchToFullSize [internal]
2238 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
2240 int i;
2241 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2243 EnableWindow32(GetDlgItem32(hDlg,0x2cf),FALSE);
2244 CC_PrepareColorGraph(hDlg);
2245 for (i=0x2bf;i<0x2c5;i++)
2246 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2247 for (i=0x2d3;i<0x2d9;i++)
2248 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2249 EnableWindow32(GetDlgItem32(hDlg,0x2c9),TRUE);
2250 EnableWindow32(GetDlgItem32(hDlg,0x2c8),TRUE);
2252 if (lprect)
2253 SetWindowPos32(hDlg,NULL,0,0,lprect->right-lprect->left,
2254 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
2256 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_SHOW);
2257 ShowWindow32(GetDlgItem32(hDlg,0x2be),SW_SHOW);
2258 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_SHOW);
2260 CC_EditSetRGB(hDlg,result);
2261 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2264 /***********************************************************************
2265 * CC_PaintPredefColorArray [internal]
2267 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
2269 HWND32 hwnd=GetDlgItem32(hDlg,0x2d0);
2270 RECT16 rect;
2271 HDC32 hdc;
2272 HBRUSH32 hBrush;
2273 int dx,dy,i,j,k;
2275 GetClientRect16(hwnd,&rect);
2276 dx=rect.right/cols;
2277 dy=rect.bottom/rows;
2278 k=rect.left;
2280 hdc=GetDC32(hwnd);
2281 GetClientRect16 (hwnd, &rect) ;
2283 for (j=0;j<rows;j++)
2285 for (i=0;i<cols;i++)
2287 hBrush = CreateSolidBrush32(predefcolors[j][i]);
2288 if (hBrush)
2290 hBrush = SelectObject32 (hdc, hBrush) ;
2291 Rectangle32(hdc, rect.left, rect.top,
2292 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2293 rect.left=rect.left+dx;
2294 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2297 rect.top=rect.top+dy;
2298 rect.left=k;
2300 ReleaseDC32(hwnd,hdc);
2301 /* FIXME: draw_a_focus_rect */
2303 /***********************************************************************
2304 * CC_PaintUserColorArray [internal]
2306 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
2308 HWND32 hwnd=GetDlgItem32(hDlg,0x2d1);
2309 RECT16 rect;
2310 HDC32 hdc;
2311 HBRUSH32 hBrush;
2312 int dx,dy,i,j,k;
2314 GetClientRect16(hwnd,&rect);
2316 dx=rect.right/cols;
2317 dy=rect.bottom/rows;
2318 k=rect.left;
2320 hdc=GetDC32(hwnd);
2321 if (hdc)
2323 for (j=0;j<rows;j++)
2325 for (i=0;i<cols;i++)
2327 hBrush = CreateSolidBrush32(lpcr[i+j*cols]);
2328 if (hBrush)
2330 hBrush = SelectObject32 (hdc, hBrush) ;
2331 Rectangle32( hdc, rect.left, rect.top,
2332 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2333 rect.left=rect.left+dx;
2334 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2337 rect.top=rect.top+dy;
2338 rect.left=k;
2340 ReleaseDC32(hwnd,hdc);
2342 /* FIXME: draw_a_focus_rect */
2347 /***********************************************************************
2348 * CC_HookCallChk [internal]
2350 static BOOL32 CC_HookCallChk(LPCHOOSECOLOR16 lpcc)
2352 if (lpcc)
2353 if(lpcc->Flags & CC_ENABLEHOOK)
2354 if (lpcc->lpfnHook)
2355 return TRUE;
2356 return FALSE;
2359 /***********************************************************************
2360 * CC_WMInitDialog [internal]
2362 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2364 int i,res;
2365 HWND16 hwnd;
2366 RECT16 rect;
2367 POINT16 point;
2368 struct CCPRIVATE * lpp;
2370 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
2371 lpp=calloc(1,sizeof(struct CCPRIVATE));
2372 lpp->lpcc=(LPCHOOSECOLOR16)lParam;
2373 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR16))
2375 EndDialog32 (hDlg, 0) ;
2376 return FALSE;
2378 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
2380 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
2381 ShowWindow32(GetDlgItem32(hDlg,0x40e),SW_HIDE);
2382 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
2383 #if 0
2384 cpos=MAKELONG(5,7); /* init */
2385 if (lpp->lpcc->Flags & CC_RGBINIT)
2387 for (i=0;i<6;i++)
2388 for (j=0;j<8;j++)
2389 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
2391 cpos=MAKELONG(i,j);
2392 goto found;
2395 found:
2396 /* FIXME: Draw_a_focus_rect & set_init_values */
2397 #endif
2398 GetWindowRect16(hDlg,&lpp->fullsize);
2399 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2401 hwnd=GetDlgItem32(hDlg,0x2cf);
2402 EnableWindow32(hwnd,FALSE);
2404 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2406 rect=lpp->fullsize;
2407 res=rect.bottom-rect.top;
2408 hwnd=GetDlgItem32(hDlg,0x2c6); /* cut at left border */
2409 point.x=point.y=0;
2410 ClientToScreen16(hwnd,&point);
2411 ScreenToClient16(hDlg,&point);
2412 GetClientRect16(hDlg,&rect);
2413 point.x+=GetSystemMetrics32(SM_CXDLGFRAME);
2414 SetWindowPos32(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
2416 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_HIDE);
2417 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_HIDE);
2419 else
2420 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
2421 res=TRUE;
2422 for (i=0x2bf;i<0x2c5;i++)
2423 SendMessage16(GetDlgItem32(hDlg,i),EM_LIMITTEXT16,3,0); /* max 3 digits: xyz */
2424 if (CC_HookCallChk(lpp->lpcc))
2425 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2426 return res;
2429 /***********************************************************************
2430 * CC_WMCommand [internal]
2432 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2434 int r,g,b,i,xx;
2435 UINT16 cokmsg;
2436 HDC32 hdc;
2437 COLORREF *cr;
2438 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2439 TRACE(commdlg,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
2440 switch (wParam)
2442 case 0x2c2: /* edit notify RGB */
2443 case 0x2c3:
2444 case 0x2c4:
2445 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2447 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
2448 r=GetRValue(lpp->lpcc->rgbResult);
2449 g=GetGValue(lpp->lpcc->rgbResult);
2450 b=GetBValue(lpp->lpcc->rgbResult);
2451 xx=0;
2452 switch (wParam)
2454 case 0x2c2:if ((xx=(i!=r))) r=i;break;
2455 case 0x2c3:if ((xx=(i!=g))) g=i;break;
2456 case 0x2c4:if ((xx=(i!=b))) b=i;break;
2458 if (xx) /* something has changed */
2460 lpp->lpcc->rgbResult=RGB(r,g,b);
2461 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2462 lpp->h=CC_RGBtoHSL('H',r,g,b);
2463 lpp->s=CC_RGBtoHSL('S',r,g,b);
2464 lpp->l=CC_RGBtoHSL('L',r,g,b);
2465 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2466 CC_PaintCross(hDlg,lpp->h,lpp->s);
2467 CC_PaintTriangle(hDlg,lpp->l);
2470 break;
2472 case 0x2bf: /* edit notify HSL */
2473 case 0x2c0:
2474 case 0x2c1:
2475 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2477 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
2478 xx=0;
2479 switch (wParam)
2481 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
2482 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
2483 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
2485 if (xx) /* something has changed */
2487 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2488 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2489 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2490 lpp->lpcc->rgbResult=RGB(r,g,b);
2491 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2492 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2493 CC_PaintCross(hDlg,lpp->h,lpp->s);
2494 CC_PaintTriangle(hDlg,lpp->l);
2497 break;
2499 case 0x2cf:
2500 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
2501 InvalidateRect32( hDlg, NULL, TRUE );
2502 SetFocus32(GetDlgItem32(hDlg,0x2bf));
2503 break;
2505 case 0x2c8: /* add colors ... column by column */
2506 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
2507 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
2508 if (++lpp->nextuserdef==16)
2509 lpp->nextuserdef=0;
2510 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2511 break;
2513 case 0x2c9: /* resulting color */
2514 hdc=GetDC32(hDlg);
2515 lpp->lpcc->rgbResult=GetNearestColor32(hdc,lpp->lpcc->rgbResult);
2516 ReleaseDC32(hDlg,hdc);
2517 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2518 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2519 r=GetRValue(lpp->lpcc->rgbResult);
2520 g=GetGValue(lpp->lpcc->rgbResult);
2521 b=GetBValue(lpp->lpcc->rgbResult);
2522 lpp->h=CC_RGBtoHSL('H',r,g,b);
2523 lpp->s=CC_RGBtoHSL('S',r,g,b);
2524 lpp->l=CC_RGBtoHSL('L',r,g,b);
2525 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2526 CC_PaintCross(hDlg,lpp->h,lpp->s);
2527 CC_PaintTriangle(hDlg,lpp->l);
2528 break;
2530 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2531 i=RegisterWindowMessage32A( HELPMSGSTRING );
2532 if (lpp->lpcc->hwndOwner)
2533 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2534 if (CC_HookCallChk(lpp->lpcc))
2535 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2536 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2537 break;
2539 case IDOK :
2540 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2541 if (lpp->lpcc->hwndOwner)
2542 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2543 break; /* do NOT close */
2545 EndDialog32 (hDlg, 1) ;
2546 return TRUE ;
2548 case IDCANCEL :
2549 EndDialog32 (hDlg, 0) ;
2550 return TRUE ;
2553 return FALSE;
2556 /***********************************************************************
2557 * CC_WMPaint [internal]
2559 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2561 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2562 /* we have to paint dialog children except text and buttons */
2564 CC_PaintPredefColorArray(hDlg,6,8);
2565 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2566 CC_PaintColorGraph(hDlg);
2567 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2568 CC_PaintCross(hDlg,lpp->h,lpp->s);
2569 CC_PaintTriangle(hDlg,lpp->l);
2570 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2572 /* special necessary for Wine */
2573 ValidateRect32(GetDlgItem32(hDlg,0x2d0),NULL);
2574 ValidateRect32(GetDlgItem32(hDlg,0x2d1),NULL);
2575 ValidateRect32(GetDlgItem32(hDlg,0x2c6),NULL);
2576 ValidateRect32(GetDlgItem32(hDlg,0x2be),NULL);
2577 ValidateRect32(GetDlgItem32(hDlg,0x2c5),NULL);
2578 /* hope we can remove it later -->FIXME */
2579 return 0;
2583 /***********************************************************************
2584 * CC_WMLButtonDown [internal]
2586 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2588 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2589 int r,g,b,i;
2590 i=0;
2591 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2592 i=1;
2593 else
2594 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2595 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2596 i=1;
2597 else
2598 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2599 i=2;
2600 else
2601 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2602 i=2;
2603 if (i==2)
2605 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2606 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2607 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2608 lpp->lpcc->rgbResult=RGB(r,g,b);
2610 if (i==1)
2612 r=GetRValue(lpp->lpcc->rgbResult);
2613 g=GetGValue(lpp->lpcc->rgbResult);
2614 b=GetBValue(lpp->lpcc->rgbResult);
2615 lpp->h=CC_RGBtoHSL('H',r,g,b);
2616 lpp->s=CC_RGBtoHSL('S',r,g,b);
2617 lpp->l=CC_RGBtoHSL('L',r,g,b);
2619 if (i)
2621 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2622 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2623 CC_PaintCross(hDlg,lpp->h,lpp->s);
2624 CC_PaintTriangle(hDlg,lpp->l);
2625 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2626 return TRUE;
2628 return FALSE;
2631 /***********************************************************************
2632 * ColorDlgProc (COMMDLG.8)
2634 LRESULT WINAPI ColorDlgProc(HWND16 hDlg, UINT16 message,
2635 WPARAM16 wParam, LONG lParam)
2637 int res;
2638 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2639 if (message!=WM_INITDIALOG)
2641 if (!lpp)
2642 return FALSE;
2643 res=0;
2644 if (CC_HookCallChk(lpp->lpcc))
2645 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2646 if (res)
2647 return res;
2650 /* FIXME: SetRGB message
2651 if (message && message==msetrgb)
2652 return HandleSetRGB(hDlg,lParam);
2655 switch (message)
2657 case WM_INITDIALOG:
2658 return CC_WMInitDialog(hDlg,wParam,lParam);
2659 case WM_NCDESTROY:
2660 DeleteDC32(lpp->hdcMem);
2661 DeleteObject32(lpp->hbmMem);
2662 free(lpp);
2663 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2664 break;
2665 case WM_COMMAND:
2666 if (CC_WMCommand(hDlg, wParam, lParam))
2667 return TRUE;
2668 break;
2669 case WM_PAINT:
2670 CC_WMPaint(hDlg, wParam, lParam);
2671 break;
2672 case WM_LBUTTONDBLCLK:
2673 if (CC_MouseCheckResultWindow(hDlg,lParam))
2674 return TRUE;
2675 break;
2676 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2677 break;
2678 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2679 break;
2680 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2681 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2682 return TRUE;
2683 break;
2685 return FALSE ;
2688 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONT32A chf32a)
2690 chf32a->lStructSize=sizeof(CHOOSEFONT32A);
2691 chf32a->hwndOwner=chf16->hwndOwner;
2692 chf32a->hDC=chf16->hDC;
2693 chf32a->iPointSize=chf16->iPointSize;
2694 chf32a->Flags=chf16->Flags;
2695 chf32a->rgbColors=chf16->rgbColors;
2696 chf32a->lCustData=chf16->lCustData;
2697 chf32a->lpfnHook=NULL;
2698 chf32a->lpTemplateName=PTR_SEG_TO_LIN(chf16->lpTemplateName);
2699 chf32a->hInstance=chf16->hInstance;
2700 chf32a->lpszStyle=PTR_SEG_TO_LIN(chf16->lpszStyle);
2701 chf32a->nFontType=chf16->nFontType;
2702 chf32a->nSizeMax=chf16->nSizeMax;
2703 chf32a->nSizeMin=chf16->nSizeMin;
2704 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16->lpLogFont), chf32a->lpLogFont);
2708 /***********************************************************************
2709 * ChooseFont16 (COMMDLG.15)
2711 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
2713 HINSTANCE16 hInst;
2714 HANDLE16 hDlgTmpl = 0;
2715 BOOL16 bRet = FALSE, win32Format = FALSE;
2716 LPCVOID template;
2717 HWND32 hwndDialog;
2718 CHOOSEFONT32A cf32a;
2719 LOGFONT32A lf32a;
2720 SEGPTR lpTemplateName;
2722 cf32a.lpLogFont=&lf32a;
2723 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
2725 TRACE(commdlg,"ChooseFont\n");
2726 if (!lpChFont) return FALSE;
2728 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
2730 if (!(template = LockResource16( lpChFont->hInstance )))
2732 CommDlgLastError = CDERR_LOADRESFAILURE;
2733 return FALSE;
2736 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2738 HANDLE16 hResInfo;
2739 if (!(hResInfo = FindResource16( lpChFont->hInstance,
2740 lpChFont->lpTemplateName,
2741 RT_DIALOG16)))
2743 CommDlgLastError = CDERR_FINDRESFAILURE;
2744 return FALSE;
2746 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
2747 !(template = LockResource16( hDlgTmpl )))
2749 CommDlgLastError = CDERR_LOADRESFAILURE;
2750 return FALSE;
2753 else
2755 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2756 win32Format = TRUE;
2759 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2761 /* lpTemplateName is not used in the dialog */
2762 lpTemplateName=lpChFont->lpTemplateName;
2763 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
2765 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
2766 lpChFont->hwndOwner,
2767 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2768 (DWORD)lpChFont, WIN_PROC_16 );
2769 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2770 if (hDlgTmpl) FreeResource16( hDlgTmpl );
2771 lpChFont->lpTemplateName=lpTemplateName;
2772 FONT_LogFont32ATo16(cf32a.lpLogFont,
2773 (LPLOGFONT16)(PTR_SEG_TO_LIN(lpChFont->lpLogFont)));
2774 return bRet;
2778 /***********************************************************************
2779 * ChooseFont32A (COMDLG32.3)
2781 BOOL32 WINAPI ChooseFont32A(LPCHOOSEFONT32A lpChFont)
2783 BOOL32 bRet=FALSE;
2784 HWND32 hwndDialog;
2785 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2786 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2787 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2788 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2789 hwndDialog = DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2790 (DLGPROC16)FormatCharDlgProc32A, (LPARAM)lpChFont, WIN_PROC_32A );
2791 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2792 return bRet;
2795 /***********************************************************************
2796 * ChooseFont32W (COMDLG32.4)
2798 BOOL32 WINAPI ChooseFont32W(LPCHOOSEFONT32W lpChFont)
2800 BOOL32 bRet=FALSE;
2801 HWND32 hwndDialog;
2802 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2803 CHOOSEFONT32A cf32a;
2804 LOGFONT32A lf32a;
2805 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2806 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2807 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2808 memcpy(&cf32a, lpChFont, sizeof(cf32a));
2809 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONT32A));
2810 lstrcpynWtoA(lf32a.lfFaceName, lpChFont->lpLogFont->lfFaceName, LF_FACESIZE);
2811 cf32a.lpLogFont=&lf32a;
2812 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
2813 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
2814 hwndDialog=DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2815 (DLGPROC16)FormatCharDlgProc32W, (LPARAM)lpChFont, WIN_PROC_32W );
2816 if (hwndDialog)bRet=DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2817 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
2818 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
2819 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONT32A));
2820 lstrcpynAtoW(lpChFont->lpLogFont->lfFaceName, lf32a.lfFaceName, LF_FACESIZE);
2821 return bRet;
2825 #define TEXT_EXTRAS 4
2826 #define TEXT_COLORS 16
2828 static const COLORREF textcolors[TEXT_COLORS]=
2830 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2831 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2832 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2833 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2836 /***********************************************************************
2837 * CFn_HookCallChk [internal]
2839 static BOOL32 CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
2841 if (lpcf)
2842 if(lpcf->Flags & CF_ENABLEHOOK)
2843 if (lpcf->lpfnHook)
2844 return TRUE;
2845 return FALSE;
2848 /***********************************************************************
2849 * CFn_HookCallChk32 [internal]
2851 static BOOL32 CFn_HookCallChk32(LPCHOOSEFONT32A lpcf)
2853 if (lpcf)
2854 if(lpcf->Flags & CF_ENABLEHOOK)
2855 if (lpcf->lpfnHook)
2856 return TRUE;
2857 return FALSE;
2861 /*************************************************************************
2862 * AddFontFamily [internal]
2864 static INT32 AddFontFamily(LPLOGFONT32A lplf, UINT32 nFontType,
2865 LPCHOOSEFONT32A lpcf, HWND32 hwnd)
2867 int i;
2868 WORD w;
2870 TRACE(commdlg,"font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
2872 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2873 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2874 return 1;
2875 if (lpcf->Flags & CF_ANSIONLY)
2876 if (lplf->lfCharSet != ANSI_CHARSET)
2877 return 1;
2878 if (lpcf->Flags & CF_TTONLY)
2879 if (!(nFontType & TRUETYPE_FONTTYPE))
2880 return 1;
2882 i=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)lplf->lfFaceName);
2883 if (i!=CB_ERR)
2885 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2886 SendMessage32A(hwnd, CB_SETITEMDATA32, i, MAKELONG(nFontType,w));
2887 return 1 ; /* store some important font information */
2889 else
2890 return 0;
2893 typedef struct
2895 HWND32 hWnd1;
2896 HWND32 hWnd2;
2897 LPCHOOSEFONT32A lpcf32a;
2898 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
2900 /*************************************************************************
2901 * FontFamilyEnumProc32 [internal]
2903 INT32 WINAPI FontFamilyEnumProc32(LPENUMLOGFONT32A lpEnumLogFont,
2904 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam)
2906 LPCFn_ENUMSTRUCT e;
2907 e=(LPCFn_ENUMSTRUCT)lParam;
2908 return AddFontFamily(&lpEnumLogFont->elfLogFont, nFontType, e->lpcf32a, e->hWnd1);
2911 /***********************************************************************
2912 * FontFamilyEnumProc16 (COMMDLG.19)
2914 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
2915 UINT16 nFontType, LPARAM lParam )
2917 HWND16 hwnd=LOWORD(lParam);
2918 HWND16 hDlg=GetParent16(hwnd);
2919 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
2920 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
2921 LOGFONT32A lf32a;
2922 FONT_LogFont16To32A(lplf, &lf32a);
2923 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
2924 hwnd);
2927 /*************************************************************************
2928 * SetFontStylesToCombo2 [internal]
2930 * Fill font style information into combobox (without using font.c directly)
2932 static int SetFontStylesToCombo2(HWND32 hwnd, HDC32 hdc, LPLOGFONT32A lplf)
2934 #define FSTYLES 4
2935 struct FONTSTYLE
2936 { int italic;
2937 int weight;
2938 char stname[20]; };
2939 static struct FONTSTYLE fontstyles[FSTYLES]={
2940 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
2941 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
2942 HFONT16 hf;
2943 TEXTMETRIC16 tm;
2944 int i,j;
2946 for (i=0;i<FSTYLES;i++)
2948 lplf->lfItalic=fontstyles[i].italic;
2949 lplf->lfWeight=fontstyles[i].weight;
2950 hf=CreateFontIndirect32A(lplf);
2951 hf=SelectObject32(hdc,hf);
2952 GetTextMetrics16(hdc,&tm);
2953 hf=SelectObject32(hdc,hf);
2954 DeleteObject32(hf);
2956 if (tm.tmWeight==fontstyles[i].weight &&
2957 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
2959 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
2960 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
2961 SEGPTR_FREE(str);
2962 if (j==CB_ERR) return 1;
2963 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
2964 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
2965 if (j==CB_ERR) return 1;
2968 return 0;
2971 /*************************************************************************
2972 * AddFontSizeToCombo3 [internal]
2974 static int AddFontSizeToCombo3(HWND32 hwnd, UINT32 h, LPCHOOSEFONT32A lpcf)
2976 int j;
2977 char buffer[20];
2979 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2980 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
2982 sprintf(buffer, "%2d", h);
2983 j=SendMessage32A(hwnd, CB_FINDSTRINGEXACT32, -1, (LPARAM)buffer);
2984 if (j==CB_ERR)
2986 j=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)buffer);
2987 if (j!=CB_ERR) j = SendMessage32A(hwnd, CB_SETITEMDATA32, j, h);
2988 if (j==CB_ERR) return 1;
2991 return 0;
2994 /*************************************************************************
2995 * SetFontSizesToCombo3 [internal]
2997 static int SetFontSizesToCombo3(HWND32 hwnd, LPCHOOSEFONT32A lpcf)
2999 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
3000 int i;
3002 for (i=0; sizes[i]; i++)
3003 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
3004 return 0;
3007 /***********************************************************************
3008 * AddFontStyle [internal]
3010 INT32 AddFontStyle(LPLOGFONT32A lplf, UINT32 nFontType,
3011 LPCHOOSEFONT32A lpcf, HWND32 hcmb2, HWND32 hcmb3, HWND32 hDlg)
3013 int i;
3015 TRACE(commdlg,"(nFontType=%d)\n",nFontType);
3016 TRACE(commdlg," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
3017 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
3018 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
3019 lplf->lfEscapement,lplf->lfOrientation,
3020 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
3021 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
3022 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
3023 if (nFontType & RASTER_FONTTYPE)
3025 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
3026 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
3028 if (!SendMessage32A(hcmb2, CB_GETCOUNT32, 0, 0))
3030 HDC32 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3031 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
3032 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3033 ReleaseDC32(hDlg,hdc);
3034 if (i)
3035 return 0;
3037 return 1 ;
3041 /***********************************************************************
3042 * FontStyleEnumProc16 (COMMDLG.18)
3044 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
3045 UINT16 nFontType, LPARAM lParam )
3047 HWND16 hcmb2=LOWORD(lParam);
3048 HWND16 hcmb3=HIWORD(lParam);
3049 HWND16 hDlg=GetParent16(hcmb3);
3050 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3051 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
3052 LOGFONT32A lf32a;
3053 FONT_LogFont16To32A(lplf, &lf32a);
3054 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
3055 hcmb2, hcmb3, hDlg);
3058 /***********************************************************************
3059 * FontStyleEnumProc32 [internal]
3061 INT32 WINAPI FontStyleEnumProc32( LPENUMLOGFONT32A lpFont,
3062 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam )
3064 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
3065 HWND32 hcmb2=s->hWnd1;
3066 HWND32 hcmb3=s->hWnd2;
3067 HWND32 hDlg=GetParent32(hcmb3);
3068 return AddFontStyle(&lpFont->elfLogFont, nFontType, s->lpcf32a, hcmb2,
3069 hcmb3, hDlg);
3072 /***********************************************************************
3073 * CFn_WMInitDialog [internal]
3075 LRESULT CFn_WMInitDialog(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3076 LPCHOOSEFONT32A lpcf)
3078 HDC32 hdc;
3079 int i,j,res,init=0;
3080 long l;
3081 LPLOGFONT32A lpxx;
3082 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3084 SetWindowLong32A(hDlg, DWL_USER, lParam);
3085 lpxx=lpcf->lpLogFont;
3086 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
3088 if (lpcf->lStructSize != sizeof(CHOOSEFONT32A))
3090 ERR(commdlg,"structure size failure !!!\n");
3091 EndDialog32 (hDlg, 0);
3092 return FALSE;
3094 if (!hBitmapTT)
3095 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3097 /* This font will be deleted by WM_COMMAND */
3098 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,
3099 CreateFont32A(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
3101 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow32(lpcf->hwndOwner))
3102 ShowWindow32(GetDlgItem32(hDlg,pshHelp),SW_HIDE);
3103 if (!(lpcf->Flags & CF_APPLY))
3104 ShowWindow32(GetDlgItem32(hDlg,psh3),SW_HIDE);
3105 if (lpcf->Flags & CF_EFFECTS)
3107 for (res=1,i=0;res && i<TEXT_COLORS;i++)
3109 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
3110 char name[20];
3111 strcpy( name, "[color name]" );
3112 j=SendDlgItemMessage32A(hDlg, cmb4, CB_ADDSTRING32, 0, (LPARAM)name);
3113 SendDlgItemMessage32A(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
3114 /* look for a fitting value in color combobox */
3115 if (textcolors[j]==lpcf->rgbColors)
3116 SendDlgItemMessage32A(hDlg,cmb4, CB_SETCURSEL32,j,0);
3119 else
3121 ShowWindow32(GetDlgItem32(hDlg,cmb4),SW_HIDE);
3122 ShowWindow32(GetDlgItem32(hDlg,chx1),SW_HIDE);
3123 ShowWindow32(GetDlgItem32(hDlg,chx2),SW_HIDE);
3124 ShowWindow32(GetDlgItem32(hDlg,grp1),SW_HIDE);
3125 ShowWindow32(GetDlgItem32(hDlg,stc4),SW_HIDE);
3127 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3128 if (hdc)
3130 CFn_ENUMSTRUCT s;
3131 s.hWnd1=GetDlgItem32(hDlg,cmb1);
3132 s.lpcf32a=lpcf;
3133 if (!EnumFontFamilies32A(hdc, NULL, FontFamilyEnumProc32, (LPARAM)&s))
3134 TRACE(commdlg,"EnumFontFamilies returns 0\n");
3135 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
3137 /* look for fitting font name in combobox1 */
3138 j=SendDlgItemMessage32A(hDlg,cmb1,CB_FINDSTRING32,-1,(LONG)lpxx->lfFaceName);
3139 if (j!=CB_ERR)
3141 SendDlgItemMessage32A(hDlg, cmb1, CB_SETCURSEL32, j, 0);
3142 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3143 GetDlgItem32(hDlg,cmb1));
3144 init=1;
3145 /* look for fitting font style in combobox2 */
3146 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
3147 for (i=0;i<TEXT_EXTRAS;i++)
3149 if (l==SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0))
3150 SendDlgItemMessage32A(hDlg, cmb2, CB_SETCURSEL32, i, 0);
3153 /* look for fitting font size in combobox3 */
3154 j=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCOUNT32, 0, 0);
3155 for (i=0;i<j;i++)
3157 if (lpxx->lfHeight==(int)SendDlgItemMessage32A(hDlg,cmb3, CB_GETITEMDATA32,i,0))
3158 SendDlgItemMessage32A(hDlg,cmb3,CB_SETCURSEL32,i,0);
3162 if (!init)
3164 SendDlgItemMessage32A(hDlg,cmb1,CB_SETCURSEL32,0,0);
3165 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3166 GetDlgItem32(hDlg,cmb1));
3168 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
3170 j=SendDlgItemMessage32A(hDlg,cmb2,CB_FINDSTRING32,-1,(LONG)lpcf->lpszStyle);
3171 if (j!=CB_ERR)
3173 j=SendDlgItemMessage32A(hDlg,cmb2,CB_SETCURSEL32,j,0);
3174 SendMessage32A(hDlg,WM_COMMAND,cmb2,
3175 MAKELONG(GetDlgItem32(hDlg,cmb2),CBN_SELCHANGE));
3179 else
3181 WARN(commdlg,"HDC failure !!!\n");
3182 EndDialog32 (hDlg, 0);
3183 return FALSE;
3186 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3187 ReleaseDC32(hDlg,hdc);
3188 SetCursor32(hcursor);
3189 return TRUE;
3193 /***********************************************************************
3194 * CFn_WMMeasureItem [internal]
3196 LRESULT CFn_WMMeasureItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3198 BITMAP32 bm;
3199 LPMEASUREITEMSTRUCT32 lpmi=(LPMEASUREITEMSTRUCT32)lParam;
3200 if (!hBitmapTT)
3201 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3202 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3203 lpmi->itemHeight=bm.bmHeight;
3204 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
3205 return 0;
3209 /***********************************************************************
3210 * CFn_WMDrawItem [internal]
3212 LRESULT CFn_WMDrawItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3214 HBRUSH32 hBrush;
3215 char buffer[40];
3216 BITMAP32 bm;
3217 COLORREF cr, oldText=0, oldBk=0;
3218 RECT32 rect;
3219 #if 0
3220 HDC32 hMemDC;
3221 int nFontType;
3222 HBITMAP32 hBitmap; /* for later TT usage */
3223 #endif
3224 LPDRAWITEMSTRUCT32 lpdi = (LPDRAWITEMSTRUCT32)lParam;
3226 if (lpdi->itemID == 0xFFFF) /* got no items */
3227 DrawFocusRect32(lpdi->hDC, &lpdi->rcItem);
3228 else
3230 if (lpdi->CtlType == ODT_COMBOBOX)
3232 if (lpdi->itemState ==ODS_SELECTED)
3234 hBrush=GetSysColorBrush32(COLOR_HIGHLIGHT);
3235 oldText=SetTextColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHTTEXT));
3236 oldBk=SetBkColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHT));
3237 } else
3239 hBrush = SelectObject32(lpdi->hDC, GetStockObject32(LTGRAY_BRUSH));
3240 SelectObject32(lpdi->hDC, hBrush);
3242 FillRect32(lpdi->hDC, &lpdi->rcItem, hBrush);
3244 else
3245 return TRUE; /* this should never happen */
3247 rect=lpdi->rcItem;
3248 switch (lpdi->CtlID)
3250 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
3251 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3252 (LPARAM)buffer);
3253 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3254 TextOut32A(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
3255 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3256 #if 0
3257 nFontType = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3258 /* FIXME: draw bitmap if truetype usage */
3259 if (nFontType&TRUETYPE_FONTTYPE)
3261 hMemDC = CreateCompatibleDC32(lpdi->hDC);
3262 hBitmap = SelectObject32(hMemDC, hBitmapTT);
3263 BitBlt32(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
3264 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
3265 SelectObject32(hMemDC, hBitmap);
3266 DeleteDC32(hMemDC);
3268 #endif
3269 break;
3270 case cmb2:
3271 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
3272 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3273 (LPARAM)buffer);
3274 TextOut32A(lpdi->hDC, lpdi->rcItem.left,
3275 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3276 break;
3278 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
3279 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3280 (LPARAM)buffer);
3281 TextOut32A(lpdi->hDC, lpdi->rcItem.left + 25+5,
3282 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3283 cr = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3284 hBrush = CreateSolidBrush32(cr);
3285 if (hBrush)
3287 hBrush = SelectObject32 (lpdi->hDC, hBrush) ;
3288 rect.right=rect.left+25;
3289 rect.top++;
3290 rect.left+=5;
3291 rect.bottom--;
3292 Rectangle32( lpdi->hDC, rect.left, rect.top,
3293 rect.right, rect.bottom );
3294 DeleteObject32( SelectObject32 (lpdi->hDC, hBrush)) ;
3296 rect=lpdi->rcItem;
3297 rect.left+=25+5;
3298 break;
3300 default: return TRUE; /* this should never happen */
3302 if (lpdi->itemState == ODS_SELECTED)
3304 SetTextColor32(lpdi->hDC, oldText);
3305 SetBkColor32(lpdi->hDC, oldBk);
3308 return TRUE;
3311 /***********************************************************************
3312 * CFn_WMCtlColor [internal]
3314 LRESULT CFn_WMCtlColorStatic(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3315 LPCHOOSEFONT32A lpcf)
3317 if (lpcf->Flags & CF_EFFECTS)
3318 if (GetDlgCtrlID32(lParam)==stc6)
3320 SetTextColor32((HDC32)wParam, lpcf->rgbColors);
3321 return GetStockObject32(WHITE_BRUSH);
3323 return 0;
3326 /***********************************************************************
3327 * CFn_WMCommand [internal]
3329 LRESULT CFn_WMCommand(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3330 LPCHOOSEFONT32A lpcf)
3332 HFONT32 hFont;
3333 int i,j;
3334 long l;
3335 HDC32 hdc;
3336 LPLOGFONT32A lpxx=lpcf->lpLogFont;
3338 TRACE(commdlg,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
3339 switch (LOWORD(wParam))
3341 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
3343 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3344 if (hdc)
3346 SendDlgItemMessage32A(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
3347 SendDlgItemMessage32A(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
3348 i=SendDlgItemMessage32A(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
3349 if (i!=CB_ERR)
3351 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3352 CFn_ENUMSTRUCT s;
3353 char str[256];
3354 SendDlgItemMessage32A(hDlg, cmb1, CB_GETLBTEXT32, i,
3355 (LPARAM)str);
3356 TRACE(commdlg,"WM_COMMAND/cmb1 =>%s\n",str);
3357 s.hWnd1=GetDlgItem32(hDlg, cmb2);
3358 s.hWnd2=GetDlgItem32(hDlg, cmb3);
3359 s.lpcf32a=lpcf;
3360 EnumFontFamilies32A(hdc, str, FontStyleEnumProc32, (LPARAM)&s);
3361 SetCursor32(hcursor);
3363 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3364 ReleaseDC32(hDlg,hdc);
3366 else
3368 WARN(commdlg,"HDC failure !!!\n");
3369 EndDialog32 (hDlg, 0);
3370 return TRUE;
3373 case chx1:
3374 case chx2:
3375 case cmb2:
3376 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
3378 char str[256];
3379 TRACE(commdlg,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
3380 i=SendDlgItemMessage32A(hDlg,cmb1,CB_GETCURSEL32,0,0);
3381 if (i==CB_ERR)
3382 i=GetDlgItemText32A( hDlg, cmb1, str, 256 );
3383 else
3385 SendDlgItemMessage32A(hDlg,cmb1,CB_GETLBTEXT32,i,
3386 (LPARAM)str);
3387 l=SendDlgItemMessage32A(hDlg,cmb1,CB_GETITEMDATA32,i,0);
3388 j=HIWORD(l);
3389 lpcf->nFontType = LOWORD(l);
3390 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
3391 /* same value reported to the EnumFonts
3392 call back with the extra FONTTYPE_... bits added */
3393 lpxx->lfPitchAndFamily=j&0xff;
3394 lpxx->lfCharSet=j>>8;
3396 strcpy(lpxx->lfFaceName,str);
3397 i=SendDlgItemMessage32A(hDlg, cmb2, CB_GETCURSEL32, 0, 0);
3398 if (i!=CB_ERR)
3400 l=SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0);
3401 if (0!=(lpxx->lfItalic=HIWORD(l)))
3402 lpcf->nFontType |= ITALIC_FONTTYPE;
3403 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
3404 lpcf->nFontType |= BOLD_FONTTYPE;
3406 i=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCURSEL32, 0, 0);
3407 if (i!=CB_ERR)
3408 lpxx->lfHeight=-LOWORD(SendDlgItemMessage32A(hDlg, cmb3, CB_GETITEMDATA32, i, 0));
3409 else
3410 lpxx->lfHeight=0;
3411 lpxx->lfStrikeOut=IsDlgButtonChecked32(hDlg,chx1);
3412 lpxx->lfUnderline=IsDlgButtonChecked32(hDlg,chx2);
3413 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
3414 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
3415 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
3416 lpxx->lfQuality=DEFAULT_QUALITY;
3417 lpcf->iPointSize= -10*lpxx->lfHeight;
3419 hFont=CreateFontIndirect32A(lpxx);
3420 if (hFont)
3422 HFONT32 oldFont=SendDlgItemMessage32A(hDlg, stc6,
3423 WM_GETFONT, 0, 0);
3424 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,hFont,TRUE);
3425 DeleteObject32(oldFont);
3428 break;
3430 case cmb4:i=SendDlgItemMessage32A(hDlg, cmb4, CB_GETCURSEL32, 0, 0);
3431 if (i!=CB_ERR)
3433 lpcf->rgbColors=textcolors[i];
3434 InvalidateRect32( GetDlgItem32(hDlg,stc6), NULL, 0 );
3436 break;
3438 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
3439 if (lpcf->hwndOwner)
3440 SendMessage32A(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLong32A(hDlg, DWL_USER));
3441 /* if (CFn_HookCallChk(lpcf))
3442 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
3443 break;
3445 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
3446 ( (lpcf->Flags & CF_LIMITSIZE) &&
3447 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
3448 (-lpxx->lfHeight <= lpcf->nSizeMax)))
3449 EndDialog32(hDlg, TRUE);
3450 else
3452 char buffer[80];
3453 sprintf(buffer,"Select a font size between %d and %d points.",
3454 lpcf->nSizeMin,lpcf->nSizeMax);
3455 MessageBox32A(hDlg, buffer, NULL, MB_OK);
3457 return(TRUE);
3458 case IDCANCEL:EndDialog32(hDlg, FALSE);
3459 return(TRUE);
3461 return(FALSE);
3464 static LRESULT CFn_WMDestroy(HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
3466 DeleteObject32(SendDlgItemMessage32A(hwnd, stc6, WM_GETFONT, 0, 0));
3467 return TRUE;
3471 /***********************************************************************
3472 * FormatCharDlgProc16 (COMMDLG.16)
3473 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
3474 2. some CF_.. flags are not supported
3475 3. some TType extensions
3477 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
3478 LPARAM lParam)
3480 LPCHOOSEFONT16 lpcf;
3481 LPCHOOSEFONT32A lpcf32a;
3482 UINT32 uMsg32;
3483 WPARAM32 wParam32;
3484 LRESULT res=0;
3485 if (message!=WM_INITDIALOG)
3487 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3488 if (!lpcf)
3489 return FALSE;
3490 if (CFn_HookCallChk(lpcf))
3491 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
3492 if (res)
3493 return res;
3495 else
3497 lpcf=(LPCHOOSEFONT16)lParam;
3498 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3499 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3501 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3502 return FALSE;
3504 if (CFn_HookCallChk(lpcf))
3505 return CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3507 WINPROC_MapMsg16To32A(message, wParam, &uMsg32, &wParam32, &lParam);
3508 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3509 switch (uMsg32)
3511 case WM_MEASUREITEM:
3512 res=CFn_WMMeasureItem(hDlg, wParam32, lParam);
3513 break;
3514 case WM_DRAWITEM:
3515 res=CFn_WMDrawItem(hDlg, wParam32, lParam);
3516 break;
3517 case WM_CTLCOLORSTATIC:
3518 res=CFn_WMCtlColorStatic(hDlg, wParam32, lParam, lpcf32a);
3519 break;
3520 case WM_COMMAND:
3521 res=CFn_WMCommand(hDlg, wParam32, lParam, lpcf32a);
3522 break;
3523 case WM_DESTROY:
3524 res=CFn_WMDestroy(hDlg, wParam32, lParam);
3525 break;
3526 case WM_CHOOSEFONT_GETLOGFONT:
3527 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3528 lParam);
3529 FIXME(commdlg, "current logfont back to caller\n");
3530 break;
3532 WINPROC_UnmapMsg16To32A(uMsg32, wParam32, lParam, res);
3533 return res;
3536 /***********************************************************************
3537 * FormatCharDlgProc32A [internal]
3539 LRESULT WINAPI FormatCharDlgProc32A(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3540 LPARAM lParam)
3542 LPCHOOSEFONT32A lpcf;
3543 LRESULT res=FALSE;
3544 if (uMsg!=WM_INITDIALOG)
3546 lpcf=(LPCHOOSEFONT32A)GetWindowLong32A(hDlg, DWL_USER);
3547 if (!lpcf)
3548 return FALSE;
3549 if (CFn_HookCallChk32(lpcf))
3550 res=CallWindowProc32A(lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
3551 if (res)
3552 return res;
3554 else
3556 lpcf=(LPCHOOSEFONT32A)lParam;
3557 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
3559 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3560 return FALSE;
3562 if (CFn_HookCallChk32(lpcf))
3563 return CallWindowProc32A(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3565 switch (uMsg)
3567 case WM_MEASUREITEM:
3568 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3569 case WM_DRAWITEM:
3570 return CFn_WMDrawItem(hDlg, wParam, lParam);
3571 case WM_CTLCOLORSTATIC:
3572 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
3573 case WM_COMMAND:
3574 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
3575 case WM_DESTROY:
3576 return CFn_WMDestroy(hDlg, wParam, lParam);
3577 case WM_CHOOSEFONT_GETLOGFONT:
3578 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3579 lParam);
3580 FIXME(commdlg, "current logfont back to caller\n");
3581 break;
3583 return res;
3586 /***********************************************************************
3587 * FormatCharDlgProc32W [internal]
3589 LRESULT WINAPI FormatCharDlgProc32W(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3590 LPARAM lParam)
3592 LPCHOOSEFONT32W lpcf32w;
3593 LPCHOOSEFONT32A lpcf32a;
3594 LRESULT res=FALSE;
3595 if (uMsg!=WM_INITDIALOG)
3597 lpcf32w=(LPCHOOSEFONT32W)GetWindowLong32A(hDlg, DWL_USER);
3598 if (!lpcf32w)
3599 return FALSE;
3600 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3601 res=CallWindowProc32W(lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
3602 if (res)
3603 return res;
3605 else
3607 lpcf32w=(LPCHOOSEFONT32W)lParam;
3608 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3609 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3611 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3612 return FALSE;
3614 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3615 return CallWindowProc32W(lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3617 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3618 switch (uMsg)
3620 case WM_MEASUREITEM:
3621 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3622 case WM_DRAWITEM:
3623 return CFn_WMDrawItem(hDlg, wParam, lParam);
3624 case WM_CTLCOLORSTATIC:
3625 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
3626 case WM_COMMAND:
3627 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
3628 case WM_DESTROY:
3629 return CFn_WMDestroy(hDlg, wParam, lParam);
3630 case WM_CHOOSEFONT_GETLOGFONT:
3631 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3632 lParam);
3633 FIXME(commdlg, "current logfont back to caller\n");
3634 break;
3636 return res;
3640 static BOOL32 Commdlg_GetFileName32A( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
3641 LPOPENFILENAME32A ofn )
3643 BOOL16 ret;
3644 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3646 memset(ofn16,'\0',sizeof(*ofn16));
3647 ofn16->lStructSize = sizeof(*ofn16);
3648 ofn16->hwndOwner = ofn->hwndOwner;
3649 /* FIXME: OPENFILENAME16 got only 16 bit for HINSTANCE... */
3650 ofn16->hInstance = 0;
3651 if (ofn->lpstrFilter) {
3652 LPSTR s,x;
3654 /* filter is a list... title\0ext\0......\0\0 */
3655 s = (LPSTR)ofn->lpstrFilter;
3656 while (*s)
3657 s = s+strlen(s)+1;
3658 s++;
3659 x = (LPSTR)SEGPTR_ALLOC(s-ofn->lpstrFilter);
3660 memcpy(x,ofn->lpstrFilter,s-ofn->lpstrFilter);
3661 ofn16->lpstrFilter = SEGPTR_GET(x);
3663 if (ofn->lpstrCustomFilter) {
3664 LPSTR s,x;
3666 /* filter is a list... title\0ext\0......\0\0 */
3667 s = (LPSTR)ofn->lpstrCustomFilter;
3668 while (*s)
3669 s = s+strlen(s)+1;
3670 s++;
3671 x = SEGPTR_ALLOC(s-ofn->lpstrCustomFilter);
3672 memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);
3673 ofn16->lpstrCustomFilter = SEGPTR_GET(x);
3675 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3676 ofn16->nFilterIndex = ofn->nFilterIndex;
3677 if (ofn->nMaxFile)
3678 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3679 ofn16->nMaxFile = ofn->nMaxFile;
3680 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3681 if (ofn16->nMaxFileTitle)
3682 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3683 if (ofn->lpstrInitialDir)
3684 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrInitialDir));
3685 if (ofn->lpstrTitle)
3686 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrTitle));
3687 ofn16->Flags = ofn->Flags|OFN_WINE32;
3688 ofn16->nFileOffset = ofn->nFileOffset;
3689 ofn16->nFileExtension = ofn->nFileExtension;
3690 if (ofn->lpstrDefExt)
3691 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrDefExt));
3692 ofn16->lCustData = ofn->lCustData;
3693 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3695 if (ofn->lpTemplateName)
3696 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpTemplateName));
3698 ret = dofunction(SEGPTR_GET(ofn16));
3700 ofn->nFileOffset = ofn16->nFileOffset;
3701 ofn->nFileExtension = ofn16->nFileExtension;
3702 if (ofn16->lpstrFilter)
3703 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3704 if (ofn16->lpTemplateName)
3705 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3706 if (ofn16->lpstrDefExt)
3707 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3708 if (ofn16->lpstrTitle)
3709 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3710 if (ofn16->lpstrInitialDir)
3711 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3712 if (ofn16->lpstrCustomFilter)
3713 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3715 if (ofn16->lpstrFile)
3717 strcpy(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3718 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3721 if (ofn16->lpstrFileTitle)
3723 strcpy(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3724 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3726 SEGPTR_FREE(ofn16);
3727 return ret;
3730 static BOOL32 Commdlg_GetFileName32W( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
3731 LPOPENFILENAME32W ofn )
3733 BOOL16 ret;
3734 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3736 memset(ofn16,'\0',sizeof(*ofn16));
3737 ofn16->lStructSize = sizeof(*ofn16);
3738 ofn16->hwndOwner = ofn->hwndOwner;
3739 /* FIXME: OPENFILENAME16 got only 16 bit for HINSTANCE... */
3740 ofn16->hInstance = 0;
3741 if (ofn->lpstrFilter) {
3742 LPWSTR s;
3743 LPSTR x,y;
3744 int n;
3746 /* filter is a list... title\0ext\0......\0\0 */
3747 s = (LPWSTR)ofn->lpstrFilter;
3748 while (*s)
3749 s = s+lstrlen32W(s)+1;
3750 s++;
3751 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
3752 x = y = (LPSTR)SEGPTR_ALLOC(n);
3753 s = (LPWSTR)ofn->lpstrFilter;
3754 while (*s) {
3755 lstrcpyWtoA(x,s);
3756 x+=lstrlen32A(x)+1;
3757 s+=lstrlen32W(s)+1;
3759 *x=0;
3760 ofn16->lpstrFilter = SEGPTR_GET(y);
3762 if (ofn->lpstrCustomFilter) {
3763 LPWSTR s;
3764 LPSTR x,y;
3765 int n;
3767 /* filter is a list... title\0ext\0......\0\0 */
3768 s = (LPWSTR)ofn->lpstrCustomFilter;
3769 while (*s)
3770 s = s+lstrlen32W(s)+1;
3771 s++;
3772 n = s - ofn->lpstrCustomFilter;
3773 x = y = (LPSTR)SEGPTR_ALLOC(n);
3774 s = (LPWSTR)ofn->lpstrCustomFilter;
3775 while (*s) {
3776 lstrcpyWtoA(x,s);
3777 x+=lstrlen32A(x)+1;
3778 s+=lstrlen32W(s)+1;
3780 *x=0;
3781 ofn16->lpstrCustomFilter = SEGPTR_GET(y);
3783 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3784 ofn16->nFilterIndex = ofn->nFilterIndex;
3785 if (ofn->nMaxFile)
3786 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3787 ofn16->nMaxFile = ofn->nMaxFile;
3788 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3789 if (ofn->nMaxFileTitle)
3790 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3791 if (ofn->lpstrInitialDir)
3792 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrInitialDir));
3793 if (ofn->lpstrTitle)
3794 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrTitle));
3795 ofn16->Flags = ofn->Flags|OFN_WINE32|OFN_UNICODE;
3796 ofn16->nFileOffset = ofn->nFileOffset;
3797 ofn16->nFileExtension = ofn->nFileExtension;
3798 if (ofn->lpstrDefExt)
3799 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrDefExt));
3800 ofn16->lCustData = ofn->lCustData;
3801 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3802 if (ofn->lpTemplateName)
3803 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpTemplateName));
3804 ret = dofunction(SEGPTR_GET(ofn16));
3806 ofn->nFileOffset = ofn16->nFileOffset;
3807 ofn->nFileExtension = ofn16->nFileExtension;
3808 if (ofn16->lpstrFilter)
3809 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3810 if (ofn16->lpTemplateName)
3811 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3812 if (ofn16->lpstrDefExt)
3813 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3814 if (ofn16->lpstrTitle)
3815 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3816 if (ofn16->lpstrInitialDir)
3817 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3818 if (ofn16->lpstrCustomFilter)
3819 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3821 if (ofn16->lpstrFile) {
3822 lstrcpyAtoW(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3823 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3826 if (ofn16->lpstrFileTitle) {
3827 lstrcpyAtoW(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3828 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3830 SEGPTR_FREE(ofn16);
3831 return ret;
3834 /***********************************************************************
3835 * GetOpenFileName32A (COMDLG32.10)
3837 BOOL32 WINAPI GetOpenFileName32A( LPOPENFILENAME32A ofn )
3839 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3840 return Commdlg_GetFileName32A(dofunction,ofn);
3843 /***********************************************************************
3844 * GetOpenFileName32W (COMDLG32.11)
3846 BOOL32 WINAPI GetOpenFileName32W( LPOPENFILENAME32W ofn )
3848 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3849 return Commdlg_GetFileName32W(dofunction,ofn);
3852 /***********************************************************************
3853 * GetSaveFileName32A (COMDLG32.12)
3855 BOOL32 WINAPI GetSaveFileName32A( LPOPENFILENAME32A ofn )
3857 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3858 return Commdlg_GetFileName32A(dofunction,ofn);
3861 /***********************************************************************
3862 * GetSaveFileName32W (COMDLG32.13)
3864 BOOL32 WINAPI GetSaveFileName32W( LPOPENFILENAME32W ofn )
3866 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3867 return Commdlg_GetFileName32W(dofunction,ofn);
3870 /***********************************************************************
3871 * ChooseColorA (COMDLG32.1)
3873 BOOL32 WINAPI ChooseColor32A(LPCHOOSECOLOR32A lpChCol )
3876 BOOL16 ret;
3877 char *str = NULL;
3878 COLORREF* ccref=SEGPTR_ALLOC(64);
3879 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3881 memset(lpcc16,'\0',sizeof(*lpcc16));
3882 lpcc16->lStructSize=sizeof(*lpcc16);
3883 lpcc16->hwndOwner=lpChCol->hwndOwner;
3884 lpcc16->hInstance=0; /* FIXME:MODULE_HANDLEtoHMODULE16(lpChCol->hInstance)*/
3885 lpcc16->rgbResult=lpChCol->rgbResult;
3886 memcpy(ccref,lpChCol->lpCustColors,64);
3887 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3888 lpcc16->Flags=lpChCol->Flags;
3889 lpcc16->lCustData=lpChCol->lCustData;
3890 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3891 if (lpChCol->lpTemplateName)
3892 str = SEGPTR_STRDUP(lpChCol->lpTemplateName );
3893 lpcc16->lpTemplateName=SEGPTR_GET(str);
3895 ret = ChooseColor16(lpcc16);
3896 if(str)
3897 SEGPTR_FREE(str);
3898 memcpy(lpChCol->lpCustColors,ccref,64);
3899 SEGPTR_FREE(ccref);
3900 SEGPTR_FREE(lpcc16);
3901 return (BOOL32)ret;
3904 /***********************************************************************
3905 * ChooseColorW (COMDLG32.2)
3907 BOOL32 WINAPI ChooseColor32W(LPCHOOSECOLOR32W lpChCol )
3910 BOOL16 ret;
3911 char *str = NULL;
3912 COLORREF* ccref=SEGPTR_ALLOC(64);
3913 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3915 memset(lpcc16,'\0',sizeof(*lpcc16));
3916 lpcc16->lStructSize=sizeof(*lpcc16);
3917 lpcc16->hwndOwner=lpChCol->hwndOwner;
3918 lpcc16->hInstance=0; /*FIXME:MODULE_HANDLEtoHMODULE16(lpChCol->hInstance)*/
3919 lpcc16->rgbResult=lpChCol->rgbResult;
3920 memcpy(ccref,lpChCol->lpCustColors,64);
3921 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3922 lpcc16->Flags=lpChCol->Flags;
3923 lpcc16->lCustData=lpChCol->lCustData;
3924 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3925 if (lpChCol->lpTemplateName)
3926 str = SEGPTR_STRDUP_WtoA(lpChCol->lpTemplateName );
3927 lpcc16->lpTemplateName=SEGPTR_GET(str);
3929 ret = ChooseColor16(lpcc16);
3930 if(str)
3931 SEGPTR_FREE(str);
3932 memcpy(lpChCol->lpCustColors,ccref,64);
3933 SEGPTR_FREE(ccref);
3934 SEGPTR_FREE(lpcc16);
3935 return (BOOL32)ret;
3938 /***********************************************************************
3939 * PageSetupDlgA (COMDLG32.15)
3941 BOOL32 WINAPI PageSetupDlg32A(LPPAGESETUPDLG32A setupdlg) {
3942 FIXME(commdlg,"(%p), stub!\n",setupdlg);
3943 return FALSE;