use XP renderer if available; implemented splitter drawing using XP functions
[wxWidgets.git] / src / msw / renderer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/renderer.cpp
3 // Purpose: implementation of wxRendererNative for Windows
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 20.07.2003
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/string.h"
29 #endif //WX_PRECOMP
30
31 #include "wx/renderer.h"
32
33 #include "wx/msw/uxtheme.h"
34
35 // ----------------------------------------------------------------------------
36 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
37 // ----------------------------------------------------------------------------
38
39 class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative
40 {
41 public:
42 wxRendererMSW() { }
43
44 static wxRendererNative& Get();
45
46 private:
47 DECLARE_NO_COPY_CLASS(wxRendererMSW)
48 };
49
50 // ----------------------------------------------------------------------------
51 // wxRendererXP: wxRendererNative implementation for Windows XP and later
52 // ----------------------------------------------------------------------------
53
54 class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative
55 {
56 public:
57 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
58
59 static wxRendererNative& Get();
60
61 virtual void DrawSplitterBorder(wxWindow *win,
62 wxDC& dc,
63 const wxRect& rect);
64 virtual void DrawSplitterSash(wxWindow *win,
65 wxDC& dc,
66 const wxSize& size,
67 wxCoord position,
68 wxOrientation orient);
69 virtual wxPoint GetSplitterSashAndBorder(const wxWindow *win);
70
71 private:
72 DECLARE_NO_COPY_CLASS(wxRendererXP)
73 };
74
75 // ============================================================================
76 // wxRendererNative and wxRendererMSW implementation
77 // ============================================================================
78
79 /* static */
80 wxRendererNative& wxRendererNative::GetDefault()
81 {
82 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
83 return themeEngine && themeEngine->IsThemeActive() ? wxRendererXP::Get()
84 : wxRendererMSW::Get();
85 }
86
87 /* static */
88 wxRendererNative& wxRendererMSW::Get()
89 {
90 static wxRendererMSW s_rendererMSW;
91
92 return s_rendererMSW;
93 }
94
95 // ============================================================================
96 // wxRendererXP implementation
97 // ============================================================================
98
99 /* static */
100 wxRendererNative& wxRendererXP::Get()
101 {
102 static wxRendererXP s_rendererXP;
103
104 return s_rendererXP;
105 }
106
107 // ----------------------------------------------------------------------------
108 // splitter drawing
109 // ----------------------------------------------------------------------------
110
111 // the width of the sash: this is the same as used by Explorer...
112 static const wxCoord SASH_WIDTH = 4;
113
114 wxPoint wxRendererXP::GetSplitterSashAndBorder(const wxWindow * WXUNUSED(win))
115 {
116 return wxPoint(SASH_WIDTH, 0);
117 }
118
119 void
120 wxRendererXP::DrawSplitterBorder(wxWindow * WXUNUSED(win),
121 wxDC& WXUNUSED(dc),
122 const wxRect& WXUNUSED(rect))
123 {
124 }
125
126 void
127 wxRendererXP::DrawSplitterSash(wxWindow *win,
128 wxDC& dc,
129 const wxSize& size,
130 wxCoord position,
131 wxOrientation orient)
132 {
133 // I don't know if it is correct to use the rebar background for the
134 // splitter but it least this works ok in the default theme
135 wxUxThemeHandle hTheme(win, L"REBAR");
136 if ( hTheme )
137 {
138 RECT rect;
139 if ( orient == wxVERTICAL )
140 {
141 rect.left = position;
142 rect.right = position + SASH_WIDTH;
143 rect.top = 0;
144 rect.bottom = size.y;
145 }
146 else // wxHORIZONTAL
147 {
148 rect.left = 0;
149 rect.right = size.x;
150 rect.top = position;
151 rect.bottom = position + SASH_WIDTH;
152 }
153
154 wxUxThemeEngine::Get()->DrawThemeBackground
155 (
156 hTheme,
157 dc.GetHDC(),
158 3 /* RP_BAND */,
159 0 /* no state */ ,
160 &rect,
161 NULL
162 );
163 }
164 }
165