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