]> git.saurik.com Git - wxWidgets.git/blame - include/wx/ownerdrw.h
no changes, just remove #if'd out code
[wxWidgets.git] / include / wx / ownerdrw.h
CommitLineData
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
4304b42f
VZ
19#include "wx/bitmap.h"
20#include "wx/colour.h"
21#include "wx/font.h"
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
53a2db12 32class WXDLLIMPEXP_CORE wxOwnerDrawn
f6bf3066
JS
33{
34public:
35 // ctor & dtor
974e8d94 36 wxOwnerDrawn(const wxString& str = wxEmptyString,
7e548f6b
WS
37 bool bCheckable = false,
38 bool bMenuItem = false); // FIXME kludge for colors
810ca882 39 virtual ~wxOwnerDrawn();
f6bf3066
JS
40
41 // fix appearance
c2dcfdef 42 void SetFont(const wxFont& font)
7e548f6b 43 { m_font = font; m_bOwnerDrawn = true; }
f6bf3066 44
c2dcfdef 45 wxFont& GetFont() const { return (wxFont &)m_font; }
f6bf3066 46
c2dcfdef 47 void SetTextColour(const wxColour& colText)
7e548f6b 48 { m_colText = colText; m_bOwnerDrawn = true; }
f6bf3066 49
c2dcfdef 50 wxColour& GetTextColour() const { return (wxColour&) m_colText; }
f6bf3066 51
c2dcfdef 52 void SetBackgroundColour(const wxColour& colBack)
7e548f6b 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;
7e548f6b 62 m_bOwnerDrawn = true; }
f6bf3066 63
4d273001
VZ
64 void SetBitmap(const wxBitmap& bmp, bool bChecked = true)
65 {
66 if ( bChecked )
67 m_bmpChecked = bmp;
68 else
69 m_bmpUnchecked = bmp;
70 m_bOwnerDrawn = true;
71 }
37d403aa 72
10403254
VZ
73 void SetDisabledBitmap( const wxBitmap& bmpDisabled )
74 { m_bmpDisabled = bmpDisabled;
7e548f6b 75 m_bOwnerDrawn = true; }
10403254 76
7e548f6b 77 const wxBitmap& GetBitmap(bool bChecked = true) const
c2dcfdef 78 { return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
f6bf3066 79
10403254
VZ
80 const wxBitmap& GetDisabledBitmap() const
81 { return m_bmpDisabled; }
82
f6bf3066
JS
83 // the height of the menu checkmark (or bitmap) is determined by the font
84 // for the current item, but the width should be always the same (for the
85 // items to be aligned), so by default it's taken to be the same as for
86 // the last item (and default width for the first one).
87 //
88 // NB: default is too small for bitmaps, but ok for checkmarks.
c2dcfdef
VZ
89 void SetMarginWidth(int nWidth)
90 {
91 ms_nLastMarginWidth = m_nMarginWidth = (size_t) nWidth;
92 if ( ((size_t) nWidth) != ms_nDefaultMarginWidth )
7e548f6b 93 m_bOwnerDrawn = true;
c2dcfdef 94 }
f6bf3066 95
c2dcfdef
VZ
96 int GetMarginWidth() const { return (int) m_nMarginWidth; }
97 static int GetDefaultMarginWidth() { return (int) ms_nDefaultMarginWidth; }
f6bf3066
JS
98
99 // accessors
974e8d94
VZ
100 void SetName(const wxString& strName) { m_strName = strName; }
101 const wxString& GetName() const { return m_strName; }
102 void SetCheckable(bool checkable) { m_bCheckable = checkable; }
103 bool IsCheckable() const { return m_bCheckable; }
f6bf3066 104
6d5b2a57
VZ
105 // this is for menu items only: accel string is drawn right aligned after the
106 // menu item if not empty
107 void SetAccelString(const wxString& strAccel) { m_strAccel = strAccel; }
108
7e548f6b 109 // this function might seem strange, but if it returns false it means that
f6bf3066 110 // no non-standard attribute are set, so there is no need for this control
7e548f6b 111 // to be owner-drawn. Moreover, you can force owner-drawn to false if you
f6bf3066
JS
112 // want to change, say, the color for the item but only if it is owner-drawn
113 // (see wxMenuItem::wxMenuItem for example)
974e8d94 114 bool IsOwnerDrawn() const { return m_bOwnerDrawn; }
10403254
VZ
115
116 // switch on/off owner-drawing the item
7e548f6b
WS
117 void SetOwnerDrawn(bool ownerDrawn = true) { m_bOwnerDrawn = ownerDrawn; }
118 void ResetOwnerDrawn() { m_bOwnerDrawn = false; }
f6bf3066
JS
119
120public:
121 // constants used in OnDrawItem
122 // (they have the same values as corresponding Win32 constants)
123 enum wxODAction
c2ff79b1 124 {
f6bf3066
JS
125 wxODDrawAll = 0x0001, // redraw entire control
126 wxODSelectChanged = 0x0002, // selection changed (see Status.Select)
c2ff79b1 127 wxODFocusChanged = 0x0004 // keyboard focus changed (see Status.Focus)
f6bf3066
JS
128 };
129
130 enum wxODStatus
131 {
132 wxODSelected = 0x0001, // control is currently selected
133 wxODGrayed = 0x0002, // item is to be grayed
134 wxODDisabled = 0x0004, // item is to be drawn as disabled
135 wxODChecked = 0x0008, // item is to be checked
136 wxODHasFocus = 0x0010, // item has the keyboard focus
51d2fa37
VZ
137 wxODDefault = 0x0020, // item is the default item
138 wxODHidePrefix= 0x0100 // hide keyboard cues (w2k and xp only)
f6bf3066
JS
139 };
140
7e548f6b 141 // virtual functions to implement drawing (return true if processed)
c86f1403 142 virtual bool OnMeasureItem(size_t *pwidth, size_t *pheight);
f6bf3066
JS
143 virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat);
144
145protected:
810ca882
VZ
146 // return true if this is a menu item
147 bool IsMenuItem() const;
148
149 // get the font to use, whether m_font is set or not
150 wxFont GetFontToUse() const;
151
152
6d5b2a57
VZ
153 wxString m_strName, // label for a manu item
154 m_strAccel; // the accel string ("Ctrl-F17") if any
f6bf3066
JS
155
156private:
c86f1403
VZ
157 static size_t ms_nDefaultMarginWidth; // menu check mark width
158 static size_t ms_nLastMarginWidth; // handy for aligning all items
f6bf3066
JS
159
160 bool m_bCheckable, // used only for menu or check listbox items
4e47fd5a
VZ
161 m_bOwnerDrawn, // true if something is non standard
162 m_isMenuItem; // true if this is a menu item
f6bf3066
JS
163
164 wxFont m_font; // font to use for drawing
974e8d94 165 wxColour m_colText, // color ----"---"---"----
f6bf3066
JS
166 m_colBack; // background color
167 wxBitmap m_bmpChecked, // bitmap to put near the item
10403254
VZ
168 m_bmpUnchecked, // (checked is used also for 'uncheckable' items)
169 m_bmpDisabled;
f6bf3066 170
974e8d94 171 size_t m_nHeight, // font height
f6bf3066
JS
172 m_nMarginWidth; // space occupied by bitmap to the left of the item
173};
174
974e8d94
VZ
175#endif // wxUSE_OWNER_DRAWN
176
7be1f0d9
JS
177#endif
178 // _OWNERDRW_H