public void PasteControlsFromClipboard(Container where)
        {
            if (CanPasteFromClipboard())
            {
                var box = Clipboard.GetDataObject().GetData(CLIPBOARD_PLAYERCONTROLS_FORMAT) as Collection <SerializationHelper.SerializablePlayerControl>;
                if (box == null)
                {
                    return;
                }

                var added = new Collection <SkinnableControl>();
                foreach (var clipb in box)
                {
                    System.Xml.XmlDocument copy_xml = clipb.XmlDocument;
                    Dictionary <string, System.IO.MemoryStream> copy_resources = clipb.Resources;

                    var controlElement = copy_xml.ChildNodes[1];

                    SkinnableControls.SkinnableControl copy = SerializationHelper.GetPlayerControlInstanceFromTagName(controlElement.Name);
                    copy.ParentView = this;
                    copy.FromXmlElement((System.Xml.XmlElement)controlElement, copy_resources);

                    copy.Parent   = where;
                    copy.Location = new PointF(copy.Location.X + 15, copy.Location.Y + 15);

                    added.Add(copy);
                }

                this.SelectMultiple(added);
                if (DesignerControlsTreeChanged != null)
                {
                    DesignerControlsTreeChanged(this, new EventArgs());
                }
            }
        }
Example #2
0
        public override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            if (lastEnterControl != null)
            {
                lastEnterControl.OnMouseLeave(new EventArgs());
                lastEnterControl = null;
            }
        }
Example #3
0
        public static SkinnableControls.SkinnableControl GetPlayerControlInstanceFromTagName(String tag)
        {
            var ctype = (SkinnableControls.SkinnableControl.SemanticType)Enum.Parse(typeof(SkinnableControls.SkinnableControl.SemanticType), tag);

            SkinnableControls.SkinnableControl.SemanticTypeMeta info =
                SkinnableControls.SkinnableControl.GetPlayerControlInstanceInfo(ctype);

            SkinnableControls.SkinnableControl c = (SkinnableControls.SkinnableControl)Activator.CreateInstance(info.InstanceType, new object[] { ctype });
            return(c);
        }
Example #4
0
 protected void OnControlAdded(SkinnableControl c)
 {
     c.ParentView = this.ParentView;
     c.Parent     = this;
     this.Invalidate();
     if (ControlAdded != null)
     {
         ControlAdded(this, new SkinnableControlEventArgs(c));
     }
 }
Example #5
0
        public override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            SkinnableControl ctl = controls.FirstOrDefault(c => c.Capture);

            if (ctl == null)
            {
                ctl = controls.FirstOrDefault(c => c.HitTest(e.Location));
            }

            if (ctl == null)
            {
                // Gestione click
                if (!this.suppressNextClick)
                {
                    var capture = this.Capture;
                    var hit     = this.IsInside(e.Location);

                    if (e.Button == MouseButtons.Left && capture && hit)
                    {
                        this.OnClick(new EventArgs());
                    }
                }
            }
            else
            {
                var capture = ctl.Capture;
                var hit     = ctl.HitTest(e.Location);

                // Gestione click
                if (e.Button == MouseButtons.Left && capture && hit && !this.suppressNextClick)
                {
                    ctl.OnClick(new EventArgs());
                }

                MouseEventArgs e2 = new MouseEventArgs(e.Button, e.Clicks, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta);
                ctl.OnMouseUp(e2);

                if (capture && !hit)
                {
                    // Il capturing è finito e ora ci ritroviamo su un controllo diverso... lanciamo
                    // gli eventi MouseLeave / MouseEnter
                    ctl.OnMouseLeave(new EventArgs());
                    SkinnableControl enterctl = controls.FirstOrDefault(c => c.HitTest(e.Location));
                    if (enterctl != null)
                    {
                        lastEnterControl = enterctl;
                        enterctl.OnMouseEnter(new EventArgs());
                    }
                }
            }

            this.suppressNextClick = false;
        }
