- New implementation of SendMessage, ReceiveMessage, ReplyMessage functions
[wine] / dlls / comctl32 / hotkey.c
1 /*
2  * Hotkey control
3  *
4  * Copyright 1998 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 "commctrl.h"
17 #include "hotkey.h"
18 #include "win.h"
19 #include "debug.h"
20
21
22 #define HOTKEY_GetInfoPtr(wndPtr) ((HOTKEY_INFO *)wndPtr->wExtra[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 (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
36 {
37     HOTKEY_INFO *infoPtr;
38     TEXTMETRIC32A tm;
39     HDC32 hdc;
40
41     /* allocate memory for info structure */
42     infoPtr = (HOTKEY_INFO *)COMCTL32_Alloc (sizeof(HOTKEY_INFO));
43     wndPtr->wExtra[0] = (DWORD)infoPtr;
44
45     if (infoPtr == NULL) {
46         ERR (listview, "could not allocate info memory!\n");
47         return 0;
48     }
49
50     if ((HOTKEY_INFO*)wndPtr->wExtra[0] != infoPtr) {
51         ERR (listview, "pointer assignment error!\n");
52         return 0;
53     }
54
55
56     /* initialize info structure */
57
58     /* get default font height */
59     hdc = GetDC32 (wndPtr->hwndSelf);
60     GetTextMetrics32A (hdc, &tm);
61     infoPtr->nHeight = tm.tmHeight;
62     ReleaseDC32 (wndPtr->hwndSelf, hdc);
63
64     return 0;
65 }
66
67
68 static LRESULT
69 HOTKEY_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
70 {
71     HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
72
73
74
75     /* free hotkey info data */
76     COMCTL32_Free (infoPtr);
77
78     return 0;
79 }
80
81
82 static LRESULT
83 HOTKEY_EraseBackground (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
84 {
85     /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
86     HBRUSH32 hBrush;
87     RECT32   rc;
88
89     hBrush =
90         (HBRUSH32)SendMessage32A (wndPtr->parent->hwndSelf, WM_CTLCOLOREDIT,
91                                   wParam, (LPARAM)wndPtr->hwndSelf);
92     if (hBrush)
93         hBrush = (HBRUSH32)GetStockObject32 (WHITE_BRUSH);
94     GetClientRect32 (wndPtr->hwndSelf, &rc);
95
96     FillRect32 ((HDC32)wParam, &rc, hBrush);
97
98     return -1;
99 }
100
101
102 __inline__ static LRESULT
103 HOTKEY_GetFont (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
104 {
105     HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
106
107     return infoPtr->hFont;
108 }
109
110
111 static LRESULT
112 HOTKEY_KeyDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
113 {
114     /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
115
116     switch (wParam) {
117         case VK_RETURN:
118         case VK_TAB:
119         case VK_SPACE:
120         case VK_DELETE:
121         case VK_ESCAPE:
122         case VK_BACK:
123             return DefWindowProc32A (wndPtr->hwndSelf, WM_KEYDOWN, wParam, lParam);
124
125         case VK_SHIFT:
126         case VK_CONTROL:
127         case VK_MENU:
128             FIXME (hotkey, "modifier key pressed!\n");
129             break;
130
131         default:
132             FIXME (hotkey, " %d\n", wParam);
133             break;
134     }
135
136     return TRUE;
137 }
138
139
140 static LRESULT
141 HOTKEY_KeyUp (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
142 {
143     /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
144
145     FIXME (hotkey, " %d\n", wParam);
146
147     return 0;
148 }
149
150
151 static LRESULT
152 HOTKEY_KillFocus (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
153 {
154     HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
155
156     infoPtr->bFocus = FALSE;
157     DestroyCaret32 ();
158
159     return 0;
160 }
161
162
163 static LRESULT
164 HOTKEY_LButtonDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
165 {
166 /*    HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
167
168     SetFocus32 (wndPtr->hwndSelf);
169
170     return 0;
171 }
172
173
174 __inline__ static LRESULT
175 HOTKEY_NCCreate (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
176 {
177     wndPtr->dwExStyle |= WS_EX_CLIENTEDGE;
178
179     return DefWindowProc32A (wndPtr->hwndSelf, WM_NCCREATE, wParam, lParam);
180 }
181
182
183
184
185
186 static LRESULT
187 HOTKEY_SetFocus (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
188 {
189     HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
190
191     infoPtr->bFocus = TRUE;
192
193
194     CreateCaret32 (wndPtr->hwndSelf, (HBITMAP32)0, 1, infoPtr->nHeight);
195
196     SetCaretPos32 (1, 1);
197
198     ShowCaret32 (wndPtr->hwndSelf);
199
200
201     return 0;
202 }
203
204
205 __inline__ static LRESULT
206 HOTKEY_SetFont (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
207 {
208     HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
209     TEXTMETRIC32A tm;
210     HDC32 hdc;
211     HFONT32 hOldFont = 0;
212
213     infoPtr->hFont = (HFONT32)wParam;
214
215     hdc = GetDC32 (wndPtr->hwndSelf);
216     if (infoPtr->hFont)
217         hOldFont = SelectObject32 (hdc, infoPtr->hFont);
218
219     GetTextMetrics32A (hdc, &tm);
220     infoPtr->nHeight = tm.tmHeight;
221
222     if (infoPtr->hFont)
223         SelectObject32 (hdc, hOldFont);
224     ReleaseDC32 (wndPtr->hwndSelf, hdc);
225
226     if (LOWORD(lParam)) {
227
228         FIXME (hotkey, "force redraw!\n");
229
230     }
231
232     return 0;
233 }
234
235
236 static LRESULT
237 HOTKEY_SysKeyDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
238 {
239     /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
240
241     switch (wParam) {
242         case VK_RETURN:
243         case VK_TAB:
244         case VK_SPACE:
245         case VK_DELETE:
246         case VK_ESCAPE:
247         case VK_BACK:
248             return DefWindowProc32A (wndPtr->hwndSelf, WM_SYSKEYDOWN, wParam, lParam);
249
250         case VK_SHIFT:
251         case VK_CONTROL:
252         case VK_MENU:
253             FIXME (hotkey, "modifier key pressed!\n");
254             break;
255
256         default:
257             FIXME (hotkey, " %d\n", wParam);
258             break;
259     }
260
261     return TRUE;
262 }
263
264
265 static LRESULT
266 HOTKEY_SysKeyUp (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
267 {
268     /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
269
270     FIXME (hotkey, " %d\n", wParam);
271
272     return 0;
273 }
274
275
276
277 LRESULT WINAPI
278 HOTKEY_WindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
279 {
280     WND *wndPtr = WIN_FindWndPtr(hwnd);
281
282     switch (uMsg)
283     {
284 /*      case HKM_GETHOTKEY: */
285 /*      case HKM_SETHOTKEY: */
286 /*      case HKM_SETRULES: */
287
288 /*      case WM_CHAR: */
289
290         case WM_CREATE:
291             return HOTKEY_Create (wndPtr, wParam, lParam);
292
293         case WM_DESTROY:
294             return HOTKEY_Destroy (wndPtr, wParam, lParam);
295
296         case WM_ERASEBKGND:
297             return HOTKEY_EraseBackground (wndPtr, wParam, lParam);
298
299         case WM_GETDLGCODE:
300             return DLGC_WANTCHARS | DLGC_WANTARROWS;
301
302         case WM_GETFONT:
303             return HOTKEY_GetFont (wndPtr, wParam, lParam);
304
305         case WM_KEYDOWN:
306         case WM_SYSKEYDOWN:
307             return HOTKEY_KeyDown (wndPtr, wParam, lParam);
308
309         case WM_KEYUP:
310         case WM_SYSKEYUP:
311             return HOTKEY_KeyUp (wndPtr, wParam, lParam);
312
313         case WM_KILLFOCUS:
314             return HOTKEY_KillFocus (wndPtr, wParam, lParam);
315
316         case WM_LBUTTONDOWN:
317             return HOTKEY_LButtonDown (wndPtr, wParam, lParam);
318
319         case WM_NCCREATE:
320             return HOTKEY_NCCreate (wndPtr, wParam, lParam);
321
322 /*      case WM_PAINT: */
323
324         case WM_SETFOCUS:
325             return HOTKEY_SetFocus (wndPtr, wParam, lParam);
326
327         case WM_SETFONT:
328             return HOTKEY_SetFont (wndPtr, wParam, lParam);
329
330 /*      case WM_SYSCHAR: */
331
332         default:
333             if (uMsg >= WM_USER)
334                 ERR (hotkey, "unknown msg %04x wp=%08x lp=%08lx\n",
335                      uMsg, wParam, lParam);
336             return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
337     }
338     return 0;
339 }
340
341
342 VOID
343 HOTKEY_Register (VOID)
344 {
345     WNDCLASS32A wndClass;
346
347     if (GlobalFindAtom32A (HOTKEY_CLASS32A)) return;
348
349     ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
350     wndClass.style         = CS_GLOBALCLASS;
351     wndClass.lpfnWndProc   = (WNDPROC32)HOTKEY_WindowProc;
352     wndClass.cbClsExtra    = 0;
353     wndClass.cbWndExtra    = sizeof(HOTKEY_INFO *);
354     wndClass.hCursor       = 0;
355     wndClass.hbrBackground = 0;
356     wndClass.lpszClassName = HOTKEY_CLASS32A;
357  
358     RegisterClass32A (&wndClass);
359 }
360
361
362 VOID
363 HOTKEY_Unregister (VOID)
364 {
365     if (GlobalFindAtom32A (HOTKEY_CLASS32A))
366         UnregisterClass32A (HOTKEY_CLASS32A, (HINSTANCE32)NULL);
367 }
368