blob: 139e5d803c42f96db101b5876404219d41d18e0f [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);
Jack Jansend4c26461995-08-17 14:35:56 +000017extern PyObject *ResObj_OptNew(Handle);
Guido van Rossum17448e21995-01-30 11:53:55 +000018extern int ResObj_Convert(PyObject *, Handle *);
19
20extern PyObject *WinObj_New(WindowPtr);
21extern int WinObj_Convert(PyObject *, WindowPtr *);
22
23extern PyObject *DlgObj_New(DialogPtr);
24extern int DlgObj_Convert(PyObject *, DialogPtr *);
25extern PyTypeObject Dialog_Type;
26#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
27
28extern PyObject *MenuObj_New(MenuHandle);
29extern int MenuObj_Convert(PyObject *, MenuHandle *);
30
31extern PyObject *CtlObj_New(ControlHandle);
32extern int CtlObj_Convert(PyObject *, ControlHandle *);
33
Guido van Rossume26c2631995-02-28 09:11:41 +000034extern PyObject *WinObj_WhichWindow(WindowPtr);
35
Guido van Rossum17448e21995-01-30 11:53:55 +000036#include <Events.h>
Guido van Rossume26c2631995-02-28 09:11:41 +000037#include <Desk.h>
Guido van Rossum17448e21995-01-30 11:53:55 +000038
39#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
40
41static PyObject *Evt_Error;
42
Jack Jansenb81cf9d1995-06-06 13:08:40 +000043static PyObject *Evt_GetCaretTime(_self, _args)
44 PyObject *_self;
45 PyObject *_args;
46{
47 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +000048 UInt32 _rv;
Jack Jansenb81cf9d1995-06-06 13:08:40 +000049 if (!PyArg_ParseTuple(_args, ""))
50 return NULL;
51 _rv = GetCaretTime();
52 _res = Py_BuildValue("l",
53 _rv);
54 return _res;
55}
56
57static PyObject *Evt_SetEventMask(_self, _args)
58 PyObject *_self;
59 PyObject *_args;
60{
61 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +000062 MacOSEventMask value;
Jack Jansenb81cf9d1995-06-06 13:08:40 +000063 if (!PyArg_ParseTuple(_args, "h",
64 &value))
65 return NULL;
66 SetEventMask(value);
67 Py_INCREF(Py_None);
68 _res = Py_None;
69 return _res;
70}
71
Jack Jansen7d0bc831995-06-09 20:56:31 +000072static PyObject *Evt_GetDblTime(_self, _args)
73 PyObject *_self;
74 PyObject *_args;
75{
76 PyObject *_res = NULL;
77 UInt32 _rv;
78 if (!PyArg_ParseTuple(_args, ""))
79 return NULL;
80 _rv = GetDblTime();
81 _res = Py_BuildValue("l",
82 _rv);
83 return _res;
84}
85
Guido van Rossum17448e21995-01-30 11:53:55 +000086static PyObject *Evt_GetNextEvent(_self, _args)
87 PyObject *_self;
88 PyObject *_args;
89{
90 PyObject *_res = NULL;
91 Boolean _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +000092 MacOSEventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +000093 EventRecord theEvent;
94 if (!PyArg_ParseTuple(_args, "h",
95 &eventMask))
96 return NULL;
97 _rv = GetNextEvent(eventMask,
98 &theEvent);
99 _res = Py_BuildValue("bO&",
100 _rv,
101 PyMac_BuildEventRecord, &theEvent);
102 return _res;
103}
104
105static PyObject *Evt_WaitNextEvent(_self, _args)
106 PyObject *_self;
107 PyObject *_args;
108{
109 PyObject *_res = NULL;
110 Boolean _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000111 MacOSEventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000112 EventRecord theEvent;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000113 UInt32 sleep;
Guido van Rossum17448e21995-01-30 11:53:55 +0000114 if (!PyArg_ParseTuple(_args, "hl",
115 &eventMask,
116 &sleep))
117 return NULL;
118 _rv = WaitNextEvent(eventMask,
119 &theEvent,
120 sleep,
121 (RgnHandle)0);
122 _res = Py_BuildValue("bO&",
123 _rv,
124 PyMac_BuildEventRecord, &theEvent);
125 return _res;
126}
127
128static PyObject *Evt_EventAvail(_self, _args)
129 PyObject *_self;
130 PyObject *_args;
131{
132 PyObject *_res = NULL;
133 Boolean _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000134 MacOSEventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000135 EventRecord theEvent;
136 if (!PyArg_ParseTuple(_args, "h",
137 &eventMask))
138 return NULL;
139 _rv = EventAvail(eventMask,
140 &theEvent);
141 _res = Py_BuildValue("bO&",
142 _rv,
143 PyMac_BuildEventRecord, &theEvent);
144 return _res;
145}
146
147static PyObject *Evt_GetMouse(_self, _args)
148 PyObject *_self;
149 PyObject *_args;
150{
151 PyObject *_res = NULL;
152 Point mouseLoc;
153 if (!PyArg_ParseTuple(_args, ""))
154 return NULL;
155 GetMouse(&mouseLoc);
156 _res = Py_BuildValue("O&",
157 PyMac_BuildPoint, mouseLoc);
158 return _res;
159}
160
161static PyObject *Evt_Button(_self, _args)
162 PyObject *_self;
163 PyObject *_args;
164{
165 PyObject *_res = NULL;
166 Boolean _rv;
167 if (!PyArg_ParseTuple(_args, ""))
168 return NULL;
169 _rv = Button();
170 _res = Py_BuildValue("b",
171 _rv);
172 return _res;
173}
174
175static PyObject *Evt_StillDown(_self, _args)
176 PyObject *_self;
177 PyObject *_args;
178{
179 PyObject *_res = NULL;
180 Boolean _rv;
181 if (!PyArg_ParseTuple(_args, ""))
182 return NULL;
183 _rv = StillDown();
184 _res = Py_BuildValue("b",
185 _rv);
186 return _res;
187}
188
189static PyObject *Evt_WaitMouseUp(_self, _args)
190 PyObject *_self;
191 PyObject *_args;
192{
193 PyObject *_res = NULL;
194 Boolean _rv;
195 if (!PyArg_ParseTuple(_args, ""))
196 return NULL;
197 _rv = WaitMouseUp();
198 _res = Py_BuildValue("b",
199 _rv);
200 return _res;
201}
202
203static PyObject *Evt_GetKeys(_self, _args)
204 PyObject *_self;
205 PyObject *_args;
206{
207 PyObject *_res = NULL;
208 KeyMap theKeys__out__;
Guido van Rossum17448e21995-01-30 11:53:55 +0000209 if (!PyArg_ParseTuple(_args, ""))
210 return NULL;
211 GetKeys(theKeys__out__);
212 _res = Py_BuildValue("s#",
Guido van Rossume26c2631995-02-28 09:11:41 +0000213 (char *)&theKeys__out__, (int)sizeof(KeyMap));
Guido van Rossum17448e21995-01-30 11:53:55 +0000214 theKeys__error__: ;
215 return _res;
216}
217
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000218static PyObject *Evt_TickCount(_self, _args)
219 PyObject *_self;
220 PyObject *_args;
221{
222 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000223 UInt32 _rv;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000224 if (!PyArg_ParseTuple(_args, ""))
225 return NULL;
226 _rv = TickCount();
227 _res = Py_BuildValue("l",
228 _rv);
229 return _res;
230}
231
232static PyObject *Evt_PostEvent(_self, _args)
233 PyObject *_self;
234 PyObject *_args;
235{
236 PyObject *_res = NULL;
237 OSErr _err;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000238 MacOSEventKind eventNum;
239 UInt32 eventMsg;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000240 if (!PyArg_ParseTuple(_args, "hl",
241 &eventNum,
242 &eventMsg))
243 return NULL;
244 _err = PostEvent(eventNum,
245 eventMsg);
246 if (_err != noErr) return PyMac_Error(_err);
247 Py_INCREF(Py_None);
248 _res = Py_None;
249 return _res;
250}
251
252static PyObject *Evt_OSEventAvail(_self, _args)
253 PyObject *_self;
254 PyObject *_args;
255{
256 PyObject *_res = NULL;
257 Boolean _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000258 MacOSEventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000259 EventRecord theEvent;
260 if (!PyArg_ParseTuple(_args, "h",
261 &mask))
262 return NULL;
263 _rv = OSEventAvail(mask,
264 &theEvent);
265 _res = Py_BuildValue("bO&",
266 _rv,
267 PyMac_BuildEventRecord, &theEvent);
268 return _res;
269}
270
271static PyObject *Evt_GetOSEvent(_self, _args)
272 PyObject *_self;
273 PyObject *_args;
274{
275 PyObject *_res = NULL;
276 Boolean _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000277 MacOSEventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000278 EventRecord theEvent;
279 if (!PyArg_ParseTuple(_args, "h",
280 &mask))
281 return NULL;
282 _rv = GetOSEvent(mask,
283 &theEvent);
284 _res = Py_BuildValue("bO&",
285 _rv,
286 PyMac_BuildEventRecord, &theEvent);
287 return _res;
288}
289
290static PyObject *Evt_FlushEvents(_self, _args)
291 PyObject *_self;
292 PyObject *_args;
293{
294 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000295 MacOSEventMask whichMask;
296 MacOSEventMask stopMask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000297 if (!PyArg_ParseTuple(_args, "hh",
298 &whichMask,
299 &stopMask))
300 return NULL;
301 FlushEvents(whichMask,
302 stopMask);
303 Py_INCREF(Py_None);
304 _res = Py_None;
305 return _res;
306}
307
Guido van Rossume26c2631995-02-28 09:11:41 +0000308static PyObject *Evt_SystemClick(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000309 PyObject *_self;
310 PyObject *_args;
311{
312 PyObject *_res = NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000313 EventRecord theEvent;
314 WindowPtr theWindow;
315 if (!PyArg_ParseTuple(_args, "O&O&",
316 PyMac_GetEventRecord, &theEvent,
317 WinObj_Convert, &theWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +0000318 return NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000319 SystemClick(&theEvent,
320 theWindow);
321 Py_INCREF(Py_None);
322 _res = Py_None;
Guido van Rossum17448e21995-01-30 11:53:55 +0000323 return _res;
324}
325
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000326static PyObject *Evt_SystemTask(_self, _args)
327 PyObject *_self;
328 PyObject *_args;
329{
330 PyObject *_res = NULL;
331 if (!PyArg_ParseTuple(_args, ""))
332 return NULL;
333 SystemTask();
334 Py_INCREF(Py_None);
335 _res = Py_None;
336 return _res;
337}
338
339static PyObject *Evt_SystemEvent(_self, _args)
340 PyObject *_self;
341 PyObject *_args;
342{
343 PyObject *_res = NULL;
344 Boolean _rv;
345 EventRecord theEvent;
346 if (!PyArg_ParseTuple(_args, "O&",
347 PyMac_GetEventRecord, &theEvent))
348 return NULL;
349 _rv = SystemEvent(&theEvent);
350 _res = Py_BuildValue("b",
351 _rv);
352 return _res;
353}
354
Guido van Rossum17448e21995-01-30 11:53:55 +0000355static PyMethodDef Evt_methods[] = {
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000356 {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000357 "() -> (UInt32 _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000358 {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000359 "(MacOSEventMask value) -> None"},
360 {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
361 "() -> (UInt32 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000362 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000363 "(MacOSEventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000364 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000365 "(MacOSEventMask eventMask, UInt32 sleep) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000366 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000367 "(MacOSEventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000368 {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
369 "() -> (Point mouseLoc)"},
370 {"Button", (PyCFunction)Evt_Button, 1,
371 "() -> (Boolean _rv)"},
372 {"StillDown", (PyCFunction)Evt_StillDown, 1,
373 "() -> (Boolean _rv)"},
374 {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
375 "() -> (Boolean _rv)"},
376 {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
377 "() -> (KeyMap theKeys)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000378 {"TickCount", (PyCFunction)Evt_TickCount, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000379 "() -> (UInt32 _rv)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000380 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000381 "(MacOSEventKind eventNum, UInt32 eventMsg) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000382 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000383 "(MacOSEventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000384 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000385 "(MacOSEventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000386 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000387 "(MacOSEventMask whichMask, MacOSEventMask stopMask) -> None"},
Guido van Rossume26c2631995-02-28 09:11:41 +0000388 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
389 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000390 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
391 "() -> None"},
392 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
393 "(EventRecord theEvent) -> (Boolean _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000394 {NULL, NULL, 0}
395};
396
397
398
399
400void initEvt()
401{
402 PyObject *m;
403 PyObject *d;
404
405
406
407
408 m = Py_InitModule("Evt", Evt_methods);
409 d = PyModule_GetDict(m);
410 Evt_Error = PyMac_GetOSErrException();
411 if (Evt_Error == NULL ||
412 PyDict_SetItemString(d, "Error", Evt_Error) != 0)
413 Py_FatalError("can't initialize Evt.Error");
414}
415
416/* ========================= End module Evt ========================= */
417