4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
27 static DWORD CommDlgLastError = 0;
29 static HBITMAP16 hFolder = 0;
30 static HBITMAP16 hFolder2 = 0;
31 static HBITMAP16 hFloppy = 0;
32 static HBITMAP16 hHDisk = 0;
33 static HBITMAP16 hCDRom = 0;
34 static HBITMAP16 hBitmapTT = 0;
35 static const char defaultfilter[]=" \0\0";
37 /***********************************************************************
38 * FileDlg_Init [internal]
40 static BOOL32 FileDlg_Init(void)
42 static BOOL32 initialized = 0;
45 if (!hFolder) hFolder = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER));
46 if (!hFolder2) hFolder2 = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FOLDER2));
47 if (!hFloppy) hFloppy = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_FLOPPY));
48 if (!hHDisk) hHDisk = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_HDISK));
49 if (!hCDRom) hCDRom = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CDROM));
50 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
51 hHDisk == 0 || hCDRom == 0)
53 WARN(commdlg, "Error loading bitmaps !\nprin");
61 /***********************************************************************
62 * GetOpenFileName (COMMDLG.1)
64 BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
67 HANDLE32 hDlgTmpl = 0, hResInfo;
68 BOOL32 bRet = FALSE, win32Format = FALSE;
70 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
72 char defaultopen[]="Open File";
75 if (!lpofn || !FileDlg_Init()) return FALSE;
77 if (lpofn->Flags & OFN_WINE32) {
78 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
80 if (!(template = LockResource32( MapHModuleSL(lpofn->hInstance ))))
82 CommDlgLastError = CDERR_LOADRESFAILURE;
86 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
88 if (!(hResInfo = FindResource32A(MapHModuleSL(lpofn->hInstance),
89 PTR_SEG_TO_LIN(lpofn->lpTemplateName), RT_DIALOG32A)))
91 CommDlgLastError = CDERR_FINDRESFAILURE;
94 if (!(hDlgTmpl = LoadResource32( MapHModuleSL(lpofn->hInstance),
96 !(template = LockResource32( hDlgTmpl )))
98 CommDlgLastError = CDERR_LOADRESFAILURE;
102 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
106 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
108 if (!(template = LockResource16( lpofn->hInstance )))
110 CommDlgLastError = CDERR_LOADRESFAILURE;
114 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
116 if (!(hResInfo = FindResource16(lpofn->hInstance,
117 lpofn->lpTemplateName,
120 CommDlgLastError = CDERR_FINDRESFAILURE;
123 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
124 !(template = LockResource16( hDlgTmpl )))
126 CommDlgLastError = CDERR_LOADRESFAILURE;
130 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
135 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
137 if (!(lpofn->lpstrFilter))
139 str = SEGPTR_ALLOC(sizeof(defaultfilter));
140 TRACE(commdlg,"Alloc %p default for Filetype in GetOpenFileName\n",str);
141 memcpy(str,defaultfilter,sizeof(defaultfilter));
142 lpofn->lpstrFilter=SEGPTR_GET(str);
145 if (!(lpofn->lpstrTitle))
147 str1 = SEGPTR_ALLOC(strlen(defaultopen)+1);
148 TRACE(commdlg,"Alloc %p default for Title in GetOpenFileName\n",str1);
149 strcpy(str1,defaultopen);
150 lpofn->lpstrTitle=SEGPTR_GET(str1);
153 /* FIXME: doesn't handle win32 format correctly yet */
154 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
156 (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
158 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
162 TRACE(commdlg,"Freeing %p default for Title in GetOpenFileName\n",str1);
169 TRACE(commdlg,"Freeing %p default for Filetype in GetOpenFileName\n",str);
171 lpofn->lpstrFilter=0;
175 if (lpofn->Flags & OFN_WINE32)
176 FreeResource32( hDlgTmpl );
178 FreeResource16( hDlgTmpl );
181 TRACE(commdlg,"return lpstrFile='%s' !\n",
182 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
187 /***********************************************************************
188 * GetSaveFileName (COMMDLG.2)
190 BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
193 HANDLE32 hDlgTmpl = 0;
194 BOOL32 bRet = FALSE, win32Format = FALSE;
195 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
198 char defaultsave[]="Save as";
199 char *str =0,*str1=0;
201 if (!lpofn || !FileDlg_Init()) return FALSE;
203 if (lpofn->Flags & OFN_WINE32) {
204 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
206 if (!(template = LockResource32( MapHModuleSL(lpofn->hInstance ))))
208 CommDlgLastError = CDERR_LOADRESFAILURE;
212 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
215 if (!(hResInfo = FindResource32A(MapHModuleSL(lpofn->hInstance),
216 PTR_SEG_TO_LIN(lpofn->lpTemplateName),
219 CommDlgLastError = CDERR_FINDRESFAILURE;
222 if (!(hDlgTmpl = LoadResource32(MapHModuleSL(lpofn->hInstance),
224 !(template = LockResource32(hDlgTmpl)))
226 CommDlgLastError = CDERR_LOADRESFAILURE;
231 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
235 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
237 if (!(template = LockResource16( lpofn->hInstance )))
239 CommDlgLastError = CDERR_LOADRESFAILURE;
243 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
246 if (!(hResInfo = FindResource16(lpofn->hInstance,
247 lpofn->lpTemplateName,
250 CommDlgLastError = CDERR_FINDRESFAILURE;
253 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
254 !(template = LockResource16( hDlgTmpl )))
256 CommDlgLastError = CDERR_LOADRESFAILURE;
260 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
265 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
267 if (!(lpofn->lpstrFilter))
269 str = SEGPTR_ALLOC(sizeof(defaultfilter));
270 TRACE(commdlg,"Alloc default for Filetype in GetSaveFileName\n");
271 memcpy(str,defaultfilter,sizeof(defaultfilter));
272 lpofn->lpstrFilter=SEGPTR_GET(str);
275 if (!(lpofn->lpstrTitle))
277 str1 = SEGPTR_ALLOC(sizeof(defaultsave)+1);
278 TRACE(commdlg,"Alloc default for Title in GetSaveFileName\n");
279 strcpy(str1,defaultsave);
280 lpofn->lpstrTitle=SEGPTR_GET(str1);
283 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
285 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
287 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
291 TRACE(commdlg,"Freeing %p default for Title in GetSaveFileName\n",str1);
298 TRACE(commdlg,"Freeing %p default for Filetype in GetSaveFileName\n",str);
300 lpofn->lpstrFilter=0;
304 if (lpofn->Flags & OFN_WINE32)
305 FreeResource32( hDlgTmpl );
307 FreeResource16( hDlgTmpl );
310 TRACE(commdlg, "return lpstrFile='%s' !\n",
311 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
315 /***********************************************************************
316 * FILEDLG_StripEditControl [internal]
317 * Strip pathnames off the contents of the edit control.
319 static void FILEDLG_StripEditControl(HWND16 hwnd)
323 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
324 cp = strrchr(temp, '\\');
328 cp = strrchr(temp, ':');
332 /* FIXME: shouldn't we do something with the result here? ;-) */
335 /***********************************************************************
336 * FILEDLG_ScanDir [internal]
338 static BOOL32 FILEDLG_ScanDir(HWND16 hWnd, LPSTR newPath)
345 lstrcpyn32A(buffer, newPath, sizeof(buffer));
347 if (str[0] && (str[1] == ':')) {
348 drive = toupper(str[0]) - 'A';
350 if (!DRIVE_SetCurrentDrive(drive))
353 drive = DRIVE_GetCurrentDrive();
356 if (str[0] && !DRIVE_Chdir(drive, str)) {
360 GetDlgItemText32A(hWnd, edt1, buffer, sizeof(buffer));
361 if ((hlb = GetDlgItem32(hWnd, lst1)) != 0) {
362 char* scptr; /* ptr on semi-colon */
363 char* filter = buffer;
365 TRACE(commdlg, "Using filter %s\n", filter);
366 SendMessage32A(hlb, LB_RESETCONTENT32, 0, 0);
368 scptr = strchr(filter, ';');
369 if (scptr) *scptr = 0;
370 TRACE(commdlg, "Using file spec %s\n", filter);
371 if (SendMessage32A(hlb, LB_DIR32, 0, (LPARAM)filter) == LB_ERR)
373 if (scptr) *scptr = ';';
374 filter = (scptr) ? (scptr + 1) : 0;
378 strcpy(buffer, "*.*");
379 return DlgDirList32A(hWnd, buffer, lst2, stc1, 0x8010);
382 /***********************************************************************
383 * FILEDLG_GetFileType [internal]
386 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
391 for ( ;(n = strlen(cfptr)) != 0; i++)
396 cfptr += strlen(cfptr) + 1;
399 for ( ;(n = strlen(fptr)) != 0; i++)
404 fptr += strlen(fptr) + 1;
406 return "*.*"; /* FIXME */
409 /***********************************************************************
410 * FILEDLG_WMDrawItem [internal]
412 static LONG FILEDLG_WMDrawItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam,int savedlg)
414 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
417 HBITMAP16 hBitmap, hPrevBitmap;
421 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
423 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
424 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
425 SelectObject32(lpdis->hDC, hBrush);
426 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
427 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
428 (LPARAM)SEGPTR_GET(str));
430 if (savedlg) /* use _gray_ text in FileSaveDlg */
432 if (!lpdis->itemState)
433 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_GRAYTEXT) );
435 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_WINDOWTEXT) );
436 /* inversion of gray would be bad readable */
439 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
441 if (lpdis->itemState != 0) {
442 InvertRect16(lpdis->hDC, &lpdis->rcItem);
448 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
450 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
451 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
452 SelectObject32(lpdis->hDC, hBrush);
453 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
454 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
455 (LPARAM)SEGPTR_GET(str));
458 GetObject16( hBitmap, sizeof(bm), &bm );
459 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
460 lpdis->rcItem.top, str, strlen(str));
461 hMemDC = CreateCompatibleDC32(lpdis->hDC);
462 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
463 BitBlt32(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
464 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
465 SelectObject32(hMemDC, hPrevBitmap);
467 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
471 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
473 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
474 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
475 SelectObject32(lpdis->hDC, hBrush);
476 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
477 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT16, lpdis->itemID,
478 (LPARAM)SEGPTR_GET(str));
479 switch(DRIVE_GetType( str[2] - 'a' ))
481 case TYPE_FLOPPY: hBitmap = hFloppy; break;
482 case TYPE_CDROM: hBitmap = hCDRom; break;
485 default: hBitmap = hHDisk; break;
487 GetObject16( hBitmap, sizeof(bm), &bm );
488 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
489 lpdis->rcItem.top, str, strlen(str));
490 hMemDC = CreateCompatibleDC32(lpdis->hDC);
491 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
492 BitBlt32( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
493 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
494 SelectObject32(hMemDC, hPrevBitmap);
496 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
503 /***********************************************************************
504 * FILEDLG_WMMeasureItem [internal]
506 static LONG FILEDLG_WMMeasureItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
509 LPMEASUREITEMSTRUCT16 lpmeasure;
511 GetObject16( hFolder2, sizeof(bm), &bm );
512 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
513 lpmeasure->itemHeight = bm.bmHeight;
517 /***********************************************************************
518 * FILEDLG_HookCallChk [internal]
520 static int FILEDLG_HookCallChk(LPOPENFILENAME16 lpofn)
523 if (lpofn->Flags & OFN_ENABLEHOOK)
529 /***********************************************************************
530 * FILEDLG_CallWindowProc [internal]
532 * Adapt the structures back for win32 calls so the callee can read lpCustData
534 static BOOL32 FILEDLG_CallWindowProc(LPOPENFILENAME16 lpofn,HWND32 hwnd,
535 UINT32 wMsg,WPARAM32 wParam,LPARAM lParam
539 BOOL32 result = FALSE;
540 WINDOWPROCTYPE ProcType; /* Type of Hook Function to be called. */
542 /* TRUE if lParam points to the OPENFILENAME16 Structure */
543 needstruct = (PTR_SEG_TO_LIN(lParam) == lpofn);
545 ProcType = (lpofn->Flags & OFN_WINE32)
546 ? (lpofn->Flags & OFN_UNICODE) /* 32-Bit call to GetOpenFileName */
547 ? WIN_PROC_32W : WIN_PROC_32A
548 : WIN_PROC_16; /* 16-Bit call to GetOpenFileName */
550 if (!(lpofn->Flags & OFN_WINE32))
551 /* Call to 16-Bit Hooking function... No Problem at all. */
552 return (BOOL32)CallWindowProc16(
553 lpofn->lpfnHook,hwnd,(UINT16)wMsg,(WPARAM16)wParam,lParam
558 /* Parameter lParam points to lpofn... Convert Structure Data... */
559 if (lpofn->Flags & OFN_UNICODE)
561 OPENFILENAME32W ofnw;
563 /* FIXME: probably needs more converted */
564 ofnw.lCustData = lpofn->lCustData;
565 return (BOOL32)CallWindowProc32W(
566 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofnw
569 else /* ! |OFN_UNICODE */
571 OPENFILENAME32A ofna;
573 /* FIXME: probably needs more converted */
574 ofna.lCustData = lpofn->lCustData;
575 return (BOOL32)CallWindowProc32A(
576 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofna
580 else /* ! needstruct */
582 HWINDOWPROC hWindowProc=NULL;
584 if (WINPROC_SetProc(&hWindowProc, lpofn->lpfnHook, ProcType, WIN_PROC_WINDOW))
586 /* Call Window Procedure converting 16-Bit Type Parameters to 32-Bit Type Parameters */
587 result = CallWindowProc16( (WNDPROC16)hWindowProc,
588 hwnd, wMsg, wParam, lParam );
590 result = LOWORD(result);
592 WINPROC_FreeProc( hWindowProc, WIN_PROC_WINDOW );
601 /***********************************************************************
602 * FILEDLG_WMInitDialog [internal]
605 static LONG FILEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
608 LPOPENFILENAME16 lpofn;
610 LPSTR pstr, old_pstr;
611 SetWindowLong32A(hWnd, DWL_USER, lParam);
612 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(lParam);
613 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
614 /* read custom filter information */
615 if (lpofn->lpstrCustomFilter)
617 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
619 TRACE(commdlg,"lpstrCustomFilter = %p\n", pstr);
623 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
624 (LPARAM)lpofn->lpstrCustomFilter + n );
625 n += strlen(pstr) + 1;
626 pstr += strlen(pstr) + 1;
627 TRACE(commdlg,"add str='%s' "
628 "associated to '%s'\n", old_pstr, pstr);
629 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
630 n += strlen(pstr) + 1;
631 pstr += strlen(pstr) + 1;
634 /* read filter information */
635 if (lpofn->lpstrFilter) {
636 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
640 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
641 (LPARAM)lpofn->lpstrFilter + n );
642 n += strlen(pstr) + 1;
643 pstr += strlen(pstr) + 1;
644 TRACE(commdlg,"add str='%s' "
645 "associated to '%s'\n", old_pstr, pstr);
646 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
647 n += strlen(pstr) + 1;
648 pstr += strlen(pstr) + 1;
651 /* set default filter */
652 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
653 lpofn->nFilterIndex = 1;
654 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL16, lpofn->nFilterIndex - 1, 0);
655 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
656 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
658 TRACE(commdlg,"nFilterIndex = %ld, SetText of edt1 to '%s'\n",
659 lpofn->nFilterIndex, tmpstr);
660 SetDlgItemText32A( hWnd, edt1, tmpstr );
663 DlgDirListComboBox32A(hWnd, tmpstr, cmb2, 0, 0xC000);
664 /* read initial directory */
665 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
667 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
669 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
670 && tmpstr[strlen(tmpstr)-1] != ':')
675 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
677 if (!FILEDLG_ScanDir(hWnd, tmpstr))
678 WARN(commdlg, "Couldn't read initial directory %s!\n",tmpstr);
680 /* select current drive in combo 2, omit missing drives */
681 for(i=0, n=-1; i<=DRIVE_GetCurrentDrive(); i++)
682 if (DRIVE_IsValid(i)) n++;
683 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL16, n, 0);
684 if (!(lpofn->Flags & OFN_SHOWHELP))
685 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
686 if (lpofn->Flags & OFN_HIDEREADONLY)
687 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
688 if (FILEDLG_HookCallChk(lpofn))
689 return (BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,WM_INITDIALOG,wParam,lParam );
694 /***********************************************************************
695 * FILEDLG_WMCommand [internal]
697 BOOL32 in_update=FALSE;
699 static LRESULT FILEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
702 LPOPENFILENAME16 lpofn;
704 char tmpstr[512], tmpstr2[512];
706 UINT16 control,notification;
708 /* Notifications are packaged differently in Win32 */
710 notification = HIWORD(lParam);
712 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
715 case lst1: /* file list */
716 FILEDLG_StripEditControl(hWnd);
717 if (notification == LBN_DBLCLK)
719 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
720 if (lRet == LB_ERR) return TRUE;
721 if ((pstr = SEGPTR_ALLOC(512)))
723 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
724 (LPARAM)SEGPTR_GET(pstr));
725 SetDlgItemText32A( hWnd, edt1, pstr );
728 if (FILEDLG_HookCallChk(lpofn))
729 FILEDLG_CallWindowProc(lpofn,hWnd,
730 RegisterWindowMessage32A( LBSELCHSTRING ),
731 control, MAKELONG(lRet,CD_LBSELCHANGE));
732 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
734 case lst2: /* directory list */
735 FILEDLG_StripEditControl(hWnd);
736 if (notification == LBN_DBLCLK)
738 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
739 if (lRet == LB_ERR) return TRUE;
740 pstr = SEGPTR_ALLOC(512);
741 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
742 (LPARAM)SEGPTR_GET(pstr));
743 strcpy( tmpstr, pstr );
745 if (tmpstr[0] == '[')
747 tmpstr[strlen(tmpstr) - 1] = 0;
748 strcpy(tmpstr,tmpstr+1);
750 strcat(tmpstr, "\\");
754 case cmb1: /* file type drop list */
755 if (notification == CBN_SELCHANGE)
765 case cmb2: /* disk drop list */
766 FILEDLG_StripEditControl(hWnd);
767 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL16, 0, 0L);
768 if (lRet == LB_ERR) return 0;
769 pstr = SEGPTR_ALLOC(512);
770 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT16, lRet,
771 (LPARAM)SEGPTR_GET(pstr));
772 sprintf(tmpstr, "%c:", pstr[2]);
775 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
778 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA16, lRet, 0);
779 TRACE(commdlg,"Selected filter : %s\n", pstr);
780 SetDlgItemText32A( hWnd, edt1, pstr );
781 FILEDLG_ScanDir(hWnd, tmpstr);
785 ofn2=*lpofn; /* for later restoring */
786 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
787 pstr = strrchr(tmpstr, '\\');
789 pstr = strrchr(tmpstr, ':');
790 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
792 /* edit control contains wildcards */
795 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
800 strcpy(tmpstr2, tmpstr);
803 TRACE(commdlg,"tmpstr=%s, tmpstr2=%s\n", tmpstr, tmpstr2);
804 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
805 FILEDLG_ScanDir(hWnd, tmpstr);
808 /* no wildcards, we might have a directory or a filename */
809 /* try appending a wildcard and reading the directory */
810 pstr2 = tmpstr + strlen(tmpstr);
811 if (pstr == NULL || *(pstr+1) != 0)
812 strcat(tmpstr, "\\");
813 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
814 if (lRet == LB_ERR) return TRUE;
815 lpofn->nFilterIndex = lRet + 1;
816 TRACE(commdlg,"lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
818 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
819 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
820 lRet), sizeof(tmpstr2));
821 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
823 /* if ScanDir succeeds, we have changed the directory */
824 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
825 /* if not, this must be a filename */
829 /* strip off the pathname */
831 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
832 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
833 /* Should we MessageBox() if this fails? */
834 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
835 strcpy(tmpstr, tmpstr2);
837 else SetDlgItemText32A( hWnd, edt1, tmpstr );
839 ShowWindow16(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
842 int drive = DRIVE_GetCurrentDrive();
843 tmpstr2[0] = 'A'+ drive;
846 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
847 if (strlen(tmpstr2) > 3)
848 strcat(tmpstr2, "\\");
849 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
850 if (lpofn->lpstrFile)
851 lstrcpyn32A(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2,lpofn->nMaxFile);
853 lpofn->nFileOffset = strrchr(tmpstr2,'\\') - tmpstr2 +1;
854 lpofn->nFileExtension = 0;
855 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
856 lpofn->nFileExtension++;
857 if (tmpstr2[lpofn->nFileExtension] == '\0')
858 lpofn->nFileExtension = 0;
860 lpofn->nFileExtension++;
864 if (FILEDLG_HookCallChk(lpofn))
865 FILEDLG_CallWindowProc(lpofn,hWnd,
866 RegisterWindowMessage32A( LBSELCHSTRING ),
867 control, MAKELONG(lRet,CD_LBSELCHANGE));
872 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
874 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
875 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
876 lpofn->lpstrFileTitle );
878 if (FILEDLG_HookCallChk(lpofn))
880 lRet= (BOOL16)FILEDLG_CallWindowProc(lpofn,
881 hWnd, RegisterWindowMessage32A( FILEOKSTRING ), 0, lParam );
884 *lpofn=ofn2; /* restore old state */
886 ShowWindow16(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
891 EndDialog32(hWnd, TRUE);
894 EndDialog32(hWnd, FALSE);
901 /***********************************************************************
902 * FileOpenDlgProc (COMMDLG.6)
904 LRESULT WINAPI FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
907 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
909 if (wMsg!=WM_INITDIALOG)
910 if (FILEDLG_HookCallChk(lpofn))
912 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
914 return lRet; /* else continue message processing */
919 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
921 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
923 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
925 return FILEDLG_WMCommand(hWnd, wParam, lParam);
928 SetBkColor((HDC16)wParam, 0x00C0C0C0);
929 switch (HIWORD(lParam))
932 SetTextColor((HDC16)wParam, 0x00000000);
934 case CTLCOLOR_STATIC:
935 SetTextColor((HDC16)wParam, 0x00000000);
945 /***********************************************************************
946 * FileSaveDlgProc (COMMDLG.7)
948 LRESULT WINAPI FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
951 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
953 if (wMsg!=WM_INITDIALOG)
954 if (FILEDLG_HookCallChk(lpofn))
956 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
958 return lRet; /* else continue message processing */
962 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
965 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
968 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
971 return FILEDLG_WMCommand(hWnd, wParam, lParam);
976 SetBkColor((HDC16)wParam, 0x00C0C0C0);
977 switch (HIWORD(lParam))
980 SetTextColor((HDC16)wParam, 0x00000000);
982 case CTLCOLOR_STATIC:
983 SetTextColor((HDC16)wParam, 0x00000000);
993 /***********************************************************************
994 * FindText16 (COMMDLG.11)
996 HWND16 WINAPI FindText16( SEGPTR find )
1000 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
1003 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1004 * For now, only the standard dialog works.
1006 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1007 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1008 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
1009 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1010 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1011 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
1012 find, WIN_PROC_16 );
1015 /***********************************************************************
1016 * FindText32A (COMMDLG.6)
1018 HWND32 WINAPI FindText32A( LPFINDREPLACE32A lpFind )
1024 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1025 * For now, only the standard dialog works.
1027 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1028 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1029 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
1030 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1031 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1032 (DLGPROC16)FindTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
1035 /***********************************************************************
1036 * FindText32W (COMMDLG.7)
1038 HWND32 WINAPI FindText32W( LPFINDREPLACE32W lpFind )
1044 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1045 * For now, only the standard dialog works.
1047 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1048 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1049 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
1050 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1051 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1052 (DLGPROC16)FindTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
1055 /***********************************************************************
1056 * ReplaceText16 (COMMDLG.12)
1058 HWND16 WINAPI ReplaceText16( SEGPTR find )
1062 LPFINDREPLACE16 lpFind = (LPFINDREPLACE16)PTR_SEG_TO_LIN(find);
1065 * FIXME : We should do error checking on the lpFind structure here
1066 * and make CommDlgExtendedError() return the error condition.
1068 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1069 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1070 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1071 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1072 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1073 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
1074 find, WIN_PROC_16 );
1077 /***********************************************************************
1078 * ReplaceText32A (COMDLG32.19)
1080 HWND32 WINAPI ReplaceText32A( LPFINDREPLACE32A lpFind )
1086 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
1087 * For now, only the standard dialog works.
1089 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1090 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1091 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1092 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1093 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1094 (DLGPROC16)ReplaceTextDlgProc32A, (LPARAM)lpFind, WIN_PROC_32A );
1097 /***********************************************************************
1098 * ReplaceText32W (COMDLG32.20)
1100 HWND32 WINAPI ReplaceText32W( LPFINDREPLACE32W lpFind )
1106 * FIXME : We should do error checking on the lpFind structure here
1107 * and make CommDlgExtendedError() return the error condition.
1109 if (lpFind->Flags & (FR_ENABLETEMPLATE | FR_ENABLETEMPLATEHANDLE |
1110 FR_ENABLEHOOK)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
1111 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
1112 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
1113 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
1114 (DLGPROC16)ReplaceTextDlgProc32W, (LPARAM)lpFind, WIN_PROC_32W );
1118 /***********************************************************************
1119 * FINDDLG_WMInitDialog [internal]
1121 static LRESULT FINDDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam, LPDWORD lpFlags,
1122 LPSTR lpstrFindWhat, BOOL32 fUnicode)
1124 SetWindowLong32A(hWnd, DWL_USER, lParam);
1125 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1127 * FIXME : If the initial FindWhat string is empty, we should disable the
1128 * FindNext (IDOK) button. Only after typing some text, the button should be
1131 if (fUnicode) SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1132 else SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1133 CheckRadioButton32(hWnd, rad1, rad2, (*lpFlags & FR_DOWN) ? rad2 : rad1);
1134 if (*lpFlags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
1135 EnableWindow32(GetDlgItem32(hWnd, rad1), FALSE);
1136 EnableWindow32(GetDlgItem32(hWnd, rad2), FALSE);
1138 if (*lpFlags & FR_HIDEUPDOWN) {
1139 ShowWindow32(GetDlgItem32(hWnd, rad1), SW_HIDE);
1140 ShowWindow32(GetDlgItem32(hWnd, rad2), SW_HIDE);
1141 ShowWindow32(GetDlgItem32(hWnd, grp1), SW_HIDE);
1143 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1144 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1145 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1146 if (*lpFlags & FR_HIDEWHOLEWORD)
1147 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1148 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1149 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1150 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1151 if (*lpFlags & FR_HIDEMATCHCASE)
1152 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1153 if (!(*lpFlags & FR_SHOWHELP)) {
1154 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1155 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1157 ShowWindow32(hWnd, SW_SHOWNORMAL);
1162 /***********************************************************************
1163 * FINDDLG_WMCommand [internal]
1165 static LRESULT FINDDLG_WMCommand(HWND32 hWnd, WPARAM32 wParam,
1166 HWND32 hwndOwner, LPDWORD lpFlags,
1167 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1170 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1171 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1176 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1177 else GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1178 if (IsDlgButtonChecked32(hWnd, rad2))
1179 *lpFlags |= FR_DOWN;
1180 else *lpFlags &= ~FR_DOWN;
1181 if (IsDlgButtonChecked32(hWnd, chx1))
1182 *lpFlags |= FR_WHOLEWORD;
1183 else *lpFlags &= ~FR_WHOLEWORD;
1184 if (IsDlgButtonChecked32(hWnd, chx2))
1185 *lpFlags |= FR_MATCHCASE;
1186 else *lpFlags &= ~FR_MATCHCASE;
1187 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1188 *lpFlags |= FR_FINDNEXT;
1189 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1190 GetWindowLong32A(hWnd, DWL_USER) );
1193 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1194 *lpFlags |= FR_DIALOGTERM;
1195 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1196 GetWindowLong32A(hWnd, DWL_USER) );
1197 DestroyWindow32(hWnd);
1200 /* FIXME : should lpfr structure be passed as an argument ??? */
1201 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1208 /***********************************************************************
1209 * FindTextDlgProc16 (COMMDLG.13)
1211 LRESULT WINAPI FindTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1214 LPFINDREPLACE16 lpfr;
1217 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1218 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1219 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat), FALSE);
1221 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1222 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1223 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1224 lpfr->wFindWhatLen, FALSE);
1229 /***********************************************************************
1230 * FindTextDlgProc32A
1232 LRESULT WINAPI FindTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1235 LPFINDREPLACE32A lpfr;
1238 lpfr=(LPFINDREPLACE32A)lParam;
1239 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1240 lpfr->lpstrFindWhat, FALSE);
1242 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1243 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1244 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1250 /***********************************************************************
1251 * FindTextDlgProc32W
1253 LRESULT WINAPI FindTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1256 LPFINDREPLACE32W lpfr;
1259 lpfr=(LPFINDREPLACE32W)lParam;
1260 return FINDDLG_WMInitDialog(hWnd, lParam, &(lpfr->Flags),
1261 (LPSTR)lpfr->lpstrFindWhat, TRUE);
1263 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1264 return FINDDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1265 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1272 /***********************************************************************
1273 * REPLACEDLG_WMInitDialog [internal]
1275 static LRESULT REPLACEDLG_WMInitDialog(HWND32 hWnd, LPARAM lParam,
1276 LPDWORD lpFlags, LPSTR lpstrFindWhat,
1277 LPSTR lpstrReplaceWith, BOOL32 fUnicode)
1279 SetWindowLong32A(hWnd, DWL_USER, lParam);
1280 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1282 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
1283 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
1288 SetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat);
1289 SetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith);
1292 SetDlgItemText32A(hWnd, edt1, lpstrFindWhat);
1293 SetDlgItemText32A(hWnd, edt2, lpstrReplaceWith);
1295 CheckDlgButton32(hWnd, chx1, (*lpFlags & FR_WHOLEWORD) ? 1 : 0);
1296 if (*lpFlags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1297 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1298 if (*lpFlags & FR_HIDEWHOLEWORD)
1299 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1300 CheckDlgButton32(hWnd, chx2, (*lpFlags & FR_MATCHCASE) ? 1 : 0);
1301 if (*lpFlags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1302 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1303 if (*lpFlags & FR_HIDEMATCHCASE)
1304 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1305 if (!(*lpFlags & FR_SHOWHELP)) {
1306 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1307 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1309 ShowWindow32(hWnd, SW_SHOWNORMAL);
1314 /***********************************************************************
1315 * REPLACEDLG_WMCommand [internal]
1317 static LRESULT REPLACEDLG_WMCommand(HWND32 hWnd, WPARAM16 wParam,
1318 HWND32 hwndOwner, LPDWORD lpFlags,
1319 LPSTR lpstrFindWhat, WORD wFindWhatLen,
1320 LPSTR lpstrReplaceWith, WORD wReplaceWithLen,
1323 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1324 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1330 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1331 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1334 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1335 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1337 if (IsDlgButtonChecked32(hWnd, chx1))
1338 *lpFlags |= FR_WHOLEWORD;
1339 else *lpFlags &= ~FR_WHOLEWORD;
1340 if (IsDlgButtonChecked32(hWnd, chx2))
1341 *lpFlags |= FR_MATCHCASE;
1342 else *lpFlags &= ~FR_MATCHCASE;
1343 *lpFlags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1344 *lpFlags |= FR_FINDNEXT;
1345 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1346 GetWindowLong32A(hWnd, DWL_USER) );
1349 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1350 *lpFlags |= FR_DIALOGTERM;
1351 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1352 GetWindowLong32A(hWnd, DWL_USER) );
1353 DestroyWindow32(hWnd);
1358 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1359 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1362 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1363 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1365 if (IsDlgButtonChecked32(hWnd, chx1))
1366 *lpFlags |= FR_WHOLEWORD;
1367 else *lpFlags &= ~FR_WHOLEWORD;
1368 if (IsDlgButtonChecked32(hWnd, chx2))
1369 *lpFlags |= FR_MATCHCASE;
1370 else *lpFlags &= ~FR_MATCHCASE;
1371 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
1372 *lpFlags |= FR_REPLACE;
1373 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1374 GetWindowLong32A(hWnd, DWL_USER) );
1379 GetDlgItemText32W(hWnd, edt1, (LPWSTR)lpstrFindWhat, wFindWhatLen/2);
1380 GetDlgItemText32W(hWnd, edt2, (LPWSTR)lpstrReplaceWith, wReplaceWithLen/2);
1383 GetDlgItemText32A(hWnd, edt1, lpstrFindWhat, wFindWhatLen);
1384 GetDlgItemText32A(hWnd, edt2, lpstrReplaceWith, wReplaceWithLen);
1386 if (IsDlgButtonChecked32(hWnd, chx1))
1387 *lpFlags |= FR_WHOLEWORD;
1388 else *lpFlags &= ~FR_WHOLEWORD;
1389 if (IsDlgButtonChecked32(hWnd, chx2))
1390 *lpFlags |= FR_MATCHCASE;
1391 else *lpFlags &= ~FR_MATCHCASE;
1392 *lpFlags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
1393 *lpFlags |= FR_REPLACEALL;
1394 SendMessage32A(hwndOwner, uFindReplaceMessage, 0,
1395 GetWindowLong32A(hWnd, DWL_USER) );
1398 /* FIXME : should lpfr structure be passed as an argument ??? */
1399 SendMessage32A(hwndOwner, uHelpMessage, 0, 0);
1406 /***********************************************************************
1407 * ReplaceTextDlgProc16 (COMMDLG.14)
1409 LRESULT WINAPI ReplaceTextDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1412 LPFINDREPLACE16 lpfr;
1415 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(lParam);
1416 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1417 PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1418 PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith), FALSE);
1420 lpfr=(LPFINDREPLACE16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1421 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1422 &lpfr->Flags, PTR_SEG_TO_LIN(lpfr->lpstrFindWhat),
1423 lpfr->wFindWhatLen, PTR_SEG_TO_LIN(lpfr->lpstrReplaceWith),
1424 lpfr->wReplaceWithLen, FALSE);
1429 /***********************************************************************
1430 * ReplaceTextDlgProc32A
1432 LRESULT WINAPI ReplaceTextDlgProc32A(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1435 LPFINDREPLACE32A lpfr;
1438 lpfr=(LPFINDREPLACE32A)lParam;
1439 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1440 lpfr->lpstrFindWhat, lpfr->lpstrReplaceWith, FALSE);
1442 lpfr=(LPFINDREPLACE32A)GetWindowLong32A(hWnd, DWL_USER);
1443 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1444 &lpfr->Flags, lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1445 lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, FALSE);
1450 /***********************************************************************
1451 * ReplaceTextDlgProc32W
1453 LRESULT WINAPI ReplaceTextDlgProc32W(HWND32 hWnd, UINT32 wMsg, WPARAM32 wParam,
1456 LPFINDREPLACE32W lpfr;
1459 lpfr=(LPFINDREPLACE32W)lParam;
1460 return REPLACEDLG_WMInitDialog(hWnd, lParam, &lpfr->Flags,
1461 (LPSTR)lpfr->lpstrFindWhat, (LPSTR)lpfr->lpstrReplaceWith,
1464 lpfr=(LPFINDREPLACE32W)GetWindowLong32A(hWnd, DWL_USER);
1465 return REPLACEDLG_WMCommand(hWnd, wParam, lpfr->hwndOwner,
1466 &lpfr->Flags, (LPSTR)lpfr->lpstrFindWhat, lpfr->wFindWhatLen,
1467 (LPSTR)lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen, TRUE);
1473 /***********************************************************************
1474 * PrintDlg16 (COMMDLG.20)
1476 BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
1479 BOOL16 bRet = FALSE;
1482 LPPRINTDLG16 lpPrint = (LPPRINTDLG16)PTR_SEG_TO_LIN(printdlg);
1484 TRACE(commdlg,"(%p) -- Flags=%08lX\n", lpPrint, lpPrint->Flags );
1486 if (lpPrint->Flags & PD_RETURNDEFAULT)
1487 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1490 if (lpPrint->Flags & PD_PRINTSETUP)
1491 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
1493 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
1495 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1496 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
1498 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
1499 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1500 MODULE_GetWndProcEntry16("PrintDlgProc")),
1501 printdlg, WIN_PROC_16 );
1502 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
1507 /***********************************************************************
1508 * PrintDlg32A (COMDLG32.17)
1510 BOOL32 WINAPI PrintDlg32A( LPPRINTDLG32A printdlg )
1512 FIXME(commdlg, "(%p): stub\n",printdlg);
1513 /* Altough returning FALSE is theoricaly the right thing
1514 * most programs check for a printer at startup, and if
1515 * none is found popup PrintDlg32A(), if it fails the program
1516 * terminates; by returning TRUE the programs can still run
1517 * as long as no printer related stuff is used
1523 /***********************************************************************
1524 * PrintDlg32W (COMDLG32.18)
1526 BOOL32 WINAPI PrintDlg32W( LPPRINTDLG32W printdlg )
1528 FIXME(commdlg, "empty stub\n" );
1533 /***********************************************************************
1534 * PrintDlgProc (COMMDLG.21)
1536 LRESULT WINAPI PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1542 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1543 ShowWindow16(hWnd, SW_SHOWNORMAL);
1549 EndDialog32(hWnd, TRUE);
1552 EndDialog32(hWnd, FALSE);
1561 /***********************************************************************
1562 * PrintSetupDlgProc (COMMDLG.22)
1564 LRESULT WINAPI PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1570 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
1571 ShowWindow16(hWnd, SW_SHOWNORMAL);
1576 EndDialog32(hWnd, TRUE);
1579 EndDialog32(hWnd, FALSE);
1588 /***********************************************************************
1589 * CommDlgExtendedError (COMMDLG.26)
1591 DWORD WINAPI CommDlgExtendedError(void)
1593 return CommDlgLastError;
1596 /***********************************************************************
1597 * GetFileTitleA (COMDLG32.8)
1599 short WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
1602 TRACE(commdlg,"(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1603 if (lpFile == NULL || lpTitle == NULL)
1605 len = strlen(lpFile);
1608 if (strpbrk(lpFile, "*[]"))
1611 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1613 for (i = len; i >= 0; i--)
1614 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1621 TRACE(commdlg,"---> '%s' \n", &lpFile[i]);
1623 len = strlen(lpFile+i)+1;
1627 strncpy(lpTitle, &lpFile[i], len);
1632 /***********************************************************************
1633 * GetFileTitleA (COMDLG32.8)
1635 short WINAPI GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf)
1637 LPSTR file = HEAP_strdupWtoA(GetProcessHeap(),0,lpFile);
1638 LPSTR title = HeapAlloc(GetProcessHeap(),0,cbBuf);
1641 ret = GetFileTitle32A(file,title,cbBuf);
1643 lstrcpynAtoW(lpTitle,title,cbBuf);
1644 HeapFree(GetProcessHeap(),0,file);
1645 HeapFree(GetProcessHeap(),0,title);
1648 /***********************************************************************
1649 * GetFileTitle (COMMDLG.27)
1651 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
1653 return GetFileTitle32A(lpFile,lpTitle,cbBuf);
1657 /* ------------------------ Choose Color Dialog --------------------------- */
1659 /***********************************************************************
1660 * ChooseColor (COMMDLG.5)
1662 BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol)
1665 HANDLE16 hDlgTmpl = 0;
1666 BOOL16 bRet = FALSE, win32Format = FALSE;
1670 TRACE(commdlg,"ChooseColor\n");
1671 if (!lpChCol) return FALSE;
1673 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1675 if (!(template = LockResource16( lpChCol->hInstance )))
1677 CommDlgLastError = CDERR_LOADRESFAILURE;
1681 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1684 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1685 lpChCol->lpTemplateName,
1688 CommDlgLastError = CDERR_FINDRESFAILURE;
1691 if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
1692 !(template = LockResource16( hDlgTmpl )))
1694 CommDlgLastError = CDERR_LOADRESFAILURE;
1700 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR );
1704 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1705 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
1707 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1708 (DWORD)lpChCol, WIN_PROC_16 );
1709 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
1710 if (hDlgTmpl) FreeResource16( hDlgTmpl );
1716 static const COLORREF predefcolors[6][8]=
1718 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1719 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1720 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1721 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1723 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1724 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1725 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1726 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1728 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1729 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1730 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1731 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1736 LPCHOOSECOLOR16 lpcc; /* points to public known data structure */
1737 int nextuserdef; /* next free place in user defined color array */
1738 HDC16 hdcMem; /* color graph used for BitBlt() */
1739 HBITMAP16 hbmMem; /* color graph bitmap */
1740 RECT16 fullsize; /* original dialog window size */
1741 UINT16 msetrgb; /* # of SETRGBSTRING message (today not used) */
1742 RECT16 old3angle; /* last position of l-marker */
1743 RECT16 oldcross; /* last position of color/satuation marker */
1744 BOOL32 updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1747 int l; /* for temporary storing of hue,sat,lum */
1750 /***********************************************************************
1751 * CC_HSLtoRGB [internal]
1753 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1760 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1761 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1766 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1772 res=(hue-80)* maxrgb; /* 0...10240 */
1773 res/=40; /* 0...256 */
1780 res=(240-hue)* maxrgb;
1783 res=res-maxrgb/2; /* -128...128 */
1786 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1789 if (lum>120 && res<256)
1790 res+=((lum-120) * (256-res))/120;
1792 return MIN(res,255);
1795 /***********************************************************************
1796 * CC_RGBtoHSL [internal]
1798 static int CC_RGBtoHSL(char c,int r,int g,int b)
1800 WORD maxi,mini,mmsum,mmdif,result=0;
1814 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1815 result=mmsum/255; /* 0...240 */
1818 case 'S':if (!mmsum)
1821 if (!mini || maxi==255)
1825 result=mmdif*240; /* 0...61200=255*240 */
1826 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1830 case 'H':if (!mmdif)
1836 iresult=40*(g-b); /* -10200 ... 10200 */
1837 iresult/=(int)mmdif; /* -40 .. 40 */
1839 iresult+=240; /* 0..40 and 200..240 */
1845 iresult/=(int)mmdif;
1846 iresult+=80; /* 40 .. 120 */
1852 iresult/=(int)mmdif;
1853 iresult+=160; /* 120 .. 200 */
1859 return result; /* is this integer arithmetic precise enough ? */
1864 /***********************************************************************
1865 * CC_MouseCheckPredefColorArray [internal]
1867 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1868 LPARAM lParam,COLORREF *cr)
1871 POINT16 point = MAKEPOINT16(lParam);
1875 ClientToScreen16(hDlg,&point);
1876 hwnd=GetDlgItem32(hDlg,dlgitem);
1877 GetWindowRect16(hwnd,&rect);
1878 if (PtInRect16(&rect,point))
1880 dx=(rect.right-rect.left)/cols;
1881 dy=(rect.bottom-rect.top)/rows;
1882 ScreenToClient16(hwnd,&point);
1884 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1888 *cr=predefcolors[y][x];
1889 /* FIXME: Draw_a_Focus_Rect() */
1896 /***********************************************************************
1897 * CC_MouseCheckUserColorArray [internal]
1899 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1900 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1903 POINT16 point = MAKEPOINT16(lParam);
1907 ClientToScreen16(hDlg,&point);
1908 hwnd=GetDlgItem32(hDlg,dlgitem);
1909 GetWindowRect16(hwnd,&rect);
1910 if (PtInRect16(&rect,point))
1912 dx=(rect.right-rect.left)/cols;
1913 dy=(rect.bottom-rect.top)/rows;
1914 ScreenToClient16(hwnd,&point);
1916 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1920 *cr=crarr[x+cols*y];
1921 /* FIXME: Draw_a_Focus_Rect() */
1931 /* 240 ^...... ^^ 240
1938 /***********************************************************************
1939 * CC_MouseCheckColorGraph [internal]
1941 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1944 POINT16 point = MAKEPOINT16(lParam);
1948 ClientToScreen16(hDlg,&point);
1949 hwnd=GetDlgItem32(hDlg,dlgitem);
1950 GetWindowRect16(hwnd,&rect);
1951 if (PtInRect16(&rect,point))
1953 GetClientRect16(hwnd,&rect);
1954 ScreenToClient16(hwnd,&point);
1956 x=(long)point.x*MAXHORI;
1958 y=(long)(rect.bottom-point.y)*MAXVERT;
1970 /***********************************************************************
1971 * CC_MouseCheckResultWindow [internal]
1973 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
1976 POINT16 point = MAKEPOINT16(lParam);
1979 ClientToScreen16(hDlg,&point);
1980 hwnd=GetDlgItem32(hDlg,0x2c5);
1981 GetWindowRect16(hwnd,&rect);
1982 if (PtInRect16(&rect,point))
1984 PostMessage16(hDlg,WM_COMMAND,0x2c9,0);
1990 /***********************************************************************
1991 * CC_CheckDigitsInEdit [internal]
1993 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
1995 int i,k,m,result,value;
1998 GetWindowText32A(hwnd,buffer,sizeof(buffer));
2003 if (buffer[i]<'0' || buffer[i]>'9')
2005 for (k=i+1;k<=m;k++) /* delete bad character */
2007 buffer[i]=buffer[k];
2015 if (value>maxval) /* build a new string */
2017 sprintf(buffer,"%d",maxval);
2022 editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
2023 SetWindowText32A(hwnd,buffer);
2024 SendMessage16(hwnd,EM_SETSEL16,0,editpos);
2031 /***********************************************************************
2032 * CC_PaintSelectedColor [internal]
2034 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
2039 HWND32 hwnd=GetDlgItem32(hDlg,0x2c5);
2040 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2043 GetClientRect16 (hwnd, &rect) ;
2044 hBrush = CreateSolidBrush32(cr);
2047 hBrush = SelectObject32 (hdc, hBrush) ;
2048 Rectangle32(hdc, rect.left,rect.top,rect.right/2,rect.bottom);
2049 DeleteObject32 (SelectObject32 (hdc,hBrush)) ;
2050 hBrush=CreateSolidBrush32(GetNearestColor32(hdc,cr));
2053 hBrush= SelectObject32 (hdc, hBrush) ;
2054 Rectangle32( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
2055 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2058 ReleaseDC32(hwnd,hdc);
2062 /***********************************************************************
2063 * CC_PaintTriangle [internal]
2065 static void CC_PaintTriangle(HWND16 hDlg,int y)
2069 int w=GetDialogBaseUnits();
2074 HWND16 hwnd=GetDlgItem32(hDlg,0x2be);
2075 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2077 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2079 GetClientRect16(hwnd,&rect);
2083 points[0].y=rect.top;
2084 points[0].x=rect.right; /* | /| */
2085 ClientToScreen16(hwnd,points); /* | / | */
2086 ScreenToClient16(hDlg,points); /* |< | */
2087 oben=points[0].y; /* | \ | */
2089 temp=(long)height*(long)y;
2090 points[0].y=oben+height -temp/(long)MAXVERT;
2091 points[1].y=points[0].y+w;
2092 points[2].y=points[0].y-w;
2093 points[2].x=points[1].x=points[0].x + w;
2095 if (lpp->old3angle.left)
2096 FillRect16(hDC,&lpp->old3angle,GetStockObject32(WHITE_BRUSH));
2097 lpp->old3angle.left =points[0].x;
2098 lpp->old3angle.right =points[1].x+1;
2099 lpp->old3angle.top =points[2].y-1;
2100 lpp->old3angle.bottom=points[1].y+1;
2101 Polygon16(hDC,points,3);
2102 ReleaseDC32(hDlg,hDC);
2107 /***********************************************************************
2108 * CC_PaintCross [internal]
2110 static void CC_PaintCross(HWND16 hDlg,int x,int y)
2113 int w=GetDialogBaseUnits();
2114 HWND16 hwnd=GetDlgItem32(hDlg,0x2c6);
2115 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2120 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2122 GetClientRect16(hwnd,&rect);
2124 SelectClipRgn32(hDC,CreateRectRgnIndirect16(&rect));
2125 hPen=CreatePen32(PS_SOLID,2,0);
2126 hPen=SelectObject32(hDC,hPen);
2127 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
2128 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
2129 if (lpp->oldcross.left!=lpp->oldcross.right)
2130 BitBlt32(hDC,lpp->oldcross.left,lpp->oldcross.top,
2131 lpp->oldcross.right-lpp->oldcross.left,
2132 lpp->oldcross.bottom-lpp->oldcross.top,
2133 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
2134 lpp->oldcross.left =point.x-w-1;
2135 lpp->oldcross.right =point.x+w+1;
2136 lpp->oldcross.top =point.y-w-1;
2137 lpp->oldcross.bottom=point.y+w+1;
2139 MoveTo(hDC,point.x-w,point.y);
2140 LineTo32(hDC,point.x+w,point.y);
2141 MoveTo(hDC,point.x,point.y-w);
2142 LineTo32(hDC,point.x,point.y+w);
2143 DeleteObject32(SelectObject32(hDC,hPen));
2144 ReleaseDC32(hwnd,hDC);
2153 /***********************************************************************
2154 * CC_PrepareColorGraph [internal]
2156 static void CC_PrepareColorGraph(HWND16 hDlg)
2158 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
2159 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2160 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2164 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT16));
2166 GetClientRect16(hwnd,&client);
2168 lpp->hdcMem = CreateCompatibleDC32(hdc);
2169 lpp->hbmMem = CreateCompatibleBitmap32(hdc,client.right,client.bottom);
2170 SelectObject32(lpp->hdcMem,lpp->hbmMem);
2172 xdif=client.right /XSTEPS;
2173 ydif=client.bottom/YSTEPS+1;
2176 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
2178 rect.right=rect.left+xdif;
2179 rect.bottom=client.bottom;
2180 for(sat=0;sat<240+sdif;sat+=sdif)
2182 rect.top=rect.bottom-ydif;
2183 r=CC_HSLtoRGB('R',hue,sat,120);
2184 g=CC_HSLtoRGB('G',hue,sat,120);
2185 b=CC_HSLtoRGB('B',hue,sat,120);
2186 hbrush=CreateSolidBrush32(RGB(r,g,b));
2187 FillRect16(lpp->hdcMem,&rect,hbrush);
2188 DeleteObject32(hbrush);
2189 rect.bottom=rect.top;
2191 rect.left=rect.right;
2193 ReleaseDC32(hwnd,hdc);
2194 SetCursor16(hcursor);
2197 /***********************************************************************
2198 * CC_PaintColorGraph [internal]
2200 static void CC_PaintColorGraph(HWND16 hDlg)
2202 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
2203 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2206 if (IsWindowVisible32(hwnd)) /* if full size */
2209 CC_PrepareColorGraph(hDlg); /* should not be necessary */
2212 GetClientRect16(hwnd,&rect);
2214 BitBlt32(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
2216 WARN(commdlg,"choose color: hdcMem is not defined\n");
2217 ReleaseDC32(hwnd,hDC);
2220 /***********************************************************************
2221 * CC_PaintLumBar [internal]
2223 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
2225 HWND32 hwnd=GetDlgItem32(hDlg,0x2be);
2227 int lum,ldif,ydif,r,g,b;
2231 if (IsWindowVisible32(hwnd))
2234 GetClientRect16(hwnd,&client);
2238 ydif=client.bottom/YSTEPS+1;
2239 for(lum=0;lum<240+ldif;lum+=ldif)
2241 rect.top=MAX(0,rect.bottom-ydif);
2242 r=CC_HSLtoRGB('R',hue,sat,lum);
2243 g=CC_HSLtoRGB('G',hue,sat,lum);
2244 b=CC_HSLtoRGB('B',hue,sat,lum);
2245 hbrush=CreateSolidBrush32(RGB(r,g,b));
2246 FillRect16(hDC,&rect,hbrush);
2247 DeleteObject32(hbrush);
2248 rect.bottom=rect.top;
2250 GetClientRect16(hwnd,&rect);
2251 FrameRect16(hDC,&rect,GetStockObject32(BLACK_BRUSH));
2252 ReleaseDC32(hwnd,hDC);
2256 /***********************************************************************
2257 * CC_EditSetRGB [internal]
2259 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
2262 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2263 int r=GetRValue(cr);
2264 int g=GetGValue(cr);
2265 int b=GetBValue(cr);
2266 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2269 sprintf(buffer,"%d",r);
2270 SetWindowText32A(GetDlgItem32(hDlg,0x2c2),buffer);
2271 sprintf(buffer,"%d",g);
2272 SetWindowText32A(GetDlgItem32(hDlg,0x2c3),buffer);
2273 sprintf(buffer,"%d",b);
2274 SetWindowText32A(GetDlgItem32(hDlg,0x2c4),buffer);
2275 lpp->updating=FALSE;
2279 /***********************************************************************
2280 * CC_EditSetHSL [internal]
2282 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
2285 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2287 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
2290 sprintf(buffer,"%d",h);
2291 SetWindowText32A(GetDlgItem32(hDlg,0x2bf),buffer);
2292 sprintf(buffer,"%d",s);
2293 SetWindowText32A(GetDlgItem32(hDlg,0x2c0),buffer);
2294 sprintf(buffer,"%d",l);
2295 SetWindowText32A(GetDlgItem32(hDlg,0x2c1),buffer);
2296 lpp->updating=FALSE;
2298 CC_PaintLumBar(hDlg,h,s);
2301 /***********************************************************************
2302 * CC_SwitchToFullSize [internal]
2304 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
2307 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2309 EnableWindow32(GetDlgItem32(hDlg,0x2cf),FALSE);
2310 CC_PrepareColorGraph(hDlg);
2311 for (i=0x2bf;i<0x2c5;i++)
2312 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2313 for (i=0x2d3;i<0x2d9;i++)
2314 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
2315 EnableWindow32(GetDlgItem32(hDlg,0x2c9),TRUE);
2316 EnableWindow32(GetDlgItem32(hDlg,0x2c8),TRUE);
2319 SetWindowPos32(hDlg,0,0,0,lprect->right-lprect->left,
2320 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
2322 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_SHOW);
2323 ShowWindow32(GetDlgItem32(hDlg,0x2be),SW_SHOW);
2324 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_SHOW);
2326 CC_EditSetRGB(hDlg,result);
2327 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2330 /***********************************************************************
2331 * CC_PaintPredefColorArray [internal]
2333 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
2335 HWND32 hwnd=GetDlgItem32(hDlg,0x2d0);
2341 GetClientRect16(hwnd,&rect);
2343 dy=rect.bottom/rows;
2347 GetClientRect16 (hwnd, &rect) ;
2349 for (j=0;j<rows;j++)
2351 for (i=0;i<cols;i++)
2353 hBrush = CreateSolidBrush32(predefcolors[j][i]);
2356 hBrush = SelectObject32 (hdc, hBrush) ;
2357 Rectangle32(hdc, rect.left, rect.top,
2358 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2359 rect.left=rect.left+dx;
2360 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2363 rect.top=rect.top+dy;
2366 ReleaseDC32(hwnd,hdc);
2367 /* FIXME: draw_a_focus_rect */
2369 /***********************************************************************
2370 * CC_PaintUserColorArray [internal]
2372 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
2374 HWND32 hwnd=GetDlgItem32(hDlg,0x2d1);
2380 GetClientRect16(hwnd,&rect);
2383 dy=rect.bottom/rows;
2389 for (j=0;j<rows;j++)
2391 for (i=0;i<cols;i++)
2393 hBrush = CreateSolidBrush32(lpcr[i+j*cols]);
2396 hBrush = SelectObject32 (hdc, hBrush) ;
2397 Rectangle32( hdc, rect.left, rect.top,
2398 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2399 rect.left=rect.left+dx;
2400 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2403 rect.top=rect.top+dy;
2406 ReleaseDC32(hwnd,hdc);
2408 /* FIXME: draw_a_focus_rect */
2413 /***********************************************************************
2414 * CC_HookCallChk [internal]
2416 static BOOL32 CC_HookCallChk(LPCHOOSECOLOR16 lpcc)
2419 if(lpcc->Flags & CC_ENABLEHOOK)
2425 /***********************************************************************
2426 * CC_WMInitDialog [internal]
2428 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2435 struct CCPRIVATE * lpp;
2437 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
2438 lpp=calloc(1,sizeof(struct CCPRIVATE));
2439 lpp->lpcc=(LPCHOOSECOLOR16)lParam;
2441 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR16))
2443 EndDialog32 (hDlg, 0) ;
2446 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
2448 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
2449 ShowWindow32(GetDlgItem32(hDlg,0x40e),SW_HIDE);
2450 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
2453 cpos=MAKELONG(5,7); /* init */
2454 if (lpp->lpcc->Flags & CC_RGBINIT)
2458 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
2465 /* FIXME: Draw_a_focus_rect & set_init_values */
2468 GetWindowRect16(hDlg,&lpp->fullsize);
2469 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2471 hwnd=GetDlgItem32(hDlg,0x2cf);
2472 EnableWindow32(hwnd,FALSE);
2474 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2477 res=rect.bottom-rect.top;
2478 hwnd=GetDlgItem32(hDlg,0x2c6); /* cut at left border */
2480 ClientToScreen16(hwnd,&point);
2481 ScreenToClient16(hDlg,&point);
2482 GetClientRect16(hDlg,&rect);
2483 point.x+=GetSystemMetrics32(SM_CXDLGFRAME);
2484 SetWindowPos32(hDlg,0,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
2486 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_HIDE);
2487 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_HIDE);
2490 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
2492 for (i=0x2bf;i<0x2c5;i++)
2493 SendMessage16(GetDlgItem32(hDlg,i),EM_LIMITTEXT16,3,0); /* max 3 digits: xyz */
2494 if (CC_HookCallChk(lpp->lpcc))
2495 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2498 /* Set the initial values of the color chooser dialog */
2499 r = GetRValue(lpp->lpcc->rgbResult);
2500 g = GetGValue(lpp->lpcc->rgbResult);
2501 b = GetBValue(lpp->lpcc->rgbResult);
2503 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2504 lpp->h=CC_RGBtoHSL('H',r,g,b);
2505 lpp->s=CC_RGBtoHSL('S',r,g,b);
2506 lpp->l=CC_RGBtoHSL('L',r,g,b);
2508 /* Doing it the long way becaus CC_EditSetRGB/HSL doesn'nt seem to work */
2509 SetDlgItemInt32(hDlg, 703, lpp->h, TRUE);
2510 SetDlgItemInt32(hDlg, 704, lpp->s, TRUE);
2511 SetDlgItemInt32(hDlg, 705, lpp->l, TRUE);
2512 SetDlgItemInt32(hDlg, 706, r, TRUE);
2513 SetDlgItemInt32(hDlg, 707, g, TRUE);
2514 SetDlgItemInt32(hDlg, 708, b, TRUE);
2516 CC_PaintCross(hDlg,lpp->h,lpp->s);
2517 CC_PaintTriangle(hDlg,lpp->l);
2522 /***********************************************************************
2523 * CC_WMCommand [internal]
2525 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2531 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2532 TRACE(commdlg,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
2535 case 0x2c2: /* edit notify RGB */
2538 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2540 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
2541 r=GetRValue(lpp->lpcc->rgbResult);
2542 g=GetGValue(lpp->lpcc->rgbResult);
2543 b=GetBValue(lpp->lpcc->rgbResult);
2547 case 0x2c2:if ((xx=(i!=r))) r=i;break;
2548 case 0x2c3:if ((xx=(i!=g))) g=i;break;
2549 case 0x2c4:if ((xx=(i!=b))) b=i;break;
2551 if (xx) /* something has changed */
2553 lpp->lpcc->rgbResult=RGB(r,g,b);
2554 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2555 lpp->h=CC_RGBtoHSL('H',r,g,b);
2556 lpp->s=CC_RGBtoHSL('S',r,g,b);
2557 lpp->l=CC_RGBtoHSL('L',r,g,b);
2558 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2559 CC_PaintCross(hDlg,lpp->h,lpp->s);
2560 CC_PaintTriangle(hDlg,lpp->l);
2565 case 0x2bf: /* edit notify HSL */
2568 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2570 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
2574 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
2575 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
2576 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
2578 if (xx) /* something has changed */
2580 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2581 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2582 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2583 lpp->lpcc->rgbResult=RGB(r,g,b);
2584 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2585 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2586 CC_PaintCross(hDlg,lpp->h,lpp->s);
2587 CC_PaintTriangle(hDlg,lpp->l);
2593 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
2594 InvalidateRect32( hDlg, NULL, TRUE );
2595 SetFocus32(GetDlgItem32(hDlg,0x2bf));
2598 case 0x2c8: /* add colors ... column by column */
2599 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
2600 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
2601 if (++lpp->nextuserdef==16)
2603 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2606 case 0x2c9: /* resulting color */
2608 lpp->lpcc->rgbResult=GetNearestColor32(hdc,lpp->lpcc->rgbResult);
2609 ReleaseDC32(hDlg,hdc);
2610 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2611 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
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);
2618 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2619 CC_PaintCross(hDlg,lpp->h,lpp->s);
2620 CC_PaintTriangle(hDlg,lpp->l);
2623 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2624 i=RegisterWindowMessage32A( HELPMSGSTRING );
2625 if (lpp->lpcc->hwndOwner)
2626 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2627 if (CC_HookCallChk(lpp->lpcc))
2628 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2629 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2633 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2634 if (lpp->lpcc->hwndOwner)
2635 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2636 break; /* do NOT close */
2638 EndDialog32 (hDlg, 1) ;
2642 EndDialog32 (hDlg, 0) ;
2649 /***********************************************************************
2650 * CC_WMPaint [internal]
2652 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2656 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2658 hdc=BeginPaint32(hDlg,&ps);
2659 EndPaint32(hDlg,&ps);
2660 /* we have to paint dialog children except text and buttons */
2662 CC_PaintPredefColorArray(hDlg,6,8);
2663 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2664 CC_PaintColorGraph(hDlg);
2665 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2666 CC_PaintCross(hDlg,lpp->h,lpp->s);
2667 CC_PaintTriangle(hDlg,lpp->l);
2668 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2670 /* special necessary for Wine */
2671 ValidateRect32(GetDlgItem32(hDlg,0x2d0),NULL);
2672 ValidateRect32(GetDlgItem32(hDlg,0x2d1),NULL);
2673 ValidateRect32(GetDlgItem32(hDlg,0x2c6),NULL);
2674 ValidateRect32(GetDlgItem32(hDlg,0x2be),NULL);
2675 ValidateRect32(GetDlgItem32(hDlg,0x2c5),NULL);
2676 /* hope we can remove it later -->FIXME */
2681 /***********************************************************************
2682 * CC_WMLButtonDown [internal]
2684 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2686 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2689 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2692 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2693 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2696 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2699 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2703 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2704 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2705 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2706 lpp->lpcc->rgbResult=RGB(r,g,b);
2710 r=GetRValue(lpp->lpcc->rgbResult);
2711 g=GetGValue(lpp->lpcc->rgbResult);
2712 b=GetBValue(lpp->lpcc->rgbResult);
2713 lpp->h=CC_RGBtoHSL('H',r,g,b);
2714 lpp->s=CC_RGBtoHSL('S',r,g,b);
2715 lpp->l=CC_RGBtoHSL('L',r,g,b);
2719 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2720 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2721 CC_PaintCross(hDlg,lpp->h,lpp->s);
2722 CC_PaintTriangle(hDlg,lpp->l);
2723 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2729 /***********************************************************************
2730 * ColorDlgProc (COMMDLG.8)
2732 LRESULT WINAPI ColorDlgProc(HWND16 hDlg, UINT16 message,
2733 WPARAM16 wParam, LONG lParam)
2736 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2737 if (message!=WM_INITDIALOG)
2742 if (CC_HookCallChk(lpp->lpcc))
2743 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2748 /* FIXME: SetRGB message
2749 if (message && message==msetrgb)
2750 return HandleSetRGB(hDlg,lParam);
2756 return CC_WMInitDialog(hDlg,wParam,lParam);
2758 DeleteDC32(lpp->hdcMem);
2759 DeleteObject32(lpp->hbmMem);
2761 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2764 if (CC_WMCommand(hDlg, wParam, lParam))
2768 if (CC_WMPaint(hDlg, wParam, lParam))
2771 case WM_LBUTTONDBLCLK:
2772 if (CC_MouseCheckResultWindow(hDlg,lParam))
2775 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2777 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2779 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2780 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2787 static void CFn_CHOOSEFONT16to32A(LPCHOOSEFONT16 chf16, LPCHOOSEFONT32A chf32a)
2789 chf32a->lStructSize=sizeof(CHOOSEFONT32A);
2790 chf32a->hwndOwner=chf16->hwndOwner;
2791 chf32a->hDC=chf16->hDC;
2792 chf32a->iPointSize=chf16->iPointSize;
2793 chf32a->Flags=chf16->Flags;
2794 chf32a->rgbColors=chf16->rgbColors;
2795 chf32a->lCustData=chf16->lCustData;
2796 chf32a->lpfnHook=NULL;
2797 chf32a->lpTemplateName=PTR_SEG_TO_LIN(chf16->lpTemplateName);
2798 chf32a->hInstance=chf16->hInstance;
2799 chf32a->lpszStyle=PTR_SEG_TO_LIN(chf16->lpszStyle);
2800 chf32a->nFontType=chf16->nFontType;
2801 chf32a->nSizeMax=chf16->nSizeMax;
2802 chf32a->nSizeMin=chf16->nSizeMin;
2803 FONT_LogFont16To32A(PTR_SEG_TO_LIN(chf16->lpLogFont), chf32a->lpLogFont);
2807 /***********************************************************************
2808 * ChooseFont16 (COMMDLG.15)
2810 BOOL16 WINAPI ChooseFont16(LPCHOOSEFONT16 lpChFont)
2813 HANDLE16 hDlgTmpl = 0;
2814 BOOL16 bRet = FALSE, win32Format = FALSE;
2817 CHOOSEFONT32A cf32a;
2819 SEGPTR lpTemplateName;
2821 cf32a.lpLogFont=&lf32a;
2822 CFn_CHOOSEFONT16to32A(lpChFont, &cf32a);
2824 TRACE(commdlg,"ChooseFont\n");
2825 if (!lpChFont) return FALSE;
2827 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
2829 if (!(template = LockResource16( lpChFont->hInstance )))
2831 CommDlgLastError = CDERR_LOADRESFAILURE;
2835 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2838 if (!(hResInfo = FindResource16( lpChFont->hInstance,
2839 lpChFont->lpTemplateName,
2842 CommDlgLastError = CDERR_FINDRESFAILURE;
2845 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
2846 !(template = LockResource16( hDlgTmpl )))
2848 CommDlgLastError = CDERR_LOADRESFAILURE;
2854 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2858 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2860 /* lpTemplateName is not used in the dialog */
2861 lpTemplateName=lpChFont->lpTemplateName;
2862 lpChFont->lpTemplateName=(SEGPTR)&cf32a;
2864 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
2865 lpChFont->hwndOwner,
2866 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2867 (DWORD)lpChFont, WIN_PROC_16 );
2868 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2869 if (hDlgTmpl) FreeResource16( hDlgTmpl );
2870 lpChFont->lpTemplateName=lpTemplateName;
2871 FONT_LogFont32ATo16(cf32a.lpLogFont,
2872 (LPLOGFONT16)(PTR_SEG_TO_LIN(lpChFont->lpLogFont)));
2877 /***********************************************************************
2878 * ChooseFont32A (COMDLG32.3)
2880 BOOL32 WINAPI ChooseFont32A(LPCHOOSEFONT32A lpChFont)
2884 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2885 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2886 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2887 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2888 hwndDialog = DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2889 (DLGPROC16)FormatCharDlgProc32A, (LPARAM)lpChFont, WIN_PROC_32A );
2890 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2894 /***********************************************************************
2895 * ChooseFont32W (COMDLG32.4)
2897 BOOL32 WINAPI ChooseFont32W(LPCHOOSEFONT32W lpChFont)
2901 HINSTANCE32 hInst=WIN_GetWindowInstance( lpChFont->hwndOwner );
2902 CHOOSEFONT32A cf32a;
2904 LPCVOID template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2905 if (lpChFont->Flags & (CF_SELECTSCRIPT | CF_NOVERTFONTS | CF_ENABLETEMPLATE |
2906 CF_ENABLETEMPLATEHANDLE)) FIXME(commdlg, ": unimplemented flag (ignored)\n");
2907 memcpy(&cf32a, lpChFont, sizeof(cf32a));
2908 memcpy(&lf32a, lpChFont->lpLogFont, sizeof(LOGFONT32A));
2909 lstrcpynWtoA(lf32a.lfFaceName, lpChFont->lpLogFont->lfFaceName, LF_FACESIZE);
2910 cf32a.lpLogFont=&lf32a;
2911 cf32a.lpszStyle=HEAP_strdupWtoA(GetProcessHeap(), 0, lpChFont->lpszStyle);
2912 lpChFont->lpTemplateName=(LPWSTR)&cf32a;
2913 hwndDialog=DIALOG_CreateIndirect(hInst, template, TRUE, lpChFont->hwndOwner,
2914 (DLGPROC16)FormatCharDlgProc32W, (LPARAM)lpChFont, WIN_PROC_32W );
2915 if (hwndDialog)bRet=DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2916 HeapFree(GetProcessHeap(), 0, cf32a.lpszStyle);
2917 lpChFont->lpTemplateName=(LPWSTR)cf32a.lpTemplateName;
2918 memcpy(lpChFont->lpLogFont, &lf32a, sizeof(CHOOSEFONT32A));
2919 lstrcpynAtoW(lpChFont->lpLogFont->lfFaceName, lf32a.lfFaceName, LF_FACESIZE);
2924 #define TEXT_EXTRAS 4
2925 #define TEXT_COLORS 16
2927 static const COLORREF textcolors[TEXT_COLORS]=
2929 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2930 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2931 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2932 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2935 /***********************************************************************
2936 * CFn_HookCallChk [internal]
2938 static BOOL32 CFn_HookCallChk(LPCHOOSEFONT16 lpcf)
2941 if(lpcf->Flags & CF_ENABLEHOOK)
2947 /***********************************************************************
2948 * CFn_HookCallChk32 [internal]
2950 static BOOL32 CFn_HookCallChk32(LPCHOOSEFONT32A lpcf)
2953 if(lpcf->Flags & CF_ENABLEHOOK)
2960 /*************************************************************************
2961 * AddFontFamily [internal]
2963 static INT32 AddFontFamily(LPLOGFONT32A lplf, UINT32 nFontType,
2964 LPCHOOSEFONT32A lpcf, HWND32 hwnd)
2969 TRACE(commdlg,"font=%s (nFontType=%d)\n", lplf->lfFaceName,nFontType);
2971 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2972 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2974 if (lpcf->Flags & CF_ANSIONLY)
2975 if (lplf->lfCharSet != ANSI_CHARSET)
2977 if (lpcf->Flags & CF_TTONLY)
2978 if (!(nFontType & TRUETYPE_FONTTYPE))
2981 i=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)lplf->lfFaceName);
2984 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2985 SendMessage32A(hwnd, CB_SETITEMDATA32, i, MAKELONG(nFontType,w));
2986 return 1 ; /* store some important font information */
2996 LPCHOOSEFONT32A lpcf32a;
2997 } CFn_ENUMSTRUCT, *LPCFn_ENUMSTRUCT;
2999 /*************************************************************************
3000 * FontFamilyEnumProc32 [internal]
3002 INT32 WINAPI FontFamilyEnumProc32(LPENUMLOGFONT32A lpEnumLogFont,
3003 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam)
3006 e=(LPCFn_ENUMSTRUCT)lParam;
3007 return AddFontFamily(&lpEnumLogFont->elfLogFont, nFontType, e->lpcf32a, e->hWnd1);
3010 /***********************************************************************
3011 * FontFamilyEnumProc16 (COMMDLG.19)
3013 INT16 WINAPI FontFamilyEnumProc16( SEGPTR logfont, SEGPTR metrics,
3014 UINT16 nFontType, LPARAM lParam )
3016 HWND16 hwnd=LOWORD(lParam);
3017 HWND16 hDlg=GetParent16(hwnd);
3018 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3019 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
3021 FONT_LogFont16To32A(lplf, &lf32a);
3022 return AddFontFamily(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
3026 /*************************************************************************
3027 * SetFontStylesToCombo2 [internal]
3029 * Fill font style information into combobox (without using font.c directly)
3031 static int SetFontStylesToCombo2(HWND32 hwnd, HDC32 hdc, LPLOGFONT32A lplf)
3038 static struct FONTSTYLE fontstyles[FSTYLES]={
3039 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
3040 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
3045 for (i=0;i<FSTYLES;i++)
3047 lplf->lfItalic=fontstyles[i].italic;
3048 lplf->lfWeight=fontstyles[i].weight;
3049 hf=CreateFontIndirect32A(lplf);
3050 hf=SelectObject32(hdc,hf);
3051 GetTextMetrics16(hdc,&tm);
3052 hf=SelectObject32(hdc,hf);
3055 if (tm.tmWeight==fontstyles[i].weight &&
3056 tm.tmItalic==fontstyles[i].italic) /* font successful created ? */
3058 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
3059 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
3061 if (j==CB_ERR) return 1;
3062 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
3063 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
3064 if (j==CB_ERR) return 1;
3070 /*************************************************************************
3071 * AddFontSizeToCombo3 [internal]
3073 static int AddFontSizeToCombo3(HWND32 hwnd, UINT32 h, LPCHOOSEFONT32A lpcf)
3078 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
3079 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
3081 sprintf(buffer, "%2d", h);
3082 j=SendMessage32A(hwnd, CB_FINDSTRINGEXACT32, -1, (LPARAM)buffer);
3085 j=SendMessage32A(hwnd, CB_ADDSTRING32, 0, (LPARAM)buffer);
3086 if (j!=CB_ERR) j = SendMessage32A(hwnd, CB_SETITEMDATA32, j, h);
3087 if (j==CB_ERR) return 1;
3093 /*************************************************************************
3094 * SetFontSizesToCombo3 [internal]
3096 static int SetFontSizesToCombo3(HWND32 hwnd, LPCHOOSEFONT32A lpcf)
3098 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
3101 for (i=0; sizes[i]; i++)
3102 if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return 1;
3106 /***********************************************************************
3107 * AddFontStyle [internal]
3109 INT32 AddFontStyle(LPLOGFONT32A lplf, UINT32 nFontType,
3110 LPCHOOSEFONT32A lpcf, HWND32 hcmb2, HWND32 hcmb3, HWND32 hDlg)
3114 TRACE(commdlg,"(nFontType=%d)\n",nFontType);
3115 TRACE(commdlg," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d"
3116 " ch=%d op=%d cp=%d q=%d pf=%xh\n",
3117 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,
3118 lplf->lfEscapement,lplf->lfOrientation,
3119 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,
3120 lplf->lfStrikeOut,lplf->lfCharSet, lplf->lfOutPrecision,
3121 lplf->lfClipPrecision,lplf->lfQuality, lplf->lfPitchAndFamily);
3122 if (nFontType & RASTER_FONTTYPE)
3124 if (AddFontSizeToCombo3(hcmb3, lplf->lfHeight, lpcf)) return 0;
3125 } else if (SetFontSizesToCombo3(hcmb3, lpcf)) return 0;
3127 if (!SendMessage32A(hcmb2, CB_GETCOUNT32, 0, 0))
3129 HDC32 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3130 i=SetFontStylesToCombo2(hcmb2,hdc,lplf);
3131 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3132 ReleaseDC32(hDlg,hdc);
3140 /***********************************************************************
3141 * FontStyleEnumProc16 (COMMDLG.18)
3143 INT16 WINAPI FontStyleEnumProc16( SEGPTR logfont, SEGPTR metrics,
3144 UINT16 nFontType, LPARAM lParam )
3146 HWND16 hcmb2=LOWORD(lParam);
3147 HWND16 hcmb3=HIWORD(lParam);
3148 HWND16 hDlg=GetParent16(hcmb3);
3149 LPCHOOSEFONT16 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3150 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
3152 FONT_LogFont16To32A(lplf, &lf32a);
3153 return AddFontStyle(&lf32a, nFontType, (LPCHOOSEFONT32A)lpcf->lpTemplateName,
3154 hcmb2, hcmb3, hDlg);
3157 /***********************************************************************
3158 * FontStyleEnumProc32 [internal]
3160 INT32 WINAPI FontStyleEnumProc32( LPENUMLOGFONT32A lpFont,
3161 LPNEWTEXTMETRIC32A metrics, UINT32 nFontType, LPARAM lParam )
3163 LPCFn_ENUMSTRUCT s=(LPCFn_ENUMSTRUCT)lParam;
3164 HWND32 hcmb2=s->hWnd1;
3165 HWND32 hcmb3=s->hWnd2;
3166 HWND32 hDlg=GetParent32(hcmb3);
3167 return AddFontStyle(&lpFont->elfLogFont, nFontType, s->lpcf32a, hcmb2,
3171 /***********************************************************************
3172 * CFn_WMInitDialog [internal]
3174 LRESULT CFn_WMInitDialog(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3175 LPCHOOSEFONT32A lpcf)
3181 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3183 SetWindowLong32A(hDlg, DWL_USER, lParam);
3184 lpxx=lpcf->lpLogFont;
3185 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
3187 if (lpcf->lStructSize != sizeof(CHOOSEFONT32A))
3189 ERR(commdlg,"structure size failure !!!\n");
3190 EndDialog32 (hDlg, 0);
3194 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3196 /* This font will be deleted by WM_COMMAND */
3197 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,
3198 CreateFont32A(0, 0, 1, 1, 400, 0, 0, 0, 0, 0, 0, 0, 0, NULL),FALSE);
3200 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow32(lpcf->hwndOwner))
3201 ShowWindow32(GetDlgItem32(hDlg,pshHelp),SW_HIDE);
3202 if (!(lpcf->Flags & CF_APPLY))
3203 ShowWindow32(GetDlgItem32(hDlg,psh3),SW_HIDE);
3204 if (lpcf->Flags & CF_EFFECTS)
3206 for (res=1,i=0;res && i<TEXT_COLORS;i++)
3208 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
3210 strcpy( name, "[color name]" );
3211 j=SendDlgItemMessage32A(hDlg, cmb4, CB_ADDSTRING32, 0, (LPARAM)name);
3212 SendDlgItemMessage32A(hDlg, cmb4, CB_SETITEMDATA16, j, textcolors[j]);
3213 /* look for a fitting value in color combobox */
3214 if (textcolors[j]==lpcf->rgbColors)
3215 SendDlgItemMessage32A(hDlg,cmb4, CB_SETCURSEL32,j,0);
3220 ShowWindow32(GetDlgItem32(hDlg,cmb4),SW_HIDE);
3221 ShowWindow32(GetDlgItem32(hDlg,chx1),SW_HIDE);
3222 ShowWindow32(GetDlgItem32(hDlg,chx2),SW_HIDE);
3223 ShowWindow32(GetDlgItem32(hDlg,grp1),SW_HIDE);
3224 ShowWindow32(GetDlgItem32(hDlg,stc4),SW_HIDE);
3226 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3230 s.hWnd1=GetDlgItem32(hDlg,cmb1);
3232 if (!EnumFontFamilies32A(hdc, NULL, FontFamilyEnumProc32, (LPARAM)&s))
3233 TRACE(commdlg,"EnumFontFamilies returns 0\n");
3234 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
3236 /* look for fitting font name in combobox1 */
3237 j=SendDlgItemMessage32A(hDlg,cmb1,CB_FINDSTRING32,-1,(LONG)lpxx->lfFaceName);
3240 SendDlgItemMessage32A(hDlg, cmb1, CB_SETCURSEL32, j, 0);
3241 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3242 GetDlgItem32(hDlg,cmb1));
3244 /* look for fitting font style in combobox2 */
3245 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
3246 for (i=0;i<TEXT_EXTRAS;i++)
3248 if (l==SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0))
3249 SendDlgItemMessage32A(hDlg, cmb2, CB_SETCURSEL32, i, 0);
3252 /* look for fitting font size in combobox3 */
3253 j=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCOUNT32, 0, 0);
3256 if (lpxx->lfHeight==(int)SendDlgItemMessage32A(hDlg,cmb3, CB_GETITEMDATA32,i,0))
3257 SendDlgItemMessage32A(hDlg,cmb3,CB_SETCURSEL32,i,0);
3263 SendDlgItemMessage32A(hDlg,cmb1,CB_SETCURSEL32,0,0);
3264 SendMessage32A(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
3265 GetDlgItem32(hDlg,cmb1));
3267 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
3269 j=SendDlgItemMessage32A(hDlg,cmb2,CB_FINDSTRING32,-1,(LONG)lpcf->lpszStyle);
3272 j=SendDlgItemMessage32A(hDlg,cmb2,CB_SETCURSEL32,j,0);
3273 SendMessage32A(hDlg,WM_COMMAND,cmb2,
3274 MAKELONG(GetDlgItem32(hDlg,cmb2),CBN_SELCHANGE));
3280 WARN(commdlg,"HDC failure !!!\n");
3281 EndDialog32 (hDlg, 0);
3285 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3286 ReleaseDC32(hDlg,hdc);
3287 SetCursor32(hcursor);
3292 /***********************************************************************
3293 * CFn_WMMeasureItem [internal]
3295 LRESULT CFn_WMMeasureItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3298 LPMEASUREITEMSTRUCT32 lpmi=(LPMEASUREITEMSTRUCT32)lParam;
3300 hBitmapTT = LoadBitmap32A(0, MAKEINTRESOURCE32A(OBM_TRTYPE));
3301 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3302 lpmi->itemHeight=bm.bmHeight;
3303 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
3308 /***********************************************************************
3309 * CFn_WMDrawItem [internal]
3311 LRESULT CFn_WMDrawItem(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam)
3316 COLORREF cr, oldText=0, oldBk=0;
3321 HBITMAP32 hBitmap; /* for later TT usage */
3323 LPDRAWITEMSTRUCT32 lpdi = (LPDRAWITEMSTRUCT32)lParam;
3325 if (lpdi->itemID == 0xFFFF) /* got no items */
3326 DrawFocusRect32(lpdi->hDC, &lpdi->rcItem);
3329 if (lpdi->CtlType == ODT_COMBOBOX)
3331 if (lpdi->itemState ==ODS_SELECTED)
3333 hBrush=GetSysColorBrush32(COLOR_HIGHLIGHT);
3334 oldText=SetTextColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHTTEXT));
3335 oldBk=SetBkColor32(lpdi->hDC, GetSysColor32(COLOR_HIGHLIGHT));
3338 hBrush = SelectObject32(lpdi->hDC, GetStockObject32(LTGRAY_BRUSH));
3339 SelectObject32(lpdi->hDC, hBrush);
3341 FillRect32(lpdi->hDC, &lpdi->rcItem, hBrush);
3344 return TRUE; /* this should never happen */
3347 switch (lpdi->CtlID)
3349 case cmb1: /* TRACE(commdlg,"WM_Drawitem cmb1\n"); */
3350 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3352 GetObject32A( hBitmapTT, sizeof(bm), &bm );
3353 TextOut32A(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
3354 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3356 nFontType = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3357 /* FIXME: draw bitmap if truetype usage */
3358 if (nFontType&TRUETYPE_FONTTYPE)
3360 hMemDC = CreateCompatibleDC32(lpdi->hDC);
3361 hBitmap = SelectObject32(hMemDC, hBitmapTT);
3362 BitBlt32(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
3363 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
3364 SelectObject32(hMemDC, hBitmap);
3370 case cmb3: /* TRACE(commdlg,"WM_DRAWITEN cmb2,cmb3\n"); */
3371 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3373 TextOut32A(lpdi->hDC, lpdi->rcItem.left,
3374 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3377 case cmb4: /* TRACE(commdlg,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
3378 SendMessage32A(lpdi->hwndItem, CB_GETLBTEXT32, lpdi->itemID,
3380 TextOut32A(lpdi->hDC, lpdi->rcItem.left + 25+5,
3381 lpdi->rcItem.top, buffer, lstrlen32A(buffer));
3382 cr = SendMessage32A(lpdi->hwndItem, CB_GETITEMDATA32, lpdi->itemID,0L);
3383 hBrush = CreateSolidBrush32(cr);
3386 hBrush = SelectObject32 (lpdi->hDC, hBrush) ;
3387 rect.right=rect.left+25;
3391 Rectangle32( lpdi->hDC, rect.left, rect.top,
3392 rect.right, rect.bottom );
3393 DeleteObject32( SelectObject32 (lpdi->hDC, hBrush)) ;
3399 default: return TRUE; /* this should never happen */
3401 if (lpdi->itemState == ODS_SELECTED)
3403 SetTextColor32(lpdi->hDC, oldText);
3404 SetBkColor32(lpdi->hDC, oldBk);
3410 /***********************************************************************
3411 * CFn_WMCtlColor [internal]
3413 LRESULT CFn_WMCtlColorStatic(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3414 LPCHOOSEFONT32A lpcf)
3416 if (lpcf->Flags & CF_EFFECTS)
3417 if (GetDlgCtrlID32(lParam)==stc6)
3419 SetTextColor32((HDC32)wParam, lpcf->rgbColors);
3420 return GetStockObject32(WHITE_BRUSH);
3425 /***********************************************************************
3426 * CFn_WMCommand [internal]
3428 LRESULT CFn_WMCommand(HWND32 hDlg, WPARAM32 wParam, LPARAM lParam,
3429 LPCHOOSEFONT32A lpcf)
3435 LPLOGFONT32A lpxx=lpcf->lpLogFont;
3437 TRACE(commdlg,"WM_COMMAND wParam=%08lX lParam=%08lX\n", (LONG)wParam, lParam);
3438 switch (LOWORD(wParam))
3440 case cmb1:if (HIWORD(wParam)==CBN_SELCHANGE)
3442 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
3445 SendDlgItemMessage32A(hDlg, cmb2, CB_RESETCONTENT16, 0, 0);
3446 SendDlgItemMessage32A(hDlg, cmb3, CB_RESETCONTENT16, 0, 0);
3447 i=SendDlgItemMessage32A(hDlg, cmb1, CB_GETCURSEL16, 0, 0);
3450 HCURSOR32 hcursor=SetCursor32(LoadCursor32A(0,IDC_WAIT32A));
3453 SendDlgItemMessage32A(hDlg, cmb1, CB_GETLBTEXT32, i,
3455 TRACE(commdlg,"WM_COMMAND/cmb1 =>%s\n",str);
3456 s.hWnd1=GetDlgItem32(hDlg, cmb2);
3457 s.hWnd2=GetDlgItem32(hDlg, cmb3);
3459 EnumFontFamilies32A(hdc, str, FontStyleEnumProc32, (LPARAM)&s);
3460 SetCursor32(hcursor);
3462 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
3463 ReleaseDC32(hDlg,hdc);
3467 WARN(commdlg,"HDC failure !!!\n");
3468 EndDialog32 (hDlg, 0);
3475 case cmb3:if (HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)== BN_CLICKED )
3478 TRACE(commdlg,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
3479 i=SendDlgItemMessage32A(hDlg,cmb1,CB_GETCURSEL32,0,0);
3481 i=GetDlgItemText32A( hDlg, cmb1, str, 256 );
3484 SendDlgItemMessage32A(hDlg,cmb1,CB_GETLBTEXT32,i,
3486 l=SendDlgItemMessage32A(hDlg,cmb1,CB_GETITEMDATA32,i,0);
3488 lpcf->nFontType = LOWORD(l);
3489 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
3490 /* same value reported to the EnumFonts
3491 call back with the extra FONTTYPE_... bits added */
3492 lpxx->lfPitchAndFamily=j&0xff;
3493 lpxx->lfCharSet=j>>8;
3495 strcpy(lpxx->lfFaceName,str);
3496 i=SendDlgItemMessage32A(hDlg, cmb2, CB_GETCURSEL32, 0, 0);
3499 l=SendDlgItemMessage32A(hDlg, cmb2, CB_GETITEMDATA32, i, 0);
3500 if (0!=(lpxx->lfItalic=HIWORD(l)))
3501 lpcf->nFontType |= ITALIC_FONTTYPE;
3502 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
3503 lpcf->nFontType |= BOLD_FONTTYPE;
3505 i=SendDlgItemMessage32A(hDlg, cmb3, CB_GETCURSEL32, 0, 0);
3507 lpxx->lfHeight=-LOWORD(SendDlgItemMessage32A(hDlg, cmb3, CB_GETITEMDATA32, i, 0));
3510 lpxx->lfStrikeOut=IsDlgButtonChecked32(hDlg,chx1);
3511 lpxx->lfUnderline=IsDlgButtonChecked32(hDlg,chx2);
3512 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
3513 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
3514 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
3515 lpxx->lfQuality=DEFAULT_QUALITY;
3516 lpcf->iPointSize= -10*lpxx->lfHeight;
3518 hFont=CreateFontIndirect32A(lpxx);
3521 HFONT32 oldFont=SendDlgItemMessage32A(hDlg, stc6,
3523 SendDlgItemMessage32A(hDlg,stc6,WM_SETFONT,hFont,TRUE);
3524 DeleteObject32(oldFont);
3529 case cmb4:i=SendDlgItemMessage32A(hDlg, cmb4, CB_GETCURSEL32, 0, 0);
3532 lpcf->rgbColors=textcolors[i];
3533 InvalidateRect32( GetDlgItem32(hDlg,stc6), NULL, 0 );
3537 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
3538 if (lpcf->hwndOwner)
3539 SendMessage32A(lpcf->hwndOwner, i, 0, (LPARAM)GetWindowLong32A(hDlg, DWL_USER));
3540 /* if (CFn_HookCallChk(lpcf))
3541 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);*/
3544 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
3545 ( (lpcf->Flags & CF_LIMITSIZE) &&
3546 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
3547 (-lpxx->lfHeight <= lpcf->nSizeMax)))
3548 EndDialog32(hDlg, TRUE);
3552 sprintf(buffer,"Select a font size between %d and %d points.",
3553 lpcf->nSizeMin,lpcf->nSizeMax);
3554 MessageBox32A(hDlg, buffer, NULL, MB_OK);
3557 case IDCANCEL:EndDialog32(hDlg, FALSE);
3563 static LRESULT CFn_WMDestroy(HWND32 hwnd, WPARAM32 wParam, LPARAM lParam)
3565 DeleteObject32(SendDlgItemMessage32A(hwnd, stc6, WM_GETFONT, 0, 0));
3570 /***********************************************************************
3571 * FormatCharDlgProc16 (COMMDLG.16)
3572 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
3573 2. some CF_.. flags are not supported
3574 3. some TType extensions
3576 LRESULT WINAPI FormatCharDlgProc16(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
3579 LPCHOOSEFONT16 lpcf;
3580 LPCHOOSEFONT32A lpcf32a;
3584 if (message!=WM_INITDIALOG)
3586 lpcf=(LPCHOOSEFONT16)GetWindowLong32A(hDlg, DWL_USER);
3589 if (CFn_HookCallChk(lpcf))
3590 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
3596 lpcf=(LPCHOOSEFONT16)lParam;
3597 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3598 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3600 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3603 if (CFn_HookCallChk(lpcf))
3604 return CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3606 WINPROC_MapMsg16To32A(message, wParam, &uMsg32, &wParam32, &lParam);
3607 lpcf32a=(LPCHOOSEFONT32A)lpcf->lpTemplateName;
3610 case WM_MEASUREITEM:
3611 res=CFn_WMMeasureItem(hDlg, wParam32, lParam);
3614 res=CFn_WMDrawItem(hDlg, wParam32, lParam);
3616 case WM_CTLCOLORSTATIC:
3617 res=CFn_WMCtlColorStatic(hDlg, wParam32, lParam, lpcf32a);
3620 res=CFn_WMCommand(hDlg, wParam32, lParam, lpcf32a);
3623 res=CFn_WMDestroy(hDlg, wParam32, lParam);
3625 case WM_CHOOSEFONT_GETLOGFONT:
3626 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3628 FIXME(commdlg, "current logfont back to caller\n");
3631 WINPROC_UnmapMsg16To32A(hDlg,uMsg32, wParam32, lParam, res);
3635 /***********************************************************************
3636 * FormatCharDlgProc32A [internal]
3638 LRESULT WINAPI FormatCharDlgProc32A(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3641 LPCHOOSEFONT32A lpcf;
3643 if (uMsg!=WM_INITDIALOG)
3645 lpcf=(LPCHOOSEFONT32A)GetWindowLong32A(hDlg, DWL_USER);
3648 if (CFn_HookCallChk32(lpcf))
3649 res=CallWindowProc32A(lpcf->lpfnHook, hDlg, uMsg, wParam, lParam);
3655 lpcf=(LPCHOOSEFONT32A)lParam;
3656 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf))
3658 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3661 if (CFn_HookCallChk32(lpcf))
3662 return CallWindowProc32A(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3666 case WM_MEASUREITEM:
3667 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3669 return CFn_WMDrawItem(hDlg, wParam, lParam);
3670 case WM_CTLCOLORSTATIC:
3671 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf);
3673 return CFn_WMCommand(hDlg, wParam, lParam, lpcf);
3675 return CFn_WMDestroy(hDlg, wParam, lParam);
3676 case WM_CHOOSEFONT_GETLOGFONT:
3677 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3679 FIXME(commdlg, "current logfont back to caller\n");
3685 /***********************************************************************
3686 * FormatCharDlgProc32W [internal]
3688 LRESULT WINAPI FormatCharDlgProc32W(HWND32 hDlg, UINT32 uMsg, WPARAM32 wParam,
3691 LPCHOOSEFONT32W lpcf32w;
3692 LPCHOOSEFONT32A lpcf32a;
3694 if (uMsg!=WM_INITDIALOG)
3696 lpcf32w=(LPCHOOSEFONT32W)GetWindowLong32A(hDlg, DWL_USER);
3699 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3700 res=CallWindowProc32W(lpcf32w->lpfnHook, hDlg, uMsg, wParam, lParam);
3706 lpcf32w=(LPCHOOSEFONT32W)lParam;
3707 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3708 if (!CFn_WMInitDialog(hDlg, wParam, lParam, lpcf32a))
3710 TRACE(commdlg, "CFn_WMInitDialog returned FALSE\n");
3713 if (CFn_HookCallChk32((LPCHOOSEFONT32A)lpcf32w))
3714 return CallWindowProc32W(lpcf32w->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
3716 lpcf32a=(LPCHOOSEFONT32A)lpcf32w->lpTemplateName;
3719 case WM_MEASUREITEM:
3720 return CFn_WMMeasureItem(hDlg, wParam, lParam);
3722 return CFn_WMDrawItem(hDlg, wParam, lParam);
3723 case WM_CTLCOLORSTATIC:
3724 return CFn_WMCtlColorStatic(hDlg, wParam, lParam, lpcf32a);
3726 return CFn_WMCommand(hDlg, wParam, lParam, lpcf32a);
3728 return CFn_WMDestroy(hDlg, wParam, lParam);
3729 case WM_CHOOSEFONT_GETLOGFONT:
3730 TRACE(commdlg,"WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n",
3732 FIXME(commdlg, "current logfont back to caller\n");
3739 static BOOL32 Commdlg_GetFileName32A( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
3740 LPOPENFILENAME32A ofn )
3743 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3745 memset(ofn16,'\0',sizeof(*ofn16));
3746 ofn16->lStructSize = sizeof(*ofn16);
3747 ofn16->hwndOwner = ofn->hwndOwner;
3748 ofn16->hInstance = MapHModuleLS(ofn->hInstance);
3749 if (ofn->lpstrFilter) {
3752 /* filter is a list... title\0ext\0......\0\0 */
3753 s = (LPSTR)ofn->lpstrFilter;
3757 x = (LPSTR)SEGPTR_ALLOC(s-ofn->lpstrFilter);
3758 memcpy(x,ofn->lpstrFilter,s-ofn->lpstrFilter);
3759 ofn16->lpstrFilter = SEGPTR_GET(x);
3761 if (ofn->lpstrCustomFilter) {
3764 /* filter is a list... title\0ext\0......\0\0 */
3765 s = (LPSTR)ofn->lpstrCustomFilter;
3769 x = SEGPTR_ALLOC(s-ofn->lpstrCustomFilter);
3770 memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);
3771 ofn16->lpstrCustomFilter = SEGPTR_GET(x);
3773 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3774 ofn16->nFilterIndex = ofn->nFilterIndex;
3776 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3777 ofn16->nMaxFile = ofn->nMaxFile;
3778 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3779 if (ofn16->nMaxFileTitle)
3780 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3781 if (ofn->lpstrInitialDir)
3782 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrInitialDir));
3783 if (ofn->lpstrTitle)
3784 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrTitle));
3785 ofn16->Flags = ofn->Flags|OFN_WINE32;
3786 ofn16->nFileOffset = ofn->nFileOffset;
3787 ofn16->nFileExtension = ofn->nFileExtension;
3788 if (ofn->lpstrDefExt)
3789 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrDefExt));
3790 ofn16->lCustData = ofn->lCustData;
3791 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3793 if (ofn->lpTemplateName)
3794 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpTemplateName));
3796 ret = dofunction(SEGPTR_GET(ofn16));
3798 ofn->nFileOffset = ofn16->nFileOffset;
3799 ofn->nFileExtension = ofn16->nFileExtension;
3800 if (ofn16->lpstrFilter)
3801 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3802 if (ofn16->lpTemplateName)
3803 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3804 if (ofn16->lpstrDefExt)
3805 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3806 if (ofn16->lpstrTitle)
3807 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3808 if (ofn16->lpstrInitialDir)
3809 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3810 if (ofn16->lpstrCustomFilter)
3811 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3813 if (ofn16->lpstrFile)
3815 strcpy(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3816 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3819 if (ofn16->lpstrFileTitle)
3821 strcpy(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3822 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3828 static BOOL32 Commdlg_GetFileName32W( BOOL16 (CALLBACK *dofunction)(SEGPTR x),
3829 LPOPENFILENAME32W ofn )
3832 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16));
3834 memset(ofn16,'\0',sizeof(*ofn16));
3835 ofn16->lStructSize = sizeof(*ofn16);
3836 ofn16->hwndOwner = ofn->hwndOwner;
3837 ofn16->hInstance = MapHModuleLS(ofn->hInstance);
3838 if (ofn->lpstrFilter) {
3843 /* filter is a list... title\0ext\0......\0\0 */
3844 s = (LPWSTR)ofn->lpstrFilter;
3846 s = s+lstrlen32W(s)+1;
3848 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */
3849 x = y = (LPSTR)SEGPTR_ALLOC(n);
3850 s = (LPWSTR)ofn->lpstrFilter;
3857 ofn16->lpstrFilter = SEGPTR_GET(y);
3859 if (ofn->lpstrCustomFilter) {
3864 /* filter is a list... title\0ext\0......\0\0 */
3865 s = (LPWSTR)ofn->lpstrCustomFilter;
3867 s = s+lstrlen32W(s)+1;
3869 n = s - ofn->lpstrCustomFilter;
3870 x = y = (LPSTR)SEGPTR_ALLOC(n);
3871 s = (LPWSTR)ofn->lpstrCustomFilter;
3878 ofn16->lpstrCustomFilter = SEGPTR_GET(y);
3880 ofn16->nMaxCustFilter = ofn->nMaxCustFilter;
3881 ofn16->nFilterIndex = ofn->nFilterIndex;
3883 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile));
3884 ofn16->nMaxFile = ofn->nMaxFile;
3885 ofn16->nMaxFileTitle = ofn->nMaxFileTitle;
3886 if (ofn->nMaxFileTitle)
3887 ofn16->lpstrFileTitle = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFileTitle));
3888 if (ofn->lpstrInitialDir)
3889 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrInitialDir));
3890 if (ofn->lpstrTitle)
3891 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrTitle));
3892 ofn16->Flags = ofn->Flags|OFN_WINE32|OFN_UNICODE;
3893 ofn16->nFileOffset = ofn->nFileOffset;
3894 ofn16->nFileExtension = ofn->nFileExtension;
3895 if (ofn->lpstrDefExt)
3896 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrDefExt));
3897 ofn16->lCustData = ofn->lCustData;
3898 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook;
3899 if (ofn->lpTemplateName)
3900 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpTemplateName));
3901 ret = dofunction(SEGPTR_GET(ofn16));
3903 ofn->nFileOffset = ofn16->nFileOffset;
3904 ofn->nFileExtension = ofn16->nFileExtension;
3905 if (ofn16->lpstrFilter)
3906 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter));
3907 if (ofn16->lpTemplateName)
3908 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName));
3909 if (ofn16->lpstrDefExt)
3910 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt));
3911 if (ofn16->lpstrTitle)
3912 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle));
3913 if (ofn16->lpstrInitialDir)
3914 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir));
3915 if (ofn16->lpstrCustomFilter)
3916 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter));
3918 if (ofn16->lpstrFile) {
3919 lstrcpyAtoW(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile));
3920 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile));
3923 if (ofn16->lpstrFileTitle) {
3924 lstrcpyAtoW(ofn->lpstrFileTitle,PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3925 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle));
3931 /***********************************************************************
3932 * GetOpenFileName32A (COMDLG32.10)
3934 BOOL32 WINAPI GetOpenFileName32A( LPOPENFILENAME32A ofn )
3936 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3937 return Commdlg_GetFileName32A(dofunction,ofn);
3940 /***********************************************************************
3941 * GetOpenFileName32W (COMDLG32.11)
3943 BOOL32 WINAPI GetOpenFileName32W( LPOPENFILENAME32W ofn )
3945 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetOpenFileName16;
3946 return Commdlg_GetFileName32W(dofunction,ofn);
3949 /***********************************************************************
3950 * GetSaveFileName32A (COMDLG32.12)
3952 BOOL32 WINAPI GetSaveFileName32A( LPOPENFILENAME32A ofn )
3954 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3955 return Commdlg_GetFileName32A(dofunction,ofn);
3958 /***********************************************************************
3959 * GetSaveFileName32W (COMDLG32.13)
3961 BOOL32 WINAPI GetSaveFileName32W( LPOPENFILENAME32W ofn )
3963 BOOL16 (CALLBACK * dofunction)(SEGPTR ofn16) = GetSaveFileName16;
3964 return Commdlg_GetFileName32W(dofunction,ofn);
3967 /***********************************************************************
3968 * ChooseColorA (COMDLG32.1)
3970 BOOL32 WINAPI ChooseColor32A(LPCHOOSECOLOR32A lpChCol )
3975 COLORREF* ccref=SEGPTR_ALLOC(64);
3976 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
3978 memset(lpcc16,'\0',sizeof(*lpcc16));
3979 lpcc16->lStructSize=sizeof(*lpcc16);
3980 lpcc16->hwndOwner=lpChCol->hwndOwner;
3981 lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
3982 lpcc16->rgbResult=lpChCol->rgbResult;
3983 memcpy(ccref,lpChCol->lpCustColors,64);
3984 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
3985 lpcc16->Flags=lpChCol->Flags;
3986 lpcc16->lCustData=lpChCol->lCustData;
3987 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
3988 if (lpChCol->lpTemplateName)
3989 str = SEGPTR_STRDUP(lpChCol->lpTemplateName );
3990 lpcc16->lpTemplateName=SEGPTR_GET(str);
3992 ret = ChooseColor16(lpcc16);
3995 lpChCol->rgbResult = lpcc16->rgbResult;
3999 memcpy(lpChCol->lpCustColors,ccref,64);
4001 SEGPTR_FREE(lpcc16);
4005 /***********************************************************************
4006 * ChooseColorW (COMDLG32.2)
4008 BOOL32 WINAPI ChooseColor32W(LPCHOOSECOLOR32W lpChCol )
4013 COLORREF* ccref=SEGPTR_ALLOC(64);
4014 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
4016 memset(lpcc16,'\0',sizeof(*lpcc16));
4017 lpcc16->lStructSize=sizeof(*lpcc16);
4018 lpcc16->hwndOwner=lpChCol->hwndOwner;
4019 lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
4020 lpcc16->rgbResult=lpChCol->rgbResult;
4021 memcpy(ccref,lpChCol->lpCustColors,64);
4022 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
4023 lpcc16->Flags=lpChCol->Flags;
4024 lpcc16->lCustData=lpChCol->lCustData;
4025 lpcc16->lpfnHook=(WNDPROC16)lpChCol->lpfnHook;
4026 if (lpChCol->lpTemplateName)
4027 str = SEGPTR_STRDUP_WtoA(lpChCol->lpTemplateName );
4028 lpcc16->lpTemplateName=SEGPTR_GET(str);
4030 ret = ChooseColor16(lpcc16);
4033 lpChCol->rgbResult = lpcc16->rgbResult;
4037 memcpy(lpChCol->lpCustColors,ccref,64);
4039 SEGPTR_FREE(lpcc16);
4043 /***********************************************************************
4044 * PageSetupDlgA (COMDLG32.15)
4046 BOOL32 WINAPI PageSetupDlg32A(LPPAGESETUPDLG32A setupdlg) {
4047 FIXME(commdlg,"(%p), stub!\n",setupdlg);