2 classvar <>allWindows, <currentFullScreen, <>initAction;
4 var dataptr, <name, <>onClose, <view, <userCanClose=true;
5 var <alwaysOnTop=false;
7 var <acceptsMouseOver=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
15 ShutDown.add { this.closeAll };
18 *new { arg name = "panel", bounds, resizable = true, border = true, server, scroll = false;
19 ^super.new.initSCWindow(name, bounds, resizable, border, scroll)
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);
27 view = SCScrollTopView(nil, argBounds.moveTo(0,0));
29 view = SCTopView(nil, argBounds.moveTo(0,0));
31 this.prInit(name, argBounds, resizable, border, scroll, view, appmodal);
32 initAction.value(this);
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 ) )};
47 list = allWindows.copy;
48 allWindows = Array.new(8);
49 list.do({ arg window; window.close; });
53 if (isClosed) { ^this };
58 onClose.value; // call user function
61 allWindows.remove(this);
64 addToOnClose { | function | onClose = onClose.addFunc(function) }
66 removeFromOnClose { | function | onClose = onClose.removeFunc(function) }
69 currentFullScreen.notNil.if({currentFullScreen.endFullScreen});
71 currentFullScreen = this;
75 currentFullScreen = nil;
79 _SCWindow_BeginFullScreen
83 _SCWindow_EndFullScreen
86 userCanClose_ { arg boo;
87 _SCWindow_SetShouldClose
90 acceptsMouseOver_{arg bool;
91 acceptsMouseOver = bool;
92 this.prSetAcceptMouseOver(bool);
99 alwaysOnTop_{|bool=true|
101 this.prSetAlwaysOnTop(bool);
104 prSetAlwaysOnTop{|boolean=true|
105 _SCWindow_AlwaysOnTop
108 acceptsClickThrough_{|boolean=true|
109 acceptsClickThrough = boolean;
110 this.prSetAcceptsClickThrough(boolean);
113 prSetAcceptsClickThrough{|boolean=true|
114 _SCWindow_AcceptsClickThrough
119 ^this.primitiveFailed
123 ^this.primitiveFailed
127 ^this.primitiveFailed
132 this.prSetName(argName);
134 // bounds are relative to the bottom left corner origin
135 bounds_ { arg argBounds;
136 this.prSetBounds(argBounds);
138 // set bounds relative to top left corner
139 setTopLeftBounds { |rect,menuSpacer=45|
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;
146 setInnerExtent { arg w,h; // resize window keeping top left corner fixed
151 this.bounds = Rect(b.left,b.top + (b.height - h), w,h);
154 ^this.prGetBounds(Rect.new);
157 ^this.prGetScreenBounds(Rect.new);
162 this.deprecated(thisMethod, this.class.findMethod(\drawFunc));
165 drawHook_ { |aFunction|
166 this.deprecated(thisMethod, this.class.findMethod(\drawFunc_));
167 this.drawFunc_(aFunction)
172 if (dataptr.notNil, {
185 prInit { arg argName, argBounds, resizable, border, scroll, view, appmodal = false;
187 ^this.primitiveFailed
191 ^this.primitiveFailed
193 prSetName { arg argName;
195 ^this.primitiveFailed
197 prGetBounds { arg argBounds;
199 ^this.primitiveFailed
201 prSetBounds { arg argBounds;
203 ^this.primitiveFailed
205 prSetAcceptMouseOver{arg bool;
206 _SCWindow_SetAcceptMouseOver
207 ^this.primitiveFailed
209 *prGetScreenBounds { arg argBounds;
210 _SCWindow_GetScreenBounds
211 ^this.primitiveFailed
214 drawFunc.value(this);
218 toFrontAction.value(this);
222 endFrontAction.value(this);
227 editable = editable.not;
229 SCIBToolboxWindow.front.addWindow(this);
232 SCIBToolboxWindow.front.removeWindow(this);
235 setCurrentSheet {|sheet| currentSheet = sheet;}
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);
245 w.view.decorator.nextLine;
246 // c = [SCSlider, SCRangeSlider, SC2DSlider, SCPopUpMenu, SCButton,
247 // SCNumberBox, SCMultiSliderView,
248 // SCStaticText, SCDragSource, SCDragSink, SCDragBoth,
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'))
260 n = SCDragSource(w, Rect(0, 0, 140, 24));
264 item.paletteExample(w, Rect(0,0,140,24));
266 "no paletteExample found".warn;
268 w.view.decorator.nextLine;
272 Document("window construction code", win.asConstructionCompileString);
279 storeArgs{^[name, this.bounds]}
280 storeModifiersOn{|stream|