Subversion Repositories filter_foundry

Rev

Rev 206 | Rev 393 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 206 Rev 259
Line 1... Line 1...
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.com.au
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
4
    Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft
4
    Copyright (C) 2018-2021 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
#include <controls.h>
21
#include <controls.h>
22
#include <controldefinitions.h>
22
#include <controldefinitions.h>
23
#include <dialogs.h>
23
#include <dialogs.h>
24
#include <resources.h>
24
#include <resources.h>
25
#include <textutils.h>
25
#include <textutils.h>
26
 
26
 
27
#include "str.h"
27
#include "str.h"
28
 
28
 
29
#include "ff.h"
29
#include "ff.h"
30
 
30
 
31
extern Point preview_scroll;
31
extern Point preview_scroll;
32
 
32
 
33
CursHandle handcursor,ibeamcursor;
33
CursHandle handcursor,ibeamcursor;
34
ControlActionUPP action_UPP,indaction_UPP;
34
ControlActionUPP action_UPP,indaction_UPP;
35
DIALOGREF thedialog;
35
DIALOGREF thedialog;
36
ControlRef exprctls[4];
36
ControlRef exprctls[4];
37
int trackingitem;
37
int trackingitem;
38
 
38
 
39
pascal void preview_item(DialogRef dp,DialogItemIndex item);
39
pascal void preview_item(DialogRef dp,DialogItemIndex item);
40
pascal void slideraction(ControlRef theControl,short partCode);
40
pascal void slideraction(ControlRef theControl,short partCode);
41
pascal Boolean sliderfilter(DialogRef dialog,EventRecord *event,short *item);
41
pascal Boolean sliderfilter(DialogRef dialog,EventRecord *event,short *item);
42
 
42
 
43
void DoAbout(AboutRecordPtr prec){
43
void DoAbout(AboutRecordPtr prec){
44
        ModalFilterUPP filterproc_UPP = NewModalFilterUPP(aboutfilter);
44
        ModalFilterUPP filterproc_UPP = NewModalFilterUPP(aboutfilter);
45
 
45
 
46
        if(gdata && gdata->standalone){
46
        if(gdata && gdata->standalone){
47
                ParamText(gdata->parm.title,gdata->parm.author,gdata->parm.copyright,NULL);
47
                ParamText(gdata->parm.title,gdata->parm.author,gdata->parm.copyright,NULL);
48
                Alert(ID_ABOUTSTANDALONEDLG,filterproc_UPP);
48
                Alert(ID_ABOUTSTANDALONEDLG,filterproc_UPP);
49
        }else
49
        }else
50
                Alert(ID_ABOUTDLG,filterproc_UPP);
50
                Alert(ID_ABOUTDLG,filterproc_UPP);
51
 
51
 
52
        DisposeModalFilterUPP(filterproc_UPP);
52
        DisposeModalFilterUPP(filterproc_UPP);
53
}
53
}
54
 
54
 
55
Boolean simplealert(char *s){
55
Boolean simplealert(char *s){
56
        int i;
56
        int i;
57
 
57
 
58
        myc2pstr(s);
58
        myc2pstr(s);
59
        ParamText((StringPtr)s,NULL,NULL,NULL);
59
        ParamText((StringPtr)s,NULL,NULL,NULL);
60
        i = StopAlert(ID_SYNTAXALERT,NULL);
60
        i = StopAlert(ID_SYNTAXALERT,NULL);
61
        myp2cstr((StringPtr)s);
61
        myp2cstr((StringPtr)s);
62
        return i == ok;
62
        return i == ok;
63
}
63
}
64
 
64
 
65
Boolean showmessage(char *s){
65
Boolean showmessage(char *s){
66
        int i;
66
        int i;
67
 
67
 
68
        myc2pstr(s);
68
        myc2pstr(s);
69
        ParamText((StringPtr)s,NULL,NULL,NULL);
69
        ParamText((StringPtr)s,NULL,NULL,NULL);
70
        i = Alert(ID_SYNTAXALERT,NULL);
70
        i = Alert(ID_SYNTAXALERT,NULL);
71
        myp2cstr((StringPtr)s);
71
        myp2cstr((StringPtr)s);
72
        return i == ok;
72
        return i == ok;
73
}
73
}
74
 
74
 
