Fixed some issues found by winapi_check.
[wine/dcerpc.git] / dlls / comctl32 / hotkey.c
blobe5ddb6f16b8a3bdfc5f6a7f7efbf6c2dd319e96d
1 /*
2 * Hotkey control
4 * Copyright 1998, 1999 Eric Kohl
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * NOTES
21 * Development in progress. An author is needed! Any volunteers?
22 * I will only improve this control once in a while.
23 * Eric <ekohl@abo.rhein-zeitung.de>
25 * TODO:
26 * - Some messages.
27 * - Display code.
30 #include <string.h>
31 #include "winbase.h"
32 #include "commctrl.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(hotkey);
37 typedef struct tagHOTKEY_INFO
39 HFONT hFont;
40 BOOL bFocus;
41 INT nHeight;
42 } HOTKEY_INFO;
44 #define HOTKEY_GetInfoPtr(hwnd) ((HOTKEY_INFO *)GetWindowLongA (hwnd, 0))
47 /* << HOTHEY_GetHotKey >> */
48 /* << HOTHEY_SetHotKey >> */
49 /* << HOTHEY_SetRules >> */
53 /* << HOTKEY_Char >> */
56 static LRESULT
57 HOTKEY_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
59 HOTKEY_INFO *infoPtr;
60 TEXTMETRICA tm;
61 HDC hdc;
63 /* allocate memory for info structure */
64 infoPtr = (HOTKEY_INFO *)COMCTL32_Alloc (sizeof(HOTKEY_INFO));
65 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
67 /* initialize info structure */
70 /* get default font height */
71 hdc = GetDC (hwnd);
72 GetTextMetricsA (hdc, &tm);
73 infoPtr->nHeight = tm.tmHeight;
74 ReleaseDC (hwnd, hdc);
76 return 0;
80 static LRESULT
81 HOTKEY_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
83 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
87 /* free hotkey info data */
88 COMCTL32_Free (infoPtr);
89 SetWindowLongA (hwnd, 0, 0);
90 return 0;
94 static LRESULT
95 HOTKEY_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam)
97 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
98 HBRUSH hBrush;
99 RECT rc;
101 hBrush =
102 (HBRUSH)SendMessageA (GetParent (hwnd), WM_CTLCOLOREDIT,
103 wParam, (LPARAM)hwnd);
104 if (hBrush)
105 hBrush = (HBRUSH)GetStockObject (WHITE_BRUSH);
106 GetClientRect (hwnd, &rc);
108 FillRect ((HDC)wParam, &rc, hBrush);
110 return -1;
114 inline static LRESULT
115 HOTKEY_GetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
117 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
119 return infoPtr->hFont;
123 static LRESULT
124 HOTKEY_KeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
126 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
128 switch (wParam) {
129 case VK_RETURN:
130 case VK_TAB:
131 case VK_SPACE:
132 case VK_DELETE:
133 case VK_ESCAPE:
134 case VK_BACK:
135 return DefWindowProcA (hwnd, WM_KEYDOWN, wParam, lParam);
137 case VK_SHIFT:
138 case VK_CONTROL:
139 case VK_MENU:
140 FIXME("modifier key pressed!\n");
141 break;
143 default:
144 FIXME(" %d\n", wParam);
145 break;
148 return TRUE;
152 static LRESULT
153 HOTKEY_KeyUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
155 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
157 FIXME(" %d\n", wParam);
159 return 0;
163 static LRESULT
164 HOTKEY_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
166 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
168 infoPtr->bFocus = FALSE;
169 DestroyCaret ();
171 return 0;
175 static LRESULT
176 HOTKEY_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
178 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
180 SetFocus (hwnd);
182 return 0;
186 inline static LRESULT
187 HOTKEY_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
189 DWORD dwExStyle = GetWindowLongA (hwnd, GWL_EXSTYLE);
190 SetWindowLongA (hwnd, GWL_EXSTYLE, dwExStyle | WS_EX_CLIENTEDGE);
191 return DefWindowProcA (hwnd, WM_NCCREATE, wParam, lParam);
198 static LRESULT
199 HOTKEY_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
201 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
203 infoPtr->bFocus = TRUE;
206 CreateCaret (hwnd, (HBITMAP)0, 1, infoPtr->nHeight);
208 SetCaretPos (1, 1);
210 ShowCaret (hwnd);
213 return 0;
217 inline static LRESULT
218 HOTKEY_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
220 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd);
221 TEXTMETRICA tm;
222 HDC hdc;
223 HFONT hOldFont = 0;
225 infoPtr->hFont = (HFONT)wParam;
227 hdc = GetDC (hwnd);
228 if (infoPtr->hFont)
229 hOldFont = SelectObject (hdc, infoPtr->hFont);
231 GetTextMetricsA (hdc, &tm);
232 infoPtr->nHeight = tm.tmHeight;
234 if (infoPtr->hFont)
235 SelectObject (hdc, hOldFont);
236 ReleaseDC (hwnd, hdc);
238 if (LOWORD(lParam)) {
240 FIXME("force redraw!\n");
244 return 0;
248 static LRESULT WINE_UNUSED
249 HOTKEY_SysKeyDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
251 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
253 switch (wParam) {
254 case VK_RETURN:
255 case VK_TAB:
256 case VK_SPACE:
257 case VK_DELETE:
258 case VK_ESCAPE:
259 case VK_BACK:
260 return DefWindowProcA (hwnd, WM_SYSKEYDOWN, wParam, lParam);
262 case VK_SHIFT:
263 case VK_CONTROL:
264 case VK_MENU:
265 FIXME("modifier key pressed!\n");
266 break;
268 default:
269 FIXME(" %d\n", wParam);
270 break;
273 return TRUE;
277 static LRESULT WINE_UNUSED
278 HOTKEY_SysKeyUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
280 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */
282 FIXME(" %d\n", wParam);
284 return 0;
289 static LRESULT WINAPI
290 HOTKEY_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
292 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
293 if (!HOTKEY_GetInfoPtr (hwnd) && (uMsg != WM_CREATE))
294 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
295 switch (uMsg)
297 /* case HKM_GETHOTKEY: */
298 /* case HKM_SETHOTKEY: */
299 /* case HKM_SETRULES: */
301 /* case WM_CHAR: */
303 case WM_CREATE:
304 return HOTKEY_Create (hwnd, wParam, lParam);
306 case WM_DESTROY:
307 return HOTKEY_Destroy (hwnd, wParam, lParam);
309 case WM_ERASEBKGND:
310 return HOTKEY_EraseBackground (hwnd, wParam, lParam);
312 case WM_GETDLGCODE:
313 return DLGC_WANTCHARS | DLGC_WANTARROWS;
315 case WM_GETFONT:
316 return HOTKEY_GetFont (hwnd, wParam, lParam);
318 case WM_KEYDOWN:
319 case WM_SYSKEYDOWN:
320 return HOTKEY_KeyDown (hwnd, wParam, lParam);
322 case WM_KEYUP:
323 case WM_SYSKEYUP:
324 return HOTKEY_KeyUp (hwnd, wParam, lParam);
326 case WM_KILLFOCUS:
327 return HOTKEY_KillFocus (hwnd, wParam, lParam);
329 case WM_LBUTTONDOWN:
330 return HOTKEY_LButtonDown (hwnd, wParam, lParam);
332 case WM_NCCREATE:
333 return HOTKEY_NCCreate (hwnd, wParam, lParam);
335 /* case WM_PAINT: */
337 case WM_SETFOCUS:
338 return HOTKEY_SetFocus (hwnd, wParam, lParam);
340 case WM_SETFONT:
341 return HOTKEY_SetFont (hwnd, wParam, lParam);
343 /* case WM_SYSCHAR: */
345 default:
346 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
347 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
348 uMsg, wParam, lParam);
349 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
351 return 0;
355 VOID
356 HOTKEY_Register (void)
358 WNDCLASSA wndClass;
360 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
361 wndClass.style = CS_GLOBALCLASS;
362 wndClass.lpfnWndProc = (WNDPROC)HOTKEY_WindowProc;
363 wndClass.cbClsExtra = 0;
364 wndClass.cbWndExtra = sizeof(HOTKEY_INFO *);
365 wndClass.hCursor = 0;
366 wndClass.hbrBackground = 0;
367 wndClass.lpszClassName = HOTKEY_CLASSA;
369 RegisterClassA (&wndClass);
373 VOID
374 HOTKEY_Unregister (void)
376 UnregisterClassA (HOTKEY_CLASSA, (HINSTANCE)NULL);