scide: LookupDialog - redo lookup on classes after partial lookup
[supercollider.git] / SCClassLibrary / Common / GUI / osx / scide_scapp / Base / SCTextField2.sc
blobe3d4f3fb052d841cb6972fa59c5295325f8f5acb
1 /*
3 w = SCWindow.new.front;
4 a = SCTextField2(w, Rect(10, 10, 100, 20));
5 b = SCTextField2(w, Rect(10, 100, 250, 40));
6 c = SCTextField(w, Rect(10, 200, 250, 20)).string_("old-style text box");
7 a.string = "hi there";
8 a.action = {arg field; field.value.postln; };
11 a.value = "yo";
12 a.string = "oy";
13 a.valueAction = "yoooo";
15 a.boxColor_(Color.yellow)
17 a.align_(\left)
18 a.align_(\center)
19 a.align_(\right)
21 b.align_(\left)
22 b.align_(\center)
23 b.align_(\right)
25 a.editable_(false);
26 a.editable_(true);
28 // Drag-and-drop NOWORKY:
29 a.defaultGetDrag
30 a.defaultCanReceiveDrag
31 a.defaultReceiveDrag
33 a.font
34 a.font_(Font(Font.defaultSerifFace))
35 a.font_(Font(Font.defaultSansFace), 8)
36 a.font_(nil)
38 a.stringColor
39 a.stringColor_(Color.red)
40 a.stringColor
42 SCTextField : SCStaticTextBase {
44         *paletteExample { arg parent, bounds;
45 //              ^this.new(parent, bounds).initBackGround.value_("edit me");
46                 ^this.new(parent, bounds).value_("edit me");
48         }
50         initBackGround {
51                 super.init;
52                 background = Color.white;
54         }
56         value {
57                 ^this.string
58         }
59         string{
60                 ^this.getProperty(\string);
61         }
63         value_{|str|
64                 ^this.string_(str);
65         }
66         valueAction_{|str|
67                 ^this.string_(str).doAction;
68         }
69         boxColor {
70                 this.deprecated(thisMethod, SCView.findMethod(\background));
71                 ^this.background;
72         }
73         boxColor_ { arg color;
74                 this.deprecated(thisMethod, SCView.findMethod(\background_));
75                 this.background_(color)
76         }
77         properties {
78                 ^super.properties ++ #[\boxColor]
79         }
81         // Dragging doesn't seem to be working here
82         defaultGetDrag {
83                 //"defaultGetDrag was called".postln;
84                 ^this.string
85         }
86         defaultCanReceiveDrag {
87                 //"defaultCanReceiveDrag was called".postln;
88                 ^currentDrag.respondsTo(\asString)
89         }
90         defaultReceiveDrag {
91                 //"defaultReceiveDrag was called".postln;
92                 this.valueAction = currentDrag;
93         }
95         // private:
96         // prClose removes action here, to prevent action acting on textview after it's gone
97         prClose { dataptr = nil; action = nil; onClose.value(this); }
101 SCNumberBox : SCTextField {
103         //var <> keyString,
104         var <>step=1, <>scroll_step=1;
105         var <>typingColor, <>normalColor;
106         var <>clipLo = -inf, <>clipHi = inf, hit, inc=1.0, <>scroll=true;
107         var <>shift_scale = 100.0, <>ctrl_scale = 10.0, <>alt_scale = 0.1;
108         //var mouseIncOrDeced = true;
110         getScale { |modifiers|
111                 ^case
112                         { modifiers & 131072 == 131072 } { shift_scale }
113                         { modifiers & 262144 == 262144 } { ctrl_scale }
114                         { modifiers & 524288 == 524288 } { alt_scale }
115                         { 1 };
116         }
118         *paletteExample { arg parent, bounds;
119                 var v;
120                 v = this.new(parent, bounds);
121                 v.value = 123.456;
122                 ^v
123         }
125 //      init { arg argParent, argBounds;
126 //              typingColor = Color.red;
127 //              normalColor = Color.black;
128 //              background = Color.white;
129 //              parent = argParent.asView; // actual view
130 //              this.prInit(parent.asView, argBounds.asRect,this.class.viewClass);
131 //              argParent.add(this);//maybe window or viewadapter
132 //      }
134 //      clipLo_ {|val = -inf|
135 //              clipLo = val;
136 //              this.setProperty(\clipLo, val);
137 //      }
139 //      clipHi_ {|val = inf|
140 //              clipHi = val;
141 //              this.setProperty(\clipHi, val);
142 //      }
144         increment {arg mul=1; this.valueAction = this.value + (step*mul); }
145         decrement {arg mul=1; this.valueAction = this.value - (step*mul); }
147         defaultKeyDownAction { arg char, modifiers, unicode;
148                 var zoom = this.getScale(modifiers);
150                 // standard chardown
151                 if (unicode == 16rF700, { this.increment(zoom); ^this });
152                 if (unicode == 16rF703, { this.increment(zoom); ^this });
153                 if (unicode == 16rF701, { this.decrement(zoom); ^this });
154                 if (unicode == 16rF702, { this.decrement(zoom); ^this });
156 //              if ((char == 3.asAscii) || (char == $\r) || (char == $\n), { // enter key
157 //                      if (keyString.notNil,{ // no error on repeated enter
158 //                              this.valueAction_(keyString.asFloat);
159 //                      });
160 //                      ^this
161 //              });
162 //              if (char == 127.asAscii, { // delete key
163 //                      keyString = nil;
164 //                      this.string = object.asString;
165 //                      this.stringColor = normalColor;
166 //                      ^this
167 //              });
168 //              if (char.isDecDigit || "+-.eE".includes(char), {
169 //                      if (keyString.isNil, {
170 //                              keyString = String.new;
171 //                              this.stringColor = typingColor;
172 //                      });
173 //                      keyString = keyString.add(char);
174 //                      this.string = keyString;
175 //                      ^this
176 //              });
180                 ^nil            // bubble if it's an invalid key
181         }
183         //value { ^object }
184 //      value_ { arg val;
185 //              keyString = nil;
186 //              this.stringColor = normalColor;
187 //              object = val !? { val.clip(clipLo, clipHi) };
188 //              this.string = object.asString;
189 //      }
190 //      valueAction_ { arg val;
191 //              var prev;
192 //              prev = object;
193 //              this.value = val !? { val.clip(clipLo, clipHi) };
194 //              if (object != prev, { this.doAction });
195 //      }
197 //      boxColor {
198 //              this.deprecated(thisMethod, SCView.findMethod(\background));
199 //              ^this.background;
200 //      }
201 //      boxColor_ { arg color;
202 //              this.deprecated(thisMethod, SCView.findMethod(\background_));
203 //              this.background_(color)
204 //      }
206         properties {
207                 ^super.properties ++ #[\boxColor]
208         }
209         defaultGetDrag {
210                 ^this.value;
211         }
212         defaultCanReceiveDrag {
213                 ^currentDrag.isNumber;
214         }
215         defaultReceiveDrag {
216                 this.valueAction = currentDrag;
217         }
219         mouseDown { arg x, y, modifiers, buttonNumber, clickCount;
220                 hit = Point(x,y);
221                 if (scroll == true, { inc = this.getScale(modifiers) });
222                 mouseDownAction.value(this, x, y, modifiers, buttonNumber, clickCount)
223         }
225         mouseMove { arg x, y, modifiers;
226                 var direction;
227                 if (scroll == true, {
228                         //mouseIncOrDeced = true;
229                         direction = 1.0;
230                                 // horizontal or vertical scrolling:
231                         if ( (x - hit.x) < 0 or: { (y - hit.y) > 0 }) { direction = -1.0; };
233                         this.valueAction = (this.value + (inc * this.scroll_step * direction));
234                         hit = Point(x, y);
235                 });
236                 mouseMoveAction.value(this, x, y, modifiers);
237         }
238         mouseUp{
240                 //if(mouseIncOrDeced, {this.value = this.value;mouseIncOrDeced = false});
241                 inc=1
242         }
245         value {
246                 ^this.getProperty(\value);
247         }
249         value_ { arg val;
250                 val = val !? { val.clip(clipLo, clipHi) };
251                 this.setProperty(\value, val);
252         }
254         valueAction_ { arg val;
255                 var prev;
256                 prev = this.value;
257                 val = val !? { val.clip(clipLo, clipHi) };
258                 if (val != prev, { this.value_(val); this.doAction });
259         }
261         // validate range here
262         doAction {
263                 var current;
264                 current = this.value;
265                 if(current.inclusivelyBetween(clipLo, clipHi).not, {
266                         this.value = current; // clips here
267                 });
268                 action.value(this);
269         }