75
/*
75
/*
76
    NOTE ON CONTROL ACTION PROCS
76
    NOTE ON CONTROL ACTION PROCS
77
 
77
 
78
    When using the TrackControl() call when tracking an indicator, the actionProc parameter
78
    When using the TrackControl() call when tracking an indicator, the actionProc parameter
79
    (type ControlActionUPP) should be replaced by a parameter of type DragGrayRgnUPP
79
    (type ControlActionUPP) should be replaced by a parameter of type DragGrayRgnUPP
80
    (see Quickdraw.h).
80
    (see Quickdraw.h).
81
 
81
 
82
    If, however, you are using the live feedback variants of scroll bars or sliders, you
82
    If, however, you are using the live feedback variants of scroll bars or sliders, you
83
    must pass a ControlActionUPP in when tracking the indicator as well. This functionality
83
    must pass a ControlActionUPP in when tracking the indicator as well. This functionality
84
    is available in Appearance 1.0 or later.
84
    is available in Appearance 1.0 or later.
85
*/
85
*/
86
 
86
 
87
pascal void slideraction(ControlRef theControl,short partCode){
87
pascal void slideraction(ControlRef theControl,short partCode){
88
        int old,delta = 0;
88
        int old,delta = 0;
89
 
89
 
90
        ENTERCALLBACK();
90
        ENTERCALLBACK();
91
 
91
 
92
        if(partCode){
92
        if(partCode){
93
                if(partCode != kControlIndicatorPart){
93
                if(partCode != kControlIndicatorPart){
94
                        switch(partCode){
94
                        switch(partCode){
95
                        case kControlUpButtonPart:   delta = -1; break;
95
                        case kControlUpButtonPart:   delta = -1; break;
96
                        case kControlDownButtonPart: delta = 1; break;
96
                        case kControlDownButtonPart: delta = 1; break;
97
                        case kControlPageUpPart:     delta = -SLIDERPAGE; break;
97
                        case kControlPageUpPart:     delta = -SLIDERPAGE; break;
98
                        case kControlPageDownPart:   delta = SLIDERPAGE; break;
98
                        case kControlPageDownPart:   delta = SLIDERPAGE; break;
99
                        }
99
                        }
100
                        SetControlValue(theControl,(old = GetControlValue(theControl)) + delta);
100
                        SetControlValue(theControl,(old = GetControlValue(theControl)) + delta);
101
                }
101
                }
102
                slidermoved(thedialog,trackingitem);
102
                slidermoved(thedialog,trackingitem);
103
                recalc_preview(gpb,thedialog);
103
                recalc_preview(gpb,thedialog);
104
        }
104
        }
105
 
105
 
106
        EXITCALLBACK();
106
        EXITCALLBACK();
107
}
107
}
108
 
108
 
