Example #1
0
        public ValueReferenceEditor(Project p, ValueReferenceGroup vrg, int rows, string frameText=null)
            : base(1.0F,1.0F,1.0F,1.0F)
        {
            Project = p;

            valueReferenceGroup = vrg;
            maxBounds = new int[valueReferenceGroup.GetNumValueReferences()];
            widgetPositions = new Tuple<uint,uint>[maxBounds.Count];
            widgets = new Gtk.Widget[maxBounds.Count];

            table = new Gtk.Table(2, 2, false);
            uint x=0,y=0;

            int cnt=0;
            foreach (ValueReference r in valueReferenceGroup.GetValueReferences()) {
                int index = cnt;
                cnt++;

                if (y >= rows) {
                    y = 0;
                    x += 3;
                }

                widgetPositions[index] = new Tuple<uint,uint>(x,y);

                if (r.ConstantsMapping != null) {
                    ComboBoxFromConstants comboBox = new ComboBoxFromConstants();
                    comboBox.SetConstantsMapping(r.ConstantsMapping);

                    comboBox.Changed += delegate(object sender, EventArgs e) {
                        r.SetValue(comboBox.ActiveValue);
                    };

                    dataModifiedExternalEvent += delegate() {
                        comboBox.ActiveValue = r.GetIntValue();
                    };

                    table.Attach(new Gtk.Label(r.Name), x+0,x+1,y,y+1);
                    table.Attach(comboBox, x+1,x+2,y,y+1);
                    widgets[index] = comboBox;

                    goto loopEnd;
                }
                // ConstantsMapping == null

                switch(r.ValueType) {
                    case DataValueType.String:
                    default:
                        {
                            table.Attach(new Gtk.Label(r.Name), x+0,x+1, y, y+1);
                            Gtk.Entry entry = new Gtk.Entry();
                            if (!r.Editable)
                                entry.Sensitive = false;
                            dataModifiedExternalEvent += delegate() {
                                entry.Text = r.GetStringValue();
                                OnDataModifiedInternal();
                            };
                            table.Attach(entry, x+1,x+2, y, y+1);
                            widgets[index] = entry;
                            break;
                        }
                    case DataValueType.Byte:
                    case DataValueType.HalfByte:
            byteCase:
                        {
                            table.Attach(new Gtk.Label(r.Name), x+0,x+1, y, y+1);
                            SpinButtonHexadecimal spinButton = new SpinButtonHexadecimal(0,255);
                            if (!r.Editable)
                                spinButton.Sensitive = false;
                            if (r.ValueType == DataValueType.HalfByte) {
                                spinButton.Digits = 1;
                                spinButton.Adjustment.Upper = 15;
                            }
                            else
                                spinButton.Digits = 2;
                            spinButton.ValueChanged += delegate(object sender, EventArgs e) {
                                Gtk.SpinButton button = sender as Gtk.SpinButton;
                                if (maxBounds[index] == 0 || button.ValueAsInt <= maxBounds[index]) {
                                    r.SetValue(button.ValueAsInt);
                                }
                                else
                                    button.Value = maxBounds[index];
                                OnDataModifiedInternal();
                            };
                            dataModifiedExternalEvent += delegate() {
                                spinButton.Value = r.GetIntValue();
                            };
                            table.Attach(spinButton, x+1,x+2, y, y+1);
                            widgets[index] = spinButton;
                        }
                        break;

                    case DataValueType.WarpDestIndex:
                        {
                            Gtk.Button newDestButton = new Gtk.Button("New\nDestination");
                            newDestButton.Clicked += delegate(object sender, EventArgs e) {
                                WarpSourceData warpData = (WarpSourceData)r.Data;
                                WarpDestGroup destGroup = warpData.GetReferencedDestGroup();
                                // Check if there's unused destination data
                                // already
                                for (int i=0; i<destGroup.GetNumWarpDests(); i++) {
                                    WarpDestData destData = destGroup.GetWarpDest(i);
                                    if (destData.GetNumReferences() == 0) {
                                        Gtk.MessageDialog d = new Gtk.MessageDialog(null,
                                                Gtk.DialogFlags.DestroyWithParent,
                                                Gtk.MessageType.Warning,
                                                Gtk.ButtonsType.YesNo,
                                                "Destination index " + i.ToString("X2") + " is not used by any sources. Use this index?\n\n(\"No\" will create a new destination instead.)");
                                        Gtk.ResponseType response = (Gtk.ResponseType)d.Run();
                                        d.Destroy();

                                        if (response == Gtk.ResponseType.Yes)
                                            warpData.SetDestData(destGroup.GetWarpDest(i));
                                        else if (response == Gtk.ResponseType.No)
                                            warpData.SetDestData(destGroup.AddDestData());
                                        break;
                                    }
                                }
                            };
                            table.Attach(newDestButton, x+2,x+3, y, y+2);
                        }
                        goto byteCase;

                    case DataValueType.Word:
                        {
                            table.Attach(new Gtk.Label(r.Name), x+0,x+1, y, y+1);
                            SpinButtonHexadecimal spinButton = new SpinButtonHexadecimal(0,0xffff);
                            if (!r.Editable)
                                spinButton.Sensitive = false;
                            spinButton.Digits = 4;
                            spinButton.ValueChanged += delegate(object sender, EventArgs e) {
                                Gtk.SpinButton button = sender as Gtk.SpinButton;
                                if (maxBounds[index] == 0 || button.ValueAsInt <= maxBounds[index]) {
                                    r.SetValue(button.ValueAsInt);
                                }
                                else
                                    button.Value = maxBounds[index];
                                OnDataModifiedInternal();
                            };
                            dataModifiedExternalEvent += delegate() {
                                spinButton.Value = r.GetIntValue();
                            };
                            table.Attach(spinButton, x+1,x+2, y, y+1);
                            widgets[index] = spinButton;
                        }
                        break;
                    case DataValueType.ByteBit:
                        {
                            table.Attach(new Gtk.Label(r.Name), x+0,x+1, y, y+1);
                            Gtk.CheckButton checkButton = new Gtk.CheckButton();
                            checkButton.CanFocus = false;
                            if (!r.Editable)
                                checkButton.Sensitive = false;
                            checkButton.Toggled += delegate(object sender, EventArgs e) {
                                Gtk.CheckButton button = sender as Gtk.CheckButton;
                                r.SetValue(button.Active ? 1 : 0);
                                OnDataModifiedInternal();
                            };
                            dataModifiedExternalEvent += delegate() {
                                checkButton.Active = r.GetIntValue() == 1;
                            };
                            table.Attach(checkButton, x+1,x+2, y, y+1);
                            widgets[index] = checkButton;
                        }
                        break;
                    case DataValueType.ByteBits:
                        {
                            table.Attach(new Gtk.Label(r.Name), x+0,x+1, y, y+1);
                            SpinButtonHexadecimal spinButton = new SpinButtonHexadecimal(0,r.MaxValue);
                            if (!r.Editable)
                                spinButton.Sensitive = false;
                            spinButton.Digits = (uint)((r.MaxValue+0xf)/0x10);
                            spinButton.ValueChanged += delegate(object sender, EventArgs e) {
                                Gtk.SpinButton button = sender as Gtk.SpinButton;
                                if (maxBounds[index] == 0 || button.ValueAsInt <= maxBounds[index]) {
                                    r.SetValue(button.ValueAsInt);
                                }
                                else
                                    button.Value = maxBounds[index];
                                OnDataModifiedInternal();
                            };
                            dataModifiedExternalEvent += delegate() {
                                spinButton.Value = r.GetIntValue();
                            };
                            table.Attach(spinButton, x+1,x+2, y, y+1);
                            widgets[index] = spinButton;
                        }
                        break;
                    case DataValueType.ObjectPointer:
                        {
                            table.Attach(new Gtk.Label(r.Name), x+0,x+1, y, y+1);

                            Gtk.Entry entry = new Gtk.Entry();
                            if (!r.Editable)
                                entry.Sensitive = false;
                            entry.Changed += delegate(object sender, EventArgs e) {
                                UpdatePointerTextBox(sender as Gtk.Entry, r);
                                OnDataModifiedInternal();
                            };
                            table.Attach(entry, x+1,x+2, y, y+1);
                            widgets[index] = entry;

                            pointerFrame = new Gtk.Frame();
                            pointerFrame.Label = "Pointer data (possibly shared)";
                            pointerFrame.BorderWidth = 5;

                            y++;
                            table.Attach(pointerFrame, x+0,x+2, y, y+1);

                            dataModifiedExternalEvent += delegate() {
                                entry.Text = r.GetStringValue();
                                UpdatePointerTextBox(entry, r);
                            };
                        }
                        break;
                }

            loopEnd:
                y++;
            }

            table.ColumnSpacing = 6;

            if (frameText != null) {
                var frame = new Gtk.Frame(frameText);
                frame.Add(table);
                this.Add(frame);
            }
            else
                this.Add(table);

            this.ShowAll();

            Data lastData = null;
            foreach (ValueReference r in valueReferenceGroup.GetValueReferences()) {
                if (lastData != r.Data) {
                    lastData = r.Data;
                    r.Data.AddDataModifiedHandler(OnDataModifiedExternal);
                    // Destroy handler
                    this.Destroyed += delegate(object sender, EventArgs e) {
                        r.Data.RemoveDataModifiedHandler(OnDataModifiedExternal);
                    };
                }
            }

            // Initial values
            if (dataModifiedExternalEvent != null)
                dataModifiedExternalEvent();
        }
