]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/misc.i
Various small fixes and tweaks
[wxWidgets.git] / utils / 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 wxSize {
35 public:
36 long x;
37 long y;
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);
44 long GetX();
45 long GetY();
46 long GetWidth();
47 long GetHeight();
48 void SetWidth(long w);
49 void SetHeight(long h);
50
51 %addmethods {
52 PyObject* asTuple() {
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 }
59 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
60 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
61
62 };
63
64 //---------------------------------------------------------------------------
65
66 class wxRealPoint {
67 public:
68 double x;
69 double y;
70 wxRealPoint(double x=0.0, double y=0.0);
71 ~wxRealPoint();
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())"
87 };
88
89
90 class wxPoint {
91 public:
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 }
102 PyObject* asTuple() {
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 }
109 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
110 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
111 };
112
113 //---------------------------------------------------------------------------
114
115 class wxRect {
116 public:
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();
120
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);
129
130
131 wxPoint GetPosition();
132 wxSize GetSize();
133
134 int GetLeft();
135 int GetTop();
136 int GetBottom();
137 int GetRight();
138
139 void SetLeft(int left);
140 void SetRight(int right);
141 void SetTop(int top);
142 void SetBottom(int bottom);
143
144
145 int x, y, width, height;
146
147 %addmethods {
148 PyObject* asTuple() {
149 PyObject* tup = PyTuple_New(4);
150 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
151 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->y));
152 PyTuple_SET_ITEM(tup, 2, PyInt_FromLong(self->width));
153 PyTuple_SET_ITEM(tup, 3, PyInt_FromLong(self->height));
154 return tup;
155 }
156 }
157 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
158 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
159 };
160
161
162 // %inline %{
163 // bool wxIntersectRect(wxRect* dest, wxRect* r1, wxRect* r2) {
164 // wxRegion reg1(*r1);
165 // wxRegion reg2(*r2);
166 // bool success;
167 // *dest = wxRect(0,0,0,0);
168 // success = reg1.Intersect(reg2);
169 // if (success) {
170 // *dest = reg1.GetBox();
171 // return *dest != wxRect(0,0,0,0);
172 // }
173 // return FALSE;
174 // }
175 // %}
176
177
178 %inline %{
179 PyObject* wxIntersectRect(wxRect* r1, wxRect* r2) {
180 wxRegion reg1(*r1);
181 wxRegion reg2(*r2);
182 wxRect dest(0,0,0,0);
183 PyObject* obj;
184
185 reg1.Intersect(reg2);
186 dest = reg1.GetBox();
187
188 if (dest != wxRect(0,0,0,0)) {
189 bool doSave = wxPyRestoreThread();
190 wxRect* newRect = new wxRect(dest);
191 obj = wxPyConstructObject((void*)newRect, "wxRect");
192 PyObject_SetAttrString(obj, "thisown", PyInt_FromLong(1));
193 wxPySaveThread(doSave);
194 return obj;
195 }
196 Py_INCREF(Py_None);
197 return Py_None;
198 }
199 %}
200
201
202 //---------------------------------------------------------------------------
203 // Miscellaneous functions
204
205 long wxNewId();
206 void wxRegisterId(long id);
207 %name(NewId) long wxNewId();
208 %name(RegisterId) void wxRegisterId(long id);
209
210 void wxBell();
211 void wxDisplaySize(int *OUTPUT, int *OUTPUT);
212 void wxEndBusyCursor();
213 long wxExecute(const wxString& command, int sync = FALSE);
214 long wxGetElapsedTime(bool resetTimer = TRUE);
215 #ifdef __WXMSW__
216 long wxGetFreeMemory();
217 #endif
218 void wxGetMousePosition(int* OUTPUT, int* OUTPUT);
219 bool wxIsBusy();
220 wxString wxNow();
221 bool wxShell(const wxString& command = wxPyEmptyStr);
222 void wxStartTimer();
223 int wxGetOsVersion(int *OUTPUT, int *OUTPUT);
224
225 void wxSleep(int secs);
226 bool wxYield();
227 bool wxSafeYield();
228 void wxEnableTopLevelWindows(bool enable);
229
230 %inline %{
231 char* wxGetResource(char *section, char *entry, char *file = NULL) {
232 char * retval;
233 wxGetResource(section, entry, &retval, file);
234 return retval;
235 }
236 %}
237
238 wxString wxStripMenuCodes(const wxString& in);
239
240 //----------------------------------------------------------------------
241
242 class wxPyTimer {
243 public:
244 wxPyTimer(PyObject* notify);
245 ~wxPyTimer();
246 int GetInterval();
247 bool IsOneShot();
248 void Start(int milliseconds=-1, int oneShot=FALSE);
249 void Stop();
250 };
251
252 //---------------------------------------------------------------------------
253
254 enum wxEdge { wxLeft, wxTop, wxRight, wxBottom, wxWidth, wxHeight,
255 wxCentre, wxCenter = wxCentre, wxCentreX, wxCentreY };
256 enum wxRelationship { wxUnconstrained = 0,
257 wxAsIs,
258 wxPercentOf,
259 wxAbove,
260 wxBelow,
261 wxLeftOf,
262 wxRightOf,
263 wxSameAs,
264 wxAbsolute };
265
266
267 class wxIndividualLayoutConstraint {
268 public:
269 // wxIndividualLayoutConstraint();
270 // ~wxIndividualLayoutConstraint();
271
272 void Above(wxWindow *otherWin, int margin=0);
273 void Absolute(int value);
274 void AsIs();
275 void Below(wxWindow *otherWin, int margin=0);
276 void Unconstrained();
277 void LeftOf(wxWindow *otherWin, int margin=0);
278 void PercentOf(wxWindow *otherWin, wxEdge edge, int percent);
279 void RightOf(wxWindow *otherWin, int margin=0);
280 void SameAs(wxWindow *otherWin, wxEdge edge, int margin=0);
281 void Set(wxRelationship rel, wxWindow *otherWin, wxEdge otherEdge, int value=0, int margin=0);
282 };
283
284
285 class wxLayoutConstraints {
286 public:
287 wxLayoutConstraints();
288
289 %readonly
290 wxIndividualLayoutConstraint bottom;
291 wxIndividualLayoutConstraint centreX;
292 wxIndividualLayoutConstraint centreY;
293 wxIndividualLayoutConstraint height;
294 wxIndividualLayoutConstraint left;
295 wxIndividualLayoutConstraint right;
296 wxIndividualLayoutConstraint top;
297 wxIndividualLayoutConstraint width;
298 %readwrite
299 }
300
301
302 //---------------------------------------------------------------------------
303 // Regions, etc.
304
305 enum wxRegionContain {
306 wxOutRegion, wxPartRegion, wxInRegion
307 };
308
309
310 class wxRegion {
311 public:
312 wxRegion();
313 ~wxRegion();
314
315 void Clear();
316 wxRegionContain Contains(long x, long y);
317 %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt);
318 %name(ContainsRect)wxRegionContain Contains(const wxRect& rect);
319 %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h);
320
321 wxRect GetBox();
322
323 bool Intersect(long x, long y, long width, long height);
324 %name(IntersectRect)bool Intersect(const wxRect& rect);
325 %name(IntersectRegion)bool Intersect(const wxRegion& region);
326
327 bool IsEmpty();
328
329 bool Union(long x, long y, long width, long height);
330 %name(UnionRect)bool Union(const wxRect& rect);
331 %name(UnionRegion)bool Union(const wxRegion& region);
332
333 bool Subtract(long x, long y, long width, long height);
334 %name(SubtractRect)bool Subtract(const wxRect& rect);
335 %name(SubtractRegion)bool Subtract(const wxRegion& region);
336
337 bool Xor(long x, long y, long width, long height);
338 %name(XorRect)bool Xor(const wxRect& rect);
339 %name(XorRegion)bool Xor(const wxRegion& region);
340 };
341
342
343
344 class wxRegionIterator {
345 public:
346 wxRegionIterator(const wxRegion& region);
347 ~wxRegionIterator();
348
349 long GetX();
350 long GetY();
351 long GetW();
352 long GetWidth();
353 long GetH();
354 long GetHeight();
355 wxRect GetRect();
356 bool HaveRects();
357 void Reset();
358
359 %addmethods {
360 void Next() {
361 (*self) ++;
362 }
363 };
364 };
365
366
367
368 //---------------------------------------------------------------------------
369 // Accelerator Entry and Table
370
371 class wxAcceleratorEntry {
372 public:
373 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0);
374 ~wxAcceleratorEntry();
375
376 void Set(int flags, int keyCode, int Cmd);
377 int GetFlags();
378 int GetKeyCode();
379 int GetCommand();
380 };
381
382
383 class wxAcceleratorTable {
384 public:
385 // Can also accept a list of 3-tuples
386 wxAcceleratorTable(int LCOUNT, wxAcceleratorEntry* LIST);
387 ~wxAcceleratorTable();
388
389 };
390
391 //---------------------------------------------------------------------------
392
393 class wxBusyInfo {
394 public:
395 wxBusyInfo(const wxString& message);
396 ~wxBusyInfo();
397 };
398
399
400
401 //---------------------------------------------------------------------------
402
403