109
pascal Boolean sliderfilter(DialogRef dialog,EventRecord *event,short *item){
109
pascal Boolean sliderfilter(DialogRef dialog,EventRecord *event,short *item){
110
        int i;
110
        int i;
111
        short part;
111
        short part;
112
        ControlHandle c;
112
        ControlHandle c;
113
        Point pt,origscroll,newscroll;
113
        Point pt,origscroll,newscroll;
114
        Boolean result = false,f;
114
        Boolean result = false,f;
115
        EventRecord ev;
115
        EventRecord ev;
116
        GrafPtr oldport;
116
        GrafPtr oldport;
117
        ControlRef focus;
117
        ControlRef focus;
118
 
118
 
119
        ENTERCALLBACK();
119
        ENTERCALLBACK();
120
 
120
 
121
        GetPort(&oldport);
121
        GetPort(&oldport);
122
        SetPortDialogPort(dialog);
122
        SetPortDialogPort(dialog);
123
 
123
 
124
/* !(result = standardfilter(dialog,event,item)) && */
124
/* !(result = standardfilter(dialog,event,item)) && */
125
 
125
 
126
        if( !event->what || (event->what == updateEvt
126
        if( !event->what || (event->what == updateEvt
127
                                                 && (WindowRef)event->message != GetDialogWindow(dialog)) )
127
                                                 && (WindowRef)event->message != GetDialogWindow(dialog)) )
128
        {       // pass null events and update events to Photoshop
128
        {       // pass null events and update events to Photoshop
129
                gpb->processEvent(event);
129
                gpb->processEvent(event);
130
        }
130
        }
131
        else if(event->what == mouseDown){
131
        else if(event->what == mouseDown){
132
 
132
 
133
                pt = event->where;
133
                pt = event->where;
134
                GlobalToLocal(&pt);
134
                GlobalToLocal(&pt);
135
 
135
 
136
                i = trackingitem = FindDialogItem(dialog,pt)+1;
136
                i = trackingitem = FindDialogItem(dialog,pt)+1;
137
/*                      if( (c = FindControlUnderMouse(pt,GetDialogWindow(dialog),&part))
137
/*                      if( (c = FindControlUnderMouse(pt,GetDialogWindow(dialog),&part))
138
                                        && part && HandleControlClick(c,pt,event->modifiers,action_UPP) )*/
138
                                        && part && HandleControlClick(c,pt,event->modifiers,action_UPP) )*/
139
                if( i>=FIRSTCTLITEM && i<=FIRSTCTLITEM+7
139
                if( i>=FIRSTCTLITEM && i<=FIRSTCTLITEM+7
140
                                && (part = FindControl(pt,GetDialogWindow(dialog),&c))
140
                                && (part = FindControl(pt,GetDialogWindow(dialog),&c))
141
                                && TrackControl(c,pt,action_UPP) ){
141
                                && TrackControl(c,pt,action_UPP) ){
142
                        *item = i;
142
                        *item = i;
143
                        result = true;
143
                        result = true;
144
                }else if(i == PREVIEWITEM){
144
                }else if(i == PREVIEWITEM){
145
                        SetCursor(*handcursor);
145
                        SetCursor(*handcursor);
146
                        origscroll = preview_scroll;
146
                        origscroll = preview_scroll;
147
                        do{
147
                        do{
148
                                f = WaitNextEvent(mUpMask,&ev,5,NULL);
148
                                f = WaitNextEvent(mUpMask,&ev,5,NULL);
149
                                newscroll.h = origscroll.h - zoomfactor*(ev.where.h - event->where.h);
149
                                newscroll.h = origscroll.h - zoomfactor*(ev.where.h - event->where.h);
150
                                newscroll.v = origscroll.v - zoomfactor*(ev.where.v - event->where.v);
150
                                newscroll.v = origscroll.v - zoomfactor*(ev.where.v - event->where.v);
151
                                if(!EqualPt(newscroll,preview_scroll)){
151
                                if(!EqualPt(newscroll,preview_scroll)){
152
                                        preview_scroll = newscroll;
152
                                        preview_scroll = newscroll;
153
                                        recalc_preview(gpb,dialog);
153
                                        recalc_preview(gpb,dialog);
154
                                }
154
                                }
155
                        }while(!f);
155
                        }while(!f);
156
 
156
 
157
                        *item = i;
157
                        *item = i;
158
                        result = true;
158
                        result = true;
159
                }
159
                }
160
 
160
 
161
        }
161
        }
162
        else{
162
        else{
163
                GetKeyboardFocus(GetDialogWindow(dialog),&focus);
163
                GetKeyboardFocus(GetDialogWindow(dialog),&focus);
164
                /* handle return keypresses */
164
                /* handle return keypresses */
165
                if( event->what == keyDown && (char)event->message == CR
165
                if( event->what == keyDown && (char)event->message == CR
166
                                && ( focus==exprctls[0] || focus==exprctls[1]
166
                                && ( focus==exprctls[0] || focus==exprctls[1]
167
                                  || focus==exprctls[2] || focus==exprctls[3] ) )
167
                                  || focus==exprctls[2] || focus==exprctls[3] ) )
168
                        result = false;
168
                        result = false;
169
                else
169
                else
170
                        result = StdFilterProc(dialog,event,item);
170
                        result = StdFilterProc(dialog,event,item);
171
        }
171
        }
172
 
172
 
173
        SetPort(oldport);
173
        SetPort(oldport);
174
 
174
 
175
        EXITCALLBACK();
175
        EXITCALLBACK();
176
 
176
 
177
        return(result);
177
        return(result);
178
}
178
}
179
 
179
 
