]>
Commit | Line | Data |
---|---|---|
9c7f49f5 VZ |
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$ | |
77ffb593 | 8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> |
65571936 | 9 | // Licence: wxWindows licence |
9c7f49f5 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | /* | |
77ffb593 | 13 | Renderers are used in wxWidgets for two similar but different things: |
9c7f49f5 VZ |
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 | ||
38c4cb6a | 28 | class WXDLLEXPORT wxDC; |
38c4cb6a VZ |
29 | class WXDLLEXPORT wxWindow; |
30 | ||
7df07b10 MB |
31 | #include "wx/gdicmn.h" // for wxPoint |
32 | ||
f0244295 VZ |
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 | ||
9c7f49f5 VZ |
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 | ||
af99040c VZ |
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 | ||
04857cb7 VZ |
88 | // wxRendererNative interface version |
89 | struct WXDLLEXPORT wxRendererVersion | |
90 | { | |
91 | wxRendererVersion(int version_, int age_) : version(version_), age(age_) { } | |
92 | ||
93 | // default copy ctor, assignment operator and dtor are ok | |
94 | ||
95 | // the current version and age of wxRendererNative interface: different | |
96 | // versions are incompatible (in both ways) while the ages inside the same | |
97 | // version are upwards compatible, i.e. the version of the renderer must | |
98 | // match the version of the main program exactly while the age may be | |
99 | // highergreater or equal to it | |
100 | // | |
101 | // NB: don't forget to increment age after adding any new virtual function! | |
102 | enum | |
103 | { | |
104 | Current_Version = 1, | |
105 | Current_Age = 5 | |
106 | }; | |
107 | ||
108 | ||
109 | // check if the given version is compatible with the current one | |
110 | static bool IsCompatible(const wxRendererVersion& ver) | |
111 | { | |
112 | return ver.version == Current_Version && ver.age >= Current_Age; | |
113 | } | |
114 | ||
115 | const int version; | |
116 | const int age; | |
117 | }; | |
118 | ||
9c7f49f5 VZ |
119 | // ---------------------------------------------------------------------------- |
120 | // wxRendererNative: abstracts drawing methods needed by the native controls | |
121 | // ---------------------------------------------------------------------------- | |
122 | ||
123 | class WXDLLEXPORT wxRendererNative | |
124 | { | |
125 | public: | |
126 | // drawing functions | |
127 | // ----------------- | |
128 | ||
129 | // draw the header control button (used by wxListCtrl) | |
130 | virtual void DrawHeaderButton(wxWindow *win, | |
131 | wxDC& dc, | |
132 | const wxRect& rect, | |
133 | int flags = 0) = 0; | |
134 | ||
135 | // draw the expanded/collapsed icon for a tree control item | |
136 | virtual void DrawTreeItemButton(wxWindow *win, | |
137 | wxDC& dc, | |
138 | const wxRect& rect, | |
139 | int flags = 0) = 0; | |
140 | ||
b3208e11 VZ |
141 | // draw the border for sash window: this border must be such that the sash |
142 | // drawn by DrawSash() blends into it well | |
143 | virtual void DrawSplitterBorder(wxWindow *win, | |
144 | wxDC& dc, | |
af99040c VZ |
145 | const wxRect& rect, |
146 | int flags = 0) = 0; | |
b3208e11 VZ |
147 | |
148 | // draw a (vertical) sash | |
149 | virtual void DrawSplitterSash(wxWindow *win, | |
150 | wxDC& dc, | |
151 | const wxSize& size, | |
62dc9cb4 | 152 | wxCoord position, |
af99040c VZ |
153 | wxOrientation orient, |
154 | int flags = 0) = 0; | |
b3208e11 VZ |
155 | |
156 | ||
157 | // geometry functions | |
158 | // ------------------ | |
159 | ||
160 | // get the splitter parameters: the x field of the returned point is the | |
161 | // sash width and the y field is the border width | |
af99040c | 162 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0; |
b3208e11 | 163 | |
9c7f49f5 VZ |
164 | |
165 | // pseudo constructors | |
166 | // ------------------- | |
167 | ||
168 | // return the currently used renderer | |
169 | static wxRendererNative& Get(); | |
170 | ||
171 | // return the generic implementation of the renderer | |
172 | static wxRendererNative& GetGeneric(); | |
f0244295 VZ |
173 | |
174 | // return the default (native) implementation for this platform | |
175 | static wxRendererNative& GetDefault(); | |
9f2be125 VZ |
176 | |
177 | ||
178 | // changing the global renderer | |
179 | // ---------------------------- | |
180 | ||
181 | #if wxUSE_DYNLIB_CLASS | |
182 | // load the renderer from the specified DLL, the returned pointer must be | |
183 | // deleted by caller if not NULL when it is not used any more | |
184 | static wxRendererNative *Load(const wxString& name); | |
185 | #endif // wxUSE_DYNLIB_CLASS | |
186 | ||
187 | // set the renderer to use, passing NULL reverts to using the default | |
188 | // renderer | |
189 | // | |
190 | // return the previous renderer used with Set() or NULL if none | |
191 | static wxRendererNative *Set(wxRendererNative *renderer); | |
04857cb7 VZ |
192 | |
193 | ||
194 | // miscellaneous stuff | |
195 | // ------------------- | |
196 | ||
197 | // this function is used for version checking: Load() refuses to load any | |
198 | // DLLs implementing an older or incompatible version; it should be | |
199 | // implemented simply by returning wxRendererVersion::Current_XXX values | |
200 | virtual wxRendererVersion GetVersion() const = 0; | |
201 | ||
202 | // virtual dtor for any base class | |
203 | virtual ~wxRendererNative(); | |
9c7f49f5 VZ |
204 | }; |
205 | ||
206 | // ---------------------------------------------------------------------------- | |
207 | // wxDelegateRendererNative: allows reuse of renderers code | |
208 | // ---------------------------------------------------------------------------- | |
209 | ||
210 | class WXDLLEXPORT wxDelegateRendererNative : public wxRendererNative | |
211 | { | |
212 | public: | |
213 | wxDelegateRendererNative() | |
214 | : m_rendererNative(GetGeneric()) { } | |
215 | ||
216 | wxDelegateRendererNative(wxRendererNative& rendererNative) | |
217 | : m_rendererNative(rendererNative) { } | |
218 | ||
219 | ||
220 | virtual void DrawHeaderButton(wxWindow *win, | |
221 | wxDC& dc, | |
222 | const wxRect& rect, | |
223 | int flags = 0) | |
224 | { m_rendererNative.DrawHeaderButton(win, dc, rect, flags); } | |
b3208e11 | 225 | |
9c7f49f5 VZ |
226 | virtual void DrawTreeItemButton(wxWindow *win, |
227 | wxDC& dc, | |
228 | const wxRect& rect, | |
229 | int flags = 0) | |
230 | { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); } | |
231 | ||
b3208e11 VZ |
232 | virtual void DrawSplitterBorder(wxWindow *win, |
233 | wxDC& dc, | |
af99040c VZ |
234 | const wxRect& rect, |
235 | int flags = 0) | |
2c0e6de1 | 236 | { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); } |
b3208e11 VZ |
237 | |
238 | virtual void DrawSplitterSash(wxWindow *win, | |
239 | wxDC& dc, | |
240 | const wxSize& size, | |
62dc9cb4 | 241 | wxCoord position, |
af99040c VZ |
242 | wxOrientation orient, |
243 | int flags = 0) | |
2c0e6de1 VZ |
244 | { m_rendererNative.DrawSplitterSash(win, dc, size, |
245 | position, orient, flags); } | |
b3208e11 VZ |
246 | |
247 | ||
af99040c VZ |
248 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) |
249 | { return m_rendererNative.GetSplitterParams(win); } | |
b3208e11 | 250 | |
04857cb7 VZ |
251 | virtual wxRendererVersion GetVersion() const |
252 | { return m_rendererNative.GetVersion(); } | |
253 | ||
9c7f49f5 VZ |
254 | protected: |
255 | wxRendererNative& m_rendererNative; | |
fc7a2a60 VZ |
256 | |
257 | DECLARE_NO_COPY_CLASS(wxDelegateRendererNative) | |
9c7f49f5 VZ |
258 | }; |
259 | ||
f0244295 VZ |
260 | // ---------------------------------------------------------------------------- |
261 | // inline functions implementation | |
262 | // ---------------------------------------------------------------------------- | |
263 | ||
264 | #ifndef wxHAS_NATIVE_RENDERER | |
265 | ||
266 | // default native renderer is the generic one then | |
267 | /* static */ inline | |
268 | wxRendererNative& wxRendererNative::GetDefault() | |
269 | { | |
270 | return GetGeneric(); | |
271 | } | |
272 | ||
273 | #endif // !wxHAS_NATIVE_RENDERER | |
274 | ||
9c7f49f5 VZ |
275 | #endif // _WX_RENDERER_H_ |
276 |