]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gbsizer.i
SWIG patch for "autodoc" and "docstring" %features
[wxWidgets.git] / wxPython / src / _gbsizer.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _gbsizer.i
3 // Purpose: SWIG interface stuff for wxGBGridBagSizer and etc.
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 05-Nov-2003
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 %}
20
21 //---------------------------------------------------------------------------
22
23 %typemap(in) wxGBPosition& (wxGBPosition temp) {
24 $1 = &temp;
25 if ( ! wxGBPosition_helper($input, &$1)) SWIG_fail;
26 }
27 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBPosition& {
28 $1 = wxPySimple_typecheck($input, wxT("wxGBPosition"), 2);
29 }
30
31 %typemap(in) wxGBSpan& (wxGBSpan temp) {
32 $1 = &temp;
33 if ( ! wxGBSpan_helper($input, &$1)) SWIG_fail;
34 }
35 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBSpan& {
36 $1 = wxPySimple_typecheck($input, wxT("wxGBSpan"), 2);
37 }
38
39
40 %{
41 bool wxGBPosition_helper(PyObject* source, wxGBPosition** obj)
42 {
43 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBPosition"));
44 }
45
46 bool wxGBSpan_helper(PyObject* source, wxGBSpan** obj)
47 {
48 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBSpan"));
49 }
50
51 %}
52
53
54 //---------------------------------------------------------------------------
55 %newgroup;
56
57
58 class wxGBPosition
59 {
60 public:
61 wxGBPosition(int row=0, int col=0);
62
63 int GetRow() const;
64 int GetCol() const;
65 void SetRow(int row);
66 void SetCol(int col);
67
68 bool operator==(const wxGBPosition& p) const;
69 bool operator!=(const wxGBPosition& p) const;
70
71 %extend {
72 PyObject* asTuple() {
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();
78 return tup;
79 }
80 }
81 %pythoncode {
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)
94 }
95
96 %pythoncode {
97 row = property(GetRow, SetRow)
98 col = property(GetCol, SetCol)
99 }
100 };
101
102
103
104
105 class wxGBSpan
106 {
107 public:
108 wxGBSpan(int rowspan=1, int colspan=1);
109
110 int GetRowspan() const;
111 int GetColspan() const;
112 void SetRowspan(int rowspan);
113 void SetColspan(int colspan);
114
115 bool operator==(const wxGBSpan& o) const;
116 bool operator!=(const wxGBSpan& o) const;
117
118 %extend {
119 PyObject* asTuple() {
120 wxPyBeginBlockThreads();
121 PyObject* tup = PyTuple_New(2);
122 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan()));
123 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan()));
124 wxPyEndBlockThreads();
125 return tup;
126 }
127 }
128 %pythoncode {
129 def __str__(self): return str(self.asTuple())
130 def __repr__(self): return 'wxGBSpan'+str(self.asTuple())
131 def __len__(self): return len(self.asTuple())
132 def __getitem__(self, index): return self.asTuple()[index]
133 def __setitem__(self, index, val):
134 if index == 0: self.SetRowspan(val)
135 elif index == 1: self.SetColspan(val)
136 else: raise IndexError
137 def __nonzero__(self): return self.asTuple() != (0,0)
138 def __getinitargs__(self): return ()
139 def __getstate__(self): return self.asTuple()
140 def __setstate__(self, state): self.Set(*state)
141 }
142
143 %pythoncode {
144 rowspan = property(GetRowspan, SetRowspan)
145 colspan = property(GetColspan, SetColspan)
146 }
147 };
148
149
150 %immutable;
151 const wxGBSpan wxDefaultSpan;
152 %mutable;
153
154
155 //---------------------------------------------------------------------------
156
157
158 class wxGBSizerItem : public wxSizerItem
159 {
160 public:
161 wxGBSizerItem();
162
163 %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window,
164 const wxGBPosition& pos,
165 const wxGBSpan& span,
166 int flag,
167 int border,
168 wxObject* userData );
169
170 %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer,
171 const wxGBPosition& pos,
172 const wxGBSpan& span,
173 int flag,
174 int border,
175 wxObject* userData );
176
177 %name(GBSizerItemSpacer) wxGBSizerItem( int width,
178 int height,
179 const wxGBPosition& pos,
180 const wxGBSpan& span,
181 int flag,
182 int border,
183 wxObject* userData);
184
185
186 // Get the grid position of the item
187 wxGBPosition GetPos() const;
188 %pythoncode { def GetPosTuple(self): return self.GetPos().asTuple() }
189
190 // Get the row and column spanning of the item
191 wxGBSpan GetSpan() const;
192 %pythoncode { def GetSpanTuple(self): return self.GetSpan().asTuple() }
193
194 // If the item is already a member of a sizer then first ensure that there
195 // is no other item that would intersect with this one at the new
196 // position, then set the new position. Returns true if the change is
197 // successful and after the next Layout the item will be moved.
198 bool SetPos( const wxGBPosition& pos );
199
200 // If the item is already a member of a sizer then first ensure that there
201 // is no other item that would intersect with this one with its new
202 // spanning size, then set the new spanning. Returns true if the change
203 // is successful and after the next Layout the item will be resized.
204 bool SetSpan( const wxGBSpan& span );
205
206 %nokwargs Intersects;
207
208 // Returns true if this item and the other item instersect
209 bool Intersects(const wxGBSizerItem& other);
210
211 // Returns true if the given pos/span would intersect with this item.
212 bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
213
214 // Get the row and column of the endpoint of this item
215 void GetEndPos(int& row, int& col);
216
217
218 wxGridBagSizer* GetGBSizer() const;
219 void SetGBSizer(wxGridBagSizer* sizer);
220
221 };
222
223
224 //---------------------------------------------------------------------------
225
226
227 class wxGridBagSizer : public wxFlexGridSizer
228 {
229 public:
230 wxGridBagSizer(int vgap = 0, int hgap = 0 );
231
232 // The Add method returns true if the item was successfully placed at the
233 // given cell position, false if something was already there.
234 %extend {
235 bool Add( PyObject* item,
236 const wxGBPosition& pos,
237 const wxGBSpan& span = wxDefaultSpan,
238 int flag = 0,
239 int border = 0,
240 PyObject* userData = NULL ) {
241
242 wxPyUserData* data = NULL;
243 wxPyBeginBlockThreads();
244 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
245 if ( userData && (info.window || info.sizer || info.gotSize) )
246 data = new wxPyUserData(userData);
247 wxPyEndBlockThreads();
248
249 // Now call the real Add method if a valid item type was found
250 if ( info.window )
251 return self->Add(info.window, pos, span, flag, border, data);
252 else if ( info.sizer )
253 return self->Add(info.sizer, pos, span, flag, border, data);
254 else if (info.gotSize)
255 return self->Add(info.size.GetWidth(), info.size.GetHeight(),
256 pos, span, flag, border, data);
257 return false;
258 }
259 }
260
261 %name(AddItem) bool Add( wxGBSizerItem *item );
262
263
264 // Get/Set the size used for cells in the grid with no item.
265 wxSize GetEmptyCellSize() const;
266 void SetEmptyCellSize(const wxSize& sz);
267
268 // Get the grid position of the specified item
269 %nokwargs GetItemPosition;
270 wxGBPosition GetItemPosition(wxWindow *window);
271 wxGBPosition GetItemPosition(wxSizer *sizer);
272 wxGBPosition GetItemPosition(size_t index);
273
274 // Set the grid position of the specified item. Returns true on success.
275 // If the move is not allowed (because an item is already there) then
276 // false is returned.
277 %nokwargs SetItemPosition;
278 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
279 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
280 bool SetItemPosition(size_t index, const wxGBPosition& pos);
281
282 // Get the row/col spanning of the specified item
283 %nokwargs GetItemSpan;
284 wxGBSpan GetItemSpan(wxWindow *window);
285 wxGBSpan GetItemSpan(wxSizer *sizer);
286 wxGBSpan GetItemSpan(size_t index);
287
288 // Set the row/col spanning of the specified item. Returns true on
289 // success. If the move is not allowed (because an item is already there)
290 // then false is returned.
291 %nokwargs SetItemSpan;
292 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
293 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
294 bool SetItemSpan(size_t index, const wxGBSpan& span);
295
296
297 // Find the sizer item for the given window or subsizer, returns NULL if
298 // not found. (non-recursive)
299 %nokwargs FindItem;
300 wxGBSizerItem* FindItem(wxWindow* window);
301 wxGBSizerItem* FindItem(wxSizer* sizer);
302
303
304 // Return the sizer item for the given grid cell, or NULL if there is no
305 // item at that position. (non-recursive)
306 wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos);
307
308
309 // Return the sizer item that has a matching user data (it only compares
310 // pointer values) or NULL if not found. (non-recursive)
311 wxGBSizerItem* FindItemWithData(const wxObject* userData);
312
313
314 // These are what make the sizer do size calculations and layout
315 virtual void RecalcSizes();
316 virtual wxSize CalcMin();
317
318
319 // Look at all items and see if any intersect (or would overlap) the given
320 // item. Returns true if so, false if there would be no overlap. If an
321 // excludeItem is given then it will not be checked for intersection, for
322 // example it may be the item we are checking the position of.
323 %nokwargs CheckForIntersection;
324 bool CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL);
325 bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL);
326
327 };
328
329
330 //---------------------------------------------------------------------------