Example #2
0
        public ValueReferenceEditor(Project p, ValueReferenceGroup vrg, int rows, string frameText = null)
            : base(1.0F, 1.0F, 1.0F, 1.0F)
        {
            Project = p;

            valueReferenceGroup  = vrg;
            maxBounds            = new int[valueReferenceGroup.GetNumValueReferences()];
            widgetPositions      = new Tuple <uint, uint> [maxBounds.Count];
            widgets              = new Gtk.Widget[maxBounds.Count];
            helpButtonContainers = new Gtk.Container[maxBounds.Count];

            table = new Gtk.Table(2, 2, false);
            uint x = 0, y = 0;

            int cnt = 0;

            foreach (ValueReference r in valueReferenceGroup.GetValueReferences())
            {
                int index = cnt;
                cnt++;

                if (y >= rows)
                {
                    y  = 0;
                    x += 3;
                }

                widgetPositions[index] = new Tuple <uint, uint>(x, y);

                // If it has a ConstantsMapping, use a combobox instead of anything else
                if (r.ConstantsMapping != null)
                {
                    ComboBoxFromConstants comboBox = new ComboBoxFromConstants(false);
                    comboBox.SetConstantsMapping(r.ConstantsMapping);

                    comboBox.Changed += delegate(object sender, EventArgs e) {
                        r.SetValue(comboBox.ActiveValue);
                        OnDataModifiedInternal();
                    };

                    dataModifiedExternalEvent += delegate() {
                        comboBox.ActiveValue = r.GetIntValue();
                    };

                    table.Attach(new Gtk.Label(r.Name), x + 0, x + 1, y, y + 1);
                    table.Attach(comboBox, x + 1, x + 2, y, y + 1);
                    widgets[index] = comboBox;

                    helpButtonContainers[index] = new Gtk.HBox();
                    table.Attach(helpButtonContainers[index], x + 2, x + 3, y, y + 1, 0, Gtk.AttachOptions.Fill, 0, 0);

                    goto loopEnd;
                }
                // ConstantsMapping == null

                switch (r.ValueType)
                {
                case DataValueType.String:
                default:
                {
                    table.Attach(new Gtk.Label(r.Name), x + 0, x + 1, y, y + 1);
                    Gtk.Entry entry = new Gtk.Entry();
                    if (!r.Editable)
                    {
                        entry.Sensitive = false;
                    }
                    dataModifiedExternalEvent += delegate() {
                        entry.Text = r.GetStringValue();
                        OnDataModifiedInternal();
                    };
                    table.Attach(entry, x + 1, x + 2, y, y + 1);
                    widgets[index] = entry;

                    helpButtonContainers[index] = new Gtk.HBox();
                    table.Attach(helpButtonContainers[index], x + 2, x + 3, y, y + 1, 0, Gtk.AttachOptions.Fill, 0, 0);
                    break;
                }

                case DataValueType.Byte:
                case DataValueType.HalfByte:
byteCase:
                    {
                        table.Attach(new Gtk.Label(r.Name), x + 0, x + 1, y, y + 1);
                        SpinButtonHexadecimal spinButton = new SpinButtonHexadecimal(0, 255);
                        if (!r.Editable)
                        {
                            spinButton.Sensitive = false;
                        }
                        if (r.ValueType == DataValueType.HalfByte)
                        {
                            spinButton.Digits           = 1;
                            spinButton.Adjustment.Upper = 15;
                        }
                        else
                        {
                            spinButton.Digits = 2;
                        }
                        spinButton.ValueChanged += delegate(object sender, EventArgs e) {
                            Gtk.SpinButton button = sender as Gtk.SpinButton;
                            if (maxBounds[index] == 0 || button.ValueAsInt <= maxBounds[index])
                            {
                                r.SetValue(button.ValueAsInt);
                            }
                            else
                            {
                                button.Value = maxBounds[index];
                            }
                            OnDataModifiedInternal();
                        };
                        dataModifiedExternalEvent += delegate() {
                            spinButton.Value = r.GetIntValue();
                        };
                        table.Attach(spinButton, x + 1, x + 2, y, y + 1);
                        widgets[index] = spinButton;

                        helpButtonContainers[index] = new Gtk.HBox();
                        table.Attach(helpButtonContainers[index], x + 2, x + 3, y, y + 1, 0, Gtk.AttachOptions.Fill, 0, 0);
                    }
                    break;

                case DataValueType.WarpDestIndex:
                {
                    Gtk.Button newDestButton = new Gtk.Button("New\nDestination");
                    newDestButton.Clicked += delegate(object sender, EventArgs e) {
                        WarpSourceData warpData  = (WarpSourceData)r.Data;
                        WarpDestGroup  destGroup = warpData.GetReferencedDestGroup();
                        // Check if there's unused destination data
                        // already
                        for (int i = 0; i < destGroup.GetNumWarpDests(); i++)
                        {
                            WarpDestData destData = destGroup.GetWarpDest(i);
                            if (destData.GetNumReferences() == 0)
                            {
                                Gtk.MessageDialog d = new Gtk.MessageDialog(null,
                                                                            Gtk.DialogFlags.DestroyWithParent,
                                                                            Gtk.MessageType.Warning,
                                                                            Gtk.ButtonsType.YesNo,
                                                                            "Destination index " + i.ToString("X2") + " is not used by any sources. Use this index?\n\n(\"No\" will create a new destination instead.)");
                                Gtk.ResponseType response = (Gtk.ResponseType)d.Run();
                                d.Destroy();

                                if (response == Gtk.ResponseType.Yes)
                                {
                                    warpData.SetDestData(destGroup.GetWarpDest(i));
                                }
                                else if (response == Gtk.ResponseType.No)
                                {
                                    warpData.SetDestData(destGroup.AddDestData());
                                }
                                break;
                            }
                        }
                    };
                    table.Attach(newDestButton, x + 2, x + 3, y, y + 2);
                }
                    goto byteCase;

                case DataValueType.Word:
                {
                    table.Attach(new Gtk.Label(r.Name), x + 0, x + 1, y, y + 1);
                    SpinButtonHexadecimal spinButton = new SpinButtonHexadecimal(0, 0xffff);
                    if (!r.Editable)
                    {
                        spinButton.Sensitive = false;
                    }
                    spinButton.Digits        = 4;
                    spinButton.ValueChanged += delegate(object sender, EventArgs e) {
                        Gtk.SpinButton button = sender as Gtk.SpinButton;
                        if (maxBounds[index] == 0 || button.ValueAsInt <= maxBounds[index])
                        {
                            r.SetValue(button.ValueAsInt);
                        }
                        else
                        {
                            button.Value = maxBounds[index];
                        }
                        OnDataModifiedInternal();
                    };
                    dataModifiedExternalEvent += delegate() {
                        spinButton.Value = r.GetIntValue();
                    };
                    table.Attach(spinButton, x + 1, x + 2, y, y + 1);
                    widgets[index] = spinButton;

                    helpButtonContainers[index] = new Gtk.HBox();
                    table.Attach(helpButtonContainers[index], x + 2, x + 3, y, y + 1, 0, Gtk.AttachOptions.Fill, 0, 0);
                }
                break;

                case DataValueType.ByteBit:
                {
                    table.Attach(new Gtk.Label(r.Name), x + 0, x + 1, y, y + 1);
                    Gtk.CheckButton checkButton = new Gtk.CheckButton();
                    checkButton.CanFocus = false;
                    if (!r.Editable)
                    {
                        checkButton.Sensitive = false;
                    }
                    checkButton.Toggled += delegate(object sender, EventArgs e) {
                        Gtk.CheckButton button = sender as Gtk.CheckButton;
                        r.SetValue(button.Active ? 1 : 0);
                        OnDataModifiedInternal();
                    };
                    dataModifiedExternalEvent += delegate() {
                        checkButton.Active = r.GetIntValue() == 1;
                    };
                    table.Attach(checkButton, x + 1, x + 2, y, y + 1);
                    widgets[index] = checkButton;

                    helpButtonContainers[index] = new Gtk.HBox();
                    table.Attach(helpButtonContainers[index], x + 2, x + 3, y, y + 1, 0, Gtk.AttachOptions.Fill, 0, 0);
                }
                break;

                case DataValueType.ByteBits:
                case DataValueType.WordBits:
                {
                    table.Attach(new Gtk.Label(r.Name), x + 0, x + 1, y, y + 1);
                    SpinButtonHexadecimal spinButton = new SpinButtonHexadecimal(0, r.MaxValue);
                    if (!r.Editable)
                    {
                        spinButton.Sensitive = false;
                    }
                    spinButton.Digits        = (uint)Math.Pow(r.MaxValue, ((double)1) / 16) + 1;
                    spinButton.ValueChanged += delegate(object sender, EventArgs e) {
                        Gtk.SpinButton button = sender as Gtk.SpinButton;
                        if (maxBounds[index] == 0 || button.ValueAsInt <= maxBounds[index])
                        {
                            r.SetValue(button.ValueAsInt);
                        }
                        else
                        {
                            button.Value = maxBounds[index];
                        }
                        OnDataModifiedInternal();
                    };
                    dataModifiedExternalEvent += delegate() {
                        spinButton.Value = r.GetIntValue();
                    };
                    table.Attach(spinButton, x + 1, x + 2, y, y + 1);
                    widgets[index] = spinButton;

                    helpButtonContainers[index] = new Gtk.HBox();
                    table.Attach(helpButtonContainers[index], x + 2, x + 3, y, y + 1, 0, Gtk.AttachOptions.Fill, 0, 0);
                }
                break;

                case DataValueType.ObjectPointer:
                {
                    table.Attach(new Gtk.Label(r.Name), x + 0, x + 1, y, y + 1);

                    Gtk.Entry entry = new Gtk.Entry();
                    if (!r.Editable)
                    {
                        entry.Sensitive = false;
                    }
                    entry.Changed += delegate(object sender, EventArgs e) {
                        UpdatePointerTextBox(sender as Gtk.Entry, r);
                        OnDataModifiedInternal();
                    };
                    table.Attach(entry, x + 1, x + 2, y, y + 1);
                    widgets[index] = entry;

                    pointerFrame             = new Gtk.Frame();
                    pointerFrame.Label       = "Pointer data (possibly shared)";
                    pointerFrame.BorderWidth = 5;

                    y++;
                    table.Attach(pointerFrame, x + 0, x + 2, y, y + 1);

                    dataModifiedExternalEvent += delegate() {
                        entry.Text = r.GetStringValue();
                        UpdatePointerTextBox(entry, r);
                    };

                    helpButtonContainers[index] = new Gtk.HBox();
                    table.Attach(helpButtonContainers[index], x + 2, x + 3, y, y + 1, 0, Gtk.AttachOptions.Fill, 0, 0);
                }
                break;
                }

loopEnd:
                y++;
            }

            table.ColumnSpacing = 6;

            if (frameText != null)
            {
                var frame = new Gtk.Frame(frameText);
                frame.Add(table);
                this.Add(frame);
            }
            else
            {
                this.Add(table);
            }

            this.ShowAll();

            Data lastData = null;

            foreach (ValueReference r in valueReferenceGroup.GetValueReferences())
            {
                if (lastData != r.Data)
                {
                    lastData = r.Data;
                    r.Data.AddDataModifiedHandler(OnDataModifiedExternal);
                    // Destroy handler
                    this.Destroyed += delegate(object sender, EventArgs e) {
                        r.Data.RemoveDataModifiedHandler(OnDataModifiedExternal);
                    };
                }
            }

            // Initial values
            if (dataModifiedExternalEvent != null)
            {
                dataModifiedExternalEvent();
            }

            UpdateHelpButtons();
        }
