]>
Commit | Line | Data |
---|---|---|
f6bf3066 JS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: ownerdrw.h | |
3 | // Purpose: interface for owner-drawn GUI elements | |
4 | // Author: Vadim Zeitlin | |
c2ff79b1 | 5 | // Modified by: |
f6bf3066 JS |
6 | // Created: 11.11.97 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 9 | // Licence: wxWindows licence |
f6bf3066 JS |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _OWNERDRW_H | |
13 | #define _OWNERDRW_H | |
14 | ||
2ecf902b WS |
15 | #include "wx/defs.h" |
16 | ||
974e8d94 VZ |
17 | #if wxUSE_OWNER_DRAWN |
18 | ||
12028905 | 19 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
974e8d94 | 20 | #pragma interface "ownerdrw.h" |
0d3820b3 JS |
21 | #endif |
22 | ||
4304b42f VZ |
23 | #include "wx/bitmap.h" |
24 | #include "wx/colour.h" | |
25 | #include "wx/font.h" | |
26 | ||
f6bf3066 JS |
27 | // ---------------------------------------------------------------------------- |
28 | // wxOwnerDrawn - a mix-in base class, derive from it to implement owner-drawn | |
29 | // behaviour | |
30 | // | |
31 | // wxOwnerDrawn supports drawing of an item with non standard font, color and | |
32 | // also supports 3 bitmaps: either a checked/unchecked bitmap for a checkable | |
33 | // element or one unchangeable bitmap otherwise. | |
34 | // ---------------------------------------------------------------------------- | |
974e8d94 | 35 | |
f6bf3066 JS |
36 | class WXDLLEXPORT wxOwnerDrawn |
37 | { | |
38 | public: | |
39 | // ctor & dtor | |
974e8d94 | 40 | wxOwnerDrawn(const wxString& str = wxEmptyString, |
7e548f6b WS |
41 | bool bCheckable = false, |
42 | bool bMenuItem = false); // FIXME kludge for colors | |
f6bf3066 JS |
43 | virtual ~wxOwnerDrawn() { } |
44 | ||
45 | // fix appearance | |
c2dcfdef | 46 | void SetFont(const wxFont& font) |
7e548f6b | 47 | { m_font = font; m_bOwnerDrawn = true; } |
f6bf3066 | 48 | |
c2dcfdef | 49 | wxFont& GetFont() const { return (wxFont &)m_font; } |
f6bf3066 | 50 | |
c2dcfdef | 51 | void SetTextColour(const wxColour& colText) |
7e548f6b | 52 | { m_colText = colText; m_bOwnerDrawn = true; } |
f6bf3066 | 53 | |
c2dcfdef | 54 | wxColour& GetTextColour() const { return (wxColour&) m_colText; } |
f6bf3066 | 55 | |
c2dcfdef | 56 | void SetBackgroundColour(const wxColour& colBack) |
7e548f6b | 57 | { m_colBack = colBack; m_bOwnerDrawn = true; } |
f6bf3066 | 58 | |
c2dcfdef VZ |
59 | wxColour& GetBackgroundColour() const |
60 | { return (wxColour&) m_colBack ; } | |
f6bf3066 | 61 | |
c2ff79b1 | 62 | void SetBitmaps(const wxBitmap& bmpChecked, |
c2dcfdef VZ |
63 | const wxBitmap& bmpUnchecked = wxNullBitmap) |
64 | { m_bmpChecked = bmpChecked; | |
65 | m_bmpUnchecked = bmpUnchecked; | |
7e548f6b | 66 | m_bOwnerDrawn = true; } |
f6bf3066 | 67 | |
6a86a6c8 | 68 | void SetBitmap(const wxBitmap& bmpChecked) |
37d403aa | 69 | { m_bmpChecked = bmpChecked; |
7e548f6b | 70 | m_bOwnerDrawn = true; } |
37d403aa | 71 | |
10403254 VZ |
72 | void SetDisabledBitmap( const wxBitmap& bmpDisabled ) |
73 | { m_bmpDisabled = bmpDisabled; | |
7e548f6b | 74 | m_bOwnerDrawn = true; } |
10403254 | 75 | |
7e548f6b | 76 | const wxBitmap& GetBitmap(bool bChecked = true) const |
c2dcfdef | 77 | { return (bChecked ? m_bmpChecked : m_bmpUnchecked); } |
f6bf3066 | 78 | |
10403254 VZ |
79 | const wxBitmap& GetDisabledBitmap() const |
80 | { return m_bmpDisabled; } | |
81 | ||
f6bf3066 JS |
82 | // the height of the menu checkmark (or bitmap) is determined by the font |
83 | // for the current item, but the width should be always the same (for the | |
84 | // items to be aligned), so by default it's taken to be the same as for | |
85 | // the last item (and default width for the first one). | |
86 | // | |
87 | // NB: default is too small for bitmaps, but ok for checkmarks. | |
c2dcfdef VZ |
88 | void SetMarginWidth(int nWidth) |
89 | { | |
90 | ms_nLastMarginWidth = m_nMarginWidth = (size_t) nWidth; | |
91 | if ( ((size_t) nWidth) != ms_nDefaultMarginWidth ) | |
7e548f6b | 92 | m_bOwnerDrawn = true; |
c2dcfdef | 93 | } |
f6bf3066 | 94 | |
c2dcfdef VZ |
95 | int GetMarginWidth() const { return (int) m_nMarginWidth; } |
96 | static int GetDefaultMarginWidth() { return (int) ms_nDefaultMarginWidth; } | |
f6bf3066 JS |
97 | |
98 | // accessors | |
974e8d94 VZ |
99 | void SetName(const wxString& strName) { m_strName = strName; } |
100 | const wxString& GetName() const { return m_strName; } | |
101 | void SetCheckable(bool checkable) { m_bCheckable = checkable; } | |
102 | bool IsCheckable() const { return m_bCheckable; } | |
f6bf3066 | 103 | |
6d5b2a57 VZ |
104 | // this is for menu items only: accel string is drawn right aligned after the |
105 | // menu item if not empty | |
106 | void SetAccelString(const wxString& strAccel) { m_strAccel = strAccel; } | |
107 | ||
7e548f6b | 108 | // this function might seem strange, but if it returns false it means that |
f6bf3066 | 109 | // no non-standard attribute are set, so there is no need for this control |
7e548f6b | 110 | // to be owner-drawn. Moreover, you can force owner-drawn to false if you |
f6bf3066 JS |
111 | // want to change, say, the color for the item but only if it is owner-drawn |
112 | // (see wxMenuItem::wxMenuItem for example) | |
974e8d94 | 113 | bool IsOwnerDrawn() const { return m_bOwnerDrawn; } |
10403254 VZ |
114 | |
115 | // switch on/off owner-drawing the item | |
7e548f6b WS |
116 | void SetOwnerDrawn(bool ownerDrawn = true) { m_bOwnerDrawn = ownerDrawn; } |
117 | void ResetOwnerDrawn() { m_bOwnerDrawn = false; } | |
f6bf3066 JS |
118 | |
119 | public: | |
120 | // constants used in OnDrawItem | |
121 | // (they have the same values as corresponding Win32 constants) | |
122 | enum wxODAction | |
c2ff79b1 | 123 | { |
f6bf3066 JS |
124 | wxODDrawAll = 0x0001, // redraw entire control |
125 | wxODSelectChanged = 0x0002, // selection changed (see Status.Select) | |
c2ff79b1 | 126 | wxODFocusChanged = 0x0004 // keyboard focus changed (see Status.Focus) |
f6bf3066 JS |
127 | }; |
128 | ||
129 | enum wxODStatus | |
130 | { | |
131 | wxODSelected = 0x0001, // control is currently selected | |
132 | wxODGrayed = 0x0002, // item is to be grayed | |
133 | wxODDisabled = 0x0004, // item is to be drawn as disabled | |
134 | wxODChecked = 0x0008, // item is to be checked | |
135 | wxODHasFocus = 0x0010, // item has the keyboard focus | |
51d2fa37 VZ |
136 | wxODDefault = 0x0020, // item is the default item |
137 | wxODHidePrefix= 0x0100 // hide keyboard cues (w2k and xp only) | |
f6bf3066 JS |
138 | }; |
139 | ||
7e548f6b | 140 | // virtual functions to implement drawing (return true if processed) |
c86f1403 | 141 | virtual bool OnMeasureItem(size_t *pwidth, size_t *pheight); |
f6bf3066 JS |
142 | virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat); |
143 | ||
144 | protected: | |
6d5b2a57 VZ |
145 | wxString m_strName, // label for a manu item |
146 | m_strAccel; // the accel string ("Ctrl-F17") if any | |
f6bf3066 JS |
147 | |
148 | private: | |
c86f1403 VZ |
149 | static size_t ms_nDefaultMarginWidth; // menu check mark width |
150 | static size_t ms_nLastMarginWidth; // handy for aligning all items | |
f6bf3066 JS |
151 | |
152 | bool m_bCheckable, // used only for menu or check listbox items | |
153 | m_bOwnerDrawn; // true if something is non standard | |
154 | ||
155 | wxFont m_font; // font to use for drawing | |
974e8d94 | 156 | wxColour m_colText, // color ----"---"---"---- |
f6bf3066 JS |
157 | m_colBack; // background color |
158 | wxBitmap m_bmpChecked, // bitmap to put near the item | |
10403254 VZ |
159 | m_bmpUnchecked, // (checked is used also for 'uncheckable' items) |
160 | m_bmpDisabled; | |
f6bf3066 | 161 | |
974e8d94 | 162 | size_t m_nHeight, // font height |
d9cf726b | 163 | m_nMinHeight, // minimum height, as determined by user's system settings |
f6bf3066 JS |
164 | m_nMarginWidth; // space occupied by bitmap to the left of the item |
165 | }; | |
166 | ||
974e8d94 VZ |
167 | #endif // wxUSE_OWNER_DRAWN |
168 | ||
7be1f0d9 JS |
169 | #endif |
170 | // _OWNERDRW_H |