Subversion Repositories filter_foundry

Rev

Rev 536 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 536 Rev 550
1
/*
1
/*
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.net
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.net
4
    Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft
4
    Copyright (C) 2018-2023 Daniel Marschall, ViaThinkSoft
5
 
5
 
6
    This program is free software; you can redistribute it and/or modify
6
    This program is free software; you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation; either version 2 of the License, or
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
9
    (at your option) any later version.
10
 
10
 
11
    This program is distributed in the hope that it will be useful,
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
14
    GNU General Public License for more details.
15
 
15
 
16
    You should have received a copy of the GNU General Public License
16
    You should have received a copy of the GNU General Public License
17
    along with this program; if not, write to the Free Software
17
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
*/
19
*/
20
 
20
 
21
/* Portions Copyright 1996 - 1999 Adobe Systems Incorporated */
21
/* Portions Copyright 1996 - 1999 Adobe Systems Incorporated */
22
/* All Rights Reserved.                                      */
22
/* All Rights Reserved.                                      */
23
 
23
 
24
//#include <stdio.h>
24
//#include <stdio.h>
25
 
25
 
26
//#include "world.h" // must come before Photoshop includes
26
//#include "world.h" // must come before Photoshop includes
27
 
27
 
28
#include "ff.h"
28
#include "ff.h"
29
 
29
 
30
#include "scripting.h"
30
#include "scripting.h"
31
//#include "ui.h"
31
//#include "ui.h"
32
#include "dbg.h"
32
#include "dbg.h"
33
 
33
 
34
//extern FilterRecordPtr gpb;
34
//extern FilterRecordPtr gpb;
35
 
35
 
36
OSErr put_cstring(PIWriteDescriptor token, DescriptorKeyID key, char* s) {
36
OSErr put_cstring(PIWriteDescriptor token, DescriptorKeyID key, char* s) {
37
        OSErr e;
37
        OSErr e;
38
        size_t n = strlen(s);
38
        size_t n = strlen(s);
39
        Ptr p;
39
        Ptr p;
40
        Handle h = PINEWHANDLE((int32)n);
40
        Handle h = PINEWHANDLE((int32)n);
41
        p = PILOCKHANDLE(h, false);
41
        p = PILOCKHANDLE(h, false);
42
        memcpy(p, s, n);
42
        memcpy(p, s, n);
43
        PIUNLOCKHANDLE(h);
43
        PIUNLOCKHANDLE(h);
44
        e = PIPutText(token, key, h);
44
        e = PIPutText(token, key, h);
45
        PIDISPOSEHANDLE(h); /* Not 100% sure if we are supposed to dispose of handle. It doesn't crash though */
45
        PIDISPOSEHANDLE(h); /* Not 100% sure if we are supposed to dispose of handle. It doesn't crash though */
46
        return e;
46
        return e;
47
}
47
}
48
 
48
 
49
char* get_cstring(PIReadDescriptor token) {
49
char* get_cstring(PIReadDescriptor token) {
50
        size_t n;
50
        size_t n;
51
        Ptr p;
51
        Ptr p;
52
        char* str = NULL;
52
        char* str = NULL;
53
        Handle h;
53
        Handle h;
54
        OSErr e = PIGetText(token, &h);
54
        OSErr e = PIGetText(token, &h);
55
 
55
 
56
        if ((e == noErr) && h) {
56
        if ((e == noErr) && h) {
57
                n = PIGETHANDLESIZE(h);
57
                n = PIGETHANDLESIZE(h);
58
                p = PILOCKHANDLE(h, false);
58
                p = PILOCKHANDLE(h, false);
59
                if ((str = (char*)malloc(n + 1))) {
59
                if ((str = (char*)malloc(n + 1))) {
60
                        memcpy(str, p, n);
60
                        memcpy(str, p, n);
61
                        str[n] = 0;
61
                        str[n] = 0;
62
                }
62
                }
63
                PIUNLOCKHANDLE(h);
63
                PIUNLOCKHANDLE(h);
64
                PIDISPOSEHANDLE(h); /* Not 100% sure if we are supposed to dispose of handle. It doesn't crash though */
64
                PIDISPOSEHANDLE(h); /* Not 100% sure if we are supposed to dispose of handle. It doesn't crash though */
65
        }
65
        }
66
        return str;
66
        return str;
67
}
67
}
68
 
