]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/misc.i
Commented out the bitmap-greying code until I have time to debug it
[wxWidgets.git] / wxPython / src / misc.i
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
13 %module misc
14
15 %{
16 #include "helpers.h"
17 #include <wx/resource.h>
18 #include <wx/tooltip.h>
19 #include <wx/busyinfo.h>
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
30
31 //---------------------------------------------------------------------------
32
33
34 class wxObject {
35 public:
36
37 %addmethods {
38 const char* GetClassName() {
39 return self->GetClassInfo()->GetClassName();
40 }
41
42 void Destroy() {
43 delete self;
44 }
45 }
46 };
47
48 //---------------------------------------------------------------------------
49
50 class wxSize {
51 public:
52 long x;
53 long y;
54 %name(width) long x;
55 %name(height)long y;
56
57 wxSize(long w=0, long h=0);
58 ~wxSize();
59 void Set(long w, long h);
60 long GetX();
61 long GetY();
62 long GetWidth();
63 long GetHeight();
64 void SetWidth(long w);
65 void SetHeight(long h);
66
67 %addmethods {
68 PyObject* asTuple() {
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));
72 return tup;
73 }
74
75 int __cmp__(const wxSize* sz) {
76 if (! sz) return 1;
77 if (*self == *sz) return 0;
78 return -1;
79 }
80 }
81
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
91 "
92
93 };
94
95 //---------------------------------------------------------------------------
96
97 class wxRealPoint {
98 public:
99 double x;
100 double y;
101 wxRealPoint(double x=0.0, double y=0.0);
102 ~wxRealPoint();
103
104 %addmethods {
105 void Set(double x, double y) {
106 self->x = x;
107 self->y = y;
108 }
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));
113 return tup;
114 }
115
116 wxRealPoint __add__(const wxRealPoint* p) {
117 if (! p) return *self;
118 return *self + *p;
119 }
120
121 wxRealPoint __sub__(const wxRealPoint* p) {
122 if (! p) return *self;
123 return *self - *p;
124 }
125
126 int __cmp__(const wxRealPoint* p) {
127 if (! p) return 1;
128 if (*self == *p) return 0;
129 return -1;
130 }
131 }
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
141 "
142 };
143
144
145 class wxPoint {
146 public:
147 long x;
148 long y;
149 wxPoint(long x=0, long y=0);
150 ~wxPoint();
151
152 %addmethods {
153 void Set(long x, long y) {
154 self->x = x;
155 self->y = y;
156 }
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));
161 return tup;
162 }
163
164 wxPoint __add__(const wxPoint* p) {
165 if (! p) return *self;
166 return *self + *p;
167 }
168
169 wxPoint __sub__(const wxPoint* p) {
170 if (! p) return *self;
171 return *self - *p;
172 }
173
174 int __cmp__(const wxPoint* p) {
175 if (! p) return 1;
176 if (*self == *p) return 0;
177 return -1;
178 }
179 }
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
189 "
190 };
191
192 //---------------------------------------------------------------------------
193
194 class wxRect {
195 public:
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);
198 ~wxRect();
199
200 int GetX();
201 void SetX(int X);
202 int GetY();
203 void SetY(int Y);
204 int GetWidth();
205 void SetWidth(int w);
206 int GetHeight();
207 void SetHeight(int h);
208
209
210 wxPoint GetPosition();
211 wxSize GetSize();
212
213 int GetLeft();
214 int GetTop();
215 int GetBottom();
216 int GetRight();
217
218 void SetLeft(int left);
219 void SetRight(int right);
220 void SetTop(int top);
221 void SetBottom(int bottom);
222
223 void Inflate(int dx, int dy);
224 bool Inside(int cx, int cy);
225
226 int x, y, width, height;
227
228 %addmethods {
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));
235 return tup;
236 }
237
238 wxRect __add__(const wxRect* rect) {
239 if (! rect) return *self;
240 return *self + *rect;
241 }
242
243 int __cmp__(const wxRect* rect) {
244 if (! rect) return 1;
245 if (*self == *rect) return 0;
246 return -1;
247 }
248 }
249
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
261
262 # override the __getattr__ made by SWIG
263 def __getattr__(self, name):
264 d = {
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,
273 }
274 try:
275 func = d[name]
276 except KeyError:
277 raise AttributeError,name
278 return func(self)
279
280 # and also the __setattr__
281 def __setattr__(self, name, value):
282 d = {
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,
291 }
292 try:
293 func = d[name]
294 except KeyError:
295 self.__dict__[name] = value
296 return
297 func(self, value)
298 "
299
300 };
301
302
303 %inline %{
304 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
305 wxRegion reg1(*r1);
306 wxRegion reg2(*r2);
307 wxRect dest(0,0,0,0);
308 PyObject* obj;
309
310 reg1.Intersect(reg2);
311 dest = reg1.GetBox();
312
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);
319 Py_DECREF(one);
320 wxPyEndBlockThreads();
321 return obj;
322 }
323 Py_INCREF(Py_None);
324 return Py_None;
325 }
326 %}
327
328
329 //---------------------------------------------------------------------------
330 // Miscellaneous functions
331
332 long wxNewId();
333 void wxRegisterId(long id);
334 %name(NewId) long wxNewId();
335 %name(RegisterId) void wxRegisterId(long id);
336 long wxGetCurrentId();
337
338 void wxBell();
339 void wxEndBusyCursor();
340
341 long wxGetElapsedTime(bool resetTimer = TRUE);
342 #ifdef __WXMSW__
343 long wxGetFreeMemory();
344 #endif
345 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
346 bool wxIsBusy();
347 wxString wxNow();
348 bool wxShell(const wxString& command = wxEmptyString);
349 void wxStartTimer();
350 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
351 wxString wxGetOsDescription();
352
353 void wxSleep(int secs);
354 void wxUsleep(unsigned long milliseconds);
355 bool wxYield();
356 bool wxYieldIfNeeded();
357 void wxEnableTopLevelWindows(bool enable);
358
359 %inline %{
360 char* wxGetResource(char *section, char *entry, char *file = NULL) {
361 char * retval;
362 wxGetResource(section, entry, &retval, file);
363 return retval;
364 }
365 %}
366
367 wxString wxStripMenuCodes(const wxString& in);
368
369
370 wxString wxGetEmailAddress();
371 wxString wxGetHostName();
372 wxString wxGetFullHostName();
373 wxString wxGetUserId();
374 wxString wxGetUserName();
375 wxString wxGetHomeDir();
376 wxString wxGetUserHome(const char* user = "");
377
378 //----------------------------------------------------------------------
379
380 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
381 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
382 enum wxRelationship { wxUnconstrained = 0,
383 wxAsIs,
384 wxPercentOf,
385 wxAbove,
386 wxBelow,
387 wxLeftOf,
388 wxRightOf,
389 wxSameAs,
390 wxAbsolute };
391
392
393 class wxIndividualLayoutConstraint : public wxObject {
394 public:
395 // wxIndividualLayoutConstraint();
396 // ~wxIndividualLayoutConstraint();
397
398 void Above(wxWindow *otherWin, int margin=0);
399 void Absolute(int value);
400 void AsIs();
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);
408 };
409
410
411 class wxLayoutConstraints : public wxObject {
412 public:
413 wxLayoutConstraints();
414
415 %readonly
416 wxIndividualLayoutConstraint bottom;
417 wxIndividualLayoutConstraint centreX;
418 wxIndividualLayoutConstraint centreY;
419 wxIndividualLayoutConstraint height;
420 wxIndividualLayoutConstraint left;
421 wxIndividualLayoutConstraint right;
422 wxIndividualLayoutConstraint top;
423 wxIndividualLayoutConstraint width;
424 %readwrite
425 }
426
427
428
429 //---------------------------------------------------------------------------
430 // Accelerator Entry and Table
431
432 class wxAcceleratorEntry {
433 public:
434 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
435 ~wxAcceleratorEntry();
436
437 void Set(int flags, int keyCode, int Cmd);
438 int GetFlags();
439 int GetKeyCode();
440 int GetCommand();
441 };
442
443
444 class wxAcceleratorTable : public wxObject {
445 public:
446 // Can also accept a list of 3-tuples
447 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* choices);
448 ~wxAcceleratorTable();
449
450 };
451
452 wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
453
454 %readonly
455 %{
456 #if 0 // we want to use the definition from the header, not the
457 // one SWIG will generate.
458 %}
459 extern wxAcceleratorTable wxNullAcceleratorTable;
460 %{
461 #endif
462 %}
463 %readwrite
464
465 //---------------------------------------------------------------------------
466
467 class wxBusyInfo : public wxObject {
468 public:
469 wxBusyInfo(const wxString& message);
470 ~wxBusyInfo();
471 };
472
473 //---------------------------------------------------------------------------
474
475
476