Subversion Repositories filter_foundry

Rev

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