68
 
69
// If parm is NULL, then it is standalone, otherwise it is the main plugin
69
// If parm is NULL, then it is standalone, otherwise it is the main plugin
70
OSType getAeteKey(char c, PARM_T* parm) {
70
OSType getAeteKey(char c, PARM_T* parm) {
71
        // To make our plugin compatible with AppleScript, each key must
71
        // To make our plugin compatible with AppleScript, each key must
72
        // be unique, since the namespace is global!
72
        // be unique, since the namespace is global!
73
        // Furthermore, the "uniqueID/scope" hstm-field in the PIPL must be empty.
73
        // Furthermore, the "uniqueID/scope" hstm-field in the PIPL must be empty.
74
 
74
 
75
        if (parm != NULL) {
75
        if (parm != NULL) {
76
                unsigned long hash;
76
                unsigned long hash;
77
                char* data;
77
                char* data;
78
                // char* debug = (char*)malloc(2000);
78
                // char* debug = (char*)malloc(2000);
79
                // sprintf(debug, "getAeteKey %c with title %s/%s in STANDALONE PLUGIN", c, parm->szTitle, parm->szCategory);
79
                // sprintf(debug, "getAeteKey %c with title %s/%s in STANDALONE PLUGIN", c, parm->szTitle, parm->szCategory);
80
                // simplealert(debug);
80
                // simplealert(debug);
81
                // free(debug);
81
                // free(debug);
82
 
82
 
83
                // Use random AETE keys, because AppleScript has a global namespace
83
                // Use random AETE keys, because AppleScript has a global namespace
84
                // and therefore requires unique AETE keys
84
                // and therefore requires unique AETE keys
85
                data = (char*)malloc(0x300);
85
                data = (char*)malloc(0x300);
86
                if (!data) return 0;
86
                if (!data) return 0;
87
                sprintf(data, "%s %s %c",
87
                sprintf(data, "%s %s %c",
88
                        parm->szCategory,
88
                        parm->szCategory,
89
                        parm->szTitle,
89
                        parm->szTitle,
90
                        c);
90
                        c);
91
                hash = printablehash(djb2(data));
91
                hash = printablehash(djb2(data));
92
                free(data);
92
                free(data);
93
                return hash;
93
                return hash;
94
        }
94
        }
95
        else {
95
        else {
96
                // char* debug = (char*)malloc(2000);
96
                // char* debug = (char*)malloc(2000);
97
                // sprintf(debug, "getAeteKey %c in MAIN PLUGIN", c);
97
                // sprintf(debug, "getAeteKey %c in MAIN PLUGIN", c);
98
                // simplealert(debug);
98
                // simplealert(debug);
99
                // free(debug);
99
                // free(debug);
100
 
100
 
101
                // Attention: AETE keys (xpr#, cTl#) must be equal in scripting.r, scripting.rc and scripting.c(getAeteKey)!
101
                // Attention: AETE keys (xpr#, cTl#) must be equal in scripting.r, scripting.rc and scripting.c(getAeteKey)!
102
                if (c == 'R') return 'xprR';
102
                if (c == 'R') return 'xprR';
103
                if (c == 'G') return 'xprG';
103
                if (c == 'G') return 'xprG';
104
                if (c == 'B') return 'xprB';
104
                if (c == 'B') return 'xprB';
105
                if (c == 'A') return 'xprA';
105
                if (c == 'A') return 'xprA';
106
                if ((c >= '0') && (c <= '9')) return 'cTl0' + (c - '0');
106
                if ((c >= '0') && (c <= '9')) return 'cTl0' + (c - '0');
107
                return 0;
107
                return 0;
108
        }
108
        }
109
}
109
}
110
 
110
 
