blob: 353c850f35d35296d4675ceca3d345a5e8e0f222 [file] [log] [blame]
Jack Jansenf93c72a1994-12-14 14:07:50 +00001/*
2** macglue - A couple of mac-specific routines often needed.
3**
4** Jack Jansen, CWI, 1994.
5*/
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include "Python.h"
12#include "macglue.h"
13
14#include <OSUtils.h> /* for Set(Current)A5 */
15#include <Resources.h>
16#include <Memory.h>
17#include <Events.h>
18#include <Windows.h>
19#include <Desk.h>
20
21/* Replace strerror with something that might work */
22char *macstrerror(int err)
23{
24 static char buf[256];
25 Handle h;
26 char *str;
27
28 h = GetResource('Estr', err);
29 if ( h ) {
30 HLock(h);
31 str = (char *)*h;
32 memcpy(buf, str+1, (unsigned char)str[0]);
33 HUnlock(h);
34 ReleaseResource(h);
35 } else {
36 sprintf(buf, "Mac OS error code %d", err);
37 }
38 return buf;
39}
40
41/* Set a MAC-specific error from errno, and return NULL; return None if no error */
42PyObject *
Guido van Rossumfffb8bb1995-01-12 12:37:24 +000043PyErr_Mac(PyObject *eobj, int err)
Jack Jansenf93c72a1994-12-14 14:07:50 +000044{
45 char *msg;
46 PyObject *v;
47 Handle h;
48
49 if (err == 0) {
50 Py_INCREF(Py_None);
51 return Py_None;
52 }
53 msg = macstrerror(err);
54 v = Py_BuildValue("(is)", err, msg);
55 PyErr_SetObject(eobj, v);
56 Py_DECREF(v);
57 return NULL;
58}
59
60/*
61** Idle routine for busy-wait loops.
62** This is rather tricky: if we see an event we check whether it is
63** for somebody else (i.e. a click outside our windows) and, if so,
64** we pass the event on (so the user can switch processes). However,
65** by doing this we loose events meant for our windows. Too bad, I guess...
66*/
67int
68PyMac_Idle()
69{
70 EventRecord ev;
71 WindowPtr wp;
72
73#if 0
74 SystemTask();
75 if ( intrcheck() )
76 return 0;
77 if ( GetNextEvent(0xffff, &ev) ) {
78 if ( ev.what == mouseDown ) {
79 if ( FindWindow(ev.where, &wp) == inSysWindow )
80 SystemClick(&ev, wp);
81 }
82 }
83#endif
84 return 1;
85}
86