]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: _gbsizer.i | |
3 | // Purpose: SWIG interface stuff for wxGBGridBagSizer and etc. | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 05-Nov-2003 | |
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 | ||
18 | %{ | |
19 | %} | |
20 | ||
21 | //--------------------------------------------------------------------------- | |
22 | ||
23 | %typemap(in) wxGBPosition& (wxGBPosition temp) { | |
24 | $1 = &temp; | |
25 | if ( ! wxGBPosition_helper($input, &$1)) SWIG_fail; | |
26 | } | |
27 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBPosition& { | |
28 | $1 = wxPySimple_typecheck($input, wxT("wxGBPosition"), 2); | |
29 | } | |
30 | ||
31 | %typemap(in) wxGBSpan& (wxGBSpan temp) { | |
32 | $1 = &temp; | |
33 | if ( ! wxGBSpan_helper($input, &$1)) SWIG_fail; | |
34 | } | |
35 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBSpan& { | |
36 | $1 = wxPySimple_typecheck($input, wxT("wxGBSpan"), 2); | |
37 | } | |
38 | ||
39 | ||
40 | %{ | |
41 | bool wxGBPosition_helper(PyObject* source, wxGBPosition** obj) | |
42 | { | |
43 | return wxPyTwoIntItem_helper(source, obj, wxT("wxGBPosition")); | |
44 | } | |
45 | ||
46 | bool wxGBSpan_helper(PyObject* source, wxGBSpan** obj) | |
47 | { | |
48 | return wxPyTwoIntItem_helper(source, obj, wxT("wxGBSpan")); | |
49 | } | |
50 | ||
51 | %} | |
52 | ||
53 | ||
54 | //--------------------------------------------------------------------------- | |
55 | %newgroup; | |
56 | ||
57 | ||
58 | class wxGBPosition | |
59 | { | |
60 | public: | |
61 | wxGBPosition(int row=0, int col=0); | |
62 | ||
63 | int GetRow() const; | |
64 | int GetCol() const; | |
65 | void SetRow(int row); | |
66 | void SetCol(int col); | |
67 | ||
68 | bool operator==(const wxGBPosition& p) const; | |
69 | bool operator!=(const wxGBPosition& p) const; | |
70 | ||
71 | %extend { | |
72 | void Set(int row=0, int col=0) { | |
73 | self->SetRow(row); | |
74 | self->SetCol(col); | |
75 | } | |
76 | ||
77 | PyObject* Get() { | |
78 | wxPyBeginBlockThreads(); | |
79 | PyObject* tup = PyTuple_New(2); | |
80 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow())); | |
81 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol())); | |
82 | wxPyEndBlockThreads(); | |
83 | return tup; | |
84 | } | |
85 | } | |
86 | %pythoncode { | |
87 | asTuple = Get | |
88 | def __str__(self): return str(self.Get()) | |
89 | def __repr__(self): return 'wx.GBPosition'+str(self.Get()) | |
90 | def __len__(self): return len(self.Get()) | |
91 | def __getitem__(self, index): return self.Get()[index] | |
92 | def __setitem__(self, index, val): | |
93 | if index == 0: self.SetRow(val) | |
94 | elif index == 1: self.SetCol(val) | |
95 | else: raise IndexError | |
96 | def __nonzero__(self): return self.Get() != (0,0) | |
97 | def __getinitargs__(self): return () | |
98 | def __getstate__(self): return self.Get() | |
99 | def __setstate__(self, state): self.Set(*state) | |
100 | } | |
101 | ||
102 | %pythoncode { | |
103 | row = property(GetRow, SetRow) | |
104 | col = property(GetCol, SetCol) | |
105 | } | |
106 | }; | |
107 | ||
108 | ||
109 | ||
110 | ||
111 | class wxGBSpan | |
112 | { | |
113 | public: | |
114 | wxGBSpan(int rowspan=1, int colspan=1); | |
115 | ||
116 | int GetRowspan() const; | |
117 | int GetColspan() const; | |
118 | void SetRowspan(int rowspan); | |
119 | void SetColspan(int colspan); | |
120 | ||
121 | bool operator==(const wxGBSpan& o) const; | |
122 | bool operator!=(const wxGBSpan& o) const; | |
123 | ||
124 | %extend { | |
125 | void Set(int rowspan=1, int colspan=1) { | |
126 | self->SetRowspan(rowspan); | |
127 | self->SetColspan(colspan); | |
128 | } | |
129 | ||
130 | PyObject* Get() { | |
131 | wxPyBeginBlockThreads(); | |
132 | PyObject* tup = PyTuple_New(2); | |
133 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan())); | |
134 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan())); | |
135 | wxPyEndBlockThreads(); | |
136 | return tup; | |
137 | } | |
138 | } | |
139 | %pythoncode { | |
140 | asTuple = Get | |
141 | def __str__(self): return str(self.Get()) | |
142 | def __repr__(self): return 'wx.GBSpan'+str(self.Get()) | |
143 | def __len__(self): return len(self.Get()) | |
144 | def __getitem__(self, index): return self.Get()[index] | |
145 | def __setitem__(self, index, val): | |
146 | if index == 0: self.SetRowspan(val) | |
147 | elif index == 1: self.SetColspan(val) | |
148 | else: raise IndexError | |
149 | def __nonzero__(self): return self.Get() != (0,0) | |
150 | def __getinitargs__(self): return () | |
151 | def __getstate__(self): return self.Get() | |
152 | def __setstate__(self, state): self.Set(*state) | |
153 | } | |
154 | ||
155 | %pythoncode { | |
156 | rowspan = property(GetRowspan, SetRowspan) | |
157 | colspan = property(GetColspan, SetColspan) | |
158 | } | |
159 | }; | |
160 | ||
161 | ||
162 | %immutable; | |
163 | const wxGBSpan wxDefaultSpan; | |
164 | %mutable; | |
165 | ||
166 | ||
167 | //--------------------------------------------------------------------------- | |
168 | ||
169 | ||
170 | class wxGBSizerItem : public wxSizerItem | |
171 | { | |
172 | public: | |
173 | wxGBSizerItem(); | |
174 | ||
175 | %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window, | |
176 | const wxGBPosition& pos, | |
177 | const wxGBSpan& span, | |
178 | int flag, | |
179 | int border, | |
180 | wxObject* userData ); | |
181 | ||
182 | %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer, | |
183 | const wxGBPosition& pos, | |
184 | const wxGBSpan& span, | |
185 | int flag, | |
186 | int border, | |
187 | wxObject* userData ); | |
188 | ||
189 | %name(GBSizerItemSpacer) wxGBSizerItem( int width, | |
190 | int height, | |
191 | const wxGBPosition& pos, | |
192 | const wxGBSpan& span, | |
193 | int flag, | |
194 | int border, | |
195 | wxObject* userData); | |
196 | ||
197 | ||
198 | // Get the grid position of the item | |
199 | wxGBPosition GetPos() const; | |
200 | %pythoncode { def GetPosTuple(self): return self.GetPos().Get() } | |
201 | ||
202 | // Get the row and column spanning of the item | |
203 | wxGBSpan GetSpan() const; | |
204 | %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() } | |
205 | ||
206 | // If the item is already a member of a sizer then first ensure that there | |
207 | // is no other item that would intersect with this one at the new | |
208 | // position, then set the new position. Returns True if the change is | |
209 | // successful and after the next Layout the item will be moved. | |
210 | bool SetPos( const wxGBPosition& pos ); | |
211 | ||
212 | // If the item is already a member of a sizer then first ensure that there | |
213 | // is no other item that would intersect with this one with its new | |
214 | // spanning size, then set the new spanning. Returns True if the change | |
215 | // is successful and after the next Layout the item will be resized. | |
216 | bool SetSpan( const wxGBSpan& span ); | |
217 | ||
218 | %nokwargs Intersects; | |
219 | ||
220 | // Returns True if this item and the other item instersect | |
221 | bool Intersects(const wxGBSizerItem& other); | |
222 | ||
223 | // Returns True if the given pos/span would intersect with this item. | |
224 | bool Intersects(const wxGBPosition& pos, const wxGBSpan& span); | |
225 | ||
226 | // Get the row and column of the endpoint of this item | |
227 | void GetEndPos(int& row, int& col); | |
228 | ||
229 | ||
230 | wxGridBagSizer* GetGBSizer() const; | |
231 | void SetGBSizer(wxGridBagSizer* sizer); | |
232 | ||
233 | }; | |
234 | ||
235 | ||
236 | //--------------------------------------------------------------------------- | |
237 | ||
238 | ||
239 | class wxGridBagSizer : public wxFlexGridSizer | |
240 | { | |
241 | public: | |
242 | wxGridBagSizer(int vgap = 0, int hgap = 0 ); | |
243 | ||
244 | // The Add method returns True if the item was successfully placed at the | |
245 | // given cell position, False if something was already there. | |
246 | %extend { | |
247 | bool Add( PyObject* item, | |
248 | const wxGBPosition& pos, | |
249 | const wxGBSpan& span = wxDefaultSpan, | |
250 | int flag = 0, | |
251 | int border = 0, | |
252 | PyObject* userData = NULL ) { | |
253 | ||
254 | wxPyUserData* data = NULL; | |
255 | wxPyBeginBlockThreads(); | |
256 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False); | |
257 | if ( userData && (info.window || info.sizer || info.gotSize) ) | |
258 | data = new wxPyUserData(userData); | |
259 | wxPyEndBlockThreads(); | |
260 | ||
261 | // Now call the real Add method if a valid item type was found | |
262 | if ( info.window ) | |
263 | return self->Add(info.window, pos, span, flag, border, data); | |
264 | else if ( info.sizer ) | |
265 | return self->Add(info.sizer, pos, span, flag, border, data); | |
266 | else if (info.gotSize) | |
267 | return self->Add(info.size.GetWidth(), info.size.GetHeight(), | |
268 | pos, span, flag, border, data); | |
269 | return False; | |
270 | } | |
271 | } | |
272 | ||
273 | %name(AddItem) bool Add( wxGBSizerItem *item ); | |
274 | ||
275 | ||
276 | // Get/Set the size used for cells in the grid with no item. | |
277 | wxSize GetEmptyCellSize() const; | |
278 | void SetEmptyCellSize(const wxSize& sz); | |
279 | ||
280 | // Get the grid position of the specified item | |
281 | %nokwargs GetItemPosition; | |
282 | wxGBPosition GetItemPosition(wxWindow *window); | |
283 | wxGBPosition GetItemPosition(wxSizer *sizer); | |
284 | wxGBPosition GetItemPosition(size_t index); | |
285 | ||
286 | // Set the grid position of the specified item. Returns True on success. | |
287 | // If the move is not allowed (because an item is already there) then | |
288 | // False is returned. | |
289 | %nokwargs SetItemPosition; | |
290 | bool SetItemPosition(wxWindow *window, const wxGBPosition& pos); | |
291 | bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos); | |
292 | bool SetItemPosition(size_t index, const wxGBPosition& pos); | |
293 | ||
294 | // Get the row/col spanning of the specified item | |
295 | %nokwargs GetItemSpan; | |
296 | wxGBSpan GetItemSpan(wxWindow *window); | |
297 | wxGBSpan GetItemSpan(wxSizer *sizer); | |
298 | wxGBSpan GetItemSpan(size_t index); | |
299 | ||
300 | // Set the row/col spanning of the specified item. Returns True on | |
301 | // success. If the move is not allowed (because an item is already there) | |
302 | // then False is returned. | |
303 | %nokwargs SetItemSpan; | |
304 | bool SetItemSpan(wxWindow *window, const wxGBSpan& span); | |
305 | bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span); | |
306 | bool SetItemSpan(size_t index, const wxGBSpan& span); | |
307 | ||
308 | ||
309 | // Find the sizer item for the given window or subsizer, returns NULL if | |
310 | // not found. (non-recursive) | |
311 | %nokwargs FindItem; | |
312 | wxGBSizerItem* FindItem(wxWindow* window); | |
313 | wxGBSizerItem* FindItem(wxSizer* sizer); | |
314 | ||
315 | ||
316 | // Return the sizer item for the given grid cell, or NULL if there is no | |
317 | // item at that position. (non-recursive) | |
318 | wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos); | |
319 | ||
320 | ||
321 | // Return the sizer item located at the point given in pt, or NULL if | |
322 | // there is no item at that point. The (x,y) coordinates in pt correspond | |
323 | // to the client coordinates of the window using the sizer for | |
324 | // layout. (non-recursive) | |
325 | wxGBSizerItem* FindItemAtPoint(const wxPoint& pt); | |
326 | ||
327 | ||
328 | // Return the sizer item that has a matching user data (it only compares | |
329 | // pointer values) or NULL if not found. (non-recursive) | |
330 | wxGBSizerItem* FindItemWithData(const wxObject* userData); | |
331 | ||
332 | ||
333 | // These are what make the sizer do size calculations and layout | |
334 | virtual void RecalcSizes(); | |
335 | virtual wxSize CalcMin(); | |
336 | ||
337 | ||
338 | // Look at all items and see if any intersect (or would overlap) the given | |
339 | // item. Returns True if so, False if there would be no overlap. If an | |
340 | // excludeItem is given then it will not be checked for intersection, for | |
341 | // example it may be the item we are checking the position of. | |
342 | %nokwargs CheckForIntersection; | |
343 | bool CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL); | |
344 | bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL); | |
345 | ||
346 | }; | |
347 | ||
348 | ||
349 | //--------------------------------------------------------------------------- |