111
/* return true if dialog should be shown */
111
/* return true if dialog should be shown */
112
enum ScriptingShowDialog ReadScriptParamsOnRead(void)
112
enum ScriptingShowDialog ReadScriptParamsOnRead(void)
113
{
113
{
114
        PIReadDescriptor token;
114
        PIReadDescriptor token;
115
        DescriptorKeyID key;
115
        DescriptorKeyID key;
116
        DescriptorTypeID type;
116
        DescriptorTypeID type;
117
        DescriptorKeyIDArray array = { NULLID };
117
        DescriptorKeyIDArray array = { NULLID };
118
        int32 flags;
118
        int32 flags;
119
        //OSErr stickyError;
119
        //OSErr stickyError;
120
        int32 v;
120
        int32 v;
121
 
121
 
122
        if (DescriptorAvailable(NULL)) { /* playing back.  Do our thing. */
122
        if (DescriptorAvailable(NULL)) { /* playing back.  Do our thing. */
123
                token = OpenReader(array);
123
                token = OpenReader(array);
124
                if (token) {
124
                if (token) {
125
                        while (PIGetKey(token, &key, &type, &flags)) {
125
                        while (PIGetKey(token, &key, &type, &flags)) {
126
                                if (key == getAeteKey('R', gdata->standalone ? &gdata->parm : NULL)) {
126
                                if (key == getAeteKey('R', gdata->parm.standalone ? &gdata->parm : NULL)) {
127
                                        if (expr[0]) free(expr[0]);
127
                                        char *tmp = get_cstring(token);
128
                                        expr[0] = get_cstring(token);
128
                                        strcpy(gdata->parm.szFormula[0], tmp);
-
 
129
                                        free(tmp);
129
                                }
130
                                }
130
                                else if (key == getAeteKey('G', gdata->standalone ? &gdata->parm : NULL)) {
131
                                else if (key == getAeteKey('G', gdata->parm.standalone ? &gdata->parm : NULL)) {
131
                                        if (expr[1]) free(expr[1]);
132
                                        char* tmp = get_cstring(token);
132
                                        expr[1] = get_cstring(token);
133
                                        strcpy(gdata->parm.szFormula[1], tmp);
-
 
134
                                        free(tmp);
133
                                }
135
                                }
134
                                else if (key == getAeteKey('B', gdata->standalone ? &gdata->parm : NULL)) {
136
                                else if (key == getAeteKey('B', gdata->parm.standalone ? &gdata->parm : NULL)) {
135
                                        if (expr[2]) free(expr[2]);
137
                                        char* tmp = get_cstring(token);
136
                                        expr[2] = get_cstring(token);
138
                                        strcpy(gdata->parm.szFormula[2], tmp);
-
 
139
                                        free(tmp);
137
                                }
140
                                }
138
                                else if (key == getAeteKey('A', gdata->standalone ? &gdata->parm : NULL)) {
141
                                else if (key == getAeteKey('A', gdata->parm.standalone ? &gdata->parm : NULL)) {
139
                                        if (expr[3]) free(expr[3]);
142
                                        char* tmp = get_cstring(token);
140
                                        expr[3] = get_cstring(token);
143
                                        strcpy(gdata->parm.szFormula[3], tmp);
-
 
144
                                        free(tmp);
141
                                }
145
                                }
142
                                else {
146
                                else {
143
                                        int i;
147
                                        int i;
144
                                        for (i = 0; i <= 7; ++i) {
148
                                        for (i = 0; i <= 7; ++i) {
145
                                                if (key == getAeteKey((char)('0'+i), gdata->standalone ? &gdata->parm : NULL)) {
149
                                                if (key == getAeteKey((char)('0'+i), gdata->parm.standalone ? &gdata->parm : NULL)) {
146
                                                        PIGetInt(token, &v);
150
                                                        PIGetInt(token, &v);
147
                                                        if (v < 0) v = 0;
151
                                                        if (v < 0) v = 0;
148
                                                        else if (v > 255) v = 255;
152
                                                        else if (v > 255) v = 255;
149
                                                        slider[i] = (uint8_t)v;
153
                                                        gdata->parm.val[i] = (uint8_t)v;
150
                                                }
154
                                                }
151
                                        }
155
                                        }
152
                                }
156
                                }
153
                        }
157
                        }
154
 
158
 
155
                        /*stickyError =*/ CloseReader(&token); // closes & disposes.
159
                        /*stickyError =*/ CloseReader(&token); // closes & disposes.
156
 
160
 
157
                        // all Filter Foundry parameters are optional,
161
                        // all Filter Foundry parameters are optional,
158
                        // so we needn't worry if any are missing
162
                        // so we needn't worry if any are missing
159
                }
163
                }
160
 
164
 
161
                return gpb->descriptorParameters->playInfo == plugInDialogDisplay ? SCR_SHOW_DIALOG : SCR_HIDE_DIALOG;
165
                return gpb->descriptorParameters->playInfo == plugInDialogDisplay ? SCR_SHOW_DIALOG : SCR_HIDE_DIALOG;
162
        }
166
        }
163
        else {
167
        else {
164
                return SCR_NO_SCRIPT;
168
                return SCR_NO_SCRIPT;
165
        }
169
        }
166
}
170
}
167
 
