Example #1
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 7, m_name);

            var widgetName = Utils.GetSafeString(args, 0);
            var widgetType = Utils.GetSafeString(args, 1).ToLower();
            var text       = Utils.GetSafeString(args, 2);
            var x          = Utils.GetSafeInt(args, 3);
            var y          = Utils.GetSafeInt(args, 4);
            var width      = Utils.GetSafeInt(args, 5);
            var height     = Utils.GetSafeInt(args, 6);
            var callback   = Utils.GetSafeString(args, 7);

            Control control = null;

            switch (widgetType)
            {
            case "button":
                var button = new Button();
                button.UseVisualStyleBackColor = true;
                control = button;
                break;

            case "checkbox":
                var checkbox = new CheckBox();
                control = checkbox;
                break;

            case "label":
                var label = new Label();
                control = label;
                break;

            case "textbox":
                var textBox = new TextBox();
                control = textBox;
                break;

            case "listview":
                var listView = new ListView();
                listView.View               = View.Details;
                listView.Bounds             = new Rectangle(new Point(x + 2, y + 2), new Size(width - 4, height - 4));
                listView.AllowColumnReorder = true;
                //listView.CheckBoxes = true;
                listView.FullRowSelect = true;
                listView.GridLines     = true;
                //listView.Sorting = SortOrder.Ascending;
                if (args[2].Type == Variable.VarType.ARRAY && args[2].Tuple.Count > 0)
                {
                    int colWidth = width / args[2].Tuple.Count - 1;
                    for (int i = 0; i < args[2].Tuple.Count; i++)
                    {
                        listView.Columns.Add(args[2].Tuple[i].AsString(), colWidth, HorizontalAlignment.Left);
                    }
                }
                else
                {
                    var dataItems = text.Split(',');
                    for (int i = 0; i < dataItems.Length; i++)
                    {
                        listView.Columns.Add(dataItems[i], -2, HorizontalAlignment.Left);
                    }
                }
                control = listView;
                break;
            }

            if (control == null)
            {
                return(Variable.EmptyInstance);
            }

            control.Location = new System.Drawing.Point(x, y);
            control.Text     = text;
            control.Size     = new System.Drawing.Size(width, height);

            CSCS_GUI.AddWidget(control, widgetName, callback);

            return(new Variable(true));
        }