blob: 2f88857d231555a8cba8b9371b1237ba8348a064 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Qd ============================ */
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
33extern PyObject *WinObj_WhichWindow(WindowPtr);
34
35#include <QuickDraw.h>
36#include <Desk.h>
37
38#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
39
40static PyObject *Qd_Error;
41
42static PyObject *Qd_GlobalToLocal(_self, _args)
43 PyObject *_self;
44 PyObject *_args;
45{
46 PyObject *_res = NULL;
47 Point thePoint;
48 if (!PyArg_ParseTuple(_args, "O&",
49 PyMac_GetPoint, &thePoint))
50 return NULL;
51 GlobalToLocal(&thePoint);
52 _res = Py_BuildValue("O&",
53 PyMac_BuildPoint, thePoint);
54 return _res;
55}
56
57static PyObject *Qd_LocalToGlobal(_self, _args)
58 PyObject *_self;
59 PyObject *_args;
60{
61 PyObject *_res = NULL;
62 Point thePoint;
63 if (!PyArg_ParseTuple(_args, "O&",
64 PyMac_GetPoint, &thePoint))
65 return NULL;
66 LocalToGlobal(&thePoint);
67 _res = Py_BuildValue("O&",
68 PyMac_BuildPoint, thePoint);
69 return _res;
70}
71
72static PyObject *Qd_SetPort(_self, _args)
73 PyObject *_self;
74 PyObject *_args;
75{
76 PyObject *_res = NULL;
77 WindowPtr thePort;
78 if (!PyArg_ParseTuple(_args, "O&",
79 WinObj_Convert, &thePort))
80 return NULL;
81 SetPort(thePort);
82 Py_INCREF(Py_None);
83 _res = Py_None;
84 return _res;
85}
86
87static PyObject *Qd_ClipRect(_self, _args)
88 PyObject *_self;
89 PyObject *_args;
90{
91 PyObject *_res = NULL;
92 Rect r;
93 if (!PyArg_ParseTuple(_args, "O&",
94 PyMac_GetRect, &r))
95 return NULL;
96 ClipRect(&r);
97 Py_INCREF(Py_None);
98 _res = Py_None;
99 return _res;
100}
101
102static PyObject *Qd_EraseRect(_self, _args)
103 PyObject *_self;
104 PyObject *_args;
105{
106 PyObject *_res = NULL;
107 Rect r;
108 if (!PyArg_ParseTuple(_args, "O&",
109 PyMac_GetRect, &r))
110 return NULL;
111 EraseRect(&r);
112 Py_INCREF(Py_None);
113 _res = Py_None;
114 return _res;
115}
116
117static PyObject *Qd_OpenDeskAcc(_self, _args)
118 PyObject *_self;
119 PyObject *_args;
120{
121 PyObject *_res = NULL;
122 Str255 name;
123 if (!PyArg_ParseTuple(_args, "O&",
124 PyMac_GetStr255, name))
125 return NULL;
126 OpenDeskAcc(name);
127 Py_INCREF(Py_None);
128 _res = Py_None;
129 return _res;
130}
131
132static PyMethodDef Qd_methods[] = {
133 {"GlobalToLocal", (PyCFunction)Qd_GlobalToLocal, 1,
134 "(Point thePoint) -> (Point thePoint)"},
135 {"LocalToGlobal", (PyCFunction)Qd_LocalToGlobal, 1,
136 "(Point thePoint) -> (Point thePoint)"},
137 {"SetPort", (PyCFunction)Qd_SetPort, 1,
138 "(WindowPtr thePort) -> None"},
139 {"ClipRect", (PyCFunction)Qd_ClipRect, 1,
140 "(Rect r) -> None"},
141 {"EraseRect", (PyCFunction)Qd_EraseRect, 1,
142 "(Rect r) -> None"},
143 {"OpenDeskAcc", (PyCFunction)Qd_OpenDeskAcc, 1,
144 "(Str255 name) -> None"},
145 {NULL, NULL, 0}
146};
147
148
149
150
151void initQd()
152{
153 PyObject *m;
154 PyObject *d;
155
156
157
158
159 m = Py_InitModule("Qd", Qd_methods);
160 d = PyModule_GetDict(m);
161 Qd_Error = PyMac_GetOSErrException();
162 if (Qd_Error == NULL ||
163 PyDict_SetItemString(d, "Error", Qd_Error) != 0)
164 Py_FatalError("can't initialize Qd.Error");
165}
166
167/* ========================= End module Qd ========================== */
168