Replaced direct access to the WND structure by corresponding calls to
[wine/multimedia.git] / dlls / comctl32 / hotkey.c
blobd50fe252796eab72446b38d14b65cfcdef49f1d6
1 /*
2 * Hotkey control
4 * Copyright 1998, 1999 Eric Kohl
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>
11 * TODO:
12 * - Some messages.
13 * - Display code.
16 #include "commctrl.h"
17 #include "hotkey.h"
18 #include "win.h"
19 #include "debug.h"
22 #define HOTKEY_GetInfoPtr(hwnd) ((HOTKEY_INFO *)GetWindowLongA (hwnd, 0))
25 /* << HOTHEY_GetHotKey >> */
26 /* << HOTHEY_SetHotKey >> */
27 /* << HOTHEY_SetRules >> */
31 /* << HOTKEY_Char >> */
34 static LRESULT
35 HOTKEY_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
37 HOTKEY_INFO *infoPtr;
38 TEXTMETRICA tm;
39 HDC hdc;
41 /* allocate memory for info structure */
42 infoPtr = (HOTKEY_INFO *)COMCTL32_Alloc (sizeof(HOTKEY_INFO));
43 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
45 /* initialize info structure */
48 /* get default font height */
49 hdc = GetDC (hwnd);
50 GetTextMetricsA (hdc, &tm);
51 infoPtr->nHeight = tm.tmHeight;
52 ReleaseDC (hwnd, hdc);
54 return 0;
58 static LRESULT
59 HOTKEY_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
61 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
65 /* free hotkey info data */
66 COMCTL32_Free (infoPtr);
68 return 0;
72 static LRESULT
73 HOTKEY_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
75 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
76 HBRUSH hBrush;
77 RECT rc;
79 hBrush =
80 (HBRUSH)SendMessageA (GetParent (hwnd), WM_CTLCOLOREDIT,
81 wParam, (LPARAM)hwnd);
82 if (hBrush)
83 hBrush = (HBRUSH)GetStockObject (WHITE_BRUSH);
84 GetClientRect (hwnd, &rc);
86 FillRect ((HDC)wParam, &rc, hBrush);
88 return -1;
92 __inline__ static LRESULT
93 HOTKEY_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
95 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
97 return infoPtr->hFont;
101 static LRESULT
102 HOTKEY_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
104 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
106 switch (wParam) {
107 case VK_RETURN:
108 case VK_TAB:
109 case VK_SPACE:
110 case VK_DELETE:
111 case VK_ESCAPE:
112 case VK_BACK:
113 return DefWindowProcA (hwnd, WM_KEYDOWN, wParam, lParam);
115 case VK_SHIFT:
116 case VK_CONTROL:
117 case VK_MENU:
118 FIXME (hotkey, "modifier key pressed!\n");
119 break;
121 default:
122 FIXME (hotkey, " %d\n", wParam);
123 break;
126 return TRUE;
130 static LRESULT
131 HOTKEY_KeyUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
133 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
135 FIXME (hotkey, " %d\n", wParam);
137 return 0;
141 static LRESULT
142 HOTKEY_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
144 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
146 infoPtr->bFocus = FALSE;
147 DestroyCaret ();
149 return 0;
153 static LRESULT
154 HOTKEY_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
156 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
158 SetFocus (hwnd);
160 return 0;
164 __inline__ static LRESULT
165 HOTKEY_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
167 DWORD dwExStyle = GetWindowLongA (hwnd, GWL_EXSTYLE);
168 SetWindowLongA (hwnd, GWL_EXSTYLE, dwExStyle | WS_EX_CLIENTEDGE);
169 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
176 static LRESULT
177 HOTKEY_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
179 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
181 infoPtr->bFocus = TRUE;
184 CreateCaret (hwnd, (HBITMAP)0, 1, infoPtr->nHeight);
186 SetCaretPos (1, 1);
188 ShowCaret (hwnd);
191 return 0;
195 __inline__ static LRESULT
196 HOTKEY_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
198 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
199 TEXTMETRICA tm;
200 HDC hdc;
201 HFONT hOldFont = 0;
203 infoPtr->hFont = (HFONT)wParam;
205 hdc = GetDC (hwnd);
206 if (infoPtr->hFont)
207 hOldFont = SelectObject (hdc, infoPtr->hFont);
209 GetTextMetricsA (hdc, &tm);
210 infoPtr->nHeight = tm.tmHeight;
212 if (infoPtr->hFont)
213 SelectObject (hdc, hOldFont);
214 ReleaseDC (hwnd, hdc);
216 if (LOWORD(lParam)) {
218 FIXME (hotkey, "force redraw!\n");
222 return 0;
226 static LRESULT WINE_UNUSED
227 HOTKEY_SysKeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
229 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
231 switch (wParam) {
232 case VK_RETURN:
233 case VK_TAB:
234 case VK_SPACE:
235 case VK_DELETE:
236 case VK_ESCAPE:
237 case VK_BACK:
238 return DefWindowProcA (hwnd, WM_SYSKEYDOWN, wParam, lParam);
240 case VK_SHIFT:
241 case VK_CONTROL:
242 case VK_MENU:
243 FIXME (hotkey, "modifier key pressed!\n");
244 break;
246 default:
247 FIXME (hotkey, " %d\n", wParam);
248 break;
251 return TRUE;
255 static LRESULT WINE_UNUSED
256 HOTKEY_SysKeyUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
258 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
260 FIXME (hotkey, " %d\n", wParam);
262 return 0;
267 LRESULT WINAPI
268 HOTKEY_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
270 switch (uMsg)
272 /* case HKM_GETHOTKEY: */
273 /* case HKM_SETHOTKEY: */
274 /* case HKM_SETRULES: */
276 /* case WM_CHAR: */
278 case WM_CREATE:
279 return HOTKEY_Create (hwnd, wParam, lParam);
281 case WM_DESTROY:
282 return HOTKEY_Destroy (hwnd, wParam, lParam);
284 case WM_ERASEBKGND:
285 return HOTKEY_EraseBackground (hwnd, wParam, lParam);
287 case WM_GETDLGCODE:
288 return DLGC_WANTCHARS | DLGC_WANTARROWS;
290 case WM_GETFONT:
291 return HOTKEY_GetFont (hwnd, wParam, lParam);
293 case WM_KEYDOWN:
294 case WM_SYSKEYDOWN:
295 return HOTKEY_KeyDown (hwnd, wParam, lParam);
297 case WM_KEYUP:
298 case WM_SYSKEYUP:
299 return HOTKEY_KeyUp (hwnd, wParam, lParam);
301 case WM_KILLFOCUS:
302 return HOTKEY_KillFocus (hwnd, wParam, lParam);
304 case WM_LBUTTONDOWN:
305 return HOTKEY_LButtonDown (hwnd, wParam, lParam);
307 case WM_NCCREATE:
308 return HOTKEY_NCCreate (hwnd, wParam, lParam);
310 /* case WM_PAINT: */
312 case WM_SETFOCUS:
313 return HOTKEY_SetFocus (hwnd, wParam, lParam);
315 case WM_SETFONT:
316 return HOTKEY_SetFont (hwnd, wParam, lParam);
318 /* case WM_SYSCHAR: */
320 default:
321 if (uMsg >= WM_USER)
322 ERR (hotkey, "unknown msg %04x wp=%08x lp=%08lx\n",
323 uMsg, wParam, lParam);
324 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
326 return 0;
330 VOID
331 HOTKEY_Register (VOID)
333 WNDCLASSA wndClass;
335 if (GlobalFindAtomA (HOTKEY_CLASSA)) return;
337 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
338 wndClass.style = CS_GLOBALCLASS;
339 wndClass.lpfnWndProc = (WNDPROC)HOTKEY_WindowProc;
340 wndClass.cbClsExtra = 0;
341 wndClass.cbWndExtra = sizeof(HOTKEY_INFO *);
342 wndClass.hCursor = 0;
343 wndClass.hbrBackground = 0;
344 wndClass.lpszClassName = HOTKEY_CLASSA;
346 RegisterClassA (&wndClass);
350 VOID
351 HOTKEY_Unregister (VOID)
353 if (GlobalFindAtomA (HOTKEY_CLASSA))
354 UnregisterClassA (HOTKEY_CLASSA, (HINSTANCE)NULL);