]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gbsizer.i
Recent changes in SWIG make this patch no longer necessary
[wxWidgets.git] / wxPython / src / _gbsizer.i
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 %noautorepr wxGBPosition;
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 PyObject* asTuple() {
73 wxPyBeginBlockThreads();
74 PyObject* tup = PyTuple_New(2);
75 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
76 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
77 wxPyEndBlockThreads();
78 return tup;
79 }
80 }
81 %pythoncode {
82 def __str__(self): return str(self.asTuple())
83 def __repr__(self): return 'wxGBPosition'+str(self.asTuple())
84 def __len__(self): return len(self.asTuple())
85 def __getitem__(self, index): return self.asTuple()[index]
86 def __setitem__(self, index, val):
87 if index == 0: self.SetRow(val)
88 elif index == 1: self.SetCol(val)
89 else: raise IndexError
90 def __nonzero__(self): return self.asTuple() != (0,0)
91 def __getinitargs__(self): return ()
92 def __getstate__(self): return self.asTuple()
93 def __setstate__(self, state): self.Set(*state)
94 }
95
96 %pythoncode {
97 row = property(GetRow, SetRow)
98 col = property(GetCol, SetCol)
99 }
100 };
101
102
103
104 %noautorepr wxGBSpan;
105
106 class wxGBSpan
107 {
108 public:
109 wxGBSpan(int rowspan=1, int colspan=1);
110
111 int GetRowspan() const;
112 int GetColspan() const;
113 void SetRowspan(int rowspan);
114 void SetColspan(int colspan);
115
116 bool operator==(const wxGBSpan& o) const;
117 bool operator!=(const wxGBSpan& o) const;
118
119 %extend {
120 PyObject* asTuple() {
121 wxPyBeginBlockThreads();
122 PyObject* tup = PyTuple_New(2);
123 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan()));
124 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan()));
125 wxPyEndBlockThreads();
126 return tup;
127 }
128 }
129 %pythoncode {
130 def __str__(self): return str(self.asTuple())
131 def __repr__(self): return 'wxGBSpan'+str(self.asTuple())
132 def __len__(self): return len(self.asTuple())
133 def __getitem__(self, index): return self.asTuple()[index]
134 def __setitem__(self, index, val):
135 if index == 0: self.SetRowspan(val)
136 elif index == 1: self.SetColspan(val)
137 else: raise IndexError
138 def __nonzero__(self): return self.asTuple() != (0,0)
139 def __getinitargs__(self): return ()
140 def __getstate__(self): return self.asTuple()
141 def __setstate__(self, state): self.Set(*state)
142 }
143
144 %pythoncode {
145 rowspan = property(GetRowspan, SetRowspan)
146 colspan = property(GetColspan, SetColspan)
147 }
148 };
149
150
151 %immutable;
152 const wxGBSpan wxDefaultSpan;
153 %mutable;
154
155
156 //---------------------------------------------------------------------------
157
158
159 class wxGBSizerItem : public wxSizerItem
160 {
161 public:
162 wxGBSizerItem();
163
164 %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window,
165 const wxGBPosition& pos,
166 const wxGBSpan& span,
167 int flag,
168 int border,
169 wxObject* userData );
170
171 %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer,
172 const wxGBPosition& pos,
173 const wxGBSpan& span,
174 int flag,
175 int border,
176 wxObject* userData );
177
178 %name(GBSizerItemSpacer) wxGBSizerItem( int width,
179 int height,
180 const wxGBPosition& pos,
181 const wxGBSpan& span,
182 int flag,
183 int border,
184 wxObject* userData);
185
186
187 // Get the grid position of the item
188 wxGBPosition GetPos() const;
189 %pythoncode { def GetPosTuple(self): return self.GetPos().asTuple() }
190
191 // Get the row and column spanning of the item
192 wxGBSpan GetSpan() const;
193 %pythoncode { def GetSpanTuple(self): return self.GetSpan().asTuple() }
194
195 // If the item is already a member of a sizer then first ensure that there
196 // is no other item that would intersect with this one at the new
197 // position, then set the new position. Returns true if the change is
198 // successful and after the next Layout the item will be moved.
199 bool SetPos( const wxGBPosition& pos );
200
201 // If the item is already a member of a sizer then first ensure that there
202 // is no other item that would intersect with this one with its new
203 // spanning size, then set the new spanning. Returns true if the change
204 // is successful and after the next Layout the item will be resized.
205 bool SetSpan( const wxGBSpan& span );
206
207 %nokwargs Intersects;
208
209 // Returns true if this item and the other item instersect
210 bool Intersects(const wxGBSizerItem& other);
211
212 // Returns true if the given pos/span would intersect with this item.
213 bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
214
215 // Get the row and column of the endpoint of this item
216 void GetEndPos(int& row, int& col);
217
218
219 wxGridBagSizer* GetGBSizer() const;
220 void SetGBSizer(wxGridBagSizer* sizer);
221
222 };
223
224
225 //---------------------------------------------------------------------------
226
227
228 class wxGridBagSizer : public wxFlexGridSizer
229 {
230 public:
231 wxGridBagSizer(int vgap = 0, int hgap = 0 );
232
233 // The Add method returns true if the item was successfully placed at the
234 // given cell position, false if something was already there.
235 %extend {
236 bool Add( PyObject* item,
237 const wxGBPosition& pos,
238 const wxGBSpan& span = wxDefaultSpan,
239 int flag = 0,
240 int border = 0,
241 PyObject* userData = NULL ) {
242
243 wxPyUserData* data = NULL;
244 wxPyBeginBlockThreads();
245 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
246 if ( userData && (info.window || info.sizer || info.gotSize) )
247 data = new wxPyUserData(userData);
248 wxPyEndBlockThreads();
249
250 // Now call the real Add method if a valid item type was found
251 if ( info.window )
252 return self->Add(info.window, pos, span, flag, border, data);
253 else if ( info.sizer )
254 return self->Add(info.sizer, pos, span, flag, border, data);
255 else if (info.gotSize)
256 return self->Add(info.size.GetWidth(), info.size.GetHeight(),
257 pos, span, flag, border, data);
258 return false;
259 }
260 }
261
262 %name(AddItem) bool Add( wxGBSizerItem *item );
263
264
265 // Get/Set the size used for cells in the grid with no item.
266 wxSize GetEmptyCellSize() const;
267 void SetEmptyCellSize(const wxSize& sz);
268
269 // Get the grid position of the specified item
270 %nokwargs GetItemPosition;
271 wxGBPosition GetItemPosition(wxWindow *window);
272 wxGBPosition GetItemPosition(wxSizer *sizer);
273 wxGBPosition GetItemPosition(size_t index);
274
275 // Set the grid position of the specified item. Returns true on success.
276 // If the move is not allowed (because an item is already there) then
277 // false is returned.
278 %nokwargs SetItemPosition;
279 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
280 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
281 bool SetItemPosition(size_t index, const wxGBPosition& pos);
282
283 // Get the row/col spanning of the specified item
284 %nokwargs GetItemSpan;
285 wxGBSpan GetItemSpan(wxWindow *window);
286 wxGBSpan GetItemSpan(wxSizer *sizer);
287 wxGBSpan GetItemSpan(size_t index);
288
289 // Set the row/col spanning of the specified item. Returns true on
290 // success. If the move is not allowed (because an item is already there)
291 // then false is returned.
292 %nokwargs SetItemSpan;
293 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
294 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
295 bool SetItemSpan(size_t index, const wxGBSpan& span);
296
297
298 // Find the sizer item for the given window or subsizer, returns NULL if
299 // not found. (non-recursive)
300 %nokwargs FindItem;
301 wxGBSizerItem* FindItem(wxWindow* window);
302 wxGBSizerItem* FindItem(wxSizer* sizer);
303
304
305 // Return the sizer item for the given grid cell, or NULL if there is no
306 // item at that position. (non-recursive)
307 wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos);
308
309
310 // Return the sizer item that has a matching user data (it only compares
311 // pointer values) or NULL if not found. (non-recursive)
312 wxGBSizerItem* FindItemWithData(const wxObject* userData);
313
314
315 // These are what make the sizer do size calculations and layout
316 virtual void RecalcSizes();
317 virtual wxSize CalcMin();
318
319
320 // Look at all items and see if any intersect (or would overlap) the given
321 // item. Returns true if so, false if there would be no overlap. If an
322 // excludeItem is given then it will not be checked for intersection, for
323 // example it may be the item we are checking the position of.
324 %nokwargs CheckForIntersection;
325 bool CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL);
326 bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL);
327
328 };
329
330
331 //---------------------------------------------------------------------------