class library: remove cruft
[supercollider.git] / SCClassLibrary / Common / GUI / PlusGUI / Collections / StringPlusGUI.sc
blobe69a2218f636162be09fcd43dbfdb188ccb82ab1
1 + String {
2         newTextWindow { arg title="Untitled", makeListener=false;
3                 Document.new(title, this, makeListener);
4         }
6         openHTMLFile{ arg selectionStart=0, selectionLength=0;
7                 var webView;
9                 if (Platform.openHTMLFileAction.notNil) {
10                         Platform.openHTMLFileAction.value(this, selectionStart, selectionLength);
11                         ^this
12                 };
14                 webView = \QWebView.asClass;
15                 if (webView.notNil) {
16                         webView = webView.new;
17                         webView.url_(this);
18                         webView.front;
19                         ^this;
20                 };
22                 this.openDocument(selectionStart, selectionLength)
23         }
25         openDocument { arg selectionStart=0, selectionLength=0;
26                 var ideClass;
27                 if(Document.implementationClass.notNil) {
28                         Document.open(this, selectionStart, selectionLength);
29                         ^this
30                 };
32                 ideClass = \ScIDE.asClass;
33                 if ( ideClass.notNil ) {
34                         if ( this.endsWith(".sc") || this.endsWith(".scd") ) {
35                                 ideClass.open(this, selectionStart, selectionLength);
36                                 ^this
37                         }
38                 };
40                 this.openOS
41         }
43         draw {
44                 this.drawAtPoint(Point(0,0), Font.default, Color.black);
45         }
46         drawAtPoint { arg point, font, color;
47                 if(GUI.id === \cocoa)
48                         { this.prDrawAtPoint( point, font, color ) }
49                         { Pen.stringAtPoint( this, point, font, color ) }
50         }
51         drawInRect { arg rect, font, color;
52                 if(GUI.id === \cocoa)
53                         { this.prDrawInRect( rect, font, color ) }
54                         { Pen.stringInRect( this, rect, font, color ) }
55         }
56         prDrawAtPoint { arg point, font, color;
57                 _String_DrawAtPoint
58                 ^this.primitiveFailed
59         }
60         prDrawInRect { arg rect, font, color;
61                 _String_DrawInRect
62                 ^this.primitiveFailed
63         }
64         drawCenteredIn { arg rect, font, color;
65                 if(GUI.id === \cocoa)
66                         { this.drawAtPoint(this.bounds( font ).centerIn(rect), font, color) }
67                         { Pen.stringCenteredIn( this, rect, font, color ) }
68         }
69         drawLeftJustIn { arg rect, font, color;
70                 var pos, bounds;
71                 if(GUI.id === \cocoa)
72                         {
73                                 bounds = this.bounds( font );
74                                 pos = bounds.centerIn(rect);
75                                 pos.x = rect.left + 2;
76                                 this.drawAtPoint(pos, font, color);
77                         }
78                         { Pen.stringLeftJustIn( this, rect, font, color ) }
79         }
80         drawRightJustIn { arg rect, font, color;
81                 var pos, bounds;
82                 if(GUI.id === \cocoa)
83                         {
84                                 bounds = this.bounds( font );
85                                 pos = bounds.centerIn(rect);
86                                 pos.x = rect.right - 2 - bounds.width;
87                                 this.drawAtPoint(pos, font, color);
88                         }
89                         { Pen.stringRightJustIn( this, rect, font, color ) }
90         }
92         bounds { arg font;
93                 if(GUI.id === \swing,{
94                         // since Swing is not in svn and can't be easily updated
95                         // let's put this temporary hack/if-statement here
96                         // rather than pollute everybody else's code with hacks/if-statements
97                         font = font ?? { Font.default };
98                         ^Rect(0, 0, this.size * font.size * 0.52146, font.size * 1.25)
99                         // width in Helvetica approx = string size * font size * 0.52146
100                         // 0.52146 is average of all 32-127 ascii characters widths
101                 },{
102                         ^GUI.stringBounds(this, font)
103                 });
104         }
105         prBounds { arg rect, font;
106                 _String_GetBounds
107                 ^this.primitiveFailed
108         }
111         findHelpFile {
112                 ^SCDoc.findHelpFile(this);
113         }
115         findHelpFileOrElse {
116                 this.findHelpFile;
117         }
119         help {
120                 if (Platform.openHelpFileAction.notNil) {
121                         Platform.openHelpFileAction.value(this)
122                 } {
123                         HelpBrowser.openHelpFor(this);
124                 }
125         }
128 + Symbol {
129         openDocument { arg selectionStart=0, selectionLength=0;
130                 ^this.asString.openDocument(selectionStart, selectionLength)
131         }