1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface for owner-drawn GUI elements
4 // Author: Vadim Zeitlin
5 // Modified by: Marcin Malich
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_OWNERDRW_H_BASE
13 #define _WX_OWNERDRW_H_BASE
20 #include "wx/colour.h"
22 class WXDLLIMPEXP_FWD_CORE wxDC
;
24 // ----------------------------------------------------------------------------
25 // wxOwnerDrawn - a mix-in base class, derive from it to implement owner-drawn
28 // wxOwnerDrawn supports drawing of an item with non standard font, color and
29 // also supports 3 bitmaps: either a checked/unchecked bitmap for a checkable
30 // element or one unchangeable bitmap otherwise.
31 // ----------------------------------------------------------------------------
33 class WXDLLIMPEXP_CORE wxOwnerDrawnBase
39 m_margin
= ms_defaultMargin
;
42 virtual ~wxOwnerDrawnBase() {}
44 void SetFont(const wxFont
& font
)
45 { m_font
= font
; m_ownerDrawn
= true; }
47 wxFont
& GetFont() const
48 { return (wxFont
&) m_font
; }
51 void SetTextColour(const wxColour
& colText
)
52 { m_colText
= colText
; m_ownerDrawn
= true; }
54 wxColour
& GetTextColour() const
55 { return (wxColour
&) m_colText
; }
57 void SetBackgroundColour(const wxColour
& colBack
)
58 { m_colBack
= colBack
; m_ownerDrawn
= true; }
60 wxColour
& GetBackgroundColour() const
61 { return (wxColour
&) m_colBack
; }
64 void SetMarginWidth(int width
)
67 int GetMarginWidth() const
70 static int GetDefaultMarginWidth()
71 { return ms_defaultMargin
; }
74 // get item name (with mnemonics if exist)
75 virtual wxString
GetName() const = 0;
78 // this function might seem strange, but if it returns false it means that
79 // no non-standard attribute are set, so there is no need for this control
80 // to be owner-drawn. Moreover, you can force owner-drawn to false if you
81 // want to change, say, the color for the item but only if it is owner-drawn
82 // (see wxMenuItem::wxMenuItem for example)
83 bool IsOwnerDrawn() const
84 { return m_ownerDrawn
; }
86 // switch on/off owner-drawing the item
87 void SetOwnerDrawn(bool ownerDrawn
= true)
88 { m_ownerDrawn
= ownerDrawn
; }
91 // constants used in OnDrawItem
92 // (they have the same values as corresponding Win32 constants)
95 wxODDrawAll
= 0x0001, // redraw entire control
96 wxODSelectChanged
= 0x0002, // selection changed (see Status.Select)
97 wxODFocusChanged
= 0x0004 // keyboard focus changed (see Status.Focus)
102 wxODSelected
= 0x0001, // control is currently selected
103 wxODGrayed
= 0x0002, // item is to be grayed
104 wxODDisabled
= 0x0004, // item is to be drawn as disabled
105 wxODChecked
= 0x0008, // item is to be checked
106 wxODHasFocus
= 0x0010, // item has the keyboard focus
107 wxODDefault
= 0x0020, // item is the default item
108 wxODHidePrefix
= 0x0100 // hide keyboard cues (w2k and xp only)
111 // virtual functions to implement drawing (return true if processed)
112 virtual bool OnMeasureItem(size_t *width
, size_t *height
);
113 virtual bool OnDrawItem(wxDC
& dc
, const wxRect
& rc
, wxODAction act
, wxODStatus stat
) = 0;
117 // get the font and colour to use, whether it is set or not
118 virtual void GetFontToUse(wxFont
& font
) const;
119 virtual void GetColourToUse(wxODStatus stat
, wxColour
& colText
, wxColour
& colBack
) const;
122 bool m_ownerDrawn
; // true if something is non standard
124 wxFont m_font
; // font to use for drawing
125 wxColour m_colText
, // color ----"---"---"----
126 m_colBack
; // background color
128 int m_margin
; // space occupied by bitmap to the left of the item
130 static int ms_defaultMargin
;
133 // ----------------------------------------------------------------------------
134 // include the platform-specific class declaration
135 // ----------------------------------------------------------------------------
137 #if defined(__WXMSW__)
138 #include "wx/msw/ownerdrw.h"
139 #elif defined(__WXPM__)
140 #include "wx/os2/ownerdrw.h"
143 #endif // wxUSE_OWNER_DRAWN
145 #endif // _WX_OWNERDRW_H_BASE