1 | /* $Id: CCBase.cpp,v 1.5 2000-03-21 17:30:40 cbratschi Exp $ */
|
---|
2 | /*
|
---|
3 | * COMCTL32 Base Functions and Macros for all Controls
|
---|
4 | *
|
---|
5 | * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
|
---|
6 | *
|
---|
7 | * parts from WINE code
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "winbase.h"
|
---|
11 | #include "comctl32.h"
|
---|
12 | #include "ccbase.h"
|
---|
13 |
|
---|
14 | BOOL checkVersion(INT iVersion)
|
---|
15 | {
|
---|
16 | return iVersion <= COMCTL32_VERSION;
|
---|
17 | }
|
---|
18 |
|
---|
19 | //init-done
|
---|
20 |
|
---|
21 | PVOID initControl(HWND hwnd,DWORD dwSize)
|
---|
22 | {
|
---|
23 | COMCTL32_HEADER *infoPtr;
|
---|
24 |
|
---|
25 | if (dwSize < sizeof(COMCTL32_HEADER)) return NULL;
|
---|
26 |
|
---|
27 | infoPtr = (COMCTL32_HEADER*)COMCTL32_Alloc(dwSize);
|
---|
28 |
|
---|
29 | if (!infoPtr) return NULL;
|
---|
30 |
|
---|
31 | setInfoPtr(hwnd,infoPtr);
|
---|
32 | ZeroMemory(infoPtr,dwSize);
|
---|
33 | infoPtr->dwSize = dwSize;
|
---|
34 | infoPtr->iVersion = 0;
|
---|
35 | infoPtr->fUnicode = IsWindowUnicode(hwnd);
|
---|
36 | infoPtr->uNotifyFormat = sendNotifyFormat(GetParent(hwnd),hwnd,NF_QUERY);
|
---|
37 | infoPtr->hwndNotify = GetParent(hwnd);
|
---|
38 |
|
---|
39 | return infoPtr;
|
---|
40 | }
|
---|
41 |
|
---|
42 | VOID doneControl(HWND hwnd)
|
---|
43 | {
|
---|
44 | COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
|
---|
45 |
|
---|
46 | if (infoPtr)
|
---|
47 | {
|
---|
48 | COMCTL32_Free(infoPtr);
|
---|
49 | setInfoPtr(hwnd,NULL);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | //Default message handler
|
---|
54 |
|
---|
55 | LRESULT defComCtl32Proc(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,BOOL unicode)
|
---|
56 | {
|
---|
57 | COMCTL32_HEADER *infoPtr;
|
---|
58 |
|
---|
59 | switch (Msg)
|
---|
60 | {
|
---|
61 | case CCM_GETVERSION:
|
---|
62 | infoPtr = getInfoPtr(hwnd);
|
---|
63 | return infoPtr ? infoPtr->iVersion:0;
|
---|
64 |
|
---|
65 | case CCM_SETVERSION:
|
---|
66 | infoPtr = getInfoPtr(hwnd);
|
---|
67 | if (infoPtr)
|
---|
68 | {
|
---|
69 | if (checkVersion((INT)wParam))
|
---|
70 | {
|
---|
71 | INT oldVersion;
|
---|
72 |
|
---|
73 | oldVersion = infoPtr->iVersion;
|
---|
74 | infoPtr->iVersion = (INT)wParam;
|
---|
75 | return oldVersion;
|
---|
76 | } else return -1;
|
---|
77 | } else return 0;
|
---|
78 |
|
---|
79 | case CCM_GETUNICODEFORMAT:
|
---|
80 | infoPtr = getInfoPtr(hwnd);
|
---|
81 | return infoPtr ? infoPtr->fUnicode:IsWindowUnicode(hwnd);
|
---|
82 |
|
---|
83 | case CCM_SETUNICODEFORMAT:
|
---|
84 | infoPtr = getInfoPtr(hwnd);
|
---|
85 | if (infoPtr)
|
---|
86 | {
|
---|
87 | BOOL oldFormat;
|
---|
88 |
|
---|
89 | oldFormat = infoPtr->fUnicode;
|
---|
90 | infoPtr->fUnicode = (INT)wParam;
|
---|
91 | return oldFormat;
|
---|
92 | } else return IsWindowUnicode(hwnd);
|
---|
93 |
|
---|
94 | case WM_NOTIFYFORMAT:
|
---|
95 | {
|
---|
96 | infoPtr = getInfoPtr(hwnd);
|
---|
97 |
|
---|
98 | if (!infoPtr) break;
|
---|
99 |
|
---|
100 | if (lParam == NF_REQUERY)
|
---|
101 | {
|
---|
102 | infoPtr->uNotifyFormat = sendNotifyFormat(GetParent(hwnd),hwnd,NF_QUERY);
|
---|
103 | if ((infoPtr->uNotifyFormat != NFR_ANSI) && (infoPtr->uNotifyFormat != NFR_UNICODE))
|
---|
104 | infoPtr->uNotifyFormat = IsWindowUnicode(GetParent(hwnd)) ? NFR_UNICODE:NFR_ANSI;
|
---|
105 | return infoPtr->uNotifyFormat;
|
---|
106 | } else if (lParam == NF_QUERY)
|
---|
107 | {
|
---|
108 | return infoPtr->uNotifyFormat;
|
---|
109 | }
|
---|
110 | break;
|
---|
111 | }
|
---|
112 |
|
---|
113 | case CCM_SETNOTIFYWINDOW:
|
---|
114 | {
|
---|
115 | infoPtr = getInfoPtr(hwnd);
|
---|
116 |
|
---|
117 | if (!infoPtr) break;
|
---|
118 |
|
---|
119 | infoPtr->hwndNotify = (HWND)wParam;
|
---|
120 |
|
---|
121 | break;
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | if (unicode)
|
---|
126 | return DefWindowProcW(hwnd,Msg,wParam,lParam);
|
---|
127 | else
|
---|
128 | return DefWindowProcA(hwnd,Msg,wParam,lParam);
|
---|
129 | }
|
---|
130 |
|
---|
131 | LRESULT defComCtl32ProcA(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
|
---|
132 | {
|
---|
133 | return defComCtl32Proc(hwnd,Msg,wParam,lParam,FALSE);
|
---|
134 | }
|
---|
135 |
|
---|
136 | LRESULT defComCtl32ProcW(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam)
|
---|
137 | {
|
---|
138 | return defComCtl32Proc(hwnd,Msg,wParam,lParam,TRUE);
|
---|
139 | }
|
---|
140 |
|
---|
141 | //Notifications
|
---|
142 |
|
---|
143 | BOOL isUnicodeNotify(COMCTL32_HEADER *infoPtr)
|
---|
144 | {
|
---|
145 | if (!infoPtr) return FALSE;
|
---|
146 |
|
---|
147 | return infoPtr->uNotifyFormat == NFR_UNICODE;
|
---|
148 | }
|
---|
149 |
|
---|
150 | BOOL isUnicodeNotify(HWND hwnd)
|
---|
151 | {
|
---|
152 | COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
|
---|
153 |
|
---|
154 | return isUnicodeNotify(infoPtr);
|
---|
155 | }
|
---|
156 |
|
---|
157 | HWND getNotifyWindow(COMCTL32_HEADER *infoPtr)
|
---|
158 | {
|
---|
159 | if (!infoPtr) return 0;
|
---|
160 |
|
---|
161 | return infoPtr->hwndNotify;
|
---|
162 | }
|
---|
163 |
|
---|
164 | HWND getNotifyWindow(HWND hwnd)
|
---|
165 | {
|
---|
166 | COMCTL32_HEADER *infoPtr = getInfoPtr(hwnd);
|
---|
167 |
|
---|
168 | return getNotifyWindow(infoPtr);
|
---|
169 | }
|
---|
170 |
|
---|
171 | LRESULT sendNotify(HWND hwnd,UINT code)
|
---|
172 | {
|
---|
173 | NMHDR nmhdr;
|
---|
174 |
|
---|
175 | nmhdr.hwndFrom = hwnd;
|
---|
176 | nmhdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
|
---|
177 | nmhdr.code = code;
|
---|
178 |
|
---|
179 | return SendMessageA(getNotifyWindow(hwnd),WM_NOTIFY,nmhdr.idFrom,(LPARAM)&nmhdr);
|
---|
180 | }
|
---|
181 |
|
---|
182 | LRESULT sendNotify(HWND hwnd,UINT code,LPNMHDR nmhdr)
|
---|
183 | {
|
---|
184 | if (!nmhdr) return 0;
|
---|
185 |
|
---|
186 | nmhdr->hwndFrom = hwnd;
|
---|
187 | nmhdr->idFrom = GetWindowLongA(hwnd,GWL_ID);
|
---|
188 | nmhdr->code = code;
|
---|
189 |
|
---|
190 | return SendMessageA(getNotifyWindow(hwnd),WM_NOTIFY,nmhdr->idFrom,(LPARAM)nmhdr);
|
---|
191 | }
|
---|
192 |
|
---|
193 | LRESULT sendNotifyFormat(HWND hwnd,HWND hwndFrom,LPARAM command)
|
---|
194 | {
|
---|
195 | return SendMessageA(hwnd,WM_NOTIFYFORMAT,hwndFrom,command);
|
---|
196 | }
|
---|
197 |
|
---|
198 | LRESULT sendCommand(HWND hwnd,UINT wNotifyCode)
|
---|
199 | {
|
---|
200 | return SendMessageA(getNotifyWindow(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),wNotifyCode),(LPARAM)hwnd);
|
---|
201 | }
|
---|
202 |
|
---|
203 | LRESULT sendHScroll(HWND hwnd,UINT wNotifyCode)
|
---|
204 | {
|
---|
205 | return SendMessageA(getNotifyWindow(hwnd),WM_HSCROLL,(WPARAM)wNotifyCode,(LPARAM)hwnd);
|
---|
206 | }
|
---|
207 |
|
---|
208 | LRESULT sendVScroll(HWND hwnd,UINT wNotifyCode)
|
---|
209 | {
|
---|
210 | return SendMessageA(getNotifyWindow(hwnd),WM_VSCROLL,(WPARAM)wNotifyCode,(LPARAM)hwnd);
|
---|
211 | }
|
---|
212 |
|
---|
213 | //Tooltips
|
---|
214 |
|
---|
215 | HWND createToolTip(HWND hwnd,UINT flags,BOOL addtool)
|
---|
216 | {
|
---|
217 | HWND hwndToolTip;
|
---|
218 | NMTOOLTIPSCREATED nmttc;
|
---|
219 | TTTOOLINFOA ti;
|
---|
220 |
|
---|
221 | hwndToolTip =
|
---|
222 | CreateWindowExA (0, TOOLTIPS_CLASSA, NULL, 0,
|
---|
223 | CW_USEDEFAULT, CW_USEDEFAULT,
|
---|
224 | CW_USEDEFAULT, CW_USEDEFAULT,
|
---|
225 | hwnd, 0, 0, 0);
|
---|
226 |
|
---|
227 | if (!hwndToolTip) return 0;
|
---|
228 |
|
---|
229 | /* Send NM_TOOLTIPSCREATED notification */
|
---|
230 | nmttc.hwndToolTips = hwndToolTip;
|
---|
231 | sendNotify(hwnd,NM_TOOLTIPSCREATED,&nmttc.hdr);
|
---|
232 |
|
---|
233 | if (addtool)
|
---|
234 | {
|
---|
235 | ZeroMemory(&ti,sizeof(TTTOOLINFOA));
|
---|
236 | ti.cbSize = sizeof(TTTOOLINFOA);
|
---|
237 | ti.uFlags = flags;
|
---|
238 | ti.hwnd = hwnd;
|
---|
239 | ti.uId = 0;
|
---|
240 | ti.lpszText = "";
|
---|
241 | SetRectEmpty (&ti.rect);
|
---|
242 |
|
---|
243 | SendMessageA(hwndToolTip,TTM_ADDTOOLA,0,(LPARAM)&ti);
|
---|
244 | }
|
---|
245 |
|
---|
246 | return hwndToolTip;
|
---|
247 | }
|
---|
248 |
|
---|
249 | VOID destroyToolTip(HWND hwndToolTip)
|
---|
250 | {
|
---|
251 | if (hwndToolTip) DestroyWindow(hwndToolTip);
|
---|
252 | }
|
---|
253 |
|
---|
254 | //stub control
|
---|
255 |
|
---|
256 | VOID drawStubControl(HWND hwnd,HDC hdc)
|
---|
257 | {
|
---|
258 | RECT rect;
|
---|
259 | HBRUSH brush = CreateSolidBrush(RGB(0,0,255));
|
---|
260 | HPEN pen = CreatePen(PS_SOLID,0,RGB(255,0,0)),oldPen;
|
---|
261 | COLORREF oldColor;
|
---|
262 |
|
---|
263 | GetClientRect(hwnd,&rect);
|
---|
264 | FillRect(hdc,&rect,brush);
|
---|
265 | oldPen = SelectObject(hdc,pen);
|
---|
266 | MoveToEx(hdc,0,0,NULL);
|
---|
267 | LineTo(hdc,rect.right,rect.bottom);
|
---|
268 | MoveToEx(hdc,rect.right,0,NULL);
|
---|
269 | LineTo(hdc,0,rect.bottom);
|
---|
270 | SelectObject(hdc,oldPen);
|
---|
271 | oldColor = SetTextColor(hdc,RGB(255,255,255));
|
---|
272 | DrawTextA(hdc,"Unimplemented Control!",-1,&rect,DT_CENTER | DT_SINGLELINE | DT_VCENTER);
|
---|
273 | SetTextColor(hdc,oldColor);
|
---|
274 |
|
---|
275 | DeleteObject(brush);
|
---|
276 | DeleteObject(pen);
|
---|
277 | }
|
---|