1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     interface of wxRendererNative 
   4 // Author:      wxWidgets team 
   5 // Licence:     wxWindows licence 
   6 ///////////////////////////////////////////////////////////////////////////// 
   9     @anchor wxCONTROL_FLAGS 
  11     The following rendering flags are defined for wxRendererNative: 
  15     /** Control is disabled. */ 
  16     wxCONTROL_DISABLED   
= 0x00000001, 
  18     /** Currently has keyboard focus. */ 
  19     wxCONTROL_FOCUSED    
= 0x00000002, 
  21     /** (Button) is pressed. */ 
  22     wxCONTROL_PRESSED    
= 0x00000004, 
  24     /** Control-specific bit. */ 
  25     wxCONTROL_SPECIAL    
= 0x00000008, 
  27     /** Only for the buttons. */ 
  28     wxCONTROL_ISDEFAULT  
= wxCONTROL_SPECIAL
, 
  30     /** Only for the menu items. */ 
  31     wxCONTROL_ISSUBMENU  
= wxCONTROL_SPECIAL
, 
  33     /** Only for the tree items. */ 
  34     wxCONTROL_EXPANDED   
= wxCONTROL_SPECIAL
, 
  36     /** Only for the status bar panes. */ 
  37     wxCONTROL_SIZEGRIP   
= wxCONTROL_SPECIAL
, 
  39     /** Checkboxes only: flat border. */ 
  40     wxCONTROL_FLAT       
= wxCONTROL_SPECIAL
, 
  42     /** Mouse is currently over the control. */ 
  43     wxCONTROL_CURRENT    
= 0x00000010, 
  45     /** Selected item in e.g.\ listbox. */ 
  46     wxCONTROL_SELECTED   
= 0x00000020, 
  48     /** (Check/radio button) is checked. */ 
  49     wxCONTROL_CHECKED    
= 0x00000040, 
  51     /** (Menu) item can be checked. */ 
  52     wxCONTROL_CHECKABLE  
= 0x00000080, 
  54     /** (Check) undetermined state. */ 
  55     wxCONTROL_UNDETERMINED 
= wxCONTROL_CHECKABLE
 
  59     Title bar buttons supported by wxRendererNative::DrawTitleBarBitmap(). 
  63     wxTITLEBAR_BUTTON_CLOSE    
= 0x01000000, 
  64     wxTITLEBAR_BUTTON_MAXIMIZE 
= 0x02000000, 
  65     wxTITLEBAR_BUTTON_ICONIZE  
= 0x04000000, 
  66     wxTITLEBAR_BUTTON_RESTORE  
= 0x08000000, 
  67     wxTITLEBAR_BUTTON_HELP     
= 0x10000000 
  71     @struct wxSplitterRenderParams 
  73     This is just a simple @c struct used as a return value of 
  74     wxRendererNative::GetSplitterParams(). 
  76     It doesn't have any methods and all of its fields are constant, so they can 
  77     only be examined but not modified. 
  82 struct wxSplitterRenderParams
 
  85         The only way to initialize this struct is by using this ctor. 
  87     wxSplitterRenderParams(wxCoord widthSash_
, wxCoord border_
, bool isSens_
); 
  90         The width of the border drawn by the splitter inside it, may be 0. 
  95         @true if the sash changes appearance when the mouse passes over it, @false 
  98     const bool isHotSensitive
; 
 101         The width of the splitter sash. 
 103     const wxCoord widthSash
; 
 107     @struct wxHeaderButtonParams 
 109     This @c struct can optionally be used with 
 110     wxRendererNative::DrawHeaderButton() to specify custom values used to draw 
 111     the text or bitmap label. 
 116 struct wxHeaderButtonParams
 
 118     wxHeaderButtonParams(); 
 120     wxColour    m_arrowColour
; 
 121     wxColour    m_selectionColour
; 
 122     wxString    m_labelText
; 
 124     wxColour    m_labelColour
; 
 125     wxBitmap    m_labelBitmap
; 
 126     int         m_labelAlignment
; 
 130     Used to specify the type of sort arrow used with 
 131     wxRendererNative::DrawHeaderButton(). 
 133 enum wxHeaderSortIconType
 
 135     wxHDR_SORT_ICON_NONE
