source: trunk/src/comctl32/hotkey.c@ 42

Last change on this file since 42 was 42, checked in by achimha, 26 years ago

New Comctl32 controls - not all are compiling/linking yet!

File size: 6.6 KB
Line 
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
33static LRESULT
34HOTKEY_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
57static LRESULT
58HOTKEY_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
71static LRESULT
72HOTKEY_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
91static LRESULT
92HOTKEY_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
93{
94 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
95
96 return infoPtr->hFont;
97}
98
99
100static LRESULT
101HOTKEY_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
129static LRESULT
130HOTKEY_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
140static LRESULT
141HOTKEY_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
152static LRESULT
153HOTKEY_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
163static LRESULT
164HOTKEY_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
175static LRESULT
176HOTKEY_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
194static LRESULT
195HOTKEY_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
225static LRESULT WINE_UNUSED
226HOTKEY_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
254static LRESULT WINE_UNUSED
255HOTKEY_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
266LRESULT WINAPI
267HOTKEY_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
329VOID
330HOTKEY_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
349VOID
350HOTKEY_Unregister (VOID)
351{
352 if (GlobalFindAtomA (HOTKEY_CLASSA))
353 UnregisterClassA (HOTKEY_CLASSA, (HINSTANCE)NULL);
354}
355
Note: See TracBrowser for help on using the repository browser.