blob: 71858f606beac6f8055835edfa4202b90c0b24cd [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Evt =========================== */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000018extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
Guido van Rossum17448e21995-01-30 11:53:55 +000020
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000023extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
Guido van Rossum17448e21995-01-30 11:53:55 +000025
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
Jack Jansen425e9eb1995-12-12 15:02:03 +000037extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Guido van Rossume26c2631995-02-28 09:11:41 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
Guido van Rossum17448e21995-01-30 11:53:55 +000045#include <Events.h>
46
47#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
48
49static PyObject *Evt_Error;
50
Jack Jansen21f96871998-02-20 16:02:09 +000051static PyObject *Evt_GetMouse(_self, _args)
52 PyObject *_self;
53 PyObject *_args;
54{
55 PyObject *_res = NULL;
56 Point mouseLoc;
57 if (!PyArg_ParseTuple(_args, ""))
58 return NULL;
59 GetMouse(&mouseLoc);
60 _res = Py_BuildValue("O&",
61 PyMac_BuildPoint, mouseLoc);
62 return _res;
63}
64
65static PyObject *Evt_Button(_self, _args)
66 PyObject *_self;
67 PyObject *_args;
68{
69 PyObject *_res = NULL;
70 Boolean _rv;
71 if (!PyArg_ParseTuple(_args, ""))
72 return NULL;
73 _rv = Button();
74 _res = Py_BuildValue("b",
75 _rv);
76 return _res;
77}
78
79static PyObject *Evt_StillDown(_self, _args)
80 PyObject *_self;
81 PyObject *_args;
82{
83 PyObject *_res = NULL;
84 Boolean _rv;
85 if (!PyArg_ParseTuple(_args, ""))
86 return NULL;
87 _rv = StillDown();
88 _res = Py_BuildValue("b",
89 _rv);
90 return _res;
91}
92
93static PyObject *Evt_WaitMouseUp(_self, _args)
94 PyObject *_self;
95 PyObject *_args;
96{
97 PyObject *_res = NULL;
98 Boolean _rv;
99 if (!PyArg_ParseTuple(_args, ""))
100 return NULL;
101 _rv = WaitMouseUp();
102 _res = Py_BuildValue("b",
103 _rv);
104 return _res;
105}
106
107static PyObject *Evt_TickCount(_self, _args)
108 PyObject *_self;
109 PyObject *_args;
110{
111 PyObject *_res = NULL;
112 UInt32 _rv;
113 if (!PyArg_ParseTuple(_args, ""))
114 return NULL;
115 _rv = TickCount();
116 _res = Py_BuildValue("l",
117 _rv);
118 return _res;
119}
120
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000121static PyObject *Evt_GetCaretTime(_self, _args)
122 PyObject *_self;
123 PyObject *_args;
124{
125 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000126 UInt32 _rv;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000127 if (!PyArg_ParseTuple(_args, ""))
128 return NULL;
129 _rv = GetCaretTime();
130 _res = Py_BuildValue("l",
131 _rv);
132 return _res;
133}
134
Jack Jansen21f96871998-02-20 16:02:09 +0000135static PyObject *Evt_GetKeys(_self, _args)
136 PyObject *_self;
137 PyObject *_args;
138{
139 PyObject *_res = NULL;
140 KeyMap theKeys__out__;
141 if (!PyArg_ParseTuple(_args, ""))
142 return NULL;
143 GetKeys(theKeys__out__);
144 _res = Py_BuildValue("s#",
145 (char *)&theKeys__out__, (int)sizeof(KeyMap));
146 theKeys__error__: ;
147 return _res;
148}
149
150static PyObject *Evt_GetDblTime(_self, _args)
151 PyObject *_self;
152 PyObject *_args;
153{
154 PyObject *_res = NULL;
155 UInt32 _rv;
156 if (!PyArg_ParseTuple(_args, ""))
157 return NULL;
158 _rv = GetDblTime();
159 _res = Py_BuildValue("l",
160 _rv);
161 return _res;
162}
163
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000164static PyObject *Evt_SetEventMask(_self, _args)
165 PyObject *_self;
166 PyObject *_args;
167{
168 PyObject *_res = NULL;
Jack Jansend40f3c61995-10-09 23:12:22 +0000169 EventMask value;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000170 if (!PyArg_ParseTuple(_args, "h",
171 &value))
172 return NULL;
173 SetEventMask(value);
174 Py_INCREF(Py_None);
175 _res = Py_None;
176 return _res;
177}
178
Guido van Rossum17448e21995-01-30 11:53:55 +0000179static PyObject *Evt_GetNextEvent(_self, _args)
180 PyObject *_self;
181 PyObject *_args;
182{
183 PyObject *_res = NULL;
184 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000185 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000186 EventRecord theEvent;
187 if (!PyArg_ParseTuple(_args, "h",
188 &eventMask))
189 return NULL;
190 _rv = GetNextEvent(eventMask,
191 &theEvent);
192 _res = Py_BuildValue("bO&",
193 _rv,
194 PyMac_BuildEventRecord, &theEvent);
195 return _res;
196}
197
Guido van Rossum17448e21995-01-30 11:53:55 +0000198static PyObject *Evt_EventAvail(_self, _args)
199 PyObject *_self;
200 PyObject *_args;
201{
202 PyObject *_res = NULL;
203 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000204 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000205 EventRecord theEvent;
206 if (!PyArg_ParseTuple(_args, "h",
207 &eventMask))
208 return NULL;
209 _rv = EventAvail(eventMask,
210 &theEvent);
211 _res = Py_BuildValue("bO&",
212 _rv,
213 PyMac_BuildEventRecord, &theEvent);
214 return _res;
215}
216
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000217static PyObject *Evt_PostEvent(_self, _args)
218 PyObject *_self;
219 PyObject *_args;
220{
221 PyObject *_res = NULL;
222 OSErr _err;
Jack Jansend40f3c61995-10-09 23:12:22 +0000223 EventKind eventNum;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000224 UInt32 eventMsg;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000225 if (!PyArg_ParseTuple(_args, "hl",
226 &eventNum,
227 &eventMsg))
228 return NULL;
229 _err = PostEvent(eventNum,
230 eventMsg);
231 if (_err != noErr) return PyMac_Error(_err);
232 Py_INCREF(Py_None);
233 _res = Py_None;
234 return _res;
235}
236
237static PyObject *Evt_OSEventAvail(_self, _args)
238 PyObject *_self;
239 PyObject *_args;
240{
241 PyObject *_res = NULL;
242 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000243 EventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000244 EventRecord theEvent;
245 if (!PyArg_ParseTuple(_args, "h",
246 &mask))
247 return NULL;
248 _rv = OSEventAvail(mask,
249 &theEvent);
250 _res = Py_BuildValue("bO&",
251 _rv,
252 PyMac_BuildEventRecord, &theEvent);
253 return _res;
254}
255
256static PyObject *Evt_GetOSEvent(_self, _args)
257 PyObject *_self;
258 PyObject *_args;
259{
260 PyObject *_res = NULL;
261 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000262 EventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000263 EventRecord theEvent;
264 if (!PyArg_ParseTuple(_args, "h",
265 &mask))
266 return NULL;
267 _rv = GetOSEvent(mask,
268 &theEvent);
269 _res = Py_BuildValue("bO&",
270 _rv,
271 PyMac_BuildEventRecord, &theEvent);
272 return _res;
273}
274
275static PyObject *Evt_FlushEvents(_self, _args)
276 PyObject *_self;
277 PyObject *_args;
278{
279 PyObject *_res = NULL;
Jack Jansend40f3c61995-10-09 23:12:22 +0000280 EventMask whichMask;
281 EventMask stopMask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000282 if (!PyArg_ParseTuple(_args, "hh",
283 &whichMask,
284 &stopMask))
285 return NULL;
286 FlushEvents(whichMask,
287 stopMask);
288 Py_INCREF(Py_None);
289 _res = Py_None;
290 return _res;
291}
292
Guido van Rossume26c2631995-02-28 09:11:41 +0000293static PyObject *Evt_SystemClick(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000294 PyObject *_self;
295 PyObject *_args;
296{
297 PyObject *_res = NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000298 EventRecord theEvent;
299 WindowPtr theWindow;
300 if (!PyArg_ParseTuple(_args, "O&O&",
301 PyMac_GetEventRecord, &theEvent,
302 WinObj_Convert, &theWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +0000303 return NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000304 SystemClick(&theEvent,
305 theWindow);
306 Py_INCREF(Py_None);
307 _res = Py_None;
Guido van Rossum17448e21995-01-30 11:53:55 +0000308 return _res;
309}
310
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000311static PyObject *Evt_SystemTask(_self, _args)
312 PyObject *_self;
313 PyObject *_args;
314{
315 PyObject *_res = NULL;
316 if (!PyArg_ParseTuple(_args, ""))
317 return NULL;
318 SystemTask();
319 Py_INCREF(Py_None);
320 _res = Py_None;
321 return _res;
322}
323
324static PyObject *Evt_SystemEvent(_self, _args)
325 PyObject *_self;
326 PyObject *_args;
327{
328 PyObject *_res = NULL;
329 Boolean _rv;
330 EventRecord theEvent;
331 if (!PyArg_ParseTuple(_args, "O&",
332 PyMac_GetEventRecord, &theEvent))
333 return NULL;
334 _rv = SystemEvent(&theEvent);
335 _res = Py_BuildValue("b",
336 _rv);
337 return _res;
338}
339
Jack Jansen91b5bed1998-09-17 15:28:58 +0000340static PyObject *Evt_WaitNextEvent(_self, _args)
341 PyObject *_self;
342 PyObject *_args;
343{
344 PyObject *_res = NULL;
345
346 Boolean _rv;
347 EventMask eventMask;
348 EventRecord theEvent;
349 UInt32 sleep;
350 Handle mouseregion = (Handle)0;
351
352 if (!PyArg_ParseTuple(_args, "hl|O&",
353 &eventMask,
354 &sleep,
355 OptResObj_Convert, &mouseregion))
356 return NULL;
357 _rv = WaitNextEvent(eventMask,
358 &theEvent,
359 sleep,
360 (RgnHandle)mouseregion);
361 _res = Py_BuildValue("bO&",
362 _rv,
363 PyMac_BuildEventRecord, &theEvent);
364 return _res;
365
366}
367
Guido van Rossum17448e21995-01-30 11:53:55 +0000368static PyMethodDef Evt_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000369 {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
370 "() -> (Point mouseLoc)"},
371 {"Button", (PyCFunction)Evt_Button, 1,
372 "() -> (Boolean _rv)"},
373 {"StillDown", (PyCFunction)Evt_StillDown, 1,
374 "() -> (Boolean _rv)"},
375 {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
376 "() -> (Boolean _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000377 {"TickCount", (PyCFunction)Evt_TickCount, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000378 "() -> (UInt32 _rv)"},
Jack Jansen21f96871998-02-20 16:02:09 +0000379 {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
380 "() -> (UInt32 _rv)"},
381 {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
382 "() -> (KeyMap theKeys)"},
383 {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
384 "() -> (UInt32 _rv)"},
385 {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
386 "(EventMask value) -> None"},
387 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
388 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansen21f96871998-02-20 16:02:09 +0000389 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
390 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000391 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000392 "(EventKind eventNum, UInt32 eventMsg) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000393 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000394 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000395 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000396 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000397 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000398 "(EventMask whichMask, EventMask stopMask) -> None"},
Guido van Rossume26c2631995-02-28 09:11:41 +0000399 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
400 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000401 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
402 "() -> None"},
403 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
404 "(EventRecord theEvent) -> (Boolean _rv)"},
Jack Jansen91b5bed1998-09-17 15:28:58 +0000405 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
406 "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000407 {NULL, NULL, 0}
408};
409
410
411
412
413void initEvt()
414{
415 PyObject *m;
416 PyObject *d;
417
418
419
420
421 m = Py_InitModule("Evt", Evt_methods);
422 d = PyModule_GetDict(m);
423 Evt_Error = PyMac_GetOSErrException();
424 if (Evt_Error == NULL ||
425 PyDict_SetItemString(d, "Error", Evt_Error) != 0)
426 Py_FatalError("can't initialize Evt.Error");
427}
428
429/* ========================= End module Evt ========================= */
430