blob: b5bc57307521632d22f63da65567ed03190709b7 [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 Jansenb81cf9d1995-06-06 13:08:40 +000051static PyObject *Evt_GetCaretTime(_self, _args)
52 PyObject *_self;
53 PyObject *_args;
54{
55 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +000056 UInt32 _rv;
Jack Jansenb81cf9d1995-06-06 13:08:40 +000057 if (!PyArg_ParseTuple(_args, ""))
58 return NULL;
59 _rv = GetCaretTime();
60 _res = Py_BuildValue("l",
61 _rv);
62 return _res;
63}
64
65static PyObject *Evt_SetEventMask(_self, _args)
66 PyObject *_self;
67 PyObject *_args;
68{
69 PyObject *_res = NULL;
Jack Jansend40f3c61995-10-09 23:12:22 +000070 EventMask value;
Jack Jansenb81cf9d1995-06-06 13:08:40 +000071 if (!PyArg_ParseTuple(_args, "h",
72 &value))
73 return NULL;
74 SetEventMask(value);
75 Py_INCREF(Py_None);
76 _res = Py_None;
77 return _res;
78}
79
Jack Jansen7d0bc831995-06-09 20:56:31 +000080static PyObject *Evt_GetDblTime(_self, _args)
81 PyObject *_self;
82 PyObject *_args;
83{
84 PyObject *_res = NULL;
85 UInt32 _rv;
86 if (!PyArg_ParseTuple(_args, ""))
87 return NULL;
88 _rv = GetDblTime();
89 _res = Py_BuildValue("l",
90 _rv);
91 return _res;
92}
93
Guido van Rossum17448e21995-01-30 11:53:55 +000094static PyObject *Evt_GetNextEvent(_self, _args)
95 PyObject *_self;
96 PyObject *_args;
97{
98 PyObject *_res = NULL;
99 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000100 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000101 EventRecord theEvent;
102 if (!PyArg_ParseTuple(_args, "h",
103 &eventMask))
104 return NULL;
105 _rv = GetNextEvent(eventMask,
106 &theEvent);
107 _res = Py_BuildValue("bO&",
108 _rv,
109 PyMac_BuildEventRecord, &theEvent);
110 return _res;
111}
112
113static PyObject *Evt_WaitNextEvent(_self, _args)
114 PyObject *_self;
115 PyObject *_args;
116{
117 PyObject *_res = NULL;
118 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000119 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000120 EventRecord theEvent;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000121 UInt32 sleep;
Guido van Rossum17448e21995-01-30 11:53:55 +0000122 if (!PyArg_ParseTuple(_args, "hl",
123 &eventMask,
124 &sleep))
125 return NULL;
126 _rv = WaitNextEvent(eventMask,
127 &theEvent,
128 sleep,
129 (RgnHandle)0);
130 _res = Py_BuildValue("bO&",
131 _rv,
132 PyMac_BuildEventRecord, &theEvent);
133 return _res;
134}
135
136static PyObject *Evt_EventAvail(_self, _args)
137 PyObject *_self;
138 PyObject *_args;
139{
140 PyObject *_res = NULL;
141 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000142 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000143 EventRecord theEvent;
144 if (!PyArg_ParseTuple(_args, "h",
145 &eventMask))
146 return NULL;
147 _rv = EventAvail(eventMask,
148 &theEvent);
149 _res = Py_BuildValue("bO&",
150 _rv,
151 PyMac_BuildEventRecord, &theEvent);
152 return _res;
153}
154
155static PyObject *Evt_GetMouse(_self, _args)
156 PyObject *_self;
157 PyObject *_args;
158{
159 PyObject *_res = NULL;
160 Point mouseLoc;
161 if (!PyArg_ParseTuple(_args, ""))
162 return NULL;
163 GetMouse(&mouseLoc);
164 _res = Py_BuildValue("O&",
165 PyMac_BuildPoint, mouseLoc);
166 return _res;
167}
168
169static PyObject *Evt_Button(_self, _args)
170 PyObject *_self;
171 PyObject *_args;
172{
173 PyObject *_res = NULL;
174 Boolean _rv;
175 if (!PyArg_ParseTuple(_args, ""))
176 return NULL;
177 _rv = Button();
178 _res = Py_BuildValue("b",
179 _rv);
180 return _res;
181}
182
183static PyObject *Evt_StillDown(_self, _args)
184 PyObject *_self;
185 PyObject *_args;
186{
187 PyObject *_res = NULL;
188 Boolean _rv;
189 if (!PyArg_ParseTuple(_args, ""))
190 return NULL;
191 _rv = StillDown();
192 _res = Py_BuildValue("b",
193 _rv);
194 return _res;
195}
196
197static PyObject *Evt_WaitMouseUp(_self, _args)
198 PyObject *_self;
199 PyObject *_args;
200{
201 PyObject *_res = NULL;
202 Boolean _rv;
203 if (!PyArg_ParseTuple(_args, ""))
204 return NULL;
205 _rv = WaitMouseUp();
206 _res = Py_BuildValue("b",
207 _rv);
208 return _res;
209}
210
211static PyObject *Evt_GetKeys(_self, _args)
212 PyObject *_self;
213 PyObject *_args;
214{
215 PyObject *_res = NULL;
216 KeyMap theKeys__out__;
Guido van Rossum17448e21995-01-30 11:53:55 +0000217 if (!PyArg_ParseTuple(_args, ""))
218 return NULL;
219 GetKeys(theKeys__out__);
220 _res = Py_BuildValue("s#",
Guido van Rossume26c2631995-02-28 09:11:41 +0000221 (char *)&theKeys__out__, (int)sizeof(KeyMap));
Guido van Rossum17448e21995-01-30 11:53:55 +0000222 theKeys__error__: ;
223 return _res;
224}
225
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000226static PyObject *Evt_TickCount(_self, _args)
227 PyObject *_self;
228 PyObject *_args;
229{
230 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000231 UInt32 _rv;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000232 if (!PyArg_ParseTuple(_args, ""))
233 return NULL;
234 _rv = TickCount();
235 _res = Py_BuildValue("l",
236 _rv);
237 return _res;
238}
239
240static PyObject *Evt_PostEvent(_self, _args)
241 PyObject *_self;
242 PyObject *_args;
243{
244 PyObject *_res = NULL;
245 OSErr _err;
Jack Jansend40f3c61995-10-09 23:12:22 +0000246 EventKind eventNum;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000247 UInt32 eventMsg;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000248 if (!PyArg_ParseTuple(_args, "hl",
249 &eventNum,
250 &eventMsg))
251 return NULL;
252 _err = PostEvent(eventNum,
253 eventMsg);
254 if (_err != noErr) return PyMac_Error(_err);
255 Py_INCREF(Py_None);
256 _res = Py_None;
257 return _res;
258}
259
260static PyObject *Evt_OSEventAvail(_self, _args)
261 PyObject *_self;
262 PyObject *_args;
263{
264 PyObject *_res = NULL;
265 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000266 EventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000267 EventRecord theEvent;
268 if (!PyArg_ParseTuple(_args, "h",
269 &mask))
270 return NULL;
271 _rv = OSEventAvail(mask,
272 &theEvent);
273 _res = Py_BuildValue("bO&",
274 _rv,
275 PyMac_BuildEventRecord, &theEvent);
276 return _res;
277}
278
279static PyObject *Evt_GetOSEvent(_self, _args)
280 PyObject *_self;
281 PyObject *_args;
282{
283 PyObject *_res = NULL;
284 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000285 EventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000286 EventRecord theEvent;
287 if (!PyArg_ParseTuple(_args, "h",
288 &mask))
289 return NULL;
290 _rv = GetOSEvent(mask,
291 &theEvent);
292 _res = Py_BuildValue("bO&",
293 _rv,
294 PyMac_BuildEventRecord, &theEvent);
295 return _res;
296}
297
298static PyObject *Evt_FlushEvents(_self, _args)
299 PyObject *_self;
300 PyObject *_args;
301{
302 PyObject *_res = NULL;
Jack Jansend40f3c61995-10-09 23:12:22 +0000303 EventMask whichMask;
304 EventMask stopMask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000305 if (!PyArg_ParseTuple(_args, "hh",
306 &whichMask,
307 &stopMask))
308 return NULL;
309 FlushEvents(whichMask,
310 stopMask);
311 Py_INCREF(Py_None);
312 _res = Py_None;
313 return _res;
314}
315
Guido van Rossume26c2631995-02-28 09:11:41 +0000316static PyObject *Evt_SystemClick(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000317 PyObject *_self;
318 PyObject *_args;
319{
320 PyObject *_res = NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000321 EventRecord theEvent;
322 WindowPtr theWindow;
323 if (!PyArg_ParseTuple(_args, "O&O&",
324 PyMac_GetEventRecord, &theEvent,
325 WinObj_Convert, &theWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +0000326 return NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000327 SystemClick(&theEvent,
328 theWindow);
329 Py_INCREF(Py_None);
330 _res = Py_None;
Guido van Rossum17448e21995-01-30 11:53:55 +0000331 return _res;
332}
333
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000334static PyObject *Evt_SystemTask(_self, _args)
335 PyObject *_self;
336 PyObject *_args;
337{
338 PyObject *_res = NULL;
339 if (!PyArg_ParseTuple(_args, ""))
340 return NULL;
341 SystemTask();
342 Py_INCREF(Py_None);
343 _res = Py_None;
344 return _res;
345}
346
347static PyObject *Evt_SystemEvent(_self, _args)
348 PyObject *_self;
349 PyObject *_args;
350{
351 PyObject *_res = NULL;
352 Boolean _rv;
353 EventRecord theEvent;
354 if (!PyArg_ParseTuple(_args, "O&",
355 PyMac_GetEventRecord, &theEvent))
356 return NULL;
357 _rv = SystemEvent(&theEvent);
358 _res = Py_BuildValue("b",
359 _rv);
360 return _res;
361}
362
Guido van Rossum17448e21995-01-30 11:53:55 +0000363static PyMethodDef Evt_methods[] = {
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000364 {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000365 "() -> (UInt32 _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000366 {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000367 "(EventMask value) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000368 {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
369 "() -> (UInt32 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000370 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000371 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000372 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000373 "(EventMask eventMask, UInt32 sleep) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000374 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000375 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000376 {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
377 "() -> (Point mouseLoc)"},
378 {"Button", (PyCFunction)Evt_Button, 1,
379 "() -> (Boolean _rv)"},
380 {"StillDown", (PyCFunction)Evt_StillDown, 1,
381 "() -> (Boolean _rv)"},
382 {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
383 "() -> (Boolean _rv)"},
384 {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
385 "() -> (KeyMap theKeys)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000386 {"TickCount", (PyCFunction)Evt_TickCount, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000387 "() -> (UInt32 _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000388 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000389 "(EventKind eventNum, UInt32 eventMsg) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000390 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000391 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000392 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000393 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000394 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000395 "(EventMask whichMask, EventMask stopMask) -> None"},
Guido van Rossume26c2631995-02-28 09:11:41 +0000396 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
397 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000398 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
399 "() -> None"},
400 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
401 "(EventRecord theEvent) -> (Boolean _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000402 {NULL, NULL, 0}
403};
404
405
406
407
408void initEvt()
409{
410 PyObject *m;
411 PyObject *d;
412
413
414
415
416 m = Py_InitModule("Evt", Evt_methods);
417 d = PyModule_GetDict(m);
418 Evt_Error = PyMac_GetOSErrException();
419 if (Evt_Error == NULL ||
420 PyDict_SetItemString(d, "Error", Evt_Error) != 0)
421 Py_FatalError("can't initialize Evt.Error");
422}
423
424/* ========================= End module Evt ========================= */
425