]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/src/sizers.i
Added a constructor that allows creation of independent wxControl
[wxWidgets.git] / utils / wxPython / src / sizers.i
CommitLineData
2f90df85
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: sizers.i
3// Purpose: SWIG definitions of the wxSizer family of classes
4//
5// Author: Robin Dunn
6//
7// Created: 18-Sept-1999
8// RCS-ID: $Id$
f0261a72 9// Copyright: (c) 1999 by Total Control Software
2f90df85
RD
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13%module sizers
14
15%{
16#include "helpers.h"
17%}
18
19//----------------------------------------------------------------------
20
21%include typemaps.i
22%include my_typemaps.i
23
24// Import some definitions of other classes, etc.
25%import _defs.i
26%import misc.i
27%import windows.i
28%import controls.i
29
30%pragma(python) code = "import wx"
31%pragma(python) code = "import string"
32
33//---------------------------------------------------------------------------
34
35%{
36class wxPyUserData : public wxObject {
37public:
38 wxPyUserData(PyObject* obj) { m_obj = obj; Py_INCREF(m_obj); }
39 ~wxPyUserData() {
40 bool doSave = wxPyRestoreThread();
41 Py_DECREF(m_obj);
42 wxPySaveThread(doSave);
43 }
44 PyObject* m_obj;
45};
46%}
47
48//---------------------------------------------------------------------------
49
50class wxSizerItem {
51public:
52 // No need to ever create one directly in Python...
53
54 //wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData);
55 //wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData );
56 //wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData );
57
58 wxSize GetSize();
59 wxSize CalcMin();
60 void SetDimension( wxPoint pos, wxSize size );
61
62 bool IsWindow();
63 bool IsSizer();
64 bool IsSpacer();
65
66 wxWindow *GetWindow();
67 wxSizer *GetSizer();
68 int GetOption();
69 int GetFlag();
70 int GetBorder();
71
72 // wxObject* GetUserData();
73 %addmethods {
74 // Assume that the user data is a wxPyUserData object and return the contents
75 PyObject* GetUserData() {
76 wxPyUserData* data = (wxPyUserData*)self->GetUserData();
77 if (data) {
78 Py_INCREF(data->m_obj);
79 return data->m_obj;
80 } else {
81 Py_INCREF(Py_None);
82 return Py_None;
83 }
84 }
85 }
86};
87
88
89//---------------------------------------------------------------------------
90
91class wxSizer {
92public:
93 // wxSizer(); **** abstract, can't instantiate
94 // ~wxSizer();
95
96 %addmethods {
97 void Destroy() { delete self; }
98
99 void AddWindow(wxWindow *window, int option=0, int flag=0, int border=0,
100 PyObject* userData=NULL) {
101 wxPyUserData* data = NULL;
102 if (userData) data = new wxPyUserData(userData);
103 self->Add(window, option, flag, border, data);
104 }
105
106 void AddSizer(wxSizer *sizer, int option=0, int flag=0, int border=0,
107 PyObject* userData=NULL) {
108 wxPyUserData* data = NULL;
109 if (userData) data = new wxPyUserData(userData);
110 self->Add(sizer, option, flag, border, data);
111 }
112
113 void AddSpacer(int width, int height, int option=0, int flag=0,
114 int border=0, PyObject* userData=NULL) {
115 wxPyUserData* data = NULL;
116 if (userData) data = new wxPyUserData(userData);
117 self->Add(width, height, option, flag, border, data);
118 }
119
120
121 void PrependWindow(wxWindow *window, int option=0, int flag=0, int border=0,
122 PyObject* userData=NULL) {
123 wxPyUserData* data = NULL;
124 if (userData) data = new wxPyUserData(userData);
125 self->Prepend(window, option, flag, border, data);
126 }
127
128 void PrependSizer(wxSizer *sizer, int option=0, int flag=0, int border=0,
129 PyObject* userData=NULL) {
130 wxPyUserData* data = NULL;
131 if (userData) data = new wxPyUserData(userData);
132 self->Prepend(sizer, option, flag, border, data);
133 }
134
135 void PrependSpacer(int width, int height, int option=0, int flag=0,
136 int border=0, PyObject* userData=NULL) {
137 wxPyUserData* data = NULL;
138 if (userData) data = new wxPyUserData(userData);
139 self->Prepend(width, height, option, flag, border, data);
140 }
141 }
142
143 %name(RemoveWindow)bool Remove( wxWindow *window );
144 %name(RemoveSizer)bool Remove( wxSizer *sizer );
145 %name(RemovePos)bool Remove( int pos );
146
147
148 %pragma(python) addtoclass = "
149 def Add(self, *args):
150 if type(args[0]) == type(1):
151 apply(self.AddSpacer, args)
152 elif string.find(args[0].this, 'Sizer') != -1:
153 apply(self.AddSizer, args)
154 else:
155 apply(self.AddWindow, args)
156
157 def Prepend(self, *args):
158 if type(args[0]) == type(1):
159 apply(self.PrependSpacer, args)
160 elif string.find(args[0].this, 'Sizer') != -1:
161 apply(self.PrependSizer, args)
162 else:
163 apply(self.PrependWindow, args)
164
165 def Remove(self, *args):
166 if type(args[0]) == type(1):
167 apply(self.RemovePos, args)
168 elif string.find(args[0].this, 'Sizer') != -1:
169 apply(self.RemoveSizer, args)
170 else:
171 apply(self.RemoveWindow, args)
172
173 def AddMany(self, widgets):
174 for childinfo in widgets:
175 if type(childinfo) != type(()):
176 childinfo = (childinfo, )
177 apply(self.Add, childinfo)
178"
179
180
181 void SetDimension( int x, int y, int width, int height );
182
183 wxSize GetSize();
184 wxPoint GetPosition();
185 wxSize GetMinSize();
186
187 // void RecalcSizes() = 0;
188 // wxSize CalcMin() = 0;
189
190 void Layout();
191
192 void Fit( wxWindow *window );
193 void SetSizeHints( wxWindow *window );
194
195 // wxList& GetChildren();
196 %addmethods {
197 PyObject* GetChildren() {
198 wxList& list = self->GetChildren();
199 return wxPy_ConvertList(&list, "wxSizerItem");
200 }
201 }
202};
203
204
205//---------------------------------------------------------------------------
206// Use this one for deriving Python classes from
207%{
208class wxPySizer : public wxSizer {
209 DECLARE_DYNAMIC_CLASS(wxPySizer);
210public:
211 wxPySizer() : wxSizer() {};
212
213 DEC_PYCALLBACK___pure(RecalcSizes);
214 DEC_PYCALLBACK_wxSize__pure(CalcMin);
215 PYPRIVATE;
216};
217
218
219IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
220IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
221
222IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
223%}
224
225
226
227class wxPySizer : public wxSizer {
228public:
229 wxPySizer();
230 void _setSelf(PyObject* self);
231 %pragma(python) addtomethod = "__init__:self._setSelf(self)"
232};
233
234
235//---------------------------------------------------------------------------
236
237class wxBoxSizer : public wxSizer {
238public:
239 wxBoxSizer(int orient = wxHORIZONTAL);
240 int GetOrientation();
241};
242
243//---------------------------------------------------------------------------
244
245class wxStaticBoxSizer : public wxBoxSizer {
246public:
247 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
248 wxStaticBox *GetStaticBox();
249};
250
251//---------------------------------------------------------------------------