Example #3
0
        public ValueReferenceEditor(Project p, ValueReferenceGroup vrg, int rows, string frameText = null)
            : base(1.0F, 1.0F, 1.0F, 1.0F)
        {
            Project = p;

            valueReferenceGroup = vrg;
            maxBounds           = new int[valueReferenceGroup.GetNumValueReferences()];
            widgetGrids         = new List <Gtk.Grid>();
            widgetPositions     = new Tuple <int, int> [maxBounds.Count];
            widgetLists         = new List <IList <Gtk.Widget> >();

            Gtk.Box hbox = new Gtk.HBox();
            hbox.Spacing = 6;

            Func <Gtk.Grid> newGrid = () => {
                Gtk.Grid g = new Gtk.Grid();
                g.ColumnSpacing = 6;
                g.RowSpacing    = 2;
                hbox.Add(g);
                return(g);
            };

            Gtk.Grid grid = newGrid();
            int      x = 0, y = 0;


            // Do not use "foreach" here. The "valueReferenceGroup" may be changed. So, whenever we
            // access a ValueReference from within an event handler, we must do so though the
            // "valueReferenceGroup" class variable, and NOT though an alias (like with foreach).
            for (int tmpCounter = 0; tmpCounter < valueReferenceGroup.Count; tmpCounter++)
            {
                int i = tmpCounter; // Variable must be distinct within each closure

                if (y >= rows)
                {
                    y    = 0;
                    x    = 0;
                    grid = newGrid();
                }

                // Each ValueReference may use up to 3 widgets in the grid row
                Gtk.Widget[] widgetList = new Gtk.Widget[3];

                widgetPositions[i] = new Tuple <int, int>(x, y);

                Action <Gtk.SpinButton> setSpinButtonLimits = (spinButton) => {
                    if (valueReferenceGroup[i].MaxValue < 0x10)
                    {
                        spinButton.Digits = 1;
                    }
                    else if (valueReferenceGroup[i].MaxValue < 0x100)
                    {
                        spinButton.Digits = 2;
                    }
                    else if (valueReferenceGroup[i].MaxValue < 0x1000)
                    {
                        spinButton.Digits = 3;
                    }
                    else
                    {
                        spinButton.Digits = 4;
                    }
                    spinButton.Adjustment.Lower = valueReferenceGroup[i].MinValue;
                    spinButton.Adjustment.Upper = valueReferenceGroup[i].MaxValue;
                };

                int entryWidgetWidth = 1;

                // If it has a ConstantsMapping, use a combobox instead of anything else
                if (valueReferenceGroup[i].ConstantsMapping != null)
                {
                    ComboBoxFromConstants comboBox = new ComboBoxFromConstants(showHelp: true, vertical: true);
                    comboBox.SetConstantsMapping(valueReferenceGroup[i].ConstantsMapping);

                    // Must put this before the "Changed" handler below to avoid
                    // it being fired (for some reason?)
                    setSpinButtonLimits(comboBox.SpinButton);

                    comboBox.Changed += delegate(object sender, EventArgs e) {
                        valueReferenceGroup[i].SetValue(comboBox.ActiveValue);
                        OnDataModifiedInternal();
                    };

                    dataModifiedExternalEvent += delegate() {
                        comboBox.ActiveValue = valueReferenceGroup[i].GetIntValue();
                    };

                    /*
                     * comboBox.MarginTop = 4;
                     * comboBox.MarginBottom = 4;
                     */

                    widgetList[0] = new Gtk.Label(valueReferenceGroup[i].Name);
                    widgetList[1] = comboBox;

                    entryWidgetWidth = 2;

                    goto loopEnd;
                }
                // ConstantsMapping == null

                switch (valueReferenceGroup[i].ValueType)
                {
                case ValueReferenceType.String:
                {
                    widgetList[0] = new Gtk.Label(valueReferenceGroup[i].Name);

                    Gtk.Entry entry = new Gtk.Entry();
                    if (!valueReferenceGroup[i].Editable)
                    {
                        entry.Sensitive = false;
                    }
                    dataModifiedExternalEvent += delegate() {
                        entry.Text = valueReferenceGroup[i].GetStringValue();
                        OnDataModifiedInternal();
                    };

                    widgetList[1] = entry;
                    break;
                }

                case ValueReferenceType.Int:
                {
                    widgetList[0] = new Gtk.Label(valueReferenceGroup[i].Name);

                    SpinButtonHexadecimal spinButton =
                        new SpinButtonHexadecimal(valueReferenceGroup[i].MinValue, valueReferenceGroup[i].MaxValue);
                    if (!valueReferenceGroup[i].Editable)
                    {
                        spinButton.Sensitive = false;
                    }
                    setSpinButtonLimits(spinButton);
                    spinButton.ValueChanged += delegate(object sender, EventArgs e) {
                        Gtk.SpinButton button = sender as Gtk.SpinButton;
                        if (maxBounds[i] == 0 || button.ValueAsInt <= maxBounds[i])
                        {
                            valueReferenceGroup[i].SetValue(button.ValueAsInt);
                        }
                        else
                        {
                            button.Value = maxBounds[i];
                        }
                        OnDataModifiedInternal();
                    };
                    dataModifiedExternalEvent += delegate() {
                        spinButton.Value = valueReferenceGroup[i].GetIntValue();
                    };

                    widgetList[1] = spinButton;
                }
                break;

                case ValueReferenceType.Bool:
                {
                    widgetList[0] = new Gtk.Label(valueReferenceGroup[i].Name);

                    Gtk.CheckButton checkButton = new Gtk.CheckButton();
                    checkButton.FocusOnClick = false;
                    if (!valueReferenceGroup[i].Editable)
                    {
                        checkButton.Sensitive = false;
                    }
                    checkButton.Toggled += delegate(object sender, EventArgs e) {
                        Gtk.CheckButton button = sender as Gtk.CheckButton;
                        valueReferenceGroup[i].SetValue(button.Active ? 1 : 0);
                        OnDataModifiedInternal();
                    };
                    dataModifiedExternalEvent += delegate() {
                        checkButton.Active = valueReferenceGroup[i].GetIntValue() == 1;
                    };

                    widgetList[1] = checkButton;
                }
                break;
                }

loopEnd:
                grid.Attach(widgetList[0], x, y, 1, 1);
                grid.Attach(widgetList[1], x + 1, y, entryWidgetWidth, 1);

                widgetList[2]         = new Gtk.Alignment(0, 0.5f, 0, 0); // Container for help button
                widgetList[2].Hexpand = true;                             // Let this absorb any extra space
                grid.Attach(widgetList[2], x + 2, y, 1, 1);

                widgetGrids.Add(grid);
                widgetLists.Add(widgetList);

                if (valueReferenceGroup[i].Tooltip != null)
                {
                    SetTooltip(i, valueReferenceGroup[i].Tooltip);
                }
                y++;
            }

            if (frameText != null)
            {
                var frame = new Gtk.Frame(frameText);
                frame.Add(hbox);
                this.Add(frame);
            }
            else
            {
                this.Add(hbox);
            }

            this.ShowAll();

            // Initial values
            if (dataModifiedExternalEvent != null)
            {
                dataModifiedExternalEvent();
            }

            UpdateHelpButtons();

            AddModifiedHandlers();
            this.Destroyed += (sender, args) => RemoveModifiedHandlers();
        }