blob: 5dd5c5ab4d03308b556ee5706297faf67fff7d19 [file] [log] [blame]
Jack Jansenda6a9711996-04-12 16:25:30 +00001
2/* ========================== Module Scrap ========================== */
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
Jack Jansen9d8b96c2000-07-14 22:16:45 +000016#include "pymactoolbox.h"
Jack Jansenda6a9711996-04-12 16:25:30 +000017
18#include <Scrap.h>
19
20/*
21** Generate ScrapInfo records
22*/
Jack Jansen9d8b96c2000-07-14 22:16:45 +000023static PyObject *
24SCRRec_New(itself)
Jack Jansenda6a9711996-04-12 16:25:30 +000025 ScrapStuff *itself;
26{
27
28 return Py_BuildValue("lO&hhO&", itself->scrapSize,
29 ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
30 PyMac_BuildStr255, itself->scrapName);
31}
32
33static PyObject *Scrap_Error;
34
35static PyObject *Scrap_InfoScrap(_self, _args)
36 PyObject *_self;
37 PyObject *_args;
38{
39 PyObject *_res = NULL;
40 ScrapStuffPtr _rv;
41 if (!PyArg_ParseTuple(_args, ""))
42 return NULL;
43 _rv = InfoScrap();
44 _res = Py_BuildValue("O&",
45 SCRRec_New, _rv);
46 return _res;
47}
48
49static PyObject *Scrap_UnloadScrap(_self, _args)
50 PyObject *_self;
51 PyObject *_args;
52{
53 PyObject *_res = NULL;
54 long _rv;
55 if (!PyArg_ParseTuple(_args, ""))
56 return NULL;
57 _rv = UnloadScrap();
58 if ( _rv ) return PyMac_Error((OSErr)_rv);
59 Py_INCREF(Py_None);
60 return Py_None;
61}
62
63static PyObject *Scrap_LoadScrap(_self, _args)
64 PyObject *_self;
65 PyObject *_args;
66{
67 PyObject *_res = NULL;
68 long _rv;
69 if (!PyArg_ParseTuple(_args, ""))
70 return NULL;
71 _rv = LoadScrap();
72 if ( _rv ) return PyMac_Error((OSErr)_rv);
73 Py_INCREF(Py_None);
74 return Py_None;
75}
76
77static PyObject *Scrap_GetScrap(_self, _args)
78 PyObject *_self;
79 PyObject *_args;
80{
81 PyObject *_res = NULL;
82 long _rv;
83 Handle hDest;
84 ResType theType;
85 long offset;
86 if (!PyArg_ParseTuple(_args, "O&O&",
87 ResObj_Convert, &hDest,
88 PyMac_GetOSType, &theType))
89 return NULL;
90 _rv = GetScrap(hDest,
91 theType,
92 &offset);
93 _res = Py_BuildValue("ll",
94 _rv,
95 offset);
96 return _res;
97}
98
99static PyObject *Scrap_ZeroScrap(_self, _args)
100 PyObject *_self;
101 PyObject *_args;
102{
103 PyObject *_res = NULL;
104 long _rv;
105 if (!PyArg_ParseTuple(_args, ""))
106 return NULL;
107 _rv = ZeroScrap();
108 if ( _rv ) return PyMac_Error((OSErr)_rv);
109 Py_INCREF(Py_None);
110 return Py_None;
111}
112
113static PyObject *Scrap_PutScrap(_self, _args)
114 PyObject *_self;
115 PyObject *_args;
116{
117 PyObject *_res = NULL;
118 long _rv;
119 long length;
120 ResType theType;
121 char *source__in__;
122 int source__len__;
123 int source__in_len__;
124 if (!PyArg_ParseTuple(_args, "O&s#",
125 PyMac_GetOSType, &theType,
126 &source__in__, &source__in_len__))
127 return NULL;
128 length = source__in_len__;
129 _rv = PutScrap(length,
130 theType,
131 source__in__);
132 if ( _rv ) return PyMac_Error((OSErr)_rv);
133 Py_INCREF(Py_None);
134 return Py_None;
135}
136
137static PyMethodDef Scrap_methods[] = {
138 {"InfoScrap", (PyCFunction)Scrap_InfoScrap, 1,
139 "() -> (ScrapStuff _rv)"},
140 {"UnloadScrap", (PyCFunction)Scrap_UnloadScrap, 1,
141 "() -> (OSErr)"},
142 {"LoadScrap", (PyCFunction)Scrap_LoadScrap, 1,
143 "() -> (OSErr)"},
144 {"GetScrap", (PyCFunction)Scrap_GetScrap, 1,
145 "(Handle hDest, ResType theType) -> (long _rv, long offset)"},
146 {"ZeroScrap", (PyCFunction)Scrap_ZeroScrap, 1,
147 "() -> (OSErr)"},
148 {"PutScrap", (PyCFunction)Scrap_PutScrap, 1,
149 "(ResType theType, Buffer source) -> (OSErr)"},
150 {NULL, NULL, 0}
151};
152
153
154
155
156void initScrap()
157{
158 PyObject *m;
159 PyObject *d;
160
161
162
163
164 m = Py_InitModule("Scrap", Scrap_methods);
165 d = PyModule_GetDict(m);
166 Scrap_Error = PyMac_GetOSErrException();
167 if (Scrap_Error == NULL ||
168 PyDict_SetItemString(d, "Error", Scrap_Error) != 0)
169 Py_FatalError("can't initialize Scrap.Error");
170}
171
172/* ======================== End module Scrap ======================== */
173