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