Removed the A/W constants for builtin cursors, icons and resource
[wine] / dlls / commdlg / colordlg16.c
1 /*
2  * COMMDLG - Color Dialog
3  *
4  * Copyright 1994 Martin Ayotte
5  * Copyright 1996 Albrecht Kleine
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 /* BUGS : still seems to not refresh correctly
23    sometimes, especially when 2 instances of the
24    dialog are loaded at the same time */
25
26 #include <ctype.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "wine/winbase16.h"
35 #include "wine/winuser16.h"
36 #include "winuser.h"
37 #include "commdlg.h"
38 #include "dlgs.h"
39 #include "wine/debug.h"
40 #include "cderr.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
43
44 #include "cdlg.h"
45 #include "colordlg.h"
46
47 /***********************************************************************
48  *           ColorDlgProc   (COMMDLG.8)
49  */
50 BOOL16 CALLBACK ColorDlgProc16( HWND16 hDlg16, UINT16 message,
51                             WPARAM16 wParam, LONG lParam )
52 {
53     BOOL16 res;
54     HWND hDlg = HWND_32(hDlg16);
55
56     LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
57     if (message != WM_INITDIALOG)
58     {
59         if (!lpp)
60             return FALSE;
61         res=0;
62         if (CC_HookCallChk(lpp->lpcc))
63             res = CallWindowProc16( (WNDPROC16)lpp->lpcc16->lpfnHook, hDlg16, message, wParam, lParam);
64         if (res)
65             return res;
66     }
67
68     /* FIXME: SetRGB message
69        if (message && message == msetrgb)
70        return HandleSetRGB(hDlg, lParam);
71     */
72
73     switch (message)
74     {
75           case WM_INITDIALOG:
76                         return CC_WMInitDialog(hDlg, wParam, lParam, TRUE);
77           case WM_NCDESTROY:
78                         DeleteDC(lpp->hdcMem);
79                         DeleteObject(lpp->hbmMem);
80                         HeapFree(GetProcessHeap(), 0, lpp->lpcc);
81                         HeapFree(GetProcessHeap(), 0, lpp);
82                         SetWindowLongA(hDlg, DWL_USER, 0L); /* we don't need it anymore */
83                         break;
84           case WM_COMMAND:
85                         if (CC_WMCommand(hDlg, wParam, lParam,
86                                          HIWORD(lParam), HWND_32(LOWORD(lParam))))
87                            return TRUE;
88                         break;
89           case WM_PAINT:
90                         if (CC_WMPaint(hDlg, wParam, lParam))
91                            return TRUE;
92                         break;
93           case WM_LBUTTONDBLCLK:
94                         if (CC_MouseCheckResultWindow(hDlg,lParam))
95                           return TRUE;
96                         break;
97           case WM_MOUSEMOVE:
98                         if (CC_WMMouseMove(hDlg, lParam))
99                           return TRUE;
100                         break;
101           case WM_LBUTTONUP:  /* FIXME: ClipCursor off (if in color graph)*/
102                         if (CC_WMLButtonUp(hDlg, wParam, lParam))
103                            return TRUE;
104                         break;
105           case WM_LBUTTONDOWN:/* FIXME: ClipCursor on  (if in color graph)*/
106                         if (CC_WMLButtonDown(hDlg, wParam, lParam))
107                            return TRUE;
108                         break;
109     }
110     return FALSE ;
111 }
112
113
114
115 /***********************************************************************
116  *            ChooseColor  (COMMDLG.5)
117  */
118 BOOL16 WINAPI ChooseColor16( LPCHOOSECOLOR16 lpChCol )
119 {
120     HINSTANCE16 hInst;
121     HANDLE16 hDlgTmpl16 = 0, hResource16 = 0;
122     HGLOBAL16 hGlobal16 = 0;
123     BOOL16 bRet = FALSE;
124     LPCVOID template;
125     FARPROC16 ptr;
126
127     TRACE("ChooseColor\n");
128     if (!lpChCol) return FALSE;
129
130     if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
131         hDlgTmpl16 = lpChCol->hInstance;
132     else if (lpChCol->Flags & CC_ENABLETEMPLATE)
133     {
134         HANDLE16 hResInfo;
135         if (!(hResInfo = FindResource16(lpChCol->hInstance,
136                                         MapSL(lpChCol->lpTemplateName),
137                                         (LPSTR)RT_DIALOG)))
138         {
139             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
140             return FALSE;
141         }
142         if (!(hDlgTmpl16 = LoadResource16(lpChCol->hInstance, hResInfo)))
143         {
144             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
145             return FALSE;
146         }
147         hResource16 = hDlgTmpl16;
148     }
149     else
150     {
151         HRSRC hResInfo;
152         HGLOBAL hDlgTmpl32;
153         LPCVOID template32;
154         DWORD size;
155         if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_COLOR", (LPSTR)RT_DIALOG)))
156         {
157             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
158             return FALSE;
159         }
160         if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo)) ||
161             !(template32 = LockResource(hDlgTmpl32)))
162         {
163             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
164             return FALSE;
165         }
166         size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo);
167         hGlobal16 = GlobalAlloc16(0, size);
168         if (!hGlobal16)
169         {
170             COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
171             ERR("alloc failure for %ld bytes\n", size);
172             return FALSE;
173         }
174         template = GlobalLock16(hGlobal16);
175         if (!template)
176         {
177             COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
178             ERR("global lock failure for %x handle\n", hDlgTmpl16);
179             GlobalFree16(hGlobal16);
180             return FALSE;
181         }
182         ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
183         hDlgTmpl16 = hGlobal16;
184     }
185
186     ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 8);
187     hInst = GetWindowLongA(HWND_32(lpChCol->hwndOwner), GWL_HINSTANCE);
188     bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChCol->hwndOwner,
189                      (DLGPROC16) ptr, (DWORD)lpChCol);
190     if (hResource16) FreeResource16(hDlgTmpl16);
191     if (hGlobal16)
192     {
193         GlobalUnlock16(hGlobal16);
194         GlobalFree16(hGlobal16);
195     }
196     return bRet;
197 }