2 using System.Windows;
\r
3 using System.Windows.Controls;
\r
4 using System.Windows.Documents;
\r
5 using System.Windows.Input;
\r
6 using System.Windows.Media;
\r
7 using System.Windows.Media.Animation;
\r
8 using System.Windows.Media.Imaging;
\r
9 using System.Windows.Shapes;
\r
10 using System.Windows.Browser;
\r
19 class Widget : public Figure {
\r
31 static bool initialized__;
\r
32 static Image default_button, default_horiz_grad;
\r
33 enum TYPE_TAG { NORMAL, ALERT };
\r
35 Color normal_foreground[2], active_foreground[2];
\r
36 Color normal_background[2], active_background[2], over_background[2];
\r
37 Stroke normal_stroke[2], active_stroke[2];
\r
38 Image button_back, *horiz_grad;
\r
40 static Theme current;
\r
41 static void initialize();
\r
46 class WidgetRect : Widget
\r
49 HumanInterfaceDevice::ButtonStateHolder mleft;
\r
54 //Theme::TYPE_TAG theme_type;
\r
55 public Rectangle area;
\r
56 public Letters label;
\r
58 public abstract WidgetRect();
\r
59 public virtual const Point getDatum() const;
\r
60 public virtual WidgetRect& setDatum(const Point&);
\r
61 public virtual WidgetRect& centering(const Point&);
\r
62 public double getWidth() const;
\r
63 public double getHeight() const;
\r
64 public double getLeft() const;
\r
65 public double getTop() const;
\r
66 public double getRight() const;
\r
67 public double getBottom() const;
\r
68 public WidgetRect& alignLeft(const double lef);
\r
69 public WidgetRect& alignTop(const double to_);
\r
70 public WidgetRect& alignRight(const double rig);
\r
71 public WidgetRect& alignBottom(const double bot);
\r
73 public virtual WidgetRect& set(double wid, double hei);
\r
74 public virtual WidgetRect& set(std::wstring name);
\r
75 public virtual WidgetRect& set(std::wstring name, double hei);
\r
76 public virtual WidgetRect& setLabel(std::wstring s);
\r
77 public virtual WidgetRect& draw(Drawable &target = *Drawable::prime);
\r
78 public bool pushed();
\r
79 public WidgetRect& pushThis();
\r
86 public string label;
\r
87 public Rectangle outer;
\r
88 public Rectangle inner;
\r
89 public Stroke outer_strk;
\r
95 public Slider(double width, double height)
\r
99 public Slider set(double width, double height)
\r
101 outer = new Rectangle(width, height);
\r
102 outer.fill = Color.gray;
\r
103 inner = new Rectangle();
\r
104 inner.fill = Color.blue;
\r
105 outer_strk = new Stroke();
\r
106 outer_strk.color = Color.white;
\r
107 outer_strk.thick = 1;
\r
110 public void checkClick()
\r
112 if (outer.include(Mouse.position))
\r
114 outer.stroke = outer_strk;
\r
121 public class Slider
\r
123 public static Color bgcolor;
\r
125 internal System.Windows.UIElement instance;
\r
126 internal System.Windows.Controls.Slider uislider;
\r
127 internal System.Windows.Controls.TextBlock uilabel;
\r
128 internal System.Windows.Controls.TextBox uibox;
\r
129 internal string label;
\r
130 internal Interval range;
\r
131 internal SelfDelegate get_;
\r
132 internal SelfDelegate set_;
\r
133 internal double retval;
\r
134 internal bool setted_;
\r
138 bgcolor.set(.5,.5, .5, .3);
\r
141 public Slider(string l, Interval r, double initialvalue)
\r
143 retval = initialvalue;
\r
147 Psychlops.Widgets.Connector.stackSlider(this);
\r
148 get_ = new SelfDelegate(get__);
\r
149 set_ = new SelfDelegate(set__);
\r
150 while (!setted_) { System.Threading.Thread.Sleep(10); }
\r
152 public static implicit operator double(Slider s)
\r
157 public delegate void SelfDelegate(System.Windows.Controls.Slider s);
\r
158 public void get__(System.Windows.Controls.Slider s) { retval = s.Value; }
\r
159 public void set__(System.Windows.Controls.Slider s) { s.Value = retval; }
\r
161 public double getValue()
\r
163 if (uislider != null) {
\r
164 uislider.Dispatcher.BeginInvoke(get_, uislider);
\r
170 public void setValue(double v)
\r
172 if (uislider != null)
\r
175 uislider.Dispatcher.BeginInvoke(set_, uislider);
\r
179 public double value
\r
181 get { return getValue(); }
\r
182 set { setValue(value); }
\r
184 public bool changed { get; set; }
\r
188 public class Browser
\r
190 public class Element
\r
193 System.Object retval;
\r
200 public static Element byID(string id_tag)
\r
202 return getElementById(id_tag);
\r
204 public static Element getElementById(string id_tag)
\r
206 Element tmp = new Element();
\r
207 Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidString(tmp.getElementById__), id_tag);
\r
210 void getElementById__(string id_tag)
\r
212 elem = HtmlPage.Document.GetElementById(id_tag);
\r
215 public void setProperty(string name, System.Object value)
\r
217 Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidStringObject(setProperty__), name, value);
\r
219 public void setProperty__(string name, System.Object value)
\r
221 elem.SetProperty(name, value);
\r
225 public static implicit operator double(Element i) { return i.getValueAsDouble(); }
\r
226 public double getValueAsDouble()
\r
229 getProperty("value");
\r
232 v = double.Parse(retval.ToString());
\r
234 catch (FormatException e)
\r
241 public static implicit operator string(Element i) { return i.getProperty("value").ToString(); }
\r
242 public System.Object getProperty(string name)
\r
244 Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidString(getProperty__), name);
\r
247 public void getProperty__(string name)
\r
249 retval = elem.GetProperty(name);
\r
255 internal static class Connector
\r
257 internal delegate void VoidString(string s);
\r
258 internal delegate void VoidStringObject(String s, System.Object o);
\r
262 delegate void StackSlider_(Slider s);
\r
263 internal static void stackSlider(Slider s)
\r
265 Internal.Main.widgetStack.Dispatcher.BeginInvoke(new StackSlider_(stackSlider__), s);
\r
267 static void stackSlider__(Slider ss)
\r
269 var label = new System.Windows.Controls.TextBlock { Text = ss.label };
\r
270 label.Foreground = Color.white;
\r
271 System.Windows.Controls.Canvas.SetLeft(label, 3);
\r
272 System.Windows.Controls.Canvas.SetTop(label, 3);
\r
273 ss.uilabel = label;
\r
275 var holder = new System.Windows.Controls.Canvas { Width = 200, Height = 50 };
\r
276 var val = new System.Windows.Controls.TextBox { Width = 100 };
\r
277 System.Windows.Controls.Canvas.SetLeft(val, 100);
\r
278 var slide = new System.Windows.Controls.Slider {
\r
279 Minimum = ss.range.begin.val, Maximum = ss.range.end.val,
\r
282 Tag = ss, Width = 200,
\r
284 System.Windows.Controls.Canvas.SetTop(slide, label.ActualHeight - 3);
\r
285 var b = new System.Windows.Data.Binding {
\r
286 Path = new PropertyPath("Value"),
\r
287 Mode = System.Windows.Data.BindingMode.TwoWay,
\r
290 val.SetBinding(TextBox.TextProperty, b);
\r
291 ss.uislider = slide;
\r
293 val.Background = Color.null_color;
\r
294 val.BorderBrush = Color.null_color;
\r
295 val.Foreground = Color.white;
\r
297 holder.Background = Slider.bgcolor;
\r
299 holder.Children.Add(label);
\r
300 holder.Children.Add(val);
\r
301 holder.Children.Add(slide);
\r
302 holder.Height = label.ActualHeight + slide.ActualHeight + val.ActualHeight + 15;
\r
303 ss.instance = holder;
\r
304 Internal.Main.widgetStack.Children.Add(ss.instance);
\r