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