]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxWindowMSW::MSWGetThemeColour(); initially use it in wxComboCtrl::OnThemeChange()
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 19 Dec 2009 14:47:37 +0000 (14:47 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 19 Dec 2009 14:47:37 +0000 (14:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62947 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/window.h
src/msw/combo.cpp
src/msw/window.cpp

index c4670e733689a610ade7385d52c10878e12ab06f..a65fa4910aedb6bb57811e9d7869b651537f2910 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef _WX_WINDOW_H_
 #define _WX_WINDOW_H_
 
+enum wxSystemColour;
+
 // if this is set to 1, we use deferred window sizing to reduce flicker when
 // resizing complicated window hierarchies, but this can in theory result in
 // different behaviour than the old code so we keep the possibility to use it
@@ -413,6 +415,21 @@ public:
     WXHBRUSH MSWGetBgBrush(WXHDC hDC) { return MSWGetBgBrush(hDC, this); }
     WXHBRUSH MSWGetBgBrush(WXHDC hDC, wxWindowMSW *child);
 
+    enum MSWThemeColour
+    {
+        ThemeColourText = 0,
+        ThemeColourBackground,
+        ThemeColourBorder
+    };
+
+    // returns a specific theme colour, or if that is not possible then
+    // wxSystemSettings::GetColour(fallback)
+    wxColour MSWGetThemeColour(const wchar_t *themeName,
+                               int themePart,
+                               int themeState,
+                               MSWThemeColour themeColour,
+                               wxSystemColour fallback);
+
     // gives the parent the possibility to draw its children background, e.g.
     // this is used by wxNotebook to do it using DrawThemeBackground()
     //
index f30d15982e990b5cde7c7297e3419490d860a525..733e068430e5855adc385d7d4e706726a29cabe7 100644 (file)
@@ -232,34 +232,12 @@ void wxComboCtrl::OnThemeChange()
         m_hasFgCol = false;
     }
 
-    wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
-
-#if wxUSE_UXTHEME
-    wxUxThemeEngine * const theme = wxUxThemeEngine::GetIfActive();
-    if ( theme )
-    {
-        // NB: use EDIT, not COMBOBOX (the latter works in XP but not Vista)
-        wxUxThemeHandle hTheme(this, L"EDIT");
-        COLORREF col;
-        HRESULT hr = theme->GetThemeColor
-                            (
-                                hTheme,
-                                EP_EDITTEXT,
-                                ETS_NORMAL,
-                                TMT_FILLCOLOR,
-                                &col
-                            );
-        if ( SUCCEEDED(hr) )
-        {
-            bgCol = wxRGBToColour(col);
-        }
-        else
-        {
-            wxLogApiError("GetThemeColor(EDIT, ETS_NORMAL, TMT_FILLCOLOR)",
-                          hr);
-        }
-    }
-#endif
+    // NB: use EDIT, not COMBOBOX (the latter works in XP but not Vista)
+    wxColour bgCol = MSWGetThemeColour(L"EDIT",
+                                       EP_EDITTEXT,
+                                       ETS_NORMAL,
+                                       ThemeColourBackground,
+                                       wxSYS_COLOUR_WINDOW);
 
     if ( !m_hasBgCol )
     {
index c95309f8aaaa613b345ed9eb25e6e7e8a838c761..033882715129ed07f075145bbef326a1a50e4cb0 100644 (file)
@@ -4701,6 +4701,64 @@ extern wxCOLORMAP *wxGetStdColourMap()
     return s_cmap;
 }
 
+#if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR)
+    #define TMT_FILLCOLOR       3802
+    #define TMT_TEXTCOLOR       3803
+    #define TMT_BORDERCOLOR     3801
+#endif
+
+wxColour wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName,
+                                        int themePart,
+                                        int themeState,
+                                        MSWThemeColour themeColour,
+                                        wxSystemColour fallback)
+{
+#if wxUSE_UXTHEME
+    const wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive();
+    if ( theme )
+    {
+        int themeProperty = 0;
+
+        // TODO: Convert this into a table? Sure would be faster.
+        switch ( themeColour )
+        {
+            case ThemeColourBackground:
+                themeProperty = TMT_FILLCOLOR;
+                break;
+            case ThemeColourText:
+                themeProperty = TMT_TEXTCOLOR;
+                break;
+            case ThemeColourBorder:
+                themeProperty = TMT_BORDERCOLOR;
+                break;
+            default:
+                wxFAIL_MSG(wxT("unsupported theme colour"));
+        };
+
+        wxUxThemeHandle hTheme(this, themeName);
+        COLORREF col;
+        HRESULT hr = theme->GetThemeColor
+                            (
+                                hTheme,
+                                themePart,
+                                themeState,
+                                themeProperty,
+                                &col
+                            );
+
+        if ( SUCCEEDED(hr) )
+            return wxRGBToColour(col);
+
+        wxLogApiError(
+            wxString::Format(
+                "GetThemeColor(%s, %i, %i, %i)",
+                themeName, themePart, themeState, themeProperty),
+            hr);
+    }
+#endif
+    return wxSystemSettings::GetColour(fallback);
+}
+
 // ---------------------------------------------------------------------------
 // painting
 // ---------------------------------------------------------------------------