Subversion Repositories filter_foundry

Rev

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

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