Rev 193 | Rev 268 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 193 | Rev 259 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | This file is part of a common library for Adobe(R) plugins |
2 | This file is part of a common library for Adobe(R) plugins |
3 | Copyright (C) 2002-2010 Toby Thain, toby@telegraphics.com.au |
3 | Copyright (C) 2002-2010 Toby Thain, toby@telegraphics.com.au |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify |
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 |
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 |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License |
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 |
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 |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
18 | */ |
19 | 19 | ||
20 | /* Mac user interface routines */ |
20 | /* Mac user interface routines */ |
21 | 21 | ||
22 | #ifndef __x86_64__ |
22 | #ifndef __x86_64__ |
23 | 23 | ||
24 | #include <string.h> |
24 | #include <string.h> |
25 | #include <stdlib.h> |
25 | #include <stdlib.h> |
26 | 26 | ||
27 | #include <NumberFormatting.h> |
27 | #include <NumberFormatting.h> |
28 | #include <controls.h> |
28 | #include <controls.h> |
29 | #include <controldefinitions.h> |
29 | #include <controldefinitions.h> |
30 | 30 | ||
31 | #include "world.h" |
31 | #include "world.h" |
32 | #include "ui_compat.h" |
32 | #include "ui_compat.h" |
33 | #include "sprintf_tiny.h" |
33 | #include "sprintf_tiny.h" |
34 | 34 | ||
35 | /* #define DLGVARS \ |
35 | /* #define DLGVARS \ |
36 | short itemType;\ |
36 | short itemType;\ |
37 | Handle itemHdl;\ |
37 | Handle itemHdl;\ |
38 | Rect itemRect;\ |
38 | Rect itemRect;\ |
39 | Str255 itemStr;\ |
39 | Str255 itemStr;\ |
40 | long itemNum;*/ |
40 | long itemNum;*/ |
41 | 41 | ||
42 | Handle get_item_handle(DIALOGREF d,int i){ |
42 | Handle get_item_handle(DIALOGREF d,int i){ |
43 | short itemType; |
43 | short itemType; |
44 | Handle itemHdl; |
44 | Handle itemHdl; |
45 | Rect itemRect; |
45 | Rect itemRect; |
46 | 46 | ||
47 | GetDialogItem(d,i,&itemType,&itemHdl,&itemRect); |
47 | GetDialogItem(d,i,&itemType,&itemHdl,&itemRect); |
48 | return itemHdl; |
48 | return itemHdl; |
49 | } |
49 | } |
50 | 50 | ||
51 | long GetDlgItemText(DIALOGREF d,int i,char *s,long n){ |
51 | long GetDlgItemText(DIALOGREF d,int i,char *s,long n){ |
52 | Str255 itemStr; |
52 | Str255 itemStr; |
53 | long maxlen; |
53 | long maxlen; |
54 | 54 | ||
55 | --n; |
55 | --n; |
56 | GetDialogItemText(get_item_handle(d,i),itemStr); |
56 | GetDialogItemText(get_item_handle(d,i),itemStr); |
57 | maxlen = *itemStr > n ? n : *itemStr; |
57 | maxlen = *itemStr > n ? n : *itemStr; |
58 | memcpy(s,itemStr+1,maxlen); |
58 | memcpy(s,itemStr+1,maxlen); |
59 | s[maxlen] = 0; |
59 | s[maxlen] = 0; |
60 | return maxlen; |
60 | return maxlen; |
61 | } |
61 | } |
62 | 62 | ||
63 | long SetDlgItemText(DIALOGREF d,int i,char *s){ |
63 | long SetDlgItemText(DIALOGREF d,int i,char *s){ |
64 | Str255 itemStr; |
64 | Str255 itemStr; |
65 | long maxlen = strlen(s); |
65 | long maxlen = strlen(s); |
66 | 66 | ||
67 | if(maxlen>255) maxlen = 255; |
67 | if(maxlen>255) maxlen = 255; |
68 | memcpy(itemStr+1,s,maxlen); |
68 | memcpy(itemStr+1,s,maxlen); |
69 | *itemStr = maxlen; |
69 | *itemStr = maxlen; |
70 | SetDialogItemText(get_item_handle(d,i),itemStr); |
70 | SetDialogItemText(get_item_handle(d,i),itemStr); |
71 | return true; |
71 | return true; |
72 | } |
72 | } |
73 | 73 | ||
74 | void SetDlgControlValue(DIALOGREF d,int i,int v){ |
74 | void SetDlgControlValue(DIALOGREF d,int i,int v){ |
75 | ControlRef c; |
75 | ControlRef c; |
76 | 76 | ||
77 | GetDialogItemAsControl(d,i,&c); |
77 | GetDialogItemAsControl(d,i,&c); |
78 | SetControlValue(c,v); |
78 | SetControlValue(c,v); |
79 | } |
79 | } |
80 | 80 | ||
81 | int GetDlgControlValue(DIALOGREF d,int i){ |
81 | int GetDlgControlValue(DIALOGREF d,int i){ |
82 | ControlRef c; |
82 | ControlRef c; |
83 | 83 | ||
84 | GetDialogItemAsControl(d,i,&c); |
84 | GetDialogItemAsControl(d,i,&c); |
85 | return GetControlValue(c); |
85 | return GetControlValue(c); |
86 | } |
86 | } |
87 | 87 | ||
88 | void EnableDlgControl(DIALOGREF d,int i){ |
88 | void EnableDlgControl(DIALOGREF d,int i){ |
89 | ControlRef c; |
89 | ControlRef c; |
90 | 90 | ||
91 | GetDialogItemAsControl(d,i,&c); |
91 | GetDialogItemAsControl(d,i,&c); |
92 | HiliteControl(c,0); |
92 | HiliteControl(c,0); |
93 | } |
93 | } |
94 | void DisableDlgControl(DIALOGREF d,int i){ |
94 | void DisableDlgControl(DIALOGREF d,int i){ |
95 | ControlRef c; |
95 | ControlRef c; |
96 | 96 | ||
97 | GetDialogItemAsControl(d,i,&c); |
97 | GetDialogItemAsControl(d,i,&c); |
98 | HiliteControl(c,255); |
98 | HiliteControl(c,255); |
99 | } |
99 | } |
100 | Boolean SetDlgItemInt(DIALOGREF d,int i,long v,Boolean bsigned){ |
100 | Boolean SetDlgItemInt(DIALOGREF d,int i,long v,Boolean bsigned){ |
101 | Str255 s; |
101 | Str255 s; |
102 | 102 | ||
103 | NumToString(v,s); |
103 | NumToString(v,s); |
104 | SetDialogItemText(get_item_handle(d,i),s); |
104 | SetDialogItemText(get_item_handle(d,i),s); |
105 | return true; |
105 | return true; |
106 | } |
106 | } |
107 | long GetDlgItemInt(DIALOGREF d,int i,Boolean *presult,Boolean bsigned){ |
107 | long GetDlgItemInt(DIALOGREF d,int i,Boolean *presult,Boolean bsigned){ |
108 | Str255 s; |
108 | Str255 s; |
109 | long v; |
109 | long v; |
110 | 110 | ||
111 | GetDialogItemText(get_item_handle(d,i),s); |
111 | GetDialogItemText(get_item_handle(d,i),s); |
112 | StringToNum(s,&v); |
112 | StringToNum(s,&v); |
113 | if(presult) *presult = true; |
113 | if(presult) *presult = true; |
114 | return v; |
114 | return v; |
115 | } |
115 | } |
116 | 116 | ||
117 | Boolean newbitmap(BITMAPREF *pb, int depth, Rect *bounds){ |
117 | Boolean newbitmap(BITMAPREF *pb, int depth, Rect *bounds){ |
118 | OSErr e; |
118 | OSErr e; |
119 | 119 | ||
120 | if( ( *pb = (BITMAPREF)malloc(sizeof(**pb)) ) |
120 | if( ( *pb = (BITMAPREF)malloc(sizeof(**pb)) ) |
121 | && !(e = NewGWorld(&(*pb)->gw, depth, bounds, nil, nil, 0)) ) |
121 | && !(e = NewGWorld(&(*pb)->gw, depth, bounds, nil, nil, 0)) ) |
122 | { |
122 | { |
123 | (*pb)->pm = GetGWorldPixMap((*pb)->gw); |
123 | (*pb)->pm = GetGWorldPixMap((*pb)->gw); |
124 | return true; |
124 | return true; |
125 | } |
125 | } |
126 | return false; |
126 | return false; |
127 | } |
127 | } |
128 | 128 | ||
129 | void disposebitmap(BITMAPREF pb){ |
129 | void disposebitmap(BITMAPREF pb){ |
130 | if(pb){ |
130 | if(pb){ |
131 | DisposeGWorld(pb->gw); |
131 | DisposeGWorld(pb->gw); |
132 | free((char*)pb); |
132 | free((char*)pb); |
133 | } |
133 | } |
134 | } |
134 | } |
135 | 135 | ||
136 | //pascal Boolean aboutfilter(DialogRef dialog, EventRecord *event, DialogItemIndex *item){ |
136 | //pascal Boolean aboutfilter(DialogRef dialog, EventRecord *event, DialogItemIndex *item){ |
137 | pascal Boolean aboutfilter(DialogRef dialog, EventRecord *event, short *item){ |
137 | pascal Boolean aboutfilter(DialogRef dialog, EventRecord *event, short *item){ |
138 | Boolean result = false; |
138 | Boolean result = false; |
139 | 139 | ||
140 | ENTERCALLBACK(); // not strictly needed; we don't use globals here |
140 | ENTERCALLBACK(); // not strictly needed; we don't use globals here |
141 | 141 | ||
142 | if( event->what == mouseDown |
142 | if( event->what == mouseDown |
143 | || event->what == keyDown |
143 | || event->what == keyDown |
144 | || event->what == autoKey ){ |
144 | || event->what == autoKey ){ |
145 | *item = ok; |
145 | *item = ok; |
146 | result = true; |
146 | result = true; |
147 | } |
147 | } |
148 | 148 | ||
149 | EXITCALLBACK(); |
149 | EXITCALLBACK(); |
150 | 150 | ||
151 | return(result); |
151 | return(result); |
152 | } |
152 | } |
153 | pascal Boolean standardfilter(DialogRef dialog, EventRecord *event, short *item){ |
153 | pascal Boolean standardfilter(DialogRef dialog, EventRecord *event, short *item){ |
154 | Boolean result = false; |
154 | Boolean result = false; |
155 | char ch = event->message; |
155 | char ch = event->message; |
156 | 156 | ||
157 | ENTERCALLBACK(); // not strictly needed; we don't use globals here |
157 | ENTERCALLBACK(); // not strictly needed; we don't use globals here |
158 | 158 | ||
159 | if( event->what == keyDown ){ |
159 | if( event->what == keyDown ){ |
160 | if(ch == kEnterCharCode){ |
160 | if(ch == kEnterCharCode){ |
161 | *item = ok; |
161 | *item = ok; |
162 | result = true; |
162 | result = true; |
163 | }else if( ch == kEscapeCharCode || (ch=='.' && (event->modifiers & cmdKey)) ){ |
163 | }else if( ch == kEscapeCharCode || (ch=='.' && (event->modifiers & cmdKey)) ){ |
164 | *item = cancel; |
164 | *item = cancel; |
165 | result = true; |
165 | result = true; |
166 | } |
166 | } |
167 | } |
167 | } |
168 | 168 | ||
169 | EXITCALLBACK(); |
169 | EXITCALLBACK(); |
170 | 170 | ||
171 | return(result); |
171 | return(result); |
172 | } |
172 | } |
173 | #if !TARGET_CARBON |
173 | #if !TARGET_CARBON |
174 | OSStatus my_InvalWindowRect(WindowRef window,const Rect *bounds){ |
174 | OSStatus my_InvalWindowRect(WindowRef window,const Rect *bounds){ |
175 | GrafPtr port; |
175 | GrafPtr port; |
176 | 176 | ||
177 | GetPort(&port); |
177 | GetPort(&port); |
178 | SetPort(window); |
178 | SetPort(window); |
179 | InvalRect(bounds); |
179 | InvalRect(bounds); |
180 | SetPort(port); |
180 | SetPort(port); |
181 | return noErr; |
181 | return noErr; |
182 | } |
182 | } |
183 | #endif |
183 | #endif |
184 | 184 | ||
185 | //kControlEditTextPart,kControlEntireControl |
185 | //kControlEditTextPart,kControlEntireControl |
186 | long getctltext(DIALOGREF d,int i,char *s,long n){ |
186 | long getctltext(DIALOGREF d,int i,char *s,long n){ |
187 | ControlRef c;// = (ControlRef)get_item_handle(d,i); |
187 | ControlRef c;// = (ControlRef)get_item_handle(d,i); |
188 | Size actual,len; |
188 | Size actual,len; |
189 | 189 | ||
190 | if( !( GetDialogItemAsControl(d,i,&c) |
190 | if( !( GetDialogItemAsControl(d,i,&c) |
191 | || GetControlDataSize(c,kControlEditTextPart,kControlEditTextTextTag,&actual) ) ){ |
191 | || GetControlDataSize(c,kControlEditTextPart,kControlEditTextTextTag,&actual) ) ){ |
192 | --n; |
192 | --n; |
193 | len = n < actual ? n : actual; |
193 | len = n < actual ? n : actual; |
194 | if(!GetControlData(c,kControlEditTextPart,kControlEditTextTextTag,len,s,&actual)){ |
194 | if(!GetControlData(c,kControlEditTextPart,kControlEditTextTextTag,len,s,&actual)){ |
195 | s[len] = 0; |
195 | s[len] = 0; |
196 | return len; |
196 | return len; |
197 | } |
197 | } |
198 | } |
198 | } |
199 | dbg("getctltext failed"); |
199 | dbg("getctltext failed"); |
200 | return 0; |
200 | return 0; |
201 | } |
201 | } |
202 | 202 | ||
203 | long setctltext(DIALOGREF d,int i,char *s){ |
203 | long setctltext(DIALOGREF d,int i,char *s){ |
204 | ControlRef c;// = (ControlRef)get_item_handle(d,i); |
204 | ControlRef c;// = (ControlRef)get_item_handle(d,i); |
205 | 205 | ||
206 | Boolean res = !( GetDialogItemAsControl(d,i,&c) |
206 | Boolean res = !( GetDialogItemAsControl(d,i,&c) |
207 | || SetControlData(c,kControlEditTextPart,kControlEditTextTextTag,strlen(s),s) ); |
207 | || SetControlData(c,kControlEditTextPart,kControlEditTextTextTag,strlen(s),s) ); |
208 | if(res) Draw1Control(c); |
208 | if(res) Draw1Control(c); |
209 | else dbg("setctltext failed"); |
209 | else dbg("setctltext failed"); |
210 | return res; |
210 | return res; |
211 | } |
211 | } |
212 | 212 | ||
213 | long selectctltext(DIALOGREF d,int i,int start,int end){ |
213 | long selectctltext(DIALOGREF d,int i,int start,int end){ |
214 | ControlRef c; |
214 | ControlRef c; |
215 | ControlEditTextSelectionRec srec; |
215 | ControlEditTextSelectionRec srec; |
216 | 216 | ||
217 | srec.selStart = start; |
217 | srec.selStart = start; |
218 | srec.selEnd = end; |
218 | srec.selEnd = end; |
219 | 219 | ||
220 | return !( GetDialogItemAsControl(d,i,&c) |
220 | return !( GetDialogItemAsControl(d,i,&c) |
221 | || SetControlData(c,kControlEditTextPart,kControlEditTextSelectionTag,sizeof(srec),&srec) ); |
221 | || SetControlData(c,kControlEditTextPart,kControlEditTextSelectionTag,sizeof(srec),&srec) ); |
222 | } |
222 | } |
223 | Boolean setctltextint(DIALOGREF d,int i,long v,Boolean bsigned){ |
223 | Boolean setctltextint(DIALOGREF d,int i,long v,Boolean bsigned){ |
224 | ControlRef c; |
224 | ControlRef c; |
225 | Str255 s; |
225 | Str255 s; |
226 | 226 | ||
227 | NumToString(v,s); |
227 | NumToString(v,s); |
228 | if( !GetDialogItemAsControl(d,i,&c) ) |
228 | if( !GetDialogItemAsControl(d,i,&c) ) |
229 | SetControlData(c,kControlEditTextPart,kControlEditTextTextTag,*s,s+1); |
229 | SetControlData(c,kControlEditTextPart,kControlEditTextTextTag,*s,s+1); |
230 | Draw1Control(c); |
230 | Draw1Control(c); |
231 | return true; |
231 | return true; |
232 | } |
232 | } |
233 | long getctltextint(DIALOGREF d,int i,Boolean *presult,Boolean bsigned){ |
233 | long getctltextint(DIALOGREF d,int i,Boolean *presult,Boolean bsigned){ |
234 | ControlRef c; |
234 | ControlRef c; |
235 | Str255 s; |
235 | Str255 s; |
236 | long num; |
236 | long num; |
237 | Size actual; |
237 | Size actual; |
238 | 238 | ||
239 | if( !(GetDialogItemAsControl(d,i,&c) |
239 | if( !(GetDialogItemAsControl(d,i,&c) |
240 | ||GetControlDataSize(c,kControlEditTextPart,kControlEditTextTextTag,&actual) |
240 | ||GetControlDataSize(c,kControlEditTextPart,kControlEditTextTextTag,&actual) |
241 | ||GetControlData(c,kControlEditTextPart,kControlEditTextTextTag,actual,s+1,&actual)) ){ |
241 | ||GetControlData(c,kControlEditTextPart,kControlEditTextTextTag,actual,s+1,&actual)) ){ |
242 | *s = actual; |
242 | *s = actual; |
243 | StringToNum(s,&num); |
243 | StringToNum(s,&num); |
244 | if(presult) *presult = true; |
244 | if(presult) *presult = true; |
245 | return num; |
245 | return num; |
246 | } |
246 | } |
247 | if(presult) *presult = false; |
247 | if(presult) *presult = false; |
248 | return 0; |
248 | return 0; |
249 | } |
249 | } |
250 | 250 | ||
251 | void menuaddcstr(CTLREF c,char *s){ |
251 | void menuaddcstr(CTLREF c,char *s){ |
252 | Str255 pstr; |
252 | Str255 pstr; |
253 | MenuRef menu = GetControlPopupMenuHandle(c); |
253 | MenuRef menu = GetControlPopupMenuHandle(c); |
254 | 254 | ||
255 | myc2pstrcpy(pstr,s); |
255 | myc2pstrcpy(pstr,s); |
256 | 256 | ||
257 | /* doing it this way intentionally defeats meta-character processing in AppendMenu; |
257 | /* doing it this way intentionally defeats meta-character processing in AppendMenu; |
258 | see: http://developer.apple.com/qa/tb/tb56.html */ |
258 | see: http://developer.apple.com/qa/tb/tb56.html */ |
259 | 259 | ||
260 | AppendMenu(menu,(StringPtr)"\001X"); // Pascal string literal, normally "\pX", done like this for non-Apple compilers (mingw?) |
260 | AppendMenu(menu,(StringPtr)"\001X"); // Pascal string literal, normally "\pX", done like this for non-Apple compilers (mingw?) |
261 | SetMenuItemText(menu,CountMenuItems(menu),pstr); |
261 | SetMenuItemText(menu,CountMenuItems(menu),pstr); |
262 | } |
262 | } |
263 | 263 | ||
264 | #endif |
264 | #endif |
265 | 265 |