Example #6
0
        public override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            SkinnableControl ctl = controls.FirstOrDefault(c => c.HitTest(e.Location));

            if (ctl != null)
            {
                MouseEventArgs e2 = new MouseEventArgs(e.Button, e.Clicks, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta);
                ctl.OnMouseWheel(e2);
            }
        }
Example #7
0
 protected virtual void OnControlRemoved(SkinnableControl c)
 {
     c.ParentView = null;
     c.Parent     = null;
     if (lastEnterControl == c)
     {
         lastEnterControl = null;
     }
     this.Invalidate();
     if (ControlAdded != null)
     {
         ControlRemoved(this, new SkinnableControlEventArgs(c));
     }
 }
Example #8
0
        /// <summary>
        /// Restituisce il prossimo (o precedente) controllo secondo le proprietà TabOrder e TabStop.
        /// Dopo aver raggiunto l'ultimo controllo restituisce null.
        /// </summary>
        /// <param name="ctl">Controllo da cui iniziare la ricerca. Se è null, parte dall'inizio (o dalla fine).</param>
        /// <param name="forward"></param>
        /// <returns></returns>
        public SkinnableControl GetNextControl(SkinnableControl ctl, bool forward)
        {
            IEnumerable <SkinnableControl> ctrls;

            if (ctl == null)
            {
                if (forward)
                {
                    ctrls = from c in this.controls
                            where (c.TabStop == true || c is Container)
                            orderby c.TabIndex, c.Top, c.Left
                    select c;
                }
                else
                {
                    ctrls = from c in this.controls
                            where (c.TabStop == true || c is Container)
                            orderby c.TabIndex descending, c.Top descending, c.Left descending
                    select c;
                }
            }
            else
            {
                if (forward)
                {
                    ctrls = from c in this.controls
                            where (c.TabStop == true || c is Container) &&
                            c.TabIndex >= ctl.TabIndex &&
                            (c.TabIndex == ctl.TabIndex ?
                             (c.Top != ctl.Top ? c.Top > ctl.Top : c.Left > ctl.Left)
                            : true)
                            orderby c.TabIndex, c.Top, c.Left
                    select c;
                }
                else
                {
                    ctrls = from c in this.controls
                            where (c.TabStop == true || c is Container) &&
                            c.TabIndex <= ctl.TabIndex &&
                            (c.TabIndex == ctl.TabIndex ?
                             (c.Top != ctl.Top ? c.Top < ctl.Top : c.Left < ctl.Left)
                            : true)
                            orderby c.TabIndex descending, c.Top descending, c.Left descending
                    select c;
                }
            }

            return(ctrls.FirstOrDefault(c => c != ctl));
        }
Example #9
0
        /// <summary>
        /// Sposta ricorsivamente il focus al controllo successivo (o precedente).
        /// Restituisce false se i controlli sono finiti, altrimenti true.
        /// </summary>
        /// <param name="forward"></param>
        /// <returns></returns>
        public bool DoTab(bool forward, bool showTabFocus)
        {
            if (this.FocusedControl is Container)
            {
                Container container = (Container)this.FocusedControl;
                bool      finished  = !container.DoTab(forward, showTabFocus);
                if (!finished)
                {
                    return(true);
                }
            }

            SkinnableControl ctl = GetNextControl(this.FocusedControl, forward);

            if (this.focusedControl != null)
            {
                this.focusedControl.IsShowingFocusRect = false;
            }
            if (ctl != null)
            {
                ctl.IsShowingFocusRect = showTabFocus;
            }
            this.FocusedControl = ctl;

            if (ctl == null)
            {
                return(false);
            }
            else
            {
                if (ctl is Container)
                {
                    Container container = (Container)ctl;
                    if (container.focusedControl != null)
                    {
                        container.focusedControl.IsShowingFocusRect = false;
                    }
                    container.FocusedControl = container.GetNextControl(null, forward);
                    if (container.focusedControl != null)
                    {
                        container.focusedControl.IsShowingFocusRect = showTabFocus;
                    }
                }
                return(true);
            }
        }
