blob: 42d55b435d14ce88b07f4e1584bcbf250f5e4353 [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 *);
18
19extern PyObject *WinObj_New(WindowPtr);
20extern int WinObj_Convert(PyObject *, WindowPtr *);
21
22extern PyObject *DlgObj_New(DialogPtr);
23extern int DlgObj_Convert(PyObject *, DialogPtr *);
24extern PyTypeObject Dialog_Type;
25#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
26
27extern PyObject *MenuObj_New(MenuHandle);
28extern int MenuObj_Convert(PyObject *, MenuHandle *);
29
30extern PyObject *CtlObj_New(ControlHandle);
31extern int CtlObj_Convert(PyObject *, ControlHandle *);
32
Guido van Rossume26c2631995-02-28 09:11:41 +000033extern PyObject *WinObj_WhichWindow(WindowPtr);
34
Guido van Rossum17448e21995-01-30 11:53:55 +000035#include <Events.h>
Guido van Rossume26c2631995-02-28 09:11:41 +000036#include <Desk.h>
Guido van Rossum17448e21995-01-30 11:53:55 +000037
38#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
39
40static PyObject *Evt_Error;
41
42static PyObject *Evt_GetNextEvent(_self, _args)
43 PyObject *_self;
44 PyObject *_args;
45{
46 PyObject *_res = NULL;
47 Boolean _rv;
48 short eventMask;
49 EventRecord theEvent;
50 if (!PyArg_ParseTuple(_args, "h",
51 &eventMask))
52 return NULL;
53 _rv = GetNextEvent(eventMask,
54 &theEvent);
55 _res = Py_BuildValue("bO&",
56 _rv,
57 PyMac_BuildEventRecord, &theEvent);
58 return _res;
59}
60
61static PyObject *Evt_WaitNextEvent(_self, _args)
62 PyObject *_self;
63 PyObject *_args;
64{
65 PyObject *_res = NULL;
66 Boolean _rv;
67 short eventMask;
68 EventRecord theEvent;
69 unsigned long sleep;
70 if (!PyArg_ParseTuple(_args, "hl",
71 &eventMask,
72 &sleep))
73 return NULL;
74 _rv = WaitNextEvent(eventMask,
75 &theEvent,
76 sleep,
77 (RgnHandle)0);
78 _res = Py_BuildValue("bO&",
79 _rv,
80 PyMac_BuildEventRecord, &theEvent);
81 return _res;
82}
83
84static PyObject *Evt_EventAvail(_self, _args)
85 PyObject *_self;
86 PyObject *_args;
87{
88 PyObject *_res = NULL;
89 Boolean _rv;
90 short eventMask;
91 EventRecord theEvent;
92 if (!PyArg_ParseTuple(_args, "h",
93 &eventMask))
94 return NULL;
95 _rv = EventAvail(eventMask,
96 &theEvent);
97 _res = Py_BuildValue("bO&",
98 _rv,
99 PyMac_BuildEventRecord, &theEvent);
100 return _res;
101}
102
103static PyObject *Evt_GetMouse(_self, _args)
104 PyObject *_self;
105 PyObject *_args;
106{
107 PyObject *_res = NULL;
108 Point mouseLoc;
109 if (!PyArg_ParseTuple(_args, ""))
110 return NULL;
111 GetMouse(&mouseLoc);
112 _res = Py_BuildValue("O&",
113 PyMac_BuildPoint, mouseLoc);
114 return _res;
115}
116
117static PyObject *Evt_Button(_self, _args)
118 PyObject *_self;
119 PyObject *_args;
120{
121 PyObject *_res = NULL;
122 Boolean _rv;
123 if (!PyArg_ParseTuple(_args, ""))
124 return NULL;
125 _rv = Button();
126 _res = Py_BuildValue("b",
127 _rv);
128 return _res;
129}
130
131static PyObject *Evt_StillDown(_self, _args)
132 PyObject *_self;
133 PyObject *_args;
134{
135 PyObject *_res = NULL;
136 Boolean _rv;
137 if (!PyArg_ParseTuple(_args, ""))
138 return NULL;
139 _rv = StillDown();
140 _res = Py_BuildValue("b",
141 _rv);
142 return _res;
143}
144
145static PyObject *Evt_WaitMouseUp(_self, _args)
146 PyObject *_self;
147 PyObject *_args;
148{
149 PyObject *_res = NULL;
150 Boolean _rv;
151 if (!PyArg_ParseTuple(_args, ""))
152 return NULL;
153 _rv = WaitMouseUp();
154 _res = Py_BuildValue("b",
155 _rv);
156 return _res;
157}
158
159static PyObject *Evt_GetKeys(_self, _args)
160 PyObject *_self;
161 PyObject *_args;
162{
163 PyObject *_res = NULL;
164 KeyMap theKeys__out__;
Guido van Rossum17448e21995-01-30 11:53:55 +0000165 if (!PyArg_ParseTuple(_args, ""))
166 return NULL;
167 GetKeys(theKeys__out__);
168 _res = Py_BuildValue("s#",
Guido van Rossume26c2631995-02-28 09:11:41 +0000169 (char *)&theKeys__out__, (int)sizeof(KeyMap));
Guido van Rossum17448e21995-01-30 11:53:55 +0000170 theKeys__error__: ;
171 return _res;
172}
173
Guido van Rossume26c2631995-02-28 09:11:41 +0000174static PyObject *Evt_SystemClick(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000175 PyObject *_self;
176 PyObject *_args;
177{
178 PyObject *_res = NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000179 EventRecord theEvent;
180 WindowPtr theWindow;
181 if (!PyArg_ParseTuple(_args, "O&O&",
182 PyMac_GetEventRecord, &theEvent,
183 WinObj_Convert, &theWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +0000184 return NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000185 SystemClick(&theEvent,
186 theWindow);
187 Py_INCREF(Py_None);
188 _res = Py_None;
Guido van Rossum17448e21995-01-30 11:53:55 +0000189 return _res;
190}
191
192static PyMethodDef Evt_methods[] = {
193 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
194 "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"},
195 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
196 "(short eventMask, unsigned long sleep) -> (Boolean _rv, EventRecord theEvent)"},
197 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
198 "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"},
199 {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
200 "() -> (Point mouseLoc)"},
201 {"Button", (PyCFunction)Evt_Button, 1,
202 "() -> (Boolean _rv)"},
203 {"StillDown", (PyCFunction)Evt_StillDown, 1,
204 "() -> (Boolean _rv)"},
205 {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
206 "() -> (Boolean _rv)"},
207 {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
208 "() -> (KeyMap theKeys)"},
Guido van Rossume26c2631995-02-28 09:11:41 +0000209 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
210 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000211 {NULL, NULL, 0}
212};
213
214
215
216
217void initEvt()
218{
219 PyObject *m;
220 PyObject *d;
221
222
223
224
225 m = Py_InitModule("Evt", Evt_methods);
226 d = PyModule_GetDict(m);
227 Evt_Error = PyMac_GetOSErrException();
228 if (Evt_Error == NULL ||
229 PyDict_SetItemString(d, "Error", Evt_Error) != 0)
230 Py_FatalError("can't initialize Evt.Error");
231}
232
233/* ========================= End module Evt ========================= */
234
Guido van Rossume26c2631995-02-28 09:11:41 +0000235