2 /* ========================== Module Scrap ========================== */
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
14 #include <Carbon/Carbon.h>
17 #if !TARGET_API_MAC_CARBON
20 ** Generate ScrapInfo records
27 return Py_BuildValue("lO&hhO&", itself
->scrapSize
,
28 ResObj_New
, itself
->scrapHandle
, itself
->scrapCount
, itself
->scrapState
,
29 PyMac_BuildStr255
, itself
->scrapName
);
33 static PyObject
*Scrap_Error
;
35 static PyObject
*Scrap_LoadScrap(_self
, _args
)
39 PyObject
*_res
= NULL
;
41 if (!PyArg_ParseTuple(_args
, ""))
44 if (_err
!= noErr
) return PyMac_Error(_err
);
50 static PyObject
*Scrap_UnloadScrap(_self
, _args
)
54 PyObject
*_res
= NULL
;
56 if (!PyArg_ParseTuple(_args
, ""))
59 if (_err
!= noErr
) return PyMac_Error(_err
);
65 #if !TARGET_API_MAC_CARBON
67 static PyObject
*Scrap_InfoScrap(_self
, _args
)
71 PyObject
*_res
= NULL
;
73 if (!PyArg_ParseTuple(_args
, ""))
76 _res
= Py_BuildValue("O&",
82 #if !TARGET_API_MAC_CARBON
84 static PyObject
*Scrap_GetScrap(_self
, _args
)
88 PyObject
*_res
= NULL
;
91 ScrapFlavorType flavorType
;
93 if (!PyArg_ParseTuple(_args
, "O&O&",
94 ResObj_Convert
, &destination
,
95 PyMac_GetOSType
, &flavorType
))
97 _rv
= GetScrap(destination
,
100 _res
= Py_BuildValue("ll",
108 static PyObject
*Scrap_ZeroScrap(_self
, _args
)
112 PyObject
*_res
= NULL
;
114 if (!PyArg_ParseTuple(_args
, ""))
116 #if TARGET_API_MAC_CARBON
120 _err
= ClearCurrentScrap();
121 if (_err
!= noErr
) return PyMac_Error(_err
);
122 _err
= GetCurrentScrap(&scrap
);
127 if (_err
!= noErr
) return PyMac_Error(_err
);
133 static PyObject
*Scrap_PutScrap(_self
, _args
)
137 PyObject
*_res
= NULL
;
139 SInt32 sourceBufferByteCount
;
140 ScrapFlavorType flavorType
;
141 char *sourceBuffer__in__
;
142 int sourceBuffer__len__
;
143 int sourceBuffer__in_len__
;
144 #if TARGET_API_MAC_CARBON
148 if (!PyArg_ParseTuple(_args
, "O&s#",
149 PyMac_GetOSType
, &flavorType
,
150 &sourceBuffer__in__
, &sourceBuffer__in_len__
))
152 sourceBufferByteCount
= sourceBuffer__in_len__
;
153 sourceBuffer__len__
= sourceBuffer__in_len__
;
154 #if TARGET_API_MAC_CARBON
155 _err
= GetCurrentScrap(&scrap
);
156 if (_err
!= noErr
) return PyMac_Error(_err
);
157 _err
= PutScrapFlavor(scrap
, flavorType
, 0, sourceBufferByteCount
, sourceBuffer__in__
);
159 _err
= PutScrap(sourceBufferByteCount
,
163 if (_err
!= noErr
) return PyMac_Error(_err
);
166 sourceBuffer__error__
: ;
170 #if TARGET_API_MAC_CARBON
172 static PyObject
*Scrap_ClearCurrentScrap(_self
, _args
)
176 PyObject
*_res
= NULL
;
178 if (!PyArg_ParseTuple(_args
, ""))
180 _err
= ClearCurrentScrap();
181 if (_err
!= noErr
) return PyMac_Error(_err
);
188 #if TARGET_API_MAC_CARBON
190 static PyObject
*Scrap_CallInScrapPromises(_self
, _args
)
194 PyObject
*_res
= NULL
;
196 if (!PyArg_ParseTuple(_args
, ""))
198 _err
= CallInScrapPromises();
199 if (_err
!= noErr
) return PyMac_Error(_err
);
206 static PyMethodDef Scrap_methods
[] = {
207 {"LoadScrap", (PyCFunction
)Scrap_LoadScrap
, 1,
209 {"UnloadScrap", (PyCFunction
)Scrap_UnloadScrap
, 1,
212 #if !TARGET_API_MAC_CARBON
213 {"InfoScrap", (PyCFunction
)Scrap_InfoScrap
, 1,
214 "() -> (ScrapStuffPtr _rv)"},
217 #if !TARGET_API_MAC_CARBON
218 {"GetScrap", (PyCFunction
)Scrap_GetScrap
, 1,
219 "(Handle destination, ScrapFlavorType flavorType) -> (long _rv, SInt32 offset)"},
222 {"ZeroScrap", (PyCFunction
)Scrap_ZeroScrap
, 1,
225 {"PutScrap", (PyCFunction
)Scrap_PutScrap
, 1,
226 "(ScrapFlavorType flavorType, Buffer sourceBuffer) -> None"},
228 #if TARGET_API_MAC_CARBON
229 {"ClearCurrentScrap", (PyCFunction
)Scrap_ClearCurrentScrap
, 1,
233 #if TARGET_API_MAC_CARBON
234 {"CallInScrapPromises", (PyCFunction
)Scrap_CallInScrapPromises
, 1,
251 m
= Py_InitModule("Scrap", Scrap_methods
);
252 d
= PyModule_GetDict(m
);
253 Scrap_Error
= PyMac_GetOSErrException();
254 if (Scrap_Error
== NULL
||
255 PyDict_SetItemString(d
, "Error", Scrap_Error
) != 0)
259 /* ======================== End module Scrap ======================== */