blob: 436cbede62496fdacff737a9536cdbe14a6d66d8 [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
Jack Jansenda6a9711996-04-12 16:25:30 +0000100
101static PyObject *Scrap_ZeroScrap(_self, _args)
102 PyObject *_self;
103 PyObject *_args;
104{
105 PyObject *_res = NULL;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000106 OSStatus _err;
Jack Jansenda6a9711996-04-12 16:25:30 +0000107 if (!PyArg_ParseTuple(_args, ""))
108 return NULL;
Jack Jansenbf21bef2001-01-29 15:20:06 +0000109#if TARGET_API_MAC_CARBON
110 {
111 ScrapRef scrap;
112
113 _err = ClearCurrentScrap();
114 if (_err != noErr) return PyMac_Error(_err);
115 _err = GetCurrentScrap(&scrap);
116 }
117#else
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000118 _err = ZeroScrap();
Jack Jansenbf21bef2001-01-29 15:20:06 +0000119#endif
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000120 if (_err != noErr) return PyMac_Error(_err);
Jack Jansenda6a9711996-04-12 16:25:30 +0000121 Py_INCREF(Py_None);
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000122 _res = Py_None;
123 return _res;
Jack Jansenda6a9711996-04-12 16:25:30 +0000124}
125
126static PyObject *Scrap_PutScrap(_self, _args)
127 PyObject *_self;
128 PyObject *_args;
129{
130 PyObject *_res = NULL;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000131 OSStatus _err;
132 SInt32 sourceBufferByteCount;
133 ScrapFlavorType flavorType;
134 char *sourceBuffer__in__;
135 int sourceBuffer__len__;
136 int sourceBuffer__in_len__;
Jack Jansenbf21bef2001-01-29 15:20:06 +0000137#if TARGET_API_MAC_CARBON
138 ScrapRef scrap;
139#endif
140
Jack Jansenda6a9711996-04-12 16:25:30 +0000141 if (!PyArg_ParseTuple(_args, "O&s#",
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000142 PyMac_GetOSType, &flavorType,
143 &sourceBuffer__in__, &sourceBuffer__in_len__))
Jack Jansenda6a9711996-04-12 16:25:30 +0000144 return NULL;
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000145 sourceBufferByteCount = sourceBuffer__in_len__;
146 sourceBuffer__len__ = sourceBuffer__in_len__;
Jack Jansenbf21bef2001-01-29 15:20:06 +0000147#if TARGET_API_MAC_CARBON
148 _err = GetCurrentScrap(&scrap);
149 if (_err != noErr) return PyMac_Error(_err);
150 _err = PutScrapFlavor(scrap, flavorType, 0, sourceBufferByteCount, sourceBuffer__in__);
151#else
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000152 _err = PutScrap(sourceBufferByteCount,
153 flavorType,
154 sourceBuffer__in__);
Jack Jansenbf21bef2001-01-29 15:20:06 +0000155#endif
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000156 if (_err != noErr) return PyMac_Error(_err);
Jack Jansenda6a9711996-04-12 16:25:30 +0000157 Py_INCREF(Py_None);
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000158 _res = Py_None;
159 sourceBuffer__error__: ;
160 return _res;
Jack Jansenda6a9711996-04-12 16:25:30 +0000161}
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000162
163#if TARGET_API_MAC_CARBON
164
165static PyObject *Scrap_ClearCurrentScrap(_self, _args)
166 PyObject *_self;
167 PyObject *_args;
168{
169 PyObject *_res = NULL;
170 OSStatus _err;
171 if (!PyArg_ParseTuple(_args, ""))
172 return NULL;
173 _err = ClearCurrentScrap();
174 if (_err != noErr) return PyMac_Error(_err);
175 Py_INCREF(Py_None);
176 _res = Py_None;
177 return _res;
178}
179#endif
180
181#if TARGET_API_MAC_CARBON
182
183static PyObject *Scrap_CallInScrapPromises(_self, _args)
184 PyObject *_self;
185 PyObject *_args;
186{
187 PyObject *_res = NULL;
188 OSStatus _err;
189 if (!PyArg_ParseTuple(_args, ""))
190 return NULL;
191 _err = CallInScrapPromises();
192 if (_err != noErr) return PyMac_Error(_err);
193 Py_INCREF(Py_None);
194 _res = Py_None;
195 return _res;
196}
197#endif
Jack Jansenda6a9711996-04-12 16:25:30 +0000198
199static PyMethodDef Scrap_methods[] = {
Jack Jansenda6a9711996-04-12 16:25:30 +0000200 {"LoadScrap", (PyCFunction)Scrap_LoadScrap, 1,
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000201 "() -> None"},
202 {"UnloadScrap", (PyCFunction)Scrap_UnloadScrap, 1,
203 "() -> None"},
204
205#if !TARGET_API_MAC_CARBON
206 {"InfoScrap", (PyCFunction)Scrap_InfoScrap, 1,
207 "() -> (ScrapStuffPtr _rv)"},
208#endif
209
210#if !TARGET_API_MAC_CARBON
Jack Jansenda6a9711996-04-12 16:25:30 +0000211 {"GetScrap", (PyCFunction)Scrap_GetScrap, 1,
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000212 "(Handle destination, ScrapFlavorType flavorType) -> (long _rv, SInt32 offset)"},
213#endif
214
Jack Jansenda6a9711996-04-12 16:25:30 +0000215 {"ZeroScrap", (PyCFunction)Scrap_ZeroScrap, 1,
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000216 "() -> None"},
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000217
Jack Jansenda6a9711996-04-12 16:25:30 +0000218 {"PutScrap", (PyCFunction)Scrap_PutScrap, 1,
Jack Jansenbf21bef2001-01-29 15:20:06 +0000219 "(ScrapFlavorType flavorType, Buffer sourceBuffer) -> None"},
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000220
221#if TARGET_API_MAC_CARBON
222 {"ClearCurrentScrap", (PyCFunction)Scrap_ClearCurrentScrap, 1,
223 "() -> None"},
224#endif
225
226#if TARGET_API_MAC_CARBON
227 {"CallInScrapPromises", (PyCFunction)Scrap_CallInScrapPromises, 1,
228 "() -> None"},
229#endif
Jack Jansenda6a9711996-04-12 16:25:30 +0000230 {NULL, NULL, 0}
231};
232
233
234
235
236void initScrap()
237{
238 PyObject *m;
239 PyObject *d;
240
241
242
243
244 m = Py_InitModule("Scrap", Scrap_methods);
245 d = PyModule_GetDict(m);
246 Scrap_Error = PyMac_GetOSErrException();
247 if (Scrap_Error == NULL ||
248 PyDict_SetItemString(d, "Error", Scrap_Error) != 0)
Jack Jansen7b3cc1f2001-01-24 16:04:01 +0000249 return;
Jack Jansenda6a9711996-04-12 16:25:30 +0000250}
251
252/* ======================== End module Scrap ======================== */
253