171
 
168
OSErr WriteScriptParamsOnRead(void)
172
OSErr WriteScriptParamsOnRead(void)
169
{
173
{
170
        PIWriteDescriptor token;
174
        PIWriteDescriptor token;
171
        OSErr gotErr = noErr;
175
        OSErr gotErr = noErr;
172
        extern int ctls[], maps[], nplanes;
176
        extern int nplanes;
173
        int i, allctls;
177
        int i, allctls;
174
 
178
 
175
        if (DescriptorAvailable(NULL)) { /* recording.  Do our thing. */
179
        if (DescriptorAvailable(NULL)) { /* recording.  Do our thing. */
176
                // 1. Call openWriteDescriptorProc which will return a PIWriteDescriptor token, such as writeToken.
180
                // 1. Call openWriteDescriptorProc which will return a PIWriteDescriptor token, such as writeToken.
177
                token = OpenWriter();
181
                token = OpenWriter();
178
                if (token) {
182
                if (token) {
179
                        // 2. Call various Put routines such as PutIntegerProc, PutFloatProc, etc., to add key/value pairs to writeToken. The keys and value types must correspond to those in your terminology resource.
183
                        // 2. Call various Put routines such as PutIntegerProc, PutFloatProc, etc., to add key/value pairs to writeToken. The keys and value types must correspond to those in your terminology resource.
180
 
184
 
181
                        // write keys here
185
                        // write keys here
182
                        if (!gdata->standalone) {
186
                        if (!gdata->parm.standalone) {
183
                                if (nplanes > 0) put_cstring(token, getAeteKey('R', gdata->standalone ? &gdata->parm : NULL), expr[0]);
187
                                if (nplanes > 0) put_cstring(token, getAeteKey('R', gdata->parm.standalone ? &gdata->parm : NULL), gdata->parm.szFormula[0]);
184
                                if (nplanes > 1) put_cstring(token, getAeteKey('G', gdata->standalone ? &gdata->parm : NULL), expr[1]);
188
                                if (nplanes > 1) put_cstring(token, getAeteKey('G', gdata->parm.standalone ? &gdata->parm : NULL), gdata->parm.szFormula[1]);
185
                                if (nplanes > 2) put_cstring(token, getAeteKey('B', gdata->standalone ? &gdata->parm : NULL), expr[2]);
189
                                if (nplanes > 2) put_cstring(token, getAeteKey('B', gdata->parm.standalone ? &gdata->parm : NULL), gdata->parm.szFormula[2]);
186
                                if (nplanes > 3) put_cstring(token, getAeteKey('A', gdata->standalone ? &gdata->parm : NULL), expr[3]);
190
                                if (nplanes > 3) put_cstring(token, getAeteKey('A', gdata->parm.standalone ? &gdata->parm : NULL), gdata->parm.szFormula[3]);
187
                        }
191
                        }
188
 
192
 
189
                        /* only write values for the sliders that are actually used! */
193
                        /* only write values for the sliders that are actually used! */
190
                        allctls = checksliders(4, ctls, maps);
194
                        allctls = checksliders(4);
191
                        for (i = 0; i <= 7; ++i) {
195
                        for (i = 0; i < 8; ++i) {
192
                                if (allctls || ctls[i]) {
196
                                if (allctls || gdata->parm.ctl_used[i]) {
193
                                        PIPutInt(token, getAeteKey((char)('0'+i), gdata->standalone ? &gdata->parm : NULL), slider[i]);
197
                                        PIPutInt(token, getAeteKey((char)('0'+i), gdata->parm.standalone ? &gdata->parm : NULL), gdata->parm.val[i]);
194
                                }
198
                                }
195
                        }
199
                        }
196
 
200
 
197
                        gotErr = CloseWriter(&token); /* closes and sets dialog optional */
201
                        gotErr = CloseWriter(&token); /* closes and sets dialog optional */
198
                        /* done.  Now pass handle on to Photoshop */
202
                        /* done.  Now pass handle on to Photoshop */
199
                }
203
                }
200
        }
204
        }
201
        return gotErr;
205
        return gotErr;
202
}
206
}
203
 
