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()); }
97 // controls by default inherit the colours of their parents, if a
98 // particular control class doesn't want to do it, it can override
99 // ShouldInheritColours() to return false
100 virtual bool ShouldInheritColours() const { return true; }
103 // WARNING: this doesn't work for all controls nor all platforms!
105 // simulates the event of given type (i.e. wxButton::Command() is just as
106 // if the button was clicked)
107 virtual void Command(wxCommandEvent
&event
);
109 virtual bool SetFont(const wxFont
& font
);
111 // wxControl-specific processing after processing the update event
112 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
116 // static utilities for mnemonics char (&) handling
117 // ------------------------------------------------
119 // returns the given string without mnemonic characters ('&')
120 static wxString
GetLabelText(const wxString
& label
);
122 // returns the given string without mnemonic characters ('&')
123 // this function is identic to GetLabelText() and is provided for clarity
124 // and for symmetry with the wxStaticText::RemoveMarkup() function.
125 static wxString
RemoveMnemonics(const wxString
& str
);
127 // escapes (by doubling them) the mnemonics
128 static wxString
EscapeMnemonics(const wxString
& str
);
131 // miscellaneous static utilities
132 // ------------------------------
134 // replaces parts of the given (multiline) string with an ellipsis if needed
135 static wxString
Ellipsize(const wxString
& label
, const wxDC
& dc
,
136 wxEllipsizeMode mode
, int maxWidth
,
137 int flags
= wxELLIPSIZE_FLAGS_DEFAULT
);
139 // return the accel index in the string or -1 if none and puts the modified
140 // string into second parameter if non NULL
141 static int FindAccelIndex(const wxString
& label
,
142 wxString
*labelOnly
= NULL
);
144 // this is a helper for the derived class GetClassDefaultAttributes()
145 // implementation: it returns the right colours for the classes which
146 // contain something else (e.g. wxListBox, wxTextCtrl, ...) instead of
147 // being simple controls (such as wxButton, wxCheckBox, ...)
148 static wxVisualAttributes
149 GetCompositeControlsDefaultAttributes(wxWindowVariant variant
);
152 // choose the default border for this window
153 virtual wxBorder
GetDefaultBorder() const;
155 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
156 // to the list of parents children
157 bool CreateControl(wxWindowBase
*parent
,
162 const wxValidator
& validator
,
163 const wxString
& name
);
165 // initialize the common fields of wxCommandEvent
166 void InitCommandEvent(wxCommandEvent
& event
) const;
168 // Ellipsize() helper:
169 static wxString
DoEllipsizeSingleLine(const wxString
& label
, const wxDC
& dc
,
170 wxEllipsizeMode mode
, int maxWidth
,
171 int replacementWidth
, int marginWidth
);
173 // this field contains the label in wx format, i.e. with '&' mnemonics
174 wxString m_labelOrig
;
176 wxDECLARE_NO_COPY_CLASS(wxControlBase
);
179 // ----------------------------------------------------------------------------
180 // include platform-dependent wxControl declarations
181 // ----------------------------------------------------------------------------
183 #if defined(__WXUNIVERSAL__)
184 #include "wx/univ/control.h"
185 #elif defined(__WXPALMOS__)
186 #include "wx/palmos/control.h"
187 #elif defined(__WXMSW__)
188 #include "wx/msw/control.h"
189 #elif defined(__WXMOTIF__)
190 #include "wx/motif/control.h"
191 #elif defined(__WXGTK20__)
192 #include "wx/gtk/control.h"
193 #elif defined(__WXGTK__)
194 #include "wx/gtk1/control.h"
195 #elif defined(__WXMAC__)
196 #include "wx/osx/control.h"
197 #elif defined(__WXCOCOA__)
198 #include "wx/cocoa/control.h"
199 #elif defined(__WXPM__)
200 #include "wx/os2/control.h"
203 #endif // wxUSE_CONTROLS
206 // _WX_CONTROL_H_BASE_