blob: 9078e9f5f97c5c73f89d1080c08d6532db9a78c2 [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>
Guido van Rossume26c2631995-02-28 09:11:41 +000046#include <Desk.h>
Guido van Rossum17448e21995-01-30 11:53:55 +000047
48#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
49
50static PyObject *Evt_Error;
51
Jack Jansenb81cf9d1995-06-06 13:08:40 +000052static PyObject *Evt_GetCaretTime(_self, _args)
53 PyObject *_self;
54 PyObject *_args;
55{
56 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +000057 UInt32 _rv;
Jack Jansenb81cf9d1995-06-06 13:08:40 +000058 if (!PyArg_ParseTuple(_args, ""))
59 return NULL;
60 _rv = GetCaretTime();
61 _res = Py_BuildValue("l",
62 _rv);
63 return _res;
64}
65
66static PyObject *Evt_SetEventMask(_self, _args)
67 PyObject *_self;
68 PyObject *_args;
69{
70 PyObject *_res = NULL;
Jack Jansend40f3c61995-10-09 23:12:22 +000071 EventMask value;
Jack Jansenb81cf9d1995-06-06 13:08:40 +000072 if (!PyArg_ParseTuple(_args, "h",
73 &value))
74 return NULL;
75 SetEventMask(value);
76 Py_INCREF(Py_None);
77 _res = Py_None;
78 return _res;
79}
80
Jack Jansen7d0bc831995-06-09 20:56:31 +000081static PyObject *Evt_GetDblTime(_self, _args)
82 PyObject *_self;
83 PyObject *_args;
84{
85 PyObject *_res = NULL;
86 UInt32 _rv;
87 if (!PyArg_ParseTuple(_args, ""))
88 return NULL;
89 _rv = GetDblTime();
90 _res = Py_BuildValue("l",
91 _rv);
92 return _res;
93}
94
Guido van Rossum17448e21995-01-30 11:53:55 +000095static PyObject *Evt_GetNextEvent(_self, _args)
96 PyObject *_self;
97 PyObject *_args;
98{
99 PyObject *_res = NULL;
100 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000101 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000102 EventRecord theEvent;
103 if (!PyArg_ParseTuple(_args, "h",
104 &eventMask))
105 return NULL;
106 _rv = GetNextEvent(eventMask,
107 &theEvent);
108 _res = Py_BuildValue("bO&",
109 _rv,
110 PyMac_BuildEventRecord, &theEvent);
111 return _res;
112}
113
114static PyObject *Evt_WaitNextEvent(_self, _args)
115 PyObject *_self;
116 PyObject *_args;
117{
118 PyObject *_res = NULL;
119 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000120 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000121 EventRecord theEvent;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000122 UInt32 sleep;
Guido van Rossum17448e21995-01-30 11:53:55 +0000123 if (!PyArg_ParseTuple(_args, "hl",
124 &eventMask,
125 &sleep))
126 return NULL;
127 _rv = WaitNextEvent(eventMask,
128 &theEvent,
129 sleep,
130 (RgnHandle)0);
131 _res = Py_BuildValue("bO&",
132 _rv,
133 PyMac_BuildEventRecord, &theEvent);
134 return _res;
135}
136
137static PyObject *Evt_EventAvail(_self, _args)
138 PyObject *_self;
139 PyObject *_args;
140{
141 PyObject *_res = NULL;
142 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000143 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000144 EventRecord theEvent;
145 if (!PyArg_ParseTuple(_args, "h",
146 &eventMask))
147 return NULL;
148 _rv = EventAvail(eventMask,
149 &theEvent);
150 _res = Py_BuildValue("bO&",
151 _rv,
152 PyMac_BuildEventRecord, &theEvent);
153 return _res;
154}
155
156static PyObject *Evt_GetMouse(_self, _args)
157 PyObject *_self;
158 PyObject *_args;
159{
160 PyObject *_res = NULL;
161 Point mouseLoc;
162 if (!PyArg_ParseTuple(_args, ""))
163 return NULL;
164 GetMouse(&mouseLoc);
165 _res = Py_BuildValue("O&",
166 PyMac_BuildPoint, mouseLoc);
167 return _res;
168}
169
170static PyObject *Evt_Button(_self, _args)
171 PyObject *_self;
172 PyObject *_args;
173{
174 PyObject *_res = NULL;
175 Boolean _rv;
176 if (!PyArg_ParseTuple(_args, ""))
177 return NULL;
178 _rv = Button();
179 _res = Py_BuildValue("b",
180 _rv);
181 return _res;
182}
183
184static PyObject *Evt_StillDown(_self, _args)
185 PyObject *_self;
186 PyObject *_args;
187{
188 PyObject *_res = NULL;
189 Boolean _rv;
190 if (!PyArg_ParseTuple(_args, ""))
191 return NULL;
192 _rv = StillDown();
193 _res = Py_BuildValue("b",
194 _rv);
195 return _res;
196}
197
198static PyObject *Evt_WaitMouseUp(_self, _args)
199 PyObject *_self;
200 PyObject *_args;
201{
202 PyObject *_res = NULL;
203 Boolean _rv;
204 if (!PyArg_ParseTuple(_args, ""))
205 return NULL;
206 _rv = WaitMouseUp();
207 _res = Py_BuildValue("b",
208 _rv);
209 return _res;
210}
211
212static PyObject *Evt_GetKeys(_self, _args)
213 PyObject *_self;
214 PyObject *_args;
215{
216 PyObject *_res = NULL;
217 KeyMap theKeys__out__;
Guido van Rossum17448e21995-01-30 11:53:55 +0000218 if (!PyArg_ParseTuple(_args, ""))
219 return NULL;
220 GetKeys(theKeys__out__);
221 _res = Py_BuildValue("s#",
Guido van Rossume26c2631995-02-28 09:11:41 +0000222 (char *)&theKeys__out__, (int)sizeof(KeyMap));
Guido van Rossum17448e21995-01-30 11:53:55 +0000223 theKeys__error__: ;
224 return _res;
225}
226
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000227static PyObject *Evt_TickCount(_self, _args)
228 PyObject *_self;
229 PyObject *_args;
230{
231 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000232 UInt32 _rv;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000233 if (!PyArg_ParseTuple(_args, ""))
234 return NULL;
235 _rv = TickCount();
236 _res = Py_BuildValue("l",
237 _rv);
238 return _res;
239}
240
241static PyObject *Evt_PostEvent(_self, _args)
242 PyObject *_self;
243 PyObject *_args;
244{
245 PyObject *_res = NULL;
246 OSErr _err;
Jack Jansend40f3c61995-10-09 23:12:22 +0000247 EventKind eventNum;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000248 UInt32 eventMsg;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000249 if (!PyArg_ParseTuple(_args, "hl",
250 &eventNum,
251 &eventMsg))
252 return NULL;
253 _err = PostEvent(eventNum,
254 eventMsg);
255 if (_err != noErr) return PyMac_Error(_err);
256 Py_INCREF(Py_None);
257 _res = Py_None;
258 return _res;
259}
260
261static PyObject *Evt_OSEventAvail(_self, _args)
262 PyObject *_self;
263 PyObject *_args;
264{
265 PyObject *_res = NULL;
266 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000267 EventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000268 EventRecord theEvent;
269 if (!PyArg_ParseTuple(_args, "h",
270 &mask))
271 return NULL;
272 _rv = OSEventAvail(mask,
273 &theEvent);
274 _res = Py_BuildValue("bO&",
275 _rv,
276 PyMac_BuildEventRecord, &theEvent);
277 return _res;
278}
279
280static PyObject *Evt_GetOSEvent(_self, _args)
281 PyObject *_self;
282 PyObject *_args;
283{
284 PyObject *_res = NULL;
285 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000286 EventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000287 EventRecord theEvent;
288 if (!PyArg_ParseTuple(_args, "h",
289 &mask))
290 return NULL;
291 _rv = GetOSEvent(mask,
292 &theEvent);
293 _res = Py_BuildValue("bO&",
294 _rv,
295 PyMac_BuildEventRecord, &theEvent);
296 return _res;
297}
298
299static PyObject *Evt_FlushEvents(_self, _args)
300 PyObject *_self;
301 PyObject *_args;
302{
303 PyObject *_res = NULL;
Jack Jansend40f3c61995-10-09 23:12:22 +0000304 EventMask whichMask;
305 EventMask stopMask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000306 if (!PyArg_ParseTuple(_args, "hh",
307 &whichMask,
308 &stopMask))
309 return NULL;
310 FlushEvents(whichMask,
311 stopMask);
312 Py_INCREF(Py_None);
313 _res = Py_None;
314 return _res;
315}
316
Guido van Rossume26c2631995-02-28 09:11:41 +0000317static PyObject *Evt_SystemClick(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000318 PyObject *_self;
319 PyObject *_args;
320{
321 PyObject *_res = NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000322 EventRecord theEvent;
323 WindowPtr theWindow;
324 if (!PyArg_ParseTuple(_args, "O&O&",
325 PyMac_GetEventRecord, &theEvent,
326 WinObj_Convert, &theWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +0000327 return NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000328 SystemClick(&theEvent,
329 theWindow);
330 Py_INCREF(Py_None);
331 _res = Py_None;
Guido van Rossum17448e21995-01-30 11:53:55 +0000332 return _res;
333}
334
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000335static PyObject *Evt_SystemTask(_self, _args)
336 PyObject *_self;
337 PyObject *_args;
338{
339 PyObject *_res = NULL;
340 if (!PyArg_ParseTuple(_args, ""))
341 return NULL;
342 SystemTask();
343 Py_INCREF(Py_None);
344 _res = Py_None;
345 return _res;
346}
347
348static PyObject *Evt_SystemEvent(_self, _args)
349 PyObject *_self;
350 PyObject *_args;
351{
352 PyObject *_res = NULL;
353 Boolean _rv;
354 EventRecord theEvent;
355 if (!PyArg_ParseTuple(_args, "O&",
356 PyMac_GetEventRecord, &theEvent))
357 return NULL;
358 _rv = SystemEvent(&theEvent);
359 _res = Py_BuildValue("b",
360 _rv);
361 return _res;
362}
363
Guido van Rossum17448e21995-01-30 11:53:55 +0000364static PyMethodDef Evt_methods[] = {
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000365 {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000366 "() -> (UInt32 _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000367 {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000368 "(EventMask value) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000369 {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
370 "() -> (UInt32 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000371 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000372 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000373 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000374 "(EventMask eventMask, UInt32 sleep) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000375 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000376 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000377 {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
378 "() -> (Point mouseLoc)"},
379 {"Button", (PyCFunction)Evt_Button, 1,
380 "() -> (Boolean _rv)"},
381 {"StillDown", (PyCFunction)Evt_StillDown, 1,
382 "() -> (Boolean _rv)"},
383 {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
384 "() -> (Boolean _rv)"},
385 {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
386 "() -> (KeyMap theKeys)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000387 {"TickCount", (PyCFunction)Evt_TickCount, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000388 "() -> (UInt32 _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000389 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000390 "(EventKind eventNum, UInt32 eventMsg) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000391 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000392 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000393 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000394 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000395 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000396 "(EventMask whichMask, EventMask stopMask) -> None"},
Guido van Rossume26c2631995-02-28 09:11:41 +0000397 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
398 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000399 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
400 "() -> None"},
401 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
402 "(EventRecord theEvent) -> (Boolean _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000403 {NULL, NULL, 0}
404};
405
406
407
408
409void initEvt()
410{
411 PyObject *m;
412 PyObject *d;
413
414
415
416
417 m = Py_InitModule("Evt", Evt_methods);
418 d = PyModule_GetDict(m);
419 Evt_Error = PyMac_GetOSErrException();
420 if (Evt_Error == NULL ||
421 PyDict_SetItemString(d, "Error", Evt_Error) != 0)
422 Py_FatalError("can't initialize Evt.Error");
423}
424
425/* ========================= End module Evt ========================= */
426