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