Mercurial > dwindows
comparison win/dw.c @ 1427:7b735226ab94
Simplified the widget color handling code on Windows.
Added support for pseudo transparent widget background colors on Windows.
Updated the readme with recent features.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 03 Dec 2011 19:33:42 +0000 |
parents | 1628bf383893 |
children | fbaec6e5df63 |
comparison
equal
deleted
inserted
replaced
1426:dfd9f177c34c | 1427:7b735226ab94 |
---|---|
2693 } | 2693 } |
2694 else | 2694 else |
2695 SetFocus(handle); | 2695 SetFocus(handle); |
2696 } | 2696 } |
2697 | 2697 |
2698 /* Subclass function that will handle setting colors on controls */ | |
2698 BOOL CALLBACK _colorwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2699 BOOL CALLBACK _colorwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2699 { | 2700 { |
2700 ColorInfo *cinfo; | 2701 ColorInfo *cinfo; |
2701 char tmpbuf[100]; | 2702 char tmpbuf[100]; |
2702 WNDPROC pOldProc = 0; | 2703 WNDPROC pOldProc = 0; |
2845 case WM_CTLCOLORDLG: | 2846 case WM_CTLCOLORDLG: |
2846 { | 2847 { |
2847 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr((HWND)mp2, GWLP_USERDATA); | 2848 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLongPtr((HWND)mp2, GWLP_USERDATA); |
2848 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) | 2849 if(thiscinfo && thiscinfo->fore != -1 && thiscinfo->back != -1) |
2849 { | 2850 { |
2851 int thisback = thiscinfo->back; | |
2852 | |
2850 /* Handle foreground */ | 2853 /* Handle foreground */ |
2851 if(thiscinfo->fore > -1 && thiscinfo->fore < 18) | 2854 if(thiscinfo->fore != DW_CLR_DEFAULT) |
2852 { | 2855 { |
2853 if(thiscinfo->fore != DW_CLR_DEFAULT) | 2856 int fore = _internal_color(thiscinfo->fore); |
2854 { | 2857 |
2855 SetTextColor((HDC)mp1, RGB(_red[thiscinfo->fore], | 2858 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(fore), |
2856 _green[thiscinfo->fore], | 2859 DW_GREEN_VALUE(fore), |
2857 _blue[thiscinfo->fore])); | 2860 DW_BLUE_VALUE(fore))); |
2858 } | |
2859 } | |
2860 else if((thiscinfo->fore & DW_RGB_COLOR) == DW_RGB_COLOR) | |
2861 { | |
2862 SetTextColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->fore), | |
2863 DW_GREEN_VALUE(thiscinfo->fore), | |
2864 DW_BLUE_VALUE(thiscinfo->fore))); | |
2865 } | 2861 } |
2866 /* Handle background */ | 2862 /* Handle background */ |
2867 if(thiscinfo->back > -1 && thiscinfo->back < 18) | 2863 if(thiscinfo->back == DW_RGB_TRANSPARENT) |
2868 { | 2864 { |
2869 if(thiscinfo->back == DW_CLR_DEFAULT) | 2865 ColorInfo *parentcinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2870 { | 2866 |
2871 HBRUSH hbr = GetSysColorBrush(COLOR_3DFACE); | 2867 if(parentcinfo && parentcinfo->back != -1) |
2872 | 2868 thisback = parentcinfo->back; |
2873 SetBkColor((HDC)mp1, GetSysColor(COLOR_3DFACE)); | |
2874 | |
2875 | |
2876 SelectObject((HDC)mp1, hbr); | |
2877 return (LONG)hbr; | |
2878 } | |
2879 else | |
2880 { | |
2881 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], | |
2882 _green[thiscinfo->back], | |
2883 _blue[thiscinfo->back])); | |
2884 if(thiscinfo->hbrush) | |
2885 DeleteObject(thiscinfo->hbrush); | |
2886 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], | |
2887 _green[thiscinfo->back], | |
2888 _blue[thiscinfo->back])); | |
2889 SelectObject((HDC)mp1, thiscinfo->hbrush); | |
2890 } | |
2891 return (LONG)thiscinfo->hbrush; | |
2892 } | 2869 } |
2893 else if((thiscinfo->back & DW_RGB_COLOR) == DW_RGB_COLOR) | 2870 if(thisback == DW_CLR_DEFAULT) |
2894 { | 2871 { |
2895 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), | 2872 HBRUSH hbr = GetSysColorBrush(COLOR_3DFACE); |
2896 DW_GREEN_VALUE(thiscinfo->back), | 2873 |
2897 DW_BLUE_VALUE(thiscinfo->back))); | 2874 SetBkColor((HDC)mp1, GetSysColor(COLOR_3DFACE)); |
2875 | |
2876 SelectObject((HDC)mp1, hbr); | |
2877 return (LONG)hbr; | |
2878 } | |
2879 else if(thisback != -1 && thisback != DW_RGB_TRANSPARENT) | |
2880 { | |
2881 int back = _internal_color(thisback); | |
2882 | |
2883 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(back), | |
2884 DW_GREEN_VALUE(back), | |
2885 DW_BLUE_VALUE(back))); | |
2898 if(thiscinfo->hbrush) | 2886 if(thiscinfo->hbrush) |
2899 DeleteObject(thiscinfo->hbrush); | 2887 DeleteObject(thiscinfo->hbrush); |
2900 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), | 2888 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(back), |
2901 DW_GREEN_VALUE(thiscinfo->back), | 2889 DW_GREEN_VALUE(back), |
2902 DW_BLUE_VALUE(thiscinfo->back))); | 2890 DW_BLUE_VALUE(back))); |
2903 SelectObject((HDC)mp1, thiscinfo->hbrush); | 2891 SelectObject((HDC)mp1, thiscinfo->hbrush); |
2904 return (LONG)thiscinfo->hbrush; | 2892 return (LONG)thiscinfo->hbrush; |
2905 } | 2893 } |
2906 } | 2894 } |
2907 | |
2908 } | 2895 } |
2909 break; | 2896 break; |
2910 } | 2897 } |
2911 } | 2898 } |
2912 | 2899 |
5608 DW_HWND_OBJECT, | 5595 DW_HWND_OBJECT, |
5609 (HMENU)id, | 5596 (HMENU)id, |
5610 DWInstance, | 5597 DWInstance, |
5611 NULL); | 5598 NULL); |
5612 dw_window_set_font(tmp, DefaultFont); | 5599 dw_window_set_font(tmp, DefaultFont); |
5600 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT); | |
5613 return tmp; | 5601 return tmp; |
5614 } | 5602 } |
5615 | 5603 |
5616 /* | 5604 /* |
5617 * Create a new status text window (widget) to be packed. | 5605 * Create a new status text window (widget) to be packed. |
6071 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | 6059 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); |
6072 cinfo->fore = cinfo->back = -1; | 6060 cinfo->fore = cinfo->back = -1; |
6073 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | 6061 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
6074 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 6062 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
6075 dw_window_set_font(tmp, DefaultFont); | 6063 dw_window_set_font(tmp, DefaultFont); |
6064 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT); | |
6076 return tmp; | 6065 return tmp; |
6077 } | 6066 } |
6078 | 6067 |
6079 | 6068 |
6080 /* | 6069 /* |
6171 cinfo->fore = cinfo->back = -1; | 6160 cinfo->fore = cinfo->back = -1; |
6172 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); | 6161 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
6173 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); | 6162 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); |
6174 dw_window_set_data(tmp, "_dw_checkbox", DW_INT_TO_POINTER(1)); | 6163 dw_window_set_data(tmp, "_dw_checkbox", DW_INT_TO_POINTER(1)); |
6175 dw_window_set_font(tmp, DefaultFont); | 6164 dw_window_set_font(tmp, DefaultFont); |
6165 dw_window_set_color(tmp, DW_CLR_DEFAULT, DW_RGB_TRANSPARENT); | |
6176 return tmp; | 6166 return tmp; |
6177 } | 6167 } |
6178 | 6168 |
6179 /* | 6169 /* |
6180 * Create a new listbox window (widget) to be packed. | 6170 * Create a new listbox window (widget) to be packed. |