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