Subversion Repositories filter_foundry

Rev

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