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 ///////////////////////////////////////////////////////////////////////////////
16 #pragma interface "ownerdrw.h"
19 typedef wxColour wxColor
;
20 typedef unsigned int uint
;
22 // ----------------------------------------------------------------------------
23 // wxOwnerDrawn - a mix-in base class, derive from it to implement owner-drawn
26 // wxOwnerDrawn supports drawing of an item with non standard font, color and
27 // also supports 3 bitmaps: either a checked/unchecked bitmap for a checkable
28 // element or one unchangeable bitmap otherwise.
29 // ----------------------------------------------------------------------------
30 class WXDLLEXPORT wxOwnerDrawn
34 wxOwnerDrawn(const wxTString
& str
= "",
35 bool bCheckable
= FALSE
,
36 bool bMenuItem
= FALSE
); // ## kludge for colors
37 virtual ~wxOwnerDrawn() { }
40 inline void SetFont(const wxFont
& font
)
41 { m_font
= font
; m_bOwnerDrawn
= TRUE
; }
43 inline wxFont
& GetFont() const { return (wxFont
&)m_font
; }
45 inline void SetTextColour(const wxColour
& colText
)
46 { m_colText
= colText
; m_bOwnerDrawn
= TRUE
; }
48 inline wxColour
& GetTextColour() const { return (wxColour
&) m_colText
; }
50 inline void SetBackgroundColour(const wxColour
& colBack
)
51 { m_colBack
= colBack
; m_bOwnerDrawn
= TRUE
; }
53 inline wxColour
& GetBackgroundColour() const
54 { return (wxColour
&) m_colBack
; }
56 inline void SetBitmaps(const wxBitmap
& bmpChecked
,
57 const wxBitmap
& bmpUnchecked
= wxNullBitmap
)
58 { m_bmpChecked
= bmpChecked
;
59 m_bmpUnchecked
= bmpUnchecked
;
60 m_bOwnerDrawn
= TRUE
; }
62 inline wxBitmap
& GetBitmap(bool bChecked
= TRUE
) const
63 { return (wxBitmap
&)(bChecked
? m_bmpChecked
: m_bmpUnchecked
); }
65 // the height of the menu checkmark (or bitmap) is determined by the font
66 // for the current item, but the width should be always the same (for the
67 // items to be aligned), so by default it's taken to be the same as for
68 // the last item (and default width for the first one).
70 // NB: default is too small for bitmaps, but ok for checkmarks.
71 inline void SetMarginWidth(int nWidth
)
72 { ms_nLastMarginWidth
= m_nMarginWidth
= (uint
) nWidth
;
73 if ( ((uint
) nWidth
) != ms_nDefaultMarginWidth
) m_bOwnerDrawn
= TRUE
; }
75 inline int GetMarginWidth() const { return (int) m_nMarginWidth
; }
76 inline static int GetDefaultMarginWidth() { return (int) ms_nDefaultMarginWidth
; }
79 void SetName(const wxString
& strName
) { m_strName
= strName
; }
80 const wxString
& GetName() const { return m_strName
; }
81 bool IsCheckable() const { return m_bCheckable
; }
83 // this function might seem strange, but if it returns FALSE it means that
84 // no non-standard attribute are set, so there is no need for this control
85 // to be owner-drawn. Moreover, you can force owner-drawn to FALSE if you
86 // want to change, say, the color for the item but only if it is owner-drawn
87 // (see wxMenuItem::wxMenuItem for example)
88 inline bool IsOwnerDrawn() const { return m_bOwnerDrawn
; }
89 inline void ResetOwnerDrawn() { m_bOwnerDrawn
= FALSE
; }
92 // constants used in OnDrawItem
93 // (they have the same values as corresponding Win32 constants)
96 wxODDrawAll
= 0x0001, // redraw entire control
97 wxODSelectChanged
= 0x0002, // selection changed (see Status.Select)
98 wxODFocusChanged
= 0x0004, // keyboard focus changed (see Status.Focus)
103 wxODSelected
= 0x0001, // control is currently selected
104 wxODGrayed
= 0x0002, // item is to be grayed
105 wxODDisabled
= 0x0004, // item is to be drawn as disabled
106 wxODChecked
= 0x0008, // item is to be checked
107 wxODHasFocus
= 0x0010, // item has the keyboard focus
108 wxODDefault
= 0x0020, // item is the default item
111 // virtual functions to implement drawing (return TRUE if processed)
112 virtual bool OnMeasureItem(uint
*pwidth
, uint
*pheight
);
113 virtual bool OnDrawItem(wxDC
& dc
, const wxRect
& rc
, wxODAction act
, wxODStatus stat
);
116 wxString m_strName
; // label for a manu item
119 static uint ms_nDefaultMarginWidth
; // menu check mark width
120 static uint ms_nLastMarginWidth
; // handy for aligning all items
122 bool m_bCheckable
, // used only for menu or check listbox items
123 m_bOwnerDrawn
; // true if something is non standard
125 wxFont m_font
; // font to use for drawing
126 wxColor m_colText
, // color ----"---"---"----
127 m_colBack
; // background color
128 wxBitmap m_bmpChecked
, // bitmap to put near the item
129 m_bmpUnchecked
; // (checked is used also for 'uncheckable' items)
131 uint m_nHeight
, // font height
132 m_nMarginWidth
; // space occupied by bitmap to the left of the item