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_PROCESS_MNEMONICS
= 1,
35 wxELLIPSIZE_EXPAND_TAB
= 2,
37 wxELLIPSIZE_DEFAULT_FLAGS
= wxELLIPSIZE_PROCESS_MNEMONICS
|wxELLIPSIZE_EXPAND_TAB
47 // ----------------------------------------------------------------------------
48 // wxControl is the base class for all controls
49 // ----------------------------------------------------------------------------
51 class WXDLLIMPEXP_CORE wxControlBase
: public wxWindow
56 virtual ~wxControlBase();
58 // Create() function adds the validator parameter
59 bool Create(wxWindow
*parent
, wxWindowID id
,
60 const wxPoint
& pos
= wxDefaultPosition
,
61 const wxSize
& size
= wxDefaultSize
,
63 const wxValidator
& validator
= wxDefaultValidator
,
64 const wxString
& name
= wxControlNameStr
);
66 // get the control alignment (left/right/centre, top/bottom/centre)
67 int GetAlignment() const { return m_windowStyle
& wxALIGN_MASK
; }
69 virtual void SetLabel(const wxString
& label
)
75 wxWindow::SetLabel(label
);
78 virtual wxString
GetLabel() const
80 // return the original string, as it was passed to SetLabel()
81 // (i.e. with wx-style mnemonics)
85 // get just the text of the label, without mnemonic characters ('&')
86 wxString
GetLabelText() const { return GetLabelText(GetLabel()); }
88 void SetLabelText(const wxString
& text
)
90 SetLabel(EscapeMnemonics(text
));
93 // controls by default inherit the colours of their parents, if a
94 // particular control class doesn't want to do it, it can override
95 // ShouldInheritColours() to return false
96 virtual bool ShouldInheritColours() const { return true; }
99 // WARNING: this doesn't work for all controls nor all platforms!
101 // simulates the event of given type (i.e. wxButton::Command() is just as
102 // if the button was clicked)
103 virtual void Command(wxCommandEvent
&event
);
105 virtual bool SetFont(const wxFont
& font
);
107 // wxControl-specific processing after processing the update event
108 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
115 // replaces parts of the (multiline) string with ellipsis if needed
116 static wxString
Ellipsize(const wxString
& label
, const wxDC
& dc
,
117 wxEllipsizeMode mode
, int maxWidth
,
118 int flags
= wxELLIPSIZE_DEFAULT_FLAGS
);
120 // get the string without mnemonic characters ('&')
121 static wxString
GetLabelText(const wxString
& label
);
123 // removes the mnemonics characters
124 static wxString
RemoveMnemonics(const wxString
& str
);
126 // escapes (by doubling them) the mnemonics
127 static wxString
EscapeMnemonics(const wxString
& str
);
129 // return the accel index in the string or -1 if none and puts the modified
130 // string into second parameter if non NULL
131 static int FindAccelIndex(const wxString
& label
,
132 wxString
*labelOnly
= NULL
);
135 // choose the default border for this window
136 virtual wxBorder
GetDefaultBorder() const;
138 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
139 // to the list of parents children
140 bool CreateControl(wxWindowBase
*parent
,
145 const wxValidator
& validator
,
146 const wxString
& name
);
148 // initialize the common fields of wxCommandEvent
149 void InitCommandEvent(wxCommandEvent
& event
) const;
151 // Ellipsize() helper:
152 static wxString
DoEllipsizeSingleLine(const wxString
& label
, const wxDC
& dc
,
153 wxEllipsizeMode mode
, int maxWidth
,
154 int replacementWidth
, int marginWidth
);
156 // this field contains the label in wx format, i.e. with '&' mnemonics
157 wxString m_labelOrig
;
159 wxDECLARE_NO_COPY_CLASS(wxControlBase
);
162 // ----------------------------------------------------------------------------
163 // include platform-dependent wxControl declarations
164 // ----------------------------------------------------------------------------
166 #if defined(__WXUNIVERSAL__)
167 #include "wx/univ/control.h"
168 #elif defined(__WXPALMOS__)
169 #include "wx/palmos/control.h"
170 #elif defined(__WXMSW__)
171 #include "wx/msw/control.h"
172 #elif defined(__WXMOTIF__)
173 #include "wx/motif/control.h"
174 #elif defined(__WXGTK20__)
175 #include "wx/gtk/control.h"
176 #elif defined(__WXGTK__)
177 #include "wx/gtk1/control.h"
178 #elif defined(__WXMAC__)
179 #include "wx/osx/control.h"
180 #elif defined(__WXCOCOA__)
181 #include "wx/cocoa/control.h"
182 #elif defined(__WXPM__)
183 #include "wx/os2/control.h"
186 #endif // wxUSE_CONTROLS
189 // _WX_CONTROL_H_BASE_