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