180
Boolean maindialog(FilterRecordPtr pb){
180
Boolean maindialog(FilterRecordPtr pb){
181
        short itemType, item;
181
        short itemType, item;
182
        Handle itemHdl;
182
        Handle itemHdl;
183
        DIALOGREF dp;
183
        DIALOGREF dp;
184
        int i;
184
        int i;
185
        UserItemUPP preview_image_UPP = NewUserItemUPP(preview_item);
185
        UserItemUPP preview_image_UPP = NewUserItemUPP(preview_item);
186
        ModalFilterUPP sliderfilter_UPP = NewModalFilterUPP(sliderfilter);
186
        ModalFilterUPP sliderfilter_UPP = NewModalFilterUPP(sliderfilter);
187
 
187
 
188
        action_UPP = NewControlActionUPP(slideraction);
188
        action_UPP = NewControlActionUPP(slideraction);
189
 
189
 
190
        dp = thedialog = GetNewDialog(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG,nil,(WindowPtr)-1);
190
        dp = thedialog = GetNewDialog(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG,nil,(WindowPtr)-1);
191
 
191
 
192
        if(gdata->standalone)
192
        if(gdata->standalone)
193
                SetWTitle(GetDialogWindow(dp),gdata->parm.title);
193
                SetWTitle(GetDialogWindow(dp),gdata->parm.title);
194
 
194
 
195
        GetDialogItem(dp,PREVIEWITEM,&itemType,&itemHdl,&preview_rect);
195
        GetDialogItem(dp,PREVIEWITEM,&itemType,&itemHdl,&preview_rect);
196
        SetDialogItem(dp,PREVIEWITEM,itemType,(Handle)preview_image_UPP,&preview_rect);
196
        SetDialogItem(dp,PREVIEWITEM,itemType,(Handle)preview_image_UPP,&preview_rect);
197
        handcursor = GetCursor(ID_HANDCURSOR);
197
        handcursor = GetCursor(ID_HANDCURSOR);
198
        ibeamcursor = GetCursor(iBeamCursor);
198
        ibeamcursor = GetCursor(iBeamCursor);
199
 
199
 
200
        SetDialogDefaultItem(dp,ok);
200
        SetDialogDefaultItem(dp,ok);
201
        SetDialogCancelItem(dp,cancel);
201
        SetDialogCancelItem(dp,cancel);
202
        SetDialogTracksCursor(dp,true);
202
        SetDialogTracksCursor(dp,true);
203
 
203
 
204
        if(!gdata->standalone)
204
        if(!gdata->standalone)
205
                for(i = 0; i < 4; ++i)
205
                for(i = 0; i < 4; ++i)
206
                        GetDialogItemAsControl(dp,FIRSTEXPRITEM+i,&exprctls[i]);
206
                        GetDialogItemAsControl(dp,FIRSTEXPRITEM+i,&exprctls[i]);
207
 
207
 
208
        maindlginit(dp);
208
        maindlginit(dp);
209
        do{
209
        do{
210
                InitCursor();
210
                InitCursor();
211
                ModalDialog(sliderfilter_UPP,&item);
211
                ModalDialog(sliderfilter_UPP,&item);
212
        }while(maindlgitem(dp,item));
212
        }while(maindlgitem(dp,item));
213
 
213
 
214
        DisposeDialog(dp);
214
        DisposeDialog(dp);
215
 
215
 
216
        DisposeUserItemUPP(preview_image_UPP);
216
        DisposeUserItemUPP(preview_image_UPP);
217
        DisposeModalFilterUPP(sliderfilter_UPP);
217
        DisposeModalFilterUPP(sliderfilter_UPP);
218
        DisposeControlActionUPP(action_UPP);
218
        DisposeControlActionUPP(action_UPP);
219
 
219
 
220
        return item == ok;
220
        return item == ok;
221
}
221
}
222
 
222
 
223
Boolean builddialog(FilterRecordPtr pb){
223
Boolean builddialog(FilterRecordPtr pb){
224
        short item;
224
        short item;
225
        DIALOGREF dp;
225
        DIALOGREF dp;
226
 
226
 
227
        dp = thedialog = GetNewDialog(ID_BUILDDLG,nil,(WindowPtr)-1);
227
        dp = thedialog = GetNewDialog(ID_BUILDDLG,nil,(WindowPtr)-1);
228
 
228
 
229
        SetDialogDefaultItem(dp,ok);
229
        SetDialogDefaultItem(dp,ok);
230
        SetDialogCancelItem(dp,cancel);
230
        SetDialogCancelItem(dp,cancel);
231
 
231
 
232
        builddlginit(dp);
232
        builddlginit(dp);
233
        do{
233
        do{
234
                ModalDialog(NULL,&item);
234
                ModalDialog(NULL,&item);
235
        }while(builddlgitem(dp,item));
235
        }while(builddlgitem(dp,item));
236
 
236
 
237
        DisposeDialog(dp);
237
        DisposeDialog(dp);
238
 
238
 
239
        return item == ok;
239
        return item == ok;
240
}
240
}