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 //---------------------------------------------------------------------------
61 wxGBPosition(int row=0, int col=0);
68 bool operator==(const wxGBPosition& p) const;
69 bool operator!=(const wxGBPosition& p) const;
72 void Set(int row=0, int col=0) {
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();
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)
103 row = property(GetRow, SetRow)
104 col = property(GetCol, SetCol)
114 wxGBSpan(int rowspan=1, int colspan=1);
116 int GetRowspan() const;
117 int GetColspan() const;
118 void SetRowspan(int rowspan);
119 void SetColspan(int colspan);
121 bool operator==(const wxGBSpan& o) const;
122 bool operator!=(const wxGBSpan& o) const;
125 void Set(int rowspan=1, int colspan=1) {
126 self->SetRowspan(rowspan);
127 self->SetColspan(colspan);
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();
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)
156 rowspan = property(GetRowspan, SetRowspan)
157 colspan = property(GetColspan, SetColspan)
163 const wxGBSpan wxDefaultSpan;
167 //---------------------------------------------------------------------------
170 class wxGBSizerItem : public wxSizerItem
175 %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window,
176 const wxGBPosition& pos,
177 const wxGBSpan& span,
180 wxObject* userData );
182 %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer,
183 const wxGBPosition& pos,
184 const wxGBSpan& span,
187 wxObject* userData );
189 %name(GBSizerItemSpacer) wxGBSizerItem( int width,
191 const wxGBPosition& pos,
192 const wxGBSpan& span,
198 // Get the grid position of the item
199 wxGBPosition GetPos() const;
200 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
202 // Get the row and column spanning of the item
203 wxGBSpan GetSpan() const;
204 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
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 );
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 );
218 %nokwargs Intersects;
220 // Returns True if this item and the other item instersect
221 bool Intersects(const wxGBSizerItem& other);
223 // Returns True if the given pos/span would intersect with this item.
224 bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
226 // Get the row and column of the endpoint of this item
227 void GetEndPos(int& row, int& col);
230 wxGridBagSizer* GetGBSizer() const;
231 void SetGBSizer(wxGridBagSizer* sizer);
236 //---------------------------------------------------------------------------
239 class wxGridBagSizer : public wxFlexGridSizer
242 wxGridBagSizer(int vgap = 0, int hgap = 0 );
244 // The Add method returns True if the item was successfully placed at the
245 // given cell position, False if something was already there.
247 bool Add( PyObject* item,
248 const wxGBPosition& pos,
249 const wxGBSpan& span = wxDefaultSpan,
252 PyObject* userData = NULL ) {
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();
261 // Now call the real Add method if a valid item type was found
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);
273 %name(AddItem) bool Add( wxGBSizerItem *item );
276 // Get/Set the size used for cells in the grid with no item.
277 wxSize GetEmptyCellSize() const;
278 void SetEmptyCellSize(const wxSize& sz);
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);
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);
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);
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);
309 // Find the sizer item for the given window or subsizer, returns NULL if
310 // not found. (non-recursive)
312 wxGBSizerItem* FindItem(wxWindow* window);
313 wxGBSizerItem* FindItem(wxSizer* sizer);
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);
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);
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);
333 // These are what make the sizer do size calculations and layout
334 virtual void RecalcSizes();
335 virtual wxSize CalcMin();
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);
349 //---------------------------------------------------------------------------