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 if (source == Py_None) {
44 **obj = wxGBPosition(-1,-1);
47 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBPosition"));
50 bool wxGBSpan_helper(PyObject* source, wxGBSpan** obj)
52 if (source == Py_None) {
53 **obj = wxGBSpan(-1,-1);
56 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBSpan"));
62 //---------------------------------------------------------------------------
69 wxGBPosition(int row=0, int col=0);
77 // bool __eq__(const wxGBPosition* other) { return other ? (*self == *other) : False; }
78 // bool __ne__(const wxGBPosition* other) { return other ? (*self != *other) : True; }
81 bool operator==(const wxGBPosition& other);
82 bool operator!=(const wxGBPosition& other);
85 void Set(int row=0, int col=0) {
91 bool blocked = wxPyBeginBlockThreads();
92 PyObject* tup = PyTuple_New(2);
93 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
94 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
95 wxPyEndBlockThreads(blocked);
101 def __str__(self): return str(self.Get())
102 def __repr__(self): return 'wx.GBPosition'+str(self.Get())
103 def __len__(self): return len(self.Get())
104 def __getitem__(self, index): return self.Get()[index]
105 def __setitem__(self, index, val):
106 if index == 0: self.SetRow(val)
107 elif index == 1: self.SetCol(val)
108 else: raise IndexError
109 def __nonzero__(self): return self.Get() != (0,0)
110 __safe_for_unpickling__ = True
111 def __reduce__(self): return (wx.GBPosition, self.Get())
115 row = property(GetRow, SetRow)
116 col = property(GetCol, SetCol)
126 wxGBSpan(int rowspan=1, int colspan=1);
128 int GetRowspan() const;
129 int GetColspan() const;
130 void SetRowspan(int rowspan);
131 void SetColspan(int colspan);
134 // bool __eq__(const wxGBSpan* other) { return other ? (*self == *other) : False; }
135 // bool __ne__(const wxGBSpan* other) { return other ? (*self != *other) : True; }
137 bool operator==(const wxGBSpan& other);
138 bool operator!=(const wxGBSpan& other);
142 void Set(int rowspan=1, int colspan=1) {
143 self->SetRowspan(rowspan);
144 self->SetColspan(colspan);
148 bool blocked = wxPyBeginBlockThreads();
149 PyObject* tup = PyTuple_New(2);
150 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan()));
151 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan()));
152 wxPyEndBlockThreads(blocked);
158 def __str__(self): return str(self.Get())
159 def __repr__(self): return 'wx.GBSpan'+str(self.Get())
160 def __len__(self): return len(self.Get())
161 def __getitem__(self, index): return self.Get()[index]
162 def __setitem__(self, index, val):
163 if index == 0: self.SetRowspan(val)
164 elif index == 1: self.SetColspan(val)
165 else: raise IndexError
166 def __nonzero__(self): return self.Get() != (0,0)
167 __safe_for_unpickling__ = True
168 def __reduce__(self): return (wx.GBSpan, self.Get())
172 rowspan = property(GetRowspan, SetRowspan)
173 colspan = property(GetColspan, SetColspan)
179 const wxGBSpan wxDefaultSpan;
183 //---------------------------------------------------------------------------
186 class wxGBSizerItem : public wxSizerItem
191 %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window,
192 const wxGBPosition& pos,
193 const wxGBSpan& span,
196 wxObject* userData );
198 %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer,
199 const wxGBPosition& pos,
200 const wxGBSpan& span,
203 wxObject* userData );
205 %name(GBSizerItemSpacer) wxGBSizerItem( int width,
207 const wxGBPosition& pos,
208 const wxGBSpan& span,
214 // Get the grid position of the item
215 wxGBPosition GetPos() const;
216 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
218 // Get the row and column spanning of the item
219 wxGBSpan GetSpan() const;
220 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
222 // If the item is already a member of a sizer then first ensure that there
223 // is no other item that would intersect with this one at the new
224 // position, then set the new position. Returns True if the change is
225 // successful and after the next Layout the item will be moved.
226 bool SetPos( const wxGBPosition& pos );
228 // If the item is already a member of a sizer then first ensure that there
229 // is no other item that would intersect with this one with its new
230 // spanning size, then set the new spanning. Returns True if the change
231 // is successful and after the next Layout the item will be resized.
232 bool SetSpan( const wxGBSpan& span );
234 %nokwargs Intersects;
236 // Returns True if this item and the other item instersect
237 bool Intersects(const wxGBSizerItem& other);
239 // Returns True if the given pos/span would intersect with this item.
240 bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
242 // Get the row and column of the endpoint of this item
243 void GetEndPos(int& row, int& col);
246 wxGridBagSizer* GetGBSizer() const;
247 void SetGBSizer(wxGridBagSizer* sizer);
252 //---------------------------------------------------------------------------
255 class wxGridBagSizer : public wxFlexGridSizer
258 wxGridBagSizer(int vgap = 0, int hgap = 0 );
260 // The Add method returns True if the item was successfully placed at the
261 // given cell position, False if something was already there.
263 bool Add( PyObject* item,
264 const wxGBPosition& pos,
265 const wxGBSpan& span = wxDefaultSpan,
268 PyObject* userData = NULL ) {
270 wxPyUserData* data = NULL;
271 bool blocked = wxPyBeginBlockThreads();
272 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
273 if ( userData && (info.window || info.sizer || info.gotSize) )
274 data = new wxPyUserData(userData);
275 wxPyEndBlockThreads(blocked);
277 // Now call the real Add method if a valid item type was found
279 return self->Add(info.window, pos, span, flag, border, data);
280 else if ( info.sizer )
281 return self->Add(info.sizer, pos, span, flag, border, data);
282 else if (info.gotSize)
283 return self->Add(info.size.GetWidth(), info.size.GetHeight(),
284 pos, span, flag, border, data);
289 %name(AddItem) bool Add( wxGBSizerItem *item );
292 // Get/Set the size used for cells in the grid with no item.
293 wxSize GetEmptyCellSize() const;
294 void SetEmptyCellSize(const wxSize& sz);
296 // Get the grid position of the specified item
297 %nokwargs GetItemPosition;
298 wxGBPosition GetItemPosition(wxWindow *window);
299 wxGBPosition GetItemPosition(wxSizer *sizer);
300 wxGBPosition GetItemPosition(size_t index);
302 // Set the grid position of the specified item. Returns True on success.
303 // If the move is not allowed (because an item is already there) then
304 // False is returned.
305 %nokwargs SetItemPosition;
306 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
307 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
308 bool SetItemPosition(size_t index, const wxGBPosition& pos);
310 // Get the row/col spanning of the specified item
311 %nokwargs GetItemSpan;
312 wxGBSpan GetItemSpan(wxWindow *window);
313 wxGBSpan GetItemSpan(wxSizer *sizer);
314 wxGBSpan GetItemSpan(size_t index);
316 // Set the row/col spanning of the specified item. Returns True on
317 // success. If the move is not allowed (because an item is already there)
318 // then False is returned.
319 %nokwargs SetItemSpan;
320 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
321 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
322 bool SetItemSpan(size_t index, const wxGBSpan& span);
325 // Find the sizer item for the given window or subsizer, returns NULL if
326 // not found. (non-recursive)
328 wxGBSizerItem* FindItem(wxWindow* window);
329 wxGBSizerItem* FindItem(wxSizer* sizer);
332 // Return the sizer item for the given grid cell, or NULL if there is no
333 // item at that position. (non-recursive)
334 wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos);
337 // Return the sizer item located at the point given in pt, or NULL if
338 // there is no item at that point. The (x,y) coordinates in pt correspond
339 // to the client coordinates of the window using the sizer for
340 // layout. (non-recursive)
341 wxGBSizerItem* FindItemAtPoint(const wxPoint& pt);
344 // Return the sizer item that has a matching user data (it only compares
345 // pointer values) or NULL if not found. (non-recursive)
346 wxGBSizerItem* FindItemWithData(const wxObject* userData);
349 // These are what make the sizer do size calculations and layout
350 virtual void RecalcSizes();
351 virtual wxSize CalcMin();
354 // Look at all items and see if any intersect (or would overlap) the given
355 // item. Returns True if so, False if there would be no overlap. If an
356 // excludeItem is given then it will not be checked for intersection, for
357 // example it may be the item we are checking the position of.
358 %nokwargs CheckForIntersection;
359 bool CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL);
360 bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL);
365 //---------------------------------------------------------------------------