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.
31 //---------------------------------------------------------------------------
38 const char* GetClassName() {
39 return self->GetClassInfo()->GetClassName();
48 //---------------------------------------------------------------------------
57 wxSize(long w=0, long h=0);
59 void Set(long w, long h);
64 void SetWidth(long w);
65 void SetHeight(long h);
69 PyObject* tup = PyTuple_New(2);
70 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
71 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
75 int __cmp__(const wxSize* sz) {
77 if (*self == *sz) return 0;
82 %pragma(python) addtoclass = "
83 def __str__(self): return str(self.asTuple())
84 def __repr__(self): return str(self.asTuple())
85 def __len__(self): return len(self.asTuple())
86 def __getitem__(self, index): return self.asTuple()[index]
87 def __setitem__(self, index, val):
88 if index == 0: self.width = val
89 elif index == 1: self.height = val
90 else: raise IndexError
95 //---------------------------------------------------------------------------
101 wxRealPoint(double x=0.0, double y=0.0);
105 void Set(double x, double y) {
109 PyObject* asTuple() {
110 PyObject* tup = PyTuple_New(2);
111 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
112 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
116 wxRealPoint __add__(const wxRealPoint* p) {
117 if (! p) return *self;
121 wxRealPoint __sub__(const wxRealPoint* p) {
122 if (! p) return *self;
126 int __cmp__(const wxRealPoint* p) {
128 if (*self == *p) return 0;
132 %pragma(python) addtoclass = "
133 def __str__(self): return str(self.asTuple())
134 def __repr__(self): return str(self.asTuple())
135 def __len__(self): return len(self.asTuple())
136 def __getitem__(self, index): return self.asTuple()[index]
137 def __setitem__(self, index, val):
138 if index == 0: self.width = val
139 elif index == 1: self.height = val
140 else: raise IndexError
149 wxPoint(long x=0, long y=0);
153 void Set(long x, long y) {
157 PyObject* asTuple() {
158 PyObject* tup = PyTuple_New(2);
159 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
160 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
164 wxPoint __add__(const wxPoint* p) {
165 if (! p) return *self;
169 wxPoint __sub__(const wxPoint* p) {
170 if (! p) return *self;
174 int __cmp__(const wxPoint* p) {
176 if (*self == *p) return 0;
180 %pragma(python) addtoclass = "
181 def __str__(self): return str(self.asTuple())
182 def __repr__(self): return str(self.asTuple())
183 def __len__(self): return len(self.asTuple())
184 def __getitem__(self, index): return self.asTuple()[index]
185 def __setitem__(self, index, val):
186 if index == 0: self.x = val
187 elif index == 1: self.y = val
188 else: raise IndexError
192 //---------------------------------------------------------------------------
196 wxRect(int x=0, int y=0, int w=0, int h=0);
197 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
205 void SetWidth(int w);
207 void SetHeight(int h);
210 wxPoint GetPosition();
218 void SetLeft(int left);
219 void SetRight(int right);
220 void SetTop(int top);
221 void SetBottom(int bottom);
223 void Inflate(int dx, int dy);
224 bool Inside(int cx, int cy);
226 int x, y, width, height;
229 PyObject* asTuple() {
230 PyObject* tup = PyTuple_New(4);
231 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
232 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
233 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
234 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
238 wxRect __add__(const wxRect* rect) {
239 if (! rect) return *self;
240 return *self + *rect;
243 int __cmp__(const wxRect* rect) {
244 if (! rect) return 1;
245 if (*self == *rect) return 0;
250 %pragma(python) addtoclass = "
251 def __str__(self): return str(self.asTuple())
252 def __repr__(self): return str(self.asTuple())
253 def __len__(self): return len(self.asTuple())
254 def __getitem__(self, index): return self.asTuple()[index]
255 def __setitem__(self, index, val):
256 if index == 0: self.x = val
257 elif index == 1: self.y = val
258 elif index == 2: self.width = val
259 elif index == 3: self.height = val
260 else: raise IndexError
262 # override the __getattr__ made by SWIG
263 def __getattr__(self, name):
265 'x' : miscc.wxRect_x_get,
266 'y' : miscc.wxRect_y_get,
267 'width' : miscc.wxRect_width_get,
268 'height' : miscc.wxRect_height_get,
269 'top' : miscc.wxRect_GetTop,
270 'bottom' : miscc.wxRect_GetBottom,
271 'left' : miscc.wxRect_GetLeft,
272 'right' : miscc.wxRect_GetRight,
277 raise AttributeError,name
280 # and also the __setattr__
281 def __setattr__(self, name, value):
283 'x' : miscc.wxRect_x_set,
284 'y' : miscc.wxRect_y_set,
285 'width' : miscc.wxRect_width_set,
286 'height' : miscc.wxRect_height_set,
287 'top' : miscc.wxRect_SetTop,
288 'bottom' : miscc.wxRect_SetBottom,
289 'left' : miscc.wxRect_SetLeft,
290 'right' : miscc.wxRect_SetRight,
295 self.__dict__[name] = value
304 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
307 wxRect dest(0,0,0,0);
310 reg1.Intersect(reg2);
311 dest = reg1.GetBox();
313 if (dest != wxRect(0,0,0,0)) {
314 wxPyBeginBlockThreads();
315 wxRect* newRect = new wxRect(dest);
316 obj = wxPyConstructObject((void*)newRect, "wxRect");
317 PyObject* one = PyInt_FromLong(1);
318 PyObject_SetAttrString(obj, "thisown", one);
320 wxPyEndBlockThreads();
329 //---------------------------------------------------------------------------
330 // Miscellaneous functions
333 void wxRegisterId(long id);
334 %name(NewId) long wxNewId();
335 %name(RegisterId) void wxRegisterId(long id);
336 long wxGetCurrentId();
339 void wxEndBusyCursor();
341 long wxGetElapsedTime(bool resetTimer = TRUE);
343 long wxGetFreeMemory();
345 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
348 bool wxShell(const wxString& command = wxEmptyString);
350 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
351 wxString wxGetOsDescription();
353 void wxSleep(int secs);
354 void wxUsleep(unsigned long milliseconds);
356 bool wxYieldIfNeeded();
357 void wxEnableTopLevelWindows(bool enable);
360 char* wxGetResource(char *section, char *entry, char *file = NULL) {
362 wxGetResource(section, entry, &retval, file);
367 wxString wxStripMenuCodes(const wxString& in);
370 wxString wxGetEmailAddress();
371 wxString wxGetHostName();
372 wxString wxGetFullHostName();
373 wxString wxGetUserId();
374 wxString wxGetUserName();
375 wxString wxGetHomeDir();
376 wxString wxGetUserHome(const char* user = "");
378 //----------------------------------------------------------------------
380 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
381 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
382 enum wxRelationship { wxUnconstrained = 0,
393 class wxIndividualLayoutConstraint : public wxObject {
395 // wxIndividualLayoutConstraint();
396 // ~wxIndividualLayoutConstraint();
398 void Above(wxWindow *otherWin, int margin=0);
399 void Absolute(int value);
401 void Below(wxWindow *otherWin, int margin=0);
402 void Unconstrained();
403 void LeftOf(wxWindow *otherWin, int margin=0);
404 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
405 void RightOf(wxWindow *otherWin, int margin=0);
406 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
407 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
411 class wxLayoutConstraints : public wxObject {
413 wxLayoutConstraints();
416 wxIndividualLayoutConstraint bottom;
417 wxIndividualLayoutConstraint centreX;
418 wxIndividualLayoutConstraint centreY;
419 wxIndividualLayoutConstraint height;
420 wxIndividualLayoutConstraint left;
421 wxIndividualLayoutConstraint right;
422 wxIndividualLayoutConstraint top;
423 wxIndividualLayoutConstraint width;
429 //---------------------------------------------------------------------------
430 // Accelerator Entry and Table
432 class wxAcceleratorEntry {
434 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
435 ~wxAcceleratorEntry();
437 void Set(int flags, int keyCode, int Cmd);
444 class wxAcceleratorTable : public wxObject {
446 // Can also accept a list of 3-tuples
447 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
448 ~wxAcceleratorTable();
452 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
456 #if 0 // we want to use the definition from the header, not the
457 // one SWIG will generate.
459 extern wxAcceleratorTable wxNullAcceleratorTable;
465 //---------------------------------------------------------------------------
467 class wxBusyInfo : public wxObject {
469 wxBusyInfo(const wxString& message);
473 //---------------------------------------------------------------------------