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