Release 971012
[wine/multimedia.git] / misc / commdlg.c
blob4c3668dbee182680124945712beaf0c4cbf86897
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "win.h"
12 #include "heap.h"
13 #include "message.h"
14 #include "commdlg.h"
15 #include "dialog.h"
16 #include "dlgs.h"
17 #include "module.h"
18 #include "resource.h"
19 #include "drive.h"
20 #include "stddebug.h"
21 #include "debug.h"
23 static DWORD CommDlgLastError = 0;
25 static HBITMAP16 hFolder = 0;
26 static HBITMAP16 hFolder2 = 0;
27 static HBITMAP16 hFloppy = 0;
28 static HBITMAP16 hHDisk = 0;
29 static HBITMAP16 hCDRom = 0;
30 static HBITMAP16 hBitmapTT = 0;
32 /***********************************************************************
33 * FileDlg_Init [internal]
35 static BOOL32 FileDlg_Init()
37 static BOOL32 initialized = 0;
39 if (!initialized) {
40 if (!hFolder) hFolder = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER));
41 if (!hFolder2) hFolder2 = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FOLDER2));
42 if (!hFloppy) hFloppy = LoadBitmap16(0, MAKEINTRESOURCE(OBM_FLOPPY));
43 if (!hHDisk) hHDisk = LoadBitmap16(0, MAKEINTRESOURCE(OBM_HDISK));
44 if (!hCDRom) hCDRom = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CDROM));
45 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
46 hHDisk == 0 || hCDRom == 0)
48 fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
49 return FALSE;
51 initialized = TRUE;
53 return TRUE;
56 /***********************************************************************
57 * GetOpenFileName (COMMDLG.1)
59 BOOL16 WINAPI GetOpenFileName16( SEGPTR ofn )
61 HINSTANCE32 hInst;
62 HANDLE32 hDlgTmpl = 0, hResInfo;
63 BOOL32 bRet = FALSE, win32Format = FALSE;
64 HWND32 hwndDialog;
65 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
66 LPCVOID template;
68 if (!lpofn || !FileDlg_Init()) return FALSE;
70 if (lpofn->Flags & OFN_WINE32) {
71 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
73 if (!(template = LockResource32( lpofn->hInstance )))
75 CommDlgLastError = CDERR_LOADRESFAILURE;
76 return FALSE;
79 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
81 if (!(hResInfo = FindResource32A(lpofn->hInstance,
82 PTR_SEG_TO_LIN(lpofn->lpTemplateName), (LPSTR)RT_DIALOG)))
84 CommDlgLastError = CDERR_FINDRESFAILURE;
85 return FALSE;
87 if (!(hDlgTmpl = LoadResource32( lpofn->hInstance, hResInfo )) ||
88 !(template = LockResource32( hDlgTmpl )))
90 CommDlgLastError = CDERR_LOADRESFAILURE;
91 return FALSE;
93 } else {
94 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
96 win32Format = TRUE;
97 } else {
98 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
100 if (!(template = LockResource16( lpofn->hInstance )))
102 CommDlgLastError = CDERR_LOADRESFAILURE;
103 return FALSE;
106 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
108 if (!(hResInfo = FindResource16(lpofn->hInstance,
109 lpofn->lpTemplateName, RT_DIALOG)))
111 CommDlgLastError = CDERR_FINDRESFAILURE;
112 return FALSE;
114 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
115 !(template = LockResource16( hDlgTmpl )))
117 CommDlgLastError = CDERR_LOADRESFAILURE;
118 return FALSE;
120 } else {
121 template = SYSRES_GetResPtr( SYSRES_DIALOG_OPEN_FILE );
122 win32Format = TRUE;
126 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
127 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
128 lpofn->hwndOwner,
129 (DLGPROC16)MODULE_GetWndProcEntry16("FileOpenDlgProc"),
130 ofn, WIN_PROC_16 );
131 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
133 if (hDlgTmpl) {
134 if (lpofn->Flags & OFN_WINE32)
135 FreeResource32( hDlgTmpl );
136 else
137 FreeResource16( hDlgTmpl );
140 dprintf_commdlg(stddeb,"GetOpenFileName // return lpstrFile='%s' !\n",
141 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
142 return bRet;
146 /***********************************************************************
147 * GetSaveFileName (COMMDLG.2)
149 BOOL16 WINAPI GetSaveFileName16( SEGPTR ofn)
151 HINSTANCE32 hInst;
152 HANDLE32 hDlgTmpl = 0;
153 BOOL32 bRet = FALSE, win32Format = FALSE;
154 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(ofn);
155 LPCVOID template;
156 HWND32 hwndDialog;
158 if (!lpofn || !FileDlg_Init()) return FALSE;
160 if (lpofn->Flags & OFN_WINE32) {
161 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
163 if (!(template = LockResource32( lpofn->hInstance )))
165 CommDlgLastError = CDERR_LOADRESFAILURE;
166 return FALSE;
169 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
171 HANDLE32 hResInfo;
172 if (!(hResInfo = FindResource32A(lpofn->hInstance,
173 PTR_SEG_TO_LIN(lpofn->lpTemplateName), (LPSTR)RT_DIALOG)))
175 CommDlgLastError = CDERR_FINDRESFAILURE;
176 return FALSE;
178 if (!(hDlgTmpl = LoadResource32(lpofn->hInstance,hResInfo)) ||
179 !(template = LockResource32(hDlgTmpl)))
181 CommDlgLastError = CDERR_LOADRESFAILURE;
182 return FALSE;
184 win32Format= TRUE;
185 } else {
186 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
187 win32Format = TRUE;
189 } else {
190 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE)
192 if (!(template = LockResource16( lpofn->hInstance )))
194 CommDlgLastError = CDERR_LOADRESFAILURE;
195 return FALSE;
198 else if (lpofn->Flags & OFN_ENABLETEMPLATE)
200 HANDLE16 hResInfo;
201 if (!(hResInfo = FindResource16(lpofn->hInstance,
202 lpofn->lpTemplateName, RT_DIALOG)))
204 CommDlgLastError = CDERR_FINDRESFAILURE;
205 return FALSE;
207 if (!(hDlgTmpl = LoadResource16( lpofn->hInstance, hResInfo )) ||
208 !(template = LockResource16( hDlgTmpl )))
210 CommDlgLastError = CDERR_LOADRESFAILURE;
211 return FALSE;
213 } else {
214 template = SYSRES_GetResPtr( SYSRES_DIALOG_SAVE_FILE );
215 win32Format = TRUE;
219 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
221 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
222 lpofn->hwndOwner,
223 (DLGPROC16)MODULE_GetWndProcEntry16("FileSaveDlgProc"),
224 ofn, WIN_PROC_16 );
225 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpofn->hwndOwner );
227 if (hDlgTmpl) {
228 if (lpofn->Flags & OFN_WINE32)
229 FreeResource32( hDlgTmpl );
230 else
231 FreeResource16( hDlgTmpl );
234 dprintf_commdlg(stddeb, "GetSaveFileName // return lpstrFile='%s' !\n",
235 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
236 return bRet;
239 /***********************************************************************
240 * FILEDLG_StripEditControl [internal]
241 * Strip pathnames off the contents of the edit control.
243 static void FILEDLG_StripEditControl(HWND16 hwnd)
245 char temp[512], *cp;
247 GetDlgItemText32A( hwnd, edt1, temp, sizeof(temp) );
248 cp = strrchr(temp, '\\');
249 if (cp != NULL) {
250 strcpy(temp, cp+1);
252 cp = strrchr(temp, ':');
253 if (cp != NULL) {
254 strcpy(temp, cp+1);
256 /* FIXME: shouldn't we do something with the result here? ;-) */
259 /***********************************************************************
260 * FILEDLG_ScanDir [internal]
262 static BOOL32 FILEDLG_ScanDir(HWND16 hWnd, LPSTR newPath)
264 int len;
265 char str[512];
267 lstrcpyn32A( str, newPath, 512 );
268 len = strlen(str);
269 GetDlgItemText32A( hWnd, edt1, str + len, sizeof(str) - len );
270 if (!DlgDirList32A( hWnd, str, lst1, 0, 0x0000 )) return FALSE;
271 strcpy( str, "*.*" );
272 return DlgDirList32A( hWnd, str, lst2, stc1, 0x8010 );
275 /***********************************************************************
276 * FILEDLG_GetFileType [internal]
279 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
281 int n, i;
282 i = 0;
283 if (cfptr)
284 for ( ;(n = strlen(cfptr)) != 0; i++)
286 cfptr += n + 1;
287 if (i == index)
288 return cfptr;
289 cfptr += strlen(cfptr) + 1;
291 if (fptr)
292 for ( ;(n = strlen(fptr)) != 0; i++)
294 fptr += n + 1;
295 if (i == index)
296 return fptr;
297 fptr += strlen(fptr) + 1;
299 return "*.*"; /* FIXME */
302 /***********************************************************************
303 * FILEDLG_WMDrawItem [internal]
305 static LONG FILEDLG_WMDrawItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam,int savedlg)
307 LPDRAWITEMSTRUCT16 lpdis = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
308 char *str;
309 HBRUSH32 hBrush;
310 HBITMAP16 hBitmap, hPrevBitmap;
311 BITMAP16 bm;
312 HDC32 hMemDC;
314 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1)
316 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
317 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
318 SelectObject32(lpdis->hDC, hBrush);
319 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
320 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
321 (LPARAM)SEGPTR_GET(str));
323 if (savedlg) /* use _gray_ text in FileSaveDlg */
324 if (!lpdis->itemState)
325 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_GRAYTEXT) );
326 else
327 SetTextColor32(lpdis->hDC,GetSysColor32(COLOR_WINDOWTEXT) );
328 /* inversion of gray would be bad readable */
330 TextOut16(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
331 str, strlen(str));
332 if (lpdis->itemState != 0) {
333 InvertRect16(lpdis->hDC, &lpdis->rcItem);
335 SEGPTR_FREE(str);
336 return TRUE;
339 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2)
341 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
342 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
343 SelectObject32(lpdis->hDC, hBrush);
344 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
345 SendMessage16(lpdis->hwndItem, LB_GETTEXT16, lpdis->itemID,
346 (LPARAM)SEGPTR_GET(str));
348 hBitmap = hFolder;
349 GetObject16( hBitmap, sizeof(bm), &bm );
350 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
351 lpdis->rcItem.top, str, strlen(str));
352 hMemDC = CreateCompatibleDC32(lpdis->hDC);
353 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
354 BitBlt32(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
355 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
356 SelectObject32(hMemDC, hPrevBitmap);
357 DeleteDC32(hMemDC);
358 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
359 SEGPTR_FREE(str);
360 return TRUE;
362 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2)
364 if (!(str = SEGPTR_ALLOC(512))) return FALSE;
365 hBrush = SelectObject32(lpdis->hDC, GetStockObject32(LTGRAY_BRUSH));
366 SelectObject32(lpdis->hDC, hBrush);
367 FillRect16(lpdis->hDC, &lpdis->rcItem, hBrush);
368 SendMessage16(lpdis->hwndItem, CB_GETLBTEXT16, lpdis->itemID,
369 (LPARAM)SEGPTR_GET(str));
370 switch(DRIVE_GetType( str[2] - 'a' ))
372 case TYPE_FLOPPY: hBitmap = hFloppy; break;
373 case TYPE_CDROM: hBitmap = hCDRom; break;
374 case TYPE_HD:
375 case TYPE_NETWORK:
376 default: hBitmap = hHDisk; break;
378 GetObject16( hBitmap, sizeof(bm), &bm );
379 TextOut16(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
380 lpdis->rcItem.top, str, strlen(str));
381 hMemDC = CreateCompatibleDC32(lpdis->hDC);
382 hPrevBitmap = SelectObject32(hMemDC, hBitmap);
383 BitBlt32( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
384 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY );
385 SelectObject32(hMemDC, hPrevBitmap);
386 DeleteDC32(hMemDC);
387 if (lpdis->itemState != 0) InvertRect16(lpdis->hDC, &lpdis->rcItem);
388 SEGPTR_FREE(str);
389 return TRUE;
391 return FALSE;
394 /***********************************************************************
395 * FILEDLG_WMMeasureItem [internal]
397 static LONG FILEDLG_WMMeasureItem(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
399 BITMAP16 bm;
400 LPMEASUREITEMSTRUCT16 lpmeasure;
402 GetObject16( hFolder2, sizeof(bm), &bm );
403 lpmeasure = (LPMEASUREITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
404 lpmeasure->itemHeight = bm.bmHeight;
405 return TRUE;
408 /***********************************************************************
409 * FILEDLG_HookCallChk [internal]
411 static int FILEDLG_HookCallChk(LPOPENFILENAME16 lpofn)
413 if (lpofn)
414 if (lpofn->Flags & OFN_ENABLEHOOK)
415 if (lpofn->lpfnHook)
416 return 1;
417 return 0;
420 /***********************************************************************
421 * FILEDLG_CallWindowProc [internal]
423 * Adapt the structures back for win32 calls so the callee can read lpCustData
425 static BOOL32 FILEDLG_CallWindowProc(LPOPENFILENAME16 lpofn,HWND32 hwnd,
426 UINT32 wMsg,WPARAM32 wParam,LPARAM lParam
429 BOOL32 needstruct;
431 needstruct = (PTR_SEG_TO_LIN(lParam) == lpofn);
433 if (!(lpofn->Flags & OFN_WINE32))
434 return (BOOL32)CallWindowProc16(
435 lpofn->lpfnHook,hwnd,(UINT16)wMsg,(WPARAM16)wParam,lParam
437 /* |OFN_WINE32 */
438 if (lpofn->Flags & OFN_UNICODE) {
439 if (needstruct) {
440 OPENFILENAME32W ofnw;
442 /* FIXME: probably needs more converted */
443 ofnw.lCustData = lpofn->lCustData;
444 return (BOOL32)CallWindowProc32W(
445 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofnw
447 } else
448 return (BOOL32)CallWindowProc32W(
449 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
452 /* ! |OFN_UNICODE */
453 if (needstruct) {
454 OPENFILENAME32A ofna;
456 /* FIXME: probably needs more converted */
457 ofna.lCustData = lpofn->lCustData;
458 return (BOOL32)CallWindowProc32A(
459 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,(LPARAM)&ofna
461 } else
462 return (BOOL32)CallWindowProc32A(
463 (WNDPROC32)lpofn->lpfnHook,hwnd,wMsg,wParam,lParam
468 /***********************************************************************
469 * FILEDLG_WMInitDialog [internal]
472 static LONG FILEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
474 int i, n;
475 LPOPENFILENAME16 lpofn;
476 char tmpstr[512];
477 LPSTR pstr;
478 SetWindowLong32A(hWnd, DWL_USER, lParam);
479 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(lParam);
480 if (lpofn->lpstrTitle) SetWindowText16( hWnd, lpofn->lpstrTitle );
481 /* read custom filter information */
482 if (lpofn->lpstrCustomFilter)
484 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
485 n = 0;
486 dprintf_commdlg(stddeb,"lpstrCustomFilter = %p\n", pstr);
487 while(*pstr)
489 dprintf_commdlg(stddeb,"lpstrCustomFilter // add str='%s' ",pstr);
490 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
491 (LPARAM)lpofn->lpstrCustomFilter + n );
492 n += strlen(pstr) + 1;
493 pstr += strlen(pstr) + 1;
494 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
495 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
496 n += strlen(pstr) + 1;
497 pstr += strlen(pstr) + 1;
500 /* read filter information */
501 if (lpofn->lpstrFilter) {
502 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
503 n = 0;
504 while(*pstr) {
505 dprintf_commdlg(stddeb,"lpstrFilter // add str='%s' ", pstr);
506 i = SendDlgItemMessage16(hWnd, cmb1, CB_ADDSTRING16, 0,
507 (LPARAM)lpofn->lpstrFilter + n );
508 n += strlen(pstr) + 1;
509 pstr += strlen(pstr) + 1;
510 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
511 SendDlgItemMessage16(hWnd, cmb1, CB_SETITEMDATA16, i, (LPARAM)pstr);
512 n += strlen(pstr) + 1;
513 pstr += strlen(pstr) + 1;
516 /* set default filter */
517 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
518 lpofn->nFilterIndex = 1;
519 SendDlgItemMessage16(hWnd, cmb1, CB_SETCURSEL16, lpofn->nFilterIndex - 1, 0);
520 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
521 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
522 tmpstr[511]=0;
523 dprintf_commdlg(stddeb,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
524 lpofn->nFilterIndex, tmpstr);
525 SetDlgItemText32A( hWnd, edt1, tmpstr );
526 /* get drive list */
527 *tmpstr = 0;
528 DlgDirListComboBox32A(hWnd, tmpstr, cmb2, 0, 0xC000);
529 /* read initial directory */
530 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
532 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
533 tmpstr[510]=0;
534 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
535 && tmpstr[strlen(tmpstr)-1] != ':')
536 strcat(tmpstr,"\\");
538 else
539 *tmpstr = 0;
540 if (!FILEDLG_ScanDir(hWnd, tmpstr))
541 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
542 /* select current drive in combo 2 */
543 n = DRIVE_GetCurrentDrive();
544 SendDlgItemMessage16(hWnd, cmb2, CB_SETCURSEL16, n, 0);
545 if (!(lpofn->Flags & OFN_SHOWHELP))
546 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
547 if (lpofn->Flags & OFN_HIDEREADONLY)
548 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
549 if (FILEDLG_HookCallChk(lpofn))
550 return (BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,WM_INITDIALOG,wParam,lParam );
551 else
552 return TRUE;
555 /***********************************************************************
556 * FILEDLG_WMCommand [internal]
558 static LRESULT FILEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
560 LONG lRet;
561 LPOPENFILENAME16 lpofn;
562 OPENFILENAME16 ofn2;
563 char tmpstr[512], tmpstr2[512];
564 LPSTR pstr, pstr2;
565 UINT16 control,notification;
567 /* Notifications are packaged differently in Win32 */
568 control = wParam;
569 notification = HIWORD(lParam);
571 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
572 switch (control)
574 case lst1: /* file list */
575 FILEDLG_StripEditControl(hWnd);
576 if (notification == LBN_DBLCLK)
577 goto almost_ok;
578 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
579 if (lRet == LB_ERR) return TRUE;
580 if ((pstr = SEGPTR_ALLOC(512)))
582 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
583 (LPARAM)SEGPTR_GET(pstr));
584 SetDlgItemText32A( hWnd, edt1, pstr );
585 SEGPTR_FREE(pstr);
587 if (FILEDLG_HookCallChk(lpofn))
588 FILEDLG_CallWindowProc(lpofn,hWnd,
589 RegisterWindowMessage32A( LBSELCHSTRING ),
590 control, MAKELONG(lRet,CD_LBSELCHANGE));
591 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
592 return TRUE;
593 case lst2: /* directory list */
594 FILEDLG_StripEditControl(hWnd);
595 if (notification == LBN_DBLCLK)
597 lRet = SendDlgItemMessage16(hWnd, lst2, LB_GETCURSEL16, 0, 0);
598 if (lRet == LB_ERR) return TRUE;
599 pstr = SEGPTR_ALLOC(512);
600 SendDlgItemMessage16(hWnd, lst2, LB_GETTEXT16, lRet,
601 (LPARAM)SEGPTR_GET(pstr));
602 strcpy( tmpstr, pstr );
603 SEGPTR_FREE(pstr);
604 if (tmpstr[0] == '[')
606 tmpstr[strlen(tmpstr) - 1] = 0;
607 strcpy(tmpstr,tmpstr+1);
609 strcat(tmpstr, "\\");
610 goto reset_scan;
612 return TRUE;
613 case cmb1: /* file type drop list */
614 if (notification == CBN_SELCHANGE)
616 *tmpstr = 0;
617 goto reset_scan;
619 return TRUE;
620 case cmb2: /* disk drop list */
621 FILEDLG_StripEditControl(hWnd);
622 lRet = SendDlgItemMessage16(hWnd, cmb2, CB_GETCURSEL16, 0, 0L);
623 if (lRet == LB_ERR) return 0;
624 pstr = SEGPTR_ALLOC(512);
625 SendDlgItemMessage16(hWnd, cmb2, CB_GETLBTEXT16, lRet,
626 (LPARAM)SEGPTR_GET(pstr));
627 sprintf(tmpstr, "%c:", pstr[2]);
628 SEGPTR_FREE(pstr);
629 reset_scan:
630 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
631 if (lRet == LB_ERR)
632 return TRUE;
633 pstr = (LPSTR)SendDlgItemMessage16(hWnd, cmb1, CB_GETITEMDATA16, lRet, 0);
634 dprintf_commdlg(stddeb,"Selected filter : %s\n", pstr);
635 SetDlgItemText32A( hWnd, edt1, pstr );
636 FILEDLG_ScanDir(hWnd, tmpstr);
637 return TRUE;
638 case chx1:
639 return TRUE;
640 case pshHelp:
641 return TRUE;
642 case IDOK:
643 almost_ok:
644 ofn2=*lpofn; /* for later restoring */
645 GetDlgItemText32A( hWnd, edt1, tmpstr, sizeof(tmpstr) );
646 pstr = strrchr(tmpstr, '\\');
647 if (pstr == NULL)
648 pstr = strrchr(tmpstr, ':');
649 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
651 /* edit control contains wildcards */
652 if (pstr != NULL)
654 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
655 *(pstr+1) = 0;
657 else
659 strcpy(tmpstr2, tmpstr);
660 *tmpstr=0;
662 dprintf_commdlg(stddeb,"commdlg: %s, %s\n", tmpstr, tmpstr2);
663 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
664 FILEDLG_ScanDir(hWnd, tmpstr);
665 return TRUE;
667 /* no wildcards, we might have a directory or a filename */
668 /* try appending a wildcard and reading the directory */
669 pstr2 = tmpstr + strlen(tmpstr);
670 if (pstr == NULL || *(pstr+1) != 0)
671 strcat(tmpstr, "\\");
672 lRet = SendDlgItemMessage16(hWnd, cmb1, CB_GETCURSEL16, 0, 0);
673 if (lRet == LB_ERR) return TRUE;
674 lpofn->nFilterIndex = lRet + 1;
675 dprintf_commdlg(stddeb,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
676 lstrcpyn32A(tmpstr2,
677 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
678 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
679 lRet), sizeof(tmpstr2));
680 SetDlgItemText32A( hWnd, edt1, tmpstr2 );
681 /* if ScanDir succeeds, we have changed the directory */
682 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
683 /* if not, this must be a filename */
684 *pstr2 = 0;
685 if (pstr != NULL)
687 /* strip off the pathname */
688 *pstr = 0;
689 SetDlgItemText32A( hWnd, edt1, pstr + 1 );
690 lstrcpyn32A(tmpstr2, pstr+1, sizeof(tmpstr2) );
691 /* Should we MessageBox() if this fails? */
692 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
693 strcpy(tmpstr, tmpstr2);
695 else SetDlgItemText32A( hWnd, edt1, tmpstr );
696 #if 0
697 ShowWindow16(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
698 #endif
700 int drive = DRIVE_GetCurrentDrive();
701 tmpstr2[0] = 'A'+ drive;
702 tmpstr2[1] = ':';
703 tmpstr2[2] = '\\';
704 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
705 if (strlen(tmpstr2) > 3)
706 strcat(tmpstr2, "\\");
707 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
708 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
710 lpofn->nFileOffset = 0;
711 lpofn->nFileExtension = 0;
712 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
713 lpofn->nFileExtension++;
714 if (lpofn->nFileExtension == '\0')
715 lpofn->nFileExtension = 0;
716 else
717 lpofn->nFileExtension++;
718 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
720 lRet = SendDlgItemMessage16(hWnd, lst1, LB_GETCURSEL16, 0, 0);
721 SendDlgItemMessage16(hWnd, lst1, LB_GETTEXT16, lRet,
722 lpofn->lpstrFileTitle );
724 if (FILEDLG_HookCallChk(lpofn))
726 lRet= (BOOL16)FILEDLG_CallWindowProc(lpofn,
727 hWnd, RegisterWindowMessage32A( FILEOKSTRING ), 0, lParam );
728 if (lRet)
730 *lpofn=ofn2; /* restore old state */
731 #if 0
732 ShowWindow16(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
733 #endif
734 break;
737 EndDialog32(hWnd, TRUE);
738 return TRUE;
739 case IDCANCEL:
740 EndDialog32(hWnd, FALSE);
741 return TRUE;
743 return FALSE;
747 /***********************************************************************
748 * FileOpenDlgProc (COMMDLG.6)
750 LRESULT WINAPI FileOpenDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
751 LPARAM lParam)
753 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
755 if (wMsg!=WM_INITDIALOG)
756 if (FILEDLG_HookCallChk(lpofn))
758 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
759 if (lRet)
760 return lRet; /* else continue message processing */
762 switch (wMsg)
764 case WM_INITDIALOG:
765 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
766 case WM_MEASUREITEM:
767 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
768 case WM_DRAWITEM:
769 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, FALSE);
770 case WM_COMMAND:
771 return FILEDLG_WMCommand(hWnd, wParam, lParam);
772 #if 0
773 case WM_CTLCOLOR:
774 SetBkColor((HDC16)wParam, 0x00C0C0C0);
775 switch (HIWORD(lParam))
777 case CTLCOLOR_BTN:
778 SetTextColor((HDC16)wParam, 0x00000000);
779 return hGRAYBrush;
780 case CTLCOLOR_STATIC:
781 SetTextColor((HDC16)wParam, 0x00000000);
782 return hGRAYBrush;
784 break;
785 #endif
787 return FALSE;
791 /***********************************************************************
792 * FileSaveDlgProc (COMMDLG.7)
794 LRESULT WINAPI FileSaveDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
795 LPARAM lParam)
797 LPOPENFILENAME16 lpofn = (LPOPENFILENAME16)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
799 if (wMsg!=WM_INITDIALOG)
800 if (FILEDLG_HookCallChk(lpofn))
802 LRESULT lRet=(BOOL16)FILEDLG_CallWindowProc(lpofn,hWnd,wMsg,wParam,lParam);
803 if (lRet)
804 return lRet; /* else continue message processing */
806 switch (wMsg) {
807 case WM_INITDIALOG:
808 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
810 case WM_MEASUREITEM:
811 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
813 case WM_DRAWITEM:
814 return FILEDLG_WMDrawItem(hWnd, wParam, lParam, TRUE);
816 case WM_COMMAND:
817 return FILEDLG_WMCommand(hWnd, wParam, lParam);
821 case WM_CTLCOLOR:
822 SetBkColor((HDC16)wParam, 0x00C0C0C0);
823 switch (HIWORD(lParam))
825 case CTLCOLOR_BTN:
826 SetTextColor((HDC16)wParam, 0x00000000);
827 return hGRAYBrush;
828 case CTLCOLOR_STATIC:
829 SetTextColor((HDC16)wParam, 0x00000000);
830 return hGRAYBrush;
832 return FALSE;
835 return FALSE;
839 /***********************************************************************
840 * FindTextDlg (COMMDLG.11)
842 HWND16 WINAPI FindText( SEGPTR find )
844 HANDLE16 hInst;
845 LPCVOID ptr;
846 LPFINDREPLACE lpFind = (LPFINDREPLACE)PTR_SEG_TO_LIN(find);
849 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
850 * For now, only the standard dialog works.
853 * FIXME : We should do error checking on the lpFind structure here
854 * and make CommDlgExtendedError() return the error condition.
856 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_FIND_TEXT );
857 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
858 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
859 (DLGPROC16)MODULE_GetWndProcEntry16("FindTextDlgProc"),
860 find, WIN_PROC_16 );
864 /***********************************************************************
865 * ReplaceText (COMMDLG.12)
867 HWND16 WINAPI ReplaceText( SEGPTR find )
869 HANDLE16 hInst;
870 LPCVOID ptr;
871 LPFINDREPLACE lpFind = (LPFINDREPLACE)PTR_SEG_TO_LIN(find);
874 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
875 * For now, only the standard dialog works.
878 * FIXME : We should do error checking on the lpFind structure here
879 * and make CommDlgExtendedError() return the error condition.
881 ptr = SYSRES_GetResPtr( SYSRES_DIALOG_REPLACE_TEXT );
882 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
883 return DIALOG_CreateIndirect( hInst, ptr, TRUE, lpFind->hwndOwner,
884 (DLGPROC16)MODULE_GetWndProcEntry16("ReplaceTextDlgProc"),
885 find, WIN_PROC_16 );
889 /***********************************************************************
890 * FINDDLG_WMInitDialog [internal]
892 static LRESULT FINDDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
894 LPFINDREPLACE lpfr;
896 SetWindowLong32A(hWnd, DWL_USER, lParam);
897 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(lParam);
898 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
900 * FIXME : If the initial FindWhat string is empty, we should disable the
901 * FindNext (IDOK) button. Only after typing some text, the button should be
902 * enabled.
904 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
905 CheckRadioButton32(hWnd, rad1, rad2, (lpfr->Flags & FR_DOWN) ? rad2 : rad1);
906 if (lpfr->Flags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
907 EnableWindow32(GetDlgItem32(hWnd, rad1), FALSE);
908 EnableWindow32(GetDlgItem32(hWnd, rad2), FALSE);
910 if (lpfr->Flags & FR_HIDEUPDOWN) {
911 ShowWindow32(GetDlgItem32(hWnd, rad1), SW_HIDE);
912 ShowWindow32(GetDlgItem32(hWnd, rad2), SW_HIDE);
913 ShowWindow32(GetDlgItem32(hWnd, grp1), SW_HIDE);
915 CheckDlgButton32(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
916 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
917 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
918 if (lpfr->Flags & FR_HIDEWHOLEWORD)
919 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
920 CheckDlgButton32(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
921 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
922 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
923 if (lpfr->Flags & FR_HIDEMATCHCASE)
924 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
925 if (!(lpfr->Flags & FR_SHOWHELP)) {
926 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
927 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
929 ShowWindow32(hWnd, SW_SHOWNORMAL);
930 return TRUE;
934 /***********************************************************************
935 * FINDDLG_WMCommand [internal]
937 static LRESULT FINDDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
939 LPFINDREPLACE lpfr;
940 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
941 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
943 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
944 switch (wParam) {
945 case IDOK:
946 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
947 if (IsDlgButtonChecked32(hWnd, rad2))
948 lpfr->Flags |= FR_DOWN;
949 else lpfr->Flags &= ~FR_DOWN;
950 if (IsDlgButtonChecked32(hWnd, chx1))
951 lpfr->Flags |= FR_WHOLEWORD;
952 else lpfr->Flags &= ~FR_WHOLEWORD;
953 if (IsDlgButtonChecked32(hWnd, chx2))
954 lpfr->Flags |= FR_MATCHCASE;
955 else lpfr->Flags &= ~FR_MATCHCASE;
956 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
957 lpfr->Flags |= FR_FINDNEXT;
958 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
959 GetWindowLong32A(hWnd, DWL_USER) );
960 return TRUE;
961 case IDCANCEL:
962 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
963 lpfr->Flags |= FR_DIALOGTERM;
964 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
965 GetWindowLong32A(hWnd, DWL_USER) );
966 DestroyWindow16(hWnd);
967 return TRUE;
968 case pshHelp:
969 /* FIXME : should lpfr structure be passed as an argument ??? */
970 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
971 return TRUE;
973 return FALSE;
977 /***********************************************************************
978 * FindTextDlgProc (COMMDLG.13)
980 LRESULT WINAPI FindTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
981 LPARAM lParam)
983 switch (wMsg) {
984 case WM_INITDIALOG:
985 return FINDDLG_WMInitDialog(hWnd, wParam, lParam);
986 case WM_COMMAND:
987 return FINDDLG_WMCommand(hWnd, wParam, lParam);
989 return FALSE;
993 /***********************************************************************
994 * REPLACEDLG_WMInitDialog [internal]
996 static LRESULT REPLACEDLG_WMInitDialog(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
998 LPFINDREPLACE lpfr;
1000 SetWindowLong32A(hWnd, DWL_USER, lParam);
1001 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(lParam);
1002 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1004 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
1005 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
1006 * enabled.
1008 SetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat);
1009 SetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith);
1010 CheckDlgButton32(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
1011 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
1012 EnableWindow32(GetDlgItem32(hWnd, chx1), FALSE);
1013 if (lpfr->Flags & FR_HIDEWHOLEWORD)
1014 ShowWindow32(GetDlgItem32(hWnd, chx1), SW_HIDE);
1015 CheckDlgButton32(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
1016 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
1017 EnableWindow32(GetDlgItem32(hWnd, chx2), FALSE);
1018 if (lpfr->Flags & FR_HIDEMATCHCASE)
1019 ShowWindow32(GetDlgItem32(hWnd, chx2), SW_HIDE);
1020 if (!(lpfr->Flags & FR_SHOWHELP)) {
1021 EnableWindow32(GetDlgItem32(hWnd, pshHelp), FALSE);
1022 ShowWindow32(GetDlgItem32(hWnd, pshHelp), SW_HIDE);
1024 ShowWindow32(hWnd, SW_SHOWNORMAL);
1025 return TRUE;
1029 /***********************************************************************
1030 * REPLACEDLG_WMCommand [internal]
1032 static LRESULT REPLACEDLG_WMCommand(HWND16 hWnd, WPARAM16 wParam, LPARAM lParam)
1034 LPFINDREPLACE lpfr;
1035 int uFindReplaceMessage = RegisterWindowMessage32A( FINDMSGSTRING );
1036 int uHelpMessage = RegisterWindowMessage32A( HELPMSGSTRING );
1038 lpfr = (LPFINDREPLACE)PTR_SEG_TO_LIN(GetWindowLong32A(hWnd, DWL_USER));
1039 switch (wParam) {
1040 case IDOK:
1041 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
1042 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
1043 if (IsDlgButtonChecked32(hWnd, chx1))
1044 lpfr->Flags |= FR_WHOLEWORD;
1045 else lpfr->Flags &= ~FR_WHOLEWORD;
1046 if (IsDlgButtonChecked32(hWnd, chx2))
1047 lpfr->Flags |= FR_MATCHCASE;
1048 else lpfr->Flags &= ~FR_MATCHCASE;
1049 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
1050 lpfr->Flags |= FR_FINDNEXT;
1051 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
1052 GetWindowLong32A(hWnd, DWL_USER) );
1053 return TRUE;
1054 case IDCANCEL:
1055 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
1056 lpfr->Flags |= FR_DIALOGTERM;
1057 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
1058 GetWindowLong32A(hWnd, DWL_USER) );
1059 DestroyWindow16(hWnd);
1060 return TRUE;
1061 case psh1:
1062 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
1063 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
1064 if (IsDlgButtonChecked32(hWnd, chx1))
1065 lpfr->Flags |= FR_WHOLEWORD;
1066 else lpfr->Flags &= ~FR_WHOLEWORD;
1067 if (IsDlgButtonChecked32(hWnd, chx2))
1068 lpfr->Flags |= FR_MATCHCASE;
1069 else lpfr->Flags &= ~FR_MATCHCASE;
1070 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
1071 lpfr->Flags |= FR_REPLACE;
1072 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
1073 GetWindowLong32A(hWnd, DWL_USER) );
1074 return TRUE;
1075 case psh2:
1076 GetDlgItemText16(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
1077 GetDlgItemText16(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
1078 if (IsDlgButtonChecked32(hWnd, chx1))
1079 lpfr->Flags |= FR_WHOLEWORD;
1080 else lpfr->Flags &= ~FR_WHOLEWORD;
1081 if (IsDlgButtonChecked32(hWnd, chx2))
1082 lpfr->Flags |= FR_MATCHCASE;
1083 else lpfr->Flags &= ~FR_MATCHCASE;
1084 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
1085 lpfr->Flags |= FR_REPLACEALL;
1086 SendMessage16(lpfr->hwndOwner, uFindReplaceMessage, 0,
1087 GetWindowLong32A(hWnd, DWL_USER) );
1088 return TRUE;
1089 case pshHelp:
1090 /* FIXME : should lpfr structure be passed as an argument ??? */
1091 SendMessage16(lpfr->hwndOwner, uHelpMessage, 0, 0);
1092 return TRUE;
1094 return FALSE;
1098 /***********************************************************************
1099 * ReplaceTextDlgProc (COMMDLG.14)
1101 LRESULT WINAPI ReplaceTextDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1102 LPARAM lParam)
1104 switch (wMsg) {
1105 case WM_INITDIALOG:
1106 return REPLACEDLG_WMInitDialog(hWnd, wParam, lParam);
1107 case WM_COMMAND:
1108 return REPLACEDLG_WMCommand(hWnd, wParam, lParam);
1110 return FALSE;
1114 /***********************************************************************
1115 * PrintDlg16 (COMMDLG.20)
1117 BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
1119 HANDLE16 hInst;
1120 BOOL16 bRet = FALSE;
1121 LPCVOID template;
1122 HWND32 hwndDialog;
1123 LPPRINTDLG16 lpPrint = (LPPRINTDLG16)PTR_SEG_TO_LIN(printdlg);
1125 dprintf_commdlg(stddeb,"PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
1127 if (lpPrint->Flags & PD_RETURNDEFAULT)
1128 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1129 return TRUE;
1131 if (lpPrint->Flags & PD_PRINTSETUP)
1132 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
1133 else
1134 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
1136 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1137 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
1138 lpPrint->hwndOwner,
1139 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
1140 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
1141 MODULE_GetWndProcEntry16("PrintDlgProc")),
1142 printdlg, WIN_PROC_16 );
1143 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
1144 return bRet;
1148 /***********************************************************************
1149 * PrintDlg32A (COMDLG32.17)
1151 BOOL32 WINAPI PrintDlg32A( LPPRINTDLG32A printdlg )
1153 fprintf( stdnimp, "PrintDlg32A: empty stub\n" );
1154 return FALSE;
1158 /***********************************************************************
1159 * PrintDlg32W (COMDLG32.18)
1161 BOOL32 WINAPI PrintDlg32W( LPPRINTDLG32W printdlg )
1163 fprintf( stdnimp, "PrintDlg32A: empty stub\n" );
1164 return FALSE;
1168 /***********************************************************************
1169 * PrintDlgProc (COMMDLG.21)
1171 LRESULT WINAPI PrintDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1172 LPARAM lParam)
1174 switch (wMsg)
1176 case WM_INITDIALOG:
1177 dprintf_commdlg(stddeb,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1178 ShowWindow16(hWnd, SW_SHOWNORMAL);
1179 return (TRUE);
1180 case WM_COMMAND:
1181 switch (wParam)
1183 case IDOK:
1184 EndDialog32(hWnd, TRUE);
1185 return(TRUE);
1186 case IDCANCEL:
1187 EndDialog32(hWnd, FALSE);
1188 return(TRUE);
1190 return(FALSE);
1192 return FALSE;
1196 /***********************************************************************
1197 * PrintSetupDlgProc (COMMDLG.22)
1199 LRESULT WINAPI PrintSetupDlgProc(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1200 LPARAM lParam)
1202 switch (wMsg)
1204 case WM_INITDIALOG:
1205 dprintf_commdlg(stddeb,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1206 ShowWindow16(hWnd, SW_SHOWNORMAL);
1207 return (TRUE);
1208 case WM_COMMAND:
1209 switch (wParam) {
1210 case IDOK:
1211 EndDialog32(hWnd, TRUE);
1212 return(TRUE);
1213 case IDCANCEL:
1214 EndDialog32(hWnd, FALSE);
1215 return(TRUE);
1217 return(FALSE);
1219 return FALSE;
1223 /***********************************************************************
1224 * CommDlgExtendedError (COMMDLG.26)
1226 DWORD WINAPI CommDlgExtendedError(void)
1228 return CommDlgLastError;
1231 /***********************************************************************
1232 * GetFileTitleA (COMDLG32.8)
1234 short WINAPI GetFileTitle32A(LPCSTR lpFile, LPSTR lpTitle, UINT32 cbBuf)
1236 int i, len;
1237 dprintf_commdlg(stddeb,"GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1238 if (lpFile == NULL || lpTitle == NULL)
1239 return -1;
1240 len = strlen(lpFile);
1241 if (len == 0)
1242 return -1;
1243 if (strpbrk(lpFile, "*[]"))
1244 return -1;
1245 len--;
1246 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1247 return -1;
1248 for (i = len; i >= 0; i--)
1249 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1251 i++;
1252 break;
1254 dprintf_commdlg(stddeb,"\n---> '%s' ", &lpFile[i]);
1256 len = strlen(lpFile+i)+1;
1257 if (cbBuf < len)
1258 return len;
1260 strncpy(lpTitle, &lpFile[i], len);
1261 return 0;
1265 /***********************************************************************
1266 * GetFileTitleA (COMDLG32.8)
1268 short WINAPI GetFileTitle32W(LPCWSTR lpFile, LPWSTR lpTitle, UINT32 cbBuf)
1270 LPSTR file = HEAP_strdupWtoA(GetProcessHeap(),0,lpFile);
1271 LPSTR title = HeapAlloc(GetProcessHeap(),0,cbBuf);
1272 short ret;
1274 ret = GetFileTitle32A(file,title,cbBuf);
1276 lstrcpynAtoW(lpTitle,title,cbBuf);
1277 HeapFree(GetProcessHeap(),0,file);
1278 HeapFree(GetProcessHeap(),0,title);
1279 return ret;
1281 /***********************************************************************
1282 * GetFileTitle (COMMDLG.27)
1284 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
1286 return GetFileTitle32A(lpFile,lpTitle,cbBuf);
1290 /* ------------------------ Choose Color Dialog --------------------------- */
1292 /***********************************************************************
1293 * ChooseColor (COMMDLG.5)
1295 BOOL16 WINAPI ChooseColor(LPCHOOSECOLOR lpChCol)
1297 HINSTANCE16 hInst;
1298 HANDLE16 hDlgTmpl = 0;
1299 BOOL16 bRet = FALSE, win32Format = FALSE;
1300 LPCVOID template;
1301 HWND32 hwndDialog;
1303 dprintf_commdlg(stddeb,"ChooseColor\n");
1304 if (!lpChCol) return FALSE;
1306 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1308 if (!(template = LockResource16( lpChCol->hInstance )))
1310 CommDlgLastError = CDERR_LOADRESFAILURE;
1311 return FALSE;
1314 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1316 HANDLE16 hResInfo;
1317 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1318 lpChCol->lpTemplateName, RT_DIALOG)))
1320 CommDlgLastError = CDERR_FINDRESFAILURE;
1321 return FALSE;
1323 if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
1324 !(template = LockResource16( hDlgTmpl )))
1326 CommDlgLastError = CDERR_LOADRESFAILURE;
1327 return FALSE;
1330 else
1332 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_COLOR );
1333 win32Format = TRUE;
1336 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
1337 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
1338 lpChCol->hwndOwner,
1339 (DLGPROC16)MODULE_GetWndProcEntry16("ColorDlgProc"),
1340 (DWORD)lpChCol, WIN_PROC_16 );
1341 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
1342 if (hDlgTmpl) FreeResource16( hDlgTmpl );
1343 return bRet;
1347 static const COLORREF predefcolors[6][8]=
1349 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
1350 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
1351 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
1352 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
1354 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
1355 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
1356 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
1357 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
1359 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
1360 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
1361 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
1362 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
1365 struct CCPRIVATE
1367 LPCHOOSECOLOR lpcc; /* points to public known data structure */
1368 int nextuserdef; /* next free place in user defined color array */
1369 HDC16 hdcMem; /* color graph used for BitBlt() */
1370 HBITMAP16 hbmMem; /* color graph bitmap */
1371 RECT16 fullsize; /* original dialog window size */
1372 UINT16 msetrgb; /* # of SETRGBSTRING message (today not used) */
1373 RECT16 old3angle; /* last position of l-marker */
1374 RECT16 oldcross; /* last position of color/satuation marker */
1375 BOOL32 updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
1376 int h;
1377 int s;
1378 int l; /* for temporary storing of hue,sat,lum */
1381 /***********************************************************************
1382 * CC_HSLtoRGB [internal]
1384 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
1386 int res=0,maxrgb;
1388 /* hue */
1389 switch(c)
1391 case 'R':if (hue>80) hue-=80; else hue+=160; break;
1392 case 'G':if (hue>160) hue-=160; else hue+=80; break;
1393 case 'B':break;
1396 /* l below 120 */
1397 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
1398 if (hue< 80)
1399 res=0;
1400 else
1401 if (hue< 120)
1403 res=(hue-80)* maxrgb; /* 0...10240 */
1404 res/=40; /* 0...256 */
1406 else
1407 if (hue< 200)
1408 res=maxrgb;
1409 else
1411 res=(240-hue)* maxrgb;
1412 res/=40;
1414 res=res-maxrgb/2; /* -128...128 */
1416 /* saturation */
1417 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
1419 /* lum above 120 */
1420 if (lum>120 && res<256)
1421 res+=((lum-120) * (256-res))/120;
1423 return MIN(res,255);
1426 /***********************************************************************
1427 * CC_RGBtoHSL [internal]
1429 static int CC_RGBtoHSL(char c,int r,int g,int b)
1431 WORD maxi,mini,mmsum,mmdif,result=0;
1432 int iresult=0;
1434 maxi=MAX(r,b);
1435 maxi=MAX(maxi,g);
1436 mini=MIN(r,b);
1437 mini=MIN(mini,g);
1439 mmsum=maxi+mini;
1440 mmdif=maxi-mini;
1442 switch(c)
1444 /* lum */
1445 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
1446 result=mmsum/255; /* 0...240 */
1447 break;
1448 /* saturation */
1449 case 'S':if (!mmsum)
1450 result=0;
1451 else
1452 if (!mini || maxi==255)
1453 result=240;
1454 else
1456 result=mmdif*240; /* 0...61200=255*240 */
1457 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
1459 break;
1460 /* hue */
1461 case 'H':if (!mmdif)
1462 result=160;
1463 else
1465 if (maxi==r)
1467 iresult=40*(g-b); /* -10200 ... 10200 */
1468 iresult/=(int)mmdif; /* -40 .. 40 */
1469 if (iresult<0)
1470 iresult+=240; /* 0..40 and 200..240 */
1472 else
1473 if (maxi==g)
1475 iresult=40*(b-r);
1476 iresult/=(int)mmdif;
1477 iresult+=80; /* 40 .. 120 */
1479 else
1480 if (maxi==b)
1482 iresult=40*(r-g);
1483 iresult/=(int)mmdif;
1484 iresult+=160; /* 120 .. 200 */
1486 result=iresult;
1488 break;
1490 return result; /* is this integer arithmetic precise enough ? */
1493 #define DISTANCE 4
1495 /***********************************************************************
1496 * CC_MouseCheckPredefColorArray [internal]
1498 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1499 LPARAM lParam,COLORREF *cr)
1501 HWND16 hwnd;
1502 POINT16 point = MAKEPOINT16(lParam);
1503 RECT16 rect;
1504 int dx,dy,x,y;
1506 ClientToScreen16(hDlg,&point);
1507 hwnd=GetDlgItem32(hDlg,dlgitem);
1508 GetWindowRect16(hwnd,&rect);
1509 if (PtInRect16(&rect,point))
1511 dx=(rect.right-rect.left)/cols;
1512 dy=(rect.bottom-rect.top)/rows;
1513 ScreenToClient16(hwnd,&point);
1515 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1517 x=point.x/dx;
1518 y=point.y/dy;
1519 *cr=predefcolors[y][x];
1520 /* FIXME: Draw_a_Focus_Rect() */
1521 return 1;
1524 return 0;
1527 /***********************************************************************
1528 * CC_MouseCheckUserColorArray [internal]
1530 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
1531 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
1533 HWND16 hwnd;
1534 POINT16 point = MAKEPOINT16(lParam);
1535 RECT16 rect;
1536 int dx,dy,x,y;
1538 ClientToScreen16(hDlg,&point);
1539 hwnd=GetDlgItem32(hDlg,dlgitem);
1540 GetWindowRect16(hwnd,&rect);
1541 if (PtInRect16(&rect,point))
1543 dx=(rect.right-rect.left)/cols;
1544 dy=(rect.bottom-rect.top)/rows;
1545 ScreenToClient16(hwnd,&point);
1547 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
1549 x=point.x/dx;
1550 y=point.y/dy;
1551 *cr=crarr[x+cols*y];
1552 /* FIXME: Draw_a_Focus_Rect() */
1553 return 1;
1556 return 0;
1559 #define MAXVERT 240
1560 #define MAXHORI 239
1562 /* 240 ^...... ^^ 240
1563 | . ||
1564 SAT | . || LUM
1565 | . ||
1566 +-----> 239 ----
1569 /***********************************************************************
1570 * CC_MouseCheckColorGraph [internal]
1572 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
1574 HWND32 hwnd;
1575 POINT16 point = MAKEPOINT16(lParam);
1576 RECT16 rect;
1577 long x,y;
1579 ClientToScreen16(hDlg,&point);
1580 hwnd=GetDlgItem32(hDlg,dlgitem);
1581 GetWindowRect16(hwnd,&rect);
1582 if (PtInRect16(&rect,point))
1584 GetClientRect16(hwnd,&rect);
1585 ScreenToClient16(hwnd,&point);
1587 x=(long)point.x*MAXHORI;
1588 x/=rect.right;
1589 y=(long)(rect.bottom-point.y)*MAXVERT;
1590 y/=rect.bottom;
1592 if (hori)
1593 *hori=x;
1594 if (vert)
1595 *vert=y;
1596 return 1;
1598 else
1599 return 0;
1601 /***********************************************************************
1602 * CC_MouseCheckResultWindow [internal]
1604 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
1606 HWND16 hwnd;
1607 POINT16 point = MAKEPOINT16(lParam);
1608 RECT16 rect;
1610 ClientToScreen16(hDlg,&point);
1611 hwnd=GetDlgItem32(hDlg,0x2c5);
1612 GetWindowRect16(hwnd,&rect);
1613 if (PtInRect16(&rect,point))
1615 PostMessage16(hDlg,WM_COMMAND,0x2c9,0);
1616 return 1;
1618 return 0;
1621 /***********************************************************************
1622 * CC_CheckDigitsInEdit [internal]
1624 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
1626 int i,k,m,result,value;
1627 long editpos;
1628 char buffer[30];
1629 GetWindowText32A(hwnd,buffer,sizeof(buffer));
1630 m=strlen(buffer);
1631 result=0;
1633 for (i=0;i<m;i++)
1634 if (buffer[i]<'0' || buffer[i]>'9')
1636 for (k=i+1;k<=m;k++) /* delete bad character */
1638 buffer[i]=buffer[k];
1639 m--;
1641 buffer[m]=0;
1642 result=1;
1645 value=atoi(buffer);
1646 if (value>maxval) /* build a new string */
1648 sprintf(buffer,"%d",maxval);
1649 result=2;
1651 if (result)
1653 editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
1654 SetWindowText32A(hwnd,buffer);
1655 SendMessage16(hwnd,EM_SETSEL16,0,editpos);
1657 return value;
1662 /***********************************************************************
1663 * CC_PaintSelectedColor [internal]
1665 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
1667 RECT16 rect;
1668 HDC32 hdc;
1669 HBRUSH32 hBrush;
1670 HWND32 hwnd=GetDlgItem32(hDlg,0x2c5);
1671 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1673 hdc=GetDC32(hwnd);
1674 GetClientRect16 (hwnd, &rect) ;
1675 hBrush = CreateSolidBrush32(cr);
1676 if (hBrush)
1678 hBrush = SelectObject32 (hdc, hBrush) ;
1679 Rectangle32(hdc, rect.left,rect.top,rect.right/2,rect.bottom);
1680 DeleteObject32 (SelectObject32 (hdc,hBrush)) ;
1681 hBrush=CreateSolidBrush32(GetNearestColor32(hdc,cr));
1682 if (hBrush)
1684 hBrush= SelectObject32 (hdc, hBrush) ;
1685 Rectangle32( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
1686 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
1689 ReleaseDC32(hwnd,hdc);
1693 /***********************************************************************
1694 * CC_PaintTriangle [internal]
1696 static void CC_PaintTriangle(HWND16 hDlg,int y)
1698 HDC32 hDC;
1699 long temp;
1700 int w=GetDialogBaseUnits();
1701 POINT16 points[3];
1702 int height;
1703 int oben;
1704 RECT16 rect;
1705 HWND16 hwnd=GetDlgItem32(hDlg,0x2be);
1706 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1708 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1710 GetClientRect16(hwnd,&rect);
1711 height=rect.bottom;
1712 hDC=GetDC32(hDlg);
1714 points[0].y=rect.top;
1715 points[0].x=rect.right; /* | /| */
1716 ClientToScreen16(hwnd,points); /* | / | */
1717 ScreenToClient16(hDlg,points); /* |< | */
1718 oben=points[0].y; /* | \ | */
1719 /* | \| */
1720 temp=(long)height*(long)y;
1721 points[0].y=oben+height -temp/(long)MAXVERT;
1722 points[1].y=points[0].y+w;
1723 points[2].y=points[0].y-w;
1724 points[2].x=points[1].x=points[0].x + w;
1726 if (lpp->old3angle.left)
1727 FillRect16(hDC,&lpp->old3angle,GetStockObject32(WHITE_BRUSH));
1728 lpp->old3angle.left =points[0].x;
1729 lpp->old3angle.right =points[1].x+1;
1730 lpp->old3angle.top =points[2].y-1;
1731 lpp->old3angle.bottom=points[1].y+1;
1732 Polygon16(hDC,points,3);
1733 ReleaseDC32(hDlg,hDC);
1738 /***********************************************************************
1739 * CC_PaintCross [internal]
1741 static void CC_PaintCross(HWND16 hDlg,int x,int y)
1743 HDC32 hDC;
1744 int w=GetDialogBaseUnits();
1745 HWND16 hwnd=GetDlgItem32(hDlg,0x2c6);
1746 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1747 RECT16 rect;
1748 POINT16 point;
1749 HPEN32 hPen;
1751 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1753 GetClientRect16(hwnd,&rect);
1754 hDC=GetDC32(hwnd);
1755 SelectClipRgn32(hDC,CreateRectRgnIndirect16(&rect));
1756 hPen=CreatePen32(PS_SOLID,2,0);
1757 hPen=SelectObject32(hDC,hPen);
1758 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
1759 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
1760 if (lpp->oldcross.left!=lpp->oldcross.right)
1761 BitBlt32(hDC,lpp->oldcross.left,lpp->oldcross.top,
1762 lpp->oldcross.right-lpp->oldcross.left,
1763 lpp->oldcross.bottom-lpp->oldcross.top,
1764 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
1765 lpp->oldcross.left =point.x-w-1;
1766 lpp->oldcross.right =point.x+w+1;
1767 lpp->oldcross.top =point.y-w-1;
1768 lpp->oldcross.bottom=point.y+w+1;
1770 MoveTo(hDC,point.x-w,point.y);
1771 LineTo32(hDC,point.x+w,point.y);
1772 MoveTo(hDC,point.x,point.y-w);
1773 LineTo32(hDC,point.x,point.y+w);
1774 DeleteObject32(SelectObject32(hDC,hPen));
1775 ReleaseDC32(hwnd,hDC);
1780 #define XSTEPS 48
1781 #define YSTEPS 24
1784 /***********************************************************************
1785 * CC_PrepareColorGraph [internal]
1787 static void CC_PrepareColorGraph(HWND16 hDlg)
1789 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
1790 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
1791 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1792 HBRUSH32 hbrush;
1793 HDC32 hdc ;
1794 RECT16 rect,client;
1795 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT));
1797 GetClientRect16(hwnd,&client);
1798 hdc=GetDC32(hwnd);
1799 lpp->hdcMem = CreateCompatibleDC32(hdc);
1800 lpp->hbmMem = CreateCompatibleBitmap32(hdc,client.right,client.bottom);
1801 SelectObject32(lpp->hdcMem,lpp->hbmMem);
1803 xdif=client.right /XSTEPS;
1804 ydif=client.bottom/YSTEPS+1;
1805 hdif=239/XSTEPS;
1806 sdif=240/YSTEPS;
1807 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
1809 rect.right=rect.left+xdif;
1810 rect.bottom=client.bottom;
1811 for(sat=0;sat<240+sdif;sat+=sdif)
1813 rect.top=rect.bottom-ydif;
1814 r=CC_HSLtoRGB('R',hue,sat,120);
1815 g=CC_HSLtoRGB('G',hue,sat,120);
1816 b=CC_HSLtoRGB('B',hue,sat,120);
1817 hbrush=CreateSolidBrush32(RGB(r,g,b));
1818 FillRect16(lpp->hdcMem,&rect,hbrush);
1819 DeleteObject32(hbrush);
1820 rect.bottom=rect.top;
1822 rect.left=rect.right;
1824 ReleaseDC32(hwnd,hdc);
1825 SetCursor16(hcursor);
1828 /***********************************************************************
1829 * CC_PaintColorGraph [internal]
1831 static void CC_PaintColorGraph(HWND16 hDlg)
1833 HWND32 hwnd=GetDlgItem32(hDlg,0x2c6);
1834 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1835 HDC32 hDC;
1836 RECT16 rect;
1837 if (IsWindowVisible32(hwnd)) /* if full size */
1839 if (!lpp->hdcMem)
1840 CC_PrepareColorGraph(hDlg); /* should not be necessary */
1842 hDC=GetDC32(hwnd);
1843 GetClientRect16(hwnd,&rect);
1844 if (lpp->hdcMem)
1845 BitBlt32(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
1846 else
1847 fprintf(stderr,"choose color: hdcMem is not defined\n");
1848 ReleaseDC32(hwnd,hDC);
1851 /***********************************************************************
1852 * CC_PaintLumBar [internal]
1854 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
1856 HWND32 hwnd=GetDlgItem32(hDlg,0x2be);
1857 RECT16 rect,client;
1858 int lum,ldif,ydif,r,g,b;
1859 HBRUSH32 hbrush;
1860 HDC32 hDC;
1862 if (IsWindowVisible32(hwnd))
1864 hDC=GetDC32(hwnd);
1865 GetClientRect16(hwnd,&client);
1866 rect=client;
1868 ldif=240/YSTEPS;
1869 ydif=client.bottom/YSTEPS+1;
1870 for(lum=0;lum<240+ldif;lum+=ldif)
1872 rect.top=MAX(0,rect.bottom-ydif);
1873 r=CC_HSLtoRGB('R',hue,sat,lum);
1874 g=CC_HSLtoRGB('G',hue,sat,lum);
1875 b=CC_HSLtoRGB('B',hue,sat,lum);
1876 hbrush=CreateSolidBrush32(RGB(r,g,b));
1877 FillRect16(hDC,&rect,hbrush);
1878 DeleteObject32(hbrush);
1879 rect.bottom=rect.top;
1881 GetClientRect16(hwnd,&rect);
1882 FrameRect16(hDC,&rect,GetStockObject32(BLACK_BRUSH));
1883 ReleaseDC32(hwnd,hDC);
1887 /***********************************************************************
1888 * CC_EditSetRGB [internal]
1890 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
1892 char buffer[10];
1893 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1894 int r=GetRValue(cr);
1895 int g=GetGValue(cr);
1896 int b=GetBValue(cr);
1897 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1899 lpp->updating=TRUE;
1900 sprintf(buffer,"%d",r);
1901 SetWindowText32A(GetDlgItem32(hDlg,0x2c2),buffer);
1902 sprintf(buffer,"%d",g);
1903 SetWindowText32A(GetDlgItem32(hDlg,0x2c3),buffer);
1904 sprintf(buffer,"%d",b);
1905 SetWindowText32A(GetDlgItem32(hDlg,0x2c4),buffer);
1906 lpp->updating=FALSE;
1910 /***********************************************************************
1911 * CC_EditSetHSL [internal]
1913 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
1915 char buffer[10];
1916 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1917 lpp->updating=TRUE;
1918 if (IsWindowVisible32(GetDlgItem32(hDlg,0x2c6))) /* if full size */
1920 lpp->updating=TRUE;
1921 sprintf(buffer,"%d",h);
1922 SetWindowText32A(GetDlgItem32(hDlg,0x2bf),buffer);
1923 sprintf(buffer,"%d",s);
1924 SetWindowText32A(GetDlgItem32(hDlg,0x2c0),buffer);
1925 sprintf(buffer,"%d",l);
1926 SetWindowText32A(GetDlgItem32(hDlg,0x2c1),buffer);
1927 lpp->updating=FALSE;
1929 CC_PaintLumBar(hDlg,h,s);
1932 /***********************************************************************
1933 * CC_SwitchToFullSize [internal]
1935 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
1937 int i;
1938 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
1940 EnableWindow32(GetDlgItem32(hDlg,0x2cf),FALSE);
1941 CC_PrepareColorGraph(hDlg);
1942 for (i=0x2bf;i<0x2c5;i++)
1943 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
1944 for (i=0x2d3;i<0x2d9;i++)
1945 EnableWindow32(GetDlgItem32(hDlg,i),TRUE);
1946 EnableWindow32(GetDlgItem32(hDlg,0x2c9),TRUE);
1947 EnableWindow32(GetDlgItem32(hDlg,0x2c8),TRUE);
1949 if (lprect)
1950 SetWindowPos32(hDlg,NULL,0,0,lprect->right-lprect->left,
1951 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
1953 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_SHOW);
1954 ShowWindow32(GetDlgItem32(hDlg,0x2be),SW_SHOW);
1955 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_SHOW);
1957 CC_EditSetRGB(hDlg,result);
1958 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1961 /***********************************************************************
1962 * CC_PaintPredefColorArray [internal]
1964 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
1966 HWND32 hwnd=GetDlgItem32(hDlg,0x2d0);
1967 RECT16 rect;
1968 HDC32 hdc;
1969 HBRUSH32 hBrush;
1970 int dx,dy,i,j,k;
1972 GetClientRect16(hwnd,&rect);
1973 dx=rect.right/cols;
1974 dy=rect.bottom/rows;
1975 k=rect.left;
1977 hdc=GetDC32(hwnd);
1978 GetClientRect16 (hwnd, &rect) ;
1980 for (j=0;j<rows;j++)
1982 for (i=0;i<cols;i++)
1984 hBrush = CreateSolidBrush32(predefcolors[j][i]);
1985 if (hBrush)
1987 hBrush = SelectObject32 (hdc, hBrush) ;
1988 Rectangle32(hdc, rect.left, rect.top,
1989 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
1990 rect.left=rect.left+dx;
1991 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
1994 rect.top=rect.top+dy;
1995 rect.left=k;
1997 ReleaseDC32(hwnd,hdc);
1998 /* FIXME: draw_a_focus_rect */
2000 /***********************************************************************
2001 * CC_PaintUserColorArray [internal]
2003 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
2005 HWND32 hwnd=GetDlgItem32(hDlg,0x2d1);
2006 RECT16 rect;
2007 HDC32 hdc;
2008 HBRUSH32 hBrush;
2009 int dx,dy,i,j,k;
2011 GetClientRect16(hwnd,&rect);
2013 dx=rect.right/cols;
2014 dy=rect.bottom/rows;
2015 k=rect.left;
2017 hdc=GetDC32(hwnd);
2018 if (hdc)
2020 for (j=0;j<rows;j++)
2022 for (i=0;i<cols;i++)
2024 hBrush = CreateSolidBrush32(lpcr[i+j*cols]);
2025 if (hBrush)
2027 hBrush = SelectObject32 (hdc, hBrush) ;
2028 Rectangle32( hdc, rect.left, rect.top,
2029 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
2030 rect.left=rect.left+dx;
2031 DeleteObject32( SelectObject32 (hdc, hBrush)) ;
2034 rect.top=rect.top+dy;
2035 rect.left=k;
2037 ReleaseDC32(hwnd,hdc);
2039 /* FIXME: draw_a_focus_rect */
2044 /***********************************************************************
2045 * CC_HookCallChk [internal]
2047 static BOOL32 CC_HookCallChk(LPCHOOSECOLOR lpcc)
2049 if (lpcc)
2050 if(lpcc->Flags & CC_ENABLEHOOK)
2051 if (lpcc->lpfnHook)
2052 return TRUE;
2053 return FALSE;
2056 /***********************************************************************
2057 * CC_WMInitDialog [internal]
2059 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2061 int i,res;
2062 HWND16 hwnd;
2063 RECT16 rect;
2064 POINT16 point;
2065 struct CCPRIVATE * lpp;
2067 dprintf_commdlg(stddeb,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
2068 lpp=calloc(1,sizeof(struct CCPRIVATE));
2069 lpp->lpcc=(LPCHOOSECOLOR)lParam;
2070 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR))
2072 EndDialog32 (hDlg, 0) ;
2073 return FALSE;
2075 SetWindowLong32A(hDlg, DWL_USER, (LONG)lpp);
2077 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
2078 ShowWindow32(GetDlgItem32(hDlg,0x40e),SW_HIDE);
2079 lpp->msetrgb=RegisterWindowMessage32A( SETRGBSTRING );
2080 #if 0
2081 cpos=MAKELONG(5,7); /* init */
2082 if (lpp->lpcc->Flags & CC_RGBINIT)
2084 for (i=0;i<6;i++)
2085 for (j=0;j<8;j++)
2086 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
2088 cpos=MAKELONG(i,j);
2089 goto found;
2092 found:
2093 /* FIXME: Draw_a_focus_rect & set_init_values */
2094 #endif
2095 GetWindowRect16(hDlg,&lpp->fullsize);
2096 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2098 hwnd=GetDlgItem32(hDlg,0x2cf);
2099 EnableWindow32(hwnd,FALSE);
2101 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
2103 rect=lpp->fullsize;
2104 res=rect.bottom-rect.top;
2105 hwnd=GetDlgItem32(hDlg,0x2c6); /* cut at left border */
2106 point.x=point.y=0;
2107 ClientToScreen16(hwnd,&point);
2108 ScreenToClient16(hDlg,&point);
2109 GetClientRect16(hDlg,&rect);
2110 point.x+=GetSystemMetrics32(SM_CXDLGFRAME);
2111 SetWindowPos32(hDlg,NULL,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
2113 ShowWindow32(GetDlgItem32(hDlg,0x2c6),SW_HIDE);
2114 ShowWindow32(GetDlgItem32(hDlg,0x2c5),SW_HIDE);
2116 else
2117 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
2118 res=TRUE;
2119 for (i=0x2bf;i<0x2c5;i++)
2120 SendMessage16(GetDlgItem32(hDlg,i),EM_LIMITTEXT16,3,0); /* max 3 digits: xyz */
2121 if (CC_HookCallChk(lpp->lpcc))
2122 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2123 return res;
2126 /***********************************************************************
2127 * CC_WMCommand [internal]
2129 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2131 int r,g,b,i,xx;
2132 UINT16 cokmsg;
2133 HDC32 hdc;
2134 COLORREF *cr;
2135 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2136 dprintf_commdlg(stddeb,"CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
2137 switch (wParam)
2139 case 0x2c2: /* edit notify RGB */
2140 case 0x2c3:
2141 case 0x2c4:
2142 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2144 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
2145 r=GetRValue(lpp->lpcc->rgbResult);
2146 g=GetGValue(lpp->lpcc->rgbResult);
2147 b=GetBValue(lpp->lpcc->rgbResult);
2148 xx=0;
2149 switch (wParam)
2151 case 0x2c2:if ((xx=(i!=r))) r=i;break;
2152 case 0x2c3:if ((xx=(i!=g))) g=i;break;
2153 case 0x2c4:if ((xx=(i!=b))) b=i;break;
2155 if (xx) /* something has changed */
2157 lpp->lpcc->rgbResult=RGB(r,g,b);
2158 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2159 lpp->h=CC_RGBtoHSL('H',r,g,b);
2160 lpp->s=CC_RGBtoHSL('S',r,g,b);
2161 lpp->l=CC_RGBtoHSL('L',r,g,b);
2162 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2163 CC_PaintCross(hDlg,lpp->h,lpp->s);
2164 CC_PaintTriangle(hDlg,lpp->l);
2167 break;
2169 case 0x2bf: /* edit notify HSL */
2170 case 0x2c0:
2171 case 0x2c1:
2172 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
2174 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
2175 xx=0;
2176 switch (wParam)
2178 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
2179 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
2180 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
2182 if (xx) /* something has changed */
2184 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2185 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2186 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2187 lpp->lpcc->rgbResult=RGB(r,g,b);
2188 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2189 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2190 CC_PaintCross(hDlg,lpp->h,lpp->s);
2191 CC_PaintTriangle(hDlg,lpp->l);
2194 break;
2196 case 0x2cf:
2197 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
2198 InvalidateRect32( hDlg, NULL, TRUE );
2199 SetFocus32(GetDlgItem32(hDlg,0x2bf));
2200 break;
2202 case 0x2c8: /* add colors ... column by column */
2203 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
2204 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
2205 if (++lpp->nextuserdef==16)
2206 lpp->nextuserdef=0;
2207 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2208 break;
2210 case 0x2c9: /* resulting color */
2211 hdc=GetDC32(hDlg);
2212 lpp->lpcc->rgbResult=GetNearestColor32(hdc,lpp->lpcc->rgbResult);
2213 ReleaseDC32(hDlg,hdc);
2214 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2215 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2216 r=GetRValue(lpp->lpcc->rgbResult);
2217 g=GetGValue(lpp->lpcc->rgbResult);
2218 b=GetBValue(lpp->lpcc->rgbResult);
2219 lpp->h=CC_RGBtoHSL('H',r,g,b);
2220 lpp->s=CC_RGBtoHSL('S',r,g,b);
2221 lpp->l=CC_RGBtoHSL('L',r,g,b);
2222 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2223 CC_PaintCross(hDlg,lpp->h,lpp->s);
2224 CC_PaintTriangle(hDlg,lpp->l);
2225 break;
2227 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
2228 i=RegisterWindowMessage32A( HELPMSGSTRING );
2229 if (lpp->lpcc->hwndOwner)
2230 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
2231 if (CC_HookCallChk(lpp->lpcc))
2232 CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,
2233 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
2234 break;
2236 case IDOK :
2237 cokmsg=RegisterWindowMessage32A( COLOROKSTRING );
2238 if (lpp->lpcc->hwndOwner)
2239 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
2240 break; /* do NOT close */
2242 EndDialog32 (hDlg, 1) ;
2243 return TRUE ;
2245 case IDCANCEL :
2246 EndDialog32 (hDlg, 0) ;
2247 return TRUE ;
2250 return FALSE;
2253 /***********************************************************************
2254 * CC_WMPaint [internal]
2256 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2258 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2259 /* we have to paint dialog children except text and buttons */
2261 CC_PaintPredefColorArray(hDlg,6,8);
2262 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
2263 CC_PaintColorGraph(hDlg);
2264 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
2265 CC_PaintCross(hDlg,lpp->h,lpp->s);
2266 CC_PaintTriangle(hDlg,lpp->l);
2267 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2269 /* special necessary for Wine */
2270 ValidateRect32(GetDlgItem32(hDlg,0x2d0),NULL);
2271 ValidateRect32(GetDlgItem32(hDlg,0x2d1),NULL);
2272 ValidateRect32(GetDlgItem32(hDlg,0x2c6),NULL);
2273 ValidateRect32(GetDlgItem32(hDlg,0x2be),NULL);
2274 ValidateRect32(GetDlgItem32(hDlg,0x2c5),NULL);
2275 /* hope we can remove it later -->FIXME */
2276 return 0;
2280 /***********************************************************************
2281 * CC_WMLButtonDown [internal]
2283 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2285 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2286 int r,g,b,i;
2287 i=0;
2288 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
2289 i=1;
2290 else
2291 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
2292 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
2293 i=1;
2294 else
2295 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
2296 i=2;
2297 else
2298 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
2299 i=2;
2300 if (i==2)
2302 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
2303 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
2304 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
2305 lpp->lpcc->rgbResult=RGB(r,g,b);
2307 if (i==1)
2309 r=GetRValue(lpp->lpcc->rgbResult);
2310 g=GetGValue(lpp->lpcc->rgbResult);
2311 b=GetBValue(lpp->lpcc->rgbResult);
2312 lpp->h=CC_RGBtoHSL('H',r,g,b);
2313 lpp->s=CC_RGBtoHSL('S',r,g,b);
2314 lpp->l=CC_RGBtoHSL('L',r,g,b);
2316 if (i)
2318 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
2319 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
2320 CC_PaintCross(hDlg,lpp->h,lpp->s);
2321 CC_PaintTriangle(hDlg,lpp->l);
2322 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
2323 return TRUE;
2325 return FALSE;
2328 /***********************************************************************
2329 * ColorDlgProc (COMMDLG.8)
2331 LRESULT WINAPI ColorDlgProc(HWND16 hDlg, UINT16 message,
2332 WPARAM16 wParam, LONG lParam)
2334 int res;
2335 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLong32A(hDlg, DWL_USER);
2336 if (message!=WM_INITDIALOG)
2338 if (!lpp)
2339 return FALSE;
2340 res=0;
2341 if (CC_HookCallChk(lpp->lpcc))
2342 res=CallWindowProc16(lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
2343 if (res)
2344 return res;
2347 /* FIXME: SetRGB message
2348 if (message && message==msetrgb)
2349 return HandleSetRGB(hDlg,lParam);
2352 switch (message)
2354 case WM_INITDIALOG:
2355 return CC_WMInitDialog(hDlg,wParam,lParam);
2356 case WM_NCDESTROY:
2357 DeleteDC32(lpp->hdcMem);
2358 DeleteObject32(lpp->hbmMem);
2359 free(lpp);
2360 SetWindowLong32A(hDlg, DWL_USER, 0L); /* we don't need it anymore */
2361 break;
2362 case WM_COMMAND:
2363 if (CC_WMCommand(hDlg, wParam, lParam))
2364 return TRUE;
2365 break;
2366 case WM_PAINT:
2367 CC_WMPaint(hDlg, wParam, lParam);
2368 break;
2369 case WM_LBUTTONDBLCLK:
2370 if (CC_MouseCheckResultWindow(hDlg,lParam))
2371 return TRUE;
2372 break;
2373 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
2374 break;
2375 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
2376 break;
2377 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
2378 if (CC_WMLButtonDown(hDlg, wParam, lParam))
2379 return TRUE;
2380 break;
2382 return FALSE ;
2387 /***********************************************************************
2388 * ChooseFont (COMMDLG.15)
2390 BOOL16 WINAPI ChooseFont(LPCHOOSEFONT lpChFont)
2392 HINSTANCE16 hInst;
2393 HANDLE16 hDlgTmpl = 0;
2394 BOOL16 bRet = FALSE, win32Format = FALSE;
2395 LPCVOID template;
2396 HWND32 hwndDialog;
2398 dprintf_commdlg(stddeb,"ChooseFont\n");
2399 if (!lpChFont) return FALSE;
2401 if (lpChFont->Flags & CF_ENABLETEMPLATEHANDLE)
2403 if (!(template = LockResource16( lpChFont->hInstance )))
2405 CommDlgLastError = CDERR_LOADRESFAILURE;
2406 return FALSE;
2409 else if (lpChFont->Flags & CF_ENABLETEMPLATE)
2411 HANDLE16 hResInfo;
2412 if (!(hResInfo = FindResource16( lpChFont->hInstance,
2413 lpChFont->lpTemplateName, RT_DIALOG)))
2415 CommDlgLastError = CDERR_FINDRESFAILURE;
2416 return FALSE;
2418 if (!(hDlgTmpl = LoadResource16( lpChFont->hInstance, hResInfo )) ||
2419 !(template = LockResource16( hDlgTmpl )))
2421 CommDlgLastError = CDERR_LOADRESFAILURE;
2422 return FALSE;
2425 else
2427 template = SYSRES_GetResPtr( SYSRES_DIALOG_CHOOSE_FONT );
2428 win32Format = TRUE;
2431 hInst = WIN_GetWindowInstance( lpChFont->hwndOwner );
2433 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
2434 lpChFont->hwndOwner,
2435 (DLGPROC16)MODULE_GetWndProcEntry16("FormatCharDlgProc"),
2436 (DWORD)lpChFont, WIN_PROC_16 );
2437 if (hwndDialog) bRet = DIALOG_DoDialogBox(hwndDialog, lpChFont->hwndOwner);
2438 if (hDlgTmpl) FreeResource16( hDlgTmpl );
2439 return bRet;
2443 #define TEXT_EXTRAS 4
2444 #define TEXT_COLORS 16
2446 static const COLORREF textcolors[TEXT_COLORS]=
2448 0x00000000L,0x00000080L,0x00008000L,0x00008080L,
2449 0x00800000L,0x00800080L,0x00808000L,0x00808080L,
2450 0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
2451 0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
2454 /***********************************************************************
2455 * CFn_HookCallChk [internal]
2457 static BOOL32 CFn_HookCallChk(LPCHOOSEFONT lpcf)
2459 if (lpcf)
2460 if(lpcf->Flags & CF_ENABLEHOOK)
2461 if (lpcf->lpfnHook)
2462 return TRUE;
2463 return FALSE;
2467 /***********************************************************************
2468 * FontFamilyEnumProc (COMMDLG.19)
2470 INT16 WINAPI FontFamilyEnumProc( SEGPTR logfont, SEGPTR metrics,
2471 UINT16 nFontType, LPARAM lParam )
2473 int i;
2474 WORD w;
2475 HWND16 hwnd=LOWORD(lParam);
2476 HWND16 hDlg=GetParent16(hwnd);
2477 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2478 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN( logfont );
2480 dprintf_commdlg(stddeb,"FontFamilyEnumProc: font=%s (nFontType=%d)\n",
2481 lplf->lfFaceName,nFontType);
2483 if (lpcf->Flags & CF_FIXEDPITCHONLY)
2484 if (!(lplf->lfPitchAndFamily & FIXED_PITCH))
2485 return 1;
2486 if (lpcf->Flags & CF_ANSIONLY)
2487 if (lplf->lfCharSet != ANSI_CHARSET)
2488 return 1;
2489 if (lpcf->Flags & CF_TTONLY)
2490 if (!(nFontType & 0x0004)) /* this means 'TRUETYPE_FONTTYPE' */
2491 return 1;
2493 i=SendMessage16(hwnd,CB_ADDSTRING16,0,
2494 (LPARAM)logfont + ((char *)lplf->lfFaceName - (char *)lplf));
2495 if (i!=CB_ERR)
2497 w=(lplf->lfCharSet << 8) | lplf->lfPitchAndFamily;
2498 SendMessage16(hwnd, CB_SETITEMDATA16,i,MAKELONG(nFontType,w));
2499 return 1 ; /* store some important font information */
2501 else
2502 return 0;
2505 /*************************************************************************
2506 * SetFontStylesToCombo2 [internal]
2508 * Fill font style information into combobox (without using font.c directly)
2510 static int SetFontStylesToCombo2(HWND16 hwnd, HDC16 hdc, LPLOGFONT16 lplf,
2511 LPTEXTMETRIC16 lptm)
2513 #define FSTYLES 4
2514 struct FONTSTYLE
2515 { int italic;
2516 int weight;
2517 char stname[20]; };
2518 static struct FONTSTYLE fontstyles[FSTYLES]={
2519 { 0,FW_NORMAL,"Regular"},{0,FW_BOLD,"Bold"},
2520 { 1,FW_NORMAL,"Italic"}, {1,FW_BOLD,"Bold Italic"}};
2521 HFONT16 hf;
2522 int i,j;
2524 for (i=0;i<FSTYLES;i++)
2526 lplf->lfItalic=fontstyles[i].italic;
2527 lplf->lfWeight=fontstyles[i].weight;
2528 hf=CreateFontIndirect16(lplf);
2529 hf=SelectObject32(hdc,hf);
2530 GetTextMetrics16(hdc,lptm);
2531 hf=SelectObject32(hdc,hf);
2532 DeleteObject32(hf);
2534 if (lptm->tmWeight==fontstyles[i].weight &&
2535 lptm->tmItalic==fontstyles[i].italic) /* font successful created ? */
2537 char *str = SEGPTR_STRDUP(fontstyles[i].stname);
2538 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(str) );
2539 SEGPTR_FREE(str);
2540 if (j==CB_ERR) return 1;
2541 j=SendMessage16(hwnd, CB_SETITEMDATA16, j,
2542 MAKELONG(fontstyles[i].weight,fontstyles[i].italic));
2543 if (j==CB_ERR) return 1;
2546 return 0;
2549 /*************************************************************************
2550 * SetFontSizesToCombo3 [internal]
2552 static int SetFontSizesToCombo3(HWND16 hwnd, LPLOGFONT16 lplf, LPCHOOSEFONT lpcf)
2554 static const int sizes[]={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72,0};
2555 int h,i,j;
2556 char *buffer;
2558 if (!(buffer = SEGPTR_ALLOC(20))) return 1;
2559 for (i=0;sizes[i] && !lplf->lfHeight;i++)
2561 h=lplf->lfHeight ? lplf->lfHeight : sizes[i];
2563 if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2564 ((lpcf->Flags & CF_LIMITSIZE) && (h >= lpcf->nSizeMin) && (h <= lpcf->nSizeMax)))
2566 sprintf(buffer,"%2d",h);
2567 j=SendMessage16(hwnd,CB_FINDSTRING16,-1,(LPARAM)SEGPTR_GET(buffer));
2568 if (j==CB_ERR)
2570 j=SendMessage16(hwnd,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(buffer));
2571 if (j!=CB_ERR) j = SendMessage16(hwnd, CB_SETITEMDATA16, j, h);
2572 if (j==CB_ERR)
2574 SEGPTR_FREE(buffer);
2575 return 1;
2580 SEGPTR_FREE(buffer);
2581 return 0;
2585 /***********************************************************************
2586 * FontStyleEnumProc (COMMDLG.18)
2588 INT16 WINAPI FontStyleEnumProc( SEGPTR logfont, SEGPTR metrics,
2589 UINT16 nFontType, LPARAM lParam )
2591 HWND16 hcmb2=LOWORD(lParam);
2592 HWND16 hcmb3=HIWORD(lParam);
2593 HWND16 hDlg=GetParent16(hcmb3);
2594 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2595 LOGFONT16 *lplf = (LOGFONT16 *)PTR_SEG_TO_LIN(logfont);
2596 TEXTMETRIC16 *lptm = (TEXTMETRIC16 *)PTR_SEG_TO_LIN(metrics);
2597 int i;
2599 dprintf_commdlg(stddeb,"FontStyleEnumProc: (nFontType=%d)\n",nFontType);
2600 dprintf_commdlg(stddeb," %s h=%d w=%d e=%d o=%d wg=%d i=%d u=%d s=%d ch=%d op=%d cp=%d q=%d pf=%xh\n",
2601 lplf->lfFaceName,lplf->lfHeight,lplf->lfWidth,lplf->lfEscapement,lplf->lfOrientation,
2602 lplf->lfWeight,lplf->lfItalic,lplf->lfUnderline,lplf->lfStrikeOut,lplf->lfCharSet,
2603 lplf->lfOutPrecision,lplf->lfClipPrecision,lplf->lfQuality,lplf->lfPitchAndFamily);
2605 if (SetFontSizesToCombo3(hcmb3, lplf ,lpcf))
2606 return 0;
2608 if (!SendMessage16(hcmb2,CB_GETCOUNT16,0,0))
2610 HDC32 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2611 i=SetFontStylesToCombo2(hcmb2,hdc,lplf,lptm);
2612 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2613 ReleaseDC32(hDlg,hdc);
2614 if (i)
2615 return 0;
2617 return 1 ;
2621 /***********************************************************************
2622 * CFn_WMInitDialog [internal]
2624 LRESULT CFn_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2626 HDC32 hdc;
2627 int i,j,res,init=0;
2628 long l;
2629 LPLOGFONT16 lpxx;
2630 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT));
2631 LPCHOOSEFONT lpcf;
2633 SetWindowLong32A(hDlg, DWL_USER, lParam);
2634 lpcf=(LPCHOOSEFONT)lParam;
2635 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2636 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
2638 if (lpcf->lStructSize != sizeof(CHOOSEFONT))
2640 dprintf_commdlg(stddeb,"WM_INITDIALOG: structure size failure !!!\n");
2641 EndDialog32 (hDlg, 0);
2642 return FALSE;
2644 if (!hBitmapTT)
2645 hBitmapTT = LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE));
2647 if (!(lpcf->Flags & CF_SHOWHELP) || !IsWindow32(lpcf->hwndOwner))
2648 ShowWindow32(GetDlgItem32(hDlg,pshHelp),SW_HIDE);
2649 if (!(lpcf->Flags & CF_APPLY))
2650 ShowWindow32(GetDlgItem32(hDlg,psh3),SW_HIDE);
2651 if (lpcf->Flags & CF_EFFECTS)
2653 for (res=1,i=0;res && i<TEXT_COLORS;i++)
2655 /* FIXME: load color name from resource: res=LoadString(...,i+....,buffer,.....); */
2656 char *name = SEGPTR_ALLOC(20);
2657 strcpy( name, "[color name]" );
2658 j=SendDlgItemMessage16(hDlg,cmb4,CB_ADDSTRING16,0,(LPARAM)SEGPTR_GET(name));
2659 SEGPTR_FREE(name);
2660 SendDlgItemMessage16(hDlg,cmb4, CB_SETITEMDATA16,j,textcolors[j]);
2661 /* look for a fitting value in color combobox */
2662 if (textcolors[j]==lpcf->rgbColors)
2663 SendDlgItemMessage16(hDlg,cmb4, CB_SETCURSEL16,j,0);
2666 else
2668 ShowWindow32(GetDlgItem32(hDlg,cmb4),SW_HIDE);
2669 ShowWindow32(GetDlgItem32(hDlg,chx1),SW_HIDE);
2670 ShowWindow32(GetDlgItem32(hDlg,chx2),SW_HIDE);
2671 ShowWindow32(GetDlgItem32(hDlg,grp1),SW_HIDE);
2672 ShowWindow32(GetDlgItem32(hDlg,stc4),SW_HIDE);
2674 hdc= (lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2675 if (hdc)
2677 if (!EnumFontFamilies16(hdc, NULL,FontFamilyEnumProc,
2678 (LPARAM)GetDlgItem32(hDlg,cmb1)))
2679 dprintf_commdlg(stddeb,"WM_INITDIALOG: EnumFontFamilies returns 0\n");
2680 if (lpcf->Flags & CF_INITTOLOGFONTSTRUCT)
2682 /* look for fitting font name in combobox1 */
2683 j=SendDlgItemMessage16(hDlg,cmb1,CB_FINDSTRING16,-1,(LONG)lpxx->lfFaceName);
2684 if (j!=CB_ERR)
2686 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL16,j,0);
2687 SendMessage16(hDlg,WM_COMMAND,cmb1,
2688 MAKELONG(GetDlgItem32(hDlg,cmb1),CBN_SELCHANGE));
2689 init=1;
2690 /* look for fitting font style in combobox2 */
2691 l=MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:FW_NORMAL,lpxx->lfItalic !=0);
2692 for (i=0;i<TEXT_EXTRAS;i++)
2694 if (l==SendDlgItemMessage16(hDlg,cmb2, CB_GETITEMDATA16,i,0))
2695 SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL16,i,0);
2698 /* look for fitting font size in combobox3 */
2699 j=SendDlgItemMessage16(hDlg,cmb3,CB_GETCOUNT16,0,0);
2700 for (i=0;i<j;i++)
2702 if (lpxx->lfHeight==(int)SendDlgItemMessage16(hDlg,cmb3, CB_GETITEMDATA16,i,0))
2703 SendDlgItemMessage16(hDlg,cmb3,CB_SETCURSEL16,i,0);
2706 if (!init)
2708 SendDlgItemMessage16(hDlg,cmb1,CB_SETCURSEL16,0,0);
2709 SendMessage16(hDlg,WM_COMMAND,cmb1,
2710 MAKELONG(GetDlgItem32(hDlg,cmb1),CBN_SELCHANGE));
2713 if (lpcf->Flags & CF_USESTYLE && lpcf->lpszStyle)
2715 j=SendDlgItemMessage16(hDlg,cmb2,CB_FINDSTRING16,-1,(LONG)lpcf->lpszStyle);
2716 if (j!=CB_ERR)
2718 j=SendDlgItemMessage16(hDlg,cmb2,CB_SETCURSEL16,j,0);
2719 SendMessage16(hDlg,WM_COMMAND,cmb2,
2720 MAKELONG(GetDlgItem32(hDlg,cmb2),CBN_SELCHANGE));
2724 else
2726 dprintf_commdlg(stddeb,"WM_INITDIALOG: HDC failure !!!\n");
2727 EndDialog32 (hDlg, 0);
2728 return FALSE;
2731 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2732 ReleaseDC32(hDlg,hdc);
2733 res=TRUE;
2734 if (CFn_HookCallChk(lpcf))
2735 res=CallWindowProc16(lpcf->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
2736 SetCursor16(hcursor);
2737 return res;
2741 /***********************************************************************
2742 * CFn_WMMeasureItem [internal]
2744 LRESULT CFn_WMMeasureItem(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2746 BITMAP16 bm;
2747 LPMEASUREITEMSTRUCT16 lpmi=PTR_SEG_TO_LIN((LPMEASUREITEMSTRUCT16)lParam);
2748 if (!hBitmapTT)
2749 hBitmapTT = LoadBitmap16(0, MAKEINTRESOURCE(OBM_TRTYPE));
2750 GetObject16( hBitmapTT, sizeof(bm), &bm );
2751 lpmi->itemHeight=bm.bmHeight;
2752 /* FIXME: use MAX of bm.bmHeight and tm.tmHeight .*/
2753 return 0;
2757 /***********************************************************************
2758 * CFn_WMDrawItem [internal]
2760 LRESULT CFn_WMDrawItem(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2762 HBRUSH16 hBrush;
2763 char *buffer;
2764 BITMAP16 bm;
2765 COLORREF cr;
2766 RECT16 rect;
2767 #if 0
2768 HDC16 hMemDC;
2769 int nFontType;
2770 HBITMAP16 hBitmap; /* for later TT usage */
2771 #endif
2772 LPDRAWITEMSTRUCT16 lpdi = (LPDRAWITEMSTRUCT16)PTR_SEG_TO_LIN(lParam);
2774 if (lpdi->itemID == 0xFFFF) /* got no items */
2775 DrawFocusRect16(lpdi->hDC, &lpdi->rcItem);
2776 else
2778 if (lpdi->CtlType == ODT_COMBOBOX)
2780 hBrush = SelectObject32(lpdi->hDC, GetStockObject32(LTGRAY_BRUSH));
2781 SelectObject32(lpdi->hDC, hBrush);
2782 FillRect16(lpdi->hDC, &lpdi->rcItem, hBrush);
2784 else
2785 return TRUE; /* this should never happen */
2787 rect=lpdi->rcItem;
2788 buffer = SEGPTR_ALLOC(40);
2789 switch (lpdi->CtlID)
2791 case cmb1: /* dprintf_commdlg(stddeb,"WM_Drawitem cmb1\n"); */
2792 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT16, lpdi->itemID,
2793 (LPARAM)SEGPTR_GET(buffer));
2794 GetObject16( hBitmapTT, sizeof(bm), &bm );
2795 TextOut16(lpdi->hDC, lpdi->rcItem.left + bm.bmWidth + 10,
2796 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2797 #if 0
2798 nFontType = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA16, lpdi->itemID,0L);
2799 /* FIXME: draw bitmap if truetype usage */
2800 if (nFontType&TRUETYPE_FONTTYPE)
2802 hMemDC = CreateCompatibleDC32(lpdi->hDC);
2803 hBitmap = SelectObject32(hMemDC, hBitmapTT);
2804 BitBlt32(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
2805 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
2806 SelectObject32(hMemDC, hBitmap);
2807 DeleteDC32(hMemDC);
2809 #endif
2810 break;
2811 case cmb2:
2812 case cmb3: /* dprintf_commdlg(stddeb,"WM_DRAWITEN cmb2,cmb3\n"); */
2813 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT16, lpdi->itemID,
2814 (LPARAM)SEGPTR_GET(buffer));
2815 TextOut16(lpdi->hDC, lpdi->rcItem.left,
2816 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2817 break;
2819 case cmb4: /* dprintf_commdlg(stddeb,"WM_DRAWITEM cmb4 (=COLOR)\n"); */
2820 SendMessage16(lpdi->hwndItem, CB_GETLBTEXT16, lpdi->itemID,
2821 (LPARAM)SEGPTR_GET(buffer));
2822 TextOut16(lpdi->hDC, lpdi->rcItem.left + 25+5,
2823 lpdi->rcItem.top, buffer, lstrlen16(buffer));
2824 cr = SendMessage16(lpdi->hwndItem, CB_GETITEMDATA16, lpdi->itemID,0L);
2825 hBrush = CreateSolidBrush32(cr);
2826 if (hBrush)
2828 hBrush = SelectObject32 (lpdi->hDC, hBrush) ;
2829 rect.right=rect.left+25;
2830 rect.top++;
2831 rect.left+=5;
2832 rect.bottom--;
2833 Rectangle32( lpdi->hDC, rect.left, rect.top,
2834 rect.right, rect.bottom );
2835 DeleteObject32( SelectObject32 (lpdi->hDC, hBrush)) ;
2837 rect=lpdi->rcItem;
2838 rect.left+=25+5;
2839 break;
2841 default: return TRUE; /* this should never happen */
2843 SEGPTR_FREE(buffer);
2844 if (lpdi->itemState ==ODS_SELECTED)
2845 InvertRect16(lpdi->hDC, &rect);
2847 return TRUE;
2850 /***********************************************************************
2851 * CFn_WMCtlColor [internal]
2853 LRESULT CFn_WMCtlColor(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2855 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2857 if (lpcf->Flags & CF_EFFECTS)
2858 if (HIWORD(lParam)==CTLCOLOR_STATIC && GetDlgCtrlID32(LOWORD(lParam))==stc6)
2860 SetTextColor32(wParam,lpcf->rgbColors);
2861 return GetStockObject32(WHITE_BRUSH);
2863 return 0;
2866 /***********************************************************************
2867 * CFn_WMCommand [internal]
2869 LRESULT CFn_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
2871 HFONT16 hFont;
2872 int i,j;
2873 long l;
2874 HDC16 hdc;
2875 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
2876 LPLOGFONT16 lpxx=PTR_SEG_TO_LIN(lpcf->lpLogFont);
2878 dprintf_commdlg(stddeb,"FormatCharDlgProc // WM_COMMAND lParam=%08lX\n", lParam);
2879 switch (wParam)
2881 case cmb1:if (HIWORD(lParam)==CBN_SELCHANGE)
2883 hdc=(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC) ? lpcf->hDC : GetDC32(hDlg);
2884 if (hdc)
2886 SendDlgItemMessage16(hDlg,cmb2,CB_RESETCONTENT16,0,0);
2887 SendDlgItemMessage16(hDlg,cmb3,CB_RESETCONTENT16,0,0);
2888 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL16,0,0);
2889 if (i!=CB_ERR)
2891 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT));
2892 char *str = SEGPTR_ALLOC(256);
2893 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT16,i,
2894 (LPARAM)SEGPTR_GET(str));
2895 dprintf_commdlg(stddeb,"WM_COMMAND/cmb1 =>%s\n",str);
2896 EnumFontFamilies16(hdc,str,FontStyleEnumProc,
2897 MAKELONG(GetDlgItem32(hDlg,cmb2),GetDlgItem32(hDlg,cmb3)));
2898 SetCursor16(hcursor);
2899 SEGPTR_FREE(str);
2901 if (!(lpcf->Flags & CF_PRINTERFONTS && lpcf->hDC))
2902 ReleaseDC32(hDlg,hdc);
2904 else
2906 dprintf_commdlg(stddeb,"WM_COMMAND: HDC failure !!!\n");
2907 EndDialog32 (hDlg, 0);
2908 return TRUE;
2911 case chx1:
2912 case chx2:
2913 case cmb2:
2914 case cmb3:if (HIWORD(lParam)==CBN_SELCHANGE || HIWORD(lParam)== BN_CLICKED )
2916 char *str = SEGPTR_ALLOC(256);
2917 dprintf_commdlg(stddeb,"WM_COMMAND/cmb2,3 =%08lX\n", lParam);
2918 i=SendDlgItemMessage16(hDlg,cmb1,CB_GETCURSEL16,0,0);
2919 if (i==CB_ERR)
2920 i=GetDlgItemText32A( hDlg, cmb1, str, 256 );
2921 else
2923 SendDlgItemMessage16(hDlg,cmb1,CB_GETLBTEXT16,i,
2924 (LPARAM)SEGPTR_GET(str));
2925 l=SendDlgItemMessage16(hDlg,cmb1,CB_GETITEMDATA16,i,0);
2926 j=HIWORD(l);
2927 lpcf->nFontType = LOWORD(l);
2928 /* FIXME: lpcf->nFontType |= .... SIMULATED_FONTTYPE and so */
2929 /* same value reported to the EnumFonts
2930 call back with the extra FONTTYPE_... bits added */
2931 lpxx->lfPitchAndFamily=j&0xff;
2932 lpxx->lfCharSet=j>>8;
2934 strcpy(lpxx->lfFaceName,str);
2935 SEGPTR_FREE(str);
2936 i=SendDlgItemMessage16(hDlg,cmb2,CB_GETCURSEL16,0,0);
2937 if (i!=CB_ERR)
2939 l=SendDlgItemMessage16(hDlg,cmb2,CB_GETITEMDATA16,i,0);
2940 if (0!=(lpxx->lfItalic=HIWORD(l)))
2941 lpcf->nFontType |= ITALIC_FONTTYPE;
2942 if ((lpxx->lfWeight=LOWORD(l)) > FW_MEDIUM)
2943 lpcf->nFontType |= BOLD_FONTTYPE;
2945 i=SendDlgItemMessage16(hDlg,cmb3,CB_GETCURSEL16,0,0);
2946 if (i!=CB_ERR)
2947 lpxx->lfHeight=-LOWORD(SendDlgItemMessage16(hDlg,cmb3,CB_GETITEMDATA16,i,0));
2948 else
2949 lpxx->lfHeight=0;
2950 lpxx->lfStrikeOut=IsDlgButtonChecked32(hDlg,chx1);
2951 lpxx->lfUnderline=IsDlgButtonChecked32(hDlg,chx2);
2952 lpxx->lfWidth=lpxx->lfOrientation=lpxx->lfEscapement=0;
2953 lpxx->lfOutPrecision=OUT_DEFAULT_PRECIS;
2954 lpxx->lfClipPrecision=CLIP_DEFAULT_PRECIS;
2955 lpxx->lfQuality=DEFAULT_QUALITY;
2956 lpcf->iPointSize= -10*lpxx->lfHeight;
2958 hFont=CreateFontIndirect16(lpxx);
2959 if (hFont)
2960 SendDlgItemMessage16(hDlg,stc6,WM_SETFONT,hFont,TRUE);
2961 /* FIXME: Delete old font ...? */
2963 break;
2965 case cmb4:i=SendDlgItemMessage16(hDlg,cmb4,CB_GETCURSEL16,0,0);
2966 if (i!=CB_ERR)
2968 lpcf->rgbColors=textcolors[i];
2969 InvalidateRect32( GetDlgItem32(hDlg,stc6), NULL, 0 );
2971 break;
2973 case psh15:i=RegisterWindowMessage32A( HELPMSGSTRING );
2974 if (lpcf->hwndOwner)
2975 SendMessage16(lpcf->hwndOwner,i,0,(LPARAM)lpcf);
2976 if (CFn_HookCallChk(lpcf))
2977 CallWindowProc16(lpcf->lpfnHook,hDlg,WM_COMMAND,psh15,(LPARAM)lpcf);
2978 break;
2980 case IDOK:if ( (!(lpcf->Flags & CF_LIMITSIZE)) ||
2981 ( (lpcf->Flags & CF_LIMITSIZE) &&
2982 (-lpxx->lfHeight >= lpcf->nSizeMin) &&
2983 (-lpxx->lfHeight <= lpcf->nSizeMax)))
2984 EndDialog32(hDlg, TRUE);
2985 else
2987 char buffer[80];
2988 sprintf(buffer,"Select a font size between %d and %d points.",
2989 lpcf->nSizeMin,lpcf->nSizeMax);
2990 MessageBox16(hDlg,buffer,NULL,MB_OK);
2992 return(TRUE);
2993 case IDCANCEL:EndDialog32(hDlg, FALSE);
2994 return(TRUE);
2996 return(FALSE);
3000 /***********************************************************************
3001 * FormatCharDlgProc (COMMDLG.16)
3002 FIXME: 1. some strings are "hardcoded", but it's better load from sysres
3003 2. some CF_.. flags are not supported
3004 3. some TType extensions
3006 LRESULT WINAPI FormatCharDlgProc(HWND16 hDlg, UINT16 message, WPARAM16 wParam,
3007 LPARAM lParam)
3009 LPCHOOSEFONT lpcf=(LPCHOOSEFONT)GetWindowLong32A(hDlg, DWL_USER);
3010 if (message!=WM_INITDIALOG)
3012 int res=0;
3013 if (!lpcf)
3014 return FALSE;
3015 if (CFn_HookCallChk(lpcf))
3016 res=CallWindowProc16(lpcf->lpfnHook,hDlg,message,wParam,lParam);
3017 if (res)
3018 return res;
3020 else
3021 return CFn_WMInitDialog(hDlg,wParam,lParam);
3022 switch (message)
3024 case WM_MEASUREITEM:
3025 return CFn_WMMeasureItem(hDlg,wParam,lParam);
3026 case WM_DRAWITEM:
3027 return CFn_WMDrawItem(hDlg,wParam,lParam);
3028 case WM_CTLCOLOR:
3029 return CFn_WMCtlColor(hDlg,wParam,lParam);
3030 case WM_COMMAND:
3031 return CFn_WMCommand(hDlg,wParam,lParam);
3032 case WM_CHOOSEFONT_GETLOGFONT:
3033 dprintf_commdlg(stddeb,
3034 "FormatCharDlgProc // WM_CHOOSEFONT_GETLOGFONT lParam=%08lX\n", lParam);
3035 /* FIXME: current logfont back to caller */
3036 break;
3038 return FALSE;
3042 #define GET_XXX_FILENAME(xxx) \
3043 BOOL32 WINAPI xxx##32A( LPOPENFILENAME32A ofn ) \
3045 BOOL16 ret; \
3046 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16)); \
3048 memset(ofn16,'\0',sizeof(*ofn16)); \
3049 ofn16->lStructSize = sizeof(*ofn16); \
3050 ofn16->hwndOwner = ofn->hwndOwner; \
3051 /* FIXME: OPENFILENAME16 got only 16 bit for HINSTANCE... */ \
3052 ofn16->hInstance = MODULE_HANDLEtoHMODULE16(ofn->hInstance); \
3053 if (ofn->lpstrFilter) { \
3054 LPSTR s,x; \
3056 /* filter is a list... title\0ext\0......\0\0 */ \
3057 s = (LPSTR)ofn->lpstrFilter; \
3058 while (*s) \
3059 s = s+strlen(s)+1; \
3060 s++; \
3061 x = (LPSTR)SEGPTR_ALLOC(s-ofn->lpstrFilter); \
3062 memcpy(x,ofn->lpstrFilter,s-ofn->lpstrFilter); \
3063 ofn16->lpstrFilter = SEGPTR_GET(x); \
3065 if (ofn->lpstrCustomFilter) { \
3066 LPSTR s,x; \
3068 /* filter is a list... title\0ext\0......\0\0 */ \
3069 s = (LPSTR)ofn->lpstrCustomFilter; \
3070 while (*s) \
3071 s = s+strlen(s)+1; \
3072 x = SEGPTR_ALLOC(s-ofn->lpstrCustomFilter); \
3073 s++; \
3074 memcpy(x,ofn->lpstrCustomFilter,s-ofn->lpstrCustomFilter);\
3075 ofn16->lpstrCustomFilter = SEGPTR_GET(x); \
3077 ofn16->nMaxCustFilter = ofn->nMaxCustFilter; \
3078 ofn16->nFilterIndex = ofn->nFilterIndex; \
3079 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile)); \
3080 ofn16->nMaxFile = ofn->nMaxFile; \
3081 if (ofn->lpstrFileTitle) \
3082 ofn16->lpstrFileTitle= SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrFileTitle));\
3083 ofn16->nMaxFileTitle = ofn->nMaxFileTitle; \
3084 if (ofn->lpstrInitialDir) \
3085 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrInitialDir));\
3086 if (ofn->lpstrTitle) \
3087 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrTitle));\
3088 ofn16->Flags = ofn->Flags|OFN_WINE32; \
3089 ofn16->nFileOffset = ofn->nFileOffset; \
3090 ofn16->nFileExtension = ofn->nFileExtension; \
3091 if (ofn->lpstrDefExt) \
3092 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpstrDefExt));\
3093 ofn16->lCustData = ofn->lCustData; \
3094 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook; \
3096 if (ofn->lpTemplateName) \
3097 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP(ofn->lpTemplateName));\
3099 ret = xxx##16(SEGPTR_GET(ofn16)); \
3101 if (ofn16->lpstrFilter) \
3102 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter)); \
3103 if (ofn16->lpTemplateName) \
3104 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName)); \
3105 if (ofn16->lpstrDefExt) \
3106 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt)); \
3107 if (ofn16->lpstrTitle) \
3108 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle)); \
3109 if (ofn16->lpstrInitialDir) \
3110 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir)); \
3111 if (ofn16->lpstrCustomFilter) \
3112 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter)); \
3114 strcpy(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile)); \
3115 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile)); \
3117 if (ofn16->lpstrFileTitle) \
3118 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle)); \
3119 SEGPTR_FREE(ofn16); \
3120 return ret; \
3123 BOOL32 WINAPI xxx##32W( LPOPENFILENAME32W ofn ) \
3125 BOOL16 ret; \
3126 LPOPENFILENAME16 ofn16 = SEGPTR_ALLOC(sizeof(OPENFILENAME16)); \
3128 memset(ofn16,'\0',sizeof(*ofn16)); \
3129 ofn16->lStructSize = sizeof(*ofn16); \
3130 ofn16->hwndOwner = ofn->hwndOwner; \
3131 /* FIXME: OPENFILENAME16 got only 16 bit for HINSTANCE... */ \
3132 ofn16->hInstance = MODULE_HANDLEtoHMODULE16(ofn->hInstance); \
3133 if (ofn->lpstrFilter) { \
3134 LPWSTR s; \
3135 LPSTR x,y; \
3136 int n; \
3138 /* filter is a list... title\0ext\0......\0\0 */ \
3139 s = (LPWSTR)ofn->lpstrFilter; \
3140 while (*s) \
3141 s = s+lstrlen32W(s)+1; \
3142 s++; \
3143 n = s - ofn->lpstrFilter; /* already divides by 2. ptr magic */\
3144 x = y = (LPSTR)SEGPTR_ALLOC(n); \
3145 s = (LPWSTR)ofn->lpstrFilter; \
3146 while (*s) { \
3147 lstrcpyWtoA(x,s); \
3148 x+=lstrlen32A(x)+1; \
3149 s+=lstrlen32W(s)+1; \
3151 *x=0; \
3152 ofn16->lpstrFilter = SEGPTR_GET(y); \
3154 if (ofn->lpstrCustomFilter) { \
3155 LPWSTR s; \
3156 LPSTR x,y; \
3157 int n; \
3159 /* filter is a list... title\0ext\0......\0\0 */ \
3160 s = (LPWSTR)ofn->lpstrCustomFilter; \
3161 while (*s) \
3162 s = s+lstrlen32W(s)+1; \
3163 s++; \
3164 n = s - ofn->lpstrCustomFilter; \
3165 x = y = (LPSTR)SEGPTR_ALLOC(n); \
3166 s = (LPWSTR)ofn->lpstrCustomFilter; \
3167 while (*s) { \
3168 lstrcpyWtoA(x,s); \
3169 x+=lstrlen32A(x)+1; \
3170 s+=lstrlen32W(s)+1; \
3172 *x=0; \
3173 ofn16->lpstrCustomFilter = SEGPTR_GET(y); \
3175 ofn16->nMaxCustFilter = ofn->nMaxCustFilter; \
3176 ofn16->nFilterIndex = ofn->nFilterIndex; \
3177 ofn16->lpstrFile = SEGPTR_GET(SEGPTR_ALLOC(ofn->nMaxFile)); \
3178 ofn16->nMaxFile = ofn->nMaxFile; \
3179 if (ofn->lpstrFileTitle) \
3180 ofn16->lpstrFileTitle= SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrFileTitle));\
3181 ofn16->nMaxFileTitle = ofn->nMaxFileTitle; \
3182 if (ofn->lpstrInitialDir) \
3183 ofn16->lpstrInitialDir = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrInitialDir));\
3184 if (ofn->lpstrTitle) \
3185 ofn16->lpstrTitle = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrTitle));\
3186 ofn16->Flags = ofn->Flags|OFN_WINE32|OFN_UNICODE; \
3187 ofn16->nFileOffset = ofn->nFileOffset; \
3188 ofn16->nFileExtension = ofn->nFileExtension; \
3189 if (ofn->lpstrDefExt) \
3190 ofn16->lpstrDefExt = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpstrDefExt));\
3191 ofn16->lCustData = ofn->lCustData; \
3192 ofn16->lpfnHook = (WNDPROC16)ofn->lpfnHook; \
3193 if (ofn->lpTemplateName) { \
3194 ofn16->lpTemplateName = SEGPTR_GET(SEGPTR_STRDUP_WtoA(ofn->lpTemplateName));\
3196 ret = xxx##16(SEGPTR_GET(ofn16)); \
3198 if (ofn16->lpstrFilter) \
3199 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFilter)); \
3200 if (ofn16->lpTemplateName) \
3201 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpTemplateName)); \
3202 if (ofn16->lpstrDefExt) \
3203 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrDefExt)); \
3204 if (ofn16->lpstrTitle) \
3205 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrTitle)); \
3206 if (ofn16->lpstrInitialDir) \
3207 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrInitialDir)); \
3208 if (ofn16->lpstrCustomFilter) \
3209 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrCustomFilter)); \
3211 lstrcpyAtoW(ofn->lpstrFile,PTR_SEG_TO_LIN(ofn16->lpstrFile)); \
3212 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFile)); \
3214 if (ofn16->lpstrFileTitle) \
3215 SEGPTR_FREE(PTR_SEG_TO_LIN(ofn16->lpstrFileTitle)); \
3216 SEGPTR_FREE(ofn16); \
3217 return ret; \
3220 GET_XXX_FILENAME(GetOpenFileName)
3221 GET_XXX_FILENAME(GetSaveFileName)