Rev 95 | Rev 102 | 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); |
||
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 | |||
64 | /* |
||
65 | NOTE ON CONTROL ACTION PROCS |
||
66 | |||
67 | When using the TrackControl() call when tracking an indicator, the actionProc parameter |
||
68 | (type ControlActionUPP) should be replaced by a parameter of type DragGrayRgnUPP |
||
69 | (see Quickdraw.h). |
||
70 | |||
71 | If, however, you are using the live feedback variants of scroll bars or sliders, you |
||
72 | must pass a ControlActionUPP in when tracking the indicator as well. This functionality |
||
73 | is available in Appearance 1.0 or later. |
||
74 | */ |
||
75 | |||
76 | pascal void slideraction(ControlRef theControl,short partCode){ |
||
23 | toby | 77 | int old,delta = 0; |
2 | toby | 78 | |
79 | ENTERCALLBACK(); |
||
80 | |||
81 | if(partCode){ |
||
82 | if(partCode != kControlIndicatorPart){ |
||
83 | switch(partCode){ |
||
84 | case kControlUpButtonPart: delta = -1; break; |
||
85 | case kControlDownButtonPart: delta = 1; break; |
||
86 | case kControlPageUpPart: delta = -SLIDERPAGE; break; |
||
87 | case kControlPageDownPart: delta = SLIDERPAGE; break; |
||
88 | } |
||
89 | SetControlValue(theControl,(old = GetControlValue(theControl)) + delta); |
||
90 | } |
||
91 | slidermoved(thedialog,trackingitem); |
||
92 | recalc_preview(gpb,thedialog); |
||
93 | } |
||
94 | |||
95 | EXITCALLBACK(); |
||
96 | } |
||
97 | |||
98 | pascal Boolean sliderfilter(DialogRef dialog,EventRecord *event,short *item){ |
||
99 | int i; |
||
100 | short part; |
||
101 | ControlHandle c; |
||
102 | Point pt,origscroll,newscroll; |
||
103 | Boolean result = false,f; |
||
104 | EventRecord ev; |
||
105 | GrafPtr oldport; |
||
106 | ControlRef focus; |
||
107 | |||
108 | ENTERCALLBACK(); |
||
109 | |||
110 | GetPort(&oldport); |
||
111 | SetPortDialogPort(dialog); |
||
112 | |||
113 | /* !(result = standardfilter(dialog,event,item)) && */ |
||
114 | |||
95 | toby | 115 | if( !event->what || (event->what == updateEvt |
116 | && (WindowRef)event->message != GetDialogWindow(dialog)) ) |
||
117 | { // pass null events and update events to Photoshop |
||
2 | toby | 118 | gpb->processEvent(event); |
95 | toby | 119 | } |
120 | else if(event->what == mouseDown){ |
||
2 | toby | 121 | |
122 | pt = event->where; |
||
123 | GlobalToLocal(&pt); |
||
124 | |||
125 | i = trackingitem = FindDialogItem(dialog,pt)+1; |
||
126 | /* if( (c = FindControlUnderMouse(pt,GetDialogWindow(dialog),&part)) |
||
127 | && part && HandleControlClick(c,pt,event->modifiers,action_UPP) )*/ |
||
128 | if( i>=FIRSTCTLITEM && i<=FIRSTCTLITEM+7 |
||
129 | && (part = FindControl(pt,GetDialogWindow(dialog),&c)) |
||
130 | && TrackControl(c,pt,action_UPP) ){ |
||
131 | *item = i; |
||
132 | result = true; |
||
133 | }else if(i == PREVIEWITEM){ |
||
134 | SetCursor(*handcursor); |
||
135 | origscroll = preview_scroll; |
||
136 | do{ |
||
137 | f = WaitNextEvent(mUpMask,&ev,5,NULL); |
||
138 | newscroll.h = origscroll.h - zoomfactor*(ev.where.h - event->where.h); |
||
139 | newscroll.v = origscroll.v - zoomfactor*(ev.where.v - event->where.v); |
||
140 | if(!EqualPt(newscroll,preview_scroll)){ |
||
141 | preview_scroll = newscroll; |
||
142 | recalc_preview(gpb,dialog); |
||
143 | } |
||
144 | }while(!f); |
||
145 | |||
146 | *item = i; |
||
147 | result = true; |
||
148 | } |
||
149 | |||
95 | toby | 150 | } |
151 | else{ |
||
2 | toby | 152 | GetKeyboardFocus(GetDialogWindow(dialog),&focus); |
153 | /* handle return keypresses */ |
||
154 | if( event->what == keyDown && (char)event->message == CR |
||
155 | && ( focus==exprctls[0] || focus==exprctls[1] |
||
156 | || focus==exprctls[2] || focus==exprctls[3] ) ) |
||
157 | result = false; |
||
158 | else |
||
159 | result = StdFilterProc(dialog,event,item); |
||
160 | } |
||
161 | |||
162 | SetPort(oldport); |
||
163 | |||
164 | EXITCALLBACK(); |
||
165 | |||
166 | return(result); |
||
167 | } |
||
168 | |||
169 | Boolean maindialog(FilterRecordPtr pb){ |
||
98 | toby | 170 | short itemType, item; |
2 | toby | 171 | Handle itemHdl; |
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) |
||
98 | toby | 194 | for(i = 0; i < 4; ++i) |
2 | toby | 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 | } |