]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/renderer.h
Further corrections to wxFileName docs
[wxWidgets.git] / interface / wx / renderer.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: renderer.h
bbc5b7f8 3// Purpose: interface of wxRendererNative
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
bbc5b7f8
BP
10 @anchor wxCONTROL_FLAGS
11
12 The following rendering flags are defined for wxRendererNative:
13*/
14enum
15{
16 /** Control is disabled. */
17 wxCONTROL_DISABLED = 0x00000001,
18
19 /** Currently has keyboard focus. */
20 wxCONTROL_FOCUSED = 0x00000002,
21
22 /** (Button) is pressed. */
23 wxCONTROL_PRESSED = 0x00000004,
24
25 /** Control-specific bit. */
26 wxCONTROL_SPECIAL = 0x00000008,
27
28 /** Only for the buttons. */
29 wxCONTROL_ISDEFAULT = wxCONTROL_SPECIAL,
30
31 /** Only for the menu items. */
32 wxCONTROL_ISSUBMENU = wxCONTROL_SPECIAL,
33
34 /** Only for the tree items. */
35 wxCONTROL_EXPANDED = wxCONTROL_SPECIAL,
36
37 /** Only for the status bar panes. */
38 wxCONTROL_SIZEGRIP = wxCONTROL_SPECIAL,
39
40 /** Checkboxes only: flat border. */
41 wxCONTROL_FLAT = wxCONTROL_SPECIAL,
42
43 /** Mouse is currently over the control. */
44 wxCONTROL_CURRENT = 0x00000010,
45
46 /** Selected item in e.g. listbox. */
47 wxCONTROL_SELECTED = 0x00000020,
48
49 /** (Check/radio button) is checked. */
50 wxCONTROL_CHECKED = 0x00000040,
51
52 /** (Menu) item can be checked. */
53 wxCONTROL_CHECKABLE = 0x00000080,
54
55 /** (Check) undetermined state. */
56 wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE
57};
58
59/**
60 @struct wxSplitterRenderParams
7c913512
FM
61
62 This is just a simple @c struct used as a return value of
bbc5b7f8 63 wxRendererNative::GetSplitterParams().
7c913512 64
bbc5b7f8
BP
65 It doesn't have any methods and all of its fields are constant, so they can
66 only be examined but not modified.
7c913512 67
23324ae1 68 @library{wxbase}
bbc5b7f8 69 @category{gdi}
23324ae1 70*/
bbc5b7f8 71struct wxSplitterRenderParams
23324ae1 72{
23324ae1 73 /**
bbc5b7f8 74 The only way to initialize this struct is by using this ctor.
23324ae1 75 */
bbc5b7f8 76 wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_);
23324ae1 77
bbc5b7f8
BP
78 /**
79 The width of the border drawn by the splitter inside it, may be 0.
80 */
81 const wxCoord border;
23324ae1
FM
82
83 /**
23324ae1
FM
84 @true if the sash changes appearance when the mouse passes over it, @false
85 otherwise.
86 */
bbc5b7f8 87 const bool isHotSensitive;
23324ae1
FM
88
89 /**
23324ae1
FM
90 The width of the splitter sash.
91 */
bbc5b7f8
BP
92 const wxCoord widthSash;
93};
94
95/**
96 @struct wxHeaderButtonParams
bbc5b7f8
BP
97
98 This @c struct can optionally be used with
99 wxRendererNative::DrawHeaderButton() to specify custom values used to draw
100 the text or bitmap label.
101
102 @library{wxbase}
103 @category{gdi}
104*/
105struct wxHeaderButtonParams
106{
107 wxHeaderButtonParams();
108
109 wxColour m_arrowColour;
110 wxColour m_selectionColour;
111 wxString m_labelText;
112 wxFont m_labelFont;
113 wxColour m_labelColour;
114 wxBitmap m_labelBitmap;
115 int m_labelAlignment;
116};
117
118/**
119 Used to specify the type of sort arrow used with
120 wxRendererNative::DrawHeaderButton().
121*/
122enum wxHeaderSortIconType
123{
124 wxHDR_SORT_ICON_NONE, ///< Don't draw a sort arrow.
125 wxHDR_SORT_ICON_UP, ///< Draw a sort arrow icon pointing up.
126 wxHDR_SORT_ICON_DOWN ///< Draw a sort arrow icon pointing down.
23324ae1
FM
127};
128
129
e54c96f1 130
23324ae1
FM
131/**
132 @class wxDelegateRendererNative
7c913512
FM
133
134 wxDelegateRendererNative allows reuse of renderers code by forwarding all the
23324ae1
FM
135 wxRendererNative methods to the given object and
136 thus allowing you to only modify some of its methods -- without having to
137 reimplement all of them.
7c913512 138
cdbcf4c2 139 Note that the "normal", inheritance-based approach, doesn't work with the
23324ae1
FM
140 renderers as it is impossible to derive from a class unknown at compile-time
141 and the renderer is only chosen at run-time. So suppose that you want to only
142 add something to the drawing of the tree control buttons but leave all the
143 other methods unchanged -- the only way to do it, considering that the renderer
144 class which you want to customize might not even be written yet when you write
145 your code (it could be written later and loaded from a DLL during run-time), is
146 by using this class.
7c913512
FM
147
148 Except for the constructor, it has exactly the same methods as
23324ae1 149 wxRendererNative and their implementation is
cdbcf4c2 150 trivial: they are simply forwarded to the real renderer. Note that the "real"
23324ae1
FM
151 renderer may, in turn, be a wxDelegateRendererNative as well and that there may
152 be arbitrarily many levels like this -- but at the end of the chain there must
153 be a real renderer which does the drawing.
7c913512 154
23324ae1 155 @library{wxcore}
bbc5b7f8
BP
156 @category{gdi}
157
158 @see wxRendererNative
23324ae1
FM
159*/
160class wxDelegateRendererNative : public wxRendererNative
161{
162public:
23324ae1
FM
163 /**
164 The default constructor does the same thing as the other one except that it
bbc5b7f8
BP
165 uses the @ref wxRendererNative::GetGeneric() "generic renderer" instead of the
166 user-specified @a rendererNative.
167
23324ae1
FM
168 In any case, this sets up the delegate renderer object to follow all calls to
169 the specified real renderer.
23324ae1
FM
170 */
171 wxDelegateRendererNative();
23324ae1 172 /**
bbc5b7f8
BP
173 This constructor uses the user-specified @a rendererNative to set up the delegate
174 renderer object to follow all calls to the specified real renderer.
175
176 @note
177 This object does not take ownership of (i.e. won't delete) @a rendererNative.
23324ae1 178 */
bbc5b7f8
BP
179 wxDelegateRendererNative(wxRendererNative& rendererNative);
180
181 // The rest of these functions inherit the documentation from wxRendererNative
182
183 virtual int DrawHeaderButton(wxWindow *win, wxDC& dc,
184 const wxRect& rect, int flags = 0,
185 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
186 wxHeaderButtonParams* params = NULL);
187
188 virtual int DrawHeaderButtonContents(wxWindow *win, wxDC& dc,
189 const wxRect& rect, int flags = 0,
190 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
191 wxHeaderButtonParams* params = NULL);
192
193 virtual int GetHeaderButtonHeight(wxWindow *win);
194
195 virtual void DrawTreeItemButton(wxWindow *win, wxDC& dc,
196 const wxRect& rect, int flags = 0);
197
198 virtual void DrawSplitterBorder(wxWindow *win, wxDC& dc,
199 const wxRect& rect, int flags = 0);
200
201 virtual void DrawSplitterSash(wxWindow *win, wxDC& dc,
202 const wxSize& size, wxCoord position,
203 wxOrientation orient, int flags = 0);
204
205 virtual void DrawComboBoxDropButton(wxWindow *win, wxDC& dc,
206 const wxRect& rect, int flags = 0);
207
208 virtual void DrawDropArrow(wxWindow *win, wxDC& dc,
209 const wxRect& rect, int flags = 0);
210
211 virtual void DrawCheckBox(wxWindow *win, wxDC& dc,
212 const wxRect& rect, int flags = 0 );
213
214 virtual void DrawPushButton(wxWindow *win, wxDC& dc,
215 const wxRect& rect, int flags = 0 );
216
217 virtual void DrawItemSelectionRect(wxWindow *win, wxDC& dc,
218 const wxRect& rect, int flags = 0 );
219
220 virtual void DrawFocusRect(wxWindow* win, wxDC& dc,
221 const wxRect& rect, int flags = 0);
222
223 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
224
225 virtual wxRendererVersion GetVersion() const;
23324ae1
FM
226};
227
228
e54c96f1 229
23324ae1
FM
230/**
231 @class wxRendererNative
7c913512 232
bbc5b7f8 233 First, a brief introduction to wxRendererNative and why it is needed.
7c913512 234
23324ae1 235 Usually wxWidgets uses the underlying low level GUI system to draw all the
cdbcf4c2 236 controls - this is what we mean when we say that it is a "native" framework.
23324ae1
FM
237 However not all controls exist under all (or even any) platforms and in this
238 case wxWidgets provides a default, generic, implementation of them written in
239 wxWidgets itself.
7c913512 240
23324ae1
FM
241 These controls don't have the native appearance if only the standard
242 line drawing and other graphics primitives are used, because the native
243 appearance is different under different platforms while the lines are always
244 drawn in the same way.
7c913512 245
bbc5b7f8 246 This is why we have renderers: wxRendererNative is a class which virtualizes the
23324ae1
FM
247 drawing, i.e. it abstracts the drawing operations and allows you to draw say, a
248 button, without caring about exactly how this is done. Of course, as we
249 can draw the button differently in different renderers, this also allows us to
250 emulate the native look and feel.
7c913512 251
23324ae1
FM
252 So the renderers work by exposing a large set of high-level drawing functions
253 which are used by the generic controls. There is always a default global
7c913512 254 renderer but it may be changed or extended by the user, see
bbc5b7f8 255 @ref page_samples_render.
7c913512 256
23324ae1 257 All drawing functions take some standard parameters:
7c913512 258
bbc5b7f8 259 @li @a win - The window being drawn. It is normally not used and when
7c913512 260 it is it should only be used as a generic wxWindow
23324ae1
FM
261 (in order to get its low level handle, for example), but you should
262 not assume that it is of some given type as the same renderer
263 function may be reused for drawing different kinds of control.
bbc5b7f8 264 @li @a dc - The wxDC to draw on. Only this device
23324ae1
FM
265 context should be used for drawing. It is not necessary to restore
266 pens and brushes for it on function exit but, on the other hand, you
267 shouldn't assume that it is in any specific state on function entry:
268 the rendering functions should always prepare it.
bbc5b7f8
BP
269 @li @a rect - The bounding rectangle for the element to be drawn.
270 @li @a flags - The optional flags (none by default) which can be a
271 combination of the @ref wxCONTROL_FLAGS.
7c913512 272
23324ae1
FM
273 Note that each drawing function restores the wxDC attributes if
274 it changes them, so it is safe to assume that the same pen, brush and colours
275 that were active before the call to this function are still in effect after it.
7c913512 276
23324ae1
FM
277 @library{wxcore}
278 @category{gdi}
279*/
7c913512 280class wxRendererNative
23324ae1
FM
281{
282public:
283 /**
284 Virtual destructor as for any base class.
285 */
286 ~wxRendererNative();
287
288 /**
289 Draw a check box (used by wxDataViewCtrl).
bbc5b7f8 290
4cc4bfaf 291 @a flags may have the @c wxCONTROL_CHECKED, @c wxCONTROL_CURRENT or
bbc5b7f8 292 @c wxCONTROL_UNDETERMINED bit set, see @ref wxCONTROL_FLAGS.
23324ae1 293 */
bbc5b7f8
BP
294 virtual void DrawCheckBox(wxWindow* win, wxDC& dc,
295 const wxRect& rect, int flags);
23324ae1
FM
296
297 /**
298 Draw a button like the one used by wxComboBox to show a
299 drop down window. The usual appearance is a downwards pointing arrow.
bbc5b7f8
BP
300
301 @a flags may have the @c wxCONTROL_PRESSED or @c wxCONTROL_CURRENT bit set,
302 see @ref wxCONTROL_FLAGS.
23324ae1 303 */
bbc5b7f8 304 virtual void DrawComboBoxDropButton(wxWindow* win, wxDC& dc,
23324ae1
FM
305 const wxRect& rect,
306 int flags);
307
308 /**
309 Draw a drop down arrow that is suitable for use outside a combo box. Arrow will
bbc5b7f8
BP
310 have transparent background.
311
4cc4bfaf 312 @a rect is not entirely filled by the arrow. Instead, you should use bounding
23324ae1 313 rectangle of a drop down button which arrow matches the size you need.
bbc5b7f8
BP
314
315 @a flags may have the @c wxCONTROL_PRESSED or @c wxCONTROL_CURRENT bit set,
316 see @ref wxCONTROL_FLAGS.
23324ae1 317 */
bbc5b7f8 318 virtual void DrawDropArrow(wxWindow* win, wxDC& dc, const wxRect& rect,
23324ae1
FM
319 int flags);
320
321 /**
322 Draw a focus rectangle using the specified rectangle.
bbc5b7f8
BP
323 wxListCtrl.
324
325 The only supported flags is @c wxCONTROL_SELECTED for items which are selected.
326 see @ref wxCONTROL_FLAGS.
23324ae1 327 */
bbc5b7f8 328 virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect,
23324ae1
FM
329 int flags = 0);
330
331 /**
bbc5b7f8
BP
332 Draw the header control button (used, for example, by wxListCtrl).
333
334 Depending on platforms the @a flags parameter may support the @c wxCONTROL_SELECTED
335 @c wxCONTROL_DISABLED and @c wxCONTROL_CURRENT bits, see @ref wxCONTROL_FLAGS.
336
337 @return
338 The optimal width to contain the the unabreviated label text or
339 bitmap, the sort arrow if present, and internal margins.
23324ae1 340 */
bbc5b7f8
BP
341 virtual int DrawHeaderButton(wxWindow* win, wxDC& dc,
342 const wxRect& rect, int flags = 0,
343 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
344 wxHeaderButtonParams* params = NULL);
345
346 /**
347 Draw the contents of a header control button (label, sort arrows,
348 etc.). This function is normally only called by DrawHeaderButton().
349
350 Depending on platforms the @a flags parameter may support the @c wxCONTROL_SELECTED
351 @c wxCONTROL_DISABLED and @c wxCONTROL_CURRENT bits, see @ref wxCONTROL_FLAGS.
352
353 @return
354 The optimal width to contain the the unabreviated label text or
355 bitmap, the sort arrow if present, and internal margins.
356 */
357 virtual int DrawHeaderButtonContents(wxWindow *win, wxDC& dc,
358 const wxRect& rect, int flags = 0,
359 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
360 wxHeaderButtonParams* params = NULL);
23324ae1
FM
361
362 /**
7c913512 363 Draw a selection rectangle underneath the text as used e.g. in a
bbc5b7f8
BP
364 wxListCtrl.
365
366 The supported @a flags are @c wxCONTROL_SELECTED for items
367 which are selected (e.g. often a blue rectangle) and @c wxCONTROL_CURRENT
368 for the item that has the focus (often a dotted line around the item's text).
369 @c wxCONTROL_FOCUSED may be used to indicate if the control has the focus
370 (othewise the the selection rectangle is e.g. often grey and not blue).
371 This may be ignored by the renderer or deduced by the code directly from
372 the @a win.
23324ae1 373 */
bbc5b7f8
BP
374 virtual void DrawItemSelectionRect(wxWindow* win, wxDC& dc,
375 const wxRect& rect, int flags = 0);
23324ae1
FM
376
377 /**
378 Draw a blank push button that looks very similar to wxButton.
bbc5b7f8 379
4cc4bfaf 380 @a flags may have the @c wxCONTROL_PRESSED, @c wxCONTROL_CURRENT or
bbc5b7f8 381 @c wxCONTROL_ISDEFAULT bit set, see @ref wxCONTROL_FLAGS.
23324ae1 382 */
bbc5b7f8
BP
383 virtual void DrawPushButton(wxWindow* win, wxDC& dc,
384 const wxRect& rect, int flags);
23324ae1
FM
385
386 /**
387 Draw the border for sash window: this border must be such that the sash
bbc5b7f8 388 drawn by DrawSplitterSash() blends into it well.
23324ae1 389 */
bbc5b7f8
BP
390 virtual void DrawSplitterBorder(wxWindow* win, wxDC& dc,
391 const wxRect& rect, int flags = 0);
23324ae1
FM
392
393 /**
4cc4bfaf
FM
394 Draw a sash. The @a orient parameter defines whether the sash should be
395 vertical or horizontal and how the @a position should be interpreted.
23324ae1 396 */
bbc5b7f8
BP
397 virtual void DrawSplitterSash(wxWindow* win, wxDC& dc,
398 const wxSize& size, wxCoord position,
399 wxOrientation orient, int flags = 0);
23324ae1
FM
400
401 /**
bbc5b7f8
BP
402 Draw the expanded/collapsed icon for a tree control item.
403
404 To draw an expanded button the @a flags parameter must contain @c wxCONTROL_EXPANDED bit,
405 see @ref wxCONTROL_FLAGS.
23324ae1 406 */
bbc5b7f8
BP
407 virtual void DrawTreeItemButton(wxWindow* win, wxDC& dc,
408 const wxRect& rect, int flags = 0);
23324ae1
FM
409
410 /**
411 Return the currently used renderer.
412 */
bbc5b7f8 413 static wxRendererNative Get();
23324ae1
FM
414
415 /**
416 Return the default (native) implementation for this platform -- this is also
7c913512 417 the one used by default but this may be changed by calling
23324ae1
FM
418 Set() in which case the return value of this
419 method may be different from the return value of Get().
420 */
bbc5b7f8 421 static wxRendererNative GetDefault();
23324ae1
FM
422
423 /**
424 Return the generic implementation of the renderer. Under some platforms, this
425 is the default renderer implementation, others have platform-specific default
426 renderer which can be retrieved by calling GetDefault().
427 */
bbc5b7f8 428 static wxRendererNative GetGeneric();
23324ae1
FM
429
430 /**
431 Returns the height of a header button, either a fixed platform height if
7c913512 432 available, or a
23324ae1
FM
433 generic height based on the window's font.
434 */
bbc5b7f8 435 virtual int GetHeaderButtonHeight(wxWindow* win);
23324ae1
FM
436
437 /**
7c913512 438 Get the splitter parameters, see
23324ae1
FM
439 wxSplitterRenderParams.
440 */
bbc5b7f8 441 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow* win);
23324ae1
FM
442
443 /**
7c913512 444 This function is used for version checking: Load()
23324ae1
FM
445 refuses to load any shared libraries implementing an older or incompatible
446 version.
bbc5b7f8
BP
447
448 @remarks
23324ae1 449 The implementation of this method is always the same in all renderers (simply
bbc5b7f8
BP
450 construct wxRendererVersion using the @c wxRendererVersion::Current_XXX values),
451 but it has to be in the derived, not base, class, to detect mismatches between
452 the renderers versions and so you have to implement it anew in all renderers.
23324ae1 453 */
bbc5b7f8 454 virtual wxRendererVersion GetVersion() const;
23324ae1
FM
455
456 /**
457 Load the renderer from the specified DLL, the returned pointer must be
458 deleted by caller if not @NULL when it is not used any more.
bbc5b7f8 459
4cc4bfaf 460 The @a name should be just the base name of the renderer and not the full
7c913512 461 name of the DLL file which is constructed differently (using
bbc5b7f8 462 wxDynamicLibrary::CanonicalizePluginName())
23324ae1
FM
463 on different systems.
464 */
bbc5b7f8 465 static wxRendererNative* Load(const wxString& name);
23324ae1
FM
466
467 /**
468 Set the renderer to use, passing @NULL reverts to using the default
469 renderer (the global renderer must always exist).
bbc5b7f8 470
23324ae1
FM
471 Return the previous renderer used with Set() or @NULL if none.
472 */
bbc5b7f8 473 static wxRendererNative* Set(wxRendererNative* renderer);
23324ae1
FM
474};
475
476
e54c96f1 477
23324ae1 478/**
bbc5b7f8 479 @struct wxRendererVersion
7c913512
FM
480
481 This simple struct represents the wxRendererNative
482 interface version and is only used as the return value of
bbc5b7f8 483 wxRendererNative::GetVersion().
7c913512 484
23324ae1
FM
485 The version has two components: the version itself and the age. If the main
486 program and the renderer have different versions they are never compatible with
487 each other because the version is only changed when an existing virtual
488 function is modified or removed. The age, on the other hand, is incremented
489 each time a new virtual method is added and so, at least for the compilers
490 using a common C++ object model, the calling program is compatible with any
491 renderer which has the age greater or equal to its age. This verification is
e54c96f1 492 done by IsCompatible() method.
7c913512 493
23324ae1 494 @library{wxbase}
bbc5b7f8 495 @category{gdi}
23324ae1 496*/
bbc5b7f8 497struct wxRendererVersion
23324ae1 498{
23324ae1 499 /**
7c913512 500 Checks if the main program is compatible with the renderer having the version
23324ae1 501 @e ver, returns @true if it is and @false otherwise.
bbc5b7f8
BP
502
503 This method is used by wxRendererNative::Load() to determine whether a
23324ae1
FM
504 renderer can be used.
505 */
506 static bool IsCompatible(const wxRendererVersion& ver);
507
508 /**
23324ae1
FM
509 The age component.
510 */
bbc5b7f8 511 const int age;
23324ae1
FM
512
513 /**
23324ae1
FM
514 The version component.
515 */
bbc5b7f8 516 const int version;
23324ae1 517};
e54c96f1 518