/// <summary>
        /// DeleteControl - Remove a control from the dialog
        /// </summary>
        /// <param name="control"></param>
        public void DeleteControl(FlexControl control)
        {
            controlPanel.Controls.RemoveByKey(control.Id);

            int top = _margin;

            foreach (Control formControl in controlPanel.Controls)
            {
                formControl.Top = top;
                top             = formControl.Bottom + _margin;
            }
        }
Exemple #2
0
        public IEnumerator <ITask> OnDeleteControl(DeleteControl delete)
        {
            FlexControl existing = _state.Controls.Find(delete.Body.CompareId);

            if (existing == null)
            {
                delete.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(
                        FaultCodes.Receiver,
                        DsspFaultCodes.UnknownEntry,
                        "A control with the requested ID does not exist: " + delete.Body.Id
                        )
                    );
            }
            else
            {
                Fault      fault  = null;
                FormInvoke invoke = new FormInvoke(
                    delegate
                {
                    _form.DeleteControl(delete.Body);
                }
                    );

                WinFormsServicePort.Post(invoke);
                yield return(Arbiter.Choice(
                                 invoke.ResultPort,
                                 EmptyHandler,
                                 delegate(Exception e)
                {
                    fault = Fault.FromException(e);
                }
                                 ));

                if (fault != null)
                {
                    delete.ResponsePort.Post(fault);
                }
                else
                {
                    _state.Controls.Remove(existing);
                    delete.ResponsePort.Post(DefaultDeleteResponseType.Instance);
                    DoSendNotification(delete);
                }
            }
        }
        void checkbox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox checkbox = sender as CheckBox;

            if (checkbox == null)
            {
                return;
            }

            FlexControl control = checkbox.Tag as FlexControl;

            if (control == null)
            {
                return;
            }

            control.Value = checkbox.Checked.ToString();
            _mainPort.Post(new UpdateControl(control));
        }
        void radio_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton radio = sender as RadioButton;

            if (radio == null)
            {
                return;
            }

            FlexControl control = radio.Tag as FlexControl;

            if (control == null)
            {
                return;
            }

            control.Value = radio.Checked.ToString();
            _mainPort.Post(new UpdateControl(control));
        }
        void textbox_TextChanged(object sender, EventArgs e)
        {
            Control formControl = sender as Control;

            if (formControl == null)
            {
                return;
            }

            FlexControl control = formControl.Tag as FlexControl;

            if (control == null)
            {
                return;
            }

            control.Value = formControl.Text;
            _mainPort.Post(new UpdateControl(control));
        }
        void combo_SelectedValueChanged(object sender, EventArgs e)
        {
            ComboBox combo = sender as ComboBox;

            if (combo == null)
            {
                return;
            }
            FlexControl control = combo.Tag as FlexControl;

            if (control == null)
            {
                return;
            }
            if (combo.SelectedIndex < 0)
            {
                control.Value = null;
            }
            else
            {
                control.Value = combo.Items[combo.SelectedIndex].ToString();
            }
            _mainPort.Post(new UpdateControl(control));
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="body"></param>
 public UpdateControl(FlexControl body)
     : base(body)
 {
     AddHeader(InternalUpdate.Instance);
 }
 /// <summary>
 /// CompareId - See if two controls are the same
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool CompareId(FlexControl other)
 {
     return(string.CompareOrdinal(_id, other._id) == 0);
 }
        /// <summary>
        /// UpdateControl - Replace the text on a control (depends on control type)
        /// </summary>
        /// <param name="control"></param>
        public void UpdateControl(FlexControl control)
        {
            Control[] controls = controlPanel.Controls.Find(control.Id, true);
            if (controls == null ||
                controls.Length != 1)
            {
                throw new ApplicationException("Could not find one control with the requested id: " + control.Id);
            }
            Control     formControl = controls[0];
            FlexControl previous    = formControl.Tag as FlexControl;

            if (previous == null)
            {
                throw new ApplicationException("Control does not have appropriate Tag");
            }

            if (previous.ControlType != control.ControlType)
            {
                throw new ApplicationException("Unable to convert control to a different type");
            }

            switch (control.ControlType)
            {
            case FlexControlType.Label:
                formControl.Text = control.Text;
                break;

            case FlexControlType.TextBox:
                formControl.Text = control.Value;
                break;

            case FlexControlType.MultiLineTextBox:
                formControl.Text = control.Value;
                break;

            case FlexControlType.Button:
                formControl.Text = control.Text;
                using (Graphics g = CreateGraphics())
                {
                    SizeF size = g.MeasureString(control.Text, Font);
                    formControl.Width = System.Math.Max(
                        _buttonWidth,
                        (int)System.Math.Ceiling(size.Width) + 2 * _margin
                        );
                }
                break;

            case FlexControlType.CheckBox:
                formControl.Text = control.Text;
                CheckBox check = formControl as CheckBox;
                check.Checked = bool.Parse(control.Value);
                break;

            case FlexControlType.RadioButton:
                formControl.Text = control.Text;
                RadioButton radio = formControl as RadioButton;
                radio.Checked = bool.Parse(control.Value);
                break;

            case FlexControlType.ComboBox:
                string[] items = control.Text.Split('|');
                ComboBox combo = formControl as ComboBox;
                combo.Items.Clear();
                combo.Items.AddRange(items);
                if (string.IsNullOrEmpty(control.Value))
                {
                    combo.SelectedIndex = -1;
                }
                else
                {
                    combo.Text = control.Value;
                }
                int width = 0;
                using (Graphics g = CreateGraphics())
                {
                    foreach (string item in items)
                    {
                        SizeF size = g.MeasureString(item, Font);
                        width = System.Math.Max(width,
                                                (int)(System.Math.Ceiling(size.Width) + 4 * _margin)
                                                );
                    }
                }
                formControl.Width = width;
                break;

            default:
            case FlexControlType.Seperator:
                break;
            }

            formControl.Tag = control;
        }
        /// <summary>
        /// InsertControl - Add a new control to the dialog
        /// </summary>
        /// <param name="control"></param>
        public void InsertControl(FlexControl control)
        {
            Control      formControl = null;
            int          height      = _buttonHeight;
            int          width       = controlPanel.ClientSize.Width - _margin * 2;
            int          top;
            AnchorStyles anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;

            if (controlPanel.Controls.Count > 0)
            {
                top = controlPanel.Controls[controlPanel.Controls.Count - 1].Bottom + _margin;
            }
            else
            {
                top = _margin;
            }

            switch (control.ControlType)
            {
            case FlexControlType.Label:
                formControl      = new Label();
                formControl.Text = control.Text;
                using (Graphics g = CreateGraphics())
                {
                    SizeF size = g.MeasureString(control.Text, Font);
                    height = (int)System.Math.Ceiling(size.Height);
                }
                break;

            case FlexControlType.TextBox:
                TextBox textbox = new TextBox();
                textbox.Multiline    = false;
                textbox.Text         = control.Value;
                textbox.TextChanged += textbox_TextChanged;
                formControl          = textbox;
                break;

            case FlexControlType.MultiLineTextBox:
                TextBox multi = new TextBox();
                multi.Multiline     = true;
                multi.ScrollBars    = ScrollBars.Vertical;
                multi.AcceptsReturn = true;
                multi.Text          = control.Value;
                multi.TextChanged  += textbox_TextChanged;
                formControl         = multi;
                height *= 5;
                break;

            case FlexControlType.Button:
                Button button = new Button();
                button.MouseDown += formButton_MouseDown;
                button.MouseUp   += formButton_MouseUp;
                button.Text       = control.Text;
                width             = 75;
                using (Graphics g = CreateGraphics())
                {
                    SizeF size = g.MeasureString(button.Text, Font);
                    if (size.Width + 2 * _margin > width)
                    {
                        width = (int)(size.Width + 2 * _margin);
                    }
                }
                anchor      = AnchorStyles.Top | AnchorStyles.Left;
                formControl = button;
                break;

            case FlexControlType.CheckBox:
                CheckBox checkbox = new CheckBox();
                checkbox.Text            = control.Text;
                checkbox.Checked         = bool.Parse(control.Value);
                checkbox.CheckedChanged += checkbox_CheckedChanged;
                formControl              = checkbox;
                break;

            case FlexControlType.RadioButton:
                RadioButton radio = new RadioButton();
                radio.Text            = control.Text;
                radio.Checked         = bool.Parse(control.Value);
                radio.CheckedChanged += radio_CheckedChanged;
                formControl           = radio;
                break;

            case FlexControlType.ComboBox:
                ComboBox combo = new ComboBox();
                combo.DropDownStyle = ComboBoxStyle.DropDownList;
                string[] items = control.Text.Split('|');
                combo.MaxDropDownItems = items.Length;
                combo.Items.AddRange(items);
                if (!string.IsNullOrEmpty(control.Value))
                {
                    combo.Text = control.Value;
                }
                combo.SelectedValueChanged += combo_SelectedValueChanged;
                width = 0;
                using (Graphics g = CreateGraphics())
                {
                    foreach (string item in items)
                    {
                        SizeF size = g.MeasureString(item, Font);
                        width = System.Math.Max(width,
                                                (int)(System.Math.Ceiling(size.Width) + 4 * _margin)
                                                );
                    }
                }
                anchor      = AnchorStyles.Top | AnchorStyles.Left;
                formControl = combo;
                break;

            default:
            case FlexControlType.Seperator:
                Label label = new Label();
                label.BorderStyle = BorderStyle.Fixed3D;
                height            = 2;
                formControl       = label;
                break;
            }
            formControl.Name     = control.Id;
            formControl.Location = new Point(_margin, top);
            formControl.Size     = new Size(width, height);
            formControl.Anchor   = anchor;
            formControl.Tag      = control;

            controlPanel.Controls.Add(formControl);
        }
Exemple #11
0
        public IEnumerator <ITask> OnHttpPost(HttpPost post)
        {
            Fault fault = null;

            NameValueCollection parameters = null;

            ReadFormData readForm = new ReadFormData(post);

            _utilities.Post(readForm);
            yield return(Arbiter.Choice(
                             readForm.ResultPort,
                             delegate(NameValueCollection success)
            {
                parameters = success;
            },
                             delegate(Exception e)
            {
                fault = Fault.FromException(e);
            }
                             ));

            string operation = parameters["Operation"];

            if (operation == "UpdateControl")
            {
                UpdateControl message = new UpdateControl();
                FlexControl   update  = message.Body;
                update.Id    = parameters["ID"];
                update.Value = parameters["Value"];
                update.Text  = parameters["Text"];

                FlexControl control = _state.Controls.Find(update.CompareId);

                if (control == null)
                {
                    post.ResponsePort.Post(Fault.FromCodeSubcodeReason(
                                               FaultCodes.Receiver,
                                               DsspFaultCodes.UnknownEntry,
                                               "Cannot find control with ID: " + update.Id
                                               ));
                    yield break;
                }
                update.ControlType = control.ControlType;

                yield return(Arbiter.ExecuteToCompletion(
                                 TaskQueue,
                                 new IterativeTask <UpdateControl>(message, OnUpdateControl)
                                 ));

                post.ResponsePort.Post(new HttpResponseType(DefaultUpdateResponseType.Instance));
            }
            else if (operation == "ButtonPress")
            {
                ButtonPress        message = new ButtonPress();
                ButtonPressRequest request = message.Body;
                request.Id      = parameters["ID"];
                request.Pressed = bool.Parse(parameters["Pressed"]);

                OnButtonPress(message);

                post.ResponsePort.Post(new HttpResponseType(DefaultUpdateResponseType.Instance));
            }
            else
            {
                fault = Fault.FromCodeSubcodeReason(
                    FaultCodes.Receiver,
                    DsspFaultCodes.MessageNotSupported,
                    "Unknown operation: " + operation
                    );
            }

            if (fault != null)
            {
                post.ResponsePort.Post(fault);
                yield break;
            }
        }