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