1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxControl common interface
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CONTROL_H_BASE_
13 #define _WX_CONTROL_H_BASE_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
23 #include "wx/window.h" // base class
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr
[];
28 // ----------------------------------------------------------------------------
29 // Ellipsize() constants
30 // ----------------------------------------------------------------------------
34 wxELLIPSIZE_FLAGS_NONE
= 0,
35 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
= 1,
36 wxELLIPSIZE_FLAGS_EXPAND_TABS
= 2,
38 wxELLIPSIZE_FLAGS_DEFAULT
= wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
|
39 wxELLIPSIZE_FLAGS_EXPAND_TABS
42 // NB: Don't change the order of these values, they're the same as in
43 // PangoEllipsizeMode enum.
52 // ----------------------------------------------------------------------------
53 // wxControl is the base class for all controls
54 // ----------------------------------------------------------------------------
56 class WXDLLIMPEXP_CORE wxControlBase
: public wxWindow
61 virtual ~wxControlBase();
63 // Create() function adds the validator parameter
64 bool Create(wxWindow
*parent
, wxWindowID id
,
65 const wxPoint
& pos
= wxDefaultPosition
,
66 const wxSize
& size
= wxDefaultSize
,
68 const wxValidator
& validator
= wxDefaultValidator
,
69 const wxString
& name
= wxControlNameStr
);
71 // get the control alignment (left/right/centre, top/bottom/centre)
72 int GetAlignment() const { return m_windowStyle
& wxALIGN_MASK
; }
74 // set label with mnemonics
75 virtual void SetLabel(const wxString
& label
)
81 wxWindow::SetLabel(label
);
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
; }
88 // set label text (mnemonics will be escaped)
89 virtual void SetLabelText(const wxString
& text
)
91 SetLabel(EscapeMnemonics(text
));
94 // get just the text of the label, without mnemonic characters ('&')
95 virtual wxString
GetLabelText() const { return GetLabelText(GetLabel()); }
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.
105 // Notice that, being HTML-like, markup also supports XML entities so '<'
106 // should be encoded as "<" 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 "&" in the input string.
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
)
115 return DoSetLabelMarkup(markup
);
117 #endif // wxUSE_MARKUP
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; }
126 // WARNING: this doesn't work for all controls nor all platforms!
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
);
132 virtual bool SetFont(const wxFont
& font
);
134 // wxControl-specific processing after processing the update event
135 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
139 // static utilities for mnemonics char (&) handling
140 // ------------------------------------------------
142 // returns the given string without mnemonic characters ('&')
143 static wxString
GetLabelText(const wxString
& label
);
145 // returns the given string without mnemonic characters ('&')
146 // this function is identic to GetLabelText() and is provided for clarity
147 // and for symmetry with the wxStaticText::RemoveMarkup() function.
148 static wxString
RemoveMnemonics(const wxString
& str
);
150 // escapes (by doubling them) the mnemonics
151 static wxString
EscapeMnemonics(const wxString
& str
);
154 // miscellaneous static utilities
155 // ------------------------------
157 // replaces parts of the given (multiline) string with an ellipsis if needed
158 static wxString
Ellipsize(const wxString
& label
, const wxDC
& dc
,
159 wxEllipsizeMode mode
, int maxWidth
,
160 int flags
= wxELLIPSIZE_FLAGS_DEFAULT
);
162 // return the accel index in the string or -1 if none and puts the modified
163 // string into second parameter if non NULL
164 static int FindAccelIndex(const wxString
& label
,
165 wxString
*labelOnly
= NULL
);
167 // this is a helper for the derived class GetClassDefaultAttributes()
168 // implementation: it returns the right colours for the classes which
169 // contain something else (e.g. wxListBox, wxTextCtrl, ...) instead of
170 // being simple controls (such as wxButton, wxCheckBox, ...)
171 static wxVisualAttributes
172 GetCompositeControlsDefaultAttributes(wxWindowVariant variant
);
175 // choose the default border for this window
176 virtual wxBorder
GetDefaultBorder() const;
178 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
179 // to the list of parents children
180 bool CreateControl(wxWindowBase
*parent
,
185 const wxValidator
& validator
,
186 const wxString
& name
);
189 // This function may be overridden in the derived classes to implement
190 // support for labels with markup. The base class version simply strips the
191 // markup and calls SetLabel() with the remaining text.
192 virtual bool DoSetLabelMarkup(const wxString
& markup
);
193 #endif // wxUSE_MARKUP
196 // initialize the common fields of wxCommandEvent
197 void InitCommandEvent(wxCommandEvent
& event
) const;
199 // Ellipsize() helper:
200 static wxString
DoEllipsizeSingleLine(const wxString
& label
, const wxDC
& dc
,
201 wxEllipsizeMode mode
, int maxWidth
,
202 int replacementWidth
);
205 // Remove markup from the given string, returns empty string on error i.e.
206 // if markup was syntactically invalid.
207 static wxString
RemoveMarkup(const wxString
& markup
);
208 #endif // wxUSE_MARKUP
211 // this field contains the label in wx format, i.e. with '&' mnemonics,
212 // as it was passed to the last SetLabel() call
213 wxString m_labelOrig
;
215 wxDECLARE_NO_COPY_CLASS(wxControlBase
);
218 // ----------------------------------------------------------------------------
219 // include platform-dependent wxControl declarations
220 // ----------------------------------------------------------------------------
222 #if defined(__WXUNIVERSAL__)
223 #include "wx/univ/control.h"
224 #elif defined(__WXPALMOS__)
225 #include "wx/palmos/control.h"
226 #elif defined(__WXMSW__)
227 #include "wx/msw/control.h"
228 #elif defined(__WXMOTIF__)
229 #include "wx/motif/control.h"
230 #elif defined(__WXGTK20__)
231 #include "wx/gtk/control.h"
232 #elif defined(__WXGTK__)
233 #include "wx/gtk1/control.h"
234 #elif defined(__WXMAC__)
235 #include "wx/osx/control.h"
236 #elif defined(__WXCOCOA__)
237 #include "wx/cocoa/control.h"
238 #elif defined(__WXPM__)
239 #include "wx/os2/control.h"
242 #endif // wxUSE_CONTROLS
245 // _WX_CONTROL_H_BASE_