Large-scale renaming of all Win32 functions and types to use the
[wine.git] / dlls / comctl32 / hotkey.c
bloba2e5d28722e03f05bfb20798ce42ace1b320300f
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 "commctrl.h"
17 #include "hotkey.h"
18 #include "win.h"
19 #include "debug.h"
22 #define HOTKEY_GetInfoPtr(wndPtr) ((HOTKEY_INFO *)wndPtr->wExtra[0])
25 /* << HOTHEY_GetHotKey >> */
26 /* << HOTHEY_SetHotKey >> */
27 /* << HOTHEY_SetRules >> */
31 /* << HOTKEY_Char >> */
34 static LRESULT
35 HOTKEY_Create (WND *wndPtr, 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 wndPtr->wExtra[0] = (DWORD)infoPtr;
45 if (infoPtr == NULL) {
46 ERR (listview, "could not allocate info memory!\n");
47 return 0;
50 if ((HOTKEY_INFO*)wndPtr->wExtra[0] != infoPtr) {
51 ERR (listview, "pointer assignment error!\n");
52 return 0;
56 /* initialize info structure */
58 /* get default font height */
59 hdc = GetDC (wndPtr->hwndSelf);
60 GetTextMetricsA (hdc, &tm);
61 infoPtr->nHeight = tm.tmHeight;
62 ReleaseDC (wndPtr->hwndSelf, hdc);
64 return 0;
68 static LRESULT
69 HOTKEY_Destroy (WND *wndPtr, WPARAM wParam, LPARAM lParam)
71 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
75 /* free hotkey info data */
76 COMCTL32_Free (infoPtr);
78 return 0;
82 static LRESULT
83 HOTKEY_EraseBackground (WND *wndPtr, WPARAM wParam, LPARAM lParam)
85 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
86 HBRUSH hBrush;
87 RECT rc;
89 hBrush =
90 (HBRUSH)SendMessageA (wndPtr->parent->hwndSelf, WM_CTLCOLOREDIT,
91 wParam, (LPARAM)wndPtr->hwndSelf);
92 if (hBrush)
93 hBrush = (HBRUSH)GetStockObject (WHITE_BRUSH);
94 GetClientRect (wndPtr->hwndSelf, &rc);
96 FillRect ((HDC)wParam, &rc, hBrush);
98 return -1;
102 __inline__ static LRESULT
103 HOTKEY_GetFont (WND *wndPtr, WPARAM wParam, LPARAM lParam)
105 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
107 return infoPtr->hFont;
111 static LRESULT
112 HOTKEY_KeyDown (WND *wndPtr, WPARAM wParam, LPARAM lParam)
114 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
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 DefWindowProcA (wndPtr->hwndSelf, WM_KEYDOWN, wParam, lParam);
125 case VK_SHIFT:
126 case VK_CONTROL:
127 case VK_MENU:
128 FIXME (hotkey, "modifier key pressed!\n");
129 break;
131 default:
132 FIXME (hotkey, " %d\n", wParam);
133 break;
136 return TRUE;
140 static LRESULT
141 HOTKEY_KeyUp (WND *wndPtr, WPARAM wParam, LPARAM lParam)
143 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
145 FIXME (hotkey, " %d\n", wParam);
147 return 0;
151 static LRESULT
152 HOTKEY_KillFocus (WND *wndPtr, WPARAM wParam, LPARAM lParam)
154 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
156 infoPtr->bFocus = FALSE;
157 DestroyCaret ();
159 return 0;
163 static LRESULT
164 HOTKEY_LButtonDown (WND *wndPtr, WPARAM wParam, LPARAM lParam)
166 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
168 SetFocus (wndPtr->hwndSelf);
170 return 0;
174 __inline__ static LRESULT
175 HOTKEY_NCCreate (WND *wndPtr, WPARAM wParam, LPARAM lParam)
177 wndPtr->dwExStyle |= WS_EX_CLIENTEDGE;
179 return DefWindowProcA (wndPtr->hwndSelf, WM_NCCREATE, wParam, lParam);
186 static LRESULT
187 HOTKEY_SetFocus (WND *wndPtr, WPARAM wParam, LPARAM lParam)
189 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
191 infoPtr->bFocus = TRUE;
194 CreateCaret (wndPtr->hwndSelf, (HBITMAP)0, 1, infoPtr->nHeight);
196 SetCaretPos (1, 1);
198 ShowCaret (wndPtr->hwndSelf);
201 return 0;
205 __inline__ static LRESULT
206 HOTKEY_SetFont (WND *wndPtr, WPARAM wParam, LPARAM lParam)
208 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr);
209 TEXTMETRICA tm;
210 HDC hdc;
211 HFONT hOldFont = 0;
213 infoPtr->hFont = (HFONT)wParam;
215 hdc = GetDC (wndPtr->hwndSelf);
216 if (infoPtr->hFont)
217 hOldFont = SelectObject (hdc, infoPtr->hFont);
219 GetTextMetricsA (hdc, &tm);
220 infoPtr->nHeight = tm.tmHeight;
222 if (infoPtr->hFont)
223 SelectObject (hdc, hOldFont);
224 ReleaseDC (wndPtr->hwndSelf, hdc);
226 if (LOWORD(lParam)) {
228 FIXME (hotkey, "force redraw!\n");
232 return 0;
236 static LRESULT
237 HOTKEY_SysKeyDown (WND *wndPtr, WPARAM wParam, LPARAM lParam)
239 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
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 DefWindowProcA (wndPtr->hwndSelf, WM_SYSKEYDOWN, wParam, lParam);
250 case VK_SHIFT:
251 case VK_CONTROL:
252 case VK_MENU:
253 FIXME (hotkey, "modifier key pressed!\n");
254 break;
256 default:
257 FIXME (hotkey, " %d\n", wParam);
258 break;
261 return TRUE;
265 static LRESULT
266 HOTKEY_SysKeyUp (WND *wndPtr, WPARAM wParam, LPARAM lParam)
268 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(wndPtr); */
270 FIXME (hotkey, " %d\n", wParam);
272 return 0;
277 LRESULT WINAPI
278 HOTKEY_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
280 WND *wndPtr = WIN_FindWndPtr(hwnd);
282 switch (uMsg)
284 /* case HKM_GETHOTKEY: */
285 /* case HKM_SETHOTKEY: */
286 /* case HKM_SETRULES: */
288 /* case WM_CHAR: */
290 case WM_CREATE:
291 return HOTKEY_Create (wndPtr, wParam, lParam);
293 case WM_DESTROY:
294 return HOTKEY_Destroy (wndPtr, wParam, lParam);
296 case WM_ERASEBKGND:
297 return HOTKEY_EraseBackground (wndPtr, wParam, lParam);
299 case WM_GETDLGCODE:
300 return DLGC_WANTCHARS | DLGC_WANTARROWS;
302 case WM_GETFONT:
303 return HOTKEY_GetFont (wndPtr, wParam, lParam);
305 case WM_KEYDOWN:
306 case WM_SYSKEYDOWN:
307 return HOTKEY_KeyDown (wndPtr, wParam, lParam);
309 case WM_KEYUP:
310 case WM_SYSKEYUP:
311 return HOTKEY_KeyUp (wndPtr, wParam, lParam);
313 case WM_KILLFOCUS:
314 return HOTKEY_KillFocus (wndPtr, wParam, lParam);
316 case WM_LBUTTONDOWN:
317 return HOTKEY_LButtonDown (wndPtr, wParam, lParam);
319 case WM_NCCREATE:
320 return HOTKEY_NCCreate (wndPtr, wParam, lParam);
322 /* case WM_PAINT: */
324 case WM_SETFOCUS:
325 return HOTKEY_SetFocus (wndPtr, wParam, lParam);
327 case WM_SETFONT:
328 return HOTKEY_SetFont (wndPtr, wParam, lParam);
330 /* case WM_SYSCHAR: */
332 default:
333 if (uMsg >= WM_USER)
334 ERR (hotkey, "unknown msg %04x wp=%08x lp=%08lx\n",
335 uMsg, wParam, lParam);
336 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
338 return 0;
342 VOID
343 HOTKEY_Register (VOID)
345 WNDCLASSA wndClass;
347 if (GlobalFindAtomA (HOTKEY_CLASSA)) return;
349 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
350 wndClass.style = CS_GLOBALCLASS;
351 wndClass.lpfnWndProc = (WNDPROC)HOTKEY_WindowProc;
352 wndClass.cbClsExtra = 0;
353 wndClass.cbWndExtra = sizeof(HOTKEY_INFO *);
354 wndClass.hCursor = 0;
355 wndClass.hbrBackground = 0;
356 wndClass.lpszClassName = HOTKEY_CLASSA;
358 RegisterClassA (&wndClass);
362 VOID
363 HOTKEY_Unregister (VOID)
365 if (GlobalFindAtomA (HOTKEY_CLASSA))
366 UnregisterClassA (HOTKEY_CLASSA, (HINSTANCE)NULL);