,    ///< Don't draw a sort arrow. 
 136     wxHDR_SORT_ICON_UP
,      ///< Draw a sort arrow icon pointing up. 
 137     wxHDR_SORT_ICON_DOWN     
///< Draw a sort arrow icon pointing down. 
 143     @class wxDelegateRendererNative 
 145     wxDelegateRendererNative allows reuse of renderers code by forwarding all the 
 146     wxRendererNative methods to the given object and 
 147     thus allowing you to only modify some of its methods -- without having to 
 148     reimplement all of them. 
 150     Note that the "normal", inheritance-based approach, doesn't work with the 
 151     renderers as it is impossible to derive from a class unknown at compile-time 
 152     and the renderer is only chosen at run-time. So suppose that you want to only 
 153     add something to the drawing of the tree control buttons but leave all the 
 154     other methods unchanged -- the only way to do it, considering that the renderer 
 155     class which you want to customize might not even be written yet when you write 
 156     your code (it could be written later and loaded from a DLL during run-time), is 
 159     Except for the constructor, it has exactly the same methods as 
 160     wxRendererNative and their implementation is 
 161     trivial: they are simply forwarded to the real renderer. Note that the "real" 
 162     renderer may, in turn, be a wxDelegateRendererNative as well and that there may 
 163     be arbitrarily many levels like this -- but at the end of the chain there must 
 164     be a real renderer which does the drawing. 
 169     @see wxRendererNative 
 171 class wxDelegateRendererNative 
