1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface for owner-drawn GUI elements
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
15 typedef wxColour wxColor
;
16 typedef unsigned int uint
;
18 // ----------------------------------------------------------------------------
19 // wxOwnerDrawn - a mix-in base class, derive from it to implement owner-drawn
22 // wxOwnerDrawn supports drawing of an item with non standard font, color and
23 // also supports 3 bitmaps: either a checked/unchecked bitmap for a checkable
24 // element or one unchangeable bitmap otherwise.
25 // ----------------------------------------------------------------------------
26 class WXDLLEXPORT wxOwnerDrawn
30 wxOwnerDrawn(const wxTString
& str
= "",
31 bool bCheckable
= FALSE
,
32 bool bMenuItem
= FALSE
); // ## kludge for colors
33 virtual ~wxOwnerDrawn() { }
36 inline void SetFont(const wxFont
& font
)
37 { m_font
= font
; m_bOwnerDrawn
= TRUE
; }
39 inline wxFont
& GetFont() const { return (wxFont
&)m_font
; }
41 inline void SetTextColour(const wxColour
& colText
)
42 { m_colText
= colText
; m_bOwnerDrawn
= TRUE
; }
44 inline wxColour
& GetTextColour() const { return (wxColour
&) m_colText
; }
46 inline void SetBackgroundColour(const wxColour
& colBack
)
47 { m_colBack
= colBack
; m_bOwnerDrawn
= TRUE
; }
49 inline wxColour
& GetBackgroundColour() const
50 { return (wxColour
&) m_colBack
; }
52 inline void SetBitmaps(const wxBitmap
& bmpChecked
,
53 const wxBitmap
& bmpUnchecked
= wxNullBitmap
)
54 { m_bmpChecked
= bmpChecked
;
55 m_bmpUnchecked
= bmpUnchecked
;
56 m_bOwnerDrawn
= TRUE
; }
58 inline wxBitmap
& GetBitmap(bool bChecked
= TRUE
) const
59 { return (wxBitmap
&)(bChecked
? m_bmpChecked
: m_bmpUnchecked
); }
61 // the height of the menu checkmark (or bitmap) is determined by the font
62 // for the current item, but the width should be always the same (for the
63 // items to be aligned), so by default it's taken to be the same as for
64 // the last item (and default width for the first one).
66 // NB: default is too small for bitmaps, but ok for checkmarks.
67 inline void SetMarginWidth(int nWidth
)
68 { ms_nLastMarginWidth
= m_nMarginWidth
= (uint
) nWidth
;
69 if ( ((uint
) nWidth
) != ms_nDefaultMarginWidth
) m_bOwnerDrawn
= TRUE
; }
71 inline int GetMarginWidth() const { return (int) m_nMarginWidth
; }
72 inline static int GetDefaultMarginWidth() { return (int) ms_nDefaultMarginWidth
; }
75 void SetName(const wxString
& strName
) { m_strName
= strName
; }
76 const wxString
& GetName() const { return m_strName
; }
77 bool IsCheckable() const { return m_bCheckable
; }
79 // this function might seem strange, but if it returns FALSE it means that
80 // no non-standard attribute are set, so there is no need for this control
81 // to be owner-drawn. Moreover, you can force owner-drawn to FALSE if you
82 // want to change, say, the color for the item but only if it is owner-drawn
83 // (see wxMenuItem::wxMenuItem for example)
84 inline bool IsOwnerDrawn() const { return m_bOwnerDrawn
; }
85 inline void ResetOwnerDrawn() { m_bOwnerDrawn
= FALSE
; }
88 // constants used in OnDrawItem
89 // (they have the same values as corresponding Win32 constants)
92 wxODDrawAll
= 0x0001, // redraw entire control
93 wxODSelectChanged
= 0x0002, // selection changed (see Status.Select)
94 wxODFocusChanged
= 0x0004, // keyboard focus changed (see Status.Focus)
99 wxODSelected
= 0x0001, // control is currently selected
100 wxODGrayed
= 0x0002, // item is to be grayed
101 wxODDisabled
= 0x0004, // item is to be drawn as disabled
102 wxODChecked
= 0x0008, // item is to be checked
103 wxODHasFocus
= 0x0010, // item has the keyboard focus
104 wxODDefault
= 0x0020, // item is the default item
107 // virtual functions to implement drawing (return TRUE if processed)
108 virtual bool OnMeasureItem(uint
*pwidth
, uint
*pheight
);
109 virtual bool OnDrawItem(wxDC
& dc
, const wxRect
& rc
, wxODAction act
, wxODStatus stat
);
112 wxString m_strName
; // label for a manu item
115 static uint ms_nDefaultMarginWidth
; // menu check mark width
116 static uint ms_nLastMarginWidth
; // handy for aligning all items
118 bool m_bCheckable
, // used only for menu or check listbox items
119 m_bOwnerDrawn
; // true if something is non standard
121 wxFont m_font
; // font to use for drawing
122 wxColor m_colText
, // color ----"---"---"----
123 m_colBack
; // background color
124 wxBitmap m_bmpChecked
, // bitmap to put near the item
125 m_bmpUnchecked
; // (checked is used also for 'uncheckable' items)
127 uint m_nHeight
, // font height
128 m_nMarginWidth
; // space occupied by bitmap to the left of the item