Removed all non-standard common control headers from the include
[wine/hacks.git] / dlls / comctl32 / hotkey.c
blobdbe7f0c4c7aee6e033a9923e45ce5a67f3316a2f
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 "winbase.h"
17 #include "commctrl.h"
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(hotkey);
22 typedef struct tagHOTKEY_INFO
24 HFONT hFont;
25 BOOL bFocus;
26 INT nHeight;
27 } HOTKEY_INFO;
29 #define HOTKEY_GetInfoPtr(hwnd) ((HOTKEY_INFO *)GetWindowLongA (hwnd, 0))
32 /* << HOTHEY_GetHotKey >> */
33 /* << HOTHEY_SetHotKey >> */
34 /* << HOTHEY_SetRules >> */
38 /* << HOTKEY_Char >> */
41 static LRESULT
42 HOTKEY_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
44 HOTKEY_INFO *infoPtr;
45 TEXTMETRICA tm;
46 HDC hdc;
48 /* allocate memory for info structure */
49 infoPtr = (HOTKEY_INFO *)COMCTL32_Alloc (sizeof(HOTKEY_INFO));
50 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
52 /* initialize info structure */
55 /* get default font height */
56 hdc = GetDC (hwnd);
57 GetTextMetricsA (hdc, &tm);
58 infoPtr->nHeight = tm.tmHeight;
59 ReleaseDC (hwnd, hdc);
61 return 0;
65 static LRESULT
66 HOTKEY_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
68 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
72 /* free hotkey info data */
73 COMCTL32_Free (infoPtr);
74 SetWindowLongA (hwnd, 0, 0);
75 return 0;
79 static LRESULT
80 HOTKEY_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
82 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
83 HBRUSH hBrush;
84 RECT rc;
86 hBrush =
87 (HBRUSH)SendMessageA (GetParent (hwnd), WM_CTLCOLOREDIT,
88 wParam, (LPARAM)hwnd);
89 if (hBrush)
90 hBrush = (HBRUSH)GetStockObject (WHITE_BRUSH);
91 GetClientRect (hwnd, &rc);
93 FillRect ((HDC)wParam, &rc, hBrush);
95 return -1;
99 inline static LRESULT
100 HOTKEY_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
102 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
104 return infoPtr->hFont;
108 static LRESULT
109 HOTKEY_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
111 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
113 switch (wParam) {
114 case VK_RETURN:
115 case VK_TAB:
116 case VK_SPACE:
117 case VK_DELETE:
118 case VK_ESCAPE:
119 case VK_BACK:
120 return DefWindowProcA (hwnd, WM_KEYDOWN, wParam, lParam);
122 case VK_SHIFT:
123 case VK_CONTROL:
124 case VK_MENU:
125 FIXME("modifier key pressed!\n");
126 break;
128 default:
129 FIXME(" %d\n", wParam);
130 break;
133 return TRUE;
137 static LRESULT
138 HOTKEY_KeyUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
140 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
142 FIXME(" %d\n", wParam);
144 return 0;
148 static LRESULT
149 HOTKEY_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
151 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
153 infoPtr->bFocus = FALSE;
154 DestroyCaret ();
156 return 0;
160 static LRESULT
161 HOTKEY_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
163 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
165 SetFocus (hwnd);
167 return 0;
171 inline static LRESULT
172 HOTKEY_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
174 DWORD dwExStyle = GetWindowLongA (hwnd, GWL_EXSTYLE);
175 SetWindowLongA (hwnd, GWL_EXSTYLE, dwExStyle | WS_EX_CLIENTEDGE);
176 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
183 static LRESULT
184 HOTKEY_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
186 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
188 infoPtr->bFocus = TRUE;
191 CreateCaret (hwnd, (HBITMAP)0, 1, infoPtr->nHeight);
193 SetCaretPos (1, 1);
195 ShowCaret (hwnd);
198 return 0;
202 inline static LRESULT
203 HOTKEY_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
205 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
206 TEXTMETRICA tm;
207 HDC hdc;
208 HFONT hOldFont = 0;
210 infoPtr->hFont = (HFONT)wParam;
212 hdc = GetDC (hwnd);
213 if (infoPtr->hFont)
214 hOldFont = SelectObject (hdc, infoPtr->hFont);
216 GetTextMetricsA (hdc, &tm);
217 infoPtr->nHeight = tm.tmHeight;
219 if (infoPtr->hFont)
220 SelectObject (hdc, hOldFont);
221 ReleaseDC (hwnd, hdc);
223 if (LOWORD(lParam)) {
225 FIXME("force redraw!\n");
229 return 0;
233 static LRESULT WINE_UNUSED
234 HOTKEY_SysKeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
236 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
238 switch (wParam) {
239 case VK_RETURN:
240 case VK_TAB:
241 case VK_SPACE:
242 case VK_DELETE:
243 case VK_ESCAPE:
244 case VK_BACK:
245 return DefWindowProcA (hwnd, WM_SYSKEYDOWN, wParam, lParam);
247 case VK_SHIFT:
248 case VK_CONTROL:
249 case VK_MENU:
250 FIXME("modifier key pressed!\n");
251 break;
253 default:
254 FIXME(" %d\n", wParam);
255 break;
258 return TRUE;
262 static LRESULT WINE_UNUSED
263 HOTKEY_SysKeyUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
265 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
267 FIXME(" %d\n", wParam);
269 return 0;
274 static LRESULT WINAPI
275 HOTKEY_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
277 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
278 if (!HOTKEY_GetInfoPtr (hwnd) && (uMsg != WM_CREATE))
279 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
280 switch (uMsg)
282 /* case HKM_GETHOTKEY: */
283 /* case HKM_SETHOTKEY: */
284 /* case HKM_SETRULES: */
286 /* case WM_CHAR: */
288 case WM_CREATE:
289 return HOTKEY_Create (hwnd, wParam, lParam);
291 case WM_DESTROY:
292 return HOTKEY_Destroy (hwnd, wParam, lParam);
294 case WM_ERASEBKGND:
295 return HOTKEY_EraseBackground (hwnd, wParam, lParam);
297 case WM_GETDLGCODE:
298 return DLGC_WANTCHARS | DLGC_WANTARROWS;
300 case WM_GETFONT:
301 return HOTKEY_GetFont (hwnd, wParam, lParam);
303 case WM_KEYDOWN:
304 case WM_SYSKEYDOWN:
305 return HOTKEY_KeyDown (hwnd, wParam, lParam);
307 case WM_KEYUP:
308 case WM_SYSKEYUP:
309 return HOTKEY_KeyUp (hwnd, wParam, lParam);
311 case WM_KILLFOCUS:
312 return HOTKEY_KillFocus (hwnd, wParam, lParam);
314 case WM_LBUTTONDOWN:
315 return HOTKEY_LButtonDown (hwnd, wParam, lParam);
317 case WM_NCCREATE:
318 return HOTKEY_NCCreate (hwnd, wParam, lParam);
320 /* case WM_PAINT: */
322 case WM_SETFOCUS:
323 return HOTKEY_SetFocus (hwnd, wParam, lParam);
325 case WM_SETFONT:
326 return HOTKEY_SetFont (hwnd, wParam, lParam);
328 /* case WM_SYSCHAR: */
330 default:
331 if (uMsg >= WM_USER)
332 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
333 uMsg, wParam, lParam);
334 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
336 return 0;
340 VOID
341 HOTKEY_Register (void)
343 WNDCLASSA wndClass;
345 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
346 wndClass.style = CS_GLOBALCLASS;
347 wndClass.lpfnWndProc = (WNDPROC)HOTKEY_WindowProc;
348 wndClass.cbClsExtra = 0;
349 wndClass.cbWndExtra = sizeof(HOTKEY_INFO *);
350 wndClass.hCursor = 0;
351 wndClass.hbrBackground = 0;
352 wndClass.lpszClassName = HOTKEY_CLASSA;
354 RegisterClassA (&wndClass);
358 VOID
359 HOTKEY_Unregister (void)
361 UnregisterClassA (HOTKEY_CLASSA, (HINSTANCE)NULL);