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