]> git.saurik.com Git - wxWidgets.git/blame - include/wx/renderer.h
add a radio box to select the combobox type (#9845)
[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
9c7f49f5
VZ
44// ----------------------------------------------------------------------------
45// constants
46// ----------------------------------------------------------------------------
47
48// control state flags used in wxRenderer and wxColourScheme
49enum
50{
51 wxCONTROL_DISABLED = 0x00000001, // control is disabled
52 wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus
53 wxCONTROL_PRESSED = 0x00000004, // (button) is pressed
fb61f58a
VZ
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
8a461249 59 wxCONTROL_FLAT = wxCONTROL_SPECIAL, // checkboxes only: flat border
9c7f49f5
VZ
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
415a0ff1 64 wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
9c7f49f5 65
a61c9122 66 wxCONTROL_FLAGS_MASK = 0x000000ff,
9c7f49f5
VZ
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
af99040c
VZ
73// ----------------------------------------------------------------------------
74// helper structs
75// ----------------------------------------------------------------------------
76
77// wxSplitterWindow parameters
53a2db12 78struct WXDLLIMPEXP_CORE wxSplitterRenderParams
af99040c
VZ
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
4b94ddc4
RD
96
97// extra optional parameters for DrawHeaderButton
53a2db12 98struct WXDLLIMPEXP_CORE wxHeaderButtonParams
4b94ddc4
RD
99{
100 wxHeaderButtonParams()
101 : m_labelAlignment(wxALIGN_LEFT)
102 { }
0856300f 103
4b94ddc4
RD
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
80752b57
RD
113enum 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
4b94ddc4 119
04857cb7 120// wxRendererNative interface version
53a2db12 121struct WXDLLIMPEXP_CORE wxRendererVersion
04857cb7
VZ
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
9c7f49f5
VZ
151// ----------------------------------------------------------------------------
152// wxRendererNative: abstracts drawing methods needed by the native controls
153// ----------------------------------------------------------------------------
154
53a2db12 155class WXDLLIMPEXP_CORE wxRendererNative
9c7f49f5
VZ
156{
157public:
158 // drawing functions
159 // -----------------
160
c97c9952
RD
161 // draw the header control button (used by wxListCtrl) Returns optimal
162 // width for the label contents.
163 virtual int DrawHeaderButton(wxWindow *win,
9c7f49f5
VZ
164 wxDC& dc,
165 const wxRect& rect,
4b94ddc4 166 int flags = 0,
80752b57 167 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4
RD
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.
c97c9952 173 virtual int DrawHeaderButtonContents(wxWindow *win,
4b94ddc4
RD
174 wxDC& dc,
175 const wxRect& rect,
176 int flags = 0,
80752b57 177 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4
RD
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
9c7f49f5
VZ
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
b3208e11
VZ
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,
af99040c
VZ
195 const wxRect& rect,
196 int flags = 0) = 0;
b3208e11
VZ
197
198 // draw a (vertical) sash
199 virtual void DrawSplitterSash(wxWindow *win,
200 wxDC& dc,
201 const wxSize& size,
62dc9cb4 202 wxCoord position,
af99040c
VZ
203 wxOrientation orient,
204 int flags = 0) = 0;
b3208e11 205
f33cef9f
VZ
206 // draw a combobox dropdown button
207 //
4c85ab75 208 // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
f33cef9f
VZ
209 virtual void DrawComboBoxDropButton(wxWindow *win,
210 wxDC& dc,
211 const wxRect& rect,
212 int flags = 0) = 0;
213
4c85ab75
VZ
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;
b3208e11 221
862d8041
RR
222 // draw check button
223 //
224 // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
90b903c2
WS
225 virtual void DrawCheckBox(wxWindow *win,
226 wxDC& dc,
227 const wxRect& rect,
228 int flags = 0) = 0;
2209baae 229
e8759560
VZ
230 // Returns the default size of a check box.
231 virtual wxSize GetCheckBoxSize(wxWindow *win) = 0;
232
2209baae
RR
233 // draw blank button
234 //
235 // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
236 virtual void DrawPushButton(wxWindow *win,
237 wxDC& dc,
238 const wxRect& rect,
239 int flags = 0) = 0;
240
daebb44c
RR
241 // draw rectangle indicating that an item in e.g. a list control
242 // has been selected or focused
243 //
0856300f 244 // flags may use
daebb44c
RR
245 // wxCONTROL_SELECTED (item is selected, e.g. draw background)
246 // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
247 // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
248 virtual void DrawItemSelectionRect(wxWindow *win,
249 wxDC& dc,
250 const wxRect& rect,
251 int flags = 0) = 0;
252
6d789987
JS
253 // draw the focus rectangle around the label contained in the given rect
254 //
255 // only wxCONTROL_SELECTED makes sense in flags here
256 virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0) = 0;
257
b3208e11
VZ
258 // geometry functions
259 // ------------------
260
261 // get the splitter parameters: the x field of the returned point is the
262 // sash width and the y field is the border width
af99040c 263 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0;
b3208e11 264
9c7f49f5
VZ
265
266 // pseudo constructors
267 // -------------------
268
269 // return the currently used renderer
270 static wxRendererNative& Get();
271
272 // return the generic implementation of the renderer
273 static wxRendererNative& GetGeneric();
f0244295
VZ
274
275 // return the default (native) implementation for this platform
276 static wxRendererNative& GetDefault();
9f2be125
VZ
277
278
279 // changing the global renderer
280 // ----------------------------
281
282#if wxUSE_DYNLIB_CLASS
283 // load the renderer from the specified DLL, the returned pointer must be
284 // deleted by caller if not NULL when it is not used any more
285 static wxRendererNative *Load(const wxString& name);
286#endif // wxUSE_DYNLIB_CLASS
287
288 // set the renderer to use, passing NULL reverts to using the default
289 // renderer
290 //
291 // return the previous renderer used with Set() or NULL if none
292 static wxRendererNative *Set(wxRendererNative *renderer);
04857cb7
VZ
293
294
295 // miscellaneous stuff
296 // -------------------
297
298 // this function is used for version checking: Load() refuses to load any
299 // DLLs implementing an older or incompatible version; it should be
300 // implemented simply by returning wxRendererVersion::Current_XXX values
301 virtual wxRendererVersion GetVersion() const = 0;
302
303 // virtual dtor for any base class
304 virtual ~wxRendererNative();
9c7f49f5
VZ
305};
306
307// ----------------------------------------------------------------------------
308// wxDelegateRendererNative: allows reuse of renderers code
309// ----------------------------------------------------------------------------
310
53a2db12 311class WXDLLIMPEXP_CORE wxDelegateRendererNative : public wxRendererNative
9c7f49f5
VZ
312{
313public:
314 wxDelegateRendererNative()
315 : m_rendererNative(GetGeneric()) { }
316
317 wxDelegateRendererNative(wxRendererNative& rendererNative)
318 : m_rendererNative(rendererNative) { }
319
320
c97c9952 321 virtual int DrawHeaderButton(wxWindow *win,
9c7f49f5
VZ
322 wxDC& dc,
323 const wxRect& rect,
4b94ddc4 324 int flags = 0,
80752b57 325 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 326 wxHeaderButtonParams* params = NULL)
c97c9952 327 { return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
0856300f 328
c97c9952 329 virtual int DrawHeaderButtonContents(wxWindow *win,
4b94ddc4
RD
330 wxDC& dc,
331 const wxRect& rect,
332 int flags = 0,
80752b57 333 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 334 wxHeaderButtonParams* params = NULL)
c97c9952 335 { return m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); }
0856300f 336
4b94ddc4
RD
337 virtual int GetHeaderButtonHeight(wxWindow *win)
338 { return m_rendererNative.GetHeaderButtonHeight(win); }
b3208e11 339
9c7f49f5
VZ
340 virtual void DrawTreeItemButton(wxWindow *win,
341 wxDC& dc,
342 const wxRect& rect,
343 int flags = 0)
344 { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); }
345
b3208e11
VZ
346 virtual void DrawSplitterBorder(wxWindow *win,
347 wxDC& dc,
af99040c
VZ
348 const wxRect& rect,
349 int flags = 0)
2c0e6de1 350 { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); }
b3208e11
VZ
351
352 virtual void DrawSplitterSash(wxWindow *win,
353 wxDC& dc,
354 const wxSize& size,
62dc9cb4 355 wxCoord position,
af99040c
VZ
356 wxOrientation orient,
357 int flags = 0)
2c0e6de1
VZ
358 { m_rendererNative.DrawSplitterSash(win, dc, size,
359 position, orient, flags); }
b3208e11 360
f33cef9f
VZ
361 virtual void DrawComboBoxDropButton(wxWindow *win,
362 wxDC& dc,
363 const wxRect& rect,
364 int flags = 0)
365 { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); }
366
4c85ab75
VZ
367 virtual void DrawDropArrow(wxWindow *win,
368 wxDC& dc,
369 const wxRect& rect,
370 int flags = 0)
371 { m_rendererNative.DrawDropArrow(win, dc, rect, flags); }
b3208e11 372
90b903c2
WS
373 virtual void DrawCheckBox(wxWindow *win,
374 wxDC& dc,
375 const wxRect& rect,
376 int flags = 0 )
377 { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); }
2209baae 378
e8759560
VZ
379 virtual wxSize GetCheckBoxSize(wxWindow *win)
380 { return m_rendererNative.GetCheckBoxSize(win); }
381
2209baae
RR
382 virtual void DrawPushButton(wxWindow *win,
383 wxDC& dc,
384 const wxRect& rect,
385 int flags = 0 )
386 { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
387
daebb44c
RR
388 virtual void DrawItemSelectionRect(wxWindow *win,
389 wxDC& dc,
390 const wxRect& rect,
391 int flags = 0 )
392 { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); }
393
6d789987
JS
394 virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0)
395 { m_rendererNative.DrawFocusRect( win, dc, rect, flags ); }
396
af99040c
VZ
397 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
398 { return m_rendererNative.GetSplitterParams(win); }
b3208e11 399
04857cb7
VZ
400 virtual wxRendererVersion GetVersion() const
401 { return m_rendererNative.GetVersion(); }
402
9c7f49f5
VZ
403protected:
404 wxRendererNative& m_rendererNative;
fc7a2a60
VZ
405
406 DECLARE_NO_COPY_CLASS(wxDelegateRendererNative)
9c7f49f5
VZ
407};
408
f0244295
VZ
409// ----------------------------------------------------------------------------
410// inline functions implementation
411// ----------------------------------------------------------------------------
412
413#ifndef wxHAS_NATIVE_RENDERER
414
415// default native renderer is the generic one then
416/* static */ inline
417wxRendererNative& wxRendererNative::GetDefault()
418{
419 return GetGeneric();
420}
421
422#endif // !wxHAS_NATIVE_RENDERER
423
9c7f49f5 424#endif // _WX_RENDERER_H_