Subversion Repositories filter_foundry

Rev

Rev 206 | Rev 393 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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