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