]> git.saurik.com Git - wxWidgets.git/blame - include/wx/renderer.h
No changes, just fix a typo in wxBannerWindow documentation.
[wxWidgets.git] / include / wx / renderer.h
CommitLineData
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
b5dbe15d
VS
28class WXDLLIMPEXP_FWD_CORE wxDC;
29class WXDLLIMPEXP_FWD_CORE wxWindow;
38c4cb6a 30
e8759560 31#include "wx/gdicmn.h" // for wxPoint, wxSize
0856300f
WS
32#include "wx/colour.h"
33#include "wx/font.h"
34#include "wx/bitmap.h"
35#include "wx/string.h"
7df07b10 36
f0244295 37// some platforms have their own renderers, others use the generic one
ac9e3f1f 38#if defined(__WXMSW__) || ( defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON ) || defined(__WXGTK__)
f0244295
VZ
39 #define wxHAS_NATIVE_RENDERER
40#else
41 #undef wxHAS_NATIVE_RENDERER
42#endif
43
ec20a753
VZ
44// only MSW and OS X currently provides DrawTitleBarBitmap() method
45#if defined(__WXMSW__) || (defined(__WXMAC__) && wxUSE_LIBPNG && wxUSE_IMAGE)
b50d93d1
VZ
46 #define wxHAS_DRAW_TITLE_BAR_BITMAP
47#endif
48
9c7f49f5
VZ
49// ----------------------------------------------------------------------------
50// constants
51// ----------------------------------------------------------------------------
52
53// control state flags used in wxRenderer and wxColourScheme
54enum
55{
56 wxCONTROL_DISABLED = 0x00000001, // control is disabled
57 wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus
58 wxCONTROL_PRESSED = 0x00000004, // (button) is pressed
fb61f58a
VZ
59 wxCONTROL_SPECIAL = 0x00000008, // control-specific bit:
60 wxCONTROL_ISDEFAULT = wxCONTROL_SPECIAL, // only for the buttons
61 wxCONTROL_ISSUBMENU = wxCONTROL_SPECIAL, // only for the menu items
62 wxCONTROL_EXPANDED = wxCONTROL_SPECIAL, // only for the tree items
63 wxCONTROL_SIZEGRIP = wxCONTROL_SPECIAL, // only for the status bar panes
8a461249 64 wxCONTROL_FLAT = wxCONTROL_SPECIAL, // checkboxes only: flat border
9c7f49f5
VZ
65 wxCONTROL_CURRENT = 0x00000010, // mouse is currently over the control
66 wxCONTROL_SELECTED = 0x00000020, // selected item in e.g. listbox
67 wxCONTROL_CHECKED = 0x00000040, // (check/radio button) is checked
68 wxCONTROL_CHECKABLE = 0x00000080, // (menu) item can be checked
415a0ff1 69 wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
9c7f49f5 70
a61c9122 71 wxCONTROL_FLAGS_MASK = 0x000000ff,
9c7f49f5
VZ
72
73 // this is a pseudo flag not used directly by wxRenderer but rather by some
74 // controls internally
75 wxCONTROL_DIRTY = 0x80000000
76};
77
b50d93d1
VZ
78// title bar buttons supported by DrawTitleBarBitmap()
79//
80// NB: they have the same values as wxTOPLEVEL_BUTTON_XXX constants in
81// wx/univ/toplevel.h as they really represent the same things
82enum wxTitleBarButton
83{
84 wxTITLEBAR_BUTTON_CLOSE = 0x01000000,
85 wxTITLEBAR_BUTTON_MAXIMIZE = 0x02000000,
3427bc78 86 wxTITLEBAR_BUTTON_ICONIZE = 0x04000000,
b50d93d1
VZ
87 wxTITLEBAR_BUTTON_RESTORE = 0x08000000,
88 wxTITLEBAR_BUTTON_HELP = 0x10000000
89};
90
af99040c
VZ
91// ----------------------------------------------------------------------------
92// helper structs
93// ----------------------------------------------------------------------------
94
95// wxSplitterWindow parameters
53a2db12 96struct WXDLLIMPEXP_CORE wxSplitterRenderParams
af99040c
VZ
97{
98 // the only way to initialize this struct is by using this ctor
99 wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_)
100 : widthSash(widthSash_), border(border_), isHotSensitive(isSens_)
101 {
102 }
103
104 // the width of the splitter sash
105 const wxCoord widthSash;
106
107 // the width of the border of the splitter window
108 const wxCoord border;
109
110 // true if the splitter changes its appearance when the mouse is over it
111 const bool isHotSensitive;
112};
113
4b94ddc4
RD
114
115// extra optional parameters for DrawHeaderButton
53a2db12 116struct WXDLLIMPEXP_CORE wxHeaderButtonParams
4b94ddc4
RD
117{
118 wxHeaderButtonParams()
119 : m_labelAlignment(wxALIGN_LEFT)
120 { }
0856300f 121
4b94ddc4
RD
122 wxColour m_arrowColour;
123 wxColour m_selectionColour;
124 wxString m_labelText;
125 wxFont m_labelFont;
126 wxColour m_labelColour;
127 wxBitmap m_labelBitmap;
128 int m_labelAlignment;
129};
130
1e417065
VZ
131enum wxHeaderSortIconType
132{
80752b57 133 wxHDR_SORT_ICON_NONE, // Header button has no sort arrow
1e417065
VZ
134 wxHDR_SORT_ICON_UP, // Header button an up sort arrow icon
135 wxHDR_SORT_ICON_DOWN // Header button a down sort arrow icon
80752b57
RD
136};
137
4b94ddc4 138
04857cb7 139// wxRendererNative interface version
53a2db12 140struct WXDLLIMPEXP_CORE wxRendererVersion
04857cb7
VZ
141{
142 wxRendererVersion(int version_, int age_) : version(version_), age(age_) { }
143
144 // default copy ctor, assignment operator and dtor are ok
145
146 // the current version and age of wxRendererNative interface: different
147 // versions are incompatible (in both ways) while the ages inside the same
148 // version are upwards compatible, i.e. the version of the renderer must
149 // match the version of the main program exactly while the age may be
150 // highergreater or equal to it
151 //
152 // NB: don't forget to increment age after adding any new virtual function!
153 enum
154 {
155 Current_Version = 1,
156 Current_Age = 5
157 };
158
159
160 // check if the given version is compatible with the current one
161 static bool IsCompatible(const wxRendererVersion& ver)
162 {
163 return ver.version == Current_Version && ver.age >= Current_Age;
164 }
165
166 const int version;
167 const int age;
168};
169
9c7f49f5
VZ
170// ----------------------------------------------------------------------------
171// wxRendererNative: abstracts drawing methods needed by the native controls
172// ----------------------------------------------------------------------------
173
53a2db12 174class WXDLLIMPEXP_CORE wxRendererNative
9c7f49f5
VZ
175{
176public:
177 // drawing functions
178 // -----------------
179
c97c9952
RD
180 // draw the header control button (used by wxListCtrl) Returns optimal
181 // width for the label contents.
182 virtual int DrawHeaderButton(wxWindow *win,
9c7f49f5
VZ
183 wxDC& dc,
184 const wxRect& rect,
4b94ddc4 185 int flags = 0,
80752b57 186 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4
RD
187 wxHeaderButtonParams* params=NULL) = 0;
188
189
190 // Draw the contents of a header control button (label, sort arrows, etc.)
191 // Normally only called by DrawHeaderButton.
c97c9952 192 virtual int DrawHeaderButtonContents(wxWindow *win,
4b94ddc4
RD
193 wxDC& dc,
194 const wxRect& rect,
195 int flags = 0,
80752b57 196 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4
RD
197 wxHeaderButtonParams* params=NULL) = 0;
198
199 // Returns the default height of a header button, either a fixed platform
200 // height if available, or a generic height based on the window's font.
201 virtual int GetHeaderButtonHeight(wxWindow *win) = 0;
202
9aebcb5e
VS
203 // Returns the margin on left and right sides of header button's label
204 virtual int GetHeaderButtonMargin(wxWindow *win) = 0;
205
9c7f49f5
VZ
206
207 // draw the expanded/collapsed icon for a tree control item
208 virtual void DrawTreeItemButton(wxWindow *win,
209 wxDC& dc,
210 const wxRect& rect,
211 int flags = 0) = 0;
212
b3208e11
VZ
213 // draw the border for sash window: this border must be such that the sash
214 // drawn by DrawSash() blends into it well
215 virtual void DrawSplitterBorder(wxWindow *win,
216 wxDC& dc,
af99040c
VZ
217 const wxRect& rect,
218 int flags = 0) = 0;
b3208e11
VZ
219
220 // draw a (vertical) sash
221 virtual void DrawSplitterSash(wxWindow *win,
222 wxDC& dc,
223 const wxSize& size,
62dc9cb4 224 wxCoord position,
af99040c
VZ
225 wxOrientation orient,
226 int flags = 0) = 0;
b3208e11 227
f33cef9f
VZ
228 // draw a combobox dropdown button
229 //
4c85ab75 230 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
f33cef9f
VZ
231 virtual void DrawComboBoxDropButton(wxWindow *win,
232 wxDC& dc,
233 const wxRect& rect,
234 int flags = 0) = 0;
235
4c85ab75
VZ
236 // draw a dropdown arrow
237 //
238 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
239 virtual void DrawDropArrow(wxWindow *win,
240 wxDC& dc,
241 const wxRect& rect,
242 int flags = 0) = 0;
b3208e11 243
862d8041
RR
244 // draw check button
245 //
246 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
90b903c2
WS
247 virtual void DrawCheckBox(wxWindow *win,
248 wxDC& dc,
249 const wxRect& rect,
250 int flags = 0) = 0;
2209baae 251
e8759560 252 // Returns the default size of a check box.
191e43fd 253 virtual wxSize GetCheckBoxSize(wxWindow *win) = 0;
e8759560 254
2209baae
RR
255 // draw blank button
256 //
257 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
258 virtual void DrawPushButton(wxWindow *win,
259 wxDC& dc,
260 const wxRect& rect,
261 int flags = 0) = 0;
262
daebb44c
RR
263 // draw rectangle indicating that an item in e.g. a list control
264 // has been selected or focused
265 //
0856300f 266 // flags may use
daebb44c
RR
267 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
268 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
269 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
270 virtual void DrawItemSelectionRect(wxWindow *win,
271 wxDC& dc,
272 const wxRect& rect,
273 int flags = 0) = 0;
274
6d789987
JS
275 // draw the focus rectangle around the label contained in the given rect
276 //
277 // only wxCONTROL_SELECTED makes sense in flags here
99c4be68
VZ
278 virtual void DrawFocusRect(wxWindow* win,
279 wxDC& dc,
280 const wxRect& rect,
281 int flags = 0) = 0;
6d789987 282
e4131985 283 // Draw a native wxChoice
99c4be68
VZ
284 virtual void DrawChoice(wxWindow* win,
285 wxDC& dc,
286 const wxRect& rect,
287 int flags = 0) = 0;
e4131985
KO
288
289 // Draw a native wxComboBox
99c4be68
VZ
290 virtual void DrawComboBox(wxWindow* win,
291 wxDC& dc,
292 const wxRect& rect,
293 int flags = 0) = 0;
e4131985
KO
294
295 // Draw a native wxTextCtrl frame
99c4be68
VZ
296 virtual void DrawTextCtrl(wxWindow* win,
297 wxDC& dc,
298 const wxRect& rect,
299 int flags = 0) = 0;
e4131985 300
6e6b532c
VZ
301 // Draw a native wxRadioButton bitmap
302 virtual void DrawRadioBitmap(wxWindow* win,
303 wxDC& dc,
304 const wxRect& rect,
305 int flags = 0) = 0;
e4131985 306
b50d93d1
VZ
307#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
308 // Draw one of the standard title bar buttons
309 //
3427bc78
VZ
310 // This is currently implemented only for MSW and OS X (for the close
311 // button only) because there is no way to render standard title bar
312 // buttons under the other platforms, the best can be done is to use normal
313 // (only) images which wxArtProvider provides for wxART_HELP and
314 // wxART_CLOSE (but not any other title bar buttons)
315 //
316 // NB: make sure PNG handler is enabled if using this function under OS X
b50d93d1
VZ
317 virtual void DrawTitleBarBitmap(wxWindow *win,
318 wxDC& dc,
319 const wxRect& rect,
320 wxTitleBarButton button,
321 int flags = 0) = 0;
322#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
323
324
b3208e11
VZ
325 // geometry functions
326 // ------------------
327
328 // get the splitter parameters: the x field of the returned point is the
329 // sash width and the y field is the border width
af99040c 330 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0;
b3208e11 331
9c7f49f5
VZ
332
333 // pseudo constructors
334 // -------------------
335
336 // return the currently used renderer
337 static wxRendererNative& Get();
338
339 // return the generic implementation of the renderer
340 static wxRendererNative& GetGeneric();
f0244295
VZ
341
342 // return the default (native) implementation for this platform
343 static wxRendererNative& GetDefault();
9f2be125
VZ
344
345
346 // changing the global renderer
347 // ----------------------------
348
349#if wxUSE_DYNLIB_CLASS
350 // load the renderer from the specified DLL, the returned pointer must be
351 // deleted by caller if not NULL when it is not used any more
352 static wxRendererNative *Load(const wxString& name);
353#endif // wxUSE_DYNLIB_CLASS
354
355 // set the renderer to use, passing NULL reverts to using the default
356 // renderer
357 //
358 // return the previous renderer used with Set() or NULL if none
359 static wxRendererNative *Set(wxRendererNative *renderer);
04857cb7
VZ
360
361
362 // miscellaneous stuff
363 // -------------------
364
365 // this function is used for version checking: Load() refuses to load any
366 // DLLs implementing an older or incompatible version; it should be
367 // implemented simply by returning wxRendererVersion::Current_XXX values
368 virtual wxRendererVersion GetVersion() const = 0;
369
370 // virtual dtor for any base class
371 virtual ~wxRendererNative();
9c7f49f5
VZ
372};
373
374// ----------------------------------------------------------------------------
375// wxDelegateRendererNative: allows reuse of renderers code
376// ----------------------------------------------------------------------------
377
53a2db12 378class WXDLLIMPEXP_CORE wxDelegateRendererNative : public wxRendererNative
9c7f49f5
VZ
379{
380public:
381 wxDelegateRendererNative()
382 : m_rendererNative(GetGeneric()) { }
383
384 wxDelegateRendererNative(wxRendererNative& rendererNative)
385 : m_rendererNative(rendererNative) { }
386
387
c97c9952 388 virtual int DrawHeaderButton(wxWindow *win,
9c7f49f5
VZ
389 wxDC& dc,
390 const wxRect& rect,
4b94ddc4 391 int flags = 0,
80752b57 392 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 393 wxHeaderButtonParams* params = NULL)
c97c9952 394 { return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
0856300f 395
c97c9952 396 virtual int DrawHeaderButtonContents(wxWindow *win,
4b94ddc4
RD
397 wxDC& dc,
398 const wxRect& rect,
399 int flags = 0,
80752b57 400 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 401 wxHeaderButtonParams* params = NULL)
c97c9952 402 { return m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); }
0856300f 403
4b94ddc4
RD
404 virtual int GetHeaderButtonHeight(wxWindow *win)
405 { return m_rendererNative.GetHeaderButtonHeight(win); }
b3208e11 406
9aebcb5e
VS
407 virtual int GetHeaderButtonMargin(wxWindow *win)
408 { return m_rendererNative.GetHeaderButtonMargin(win); }
409
9c7f49f5
VZ
410 virtual void DrawTreeItemButton(wxWindow *win,
411 wxDC& dc,
412 const wxRect& rect,
413 int flags = 0)
414 { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); }
415
b3208e11
VZ
416 virtual void DrawSplitterBorder(wxWindow *win,
417 wxDC& dc,
af99040c
VZ
418 const wxRect& rect,
419 int flags = 0)
2c0e6de1 420 { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); }
b3208e11
VZ
421
422 virtual void DrawSplitterSash(wxWindow *win,
423 wxDC& dc,
424 const wxSize& size,
62dc9cb4 425 wxCoord position,
af99040c
VZ
426 wxOrientation orient,
427 int flags = 0)
2c0e6de1
VZ
428 { m_rendererNative.DrawSplitterSash(win, dc, size,
429 position, orient, flags); }
b3208e11 430
f33cef9f
VZ
431 virtual void DrawComboBoxDropButton(wxWindow *win,
432 wxDC& dc,
433 const wxRect& rect,
434 int flags = 0)
435 { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); }
436
4c85ab75
VZ
437 virtual void DrawDropArrow(wxWindow *win,
438 wxDC& dc,
439 const wxRect& rect,
440 int flags = 0)
441 { m_rendererNative.DrawDropArrow(win, dc, rect, flags); }
b3208e11 442
90b903c2
WS
443 virtual void DrawCheckBox(wxWindow *win,
444 wxDC& dc,
445 const wxRect& rect,
99c4be68 446 int flags = 0)
90b903c2 447 { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); }
2209baae 448
191e43fd
FM
449 virtual wxSize GetCheckBoxSize(wxWindow *win)
450 { return m_rendererNative.GetCheckBoxSize(win); }
e8759560 451
2209baae
RR
452 virtual void DrawPushButton(wxWindow *win,
453 wxDC& dc,
454 const wxRect& rect,
99c4be68 455 int flags = 0)
2209baae
RR
456 { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
457
daebb44c
RR
458 virtual void DrawItemSelectionRect(wxWindow *win,
459 wxDC& dc,
460 const wxRect& rect,
99c4be68 461 int flags = 0)
daebb44c
RR
462 { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); }
463
99c4be68
VZ
464 virtual void DrawFocusRect(wxWindow* win,
465 wxDC& dc,
466 const wxRect& rect,
467 int flags = 0)
6d789987
JS
468 { m_rendererNative.DrawFocusRect( win, dc, rect, flags ); }
469
99c4be68
VZ
470 virtual void DrawChoice(wxWindow* win,
471 wxDC& dc,
472 const wxRect& rect,
473 int flags = 0)
e4131985
KO
474 { m_rendererNative.DrawChoice( win, dc, rect, flags); }
475
99c4be68
VZ
476 virtual void DrawComboBox(wxWindow* win,
477 wxDC& dc,
478 const wxRect& rect,
479 int flags = 0)
e4131985
KO
480 { m_rendererNative.DrawComboBox( win, dc, rect, flags); }
481
99c4be68
VZ
482 virtual void DrawTextCtrl(wxWindow* win,
483 wxDC& dc,
484 const wxRect& rect,
485 int flags = 0)
e4131985
KO
486 { m_rendererNative.DrawTextCtrl( win, dc, rect, flags); }
487
6e6b532c
VZ
488 virtual void DrawRadioBitmap(wxWindow* win,
489 wxDC& dc,
490 const wxRect& rect,
491 int flags = 0)
492 { m_rendererNative.DrawRadioBitmap(win, dc, rect, flags); }
e4131985 493
b50d93d1
VZ
494#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
495 virtual void DrawTitleBarBitmap(wxWindow *win,
496 wxDC& dc,
497 const wxRect& rect,
498 wxTitleBarButton button,
499 int flags = 0)
500 { m_rendererNative.DrawTitleBarBitmap(win, dc, rect, button, flags); }
501#endif // wxHAS_DRAW_TITLE_BAR_BITMAP
502
af99040c
VZ
503 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
504 { return m_rendererNative.GetSplitterParams(win); }
b3208e11 505
04857cb7
VZ
506 virtual wxRendererVersion GetVersion() const
507 { return m_rendererNative.GetVersion(); }
508
9c7f49f5
VZ
509protected:
510 wxRendererNative& m_rendererNative;
fc7a2a60 511
c0c133e1 512 wxDECLARE_NO_COPY_CLASS(wxDelegateRendererNative);
9c7f49f5
VZ
513};
514
f0244295
VZ
515// ----------------------------------------------------------------------------
516// inline functions implementation
517// ----------------------------------------------------------------------------
518
519#ifndef wxHAS_NATIVE_RENDERER
520
521// default native renderer is the generic one then
522/* static */ inline
523wxRendererNative& wxRendererNative::GetDefault()
524{
525 return GetGeneric();
526}
527
528#endif // !wxHAS_NATIVE_RENDERER
529
9c7f49f5 530#endif // _WX_RENDERER_H_