]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _control.i | |
3 | // Purpose: SWIG interface defs for wxControl and other base classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 10-June-1998 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | ||
b2dc1044 | 18 | MAKE_CONST_WXSTRING(ControlNameStr); |
d14a1e28 RD |
19 | |
20 | //--------------------------------------------------------------------------- | |
21 | %newgroup; | |
22 | ||
23 | ||
861d4832 RD |
24 | DocStr(wxControl, |
25 | "This is the base class for a control or 'widget'. | |
26 | ||
d07d2bc9 RD |
27 | A control is generally a small window which processes user input |
28 | and/or displays one or more item of data.", ""); | |
861d4832 | 29 | |
ab1f7d2a RD |
30 | MustHaveApp(wxControl); |
31 | ||
d14a1e28 RD |
32 | class wxControl : public wxWindow |
33 | { | |
34 | public: | |
2b9048c5 RD |
35 | %pythonAppend wxControl "self._setOORInfo(self)" |
36 | %pythonAppend wxControl() "" | |
b39c3fa0 | 37 | %typemap(out) wxControl*; // turn off this typemap |
d14a1e28 | 38 | |
861d4832 RD |
39 | DocCtorStr( |
40 | wxControl(wxWindow *parent, | |
11ec0dce RD |
41 | wxWindowID id=-1, |
42 | const wxPoint& pos=wxDefaultPosition, | |
43 | const wxSize& size=wxDefaultSize, | |
44 | long style=0, | |
45 | const wxValidator& validator=wxDefaultValidator, | |
861d4832 | 46 | const wxString& name=wxPyControlNameStr), |
d07d2bc9 RD |
47 | "Create a Control. Normally you should only call this from a subclass' |
48 | __init__ as a plain old wx.Control is not very useful.", ""); | |
861d4832 RD |
49 | |
50 | DocCtorStrName( | |
51 | wxControl(), | |
d07d2bc9 | 52 | "Precreate a Control control for 2-phase creation", "", |
861d4832 RD |
53 | PreControl); |
54 | ||
b39c3fa0 RD |
55 | // Turn it back on again |
56 | %typemap(out) wxControl* { $result = wxPyMake_wxObject($1, $owner); } | |
57 | ||
58 | ||
861d4832 RD |
59 | DocDeclStr( |
60 | bool , Create(wxWindow *parent, | |
d5573410 | 61 | wxWindowID id=-1, |
861d4832 RD |
62 | const wxPoint& pos=wxDefaultPosition, |
63 | const wxSize& size=wxDefaultSize, | |
64 | long style=0, | |
65 | const wxValidator& validator=wxDefaultValidator, | |
66 | const wxString& name=wxPyControlNameStr), | |
d07d2bc9 | 67 | "Do the 2nd phase and create the GUI control.", ""); |
861d4832 | 68 | |
d14a1e28 | 69 | |
6aaca5ba RD |
70 | DocDeclStr( |
71 | int , GetAlignment() const, | |
72 | "Get the control alignment (left/right/centre, top/bottom/centre)", ""); | |
73 | ||
74 | ||
3f847dc2 RD |
75 | // DocDeclStr( |
76 | // static wxString , GetLabelText(const wxString& label), | |
77 | // "Get the string without mnemonic characters ('&')", ""); | |
6aaca5ba RD |
78 | |
79 | ||
80 | DocDeclStr( | |
81 | wxString , GetLabelText() const, | |
82 | "Get just the text of the label, without mnemonic characters ('&')", ""); | |
83 | ||
84 | ||
85 | ||
861d4832 RD |
86 | DocDeclStr( |
87 | void , Command(wxCommandEvent& event), | |
d07d2bc9 RD |
88 | "Simulates the effect of the user issuing a command to the item. |
89 | ||
90 | :see: `wx.CommandEvent` | |
91 | ", ""); | |
861d4832 RD |
92 | |
93 | DocDeclStr( | |
94 | wxString , GetLabel(), | |
d07d2bc9 | 95 | "Return a control's text.", ""); |
861d4832 RD |
96 | |
97 | DocDeclStr( | |
98 | void , SetLabel(const wxString& label), | |
d07d2bc9 | 99 | "Sets the item's text.", ""); |
174051f6 | 100 | |
fe161a26 | 101 | |
d8d39b51 RD |
102 | // DocDeclStr( |
103 | // bool , GetAdjustMinSizeFlag(), | |
104 | // "Returns whether the minsize should be adjusted for this control when | |
105 | // `SetLabel` or `SetFont` are called.", ""); | |
fe161a26 | 106 | |
d8d39b51 RD |
107 | // DocDeclStr( |
108 | // void , SetAdjustMinSizeFlag(bool adjust), | |
109 | // "By default controls will readjust their size and minsize when | |
110 | // `SetLabel` or `SetFont` are called. This flag will allow you to | |
111 | // control this behavior.", " | |
112 | ||
113 | // :see: `GetAdjustMinSizeFlag` | |
114 | // "); | |
174051f6 RD |
115 | |
116 | static wxVisualAttributes | |
117 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
0eae5d09 RD |
118 | |
119 | %property(Alignment, GetAlignment, doc="See `GetAlignment`"); | |
120 | %property(Label, GetLabel, doc="See `GetLabel`"); | |
121 | %property(LabelText, GetLabelText, doc="See `GetLabelText`"); | |
122 | ||
d14a1e28 RD |
123 | }; |
124 | ||
125 | ||
126 | //--------------------------------------------------------------------------- | |
127 | %newgroup; | |
128 | ||
129 | ||
6f259188 RD |
130 | |
131 | ||
861d4832 | 132 | DocStr(wxItemContainer, |
6f259188 RD |
133 | "The wx.ItemContainer class defines an interface which is implemented |
134 | by all controls which have string subitems, each of which may be | |
135 | selected, such as `wx.ListBox`, `wx.CheckListBox`, `wx.Choice` as well | |
136 | as `wx.ComboBox` which implements an extended interface deriving from | |
d07d2bc9 | 137 | this one. |
861d4832 | 138 | |
d07d2bc9 RD |
139 | It defines the methods for accessing the control's items and although |
140 | each of the derived classes implements them differently, they still | |
141 | all conform to the same interface. | |
861d4832 | 142 | |
d07d2bc9 RD |
143 | The items in a wx.ItemContainer have (non empty) string labels and, |
144 | optionally, client data associated with them. | |
145 | ", ""); | |
861d4832 | 146 | |
d14a1e28 RD |
147 | class wxItemContainer |
148 | { | |
149 | public: | |
b870f2e6 | 150 | // wxItemContainer() ** It's an ABC |
861d4832 | 151 | |
d14a1e28 | 152 | |
d14a1e28 | 153 | %extend { |
861d4832 | 154 | DocStr(Append, |
d07d2bc9 RD |
155 | "Adds the item to the control, associating the given data with the item |
156 | if not None. The return value is the index of the newly added item | |
157 | which may be different from the last one if the control is sorted (e.g. | |
158 | has wx.LB_SORT or wx.CB_SORT style).", ""); | |
d14a1e28 RD |
159 | int Append(const wxString& item, PyObject* clientData=NULL) { |
160 | if (clientData) { | |
161 | wxPyClientData* data = new wxPyClientData(clientData); | |
162 | return self->Append(item, data); | |
163 | } else | |
164 | return self->Append(item); | |
165 | } | |
166 | } | |
167 | ||
d20c6820 | 168 | DocDeclAStrName( |
861d4832 | 169 | void , Append(const wxArrayString& strings), |
8423f117 | 170 | "AppendItems(self, List strings)", |
d07d2bc9 RD |
171 | "Apend several items at once to the control. Notice that calling this |
172 | method may be much faster than appending the items one by one if you | |
173 | need to add a lot of items.", "", | |
861d4832 | 174 | AppendItems); |
d14a1e28 | 175 | |
861d4832 | 176 | |
d14a1e28 | 177 | %extend { |
861d4832 | 178 | DocStr(Insert, |
d07d2bc9 RD |
179 | "Insert an item into the control before the item at the ``pos`` index, |
180 | optionally associating some data object with the item.", ""); | |
3f5ec806 | 181 | int Insert(const wxString& item, unsigned int pos, PyObject* clientData=NULL) { |
d14a1e28 RD |
182 | if (clientData) { |
183 | wxPyClientData* data = new wxPyClientData(clientData); | |
184 | return self->Insert(item, pos, data); | |
185 | } else | |
186 | return self->Insert(item, pos); | |
187 | } | |
188 | } | |
189 | ||
190 | ||
861d4832 RD |
191 | DocDeclStr( |
192 | virtual void , Clear(), | |
d07d2bc9 | 193 | "Removes all items from the control.", ""); |
861d4832 RD |
194 | |
195 | DocDeclStr( | |
3f5ec806 | 196 | virtual void , Delete(unsigned int n), |
d07d2bc9 RD |
197 | "Deletes the item at the zero-based index 'n' from the control. Note |
198 | that it is an error (signalled by a `wx.PyAssertionError` exception if | |
199 | enabled) to remove an item with the index negative or greater or equal | |
200 | than the number of items in the control.", ""); | |
861d4832 | 201 | |
d14a1e28 RD |
202 | |
203 | ||
6f259188 RD |
204 | |
205 | %extend { | |
206 | DocStr(GetClientData, | |
207 | "Returns the client data associated with the given item, (if any.)", ""); | |
3f5ec806 | 208 | PyObject* GetClientData(unsigned int n) { |
6f259188 RD |
209 | wxPyClientData* data = (wxPyClientData*)self->GetClientObject(n); |
210 | if (data) { | |
211 | Py_INCREF(data->m_obj); | |
212 | return data->m_obj; | |
213 | } else { | |
214 | Py_INCREF(Py_None); | |
215 | return Py_None; | |
216 | } | |
217 | } | |
218 | ||
219 | DocStr(SetClientData, | |
220 | "Associate the given client data with the item at position n.", ""); | |
3f5ec806 | 221 | void SetClientData(unsigned int n, PyObject* clientData) { |
6f259188 RD |
222 | wxPyClientData* data = new wxPyClientData(clientData); |
223 | self->SetClientObject(n, data); | |
224 | } | |
225 | } | |
226 | ||
227 | ||
228 | ||
861d4832 | 229 | DocDeclStr( |
3f5ec806 | 230 | virtual unsigned int , GetCount() const, |
d07d2bc9 | 231 | "Returns the number of items in the control.", ""); |
861d4832 RD |
232 | |
233 | DocDeclStr( | |
234 | bool , IsEmpty() const, | |
d07d2bc9 | 235 | "Returns True if the control is empty or False if it has some items.", ""); |
861d4832 RD |
236 | |
237 | DocDeclStr( | |
3f5ec806 | 238 | virtual wxString , GetString(unsigned int n) const, |
d07d2bc9 | 239 | "Returns the label of the item with the given index.", ""); |
861d4832 RD |
240 | |
241 | DocDeclStr( | |
242 | wxArrayString , GetStrings() const, | |
d07d2bc9 | 243 | "", ""); |
861d4832 RD |
244 | |
245 | DocDeclStr( | |
3f5ec806 | 246 | virtual void , SetString(unsigned int n, const wxString& s), |
d07d2bc9 | 247 | "Sets the label for the given item.", ""); |
861d4832 RD |
248 | |
249 | DocDeclStr( | |
250 | virtual int , FindString(const wxString& s) const, | |
d07d2bc9 RD |
251 | "Finds an item whose label matches the given string. Returns the |
252 | zero-based position of the item, or ``wx.NOT_FOUND`` if the string was not | |
253 | found.", ""); | |
861d4832 | 254 | |
d14a1e28 | 255 | |
861d4832 | 256 | DocDeclStr( |
6f259188 | 257 | virtual void , SetSelection(int n), |
d07d2bc9 | 258 | "Sets the item at index 'n' to be the selected item.", ""); |
861d4832 RD |
259 | |
260 | DocDeclStr( | |
261 | virtual int , GetSelection() const, | |
d07d2bc9 RD |
262 | "Returns the index of the selected item or ``wx.NOT_FOUND`` if no item |
263 | is selected.", ""); | |
861d4832 RD |
264 | |
265 | ||
6f259188 RD |
266 | bool SetStringSelection(const wxString& s); |
267 | ||
861d4832 RD |
268 | DocDeclStr( |
269 | wxString , GetStringSelection() const, | |
d07d2bc9 RD |
270 | "Returns the label of the selected item or an empty string if no item |
271 | is selected.", ""); | |
861d4832 | 272 | |
d14a1e28 | 273 | |
6f259188 RD |
274 | DocDeclStr( |
275 | void , Select(int n), | |
276 | "This is the same as `SetSelection` and exists only because it is | |
277 | slightly more natural for controls which support multiple selection.", ""); | |
278 | ||
d14a1e28 | 279 | |
e8b49596 RD |
280 | %pythoncode { |
281 | def GetItems(self): | |
282 | """Return a list of the strings in the control""" | |
283 | return [self.GetString(i) for i in xrange(self.GetCount())] | |
284 | ||
285 | def SetItems(self, items): | |
286 | """Clear and set the strings in the control from a list""" | |
287 | self.Clear() | |
288 | for i in items: | |
289 | self.Append(i) | |
290 | } | |
76b8fa1d RD |
291 | |
292 | %property(Count, GetCount, doc="See `GetCount`"); | |
293 | %property(Items, GetItems, SetItems, doc="See `GetItems` and `SetItems`"); | |
294 | %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`"); | |
295 | %property(StringSelection, GetStringSelection, SetStringSelection, doc="See `GetStringSelection` and `SetStringSelection`"); | |
296 | %property(Strings, GetStrings, doc="See `GetStrings`"); | |
6f259188 | 297 | |
d14a1e28 RD |
298 | }; |
299 | ||
300 | ||
301 | //--------------------------------------------------------------------------- | |
302 | %newgroup; | |
303 | ||
861d4832 | 304 | DocStr(wxControlWithItems, |
d07d2bc9 RD |
305 | "wx.ControlWithItems combines the ``wx.ItemContainer`` class with the |
306 | wx.Control class, and is used for the base class of various controls | |
307 | that have items.", ""); | |
861d4832 | 308 | |
d14a1e28 RD |
309 | class wxControlWithItems : public wxControl, public wxItemContainer |
310 | { | |
311 | public: | |
312 | }; | |
313 | ||
314 | //--------------------------------------------------------------------------- | |
315 |