]> git.saurik.com Git - wxWidgets.git/blame - include/wx/ownerdrw.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / ownerdrw.h
CommitLineData
f6bf3066 1///////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/ownerdrw.h
f6bf3066
JS
3// Purpose: interface for owner-drawn GUI elements
4// Author: Vadim Zeitlin
98fbab9e 5// Modified by: Marcin Malich
f6bf3066 6// Created: 11.11.97
f6bf3066 7// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 8// Licence: wxWindows licence
f6bf3066
JS
9///////////////////////////////////////////////////////////////////////////////
10
98fbab9e
VZ
11#ifndef _WX_OWNERDRW_H_BASE
12#define _WX_OWNERDRW_H_BASE
f6bf3066 13
2ecf902b
WS
14#include "wx/defs.h"
15
974e8d94
VZ
16#if wxUSE_OWNER_DRAWN
17
4304b42f 18#include "wx/font.h"
98fbab9e 19#include "wx/colour.h"
4304b42f 20
9d043a92
VZ
21class WXDLLIMPEXP_FWD_CORE wxDC;
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
98fbab9e 32class WXDLLIMPEXP_CORE wxOwnerDrawnBase
f6bf3066
JS
33{
34public:
98fbab9e
VZ
35 wxOwnerDrawnBase()
36 {
37 m_ownerDrawn = false;
38 m_margin = ms_defaultMargin;
39 }
40
41 virtual ~wxOwnerDrawnBase() {}
42
43 void SetFont(const wxFont& font)
44 { m_font = font; m_ownerDrawn = true; }
45
46 wxFont& GetFont() const
47 { return (wxFont&) m_font; }
48
49
50 void SetTextColour(const wxColour& colText)
51 { m_colText = colText; m_ownerDrawn = true; }
52
53 wxColour& GetTextColour() const
54 { return (wxColour&) m_colText; }
55
56 void SetBackgroundColour(const wxColour& colBack)
57 { m_colBack = colBack; m_ownerDrawn = true; }
58
59 wxColour& GetBackgroundColour() const
60 { return (wxColour&) m_colBack ; }
61
62
63 void SetMarginWidth(int width)
64 { m_margin = width; }
65
66 int GetMarginWidth() const
67 { return m_margin; }
68
69 static int GetDefaultMarginWidth()
70 { return ms_defaultMargin; }
71
72
73 // get item name (with mnemonics if exist)
74 virtual wxString GetName() const = 0;
75
6d5b2a57 76
7e548f6b 77 // this function might seem strange, but if it returns false it means that
f6bf3066 78 // no non-standard attribute are set, so there is no need for this control
7e548f6b 79 // to be owner-drawn. Moreover, you can force owner-drawn to false if you
f6bf3066
JS
80 // want to change, say, the color for the item but only if it is owner-drawn
81 // (see wxMenuItem::wxMenuItem for example)
98fbab9e
VZ
82 bool IsOwnerDrawn() const
83 { return m_ownerDrawn; }
84
85 // switch on/off owner-drawing the item
86 void SetOwnerDrawn(bool ownerDrawn = true)
87 { m_ownerDrawn = ownerDrawn; }
88
89
90 // constants used in OnDrawItem
91 // (they have the same values as corresponding Win32 constants)
92 enum wxODAction
93 {
94 wxODDrawAll = 0x0001, // redraw entire control
95 wxODSelectChanged = 0x0002, // selection changed (see Status.Select)
96 wxODFocusChanged = 0x0004 // keyboard focus changed (see Status.Focus)
97 };
98
99 enum wxODStatus
100 {
101 wxODSelected = 0x0001, // control is currently selected
102 wxODGrayed = 0x0002, // item is to be grayed
103 wxODDisabled = 0x0004, // item is to be drawn as disabled
104 wxODChecked = 0x0008, // item is to be checked
105 wxODHasFocus = 0x0010, // item has the keyboard focus
106 wxODDefault = 0x0020, // item is the default item
107 wxODHidePrefix= 0x0100 // hide keyboard cues (w2k and xp only)
108 };
109
110 // virtual functions to implement drawing (return true if processed)
111 virtual bool OnMeasureItem(size_t *width, size_t *height);
112 virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat) = 0;
f6bf3066
JS
113
114protected:
810ca882 115
98fbab9e
VZ
116 // get the font and colour to use, whether it is set or not
117 virtual void GetFontToUse(wxFont& font) const;
118 virtual void GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const;
810ca882 119
98fbab9e
VZ
120private:
121 bool m_ownerDrawn; // true if something is non standard
810ca882 122
98fbab9e
VZ
123 wxFont m_font; // font to use for drawing
124 wxColour m_colText, // color ----"---"---"----
125 m_colBack; // background color
f6bf3066 126
98fbab9e
VZ
127 int m_margin; // space occupied by bitmap to the left of the item
128
129 static int ms_defaultMargin;
f6bf3066
JS
130};
131
98fbab9e
VZ
132// ----------------------------------------------------------------------------
133// include the platform-specific class declaration
134// ----------------------------------------------------------------------------
974e8d94 135
98fbab9e
VZ
136#if defined(__WXMSW__)
137 #include "wx/msw/ownerdrw.h"
138#elif defined(__WXPM__)
139 #include "wx/os2/ownerdrw.h"
7be1f0d9 140#endif
98fbab9e
VZ
141
142#endif // wxUSE_OWNER_DRAWN
143
144#endif // _WX_OWNERDRW_H_BASE