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 //---------------------------------------------------------------------------
33 // Put some wx default wxChar* values into wxStrings.
34 static const wxString wxPyEmptyString(wxT(""));
36 //---------------------------------------------------------------------------
43 wxString GetClassName() {
44 return self->GetClassInfo()->GetClassName();
53 //---------------------------------------------------------------------------
62 wxSize(long w=0, long h=0);
64 void Set(long w, long h);
69 void SetWidth(long w);
70 void SetHeight(long h);
74 wxPyBeginBlockThreads();
75 PyObject* tup = PyTuple_New(2);
76 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
77 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
78 wxPyEndBlockThreads();
82 int __cmp__(const wxSize* sz) {
84 if (*self == *sz) return 0;
89 %pragma(python) addtoclass = "
90 def __str__(self): return str(self.asTuple())
91 def __repr__(self): return str(self.asTuple())
92 def __len__(self): return len(self.asTuple())
93 def __getitem__(self, index): return self.asTuple()[index]
94 def __setitem__(self, index, val):
95 if index == 0: self.width = val
96 elif index == 1: self.height = val
97 else: raise IndexError
102 //---------------------------------------------------------------------------
108 wxRealPoint(double x=0.0, double y=0.0);
112 void Set(double x, double y) {
116 PyObject* asTuple() {
117 wxPyBeginBlockThreads();
118 PyObject* tup = PyTuple_New(2);
119 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
120 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
121 wxPyEndBlockThreads();
125 wxRealPoint __add__(const wxRealPoint* p) {
126 if (! p) return *self;
130 wxRealPoint __sub__(const wxRealPoint* p) {
131 if (! p) return *self;
135 int __cmp__(const wxRealPoint* p) {
137 if (*self == *p) return 0;
141 %pragma(python) addtoclass = "
142 def __str__(self): return str(self.asTuple())
143 def __repr__(self): return str(self.asTuple())
144 def __len__(self): return len(self.asTuple())
145 def __getitem__(self, index): return self.asTuple()[index]
146 def __setitem__(self, index, val):
147 if index == 0: self.width = val
148 elif index == 1: self.height = val
149 else: raise IndexError
158 wxPoint(long x=0, long y=0);
162 void Set(long x, long y) {
166 PyObject* asTuple() {
167 wxPyBeginBlockThreads();
168 PyObject* tup = PyTuple_New(2);
169 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
170 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
171 wxPyEndBlockThreads();
175 wxPoint __add__(const wxPoint* p) {
176 if (! p) return *self;
180 wxPoint __sub__(const wxPoint* p) {
181 if (! p) return *self;
185 int __cmp__(const wxPoint* p) {
187 if (*self == *p) return 0;
191 %pragma(python) addtoclass = "
192 def __str__(self): return str(self.asTuple())
193 def __repr__(self): return str(self.asTuple())
194 def __len__(self): return len(self.asTuple())
195 def __getitem__(self, index): return self.asTuple()[index]
196 def __setitem__(self, index, val):
197 if index == 0: self.x = val
198 elif index == 1: self.y = val
199 else: raise IndexError
203 //---------------------------------------------------------------------------
207 wxRect(int x=0, int y=0, int w=0, int h=0);
208 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
216 void SetWidth(int w);
218 void SetHeight(int h);
221 wxPoint GetPosition();
223 void SetPosition( const wxPoint &p );
224 void SetSize( const wxSize &s );
231 void SetLeft(int left);
232 void SetRight(int right);
233 void SetTop(int top);
234 void SetBottom(int bottom);
236 void Inflate(int dx, int dy);
237 bool Inside(int cx, int cy);
239 int x, y, width, height;
242 PyObject* asTuple() {
243 wxPyBeginBlockThreads();
244 PyObject* tup = PyTuple_New(4);
245 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
246 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
247 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
248 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
249 wxPyEndBlockThreads();
253 wxRect __add__(const wxRect* rect) {
254 if (! rect) return *self;
255 return *self + *rect;
258 int __cmp__(const wxRect* rect) {
259 if (! rect) return 1;
260 if (*self == *rect) return 0;
265 %pragma(python) addtoclass = "
266 def __str__(self): return str(self.asTuple())
267 def __repr__(self): return str(self.asTuple())
268 def __len__(self): return len(self.asTuple())
269 def __getitem__(self, index): return self.asTuple()[index]
270 def __setitem__(self, index, val):
271 if index == 0: self.x = val
272 elif index == 1: self.y = val
273 elif index == 2: self.width = val
274 elif index == 3: self.height = val
275 else: raise IndexError
277 # override the __getattr__ made by SWIG
278 def __getattr__(self, name):
280 'x' : miscc.wxRect_x_get,
281 'y' : miscc.wxRect_y_get,
282 'width' : miscc.wxRect_width_get,
283 'height' : miscc.wxRect_height_get,
284 'top' : miscc.wxRect_GetTop,
285 'bottom' : miscc.wxRect_GetBottom,
286 'left' : miscc.wxRect_GetLeft,
287 'right' : miscc.wxRect_GetRight,
292 raise AttributeError,name
295 # and also the __setattr__
296 def __setattr__(self, name, value):
298 'x' : miscc.wxRect_x_set,
299 'y' : miscc.wxRect_y_set,
300 'width' : miscc.wxRect_width_set,
301 'height' : miscc.wxRect_height_set,
302 'top' : miscc.wxRect_SetTop,
303 'bottom' : miscc.wxRect_SetBottom,
304 'left' : miscc.wxRect_SetLeft,
305 'right' : miscc.wxRect_SetRight,
310 self.__dict__[name] = value
319 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
322 wxRect dest(0,0,0,0);
325 reg1.Intersect(reg2);
326 dest = reg1.GetBox();
328 if (dest != wxRect(0,0,0,0)) {
329 wxPyBeginBlockThreads();
330 wxRect* newRect = new wxRect(dest);
331 obj = wxPyConstructObject((void*)newRect, "wxRect");
332 PyObject* one = PyInt_FromLong(1);
333 PyObject_SetAttrString(obj, "thisown", one);
335 wxPyEndBlockThreads();
344 //---------------------------------------------------------------------------
345 // Miscellaneous functions
348 void wxRegisterId(long id);
349 %name(NewId) long wxNewId();
350 %name(RegisterId) void wxRegisterId(long id);
351 long wxGetCurrentId();
354 void wxEndBusyCursor();
356 long wxGetElapsedTime(bool resetTimer = TRUE);
358 long wxGetFreeMemory();
360 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
363 bool wxShell(const wxString& command = wxPyEmptyString);
365 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
366 wxString wxGetOsDescription();
370 wxSHUTDOWN_POWEROFF, // power off the computer
371 wxSHUTDOWN_REBOOT // shutdown and reboot
374 // Shutdown or reboot the PC
375 bool wxShutdown(wxShutdownFlags wFlags);
378 void wxSleep(int secs);
379 void wxUsleep(unsigned long milliseconds);
381 bool wxYieldIfNeeded();
382 void wxEnableTopLevelWindows(bool enable);
385 wxString wxGetResource(const wxString& section, const wxString& entry,
386 const wxString& file = wxPyEmptyString) {
388 wxGetResource(section, entry, &retval, file);
393 wxString wxStripMenuCodes(const wxString& in);
396 wxString wxGetEmailAddress();
397 wxString wxGetHostName();
398 wxString wxGetFullHostName();
399 wxString wxGetUserId();
400 wxString wxGetUserName();
401 wxString wxGetHomeDir();
402 wxString wxGetUserHome(const wxString& user = wxPyEmptyString);
404 unsigned long wxGetProcessId();
406 // When wxApp gets the virtual method magic then enable this.
407 // bool wxHandleFatalExceptions(bool doIt = TRUE);
409 //----------------------------------------------------------------------
411 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
412 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
413 enum wxRelationship { wxUnconstrained = 0,
424 class wxIndividualLayoutConstraint : public wxObject {
426 // wxIndividualLayoutConstraint();
427 // ~wxIndividualLayoutConstraint();
429 void Above(wxWindow *otherWin, int margin=0);
430 void Absolute(int value);
432 void Below(wxWindow *otherWin, int margin=0);
433 void Unconstrained();
434 void LeftOf(wxWindow *otherWin, int margin=0);
435 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
436 void RightOf(wxWindow *otherWin, int margin=0);
437 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
438 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
442 class wxLayoutConstraints : public wxObject {
444 wxLayoutConstraints();
447 wxIndividualLayoutConstraint bottom;
448 wxIndividualLayoutConstraint centreX;
449 wxIndividualLayoutConstraint centreY;
450 wxIndividualLayoutConstraint height;
451 wxIndividualLayoutConstraint left;
452 wxIndividualLayoutConstraint right;
453 wxIndividualLayoutConstraint top;
454 wxIndividualLayoutConstraint width;
460 //---------------------------------------------------------------------------
461 // Accelerator Entry and Table
463 class wxAcceleratorEntry {
465 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
466 ~wxAcceleratorEntry();
468 void Set(int flags, int keyCode, int Cmd);
475 class wxAcceleratorTable : public wxObject {
477 // Can also accept a list of 3-tuples
478 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
479 ~wxAcceleratorTable();
483 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
487 #if 0 // we want to use the definition from the header, not the
488 // one SWIG will generate.
490 extern wxAcceleratorTable wxNullAcceleratorTable;
496 //---------------------------------------------------------------------------
498 class wxBusyInfo : public wxObject {
500 wxBusyInfo(const wxString& message);
505 //---------------------------------------------------------------------------