]> git.saurik.com Git - wxWidgets.git/commitdiff
don't use GetThemeMetric(HP_HEADERITEM, TMT_HEIGHT) as it doesn't seem to work; imple...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 3 Sep 2007 21:50:28 +0000 (21:50 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 3 Sep 2007 21:50:28 +0000 (21:50 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48535 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/render/render.cpp
src/msw/renderer.cpp

index b8a3ddc525efebc8a4012ab70a14088822664710..782bd03f70ad8c3ad0b2dfa5c64e897ca63639cd 100644 (file)
@@ -133,8 +133,10 @@ public:
         dc.DrawText(_T("Below is the standard header button drawn"), 10, 10);
         dc.DrawText(_T("using the current renderer:"), 10, 40);
 
         dc.DrawText(_T("Below is the standard header button drawn"), 10, 10);
         dc.DrawText(_T("using the current renderer:"), 10, 40);
 
-        wxRendererNative::Get().DrawHeaderButton(this, dc,
-                                                 wxRect(20, 70, 100, 60));
+        wxRendererNative& renderer = wxRendererNative::Get();
+        const wxCoord height = renderer.GetHeaderButtonHeight(this);
+
+        renderer.DrawHeaderButton(this, dc, wxRect(20, 70, 100, height));
     }
 
     DECLARE_EVENT_TABLE()
     }
 
     DECLARE_EVENT_TABLE()
index 403fec65796b2e89eed2b46961c73512d7672996..e40371fca0be236d4afadff511b739647cf455f2 100644 (file)
@@ -31,6 +31,7 @@
     #include "wx/settings.h"
 #endif //WX_PRECOMP
 
     #include "wx/settings.h"
 #endif //WX_PRECOMP
 
+#include "wx/scopeguard.h"
 #include "wx/splitter.h"
 #include "wx/renderer.h"
 #include "wx/msw/private.h"
 #include "wx/splitter.h"
 #include "wx/renderer.h"
 #include "wx/msw/private.h"
@@ -115,7 +116,13 @@ public:
                                 const wxRect& rect,
                                 int flags = 0);
 
                                 const wxRect& rect,
                                 int flags = 0);
 
-    virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0);
+    virtual void DrawFocusRect(wxWindow* win,
+                               wxDC& dc,
+                               const wxRect& rect,
+                               int flags = 0);
+
+    virtual int GetHeaderButtonHeight(wxWindow *win);
+
 private:
     DECLARE_NO_COPY_CLASS(wxRendererMSW)
 };
 private:
     DECLARE_NO_COPY_CLASS(wxRendererMSW)
 };
@@ -139,7 +146,6 @@ public:
                                   int flags = 0,
                                   wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL);
                                   int flags = 0,
                                   wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                   wxHeaderButtonParams* params = NULL);
-    virtual int GetHeaderButtonHeight(wxWindow *win);
 
     virtual void DrawTreeItemButton(wxWindow *win,
                                     wxDC& dc,
 
     virtual void DrawTreeItemButton(wxWindow *win,
                                     wxDC& dc,
@@ -277,7 +283,10 @@ wxRendererMSW::DrawPushButton(wxWindow * WXUNUSED(win),
     ::DrawFrameControl(GetHdcOf(dc), &rc, DFC_BUTTON, style);
 }
 
     ::DrawFrameControl(GetHdcOf(dc), &rc, DFC_BUTTON, style);
 }
 
-void wxRendererMSW::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRect& rect, int WXUNUSED(flags))
+void wxRendererMSW::DrawFocusRect(wxWindow * WXUNUSED(win),
+                                  wxDC& dc,
+                                  const wxRect& rect,
+                                  int WXUNUSED(flags))
 {
     RECT rc;
     wxCopyRectToRECT(rect, rc);
 {
     RECT rc;
     wxCopyRectToRECT(rect, rc);
@@ -285,6 +294,29 @@ void wxRendererMSW::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRec
     ::DrawFocusRect(GetHdcOf(dc), &rc);
 }
 
     ::DrawFocusRect(GetHdcOf(dc), &rc);
 }
 
+int wxRendererMSW::GetHeaderButtonHeight(wxWindow * WXUNUSED(win))
+{
+    // some "reasonable" value returned in case of error, it doesn't really
+    // correspond to anything but it's better than returning 0
+    static const int DEFAULT_HEIGHT = 20;
+
+
+    // create a temporary header window just to get its geometry
+    HWND hwndHeader = ::CreateWindow(WC_HEADER, NULL, NULL,
+                                     0, 0, 0, 0, NULL, NULL, NULL, NULL);
+    if ( !hwndHeader )
+        return DEFAULT_HEIGHT;
+
+    wxON_BLOCK_EXIT1( ::DestroyWindow, hwndHeader );
+
+    // initialize the struct filled with the values by Header_Layout()
+    RECT parentRect = { 0, 0, 100, 100 };
+    WINDOWPOS wp = { 0 };
+    HDLAYOUT hdl = { &parentRect, &wp };
+
+    return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT;
+}
+
 // ============================================================================
 // wxRendererXP implementation
 // ============================================================================
 // ============================================================================
 // wxRendererXP implementation
 // ============================================================================
@@ -383,31 +415,6 @@ wxRendererXP::DrawHeaderButton(wxWindow *win,
 }
 
 
 }
 
 
-int
-wxRendererXP::GetHeaderButtonHeight(wxWindow *win)
-{
-    wxUxThemeHandle hTheme(win, L"HEADER");
-    if ( !hTheme )
-    {
-        return m_rendererNative.GetHeaderButtonHeight(win);
-    }
-
-    HRESULT hr;
-    int value = -1;
-
-    hr = wxUxThemeEngine::Get()->GetThemeMetric( hTheme,
-                                                 NULL,
-                                                 HP_HEADERITEM,
-                                                 HIS_NORMAL,
-                                                 TMT_HEIGHT,
-                                                 &value );
-    if ( hr == S_OK )
-        return value;
-    else
-        return 20;
-}
-
-
 void
 wxRendererXP::DrawTreeItemButton(wxWindow *win,
                                  wxDC& dc,
 void
 wxRendererXP::DrawTreeItemButton(wxWindow *win,
                                  wxDC& dc,