: public wxRendererNative
 
 175         The default constructor does the same thing as the other one except that it 
 176         uses the @ref wxRendererNative::GetGeneric() "generic renderer" instead of the 
 177         user-specified @a rendererNative. 
 179         In any case, this sets up the delegate renderer object to follow all calls to 
 180         the specified real renderer. 
 182     wxDelegateRendererNative(); 
 184         This constructor uses the user-specified @a rendererNative to set up the delegate 
 185         renderer object to follow all calls to the specified real renderer. 
 188         This object does not take ownership of (i.e. won't delete) @a rendererNative. 
 190     wxDelegateRendererNative(wxRendererNative
& rendererNative
); 
 192     // The rest of these functions inherit the documentation from wxRendererNative 
 194     virtual int DrawHeaderButton(wxWindow 
*win
, wxDC
& dc
, 
 195                                  const wxRect
& rect
, int flags 
= 0, 
 196                                  wxHeaderSortIconType sortArrow 
= wxHDR_SORT_ICON_NONE
, 
 197                                  wxHeaderButtonParams
* params 
= NULL
); 
 199     virtual int DrawHeaderButtonContents(wxWindow 
*win
, wxDC
& dc
, 
 200                                          const wxRect
& rect
, int flags 
= 0, 
 201                                          wxHeaderSortIconType sortArrow 
= wxHDR_SORT_ICON_NONE
, 
 202                                          wxHeaderButtonParams
* params 
= NULL
); 
 204     virtual int GetHeaderButtonHeight(wxWindow 
*win
); 
 206     virtual int GetHeaderButtonMargin(wxWindow 
*win
); 
 208     virtual void DrawTreeItemButton(wxWindow 
*win
, wxDC
& dc
, 
 209                                     const wxRect
& rect
, int flags 
= 0); 
 211     virtual void DrawSplitterBorder(wxWindow 
*win
, wxDC
& dc
, 
 212                                     const wxRect
& rect
, int flags 
= 0); 
 214     virtual void DrawSplitterSash(wxWindow 
*win
, wxDC
& dc
, 
 215                                   const wxSize
& size
, wxCoord position
, 
 216                                   wxOrientation orient
, int flags 
= 0); 
 218     virtual void DrawComboBoxDropButton(wxWindow 
*win
, wxDC
& dc
, 
 219                                         const wxRect
& rect
, int flags 
= 0); 
 221     virtual void DrawDropArrow(wxWindow 
*win
, wxDC
& dc
, 
 222                                const wxRect
& rect
, int flags 
= 0); 
 224     virtual void DrawCheckBox(wxWindow 
*win
, wxDC
& dc
, 
 225                               const wxRect
& rect
, int flags 
= 0 ); 
 227     virtual wxSize 
GetCheckBoxSize(wxWindow 
*win
); 
 229     virtual void DrawPushButton(wxWindow 
*win
, wxDC
& dc
, 
 230                                 const wxRect
& rect
, int flags 
= 0 ); 
 232     virtual void DrawItemSelectionRect(wxWindow 
*win
, wxDC
& dc
, 
 233                                        const wxRect
& rect
, int flags 
= 0 ); 
 235     virtual void DrawFocusRect(wxWindow
* win
, wxDC
& dc
, 
 236                                const wxRect
& rect
, int flags 
= 0); 
 238     virtual wxSplitterRenderParams 
GetSplitterParams(const wxWindow 
*win
); 
 240     virtual wxRendererVersion 
GetVersion() const; 
 246     @class wxRendererNative 
 248     First, a brief introduction to wxRendererNative and why it is needed. 
 250     Usually wxWidgets uses the underlying low level GUI system to draw all the 
 251     controls - this is what we mean when we say that it is a "native" framework. 
 252     However not all controls exist under all (or even any) platforms and in this 
 253     case wxWidgets provides a default, generic, implementation of them written in 
 256     These controls don't have the native appearance if only the standard 
 257     line drawing and other graphics primitives are used, because the native 
 258     appearance is different under different platforms while the lines are always 
 259     drawn in the same way. 
 261     This is why we have renderers: wxRendererNative is a class which virtualizes the 
 262     drawing, i.e. it abstracts the drawing operations and allows you to draw say, a 
 263     button, without caring about exactly how this is done. Of course, as we 
 264     can draw the button differently in different renderers, this also allows us to 
 265     emulate the native look and feel. 
 267     So the renderers work by exposing a large set of high-level drawing functions 
 268     which are used by the generic controls. There is always a default global 
 269     renderer but it may be changed or extended by the user, see 
 270     @ref page_samples_render. 
 272     All drawing functions take some standard parameters: 
 274     @li @a win - The window being drawn. It is normally not used and when 
 275     it is it should only be used as a generic wxWindow 
 276     (in order to get its low level handle, for example), but you should 
 277     not assume that it is of some given type as the same renderer 
 278     function may be reused for drawing different kinds of control. 
 279     @li @a dc - The wxDC to draw on. Only this device 
 280     context should be used for drawing. It is not necessary to restore 
 281     pens and brushes for it on function exit but, on the other hand, you 
 282     shouldn't assume that it is in any specific state on function entry: 
 283     the rendering functions should always prepare it. 
 284     @li @a rect - The bounding rectangle for the element to be drawn. 
 285     @li @a flags - The optional flags (none by default) which can be a 
 286     combination of the @ref wxCONTROL_FLAGS. 
 288     Note that each drawing function restores the wxDC attributes if 
 289     it changes them, so it is safe to assume that the same pen, brush and colours 
 290     that were active before the call to this function are still in effect after it. 
 295 class wxRendererNative
 
 299         Virtual destructor as for any base class. 
 301     virtual ~wxRendererNative(); 
 306         @a flags may have the @c wxCONTROL_CHECKED, @c wxCONTROL_CURRENT or 
 307         @c wxCONTROL_UNDETERMINED bit set, see @ref wxCONTROL_FLAGS. 
 309     virtual void DrawCheckBox(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, 
 313         Draw a button like the one used by wxComboBox to show a 
 314         drop down window. The usual appearance is a downwards pointing arrow. 
 316         @a flags may have the @c wxCONTROL_PRESSED or @c wxCONTROL_CURRENT bit set, 
 317         see @ref wxCONTROL_FLAGS. 
 319     virtual void DrawComboBoxDropButton(wxWindow
* win
, wxDC
& dc
, 
 320                                         const wxRect
& rect
, int flags 
= 0) = 0; 
 323         Draw a drop down arrow that is suitable for use outside a combo box. Arrow will 
 324         have transparent background. 
 326         @a rect is not entirely filled by the arrow. Instead, you should use bounding 
 327         rectangle of a drop down button which arrow matches the size you need. 
 329         @a flags may have the @c wxCONTROL_PRESSED or @c wxCONTROL_CURRENT bit set, 
 330         see @ref wxCONTROL_FLAGS. 
 332     virtual void DrawDropArrow(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, 
 336         Draw a focus rectangle using the specified rectangle. 
 339         The only supported flags is @c wxCONTROL_SELECTED for items which are selected. 
 340         see @ref wxCONTROL_FLAGS. 
 342     virtual void DrawFocusRect(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, 
 346         Draw the header control button (used, for example, by wxListCtrl). 
 348         Depending on platforms the @a flags parameter may support the @c wxCONTROL_SELECTED 
 349         @c wxCONTROL_DISABLED and @c wxCONTROL_CURRENT bits, see @ref wxCONTROL_FLAGS. 
 352         The optimal width to contain the unabbreviated label text or 
 353         bitmap, the sort arrow if present, and internal margins. 
 355     virtual int DrawHeaderButton(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, 
 357                                  wxHeaderSortIconType sortArrow 
= wxHDR_SORT_ICON_NONE
, wxHeaderButtonParams
* params 
= NULL
) = 0; 
 360         Draw the contents of a header control button (label, sort arrows, 
 361         etc.). This function is normally only called by DrawHeaderButton(). 
 363         Depending on platforms the @a flags parameter may support the @c wxCONTROL_SELECTED 
 364         @c wxCONTROL_DISABLED and @c wxCONTROL_CURRENT bits, see @ref wxCONTROL_FLAGS. 
 367         The optimal width to contain the unabbreviated label text or 
 368         bitmap, the sort arrow if present, and internal margins. 
 370     virtual int DrawHeaderButtonContents(wxWindow
* win
, wxDC
& dc
, 
 371                                          const wxRect
& rect
, int flags 
= 0, 
 372                                          wxHeaderSortIconType sortArrow 
= wxHDR_SORT_ICON_NONE
, wxHeaderButtonParams
* params 
= NULL
) = 0; 
 375         Draw a selection rectangle underneath the text as used e.g. in a 
 378         The supported @a flags are @c wxCONTROL_SELECTED for items 
 379         which are selected (e.g. often a blue rectangle) and @c wxCONTROL_CURRENT 
 380         for the item that has the focus (often a dotted line around the item's text). 
 381         @c wxCONTROL_FOCUSED may be used to indicate if the control has the focus 
 382         (otherwise the selection rectangle is e.g. often grey and not blue). 
 383         This may be ignored by the renderer or deduced by the code directly from 
 386     virtual void DrawItemSelectionRect(wxWindow
* win
, wxDC
& dc
, 
 387                                        const wxRect
& rect
, int flags 
= 0) = 0; 
 390         Draw a blank push button that looks very similar to wxButton. 
 392         @a flags may have the @c wxCONTROL_PRESSED, @c wxCONTROL_CURRENT or 
 393         @c wxCONTROL_ISDEFAULT bit set, see @ref wxCONTROL_FLAGS. 
 395     virtual void DrawPushButton(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, 
 399         Draw the border for sash window: this border must be such that the sash 
 400         drawn by DrawSplitterSash() blends into it well. 
 402     virtual void DrawSplitterBorder(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, 
 406         Draw a sash. The @a orient parameter defines whether the sash should be 
 407         vertical or horizontal and how the @a position should be interpreted. 
 409     virtual void DrawSplitterSash(wxWindow
* win
, wxDC
& dc
, const wxSize
& size
, 
 410                                   wxCoord position
, wxOrientation orient
, 
 414         Draw the expanded/collapsed icon for a tree control item. 
 416         To draw an expanded button the @a flags parameter must contain @c wxCONTROL_EXPANDED bit, 
 417         see @ref wxCONTROL_FLAGS. 
 419     virtual void DrawTreeItemButton(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, 
 423         Draw a native wxChoice 
 425     virtual void DrawChoice(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags 
= 0) = 0; 
 428         Draw a native wxComboBox 
 430     virtual void DrawComboBox(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags 
= 0) = 0; 
 433         Draw a native wxTextCtrl frame 
 435     virtual void DrawTextCtrl(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags 
= 0) = 0; 
 438         Draw a native wxRadioButton bitmap. 
 440     virtual void DrawRadioBitmap(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags 
= 0) = 0; 
 443         Draw a title bar button in the given state. 
 445         This function is currently only available under MSW and OS X (and only 
 446         for wxTITLEBAR_BUTTON_CLOSE under the latter), its best replacement for 
 447         the other platforms is to use wxArtProvider to retrieve the bitmaps for 
 448         @c wxART_HELP and @c wxART_CLOSE (but not any other title bar buttons 
 449         and not for any state but normal, i.e. not pressed and not current one). 
 451         The presence of this function is indicated by @c 
 452         wxHAS_DRAW_TITLE_BAR_BITMAP symbol being defined. 
 454         Also notice that PNG handler must be enabled using wxImage::AddHandler() 
 455         to use this function under OS X currently as the bitmaps are embedded 
 456         in the library itself in PNG format. 
 460     virtual void DrawTitleBarBitmap(wxWindow 
*win
, 
 463                                     wxTitleBarButton button
, 
 467         Return the currently used renderer. 
 469     static wxRendererNative
& Get(); 
 472         Return the default (native) implementation for this platform -- this is also 
 473         the one used by default but this may be changed by calling 
 474         Set() in which case the return value of this 
 475         method may be different from the return value of Get(). 
 477     static wxRendererNative
& GetDefault(); 
 480         Return the generic implementation of the renderer. Under some platforms, this 
 481         is the default renderer implementation, others have platform-specific default 
 482         renderer which can be retrieved by calling GetDefault(). 
 484     static wxRendererNative
& GetGeneric(); 
 487         Returns the size of a check box. 
 488         The @a win parameter is not used currently and can be @NULL. 
 490     virtual wxSize 
GetCheckBoxSize(wxWindow
* win
) = 0; 
 493         Returns the height of a header button, either a fixed platform height if 
 494         available, or a generic height based on the @a win window's font. 
 496     virtual int GetHeaderButtonHeight(wxWindow
* win
) = 0; 
 499         Returns the horizontal margin on the left and right sides of header 
 504     virtual int GetHeaderButtonMargin(wxWindow 
*win
) = 0; 
 507         Get the splitter parameters, see wxSplitterRenderParams. 
 508         The @a win parameter should be a wxSplitterWindow. 
 510     virtual wxSplitterRenderParams 
GetSplitterParams(const wxWindow
* win
) = 0; 
 513         This function is used for version checking: Load() 
 514         refuses to load any shared libraries implementing an older or incompatible 
 518         The implementation of this method is always the same in all renderers (simply 
 519         construct wxRendererVersion using the @c wxRendererVersion::Current_XXX values), 
 520         but it has to be in the derived, not base, class, to detect mismatches between 
 521         the renderers versions and so you have to implement it anew in all renderers. 
 523     virtual wxRendererVersion 
GetVersion() const = 0; 
 526         Load the renderer from the specified DLL, the returned pointer must be 
 527         deleted by caller if not @NULL when it is not used any more. 
 529         The @a name should be just the base name of the renderer and not the full 
 530         name of the DLL file which is constructed differently (using 
 531         wxDynamicLibrary::CanonicalizePluginName()) 
 532         on different systems. 
 534     static wxRendererNative
* Load(const wxString
& name
); 
 537         Set the renderer to use, passing @NULL reverts to using the default 
 538         renderer (the global renderer must always exist). 
 540         Return the previous renderer used with Set() or @NULL if none. 
 542     static wxRendererNative
* Set(wxRendererNative
* renderer
); 
 548     @struct wxRendererVersion 
 550     This simple struct represents the wxRendererNative 
 551     interface version and is only used as the return value of 
 552     wxRendererNative::GetVersion(). 
 554     The version has two components: the version itself and the age. If the main 
 555     program and the renderer have different versions they are never compatible with 
 556     each other because the version is only changed when an existing virtual 
 557     function is modified or removed. The age, on the other hand, is incremented 
 558     each time a new virtual method is added and so, at least for the compilers 
 559     using a common C++ object model, the calling program is compatible with any 
 560     renderer which has the age greater or equal to its age. This verification is 
 561     done by IsCompatible() method. 
 566 struct wxRendererVersion
 
 568     wxRendererVersion(int version_
, int age_
); 
 571         Checks if the main program is compatible with the renderer having the version 
 572         @e ver, returns @true if it is and @false otherwise. 
 574         This method is used by wxRendererNative::Load() to determine whether a 
 575         renderer can be used. 
 577     static bool IsCompatible(const wxRendererVersion
& ver
); 
 585         The version component.