class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / editors / scapp / GUIPrimitives.M
blob10c605d083feb48cb1e547badfbfae2de4a67b2f
1 /*
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <Cocoa/Cocoa.h>
22 #include <Carbon/Carbon.h>
23 #import "SCBase.h"
24 #import "PyrSymbol.h"
25 #include "PyrPrimitive.h"
26 #include "PyrObject.h"
27 #include "PyrKernel.h"
28 #include "VMGlobals.h"
29 #include "SC_RGen.h"
30 #import "MyDocument.h"
31 #import "SCGraphView.h"
32 #import "SCVirtualMachine.h"
33 #import "ChangeCounter.h"
34 #import "GC.h"
35 #import "SCTextView.h"
36 #import "SCNSWindow.h"
37 #import "SCCocoaView.h"
39 #if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4)
40 typedef float ColorData;
41 #else
42 typedef CGFloat ColorData;
43 #endif
46 extern ChangeCounter gUIChangeCounter;
47 extern NSTextView* gPostView;
48 PyrSymbol *s_draw;
49 PyrSymbol *s_font;
50 PyrSymbol *s_closed;
51 PyrSymbol *s_tick;
52 PyrSymbol *s_doaction;
53 PyrSymbol *s_didBecomeKey;
54 PyrSymbol *s_didResignKey;
56 extern bool docCreatedFromLang;
57 extern bool defaultDocumentUseAutoInOutDent;
58 int slotColorVal(PyrSlot *slot, SCColor *sccolor);
60 int prNumberOfOpenTextWindows(struct VMGlobals *g, int numArgsPushed);
61 int prNumberOfOpenTextWindows(struct VMGlobals *g, int numArgsPushed)
63 if (!g->canCallOS) return errCantCallOS;
65 PyrSlot *a = g->sp;
67 NSDocumentController *docctl = [NSDocumentController sharedDocumentController];
68 if (!docctl) return errFailed;
69 int num = [[docctl documents] count];
70 if (!num) return errFailed;
71 SetInt(a, num);
72 return errNone;
76 int prTextWindow_IsEdited(struct VMGlobals *g, int numArgsPushed);
77 int prTextWindow_IsEdited(struct VMGlobals *g, int numArgsPushed)
79 if (!g->canCallOS) return errCantCallOS;
81 PyrSlot *a = g->sp;
83 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
84 if (!doc) return errFailed;
85 bool edited = (bool) [doc isDocumentEdited];
86 if(edited) SetTrue(a);
87 else SetFalse(a);
88 return errNone;
91 int prTextWindow_SetEditable(struct VMGlobals *g, int numArgsPushed);
92 int prTextWindow_SetEditable(struct VMGlobals *g, int numArgsPushed)
94 if (!g->canCallOS) return errCantCallOS;
96 PyrSlot *a = g->sp-1;
97 PyrSlot *b = g->sp;
99 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
100 if (!doc) return errFailed;
101 if(IsFalse(b)){
102 [[doc textView] setEditable: NO];
103 [[doc textView2] setEditable: NO];
104 } else {
105 [[doc textView] setEditable: YES];
106 [[doc textView2] setEditable: YES];
108 return errNone;
111 int slotGetNSRect(PyrSlot* a, NSRect *r);
113 int prTextWindow_SetBounds(struct VMGlobals *g, int numArgsPushed);
114 int prTextWindow_SetBounds(struct VMGlobals *g, int numArgsPushed)
116 if (!g->canCallOS) return errCantCallOS;
118 PyrSlot *a = g->sp - 1;
119 PyrSlot *b = g->sp;
121 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
123 NSRect bounds;
124 int err = slotGetNSRect(b, &bounds);
125 if (err) return err;
127 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
128 if (!doc) return errFailed;
130 NSWindow *window = [[doc textView] window];
131 //[window setFrame: bounds display: YES];
133 SEL sel = @selector(setFrame:display:);
134 NSMethodSignature *sig = [NSWindow instanceMethodSignatureForSelector: sel];
135 BOOL flag = YES;
137 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
138 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
139 [anInvocation setTarget: window];
140 [anInvocation setSelector: sel];
141 [anInvocation setArgument: &bounds atIndex: 2];
142 [anInvocation setArgument: &flag atIndex: 3];
143 [scvm defer: anInvocation];
145 return errNone;
148 int prTextWindow_GetBounds(struct VMGlobals *g, int numArgsPushed);
149 int prTextWindow_GetBounds(struct VMGlobals *g, int numArgsPushed)
151 if (!g->canCallOS) return errCantCallOS;
153 PyrSlot *a = g->sp - 1;
154 PyrSlot *b = g->sp;
156 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
158 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
159 if (!doc) return errFailed;
161 NSWindow *window = [[doc textView] window];
163 NSRect bounds = [window frame];
164 PyrSlot *slots = slotRawObject(b)->slots;
165 SetFloat(slots+0, bounds.origin.x);
166 SetFloat(slots+1, bounds.origin.y);
167 SetFloat(slots+2, bounds.size.width);
168 SetFloat(slots+3, bounds.size.height);
169 slotCopy(a, b);
171 return errNone;
174 int prTextWindow_SetName(struct VMGlobals *g, int numArgsPushed);
175 int prTextWindow_SetName(struct VMGlobals *g, int numArgsPushed)
177 if (!g->canCallOS) return errCantCallOS;
179 PyrSlot *a = g->sp - 1;
180 PyrSlot *b = g->sp;
182 if (!(isKindOfSlot(b, class_string))) return errWrongType;
184 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
185 if (!doc) return errFailed;
187 NSWindow *window = [[doc textView] window];
188 PyrString *string = slotRawString(b);
189 NSString *title = [NSString stringWithCString: string->s length: string->size];
190 [window setTitle: title];
191 return errNone;
194 int prTextWindow_SetBackgroundColor(struct VMGlobals *g, int numArgsPushed);
195 int prTextWindow_SetBackgroundColor(struct VMGlobals *g, int numArgsPushed)
197 if (!g->canCallOS) return errCantCallOS;
199 PyrSlot *a = g->sp-1;
200 PyrSlot *b = g->sp;
201 if (IsNil(b)) return errNone;
202 SCColor rgb;
203 int err = slotColorVal(b, &rgb);
204 if (err) return err;
205 NSColor *color = [NSColor colorWithCalibratedRed: rgb.red
206 green: rgb.green
207 blue: rgb.blue
208 alpha: rgb.alpha];
210 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
211 if (!doc) return errFailed;
212 [doc setBackgroundColor: color];
213 //[[doc textView] didChangeText];
215 return errNone;
218 int prTextWindow_GetBackgroundColor(struct VMGlobals *g, int numArgsPushed);
219 int prTextWindow_GetBackgroundColor(struct VMGlobals *g, int numArgsPushed)
221 if (!g->canCallOS) return errCantCallOS;
222 // let the lang allocate the Color
223 // rtf seems not to save the backgroundcolor. set it in the lang first!
224 PyrSlot *a = g->sp-1;
225 PyrSlot *b = g->sp;
226 if (IsNil(b)) return errNone;
227 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
228 if (!doc) return errFailed;
229 NSTextView * view = [doc initTextView];
230 if(!view) view = [doc textView];
231 if(!view) return errNone;
232 NSColor * color = [view backgroundColor];
233 if(!color) return errNone;
234 ColorData red, green, blue, alpha;
235 [color getRed:&red green:&green blue:&blue alpha:&alpha];
236 PyrSlot *slots = slotRawObject(b)->slots;
237 SetFloat(slots+0, red);
238 SetFloat(slots+1, green);
239 SetFloat(slots+2, blue);
240 SetFloat(slots+3, alpha);
241 return errNone;
244 extern SCColor synColText, synColClass, synColString, synColSymbol, synColComment, synColNumber, synColSpecialVals, synColSpecialVars, synColDecl, synColPunc, synColEnv;
246 int prSetSyntaxColorTheme(struct VMGlobals *g, int numArgsPushed);
247 int prSetSyntaxColorTheme(struct VMGlobals *g, int numArgsPushed)
249 PyrSlot *colText;
250 PyrSlot *colClass;
251 PyrSlot *colString;
252 PyrSlot *colSymbol;
253 PyrSlot *colComment;
254 PyrSlot *colNumber;
255 PyrSlot *colVals;
256 PyrSlot *colVars;
257 PyrSlot *colDecl;
258 PyrSlot *colPunc;
259 PyrSlot *colEnviron;
261 colText = g->sp - numArgsPushed + 2;
262 colClass = colText + 1;
263 colString = colClass + 1;
264 colSymbol = colString + 1;
265 colComment = colSymbol + 1;
266 colNumber = colComment + 1;
267 colVals = colNumber + 1;
268 colVars = colVals + 1;
269 colDecl = colVars + 1;
270 colPunc = colDecl + 1;
271 colEnviron = colPunc + 1;
273 if (isKindOfSlot(colText, s_color->u.classobj)) {
274 int err = slotColorVal(colText, &synColText);
275 if(err) return err;
278 if (isKindOfSlot(colClass, s_color->u.classobj)) {
279 int err = slotColorVal(colClass, &synColClass);
280 if(err) return err;
283 if (isKindOfSlot(colString, s_color->u.classobj)) {
284 int err = slotColorVal(colString, &synColString);
285 if(err) return err;
288 if (isKindOfSlot(colSymbol, s_color->u.classobj)) {
289 int err = slotColorVal(colSymbol, &synColSymbol);
290 if(err) return err;
293 if (isKindOfSlot(colComment, s_color->u.classobj)) {
294 int err = slotColorVal(colComment, &synColComment);
295 if(err) return err;
298 if (isKindOfSlot(colNumber, s_color->u.classobj)) {
299 int err = slotColorVal(colNumber, &synColNumber);
300 if(err) return err;
303 if (isKindOfSlot(colVals, s_color->u.classobj)) {
304 int err = slotColorVal(colVals, &synColSpecialVals);
305 if(err) return err;
308 if (isKindOfSlot(colVars, s_color->u.classobj)) {
309 int err = slotColorVal(colVars, &synColSpecialVars);
310 if(err) return err;
313 if (isKindOfSlot(colDecl, s_color->u.classobj)) {
314 int err = slotColorVal(colDecl, &synColDecl);
315 if(err) return err;
318 if (isKindOfSlot(colPunc, s_color->u.classobj)) {
319 int err = slotColorVal(colPunc, &synColPunc);
320 if(err) return err;
323 if (isKindOfSlot(colPunc, s_color->u.classobj)) {
324 int err = slotColorVal(colEnviron, &synColEnv);
325 if(err) return err;
328 return errNone;
332 int prTextWindow_SetSelectedBackgroundColor(struct VMGlobals *g, int numArgsPushed);
333 int prTextWindow_SetSelectedBackgroundColor(struct VMGlobals *g, int numArgsPushed)
335 if (!g->canCallOS) return errCantCallOS;
336 PyrSlot *a = g->sp-1;
337 PyrSlot *b = g->sp;
338 if (IsNil(b)) return errNone;
339 SCColor rgb;
340 int err = slotColorVal(b, &rgb);
341 if (err) return err;
342 NSColor *color = [NSColor colorWithCalibratedRed: rgb.red
343 green: rgb.green
344 blue: rgb.blue
345 alpha: rgb.alpha];
346 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
347 if (!doc) return errFailed;
348 [doc setSelectedBackgroundColor: color];
349 return errNone;
352 int prTextWindow_GetSelectedBackgroundColor(struct VMGlobals *g, int numArgsPushed);
353 int prTextWindow_GetSelectedBackgroundColor(struct VMGlobals *g, int numArgsPushed)
355 if (!g->canCallOS) return errCantCallOS;
357 PyrSlot *a = g->sp-1;
358 PyrSlot *b = g->sp;
359 if (IsNil(b)) return errNone;
360 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
361 if (!doc) return errFailed;
362 NSTextView * view = [doc initTextView];
363 if(!view) view = [doc textView];
364 if(!view) return errNone;
365 NSColor * color = [[[view selectedTextAttributes] objectForKey: NSBackgroundColorAttributeName] colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
366 if(!color) return errNone;
367 ColorData red, green, blue, alpha;
368 [color getRed:&red green:&green blue:&blue alpha:&alpha];
369 PyrSlot *slots = slotRawObject(b)->slots;
370 SetFloat(slots+0, red);
371 SetFloat(slots+1, green);
372 SetFloat(slots+2, blue);
373 SetFloat(slots+3, alpha);
374 return errNone;
378 int prTextWindow_SetTextColor(struct VMGlobals *g, int numArgsPushed);
379 int prTextWindow_SetTextColor(struct VMGlobals *g, int numArgsPushed)
381 if (!g->canCallOS) return errCantCallOS;
383 PyrSlot *a = g->sp-3;
384 PyrSlot *b = g->sp-2;
385 PyrSlot *c = g->sp-1;
386 PyrSlot *d = g->sp;
388 int rangeStart, rangeSize;
389 if (IsNil(b)) return errNone;
391 SCColor rgb;
392 int err = slotColorVal(b, &rgb);
393 if (err) return err;
394 err = slotIntVal(c, &rangeStart); //if -1 do not use range
395 if (err) return err;
396 err = slotIntVal(d, &rangeSize);
397 if (err) return err;
400 NSColor *color = [NSColor colorWithCalibratedRed: rgb.red
401 green: rgb.green
402 blue: rgb.blue
403 alpha: rgb.alpha];
405 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
406 if (!doc) return errFailed;
407 //[[doc textView] setBackgroundColor: color];
409 if(rangeStart < 0){
410 [[doc activeTextView] setTextColor: color];
411 [[doc activeTextView] didChangeText];
412 return errNone;
414 int length = [[[doc activeTextView] string] length];
415 if(rangeStart >= length) rangeStart = length - 1 ;
416 if(rangeStart + rangeSize >= length) rangeSize = length - rangeStart;
417 NSRange selectedRange = NSMakeRange(rangeStart, rangeSize);
420 [[doc activeTextView] setTextColor: color range: selectedRange];
421 [[doc activeTextView] didChangeText];
426 return errNone;
429 int prTextWindow_SetFont(struct VMGlobals *g, int numArgsPushed);
430 int prTextWindow_SetFont(struct VMGlobals *g, int numArgsPushed)
432 if (!g->canCallOS) return errCantCallOS;
433 PyrSlot *a = g->sp - 3;
434 PyrSlot *fontSlot = g->sp - 2; //fontsize
436 PyrSlot *d = g->sp - 1; //rangestart
437 PyrSlot *e = g->sp; //rangesize
438 if (IsNil(fontSlot)) return errNone; // use default font
439 if (!(isKindOfSlot(fontSlot, s_font->u.classobj))) return errWrongType;
441 PyrSlot *nameSlot = slotRawObject(fontSlot)->slots+0;
442 PyrSlot *sizeSlot = slotRawObject(fontSlot)->slots+1;
443 float size;
444 int err = slotFloatVal(sizeSlot, &size);
445 if (err) return err;
447 PyrString *pstring = slotRawString(nameSlot);
448 NSString *fontName = [NSString stringWithCString: pstring->s length: pstring->size];
449 if (!fontName) return errFailed;
450 NSFont *font = [NSFont fontWithName: fontName size: size];
451 if (!font) return errFailed;
453 int rangeStart, rangeSize;
454 err = slotIntVal(d, &rangeStart); //if -1 do not use range
455 if (err) return err;
456 err = slotIntVal(e, &rangeSize);
457 if (err) return err;
459 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
460 if (!doc) return errFailed;
461 if(rangeStart < 0){
462 [[doc activeTextView] setFont: font];
463 return errNone;
465 NSString* string = [[doc activeTextView] string];
466 int length = [string length];
467 if(length < 1) return errFailed;
468 if(rangeStart >= length) rangeStart = length - 1 ;
469 if(rangeStart + rangeSize >= length) rangeSize = length - rangeStart;
470 NSRange selectedRange = NSMakeRange(rangeStart, rangeSize);
472 [[doc activeTextView] setFont: font range: selectedRange];
473 return errNone;
475 int prTextWindow_UnderlineSelection(struct VMGlobals *g, int numArgsPushed);
476 int prTextWindow_UnderlineSelection(struct VMGlobals *g, int numArgsPushed)
478 if (!g->canCallOS) return errCantCallOS;
480 PyrSlot *a = g->sp;
482 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
483 if (!doc) return errFailed;
484 [[doc activeTextView] underline: NULL];
485 return errNone;
489 int prTextWindow_Close(struct VMGlobals *g, int numArgsPushed);
490 int prTextWindow_Close(struct VMGlobals *g, int numArgsPushed)
492 if (!g->canCallOS) return errCantCallOS;
494 PyrSlot *a = g->sp;
496 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
497 if (!doc) return errFailed;
498 SEL sel = @selector(closeWindow);
499 NSMethodSignature *sig = [MyDocument instanceMethodSignatureForSelector: sel];
501 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
502 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
503 [anInvocation setTarget: doc];
504 [anInvocation setSelector: sel];
505 [scvm defer: anInvocation];
508 return errNone;
511 int prTextWindow_SelectLine(struct VMGlobals *g, int numArgsPushed);
512 int prTextWindow_SelectLine(struct VMGlobals *g, int numArgsPushed)
514 if (!g->canCallOS) return errCantCallOS;
516 PyrSlot *a = g->sp - 1;
517 PyrSlot *b = g->sp; //the win number
519 int err, linenum;
520 err = slotIntVal(b, &linenum);
521 if (err) return errWrongType;
522 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
523 if (!doc) return errFailed;
524 //[doc selectLine: linenum];
525 SEL sel = @selector(selectLine:);
526 NSMethodSignature *sig = [MyDocument instanceMethodSignatureForSelector: sel];
528 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
529 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
530 [anInvocation setTarget: doc];
531 [anInvocation setSelector: sel];
532 [anInvocation setArgument: &linenum atIndex: 2];
533 [scvm defer: anInvocation];
535 return errNone;
538 int prTextWindow_SelectRange(struct VMGlobals *g, int numArgsPushed);
539 int prTextWindow_SelectRange(struct VMGlobals *g, int numArgsPushed)
541 if (!g->canCallOS) return errCantCallOS;
542 PyrSlot *a = g->sp - 2;
543 PyrSlot *b = g->sp - 1; //the win number
544 PyrSlot *c = g->sp;
546 int rangeStart, rangeSize;
547 int err = slotIntVal(b, &rangeStart);
548 if (err) return err;
549 err = slotIntVal(c, &rangeSize);
550 if (err) return err;
551 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
552 if (!doc) return errFailed;
553 [doc selectRangeStart: rangeStart size: rangeSize];
554 return errNone;
557 int prTextWindow_GetByIndex(struct VMGlobals *g, int numArgsPushed);
558 int prTextWindow_GetByIndex(struct VMGlobals *g, int numArgsPushed)
560 if (!g->canCallOS) return errCantCallOS;
562 PyrSlot *a = g->sp - 1;
563 PyrSlot *b = g->sp; //the win number
565 int err, inputIndex;
566 err = slotIntVal(b, &inputIndex);
567 if (err) return errWrongType;
569 NSDocumentController *docctl = [NSDocumentController sharedDocumentController];
570 if (!docctl) return errFailed;
571 MyDocument* doc = [[docctl documents] objectAtIndex: inputIndex];
572 if (!doc) return errFailed;
573 PyrObject * obj = [doc getSCObject];
574 //if there is a scobject already don't store i
575 if(obj){
576 //post("docuemnt has scObject already\n");
577 SetNil(a);
578 return errNone;
580 [doc setSCObject: slotRawObject(a)];
581 SetPtr(slotRawObject(a)->slots + 0, doc);
582 // if([doc getSCKeyDownAction])
583 // SetObject(slotRawObject(a)->slots + 1, [doc getSCKeyDownAction]);
584 return errNone;
587 int prTextWindow_GetLastIndex(struct VMGlobals *g, int numArgsPushed);
588 int prTextWindow_GetLastIndex(struct VMGlobals *g, int numArgsPushed)
590 if (!g->canCallOS) return errCantCallOS;
592 PyrSlot *a = g->sp;
593 NSDocumentController *docctl = [NSDocumentController sharedDocumentController];
594 if (!docctl) return errFailed;
595 MyDocument* doc = [[docctl documents] lastObject];
596 if (!doc) return errFailed;
597 PyrObject * obj = [doc getSCObject];
598 if(obj){
599 //post("docuemnt has scObject already\n");
600 SetNil(a);
601 return errNone;
603 [doc setSCObject: slotRawObject(a)];
604 SetPtr(slotRawObject(a)->slots + 0, doc);
605 return errNone;
608 int prTextWindow_ToFront(struct VMGlobals *g, int numArgsPushed);
609 int prTextWindow_ToFront(struct VMGlobals *g, int numArgsPushed)
611 if (!g->canCallOS) return errCantCallOS;
613 PyrSlot *b = g->sp; //the win number
615 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(b)->slots);
616 if (!doc) return errFailed;
617 docCreatedFromLang = true;
618 [[[doc textView] window] makeKeyAndOrderFront: nil];
619 docCreatedFromLang = false;
620 return errNone;
623 int prTextWindow_SyntaxColorize(struct VMGlobals *g, int numArgsPushed);
624 int prTextWindow_SyntaxColorize(struct VMGlobals *g, int numArgsPushed)
626 if (!g->canCallOS) return errCantCallOS;
628 PyrSlot *b = g->sp; //the win number
630 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(b)->slots);
631 if (!doc) return errFailed;
632 [doc syntaxColorize: nil];
633 return errNone;
636 int prTextWindow_InsertTextInRange(struct VMGlobals *g, int numArgsPushed);
637 int prTextWindow_InsertTextInRange(struct VMGlobals *g, int numArgsPushed)
639 if (!g->canCallOS) return errCantCallOS;
640 PyrSlot *a = g->sp - 3;
641 PyrSlot *b = g->sp - 2; //the text
642 PyrSlot *c = g->sp - 1;
643 PyrSlot *d = g->sp;
645 if (!(isKindOfSlot(b, class_string))) return errWrongType;
647 int rangeStart, rangeSize;
648 int err = slotIntVal(c, &rangeStart); //if -1 do not use range
649 if (err) return err;
650 err = slotIntVal(d, &rangeSize);
651 if (err) return err;
653 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
654 if (!doc) return errFailed;
655 PyrString* pstring = slotRawString(b);
656 NSRange selectedRange;
657 int length = [[[doc activeTextView] string] length];
659 if(rangeSize < 0) rangeSize = length - 1;
660 if(rangeStart >= length) rangeStart = length - 1 ;
661 if(rangeStart + rangeSize >= length) rangeSize = length - rangeStart;
663 if(rangeStart<0) selectedRange = NSMakeRange(0, length);
664 else selectedRange = NSMakeRange(rangeStart, rangeSize);
667 NSString *string = [[NSString alloc] initWithCString: pstring->s length: pstring->size];
668 if ([[doc activeTextView] shouldChangeTextInRange: selectedRange replacementString: string]) {
669 [[doc activeTextView] replaceCharactersInRange: selectedRange withString: string];
670 [[doc activeTextView] didChangeText];
672 [string release];
674 return errNone;
677 //insert in current position
678 int prTextWindow_InsertText(struct VMGlobals *g, int numArgsPushed);
679 int prTextWindow_InsertText(struct VMGlobals *g, int numArgsPushed)
681 if (!g->canCallOS) return errCantCallOS;
682 PyrSlot *b = g->sp - 1;
683 PyrSlot *c = g->sp; //the text
684 if (!(isKindOfSlot(c, class_string))) return errWrongType;
686 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(b)->slots);
687 if (!doc) return errFailed;
688 PyrString* string = slotRawString(c);
689 [doc insertText: string->s length: string->size];
690 return errNone;
693 int prTextWindow_GetName(struct VMGlobals *g, int numArgsPushed);
694 int prTextWindow_GetName(struct VMGlobals *g, int numArgsPushed)
696 if (!g->canCallOS) return errCantCallOS;
697 PyrSlot *a = g->sp;
698 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
699 if (!doc) return errFailed;
700 // const char * cstr = [[doc displayName] UTF8String];
701 const char * cstr = [[[[doc textView] window] title] UTF8String];
702 PyrString *string = newPyrString(g->gc, cstr, 0, true);
703 SetObject(a, string);
704 return errNone;
707 int prTextWindow_GetFileName(struct VMGlobals *g, int numArgsPushed);
708 int prTextWindow_GetFileName(struct VMGlobals *g, int numArgsPushed)
710 if (!g->canCallOS) return errCantCallOS;
711 PyrSlot *a = g->sp;
712 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
713 if (!doc) return errFailed;
714 const char * cstr = [[doc fileName] UTF8String];
715 if(!cstr){
716 SetNil(a);
717 return errNone;
719 PyrString *string = newPyrString(g->gc, cstr, 0, true);
720 SetObject(a, string);
721 return errNone;
723 int prTextWindow_SetFileName(struct VMGlobals *g, int numArgsPushed);
724 int prTextWindow_SetFileName(struct VMGlobals *g, int numArgsPushed)
726 if (!g->canCallOS) return errCantCallOS;
727 PyrSlot *a = g->sp-1;
728 PyrSlot *b = g->sp;
729 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
730 if (!doc) return errFailed;
731 PyrString* filenmae = slotRawString(b);
732 NSString *nsname = [NSString stringWithCString: filenmae->s length: filenmae->size];
733 if(!nsname) return errFailed;
734 [doc setFileName: nsname];
735 return errNone;
737 int prTextWindow_GetSelectedRangeLocation(struct VMGlobals *g, int numArgsPushed);
738 int prTextWindow_GetSelectedRangeLocation(struct VMGlobals *g, int numArgsPushed)
740 if (!g->canCallOS) return errCantCallOS;
742 PyrSlot *a = g->sp;
743 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
744 if (!doc) return errFailed;
745 NSRange range = [[doc activeTextView] selectedRange];
746 SetInt(a, range.location);
747 return errNone;
750 #if 0
751 int prTextWindow_SelectToken(struct VMGlobals *g, int numArgsPushed);
752 int prTextWindow_SelectToken(struct VMGlobals *g, int numArgsPushed)
754 if (!g->canCallOS) return errCantCallOS;
756 PyrSlot *a = g->sp;
757 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
758 if (!doc) return errFailed;
760 NSString* string = [[doc activeTextView] string];
761 NSRange range = [[doc activeTextView] selectedRange];
762 int clickLoc = range.location;
763 range.location = range.location < 64 ? 0 : range.location - 64;
764 range.length = 64;
765 NSRange wordRange = range;
766 for (int i=clickLoc; i>=(int)range.location; --i) {
767 if (isspace([string characterAtIndex: i])) {
768 wordRange.location = i;
769 wordRange.length = range.location + range.length - i;
770 break;
773 for (int i=clickLoc; i<(int)(range.location + range.length); ++i) {
774 if (isspace([string characterAtIndex: i])) {
775 wordRange.length = i - wordRange.location;
776 break;
780 [doc selectRangeStart: wordRange.location size: wordRange.length];
782 return errNone;
784 #endif
786 int prTextWindow_SelectUnderlinedText(struct VMGlobals *g, int numArgsPushed);
787 int prTextWindow_SelectUnderlinedText(struct VMGlobals *g, int numArgsPushed)
789 if (!g->canCallOS) return errCantCallOS;
791 PyrSlot *a = g->sp - 1;
792 PyrSlot *b = g->sp;
794 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
795 if (!doc) return errFailed;
797 NSTextView *textView = [doc activeTextView];
799 int clickLoc;
800 int err = slotIntVal(b, &clickLoc);
801 if (err) {
802 clickLoc = [textView selectedRange].location;
804 NSRange range = NSMakeRange(clickLoc, 0);
806 NSTextStorage *textStorage = [textView textStorage];
807 NSRange limitRange = NSMakeRange(0, [textStorage length]);
808 NSRange underlineRange;
809 if (range.location < limitRange.length) {
811 id isUnderlined = [textStorage attribute: NSUnderlineStyleAttributeName
812 atIndex: range.location
813 longestEffectiveRange: &underlineRange
814 inRange: limitRange];
816 if (isUnderlined) {
818 NSString* string = [[doc activeTextView] string];
820 // underlined range should not cross newlines.
821 for (int i=clickLoc; i>=(int)underlineRange.location; --i) {
822 int c = [string characterAtIndex: i];
823 if (c == '\n') {
824 underlineRange.length -= i + 1 - underlineRange.location;
825 underlineRange.location = i + 1;
826 break;
829 for (int i=clickLoc; i<(int)(underlineRange.location + underlineRange.length); ++i) {
830 int c = [string characterAtIndex: i];
831 if (c == '\n') {
832 underlineRange.length = i - underlineRange.location;
833 break;
837 // trim whitespace
838 int start = underlineRange.location;
839 int end = underlineRange.location + underlineRange.length;
840 for (int i=start; i<end; ++i) {
841 int c = [string characterAtIndex: i];
842 if (!isspace(c)) break;
843 underlineRange.location ++;
844 underlineRange.length --;
847 start = underlineRange.location + underlineRange.length - 1;
848 end = underlineRange.location;
849 for (int i=start; i>=end; --i) {
850 int c = [string characterAtIndex: i];
851 if (!isspace(c)) break;
852 underlineRange.length --;
855 // include square brackets in selection
856 start = underlineRange.location - 1;
857 end = underlineRange.location + underlineRange.length;
858 if (start >= 0 && [string characterAtIndex: start] == '['
859 && end < (int)limitRange.length && [string characterAtIndex: end] == ']') {
860 underlineRange.location --;
861 underlineRange.length += 2;
863 // include parentheses in selection
864 if (start >= 0 && [string characterAtIndex: start] == '('
865 && end < (int)limitRange.length && [string characterAtIndex: end] == ')') {
866 underlineRange.location --;
867 underlineRange.length += 2;
870 if ((int)underlineRange.length > 0 && (int)underlineRange.location <= clickLoc && clickLoc < (int)(underlineRange.location + underlineRange.length)) {
871 [doc selectRangeStart: underlineRange.location size: underlineRange.length];
872 SetTrue(a);
873 } else {
874 SetFalse(a);
876 } else {
877 SetFalse(a);
879 } else {
880 SetFalse(a);
882 return errNone;
885 int prTextWindow_LinkAtClickPos(struct VMGlobals *g, int numArgsPushed);
886 int prTextWindow_LinkAtClickPos(struct VMGlobals *g, int numArgsPushed)
888 if (!g->canCallOS) return errCantCallOS;
890 PyrSlot *a = g->sp - 1;
891 PyrSlot *b = g->sp;
893 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
894 if (!doc) return errFailed;
896 NSTextView *textView = [doc activeTextView];
898 int clickLoc;
899 int err = slotIntVal(b, &clickLoc);
900 if (err) {
901 clickLoc = [textView selectedRange].location;
903 NSRange range = NSMakeRange(clickLoc, 0);
905 NSTextStorage *textStorage = [textView textStorage];
906 NSRange limitRange = NSMakeRange(0, [textStorage length]);
907 if (range.location < limitRange.length) {
909 id isLink = [textStorage attribute: NSLinkAttributeName atIndex: range.location effectiveRange: NULL];
911 if (isLink) { SetTrue(a);} else { SetFalse(a);}
913 } else {
914 SetFalse(a);
916 return errNone;
920 int prTextWindow_GetSelectedRangeLength(struct VMGlobals *g, int numArgsPushed);
921 int prTextWindow_GetSelectedRangeLength(struct VMGlobals *g, int numArgsPushed)
923 if (!g->canCallOS) return errCantCallOS;
924 PyrSlot *a = g->sp;
925 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
926 if (!doc) return errFailed;
927 NSRange range = [[doc activeTextView] selectedRange];
928 SetInt(a, range.length);
929 return errNone;
932 int prTextWindow_SelectedText(struct VMGlobals *g, int numArgsPushed);
933 int prTextWindow_SelectedText(struct VMGlobals *g, int numArgsPushed)
935 if (!g->canCallOS) return errCantCallOS;
937 PyrSlot *a = g->sp;
939 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
940 if (!doc) return errFailed;
942 NSString* str = [[doc activeTextView] currentlySelectedTextOrLine:NULL];
943 const char * cstr = [str UTF8String];
944 PyrString *string = newPyrString(g->gc, cstr, 0, true);
945 SetObject(a, string);
946 return errNone;
949 int prTextWindow_TextWithRange(struct VMGlobals *g, int numArgsPushed);
950 int prTextWindow_TextWithRange(struct VMGlobals *g, int numArgsPushed)
953 if (!g->canCallOS) return errCantCallOS;
954 PyrSlot *a = g->sp - 2;
955 PyrSlot *b = g->sp - 1; //from
956 PyrSlot *c = g->sp;//length
958 int rangeStart, rangeSize;
959 int err = slotIntVal(b, &rangeStart);
960 if (err) return err;
961 err = slotIntVal(c, &rangeSize);
962 if (err) return err;
963 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
964 if (!doc) return errFailed;
965 NSString* string = [[doc activeTextView] string];
966 int length = [string length];
967 if(length < 1)
969 SetNil(a);
970 return errNone;
972 if(rangeStart >= length) rangeStart = length - 1 ;
973 if(rangeStart + rangeSize >= length) rangeSize = length - rangeStart;
975 NSRange selectedRange = NSMakeRange(rangeStart, rangeSize);
976 NSString* str = [string substringWithRange: selectedRange];
977 const char * cstr = [str UTF8String];
978 PyrString *pstring = newPyrString(g->gc, cstr, 0, true);
979 SetObject(a, pstring);
980 return errNone;
983 int prTextWindow_Text(struct VMGlobals *g, int numArgsPushed);
984 int prTextWindow_Text(struct VMGlobals *g, int numArgsPushed)
986 if (!g->canCallOS) return errCantCallOS;
988 PyrSlot *a = g->sp;
990 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
991 if (!doc) return errFailed;
993 NSString* str = [[doc activeTextView] string];
994 const char * cstr = [str UTF8String];
995 PyrString *string = newPyrString(g->gc, cstr, 0, true);
996 SetObject(a, string);
997 return errNone;
999 int prTextWindow_RemoveUndo(struct VMGlobals *g, int numArgsPushed);
1000 int prTextWindow_RemoveUndo(struct VMGlobals *g, int numArgsPushed)
1002 if (!g->canCallOS) return errCantCallOS;
1004 PyrSlot *a = g->sp;
1006 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
1007 if (!doc) return errFailed;
1008 [doc updateChangeCount: NSChangeCleared];
1009 return errNone;
1012 int prTextWindow_UnfocusedFront(struct VMGlobals *g, int numArgsPushed);
1013 int prTextWindow_UnfocusedFront(struct VMGlobals *g, int numArgsPushed)
1015 if (!g->canCallOS) return errCantCallOS;
1017 PyrSlot *a = g->sp;
1019 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
1020 if (!doc) return errFailed;
1021 [[[doc textView] window] orderFrontRegardless];
1022 return errNone;
1025 int prTextWindow_AlwaysOnTop(struct VMGlobals *g, int numArgsPushed);
1026 int prTextWindow_AlwaysOnTop(struct VMGlobals *g, int numArgsPushed)
1028 if (!g->canCallOS) return errCantCallOS;
1030 PyrSlot *a = g->sp-1;
1031 PyrSlot *b = g->sp;
1033 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
1034 if (!doc) return errFailed;
1035 if(IsTrue(b))
1036 [[[doc textView] window] setLevel:NSFloatingWindowLevel];
1037 else
1038 [[[doc textView] window] setLevel:NSNormalWindowLevel];
1039 return errNone;
1042 int prTextWindow_IsAlwaysOnTop(struct VMGlobals *g, int numArgsPushed);
1043 int prTextWindow_IsAlwaysOnTop(struct VMGlobals *g, int numArgsPushed)
1045 if (!g->canCallOS) return errCantCallOS;
1046 PyrSlot *a = g->sp;
1047 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
1048 if (!doc) return errFailed;
1049 int level = [[[doc textView] window] level];
1050 if(level>0) SetTrue(a);
1051 else SetFalse(a);
1052 return errNone;
1055 int prTextWindow_SetPromptToSave(struct VMGlobals *g, int numArgsPushed);
1056 int prTextWindow_SetPromptToSave(struct VMGlobals *g, int numArgsPushed)
1058 if (!g->canCallOS) return errCantCallOS;
1060 PyrSlot *a = g->sp-1;
1061 PyrSlot *b = g->sp;
1063 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
1064 if (!doc) return errFailed;
1065 if(IsTrue(b))
1066 [doc setPromptToSave:YES];
1067 else
1068 [doc setPromptToSave:NO];
1069 return errNone;
1072 int prTextWindow_PromptToSave(struct VMGlobals *g, int numArgsPushed);
1073 int prTextWindow_PromptToSave(struct VMGlobals *g, int numArgsPushed)
1075 if (!g->canCallOS) return errCantCallOS;
1076 PyrSlot *a = g->sp;
1077 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
1078 if (!doc) return errFailed;
1079 bool flag = [doc promptToSave];
1080 if(flag) SetTrue(a);
1081 else SetFalse(a);
1082 return errNone;
1085 extern NSTextView *gPostView;
1087 int prTextWindow_GetIndexOfListener(struct VMGlobals *g, int numArgsPushed);
1088 int prTextWindow_GetIndexOfListener(struct VMGlobals *g, int numArgsPushed)
1090 if (!g->canCallOS) return errCantCallOS;
1092 PyrSlot *a = g->sp;
1093 NSDocumentController *docctl = [NSDocumentController sharedDocumentController];
1094 if (!docctl) return errFailed;
1095 MyDocument* doc = [gPostView delegate];
1096 if (!doc) return errFailed;
1097 int index = [[docctl documents] indexOfObject: doc];
1098 SetInt(a, index);
1099 return errNone;
1102 int prTextWindow_UsesAutoInOutdent(struct VMGlobals *g, int numArgsPushed);
1103 int prTextWindow_UsesAutoInOutdent(struct VMGlobals *g, int numArgsPushed)
1105 if (!g->canCallOS) return errCantCallOS;
1107 PyrSlot *a = g->sp - 1;
1108 PyrSlot *b = g->sp; //bool
1110 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
1111 if (!doc) return errFailed;
1112 [doc setUsesAutoInOutdent:IsTrue(b)];
1113 return errNone;
1116 int prTextWindow_DefaultUsesAutoInOutdent(struct VMGlobals *g, int numArgsPushed);
1117 int prTextWindow_DefaultUsesAutoInOutdent(struct VMGlobals *g, int numArgsPushed)
1119 if (!g->canCallOS) return errCantCallOS;
1121 //PyrSlot *a = g->sp - 1;
1122 PyrSlot *b = g->sp; //bool
1124 defaultDocumentUseAutoInOutDent = IsTrue(b);
1125 return errNone;
1129 ///////
1132 int prNewTextWindow(struct VMGlobals *g, int numArgsPushed);
1133 int prNewTextWindow(struct VMGlobals *g, int numArgsPushed)
1135 if (!g->canCallOS) return errCantCallOS;
1137 PyrSlot *d = g->sp - 3;
1138 PyrSlot *titleSlot = g->sp - 2;
1139 PyrSlot *stringSlot = g->sp - 1;
1140 PyrSlot *c = g->sp;
1142 if (!(isKindOfSlot(stringSlot, class_string))) return errWrongType;
1144 PyrString* string = slotRawString(stringSlot);
1145 NSDocumentController *docctl = [NSDocumentController sharedDocumentController];
1146 if (!docctl) return errFailed;
1147 docCreatedFromLang = true;
1148 NSError * outError;
1149 MyDocument* doc = [docctl openUntitledDocumentAndDisplay:YES error: &outError];
1150 // MyDocument* doc = [docctl currentDocument];
1151 if (!doc) {
1152 docCreatedFromLang = false;
1153 return errFailed;
1156 [doc insertText: string->s length: string->size];
1157 NSWindow *window = [[[doc windowControllers] objectAtIndex: 0] window];
1158 if (!window) {
1159 docCreatedFromLang = false;
1160 return errFailed;
1162 if (isKindOfSlot(titleSlot, class_string)) {
1163 PyrString* title = slotRawString(titleSlot);
1164 NSString *nstitle = [NSString stringWithCString: title->s length: title->size];
1165 [window setTitle: nstitle];
1167 [[doc undoManager] removeAllActions];
1169 if (IsTrue(c)) {
1170 gPostView = [doc textView];
1172 PyrObject * obj = [doc getSCObject];
1173 if(obj){
1174 //post("docuemnt has scObject already\n");
1175 docCreatedFromLang = false;
1176 SetNil(d);
1177 return errNone;
1179 [doc setSCObject: slotRawObject(d)];
1180 SetPtr(slotRawObject(d)->slots + 0, doc);
1181 docCreatedFromLang = false;
1182 return errNone;
1186 int prOpenTextFile(struct VMGlobals *g, int numArgsPushed);
1187 int prOpenTextFile(struct VMGlobals *g, int numArgsPushed)
1189 if (!g->canCallOS) return errCantCallOS;
1190 PyrSlot *d = g->sp - 3;
1192 PyrSlot *a = g->sp - 2;
1193 PyrSlot *b = g->sp - 1;
1194 PyrSlot *c = g->sp;
1196 if (!(isKindOfSlot(a, class_string))) return errWrongType;
1197 PyrString* string = slotRawString(a);
1198 if(string->size == 0) return errFailed;
1199 int rangeStart, rangeSize;
1200 int err = slotIntVal(b, &rangeStart);
1201 if (err) return err;
1202 err = slotIntVal(c, &rangeSize);
1203 if (err) return err;
1205 NSDocumentController *docctl = [NSDocumentController sharedDocumentController];
1206 if (!docctl) {
1207 post("No NSDocumentController\n");
1208 return errFailed;
1211 NSString *nsstring = [NSString stringWithCString: string->s length: string->size];
1212 NSURL *url = [NSURL fileURLWithPath: nsstring];
1213 NSString *nspath = [url path];
1215 docCreatedFromLang = true;
1216 MyDocument *doc = [docctl openDocumentWithContentsOfFile: nspath display: true];
1217 if (!doc) {
1218 post("Can't open Document '%s'\n", [nspath cString]);
1219 docCreatedFromLang = false;
1220 return errFailed;
1222 NSWindow *window = [[[doc windowControllers] objectAtIndex: 0] window];
1223 if (!window) {
1224 post("window controller returns nil\n");
1225 docCreatedFromLang = false;
1226 return errFailed;
1228 [window makeKeyAndOrderFront: nil];
1230 // select
1231 [doc selectRangeStart: rangeStart size: rangeSize];
1233 PyrObject * obj = [doc getSCObject];
1234 //if there is a scobject already don't store i
1235 if(obj){
1236 //post("docuemnt has scObject already\n");
1237 SetNil(d);
1238 docCreatedFromLang = false;
1239 return errNone;
1241 [doc setSCObject: slotRawObject(d)];
1242 SetPtr(slotRawObject(d)->slots + 0, doc);
1243 docCreatedFromLang = false;
1244 return errNone;
1247 int prGetStringFromUser(struct VMGlobals *g, int numArgsPushed);
1248 int prGetStringFromUser(struct VMGlobals *g, int numArgsPushed)
1250 if (!g->canCallOS) return errCantCallOS;
1252 //PyrSlot *a = g->sp - 2;
1253 //PyrSlot *b = g->sp - 1;
1254 //PyrSlot *c = g->sp;
1256 return errNone;
1259 extern NSFont *defaultFont;
1261 int prTextWindow_SetDefaultFont(struct VMGlobals *g, int numArgsPushed);
1262 int prTextWindow_SetDefaultFont(struct VMGlobals *g, int numArgsPushed)
1264 NSFont *newDefault, *oldDefault;
1265 if (!g->canCallOS) return errCantCallOS;
1266 PyrSlot *a = g->sp - 1;
1267 PyrSlot *fontSlot = g->sp; //font
1268 if (IsNil(fontSlot)) return errNone; // use default font
1269 if (!(isKindOfSlot(fontSlot, s_font->u.classobj))) return errWrongType;
1271 PyrSlot *nameSlot = slotRawObject(fontSlot)->slots+0;
1272 PyrSlot *sizeSlot = slotRawObject(fontSlot)->slots+1;
1273 float size;
1274 int err = slotFloatVal(sizeSlot, &size);
1275 if (err) return err;
1277 PyrString *pstring = slotRawString(nameSlot);
1278 NSString *fontName = [NSString stringWithCString: pstring->s length: pstring->size];
1279 if (!fontName) return errFailed;
1280 newDefault = [NSFont fontWithName: fontName size: size];
1281 if (!newDefault) {
1282 return errFailed;
1283 } else {
1284 oldDefault = defaultFont;
1285 [newDefault retain];
1286 defaultFont = newDefault;
1287 [oldDefault release];
1289 return errNone;
1293 extern SCColor postTextColor;
1295 int prSetPostTextColor(struct VMGlobals *g, int numArgsPushed);
1296 int prSetPostTextColor(struct VMGlobals *g, int numArgsPushed)
1298 PyrSlot *a;
1299 PyrSlot *c;
1301 a = g->sp - 1;
1302 c = a + 1;
1304 if(!(isKindOfSlot(c, s_color->u.classobj))) return errWrongType;
1306 int err = slotColorVal(c, &postTextColor);
1307 if(err) return err;
1309 return errNone;
1313 int prBalanceParens(struct VMGlobals *g, int numArgsPushed);
1314 int prBalanceParens(struct VMGlobals *g, int numArgsPushed)
1316 if (!g->canCallOS) return errCantCallOS;
1318 PyrSlot *a = g->sp;
1320 MyDocument* doc = (MyDocument*) slotRawPtr(slotRawObject(a)->slots);
1321 if (!doc) return errFailed;
1322 [[doc activeTextView] balanceParens: nil];
1324 return errNone;
1328 int slotGetNSRect(PyrSlot* a, NSRect *r)
1330 PyrSlot *slots = slotRawObject(a)->slots;
1331 int err;
1332 err = slotVal(slots+0, &r->origin.x);
1333 if (err) return err;
1334 err = slotVal(slots+1, &r->origin.y);
1335 if (err) return err;
1336 err = slotVal(slots+2, &r->size.width);
1337 if (err) return err;
1338 err = slotVal(slots+3, &r->size.height);
1339 if (err) return err;
1341 return errNone;
1345 int slotGetCGRect(PyrSlot* a, CGRect *r)
1347 PyrSlot *slots = slotRawObject(a)->slots;
1348 int err;
1349 err = slotVal(slots+0, &r->origin.x);
1350 if (err) return err;
1351 err = slotVal(slots+1, &r->origin.y);
1352 if (err) return err;
1353 err = slotVal(slots+2, &r->size.width);
1354 if (err) return err;
1355 err = slotVal(slots+3, &r->size.height);
1356 if (err) return err;
1358 return errNone;
1362 int slotGetPoint(PyrSlot* a, NSPoint *p)
1364 PyrSlot *slots = slotRawObject(a)->slots;
1365 int err;
1366 err = slotVal(slots+0, &p->x);
1367 if (err) return err;
1368 err = slotVal(slots+1, &p->y);
1369 if (err) return err;
1371 return errNone;
1374 int prSCWindow_New(struct VMGlobals *g, int numArgsPushed);
1375 int prSCWindow_New(struct VMGlobals *g, int numArgsPushed)
1377 if (!g->canCallOS) return errCantCallOS;
1379 PyrSlot *args = g->sp - 6;
1380 PyrSlot *a = args + 0;
1381 PyrSlot *b = args + 1; // name
1382 PyrSlot *c = args + 2; // bounds
1383 PyrSlot *d = args + 3; // resizable
1384 PyrSlot *e = args + 4; // border
1385 PyrSlot *f = args + 6; // view
1386 PyrSlot *h = args + 5; // scroll
1387 PyrSlot *j = args + 7; // is this app modal? (Doesn't matter for sheets as they have no close button)
1389 if (!(isKindOfSlot(b, class_string))) return errWrongType;
1390 if (!(isKindOfSlot(c, s_rect->u.classobj))) return errWrongType;
1392 bool eIsTrue = IsTrue(e);
1393 unsigned int mask = IsTrue(d) && eIsTrue ? NSResizableWindowMask : 0;
1394 if (IsFalse(j) && eIsTrue){
1395 mask |= NSMiniaturizableWindowMask | NSClosableWindowMask;
1397 mask |= eIsTrue ? NSTitledWindowMask | NSTexturedBackgroundWindowMask : NSBorderlessWindowMask;
1399 NSRect bounds;
1400 int err = slotGetNSRect(c, &bounds);
1401 if (err) return err;
1403 PyrString *string = slotRawString(b);
1404 NSString *title = [NSString stringWithCString: string->s length: string->size];
1406 SCNSWindow *window = [[SCNSWindow alloc]
1407 initWithContentRect: bounds
1408 styleMask: mask
1409 backing: NSBackingStoreBuffered
1410 defer: NO];
1411 [window setTitle: title];
1412 [window setHasBorders: YES];
1414 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1415 SCGraphView* view = [[SCGraphView alloc] initWithFrame: bounds];
1416 [view setSCObject: slotRawObject(a)];
1417 SetPtr(slotRawObject(a)->slots + 0, view);
1418 [window setDelegate: scvm];
1419 [window setSCGraphView: view];
1421 if(IsTrue(h)) {
1422 SCScrollTopView* scrollTopView = (SCScrollTopView*)slotRawPtr(slotRawObject(f)->slots);
1423 [view setSCTopView: scrollTopView];
1425 NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame: bounds];
1426 [scrollView setHasVerticalScroller:YES];
1427 [scrollView setHasHorizontalScroller:YES];
1428 [scrollView setAutohidesScrollers:YES];
1429 [[scrollView horizontalScroller] setControlSize:NSSmallControlSize];
1430 [[scrollView verticalScroller] setControlSize:NSSmallControlSize];
1431 [[scrollView horizontalScroller] setControlTint:NSGraphiteControlTint];
1432 [[scrollView verticalScroller] setControlTint:NSGraphiteControlTint];
1434 [scrollView setBackgroundColor:[NSColor clearColor]];
1435 [scrollView setDrawsBackground:NO];
1436 // configure the scroller to have no visible border
1437 [scrollView setBorderType:NSNoBorder];
1438 [scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
1439 [scrollView setDocumentView:view];
1441 [scrollView setPostsFrameChangedNotifications: YES]; // we need this to resize the SCGraphView if the scroll view exceeds its bounds
1442 [[NSNotificationCenter defaultCenter] addObserver:view
1443 selector:@selector(scrollViewResized:)
1444 name:@"NSViewFrameDidChangeNotification"
1445 object:scrollView];
1447 NSClipView *contentView = [scrollView contentView];
1448 [contentView setPostsBoundsChangedNotifications:YES];
1449 [[NSNotificationCenter defaultCenter] addObserver:view
1450 selector:@selector(userScrolled:)
1451 name:@"NSViewBoundsDidChangeNotification"
1452 object:contentView];
1454 scrollTopView->SetNSScrollView(scrollView);
1455 [view autorelease];
1457 [window setContentView: scrollView];
1458 [scrollView autorelease];
1460 } else {
1461 [view setSCTopView: (SCTopView*)slotRawPtr(slotRawObject(f)->slots)];
1462 [window setContentView: view];
1463 [view autorelease];
1466 NSRect matrect = NSMakeRect(40,40,400,400);
1467 NSSize cellsize = NSMakeSize(200,100);
1468 id mx = [[NSMatrix alloc]
1469 initWithFrame: matrect
1470 mode: NSTrackModeMatrix
1471 cellClass: [NSSliderCell class]
1472 numberOfRows: 4
1473 numberOfColumns: 2 ];
1474 [mx setCellSize: cellsize];
1475 [view addSubview: mx];
1478 [window makeFirstResponder: view];
1479 [window setFrameOrigin: bounds.origin];
1480 [scvm addWindow: window];
1483 id sender = nil;
1485 SEL sel = @selector(makeKeyAndOrderFront:);
1486 NSMethodSignature *sig = [NSWindow instanceMethodSignatureForSelector: sel];
1488 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1489 [anInvocation setTarget: window];
1490 [anInvocation setSelector: sel];
1491 [anInvocation setArgument: &sender atIndex: 2];
1492 [scvm defer: anInvocation];
1495 SEL sel = @selector(newGuiWindowTitle:bounds:SCObject:styleMask:);
1496 NSMethodSignature *sig = [SCVirtualMachine instanceMethodSignatureForSelector: sel];
1498 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1499 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1500 [anInvocation setTarget: scvm];
1501 [anInvocation setSelector: sel];
1502 [anInvocation setArgument: &title atIndex: 2];
1503 [anInvocation setArgument: &bounds atIndex: 3];
1504 [anInvocation setArgument: &slotRawObject(a) atIndex: 4];
1505 [anInvocation setArgument: &flags atIndex: 5];
1506 [scvm defer: anInvocation];
1508 return errNone;
1511 int prSCWindow_Refresh(struct VMGlobals *g, int numArgsPushed);
1512 int prSCWindow_Refresh(struct VMGlobals *g, int numArgsPushed)
1514 if (!g->canCallOS) return errCantCallOS;
1516 PyrSlot *a = g->sp;
1517 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1518 if (!view) return errNone;
1520 SEL sel = @selector(setNeedsDisplay:);
1521 NSMethodSignature *sig = [NSView instanceMethodSignatureForSelector: sel];
1523 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1524 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1525 [anInvocation setTarget: view];
1526 [anInvocation setSelector: sel];
1527 BOOL flag = YES;
1528 [anInvocation setArgument: &flag atIndex: 2];
1529 [scvm defer: anInvocation];
1531 return errNone;
1534 int prSCWindow_Close(struct VMGlobals *g, int numArgsPushed);
1535 int prSCWindow_Close(struct VMGlobals *g, int numArgsPushed)
1537 PyrSlot *a = g->sp;
1538 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1539 if (!view) return errNone;
1540 // [[view window] close];
1542 // NSWindow *window = [view window];
1544 SEL sel = @selector(closeWindow);
1545 NSMethodSignature *sig = [SCGraphView instanceMethodSignatureForSelector: sel];
1547 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1548 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1549 [anInvocation setTarget: view];
1550 [anInvocation setSelector: sel];
1551 [scvm defer: anInvocation];
1553 return errNone;
1556 int prSCWindow_Minimize(struct VMGlobals *g, int numArgsPushed);
1557 int prSCWindow_Minimize(struct VMGlobals *g, int numArgsPushed)
1559 if (!g->canCallOS) return errCantCallOS;
1561 PyrSlot *a = g->sp;
1562 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1563 if (!view) return errNone;
1564 //[[view window] miniaturize: nil];
1566 NSWindow *window = [view window];
1567 id sender = nil;
1569 SEL sel = @selector(miniaturize:);
1570 NSMethodSignature *sig = [NSWindow instanceMethodSignatureForSelector: sel];
1572 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1573 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1574 [anInvocation setTarget: window];
1575 [anInvocation setSelector: sel];
1576 [anInvocation setArgument: &sender atIndex: 2];
1577 [scvm defer: anInvocation];
1579 return errNone;
1582 int prSCWindow_ToFront(struct VMGlobals *g, int numArgsPushed);
1583 int prSCWindow_ToFront(struct VMGlobals *g, int numArgsPushed)
1585 if (!g->canCallOS) return errCantCallOS;
1587 PyrSlot *a = g->sp;
1588 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1589 if (!view) return errNone;
1590 //[[view window] makeKeyAndOrderFront: nil];
1592 NSWindow *window = [view window];
1593 id sender = nil;
1595 SEL sel = @selector(makeKeyAndOrderFront:);
1596 NSMethodSignature *sig = [NSWindow instanceMethodSignatureForSelector: sel];
1598 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1599 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1600 [anInvocation setTarget: window];
1601 [anInvocation setSelector: sel];
1602 [anInvocation setArgument: &sender atIndex: 2];
1603 [scvm defer: anInvocation];
1605 return errNone;
1609 int prSCWindow_FullScreen(struct VMGlobals *g, int numArgsPushed);
1610 int prSCWindow_FullScreen(struct VMGlobals *g, int numArgsPushed)
1612 if (!g->canCallOS) return errCantCallOS;
1614 PyrSlot *a = g->sp;
1615 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1616 if (!view) return errNone;
1618 NSWindow *window = [view window];
1620 SEL sel = @selector(becomeFullScreen:);
1621 NSMethodSignature *sig = [SCVirtualMachine instanceMethodSignatureForSelector: sel];
1623 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1624 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1625 [anInvocation setTarget: scvm];
1626 [anInvocation setSelector: sel];
1627 [anInvocation setArgument: &window atIndex: 2];
1628 [scvm defer: anInvocation];
1630 return errNone;
1633 int prSCWindow_EndFullScreen(struct VMGlobals *g, int numArgsPushed);
1634 int prSCWindow_EndFullScreen(struct VMGlobals *g, int numArgsPushed)
1636 if (!g->canCallOS) return errCantCallOS;
1638 PyrSlot *a = g->sp;
1639 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1640 if (!view) return errNone;
1642 NSWindow *window = [view window];
1644 SEL sel = @selector(endFullScreen:);
1645 NSMethodSignature *sig = [SCVirtualMachine instanceMethodSignatureForSelector: sel];
1647 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1648 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1649 [anInvocation setTarget: scvm];
1650 [anInvocation setSelector: sel];
1651 [anInvocation setArgument: &window atIndex: 2];
1652 [scvm defer: anInvocation];
1654 return errNone;
1657 int prSCWindow_SetShouldClose(struct VMGlobals *g, int numArgsPushed);
1658 int prSCWindow_SetShouldClose(struct VMGlobals *g, int numArgsPushed)
1660 PyrSlot *a = g->sp - 1;
1661 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1662 if (!view) return errNone;
1663 PyrSlot *boo = g->sp;
1665 // no need to defer, right ?
1666 [view setWindowShouldClose: IsTrue(boo)];
1668 return errNone;
1671 int prSCWindow_AlwaysOnTop(struct VMGlobals *g, int numArgsPushed);
1672 int prSCWindow_AlwaysOnTop(struct VMGlobals *g, int numArgsPushed)
1674 if (!g->canCallOS) return errCantCallOS;
1676 PyrSlot *a = g->sp - 1;
1677 PyrSlot *b = g->sp;
1679 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1680 if (!view) return errNone;
1681 NSWindow *window = [view window];
1682 if(IsTrue(b))
1683 [window setLevel:NSFloatingWindowLevel];
1684 else
1685 [window setLevel:NSNormalWindowLevel];
1686 return errNone;
1689 int prSCWindow_AcceptsClickThrough(struct VMGlobals *g, int numArgsPushed);
1690 int prSCWindow_AcceptsClickThrough(struct VMGlobals *g, int numArgsPushed)
1692 if (!g->canCallOS) return errCantCallOS;
1694 PyrSlot *a = g->sp - 1;
1695 PyrSlot *b = g->sp;
1697 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1698 if (!view) return errNone;
1699 if(IsTrue(b))
1700 [view setAcceptsClickThrough:YES];
1701 else
1702 [view setAcceptsClickThrough:NO];
1703 return errNone;
1706 int prSCWindow_SetName(struct VMGlobals *g, int numArgsPushed);
1707 int prSCWindow_SetName(struct VMGlobals *g, int numArgsPushed)
1709 if (!g->canCallOS) return errCantCallOS;
1711 PyrSlot *a = g->sp - 1;
1712 PyrSlot *b = g->sp;
1714 if (!(isKindOfSlot(b, class_string))) return errWrongType;
1716 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1717 if (!view) return errNone;
1718 PyrString *string = slotRawString(b);
1719 NSString *title = [NSString stringWithCString: string->s length: string->size];
1720 [[view window] setTitle: title];
1721 return errNone;
1724 int prSCWindow_SetBounds(struct VMGlobals *g, int numArgsPushed);
1725 int prSCWindow_SetBounds(struct VMGlobals *g, int numArgsPushed)
1727 if (!g->canCallOS) return errCantCallOS;
1729 PyrSlot *a = g->sp - 1;
1730 PyrSlot *b = g->sp;
1732 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
1734 NSRect bounds;
1735 int err = slotGetNSRect(b, &bounds);
1736 if (err) return err;
1738 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1739 if (!view) return errNone;
1741 NSWindow *window = [view window];
1743 bounds = [NSWindow frameRectForContentRect: bounds styleMask: [window styleMask]];
1745 //[window setFrame: bounds display: YES];
1747 SEL sel = @selector(setFrame:display:);
1748 NSMethodSignature *sig = [NSWindow instanceMethodSignatureForSelector: sel];
1749 BOOL flag = YES;
1751 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1752 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1753 [anInvocation setTarget: window];
1754 [anInvocation setSelector: sel];
1755 [anInvocation setArgument: &bounds atIndex: 2];
1756 [anInvocation setArgument: &flag atIndex: 3];
1757 [scvm defer: anInvocation];
1759 return errNone;
1762 int prSCWindow_GetBounds(struct VMGlobals *g, int numArgsPushed);
1763 int prSCWindow_GetBounds(struct VMGlobals *g, int numArgsPushed)
1765 if (!g->canCallOS) return errCantCallOS;
1767 PyrSlot *a = g->sp - 1;
1768 PyrSlot *b = g->sp;
1770 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
1772 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1773 if (!view) return errNone;
1775 NSWindow *window = [view window];
1776 NSRect bounds = [window frame];
1777 bounds = [NSWindow contentRectForFrameRect: bounds styleMask: [window styleMask]];
1779 PyrSlot *slots = slotRawObject(b)->slots;
1780 SetFloat(slots+0, bounds.origin.x);
1781 SetFloat(slots+1, bounds.origin.y);
1782 SetFloat(slots+2, bounds.size.width);
1783 SetFloat(slots+3, bounds.size.height);
1784 slotCopy(a, b);
1786 return errNone;
1789 int prSCWindow_GetScreenBounds(struct VMGlobals *g, int numArgsPushed);
1790 int prSCWindow_GetScreenBounds(struct VMGlobals *g, int numArgsPushed)
1792 if (!g->canCallOS) return errCantCallOS;
1794 PyrSlot *a = g->sp - 1;
1795 PyrSlot *b = g->sp;
1797 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
1799 NSRect bounds = [[NSScreen mainScreen] frame];
1800 PyrSlot *slots = slotRawObject(b)->slots;
1801 SetFloat(slots+0, bounds.origin.x);
1802 SetFloat(slots+1, bounds.origin.y);
1803 SetFloat(slots+2, bounds.size.width);
1804 SetFloat(slots+3, bounds.size.height);
1805 slotCopy(a, b);
1807 return errNone;
1813 //doesn't work as intended
1814 int prSCWindow_Show(struct VMGlobals *g, int numArgsPushed);
1815 int prSCWindow_Show(struct VMGlobals *g, int numArgsPushed)
1817 if (!g->canCallOS) return errCantCallOS;
1819 PyrSlot *a = g->sp;
1820 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1822 NSWindow *window = [view window];
1823 NSRect frame = [window frame];
1825 SEL sel = @selector(setFrame:display:);
1826 NSMethodSignature *sig = [NSWindow instanceMethodSignatureForSelector: sel];
1827 BOOL flag = YES;
1829 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1830 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1831 [anInvocation setTarget: window];
1832 [anInvocation setSelector: sel];
1833 [anInvocation setArgument: &frame atIndex: 2];
1834 [anInvocation setArgument: &flag atIndex: 3];
1835 [scvm defer: anInvocation];
1837 return errNone;
1839 //doesn't work as intended
1840 int prSCWindow_Hide(struct VMGlobals *g, int numArgsPushed);
1841 int prSCWindow_Hide(struct VMGlobals *g, int numArgsPushed)
1843 if (!g->canCallOS) return errCantCallOS;
1845 PyrSlot *a = g->sp;
1846 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1847 NSWindow *window = [view window];
1848 NSRect frame = [window frame];
1850 SEL sel = @selector(setFrame:display:);
1851 NSMethodSignature *sig = [NSWindow instanceMethodSignatureForSelector: sel];
1852 BOOL flag = NO;
1854 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1855 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1856 [anInvocation setTarget: window];
1857 [anInvocation setSelector: sel];
1858 [anInvocation setArgument: &frame atIndex: 2];
1859 [anInvocation setArgument: &flag atIndex: 3];
1860 [scvm defer: anInvocation];
1862 return errNone;
1865 int prSCWindow_SetAlpha(struct VMGlobals *g, int numArgsPushed);
1866 int prSCWindow_SetAlpha(struct VMGlobals *g, int numArgsPushed)
1868 if (!g->canCallOS) return errCantCallOS;
1870 PyrSlot *a = g->sp - 1;
1871 PyrSlot *b = g->sp;
1873 float alpha;
1874 int err = slotFloatVal(b, &alpha);
1875 if (err) return err;
1877 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1878 if (!view) return errNone;
1880 //[[view window] setAlphaValue: alpha];
1881 NSWindow *window = [view window];
1883 SEL sel = @selector(setAlphaValue:);
1884 NSMethodSignature *sig = [NSWindow instanceMethodSignatureForSelector: sel];
1886 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1887 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1888 [anInvocation setTarget: window];
1889 [anInvocation setSelector: sel];
1890 [anInvocation setArgument: &alpha atIndex: 2];
1891 [scvm defer: anInvocation];
1893 return errNone;
1896 int prSCWindow_SetAcceptMouseOver(struct VMGlobals *g, int numArgsPushed);
1897 int prSCWindow_SetAcceptMouseOver(struct VMGlobals *g, int numArgsPushed)
1899 if (!g->canCallOS) return errCantCallOS;
1901 PyrSlot *a = g->sp - 1;
1902 PyrSlot *b = g->sp;
1904 BOOL accept;
1905 accept = (BOOL) IsTrue(b);
1907 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1908 if (!view) return errNone;
1910 NSWindow *window = [view window];
1911 [window setAcceptsMouseMovedEvents:accept];
1912 return errNone;
1915 int prSCWindow_RunModal(struct VMGlobals *g, int numArgsPushed);
1916 int prSCWindow_RunModal(struct VMGlobals *g, int numArgsPushed)
1918 if (!g->canCallOS) return errCantCallOS;
1920 PyrSlot *a = g->sp;
1922 SCGraphView* view = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1923 if (!view) return errNone;
1925 NSWindow *window = [view window];
1927 SEL sel = @selector(runAsModal:);
1928 NSMethodSignature *sig = [SCVirtualMachine instanceMethodSignatureForSelector: sel];
1930 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1931 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1932 [anInvocation setTarget: scvm];
1933 [anInvocation setSelector: sel];
1934 [anInvocation setArgument: &window atIndex: 2];
1935 [scvm defer: anInvocation];
1937 return errNone;
1940 int prSCWindow_StopModal(struct VMGlobals *g, int numArgsPushed);
1941 int prSCWindow_StopModal(struct VMGlobals *g, int numArgsPushed)
1943 if (!g->canCallOS) return errCantCallOS;
1945 [NSApp abortModal];
1947 return errNone;
1950 int prSCWindow_RunModalSheet(struct VMGlobals *g, int numArgsPushed);
1951 int prSCWindow_RunModalSheet(struct VMGlobals *g, int numArgsPushed)
1953 if (!g->canCallOS) return errCantCallOS;
1955 PyrSlot *a = g->sp - 1;
1956 PyrSlot *b = g->sp;
1958 SCGraphView* sheetView = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1959 if (!sheetView) return errNone;
1961 SCNSWindow *sheet = (SCNSWindow*)[sheetView window];
1963 SCGraphView* windowView = (SCGraphView*)slotRawPtr(slotRawObject(b)->slots);
1964 if (!windowView) return errNone;
1966 NSWindow *window = [windowView window];
1968 SEL sel = @selector(runAsModalSheet:forWindow:);
1969 NSMethodSignature *sig = [SCVirtualMachine instanceMethodSignatureForSelector: sel];
1971 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
1972 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
1973 [anInvocation setTarget: scvm];
1974 [anInvocation setSelector: sel];
1975 [anInvocation setArgument: &sheet atIndex: 2];
1976 [anInvocation setArgument: &window atIndex: 3];
1977 [scvm defer: anInvocation];
1979 return errNone;
1982 int prSCWindow_StopModalSheet(struct VMGlobals *g, int numArgsPushed);
1983 int prSCWindow_StopModalSheet(struct VMGlobals *g, int numArgsPushed)
1985 if (!g->canCallOS) return errCantCallOS;
1987 PyrSlot *a = g->sp;
1989 SCGraphView* sheetView = (SCGraphView*)slotRawPtr(slotRawObject(a)->slots);
1990 if (!sheetView) return errNone;
1992 NSWindow *sheet = [sheetView window];
1994 [NSApp endSheet:sheet];
1996 return errNone;
1999 int prShowCursor(struct VMGlobals *g, int numArgsPushed);
2000 int prShowCursor(struct VMGlobals *g, int numArgsPushed)
2002 if (!g->canCallOS) return errCantCallOS;
2004 PyrSlot *a = g->sp - 1;
2005 PyrSlot *b = g->sp;
2007 BOOL show;
2008 show = (BOOL) IsTrue(b);
2009 if(show) [NSCursor unhide];
2010 else [NSCursor hide];
2011 return errNone;
2014 int addFontAttribute(NSMutableDictionary *dict, PyrSlot *fontSlot);
2015 int addFontAttribute(NSMutableDictionary *dict, PyrSlot *fontSlot)
2017 if (IsNil(fontSlot)) return errNone; // use default font
2018 if (!(isKindOfSlot(fontSlot, s_font->u.classobj))) return errWrongType;
2020 PyrSlot *nameSlot = slotRawObject(fontSlot)->slots+0;
2021 PyrSlot *sizeSlot = slotRawObject(fontSlot)->slots+1;
2023 if (!(isKindOfSlot(nameSlot, class_string))) return errWrongType;
2025 float size;
2026 int err = slotFloatVal(sizeSlot, &size);
2027 if (err) return err;
2029 PyrString *string = slotRawString(nameSlot);
2030 NSString *fontName = [NSString stringWithCString: string->s length: string->size];
2031 if (!fontName) return errFailed;
2032 NSFont *font = [NSFont fontWithName: fontName size: size];
2033 if (!font) return errFailed;
2034 [dict setObject: font forKey: NSFontAttributeName ];
2036 return errNone;
2041 int slotRGBColorVal(PyrSlot *slot, RGBColor *rgbcolor)
2043 if (!(isKindOfSlot(slot, s_color->u.classobj))) return errWrongType;
2045 PyrSlot *slots = slotRawObject(slot)->slots;
2047 int err;
2048 float red, green, blue, alpha;
2049 err = slotFloatVal(slots+0, &red);
2050 if (err) return err;
2051 err = slotFloatVal(slots+1, &green);
2052 if (err) return err;
2053 err = slotFloatVal(slots+2, &blue);
2054 if (err) return err;
2055 err = slotFloatVal(slots+3, &alpha);
2056 if (err) return err;
2058 rgbcolor->red = (unsigned short)(red * 65535.);
2059 rgbcolor->green = (unsigned short)(green * 65535.);
2060 rgbcolor->blue = (unsigned short)(blue * 65535.);
2061 //rgbcolor->alpha = (unsigned short)(alpha * 65535.);
2063 return errNone;
2066 int addFontColorAttribute(NSMutableDictionary *dict, PyrSlot *colorSlot);
2067 int addFontColorAttribute(NSMutableDictionary *dict, PyrSlot *colorSlot)
2069 if (IsNil(colorSlot)) return errNone; // use default color
2070 SCColor rgb;
2071 int err = slotColorVal(colorSlot, &rgb);
2072 if (err) return err;
2073 NSColor *color = [NSColor colorWithCalibratedRed: rgb.red
2074 green: rgb.green
2075 blue: rgb.blue
2076 alpha: rgb.alpha];
2077 [dict setObject: color forKey: NSForegroundColorAttributeName ];
2079 return errNone;
2082 int prFont_AvailableFonts(struct VMGlobals *g, int numArgsPushed);
2083 int prFont_AvailableFonts(struct VMGlobals *g, int numArgsPushed)
2085 if (!g->canCallOS) return errCantCallOS;
2087 PyrSlot *a = g->sp;
2089 NSFontManager *fontManager = [NSFontManager sharedFontManager];
2090 NSArray *fonts = [fontManager availableFonts];
2092 int size = [fonts count];
2093 PyrObject* array = newPyrArray(g->gc, size, 0, true);
2094 SetObject(a, array);
2096 for (int i=0; i<size; ++i) {
2097 NSString *name = [fonts objectAtIndex: i];
2098 //if (!name) continue;
2099 PyrString *string = newPyrString(g->gc, [name UTF8String], 0, true);
2100 SetObject(array->slots + array->size, string);
2101 array->size++;
2102 g->gc->GCWrite(array, string);
2105 return errNone;
2108 int prFont_SetAntiAliasing(struct VMGlobals *g, int numArgsPushed);
2109 int prFont_SetAntiAliasing(struct VMGlobals *g, int numArgsPushed)
2111 if (!g->canCallOS) return errCantCallOS;
2113 //PyrSlot *a = g->sp - 1;
2114 PyrSlot *b = g->sp;
2116 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2117 if (!gctx) return errFailed;
2118 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2119 CGContextSetShouldAntialias(cgc, IsTrue(b));
2121 return errNone;
2124 int prFont_SetSmoothing(struct VMGlobals *g, int numArgsPushed);
2125 int prFont_SetSmoothing(struct VMGlobals *g, int numArgsPushed)
2127 if (!g->canCallOS) return errCantCallOS;
2129 //PyrSlot *a = g->sp - 1;
2130 PyrSlot *b = g->sp;
2132 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2133 if (!gctx) return errFailed;
2134 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2135 CGContextSetShouldSmoothFonts(cgc, IsTrue(b));
2137 return errNone;
2140 int prPen_SetSmoothing(struct VMGlobals *g, int numArgsPushed);
2141 int prPen_SetSmoothing(struct VMGlobals *g, int numArgsPushed)
2143 if (!g->canCallOS) return errCantCallOS;
2145 //PyrSlot *a = g->sp - 1;
2146 PyrSlot *b = g->sp;
2148 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2149 if (!gctx) return errFailed;
2150 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2151 CGContextSetShouldAntialias(cgc, IsTrue(b));
2153 return errNone;
2157 int prString_GetBounds(struct VMGlobals *g, int numArgsPushed);
2158 int prString_GetBounds(struct VMGlobals *g, int numArgsPushed)
2160 if (!g->canCallOS) return errCantCallOS;
2162 PyrSlot *a = g->sp - 2;
2163 PyrSlot *b = g->sp - 1;
2164 PyrSlot *c = g->sp;
2166 if (!isKindOfSlot(b, s_rect->u.classobj)) return errWrongType;
2168 NSMutableDictionary *dict = [NSMutableDictionary dictionary];
2169 int err = addFontAttribute(dict, c);
2170 if (err) return err;
2172 PyrString* string = slotRawString(a);
2173 NSString *nsstring = [NSString stringWithCString: string->s length: string->size];
2174 if (!nsstring) return errFailed;
2175 NSSize size = [nsstring sizeWithAttributes: dict];
2177 PyrSlot* rectSlots = slotRawObject(b)->slots;
2178 SetFloat(rectSlots+0, 0.);
2179 SetFloat(rectSlots+1, 0.);
2180 SetFloat(rectSlots+2, size.width);
2181 SetFloat(rectSlots+3, size.height);
2182 slotCopy(a, b);
2184 return errNone;
2187 int prString_DrawAtPoint(struct VMGlobals *g, int numArgsPushed);
2188 int prString_DrawAtPoint(struct VMGlobals *g, int numArgsPushed)
2190 if (!g->canCallOS) return errCantCallOS;
2192 PyrSlot *a = g->sp - 3;
2193 PyrSlot *b = g->sp - 2;
2194 PyrSlot *c = g->sp - 1;
2195 PyrSlot *d = g->sp;
2197 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
2199 NSPoint p;
2200 int err = slotGetPoint(b, &p);
2201 if (err) return err;
2203 NSMutableDictionary *dict = [NSMutableDictionary dictionary];
2204 err = addFontAttribute(dict, c);
2205 if (err) return err;
2206 err = addFontColorAttribute(dict, d);
2207 if (err) return err;
2209 PyrString* string = slotRawString(a);
2210 NSString *nsstring = [NSString stringWithCString: string->s length: string->size];
2211 if (!nsstring) return errFailed;
2213 [nsstring drawAtPoint: p withAttributes: dict];
2215 return errNone;
2218 int prString_DrawInRect(struct VMGlobals *g, int numArgsPushed);
2219 int prString_DrawInRect(struct VMGlobals *g, int numArgsPushed)
2221 if (!g->canCallOS) return errCantCallOS;
2223 PyrSlot *a = g->sp - 3;
2224 PyrSlot *b = g->sp - 2;
2225 PyrSlot *c = g->sp - 1;
2226 PyrSlot *d = g->sp;
2228 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
2230 NSRect rect;
2231 int err = slotGetNSRect(b, &rect);
2232 if (err) return err;
2234 NSMutableDictionary *dict = [NSMutableDictionary dictionary];
2235 err = addFontAttribute(dict, c);
2236 if (err) return err;
2237 err = addFontColorAttribute(dict, d);
2238 if (err) return err;
2240 PyrString* string = slotRawString(a);
2241 NSString *nsstring = [NSString stringWithCString: string->s length: string->size];
2242 if (!nsstring) return errFailed;
2244 [nsstring drawInRect: rect withAttributes: dict];
2246 return errNone;
2249 int prColor_SetStroke(struct VMGlobals *g, int numArgsPushed);
2250 int prColor_SetStroke(struct VMGlobals *g, int numArgsPushed)
2252 if (!g->canCallOS) return errCantCallOS;
2254 PyrSlot *a = g->sp;
2255 PyrSlot *slots = slotRawObject(a)->slots;
2256 int err;
2257 float red, green, blue, alpha;
2259 err = slotFloatVal(slots+0, &red);
2260 if (err) return err;
2261 err = slotFloatVal(slots+1, &green);
2262 if (err) return err;
2263 err = slotFloatVal(slots+2, &blue);
2264 if (err) return err;
2265 err = slotFloatVal(slots+3, &alpha);
2266 if (err) return err;
2268 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2269 if (!gctx) return errFailed;
2270 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2271 CGContextSetRGBStrokeColor(cgc, red, green, blue, alpha);
2272 // CGContextSetRGBFillColor(cgc, red, green, blue, alpha);
2273 /* NSColor *color = [NSColor colorWithCalibratedRed: red
2274 green: green
2275 blue: blue
2276 alpha: alpha];
2277 if (color) {
2278 [color set];
2281 return errNone;
2284 int prColor_SetFill(struct VMGlobals *g, int numArgsPushed);
2285 int prColor_SetFill(struct VMGlobals *g, int numArgsPushed)
2287 if (!g->canCallOS) return errCantCallOS;
2289 PyrSlot *a = g->sp;
2290 PyrSlot *slots = slotRawObject(a)->slots;
2291 int err;
2292 float red, green, blue, alpha;
2294 err = slotFloatVal(slots+0, &red);
2295 if (err) return err;
2296 err = slotFloatVal(slots+1, &green);
2297 if (err) return err;
2298 err = slotFloatVal(slots+2, &blue);
2299 if (err) return err;
2300 err = slotFloatVal(slots+3, &alpha);
2301 if (err) return err;
2303 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2304 if (!gctx) return errFailed;
2305 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2306 CGContextSetRGBFillColor(cgc, red, green, blue, alpha);
2307 // NSColor *color = [NSColor colorWithCalibratedRed: red
2308 // green: green
2309 // blue: blue
2310 // alpha: alpha];
2311 // if (color) {
2312 // [color setFill];
2313 // }
2315 return errNone;
2318 int prPen_Push(struct VMGlobals *g, int numArgsPushed);
2319 int prPen_Push(struct VMGlobals *g, int numArgsPushed)
2321 if (!g->canCallOS) return errCantCallOS;
2323 [NSGraphicsContext saveGraphicsState];
2324 return errNone;
2327 int prPen_Pop(struct VMGlobals *g, int numArgsPushed);
2328 int prPen_Pop(struct VMGlobals *g, int numArgsPushed)
2330 if (!g->canCallOS) return errCantCallOS;
2332 [NSGraphicsContext restoreGraphicsState];
2333 return errNone;
2336 int prPen_AddRect(struct VMGlobals *g, int numArgsPushed);
2337 int prPen_AddRect(struct VMGlobals *g, int numArgsPushed)
2339 if (!g->canCallOS) return errCantCallOS;
2341 //PyrSlot *a = g->sp - 1;
2342 PyrSlot *b = g->sp;
2344 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
2346 CGRect rect;
2347 int err = slotGetCGRect(b, &rect);
2348 if (err) return err;
2350 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2351 if (!gctx) return errFailed;
2352 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2354 CGContextAddRect(cgc, rect);
2355 return errNone;
2358 int prPen_StrokeRect(struct VMGlobals *g, int numArgsPushed);
2359 int prPen_StrokeRect(struct VMGlobals *g, int numArgsPushed)
2361 if (!g->canCallOS) return errCantCallOS;
2363 //PyrSlot *a = g->sp - 1;
2364 PyrSlot *b = g->sp;
2366 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
2368 CGRect rect;
2369 int err = slotGetCGRect(b, &rect);
2370 if (err)
2371 return err;
2373 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2374 if (!gctx)
2375 return errFailed;
2377 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2378 CGContextBeginPath(cgc);
2379 CGContextAddRect(cgc, rect);
2380 CGContextDrawPath(cgc, kCGPathStroke);
2382 return errNone;
2385 int prPen_FillRect(struct VMGlobals *g, int numArgsPushed);
2386 int prPen_FillRect(struct VMGlobals *g, int numArgsPushed)
2388 if (!g->canCallOS) return errCantCallOS;
2390 //PyrSlot *a = g->sp - 1;
2391 PyrSlot *b = g->sp;
2393 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
2395 CGRect rect;
2396 int err = slotGetCGRect(b, &rect);
2397 if (err)
2398 return err;
2400 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
2401 if( !ctx )
2402 return errFailed;
2404 CGContextFillRect( ctx, rect );
2406 return errNone;
2409 int prPen_StrokeOval(struct VMGlobals *g, int numArgsPushed);
2410 int prPen_StrokeOval(struct VMGlobals *g, int numArgsPushed)
2412 if (!g->canCallOS) return errCantCallOS;
2414 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
2415 if( !ctx )
2416 return errFailed;
2418 //PyrSlot *a = g->sp - 1;
2419 PyrSlot *b = g->sp;
2421 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
2423 CGRect rect;
2424 int err = slotGetCGRect(b, &rect);
2425 if (err)
2426 return err;
2428 CGContextAddEllipseInRect( ctx, rect );
2429 CGContextStrokePath( ctx );
2431 return errNone;
2434 int prPen_FillOval(struct VMGlobals *g, int numArgsPushed);
2435 int prPen_FillOval(struct VMGlobals *g, int numArgsPushed)
2437 if (!g->canCallOS) return errCantCallOS;
2439 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
2440 if( !ctx )
2441 return errFailed;
2443 //PyrSlot *a = g->sp - 1;
2444 PyrSlot *b = g->sp;
2446 if (!(isKindOfSlot(b, s_rect->u.classobj)))
2447 return errWrongType;
2449 NSRect rect;
2450 int err = slotGetNSRect(b, &rect);
2451 if (err) return err;
2453 CGContextAddEllipseInRect( ctx, *(CGRect*)&rect );
2454 CGContextFillPath( ctx );
2456 return errNone;
2459 int prPen_StrokeLine(struct VMGlobals *g, int numArgsPushed);
2460 int prPen_StrokeLine(struct VMGlobals *g, int numArgsPushed)
2462 if (!g->canCallOS) return errCantCallOS;
2464 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
2465 if( !ctx )
2466 return errFailed;
2468 //PyrSlot *a = g->sp - 2;
2469 PyrSlot *b = g->sp - 1;
2470 PyrSlot *c = g->sp;
2472 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
2473 if (!(isKindOfSlot(c, s_point->u.classobj))) return errWrongType;
2475 NSPoint p1, p2;
2476 int err = slotGetPoint(b, &p1);
2477 if (err) return err;
2478 err = slotGetPoint(c, &p2);
2479 if (err) return err;
2481 CGContextMoveToPoint( ctx, p1.x, p2.x );
2482 CGContextAddLineToPoint( ctx, p1.x, p2.x );
2483 CGContextStrokePath( ctx );
2484 return errNone;
2487 int prPen_MoveTo(struct VMGlobals *g, int numArgsPushed);
2488 int prPen_MoveTo(struct VMGlobals *g, int numArgsPushed)
2490 if (!g->canCallOS) return errCantCallOS;
2492 //PyrSlot *a = g->sp - 1;
2493 PyrSlot *b = g->sp;
2495 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
2497 NSPoint p1;
2498 int err = slotGetPoint(b, &p1);
2499 if (err) return err;
2501 CGContextRef cgc = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
2502 if( !cgc )
2503 return errFailed;
2505 CGContextMoveToPoint(cgc, p1.x, p1.y);
2506 return errNone;
2509 int prPen_LineTo(struct VMGlobals *g, int numArgsPushed);
2510 int prPen_LineTo(struct VMGlobals *g, int numArgsPushed)
2512 if (!g->canCallOS) return errCantCallOS;
2514 //PyrSlot *a = g->sp - 1;
2515 PyrSlot *b = g->sp;
2517 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
2519 NSPoint p1;
2520 int err = slotGetPoint(b, &p1);
2521 if (err) return err;
2523 CGContextRef cgc = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
2524 if( !cgc )
2525 return errFailed;
2527 CGContextAddLineToPoint(cgc, p1.x, p1.y);
2529 return errNone;
2532 int prPen_AddArc(struct VMGlobals *g, int numArgsPushed);
2533 int prPen_AddArc(struct VMGlobals *g, int numArgsPushed)
2535 if (!g->canCallOS) return errCantCallOS;
2537 //PyrSlot *a = g->sp - 4;
2538 PyrSlot *b = g->sp - 3;
2539 PyrSlot *c = g->sp - 2; // radius
2540 PyrSlot *d = g->sp - 1; // start angle
2541 PyrSlot *e = g->sp; // angle
2543 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
2545 NSPoint p1;
2546 int err = slotGetPoint(b, &p1);
2547 if (err) return err;
2549 float radius;
2550 err = slotFloatVal(c, &radius);
2551 if (err) return err;
2553 float startAngle;
2554 err = slotFloatVal(d, &startAngle);
2555 if (err) return err;
2557 float angle;
2558 err = slotFloatVal(e, &angle);
2559 if (err) return err;
2561 int clockwise = angle > 0. ? 0 : 1;
2562 float endAngle = startAngle + angle;
2564 NSPoint p2;
2565 p2.x = p1.x + radius * cos(startAngle);
2566 p2.y = p1.y + radius * sin(startAngle);
2568 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2569 if (!gctx) return errFailed;
2570 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2571 //post("start %g %g end %g %g arc %g %g\n", startAngle, startAngle * 180./3.14156, endAngle, endAngle * 180./3.14156, angle, angle * 180./3.14156);
2572 CGContextMoveToPoint(cgc, p2.x, p2.y);
2573 CGContextAddArc(cgc, p1.x, p1.y, radius, startAngle, endAngle, clockwise);
2575 return errNone;
2578 int prPen_AddWedge(struct VMGlobals *g, int numArgsPushed);
2579 int prPen_AddWedge(struct VMGlobals *g, int numArgsPushed)
2581 if (!g->canCallOS) return errCantCallOS;
2583 //PyrSlot *a = g->sp - 4;
2584 PyrSlot *b = g->sp - 3;
2585 PyrSlot *c = g->sp - 2; // radius
2586 PyrSlot *d = g->sp - 1; // start angle
2587 PyrSlot *e = g->sp; // angle
2589 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
2591 NSPoint p1;
2592 int err = slotGetPoint(b, &p1);
2593 if (err) return err;
2595 float radius;
2596 err = slotFloatVal(c, &radius);
2597 if (err) return err;
2599 float startAngle;
2600 err = slotFloatVal(d, &startAngle);
2601 if (err) return err;
2603 float angle;
2604 err = slotFloatVal(e, &angle);
2605 if (err) return err;
2607 int clockwise = angle > 0. ? 0 : 1;
2608 float endAngle = startAngle + angle;
2610 NSPoint p2;
2611 p2.x = p1.x + radius * cos(startAngle);
2612 p2.y = p1.y + radius * sin(startAngle);
2614 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2615 if (!gctx) return errFailed;
2616 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2617 CGContextMoveToPoint(cgc, p1.x, p1.y);
2618 CGContextAddLineToPoint(cgc, p2.x, p2.y);
2619 CGContextAddArc(cgc, p1.x, p1.y, radius, startAngle, endAngle, clockwise);
2620 CGContextAddLineToPoint(cgc, p1.x, p1.y);
2622 return errNone;
2625 int prPen_AddAnnularWedge(struct VMGlobals *g, int numArgsPushed);
2626 int prPen_AddAnnularWedge(struct VMGlobals *g, int numArgsPushed)
2628 if (!g->canCallOS) return errCantCallOS;
2630 //PyrSlot *a = g->sp - 5;
2631 PyrSlot *b = g->sp - 4;
2632 PyrSlot *c = g->sp - 3; // innerRadius
2633 PyrSlot *d = g->sp - 2; // outerRadius
2634 PyrSlot *e = g->sp - 1; // start angle
2635 PyrSlot *f = g->sp; // angle
2637 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
2639 NSPoint p1;
2640 int err = slotGetPoint(b, &p1);
2641 if (err) return err;
2643 float innerRadius;
2644 err = slotFloatVal(c, &innerRadius);
2645 if (err) return err;
2647 float outerRadius;
2648 err = slotFloatVal(d, &outerRadius);
2649 if (err) return err;
2651 float startAngle;
2652 err = slotFloatVal(e, &startAngle);
2653 if (err) return err;
2655 float angle;
2656 err = slotFloatVal(f, &angle);
2657 if (err) return err;
2659 int clockwise = angle > 0. ? 0 : 1;
2660 float endAngle = startAngle + angle;
2662 NSPoint p2, p3, p4;
2663 p2.x = p1.x + innerRadius * cos(startAngle);
2664 p2.y = p1.y + innerRadius * sin(startAngle);
2665 p3.x = p1.x + outerRadius * cos(startAngle);
2666 p3.y = p1.y + outerRadius * sin(startAngle);
2667 p4.x = p1.x + innerRadius * cos(endAngle);
2668 p4.y = p1.y + innerRadius * sin(endAngle);
2670 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2671 if (!gctx) return errFailed;
2672 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2673 CGContextMoveToPoint(cgc, p2.x, p2.y);
2674 CGContextAddLineToPoint(cgc, p3.x, p3.y);
2675 CGContextAddArc(cgc, p1.x, p1.y, outerRadius, startAngle, endAngle, clockwise);
2676 CGContextAddLineToPoint(cgc, p4.x, p4.y);
2677 CGContextAddArc(cgc, p1.x, p1.y, innerRadius, endAngle, startAngle, 1-clockwise);
2679 return errNone;
2682 int prPen_BeginPath(struct VMGlobals *g, int numArgsPushed);
2683 int prPen_BeginPath(struct VMGlobals *g, int numArgsPushed)
2685 if (!g->canCallOS) return errCantCallOS;
2687 //PyrSlot *a = g->sp;
2689 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2690 if (!gctx) return errFailed;
2691 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2692 CGContextBeginPath(cgc);
2694 return errNone;
2697 int prPen_ClosePath(struct VMGlobals *g, int numArgsPushed);
2698 int prPen_ClosePath(struct VMGlobals *g, int numArgsPushed)
2700 if (!g->canCallOS) return errCantCallOS;
2702 //PyrSlot *a = g->sp;
2704 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2705 if (!gctx) return errFailed;
2706 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2707 CGContextClosePath(cgc);
2709 return errNone;
2712 int prPen_StrokePath(struct VMGlobals *g, int numArgsPushed);
2713 int prPen_StrokePath(struct VMGlobals *g, int numArgsPushed)
2715 if (!g->canCallOS) return errCantCallOS;
2717 //PyrSlot *a = g->sp;
2719 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2720 if (!gctx) return errFailed;
2721 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2722 CGContextDrawPath(cgc, kCGPathStroke);
2724 return errNone;
2727 int prPen_FillPath(struct VMGlobals *g, int numArgsPushed);
2728 int prPen_FillPath(struct VMGlobals *g, int numArgsPushed)
2730 if (!g->canCallOS) return errCantCallOS;
2732 //PyrSlot *a = g->sp;
2734 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2735 if (!gctx) return errFailed;
2736 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2737 CGContextFillPath(cgc);
2739 return errNone;
2743 int prPen_ClipPath(struct VMGlobals *g, int numArgsPushed);
2744 int prPen_ClipPath(struct VMGlobals *g, int numArgsPushed)
2746 if (!g->canCallOS) return errCantCallOS;
2748 //PyrSlot *a = g->sp;
2750 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2751 if (!gctx) return errFailed;
2752 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2753 CGContextClip(cgc);
2755 return errNone;
2760 int prPen_Translate(struct VMGlobals *g, int numArgsPushed);
2761 int prPen_Translate(struct VMGlobals *g, int numArgsPushed)
2763 if (!g->canCallOS) return errCantCallOS;
2765 //PyrSlot *a = g->sp - 2;
2766 PyrSlot *b = g->sp - 1;
2767 PyrSlot *c = g->sp;
2769 float x, y;
2770 int err = slotFloatVal(b, &x);
2771 if (err) return err;
2772 err = slotFloatVal(c, &y);
2773 if (err) return err;
2775 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2776 if (!gctx) return errFailed;
2777 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2778 CGContextTranslateCTM(cgc, x, y);
2780 return errNone;
2783 int prPen_Scale(struct VMGlobals *g, int numArgsPushed);
2784 int prPen_Scale(struct VMGlobals *g, int numArgsPushed)
2786 if (!g->canCallOS) return errCantCallOS;
2788 //PyrSlot *a = g->sp - 2;
2789 PyrSlot *b = g->sp - 1;
2790 PyrSlot *c = g->sp;
2792 float x, y;
2793 int err = slotFloatVal(b, &x);
2794 if (err) return err;
2795 err = slotFloatVal(c, &y);
2796 if (err) return err;
2798 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2799 if (!gctx) return errFailed;
2800 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2801 CGContextScaleCTM(cgc, x, y);
2803 return errNone;
2806 int prPen_Rotate(struct VMGlobals *g, int numArgsPushed);
2807 int prPen_Rotate(struct VMGlobals *g, int numArgsPushed)
2809 if (!g->canCallOS) return errCantCallOS;
2811 //PyrSlot *a = g->sp - 3;
2812 PyrSlot *b = g->sp - 2;
2813 PyrSlot *c = g->sp - 1;
2814 PyrSlot *d = g->sp;
2816 float angle, x, y;
2817 int err = slotFloatVal(b, &angle);
2818 if (err) return err;
2819 err = slotFloatVal(c, &x);
2820 if (err) return err;
2821 err = slotFloatVal(d, &y);
2822 if (err) return err;
2824 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2825 if (!gctx) return errFailed;
2826 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2827 if (x == 0. && y == 0.) {
2828 CGContextRotateCTM(cgc, angle);
2829 } else {
2830 CGContextTranslateCTM(cgc, x, y);
2831 CGContextRotateCTM(cgc, angle);
2832 CGContextTranslateCTM(cgc, -x, -y);
2834 return errNone;
2837 int prPen_SetWidth(struct VMGlobals *g, int numArgsPushed);
2838 int prPen_SetWidth(struct VMGlobals *g, int numArgsPushed)
2840 if (!g->canCallOS) return errCantCallOS;
2842 //PyrSlot *a = g->sp - 1;
2843 PyrSlot *b = g->sp;
2845 float width;
2846 int err = slotFloatVal(b, &width);
2847 if (err) return err;
2849 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2850 if (!gctx) return errFailed;
2851 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2852 CGContextSetLineWidth(cgc, width);
2853 return errNone;
2856 int prPen_SetMatrix(struct VMGlobals *g, int numArgsPushed);
2857 int prPen_SetMatrix(struct VMGlobals *g, int numArgsPushed)
2859 if (!g->canCallOS) return errCantCallOS;
2861 //PyrSlot *a = g->sp - 1;
2862 PyrSlot *b = g->sp;
2864 if (!isKindOfSlot(b, class_arrayed_collection)) return errWrongType;
2866 if (slotRawObject(b)->size < 6) return errFailed;
2867 PyrObject *mobj = slotRawObject(b);
2869 CGAffineTransform afx;
2871 int err = getIndexedVal(mobj, 0, &afx.a);
2872 if (err) return err;
2873 err = getIndexedVal(mobj, 1, &afx.b);
2874 if (err) return err;
2875 err = getIndexedVal(mobj, 2, &afx.c);
2876 if (err) return err;
2877 err = getIndexedVal(mobj, 3, &afx.d);
2878 if (err) return err;
2879 err = getIndexedVal(mobj, 4, &afx.tx);
2880 if (err) return err;
2881 err = getIndexedVal(mobj, 5, &afx.ty);
2882 if (err) return err;
2884 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2885 if (!gctx) return errFailed;
2886 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2887 CGContextConcatCTM(cgc, afx);
2889 return errNone;
2892 int prPen_Skew(struct VMGlobals *g, int numArgsPushed);
2893 int prPen_Skew(struct VMGlobals *g, int numArgsPushed)
2895 if (!g->canCallOS) return errCantCallOS;
2897 //PyrSlot *a = g->sp - 1;
2898 PyrSlot *b = g->sp - 1;
2899 PyrSlot *c = g->sp;
2901 float x;
2902 int err = slotFloatVal(b, &x);
2903 if (err) return err;
2905 float y;
2906 err = slotFloatVal(c, &y);
2907 if (err) return err;
2909 CGAffineTransform afx;
2910 afx.a = 1.0;
2911 afx.b = y;
2912 afx.c = x;
2913 afx.d = 1.0;
2914 afx.tx = 0.0;
2915 afx.ty = 0.0;
2917 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2918 if (!gctx) return errFailed;
2919 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2920 CGContextConcatCTM(cgc, afx);
2922 return errNone;
2926 int prPen_SetBlend(struct VMGlobals *g, int numArgsPushed);
2927 int prPen_SetBlend(struct VMGlobals *g, int numArgsPushed)
2929 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2930 if (!g->canCallOS) return errCantCallOS;
2931 PyrSlot *c = g->sp; // blendmode
2932 int mode = 0, err = errFailed;
2934 err = slotIntVal(c, &mode);
2935 if( err != errNone )
2936 return err;
2938 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2939 if (!gctx)
2940 return errFailed;
2942 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
2943 CGContextSetBlendMode(cgc, (CGBlendMode)mode);
2944 #endif
2945 return errNone;
2948 int prPen_SetShadow(struct VMGlobals *g, int numArgsPushed);
2949 int prPen_SetShadow(struct VMGlobals *g, int numArgsPushed)
2951 if (!g->canCallOS) return errCantCallOS;
2953 int err;
2955 PyrSlot *a = g->sp - 2; // offset
2956 PyrSlot *b = g->sp - 1; // blur
2957 PyrSlot *c = g->sp; // color
2959 NSPoint offset;
2960 float blur;
2961 SCColor scColor;
2963 err = slotColorVal(c, &scColor);
2964 if( err != errNone )
2965 return err;
2967 err = slotGetPoint(a, &offset);
2968 if( err != errNone )
2969 return err;
2971 err = slotFloatVal(b, &blur);
2972 if( err != errNone )
2973 return err;
2975 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
2976 if (!gctx)
2977 return errFailed;
2979 CGContextRef _ctx = (CGContextRef)[gctx graphicsPort];
2980 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
2981 ColorData colors[4];
2982 colors[0] = scColor.red;
2983 colors[1] = scColor.green;
2984 colors[2] = scColor.blue;
2985 colors[3] = scColor.alpha;
2986 CGColorRef col = CGColorCreate(colorSpace, colors);
2987 if(!col){
2988 CGColorSpaceRelease(colorSpace);
2989 return errFailed;
2992 CGContextSetShadowWithColor(_ctx, (CGSize){offset.x, offset.y}, blur, col);
2994 CGColorSpaceRelease(colorSpace);
2995 CGColorRelease(col);
2997 return errNone;
3000 int prPen_AddOval(struct VMGlobals *g, int numArgsPushed);
3001 int prPen_AddOval(struct VMGlobals *g, int numArgsPushed)
3003 if (!g->canCallOS) return errCantCallOS;
3005 //PyrSlot *a = g->sp - 1;
3006 PyrSlot *b = g->sp;
3008 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
3010 CGRect rect;
3011 int err = slotGetCGRect(b, &rect);
3012 if (err) return err;
3014 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3015 if (!gctx)
3016 return errFailed;
3018 CGContextAddEllipseInRect((CGContextRef)[gctx graphicsPort], rect);
3020 return errNone;
3023 int prPen_AddBezierQuadCurve(struct VMGlobals *g, int numArgsPushed);
3024 int prPen_AddBezierQuadCurve(struct VMGlobals *g, int numArgsPushed)
3026 if (!g->canCallOS) return errCantCallOS;
3028 int err;
3029 NSPoint points[2];
3031 PyrSlot *a = g->sp - 1; // point
3032 PyrSlot *b = g->sp; // control point 1
3034 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
3036 err = slotGetPoint(a, &points[0]);
3037 if( err != errNone )
3038 return err;
3040 err = slotGetPoint(b, &points[1]);
3041 if( err != errNone )
3042 return err;
3044 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3045 if (!gctx)
3046 return errFailed;
3048 CGContextAddQuadCurveToPoint((CGContextRef)[gctx graphicsPort],
3049 points[1].x, points[1].y,
3050 points[0].x, points[0].y
3053 return errNone;
3056 int prPen_AddBezierCubicCurve(struct VMGlobals *g, int numArgsPushed);
3057 int prPen_AddBezierCubicCurve(struct VMGlobals *g, int numArgsPushed)
3059 if (!g->canCallOS) return errCantCallOS;
3061 int err;
3062 NSPoint points[3];
3064 PyrSlot *a = g->sp - 2; // point
3065 PyrSlot *b = g->sp - 1; // control point 1
3066 PyrSlot *c = g->sp; // control point 2
3068 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
3069 if (!(isKindOfSlot(c, s_point->u.classobj))) return errWrongType;
3071 err = slotGetPoint(a, &points[0]);
3072 if( err != errNone )
3073 return err;
3075 err = slotGetPoint(b, &points[1]);
3076 if( err != errNone )
3077 return err;
3079 err = slotGetPoint(c, &points[2]);
3080 if( err != errNone )
3081 return err;
3083 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3084 if ( !gctx )
3085 return errFailed;
3087 CGContextAddCurveToPoint((CGContextRef)[gctx graphicsPort],
3088 points[1].x, points[1].y,
3089 points[2].x, points[2].y,
3090 points[0].x, points[0].y
3093 return errNone;
3096 int prPen_AddArcToPoint(struct VMGlobals *g, int numArgsPushed);
3097 int prPen_AddArcToPoint(struct VMGlobals *g, int numArgsPushed)
3099 if (!g->canCallOS) return errCantCallOS;
3101 PyrSlot *a = g->sp - 2; // point1
3102 PyrSlot *b = g->sp - 1; // point2
3103 PyrSlot *c = g->sp; // radius
3105 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
3107 NSPoint p1;
3108 NSPoint p2;
3110 int err = slotGetPoint(a, &p1);
3111 if (err) return err;
3113 err = slotGetPoint(b, &p2);
3114 if (err) return err;
3116 float radius;
3117 err = slotFloatVal(c, &radius);
3118 if (err) return err;
3120 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3121 if ( !gctx )
3122 return errFailed;
3124 CGContextAddArcToPoint((CGContextRef)[gctx graphicsPort], p1.x, p1.y, p2.x, p2.y, radius);
3126 return errNone;
3129 int prPen_ClearRect(struct VMGlobals *g, int numArgsPushed);
3130 int prPen_ClearRect(struct VMGlobals *g, int numArgsPushed)
3132 if (!g->canCallOS) return errCantCallOS;
3134 PyrSlot *b = g->sp;
3136 if (!(isKindOfSlot(b, s_rect->u.classobj))) return errWrongType;
3138 CGRect rect;
3139 int err = slotGetCGRect(b, &rect);
3140 if (err) return err;
3143 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3144 if ( !gctx )
3145 return errFailed;
3147 CGContextClearRect((CGContextRef)[gctx graphicsPort], rect);
3149 return errNone;
3152 int prPen_DrawPath(struct VMGlobals *g, int numArgsPushed);
3153 int prPen_DrawPath(struct VMGlobals *g, int numArgsPushed)
3155 if (!g->canCallOS) return errCantCallOS;
3157 PyrSlot *b = g->sp;
3158 int err, mode=0;
3160 if( (err = slotIntVal(b, &mode)) != noErr )
3161 return err;
3163 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3164 if ( !gctx )
3165 return errFailed;
3167 CGContextRef cgc = (CGContextRef)[gctx graphicsPort];
3168 //kCGPathFill=0, kCGPathEOFill=1, kCGPathStroke=2, kCGPathFillStroke=3, or kCGPathEOFillStroke=4
3169 CGContextDrawPath(
3170 (CGContextRef)[gctx graphicsPort],
3171 (CGPathDrawingMode)sc_clip( mode, kCGPathFill, kCGPathEOFillStroke )
3173 return errNone;
3176 int prPen_BeginTransparencyLayer(struct VMGlobals *g, int numArgsPushed);
3177 int prPen_BeginTransparencyLayer(struct VMGlobals *g, int numArgsPushed)
3180 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3
3182 if (!g->canCallOS) return errCantCallOS;
3183 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3184 if (!gctx)
3185 return errFailed;
3188 #if 1/*MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5*/
3190 CGContextBeginTransparencyLayer((CGContextRef)[gctx graphicsPort], NULL);
3192 #else /*MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5*/
3194 PyrSlot *b = g->sp;
3195 if (!(isKindOfSlot(b, s_rect->u.classobj)))
3196 return errWrongType;
3198 CGRect rect;
3199 int err = slotGetCGRect(b, &rect);
3200 if (err)
3201 return err;
3203 if(rect.size.width == 0 || rect.size.height == 0) // NULL in either side should take all current clipped region
3204 CGContextBeginTransparencyLayer((CGContextRef)[gctx graphicsPort], NULL);
3205 else
3206 CGContextBeginTransparencyLayerWithRect((CGContextRef)[gctx graphicsPort], rect, NULL);
3208 #endif
3210 #endif
3211 return errNone;
3214 int prPen_EndTransparencyLayer(struct VMGlobals *g, int numArgsPushed);
3215 int prPen_EndTransparencyLayer(struct VMGlobals *g, int numArgsPushed)
3218 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_3
3220 if (!g->canCallOS)
3221 return errCantCallOS;
3223 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3224 if (!gctx)
3225 return errFailed;
3227 CGContextEndTransparencyLayer((CGContextRef)[gctx graphicsPort]);
3229 #endif
3231 return errNone;
3234 int prPen_LineJoin(struct VMGlobals *g, int numArgsPushed);
3235 int prPen_LineJoin(struct VMGlobals *g, int numArgsPushed)
3237 int mode=0, err;
3239 if (!g->canCallOS)
3240 return errCantCallOS;
3242 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3243 if (!gctx)
3244 return errFailed;
3246 PyrSlot *b = g->sp; // mode
3247 if((err = slotIntVal(b, &mode)) != noErr)
3248 return err;
3250 //kCGLineJoinMiter=0, kCGLineJoinRound=1,kCGLineJoinBevel=2
3251 CGContextSetLineJoin(
3252 (CGContextRef)[gctx graphicsPort],
3253 (CGLineJoin)sc_clip( mode, kCGLineJoinMiter, kCGLineJoinBevel )
3256 return errNone;
3259 int prPen_LineDash(struct VMGlobals *g, int numArgsPushed);
3260 int prPen_LineDash(struct VMGlobals *g, int numArgsPushed)
3262 if ( !g->canCallOS )
3263 return errCantCallOS;
3265 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3266 if ( !gctx )
3267 return errFailed;
3269 PyrSlot *a = g->sp; // array of floats
3270 PyrObject* pyrarray = slotRawObject(a);
3271 PyrClass* pyrclass = pyrarray->classptr;
3273 if( pyrclass == class_floatarray ) // float array only
3275 ColorData *colors = (ColorData *) malloc(pyrarray->size*sizeof(ColorData));
3276 int i;
3277 float *src = ((PyrFloatArray *)pyrarray)->f;
3278 for (i=0; i<pyrarray->size; i++)
3280 colors[i] = (ColorData) *(src++);
3282 CGContextSetLineDash(
3283 (CGContextRef)[gctx graphicsPort],
3285 colors,
3286 pyrarray->size
3288 free(colors);
3289 return errNone;
3291 else
3293 post("Pen line dash needs a FloatArray as argument !\n");
3296 return errFailed;
3299 int prPen_LineCap(struct VMGlobals *g, int numArgsPushed);
3300 int prPen_LineCap(struct VMGlobals *g, int numArgsPushed)
3302 if ( !g->canCallOS )
3303 return errCantCallOS;
3305 int err=noErr, mode = 0;
3306 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3307 if ( !gctx )
3308 return errFailed;
3310 PyrSlot *b = g->sp; // mode
3311 if( (err = slotIntVal(b, &mode)) != noErr )
3312 return err;
3314 //kCGLineCapButt (default - 0), kCGLineCapRound - 1, or kCGLineCapSquare - 2
3315 CGContextSetLineCap(
3316 (CGContextRef)[gctx graphicsPort],
3317 (CGLineCap)sc_clip(mode, kCGLineCapButt, kCGLineCapSquare)
3319 return errNone;
3322 int prPen_SetAlpha(struct VMGlobals *g, int numArgsPushed);
3323 int prPen_SetAlpha(struct VMGlobals *g, int numArgsPushed)
3325 if (!g->canCallOS)
3326 return errCantCallOS;
3328 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3329 if (!gctx)
3330 return errFailed;
3332 int err = errNone; float value;
3333 PyrSlot *a = g->sp; // float
3335 err = slotFloatVal(a, &value);
3336 if(err != errNone)
3337 return err;
3339 CGContextSetAlpha((CGContextRef)[gctx graphicsPort], value);
3341 return errNone;
3346 * Gradient Functions
3347 * Valid only for MAC OS X 10.2 -) use the CGShading object
3350 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2
3352 typedef struct GradientInfo {
3353 SCColor color0;
3354 SCColor color1;
3355 int scCallback; // future plan for custom gradient calc functions
3356 } GradientInfo, GradientInfoRef;
3358 static GradientInfo gGradientInfo;
3360 static void GradientCalcLinear(void *info, const ColorData *in, ColorData *out)
3362 size_t k;
3364 if(gGradientInfo.scCallback) {
3365 for (k = 0; k < 4; k++) {
3366 *out++ = // result of Pen.gradientCalcFunc call;
3368 }else{
3370 for (k = 0; k < 4; k++) {
3371 *out++ = (ColorData)(((float *)(&gGradientInfo.color1))[k]) * (*in) + (ColorData)(((float *)(&gGradientInfo.color0))[k]) * (1-(*in));
3376 static CGFunctionRef CreateGradientFunctionRef()
3378 size_t components;
3379 static const ColorData input_value_range [2] = { 0, 1 };
3380 static const ColorData output_value_ranges [8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
3381 static const CGFunctionCallbacks callbacks = { 0,
3382 &GradientCalcLinear,
3383 NULL};
3387 Note: (colorspace = RGBA == 4)
3388 -------------------------
3389 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
3390 components = 1 + CGColorSpaceGetNumberOfComponents (colorSpace);
3391 CGColorSpaceRelease(colorSpace);
3394 // initialize gradient info
3395 gGradientInfo.color0 = SCMakeColor(1.f,1.f,1.f,1.f);
3396 gGradientInfo.color1 = SCMakeColor(0.f,0.f,0.f,1.f);
3397 gGradientInfo.scCallback = false;
3399 return CGFunctionCreate ((void *) &gGradientInfo,
3401 input_value_range,
3402 4, /* RGBA */
3403 output_value_ranges,
3404 &callbacks);
3408 static CGFunctionRef gGradientFunctionRef = NULL;
3409 static CGFunctionRef GetGradientFunction()
3411 if(!gGradientFunctionRef) {
3412 post("creating gradient function !\n");
3413 gGradientFunctionRef = CreateGradientFunctionRef();
3415 return gGradientFunctionRef;
3419 int prPen_DrawAxialGradient(struct VMGlobals *g, int numArgsPushed);
3420 int prPen_DrawAxialGradient(struct VMGlobals *g, int numArgsPushed)
3422 if (!g->canCallOS) return errCantCallOS;
3424 int err;
3425 NSPoint points[2];
3427 PyrSlot *a = g->sp - 3; // point 1
3428 PyrSlot *b = g->sp - 2; // point 2
3429 PyrSlot *c0= g->sp - 1; // color 1
3430 PyrSlot *c1= g->sp; // color 2
3432 if (!(isKindOfSlot(a, s_point->u.classobj))) return errWrongType;
3433 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
3434 if (!(isKindOfSlot(c0, s_color->u.classobj))) return errWrongType;
3435 if (!(isKindOfSlot(c1, s_color->u.classobj))) return errWrongType;
3437 CGFunctionRef gradFunc = CreateGradientFunctionRef(); // we need to create a new function ref since Quartz cache it
3438 if(!gradFunc) {
3439 post("Error: Failed creating gradient function !\n");
3440 return errFailed;
3443 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3444 if (!gctx)
3445 return errFailed;
3447 err = slotColorVal(c0, &(gGradientInfo.color0));
3448 if( err != errNone )
3449 return err;
3451 err = slotColorVal(c1, &(gGradientInfo.color1));
3452 if( err != errNone )
3453 return err;
3455 err = slotGetPoint(a, &points[0]);
3456 if( err != errNone )
3457 return err;
3459 err = slotGetPoint(b, &points[1]);
3460 if( err != errNone )
3461 return err;
3463 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
3464 CGShadingRef shadingRef = CGShadingCreateAxial(
3465 colorSpace,
3466 *(CGPoint*)(&points[0]), *(CGPoint*)(&points[1]),
3467 gradFunc, true, true
3470 CGContextSaveGState((CGContextRef)[gctx graphicsPort]);
3471 CGContextClip((CGContextRef)[gctx graphicsPort]);
3472 CGContextDrawShading(
3473 (CGContextRef)[gctx graphicsPort], shadingRef
3475 CGContextRestoreGState((CGContextRef)[gctx graphicsPort]);
3477 CGColorSpaceRelease(colorSpace);
3478 CGShadingRelease(shadingRef);
3479 CGFunctionRelease(gradFunc);
3481 return errNone;
3484 int prPen_DrawRadialGradient(struct VMGlobals *g, int numArgsPushed);
3485 int prPen_DrawRadialGradient(struct VMGlobals *g, int numArgsPushed)
3487 if (!g->canCallOS) return errCantCallOS;
3489 int err;
3490 NSPoint points[2];
3491 float radius[2] = {0.f, 0.f};
3493 PyrSlot *a = g->sp - 5; // point 1
3494 PyrSlot *b = g->sp - 4; // point 2
3495 PyrSlot *srad = g->sp - 3; // start radius
3496 PyrSlot *erad = g->sp - 2; // end radius
3497 PyrSlot *c0= g->sp - 1; // color 1
3498 PyrSlot *c1= g->sp; // color 2
3501 if (!(isKindOfSlot(a, s_point->u.classobj))) return errWrongType;
3502 if (!(isKindOfSlot(b, s_point->u.classobj))) return errWrongType;
3503 if (!(isKindOfSlot(c0, s_color->u.classobj))) return errWrongType;
3504 if (!(isKindOfSlot(c1, s_color->u.classobj))) return errWrongType;
3506 CGFunctionRef gradFunc = CreateGradientFunctionRef();
3507 if(!gradFunc) {
3508 NSLog(@"Error: prPen_DrawRadialGradient Failed creating gradient function !\n");
3509 return errFailed;
3512 NSGraphicsContext *gctx = [NSGraphicsContext currentContext];
3513 if (!gctx)
3514 return errFailed;
3516 err = slotColorVal(c0, &(gGradientInfo.color0));
3517 if( err != errNone )
3518 return err;
3520 err = slotColorVal(c1, &(gGradientInfo.color1));
3521 if( err != errNone )
3522 return err;
3524 err = slotGetPoint(a, &points[0]);
3525 if( err != errNone )
3526 return err;
3528 err = slotGetPoint(b, &points[1]);
3529 if( err != errNone )
3530 return err;
3532 err = slotFloatVal(srad, &radius[0]);
3533 if( err != errNone )
3534 return err;
3536 err = slotFloatVal(erad, &radius[1]);
3537 if( err != errNone )
3538 return err;
3540 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
3541 CGShadingRef shadingRef = CGShadingCreateRadial(
3542 colorSpace,
3543 *(CGPoint*)(&points[0]), radius[0],
3544 *(CGPoint*)(&points[1]), radius[1],
3545 gradFunc, true, true
3548 CGContextSaveGState( (CGContextRef)[gctx graphicsPort] );
3549 CGContextClip( (CGContextRef)[gctx graphicsPort] );
3550 CGContextDrawShading(
3551 (CGContextRef)[gctx graphicsPort], shadingRef
3553 CGContextRestoreGState( (CGContextRef)[gctx graphicsPort] );
3555 CGColorSpaceRelease(colorSpace);
3556 CGShadingRelease(shadingRef);
3557 CGFunctionRelease(gradFunc);
3558 return errNone;
3560 #else
3561 // Dummy primitives if mac os x < 10.2 // should never be the case now... but
3562 int prPen_DrawAxialGradient(struct VMGlobals *g, int numArgsPushed);
3563 int prPen_DrawAxialGradient(struct VMGlobals *g, int numArgsPushed) {return errNone;}
3564 int prPen_DrawRadialGradient(struct VMGlobals *g, int numArgsPushed);
3565 int prPen_DrawRadialGradient(struct VMGlobals *g, int numArgsPushed) {return errNone;}
3566 #endif
3569 * End Of Gradient Functions
3572 int prLoadUserPanel(struct VMGlobals *g, int numArgsPushed);
3573 int prLoadUserPanel(struct VMGlobals *g, int numArgsPushed)
3575 if (!g->canCallOS) return errCantCallOS;
3577 PyrSlot *a = g->sp - 1;
3578 PyrSlot *b = g->sp;
3580 if (!isKindOfSlot(b, class_string)) return errWrongType;
3581 PyrString* string = slotRawString(b);
3583 NSString *nsstring = [NSString stringWithCString: string->s length: string->size];
3584 [nsstring retain];
3586 void *scobj = slotRawObject(a);
3587 SEL sel = @selector(loadUserPanel:SCObject:);
3588 NSMethodSignature *sig = [SCVirtualMachine instanceMethodSignatureForSelector: sel];
3590 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
3591 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
3592 [anInvocation setTarget: scvm];
3593 [anInvocation setSelector: sel];
3594 [anInvocation setArgument: &nsstring atIndex: 2];
3595 [anInvocation setArgument: &scobj atIndex: 3];
3596 [scvm defer: anInvocation];
3598 return errNone;
3601 int prHasDeferred(struct VMGlobals *g, int numArgsPushed);
3602 int prHasDeferred(struct VMGlobals *g, int numArgsPushed)
3604 gUIChangeCounter.Change();
3605 return errNone;
3609 int prNewMenuItem(struct VMGlobals *g, int numArgsPushed);
3610 int prNewMenuItem(struct VMGlobals *g, int numArgsPushed)
3612 if (!g->canCallOS) return errCantCallOS;
3614 PyrSlot *caller = g->sp - 4; // the SC Object
3615 PyrSlot *parentObj = g->sp - 3; // the parent menu or nil for app menu
3616 PyrSlot *ind = g->sp - 2; // the index
3617 PyrSlot *stringSlot = g->sp - 1; // name of the menu item
3618 PyrSlot *submenbool = g->sp; // submenu bool
3620 bool nilIndex;
3621 int menIndex, err;
3623 nilIndex = IsNil(ind);
3624 if(!nilIndex){
3625 err = slotIntVal(ind, &menIndex);
3626 if (err) return err;
3629 //NSLog(@"menIndex: %i", menIndex);
3631 if (!(isKindOfSlot(stringSlot, class_string))) return errWrongType;
3633 PyrString* string = slotRawString(stringSlot);
3635 NSString *label = [[NSString alloc] initWithCString: string->s length: string->size];
3637 //NSLog(@"Label: %@", label);
3638 // make a menu item
3639 SCNSMenuItem *menuItem = [[SCNSMenuItem alloc] initWithTitle:label action:@selector(doAction:) keyEquivalent:@""];
3640 [menuItem setTarget:menuItem];
3641 [menuItem setSCObject: slotRawObject(caller)];
3642 SetPtr(slotRawObject(caller)->slots + 0, menuItem); // set the dataptr
3644 if (IsTrue(submenbool)) {
3645 // make a submenu if needed
3646 //NSLog(@"Is SubMenu");
3647 [menuItem setSubmenu:[[NSMenu alloc] initWithTitle:label]];
3648 [[menuItem submenu] setAutoenablesItems:NO];
3651 NSMenu *parentMenu;
3652 if (IsNil(parentObj)) {
3653 // make a submenu if needed
3654 //NSLog(@"Top Level");
3655 parentMenu = [NSApp mainMenu];
3656 } else if (IsSym(parentObj)) {
3657 PyrSymbol *parentSymbol;
3658 int err = slotSymbolVal(parentObj, &parentSymbol);
3659 if (err) return err;
3660 if (strcmp(parentSymbol->name, "Help")==0) {
3661 parentMenu = [[[NSApp mainMenu] itemWithTitle:NSLocalizedString(@"Help", @"Help Menu Name")] submenu];
3663 } else if (isKindOfSlot(parentObj, getsym("CocoaMenuItem")->u.classobj)){
3664 SCNSMenuItem *parentItem = (SCNSMenuItem*)(slotRawPtr(slotRawObject(parentObj)->slots));
3665 if([parentItem hasSubmenu]) {
3666 //NSLog(@"Parent has submenu");
3667 parentMenu = [parentItem submenu];
3671 if(!parentMenu) {
3672 [label release];
3673 return errWrongType;
3676 // protect against bad indices
3677 int parentSize = [parentMenu numberOfItems];
3678 //NSLog(@"parentSize: %i", parentSize);
3679 if(menIndex > parentSize || nilIndex) {
3680 //NSLog(@"Index > parentSize");
3681 menIndex = parentSize;
3683 if(menIndex < 0) {
3684 //NSLog(@"Index < 0");
3685 menIndex = 0;
3687 //NSLog(@"Final Index: %i", menIndex);
3689 [parentMenu insertItem:menuItem atIndex:menIndex];
3690 [menuItem retain];
3691 if([menuItem hasSubmenu]) { [[menuItem submenu] release]; } // this has been retained
3692 [label release];
3693 return errNone;
3696 int prNewMenuSeparator(struct VMGlobals *g, int numArgsPushed);
3697 int prNewMenuSeparator(struct VMGlobals *g, int numArgsPushed)
3699 if (!g->canCallOS) return errCantCallOS;
3701 PyrSlot *caller = g->sp - 2; // the SC Object
3702 PyrSlot *parentObj = g->sp - 1; // the parent menu or nil for app menu
3703 PyrSlot *ind = g->sp; // the index
3705 bool nilIndex;
3706 int menIndex, err;
3708 nilIndex = IsNil(ind);
3709 if(!nilIndex){
3710 err = slotIntVal(ind, &menIndex);
3711 if (err) return err;
3714 // make a menu item
3715 NSMenuItem *menuItem = [NSMenuItem separatorItem];
3716 SetPtr(slotRawObject(caller)->slots + 0, menuItem); // set the dataptr
3718 NSMenu *parentMenu;
3719 if (IsNil(parentObj)) {
3720 parentMenu = [NSApp mainMenu];
3721 } else if (IsSym(parentObj)) {
3722 PyrSymbol *parentSymbol;
3723 int err = slotSymbolVal(parentObj, &parentSymbol);
3724 if (err) return err;
3725 if (strcmp(parentSymbol->name, "Help")==0) {
3726 parentMenu = [[[NSApp mainMenu] itemWithTitle:NSLocalizedString(@"Help", @"Help Menu Name")] submenu];
3728 } else if (isKindOfSlot(parentObj, getsym("CocoaMenuItem")->u.classobj)){
3729 SCNSMenuItem *parentItem = (SCNSMenuItem*)(slotRawPtr(slotRawObject(parentObj)->slots));
3730 if([parentItem hasSubmenu]) {
3731 //NSLog(@"Parent has submenu");
3732 parentMenu = [parentItem submenu];
3736 if(!parentMenu) {
3737 return errWrongType;
3740 // protect against bad indices
3741 int parentSize = [parentMenu numberOfItems];
3742 //NSLog(@"parentSize: %i", parentSize);
3743 if(menIndex > parentSize || nilIndex) {
3744 //NSLog(@"Index > parentSize");
3745 menIndex = parentSize;
3747 if(menIndex < 0) {
3748 //NSLog(@"Index < 0");
3749 menIndex = 0;
3751 //NSLog(@"Final Index: %i", menIndex);
3753 [parentMenu insertItem:menuItem atIndex:menIndex];
3754 [menuItem retain];
3755 return errNone;
3759 int prRemoveMenuItem(struct VMGlobals *g, int numArgsPushed);
3760 int prRemoveMenuItem(struct VMGlobals *g, int numArgsPushed)
3763 PyrSlot *caller = g->sp;
3765 NSMenuItem *menuItem = (NSMenuItem*)(slotRawPtr(slotRawObject(caller)->slots));
3766 if(!menuItem) return errFailed;
3767 [[menuItem menu] removeItem:menuItem];
3768 SetPtr(slotRawObject(caller)->slots, NULL); // we're now a lame duck
3769 //if([menuItem hasSubmenu]) { [[menuItem submenu] release] };
3770 [menuItem release];
3771 return errNone;
3774 int prEnableMenuItem(struct VMGlobals *g, int numArgsPushed);
3775 int prEnableMenuItem(struct VMGlobals *g, int numArgsPushed)
3777 if (!g->canCallOS) return errCantCallOS;
3779 PyrSlot *caller = g->sp - 1;
3780 PyrSlot *boolean = g->sp;
3782 SCNSMenuItem *menuItem = (SCNSMenuItem*)(slotRawPtr(slotRawObject(caller)->slots));
3783 if(!menuItem) return errFailed;
3784 if(IsTrue(boolean)) {
3785 [menuItem setEnabled:YES];
3786 } else {
3787 [menuItem setEnabled:NO];
3789 return errNone;
3792 int prSetMenuItemState(struct VMGlobals *g, int numArgsPushed);
3793 int prSetMenuItemState(struct VMGlobals *g, int numArgsPushed)
3795 if (!g->canCallOS) return errCantCallOS;
3797 PyrSlot *caller = g->sp - 1;
3798 PyrSlot *boolean = g->sp;
3800 SCNSMenuItem *menuItem = (SCNSMenuItem*)(slotRawPtr(slotRawObject(caller)->slots));
3801 if(!menuItem) return errFailed;
3802 if(IsTrue(boolean)) {
3803 [menuItem setState:NSOnState];
3804 } else {
3805 [menuItem setState:NSOffState];
3807 return errNone;
3810 int prSetMenuItemKeyboardEquivalent(struct VMGlobals *g, int numArgsPushed);
3811 int prSetMenuItemKeyboardEquivalent(struct VMGlobals *g, int numArgsPushed)
3813 if (!g->canCallOS) return errCantCallOS;
3814 PyrSlot *caller = g->sp - 3;
3815 PyrSlot *stringSlot = g->sp - 2;
3816 PyrSlot *alt = g->sp - 1;
3817 PyrSlot *ctrl = g->sp;
3819 SCNSMenuItem *menuItem = (SCNSMenuItem*)(slotRawPtr(slotRawObject(caller)->slots));
3820 if(!menuItem) return errFailed;
3822 if (!(isKindOfSlot(stringSlot, class_string))) return errWrongType;
3824 PyrString* string = slotRawString(stringSlot);
3826 NSString *kbEquiv = [[NSString alloc] initWithCString: string->s length: string->size];
3828 [menuItem setKeyEquivalent:kbEquiv];
3830 int mod = NSCommandKeyMask;
3831 if(IsTrue(alt)) {
3832 mod = mod | NSAlternateKeyMask;
3835 if(IsTrue(ctrl)) {
3836 mod = mod | NSControlKeyMask;
3839 [menuItem setKeyEquivalentModifierMask:mod];
3841 [kbEquiv release];
3842 return errNone;
3845 int prMouse_getCoords(struct VMGlobals *g, int numArgsPushed);
3846 int prMouse_getCoords(struct VMGlobals *g, int numArgsPushed)
3848 if (!g->canCallOS) return errCantCallOS;
3850 PyrSlot *a = g->sp - 1;
3851 PyrSlot *b = g->sp;
3853 NSPoint mouse_location = [NSEvent mouseLocation];
3854 PyrSlot *slots = slotRawObject(b)->slots;
3855 SetFloat( slots+0, mouse_location.x );
3856 SetFloat( slots+1, mouse_location.y );
3857 slotCopy(a, b);
3860 return errNone;
3863 int prRecompile(struct VMGlobals *g, int numArgsPushed);
3864 int prRecompile(struct VMGlobals *g, int numArgsPushed)
3866 SEL sel = @selector(compileLibrary:);
3867 NSMethodSignature *sig = [SCVirtualMachine instanceMethodSignatureForSelector: sel];
3869 NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature: sig];
3870 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
3871 [anInvocation setTarget: scvm];
3872 [anInvocation setSelector: sel];
3873 [scvm defer: anInvocation];
3875 return errNone;
3878 int prSetDeferredTaskInterval(struct VMGlobals *g, int numArgsPushed);
3879 int prSetDeferredTaskInterval(struct VMGlobals *g, int numArgsPushed)
3881 if (!g->canCallOS) return errCantCallOS;
3883 PyrSlot *intv = g->sp;
3885 int err;
3886 float interval;
3888 err = slotFloatVal(intv, &interval);
3889 if (err) return err;
3890 SCVirtualMachine* scvm = [SCVirtualMachine sharedInstance];
3891 [scvm setDeferredTaskInterval: interval];
3893 return errNone;
3896 void initSCImagePrimitives();
3898 void initGUIPrimitives()
3900 int base, index;
3902 s_draw = getsym("draw");
3903 s_font = getsym("SCFont");
3904 s_closed = getsym("closed");
3905 s_tick = getsym("tick");
3906 s_doaction = getsym("doAction");
3907 s_didBecomeKey = getsym("didBecomeKey");
3908 s_didResignKey = getsym("didResignKey");
3910 base = nextPrimitiveIndex();
3911 index = 0;
3914 //reset scobjects in mydocument
3915 //_TextWindow_ primitves by jan.t
3916 NSDocumentController *docctl = [NSDocumentController sharedDocumentController];
3917 if (docctl) {
3918 int num = [[docctl documents] count];
3919 for(int i=0; i<num; i++){
3920 MyDocument * doc = [[docctl documents] objectAtIndex: i];
3921 [doc setSCObject: nil];
3925 definePrimitive(base, index++, "_TextWindow_ToFront", prTextWindow_ToFront, 1, 0);
3926 definePrimitive(base, index++, "_TextWindow_SelectedText", prTextWindow_SelectedText, 1, 0);
3927 definePrimitive(base, index++, "_TextWindow_InsertText", prTextWindow_InsertText, 2, 0);
3928 definePrimitive(base, index++, "_TextWindow_InsertTextInRange", prTextWindow_InsertTextInRange, 4, 0);
3929 definePrimitive(base, index++, "_TextWindow_GetByIndex", prTextWindow_GetByIndex, 2, 0);
3930 definePrimitive(base, index++, "_NumberOfOpenTextWindows", prNumberOfOpenTextWindows, 1, 0);
3931 definePrimitive(base, index++, "_TextWindow_GetLastIndex", prTextWindow_GetLastIndex, 1, 0);
3932 definePrimitive(base, index++, "_TextWindow_GetName", prTextWindow_GetName, 1, 0);
3933 definePrimitive(base, index++, "_TextWindow_IsEdited", prTextWindow_IsEdited, 1, 0);
3934 definePrimitive(base, index++, "_TextWindow_Close", prTextWindow_Close, 1, 0);
3935 definePrimitive(base, index++, "_TextWindow_Text", prTextWindow_Text, 1, 0);
3936 definePrimitive(base, index++, "_TextWindow_SetBackgroundColor", prTextWindow_SetBackgroundColor, 2, 0);
3937 definePrimitive(base, index++, "_TextWindow_GetBackgroundColor", prTextWindow_GetBackgroundColor, 2, 0);
3938 definePrimitive(base, index++, "_TextWindow_SetSelectedBackgroundColor", prTextWindow_SetSelectedBackgroundColor, 2, 0);
3939 definePrimitive(base, index++, "_TextWindow_GetSelectedBackgroundColor", prTextWindow_GetSelectedBackgroundColor, 2, 0);
3940 definePrimitive(base, index++, "_TextWindow_SetTextColor", prTextWindow_SetTextColor, 4, 0);
3941 definePrimitive(base, index++, "_TextWindow_SyntaxColorize", prTextWindow_SyntaxColorize, 1, 0);
3942 definePrimitive(base, index++, "_TextWindow_SelectLine", prTextWindow_SelectLine, 2, 0);
3943 definePrimitive(base, index++, "_TextWindow_SelectRange", prTextWindow_SelectRange, 3, 0);
3944 definePrimitive(base, index++, "_TextWindow_TextWithRange", prTextWindow_TextWithRange, 3, 0);
3945 definePrimitive(base, index++, "_TextWindow_SetFont", prTextWindow_SetFont, 4, 0);
3946 definePrimitive(base, index++, "_TextWindow_GetIndexOfListener", prTextWindow_GetIndexOfListener, 1, 0);
3947 definePrimitive(base, index++, "_TextWindow_GetSelectedRangeLocation", prTextWindow_GetSelectedRangeLocation, 1, 0);
3948 definePrimitive(base, index++, "_TextWindow_GetSelectedRangeLength", prTextWindow_GetSelectedRangeLength, 1, 0);
3949 definePrimitive(base, index++, "_TextWindow_UnfocusedFront", prTextWindow_UnfocusedFront, 1, 0);
3950 definePrimitive(base, index++, "_TextWindow_SetBounds", prTextWindow_SetBounds, 2, 0);
3951 definePrimitive(base, index++, "_TextWindow_GetBounds", prTextWindow_GetBounds, 2, 0);
3952 definePrimitive(base, index++, "_TextWindow_SetName", prTextWindow_SetName, 2, 0);
3953 definePrimitive(base, index++, "_TextWindow_SetEditable", prTextWindow_SetEditable, 2, 0);
3954 definePrimitive(base, index++, "_TextWindow_RemoveUndo", prTextWindow_RemoveUndo, 1, 0);
3955 // definePrimitive(base, index++, "_TextWindow_SelectToken", prTextWindow_SelectToken, 1, 0);
3956 definePrimitive(base, index++, "_TextWindow_SelectUnderlinedText", prTextWindow_SelectUnderlinedText, 2, 0);
3957 definePrimitive(base, index++, "_TextWindow_GetFileName", prTextWindow_GetFileName, 1, 0);
3958 definePrimitive(base, index++, "_TextWindow_SetFileName", prTextWindow_SetFileName, 2, 0);
3960 definePrimitive(base, index++, "_TextWindow_UnderlineSelection", prTextWindow_UnderlineSelection, 1, 0);
3961 definePrimitive(base, index++, "_TextWindow_AlwaysOnTop", prTextWindow_AlwaysOnTop, 2, 0);
3962 definePrimitive(base, index++, "_TextWindow_IsAlwaysOnTop", prTextWindow_IsAlwaysOnTop, 1, 0);
3963 definePrimitive(base, index++, "_TextWindow_SetPromptToSave", prTextWindow_SetPromptToSave, 2, 0);
3964 definePrimitive(base, index++, "_TextWindow_PromptToSave", prTextWindow_PromptToSave, 1, 0);
3965 definePrimitive(base, index++, "_TextWindow_SetDefaultFont", prTextWindow_SetDefaultFont, 2, 0);
3966 definePrimitive(base, index++, "_PostWindow_SetTextColor", prSetPostTextColor, 2, 0);
3967 definePrimitive(base, index++, "_TextWindow_SetSyntaxColorTheme", prSetSyntaxColorTheme, 11, 0);
3968 definePrimitive(base, index++, "_TextWindow_BalanceParens", prBalanceParens, 1, 0);
3969 definePrimitive(base, index++, "_TextWindow_UsesAutoInOutdent", prTextWindow_UsesAutoInOutdent, 2, 0);
3970 definePrimitive(base, index++, "_TextWindow_DefaultUsesAutoInOutdent", prTextWindow_DefaultUsesAutoInOutdent, 2, 0);
3974 definePrimitive(base, index++, "_NewTextWindow", prNewTextWindow, 4, 0);
3975 definePrimitive(base, index++, "_OpenTextFile", prOpenTextFile, 4, 0);
3977 definePrimitive(base, index++, "_GetStringFromUser", prGetStringFromUser, 3, 0);
3978 definePrimitive(base, index++, "_SCWindow_New", prSCWindow_New, 7, 0);
3979 definePrimitive(base, index++, "_SCWindow_Refresh", prSCWindow_Refresh, 1, 0);
3980 definePrimitive(base, index++, "_SCWindow_Close", prSCWindow_Close, 1, 0);
3981 definePrimitive(base, index++, "_SCWindow_Minimize", prSCWindow_Minimize, 1, 0);
3982 definePrimitive(base, index++, "_SCWindow_ToFront", prSCWindow_ToFront, 1, 0);
3983 definePrimitive(base, index++, "_SCWindow_BeginFullScreen", prSCWindow_FullScreen, 1, 0);
3984 definePrimitive(base, index++, "_SCWindow_EndFullScreen", prSCWindow_EndFullScreen, 1, 0);
3985 definePrimitive(base, index++, "_SCWindow_SetShouldClose", prSCWindow_SetShouldClose, 2, 0);
3987 definePrimitive(base, index++, "_SCWindow_Show", prSCWindow_Show, 1, 0);
3988 definePrimitive(base, index++, "_SCWindow_Hide", prSCWindow_Hide, 1, 0);
3989 definePrimitive(base, index++, "_SCWindow_AlwaysOnTop", prSCWindow_AlwaysOnTop, 2, 0);
3990 definePrimitive(base, index++, "_SCWindow_AcceptsClickThrough", prSCWindow_AcceptsClickThrough, 2, 0);
3992 definePrimitive(base, index++, "_SCWindow_SetName", prSCWindow_SetName, 2, 0);
3993 definePrimitive(base, index++, "_SCWindow_SetAlpha", prSCWindow_SetAlpha, 2, 0);
3994 definePrimitive(base, index++, "_SCWindow_SetBounds", prSCWindow_SetBounds, 2, 0);
3995 definePrimitive(base, index++, "_SCWindow_GetBounds", prSCWindow_GetBounds, 2, 0);
3996 definePrimitive(base, index++, "_SCWindow_GetScreenBounds", prSCWindow_GetScreenBounds, 2, 0);
3997 definePrimitive(base, index++, "_SCWindow_SetAcceptMouseOver", prSCWindow_SetAcceptMouseOver, 2, 0);
3998 definePrimitive(base, index++, "_SCWindow_RunModal", prSCWindow_RunModal, 1, 0);
3999 definePrimitive(base, index++, "_SCWindow_StopModal", prSCWindow_StopModal, 1, 0);
4000 definePrimitive(base, index++, "_SCWindow_RunModalSheet", prSCWindow_RunModalSheet, 2, 0);
4001 definePrimitive(base, index++, "_SCWindow_StopModalSheet", prSCWindow_StopModalSheet, 1, 0);
4002 definePrimitive(base, index++, "_ShowCursor", prShowCursor, 2, 0);
4004 definePrimitive(base, index++, "_String_GetBounds", prString_GetBounds, 3, 0);
4005 definePrimitive(base, index++, "_String_DrawAtPoint", prString_DrawAtPoint, 4, 0);
4006 definePrimitive(base, index++, "_String_DrawInRect", prString_DrawInRect, 4, 0);
4007 definePrimitive(base, index++, "_Color_SetStroke", prColor_SetStroke, 1, 0);
4008 definePrimitive(base, index++, "_Color_SetFill", prColor_SetFill, 1, 0);
4010 definePrimitive(base, index++, "_Pen_StrokeRect", prPen_StrokeRect, 2, 0);
4011 definePrimitive(base, index++, "_Pen_FillRect", prPen_FillRect, 2, 0);
4012 definePrimitive(base, index++, "_Pen_StrokeOval", prPen_StrokeOval, 2, 0);
4013 definePrimitive(base, index++, "_Pen_FillOval", prPen_FillOval, 2, 0);
4014 definePrimitive(base, index++, "_Pen_StrokeLine", prPen_StrokeLine, 3, 0);
4015 definePrimitive(base, index++, "_Pen_Push", prPen_Push, 1, 0);
4016 definePrimitive(base, index++, "_Pen_Pop", prPen_Pop, 1, 0);
4017 definePrimitive(base, index++, "_Pen_Translate", prPen_Translate, 3, 0);
4018 definePrimitive(base, index++, "_Pen_Skew", prPen_Skew, 3, 0);
4019 definePrimitive(base, index++, "_Pen_Scale", prPen_Scale, 3, 0);
4020 definePrimitive(base, index++, "_Pen_Rotate", prPen_Rotate, 4, 0);
4021 definePrimitive(base, index++, "_Pen_SetWidth", prPen_SetWidth, 2, 0);
4022 definePrimitive(base, index++, "_Pen_SetMatrix", prPen_SetMatrix, 2, 0);
4023 definePrimitive(base, index++, "_Pen_AddRect", prPen_AddRect, 2, 0);
4024 definePrimitive(base, index++, "_Pen_AddArc", prPen_AddArc, 5, 0);
4025 definePrimitive(base, index++, "_Pen_AddWedge", prPen_AddWedge, 5, 0);
4026 definePrimitive(base, index++, "_Pen_AddAnnularWedge", prPen_AddAnnularWedge, 6, 0);
4028 definePrimitive(base, index++, "_Pen_BeginPath", prPen_BeginPath, 1, 0);
4029 definePrimitive(base, index++, "_Pen_ClosePath", prPen_ClosePath, 1, 0);
4030 definePrimitive(base, index++, "_Pen_MoveTo", prPen_MoveTo, 2, 0);
4031 definePrimitive(base, index++, "_Pen_LineTo", prPen_LineTo, 2, 0);
4032 definePrimitive(base, index++, "_Pen_StrokePath", prPen_StrokePath, 1, 0);
4033 definePrimitive(base, index++, "_Pen_FillPath", prPen_FillPath, 1, 0);
4034 definePrimitive(base, index++, "_Pen_ClipPath", prPen_ClipPath, 1, 0);
4036 definePrimitive(base, index++, "_Pen_AddQuadCurve", prPen_AddBezierQuadCurve, 3, 0);
4037 definePrimitive(base, index++, "_Pen_AddCubicCurve", prPen_AddBezierCubicCurve, 4, 0);
4038 definePrimitive(base, index++, "_Pen_AddArcToPoint", prPen_AddArcToPoint, 4, 0);
4039 definePrimitive(base, index++, "_Pen_ClearRect", prPen_ClearRect, 2, 0);
4040 definePrimitive(base, index++, "_Pen_SetBlendMode", prPen_SetBlend, 2, 0);
4041 definePrimitive(base, index++, "_Pen_SetShadow", prPen_SetShadow, 4, 0);
4042 definePrimitive(base, index++, "_Pen_SetAlpha", prPen_SetAlpha, 2, 0);
4043 definePrimitive(base, index++, "_Pen_BeginTLayer", prPen_BeginTransparencyLayer, 1, 0);
4044 definePrimitive(base, index++, "_Pen_EndTLayer", prPen_EndTransparencyLayer, 1, 0);
4045 definePrimitive(base, index++, "_Pen_DrawPath", prPen_DrawPath, 2, 0);
4046 definePrimitive(base, index++, "_Pen_LineJoin", prPen_LineJoin, 2, 0);
4047 definePrimitive(base, index++, "_Pen_LineDash", prPen_LineDash, 2, 0);
4048 definePrimitive(base, index++, "_Pen_LineCap", prPen_LineCap, 2, 0);
4049 definePrimitive(base, index++, "_Pen_AddOval", prPen_AddOval, 2, 0);
4050 definePrimitive(base, index++, "_Pen_DrawAxialGradient", prPen_DrawAxialGradient, 5, 0);
4051 definePrimitive(base, index++, "_Pen_DrawRadialGradient", prPen_DrawRadialGradient, 7, 0);
4053 definePrimitive(base, index++, "_HasDeferred", prHasDeferred, 1, 0);
4054 definePrimitive(base, index++, "_LoadUserPanel", prLoadUserPanel, 2, 0);
4056 definePrimitive(base, index++, "_Font_AvailableFonts", prFont_AvailableFonts, 1, 0);
4057 definePrimitive(base, index++, "_Font_SetAntiAliasing", prFont_SetAntiAliasing, 2, 0);
4058 definePrimitive(base, index++, "_Font_SetSmoothing", prFont_SetSmoothing, 2, 0);
4060 definePrimitive(base, index++, "_TextWindow_LinkAtClickPos", prTextWindow_LinkAtClickPos, 2, 0);
4061 definePrimitive(base, index++, "_Pen_SetSmoothing", prPen_SetSmoothing, 2, 0);
4063 definePrimitive(base, index++, "_NewMenuItem", prNewMenuItem, 5, 0);
4064 definePrimitive(base, index++, "_NewMenuSeparator", prNewMenuSeparator, 3, 0);
4065 definePrimitive(base, index++, "_RemoveMenuItem", prRemoveMenuItem, 1, 0);
4066 definePrimitive(base, index++, "_EnableMenuItem", prEnableMenuItem, 2, 0);
4067 definePrimitive(base, index++, "_SetMenuItemState", prSetMenuItemState, 2, 0);
4068 definePrimitive(base, index++, "_SetMenuItemKeyboardEquivalent", prSetMenuItemKeyboardEquivalent, 4, 0);
4069 definePrimitive(base, index++, "_Mouse_getCoords", prMouse_getCoords, 2, 0);
4071 definePrimitive(base, index++, "_Recompile", prRecompile, 1, 0);
4072 definePrimitive(base, index++, "_SetDeferredTaskInterval", prSetDeferredTaskInterval, 2, 0);
4074 initSCImagePrimitives();