]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ownerdrw.h
remove unused variable assignment, closes #14928
[wxWidgets.git] / include / wx / ownerdrw.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ownerdrw.h
3 // Purpose: interface for owner-drawn GUI elements
4 // Author: Vadim Zeitlin
5 // Modified by: Marcin Malich
6 // Created: 11.11.97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_OWNERDRW_H_BASE
13 #define _WX_OWNERDRW_H_BASE
14
15 #include "wx/defs.h"
16
17 #if wxUSE_OWNER_DRAWN
18
19 #include "wx/font.h"
20 #include "wx/colour.h"
21
22 class WXDLLIMPEXP_FWD_CORE wxDC;
23
24 // ----------------------------------------------------------------------------
25 // wxOwnerDrawn - a mix-in base class, derive from it to implement owner-drawn
26 // behaviour
27 //
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 // ----------------------------------------------------------------------------
32
33 class WXDLLIMPEXP_CORE wxOwnerDrawnBase
34 {
35 public:
36 wxOwnerDrawnBase()
37 {
38 m_ownerDrawn = false;
39 m_margin = ms_defaultMargin;
40 }
41
42 virtual ~wxOwnerDrawnBase() {}
43
44 void SetFont(const wxFont& font)
45 { m_font = font; m_ownerDrawn = true; }
46
47 wxFont& GetFont() const
48 { return (wxFont&) m_font; }
49
50
51 void SetTextColour(const wxColour& colText)
52 { m_colText = colText; m_ownerDrawn = true; }
53
54 wxColour& GetTextColour() const
55 { return (wxColour&) m_colText; }
56
57 void SetBackgroundColour(const wxColour& colBack)
58 { m_colBack = colBack; m_ownerDrawn = true; }
59
60 wxColour& GetBackgroundColour() const
61 { return (wxColour&) m_colBack ; }
62
63
64 void SetMarginWidth(int width)
65 { m_margin = width; }
66
67 int GetMarginWidth() const
68 { return m_margin; }
69
70 static int GetDefaultMarginWidth()
71 { return ms_defaultMargin; }
72
73
74 // get item name (with mnemonics if exist)
75 virtual wxString GetName() const = 0;
76
77
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; }
85
86 // switch on/off owner-drawing the item
87 void SetOwnerDrawn(bool ownerDrawn = true)
88 { m_ownerDrawn = ownerDrawn; }
89
90
91 // constants used in OnDrawItem
92 // (they have the same values as corresponding Win32 constants)
93 enum wxODAction
94 {
95 wxODDrawAll = 0x0001, // redraw entire control
96 wxODSelectChanged = 0x0002, // selection changed (see Status.Select)
97 wxODFocusChanged = 0x0004 // keyboard focus changed (see Status.Focus)
98 };
99
100 enum wxODStatus
101 {
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)
109 };
110
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;
114
115 protected:
116
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;
120
121 private:
122 bool m_ownerDrawn; // true if something is non standard
123
124 wxFont m_font; // font to use for drawing
125 wxColour m_colText, // color ----"---"---"----
126 m_colBack; // background color
127
128 int m_margin; // space occupied by bitmap to the left of the item
129
130 static int ms_defaultMargin;
131 };
132
133 // ----------------------------------------------------------------------------
134 // include the platform-specific class declaration
135 // ----------------------------------------------------------------------------
136
137 #if defined(__WXMSW__)
138 #include "wx/msw/ownerdrw.h"
139 #elif defined(__WXPM__)
140 #include "wx/os2/ownerdrw.h"
141 #endif
142
143 #endif // wxUSE_OWNER_DRAWN
144
145 #endif // _WX_OWNERDRW_H_BASE