]> git.saurik.com Git - wxWidgets.git/blob - include/wx/control.h
Replace wxST_MARKUP style with wxControl::SetLabelMarkup().
[wxWidgets.git] / include / wx / control.h
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$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CONTROL_H_BASE_
13 #define _WX_CONTROL_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/defs.h"
20
21 #if wxUSE_CONTROLS
22
23 #include "wx/window.h" // base class
24
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr[];
26
27
28 // ----------------------------------------------------------------------------
29 // Ellipsize() constants
30 // ----------------------------------------------------------------------------
31
32 enum wxEllipsizeFlags
33 {
34 wxELLIPSIZE_FLAGS_NONE = 0,
35 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS = 1,
36 wxELLIPSIZE_FLAGS_EXPAND_TABS = 2,
37
38 wxELLIPSIZE_FLAGS_DEFAULT = wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS |
39 wxELLIPSIZE_FLAGS_EXPAND_TABS
40 };
41
42 // NB: Don't change the order of these values, they're the same as in
43 // PangoEllipsizeMode enum.
44 enum wxEllipsizeMode
45 {
46 wxELLIPSIZE_NONE,
47 wxELLIPSIZE_START,
48 wxELLIPSIZE_MIDDLE,
49 wxELLIPSIZE_END
50 };
51
52 // ----------------------------------------------------------------------------
53 // wxControl is the base class for all controls
54 // ----------------------------------------------------------------------------
55
56 class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
57 {
58 public:
59 wxControlBase() { }
60
61 virtual ~wxControlBase();
62
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
71 // get the control alignment (left/right/centre, top/bottom/centre)
72 int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
73
74 // set label with mnemonics
75 virtual void SetLabel(const wxString& label)
76 {
77 m_labelOrig = label;
78
79 InvalidateBestSize();
80
81 wxWindow::SetLabel(label);
82 }
83
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; }
87
88 // set label text (mnemonics will be escaped)
89 virtual void SetLabelText(const wxString& text)
90 {
91 SetLabel(EscapeMnemonics(text));
92 }
93
94 // get just the text of the label, without mnemonic characters ('&')
95 virtual wxString GetLabelText() const { return GetLabelText(GetLabel()); }
96
97
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 }
116
117
118 // controls by default inherit the colours of their parents, if a
119 // particular control class doesn't want to do it, it can override
120 // ShouldInheritColours() to return false
121 virtual bool ShouldInheritColours() const { return true; }
122
123
124 // WARNING: this doesn't work for all controls nor all platforms!
125 //
126 // simulates the event of given type (i.e. wxButton::Command() is just as
127 // if the button was clicked)
128 virtual void Command(wxCommandEvent &event);
129
130 virtual bool SetFont(const wxFont& font);
131
132 // wxControl-specific processing after processing the update event
133 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
134
135
136
137 // static utilities for mnemonics char (&) handling
138 // ------------------------------------------------
139
140 // returns the given string without mnemonic characters ('&')
141 static wxString GetLabelText(const wxString& label);
142
143 // returns the given string without mnemonic characters ('&')
144 // this function is identic to GetLabelText() and is provided for clarity
145 // and for symmetry with the wxStaticText::RemoveMarkup() function.
146 static wxString RemoveMnemonics(const wxString& str);
147
148 // escapes (by doubling them) the mnemonics
149 static wxString EscapeMnemonics(const wxString& str);
150
151
152 // miscellaneous static utilities
153 // ------------------------------
154
155 // replaces parts of the given (multiline) string with an ellipsis if needed
156 static wxString Ellipsize(const wxString& label, const wxDC& dc,
157 wxEllipsizeMode mode, int maxWidth,
158 int flags = wxELLIPSIZE_FLAGS_DEFAULT);
159
160 // return the accel index in the string or -1 if none and puts the modified
161 // string into second parameter if non NULL
162 static int FindAccelIndex(const wxString& label,
163 wxString *labelOnly = NULL);
164
165 // this is a helper for the derived class GetClassDefaultAttributes()
166 // implementation: it returns the right colours for the classes which
167 // contain something else (e.g. wxListBox, wxTextCtrl, ...) instead of
168 // being simple controls (such as wxButton, wxCheckBox, ...)
169 static wxVisualAttributes
170 GetCompositeControlsDefaultAttributes(wxWindowVariant variant);
171
172 protected:
173 // choose the default border for this window
174 virtual wxBorder GetDefaultBorder() const;
175
176 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
177 // to the list of parents children
178 bool CreateControl(wxWindowBase *parent,
179 wxWindowID id,
180 const wxPoint& pos,
181 const wxSize& size,
182 long style,
183 const wxValidator& validator,
184 const wxString& name);
185
186 // This function may be overridden in the derived classes to implement
187 // support for labels with markup. The base class version simply strips the
188 // markup and calls SetLabel() with the remaining text.
189 virtual bool DoSetLabelMarkup(const wxString& markup);
190
191
192 // initialize the common fields of wxCommandEvent
193 void InitCommandEvent(wxCommandEvent& event) const;
194
195 // Ellipsize() helper:
196 static wxString DoEllipsizeSingleLine(const wxString& label, const wxDC& dc,
197 wxEllipsizeMode mode, int maxWidth,
198 int replacementWidth);
199
200 // Remove markup from the given string, returns empty string on error i.e.
201 // if markup was syntactically invalid.
202 static wxString RemoveMarkup(const wxString& markup);
203
204
205 // this field contains the label in wx format, i.e. with '&' mnemonics,
206 // as it was passed to the last SetLabel() call
207 wxString m_labelOrig;
208
209 wxDECLARE_NO_COPY_CLASS(wxControlBase);
210 };
211
212 // ----------------------------------------------------------------------------
213 // include platform-dependent wxControl declarations
214 // ----------------------------------------------------------------------------
215
216 #if defined(__WXUNIVERSAL__)
217 #include "wx/univ/control.h"
218 #elif defined(__WXPALMOS__)
219 #include "wx/palmos/control.h"
220 #elif defined(__WXMSW__)
221 #include "wx/msw/control.h"
222 #elif defined(__WXMOTIF__)
223 #include "wx/motif/control.h"
224 #elif defined(__WXGTK20__)
225 #include "wx/gtk/control.h"
226 #elif defined(__WXGTK__)
227 #include "wx/gtk1/control.h"
228 #elif defined(__WXMAC__)
229 #include "wx/osx/control.h"
230 #elif defined(__WXCOCOA__)
231 #include "wx/cocoa/control.h"
232 #elif defined(__WXPM__)
233 #include "wx/os2/control.h"
234 #endif
235
236 #endif // wxUSE_CONTROLS
237
238 #endif
239 // _WX_CONTROL_H_BASE_