comparison win/dw.c @ 1763:d894f87387b2

Switch to using a single tooltip window to prevent leaking tooltip handles on Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 27 Jun 2012 22:14:28 +0000
parents b472a892ce1f
children 15414cbe857f
comparison
equal deleted inserted replaced
1762:b472a892ce1f 1763:d894f87387b2
244 #endif 244 #endif
245 #if !defined(LVS_EX_DOUBLEBUFFER) 245 #if !defined(LVS_EX_DOUBLEBUFFER)
246 # define LVS_EX_DOUBLEBUFFER 0x10000 246 # define LVS_EX_DOUBLEBUFFER 0x10000
247 #endif 247 #endif
248 248
249 HWND popup = (HWND)NULL, DW_HWND_OBJECT = (HWND)NULL; 249 HWND popup = (HWND)NULL, DW_HWND_OBJECT = (HWND)NULL, hwndTooltip = (HWND)0;
250 250
251 HINSTANCE DWInstance = NULL; 251 HINSTANCE DWInstance = NULL;
252 252
253 DWORD dwVersion = 0, dwComctlVer = 0; 253 DWORD dwVersion = 0, dwComctlVer = 0;
254 DWTID _dwtid = -1; 254 DWTID _dwtid = -1;
726 { 726 {
727 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 727 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
728 HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); 728 HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0);
729 HICON oldicon = (HICON)SendMessage(handle, WM_GETICON, 0, 0); 729 HICON oldicon = (HICON)SendMessage(handle, WM_GETICON, 0, 0);
730 TCHAR tmpbuf[100] = {0}; 730 TCHAR tmpbuf[100] = {0};
731 HWND tooltip = (HWND)dw_window_get_data(handle, "_dw_tooltip");
732 731
733 if(tooltip) 732 TOOLINFO ti = { 0 };
734 DestroyWindow(tooltip); 733
734 ti.cbSize = sizeof(TOOLINFO);
735 ti.hwnd = handle;
736 ti.hinst = DWInstance;
737
738 SendMessage(hwndTooltip, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
735 739
736 GetClassName(handle, tmpbuf, 99); 740 GetClassName(handle, tmpbuf, 99);
737 741
738 /* Don't try to free memory from an OLE embedded IE */ 742 /* Don't try to free memory from an OLE embedded IE */
739 if(_tcsncmp(tmpbuf, TEXT("Internet Explorer_Server"), 25) == 0) 743 if(_tcsncmp(tmpbuf, TEXT("Internet Explorer_Server"), 25) == 0)
3754 } 3758 }
3755 } 3759 }
3756 3760
3757 void _create_tooltip(HWND handle, char *text) 3761 void _create_tooltip(HWND handle, char *text)
3758 { 3762 {
3759 HWND hwndTT = 0; 3763 TOOLINFO ti = { 0 };
3760 HWND oldTT = (HWND)dw_window_get_data(handle, "_dw_tooltip");
3761 3764
3762 if(oldTT) 3765 ti.cbSize = sizeof(TOOLINFO);
3763 DestroyWindow(oldTT); 3766 ti.hwnd = handle;
3767 ti.hinst = DWInstance;
3768
3769 SendMessage(hwndTooltip, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
3764 if(text) 3770 if(text)
3765 { 3771 {
3766 TOOLINFO ti = { 0 };
3767
3768 /* Create a tooltip. */
3769 hwndTT = CreateWindowEx(WS_EX_TOPMOST,
3770 TOOLTIPS_CLASS, NULL,
3771 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
3772 CW_USEDEFAULT, CW_USEDEFAULT,
3773 CW_USEDEFAULT, CW_USEDEFAULT,
3774 handle, NULL, DWInstance,NULL);
3775
3776 SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
3777
3778 /* Set up "tool" information. 3772 /* Set up "tool" information.
3779 * In this case, the "tool" is the entire parent window. 3773 * In this case, the "tool" is the entire parent window.
3780 */ 3774 */
3781 ti.cbSize = sizeof(TOOLINFO);
3782 ti.uFlags = TTF_SUBCLASS; 3775 ti.uFlags = TTF_SUBCLASS;
3783 ti.hwnd = handle;
3784 ti.hinst = DWInstance;
3785 ti.lpszText = UTF8toWide(text); 3776 ti.lpszText = UTF8toWide(text);
3786 ti.rect.right = ti.rect.bottom = 2000; 3777 ti.rect.right = ti.rect.bottom = 2000;
3787 3778
3788 /* Associate the tooltip with the "tool" window. */ 3779 /* Associate the tooltip with the "tool" window. */
3789 SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); 3780 SendMessage(hwndTooltip, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
3790 } 3781 }
3791 dw_window_set_data(handle, "_dw_tooltip", (void *)hwndTT);
3792 } 3782 }
3793 3783
3794 #ifndef GDIPLUS 3784 #ifndef GDIPLUS
3795 /* This function determines the handle for a supplied image filename 3785 /* This function determines the handle for a supplied image filename
3796 */ 3786 */
4026 * temporary window that isn't visible and really does nothing 4016 * temporary window that isn't visible and really does nothing
4027 * except temporarily hold the child windows before they are 4017 * except temporarily hold the child windows before they are
4028 * packed into their correct parent. 4018 * packed into their correct parent.
4029 */ 4019 */
4030 4020
4031 DW_HWND_OBJECT = CreateWindow(ObjectClassName, NULL, 0, 0, 0, 4021 DW_HWND_OBJECT = CreateWindow(ObjectClassName, TEXT("HWND_OBJECT"), 0, 0, 0,
4032 0, 0, HWND_DESKTOP, NULL, DWInstance, NULL); 4022 0, 0, HWND_DESKTOP, NULL, DWInstance, NULL);
4033 4023
4034 if(!DW_HWND_OBJECT) 4024 if(!DW_HWND_OBJECT)
4035 { 4025 {
4036 dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError()); 4026 dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError());
4037 exit(1); 4027 exit(1);
4038 } 4028 }
4039 4029
4030 /* Create a tooltip. */
4031 hwndTooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
4032 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, DW_HWND_OBJECT, NULL, DWInstance,NULL);
4033
4034 SetWindowPos(hwndTooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
4035
4040 /* Create empty box data */ 4036 /* Create empty box data */
4041 SetWindowLongPtr(DW_HWND_OBJECT, GWLP_USERDATA, (LONG_PTR)calloc(sizeof(Box), 1)); 4037 SetWindowLongPtr(DW_HWND_OBJECT, GWLP_USERDATA, (LONG_PTR)calloc(sizeof(Box), 1));
4042 4038
4043 /* We need the version to check capability like up-down controls */ 4039 /* We need the version to check capability like up-down controls */
4044 dwVersion = GetVersion(); 4040 dwVersion = GetVersion();
11373 #ifdef AEROGLASS 11369 #ifdef AEROGLASS
11374 /* Free any in use libraries */ 11370 /* Free any in use libraries */
11375 FreeLibrary(hdwm); 11371 FreeLibrary(hdwm);
11376 #endif 11372 #endif
11377 FreeLibrary(huxtheme); 11373 FreeLibrary(huxtheme);
11374 DestroyWindow(hwndTooltip);
11378 exit(exitcode); 11375 exit(exitcode);
11379 } 11376 }
11380 11377
11381 /* 11378 /*
11382 * Creates a splitbar window (widget) with given parameters. 11379 * Creates a splitbar window (widget) with given parameters.