changes by Barry, e.g. font lock & email addresses
[python/dscho.git] / Mac / Modules / evt / Evtmodule.c
blob139e5d803c42f96db101b5876404219d41d18e0f
2 /* =========================== Module Evt =========================== */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
16 extern PyObject *ResObj_New(Handle);
17 extern PyObject *ResObj_OptNew(Handle);
18 extern int ResObj_Convert(PyObject *, Handle *);
20 extern PyObject *WinObj_New(WindowPtr);
21 extern int WinObj_Convert(PyObject *, WindowPtr *);
23 extern PyObject *DlgObj_New(DialogPtr);
24 extern int DlgObj_Convert(PyObject *, DialogPtr *);
25 extern PyTypeObject Dialog_Type;
26 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
28 extern PyObject *MenuObj_New(MenuHandle);
29 extern int MenuObj_Convert(PyObject *, MenuHandle *);
31 extern PyObject *CtlObj_New(ControlHandle);
32 extern int CtlObj_Convert(PyObject *, ControlHandle *);
34 extern PyObject *WinObj_WhichWindow(WindowPtr);
36 #include <Events.h>
37 #include <Desk.h>
39 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
41 static PyObject *Evt_Error;
43 static PyObject *Evt_GetCaretTime(_self, _args)
44 PyObject *_self;
45 PyObject *_args;
47 PyObject *_res = NULL;
48 UInt32 _rv;
49 if (!PyArg_ParseTuple(_args, ""))
50 return NULL;
51 _rv = GetCaretTime();
52 _res = Py_BuildValue("l",
53 _rv);
54 return _res;
57 static PyObject *Evt_SetEventMask(_self, _args)
58 PyObject *_self;
59 PyObject *_args;
61 PyObject *_res = NULL;
62 MacOSEventMask value;
63 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;
72 static PyObject *Evt_GetDblTime(_self, _args)
73 PyObject *_self;
74 PyObject *_args;
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;
86 static PyObject *Evt_GetNextEvent(_self, _args)
87 PyObject *_self;
88 PyObject *_args;
90 PyObject *_res = NULL;
91 Boolean _rv;
92 MacOSEventMask eventMask;
93 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;
105 static PyObject *Evt_WaitNextEvent(_self, _args)
106 PyObject *_self;
107 PyObject *_args;
109 PyObject *_res = NULL;
110 Boolean _rv;
111 MacOSEventMask eventMask;
112 EventRecord theEvent;
113 UInt32 sleep;
114 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;
128 static PyObject *Evt_EventAvail(_self, _args)
129 PyObject *_self;
130 PyObject *_args;
132 PyObject *_res = NULL;
133 Boolean _rv;
134 MacOSEventMask eventMask;
135 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;
147 static PyObject *Evt_GetMouse(_self, _args)
148 PyObject *_self;
149 PyObject *_args;
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;
161 static PyObject *Evt_Button(_self, _args)
162 PyObject *_self;
163 PyObject *_args;
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;
175 static PyObject *Evt_StillDown(_self, _args)
176 PyObject *_self;
177 PyObject *_args;
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;
189 static PyObject *Evt_WaitMouseUp(_self, _args)
190 PyObject *_self;
191 PyObject *_args;
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;
203 static PyObject *Evt_GetKeys(_self, _args)
204 PyObject *_self;
205 PyObject *_args;
207 PyObject *_res = NULL;
208 KeyMap theKeys__out__;
209 if (!PyArg_ParseTuple(_args, ""))
210 return NULL;
211 GetKeys(theKeys__out__);
212 _res = Py_BuildValue("s#",
213 (char *)&theKeys__out__, (int)sizeof(KeyMap));
214 theKeys__error__: ;
215 return _res;
218 static PyObject *Evt_TickCount(_self, _args)
219 PyObject *_self;
220 PyObject *_args;
222 PyObject *_res = NULL;
223 UInt32 _rv;
224 if (!PyArg_ParseTuple(_args, ""))
225 return NULL;
226 _rv = TickCount();
227 _res = Py_BuildValue("l",
228 _rv);
229 return _res;
232 static PyObject *Evt_PostEvent(_self, _args)
233 PyObject *_self;
234 PyObject *_args;
236 PyObject *_res = NULL;
237 OSErr _err;
238 MacOSEventKind eventNum;
239 UInt32 eventMsg;
240 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;
252 static PyObject *Evt_OSEventAvail(_self, _args)
253 PyObject *_self;
254 PyObject *_args;
256 PyObject *_res = NULL;
257 Boolean _rv;
258 MacOSEventMask mask;
259 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;
271 static PyObject *Evt_GetOSEvent(_self, _args)
272 PyObject *_self;
273 PyObject *_args;
275 PyObject *_res = NULL;
276 Boolean _rv;
277 MacOSEventMask mask;
278 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;
290 static PyObject *Evt_FlushEvents(_self, _args)
291 PyObject *_self;
292 PyObject *_args;
294 PyObject *_res = NULL;
295 MacOSEventMask whichMask;
296 MacOSEventMask stopMask;
297 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;
308 static PyObject *Evt_SystemClick(_self, _args)
309 PyObject *_self;
310 PyObject *_args;
312 PyObject *_res = NULL;
313 EventRecord theEvent;
314 WindowPtr theWindow;
315 if (!PyArg_ParseTuple(_args, "O&O&",
316 PyMac_GetEventRecord, &theEvent,
317 WinObj_Convert, &theWindow))
318 return NULL;
319 SystemClick(&theEvent,
320 theWindow);
321 Py_INCREF(Py_None);
322 _res = Py_None;
323 return _res;
326 static PyObject *Evt_SystemTask(_self, _args)
327 PyObject *_self;
328 PyObject *_args;
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;
339 static PyObject *Evt_SystemEvent(_self, _args)
340 PyObject *_self;
341 PyObject *_args;
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;
355 static PyMethodDef Evt_methods[] = {
356 {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
357 "() -> (UInt32 _rv)"},
358 {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
359 "(MacOSEventMask value) -> None"},
360 {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
361 "() -> (UInt32 _rv)"},
362 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
363 "(MacOSEventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
364 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
365 "(MacOSEventMask eventMask, UInt32 sleep) -> (Boolean _rv, EventRecord theEvent)"},
366 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
367 "(MacOSEventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
368 {"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)"},
378 {"TickCount", (PyCFunction)Evt_TickCount, 1,
379 "() -> (UInt32 _rv)"},
380 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
381 "(MacOSEventKind eventNum, UInt32 eventMsg) -> None"},
382 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
383 "(MacOSEventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
384 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
385 "(MacOSEventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
386 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
387 "(MacOSEventMask whichMask, MacOSEventMask stopMask) -> None"},
388 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
389 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
390 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
391 "() -> None"},
392 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
393 "(EventRecord theEvent) -> (Boolean _rv)"},
394 {NULL, NULL, 0}
400 void initEvt()
402 PyObject *m;
403 PyObject *d;
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");
416 /* ========================= End module Evt ========================= */