blob: e84a299f21debe650780981050387aab33d71931 [file] [log] [blame]
Jack Jansenda6a9711996-04-12 16:25:30 +00001
2/* ========================== Module Scrap ========================== */
3
4#include "Python.h"
Jack Jansenda6a9711996-04-12 16:25:30 +00005
Jack Jansen7b3cc1f2001-01-24 16:04:01 +00006
7
8#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Jack Jansenda6a9711996-04-12 16:25:30 +000010
11#include <Scrap.h>
12
13/*
14** Generate ScrapInfo records
15*/
Jack Jansen9d8b96c2000-07-14 22:16:45 +000016static PyObject *
17SCRRec_New(itself)
Jack Jansenda6a9711996-04-12 16:25:30 +000018 ScrapStuff *itself;
19{
20
21 return Py_BuildValue("lO&hhO&", itself->scrapSize,
22 ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
23 PyMac_BuildStr255, itself->scrapName);
24}
25
26static PyObject *Scrap_Error;
27
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000028static PyObject *Scrap_LoadScrap(_self, _args)
29 PyObject *_self;
30 PyObject *_args;
31{
32 PyObject *_res = NULL;
33 OSStatus _err;
34 if (!PyArg_ParseTuple(_args, ""))
35 return NULL;
36 _err = LoadScrap();
37 if (_err != noErr) return PyMac_Error(_err);
38 Py_INCREF(Py_None);
39 _res = Py_None;
40 return _res;
41}
42
43static PyObject *Scrap_UnloadScrap(_self, _args)
44 PyObject *_self;
45 PyObject *_args;
46{
47 PyObject *_res = NULL;
48 OSStatus _err;
49 if (!PyArg_ParseTuple(_args, ""))
50 return NULL;
51 _err = UnloadScrap();
52 if (_err != noErr) return PyMac_Error(_err);
53 Py_INCREF(Py_None);
54 _res = Py_None;
55 return _res;
56}
57
58#if !TARGET_API_MAC_CARBON
59
Jack Jansenda6a9711996-04-12 16:25:30 +000060static PyObject *Scrap_InfoScrap(_self, _args)
61 PyObject *_self;
62 PyObject *_args;
63{
64 PyObject *_res = NULL;
65 ScrapStuffPtr _rv;
66 if (!PyArg_ParseTuple(_args, ""))
67 return NULL;
68 _rv = InfoScrap();
69 _res = Py_BuildValue("O&",
70 SCRRec_New, _rv);
71 return _res;
72}
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000073#endif
Jack Jansenda6a9711996-04-12 16:25:30 +000074
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000075#if !TARGET_API_MAC_CARBON
Jack Jansenda6a9711996-04-12 16:25:30 +000076
77static PyObject *Scrap_GetScrap(_self, _args)
78 PyObject *_self;
79 PyObject *_args;
80{
81 PyObject *_res = NULL;
82 long _rv;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000083 Handle destination;
84 ScrapFlavorType flavorType;
85 SInt32 offset;
Jack Jansenda6a9711996-04-12 16:25:30 +000086 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000087 ResObj_Convert, &destination,
88 PyMac_GetOSType, &flavorType))
Jack Jansenda6a9711996-04-12 16:25:30 +000089 return NULL;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000090 _rv = GetScrap(destination,
91 flavorType,
Jack Jansenda6a9711996-04-12 16:25:30 +000092 &offset);
93 _res = Py_BuildValue("ll",
94 _rv,
95 offset);
96 return _res;
97}
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000098#endif
99
100#if !TARGET_API_MAC_CARBON
Jack Jansenda6a9711996-04-12 16:25:30 +0000101
102static PyObject *Scrap_ZeroScrap(_self, _args)
103 PyObject *_self;
104 PyObject *_args;
105{
106 PyObject *_res = NULL;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000107 OSStatus _err;
Jack Jansenda6a9711996-04-12 16:25:30 +0000108 if (!PyArg_ParseTuple(_args, ""))
109 return NULL;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000110 _err = ZeroScrap();
111 if (_err != noErr) return PyMac_Error(_err);
Jack Jansenda6a9711996-04-12 16:25:30 +0000112 Py_INCREF(Py_None);
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000113 _res = Py_None;
114 return _res;
Jack Jansenda6a9711996-04-12 16:25:30 +0000115}
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000116#endif
117
118#if !TARGET_API_MAC_CARBON
Jack Jansenda6a9711996-04-12 16:25:30 +0000119
120static PyObject *Scrap_PutScrap(_self, _args)
121 PyObject *_self;
122 PyObject *_args;
123{
124 PyObject *_res = NULL;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000125 OSStatus _err;
126 SInt32 sourceBufferByteCount;
127 ScrapFlavorType flavorType;
128 char *sourceBuffer__in__;
129 int sourceBuffer__len__;
130 int sourceBuffer__in_len__;
Jack Jansenda6a9711996-04-12 16:25:30 +0000131 if (!PyArg_ParseTuple(_args, "O&s#",
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000132 PyMac_GetOSType, &flavorType,
133 &sourceBuffer__in__, &sourceBuffer__in_len__))
Jack Jansenda6a9711996-04-12 16:25:30 +0000134 return NULL;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000135 sourceBufferByteCount = sourceBuffer__in_len__;
136 sourceBuffer__len__ = sourceBuffer__in_len__;
137 _err = PutScrap(sourceBufferByteCount,
138 flavorType,
139 sourceBuffer__in__);
140 if (_err != noErr) return PyMac_Error(_err);
Jack Jansenda6a9711996-04-12 16:25:30 +0000141 Py_INCREF(Py_None);
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000142 _res = Py_None;
143 sourceBuffer__error__: ;
144 return _res;
Jack Jansenda6a9711996-04-12 16:25:30 +0000145}
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000146#endif
147
148#if TARGET_API_MAC_CARBON
149
150static PyObject *Scrap_ClearCurrentScrap(_self, _args)
151 PyObject *_self;
152 PyObject *_args;
153{
154 PyObject *_res = NULL;
155 OSStatus _err;
156 if (!PyArg_ParseTuple(_args, ""))
157 return NULL;
158 _err = ClearCurrentScrap();
159 if (_err != noErr) return PyMac_Error(_err);
160 Py_INCREF(Py_None);
161 _res = Py_None;
162 return _res;
163}
164#endif
165
166#if TARGET_API_MAC_CARBON
167
168static PyObject *Scrap_CallInScrapPromises(_self, _args)
169 PyObject *_self;
170 PyObject *_args;
171{
172 PyObject *_res = NULL;
173 OSStatus _err;
174 if (!PyArg_ParseTuple(_args, ""))
175 return NULL;
176 _err = CallInScrapPromises();
177 if (_err != noErr) return PyMac_Error(_err);
178 Py_INCREF(Py_None);
179 _res = Py_None;
180 return _res;
181}
182#endif
Jack Jansenda6a9711996-04-12 16:25:30 +0000183
184static PyMethodDef Scrap_methods[] = {
Jack Jansenda6a9711996-04-12 16:25:30 +0000185 {"LoadScrap", (PyCFunction)Scrap_LoadScrap, 1,
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000186 "() -> None"},
187 {"UnloadScrap", (PyCFunction)Scrap_UnloadScrap, 1,
188 "() -> None"},
189
190#if !TARGET_API_MAC_CARBON
191 {"InfoScrap", (PyCFunction)Scrap_InfoScrap, 1,
192 "() -> (ScrapStuffPtr _rv)"},
193#endif
194
195#if !TARGET_API_MAC_CARBON
Jack Jansenda6a9711996-04-12 16:25:30 +0000196 {"GetScrap", (PyCFunction)Scrap_GetScrap, 1,
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000197 "(Handle destination, ScrapFlavorType flavorType) -> (long _rv, SInt32 offset)"},
198#endif
199
200#if !TARGET_API_MAC_CARBON
Jack Jansenda6a9711996-04-12 16:25:30 +0000201 {"ZeroScrap", (PyCFunction)Scrap_ZeroScrap, 1,
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000202 "() -> None"},
203#endif
204
205#if !TARGET_API_MAC_CARBON
Jack Jansenda6a9711996-04-12 16:25:30 +0000206 {"PutScrap", (PyCFunction)Scrap_PutScrap, 1,
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000207 "(SInt32 sourceBufferByteCount, ScrapFlavorType flavorType, Buffer sourceBuffer) -> None"},
208#endif
209
210#if TARGET_API_MAC_CARBON
211 {"ClearCurrentScrap", (PyCFunction)Scrap_ClearCurrentScrap, 1,
212 "() -> None"},
213#endif
214
215#if TARGET_API_MAC_CARBON
216 {"CallInScrapPromises", (PyCFunction)Scrap_CallInScrapPromises, 1,
217 "() -> None"},
218#endif
Jack Jansenda6a9711996-04-12 16:25:30 +0000219 {NULL, NULL, 0}
220};
221
222
223
224
225void initScrap()
226{
227 PyObject *m;
228 PyObject *d;
229
230
231
232
233 m = Py_InitModule("Scrap", Scrap_methods);
234 d = PyModule_GetDict(m);
235 Scrap_Error = PyMac_GetOSErrException();
236 if (Scrap_Error == NULL ||
237 PyDict_SetItemString(d, "Error", Scrap_Error) != 0)
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000238 return;
Jack Jansenda6a9711996-04-12 16:25:30 +0000239}
240
241/* ======================== End module Scrap ======================== */
242