deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / GUI / osx / scide_scapp / Base / GUIScreen.sc
blob2313577c2c2c60047d3c63d614a20f4bad3b4bcb
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.decorator_( FlowLayout( view.bounds.moveTo(0,0), margin, gap ) );
40                 ^this.view.decorator;
41          }
43         *closeAll {
44                 var list;
45                 list = allWindows.copy;
46                 allWindows = Array.new(8);
47                 list.do({ arg window; window.close; });
48         }
50         close {
51                 if (isClosed) { ^this };
52                 this.prClose;
53         }
54         closed {
55                 isClosed = true;
56                 onClose.value; // call user function
57                 dataptr = nil;
58                 view.prClose;
59                 allWindows.remove(this);
60         }
62         addToOnClose { | function | onClose = onClose.addFunc(function) }
64         removeFromOnClose { | function | onClose = onClose.removeFunc(function) }
66         fullScreen {
67                 currentFullScreen.notNil.if({currentFullScreen.endFullScreen});
68                 this.prFullScreen;
69                 currentFullScreen = this;
70         }
71         endFullScreen {
72                 this.prEndFullScreen;
73                 currentFullScreen = nil;
74         }
76         prFullScreen {
77                 _SCWindow_BeginFullScreen
78                 ^this.primitiveFailed
79         }
80         prEndFullScreen {
81                 _SCWindow_EndFullScreen
82                 ^this.primitiveFailed
83         }
84         userCanClose_ { arg boo;
85                 _SCWindow_SetShouldClose
86                 ^this.primitiveFailed
87         }
88         acceptsMouseOver_{arg bool;
89                 acceptsMouseOver = bool;
90                 this.prSetAcceptMouseOver(bool);
91         }
92         front {
93                 _SCWindow_ToFront
94                 ^this.primitiveFailed
95         }
97         alwaysOnTop_{|bool=true|
98                 alwaysOnTop = bool;
99                 this.prSetAlwaysOnTop(bool);
100         }
102         prSetAlwaysOnTop{|boolean=true|
103                 _SCWindow_AlwaysOnTop
104         }
106         acceptsClickThrough_{|boolean=true|
107                 acceptsClickThrough = boolean;
108                 this.prSetAcceptsClickThrough(boolean);
109         }
111         prSetAcceptsClickThrough{|boolean=true|
112                 _SCWindow_AcceptsClickThrough
113         }
115         refresh {
116                 _SCWindow_Refresh
117                 ^this.primitiveFailed
118         }
119         minimize {
120                 _SCWindow_Minimize
121                 ^this.primitiveFailed
122         }
123         alpha_ { arg alpha;
124                 _SCWindow_SetAlpha
125                 ^this.primitiveFailed
126         }
128         name_ { arg argName;
129                 name = argName.asString;
130                 this.prSetName(name);
131         }
132         // bounds are relative to the bottom left corner origin
133         bounds_ { arg argBounds;
134                 this.prSetBounds(argBounds);
135         }
136         // set bounds relative to top left corner
137         setTopLeftBounds { |rect,menuSpacer=45|
138                 rect = rect.copy;
139                 // 45 is the height of the mac os menu
140                 // if you are in full screen mode you would want to pass in 0
141                 rect.top = SCWindow.screenBounds.height - rect.height - rect.top - menuSpacer;
142                 this.bounds = rect
143         }
144         setInnerExtent { arg w,h; // resize window keeping top left corner fixed
145                 var b;
146                 b = this.bounds;
147                 w = w ? b.width;
148                 h = h ? b.height;
149                 this.bounds = Rect(b.left,b.top + (b.height - h), w,h);
150         }
151         bounds {
152                 ^this.prGetBounds(Rect.new);
153         }
154         *screenBounds {
155                 ^this.prGetScreenBounds(Rect.new);
156         }
158         play { arg function;
159                 AppClock.play({
160                         if (dataptr.notNil, {
161                                 function.value;
162                         });
163                 });
165         }
167         findByID { arg id;
168                 ^view.findByID(id)
169         }
171         // PRIVATE
172         // primitives
173         prInit { arg argName, argBounds, resizable, border, scroll, view, appmodal = false;
174                 _SCWindow_New
175                 ^this.primitiveFailed
176         }
177         prClose {
178                 _SCWindow_Close
179                 ^this.primitiveFailed
180         }
181         prSetName { arg argName;
182                 _SCWindow_SetName
183                 ^this.primitiveFailed
184         }
185         prGetBounds { arg argBounds;
186                 _SCWindow_GetBounds
187                 ^this.primitiveFailed
188         }
189         prSetBounds { arg argBounds;
190                 _SCWindow_SetBounds
191                 ^this.primitiveFailed
192         }
193         prSetAcceptMouseOver{arg bool;
194                 _SCWindow_SetAcceptMouseOver
195                 ^this.primitiveFailed
196         }
197         *prGetScreenBounds { arg argBounds;
198                 _SCWindow_GetScreenBounds
199                 ^this.primitiveFailed
200         }
201         callDrawFunc {
202                 drawFunc.value(this);
203         }
205         didBecomeKey {
206                 toFrontAction.value(this);
207         }
209         didResignKey {
210                 endFrontAction.value(this);
211         }
213         toggleEditMode{
214                 var panel;
215                 editable = editable.not;
216                 if(editable){
217                         SCIBToolboxWindow.front.addWindow(this);
218                         this.refresh;
219                 }{
220                         SCIBToolboxWindow.front.removeWindow(this);
221                 }
222         }
223         setCurrentSheet {|sheet| currentSheet = sheet;}
224         /*
225         *viewPalette {|win|
226                 var w, v, f, c;
227                 w = SCWindow("View Palette", Rect(532, 64, 300, 320),  scroll: true).front;
228                 w.view.decorator = f = FlowLayout(w.view.bounds);
229                 SCButton(w, 300@20).states_([ ["-> CODE"]])
230                         .canFocus_(false).action_{
231                                 Document("window construction code", win.asConstructionCompileString);
232                                 };
233                 w.view.decorator.nextLine;
234 //              c = [SCSlider, SCRangeSlider, SC2DSlider, SCPopUpMenu, SCButton,
235 //                      SCNumberBox, SCMultiSliderView,
236 //                      SCStaticText, SCDragSource, SCDragSink, SCDragBoth,
237 //              ];
238                 c = SCView.allSubclasses.reject{|it|
239                         (it.superclasses.indexOf(SCContainerView).notNil
240                         or: (it.name === 'SCContainerView')
241                         or: (it.name ==='SCStaticTextBase')
242                         or: (it.name === 'SCSliderBase')
243                         or: (it.name === 'SCControlView'))
244                 };
246                 c.do({ arg item;
247                         var n;
248                         n = SCDragSource(w, Rect(0, 0, 140, 24));
249                         n.object = item;
251                         try{
252                                 item.paletteExample(w, Rect(0,0,140,24));
253                         }{
254                                 "no paletteExample found".warn;
255                         };
256                         w.view.decorator.nextLine;
258                 });
259                 win.onClose_{
260                         Document("window construction code", win.asConstructionCompileString);
261                         w.close
262                         };
263                 ^w
264         }
265         */
267         storeArgs{^[name, this.bounds]}
268         storeModifiersOn{|stream|
269                 stream << ".front;";
270         }
273 SCAbstractModalWindow : SCWindow {
275         front {
276                 this.shouldNotImplement(thisMethod);
277         }
279         userCanClose_ {
280                 this.shouldNotImplement(thisMethod);
281         }
285 SCModalWindow : SCAbstractModalWindow {
287         classvar <current;
289         *new { arg name = "panel", bounds, resizable = false, border = true, server, scroll = false;
290                 // app modal flag is true
291                 ^super.new(name, bounds, resizable, border, nil, scroll).setCurrent.runModal;
292         }
294         // override to set appmodal to true
295         initSCWindow {|argName, argBounds, resizable, border, scroll, appmodal|
296                 ^super.initSCWindow(argName, argBounds !? {argBounds.asRect}, resizable, border, scroll, true);
297         }
300         /// PRIVATE
302         setCurrent { current = this; }
304         runModal {
305                 _SCWindow_RunModal
306                 ^this.primitiveFailed;
307         }
309         prClose {
310                 _SCWindow_StopModal
311                 ^this.primitiveFailed;
312         }
314         closed { current = nil; super.closed }
318 SCModalSheet : SCAbstractModalWindow {
319         var parentWindow;
321         *new { arg window, bounds, resizable = false, border = true, server, scroll = false;
322                 ^window.isClosed.not.if({
323                         super.new("", bounds !? {bounds.asRect}, resizable, border, nil, scroll)
324                                 .setCurrent(window)
325                                 .runModal(window);
326                 }, nil);
327         }
329         /// PRIVATE
331         setCurrent { |window|
332                 parentWindow = window;
333                 parentWindow.setCurrentSheet(this);
334         }
336         runModal {|window|
337                 _SCWindow_RunModalSheet
338                 ^this.primitiveFailed;
339         }
341         prClose {
342                 _SCWindow_StopModalSheet
343                 ^this.primitiveFailed;
344         }
346         closed { parentWindow.setCurrentSheet(nil); super.closed }