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