]> git.saurik.com Git - wxWidgets.git/blob - include/wx/renderer.h
added Load() and Set() methods
[wxWidgets.git] / include / wx / renderer.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/renderer.h
3 // Purpose: wxRendererNative class declaration
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 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 /*
13 Renderers are used in wxWindows for two similar but different things:
14 (a) wxUniversal uses them to draw everything, i.e. all the control
15 (b) all the native ports use them to draw generic controls only
16
17 wxUniversal needs more functionality than what is included in the base class
18 as it needs to draw stuff like scrollbars which are never going to be
19 generic. So we put the bare minimum needed by the native ports here and the
20 full wxRenderer class is declared in wx/univ/renderer.h and is only used by
21 wxUniveral (although note that native ports can load wxRenderer objects from
22 theme DLLs and use them as wxRendererNative ones, of course).
23 */
24
25 #ifndef _WX_RENDERER_H_
26 #define _WX_RENDERER_H_
27
28 class WXDLLEXPORT wxDC;
29 class WXDLLEXPORT wxWindow;
30
31 #include "wx/gdicmn.h" // for wxPoint
32
33 // some platforms have their own renderers, others use the generic one
34 #if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK__)
35 #define wxHAS_NATIVE_RENDERER
36 #else
37 #undef wxHAS_NATIVE_RENDERER
38 #endif
39
40 // ----------------------------------------------------------------------------
41 // constants
42 // ----------------------------------------------------------------------------
43
44 // control state flags used in wxRenderer and wxColourScheme
45 enum
46 {
47 wxCONTROL_DISABLED = 0x00000001, // control is disabled
48 wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus
49 wxCONTROL_PRESSED = 0x00000004, // (button) is pressed
50 wxCONTROL_ISDEFAULT = 0x00000008, // only applies to the buttons
51 wxCONTROL_ISSUBMENU = wxCONTROL_ISDEFAULT, // only for menu items
52 wxCONTROL_EXPANDED = wxCONTROL_ISDEFAULT, // only for the tree items
53 wxCONTROL_CURRENT = 0x00000010, // mouse is currently over the control
54 wxCONTROL_SELECTED = 0x00000020, // selected item in e.g. listbox
55 wxCONTROL_CHECKED = 0x00000040, // (check/radio button) is checked
56 wxCONTROL_CHECKABLE = 0x00000080, // (menu) item can be checked
57
58 wxCONTROL_FLAGS_MASK = 0x000000ff,
59
60 // this is a pseudo flag not used directly by wxRenderer but rather by some
61 // controls internally
62 wxCONTROL_DIRTY = 0x80000000
63 };
64
65 // ----------------------------------------------------------------------------
66 // helper structs
67 // ----------------------------------------------------------------------------
68
69 // wxSplitterWindow parameters
70 struct WXDLLEXPORT wxSplitterRenderParams
71 {
72 // the only way to initialize this struct is by using this ctor
73 wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_)
74 : widthSash(widthSash_), border(border_), isHotSensitive(isSens_)
75 {
76 }
77
78 // the width of the splitter sash
79 const wxCoord widthSash;
80
81 // the width of the border of the splitter window
82 const wxCoord border;
83
84 // true if the splitter changes its appearance when the mouse is over it
85 const bool isHotSensitive;
86 };
87
88 // ----------------------------------------------------------------------------
89 // wxRendererNative: abstracts drawing methods needed by the native controls
90 // ----------------------------------------------------------------------------
91
92 class WXDLLEXPORT wxRendererNative
93 {
94 public:
95 virtual ~wxRendererNative() { } // stop GCC warning
96
97 // drawing functions
98 // -----------------
99
100 // draw the header control button (used by wxListCtrl)
101 virtual void DrawHeaderButton(wxWindow *win,
102 wxDC& dc,
103 const wxRect& rect,
104 int flags = 0) = 0;
105
106 // draw the expanded/collapsed icon for a tree control item
107 virtual void DrawTreeItemButton(wxWindow *win,
108 wxDC& dc,
109 const wxRect& rect,
110 int flags = 0) = 0;
111
112 // draw the border for sash window: this border must be such that the sash
113 // drawn by DrawSash() blends into it well
114 virtual void DrawSplitterBorder(wxWindow *win,
115 wxDC& dc,
116 const wxRect& rect,
117 int flags = 0) = 0;
118
119 // draw a (vertical) sash
120 virtual void DrawSplitterSash(wxWindow *win,
121 wxDC& dc,
122 const wxSize& size,
123 wxCoord position,
124 wxOrientation orient,
125 int flags = 0) = 0;
126
127
128 // geometry functions
129 // ------------------
130
131 // get the splitter parameters: the x field of the returned point is the
132 // sash width and the y field is the border width
133 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0;
134
135
136 // pseudo constructors
137 // -------------------
138
139 // return the currently used renderer
140 static wxRendererNative& Get();
141
142 // return the generic implementation of the renderer
143 static wxRendererNative& GetGeneric();
144
145 // return the default (native) implementation for this platform
146 static wxRendererNative& GetDefault();
147
148
149 // changing the global renderer
150 // ----------------------------
151
152 #if wxUSE_DYNLIB_CLASS
153 // load the renderer from the specified DLL, the returned pointer must be
154 // deleted by caller if not NULL when it is not used any more
155 static wxRendererNative *Load(const wxString& name);
156 #endif // wxUSE_DYNLIB_CLASS
157
158 // set the renderer to use, passing NULL reverts to using the default
159 // renderer
160 //
161 // return the previous renderer used with Set() or NULL if none
162 static wxRendererNative *Set(wxRendererNative *renderer);
163 };
164
165 // ----------------------------------------------------------------------------
166 // wxDelegateRendererNative: allows reuse of renderers code
167 // ----------------------------------------------------------------------------
168
169 class WXDLLEXPORT wxDelegateRendererNative : public wxRendererNative
170 {
171 public:
172 wxDelegateRendererNative()
173 : m_rendererNative(GetGeneric()) { }
174
175 wxDelegateRendererNative(wxRendererNative& rendererNative)
176 : m_rendererNative(rendererNative) { }
177
178
179 virtual void DrawHeaderButton(wxWindow *win,
180 wxDC& dc,
181 const wxRect& rect,
182 int flags = 0)
183 { m_rendererNative.DrawHeaderButton(win, dc, rect, flags); }
184
185 virtual void DrawTreeItemButton(wxWindow *win,
186 wxDC& dc,
187 const wxRect& rect,
188 int flags = 0)
189 { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); }
190
191 virtual void DrawSplitterBorder(wxWindow *win,
192 wxDC& dc,
193 const wxRect& rect,
194 int flags = 0)
195 { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); }
196
197 virtual void DrawSplitterSash(wxWindow *win,
198 wxDC& dc,
199 const wxSize& size,
200 wxCoord position,
201 wxOrientation orient,
202 int flags = 0)
203 { m_rendererNative.DrawSplitterSash(win, dc, size,
204 position, orient, flags); }
205
206
207 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
208 { return m_rendererNative.GetSplitterParams(win); }
209
210 protected:
211 wxRendererNative& m_rendererNative;
212
213 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative)
214 };
215
216 // ----------------------------------------------------------------------------
217 // inline functions implementation
218 // ----------------------------------------------------------------------------
219
220 #ifndef wxHAS_NATIVE_RENDERER
221
222 // default native renderer is the generic one then
223 /* static */ inline
224 wxRendererNative& wxRendererNative::GetDefault()
225 {
226 return GetGeneric();
227 }
228
229 #endif // !wxHAS_NATIVE_RENDERER
230
231 #endif // _WX_RENDERER_H_
232