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