2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
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.
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.
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
21 #import <UIKit/UIKit.h>
22 #include "PyrPrimitive.h"
23 #include "PyrObject.h"
24 #include "PyrKernel.h"
25 #include "PyrSymbol.h"
26 #include "VMGlobals.h"
30 #import "iPhoneSCGraphView.h"
31 #import "ChangeCounter.h"
33 #import "iPhoneSCNSWindow.h"
34 #import "iSCLangController.h"
35 //#import "SCTextView.h"
36 //#import "SCCocoaView.h"
38 extern ChangeCounter gUIChangeCounter;
39 //extern NSTextView* gPostView;
44 PyrSymbol *s_doaction;
45 PyrSymbol *s_didBecomeKey;
46 PyrSymbol *s_didResignKey;
48 extern bool docCreatedFromLang;
49 int slotColorVal(PyrSlot *slot, SCColor *sccolor);
52 int slotGetCGRect(PyrSlot* a, CGRect *r)
54 PyrSlot *slots = slotRawObject(a)->slots;
56 err = slotFloatVal(slots+0, &r->origin.x);
58 err = slotFloatVal(slots+1, &r->origin.y);
60 err = slotFloatVal(slots+2, &r->size.width);
62 err = slotFloatVal(slots+3, &r->size.height);
68 int slotGetQDRect(PyrSlot* a, Rect *r)
70 PyrSlot *slots = slotRawObject(a)->slots;
72 float x, y, width, height;
74 err = slotFloatVal(slots+0, &x);
76 err = slotFloatVal(slots+1, &y);
78 err = slotFloatVal(slots+2, &width);
80 err = slotFloatVal(slots+3, &height);
84 r->right = (int)(x + width);
85 r->top = (int)(y - height);
91 int slotGetPoint(PyrSlot* a, CGPoint *p)
93 PyrSlot *slots = slotRawObject(a)->slots;
95 err = slotFloatVal(slots+0, &p->x);
97 err = slotFloatVal(slots+1, &p->y);
104 int prSCWindow_New(struct VMGlobals *g, int numArgsPushed);
105 int prSCWindow_New(struct VMGlobals *g, int numArgsPushed)
107 if (!g->canCallOS) return errCantCallOS;
109 PyrSlot *args = g->sp - 6;
110 PyrSlot *a = args + 0;
111 PyrSlot *b = args + 1; // name
112 PyrSlot *c = args + 2; // bounds
113 PyrSlot *d = args + 3; // resizable
114 PyrSlot *e = args + 4; // border
115 PyrSlot *f = args + 6; // view
116 PyrSlot *h = args + 5; // scroll
117 PyrSlot *j = args + 7; // is this app modal? (Doesn't matter for sheets as they have no close button)
119 if (!(isKindOfSlot(b, class_string))) return errWrongType;
120 if (!(isKindOfSlot(c, s_rect->u.classobj))) return errWrongType;
123 int err = slotGetCGRect(c, &bounds);
126 PyrString *string = slotRawString(b);
127 NSString *title = [NSString stringWithCString: string->s length: string->size];
129 SCNSWindow *window = [[SCNSWindow alloc] initWithFrame: bounds];
130 [window setTitle: title];
131 [window setHasBorders: YES];
133 iSCLangController *controller = [iSCLangController sharedInstance];
134 SCGraphView* view = [[SCGraphView alloc] initWithFrame: bounds];
135 [view setSCObject: slotRawObject(a)];
136 SetPtr(slotRawObject(a)->slots + 0, view);
137 [controller insertWindow:window];
138 [window setSCGraphView: view];
142 SCScrollTopView* scrollTopView = (SCScrollTopView*)slotRawInt(slotRawObject(f)->slots);
143 [view setSCTopView: scrollTopView];
145 NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame: bounds];
146 [scrollView setHasVerticalScroller:YES];
147 [scrollView setHasHorizontalScroller:YES];
148 [scrollView setAutohidesScrollers:YES];
149 [[scrollView horizontalScroller] setControlSize:NSSmallControlSize];
150 [[scrollView verticalScroller] setControlSize:NSSmallControlSize];
151 [[scrollView horizontalScroller] setControlTint:NSGraphiteControlTint];
152 [[scrollView verticalScroller] setControlTint:NSGraphiteControlTint];
154 [scrollView setBackgroundColor:[NSColor clearColor]];
155 [scrollView setDrawsBackground:NO];
156 // configure the scroller to have no visible border
157 [scrollView setBorderType:NSNoBorder];
158 [scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
159 [scrollView setDocumentView:view];
161 [scrollView setPostsFrameChangedNotifications: YES]; // we need this to resize the SCGraphView if the scroll view exceeds its bounds
162 [[NSNotificationCenter defaultCenter] addObserver:view
163 selector:@selector(scrollViewResized:)
164 name:@"NSViewFrameDidChangeNotification"
167 NSClipView *contentView = [scrollView contentView];
168 [contentView setPostsBoundsChangedNotifications:YES];
169 [[NSNotificationCenter defaultCenter] addObserver:view
170 selector:@selector(userScrolled:)
171 name:@"NSViewBoundsDidChangeNotification"
174 scrollTopView->SetNSScrollView(scrollView);
177 [window setContentView: scrollView];
178 [scrollView autorelease];
181 [view setSCTopView: (SCTopView*)slotRawPtr(slotRawObject(f)->slots)];
182 [window addSubview: view];
185 //[window makeFirstResponder: view];
186 //[window setFrameOrigin: bounds.origin];
193 int prSCWindow_Refresh(struct VMGlobals *g, int numArgsPushed);
194 int prSCWindow_Refresh(struct VMGlobals *g, int numArgsPushed)
196 if (!g->canCallOS) return errCantCallOS;
199 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
200 if (!view) return errNone;
202 SEL sel = @selector(setNeedsDisplay:);
203 NSMethodSignature *sig = [UIView instanceMethodSignatureForSelector: sel];
205 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
206 iSCLangController* controller = [iSCLangController sharedInstance];
207 [anInvocation setTarget: view];
208 [anInvocation setSelector: sel];
210 [anInvocation setArgument: &flag atIndex: 2];
211 [controller defer: anInvocation];
216 int prSCWindow_Close(struct VMGlobals *g, int numArgsPushed);
217 int prSCWindow_Close(struct VMGlobals *g, int numArgsPushed)
219 if (!g->canCallOS) return errCantCallOS;
222 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
223 if (!view) return errNone;
225 SCNSWindow *window = (SCNSWindow *) [view superview];
227 SEL sel = @selector(closeWindow:);
228 NSMethodSignature *sig = [iSCLangController instanceMethodSignatureForSelector: sel];
230 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
231 iSCLangController* controller = [iSCLangController sharedInstance];
232 [anInvocation setTarget: controller];
233 [anInvocation setSelector: sel];
234 [anInvocation setArgument: &window atIndex: 2];
235 [controller defer: anInvocation];
240 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
241 if (!view) return errNone;
243 SEL sel = @selector(closeWindow);
244 NSMethodSignature *sig = [SCGraphView instanceMethodSignatureForSelector: sel];
246 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
247 iSCLangController* controller = [iSCLangController sharedInstance];
248 [anInvocation setTarget: view];
249 [anInvocation setSelector: sel];
250 [controller defer: anInvocation];
257 int prSCWindow_ToFront(struct VMGlobals *g, int numArgsPushed);
258 int prSCWindow_ToFront(struct VMGlobals *g, int numArgsPushed)
260 if (!g->canCallOS) return errCantCallOS;
263 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
264 if (!view) return errNone;
266 SCNSWindow *window = (SCNSWindow *) [view superview];
268 SEL sel = @selector(makeWindowFront:);
269 NSMethodSignature *sig = [iSCLangController instanceMethodSignatureForSelector: sel];
271 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
272 iSCLangController* controller = [iSCLangController sharedInstance];
273 [anInvocation setTarget: controller];
274 [anInvocation setSelector: sel];
275 [anInvocation setArgument: &window atIndex: 2];
276 [controller defer: anInvocation];
281 int prSCWindow_SetName(struct VMGlobals *g, int numArgsPushed);
282 int prSCWindow_SetName(struct VMGlobals *g, int numArgsPushed)
284 if (!g->canCallOS) return errCantCallOS;
286 PyrSlot *a = g->sp - 1;
289 if (!(isKindOfSlot(b, class_string))) return errWrongType;
291 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
292 if (!view) return errNone;
293 PyrString *string = slotRawString(b);
294 NSString *title = [NSString stringWithCString: string->s length: string->size];
295 [[view window] setTitle: title];
300 int prFont_AvailableFonts(struct VMGlobals *g, int numArgsPushed);
301 int prFont_AvailableFonts(struct VMGlobals *g, int numArgsPushed)
303 if (!g->canCallOS) return errCantCallOS;
307 NSArray *fonts = [UIFont familyNames];
309 int size = [fonts count];
310 PyrObject* array = newPyrArray(g->gc, size, 0, true);
313 for (int i=0; i<size; ++i) {
314 NSString *name = [fonts objectAtIndex: i];
315 //if (!name) continue;
316 PyrString *string = newPyrString(g->gc, [name UTF8String], 0, true);
317 SetObject(array->slots + array->size, string);
319 g->gc->GCWrite(array, string);
326 void initGUIPrimitives()
330 s_draw = getsym("draw");
331 s_font = getsym("SCFont");
332 s_closed = getsym("closed");
333 s_tick = getsym("tick");
334 s_doaction = getsym("doAction");
335 s_didBecomeKey = getsym("didBecomeKey");
336 s_didResignKey = getsym("didResignKey");
338 base = nextPrimitiveIndex();
341 definePrimitive(base, index++, "_SCWindow_New", prSCWindow_New, 7, 0);
342 definePrimitive(base, index++, "_SCWindow_Refresh", prSCWindow_Refresh, 1, 0);
343 definePrimitive(base, index++, "_SCWindow_Close", prSCWindow_Close, 1, 0);
344 definePrimitive(base, index++, "_SCWindow_ToFront", prSCWindow_ToFront, 1, 0);
345 definePrimitive(base, index++, "_SCWindow_SetName", prSCWindow_SetName, 2, 0);
347 definePrimitive(base, index++, "_Font_AvailableFonts", prFont_AvailableFonts, 1, 0);