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