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