]> git.saurik.com Git - wxWidgets.git/blame - include/wx/control.h
Add demonstration of a few more wxRenderer methods.
[wxWidgets.git] / include / wx / control.h
CommitLineData
8d99be5f
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/control.h
3// Purpose: wxControl common interface
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 26.07.99
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
8d99be5f
VZ
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_CONTROL_H_BASE_
13#define _WX_CONTROL_H_BASE_
c801d85f 14
8d99be5f
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
997176a3
VZ
19#include "wx/defs.h"
20
1e6feb95
VZ
21#if wxUSE_CONTROLS
22
8d99be5f
VZ
23#include "wx/window.h" // base class
24
53a2db12 25extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr[];
1e6feb95 26
a78618b0
FM
27
28// ----------------------------------------------------------------------------
29// Ellipsize() constants
30// ----------------------------------------------------------------------------
31
32enum wxEllipsizeFlags
33{
34 wxELLIPSIZE_PROCESS_MNEMONICS = 1,
35 wxELLIPSIZE_EXPAND_TAB = 2,
36
37 wxELLIPSIZE_DEFAULT_FLAGS = wxELLIPSIZE_PROCESS_MNEMONICS|wxELLIPSIZE_EXPAND_TAB
38};
39
5c87527c
FM
40enum wxEllipsizeMode
41{
42 wxELLIPSIZE_START,
43 wxELLIPSIZE_MIDDLE,
44 wxELLIPSIZE_END
45};
46
8d99be5f
VZ
47// ----------------------------------------------------------------------------
48// wxControl is the base class for all controls
49// ----------------------------------------------------------------------------
50
53a2db12 51class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
8d99be5f
VZ
52{
53public:
c0e6c051 54 wxControlBase() { }
fc7a2a60 55
799ea011
GD
56 virtual ~wxControlBase();
57
1e6feb95
VZ
58 // Create() function adds the validator parameter
59 bool Create(wxWindow *parent, wxWindowID id,
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = 0,
63 const wxValidator& validator = wxDefaultValidator,
64 const wxString& name = wxControlNameStr);
65
1e6feb95
VZ
66 // get the control alignment (left/right/centre, top/bottom/centre)
67 int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
68
39bc0347
VZ
69 virtual void SetLabel(const wxString& label)
70 {
71 m_labelOrig = label;
72
73 InvalidateBestSize();
74
75 wxWindow::SetLabel(label);
76 }
77
78 virtual wxString GetLabel() const
79 {
80 // return the original string, as it was passed to SetLabel()
81 // (i.e. with wx-style mnemonics)
82 return m_labelOrig;
83 }
84
5b8b2c84
VZ
85 // get just the text of the label, without mnemonic characters ('&')
86 wxString GetLabelText() const { return GetLabelText(GetLabel()); }
87
88 void SetLabelText(const wxString& text)
89 {
440d3d2a 90 SetLabel(EscapeMnemonics(text));
5b8b2c84
VZ
91 }
92
d4864e97
VZ
93 // controls by default inherit the colours of their parents, if a
94 // particular control class doesn't want to do it, it can override
95 // ShouldInheritColours() to return false
96 virtual bool ShouldInheritColours() const { return true; }
97
9f4b4671
VZ
98
99 // WARNING: this doesn't work for all controls nor all platforms!
100 //
101 // simulates the event of given type (i.e. wxButton::Command() is just as
102 // if the button was clicked)
103 virtual void Command(wxCommandEvent &event);
104
9f884528
RD
105 virtual bool SetFont(const wxFont& font);
106
a3a4105d
VZ
107 // wxControl-specific processing after processing the update event
108 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
109
a78618b0
FM
110
111
112 // static utilities
113 // ----------------
114
115 // replaces parts of the (multiline) string with ellipsis if needed
116 static wxString Ellipsize(const wxString& label, const wxDC& dc,
117 wxEllipsizeMode mode, int maxWidth,
118 int flags = wxELLIPSIZE_DEFAULT_FLAGS);
119
120 // get the string without mnemonic characters ('&')
121 static wxString GetLabelText(const wxString& label);
122
123 // removes the mnemonics characters
124 static wxString RemoveMnemonics(const wxString& str);
125
126 // escapes (by doubling them) the mnemonics
127 static wxString EscapeMnemonics(const wxString& str);
128
129 // return the accel index in the string or -1 if none and puts the modified
130 // string into second parameter if non NULL
131 static int FindAccelIndex(const wxString& label,
132 wxString *labelOnly = NULL);
133
0534259a
VZ
134 // this is a helper for the derived class GetClassDefaultAttributes()
135 // implementation: it returns the right colours for the classes which
136 // contain something else (e.g. wxListBox, wxTextCtrl, ...) instead of
137 // being simple controls (such as wxButton, wxCheckBox, ...)
138 static wxVisualAttributes
139 GetCompositeControlsDefaultAttributes(wxWindowVariant variant);
140
8d99be5f 141protected:
dc797d8e
JS
142 // choose the default border for this window
143 virtual wxBorder GetDefaultBorder() const;
144
3f2711d5
VZ
145 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
146 // to the list of parents children
8d99be5f
VZ
147 bool CreateControl(wxWindowBase *parent,
148 wxWindowID id,
149 const wxPoint& pos,
150 const wxSize& size,
151 long style,
152 const wxValidator& validator,
153 const wxString& name);
154
bfbd6dc1
VZ
155 // initialize the common fields of wxCommandEvent
156 void InitCommandEvent(wxCommandEvent& event) const;
fc7a2a60 157
a78618b0
FM
158 // Ellipsize() helper:
159 static wxString DoEllipsizeSingleLine(const wxString& label, const wxDC& dc,
160 wxEllipsizeMode mode, int maxWidth,
161 int replacementWidth, int marginWidth);
162
39bc0347
VZ
163 // this field contains the label in wx format, i.e. with '&' mnemonics
164 wxString m_labelOrig;
165
c0c133e1 166 wxDECLARE_NO_COPY_CLASS(wxControlBase);
8d99be5f
VZ
167};
168
169// ----------------------------------------------------------------------------
170// include platform-dependent wxControl declarations
171// ----------------------------------------------------------------------------
f03fc89f 172
1e6feb95
VZ
173#if defined(__WXUNIVERSAL__)
174 #include "wx/univ/control.h"
4055ed82 175#elif defined(__WXPALMOS__)
ffecfa5a 176 #include "wx/palmos/control.h"
1e6feb95 177#elif defined(__WXMSW__)
8d99be5f 178 #include "wx/msw/control.h"
2049ba38 179#elif defined(__WXMOTIF__)
8d99be5f 180 #include "wx/motif/control.h"
1be7a35c 181#elif defined(__WXGTK20__)
8d99be5f 182 #include "wx/gtk/control.h"
1be7a35c
MR
183#elif defined(__WXGTK__)
184 #include "wx/gtk1/control.h"
34138703 185#elif defined(__WXMAC__)
ef0e9220 186 #include "wx/osx/control.h"
e64df9bc
DE
187#elif defined(__WXCOCOA__)
188 #include "wx/cocoa/control.h"
1777b9bb
DW
189#elif defined(__WXPM__)
190 #include "wx/os2/control.h"
c801d85f
KB
191#endif
192
1e6feb95
VZ
193#endif // wxUSE_CONTROLS
194
c801d85f 195#endif
34138703 196 // _WX_CONTROL_H_BASE_