Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 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 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
| 18 | |
| 19 | extern PyObject *WinObj_New(WindowPtr); |
| 20 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 21 | |
| 22 | extern PyObject *DlgObj_New(DialogPtr); |
| 23 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 24 | extern PyTypeObject Dialog_Type; |
| 25 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 26 | |
| 27 | extern PyObject *MenuObj_New(MenuHandle); |
| 28 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 29 | |
| 30 | extern PyObject *CtlObj_New(ControlHandle); |
| 31 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 32 | |
Guido van Rossum | e26c263 | 1995-02-28 09:11:41 +0000 | [diff] [blame] | 33 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 34 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 35 | #include <Events.h> |
Guido van Rossum | e26c263 | 1995-02-28 09:11:41 +0000 | [diff] [blame] | 36 | #include <Desk.h> |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 37 | |
| 38 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 39 | |
| 40 | static PyObject *Evt_Error; |
| 41 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 42 | static PyObject *Evt_GetDblTime(_self, _args) |
| 43 | PyObject *_self; |
| 44 | PyObject *_args; |
| 45 | { |
| 46 | PyObject *_res = NULL; |
| 47 | long _rv; |
| 48 | if (!PyArg_ParseTuple(_args, "")) |
| 49 | return NULL; |
| 50 | _rv = GetDblTime(); |
| 51 | _res = Py_BuildValue("l", |
| 52 | _rv); |
| 53 | return _res; |
| 54 | } |
| 55 | |
| 56 | static PyObject *Evt_GetCaretTime(_self, _args) |
| 57 | PyObject *_self; |
| 58 | PyObject *_args; |
| 59 | { |
| 60 | PyObject *_res = NULL; |
| 61 | long _rv; |
| 62 | if (!PyArg_ParseTuple(_args, "")) |
| 63 | return NULL; |
| 64 | _rv = GetCaretTime(); |
| 65 | _res = Py_BuildValue("l", |
| 66 | _rv); |
| 67 | return _res; |
| 68 | } |
| 69 | |
| 70 | static PyObject *Evt_SetEventMask(_self, _args) |
| 71 | PyObject *_self; |
| 72 | PyObject *_args; |
| 73 | { |
| 74 | PyObject *_res = NULL; |
| 75 | short value; |
| 76 | if (!PyArg_ParseTuple(_args, "h", |
| 77 | &value)) |
| 78 | return NULL; |
| 79 | SetEventMask(value); |
| 80 | Py_INCREF(Py_None); |
| 81 | _res = Py_None; |
| 82 | return _res; |
| 83 | } |
| 84 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 85 | static PyObject *Evt_GetNextEvent(_self, _args) |
| 86 | PyObject *_self; |
| 87 | PyObject *_args; |
| 88 | { |
| 89 | PyObject *_res = NULL; |
| 90 | Boolean _rv; |
| 91 | short eventMask; |
| 92 | EventRecord theEvent; |
| 93 | if (!PyArg_ParseTuple(_args, "h", |
| 94 | &eventMask)) |
| 95 | return NULL; |
| 96 | _rv = GetNextEvent(eventMask, |
| 97 | &theEvent); |
| 98 | _res = Py_BuildValue("bO&", |
| 99 | _rv, |
| 100 | PyMac_BuildEventRecord, &theEvent); |
| 101 | return _res; |
| 102 | } |
| 103 | |
| 104 | static PyObject *Evt_WaitNextEvent(_self, _args) |
| 105 | PyObject *_self; |
| 106 | PyObject *_args; |
| 107 | { |
| 108 | PyObject *_res = NULL; |
| 109 | Boolean _rv; |
| 110 | short eventMask; |
| 111 | EventRecord theEvent; |
| 112 | unsigned long sleep; |
| 113 | if (!PyArg_ParseTuple(_args, "hl", |
| 114 | &eventMask, |
| 115 | &sleep)) |
| 116 | return NULL; |
| 117 | _rv = WaitNextEvent(eventMask, |
| 118 | &theEvent, |
| 119 | sleep, |
| 120 | (RgnHandle)0); |
| 121 | _res = Py_BuildValue("bO&", |
| 122 | _rv, |
| 123 | PyMac_BuildEventRecord, &theEvent); |
| 124 | return _res; |
| 125 | } |
| 126 | |
| 127 | static PyObject *Evt_EventAvail(_self, _args) |
| 128 | PyObject *_self; |
| 129 | PyObject *_args; |
| 130 | { |
| 131 | PyObject *_res = NULL; |
| 132 | Boolean _rv; |
| 133 | short eventMask; |
| 134 | EventRecord theEvent; |
| 135 | if (!PyArg_ParseTuple(_args, "h", |
| 136 | &eventMask)) |
| 137 | return NULL; |
| 138 | _rv = EventAvail(eventMask, |
| 139 | &theEvent); |
| 140 | _res = Py_BuildValue("bO&", |
| 141 | _rv, |
| 142 | PyMac_BuildEventRecord, &theEvent); |
| 143 | return _res; |
| 144 | } |
| 145 | |
| 146 | static PyObject *Evt_GetMouse(_self, _args) |
| 147 | PyObject *_self; |
| 148 | PyObject *_args; |
| 149 | { |
| 150 | PyObject *_res = NULL; |
| 151 | Point mouseLoc; |
| 152 | if (!PyArg_ParseTuple(_args, "")) |
| 153 | return NULL; |
| 154 | GetMouse(&mouseLoc); |
| 155 | _res = Py_BuildValue("O&", |
| 156 | PyMac_BuildPoint, mouseLoc); |
| 157 | return _res; |
| 158 | } |
| 159 | |
| 160 | static PyObject *Evt_Button(_self, _args) |
| 161 | PyObject *_self; |
| 162 | PyObject *_args; |
| 163 | { |
| 164 | PyObject *_res = NULL; |
| 165 | Boolean _rv; |
| 166 | if (!PyArg_ParseTuple(_args, "")) |
| 167 | return NULL; |
| 168 | _rv = Button(); |
| 169 | _res = Py_BuildValue("b", |
| 170 | _rv); |
| 171 | return _res; |
| 172 | } |
| 173 | |
| 174 | static PyObject *Evt_StillDown(_self, _args) |
| 175 | PyObject *_self; |
| 176 | PyObject *_args; |
| 177 | { |
| 178 | PyObject *_res = NULL; |
| 179 | Boolean _rv; |
| 180 | if (!PyArg_ParseTuple(_args, "")) |
| 181 | return NULL; |
| 182 | _rv = StillDown(); |
| 183 | _res = Py_BuildValue("b", |
| 184 | _rv); |
| 185 | return _res; |
| 186 | } |
| 187 | |
| 188 | static PyObject *Evt_WaitMouseUp(_self, _args) |
| 189 | PyObject *_self; |
| 190 | PyObject *_args; |
| 191 | { |
| 192 | PyObject *_res = NULL; |
| 193 | Boolean _rv; |
| 194 | if (!PyArg_ParseTuple(_args, "")) |
| 195 | return NULL; |
| 196 | _rv = WaitMouseUp(); |
| 197 | _res = Py_BuildValue("b", |
| 198 | _rv); |
| 199 | return _res; |
| 200 | } |
| 201 | |
| 202 | static PyObject *Evt_GetKeys(_self, _args) |
| 203 | PyObject *_self; |
| 204 | PyObject *_args; |
| 205 | { |
| 206 | PyObject *_res = NULL; |
| 207 | KeyMap theKeys__out__; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 208 | if (!PyArg_ParseTuple(_args, "")) |
| 209 | return NULL; |
| 210 | GetKeys(theKeys__out__); |
| 211 | _res = Py_BuildValue("s#", |
Guido van Rossum | e26c263 | 1995-02-28 09:11:41 +0000 | [diff] [blame] | 212 | (char *)&theKeys__out__, (int)sizeof(KeyMap)); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 213 | theKeys__error__: ; |
| 214 | return _res; |
| 215 | } |
| 216 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 217 | static PyObject *Evt_TickCount(_self, _args) |
| 218 | PyObject *_self; |
| 219 | PyObject *_args; |
| 220 | { |
| 221 | PyObject *_res = NULL; |
| 222 | unsigned long _rv; |
| 223 | if (!PyArg_ParseTuple(_args, "")) |
| 224 | return NULL; |
| 225 | _rv = TickCount(); |
| 226 | _res = Py_BuildValue("l", |
| 227 | _rv); |
| 228 | return _res; |
| 229 | } |
| 230 | |
| 231 | static PyObject *Evt_PostEvent(_self, _args) |
| 232 | PyObject *_self; |
| 233 | PyObject *_args; |
| 234 | { |
| 235 | PyObject *_res = NULL; |
| 236 | OSErr _err; |
| 237 | short eventNum; |
| 238 | long eventMsg; |
| 239 | if (!PyArg_ParseTuple(_args, "hl", |
| 240 | &eventNum, |
| 241 | &eventMsg)) |
| 242 | return NULL; |
| 243 | _err = PostEvent(eventNum, |
| 244 | eventMsg); |
| 245 | if (_err != noErr) return PyMac_Error(_err); |
| 246 | Py_INCREF(Py_None); |
| 247 | _res = Py_None; |
| 248 | return _res; |
| 249 | } |
| 250 | |
| 251 | static PyObject *Evt_OSEventAvail(_self, _args) |
| 252 | PyObject *_self; |
| 253 | PyObject *_args; |
| 254 | { |
| 255 | PyObject *_res = NULL; |
| 256 | Boolean _rv; |
| 257 | short mask; |
| 258 | EventRecord theEvent; |
| 259 | if (!PyArg_ParseTuple(_args, "h", |
| 260 | &mask)) |
| 261 | return NULL; |
| 262 | _rv = OSEventAvail(mask, |
| 263 | &theEvent); |
| 264 | _res = Py_BuildValue("bO&", |
| 265 | _rv, |
| 266 | PyMac_BuildEventRecord, &theEvent); |
| 267 | return _res; |
| 268 | } |
| 269 | |
| 270 | static PyObject *Evt_GetOSEvent(_self, _args) |
| 271 | PyObject *_self; |
| 272 | PyObject *_args; |
| 273 | { |
| 274 | PyObject *_res = NULL; |
| 275 | Boolean _rv; |
| 276 | short mask; |
| 277 | EventRecord theEvent; |
| 278 | if (!PyArg_ParseTuple(_args, "h", |
| 279 | &mask)) |
| 280 | return NULL; |
| 281 | _rv = GetOSEvent(mask, |
| 282 | &theEvent); |
| 283 | _res = Py_BuildValue("bO&", |
| 284 | _rv, |
| 285 | PyMac_BuildEventRecord, &theEvent); |
| 286 | return _res; |
| 287 | } |
| 288 | |
| 289 | static PyObject *Evt_FlushEvents(_self, _args) |
| 290 | PyObject *_self; |
| 291 | PyObject *_args; |
| 292 | { |
| 293 | PyObject *_res = NULL; |
| 294 | short whichMask; |
| 295 | short stopMask; |
| 296 | if (!PyArg_ParseTuple(_args, "hh", |
| 297 | &whichMask, |
| 298 | &stopMask)) |
| 299 | return NULL; |
| 300 | FlushEvents(whichMask, |
| 301 | stopMask); |
| 302 | Py_INCREF(Py_None); |
| 303 | _res = Py_None; |
| 304 | return _res; |
| 305 | } |
| 306 | |
Guido van Rossum | e26c263 | 1995-02-28 09:11:41 +0000 | [diff] [blame] | 307 | static PyObject *Evt_SystemClick(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 308 | PyObject *_self; |
| 309 | PyObject *_args; |
| 310 | { |
| 311 | PyObject *_res = NULL; |
Guido van Rossum | e26c263 | 1995-02-28 09:11:41 +0000 | [diff] [blame] | 312 | EventRecord theEvent; |
| 313 | WindowPtr theWindow; |
| 314 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 315 | PyMac_GetEventRecord, &theEvent, |
| 316 | WinObj_Convert, &theWindow)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 317 | return NULL; |
Guido van Rossum | e26c263 | 1995-02-28 09:11:41 +0000 | [diff] [blame] | 318 | SystemClick(&theEvent, |
| 319 | theWindow); |
| 320 | Py_INCREF(Py_None); |
| 321 | _res = Py_None; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 322 | return _res; |
| 323 | } |
| 324 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 325 | static PyObject *Evt_SystemTask(_self, _args) |
| 326 | PyObject *_self; |
| 327 | PyObject *_args; |
| 328 | { |
| 329 | PyObject *_res = NULL; |
| 330 | if (!PyArg_ParseTuple(_args, "")) |
| 331 | return NULL; |
| 332 | SystemTask(); |
| 333 | Py_INCREF(Py_None); |
| 334 | _res = Py_None; |
| 335 | return _res; |
| 336 | } |
| 337 | |
| 338 | static PyObject *Evt_SystemEvent(_self, _args) |
| 339 | PyObject *_self; |
| 340 | PyObject *_args; |
| 341 | { |
| 342 | PyObject *_res = NULL; |
| 343 | Boolean _rv; |
| 344 | EventRecord theEvent; |
| 345 | if (!PyArg_ParseTuple(_args, "O&", |
| 346 | PyMac_GetEventRecord, &theEvent)) |
| 347 | return NULL; |
| 348 | _rv = SystemEvent(&theEvent); |
| 349 | _res = Py_BuildValue("b", |
| 350 | _rv); |
| 351 | return _res; |
| 352 | } |
| 353 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 354 | static PyMethodDef Evt_methods[] = { |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 355 | {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1, |
| 356 | "() -> (long _rv)"}, |
| 357 | {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1, |
| 358 | "() -> (long _rv)"}, |
| 359 | {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1, |
| 360 | "(short value) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 361 | {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1, |
| 362 | "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"}, |
| 363 | {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1, |
| 364 | "(short eventMask, unsigned long sleep) -> (Boolean _rv, EventRecord theEvent)"}, |
| 365 | {"EventAvail", (PyCFunction)Evt_EventAvail, 1, |
| 366 | "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"}, |
| 367 | {"GetMouse", (PyCFunction)Evt_GetMouse, 1, |
| 368 | "() -> (Point mouseLoc)"}, |
| 369 | {"Button", (PyCFunction)Evt_Button, 1, |
| 370 | "() -> (Boolean _rv)"}, |
| 371 | {"StillDown", (PyCFunction)Evt_StillDown, 1, |
| 372 | "() -> (Boolean _rv)"}, |
| 373 | {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1, |
| 374 | "() -> (Boolean _rv)"}, |
| 375 | {"GetKeys", (PyCFunction)Evt_GetKeys, 1, |
| 376 | "() -> (KeyMap theKeys)"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 377 | {"TickCount", (PyCFunction)Evt_TickCount, 1, |
| 378 | "() -> (unsigned long _rv)"}, |
| 379 | {"PostEvent", (PyCFunction)Evt_PostEvent, 1, |
| 380 | "(short eventNum, long eventMsg) -> None"}, |
| 381 | {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1, |
| 382 | "(short mask) -> (Boolean _rv, EventRecord theEvent)"}, |
| 383 | {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1, |
| 384 | "(short mask) -> (Boolean _rv, EventRecord theEvent)"}, |
| 385 | {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1, |
| 386 | "(short whichMask, short stopMask) -> None"}, |
Guido van Rossum | e26c263 | 1995-02-28 09:11:41 +0000 | [diff] [blame] | 387 | {"SystemClick", (PyCFunction)Evt_SystemClick, 1, |
| 388 | "(EventRecord theEvent, WindowPtr theWindow) -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 389 | {"SystemTask", (PyCFunction)Evt_SystemTask, 1, |
| 390 | "() -> None"}, |
| 391 | {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1, |
| 392 | "(EventRecord theEvent) -> (Boolean _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 393 | {NULL, NULL, 0} |
| 394 | }; |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | void initEvt() |
| 400 | { |
| 401 | PyObject *m; |
| 402 | PyObject *d; |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | m = Py_InitModule("Evt", Evt_methods); |
| 408 | d = PyModule_GetDict(m); |
| 409 | Evt_Error = PyMac_GetOSErrException(); |
| 410 | if (Evt_Error == NULL || |
| 411 | PyDict_SetItemString(d, "Error", Evt_Error) != 0) |
| 412 | Py_FatalError("can't initialize Evt.Error"); |
| 413 | } |
| 414 | |
| 415 | /* ========================= End module Evt ========================= */ |
| 416 | |