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
[];
34 // ----------------------------------------------------------------------------
35 // wxControl is the base class for all controls
36 // ----------------------------------------------------------------------------
38 class WXDLLIMPEXP_CORE wxControlBase
: public wxWindow
43 virtual ~wxControlBase();
45 // Create() function adds the validator parameter
46 bool Create(wxWindow
*parent
, wxWindowID id
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
,
50 const wxValidator
& validator
= wxDefaultValidator
,
51 const wxString
& name
= wxControlNameStr
);
53 // get the control alignment (left/right/centre, top/bottom/centre)
54 int GetAlignment() const { return m_windowStyle
& wxALIGN_MASK
; }
56 virtual void SetLabel(const wxString
& label
)
62 wxWindow::SetLabel(label
);
65 virtual wxString
GetLabel() const
67 // return the original string, as it was passed to SetLabel()
68 // (i.e. with wx-style mnemonics)
72 // get just the text of the label, without mnemonic characters ('&')
73 wxString
GetLabelText() const { return GetLabelText(GetLabel()); }
75 void SetLabelText(const wxString
& text
)
77 SetLabel(EscapeMnemonics(text
));
82 // replaces parts of the string with ellipsis if needed
83 static wxString
Ellipsize(const wxString
& label
, const wxDC
& dc
,
84 wxEllipsizeMode mode
, int maxWidth
);
86 // get the string without mnemonic characters ('&')
87 static wxString
GetLabelText(const wxString
& label
);
89 // removes the mnemonics characters
90 static wxString
RemoveMnemonics(const wxString
& str
);
92 // escapes (by doubling them) the mnemonics
93 static wxString
EscapeMnemonics(const wxString
& str
);
95 // return the accel index in the string or -1 if none and puts the modified
96 // string into second parameter if non NULL
97 static int FindAccelIndex(const wxString
& label
,
98 wxString
*labelOnly
= NULL
);
101 // controls by default inherit the colours of their parents, if a
102 // particular control class doesn't want to do it, it can override
103 // ShouldInheritColours() to return false
104 virtual bool ShouldInheritColours() const { return true; }
107 // WARNING: this doesn't work for all controls nor all platforms!
109 // simulates the event of given type (i.e. wxButton::Command() is just as
110 // if the button was clicked)
111 virtual void Command(wxCommandEvent
&event
);
113 virtual bool SetFont(const wxFont
& font
);
115 // wxControl-specific processing after processing the update event
116 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
119 // choose the default border for this window
120 virtual wxBorder
GetDefaultBorder() const;
122 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
123 // to the list of parents children
124 bool CreateControl(wxWindowBase
*parent
,
129 const wxValidator
& validator
,
130 const wxString
& name
);
132 // initialize the common fields of wxCommandEvent
133 void InitCommandEvent(wxCommandEvent
& event
) const;
135 // this field contains the label in wx format, i.e. with '&' mnemonics
136 wxString m_labelOrig
;
138 DECLARE_NO_COPY_CLASS(wxControlBase
)
141 // ----------------------------------------------------------------------------
142 // include platform-dependent wxControl declarations
143 // ----------------------------------------------------------------------------
145 #if defined(__WXUNIVERSAL__)
146 #include "wx/univ/control.h"
147 #elif defined(__WXPALMOS__)
148 #include "wx/palmos/control.h"
149 #elif defined(__WXMSW__)
150 #include "wx/msw/control.h"
151 #elif defined(__WXMOTIF__)
152 #include "wx/motif/control.h"
153 #elif defined(__WXGTK20__)
154 #include "wx/gtk/control.h"
155 #elif defined(__WXGTK__)
156 #include "wx/gtk1/control.h"
157 #elif defined(__WXMAC__)
158 #include "wx/osx/control.h"
159 #elif defined(__WXCOCOA__)
160 #include "wx/cocoa/control.h"
161 #elif defined(__WXPM__)
162 #include "wx/os2/control.h"
165 #endif // wxUSE_CONTROLS
168 // _WX_CONTROL_H_BASE_