]> git.saurik.com Git - wxWidgets.git/blame - include/wx/control.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[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
77ffb593 7// Copyright: (c) wxWidgets team
65571936 8// Licence: wxWindows licence
8d99be5f
VZ
9/////////////////////////////////////////////////////////////////////////////
10
34138703
JS
11#ifndef _WX_CONTROL_H_BASE_
12#define _WX_CONTROL_H_BASE_
c801d85f 13
8d99be5f
VZ
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
997176a3
VZ
18#include "wx/defs.h"
19
1e6feb95
VZ
20#if wxUSE_CONTROLS
21
8d99be5f
VZ
22#include "wx/window.h" // base class
23
53a2db12 24extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr[];
1e6feb95 25
a78618b0
FM
26
27// ----------------------------------------------------------------------------
28// Ellipsize() constants
29// ----------------------------------------------------------------------------
30
31enum wxEllipsizeFlags
32{
355ce7ad
VZ
33 wxELLIPSIZE_FLAGS_NONE = 0,
34 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS = 1,
35 wxELLIPSIZE_FLAGS_EXPAND_TABS = 2,
a78618b0 36
355ce7ad
VZ
37 wxELLIPSIZE_FLAGS_DEFAULT = wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS |
38 wxELLIPSIZE_FLAGS_EXPAND_TABS
a78618b0
FM
39};
40
c937bcac
VZ
41// NB: Don't change the order of these values, they're the same as in
42// PangoEllipsizeMode enum.
5c87527c
FM
43enum wxEllipsizeMode
44{
c937bcac 45 wxELLIPSIZE_NONE,
5c87527c
FM
46 wxELLIPSIZE_START,
47 wxELLIPSIZE_MIDDLE,
48 wxELLIPSIZE_END
49};
50
8d99be5f
VZ
51// ----------------------------------------------------------------------------
52// wxControl is the base class for all controls
53// ----------------------------------------------------------------------------
54
53a2db12 55class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
8d99be5f
VZ
56{
57public:
c0e6c051 58 wxControlBase() { }
fc7a2a60 59
799ea011
GD
60 virtual ~wxControlBase();
61
1e6feb95
VZ
62 // Create() function adds the validator parameter
63 bool Create(wxWindow *parent, wxWindowID id,
64 const wxPoint& pos = wxDefaultPosition,
65 const wxSize& size = wxDefaultSize,
66 long style = 0,
67 const wxValidator& validator = wxDefaultValidator,
68 const wxString& name = wxControlNameStr);
69
1e6feb95
VZ
70 // get the control alignment (left/right/centre, top/bottom/centre)
71 int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
72
32ee98eb 73 // set label with mnemonics
39bc0347
VZ
74 virtual void SetLabel(const wxString& label)
75 {
76 m_labelOrig = label;
77
78 InvalidateBestSize();
79
80 wxWindow::SetLabel(label);
81 }
82
32ee98eb
FM
83 // return the original string, as it was passed to SetLabel()
84 // (i.e. with wx-style mnemonics)
85 virtual wxString GetLabel() const { return m_labelOrig; }
5b8b2c84 86
32ee98eb
FM
87 // set label text (mnemonics will be escaped)
88 virtual void SetLabelText(const wxString& text)
5b8b2c84 89 {
440d3d2a 90 SetLabel(EscapeMnemonics(text));
5b8b2c84
VZ
91 }
92
32ee98eb
FM
93 // get just the text of the label, without mnemonic characters ('&')
94 virtual wxString GetLabelText() const { return GetLabelText(GetLabel()); }
95
3da9cffc 96
f5bdfc69 97#if wxUSE_MARKUP
3da9cffc
VZ
98 // Set the label with markup (and mnemonics). Markup is a simple subset of
99 // HTML with tags such as <b>, <i> and <span>. By default it is not
100 // supported i.e. all the markup is simply stripped and SetLabel() is
101 // called but some controls in some ports do support this already and in
102 // the future most of them should.
103 //
104 // Notice that, being HTML-like, markup also supports XML entities so '<'
105 // should be encoded as "&lt;" and so on, a bare '<' in the input will
106 // likely result in an error. As an exception, a bare '&' is allowed and
107 // indicates that the next character is a mnemonic. To insert a literal '&'
108 // in the control you need to use "&amp;" in the input string.
109 //
110 // Returns true if the label was set, even if the markup in it was ignored.
111 // False is only returned if we failed to parse the label.
112 bool SetLabelMarkup(const wxString& markup)
113 {
114 return DoSetLabelMarkup(markup);
115 }
f5bdfc69 116#endif // wxUSE_MARKUP
3da9cffc
VZ
117
118
d4864e97
VZ
119 // controls by default inherit the colours of their parents, if a
120 // particular control class doesn't want to do it, it can override
121 // ShouldInheritColours() to return false
122 virtual bool ShouldInheritColours() const { return true; }
123
9f4b4671
VZ
124
125 // WARNING: this doesn't work for all controls nor all platforms!
126 //
127 // simulates the event of given type (i.e. wxButton::Command() is just as
128 // if the button was clicked)
129 virtual void Command(wxCommandEvent &event);
130
9f884528
RD
131 virtual bool SetFont(const wxFont& font);
132
a3a4105d
VZ
133 // wxControl-specific processing after processing the update event
134 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
135
7a78a937
VZ
136 wxSize GetSizeFromTextSize(int xlen, int ylen = -1) const
137 { return DoGetSizeFromTextSize(xlen, ylen); }
138 wxSize GetSizeFromTextSize(const wxSize& tsize) const
139 { return DoGetSizeFromTextSize(tsize.x, tsize.y); }
a78618b0
FM
140
141
32ee98eb
FM
142 // static utilities for mnemonics char (&) handling
143 // ------------------------------------------------
a78618b0 144
32ee98eb 145 // returns the given string without mnemonic characters ('&')
a78618b0
FM
146 static wxString GetLabelText(const wxString& label);
147
32ee98eb
FM
148 // returns the given string without mnemonic characters ('&')
149 // this function is identic to GetLabelText() and is provided for clarity
150 // and for symmetry with the wxStaticText::RemoveMarkup() function.
a78618b0
FM
151 static wxString RemoveMnemonics(const wxString& str);
152
153 // escapes (by doubling them) the mnemonics
154 static wxString EscapeMnemonics(const wxString& str);
155
32ee98eb
FM
156
157 // miscellaneous static utilities
158 // ------------------------------
159
160 // replaces parts of the given (multiline) string with an ellipsis if needed
161 static wxString Ellipsize(const wxString& label, const wxDC& dc,
162 wxEllipsizeMode mode, int maxWidth,
163 int flags = wxELLIPSIZE_FLAGS_DEFAULT);
164
a78618b0
FM
165 // return the accel index in the string or -1 if none and puts the modified
166 // string into second parameter if non NULL
167 static int FindAccelIndex(const wxString& label,
168 wxString *labelOnly = NULL);
169
0534259a
VZ
170 // this is a helper for the derived class GetClassDefaultAttributes()
171 // implementation: it returns the right colours for the classes which
172 // contain something else (e.g. wxListBox, wxTextCtrl, ...) instead of
173 // being simple controls (such as wxButton, wxCheckBox, ...)
174 static wxVisualAttributes
175 GetCompositeControlsDefaultAttributes(wxWindowVariant variant);
176
8d99be5f 177protected:
dc797d8e
JS
178 // choose the default border for this window
179 virtual wxBorder GetDefaultBorder() const;
180
3f2711d5
VZ
181 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
182 // to the list of parents children
8d99be5f
VZ
183 bool CreateControl(wxWindowBase *parent,
184 wxWindowID id,
185 const wxPoint& pos,
186 const wxSize& size,
187 long style,
188 const wxValidator& validator,
189 const wxString& name);
190
f5bdfc69 191#if wxUSE_MARKUP
3da9cffc
VZ
192 // This function may be overridden in the derived classes to implement
193 // support for labels with markup. The base class version simply strips the
194 // markup and calls SetLabel() with the remaining text.
195 virtual bool DoSetLabelMarkup(const wxString& markup);
f5bdfc69 196#endif // wxUSE_MARKUP
3da9cffc 197
7a78a937
VZ
198 // override this to return the total control's size from a string size
199 virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
3da9cffc 200
bfbd6dc1
VZ
201 // initialize the common fields of wxCommandEvent
202 void InitCommandEvent(wxCommandEvent& event) const;
fc7a2a60 203
a78618b0
FM
204 // Ellipsize() helper:
205 static wxString DoEllipsizeSingleLine(const wxString& label, const wxDC& dc,
206 wxEllipsizeMode mode, int maxWidth,
1d065710 207 int replacementWidth);
a78618b0 208
f5bdfc69 209#if wxUSE_MARKUP
3da9cffc
VZ
210 // Remove markup from the given string, returns empty string on error i.e.
211 // if markup was syntactically invalid.
212 static wxString RemoveMarkup(const wxString& markup);
f5bdfc69 213#endif // wxUSE_MARKUP
3da9cffc
VZ
214
215
7517dcb5
FM
216 // this field contains the label in wx format, i.e. with '&' mnemonics,
217 // as it was passed to the last SetLabel() call
39bc0347
VZ
218 wxString m_labelOrig;
219
c0c133e1 220 wxDECLARE_NO_COPY_CLASS(wxControlBase);
8d99be5f
VZ
221};
222
223// ----------------------------------------------------------------------------
224// include platform-dependent wxControl declarations
225// ----------------------------------------------------------------------------
f03fc89f 226
1e6feb95
VZ
227#if defined(__WXUNIVERSAL__)
228 #include "wx/univ/control.h"
229#elif defined(__WXMSW__)
8d99be5f 230 #include "wx/msw/control.h"
2049ba38 231#elif defined(__WXMOTIF__)
8d99be5f 232 #include "wx/motif/control.h"
1be7a35c 233#elif defined(__WXGTK20__)
8d99be5f 234 #include "wx/gtk/control.h"
1be7a35c
MR
235#elif defined(__WXGTK__)
236 #include "wx/gtk1/control.h"
34138703 237#elif defined(__WXMAC__)
ef0e9220 238 #include "wx/osx/control.h"
e64df9bc
DE
239#elif defined(__WXCOCOA__)
240 #include "wx/cocoa/control.h"
1777b9bb
DW
241#elif defined(__WXPM__)
242 #include "wx/os2/control.h"
c801d85f
KB
243#endif
244
1e6feb95
VZ
245#endif // wxUSE_CONTROLS
246
c801d85f 247#endif
34138703 248 // _WX_CONTROL_H_BASE_