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