Mercurial > dwindows
comparison win/dw.c @ 759:6d880e68e8d4
Removed the custom tooltip creator I ported from OS/2 and switched to using native Win32 tooltips.
This fixes some issues I was having with the old tooltips with the new common controls.
It also allows the tooltips to use the current Windows theme.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 17 Mar 2011 20:56:43 +0000 |
parents | d26bfc4cd1f0 |
children | acbc44e6e11a |
comparison
equal
deleted
inserted
replaced
758:842bc671eaa7 | 759:6d880e68e8d4 |
---|---|
28 | 28 |
29 #if !defined( MIM_MENUDATA ) | 29 #if !defined( MIM_MENUDATA ) |
30 # define MIM_MENUDATA 0x00000008 | 30 # define MIM_MENUDATA 0x00000008 |
31 #endif | 31 #endif |
32 | 32 |
33 HWND popup = (HWND)NULL, hwndBubble = (HWND)NULL, DW_HWND_OBJECT = (HWND)NULL; | 33 HWND popup = (HWND)NULL, DW_HWND_OBJECT = (HWND)NULL; |
34 | 34 |
35 HINSTANCE DWInstance = NULL; | 35 HINSTANCE DWInstance = NULL; |
36 | 36 |
37 DWORD dwVersion = 0, dwComctlVer = 0; | 37 DWORD dwVersion = 0, dwComctlVer = 0; |
38 DWTID _dwtid = -1; | 38 DWTID _dwtid = -1; |
3259 */ | 3259 */ |
3260 | 3260 |
3261 BOOL CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) | 3261 BOOL CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) |
3262 { | 3262 { |
3263 BubbleButton *bubble; | 3263 BubbleButton *bubble; |
3264 static int bMouseOver = 0; | |
3265 static BubbleButton *this_bubble = NULL; | |
3266 POINT point; | 3264 POINT point; |
3267 RECT rect; | 3265 RECT rect; |
3268 WNDPROC pOldProc; | 3266 WNDPROC pOldProc; |
3269 | 3267 |
3270 bubble = (BubbleButton *)GetWindowLongPtr(hwnd, GWLP_USERDATA); | 3268 bubble = (BubbleButton *)GetWindowLongPtr(hwnd, GWLP_USERDATA); |
3271 if ( bubble != this_bubble ) | |
3272 { | |
3273 /* | |
3274 * If we missed the release capture, then if the bubble details | |
3275 * from this window are different from the last we must be in a | |
3276 * different button, so delete the last bubble text | |
3277 */ | |
3278 bMouseOver = 0; | |
3279 this_bubble = bubble; | |
3280 if ( hwndBubble ) | |
3281 { | |
3282 _free_window_memory(hwndBubble, 0); | |
3283 DestroyWindow(hwndBubble); | |
3284 hwndBubble = 0; | |
3285 } | |
3286 } | |
3287 | 3269 |
3288 if ( !bubble ) | 3270 if ( !bubble ) |
3289 return DefWindowProc(hwnd, msg, mp1, mp2); | 3271 return DefWindowProc(hwnd, msg, mp1, mp2); |
3290 | 3272 |
3291 /* We must save a pointer to the old | 3273 /* We must save a pointer to the old |
3310 _wndproc(hwnd, msg, mp1, mp2); | 3292 _wndproc(hwnd, msg, mp1, mp2); |
3311 break; | 3293 break; |
3312 case WM_LBUTTONUP: | 3294 case WM_LBUTTONUP: |
3313 { | 3295 { |
3314 SignalHandler *tmp = Root; | 3296 SignalHandler *tmp = Root; |
3315 /* | |
3316 * If we have bubbletext displaying when we | |
3317 * release the mouse, get rid of the bubbletext window | |
3318 */ | |
3319 if ( hwndBubble ) | |
3320 { | |
3321 _free_window_memory(hwndBubble, 0); | |
3322 DestroyWindow(hwndBubble); | |
3323 hwndBubble = 0; | |
3324 } | |
3325 | 3297 |
3326 /* Find any callbacks for this function */ | 3298 /* Find any callbacks for this function */ |
3327 while(tmp) | 3299 while(tmp) |
3328 { | 3300 { |
3329 if(tmp->message == WM_COMMAND) | 3301 if(tmp->message == WM_COMMAND) |
3389 if(mp1 == VK_LEFT || mp1 == VK_UP) | 3361 if(mp1 == VK_LEFT || mp1 == VK_UP) |
3390 _shift_focus_back(hwnd); | 3362 _shift_focus_back(hwnd); |
3391 if(mp1 == VK_RIGHT || mp1 == VK_DOWN) | 3363 if(mp1 == VK_RIGHT || mp1 == VK_DOWN) |
3392 _shift_focus(hwnd); | 3364 _shift_focus(hwnd); |
3393 break; | 3365 break; |
3394 case WM_MOUSEMOVE: | |
3395 GetCursorPos(&point); | |
3396 GetWindowRect(hwnd, &rect); | |
3397 | |
3398 if ( PtInRect(&rect, point) ) | |
3399 { | |
3400 if ( hwnd != GetCapture() ) | |
3401 { | |
3402 SetCapture(hwnd); | |
3403 } | |
3404 if ( !bMouseOver ) | |
3405 { | |
3406 bMouseOver = 1; | |
3407 if(!*bubble->bubbletext) | |
3408 break; | |
3409 | |
3410 if(hwndBubble) | |
3411 { | |
3412 _free_window_memory(hwndBubble, 0); | |
3413 DestroyWindow(hwndBubble); | |
3414 hwndBubble = 0; | |
3415 } | |
3416 | |
3417 if(!hwndBubble) | |
3418 { | |
3419 POINTL ptlWork = {0,0}; | |
3420 SIZE size; | |
3421 HFONT hFont, oldFont = (HFONT)0; | |
3422 HDC hdc; | |
3423 RECT rect; | |
3424 | |
3425 /* Use the WS_EX_TOOLWINDOW extended style | |
3426 * so the window doesn't get listed in the | |
3427 * taskbar. | |
3428 */ | |
3429 hwndBubble = CreateWindowEx(WS_EX_TOOLWINDOW, | |
3430 STATICCLASSNAME, | |
3431 bubble->bubbletext, | |
3432 BS_TEXT | WS_POPUP | | |
3433 WS_BORDER | | |
3434 SS_CENTER, | |
3435 0,0,50,20, | |
3436 HWND_DESKTOP, | |
3437 NULL, | |
3438 DWInstance, | |
3439 NULL); | |
3440 | |
3441 dw_window_set_font(hwndBubble, DefaultFont); | |
3442 dw_window_set_color(hwndBubble, DW_CLR_BLACK, DW_CLR_YELLOW); | |
3443 | |
3444 hFont = (HFONT)SendMessage(hwndBubble, WM_GETFONT, 0, 0); | |
3445 | |
3446 hdc = GetDC(hwndBubble); | |
3447 | |
3448 if(hFont) | |
3449 oldFont = (HFONT)SelectObject(hdc, hFont); | |
3450 | |
3451 GetTextExtentPoint32(hdc, bubble->bubbletext, strlen(bubble->bubbletext), &size); | |
3452 | |
3453 if(hFont) | |
3454 SelectObject(hdc, oldFont); | |
3455 | |
3456 MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)&ptlWork, 1); | |
3457 | |
3458 GetWindowRect(hwnd, &rect); | |
3459 | |
3460 SetWindowPos(hwndBubble, | |
3461 HWND_TOP, | |
3462 ptlWork.x, | |
3463 ptlWork.y + (rect.bottom-rect.top) + 1, | |
3464 size.cx + 8, | |
3465 size.cy + 2, | |
3466 SWP_NOACTIVATE | SWP_SHOWWINDOW); | |
3467 | |
3468 ReleaseDC(hwndBubble, hdc); | |
3469 } | |
3470 } | |
3471 } | |
3472 else{ | |
3473 /* Calling ReleaseCapture in Win95 also causes WM_CAPTURECHANGED | |
3474 * to be sent. Be sure to account for that. | |
3475 */ | |
3476 ReleaseCapture(); | |
3477 | |
3478 if(bMouseOver && hwndBubble) | |
3479 { | |
3480 bMouseOver = 0; | |
3481 _free_window_memory(hwndBubble, 0); | |
3482 DestroyWindow(hwndBubble); | |
3483 hwndBubble = 0; | |
3484 } | |
3485 } | |
3486 _wndproc(hwnd, msg, mp1, mp2); | |
3487 break; | |
3488 case WM_CAPTURECHANGED: | |
3489 /* This message means we are losing the capture for some reason | |
3490 * Either because we intentionally lost it or another window | |
3491 * stole it | |
3492 */ | |
3493 if ( bMouseOver && hwndBubble ) | |
3494 { | |
3495 bMouseOver = 0; | |
3496 _free_window_memory(hwndBubble, 0); | |
3497 DestroyWindow(hwndBubble); | |
3498 hwndBubble = 0; | |
3499 } | |
3500 break; | |
3501 } | 3366 } |
3502 | 3367 |
3503 if ( !pOldProc ) | 3368 if ( !pOldProc ) |
3504 return DefWindowProc(hwnd, msg, mp1, mp2); | 3369 return DefWindowProc(hwnd, msg, mp1, mp2); |
3505 return CallWindowProc(pOldProc, hwnd, msg, mp1, mp2); | 3370 return CallWindowProc(pOldProc, hwnd, msg, mp1, mp2); |
3529 } | 3394 } |
3530 | 3395 |
3531 ShowWindow(array[pageid]->hwnd, SW_SHOWNORMAL); | 3396 ShowWindow(array[pageid]->hwnd, SW_SHOWNORMAL); |
3532 } | 3397 } |
3533 } | 3398 } |
3399 | |
3400 void _create_tooltip(HWND handle, char *text) | |
3401 { | |
3402 /* Create a tooltip. */ | |
3403 HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, | |
3404 TOOLTIPS_CLASS, NULL, | |
3405 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, | |
3406 CW_USEDEFAULT, CW_USEDEFAULT, | |
3407 CW_USEDEFAULT, CW_USEDEFAULT, | |
3408 handle, NULL, DWInstance,NULL); | |
3409 TOOLINFO ti = { 0 }; | |
3410 | |
3411 SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | |
3412 | |
3413 /* Set up "tool" information. | |
3414 * In this case, the "tool" is the entire parent window. | |
3415 */ | |
3416 ti.cbSize = sizeof(TOOLINFO); | |
3417 ti.uFlags = TTF_SUBCLASS; | |
3418 ti.hwnd = handle; | |
3419 ti.hinst = DWInstance; | |
3420 ti.lpszText = text; | |
3421 GetClientRect(handle, &ti.rect); | |
3422 | |
3423 /* Associate the tooltip with the "tool" window. */ | |
3424 SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); | |
3425 } | |
3426 | |
3534 | 3427 |
3535 /* This function determines the handle for a supplied image filename | 3428 /* This function determines the handle for a supplied image filename |
3536 */ | 3429 */ |
3537 int _dw_get_image_handle(char *filename, HANDLE *icon, HBITMAP *hbitmap) | 3430 int _dw_get_image_handle(char *filename, HANDLE *icon, HBITMAP *hbitmap) |
3538 { | 3431 { |
5200 | 5093 |
5201 bubble->id = id; | 5094 bubble->id = id; |
5202 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); | 5095 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); |
5203 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; | 5096 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; |
5204 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | 5097 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
5205 | 5098 |
5206 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); | 5099 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); |
5100 | |
5101 _create_tooltip(tmp, text); | |
5207 | 5102 |
5208 if(icon) | 5103 if(icon) |
5209 { | 5104 { |
5210 SendMessage(tmp, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) icon); | 5105 SendMessage(tmp, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) icon); |
5211 } | 5106 } |
5251 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); | 5146 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); |
5252 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; | 5147 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; |
5253 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | 5148 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
5254 | 5149 |
5255 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); | 5150 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); |
5151 | |
5152 _create_tooltip(tmp, text); | |
5256 | 5153 |
5257 if (icon) | 5154 if (icon) |
5258 { | 5155 { |
5259 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_ICON,(LPARAM) icon); | 5156 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_ICON,(LPARAM) icon); |
5260 } | 5157 } |
5328 strncpy( bubble->bubbletext, text, BUBBLE_HELP_MAX - 1 ); | 5225 strncpy( bubble->bubbletext, text, BUBBLE_HELP_MAX - 1 ); |
5329 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; | 5226 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; |
5330 bubble->pOldProc = (WNDPROC)SubclassWindow( tmp, _BtProc ); | 5227 bubble->pOldProc = (WNDPROC)SubclassWindow( tmp, _BtProc ); |
5331 | 5228 |
5332 SetWindowLongPtr( tmp, GWLP_USERDATA, (LONG_PTR)bubble ); | 5229 SetWindowLongPtr( tmp, GWLP_USERDATA, (LONG_PTR)bubble ); |
5230 | |
5231 _create_tooltip(tmp, text); | |
5333 | 5232 |
5334 if ( icon ) | 5233 if ( icon ) |
5335 { | 5234 { |
5336 SendMessage( tmp, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) icon); | 5235 SendMessage( tmp, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) icon); |
5337 } | 5236 } |