7
internal class WidgetTreeCombo: Button
11
Stetic.Wrapper.Widget rootWidget;
12
Stetic.IProject project;
13
Stetic.Wrapper.Widget selection;
14
WidgetTreePopup popup;
16
public WidgetTreeCombo ()
19
image = new Gtk.Image ();
21
HBox bb = new HBox ();
22
bb.PackStart (image, false, false, 3);
23
bb.PackStart (label, true, true, 3);
25
label.HeightRequest = 18;
26
bb.PackStart (new VSeparator (), false, false, 1);
27
bb.PackStart (new Arrow (ArrowType.Down, ShadowType.None), false, false, 1);
29
this.WidthRequest = 300;
33
public override void Dispose ()
41
public Stetic.Wrapper.Widget RootWidget {
42
get { return rootWidget; }
45
Sensitive = rootWidget != null;
46
if (rootWidget != null)
47
project = rootWidget.Project;
52
public void SetSelection (Stetic.Wrapper.Widget widget)
60
if (selection != null) {
61
label.Text = selection.Wrapped.Name;
62
image.Pixbuf = selection.ClassDescriptor.Icon.ScaleSimple (16, 16, Gdk.InterpType.Bilinear);
70
protected override void OnPressed ()
74
popup = new WidgetTreePopup (project);
75
popup.WidgetActivated += OnPopupActivated;
76
popup.SetDefaultSize (Allocation.Width, 500);
78
else if (popup.Visible) {
84
ParentWindow.GetOrigin (out x, out y);
86
y += Allocation.Y + Allocation.Height;
88
popup.Fill (RootWidget.Wrapped);
93
protected override bool OnFocusOutEvent (Gdk.EventFocus evnt)
97
return base.OnFocusOutEvent (evnt);
101
void OnPopupActivated (object s, EventArgs a)
104
Stetic.Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup (popup.Selection);
105
GLib.Timeout.Add (10, delegate {
112
class WidgetTreePopup: Window
116
Gtk.Widget selection;
117
Stetic.IProject project;
119
public event EventHandler WidgetActivated;
121
public WidgetTreePopup (Stetic.IProject project): base (WindowType.Popup)
123
this.project = project;
124
Gtk.Frame frame = new Frame ();
125
frame.ShadowType = Gtk.ShadowType.Out;
128
Gtk.ScrolledWindow sc = new ScrolledWindow ();
129
sc.VscrollbarPolicy = PolicyType.Automatic;
130
sc.HscrollbarPolicy = PolicyType.Automatic;
133
tree = new TreeView ();
134
store = new TreeStore (typeof(Gdk.Pixbuf), typeof(string), typeof(Widget));
136
tree.HeadersVisible = false;
138
TreeViewColumn col = new TreeViewColumn ();
139
CellRendererPixbuf cr = new CellRendererPixbuf ();
140
col.PackStart (cr, false);
141
col.AddAttribute (cr, "pixbuf", 0);
143
CellRendererText tr = new CellRendererText ();
144
col.PackStart (tr, true);
145
col.AddAttribute (tr, "markup", 1);
147
tree.AppendColumn (col);
149
tree.ButtonReleaseEvent += OnButtonRelease;
150
tree.RowActivated += OnButtonRelease;
156
public void Fill (Gtk.Widget widget)
159
Fill (TreeIter.Zero, widget);
162
public void Fill (TreeIter iter, Gtk.Widget widget)
164
Stetic.Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup (widget);
165
if (wrapper == null) return;
167
if (!wrapper.Unselectable) {
169
Gdk.Pixbuf icon = wrapper.ClassDescriptor.Icon.ScaleSimple (16, 16, Gdk.InterpType.Bilinear);
171
if (widget == project.Selection)
172
txt = "<b>" + GLib.Markup.EscapeText (widget.Name) + "</b>";
174
txt = GLib.Markup.EscapeText (widget.Name);
176
if (!iter.Equals (TreeIter.Zero))
177
iter = store.AppendValues (iter, icon, txt, widget);
179
iter = store.AppendValues (icon, txt, widget);
182
Gtk.Container cc = widget as Gtk.Container;
183
if (cc != null && wrapper.ClassDescriptor.AllowChildren) {
184
foreach (Gtk.Widget child in cc.Children)
187
if (widget == project.Selection) {
188
tree.ExpandToPath (store.GetPath (iter));
189
tree.ExpandRow (store.GetPath (iter), false);
190
tree.Selection.SelectIter (iter);
194
public Gtk.Widget Selection {
195
get { return selection; }
198
void OnButtonRelease (object s, EventArgs a)
203
void NotifyActivated ()
206
if (!tree.Selection.GetSelected (out iter))
208
selection = (Gtk.Widget) store.GetValue (iter, 2);
209
if (WidgetActivated != null)
210
WidgetActivated (this, EventArgs.Empty);