Rename wxEllipsizeFlags elements to avoid confusion with wxEllipsizeMode.
[wxWidgets.git] / include / wx / control.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/control.h
3 // Purpose: wxControl common interface
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 26.07.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CONTROL_H_BASE_
13 #define _WX_CONTROL_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/defs.h"
20
21 #if wxUSE_CONTROLS
22
23 #include "wx/window.h" // base class
24
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr[];
26
27
28 // ----------------------------------------------------------------------------
29 // Ellipsize() constants
30 // ----------------------------------------------------------------------------
31
32 enum wxEllipsizeFlags
33 {
34 wxELLIPSIZE_FLAGS_NONE = 0,
35 wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS = 1,
36 wxELLIPSIZE_FLAGS_EXPAND_TABS = 2,
37
38 wxELLIPSIZE_FLAGS_DEFAULT = wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS |
39 wxELLIPSIZE_FLAGS_EXPAND_TABS
40 };
41
42 enum wxEllipsizeMode
43 {
44 wxELLIPSIZE_START,
45 wxELLIPSIZE_MIDDLE,
46 wxELLIPSIZE_END
47 };
48
49 // ----------------------------------------------------------------------------
50 // wxControl is the base class for all controls
51 // ----------------------------------------------------------------------------
52
53 class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
54 {
55 public:
56 wxControlBase() { }
57
58 virtual ~wxControlBase();
59
60 // Create() function adds the validator parameter
61 bool Create(wxWindow *parent, wxWindowID id,
62 const wxPoint& pos = wxDefaultPosition,
63 const wxSize& size = wxDefaultSize,
64 long style = 0,
65 const wxValidator& validator = wxDefaultValidator,
66 const wxString& name = wxControlNameStr);
67
68 // get the control alignment (left/right/centre, top/bottom/centre)
69 int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
70
71 virtual void SetLabel(const wxString& label)
72 {
73 m_labelOrig = label;
74
75 InvalidateBestSize();
76
77 wxWindow::SetLabel(label);
78 }
79
80 virtual wxString GetLabel() const
81 {
82 // return the original string, as it was passed to SetLabel()
83 // (i.e. with wx-style mnemonics)
84 return m_labelOrig;
85 }
86
87 // get just the text of the label, without mnemonic characters ('&')
88 wxString GetLabelText() const { return GetLabelText(GetLabel()); }
89
90 void SetLabelText(const wxString& text)
91 {
92 SetLabel(EscapeMnemonics(text));
93 }
94
95 // controls by default inherit the colours of their parents, if a
96 // particular control class doesn't want to do it, it can override
97 // ShouldInheritColours() to return false
98 virtual bool ShouldInheritColours() const { return true; }
99
100
101 // WARNING: this doesn't work for all controls nor all platforms!
102 //
103 // simulates the event of given type (i.e. wxButton::Command() is just as
104 // if the button was clicked)
105 virtual void Command(wxCommandEvent &event);
106
107 virtual bool SetFont(const wxFont& font);
108
109 // wxControl-specific processing after processing the update event
110 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
111
112
113
114 // static utilities
115 // ----------------
116
117 // replaces parts of the (multiline) string with ellipsis if needed
118 static wxString Ellipsize(const wxString& label, const wxDC& dc,
119 wxEllipsizeMode mode, int maxWidth,
120 int flags = wxELLIPSIZE_FLAGS_DEFAULT);
121
122 // get the string without mnemonic characters ('&')
123 static wxString GetLabelText(const wxString& label);
124
125 // removes the mnemonics characters
126 static wxString RemoveMnemonics(const wxString& str);
127
128 // escapes (by doubling them) the mnemonics
129 static wxString EscapeMnemonics(const wxString& str);
130
131 // return the accel index in the string or -1 if none and puts the modified
132 // string into second parameter if non NULL
133 static int FindAccelIndex(const wxString& label,
134 wxString *labelOnly = NULL);
135
136 // this is a helper for the derived class GetClassDefaultAttributes()
137 // implementation: it returns the right colours for the classes which
138 // contain something else (e.g. wxListBox, wxTextCtrl, ...) instead of
139 // being simple controls (such as wxButton, wxCheckBox, ...)
140 static wxVisualAttributes
141 GetCompositeControlsDefaultAttributes(wxWindowVariant variant);
142
143 protected:
144 // choose the default border for this window
145 virtual wxBorder GetDefaultBorder() const;
146
147 // creates the control (calls wxWindowBase::CreateBase inside) and adds it
148 // to the list of parents children
149 bool CreateControl(wxWindowBase *parent,
150 wxWindowID id,
151 const wxPoint& pos,
152 const wxSize& size,
153 long style,
154 const wxValidator& validator,
155 const wxString& name);
156
157 // initialize the common fields of wxCommandEvent
158 void InitCommandEvent(wxCommandEvent& event) const;
159
160 // Ellipsize() helper:
161 static wxString DoEllipsizeSingleLine(const wxString& label, const wxDC& dc,
162 wxEllipsizeMode mode, int maxWidth,
163 int replacementWidth, int marginWidth);
164
165 // this field contains the label in wx format, i.e. with '&' mnemonics
166 wxString m_labelOrig;
167
168 wxDECLARE_NO_COPY_CLASS(wxControlBase);
169 };
170
171 // ----------------------------------------------------------------------------
172 // include platform-dependent wxControl declarations
173 // ----------------------------------------------------------------------------
174
175 #if defined(__WXUNIVERSAL__)
176 #include "wx/univ/control.h"
177 #elif defined(__WXPALMOS__)
178 #include "wx/palmos/control.h"
179 #elif defined(__WXMSW__)
180 #include "wx/msw/control.h"
181 #elif defined(__WXMOTIF__)
182 #include "wx/motif/control.h"
183 #elif defined(__WXGTK20__)
184 #include "wx/gtk/control.h"
185 #elif defined(__WXGTK__)
186 #include "wx/gtk1/control.h"
187 #elif defined(__WXMAC__)
188 #include "wx/osx/control.h"
189 #elif defined(__WXCOCOA__)
190 #include "wx/cocoa/control.h"
191 #elif defined(__WXPM__)
192 #include "wx/os2/control.h"
193 #endif
194
195 #endif // wxUSE_CONTROLS
196
197 #endif
198 // _WX_CONTROL_H_BASE_