207
 
204
 
208
 
205
//-------------------------------------------------------------------------------
209
//-------------------------------------------------------------------------------
206
//
210
//
207
//      HostDescriptorAvailable
211
//      HostDescriptorAvailable
208
//
212
//
209
//      Determines whether the PIDescriptorParameters callback is available.
213
//      Determines whether the PIDescriptorParameters callback is available.
210
//
214
//
211
//      Check for valid suite version, routine suite version, and routine count.
215
//      Check for valid suite version, routine suite version, and routine count.
212
//      Also check that the subset of routines we actually use is actually present.
216
//      Also check that the subset of routines we actually use is actually present.
213
//
217
//
214
//-------------------------------------------------------------------------------
218
//-------------------------------------------------------------------------------
215
 
219
 
216
Boolean HostDescriptorAvailable(PIDescriptorParameters* procs, Boolean* outNewerVersion)
220
Boolean HostDescriptorAvailable(PIDescriptorParameters* procs, Boolean* outNewerVersion)
217
{
221
{
218
        if (procs == NULL) return FALSE; // Photoshop < 4.0 don't has scripting
222
        if (procs == NULL) return FALSE; // Photoshop < 4.0 don't has scripting
219
 
223
 
220
        if (outNewerVersion)
224
        if (outNewerVersion)
221
                *outNewerVersion = procs->descriptorParametersVersion > kCurrentDescriptorParametersVersion
225
                *outNewerVersion = procs->descriptorParametersVersion > kCurrentDescriptorParametersVersion
222
                || procs->readDescriptorProcs->readDescriptorProcsVersion > kCurrentReadDescriptorProcsVersion
226
                || procs->readDescriptorProcs->readDescriptorProcsVersion > kCurrentReadDescriptorProcsVersion
223
                || procs->writeDescriptorProcs->writeDescriptorProcsVersion > kCurrentWriteDescriptorProcsVersion;
227
                || procs->writeDescriptorProcs->writeDescriptorProcsVersion > kCurrentWriteDescriptorProcsVersion;
224
 
228
 
225
        return procs != NULL
229
        return procs != NULL
226
                && procs->descriptorParametersVersion == kCurrentDescriptorParametersVersion
230
                && procs->descriptorParametersVersion == kCurrentDescriptorParametersVersion
227
 
231
 
228
                && procs->readDescriptorProcs != NULL
232
                && procs->readDescriptorProcs != NULL
229
                && procs->readDescriptorProcs->readDescriptorProcsVersion == kCurrentReadDescriptorProcsVersion
233
                && procs->readDescriptorProcs->readDescriptorProcsVersion == kCurrentReadDescriptorProcsVersion
230
                && (unsigned int)(procs->readDescriptorProcs->numReadDescriptorProcs) >= kCurrentReadDescriptorProcsCount
234
                && (unsigned int)(procs->readDescriptorProcs->numReadDescriptorProcs) >= kCurrentReadDescriptorProcsCount
231
                && procs->readDescriptorProcs->openReadDescriptorProc != NULL
235
                && procs->readDescriptorProcs->openReadDescriptorProc != NULL
232
                && procs->readDescriptorProcs->closeReadDescriptorProc != NULL
236
                && procs->readDescriptorProcs->closeReadDescriptorProc != NULL
233
                && procs->readDescriptorProcs->getKeyProc != NULL
237
                && procs->readDescriptorProcs->getKeyProc != NULL
234
                && procs->readDescriptorProcs->getTextProc != NULL
238
                && procs->readDescriptorProcs->getTextProc != NULL
235
                && procs->readDescriptorProcs->getIntegerProc != NULL
239
                && procs->readDescriptorProcs->getIntegerProc != NULL
236
 
240
 
237
                && procs->writeDescriptorProcs != NULL
241
                && procs->writeDescriptorProcs != NULL
238
                && procs->writeDescriptorProcs->writeDescriptorProcsVersion == kCurrentWriteDescriptorProcsVersion
242
                && procs->writeDescriptorProcs->writeDescriptorProcsVersion == kCurrentWriteDescriptorProcsVersion
239
                && (unsigned int)(procs->writeDescriptorProcs->numWriteDescriptorProcs) >= kCurrentWriteDescriptorProcsCount
243
                && (unsigned int)(procs->writeDescriptorProcs->numWriteDescriptorProcs) >= kCurrentWriteDescriptorProcsCount
240
                && procs->writeDescriptorProcs->openWriteDescriptorProc != NULL
244
                && procs->writeDescriptorProcs->openWriteDescriptorProc != NULL
241
                && procs->writeDescriptorProcs->closeWriteDescriptorProc != NULL
245
                && procs->writeDescriptorProcs->closeWriteDescriptorProc != NULL
242
                && procs->writeDescriptorProcs->putTextProc != NULL
246
                && procs->writeDescriptorProcs->putTextProc != NULL
243
                && procs->writeDescriptorProcs->putIntegerProc != NULL;
247
                && procs->writeDescriptorProcs->putIntegerProc != NULL;
244
}
248
}
245
 
