1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface stuff for wxGBGridBagSizer and etc.
7 // Created: 05-Nov-2003
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
23 %typemap(in) wxGBPosition& (wxGBPosition temp) {
25 if ( ! wxGBPosition_helper($input, &$1)) SWIG_fail;
27 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBPosition& {
28 $1 = wxPySimple_typecheck($input, wxT("wxGBPosition"), 2);
31 %typemap(in) wxGBSpan& (wxGBSpan temp) {
33 if ( ! wxGBSpan_helper($input, &$1)) SWIG_fail;
35 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBSpan& {
36 $1 = wxPySimple_typecheck($input, wxT("wxGBSpan"), 2);
41 bool wxGBPosition_helper(PyObject* source, wxGBPosition** obj)
43 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBPosition"));
46 bool wxGBSpan_helper(PyObject* source, wxGBSpan** obj)
48 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBSpan"));
54 //---------------------------------------------------------------------------
56 %noautorepr wxGBPosition;
61 wxGBPosition(int row=0, int col=0);
68 bool operator==(const wxGBPosition& p) const;
69 bool operator!=(const wxGBPosition& p) const;
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();
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)
97 row = property(GetRow, SetRow)
98 col = property(GetCol, SetCol)
104 %noautorepr wxGBSpan;
109 wxGBSpan(int rowspan=1, int colspan=1);
111 int GetRowspan() const;
112 int GetColspan() const;
113 void SetRowspan(int rowspan);
114 void SetColspan(int colspan);
116 bool operator==(const wxGBSpan& o) const;
117 bool operator!=(const wxGBSpan& o) const;
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();
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)
145 rowspan = property(GetRowspan, SetRowspan)
146 colspan = property(GetColspan, SetColspan)
152 const wxGBSpan wxDefaultSpan;
156 //---------------------------------------------------------------------------
159 class wxGBSizerItem : public wxSizerItem
164 %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window,
165 const wxGBPosition& pos,
166 const wxGBSpan& span,
169 wxObject* userData );
171 %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer,
172 const wxGBPosition& pos,
173 const wxGBSpan& span,
176 wxObject* userData );
178 %name(GBSizerItemSpacer) wxGBSizerItem( int width,
180 const wxGBPosition& pos,
181 const wxGBSpan& span,
187 // Get the grid position of the item
188 wxGBPosition GetPos() const;
189 %pythoncode { def GetPosTuple(self): return self.GetPos().asTuple() }
191 // Get the row and column spanning of the item
192 wxGBSpan GetSpan() const;
193 %pythoncode { def GetSpanTuple(self): return self.GetSpan().asTuple() }
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 );
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 );
207 %nokwargs Intersects;
209 // Returns true if this item and the other item instersect
210 bool Intersects(const wxGBSizerItem& other);
212 // Returns true if the given pos/span would intersect with this item.
213 bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
215 // Get the row and column of the endpoint of this item
216 void GetEndPos(int& row, int& col);
219 wxGridBagSizer* GetGBSizer() const;
220 void SetGBSizer(wxGridBagSizer* sizer);
225 //---------------------------------------------------------------------------
228 class wxGridBagSizer : public wxFlexGridSizer
231 wxGridBagSizer(int vgap = 0, int hgap = 0 );
233 // The Add method returns true if the item was successfully placed at the
234 // given cell position, false if something was already there.
236 bool Add( PyObject* item,
237 const wxGBPosition& pos,
238 const wxGBSpan& span = wxDefaultSpan,
241 PyObject* userData = NULL ) {
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();
250 // Now call the real Add method if a valid item type was found
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);
262 %name(AddItem) bool Add( wxGBSizerItem *item );
265 // Get/Set the size used for cells in the grid with no item.
266 wxSize GetEmptyCellSize() const;
267 void SetEmptyCellSize(const wxSize& sz);
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);
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);
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);
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);
298 // Find the sizer item for the given window or subsizer, returns NULL if
299 // not found. (non-recursive)
301 wxGBSizerItem* FindItem(wxWindow* window);
302 wxGBSizerItem* FindItem(wxSizer* sizer);
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);
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);
315 // These are what make the sizer do size calculations and layout
316 virtual void RecalcSizes();
317 virtual wxSize CalcMin();
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);
331 //---------------------------------------------------------------------------