1 | /*
|
---|
2 | * Hotkey control
|
---|
3 | *
|
---|
4 | * Copyright 1998, 1999 Eric Kohl
|
---|
5 | *
|
---|
6 | * NOTES
|
---|
7 | * Development in progress. An author is needed! Any volunteers?
|
---|
8 | * I will only improve this control once in a while.
|
---|
9 | * Eric <ekohl@abo.rhein-zeitung.de>
|
---|
10 | *
|
---|
11 | * TODO:
|
---|
12 | * - Some messages.
|
---|
13 | * - Display code.
|
---|
14 | */
|
---|
15 |
|
---|
16 | #include "winbase.h"
|
---|
17 | #include "commctrl.h"
|
---|
18 | #include "hotkey.h"
|
---|
19 |
|
---|
20 |
|
---|
21 | #define HOTKEY_GetInfoPtr(hwnd) ((HOTKEY_INFO *)GetWindowLongA (hwnd, 0))
|
---|
22 |
|
---|
23 |
|
---|
24 | /* << HOTHEY_GetHotKey >> */
|
---|
25 | /* << HOTHEY_SetHotKey >> */
|
---|
26 | /* << HOTHEY_SetRules >> */
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 | /* << HOTKEY_Char >> */
|
---|
31 |
|
---|
32 |
|
---|
33 | static LRESULT
|
---|
34 | HOTKEY_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
35 | {
|
---|
36 | HOTKEY_INFO *infoPtr;
|
---|
37 | TEXTMETRICA tm;
|
---|
38 | HDC hdc;
|
---|
39 |
|
---|
40 | /* allocate memory for info structure */
|
---|
41 | infoPtr = (HOTKEY_INFO *)COMCTL32_Alloc (sizeof(HOTKEY_INFO));
|
---|
42 | SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
|
---|
43 |
|
---|
44 | /* initialize info structure */
|
---|
45 |
|
---|
46 |
|
---|
47 | /* get default font height */
|
---|
48 | hdc = GetDC (hwnd);
|
---|
49 | GetTextMetricsA (hdc, &tm);
|
---|
50 | infoPtr->nHeight = tm.tmHeight;
|
---|
51 | ReleaseDC (hwnd, hdc);
|
---|
52 |
|
---|
53 | return 0;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | static LRESULT
|
---|
58 | HOTKEY_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
59 | {
|
---|
60 | HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
|
---|
61 |
|
---|
62 |
|
---|
63 |
|
---|
64 | /* free hotkey info data */
|
---|
65 | COMCTL32_Free (infoPtr);
|
---|
66 |
|
---|
67 | return 0;
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | static LRESULT
|
---|
72 | HOTKEY_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
73 | {
|
---|
74 | /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
|
---|
75 | HBRUSH hBrush;
|
---|
76 | RECT rc;
|
---|
77 |
|
---|
78 | hBrush =
|
---|
79 | (HBRUSH)SendMessageA (GetParent (hwnd), WM_CTLCOLOREDIT,
|
---|
80 | wParam, (LPARAM)hwnd);
|
---|
81 | if (hBrush)
|
---|
82 | hBrush = (HBRUSH)GetStockObject (WHITE_BRUSH);
|
---|
83 | GetClientRect (hwnd, &rc);
|
---|
84 |
|
---|
85 | FillRect ((HDC)wParam, &rc, hBrush);
|
---|
86 |
|
---|
87 | return -1;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | static LRESULT
|
---|
92 | HOTKEY_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
93 | {
|
---|
94 | HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
|
---|
95 |
|
---|
96 | return infoPtr->hFont;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | static LRESULT
|
---|
101 | HOTKEY_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
102 | {
|
---|
103 | /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
|
---|
104 |
|
---|
105 | switch (wParam) {
|
---|
106 | case VK_RETURN:
|
---|
107 | case VK_TAB:
|
---|
108 | case VK_SPACE:
|
---|
109 | case VK_DELETE:
|
---|
110 | case VK_ESCAPE:
|
---|
111 | case VK_BACK:
|
---|
112 | return DefWindowProcA (hwnd, WM_KEYDOWN, wParam, lParam);
|
---|
113 |
|
---|
114 | case VK_SHIFT:
|
---|
115 | case VK_CONTROL:
|
---|
116 | case VK_MENU:
|
---|
117 | // FIXME (hotkey, "modifier key pressed!\n");
|
---|
118 | break;
|
---|
119 |
|
---|
120 | default:
|
---|
121 | // FIXME (hotkey, " %d\n", wParam);
|
---|
122 | break;
|
---|
123 | }
|
---|
124 |
|
---|
125 | return TRUE;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | static LRESULT
|
---|
130 | HOTKEY_KeyUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
131 | {
|
---|
132 | /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
|
---|
133 |
|
---|
134 | // FIXME (hotkey, " %d\n", wParam);
|
---|
135 |
|
---|
136 | return 0;
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | static LRESULT
|
---|
141 | HOTKEY_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
142 | {
|
---|
143 | HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
|
---|
144 |
|
---|
145 | infoPtr->bFocus = FALSE;
|
---|
146 | DestroyCaret ();
|
---|
147 |
|
---|
148 | return 0;
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | static LRESULT
|
---|
153 | HOTKEY_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
154 | {
|
---|
155 | /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
|
---|
156 |
|
---|
157 | SetFocus (hwnd);
|
---|
158 |
|
---|
159 | return 0;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | static LRESULT
|
---|
164 | HOTKEY_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
165 | {
|
---|
166 | DWORD dwExStyle = GetWindowLongA (hwnd, GWL_EXSTYLE);
|
---|
167 | SetWindowLongA (hwnd, GWL_EXSTYLE, dwExStyle | WS_EX_CLIENTEDGE);
|
---|
168 | return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 |
|
---|
174 |
|
---|
175 | static LRESULT
|
---|
176 | HOTKEY_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
177 | {
|
---|
178 | HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
|
---|
179 |
|
---|
180 | infoPtr->bFocus = TRUE;
|
---|
181 |
|
---|
182 |
|
---|
183 | CreateCaret (hwnd, (HBITMAP)0, 1, infoPtr->nHeight);
|
---|
184 |
|
---|
185 | SetCaretPos (1, 1);
|
---|
186 |
|
---|
187 | ShowCaret (hwnd);
|
---|
188 |
|
---|
189 |
|
---|
190 | return 0;
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | static LRESULT
|
---|
195 | HOTKEY_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
196 | {
|
---|
197 | HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
|
---|
198 | TEXTMETRICA tm;
|
---|
199 | HDC hdc;
|
---|
200 | HFONT hOldFont = 0;
|
---|
201 |
|
---|
202 | infoPtr->hFont = (HFONT)wParam;
|
---|
203 |
|
---|
204 | hdc = GetDC (hwnd);
|
---|
205 | if (infoPtr->hFont)
|
---|
206 | hOldFont = SelectObject (hdc, infoPtr->hFont);
|
---|
207 |
|
---|
208 | GetTextMetricsA (hdc, &tm);
|
---|
209 | infoPtr->nHeight = tm.tmHeight;
|
---|
210 |
|
---|
211 | if (infoPtr->hFont)
|
---|
212 | SelectObject (hdc, hOldFont);
|
---|
213 | ReleaseDC (hwnd, hdc);
|
---|
214 |
|
---|
215 | if (LOWORD(lParam)) {
|
---|
216 |
|
---|
217 | // FIXME (hotkey, "force redraw!\n");
|
---|
218 |
|
---|
219 | }
|
---|
220 |
|
---|
221 | return 0;
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 | static LRESULT WINE_UNUSED
|
---|
226 | HOTKEY_SysKeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
227 | {
|
---|
228 | /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
|
---|
229 |
|
---|
230 | switch (wParam) {
|
---|
231 | case VK_RETURN:
|
---|
232 | case VK_TAB:
|
---|
233 | case VK_SPACE:
|
---|
234 | case VK_DELETE:
|
---|
235 | case VK_ESCAPE:
|
---|
236 | case VK_BACK:
|
---|
237 | return DefWindowProcA (hwnd, WM_SYSKEYDOWN, wParam, lParam);
|
---|
238 |
|
---|
239 | case VK_SHIFT:
|
---|
240 | case VK_CONTROL:
|
---|
241 | case VK_MENU:
|
---|
242 | // FIXME (hotkey, "modifier key pressed!\n");
|
---|
243 | break;
|
---|
244 |
|
---|
245 | default:
|
---|
246 | // FIXME (hotkey, " %d\n", wParam);
|
---|
247 | break;
|
---|
248 | }
|
---|
249 |
|
---|
250 | return TRUE;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | static LRESULT WINE_UNUSED
|
---|
255 | HOTKEY_SysKeyUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
256 | {
|
---|
257 | /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
|
---|
258 |
|
---|
259 | // FIXME (hotkey, " %d\n", wParam);
|
---|
260 |
|
---|
261 | return 0;
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 |
|
---|
266 | LRESULT WINAPI
|
---|
267 | HOTKEY_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
268 | {
|
---|
269 | switch (uMsg)
|
---|
270 | {
|
---|
271 | /* case HKM_GETHOTKEY: */
|
---|
272 | /* case HKM_SETHOTKEY: */
|
---|
273 | /* case HKM_SETRULES: */
|
---|
274 |
|
---|
275 | /* case WM_CHAR: */
|
---|
276 |
|
---|
277 | case WM_CREATE:
|
---|
278 | return HOTKEY_Create (hwnd, wParam, lParam);
|
---|
279 |
|
---|
280 | case WM_DESTROY:
|
---|
281 | return HOTKEY_Destroy (hwnd, wParam, lParam);
|
---|
282 |
|
---|
283 | case WM_ERASEBKGND:
|
---|
284 | return HOTKEY_EraseBackground (hwnd, wParam, lParam);
|
---|
285 |
|
---|
286 | case WM_GETDLGCODE:
|
---|
287 | return DLGC_WANTCHARS | DLGC_WANTARROWS;
|
---|
288 |
|
---|
289 | case WM_GETFONT:
|
---|
290 | return HOTKEY_GetFont (hwnd, wParam, lParam);
|
---|
291 |
|
---|
292 | case WM_KEYDOWN:
|
---|
293 | case WM_SYSKEYDOWN:
|
---|
294 | return HOTKEY_KeyDown (hwnd, wParam, lParam);
|
---|
295 |
|
---|
296 | case WM_KEYUP:
|
---|
297 | case WM_SYSKEYUP:
|
---|
298 | return HOTKEY_KeyUp (hwnd, wParam, lParam);
|
---|
299 |
|
---|
300 | case WM_KILLFOCUS:
|
---|
301 | return HOTKEY_KillFocus (hwnd, wParam, lParam);
|
---|
302 |
|
---|
303 | case WM_LBUTTONDOWN:
|
---|
304 | return HOTKEY_LButtonDown (hwnd, wParam, lParam);
|
---|
305 |
|
---|
306 | case WM_NCCREATE:
|
---|
307 | return HOTKEY_NCCreate (hwnd, wParam, lParam);
|
---|
308 |
|
---|
309 | /* case WM_PAINT: */
|
---|
310 |
|
---|
311 | case WM_SETFOCUS:
|
---|
312 | return HOTKEY_SetFocus (hwnd, wParam, lParam);
|
---|
313 |
|
---|
314 | case WM_SETFONT:
|
---|
315 | return HOTKEY_SetFont (hwnd, wParam, lParam);
|
---|
316 |
|
---|
317 | /* case WM_SYSCHAR: */
|
---|
318 |
|
---|
319 | default:
|
---|
320 | // if (uMsg >= WM_USER)
|
---|
321 | // ERR (hotkey, "unknown msg %04x wp=%08x lp=%08lx\n",
|
---|
322 | // uMsg, wParam, lParam);
|
---|
323 | return DefWindowProcA (hwnd, uMsg, wParam, lParam);
|
---|
324 | }
|
---|
325 | return 0;
|
---|
326 | }
|
---|
327 |
|
---|
328 |
|
---|
329 | VOID
|
---|
330 | HOTKEY_Register (VOID)
|
---|
331 | {
|
---|
332 | WNDCLASSA wndClass;
|
---|
333 |
|
---|
334 | if (GlobalFindAtomA (HOTKEY_CLASSA)) return;
|
---|
335 |
|
---|
336 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
---|
337 | wndClass.style = CS_GLOBALCLASS;
|
---|
338 | wndClass.lpfnWndProc = (WNDPROC)HOTKEY_WindowProc;
|
---|
339 | wndClass.cbClsExtra = 0;
|
---|
340 | wndClass.cbWndExtra = sizeof(HOTKEY_INFO *);
|
---|
341 | wndClass.hCursor = 0;
|
---|
342 | wndClass.hbrBackground = 0;
|
---|
343 | wndClass.lpszClassName = HOTKEY_CLASSA;
|
---|
344 |
|
---|
345 | RegisterClassA (&wndClass);
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | VOID
|
---|
350 | HOTKEY_Unregister (VOID)
|
---|
351 | {
|
---|
352 | if (GlobalFindAtomA (HOTKEY_CLASSA))
|
---|
353 | UnregisterClassA (HOTKEY_CLASSA, (HINSTANCE)NULL);
|
---|
354 | }
|
---|
355 |
|
---|