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