Example #1
0
        private Atk.Object GetAccessible(BasicWidgetType type, string text, object preWidget, bool real, bool embeddedImage)
        {
            Atk.Object     accessible = null;
            Gtk.Widget     widget     = null;
            Gtk.Adjustment adj        = new Gtk.Adjustment(50, 0, 100, 1, 10, 20);
            switch (type)
            {
            case BasicWidgetType.Label:
                widget = new Gtk.Label();
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealLabel();
                }
                ((Gtk.Label)widget).Text = text;
                break;

            case BasicWidgetType.NormalButton:
                widget = new Gtk.Button();
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealButton(embeddedImage);
                }
                ((Gtk.Button)widget).Label = text;
                break;

            case BasicWidgetType.Window:
                widget = new Gtk.Window(text);
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealWindow();
                }
                break;

            case BasicWidgetType.CheckBox:
                widget = new Gtk.CheckButton();
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealCheckBox(embeddedImage);
                }
                ((Gtk.CheckButton)widget).Label = text;
                break;

            case BasicWidgetType.RadioButton:
                if (!real)
                {
                    throw new NotSupportedException("We cannot use non-real radio buttons because of some wierd behaviour");
                }

                widget = GailTestApp.MainClass.GiveMeARealRadioButton(embeddedImage);
                RunInGuiThread(delegate {
                    ((Gtk.CheckButton)widget).Label = text;
                });
                break;

            case BasicWidgetType.StatusBar:
                widget = new Gtk.Statusbar();
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealStatusbar();
                }
                ((Gtk.Statusbar)widget).Push(0, text);
                break;

            case BasicWidgetType.TextBoxEntry:
                if (!real)
                {
                    throw new NotSupportedException();
                }

                widget = GailTestApp.MainClass.GiveMeARealEntry(true);
                RunInGuiThread(delegate {
                    ((Gtk.Entry)widget).Text = text;
                });
                break;

            case BasicWidgetType.RichTextBox:
            case BasicWidgetType.TextBoxView:
                if (!real)
                {
                    throw new NotSupportedException();
                }

                widget = GailTestApp.MainClass.GiveMeARealTextView();
                RunInGuiThread(delegate {
                    ((Gtk.TextView)widget).Buffer.Text = text;
                });
                break;

            case BasicWidgetType.PasswordCharTextBoxEntry:
                if (!real)
                {
                    throw new NotSupportedException();
                }

                widget = GailTestApp.MainClass.GiveMeARealEntry(false);
                RunInGuiThread(delegate {
                    ((Gtk.Entry)widget).Text = text;
                });
                break;

            case BasicWidgetType.HScrollBar:
                widget = new Gtk.HScrollbar(adj);
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealHScrollbar();
                }
                break;

            case BasicWidgetType.VScrollBar:
                widget = new Gtk.VScrollbar(adj);
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealVScrollbar();
                }
                break;

            case BasicWidgetType.ProgressBar:
                widget = new Gtk.ProgressBar(adj);
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealProgressBar();
                }
                break;

            case BasicWidgetType.Spinner:
                widget = new Gtk.SpinButton(adj, 1, 2);
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealSpinButton();
                }
                break;

            case BasicWidgetType.PictureBox:
                widget = new Gtk.Image();
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealImage(embeddedImage);
                }
                break;

            case BasicWidgetType.ListView:
            case BasicWidgetType.TreeView:
                Gtk.TreeStore store       = null;
                List <string> columnNames = new List <String> ();
                XmlDocument   xml         = new XmlDocument();
                xml.LoadXml(text);
                foreach (XmlElement th in xml.GetElementsByTagName("th"))
                {
                    foreach (XmlElement td in th.GetElementsByTagName("td"))
                    {
                        columnNames.Add(td.InnerText);
                    }
                }
                if (columnNames.Count == 0)
                {
                    columnNames.Add(string.Empty);
                }
                if (columnNames.Count == 1)
                {
                    store = new Gtk.TreeStore(typeof(string));
                }
                else if (columnNames.Count == 2)
                {
                    store = new Gtk.TreeStore(typeof(string), typeof(string));
                }
                else if (columnNames.Count == 3)
                {
                    store = new Gtk.TreeStore(typeof(string), typeof(string), typeof(string));
                }
                else
                {
                    Assert.Fail("This test only supports 1-3 columns; got " + columnNames.Count);
                }
                Gtk.TreeIter[] iters = new Gtk.TreeIter [8];
                XmlElement     root  = xml.DocumentElement;
                for (XmlNode node = root.FirstChild; node != null; node = node.NextSibling)
                {
                    if (node.Name == "tr")
                    {
                        AddToTreeStore(store, iters, 0, node);
                    }
                }
                widget = new Gtk.TreeView(store);
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealTreeView();
                    RunInGuiThread(delegate {
                        ((Gtk.TreeView)widget).Model = store;
                    });
                }

                RunInGuiThread(delegate {
                    Gtk.TreeView treeView = (Gtk.TreeView)widget;
                    int i;
                    for (i = treeView.Columns.Length - 1; i >= 0; i--)
                    {
                        treeView.RemoveColumn(treeView.Columns [i]);
                    }
                    i = 0;
                    foreach (string columnName in columnNames)
                    {
                        Gtk.TreeViewColumn col = new Gtk.TreeViewColumn();
                        col.Title = columnName;
                        treeView.AppendColumn(col);
                        Gtk.CellRendererText cell = new Gtk.CellRendererText();
                        col.PackStart(cell, true);
                        col.AddAttribute(cell, "text", i++);
                    }
                    ((Gtk.TreeView)widget).HeadersClickable = text.Contains("<th>");
                    ((Gtk.TreeView)widget).HeadersVisible   = ((Gtk.TreeView)widget).HeadersClickable;
                });
                break;

            case BasicWidgetType.ContainerPanel:
                widget = new Gtk.Frame();
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealFrame();
                }
                break;

            case BasicWidgetType.HSplitContainer:
                widget = new Gtk.HPaned();
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealHPaned();
                }
                break;

            case BasicWidgetType.VTrackBar:
                widget = new Gtk.VScale(adj);
                if (real)
                {
                    widget = GailTestApp.MainClass.GiveMeARealVScale();
                }
                break;

            case BasicWidgetType.ComboBoxDropDownEntry:
            case BasicWidgetType.ComboBoxDropDownList:
            case BasicWidgetType.ComboBoxSimple:
                throw new NotSupportedException("You have to use the GetObject overload that receives a name array");

            default:
                throw new NotImplementedException("The widget finder backend still hasn't got support for " +
                                                  type.ToString());
            }

            accessible            = widget.Accessible;
            mappings [accessible] = widget;

            return(accessible);
        }