22/* ========================== Module Scrap ========================== */
33
44#include "Python.h"
5- #include "macglue.h"
6- #include <Memory.h>
7- #include <Dialogs.h>
8- #include <Menus.h>
9- #include <Controls.h>
105
6+
7+
8+ #include "macglue.h"
119#include "pymactoolbox.h"
1210
1311#include <Scrap.h>
@@ -27,17 +25,18 @@ SCRRec_New(itself)
2725
2826static PyObject * Scrap_Error ;
2927
30- static PyObject * Scrap_InfoScrap (_self , _args )
28+ static PyObject * Scrap_LoadScrap (_self , _args )
3129 PyObject * _self ;
3230 PyObject * _args ;
3331{
3432 PyObject * _res = NULL ;
35- ScrapStuffPtr _rv ;
33+ OSStatus _err ;
3634 if (!PyArg_ParseTuple (_args , "" ))
3735 return NULL ;
38- _rv = InfoScrap ();
39- _res = Py_BuildValue ("O&" ,
40- SCRRec_New , _rv );
36+ _err = LoadScrap ();
37+ if (_err != noErr ) return PyMac_Error (_err );
38+ Py_INCREF (Py_None );
39+ _res = Py_None ;
4140 return _res ;
4241}
4342
@@ -46,102 +45,177 @@ static PyObject *Scrap_UnloadScrap(_self, _args)
4645 PyObject * _args ;
4746{
4847 PyObject * _res = NULL ;
49- long _rv ;
48+ OSStatus _err ;
5049 if (!PyArg_ParseTuple (_args , "" ))
5150 return NULL ;
52- _rv = UnloadScrap ();
53- if ( _rv ) return PyMac_Error (( OSErr ) _rv );
51+ _err = UnloadScrap ();
52+ if (_err != noErr ) return PyMac_Error (_err );
5453 Py_INCREF (Py_None );
55- return Py_None ;
54+ _res = Py_None ;
55+ return _res ;
5656}
5757
58- static PyObject * Scrap_LoadScrap (_self , _args )
58+ #if !TARGET_API_MAC_CARBON
59+
60+ static PyObject * Scrap_InfoScrap (_self , _args )
5961 PyObject * _self ;
6062 PyObject * _args ;
6163{
6264 PyObject * _res = NULL ;
63- long _rv ;
65+ ScrapStuffPtr _rv ;
6466 if (!PyArg_ParseTuple (_args , "" ))
6567 return NULL ;
66- _rv = LoadScrap ();
67- if ( _rv ) return PyMac_Error (( OSErr ) _rv );
68- Py_INCREF ( Py_None );
69- return Py_None ;
68+ _rv = InfoScrap ();
69+ _res = Py_BuildValue ( "O&" ,
70+ SCRRec_New , _rv );
71+ return _res ;
7072}
73+ #endif
74+
75+ #if !TARGET_API_MAC_CARBON
7176
7277static PyObject * Scrap_GetScrap (_self , _args )
7378 PyObject * _self ;
7479 PyObject * _args ;
7580{
7681 PyObject * _res = NULL ;
7782 long _rv ;
78- Handle hDest ;
79- ResType theType ;
80- long offset ;
83+ Handle destination ;
84+ ScrapFlavorType flavorType ;
85+ SInt32 offset ;
8186 if (!PyArg_ParseTuple (_args , "O&O&" ,
82- ResObj_Convert , & hDest ,
83- PyMac_GetOSType , & theType ))
87+ ResObj_Convert , & destination ,
88+ PyMac_GetOSType , & flavorType ))
8489 return NULL ;
85- _rv = GetScrap (hDest ,
86- theType ,
90+ _rv = GetScrap (destination ,
91+ flavorType ,
8792 & offset );
8893 _res = Py_BuildValue ("ll" ,
8994 _rv ,
9095 offset );
9196 return _res ;
9297}
98+ #endif
99+
100+ #if !TARGET_API_MAC_CARBON
93101
94102static PyObject * Scrap_ZeroScrap (_self , _args )
95103 PyObject * _self ;
96104 PyObject * _args ;
97105{
98106 PyObject * _res = NULL ;
99- long _rv ;
107+ OSStatus _err ;
100108 if (!PyArg_ParseTuple (_args , "" ))
101109 return NULL ;
102- _rv = ZeroScrap ();
103- if ( _rv ) return PyMac_Error (( OSErr ) _rv );
110+ _err = ZeroScrap ();
111+ if (_err != noErr ) return PyMac_Error (_err );
104112 Py_INCREF (Py_None );
105- return Py_None ;
113+ _res = Py_None ;
114+ return _res ;
106115}
116+ #endif
117+
118+ #if !TARGET_API_MAC_CARBON
107119
108120static PyObject * Scrap_PutScrap (_self , _args )
109121 PyObject * _self ;
110122 PyObject * _args ;
111123{
112124 PyObject * _res = NULL ;
113- long _rv ;
114- long length ;
115- ResType theType ;
116- char * source__in__ ;
117- int source__len__ ;
118- int source__in_len__ ;
125+ OSStatus _err ;
126+ SInt32 sourceBufferByteCount ;
127+ ScrapFlavorType flavorType ;
128+ char * sourceBuffer__in__ ;
129+ int sourceBuffer__len__ ;
130+ int sourceBuffer__in_len__ ;
119131 if (!PyArg_ParseTuple (_args , "O&s#" ,
120- PyMac_GetOSType , & theType ,
121- & source__in__ , & source__in_len__ ))
132+ PyMac_GetOSType , & flavorType ,
133+ & sourceBuffer__in__ , & sourceBuffer__in_len__ ))
134+ return NULL ;
135+ 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 );
141+ Py_INCREF (Py_None );
142+ _res = Py_None ;
143+ sourceBuffer__error__ : ;
144+ return _res ;
145+ }
146+ #endif
147+
148+ #if TARGET_API_MAC_CARBON
149+
150+ static 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+
168+ static PyObject * Scrap_CallInScrapPromises (_self , _args )
169+ PyObject * _self ;
170+ PyObject * _args ;
171+ {
172+ PyObject * _res = NULL ;
173+ OSStatus _err ;
174+ if (!PyArg_ParseTuple (_args , "" ))
122175 return NULL ;
123- length = source__in_len__ ;
124- _rv = PutScrap (length ,
125- theType ,
126- source__in__ );
127- if ( _rv ) return PyMac_Error ((OSErr )_rv );
176+ _err = CallInScrapPromises ();
177+ if (_err != noErr ) return PyMac_Error (_err );
128178 Py_INCREF (Py_None );
129- return Py_None ;
179+ _res = Py_None ;
180+ return _res ;
130181}
182+ #endif
131183
132184static PyMethodDef Scrap_methods [] = {
133- {"InfoScrap" , (PyCFunction )Scrap_InfoScrap , 1 ,
134- "() -> (ScrapStuff _rv)" },
135- {"UnloadScrap" , (PyCFunction )Scrap_UnloadScrap , 1 ,
136- "() -> (OSErr)" },
137185 {"LoadScrap" , (PyCFunction )Scrap_LoadScrap , 1 ,
138- "() -> (OSErr)" },
186+ "() -> 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
139196 {"GetScrap" , (PyCFunction )Scrap_GetScrap , 1 ,
140- "(Handle hDest, ResType theType) -> (long _rv, long offset)" },
197+ "(Handle destination, ScrapFlavorType flavorType) -> (long _rv, SInt32 offset)" },
198+ #endif
199+
200+ #if !TARGET_API_MAC_CARBON
141201 {"ZeroScrap" , (PyCFunction )Scrap_ZeroScrap , 1 ,
142- "() -> (OSErr)" },
202+ "() -> None" },
203+ #endif
204+
205+ #if !TARGET_API_MAC_CARBON
143206 {"PutScrap" , (PyCFunction )Scrap_PutScrap , 1 ,
144- "(ResType theType, Buffer source) -> (OSErr)" },
207+ "(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
145219 {NULL , NULL , 0 }
146220};
147221
@@ -161,7 +235,7 @@ void initScrap()
161235 Scrap_Error = PyMac_GetOSErrException ();
162236 if (Scrap_Error == NULL ||
163237 PyDict_SetItemString (d , "Error" , Scrap_Error ) != 0 )
164- Py_FatalError ( "can't initialize Scrap.Error" ) ;
238+ return ;
165239}
166240
167241/* ======================== End module Scrap ======================== */
0 commit comments