1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Definitions of miscelaneous functions and classes
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include <wx/resource.h>
18 #include <wx/tooltip.h>
19 #include <wx/busyinfo.h>
22 //----------------------------------------------------------------------
25 %include my_typemaps.i
27 // Import some definitions of other classes, etc.
32 static wxString wxPyEmptyStr("");
35 //---------------------------------------------------------------------------
42 const char* GetClassName() {
43 return self->GetClassInfo()->GetClassName();
52 //---------------------------------------------------------------------------
61 wxSize(long w=0, long h=0);
63 void Set(long w, long h);
68 void SetWidth(long w);
69 void SetHeight(long h);
73 PyObject* tup = PyTuple_New(2);
74 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
75 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
80 %pragma(python) addtoclass = "
81 def __str__(self): return str(self.asTuple())
82 def __repr__(self): return str(self.asTuple())
83 def __len__(self): return len(self.asTuple())
84 def __getitem__(self, index): return self.asTuple()[index]
85 def __setitem__(self, index, val):
86 if index == 0: self.width = val
87 elif index == 1: self.height = val
88 else: raise IndexError
93 //---------------------------------------------------------------------------
99 wxRealPoint(double x=0.0, double y=0.0);
103 void Set(double x, double y) {
107 PyObject* asTuple() {
108 PyObject* tup = PyTuple_New(2);
109 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
110 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
114 wxRealPoint __add__(const wxRealPoint* p) {
115 if (! p) return *self;
119 wxRealPoint __sub__(const wxRealPoint* p) {
120 if (! p) return *self;
124 int __cmp__(const wxRealPoint* p) {
129 %pragma(python) addtoclass = "
130 def __str__(self): return str(self.asTuple())
131 def __repr__(self): return str(self.asTuple())
132 def __len__(self): return len(self.asTuple())
133 def __getitem__(self, index): return self.asTuple()[index]
134 def __setitem__(self, index, val):
135 if index == 0: self.width = val
136 elif index == 1: self.height = val
137 else: raise IndexError
146 wxPoint(long x=0, long y=0);
150 void Set(long x, long y) {
154 PyObject* asTuple() {
155 PyObject* tup = PyTuple_New(2);
156 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
157 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
161 wxPoint __add__(const wxPoint* p) {
162 if (! p) return *self;
166 wxPoint __sub__(const wxPoint* p) {
167 if (! p) return *self;
171 int __cmp__(const wxPoint* p) {
176 %pragma(python) addtoclass = "
177 def __str__(self): return str(self.asTuple())
178 def __repr__(self): return str(self.asTuple())
179 def __len__(self): return len(self.asTuple())
180 def __getitem__(self, index): return self.asTuple()[index]
181 def __setitem__(self, index, val):
182 if index == 0: self.x = val
183 elif index == 1: self.y = val
184 else: raise IndexError
188 //---------------------------------------------------------------------------
192 wxRect(int x=0, int y=0, int w=0, int h=0);
193 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
201 void SetWidth(int w);
203 void SetHeight(int h);
206 wxPoint GetPosition();
214 void SetLeft(int left);
215 void SetRight(int right);
216 void SetTop(int top);
217 void SetBottom(int bottom);
219 void Inflate(int dx, int dy);
220 bool Inside(int cx, int cy);
222 int x, y, width, height;
225 PyObject* asTuple() {
226 PyObject* tup = PyTuple_New(4);
227 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
228 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
229 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
230 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
234 wxRect __add__(const wxRect* rect) {
235 if (! rect) return *self;
236 return *self + *rect;
239 int __cmp__(const wxRect* rect) {
240 if (! rect) return 0;
241 return *self == *rect;
245 %pragma(python) addtoclass = "
246 def __str__(self): return str(self.asTuple())
247 def __repr__(self): return str(self.asTuple())
248 def __len__(self): return len(self.asTuple())
249 def __getitem__(self, index): return self.asTuple()[index]
250 def __setitem__(self, index, val):
251 if index == 0: self.x = val
252 elif index == 1: self.y = val
253 elif index == 2: self.width = val
254 elif index == 3: self.height = val
255 else: raise IndexError
257 # override the __getattr__ made by SWIG
258 def __getattr__(self, name):
260 'x' : miscc.wxRect_x_get,
261 'y' : miscc.wxRect_y_get,
262 'width' : miscc.wxRect_width_get,
263 'height' : miscc.wxRect_height_get,
264 'top' : miscc.wxRect_GetTop,
265 'bottom' : miscc.wxRect_GetBottom,
266 'left' : miscc.wxRect_GetLeft,
267 'right' : miscc.wxRect_GetRight,
272 raise AttributeError,name
275 # and also the __setattr__
276 def __setattr__(self, name, value):
278 'x' : miscc.wxRect_x_set,
279 'y' : miscc.wxRect_y_set,
280 'width' : miscc.wxRect_width_set,
281 'height' : miscc.wxRect_height_set,
282 'top' : miscc.wxRect_SetTop,
283 'bottom' : miscc.wxRect_SetBottom,
284 'left' : miscc.wxRect_SetLeft,
285 'right' : miscc.wxRect_SetRight,
290 self.__dict__[name] = value
299 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
302 wxRect dest(0,0,0,0);
305 reg1.Intersect(reg2);
306 dest = reg1.GetBox();
308 if (dest != wxRect(0,0,0,0)) {
309 bool doSave = wxPyRestoreThread();
310 wxRect* newRect = new wxRect(dest);
311 obj = wxPyConstructObject((void*)newRect, "wxRect");
312 PyObject* one = PyInt_FromLong(1);
313 PyObject_SetAttrString(obj, "thisown", one);
315 wxPySaveThread(doSave);
324 //---------------------------------------------------------------------------
325 // Miscellaneous functions
328 void wxRegisterId(long id);
329 %name(NewId) long wxNewId();
330 %name(RegisterId) void wxRegisterId(long id);
331 long wxGetCurrentId();
334 void wxEndBusyCursor();
336 long wxGetElapsedTime(bool resetTimer = TRUE);
338 long wxGetFreeMemory();
340 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
343 bool wxShell(const wxString& command = wxPyEmptyStr);
345 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
346 wxString wxGetOsDescription();
348 void wxSleep(int secs);
349 void wxUsleep(unsigned long milliseconds);
351 bool wxYieldIfNeeded();
352 void wxEnableTopLevelWindows(bool enable);
355 char* wxGetResource(char *section, char *entry, char *file = NULL) {
357 wxGetResource(section, entry, &retval, file);
362 wxString wxStripMenuCodes(const wxString& in);
365 wxString wxGetEmailAddress();
366 wxString wxGetHostName();
367 wxString wxGetFullHostName();
368 wxString wxGetUserId();
369 wxString wxGetUserName();
370 wxString wxGetHomeDir();
373 //----------------------------------------------------------------------
375 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
376 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
377 enum wxRelationship { wxUnconstrained = 0,
388 class wxIndividualLayoutConstraint : public wxObject {
390 // wxIndividualLayoutConstraint();
391 // ~wxIndividualLayoutConstraint();
393 void Above(wxWindow *otherWin, int margin=0);
394 void Absolute(int value);
396 void Below(wxWindow *otherWin, int margin=0);
397 void Unconstrained();
398 void LeftOf(wxWindow *otherWin, int margin=0);
399 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
400 void RightOf(wxWindow *otherWin, int margin=0);
401 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
402 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
406 class wxLayoutConstraints : public wxObject {
408 wxLayoutConstraints();
411 wxIndividualLayoutConstraint bottom;
412 wxIndividualLayoutConstraint centreX;
413 wxIndividualLayoutConstraint centreY;
414 wxIndividualLayoutConstraint height;
415 wxIndividualLayoutConstraint left;
416 wxIndividualLayoutConstraint right;
417 wxIndividualLayoutConstraint top;
418 wxIndividualLayoutConstraint width;
424 //---------------------------------------------------------------------------
425 // Accelerator Entry and Table
427 class wxAcceleratorEntry {
429 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
430 ~wxAcceleratorEntry();
432 void Set(int flags, int keyCode, int Cmd);
439 class wxAcceleratorTable : public wxObject {
441 // Can also accept a list of 3-tuples
442 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
443 ~wxAcceleratorTable();
447 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
451 #if 0 // we want to use the definition from the header, not the
452 // one SWIG will generate.
454 extern wxAcceleratorTable wxNullAcceleratorTable;
460 //---------------------------------------------------------------------------
462 class wxBusyInfo : public wxObject {
464 wxBusyInfo(const wxString& message);
468 //---------------------------------------------------------------------------