Example #10
0
        public override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            //var someoneHit = false;

            SkinnableControl ctl = controls.FirstOrDefault(c => c.Capture);

            if (ctl == null)
            {
                ctl = controls.FirstOrDefault(c => c.HitTest(e.Location));
                if (ctl != null)
                {
                    if (lastEnterControl != ctl)
                    {
                        // Lanciamo mouseLeave / mouseEnter sul vecchio / nuovo controllo sopra il quale ci troviamo.
                        if (lastEnterControl != null)
                        {
                            lastEnterControl.OnMouseLeave(new EventArgs());
                        }
                        lastEnterControl = ctl;
                        ctl.OnMouseEnter(new EventArgs());
                    }

                    MouseEventArgs e2 = new MouseEventArgs(e.Button, e.Clicks, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta);
                    ctl.OnMouseMove(e2);
                }
                else
                {
                    // Non ci troviamo sopra a nessun controllo: se qualcuno dei nostri
                    // controlli aveva il mouseEnter, gli chiamiamo mouseLeave.
                    if (lastEnterControl != null)
                    {
                        lastEnterControl.OnMouseLeave(new EventArgs());
                        lastEnterControl = null;
                    }
                }
            }
            else
            {
                MouseEventArgs e2 = new MouseEventArgs(e.Button, e.Clicks, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta);
                ctl.OnMouseMove(e2);
            }
        }
Example #11
0
        /// <summary>
        /// In seguito a un ridimensionamento di this, corregge la dimensione e la posizione
        /// di un controllo in accordo con la sua proprietà Anchor.
        /// </summary>
        /// <param name="control">Controllo di cui correggere dimensione e posizione</param>
        /// <param name="oldContainerSize">La vecchia dimensione di this</param>
        private void AdjustSizeWithAnchor(SkinnableControl control, SizeF oldContainerSize)
        {
            var a_left   = (control.Anchor & AnchorStyles.Left) == AnchorStyles.Left;
            var a_right  = (control.Anchor & AnchorStyles.Right) == AnchorStyles.Right;
            var a_top    = (control.Anchor & AnchorStyles.Top) == AnchorStyles.Top;
            var a_bottom = (control.Anchor & AnchorStyles.Bottom) == AnchorStyles.Bottom;

            if (!a_left && !a_right)
            {
                // ctrl.left + (half) : sizeBeforeResize.Width = x + (half) : this.Size.Width
                var half = control.Size.Width / 2;
                control.Left = ((control.Left + half) * this.Size.Width / oldContainerSize.Width) - half;
            }
            else if (a_left && a_right)
            {
                var control_right = oldContainerSize.Width - control.Left - control.Size.Width;
                control.Size = new SizeF(this.Size.Width - control.Left - control_right, control.Size.Height);
            }
            else if (!a_left && a_right)
            {
                control.Left += this.Size.Width - oldContainerSize.Width;
            }

            if (!a_top && !a_bottom)
            {
                var half = control.Size.Height / 2;
                control.Top = ((control.Top + half) * this.Size.Height / oldContainerSize.Height) - half;
            }
            else if (a_top && a_bottom)
            {
                // ctrl.height = container.height - ctrl.top - ctrl.bottom
                // ctrl.bottom = container.height - ctrl.top - ctrl.height
                var control_bottom = oldContainerSize.Height - control.Top - control.Size.Height;
                control.Size = new SizeF(control.Size.Width, this.Size.Height - control.Top - control_bottom);
            }
            else if (!a_top && a_bottom)
            {
                control.Top += this.Size.Height - oldContainerSize.Height;
            }
        }
        void SnapTopToGrid(SkinnableControl control)
        {
            float            minHeightDifference    = float.MaxValue;
            SkinnableControl minHeightDifferenceCtl = control;

            foreach (var ctl in this.controls)
            {
                if (ctl == control)
                {
                    continue;
                }
                float topdiff = control.Top - ctl.Top;
                if (topdiff >= 0 && topdiff < minHeightDifference)
                {
                    minHeightDifference    = topdiff;
                    minHeightDifferenceCtl = ctl;
                }
            }

            DetachUpdateEvents(control);
            control.Top = minHeightDifferenceCtl.Top;
            AttachUpdateEvents(control);
        }
