]>
Commit | Line | Data |
---|---|---|
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@wxwidgets.org> | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | /* | |
13 | Renderers are used in wxWidgets 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 | #include "wx/colour.h" | |
33 | #include "wx/font.h" | |
34 | #include "wx/bitmap.h" | |
35 | #include "wx/string.h" | |
36 | ||
37 | // some platforms have their own renderers, others use the generic one | |
38 | #if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK__) | |
39 | #define wxHAS_NATIVE_RENDERER | |
40 | #else | |
41 | #undef wxHAS_NATIVE_RENDERER | |
42 | #endif | |
43 | ||
44 | // ---------------------------------------------------------------------------- | |
45 | // constants | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | // control state flags used in wxRenderer and wxColourScheme | |
49 | enum | |
50 | { | |
51 | wxCONTROL_DISABLED = 0x00000001, // control is disabled | |
52 | wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus | |
53 | wxCONTROL_PRESSED = 0x00000004, // (button) is pressed | |
54 | wxCONTROL_SPECIAL = 0x00000008, // control-specific bit: | |
55 | wxCONTROL_ISDEFAULT = wxCONTROL_SPECIAL, // only for the buttons | |
56 | wxCONTROL_ISSUBMENU = wxCONTROL_SPECIAL, // only for the menu items | |
57 | wxCONTROL_EXPANDED = wxCONTROL_SPECIAL, // only for the tree items | |
58 | wxCONTROL_SIZEGRIP = wxCONTROL_SPECIAL, // only for the status bar panes | |
59 | wxCONTROL_CURRENT = 0x00000010, // mouse is currently over the control | |
60 | wxCONTROL_SELECTED = 0x00000020, // selected item in e.g. listbox | |
61 | wxCONTROL_CHECKED = 0x00000040, // (check/radio button) is checked | |
62 | wxCONTROL_CHECKABLE = 0x00000080, // (menu) item can be checked | |
63 | wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state | |
64 | ||
65 | wxCONTROL_FLAGS_MASK = 0x000000ff, | |
66 | ||
67 | // this is a pseudo flag not used directly by wxRenderer but rather by some | |
68 | // controls internally | |
69 | wxCONTROL_DIRTY = 0x80000000 | |
70 | }; | |
71 | ||
72 | // ---------------------------------------------------------------------------- | |
73 | // helper structs | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | // wxSplitterWindow parameters | |
77 | struct WXDLLEXPORT wxSplitterRenderParams | |
78 | { | |
79 | // the only way to initialize this struct is by using this ctor | |
80 | wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_) | |
81 | : widthSash(widthSash_), border(border_), isHotSensitive(isSens_) | |
82 | { | |
83 | } | |
84 | ||
85 | // the width of the splitter sash | |
86 | const wxCoord widthSash; | |
87 | ||
88 | // the width of the border of the splitter window | |
89 | const wxCoord border; | |
90 | ||
91 | // true if the splitter changes its appearance when the mouse is over it | |
92 | const bool isHotSensitive; | |
93 | }; | |
94 | ||
95 | ||
96 | // extra optional parameters for DrawHeaderButton | |
97 | struct WXDLLEXPORT wxHeaderButtonParams | |
98 | { | |
99 | wxHeaderButtonParams() | |
100 | : m_labelAlignment(wxALIGN_LEFT) | |
101 | { } | |
102 | ||
103 | wxColour m_arrowColour; | |
104 | wxColour m_selectionColour; | |
105 | wxString m_labelText; | |
106 | wxFont m_labelFont; | |
107 | wxColour m_labelColour; | |
108 | wxBitmap m_labelBitmap; | |
109 | int m_labelAlignment; | |
110 | }; | |
111 | ||
112 | enum wxHeaderSortIconType { | |
113 | wxHDR_SORT_ICON_NONE, // Header button has no sort arrow | |
114 | wxHDR_SORT_ICON_UP, // Header button an an up sort arrow icon | |
115 | wxHDR_SORT_ICON_DOWN // Header button an a down sort arrow icon | |
116 | }; | |
117 | ||
118 | ||
119 | // wxRendererNative interface version | |
120 | struct WXDLLEXPORT wxRendererVersion | |
121 | { | |
122 | wxRendererVersion(int version_, int age_) : version(version_), age(age_) { } | |
123 | ||
124 | // default copy ctor, assignment operator and dtor are ok | |
125 | ||
126 | // the current version and age of wxRendererNative interface: different | |
127 | // versions are incompatible (in both ways) while the ages inside the same | |
128 | // version are upwards compatible, i.e. the version of the renderer must | |
129 | // match the version of the main program exactly while the age may be | |
130 | // highergreater or equal to it | |
131 | // | |
132 | // NB: don't forget to increment age after adding any new virtual function! | |
133 | enum | |
134 | { | |
135 | Current_Version = 1, | |
136 | Current_Age = 5 | |
137 | }; | |
138 | ||
139 | ||
140 | // check if the given version is compatible with the current one | |
141 | static bool IsCompatible(const wxRendererVersion& ver) | |
142 | { | |
143 | return ver.version == Current_Version && ver.age >= Current_Age; | |
144 | } | |
145 | ||
146 | const int version; | |
147 | const int age; | |
148 | }; | |
149 | ||
150 | // ---------------------------------------------------------------------------- | |
151 | // wxRendererNative: abstracts drawing methods needed by the native controls | |
152 | // ---------------------------------------------------------------------------- | |
153 | ||
154 | class WXDLLEXPORT wxRendererNative | |
155 | { | |
156 | public: | |
157 | // drawing functions | |
158 | // ----------------- | |
159 | ||
160 | // draw the header control button (used by wxListCtrl) | |
161 | virtual void DrawHeaderButton(wxWindow *win, | |
162 | wxDC& dc, | |
163 | const wxRect& rect, | |
164 | int flags = 0, | |
165 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, | |
166 | wxHeaderButtonParams* params=NULL) = 0; | |
167 | ||
168 | ||
169 | // Draw the contents of a header control button (label, sort arrows, etc.) | |
170 | // Normally only called by DrawHeaderButton. | |
171 | virtual void DrawHeaderButtonContents(wxWindow *win, | |
172 | wxDC& dc, | |
173 | const wxRect& rect, | |
174 | int flags = 0, | |
175 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, | |
176 | wxHeaderButtonParams* params=NULL) = 0; | |
177 | ||
178 | // Returns the default height of a header button, either a fixed platform | |
179 | // height if available, or a generic height based on the window's font. | |
180 | virtual int GetHeaderButtonHeight(wxWindow *win) = 0; | |
181 | ||
182 | ||
183 | // draw the expanded/collapsed icon for a tree control item | |
184 | virtual void DrawTreeItemButton(wxWindow *win, | |
185 | wxDC& dc, | |
186 | const wxRect& rect, | |
187 | int flags = 0) = 0; | |
188 | ||
189 | // draw the border for sash window: this border must be such that the sash | |
190 | // drawn by DrawSash() blends into it well | |
191 | virtual void DrawSplitterBorder(wxWindow *win, | |
192 | wxDC& dc, | |
193 | const wxRect& rect, | |
194 | int flags = 0) = 0; | |
195 | ||
196 | // draw a (vertical) sash | |
197 | virtual void DrawSplitterSash(wxWindow *win, | |
198 | wxDC& dc, | |
199 | const wxSize& size, | |
200 | wxCoord position, | |
201 | wxOrientation orient, | |
202 | int flags = 0) = 0; | |
203 | ||
204 | // draw a combobox dropdown button | |
205 | // | |
206 | // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT | |
207 | virtual void DrawComboBoxDropButton(wxWindow *win, | |
208 | wxDC& dc, | |
209 | const wxRect& rect, | |
210 | int flags = 0) = 0; | |
211 | ||
212 | // draw a dropdown arrow | |
213 | // | |
214 | // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT | |
215 | virtual void DrawDropArrow(wxWindow *win, | |
216 | wxDC& dc, | |
217 | const wxRect& rect, | |
218 | int flags = 0) = 0; | |
219 | ||
220 | // draw check button | |
221 | // | |
222 | // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT | |
223 | virtual void DrawCheckBox(wxWindow *win, | |
224 | wxDC& dc, | |
225 | const wxRect& rect, | |
226 | int flags = 0) = 0; | |
227 | ||
228 | // draw blank button | |
229 | // | |
230 | // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT | |
231 | virtual void DrawPushButton(wxWindow *win, | |
232 | wxDC& dc, | |
233 | const wxRect& rect, | |
234 | int flags = 0) = 0; | |
235 | ||
236 | // draw rectangle indicating that an item in e.g. a list control | |
237 | // has been selected or focused | |
238 | // | |
239 | // flags may use | |
240 | // wxCONTROL_SELECTED (item is selected, e.g. draw background) | |
241 | // wxCONTROL_CURRENT (item is the current item, e.g. dotted border) | |
242 | // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise) | |
243 | virtual void DrawItemSelectionRect(wxWindow *win, | |
244 | wxDC& dc, | |
245 | const wxRect& rect, | |
246 | int flags = 0) = 0; | |
247 | ||
248 | // geometry functions | |
249 | // ------------------ | |
250 | ||
251 | // get the splitter parameters: the x field of the returned point is the | |
252 | // sash width and the y field is the border width | |
253 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0; | |
254 | ||
255 | ||
256 | // pseudo constructors | |
257 | // ------------------- | |
258 | ||
259 | // return the currently used renderer | |
260 | static wxRendererNative& Get(); | |
261 | ||
262 | // return the generic implementation of the renderer | |
263 | static wxRendererNative& GetGeneric(); | |
264 | ||
265 | // return the default (native) implementation for this platform | |
266 | static wxRendererNative& GetDefault(); | |
267 | ||
268 | ||
269 | // changing the global renderer | |
270 | // ---------------------------- | |
271 | ||
272 | #if wxUSE_DYNLIB_CLASS | |
273 | // load the renderer from the specified DLL, the returned pointer must be | |
274 | // deleted by caller if not NULL when it is not used any more | |
275 | static wxRendererNative *Load(const wxString& name); | |
276 | #endif // wxUSE_DYNLIB_CLASS | |
277 | ||
278 | // set the renderer to use, passing NULL reverts to using the default | |
279 | // renderer | |
280 | // | |
281 | // return the previous renderer used with Set() or NULL if none | |
282 | static wxRendererNative *Set(wxRendererNative *renderer); | |
283 | ||
284 | ||
285 | // miscellaneous stuff | |
286 | // ------------------- | |
287 | ||
288 | // this function is used for version checking: Load() refuses to load any | |
289 | // DLLs implementing an older or incompatible version; it should be | |
290 | // implemented simply by returning wxRendererVersion::Current_XXX values | |
291 | virtual wxRendererVersion GetVersion() const = 0; | |
292 | ||
293 | // virtual dtor for any base class | |
294 | virtual ~wxRendererNative(); | |
295 | }; | |
296 | ||
297 | // ---------------------------------------------------------------------------- | |
298 | // wxDelegateRendererNative: allows reuse of renderers code | |
299 | // ---------------------------------------------------------------------------- | |
300 | ||
301 | class WXDLLEXPORT wxDelegateRendererNative : public wxRendererNative | |
302 | { | |
303 | public: | |
304 | wxDelegateRendererNative() | |
305 | : m_rendererNative(GetGeneric()) { } | |
306 | ||
307 | wxDelegateRendererNative(wxRendererNative& rendererNative) | |
308 | : m_rendererNative(rendererNative) { } | |
309 | ||
310 | ||
311 | virtual void DrawHeaderButton(wxWindow *win, | |
312 | wxDC& dc, | |
313 | const wxRect& rect, | |
314 | int flags = 0, | |
315 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, | |
316 | wxHeaderButtonParams* params = NULL) | |
317 | { m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); } | |
318 | ||
319 | virtual void DrawHeaderButtonContents(wxWindow *win, | |
320 | wxDC& dc, | |
321 | const wxRect& rect, | |
322 | int flags = 0, | |
323 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, | |
324 | wxHeaderButtonParams* params = NULL) | |
325 | { m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); } | |
326 | ||
327 | virtual int GetHeaderButtonHeight(wxWindow *win) | |
328 | { return m_rendererNative.GetHeaderButtonHeight(win); } | |
329 | ||
330 | virtual void DrawTreeItemButton(wxWindow *win, | |
331 | wxDC& dc, | |
332 | const wxRect& rect, | |
333 | int flags = 0) | |
334 | { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); } | |
335 | ||
336 | virtual void DrawSplitterBorder(wxWindow *win, | |
337 | wxDC& dc, | |
338 | const wxRect& rect, | |
339 | int flags = 0) | |
340 | { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); } | |
341 | ||
342 | virtual void DrawSplitterSash(wxWindow *win, | |
343 | wxDC& dc, | |
344 | const wxSize& size, | |
345 | wxCoord position, | |
346 | wxOrientation orient, | |
347 | int flags = 0) | |
348 | { m_rendererNative.DrawSplitterSash(win, dc, size, | |
349 | position, orient, flags); } | |
350 | ||
351 | virtual void DrawComboBoxDropButton(wxWindow *win, | |
352 | wxDC& dc, | |
353 | const wxRect& rect, | |
354 | int flags = 0) | |
355 | { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); } | |
356 | ||
357 | virtual void DrawDropArrow(wxWindow *win, | |
358 | wxDC& dc, | |
359 | const wxRect& rect, | |
360 | int flags = 0) | |
361 | { m_rendererNative.DrawDropArrow(win, dc, rect, flags); } | |
362 | ||
363 | virtual void DrawCheckBox(wxWindow *win, | |
364 | wxDC& dc, | |
365 | const wxRect& rect, | |
366 | int flags = 0 ) | |
367 | { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); } | |
368 | ||
369 | virtual void DrawPushButton(wxWindow *win, | |
370 | wxDC& dc, | |
371 | const wxRect& rect, | |
372 | int flags = 0 ) | |
373 | { m_rendererNative.DrawPushButton( win, dc, rect, flags ); } | |
374 | ||
375 | virtual void DrawItemSelectionRect(wxWindow *win, | |
376 | wxDC& dc, | |
377 | const wxRect& rect, | |
378 | int flags = 0 ) | |
379 | { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); } | |
380 | ||
381 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) | |
382 | { return m_rendererNative.GetSplitterParams(win); } | |
383 | ||
384 | virtual wxRendererVersion GetVersion() const | |
385 | { return m_rendererNative.GetVersion(); } | |
386 | ||
387 | protected: | |
388 | wxRendererNative& m_rendererNative; | |
389 | ||
390 | DECLARE_NO_COPY_CLASS(wxDelegateRendererNative) | |
391 | }; | |
392 | ||
393 | // ---------------------------------------------------------------------------- | |
394 | // inline functions implementation | |
395 | // ---------------------------------------------------------------------------- | |
396 | ||
397 | #ifndef wxHAS_NATIVE_RENDERER | |
398 | ||
399 | // default native renderer is the generic one then | |
400 | /* static */ inline | |
401 | wxRendererNative& wxRendererNative::GetDefault() | |
402 | { | |
403 | return GetGeneric(); | |
404 | } | |
405 | ||
406 | #endif // !wxHAS_NATIVE_RENDERER | |
407 | ||
408 | #endif // _WX_RENDERER_H_ |