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