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