deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / GUI / iphone / Base / GUIScreen.sc
blob70324c0792df87ea091a8122f996ddd30cf4e686
1 SCWindow {
2         classvar <>allWindows, <currentFullScreen, <>initAction;
4         var dataptr, <name, <>onClose, <view, <userCanClose=true;
5         var <alwaysOnTop=false;
6         var <>drawFunc;
7         var <acceptsMouseOver=false;
8         var <isClosed = false;
9         var <acceptsClickThrough = true;
10         var <> toFrontAction, <> endFrontAction;
11         var <editable=false, <>constructionView;
12         var <currentSheet; // current modal sheet attached to this window, if it exists
14         *initClass {
15                 ShutDown.add { this.closeAll };
16         }
18         *new { arg name = "panel", bounds, resizable = true, border = true, server, scroll = false;
19                 ^super.new.initSCWindow(name, bounds, resizable, border, scroll)
20         }
21         // appmodal is a private flag used to disable the close button
22         initSCWindow { arg argName, argBounds, resizable, border, scroll, appmodal = false;
23                 name = argName.asString;
24                 argBounds = argBounds ?? {Rect(128, 64, 400, 400)};
25                 allWindows = allWindows.add(this);
26                 scroll.if({
27                         view = SCScrollTopView(nil, argBounds.moveTo(0,0));
28                 },{
29                         view = SCTopView(nil, argBounds.moveTo(0,0));
30                 });
31                 this.prInit(name, argBounds, resizable, border, scroll, view, appmodal);
32                 initAction.value(this);
33         }
35         asView { ^view }
36         add { arg aView; view.add(aView) }
38         addFlowLayout { |margin, gap|
39                 view.relativeOrigin.if
40                         {view.decorator_( FlowLayout( view.bounds.moveTo(0,0), margin, gap ) )}
41                         {view.decorator_( FlowLayout( view.bounds, margin, gap ) )};
42                 ^this.view.decorator;
43                  }
45         *closeAll {
46                 var list;
47                 list = allWindows.copy;
48                 allWindows = Array.new(8);
49                 list.do({ arg window; window.close; });
50         }
52         close {
53                 if (isClosed) { ^this };
54                 this.prClose;
55         }
56         closed {
57                 isClosed = true;
58                 onClose.value; // call user function
59                 dataptr = nil;
60                 view.prClose;
61                 allWindows.remove(this);
62         }
64         addToOnClose { | function | onClose = onClose.addFunc(function) }
66         removeFromOnClose { | function | onClose = onClose.removeFunc(function) }
68         fullScreen {
69                 currentFullScreen.notNil.if({currentFullScreen.endFullScreen});
70                 this.prFullScreen;
71                 currentFullScreen = this;
72         }
73         endFullScreen {
74                 this.prEndFullScreen;
75                 currentFullScreen = nil;
76         }
78         prFullScreen {
79                 _SCWindow_BeginFullScreen
80                 ^this.primitiveFailed
81         }
82         prEndFullScreen {
83                 _SCWindow_EndFullScreen
84                 ^this.primitiveFailed
85         }
86         userCanClose_ { arg boo;
87                 _SCWindow_SetShouldClose
88                 ^this.primitiveFailed
89         }
90         acceptsMouseOver_{arg bool;
91                 acceptsMouseOver = bool;
92                 this.prSetAcceptMouseOver(bool);
93         }
94         front {
95                 _SCWindow_ToFront
96                 ^this.primitiveFailed
97         }
99         alwaysOnTop_{|bool=true|
100                 alwaysOnTop = bool;
101                 this.prSetAlwaysOnTop(bool);
102         }
104         prSetAlwaysOnTop{|boolean=true|
105                 _SCWindow_AlwaysOnTop
106         }
108         acceptsClickThrough_{|boolean=true|
109                 acceptsClickThrough = boolean;
110                 this.prSetAcceptsClickThrough(boolean);
111         }
113         prSetAcceptsClickThrough{|boolean=true|
114                 _SCWindow_AcceptsClickThrough
115         }
117         refresh {
118                 _SCWindow_Refresh
119                 ^this.primitiveFailed
120         }
121         minimize {
122                 _SCWindow_Minimize
123                 ^this.primitiveFailed
124         }
125         alpha_ { arg alpha;
126                 _SCWindow_SetAlpha
127                 ^this.primitiveFailed
128         }
130         name_ { arg argName;
131                 name = argName;
132                 this.prSetName(argName);
133         }
134         // bounds are relative to the bottom left corner origin
135         bounds_ { arg argBounds;
136                 this.prSetBounds(argBounds);
137         }
138         // set bounds relative to top left corner
139         setTopLeftBounds { |rect,menuSpacer=45|
140                 rect = rect.copy;
141                 // 45 is the height of the mac os menu
142                 // if you are in full screen mode you would want to pass in 0
143                 rect.top = SCWindow.screenBounds.height - rect.height - rect.top - menuSpacer;
144                 this.bounds = rect
145         }
146         setInnerExtent { arg w,h; // resize window keeping top left corner fixed
147                 var b;
148                 b = this.bounds;
149                 w = w ? b.width;
150                 h = h ? b.height;
151                 this.bounds = Rect(b.left,b.top + (b.height - h), w,h);
152         }
153         bounds {
154                 ^this.prGetBounds(Rect.new);
155         }
156         *screenBounds {
157                 ^this.prGetScreenBounds(Rect.new);
158         }
160         // deprecation
161         drawHook {
162                 this.deprecated(thisMethod, this.class.findMethod(\drawFunc));
163                 ^drawFunc
164         }
165         drawHook_ { |aFunction|
166                 this.deprecated(thisMethod, this.class.findMethod(\drawFunc_));
167                 this.drawFunc_(aFunction)
168         }
170         play { arg function;
171                 AppClock.play({
172                         if (dataptr.notNil, {
173                                 function.value;
174                         });
175                 });
177         }
179         findByID { arg id;
180                 ^view.findByID(id)
181         }
183         // PRIVATE
184         // primitives
185         prInit { arg argName, argBounds, resizable, border, scroll, view, appmodal = false;
186                 _SCWindow_New
187                 ^this.primitiveFailed
188         }
189         prClose {
190                 _SCWindow_Close
191                 ^this.primitiveFailed
192         }
193         prSetName { arg argName;
194                 _SCWindow_SetName
195                 ^this.primitiveFailed
196         }
197         prGetBounds { arg argBounds;
198                 _SCWindow_GetBounds
199                 ^this.primitiveFailed
200         }
201         prSetBounds { arg argBounds;
202                 _SCWindow_SetBounds
203                 ^this.primitiveFailed
204         }
205         prSetAcceptMouseOver{arg bool;
206                 _SCWindow_SetAcceptMouseOver
207                 ^this.primitiveFailed
208         }
209         *prGetScreenBounds { arg argBounds;
210                 _SCWindow_GetScreenBounds
211                 ^this.primitiveFailed
212         }
213         callDrawFunc {
214                 drawFunc.value(this);
215         }
217         didBecomeKey {
218                 toFrontAction.value(this);
219         }
221         didResignKey {
222                 endFrontAction.value(this);
223         }
225         toggleEditMode{
226                 var panel;
227                 editable = editable.not;
228                 if(editable){
229                         SCIBToolboxWindow.front.addWindow(this);
230                         this.refresh;
231                 }{
232                         SCIBToolboxWindow.front.removeWindow(this);
233                 }
234         }
235         setCurrentSheet {|sheet| currentSheet = sheet;}
236         /*
237         *viewPalette {|win|
238                 var w, v, f, c;
239                 w = SCWindow("View Palette", Rect(532, 64, 300, 320),  scroll: true).front;
240                 w.view.decorator = f = FlowLayout(w.view.bounds);
241                 SCButton(w, 300@20).states_([ ["-> CODE"]])
242                         .canFocus_(false).action_{
243                                 Document("window construction code", win.asConstructionCompileString);
244                                 };
245                 w.view.decorator.nextLine;
246 //              c = [SCSlider, SCRangeSlider, SC2DSlider, SCPopUpMenu, SCButton,
247 //                      SCNumberBox, SCMultiSliderView,
248 //                      SCStaticText, SCDragSource, SCDragSink, SCDragBoth,
249 //              ];
250                 c = SCView.allSubclasses.reject{|it|
251                         (it.superclasses.indexOf(SCContainerView).notNil
252                         or: (it.name === 'SCContainerView')
253                         or: (it.name ==='SCStaticTextBase')
254                         or: (it.name === 'SCSliderBase')
255                         or: (it.name === 'SCControlView'))
256                 };
258                 c.do({ arg item;
259                         var n;
260                         n = SCDragSource(w, Rect(0, 0, 140, 24));
261                         n.object = item;
263                         try{
264                                 item.paletteExample(w, Rect(0,0,140,24));
265                         }{
266                                 "no paletteExample found".warn;
267                         };
268                         w.view.decorator.nextLine;
270                 });
271                 win.onClose_{
272                         Document("window construction code", win.asConstructionCompileString);
273                         w.close
274                         };
275                 ^w
276         }
277         */
279         storeArgs{^[name, this.bounds]}
280         storeModifiersOn{|stream|
281                 stream << ".front;";
282         }