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