From 51c42fc50a57a09392e7d119608b74f91cf85d05 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 3 Sep 2007 21:50:28 +0000 Subject: [PATCH] don't use GetThemeMetric(HP_HEADERITEM, TMT_HEIGHT) as it doesn't seem to work; implement GetHeaderButtonHeight() in wxRendererMSW instead of doing it in wxRendererXP using HDM_LAYOUT; added test for this renderer method to the sample git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48535 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/render/render.cpp | 6 +++-- src/msw/renderer.cpp | 63 ++++++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/samples/render/render.cpp b/samples/render/render.cpp index b8a3ddc..782bd03 100644 --- a/samples/render/render.cpp +++ b/samples/render/render.cpp @@ -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); - 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() diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 403fec6..e40371f 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -31,6 +31,7 @@ #include "wx/settings.h" #endif //WX_PRECOMP +#include "wx/scopeguard.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); - 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) }; @@ -139,7 +146,6 @@ public: int flags = 0, wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, wxHeaderButtonParams* params = NULL); - virtual int GetHeaderButtonHeight(wxWindow *win); virtual void DrawTreeItemButton(wxWindow *win, wxDC& dc, @@ -277,7 +283,10 @@ wxRendererMSW::DrawPushButton(wxWindow * WXUNUSED(win), ::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); @@ -285,6 +294,29 @@ void wxRendererMSW::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRec ::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 // ============================================================================ @@ -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, -- 2.7.4