Subversion Repositories filter_foundry

Rev

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