249
 
246
 
250
 
247
//-------------------------------------------------------------------------------
251
//-------------------------------------------------------------------------------
248
//
252
//
249
//      HostCloseReader
253
//      HostCloseReader
250
//
254
//
251
//      Closes a read token, disposes its handle, sets the token to NULL, and
255
//      Closes a read token, disposes its handle, sets the token to NULL, and
252
//      sets the parameter blocks' descriptor to NULL.
256
//      sets the parameter blocks' descriptor to NULL.
253
//
257
//
254
//      The Descriptor Parameters suite are callbacks designed for
258
//      The Descriptor Parameters suite are callbacks designed for
255
//      scripting and automation.  See PIActions.h.
259
//      scripting and automation.  See PIActions.h.
256
//
260
//
257
//      Inputs:
261
//      Inputs:
258
//              PIDescriptorParameters *procs   Pointer to Descriptor Parameters suite.
262
//              PIDescriptorParameters *procs   Pointer to Descriptor Parameters suite.
259
//
263
//
260
//              HandleProcs *hProcs                             Pointer to HandleProcs callback.
264
//              HandleProcs *hProcs                             Pointer to HandleProcs callback.
261
//
265
//
262
//              PIReadDescriptor *token                 Pointer to token to close.
266
//              PIReadDescriptor *token                 Pointer to token to close.
263
//
267
//
264
//              procs->descriptor                               Pointer to original read handle.
268
//              procs->descriptor                               Pointer to original read handle.
265
//
269
//
266
//      Outputs:
270
//      Outputs:
267
//              PIReadDescriptor *token                 Set to NULL.
271
//              PIReadDescriptor *token                 Set to NULL.
268
//
272
//
269
//              procs->descriptor                               Disposed then set to NULL.
273
//              procs->descriptor                               Disposed then set to NULL.
270
//
274
//
271
//              returns OSErr                                   noErr or error if one occurred.
275
//              returns OSErr                                   noErr or error if one occurred.
272
//
276
//
273
//-------------------------------------------------------------------------------
277
//-------------------------------------------------------------------------------
274
 
278
 
275
OSErr HostCloseReader(PIDescriptorParameters* procs,
279
OSErr HostCloseReader(PIDescriptorParameters* procs,
276
        HandleProcs* hProcs,
280
        HandleProcs* hProcs,
277
        PIReadDescriptor* token)
281
        PIReadDescriptor* token)
278
{
282
{
279
        // Close token:
283
        // Close token:
280
        OSErr err = procs->readDescriptorProcs->closeReadDescriptorProc(*token);
284
        OSErr err = procs->readDescriptorProcs->closeReadDescriptorProc(*token);
281
 
285
 
282
        // Dispose the parameter block descriptor:
286
        // Dispose the parameter block descriptor:
283
        hProcs->disposeProc(procs->descriptor);
287
        hProcs->disposeProc(procs->descriptor);
284
 
288
 
285
        // Set the descriptor and the read token to NULL:
289
        // Set the descriptor and the read token to NULL:
286
        procs->descriptor = NULL;
290
        procs->descriptor = NULL;
287
        *token = NULL;
291
        *token = NULL;
288
 
292
 
289
        return err;
293
        return err;
290
 
294
 
291
} // end HostCloseReader
295
} // end HostCloseReader
292
 
296
 
