1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxControl common interface
4 // Author: Vadim Zeitlin
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CONTROL_H_BASE_
12 #define _WX_CONTROL_H_BASE_
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
22 #include "wx/window.h" // base class
24 extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr
[];
27 // ----------------------------------------------------------------------------
28 // Ellipsize() constants
29 // ----------------------------------------------------------------------------
33 wxELLIPSIZE_FLAGS_NONE
= 0,
34 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
= 1,
35 wxELLIPSIZE_FLAGS_EXPAND_TABS
= 2,
37 wxELLIPSIZE_FLAGS_DEFAULT
= wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS
|
38 wxELLIPSIZE_FLAGS_EXPAND_TABS
41 // NB: Don't change the order of these values, they're the same as in
42 // PangoEllipsizeMode enum.
51 // ----------------------------------------------------------------------------
52 // wxControl is the base class for all controls
53 // ----------------------------------------------------------------------------
55 class WXDLLIMPEXP_CORE wxControlBase
: public wxWindow
60 virtual ~wxControlBase();
62 // Create() function adds the validator parameter
63 bool Create(wxWindow
*parent
, wxWindowID id
,
64 const wxPoint
& pos
= wxDefaultPosition
,
65 const wxSize
& size
= wxDefaultSize
,
67 const wxValidator
& validator
= wxDefaultValidator
,
68 const wxString
& name
= wxControlNameStr
);
70 // get the control alignment (left/right/centre, top/bottom/centre)
71 int GetAlignment() const { return m_windowStyle
& wxALIGN_MASK
; }
73 // set label with mnemonics
74 virtual void SetLabel(const wxString
& label
)
80 wxWindow::SetLabel(label
);
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
; }
87 // set label text (mnemonics will be escaped)
88 virtual void SetLabelText(const wxString
& text
)
90 SetLabel(EscapeMnemonics(text
));
93 // get just the text of the label, without mnemonic characters ('&')
94 virtual wxString
GetLabelText() const { return GetLabelText(GetLabel()); }
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.
104 // Notice that, being HTML-like, markup also supports XML entities so '<'
105 // should be encoded as "<" 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 "&" in the input string.
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
)
114 return DoSetLabelMarkup(markup
);
116 #endif // wxUSE_MARKUP
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; }
125 // WARNING: this doesn't work for all controls nor all platforms!
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
);
131 virtual bool SetFont(const wxFont
& font
);
133 // wxControl-specific processing after processing the update event
134 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
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
); }
142 // static utilities for mnemonics char (&) handling
143 // ------------------------------------------------
145 // returns the given string without mnemonic characters ('&')
146 static wxString
GetLabelText(const wxString
& label
);
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.
151 static wxString
RemoveMnemonics(const wxString
& str
);
153 // escapes (by doubling them) the mnemonics
154 static wxString
EscapeMnemonics(const wxString
& str
);
157 // miscellaneous static utilities
158 // ------------------------------
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
);
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
);
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
);
178 // choose the default border for this window
179 virtual wxBorder
GetDefaultBorder() const;
181 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
182 // to the list of parents children
183 bool CreateControl(wxWindowBase
*parent
,
188 const wxValidator
& validator
,
189 const wxString
& name
);
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
);
196 #endif // wxUSE_MARKUP
198 // override this to return the total control's size from a string size
199 virtual wxSize
DoGetSizeFromTextSize(int xlen
, int ylen
= -1) const;
201 // initialize the common fields of wxCommandEvent
202 void InitCommandEvent(wxCommandEvent
& event
) const;
204 // Ellipsize() helper:
205 static wxString
DoEllipsizeSingleLine(const wxString
& label
, const wxDC
& dc
,
206 wxEllipsizeMode mode
, int maxWidth
,
207 int replacementWidth
);
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
);
213 #endif // wxUSE_MARKUP
216 // this field contains the label in wx format, i.e. with '&' mnemonics,
217 // as it was passed to the last SetLabel() call
218 wxString m_labelOrig
;
220 wxDECLARE_NO_COPY_CLASS(wxControlBase
);
223 // ----------------------------------------------------------------------------
224 // include platform-dependent wxControl declarations
225 // ----------------------------------------------------------------------------
227 #if defined(__WXUNIVERSAL__)
228 #include "wx/univ/control.h"
229 #elif defined(__WXMSW__)
230 #include "wx/msw/control.h"
231 #elif defined(__WXMOTIF__)
232 #include "wx/motif/control.h"
233 #elif defined(__WXGTK20__)
234 #include "wx/gtk/control.h"
235 #elif defined(__WXGTK__)
236 #include "wx/gtk1/control.h"
237 #elif defined(__WXMAC__)
238 #include "wx/osx/control.h"
239 #elif defined(__WXCOCOA__)
240 #include "wx/cocoa/control.h"
241 #elif defined(__WXPM__)
242 #include "wx/os2/control.h"
245 #endif // wxUSE_CONTROLS
248 // _WX_CONTROL_H_BASE_