Example #13
0
        public override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            SkinnableControl ctl = controls.FirstOrDefault(c => c.HitTest(e.Location));

            if (ctl != null)
            {
                MouseEventArgs e2 = new MouseEventArgs(e.Button, e.Clicks, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta);
                ctl.OnMouseDown(e2);
                this.FocusedControl = ctl;
            }

            // Gestione doppio click
            if ((DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond - lastDoubleClickMsec) <= System.Windows.Forms.SystemInformation.DoubleClickTime)
            {
                Size dbsz = System.Windows.Forms.SystemInformation.DoubleClickSize;
                if (Math.Abs(lastDoubleClickPt.X - e.X) <= dbsz.Width && Math.Abs(lastDoubleClickPt.Y - e.Y) <= dbsz.Height)
                {
                    suppressNextClick = true;
                    if (ctl == null)
                    {
                        base.OnMouseDoubleClick(new MouseEventArgs(e.Button, e.Clicks + 1, e.X, e.Y, e.Delta));
                    }
                    else
                    {
                        ctl.OnMouseDoubleClick(new MouseEventArgs(e.Button, e.Clicks + 1, e.X - (int)Math.Round(ctl.Left, 0, MidpointRounding.ToEven), e.Y - (int)Math.Round(ctl.Top, 0, MidpointRounding.ToEven), e.Delta));
                    }
                }
            }
            else
            {
                lastDoubleClickMsec = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;
                lastDoubleClickPt   = e.Location;
                lastDoubleClickCtl  = ctl;
            }
        }
 void DetachUpdateEvents(SkinnableControl c)
 {
     c.Resize -= Control_Resize;
     c.Move   -= Control_Move;
 }
 void AttachUpdateEvents(SkinnableControl c)
 {
     DetachUpdateEvents(c);
     c.Resize += Control_Resize;
     c.Move   += Control_Move;
 }