293
//-------------------------------------------------------------------------------
297
//-------------------------------------------------------------------------------
294
//
298
//
295
//      HostCloseWriter
299
//      HostCloseWriter
296
//
300
//
297
//      Closes a write token, stores its handle in the global parameter block for
301
//      Closes a write token, stores its handle in the global parameter block for
298
//      the host to use, sets the token to NULL, and sets the recordInfo to
302
//      the host to use, sets the token to NULL, and sets the recordInfo to
299
//      plugInDialogOptional (the default).
303
//      plugInDialogOptional (the default).
300
//
304
//
301
//      The Descriptor Parameters suite are callbacks designed for
305
//      The Descriptor Parameters suite are callbacks designed for
302
//      scripting and automation.  See PIActions.h.
306
//      scripting and automation.  See PIActions.h.
303
//
307
//
304
//      Inputs:
308
//      Inputs:
305
//              PIDescriptorParameters *procs   Pointer to Descriptor Parameters suite.
309
//              PIDescriptorParameters *procs   Pointer to Descriptor Parameters suite.
306
//
310
//
307
//              HandleProcs *hProcs                             Pointer to HandleProcs callback.
311
//              HandleProcs *hProcs                             Pointer to HandleProcs callback.
308
//
312
//
309
//              PIWriteDescriptor *token                Pointer to token to close and pass on.
313
//              PIWriteDescriptor *token                Pointer to token to close and pass on.
310
//
314
//
311
//              procs->descriptor                               Should be NULL.  If not, its contents
315
//              procs->descriptor                               Should be NULL.  If not, its contents
312
//                                                                              will be disposed and replaced.
316
//                                                                              will be disposed and replaced.
313
//
317
//
314
//      Outputs:
318
//      Outputs:
315
//              PIWriteDescriptor *token                Set to NULL.
319
//              PIWriteDescriptor *token                Set to NULL.
316
//
320
//
317
//              procs->descriptor                               Set to descriptor handle.
321
//              procs->descriptor                               Set to descriptor handle.
318
//
322
//
319
//              returns OSErr                                   noErr or error if one occurred.
323
//              returns OSErr                                   noErr or error if one occurred.
320
//
324
//
321
//-------------------------------------------------------------------------------
325
//-------------------------------------------------------------------------------
322
 
326
 
323
OSErr   HostCloseWriter(PIDescriptorParameters* procs,
327
OSErr   HostCloseWriter(PIDescriptorParameters* procs,
324
        HandleProcs* hProcs,
328
        HandleProcs* hProcs,
325
        PIWriteDescriptor* token)
329
        PIWriteDescriptor* token)
326
{
330
{
327
        OSErr err = noErr; // assume no error
331
        OSErr err = noErr; // assume no error
328
        PIDescriptorHandle h = NULL;
332
        PIDescriptorHandle h = NULL;
329
 
333
 
330
        if (procs->descriptor != NULL) // don't need descriptor passed to us
334
        if (procs->descriptor != NULL) // don't need descriptor passed to us
331
                hProcs->disposeProc(procs->descriptor); // dispose.
335
                hProcs->disposeProc(procs->descriptor); // dispose.
332
 
336
 
333
        // 3. Call CloseWriteDescriptorProc with writeToken, which will create a PIDescriptorHandle.
337
        // 3. Call CloseWriteDescriptorProc with writeToken, which will create a PIDescriptorHandle.
334
        procs->writeDescriptorProcs->closeWriteDescriptorProc(*token, &h);
338
        procs->writeDescriptorProcs->closeWriteDescriptorProc(*token, &h);
335
 
339
 
336
        // 4. Place the PIDescriptorHandle into the descriptor field. The host will dispose of it when finished.
340
        // 4. Place the PIDescriptorHandle into the descriptor field. The host will dispose of it when finished.
337
        procs->descriptor = h;
341
        procs->descriptor = h;
338
 
342
 
339
        // 5. Set recordInfo.  Options are: plugInDialogOptional,
343
        // 5. Set recordInfo.  Options are: plugInDialogOptional,
340
        // plugInDialogRequire, plugInDialogNone:
344
        // plugInDialogRequire, plugInDialogNone:
341
        procs->recordInfo = plugInDialogOptional;
345
        procs->recordInfo = plugInDialogOptional;
342
 
346
 
343
        *token = NULL;
347
        *token = NULL;
344
 
348
 
345
        return err;
349
        return err;
346
 
350
 
347
} // end HostCloseWriter
351
} // end HostCloseWriter
348
 
352