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