New stubs.
[wine/multimedia.git] / dlls / comctl32 / hotkey.c
blob902374d50996e28f555f6ee329e427d34fdb0f15
1 /*
2 * Hotkey control
4 * Copyright 1998 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 "windows.h"
17 #include "commctrl.h"
18 #include "hotkey.h"
19 #include "win.h"
20 #include "debug.h"
23 #define HOTKEY_GetInfoPtr(wndPtr) ((HOTKEY_INFO *)wndPtr->wExtra[0])
26 // << HOTHEY_GetHotKey >>
27 // << HOTHEY_SetHotKey >>
28 // << HOTHEY_SetRules >>
32 // << HOTKEY_Char >>
35 static LRESULT
36 HOTKEY_Create (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
38 HOTKEY_INFO *infoPtr;
39 TEXTMETRIC32A tm;
40 HDC32 hdc;
42 /* allocate memory for info structure */
43 infoPtr = (HOTKEY_INFO *)COMCTL32_Alloc (sizeof(HOTKEY_INFO));
44 wndPtr->wExtra[0] = (DWORD)infoPtr;
46 if (infoPtr == NULL) {
47 ERR (listview, "could not allocate info memory!\n");
48 return 0;
51 if ((HOTKEY_INFO*)wndPtr->wExtra[0] != infoPtr) {
52 ERR (listview, "pointer assignment error!\n");
53 return 0;
57 /* initialize info structure */
59 /* get default font height */
60 hdc = GetDC32 (wndPtr->hwndSelf);
61 GetTextMetrics32A (hdc, &tm);
62 infoPtr->nHeight = tm.tmHeight;
63 ReleaseDC32 (wndPtr->hwndSelf, hdc);
65 return 0;
69 static LRESULT
70 HOTKEY_Destroy (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
72 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
76 /* free hotkey info data */
77 COMCTL32_Free (infoPtr);
79 return 0;
83 static LRESULT
84 HOTKEY_EraseBackground (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
86 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
87 HBRUSH32 hBrush;
88 RECT32 rc;
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);
97 FillRect32 ((HDC32)wParam, &rc, hBrush);
99 return -1;
103 __inline__ static LRESULT
104 HOTKEY_GetFont (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
106 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
108 return infoPtr->hFont;
112 static LRESULT
113 HOTKEY_KeyDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
115 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
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);
126 case VK_SHIFT:
127 case VK_CONTROL:
128 case VK_MENU:
129 FIXME (hotkey, "modifier key pressed!\n");
130 break;
132 default:
133 FIXME (hotkey, " %d\n", wParam);
134 break;
137 return TRUE;
141 static LRESULT
142 HOTKEY_KeyUp (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
144 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
146 FIXME (hotkey, " %d\n", wParam);
148 return 0;
152 static LRESULT
153 HOTKEY_KillFocus (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
155 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
157 infoPtr->bFocus = FALSE;
158 DestroyCaret32 ();
160 return 0;
164 static LRESULT
165 HOTKEY_LButtonDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
167 // HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
169 SetFocus32 (wndPtr->hwndSelf);
171 return 0;
175 __inline__ static LRESULT
176 HOTKEY_NCCreate (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
178 wndPtr->dwExStyle |= WS_EX_CLIENTEDGE;
180 return DefWindowProc32A (wndPtr->hwndSelf, WM_NCCREATE, wParam, lParam);
187 static LRESULT
188 HOTKEY_SetFocus (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
190 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
192 infoPtr->bFocus = TRUE;
195 CreateCaret32 (wndPtr->hwndSelf, (HBITMAP32)0, 1, infoPtr->nHeight);
197 SetCaretPos32 (1, 1);
199 ShowCaret32 (wndPtr->hwndSelf);
202 return 0;
206 __inline__ static LRESULT
207 HOTKEY_SetFont (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
209 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
210 TEXTMETRIC32A tm;
211 HDC32 hdc;
212 HFONT32 hOldFont = 0;
214 infoPtr->hFont = (HFONT32)wParam;
216 hdc = GetDC32 (wndPtr->hwndSelf);
217 if (infoPtr->hFont)
218 hOldFont = SelectObject32 (hdc, infoPtr->hFont);
220 GetTextMetrics32A (hdc, &tm);
221 infoPtr->nHeight = tm.tmHeight;
223 if (infoPtr->hFont)
224 SelectObject32 (hdc, hOldFont);
225 ReleaseDC32 (wndPtr->hwndSelf, hdc);
227 if (LOWORD(lParam)) {
229 FIXME (hotkey, "force redraw!\n");
233 return 0;
237 static LRESULT
238 HOTKEY_SysKeyDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
240 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
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);
251 case VK_SHIFT:
252 case VK_CONTROL:
253 case VK_MENU:
254 FIXME (hotkey, "modifier key pressed!\n");
255 break;
257 default:
258 FIXME (hotkey, " %d\n", wParam);
259 break;
262 return TRUE;
266 static LRESULT
267 HOTKEY_SysKeyUp (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
269 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
271 FIXME (hotkey, " %d\n", wParam);
273 return 0;
278 LRESULT WINAPI
279 HOTKEY_WindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
281 WND *wndPtr = WIN_FindWndPtr(hwnd);
283 switch (uMsg)
285 // case HKM_GETHOTKEY:
286 // case HKM_SETHOTKEY:
287 // case HKM_SETRULES:
289 // case WM_CHAR:
291 case WM_CREATE:
292 return HOTKEY_Create (wndPtr, wParam, lParam);
294 case WM_DESTROY:
295 return HOTKEY_Destroy (wndPtr, wParam, lParam);
297 case WM_ERASEBKGND:
298 return HOTKEY_EraseBackground (wndPtr, wParam, lParam);
300 case WM_GETDLGCODE:
301 return DLGC_WANTCHARS | DLGC_WANTARROWS;
303 case WM_GETFONT:
304 return HOTKEY_GetFont (wndPtr, wParam, lParam);
306 case WM_KEYDOWN:
307 case WM_SYSKEYDOWN:
308 return HOTKEY_KeyDown (wndPtr, wParam, lParam);
310 case WM_KEYUP:
311 case WM_SYSKEYUP:
312 return HOTKEY_KeyUp (wndPtr, wParam, lParam);
314 case WM_KILLFOCUS:
315 return HOTKEY_KillFocus (wndPtr, wParam, lParam);
317 case WM_LBUTTONDOWN:
318 return HOTKEY_LButtonDown (wndPtr, wParam, lParam);
320 case WM_NCCREATE:
321 return HOTKEY_NCCreate (wndPtr, wParam, lParam);
323 // case WM_PAINT:
325 case WM_SETFOCUS:
326 return HOTKEY_SetFocus (wndPtr, wParam, lParam);
328 case WM_SETFONT:
329 return HOTKEY_SetFont (wndPtr, wParam, lParam);
331 // case WM_SYSCHAR:
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);
339 return 0;
343 VOID
344 HOTKEY_Register (VOID)
346 WNDCLASS32A wndClass;
348 if (GlobalFindAtom32A (HOTKEY_CLASS32A)) return;
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;
359 RegisterClass32A (&wndClass);
363 VOID
364 HOTKEY_Unregister (VOID)
366 if (GlobalFindAtom32A (HOTKEY_CLASS32A))
367 UnregisterClass32A (HOTKEY_CLASS32A, (HINSTANCE32)NULL);