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);
69 bool __eq__(const wxGBPosition* other) { return other ? (*self == *other) : False; }
70 bool __ne__(const wxGBPosition* other) { return other ? (*self != *other) : True; }
74 void Set(int row=0, int col=0) {
80 wxPyBeginBlockThreads();
81 PyObject* tup = PyTuple_New(2);
82 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
83 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
84 wxPyEndBlockThreads();
90 def __str__(self): return str(self.Get())
91 def __repr__(self): return 'wx.GBPosition'+str(self.Get())
92 def __len__(self): return len(self.Get())
93 def __getitem__(self, index): return self.Get()[index]
94 def __setitem__(self, index, val):
95 if index == 0: self.SetRow(val)
96 elif index == 1: self.SetCol(val)
97 else: raise IndexError
98 def __nonzero__(self): return self.Get() != (0,0)
99 __safe_for_unpickling__ = True
100 def __reduce__(self): return (wx.GBPosition, self.Get())
104 row = property(GetRow, SetRow)
105 col = property(GetCol, SetCol)
115 wxGBSpan(int rowspan=1, int colspan=1);
117 int GetRowspan() const;
118 int GetColspan() const;
119 void SetRowspan(int rowspan);
120 void SetColspan(int colspan);
123 bool __eq__(const wxGBSpan* other) { return other ? (*self == *other) : False; }
124 bool __ne__(const wxGBSpan* other) { return other ? (*self != *other) : True; }
128 void Set(int rowspan=1, int colspan=1) {
129 self->SetRowspan(rowspan);
130 self->SetColspan(colspan);
134 wxPyBeginBlockThreads();
135 PyObject* tup = PyTuple_New(2);
136 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan()));
137 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan()));
138 wxPyEndBlockThreads();
144 def __str__(self): return str(self.Get())
145 def __repr__(self): return 'wx.GBSpan'+str(self.Get())
146 def __len__(self): return len(self.Get())
147 def __getitem__(self, index): return self.Get()[index]
148 def __setitem__(self, index, val):
149 if index == 0: self.SetRowspan(val)
150 elif index == 1: self.SetColspan(val)
151 else: raise IndexError
152 def __nonzero__(self): return self.Get() != (0,0)
153 __safe_for_unpickling__ = True
154 def __reduce__(self): return (wx.GBSpan, self.Get())
158 rowspan = property(GetRowspan, SetRowspan)
159 colspan = property(GetColspan, SetColspan)
165 const wxGBSpan wxDefaultSpan;
169 //---------------------------------------------------------------------------
172 class wxGBSizerItem : public wxSizerItem
177 %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window,
178 const wxGBPosition& pos,
179 const wxGBSpan& span,
182 wxObject* userData );
184 %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer,
185 const wxGBPosition& pos,
186 const wxGBSpan& span,
189 wxObject* userData );
191 %name(GBSizerItemSpacer) wxGBSizerItem( int width,
193 const wxGBPosition& pos,
194 const wxGBSpan& span,
200 // Get the grid position of the item
201 wxGBPosition GetPos() const;
202 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
204 // Get the row and column spanning of the item
205 wxGBSpan GetSpan() const;
206 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
208 // If the item is already a member of a sizer then first ensure that there
209 // is no other item that would intersect with this one at the new
210 // position, then set the new position. Returns True if the change is
211 // successful and after the next Layout the item will be moved.
212 bool SetPos( const wxGBPosition& pos );
214 // If the item is already a member of a sizer then first ensure that there
215 // is no other item that would intersect with this one with its new
216 // spanning size, then set the new spanning. Returns True if the change
217 // is successful and after the next Layout the item will be resized.
218 bool SetSpan( const wxGBSpan& span );
220 %nokwargs Intersects;
222 // Returns True if this item and the other item instersect
223 bool Intersects(const wxGBSizerItem& other);
225 // Returns True if the given pos/span would intersect with this item.
226 bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
228 // Get the row and column of the endpoint of this item
229 void GetEndPos(int& row, int& col);
232 wxGridBagSizer* GetGBSizer() const;
233 void SetGBSizer(wxGridBagSizer* sizer);
238 //---------------------------------------------------------------------------
241 class wxGridBagSizer : public wxFlexGridSizer
244 wxGridBagSizer(int vgap = 0, int hgap = 0 );
246 // The Add method returns True if the item was successfully placed at the
247 // given cell position, False if something was already there.
249 bool Add( PyObject* item,
250 const wxGBPosition& pos,
251 const wxGBSpan& span = wxDefaultSpan,
254 PyObject* userData = NULL ) {
256 wxPyUserData* data = NULL;
257 wxPyBeginBlockThreads();
258 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
259 if ( userData && (info.window || info.sizer || info.gotSize) )
260 data = new wxPyUserData(userData);
261 wxPyEndBlockThreads();
263 // Now call the real Add method if a valid item type was found
265 return self->Add(info.window, pos, span, flag, border, data);
266 else if ( info.sizer )
267 return self->Add(info.sizer, pos, span, flag, border, data);
268 else if (info.gotSize)
269 return self->Add(info.size.GetWidth(), info.size.GetHeight(),
270 pos, span, flag, border, data);
275 %name(AddItem) bool Add( wxGBSizerItem *item );
278 // Get/Set the size used for cells in the grid with no item.
279 wxSize GetEmptyCellSize() const;
280 void SetEmptyCellSize(const wxSize& sz);
282 // Get the grid position of the specified item
283 %nokwargs GetItemPosition;
284 wxGBPosition GetItemPosition(wxWindow *window);
285 wxGBPosition GetItemPosition(wxSizer *sizer);
286 wxGBPosition GetItemPosition(size_t index);
288 // Set the grid position of the specified item. Returns True on success.
289 // If the move is not allowed (because an item is already there) then
290 // False is returned.
291 %nokwargs SetItemPosition;
292 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
293 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
294 bool SetItemPosition(size_t index, const wxGBPosition& pos);
296 // Get the row/col spanning of the specified item
297 %nokwargs GetItemSpan;
298 wxGBSpan GetItemSpan(wxWindow *window);
299 wxGBSpan GetItemSpan(wxSizer *sizer);
300 wxGBSpan GetItemSpan(size_t index);
302 // Set the row/col spanning of the specified item. Returns True on
303 // success. If the move is not allowed (because an item is already there)
304 // then False is returned.
305 %nokwargs SetItemSpan;
306 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
307 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
308 bool SetItemSpan(size_t index, const wxGBSpan& span);
311 // Find the sizer item for the given window or subsizer, returns NULL if
312 // not found. (non-recursive)
314 wxGBSizerItem* FindItem(wxWindow* window);
315 wxGBSizerItem* FindItem(wxSizer* sizer);
318 // Return the sizer item for the given grid cell, or NULL if there is no
319 // item at that position. (non-recursive)
320 wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos);
323 // Return the sizer item located at the point given in pt, or NULL if
324 // there is no item at that point. The (x,y) coordinates in pt correspond
325 // to the client coordinates of the window using the sizer for
326 // layout. (non-recursive)
327 wxGBSizerItem* FindItemAtPoint(const wxPoint& pt);
330 // Return the sizer item that has a matching user data (it only compares
331 // pointer values) or NULL if not found. (non-recursive)
332 wxGBSizerItem* FindItemWithData(const wxObject* userData);
335 // These are what make the sizer do size calculations and layout
336 virtual void RecalcSizes();
337 virtual wxSize CalcMin();
340 // Look at all items and see if any intersect (or would overlap) the given
341 // item. Returns True if so, False if there would be no overlap. If an
342 // excludeItem is given then it will not be checked for intersection, for
343 // example it may be the item we are checking the position of.
344 %nokwargs CheckForIntersection;
345 bool CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL);
346 bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL);
351 //---------------------------------------------------------------------------