#endif // WXWIN_COMPATIBILITY_2_8
#ifdef __WXMSW__
+ // GetHDC() is the simplest way to retrieve an HDC From a wxDC but only
+ // works if this wxDC is GDI-based and fails for GDI+ contexts (and
+ // anything else without HDC, e.g. wxPostScriptDC)
WXHDC GetHDC() const;
+
+ // don't use these methods manually, use GetTempHDC() instead
+ virtual WXHDC AcquireHDC() { return GetHDC(); }
+ virtual void ReleaseHDC(WXHDC WXUNUSED(hdc)) { }
+
+ // helper class holding the result of GetTempHDC() with std::auto_ptr<>-like
+ // semantics, i.e. it is moved when copied
+ class TempHDC
+ {
+ public:
+ TempHDC(wxDC& dc)
+ : m_dc(dc),
+ m_hdc(dc.AcquireHDC())
+ {
+ }
+
+ TempHDC(const TempHDC& thdc)
+ : m_dc(thdc.m_dc),
+ m_hdc(thdc.m_hdc)
+ {
+ const_cast<TempHDC&>(thdc).m_hdc = 0;
+ }
+
+ ~TempHDC()
+ {
+ if ( m_hdc )
+ m_dc.ReleaseHDC(m_hdc);
+ }
+
+ WXHDC GetHDC() const { return m_hdc; }
+
+ private:
+ wxDC& m_dc;
+ WXHDC m_hdc;
+
+ wxDECLARE_NO_ASSIGN_CLASS(TempHDC);
+ };
+
+ // GetTempHDC() also works for wxGCDC (but still not for wxPostScriptDC &c)
+ TempHDC GetTempHDC() { return TempHDC(*this); }
#endif // __WXMSW__
protected:
#include "wx/private/graphics.h"
#include "wx/msw/wrapgdip.h"
#include "wx/msw/dc.h"
+#include "wx/dcgraph.h"
#include "wx/stack.h"
IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule, wxModule)
+// ----------------------------------------------------------------------------
+// wxMSW-specific parts of wxGCDC
+// ----------------------------------------------------------------------------
+
+WXHDC wxGCDC::AcquireHDC()
+{
+ wxGraphicsContext * const gc = GetGraphicsContext();
+ if ( !gc )
+ return NULL;
+
+ Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext());
+ return g ? g->GetHDC() : NULL;
+}
+
+void wxGCDC::ReleaseHDC(WXHDC hdc)
+{
+ if ( !hdc )
+ return;
+
+ wxGraphicsContext * const gc = GetGraphicsContext();
+ wxCHECK_RET( gc, "can't release HDC because there is no wxGraphicsContext" );
+
+ Graphics * const g = static_cast<Graphics *>(gc->GetNativeContext());
+ wxCHECK_RET( g, "can't release HDC because there is no Graphics" );
+
+ g->ReleaseHDC((HDC)hdc);
+}
+
#endif // wxUSE_GRAPHICS_CONTEXT
#include "wx/splitter.h"
#include "wx/renderer.h"
#include "wx/msw/private.h"
-#include "wx/msw/dc.h"
#include "wx/msw/uxtheme.h"
-#if wxUSE_GRAPHICS_CONTEXT
-// TODO remove this dependency (gdiplus needs the macros)
-#ifndef max
-#define max(a,b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#ifndef min
-#define min(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
-#include "wx/dcgraph.h"
-#include "gdiplus.h"
-using namespace Gdiplus;
-#endif // wxUSE_GRAPHICS_CONTEXT
-
// tmschema.h is in Win32 Platform SDK and might not be available with earlier
// compilers
#ifndef CP_DROPDOWNBUTTON
#define TMT_EDGEFILLCOLOR 3808
#endif
-
-// ----------------------------------------------------------------------------
-// If the DC is a wxGCDC then pull out the HDC from the GraphicsContext when
-// it is needed, and handle the Release when done.
-
-class GraphicsHDC
-{
-public:
- GraphicsHDC(wxDC* dc)
- {
-#if wxUSE_GRAPHICS_CONTEXT
- m_graphics = NULL;
- wxGCDC* gcdc = wxDynamicCast(dc, wxGCDC);
- if (gcdc) {
- m_graphics = (Graphics*)gcdc->GetGraphicsContext()->GetNativeContext();
- m_hdc = m_graphics->GetHDC();
- }
- else
-#endif
- m_hdc = GetHdcOf(*((wxMSWDCImpl*)dc->GetImpl()));
- }
-
- ~GraphicsHDC()
- {
-#if wxUSE_GRAPHICS_CONTEXT
- if (m_graphics)
- m_graphics->ReleaseHDC(m_hdc);
-#endif
- }
-
- operator HDC() const { return m_hdc; }
-
-private:
- HDC m_hdc;
-#if wxUSE_GRAPHICS_CONTEXT
- Graphics* m_graphics;
-#endif
-};
-
#if defined(__WXWINCE__)
#ifndef DFCS_FLAT
#define DFCS_FLAT 0
RECT rc;
wxCopyRectToRECT(rect, rc);
- ::DrawFocusRect(GraphicsHDC(&dc), &rc);
+ ::DrawFocusRect(GetHdcOf(dc.GetTempHDC()), &rc);
}
void wxRendererMSWBase::DrawItemSelectionRect(wxWindow *win,
if ( flags & wxCONTROL_PRESSED )
style |= DFCS_PUSHED | DFCS_FLAT;
- ::DrawFrameControl(GraphicsHDC(&dc), &r, DFC_SCROLL, style);
+ ::DrawFrameControl(GetHdcOf(dc.GetTempHDC()), &r, DFC_SCROLL, style);
}
void
if ( flags & wxCONTROL_CURRENT )
style |= DFCS_HOT;
- ::DrawFrameControl(GraphicsHDC(&dc), &r, DFC_BUTTON, style);
+ ::DrawFrameControl(GetHdcOf(dc.GetTempHDC()), &r, DFC_BUTTON, style);
}
void
wxUxThemeEngine::Get()->DrawThemeBackground
(
hTheme,
- GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
+ GetHdcOf(dc.GetTempHDC()),
CP_DROPDOWNBUTTON,
state,
&r,
wxUxThemeEngine::Get()->DrawThemeBackground
(
hTheme,
- GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
+ GetHdcOf(dc.GetTempHDC()),
HP_HEADERITEM,
state,
&r,
wxUxThemeEngine::Get()->DrawThemeBackground
(
hTheme,
- GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
+ GetHdcOf(dc.GetTempHDC()),
TVP_GLYPH,
state,
&r,
wxUxThemeEngine::Get()->DrawThemeBackground
(
hTheme,
- GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
+ GetHdcOf(dc.GetTempHDC()),
kind,
state,
&r,