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

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

Added CVS tag to many files (comctl32 and headers) .

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