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