Example #16
0
 public virtual void SendToBack(SkinnableControl c)
 {
     controls.MoveToLast(c);
     c.Invalidate();
 }
        protected override void OnDragDrop(DragEventArgs e)
        {
            base.OnDragDrop(e);

            if (e.Data.GetDataPresent(typeof(SkinnableControls.SkinnableControl.SemanticType)))
            {
                // Drop dalla toolbox

                var dropInfo = ControlDropAllowed(this.PointToClient(new Point(e.X, e.Y)), true);
                if (dropInfo != null)
                {
                    SkinnableControls.SkinnableControl.SemanticType ctype =
                        (SkinnableControls.SkinnableControl.SemanticType)e.Data.GetData(typeof(SkinnableControls.SkinnableControl.SemanticType));

                    SkinnableControls.SkinnableControl.SemanticTypeMeta info =
                        SkinnableControls.SkinnableControl.GetPlayerControlInstanceInfo(ctype);

                    e.Effect = DragDropEffects.Copy;

                    // Istanziamo un nuovo oggetto del tipo draggato, e lo aggiungiamo al playerView
                    SkinnableControls.SkinnableControl c = (SkinnableControls.SkinnableControl)Activator.CreateInstance(info.InstanceType, new object[] { ctype });

                    // Inizializiamo qualche proprietà per i controlli standard
                    if (c is SkinnableControls.Button)
                    {
                        ((SkinnableControls.Button)c).Text = info.Title;
                    }
                    else if (c is SkinnableControls.ToggleButton)
                    {
                        ((SkinnableControls.ToggleButton)c).Text        = info.Title;
                        ((SkinnableControls.ToggleButton)c).CheckedText = info.Title;
                    }
                    else if (c is SkinnableControls.Label)
                    {
                        ((SkinnableControls.Label)c).Text = info.Title;
                    }

                    dropInfo.Item3.Controls.AddFirst(c);
                    var location = this.PointToClient(new Point(e.X, e.Y));
                    // Non posizioniamo sotto al mouse le coordinate (0,0) del controllo: lo spostiamo un pochino in alto e a sinistra.
                    const float mouseOffsetX = 7, mouseOffsetY = 7;
                    c.Location = new PointF(Math.Max(0, location.X - dropInfo.Item1 - mouseOffsetX), Math.Max(0, location.Y - dropInfo.Item2 - mouseOffsetY));

                    if (DesignerControlsTreeChanged != null)
                    {
                        DesignerControlsTreeChanged(this, new EventArgs());
                    }
                    this.Select(c);

                    this.Focus();
                }
            }
            else if (e.Data.GetDataPresent(typeof(SkinnableControl).FullName))
            {
                // Drop di un controllo
                var c = (SkinnableControl)e.Data.GetData(typeof(SkinnableControl).FullName);

                if (c.Parent != null)
                {
                    // Qualcuno lo ha già riaggiunto alla View prima di noi (probabilmente OnQueryContinueDrag che
                    // credeva che il dragging fosse stato annullato).
                    // Togliamolo così più sotto lo reinseriamo al posto giusto.
                    c.Parent = null;
                    this.Select(null);
                }

                var dropInfo = ControlDropAllowed(this.PointToClient(new Point(e.X, e.Y)), false);
                if (dropInfo != null)
                {
                    var newParent = dropInfo.Item3;
                    if (newParent != c)
                    {
                        newParent.Controls.AddFirst(c);
                    }
                    var location = this.PointToClient(new Point(e.X, e.Y));
                    c.Location           = new PointF(location.X - this.draggingOffset.X - dropInfo.Item1, location.Y - this.draggingOffset.Y - dropInfo.Item2);
                    this.draggingControl = null;
                    if (DesignerControlsTreeChanged != null)
                    {
                        DesignerControlsTreeChanged(this, new EventArgs());
                    }
                    this.Select(c);
                    if (SelectedObjectPropertyChanged != null)
                    {
                        SelectedObjectPropertyChanged(this, new EventArgs());
                    }
                }
            }
        }
 void DetachUpdateEvents(SkinnableControl c)
 {
     c.Resize -= Control_Resize;
     c.Move -= Control_Move;
 }
 void AttachUpdateEvents(SkinnableControl c)
 {
     DetachUpdateEvents(c);
     c.Resize += Control_Resize;
     c.Move += Control_Move;
 }
        void SnapTopToGrid(SkinnableControl control)
        {
            float minHeightDifference = float.MaxValue;
            SkinnableControl minHeightDifferenceCtl = control;

            foreach (var ctl in this.controls)
            {
                if (ctl == control) continue;
                float topdiff = control.Top - ctl.Top;
                if (topdiff >= 0 && topdiff < minHeightDifference)
                {
                    minHeightDifference = topdiff;
                    minHeightDifferenceCtl = ctl;
                }
            }

            DetachUpdateEvents(control);
            control.Top = minHeightDifferenceCtl.Top;
            AttachUpdateEvents(control);
        }
Example #21
0
 public SkinnableControlEventArgs(SkinnableControl control) : base()
 {
     this.Control = control;
 }
 public SkinnableControlEventArgs(SkinnableControl control)
     : base()
 {
     this.Control = control;
 }
Example #23
0
 public virtual void BringToFront(SkinnableControl c)
 {
     controls.MoveToFirst(c);
     c.Invalidate();
 }