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