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