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 __safe_for_unpickling__ = True
98 def __reduce__(self): return (wx.GBPosition, self.Get())
102 row = property(GetRow, SetRow)
103 col = property(GetCol, SetCol)
113 wxGBSpan(int rowspan=1, int colspan=1);
115 int GetRowspan() const;
116 int GetColspan() const;
117 void SetRowspan(int rowspan);
118 void SetColspan(int colspan);
120 bool operator==(const wxGBSpan& o) const;
121 bool operator!=(const wxGBSpan& o) const;
124 void Set(int rowspan=1, int colspan=1) {
125 self->SetRowspan(rowspan);
126 self->SetColspan(colspan);
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();
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())
154 rowspan = property(GetRowspan, SetRowspan)
155 colspan = property(GetColspan, SetColspan)
161 const wxGBSpan wxDefaultSpan;
165 //---------------------------------------------------------------------------
168 class wxGBSizerItem : public wxSizerItem
173 %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window,
174 const wxGBPosition& pos,
175 const wxGBSpan& span,
178 wxObject* userData );
180 %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer,
181 const wxGBPosition& pos,
182 const wxGBSpan& span,
185 wxObject* userData );
187 %name(GBSizerItemSpacer) wxGBSizerItem( int width,
189 const wxGBPosition& pos,
190 const wxGBSpan& span,
196 // Get the grid position of the item
197 wxGBPosition GetPos() const;
198 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
200 // Get the row and column spanning of the item
201 wxGBSpan GetSpan() const;
202 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
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 );
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 );
216 %nokwargs Intersects;
218 // Returns True if this item and the other item instersect
219 bool Intersects(const wxGBSizerItem& other);
221 // Returns True if the given pos/span would intersect with this item.
222 bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
224 // Get the row and column of the endpoint of this item
225 void GetEndPos(int& row, int& col);
228 wxGridBagSizer* GetGBSizer() const;
229 void SetGBSizer(wxGridBagSizer* sizer);
234 //---------------------------------------------------------------------------
237 class wxGridBagSizer : public wxFlexGridSizer
240 wxGridBagSizer(int vgap = 0, int hgap = 0 );
242 // The Add method returns True if the item was successfully placed at the
243 // given cell position, False if something was already there.
245 bool Add( PyObject* item,
246 const wxGBPosition& pos,
247 const wxGBSpan& span = wxDefaultSpan,
250 PyObject* userData = NULL ) {
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();
259 // Now call the real Add method if a valid item type was found
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);
271 %name(AddItem) bool Add( wxGBSizerItem *item );
274 // Get/Set the size used for cells in the grid with no item.
275 wxSize GetEmptyCellSize() const;
276 void SetEmptyCellSize(const wxSize& sz);
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);
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);
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);
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);
307 // Find the sizer item for the given window or subsizer, returns NULL if
308 // not found. (non-recursive)
310 wxGBSizerItem* FindItem(wxWindow* window);
311 wxGBSizerItem* FindItem(wxSizer* sizer);
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);
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);
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);
331 // These are what make the sizer do size calculations and layout
332 virtual void RecalcSizes();
333 virtual wxSize CalcMin();
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);
347 //---------------------------------------------------------------------------