comparison win/dw.c @ 2135:d9720d48d61e

Win: Code cleanup, create internal helper functions _dw_window_get_cinfo() and _dw_window_new_cinfo() to simply code dealing with ColorInfo structs. Remove the vcenter and unused user fields replacing them with style and rect. Style will cache the requested style for a window instead of the active style, which may differ based on the state of the system. So now we can just check the style to see if VCENTER is set.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 08 Jul 2020 22:24:33 +0000
parents 9e6e4ebd5e96
children bbd81ee0ca9a
comparison
equal deleted inserted replaced
2134:9e6e4ebd5e96 2135:d9720d48d61e
1006 return SignalTranslate[z].message; 1006 return SignalTranslate[z].message;
1007 } 1007 }
1008 return 0L; 1008 return 0L;
1009 } 1009 }
1010 1010
1011 /* Internal function to get the ColorInfo struct from a widget/window */
1012 ColorInfo *_dw_window_get_cinfo(HWND handle)
1013 {
1014 return (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
1015 }
1016
1017 /* Internal function to add ColorInfo and subclass a widget/window */
1018 ColorInfo *_dw_window_new_cinfo(HWND handle, BOOL subclass)
1019 {
1020 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
1021
1022 if(cinfo)
1023 {
1024 cinfo->back = cinfo->fore = -1;
1025 if(subclass)
1026 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc);
1027 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo);
1028 }
1029 return cinfo;
1030 }
1031
1011 /* This function removes any handlers on windows and frees 1032 /* This function removes any handlers on windows and frees
1012 * the user memory and resources allocated to it. 1033 * the user memory and resources allocated to it.
1013 */ 1034 */
1014 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam) 1035 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam)
1015 { 1036 {
1016 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 1037 ColorInfo *thiscinfo = _dw_window_get_cinfo(handle);
1017 HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); 1038 HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0);
1018 HICON oldicon = (HICON)SendMessage(handle, WM_GETICON, 0, 0); 1039 HICON oldicon = (HICON)SendMessage(handle, WM_GETICON, 0, 0);
1019 TCHAR tmpbuf[100] = {0}; 1040 TCHAR tmpbuf[100] = {0};
1020 1041
1021 TOOLINFO ti = { 0 }; 1042 TOOLINFO ti = { 0 };
1112 } 1133 }
1113 } 1134 }
1114 else if(_tcsnicmp(tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1)==0) 1135 else if(_tcsnicmp(tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1)==0)
1115 { 1136 {
1116 /* for spinbuttons, we need to get the spinbutton's "buddy", the text window associated and destroy it */ 1137 /* for spinbuttons, we need to get the spinbutton's "buddy", the text window associated and destroy it */
1117 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 1138 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
1118 1139
1119 if(cinfo && cinfo->buddy) 1140 if(cinfo && cinfo->buddy)
1120 DestroyWindow( cinfo->buddy ); 1141 DestroyWindow(cinfo->buddy);
1121 } 1142 }
1122 /* Some Edge Windows have an empty class.. abort. */ 1143 /* Some Edge Windows have an empty class.. abort. */
1123 else if(_tcslen(tmpbuf) == 0) 1144 else if(_tcslen(tmpbuf) == 0)
1124 return TRUE; 1145 return TRUE;
1125 1146
1231 TCHAR tmpbuf[100] = {0}; 1252 TCHAR tmpbuf[100] = {0};
1232 1253
1233 GetClassName(handle, tmpbuf, 99); 1254 GetClassName(handle, tmpbuf, 99);
1234 if(_tcsnicmp(tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS))==0) /* Spinner */ 1255 if(_tcsnicmp(tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS))==0) /* Spinner */
1235 { 1256 {
1236 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 1257 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
1237 1258
1238 if(cinfo && cinfo->buddy) 1259 if(cinfo && cinfo->buddy)
1239 return cinfo->buddy; 1260 return cinfo->buddy;
1240 } 1261 }
1241 if(_tcsnicmp(tmpbuf, COMBOBOXCLASSNAME, _tcslen(COMBOBOXCLASSNAME))==0) /* Combobox */ 1262 if(_tcsnicmp(tmpbuf, COMBOBOXCLASSNAME, _tcslen(COMBOBOXCLASSNAME))==0) /* Combobox */
1242 { 1263 {
1243 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 1264 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
1244 1265
1245 if(cinfo && cinfo->buddy) 1266 if(cinfo && cinfo->buddy)
1246 return cinfo->buddy; 1267 return cinfo->buddy;
1247 } 1268 }
1248 return handle; 1269 return handle;
1393 return 1; 1414 return 1;
1394 } 1415 }
1395 } 1416 }
1396 else if(_tcsnicmp(tmpbuf, ScrollClassName, _tcslen(ScrollClassName))==0) /* Scroll Box */ 1417 else if(_tcsnicmp(tmpbuf, ScrollClassName, _tcslen(ScrollClassName))==0) /* Scroll Box */
1397 { 1418 {
1398 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(box->items[z].hwnd, GWLP_USERDATA); 1419 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
1399 Box *scrollbox = (Box *)GetWindowLongPtr(cinfo->combo, GWLP_USERDATA); 1420 Box *scrollbox = (Box *)GetWindowLongPtr(cinfo->combo, GWLP_USERDATA);
1400 1421
1401 if(scrollbox && _focus_check_box(scrollbox, handle, start == 3 ? 3 : 0, direction, defaultitem)) 1422 if(scrollbox && _focus_check_box(scrollbox, handle, start == 3 ? 3 : 0, direction, defaultitem))
1402 return 1; 1423 return 1;
1403 } 1424 }
1699 } 1720 }
1700 #endif 1721 #endif
1701 else if(_tcsnicmp(tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1)==0) 1722 else if(_tcsnicmp(tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1)==0)
1702 { 1723 {
1703 /* Handle special case Spinbutton */ 1724 /* Handle special case Spinbutton */
1704 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 1725 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
1705 1726
1706 MoveWindow(handle, currentx + pad + (width - 20) + xborder, currenty + pad + yborder, 1727 MoveWindow(handle, currentx + pad + (width - 20) + xborder, currenty + pad + yborder,
1707 20, height, FALSE); 1728 20, height, FALSE);
1708 1729
1709 if(cinfo) 1730 if(cinfo)
1713 } 1734 }
1714 } 1735 }
1715 else if(_tcsncmp(tmpbuf, ScrollClassName, _tcslen(ScrollClassName)+1)==0) 1736 else if(_tcsncmp(tmpbuf, ScrollClassName, _tcslen(ScrollClassName)+1)==0)
1716 { 1737 {
1717 /* Handle special case of scrollbox */ 1738 /* Handle special case of scrollbox */
1718 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 1739 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
1719 int cx, cy, depth = 0; 1740 int cx, cy, depth = 0;
1720 Box *thisbox = (Box *)GetWindowLongPtr(cinfo->combo, GWLP_USERDATA); 1741 Box *thisbox = (Box *)GetWindowLongPtr(cinfo->combo, GWLP_USERDATA);
1721 SCROLLINFO hsi, vsi; 1742 SCROLLINFO hsi, vsi;
1722 RECT rect; 1743 RECT rect;
1723 1744
1789 _handle_splitbar_resize(handle, *percent, type, width, height); 1810 _handle_splitbar_resize(handle, *percent, type, width, height);
1790 } 1811 }
1791 else if(_tcsnicmp(tmpbuf, STATICCLASSNAME, _tcslen(STATICCLASSNAME)+1)==0) 1812 else if(_tcsnicmp(tmpbuf, STATICCLASSNAME, _tcslen(STATICCLASSNAME)+1)==0)
1792 { 1813 {
1793 /* Handle special case Vertically Center static text */ 1814 /* Handle special case Vertically Center static text */
1794 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 1815 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
1795 1816
1796 if(cinfo && cinfo->vcenter) 1817 if(cinfo && cinfo->style & DW_DT_VCENTER)
1797 { 1818 {
1798 /* We are centered so calculate a new position */ 1819 /* We are centered so calculate a new position */
1799 TCHAR tmpbuf[1024] = {0}, *thisbuf = tmpbuf; 1820 TCHAR tmpbuf[1024] = {0}, *thisbuf = tmpbuf;
1800 int textheight, diff, total = height; 1821 int textheight, diff, total = height;
1801 1822
1999 * made dark, hide it and add the button to the titlebar instead. 2020 * made dark, hide it and add the button to the titlebar instead.
2000 */ 2021 */
2001 if(msg == WM_NCCALCSIZE && mp2 && _DW_DARK_MODE_ENABLED && _DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC) 2022 if(msg == WM_NCCALCSIZE && mp2 && _DW_DARK_MODE_ENABLED && _DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC)
2002 { 2023 {
2003 MARGINS *margins = dw_window_get_data(hWnd, "_dw_margins"); 2024 MARGINS *margins = dw_window_get_data(hWnd, "_dw_margins");
2004 RECT *border_thickness = dw_window_get_data(hWnd, "_dw_border"); 2025 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd);
2005 2026
2006 if (margins && border_thickness) 2027 if(margins && cinfo)
2007 { 2028 {
2008 NCCALCSIZE_PARAMS* sz = (NCCALCSIZE_PARAMS*)mp2; 2029 NCCALCSIZE_PARAMS* sz = (NCCALCSIZE_PARAMS*)mp2;
2009 2030
2010 sz->rgrc[0].left += border_thickness->left; 2031 sz->rgrc[0].left += cinfo->rect.left;
2011 sz->rgrc[0].right -= border_thickness->right; 2032 sz->rgrc[0].right -= cinfo->rect.right;
2012 sz->rgrc[0].bottom -= border_thickness->bottom; 2033 sz->rgrc[0].bottom -= cinfo->rect.bottom;
2013 2034
2014 if (_DwmExtendFrameIntoClientArea) 2035 if (_DwmExtendFrameIntoClientArea)
2015 _DwmExtendFrameIntoClientArea(hWnd, margins); 2036 _DwmExtendFrameIntoClientArea(hWnd, margins);
2016 SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); 2037 SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
2017 return 0; 2038 return 0;
2028 /* Do default processing, except change the result for caption area */ 2049 /* Do default processing, except change the result for caption area */
2029 lResult = DefWindowProc(hWnd, msg, mp1, mp2); 2050 lResult = DefWindowProc(hWnd, msg, mp1, mp2);
2030 if(lResult == HTCLIENT) 2051 if(lResult == HTCLIENT)
2031 { 2052 {
2032 MARGINS *margins = dw_window_get_data(hWnd, "_dw_margins"); 2053 MARGINS *margins = dw_window_get_data(hWnd, "_dw_margins");
2033 RECT *border_thickness = dw_window_get_data(hWnd, "_dw_border"); 2054 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd);
2034 2055
2035 if (margins && border_thickness) 2056 if(margins && cinfo)
2036 { 2057 {
2037 POINT pt = { LOWORD(mp2), HIWORD(mp2) }; 2058 POINT pt = { LOWORD(mp2), HIWORD(mp2) };
2038 2059
2039 ScreenToClient(hWnd, &pt); 2060 ScreenToClient(hWnd, &pt);
2040 if (pt.y < border_thickness->top) return HTTOP; 2061 if (pt.y < cinfo->rect.top) return HTTOP;
2041 if (pt.y < margins->cyTopHeight) return HTCAPTION; 2062 if (pt.y < margins->cyTopHeight) return HTCAPTION;
2042 } 2063 }
2043 } 2064 }
2044 return lResult; 2065 return lResult;
2045 } 2066 }
2622 lasthwnd = hWnd; 2643 lasthwnd = hWnd;
2623 2644
2624 #ifdef DARK_MODE_TITLEBAR_MENU 2645 #ifdef DARK_MODE_TITLEBAR_MENU
2625 if(_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED) 2646 if(_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED)
2626 { 2647 {
2627 RECT *border_thickness = dw_window_get_data(hWnd, "_dw_border"); 2648 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd);
2628 2649
2629 if(border_thickness) 2650 if(cinfo)
2630 { 2651 {
2631 dw_debug("Modifying resize from original %d, %d, %d, %d\n", x, y, xborder, yborder); 2652 x -= (cinfo->rect.left + cinfo->rect.right);
2632 x -= (border_thickness->left + border_thickness->right); 2653 y -= (cinfo->rect.top + cinfo->rect.bottom);
2633 y -= (border_thickness->top + border_thickness->bottom); 2654 xborder = cinfo->rect.left;
2634 xborder = border_thickness->left; 2655 yborder = cinfo->rect.top;
2635 yborder = border_thickness->top;
2636 dw_debug("To resize %d, %d, %d, %d\n", x, y, xborder, yborder);
2637 } 2656 }
2638 } 2657 }
2639 #endif 2658 #endif
2640 2659
2641 ShowWindow(mybox->items[0].hwnd, SW_HIDE); 2660 ShowWindow(mybox->items[0].hwnd, SW_HIDE);
2821 } 2840 }
2822 break; 2841 break;
2823 #endif 2842 #endif
2824 case WM_PAINT: 2843 case WM_PAINT:
2825 { 2844 {
2826 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); 2845 ColorInfo *thiscinfo = _dw_window_get_cinfo(hWnd);
2827 2846
2828 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) 2847 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1)
2829 { 2848 {
2830 PAINTSTRUCT ps; 2849 PAINTSTRUCT ps;
2831 HDC hdcPaint = BeginPaint(hWnd, &ps); 2850 HDC hdcPaint = BeginPaint(hWnd, &ps);
2932 return rcode; 2951 return rcode;
2933 } 2952 }
2934 2953
2935 LRESULT CALLBACK _spinnerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) 2954 LRESULT CALLBACK _spinnerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2)
2936 { 2955 {
2937 ColorInfo *cinfo; 2956 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd);
2938
2939 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
2940 2957
2941 if(msg == WM_MOUSEMOVE) 2958 if(msg == WM_MOUSEMOVE)
2942 _wndproc(hWnd, msg, mp1, mp2); 2959 _wndproc(hWnd, msg, mp1, mp2);
2943 2960
2944 if(cinfo) 2961 if(cinfo)
3077 } 3094 }
3078 3095
3079 /* Subclass function that will handle setting colors on controls */ 3096 /* Subclass function that will handle setting colors on controls */
3080 LRESULT CALLBACK _colorwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) 3097 LRESULT CALLBACK _colorwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2)
3081 { 3098 {
3082 ColorInfo *cinfo; 3099 ColorInfo *cinfo = _dw_window_get_cinfo(hWnd);
3083 TCHAR tmpbuf[100] = {0}; 3100 TCHAR tmpbuf[100] = {0};
3084 WNDPROC pOldProc = 0; 3101 WNDPROC pOldProc = 0;
3085 LRESULT ret = -1; 3102 LRESULT ret = -1;
3086
3087 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
3088 3103
3089 GetClassName(hWnd, tmpbuf, 99); 3104 GetClassName(hWnd, tmpbuf, 99);
3090 if(_tcsncmp(tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1) == 0) 3105 if(_tcsncmp(tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1) == 0)
3091 cinfo = &(((Box *)cinfo)->cinfo); 3106 cinfo = &(((Box *)cinfo)->cinfo);
3092 3107
3188 /* 3203 /*
3189 * Find the toplevel window for the current window and check if it 3204 * Find the toplevel window for the current window and check if it
3190 * has a default click set 3205 * has a default click set
3191 */ 3206 */
3192 HWND tl = _toplevel_window( hWnd ); 3207 HWND tl = _toplevel_window( hWnd );
3193 ColorInfo *mycinfo = (ColorInfo *)GetWindowLongPtr( tl, GWLP_USERDATA ); 3208 ColorInfo *mycinfo = _dw_window_get_cinfo(tl);
3194 if ( mycinfo && mycinfo->clickdefault ) 3209
3210 if(mycinfo && mycinfo->clickdefault)
3195 { 3211 {
3196 _click_default( mycinfo->clickdefault ); 3212 _click_default(mycinfo->clickdefault);
3197 return (LRESULT)TRUE; 3213 return (LRESULT)TRUE;
3198 } 3214 }
3199 } 3215 }
3200 } 3216 }
3201 3217
3226 case WM_CTLCOLOREDIT: 3242 case WM_CTLCOLOREDIT:
3227 case WM_CTLCOLORMSGBOX: 3243 case WM_CTLCOLORMSGBOX:
3228 case WM_CTLCOLORSCROLLBAR: 3244 case WM_CTLCOLORSCROLLBAR:
3229 case WM_CTLCOLORDLG: 3245 case WM_CTLCOLORDLG:
3230 { 3246 {
3231 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr((HWND)mp2, GWLP_USERDATA); 3247 ColorInfo *thiscinfo = _dw_window_get_cinfo((HWND)mp2);
3232 3248
3233 if(msg == WM_CTLCOLORBTN) 3249 if(msg == WM_CTLCOLORBTN)
3234 { 3250 {
3235 /* Groupbox color info is on the frame window it is attached to */ 3251 /* Groupbox color info is on the frame window it is attached to */
3236 if(GetWindowLongPtr((HWND)mp2, GWL_STYLE) & BS_GROUPBOX) 3252 if(GetWindowLongPtr((HWND)mp2, GWL_STYLE) & BS_GROUPBOX)
3259 SetTextColor((HDC)mp1, _DW_GetSysColor(COLOR_WINDOWTEXT)); 3275 SetTextColor((HDC)mp1, _DW_GetSysColor(COLOR_WINDOWTEXT));
3260 #endif 3276 #endif
3261 /* Handle background */ 3277 /* Handle background */
3262 if(thiscinfo->back == DW_RGB_TRANSPARENT) 3278 if(thiscinfo->back == DW_RGB_TRANSPARENT)
3263 { 3279 {
3264 ColorInfo *parentcinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); 3280 ColorInfo *parentcinfo = _dw_window_get_cinfo(hWnd);
3265 3281
3266 if(parentcinfo && parentcinfo->back != -1) 3282 if(parentcinfo && parentcinfo->back != -1)
3267 thisback = parentcinfo->back; 3283 thisback = parentcinfo->back;
3268 } 3284 }
3269 if(thisback == DW_CLR_DEFAULT) 3285 if(thisback == DW_CLR_DEFAULT)
3326 case WM_CTLCOLORSCROLLBAR: 3342 case WM_CTLCOLORSCROLLBAR:
3327 case WM_CTLCOLORDLG: 3343 case WM_CTLCOLORDLG:
3328 { 3344 {
3329 if(_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED) 3345 if(_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED)
3330 { 3346 {
3331 ColorInfo *parentcinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); 3347 ColorInfo *parentcinfo = _dw_window_get_cinfo(hWnd);
3332 int thisback = thiscinfo ? thiscinfo->back : -1; 3348 int thisback = thiscinfo ? thiscinfo->back : -1;
3333 3349
3334 if(thisback == DW_RGB_TRANSPARENT && parentcinfo) 3350 if(thisback == DW_RGB_TRANSPARENT && parentcinfo)
3335 thisback = parentcinfo->back; 3351 thisback = parentcinfo->back;
3336 3352
3690 switch (msg) 3706 switch (msg)
3691 { 3707 {
3692 case WM_HSCROLL: 3708 case WM_HSCROLL:
3693 case WM_VSCROLL: 3709 case WM_VSCROLL:
3694 { 3710 {
3695 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA); 3711 ColorInfo *cinfo = _dw_window_get_cinfo(hwnd);
3696 SCROLLINFO hsi, vsi, *si = &hsi; 3712 SCROLLINFO hsi, vsi, *si = &hsi;
3697 int bar = SB_HORZ; 3713 int bar = SB_HORZ;
3698 int which = LOWORD(mp1); 3714 int which = LOWORD(mp1);
3699 3715
3700 /* Initialize the scroll info structs */ 3716 /* Initialize the scroll info structs */
3883 HDC hdcPaint; 3899 HDC hdcPaint;
3884 PAINTSTRUCT ps; 3900 PAINTSTRUCT ps;
3885 RECT rc; 3901 RECT rc;
3886 unsigned long cx, cy; 3902 unsigned long cx, cy;
3887 TCHAR tempbuf[1025] = { 0 }; 3903 TCHAR tempbuf[1025] = { 0 };
3888 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA); 3904 ColorInfo *cinfo = _dw_window_get_cinfo(hwnd);
3889 HFONT hfont = _acquire_font(hwnd, cinfo ? cinfo->fontname : NULL); 3905 HFONT hfont = _acquire_font(hwnd, cinfo ? cinfo->fontname : NULL);
3890 HFONT oldfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); 3906 HFONT oldfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
3891 3907
3892 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy); 3908 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy);
3893 GetWindowText(hwnd, tempbuf, 1024); 3909 GetWindowText(hwnd, tempbuf, 1024);
3942 3958
3943 #ifdef AEROGLASS 3959 #ifdef AEROGLASS
3944 /* Window procedure to handle drawing themed text when in composited mode */ 3960 /* Window procedure to handle drawing themed text when in composited mode */
3945 LRESULT CALLBACK _staticwndproc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) 3961 LRESULT CALLBACK _staticwndproc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2)
3946 { 3962 {
3947 ColorInfo *parentcinfo, *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA); 3963 ColorInfo *parentcinfo, *cinfo = _dw_window_get_cinfo(hwnd);
3948 WNDPROC pOldProc; 3964 WNDPROC pOldProc;
3949 3965
3950 if (!cinfo) 3966 if (!cinfo)
3951 return DefWindowProc(hwnd, msg, mp1, mp2); 3967 return DefWindowProc(hwnd, msg, mp1, mp2);
3952 3968
3953 /* Need the parent to do the check completely */ 3969 /* Need the parent to do the check completely */
3954 parentcinfo = (ColorInfo *)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); 3970 parentcinfo = _dw_window_get_cinfo(GetParent(hwnd));
3955 3971
3956 /* If we don't require themed drawing */ 3972 /* If we don't require themed drawing */
3957 if(((cinfo->back != -1 && cinfo->back != DW_RGB_TRANSPARENT) || (parentcinfo && parentcinfo->back != -1)) 3973 if(((cinfo->back != -1 && cinfo->back != DW_RGB_TRANSPARENT) || (parentcinfo && parentcinfo->back != -1))
3958 || !_dw_composition || !(GetWindowLongPtr(_toplevel_window(hwnd), GWL_EXSTYLE) & WS_EX_LAYERED)) 3974 || !_dw_composition || !(GetWindowLongPtr(_toplevel_window(hwnd), GWL_EXSTYLE) & WS_EX_LAYERED))
3959 return _colorwndproc(hwnd, msg, mp1, mp2); 3975 return _colorwndproc(hwnd, msg, mp1, mp2);
4086 * Abstract: Subclass procedure for buttons 4102 * Abstract: Subclass procedure for buttons
4087 */ 4103 */
4088 4104
4089 LRESULT CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2) 4105 LRESULT CALLBACK _BtProc(HWND hwnd, ULONG msg, WPARAM mp1, LPARAM mp2)
4090 { 4106 {
4091 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA); 4107 ColorInfo *cinfo = _dw_window_get_cinfo(hwnd);
4092 WNDPROC pOldProc; 4108 WNDPROC pOldProc;
4093 int retval = -1; 4109 int retval = -1;
4094 4110
4095 if ( !cinfo ) 4111 if ( !cinfo )
4096 return DefWindowProc(hwnd, msg, mp1, mp2); 4112 return DefWindowProc(hwnd, msg, mp1, mp2);
5371 * fontname: Name and size of the font in the form "size.fontname" 5387 * fontname: Name and size of the font in the form "size.fontname"
5372 */ 5388 */
5373 int API dw_window_set_font(HWND handle, const char *fontname) 5389 int API dw_window_set_font(HWND handle, const char *fontname)
5374 { 5390 {
5375 HFONT hfont, oldfont; 5391 HFONT hfont, oldfont;
5376 ColorInfo *cinfo; 5392 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
5377 TCHAR tmpbuf[100] = {0}; 5393 TCHAR tmpbuf[100] = {0};
5378
5379 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
5380 5394
5381 GetClassName(handle, tmpbuf, 99); 5395 GetClassName(handle, tmpbuf, 99);
5382 if ( _tcsnicmp( tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1) == 0 ) 5396 if ( _tcsnicmp( tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1) == 0 )
5383 { 5397 {
5384 /* groupbox */ 5398 /* groupbox */
5393 oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); 5407 oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0);
5394 hfont = _acquire_font(handle, fontname); 5408 hfont = _acquire_font(handle, fontname);
5395 5409
5396 if(hfont && fontname) 5410 if(hfont && fontname)
5397 { 5411 {
5398 if(cinfo) 5412 if(cinfo || (cinfo = _dw_window_new_cinfo(handle, TRUE)))
5399 { 5413 {
5400 strcpy(cinfo->fontname, fontname); 5414 strncpy(cinfo->fontname, fontname, 127);
5401 if(!oldfont) 5415 if(!oldfont)
5402 oldfont = cinfo->hfont; 5416 oldfont = cinfo->hfont;
5403 cinfo->hfont = hfont; 5417 cinfo->hfont = hfont;
5404 }
5405 else if((cinfo = calloc(1, sizeof(ColorInfo))))
5406 {
5407 cinfo->fore = cinfo->back = -1;
5408
5409 strncpy(cinfo->fontname, fontname, 127);
5410
5411 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc);
5412 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo);
5413 } 5418 }
5414 } 5419 }
5415 /* If we changed the font... */ 5420 /* If we changed the font... */
5416 if(hfont) 5421 if(hfont)
5417 { 5422 {
5530 * fore: Foreground color in RGB format. 5535 * fore: Foreground color in RGB format.
5531 * back: Background color in RGB format. 5536 * back: Background color in RGB format.
5532 */ 5537 */
5533 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) 5538 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back)
5534 { 5539 {
5535 ColorInfo *cinfo; 5540 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
5536 Box *thisbox; 5541 Box *thisbox;
5537 TCHAR tmpbuf[100] = {0}; 5542 TCHAR tmpbuf[100] = {0};
5538
5539 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
5540 5543
5541 GetClassName(handle, tmpbuf, 99); 5544 GetClassName(handle, tmpbuf, 99);
5542 5545
5543 if(_tcsnicmp(tmpbuf, WC_LISTVIEW, _tcslen(WC_LISTVIEW))==0) 5546 if(_tcsnicmp(tmpbuf, WC_LISTVIEW, _tcslen(WC_LISTVIEW))==0)
5544 { 5547 {
5566 thisbox->cinfo.fore = fore; 5569 thisbox->cinfo.fore = fore;
5567 thisbox->cinfo.back = back; 5570 thisbox->cinfo.back = back;
5568 } 5571 }
5569 } 5572 }
5570 5573
5571 if(cinfo) 5574 if(cinfo || (cinfo = _dw_window_new_cinfo(handle, TRUE)))
5572 { 5575 {
5573 cinfo->fore = fore; 5576 cinfo->fore = fore;
5574 cinfo->back = back; 5577 cinfo->back = back;
5575 }
5576 else if((cinfo = calloc(1, sizeof(ColorInfo))))
5577 {
5578 cinfo->fore = fore;
5579 cinfo->back = back;
5580
5581 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc);
5582 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo);
5583 } 5578 }
5584 InvalidateRgn(handle, NULL, TRUE); 5579 InvalidateRgn(handle, NULL, TRUE);
5585 return TRUE; 5580 return TRUE;
5586 } 5581 }
5587 5582
5645 HWND hwndframe; 5640 HWND hwndframe;
5646 Box *newbox = calloc(sizeof(Box), 1); 5641 Box *newbox = calloc(sizeof(Box), 1);
5647 ULONG flStyleEx = 0; 5642 ULONG flStyleEx = 0;
5648 #ifdef AEROGLASS 5643 #ifdef AEROGLASS
5649 MARGINS *margins = calloc(1, sizeof(MARGINS)); 5644 MARGINS *margins = calloc(1, sizeof(MARGINS));
5650 RECT *border_thickness = calloc(1, sizeof(RECT));
5651 5645
5652 if (_dw_composition && (flStyle & DW_FCF_COMPOSITED)) 5646 if (_dw_composition && (flStyle & DW_FCF_COMPOSITED))
5653 flStyleEx = WS_EX_LAYERED; 5647 flStyleEx = WS_EX_LAYERED;
5654 #endif 5648 #endif
5655 5649
5656 newbox->type = DW_VERT; 5650 newbox->type = DW_VERT;
5657 newbox->vsize = newbox->hsize = SIZEEXPAND; 5651 newbox->vsize = newbox->hsize = SIZEEXPAND;
5658 newbox->cinfo.fore = newbox->cinfo.back = -1; 5652 newbox->cinfo.fore = newbox->cinfo.back = -1;
5653 newbox->cinfo.style = flStyle;
5659 5654
5660 if(!(flStyle & WS_CAPTION)) 5655 if(!(flStyle & WS_CAPTION))
5661 flStyle |= WS_POPUPWINDOW; 5656 flStyle |= WS_POPUPWINDOW;
5662 5657
5663 if(flStyle & DW_FCF_TASKLIST || 5658 if(flStyle & DW_FCF_TASKLIST ||
5679 if(hwndOwner) 5674 if(hwndOwner)
5680 SetParent(hwndframe, hwndOwner); 5675 SetParent(hwndframe, hwndOwner);
5681 5676
5682 #ifdef AEROGLASS 5677 #ifdef AEROGLASS
5683 /* Determine the borders of the default window frame */ 5678 /* Determine the borders of the default window frame */
5684 AdjustWindowRectEx(border_thickness, flStyle, FALSE, 0); 5679 AdjustWindowRectEx(&(newbox->cinfo.rect), flStyle, FALSE, 0);
5685 border_thickness->left *= -1; 5680 newbox->cinfo.rect.left *= -1;
5686 border_thickness->top *= -1; 5681 newbox->cinfo.rect.top *= -1;
5687 5682
5688 /* With the DW_FCF_COMPOSITED flag, expand it to the entire window */ 5683 /* With the DW_FCF_COMPOSITED flag, expand it to the entire window */
5689 if (flStyle & DW_FCF_COMPOSITED) 5684 if (flStyle & DW_FCF_COMPOSITED)
5690 { 5685 {
5691 MARGINS fullmar = { -1 }; 5686 MARGINS fullmar = { -1 };
5692 *margins = fullmar; 5687 *margins = fullmar;
5693 } 5688 }
5694 else 5689 else
5695 { 5690 {
5696 /* Otherwise use the calculated border sizes */ 5691 /* Otherwise use the calculated border sizes */
5697 margins->cyTopHeight = border_thickness->top; 5692 margins->cyTopHeight = newbox->cinfo.rect.top;
5698 } 5693 }
5699 5694
5700 dw_window_set_data(hwndframe, "_dw_margins", margins); 5695 dw_window_set_data(hwndframe, "_dw_margins", margins);
5701 dw_window_set_data(hwndframe, "_dw_border", border_thickness);
5702 5696
5703 /* Attempt to enable Aero glass background on the entire window */ 5697 /* Attempt to enable Aero glass background on the entire window */
5704 if(_DwmExtendFrameIntoClientArea && _dw_composition && 5698 if(_DwmExtendFrameIntoClientArea && _dw_composition &&
5705 ((flStyle & DW_FCF_COMPOSITED) || (_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED))) 5699 ((flStyle & DW_FCF_COMPOSITED) || (_DW_DARK_MODE_ALLOWED > DW_DARK_MODE_BASIC && _DW_DARK_MODE_ENABLED)))
5706 { 5700 {
5751 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). 5745 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
5752 * pad: Number of pixels to pad around the box. 5746 * pad: Number of pixels to pad around the box.
5753 */ 5747 */
5754 HWND API dw_scrollbox_new(int type, int pad) 5748 HWND API dw_scrollbox_new(int type, int pad)
5755 { 5749 {
5756 ColorInfo *cinfo = calloc(sizeof(ColorInfo), 1); 5750 HWND hwndframe, box = dw_box_new(type, pad);
5757 HWND hwndframe, box = dw_box_new(type, pad); 5751 HWND tmpbox = dw_box_new(DW_VERT, 0);
5758 HWND tmpbox = dw_box_new(DW_VERT, 0); 5752 ColorInfo *cinfo;
5759 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0); 5753
5760 5754 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0);
5761 cinfo->fore = cinfo->back = -1; 5755
5762 5756 hwndframe = CreateWindow(ScrollClassName,
5763 hwndframe = CreateWindow(ScrollClassName, 5757 NULL,
5764 NULL, 5758 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
5765 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL, 5759 0,0,0,0,
5766 0,0,0,0, 5760 DW_HWND_OBJECT,
5767 DW_HWND_OBJECT, 5761 NULL,
5768 NULL, 5762 DWInstance,
5769 DWInstance, 5763 NULL);
5770 NULL); 5764
5771 5765 if((cinfo = _dw_window_new_cinfo(hwndframe, FALSE)))
5772 cinfo->buddy = box; 5766 {
5773 cinfo->combo = tmpbox; 5767 cinfo->buddy = box;
5774 SetParent(tmpbox, hwndframe); 5768 cinfo->combo = tmpbox;
5775 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)cinfo); 5769 }
5776 return hwndframe; 5770 SetParent(tmpbox, hwndframe);
5771 return hwndframe;
5777 } 5772 }
5778 5773
5779 /* 5774 /*
5780 * Returns the position of the scrollbar in the scrollbox 5775 * Returns the position of the scrollbar in the scrollbox
5781 * Parameters: 5776 * Parameters:
6046 HWND API dw_notebook_new(ULONG id, int top) 6041 HWND API dw_notebook_new(ULONG id, int top)
6047 { 6042 {
6048 ULONG flags = 0; 6043 ULONG flags = 0;
6049 HWND tmp; 6044 HWND tmp;
6050 NotebookPage **array = calloc(256, sizeof(NotebookPage *)); 6045 NotebookPage **array = calloc(256, sizeof(NotebookPage *));
6051 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6046 ColorInfo *cinfo;
6052 6047
6053 if(!top) 6048 if(!top)
6054 flags = TCS_BOTTOM; 6049 flags = TCS_BOTTOM;
6055 6050
6056 tmp = CreateWindow(WC_TABCONTROL, 6051 tmp = CreateWindow(WC_TABCONTROL,
6059 0,0,0,0, 6054 0,0,0,0,
6060 DW_HWND_OBJECT, 6055 DW_HWND_OBJECT,
6061 (HMENU)(uintptr_t)id, 6056 (HMENU)(uintptr_t)id,
6062 DWInstance, 6057 DWInstance,
6063 NULL); 6058 NULL);
6064 cinfo->fore = cinfo->back = -1; 6059 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
6065 cinfo->pOldProc = SubclassWindow(tmp, _simplewndproc); 6060 cinfo->pOldProc = SubclassWindow(tmp, _simplewndproc);
6066 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6067 dw_window_set_data(tmp, "_dw_array", (void *)array); 6061 dw_window_set_data(tmp, "_dw_array", (void *)array);
6068 dw_window_set_font(tmp, DefaultFont); 6062 dw_window_set_font(tmp, DefaultFont);
6069 return tmp; 6063 return tmp;
6070 } 6064 }
6071 6065
6571 DW_HWND_OBJECT, 6565 DW_HWND_OBJECT,
6572 (HMENU)(uintptr_t)id, 6566 (HMENU)(uintptr_t)id,
6573 DWInstance, 6567 DWInstance,
6574 NULL); 6568 NULL);
6575 #ifdef AEROGLASS 6569 #ifdef AEROGLASS
6576 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6570 ColorInfo *cinfo = _dw_window_new_cinfo(tmp, FALSE);
6577 6571
6578 cinfo->back = cinfo->fore = -1; 6572 if(cinfo)
6579 6573 cinfo->pOldProc = SubclassWindow(tmp, _staticwndproc);
6580 cinfo->pOldProc = SubclassWindow(tmp, _staticwndproc);
6581 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6582 #endif 6574 #endif
6583 dw_window_set_font(tmp, DefaultFont); 6575 dw_window_set_font(tmp, DefaultFont);
6584 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT); 6576 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT);
6585 return tmp; 6577 return tmp;
6586 } 6578 }
6659 0,0,0,0, 6651 0,0,0,0,
6660 DW_HWND_OBJECT, 6652 DW_HWND_OBJECT,
6661 (HMENU)(uintptr_t)id, 6653 (HMENU)(uintptr_t)id,
6662 DWInstance, 6654 DWInstance,
6663 NULL); 6655 NULL);
6664 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6656
6665 6657 _dw_window_new_cinfo(tmp, TRUE);
6666 cinfo->back = cinfo->fore = -1;
6667
6668 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc);
6669 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6670 dw_window_set_font(tmp, DefaultFont); 6658 dw_window_set_font(tmp, DefaultFont);
6671 return tmp; 6659 return tmp;
6672 } 6660 }
6673 6661
6674 /* 6662 /*
6688 0,0,0,0, 6676 0,0,0,0,
6689 DW_HWND_OBJECT, 6677 DW_HWND_OBJECT,
6690 (HMENU)(uintptr_t)id, 6678 (HMENU)(uintptr_t)id,
6691 DWInstance, 6679 DWInstance,
6692 NULL); 6680 NULL);
6693 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6681
6694 6682 _dw_window_new_cinfo(tmp, TRUE);
6695 cinfo->back = cinfo->fore = -1;
6696
6697 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc);
6698 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6699 dw_window_set_font(tmp, DefaultFont); 6683 dw_window_set_font(tmp, DefaultFont);
6700 return tmp; 6684 return tmp;
6701 } 6685 }
6702 6686
6703 BOOL CALLBACK _subclass_child(HWND handle, LPARAM lp) 6687 BOOL CALLBACK _subclass_child(HWND handle, LPARAM lp)
6761 * text: The text to be display by the static text widget. 6745 * text: The text to be display by the static text widget.
6762 * id: An ID to be used with dw_window_from_id() or 0L. 6746 * id: An ID to be used with dw_window_from_id() or 0L.
6763 */ 6747 */
6764 HWND API dw_button_new(const char *text, ULONG id) 6748 HWND API dw_button_new(const char *text, ULONG id)
6765 { 6749 {
6766 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
6767
6768 HWND tmp = CreateWindow(BUTTONCLASSNAME, 6750 HWND tmp = CreateWindow(BUTTONCLASSNAME,
6769 UTF8toWide(text), 6751 UTF8toWide(text),
6770 WS_CHILD | BS_PUSHBUTTON | 6752 WS_CHILD | BS_PUSHBUTTON |
6771 WS_VISIBLE | WS_CLIPCHILDREN, 6753 WS_VISIBLE | WS_CLIPCHILDREN,
6772 0,0,0,0, 6754 0,0,0,0,
6773 DW_HWND_OBJECT, 6755 DW_HWND_OBJECT,
6774 (HMENU)(uintptr_t)id, 6756 (HMENU)(uintptr_t)id,
6775 DWInstance, 6757 DWInstance,
6776 NULL); 6758 NULL);
6777 cinfo->fore = cinfo->back = -1; 6759 ColorInfo *cinfo;
6778 cinfo->pOldProc = SubclassWindow(tmp, _BtProc); 6760
6779 6761 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
6780 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 6762 cinfo->pOldProc = SubclassWindow(tmp, _BtProc);
6763
6781 dw_window_set_font(tmp, DefaultFont); 6764 dw_window_set_font(tmp, DefaultFont);
6782 return tmp; 6765 return tmp;
6783 } 6766 }
6784 6767
6785 #ifdef TOOLBAR 6768 #ifdef TOOLBAR
6874 * text: Bubble help text to be displayed. 6857 * text: Bubble help text to be displayed.
6875 * id: An ID of a bitmap in the resource file. 6858 * id: An ID of a bitmap in the resource file.
6876 */ 6859 */
6877 HWND API dw_bitmapbutton_new(const char *text, ULONG id) 6860 HWND API dw_bitmapbutton_new(const char *text, ULONG id)
6878 { 6861 {
6879 HWND tmp;
6880 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
6881 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, 0); 6862 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, 0);
6882 HBITMAP hbitmap = icon ? 0 : LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); 6863 HBITMAP hbitmap = icon ? 0 : LoadBitmap(DWInstance, MAKEINTRESOURCE(id));
6864 ColorInfo *cinfo;
6865 HWND tmp;
6866
6883 #ifdef TOOLBAR 6867 #ifdef TOOLBAR
6884 if((tmp = _create_toolbar(text, id, icon, hbitmap))) 6868 if((tmp = _create_toolbar(text, id, icon, hbitmap)))
6885 { 6869 {
6886 cinfo->fore = cinfo->back = -1; 6870 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
6887 cinfo->pOldProc = SubclassWindow(tmp, _simplewndproc); 6871 cinfo->pOldProc = SubclassWindow(tmp, _simplewndproc);
6888 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6889 return tmp; 6872 return tmp;
6890 } 6873 }
6891 #endif 6874 #endif
6892 6875
6893 tmp = CreateWindow(BUTTONCLASSNAME, 6876 tmp = CreateWindow(BUTTONCLASSNAME,
6899 DW_HWND_OBJECT, 6882 DW_HWND_OBJECT,
6900 (HMENU)(uintptr_t)id, 6883 (HMENU)(uintptr_t)id,
6901 DWInstance, 6884 DWInstance,
6902 NULL); 6885 NULL);
6903 6886
6904 cinfo->fore = cinfo->back = -1; 6887 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
6905 cinfo->pOldProc = SubclassWindow(tmp, _BtProc); 6888 cinfo->pOldProc = SubclassWindow(tmp, _BtProc);
6906
6907 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6908 6889
6909 _create_tooltip(tmp, text); 6890 _create_tooltip(tmp, text);
6910 6891
6911 if(icon) 6892 if(icon)
6912 { 6893 SendMessage(tmp, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)icon);
6913 SendMessage(tmp, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) icon);
6914 }
6915 else if(hbitmap) 6894 else if(hbitmap)
6916 { 6895 SendMessage(tmp, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbitmap);
6917 SendMessage(tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap);
6918 }
6919 return tmp; 6896 return tmp;
6920 } 6897 }
6921 6898
6922 /* 6899 /*
6923 * Create a new bitmap button window (widget) to be packed from a file. 6900 * Create a new bitmap button window (widget) to be packed from a file.
6929 * (BMP or ICO on OS/2 or Windows, XPM on Unix) 6906 * (BMP or ICO on OS/2 or Windows, XPM on Unix)
6930 */ 6907 */
6931 HWND API dw_bitmapbutton_new_from_file(const char *text, unsigned long id, const char *filename) 6908 HWND API dw_bitmapbutton_new_from_file(const char *text, unsigned long id, const char *filename)
6932 { 6909 {
6933 HWND tmp; 6910 HWND tmp;
6934 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6911 ColorInfo *cinfo;
6935 HBITMAP hbitmap = 0; 6912 HBITMAP hbitmap = 0;
6936 HANDLE hicon = 0; 6913 HANDLE hicon = 0;
6937 int windowtype = 0; 6914 int windowtype = 0;
6938
6939 if (!cinfo)
6940 return 0;
6941 6915
6942 #ifdef GDIPLUS 6916 #ifdef GDIPLUS
6943 if((hicon = _dw_load_icon(filename))) 6917 if((hicon = _dw_load_icon(filename)))
6944 windowtype = BS_ICON; 6918 windowtype = BS_ICON;
6945 else 6919 else
6952 #endif 6926 #endif
6953 6927
6954 #ifdef TOOLBAR 6928 #ifdef TOOLBAR
6955 if((tmp = _create_toolbar(text, id, hicon, hbitmap))) 6929 if((tmp = _create_toolbar(text, id, hicon, hbitmap)))
6956 { 6930 {
6957 cinfo->fore = cinfo->back = -1; 6931 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
6958 cinfo->pOldProc = SubclassWindow(tmp, _simplewndproc); 6932 cinfo->pOldProc = SubclassWindow(tmp, _simplewndproc);
6959 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6960 return tmp; 6933 return tmp;
6961 } 6934 }
6962 #endif 6935 #endif
6963 tmp = CreateWindow( BUTTONCLASSNAME, 6936 tmp = CreateWindow( BUTTONCLASSNAME,
6964 NULL, 6937 NULL,
6967 DW_HWND_OBJECT, 6940 DW_HWND_OBJECT,
6968 (HMENU)(uintptr_t)id, 6941 (HMENU)(uintptr_t)id,
6969 DWInstance, 6942 DWInstance,
6970 NULL); 6943 NULL);
6971 6944
6972 cinfo->fore = cinfo->back = -1; 6945 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
6973 cinfo->pOldProc = SubclassWindow(tmp, _BtProc); 6946 cinfo->pOldProc = SubclassWindow(tmp, _BtProc);
6974
6975 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6976 6947
6977 _create_tooltip(tmp, text); 6948 _create_tooltip(tmp, text);
6978 6949
6979 if (hicon) 6950 if (hicon)
6980 { 6951 SendMessage(tmp, BM_SETIMAGE,(WPARAM)IMAGE_ICON,(LPARAM)hicon);
6981 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_ICON,(LPARAM) hicon);
6982 }
6983 else if (hbitmap) 6952 else if (hbitmap)
6984 { 6953 SendMessage(tmp, BM_SETIMAGE,(WPARAM)IMAGE_BITMAP, (LPARAM)hbitmap);
6985 SendMessage(tmp, BM_SETIMAGE,(WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap);
6986 }
6987 return tmp; 6954 return tmp;
6988 } 6955 }
6989 6956
6990 /* 6957 /*
6991 * Create a new bitmap button window (widget) to be packed from data. 6958 * Create a new bitmap button window (widget) to be packed from data.
6997 * len: length of str 6964 * len: length of str
6998 */ 6965 */
6999 HWND API dw_bitmapbutton_new_from_data(const char *text, unsigned long id, const char *data, int len) 6966 HWND API dw_bitmapbutton_new_from_data(const char *text, unsigned long id, const char *data, int len)
7000 { 6967 {
7001 HWND tmp; 6968 HWND tmp;
7002 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6969 ColorInfo *cinfo;
7003 HBITMAP hbitmap = 0; 6970 HBITMAP hbitmap = 0;
7004 HANDLE hicon = 0; 6971 HANDLE hicon = 0;
7005 char *file; 6972 char *file;
7006 FILE *fp; 6973 FILE *fp;
7007 int windowtype = BS_BITMAP; 6974 int windowtype = BS_BITMAP;
7008
7009 if (!cinfo)
7010 return 0;
7011 6975
7012 file = _tempnam( _dw_alternate_temp_dir, "dw" ); 6976 file = _tempnam( _dw_alternate_temp_dir, "dw" );
7013 if ( file != NULL ) 6977 if ( file != NULL )
7014 { 6978 {
7015 fp = fopen( file, "wb" ); 6979 fp = fopen( file, "wb" );
7043 } 7007 }
7044 7008
7045 #ifdef TOOLBAR 7009 #ifdef TOOLBAR
7046 if((tmp = _create_toolbar(text, id, hicon, hbitmap))) 7010 if((tmp = _create_toolbar(text, id, hicon, hbitmap)))
7047 { 7011 {
7048 cinfo->fore = cinfo->back = -1; 7012 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
7049 cinfo->pOldProc = SubclassWindow(tmp, _simplewndproc); 7013 cinfo->pOldProc = SubclassWindow(tmp, _simplewndproc);
7050 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
7051 return tmp; 7014 return tmp;
7052 } 7015 }
7053 #endif 7016 #endif
7054 tmp = CreateWindow( BUTTONCLASSNAME, 7017 tmp = CreateWindow( BUTTONCLASSNAME,
7055 NULL, 7018 NULL,
7060 DW_HWND_OBJECT, 7023 DW_HWND_OBJECT,
7061 (HMENU)(uintptr_t)id, 7024 (HMENU)(uintptr_t)id,
7062 DWInstance, 7025 DWInstance,
7063 NULL ); 7026 NULL );
7064 7027
7065 cinfo->fore = cinfo->back = -1; 7028 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
7066 cinfo->pOldProc = SubclassWindow( tmp, _BtProc ); 7029 cinfo->pOldProc = SubclassWindow( tmp, _BtProc );
7067
7068 SetWindowLongPtr( tmp, GWLP_USERDATA, (LONG_PTR)cinfo );
7069 7030
7070 _create_tooltip(tmp, text); 7031 _create_tooltip(tmp, text);
7071 7032
7072 if ( hicon ) 7033 if(hicon)
7073 { 7034 SendMessage(tmp, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hicon);
7074 SendMessage( tmp, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) hicon); 7035 else if(hbitmap)
7075 } 7036 SendMessage(tmp, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbitmap);
7076 else if( hbitmap )
7077 {
7078 SendMessage( tmp, BM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hbitmap);
7079 }
7080 return tmp; 7037 return tmp;
7081 } 7038 }
7082 7039
7083 /* 7040 /*
7084 * Create a new spinbutton window (widget) to be packed. 7041 * Create a new spinbutton window (widget) to be packed.
7107 0,0,0,0, 7064 0,0,0,0,
7108 DW_HWND_OBJECT, 7065 DW_HWND_OBJECT,
7109 (HMENU)(uintptr_t)id, 7066 (HMENU)(uintptr_t)id,
7110 DWInstance, 7067 DWInstance,
7111 NULL); 7068 NULL);
7112 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 7069 ColorInfo *cinfo;
7113 7070
7114 SendMessage(tmp, UDM_SETRANGE32, (WPARAM)-65536,(LPARAM)65536); 7071 SendMessage(tmp, UDM_SETRANGE32, (WPARAM)-65536,(LPARAM)65536);
7115 SendMessage(tmp, UDM_SETBUDDY, (WPARAM)buddy, 0); 7072 SendMessage(tmp, UDM_SETBUDDY, (WPARAM)buddy, 0);
7116 cinfo->back = cinfo->fore = -1; 7073
7117 cinfo->buddy = tmp; 7074 if((cinfo = _dw_window_new_cinfo(buddy, TRUE)))
7118 7075 cinfo->buddy = tmp;
7119 cinfo->pOldProc = SubclassWindow(buddy, _colorwndproc); 7076
7120 SetWindowLongPtr(buddy, GWLP_USERDATA, (LONG_PTR)cinfo); 7077 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
7121 7078 {
7122 cinfo = calloc(1, sizeof(ColorInfo)); 7079 cinfo->buddy = buddy;
7123 cinfo->buddy = buddy; 7080
7124 /* The horrible spinbutton workaround isn't necessary 7081 /* The horrible spinbutton workaround isn't necessary
7125 * any more on Vista or 7... but still seems necessary 7082 * any more on Vista or 7... but still seems necessary
7126 * for XP, so only enable it if on XP or lower. 7083 * for XP, so only enable it if on XP or lower.
7127 */ 7084 */
7128 if(!IS_VISTAPLUS) 7085 if(!IS_VISTAPLUS)
7129 { 7086 cinfo->pOldProc = SubclassWindow(tmp, _spinnerwndproc);
7130 cinfo->pOldProc = SubclassWindow(tmp, _spinnerwndproc); 7087 }
7131 } 7088
7132
7133 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
7134 dw_window_set_font(buddy, DefaultFont); 7089 dw_window_set_font(buddy, DefaultFont);
7135 return tmp; 7090 return tmp;
7136 } 7091 }
7137 7092
7138 /* 7093 /*
7156 7111
7157 /* Disable visual styles by default */ 7112 /* Disable visual styles by default */
7158 if(_SetWindowTheme) 7113 if(_SetWindowTheme)
7159 _SetWindowTheme(tmp, L"", L""); 7114 _SetWindowTheme(tmp, L"", L"");
7160 7115
7161 cinfo = calloc(1, sizeof(ColorInfo)); 7116 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
7162 cinfo->fore = cinfo->back = -1; 7117 cinfo->pOldProc = SubclassWindow(tmp, _BtProc);
7163 cinfo->pOldProc = SubclassWindow(tmp, _BtProc);
7164 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
7165 dw_window_set_font(tmp, DefaultFont); 7118 dw_window_set_font(tmp, DefaultFont);
7166 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT); 7119 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT);
7167 return tmp; 7120 return tmp;
7168 } 7121 }
7169 7122
7184 0,0,0,0, 7137 0,0,0,0,
7185 DW_HWND_OBJECT, 7138 DW_HWND_OBJECT,
7186 (HMENU)(uintptr_t)id, 7139 (HMENU)(uintptr_t)id,
7187 DWInstance, 7140 DWInstance,
7188 NULL); 7141 NULL);
7189 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 7142
7190 7143 _dw_window_new_cinfo(tmp, TRUE);
7191 cinfo->back = cinfo->fore = -1;
7192
7193 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc);
7194 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
7195 SendMessage(tmp, TBM_SETRANGE, (WPARAM)FALSE, MAKELPARAM(0, increments-1)); 7144 SendMessage(tmp, TBM_SETRANGE, (WPARAM)FALSE, MAKELPARAM(0, increments-1));
7196 return tmp; 7145 return tmp;
7197 } 7146 }
7198 7147
7199 /* 7148 /*
7212 0,0,0,0, 7161 0,0,0,0,
7213 DW_HWND_OBJECT, 7162 DW_HWND_OBJECT,
7214 (HMENU)(uintptr_t)id, 7163 (HMENU)(uintptr_t)id,
7215 DWInstance, 7164 DWInstance,
7216 NULL); 7165 NULL);
7217 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 7166
7218 7167 _dw_window_new_cinfo(tmp, TRUE);
7219 cinfo->back = cinfo->fore = -1;
7220
7221 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc);
7222 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
7223 dw_window_set_data(tmp, "_dw_scrollbar", (void *)1); 7168 dw_window_set_data(tmp, "_dw_scrollbar", (void *)1);
7224 return tmp; 7169 return tmp;
7225 } 7170 }
7226 7171
7227 /* 7172 /*
7247 * text: The text to be display by the static text widget. 7192 * text: The text to be display by the static text widget.
7248 * id: An ID to be used with dw_window_from_id() or 0L. 7193 * id: An ID to be used with dw_window_from_id() or 0L.
7249 */ 7194 */
7250 HWND API dw_checkbox_new(const char *text, ULONG id) 7195 HWND API dw_checkbox_new(const char *text, ULONG id)
7251 { 7196 {
7252 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 7197 ColorInfo *cinfo;
7253 HWND tmp = CreateWindow(BUTTONCLASSNAME, 7198 HWND tmp = CreateWindow(BUTTONCLASSNAME,
7254 UTF8toWide(text), 7199 UTF8toWide(text),
7255 WS_CHILD | BS_AUTOCHECKBOX | 7200 WS_CHILD | BS_AUTOCHECKBOX |
7256 BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE, 7201 BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE,
7257 0,0,0,0, 7202 0,0,0,0,
7262 7207
7263 /* Disable visual styles by default */ 7208 /* Disable visual styles by default */
7264 if(_SetWindowTheme) 7209 if(_SetWindowTheme)
7265 _SetWindowTheme(tmp, L"", L""); 7210 _SetWindowTheme(tmp, L"", L"");
7266 7211
7267 cinfo->pOldProc = SubclassWindow(tmp, _BtProc); 7212 if((cinfo = _dw_window_new_cinfo(tmp, FALSE)))
7268 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 7213 cinfo->pOldProc = SubclassWindow(tmp, _BtProc);
7269 dw_window_set_data(tmp, "_dw_checkbox", DW_INT_TO_POINTER(1)); 7214 dw_window_set_data(tmp, "_dw_checkbox", DW_INT_TO_POINTER(1));
7270 dw_window_set_font(tmp, DefaultFont); 7215 dw_window_set_font(tmp, DefaultFont);
7271 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT); 7216 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT);
7272 return tmp; 7217 return tmp;
7273 } 7218 }
7510 GetClassName(handle, tmpbuf, 99); 7455 GetClassName(handle, tmpbuf, 99);
7511 7456
7512 SetWindowText(handle, wtext); 7457 SetWindowText(handle, wtext);
7513 7458
7514 /* Combobox */ 7459 /* Combobox */
7515 if ( _tcsnicmp( tmpbuf, COMBOBOXCLASSNAME, _tcslen(COMBOBOXCLASSNAME)+1) == 0 ) 7460 if(_tcsnicmp( tmpbuf, COMBOBOXCLASSNAME, _tcslen(COMBOBOXCLASSNAME)+1) == 0)
7516 SendMessage(handle, CB_SETEDITSEL, 0, MAKELPARAM(-1, 0)); 7461 SendMessage(handle, CB_SETEDITSEL, 0, MAKELPARAM(-1, 0));
7517 else if ( _tcsnicmp( tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1) == 0 ) 7462 else if(_tcsnicmp( tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1) == 0)
7518 { 7463 {
7519 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 7464 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
7520 if( cinfo && cinfo->buddy ) 7465 if(cinfo && cinfo->buddy)
7521 SetWindowText( cinfo->buddy, wtext ); 7466 SetWindowText(cinfo->buddy, wtext);
7522 } 7467 }
7523 else if ( _tcsnicmp( tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1) == 0 ) 7468 else if(_tcsnicmp( tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1) == 0)
7524 { 7469 {
7525 /* groupbox */ 7470 /* groupbox */
7526 thisbox = (Box *)GetWindowLongPtr( handle, GWLP_USERDATA ); 7471 thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA);
7527 if ( thisbox && thisbox->grouphwnd != (HWND)NULL ) 7472 if(thisbox && thisbox->grouphwnd != (HWND)NULL)
7528 SetWindowText( thisbox->grouphwnd, wtext ); 7473 SetWindowText(thisbox->grouphwnd, wtext);
7529 } 7474 }
7530 /* If we changed the text... */ 7475 /* If we changed the text... */
7531 { 7476 {
7532 Item *item = _box_item(handle); 7477 Item *item = _box_item(handle);
7533 7478
7559 * handle: Handle to the window (widget). 7504 * handle: Handle to the window (widget).
7560 * bubbletext: The text in the floating bubble tooltip. 7505 * bubbletext: The text in the floating bubble tooltip.
7561 */ 7506 */
7562 void API dw_window_set_tooltip(HWND handle, const char *bubbletext) 7507 void API dw_window_set_tooltip(HWND handle, const char *bubbletext)
7563 { 7508 {
7564 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 7509 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
7565 7510
7566 if(cinfo && cinfo->buddy) 7511 if(cinfo && cinfo->buddy)
7567 _create_tooltip(cinfo->buddy, bubbletext); 7512 _create_tooltip(cinfo->buddy, bubbletext);
7568 _create_tooltip(handle, bubbletext); 7513 _create_tooltip(handle, bubbletext);
7569 } 7514 }
7581 TCHAR *tempbuf, tmpbuf[100] = { 0 }; 7526 TCHAR *tempbuf, tmpbuf[100] = { 0 };
7582 int len; 7527 int len;
7583 7528
7584 GetClassName(handle, tmpbuf, 99); 7529 GetClassName(handle, tmpbuf, 99);
7585 7530
7586 if ( _tcsnicmp( tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1) == 0 ) 7531 if(_tcsnicmp( tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1) == 0)
7587 { 7532 {
7588 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 7533 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
7589 7534
7590 if( cinfo && cinfo->buddy ) 7535 if(cinfo && cinfo->buddy)
7591 handle = cinfo->buddy; 7536 handle = cinfo->buddy;
7592 else 7537 else
7593 return NULL; 7538 return NULL;
7594 } 7539 }
7595 7540
7698 GetClassName(box, tmpbuf, 99); 7643 GetClassName(box, tmpbuf, 99);
7699 7644
7700 /* If we are in a scrolled box... extract the interal box */ 7645 /* If we are in a scrolled box... extract the interal box */
7701 if(_tcsnicmp(tmpbuf, ScrollClassName, _tcslen(ScrollClassName)+1)==0) 7646 if(_tcsnicmp(tmpbuf, ScrollClassName, _tcslen(ScrollClassName)+1)==0)
7702 { 7647 {
7703 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(box, GWLP_USERDATA); 7648 ColorInfo *cinfo = _dw_window_get_cinfo(box);
7704 if(cinfo) 7649 if(cinfo)
7705 { 7650 {
7706 box = cinfo->buddy; 7651 box = cinfo->buddy;
7707 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA); 7652 thisbox = (Box *)GetWindowLongPtr(box, GWLP_USERDATA);
7708 } 7653 }
7784 AllowDarkModeForWindow(item, _DW_DARK_MODE_ENABLED); 7729 AllowDarkModeForWindow(item, _DW_DARK_MODE_ENABLED);
7785 #endif 7730 #endif
7786 SetParent(item, box); 7731 SetParent(item, box);
7787 if(_tcsnicmp(tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1)==0) 7732 if(_tcsnicmp(tmpbuf, UPDOWN_CLASS, _tcslen(UPDOWN_CLASS)+1)==0)
7788 { 7733 {
7789 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(item, GWLP_USERDATA); 7734 ColorInfo *cinfo = _dw_window_get_cinfo(item);
7790 7735
7791 if(cinfo) 7736 if(cinfo)
7792 { 7737 {
7793 SetParent(cinfo->buddy, box); 7738 SetParent(cinfo->buddy, box);
7794 ShowWindow(cinfo->buddy, SW_SHOW); 7739 ShowWindow(cinfo->buddy, SW_SHOW);
8287 } 8232 }
8288 8233
8289 GetClassName(handle, tmpbuf, 99); 8234 GetClassName(handle, tmpbuf, 99);
8290 8235
8291 currentstyle = GetWindowLong(handle, GWL_STYLE); 8236 currentstyle = GetWindowLong(handle, GWL_STYLE);
8292 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 8237 cinfo = _dw_window_get_cinfo(handle);
8293 8238
8294 #ifdef TOOLBAR 8239 #ifdef TOOLBAR
8295 /* Bitmap Buttons */ 8240 /* Bitmap Buttons */
8296 if(_tcsnicmp(tmpbuf, TOOLBARCLASSNAME, _tcslen(TOOLBARCLASSNAME)+1) == 0) 8241 if(_tcsnicmp(tmpbuf, TOOLBARCLASSNAME, _tcslen(TOOLBARCLASSNAME)+1) == 0)
8297 { 8242 {
8354 /* Need to filter out bits that shouldn't be set */ 8299 /* Need to filter out bits that shouldn't be set */
8355 tmp = currentstyle | thismask; 8300 tmp = currentstyle | thismask;
8356 tmp ^= thismask; 8301 tmp ^= thismask;
8357 tmp |= thisstyle & thismask; 8302 tmp |= thisstyle & thismask;
8358 8303
8359 if(mask & DW_DT_VCENTER) 8304 if(mask & DW_DT_VCENTER && style & DW_DT_VCENTER && !cinfo)
8360 { 8305 cinfo = _dw_window_new_cinfo(handle, TRUE);
8361 if(style & DW_DT_VCENTER) 8306
8362 {
8363 if(cinfo)
8364 cinfo->vcenter = 1;
8365 else
8366 {
8367 cinfo = calloc(1, sizeof(ColorInfo));
8368 cinfo->fore = cinfo->back = -1;
8369 cinfo->vcenter = 1;
8370
8371 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc);
8372 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo);
8373 }
8374 }
8375 else if(cinfo)
8376 cinfo->vcenter = 0;
8377 }
8378 /* Alignment style is 0 for word wrap */ 8307 /* Alignment style is 0 for word wrap */
8379 if((style & DW_DT_WORDBREAK) && (mask & DW_DT_WORDBREAK)) 8308 if((style & DW_DT_WORDBREAK) && (mask & DW_DT_WORDBREAK))
8380 tmp &= ~(0xFL); 8309 tmp &= ~(0xFL);
8381 else if(type == SS_LEFTNOWORDWRAP) 8310 else if(type == SS_LEFTNOWORDWRAP)
8382 tmp = (tmp & ~(0xFL)) | SS_LEFTNOWORDWRAP; 8311 tmp = (tmp & ~(0xFL)) | SS_LEFTNOWORDWRAP;
8383 else if(type == SS_CENTER) 8312 else if(type == SS_CENTER)
8384 tmp = (tmp & ~(0xFL)) | SS_CENTER; 8313 tmp = (tmp & ~(0xFL)) | SS_CENTER;
8385 else if(type == SS_RIGHT) 8314 else if(type == SS_RIGHT)
8386 tmp = (tmp & ~(0xFL)) | SS_RIGHT; 8315 tmp = (tmp & ~(0xFL)) | SS_RIGHT;
8316 }
8317
8318 /* If we have cinfo store the style there for later use */
8319 if(cinfo)
8320 {
8321 cinfo->style = cinfo->style | mask;
8322 cinfo->style ^= mask;
8323 cinfo->style |= style & mask;
8387 } 8324 }
8388 8325
8389 SetWindowLong(handle, GWL_STYLE, tmp); 8326 SetWindowLong(handle, GWL_STYLE, tmp);
8390 } 8327 }
8391 8328
9301 * position: Current value of the spinbutton. 9238 * position: Current value of the spinbutton.
9302 */ 9239 */
9303 void API dw_spinbutton_set_pos(HWND handle, long position) 9240 void API dw_spinbutton_set_pos(HWND handle, long position)
9304 { 9241 {
9305 TCHAR tmpbuf[101] = {0}; 9242 TCHAR tmpbuf[101] = {0};
9306 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 9243 ColorInfo *cinfo = _dw_window_get_cinfo(handle);
9307 9244
9308 _sntprintf(tmpbuf, 100, TEXT("%ld"), position); 9245 _sntprintf(tmpbuf, 100, TEXT("%ld"), position);
9309 9246
9310 if(cinfo && cinfo->buddy) 9247 if(cinfo && cinfo->buddy)
9311 SetWindowText(cinfo->buddy, tmpbuf); 9248 SetWindowText(cinfo->buddy, tmpbuf);
11172 hdc = pixmap->hdc; 11109 hdc = pixmap->hdc;
11173 else 11110 else
11174 return; 11111 return;
11175 11112
11176 if(handle) 11113 if(handle)
11177 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 11114 cinfo = _dw_window_get_cinfo(handle);
11178 else if(pixmap->font) 11115 else if(pixmap->font)
11179 hFont = pixmap->font; 11116 hFont = pixmap->font;
11180 else if(pixmap->handle) 11117 else if(pixmap->handle)
11181 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); 11118 cinfo = _dw_window_get_cinfo(pixmap->handle);
11182 11119
11183 if(cinfo) 11120 if(cinfo)
11184 { 11121 {
11185 hFont = _acquire_font(handle, cinfo->fontname); 11122 hFont = _acquire_font(handle, cinfo->fontname);
11186 mustdelete = 1; 11123 mustdelete = 1;
11236 { 11173 {
11237 hFont = pixmap->font; 11174 hFont = pixmap->font;
11238 } 11175 }
11239 else 11176 else
11240 { 11177 {
11241 ColorInfo *cinfo; 11178 ColorInfo *cinfo = NULL;
11242 11179
11243 if(handle) 11180 if(handle)
11244 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 11181 cinfo = _dw_window_get_cinfo(handle);
11245 else 11182 else if(pixmap && pixmap->handle)
11246 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); 11183 cinfo = _dw_window_get_cinfo(pixmap->handle);
11247 11184
11248 if(cinfo) 11185 if(cinfo)
11249 { 11186 {
11250 hFont = _acquire_font(handle, cinfo->fontname); 11187 hFont = _acquire_font(handle, cinfo->fontname);
11251 mustdelete = 1; 11188 mustdelete = 1;
12403 * window: Window (widget) to look for the ENTER press. 12340 * window: Window (widget) to look for the ENTER press.
12404 * next: Window (widget) to move to next (or click) 12341 * next: Window (widget) to move to next (or click)
12405 */ 12342 */
12406 void API dw_window_click_default(HWND window, HWND next) 12343 void API dw_window_click_default(HWND window, HWND next)
12407 { 12344 {
12408 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); 12345 ColorInfo *cinfo = _dw_window_get_cinfo(window);
12409 12346
12410 if (cinfo) 12347 if(cinfo)
12411 {
12412 cinfo->clickdefault = next; 12348 cinfo->clickdefault = next;
12413 }
12414 } 12349 }
12415 12350
12416 /* 12351 /*
12417 * Gets the contents of the default clipboard as text. 12352 * Gets the contents of the default clipboard as text.
12418 * Parameters: 12353 * Parameters:
13128 * dataname: A string pointer identifying which signal to be hooked. 13063 * dataname: A string pointer identifying which signal to be hooked.
13129 * data: User data to be passed to the handler function. 13064 * data: User data to be passed to the handler function.
13130 */ 13065 */
13131 void API dw_window_set_data(HWND window, const char *dataname, void *data) 13066 void API dw_window_set_data(HWND window, const char *dataname, void *data)
13132 { 13067 {
13133 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); 13068 ColorInfo *cinfo = _dw_window_get_cinfo(window);
13134 13069
13135 if(!cinfo) 13070 if(!cinfo)
13136 { 13071 {
13137 if(!dataname) 13072 if(!dataname)
13138 return; 13073 return;
13139 13074
13140 cinfo = calloc(1, sizeof(ColorInfo)); 13075 cinfo = _dw_window_new_cinfo(window, FALSE);
13141 cinfo->fore = cinfo->back = -1;
13142 SetWindowLongPtr(window, GWLP_USERDATA, (LONG_PTR)cinfo);
13143 } 13076 }
13144 13077
13145 if(cinfo) 13078 if(cinfo)
13146 { 13079 {
13147 if(data) 13080 if(data)
13163 * dataname: A string pointer identifying which signal to be hooked. 13096 * dataname: A string pointer identifying which signal to be hooked.
13164 * data: User data to be passed to the handler function. 13097 * data: User data to be passed to the handler function.
13165 */ 13098 */
13166 void * API dw_window_get_data(HWND window, const char *dataname) 13099 void * API dw_window_get_data(HWND window, const char *dataname)
13167 { 13100 {
13168 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); 13101 ColorInfo *cinfo = _dw_window_get_cinfo(window);
13169 13102
13170 if(cinfo && cinfo->root && dataname) 13103 if(cinfo && cinfo->root && dataname)
13171 { 13104 {
13172 UserData *ud = _find_userdata(&(cinfo->root), dataname); 13105 UserData *ud = _find_userdata(&(cinfo->root), dataname);
13173 if(ud) 13106 if(ud)