]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/misc.i
Added Net library to contrib
[wxWidgets.git] / wxPython / src / misc.i
CommitLineData
7bf85405
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: misc.i
3// Purpose: Definitions of miscelaneous functions and classes
4//
5// Author: Robin Dunn
6//
7// Created: 7/3/97
8// RCS-ID: $Id$
9// Copyright: (c) 1998 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
03e9bead 13%module misc
7bf85405 14
03e9bead 15%{
7bf85405
RD
16#include "helpers.h"
17#include <wx/resource.h>
af309447 18#include <wx/tooltip.h>
2abc0a0f 19#include <wx/busyinfo.h>
7bf85405
RD
20%}
21
22//----------------------------------------------------------------------
23
24%include typemaps.i
25%include my_typemaps.i
26
27// Import some definitions of other classes, etc.
28%import _defs.i
29
7bf85405 30
b68dc582
RD
31%{
32 static wxString wxPyEmptyStr("");
33%}
34
bb0054cd 35//---------------------------------------------------------------------------
7bf85405
RD
36
37
9416aa89
RD
38class wxObject {
39public:
40
41 %addmethods {
42 const char* GetClassName() {
43 return self->GetClassInfo()->GetClassName();
44 }
45
46 void Destroy() {
47 delete self;
48 }
49 }
50};
51
52//---------------------------------------------------------------------------
53
7bf85405
RD
54class wxSize {
55public:
af309447
RD
56 long x;
57 long y;
7bf85405
RD
58 %name(width) long x;
59 %name(height)long y;
60
61 wxSize(long w=0, long h=0);
62 ~wxSize();
63 void Set(long w, long h);
af309447
RD
64 long GetX();
65 long GetY();
bb0054cd
RD
66 long GetWidth();
67 long GetHeight();
68 void SetWidth(long w);
69 void SetHeight(long h);
7bf85405
RD
70
71 %addmethods {
af309447 72 PyObject* asTuple() {
7bf85405
RD
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));
76 return tup;
77 }
419c299a
RD
78
79 int __cmp__(const wxSize* sz) {
80 if (! sz) return 1;
81 if (*self == *sz) return 0;
82 return -1;
83 }
7bf85405 84 }
1b62f00d
RD
85
86 %pragma(python) addtoclass = "
87 def __str__(self): return str(self.asTuple())
88 def __repr__(self): return str(self.asTuple())
211a46cf 89 def __len__(self): return len(self.asTuple())
1b62f00d
RD
90 def __getitem__(self, index): return self.asTuple()[index]
91 def __setitem__(self, index, val):
92 if index == 0: self.width = val
93 elif index == 1: self.height = val
94 else: raise IndexError
95"
af309447 96
7bf85405
RD
97};
98
99//---------------------------------------------------------------------------
100
101class wxRealPoint {
102public:
103 double x;
104 double y;
105 wxRealPoint(double x=0.0, double y=0.0);
106 ~wxRealPoint();
efc5f224
RD
107
108 %addmethods {
109 void Set(double x, double y) {
110 self->x = x;
111 self->y = y;
112 }
113 PyObject* asTuple() {
114 PyObject* tup = PyTuple_New(2);
115 PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->x));
116 PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->y));
117 return tup;
118 }
c368d904
RD
119
120 wxRealPoint __add__(const wxRealPoint* p) {
121 if (! p) return *self;
122 return *self + *p;
123 }
124
125 wxRealPoint __sub__(const wxRealPoint* p) {
126 if (! p) return *self;
127 return *self - *p;
128 }
129
130 int __cmp__(const wxRealPoint* p) {
419c299a
RD
131 if (! p) return 1;
132 if (*self == *p) return 0;
133 return -1;
c368d904 134 }
efc5f224 135 }
1b62f00d
RD
136 %pragma(python) addtoclass = "
137 def __str__(self): return str(self.asTuple())
138 def __repr__(self): return str(self.asTuple())
211a46cf 139 def __len__(self): return len(self.asTuple())
1b62f00d
RD
140 def __getitem__(self, index): return self.asTuple()[index]
141 def __setitem__(self, index, val):
142 if index == 0: self.width = val
143 elif index == 1: self.height = val
144 else: raise IndexError
145"
7bf85405
RD
146};
147
efc5f224 148
7bf85405
RD
149class wxPoint {
150public:
151 long x;
152 long y;
153 wxPoint(long x=0, long y=0);
154 ~wxPoint();
155
156 %addmethods {
157 void Set(long x, long y) {
158 self->x = x;
159 self->y = y;
160 }
af309447 161 PyObject* asTuple() {
7bf85405
RD
162 PyObject* tup = PyTuple_New(2);
163 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
164 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
165 return tup;
166 }
c368d904
RD
167
168 wxPoint __add__(const wxPoint* p) {
169 if (! p) return *self;
170 return *self + *p;
171 }
172
173 wxPoint __sub__(const wxPoint* p) {
174 if (! p) return *self;
175 return *self - *p;
176 }
177
178 int __cmp__(const wxPoint* p) {
419c299a
RD
179 if (! p) return 1;
180 if (*self == *p) return 0;
181 return -1;
c368d904 182 }
7bf85405 183 }
1b62f00d
RD
184 %pragma(python) addtoclass = "
185 def __str__(self): return str(self.asTuple())
186 def __repr__(self): return str(self.asTuple())
211a46cf 187 def __len__(self): return len(self.asTuple())
1b62f00d
RD
188 def __getitem__(self, index): return self.asTuple()[index]
189 def __setitem__(self, index, val):
190 if index == 0: self.x = val
191 elif index == 1: self.y = val
192 else: raise IndexError
193"
7bf85405
RD
194};
195
196//---------------------------------------------------------------------------
197
198class wxRect {
199public:
eb715945
RD
200 wxRect(int x=0, int y=0, int w=0, int h=0);
201 // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
202 ~wxRect();
7bf85405 203
eb715945
RD
204 int GetX();
205 void SetX(int X);
206 int GetY();
207 void SetY(int Y);
208 int GetWidth();
209 void SetWidth(int w);
210 int GetHeight();
211 void SetHeight(int h);
7bf85405
RD
212
213
eb715945
RD
214 wxPoint GetPosition();
215 wxSize GetSize();
7bf85405 216
eb715945
RD
217 int GetLeft();
218 int GetTop();
219 int GetBottom();
220 int GetRight();
7bf85405 221
eb715945
RD
222 void SetLeft(int left);
223 void SetRight(int right);
224 void SetTop(int top);
225 void SetBottom(int bottom);
226
f6bcfd97
BP
227 void Inflate(int dx, int dy);
228 bool Inside(int cx, int cy);
eb715945
RD
229
230 int x, y, width, height;
af309447
RD
231
232 %addmethods {
233 PyObject* asTuple() {
234 PyObject* tup = PyTuple_New(4);
235 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
236 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
f0261a72
RD
237 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
238 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
af309447
RD
239 return tup;
240 }
f6bcfd97
BP
241
242 wxRect __add__(const wxRect* rect) {
243 if (! rect) return *self;
244 return *self + *rect;
245 }
246
247 int __cmp__(const wxRect* rect) {
419c299a
RD
248 if (! rect) return 1;
249 if (*self == *rect) return 0;
250 return -1;
f6bcfd97 251 }
af309447 252 }
f6bcfd97 253
9b3d3bc4 254 %pragma(python) addtoclass = "
1b62f00d
RD
255 def __str__(self): return str(self.asTuple())
256 def __repr__(self): return str(self.asTuple())
211a46cf 257 def __len__(self): return len(self.asTuple())
1b62f00d
RD
258 def __getitem__(self, index): return self.asTuple()[index]
259 def __setitem__(self, index, val):
260 if index == 0: self.x = val
261 elif index == 1: self.y = val
262 elif index == 2: self.width = val
263 elif index == 3: self.height = val
264 else: raise IndexError
265
9b3d3bc4
RD
266 # override the __getattr__ made by SWIG
267 def __getattr__(self, name):
268 d = {
269 'x' : miscc.wxRect_x_get,
270 'y' : miscc.wxRect_y_get,
271 'width' : miscc.wxRect_width_get,
272 'height' : miscc.wxRect_height_get,
273 'top' : miscc.wxRect_GetTop,
274 'bottom' : miscc.wxRect_GetBottom,
275 'left' : miscc.wxRect_GetLeft,
276 'right' : miscc.wxRect_GetRight,
277 }
278 try:
279 func = d[name]
280 except KeyError:
281 raise AttributeError,name
282 return func(self)
283
284 # and also the __setattr__
285 def __setattr__(self, name, value):
286 d = {
287 'x' : miscc.wxRect_x_set,
288 'y' : miscc.wxRect_y_set,
289 'width' : miscc.wxRect_width_set,
290 'height' : miscc.wxRect_height_set,
291 'top' : miscc.wxRect_SetTop,
292 'bottom' : miscc.wxRect_SetBottom,
293 'left' : miscc.wxRect_SetLeft,
294 'right' : miscc.wxRect_SetRight,
295 }
296 try:
297 func = d[name]
298 except KeyError:
299 self.__dict__[name] = value
300 return
301 func(self, value)
302 "
303
7bf85405
RD
304};
305
306
eb715945
RD
307%inline %{
308 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
309 wxRegion reg1(*r1);
310 wxRegion reg2(*r2);
311 wxRect dest(0,0,0,0);
312 PyObject* obj;
313
314 reg1.Intersect(reg2);
315 dest = reg1.GetBox();
316
317 if (dest != wxRect(0,0,0,0)) {
318 bool doSave = wxPyRestoreThread();
319 wxRect* newRect = new wxRect(dest);
320 obj = wxPyConstructObject((void*)newRect, "wxRect");
de20db99
RD
321 PyObject* one = PyInt_FromLong(1);
322 PyObject_SetAttrString(obj, "thisown", one);
323 Py_DECREF(one);
eb715945
RD
324 wxPySaveThread(doSave);
325 return obj;
326 }
327 Py_INCREF(Py_None);
328 return Py_None;
329 }
330%}
7bf85405 331
7bf85405
RD
332
333//---------------------------------------------------------------------------
334// Miscellaneous functions
335
cf694132
RD
336long wxNewId();
337void wxRegisterId(long id);
338%name(NewId) long wxNewId();
339%name(RegisterId) void wxRegisterId(long id);
83b18bab 340long wxGetCurrentId();
cf694132 341
7bf85405 342void wxBell();
7bf85405 343void wxEndBusyCursor();
c368d904 344
7bf85405 345long wxGetElapsedTime(bool resetTimer = TRUE);
bc29c5e0 346#ifdef __WXMSW__
7bf85405 347long wxGetFreeMemory();
bc29c5e0 348#endif
7bf85405
RD
349void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
350bool wxIsBusy();
351wxString wxNow();
fb5e0af0 352bool wxShell(const wxString& command = wxPyEmptyStr);
7bf85405 353void wxStartTimer();
fb5e0af0 354int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
c368d904 355wxString wxGetOsDescription();
fb5e0af0 356
bb0054cd 357void wxSleep(int secs);
c368d904 358void wxUsleep(unsigned long milliseconds);
7bf85405 359bool wxYield();
83b18bab 360bool wxYieldIfNeeded();
bb0054cd 361void wxEnableTopLevelWindows(bool enable);
7bf85405 362
7bf85405
RD
363%inline %{
364 char* wxGetResource(char *section, char *entry, char *file = NULL) {
365 char * retval;
366 wxGetResource(section, entry, &retval, file);
367 return retval;
368 }
369%}
370
694759cf 371wxString wxStripMenuCodes(const wxString& in);
7bf85405 372
c368d904
RD
373
374wxString wxGetEmailAddress();
375wxString wxGetHostName();
376wxString wxGetFullHostName();
377wxString wxGetUserId();
378wxString wxGetUserName();
379wxString wxGetHomeDir();
380
381
7bf85405
RD
382//----------------------------------------------------------------------
383
7bf85405
RD
384enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
385 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
386enum wxRelationship { wxUnconstrained = 0,
387 wxAsIs,
388 wxPercentOf,
389 wxAbove,
390 wxBelow,
391 wxLeftOf,
392 wxRightOf,
393 wxSameAs,
394 wxAbsolute };
395
396
9416aa89 397class wxIndividualLayoutConstraint : public wxObject {
7bf85405
RD
398public:
399// wxIndividualLayoutConstraint();
400// ~wxIndividualLayoutConstraint();
401
402 void Above(wxWindow *otherWin, int margin=0);
403 void Absolute(int value);
08127323 404 void AsIs();
7bf85405 405 void Below(wxWindow *otherWin, int margin=0);
08127323 406 void Unconstrained();
7bf85405
RD
407 void LeftOf(wxWindow *otherWin, int margin=0);
408 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
409 void RightOf(wxWindow *otherWin, int margin=0);
410 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
411 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
412};
413
414
9416aa89 415class wxLayoutConstraints : public wxObject {
7bf85405
RD
416public:
417 wxLayoutConstraints();
418
419%readonly
420 wxIndividualLayoutConstraint bottom;
421 wxIndividualLayoutConstraint centreX;
422 wxIndividualLayoutConstraint centreY;
423 wxIndividualLayoutConstraint height;
424 wxIndividualLayoutConstraint left;
425 wxIndividualLayoutConstraint right;
426 wxIndividualLayoutConstraint top;
427 wxIndividualLayoutConstraint width;
428%readwrite
429}
430
431
b639c3c5 432
7bf85405
RD
433//---------------------------------------------------------------------------
434// Accelerator Entry and Table
435
436class wxAcceleratorEntry {
437public:
438 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
2f90df85 439 ~wxAcceleratorEntry();
7bf85405
RD
440
441 void Set(int flags, int keyCode, int Cmd);
442 int GetFlags();
443 int GetKeyCode();
444 int GetCommand();
445};
446
447
9416aa89 448class wxAcceleratorTable : public wxObject {
7bf85405
RD
449public:
450 // Can also accept a list of 3-tuples
eec92d76 451 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
2f90df85 452 ~wxAcceleratorTable();
7bf85405
RD
453
454};
faf3cb35 455
c368d904 456wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
f6bcfd97
BP
457
458%readonly
459%{
460#if 0 // we want to use the definition from the header, not the
461 // one SWIG will generate.
462%}
463extern wxAcceleratorTable wxNullAcceleratorTable;
464%{
465#endif
466%}
467%readwrite
468
8bf5d46e 469//---------------------------------------------------------------------------
2abc0a0f 470
9416aa89 471class wxBusyInfo : public wxObject {
2abc0a0f
RD
472public:
473 wxBusyInfo(const wxString& message);
474 ~wxBusyInfo();
475};
476
8bf5d46e
RD
477//---------------------------------------------------------------------------
478
479
c368d904 480