Changeset 968 for trunk/src/comctl32/hotkey.c
- Timestamp:
- Sep 18, 1999, 2:21:26 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/hotkey.c
r496 r968 1 /* $Id: hotkey.c,v 1. 4 1999-08-14 16:13:10cbratschi Exp $ */1 /* $Id: hotkey.c,v 1.5 1999-09-18 12:21:26 cbratschi Exp $ */ 2 2 /* 3 3 * Hotkey control … … 5 5 * Copyright 1998, 1999 Eric Kohl 6 6 * Copyright 1999 Achim Hasenmueller 7 * Copyright 1999 Christoph Bratschi 7 8 * 8 9 * NOTES 9 * Development in progress. An author is needed! Any volunteers? 10 * I will only improve this control once in a while. 11 * Eric <ekohl@abo.rhein-zeitung.de> 10 * Development in progress. 11 * CB: difficult with new User32 12 12 * 13 13 * TODO: 14 * - Some messages. 15 * - Display code. 14 * - keyboard messages 16 15 */ 17 16 … … 19 18 #include "commctrl.h" 20 19 #include "hotkey.h" 21 22 23 #define HOTKEY_GetInfoPtr(hwnd) ((HOTKEY_INFO *)GetWindowLongA (hwnd, 0)) 24 25 26 /* << HOTHEY_GetHotKey >> */ 27 /* << HOTHEY_SetHotKey >> */ 28 /* << HOTHEY_SetRules >> */ 29 30 31 32 /* << HOTKEY_Char >> */ 20 #include <string.h> 21 22 #define HOTKEY_GetInfoPtr(hwnd) ((HOTKEY_INFO*)GetWindowLongA(hwnd,0)) 23 24 static VOID 25 HOTKEY_UpdateHotKey(HWND hwnd); 26 27 static BYTE 28 HOTKEY_Check(HOTKEY_INFO *infoPtr,BYTE bfMods) 29 { 30 if ((infoPtr->fwCombInv & HKCOMB_A && bfMods == HOTKEYF_ALT) || 31 (infoPtr->fwCombInv & HKCOMB_C && bfMods == HOTKEYF_CONTROL) || 32 (infoPtr->fwCombInv & HKCOMB_CA && bfMods == HOTKEYF_CONTROL | HOTKEYF_ALT) || 33 (infoPtr->fwCombInv & HKCOMB_NONE && bfMods == 0) || 34 (infoPtr->fwCombInv & HKCOMB_S && bfMods == HOTKEYF_SHIFT) || 35 (infoPtr->fwCombInv & HKCOMB_SA && bfMods == HOTKEYF_SHIFT | HOTKEYF_ALT) || 36 (infoPtr->fwCombInv & HKCOMB_SC && bfMods == HOTKEYF_SHIFT | HOTKEYF_CONTROL) || 37 (infoPtr->fwCombInv & HKCOMB_SCA && bfMods == HOTKEYF_SHIFT | HOTKEYF_CONTROL | HOTKEYF_ALT)) 38 return infoPtr->fwModInv; 39 else 40 return bfMods; 41 } 42 43 44 static LRESULT 45 HOTKEY_SetHotKey(HWND hwnd,WPARAM wParam,LPARAM lParam) 46 { 47 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(hwnd); 48 49 infoPtr->bVKHotKey = wParam & 0xFF; 50 infoPtr->bfMods = HOTKEY_Check(infoPtr,wParam & 0xFF00); 51 52 HOTKEY_UpdateHotKey(hwnd); 53 54 return 0; 55 } 56 57 58 static LRESULT 59 HOTKEY_GetHotKey(HWND hwnd,WPARAM wParam,LPARAM lParam) 60 { 61 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(hwnd); 62 63 return MAKEWORD(infoPtr->bVKHotKey,infoPtr->bfMods); 64 } 65 66 67 static LRESULT 68 HOTKEY_SetRules(HWND hwnd,WPARAM wParam,LPARAM lParam) 69 { 70 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(hwnd); 71 BYTE oldMods = infoPtr->bfMods; 72 73 infoPtr->fwCombInv = wParam; 74 infoPtr->fwModInv = lParam; 75 76 infoPtr->bfMods = HOTKEY_Check(infoPtr,infoPtr->bfMods); 77 if (infoPtr->bfMods != oldMods) HOTKEY_UpdateHotKey(hwnd); 78 79 return 0; 80 } 81 82 83 static LRESULT 84 HOTKEY_Char(HWND hwnd,WPARAM wParam,LPARAM lParam) 85 { 86 //CB: 87 return 0; 88 } 89 90 91 static LRESULT 92 HOTKEY_SysChar(HWND hwnd,WPARAM wParam,LPARAM lParam) 93 { 94 //CB: 95 return 0; 96 } 33 97 34 98 … … 42 106 /* allocate memory for info structure */ 43 107 infoPtr = (HOTKEY_INFO *)COMCTL32_Alloc (sizeof(HOTKEY_INFO)); 44 SetWindowLongA (hwnd, 0,(DWORD)infoPtr);108 SetWindowLongA(hwnd,0,(DWORD)infoPtr); 45 109 46 110 /* initialize info structure */ 47 111 112 infoPtr->hFont = 0; 113 infoPtr->bFocus = FALSE; 114 infoPtr->bVKHotKey = 0; 115 infoPtr->bfMods = 0; 116 infoPtr->fwCombInv = 0; 117 infoPtr->fwModInv = 0; 48 118 49 119 /* get default font height */ … … 62 132 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); 63 133 64 65 66 134 /* free hotkey info data */ 67 135 COMCTL32_Free (infoPtr); … … 74 142 HOTKEY_EraseBackground (HWND hwnd, WPARAM wParam, LPARAM lParam) 75 143 { 76 /* HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr (hwnd); */77 144 HBRUSH hBrush; 78 145 RECT rc; 79 146 80 hBrush = 81 (HBRUSH)SendMessageA (GetParent (hwnd), WM_CTLCOLOREDIT, 82 wParam, (LPARAM)hwnd); 83 if (hBrush) 84 hBrush = (HBRUSH)GetStockObject (WHITE_BRUSH); 85 GetClientRect (hwnd, &rc); 86 87 FillRect ((HDC)wParam, &rc, hBrush); 147 hBrush = (HBRUSH)SendMessageA(GetParent(hwnd),WM_CTLCOLOREDIT,wParam,(LPARAM)hwnd); 148 if (!hBrush) hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH); 149 GetClientRect(hwnd,&rc); 150 FillRect((HDC)wParam,&rc,hBrush); 88 151 89 152 return -1; … … 172 235 173 236 174 175 237 static VOID 238 HOTKEY_Draw(HWND hwnd,HDC hdc) 239 { 240 HOTKEY_INFO *infoPtr = HOTKEY_GetInfoPtr(hwnd); 241 RECT rect; 242 char text[50]; 243 HFONT oldFont; 244 245 GetClientRect(hwnd,&rect); 246 DrawEdge(hdc,&rect,EDGE_SUNKEN,BF_RECT | BF_ADJUST); 247 248 //draw string 249 text[0] = 0; 250 if (infoPtr->bfMods & HOTKEYF_ALT) strcat(text,"ALT"); 251 if (infoPtr->bfMods & HOTKEYF_CONTROL) 252 { 253 if (text[0]) strcat(text,"+"); 254 strcat(text,"CONTROL"); 255 } 256 if (infoPtr->bfMods & HOTKEYF_SHIFT) 257 { 258 if (text[0]) strcat(text,"+"); 259 strcat(text,"SHIFT"); 260 } 261 262 if (infoPtr->bVKHotKey) 263 { 264 char char2[2]; 265 266 if (text[0]) strcat(text,"+"); 267 char2[0] = (char)infoPtr->bVKHotKey; 268 char2[1] = 0; 269 strcat(text,char2); 270 } 271 if(infoPtr->hFont) oldFont = SelectObject(hdc,infoPtr->hFont); 272 SetBkMode(hdc,TRANSPARENT); 273 DrawTextA(hdc,text,strlen(text),&rect,DT_LEFT | DT_BOTTOM | DT_SINGLELINE); 274 if (infoPtr->hFont) SelectObject(hdc,oldFont); 275 } 276 277 278 static LRESULT 279 HOTKEY_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam) 280 { 281 PAINTSTRUCT ps; 282 HDC hdc; 283 284 if (wParam == 0) hdc = BeginPaint(hwnd,&ps); 285 else hdc = wParam; 286 287 HOTKEY_Draw(hwnd,hdc); 288 289 if (wParam == 0) EndPaint(hwnd,&ps); 290 291 return 0; 292 } 293 294 295 static VOID 296 HOTKEY_UpdateHotKey(HWND hwnd) 297 { 298 HDC hdc; 299 RECT rect; 300 HBRUSH hBrush; 301 302 GetClientRect(hwnd,&rect); 303 InflateRect(&rect,2,2); 304 hdc = GetDC(hwnd); 305 hBrush = (HBRUSH)SendMessageA(GetParent(hwnd),WM_CTLCOLOREDIT,hdc,(LPARAM)hwnd); 306 if (!hBrush) hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH); 307 FillRect(hdc,&rect,hBrush); 308 HOTKEY_Draw(hwnd,hdc); 309 ReleaseDC(hwnd,hdc); 310 } 176 311 177 312 static LRESULT … … 182 317 infoPtr->bFocus = TRUE; 183 318 184 185 319 CreateCaret (hwnd, (HBITMAP)0, 1, infoPtr->nHeight); 186 187 SetCaretPos (1, 1); 188 320 SetCaretPos (3,3); 189 321 ShowCaret (hwnd); 190 191 322 192 323 return 0; … … 215 346 ReleaseDC (hwnd, hdc); 216 347 217 if (LOWORD(lParam)) { 218 219 // FIXME (hotkey, "force redraw!\n"); 220 221 } 348 if (LOWORD(lParam)) HOTKEY_UpdateHotKey(hwnd); 222 349 223 350 return 0; … … 271 398 switch (uMsg) 272 399 { 273 /* case HKM_GETHOTKEY: */ 274 /* case HKM_SETHOTKEY: */ 275 /* case HKM_SETRULES: */ 276 277 /* case WM_CHAR: */ 400 case HKM_GETHOTKEY: 401 return HOTKEY_GetHotKey(hwnd,wParam,lParam); 402 403 case HKM_SETHOTKEY: 404 return HOTKEY_SetHotKey(hwnd,wParam,lParam); 405 406 case HKM_SETRULES: 407 return HOTKEY_SetRules(hwnd,wParam,lParam); 408 409 case WM_CHAR: 410 return HOTKEY_Char(hwnd,wParam,lParam); 278 411 279 412 case WM_CREATE: … … 293 426 294 427 case WM_KEYDOWN: 428 return HOTKEY_KeyDown(hwnd,wParam,lParam); 429 295 430 case WM_SYSKEYDOWN: 296 return HOTKEY_ KeyDown (hwnd, wParam, lParam);431 return HOTKEY_SysKeyDown (hwnd, wParam, lParam); 297 432 298 433 case WM_KEYUP: 434 return HOTKEY_KeyUp(hwnd,wParam,lParam); 435 299 436 case WM_SYSKEYUP: 300 return HOTKEY_ KeyUp (hwnd, wParam, lParam);437 return HOTKEY_SysKeyUp (hwnd, wParam, lParam); 301 438 302 439 case WM_KILLFOCUS: … … 309 446 return HOTKEY_NCCreate (hwnd, wParam, lParam); 310 447 311 /* case WM_PAINT: */ 448 case WM_PAINT: 449 return HOTKEY_Paint(hwnd,wParam,lParam); 312 450 313 451 case WM_SETFOCUS: … … 317 455 return HOTKEY_SetFont (hwnd, wParam, lParam); 318 456 319 /* case WM_SYSCHAR: */ 457 case WM_SYSCHAR: 458 return HOTKEY_SysChar(hwnd,wParam,lParam); 320 459 321 460 default:
Note:
See TracChangeset
for help on using the changeset viewer.