예제 #1
0
        private void ToolBarDoubleClick(object sender, System.EventArgs e)
        {
            ToolBarDockHolder holder = (ToolBarDockHolder)sender;

            if (IsDocked(holder))
            {
                ToolBarDockArea docked = GetDockedArea(holder);
                docked.SuspendLayout();
                holder.Parent            = holder.FloatForm;
                holder.Location          = new Point(0, 0);
                holder.DockStyle         = DockStyle.None;
                holder.FloatForm.Visible = true;
                holder.FloatForm.Size    = holder.Size;
                docked.ResumeLayout();
                docked.PerformLayout();
            }
            else
            {
                ToolBarDockArea area = holder.PreferredDockedArea;
                area.SuspendLayout();
                Point newLoc = holder.PreferredDockedLocation;
                holder.DockStyle = area.Dock;
                holder.Parent    = area;
                holder.PreferredDockedLocation = newLoc;
                holder.FloatForm.Visible       = false;
                holder.PreferredDockedArea     = area;
                area.ResumeLayout();
                area.PerformLayout();
            }
        }
예제 #2
0
 public ToolBarManager(ScrollableControl dockStation, Form mainForm)
 {
     this.DockStation = dockStation;
     this.MainForm = mainForm;
     _left = new ToolBarDockArea(this, DockStyle.Left);
     _right = new ToolBarDockArea(this, DockStyle.Right);
     _top = new ToolBarDockArea(this, DockStyle.Top);
     _bottom = new ToolBarDockArea(this, DockStyle.Bottom);
     Application.AddMessageFilter(this);
 }
예제 #3
0
 public ToolBarManager(ScrollableControl dockStation, Form mainForm)
 {
     this.DockStation = dockStation;
     this.MainForm    = mainForm;
     _left            = new ToolBarDockArea(this, DockStyle.Left);
     _right           = new ToolBarDockArea(this, DockStyle.Right);
     _top             = new ToolBarDockArea(this, DockStyle.Top);
     _bottom          = new ToolBarDockArea(this, DockStyle.Bottom);
     Application.AddMessageFilter(this);
 }
예제 #4
0
 public bool PreFilterMessage(ref Message m)
 {
     if (m.Msg == WM_KEYDOWN)
     {
         Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
         if (keyCode == Keys.ControlKey)
         {
             if (!_ctrlDown && _dragged != null && IsDocked(_dragged))
             {
                 ToolBarDockArea docked = GetDockedArea(_dragged);
                 docked.SuspendLayout();
                 _dragged.Parent             = _dragged.FloatForm;
                 _dragged.Location           = new Point(0, 0);
                 _dragged.DockStyle          = DockStyle.None;
                 _dragged.FloatForm.Visible  = true;
                 _dragged.FloatForm.Location = new Point(Control.MousePosition.X - _ptOffset.X, Control.MousePosition.Y - 8);
                 _dragged.FloatForm.Size     = _dragged.Size;
                 docked.ResumeLayout();
                 docked.PerformLayout();
             }
             _ctrlDown = true;
         }
     }
     else if (m.Msg == WM_KEYUP)
     {
         Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
         if (keyCode == Keys.ControlKey)
         {
             if (_ctrlDown && _dragged != null && !IsDocked(_dragged))
             {
                 ToolBarDockArea closest = GetClosestArea(Control.MousePosition, _dragged.PreferredDockedArea);
                 if (closest != null)
                 {
                     closest.SuspendLayout();
                     Point newLoc = closest.PointToClient(Control.MousePosition);
                     _dragged.DockStyle = closest.Dock;
                     _dragged.Parent    = closest;
                     _dragged.PreferredDockedLocation = newLoc;
                     _dragged.FloatForm.Visible       = false;
                     _dragged.PreferredDockedArea     = closest;
                     closest.ResumeLayout();
                     closest.PerformLayout();
                 }
             }
             _ctrlDown = false;
         }
     }
     return(false);
 }
예제 #5
0
        protected ToolBarDockArea GetClosestArea(Point ptScreen, ToolBarDockArea preferred)
        {
            if (preferred != null)
            {
                Rectangle p = preferred.RectangleToScreen(preferred.ClientRectangle);
                p.Inflate(8, 8);
                if (p.Contains(ptScreen))
                {
                    return(preferred);
                }
            }

            Rectangle l = _left.RectangleToScreen(_left.ClientRectangle);

            l.Inflate(8, 8);
            Rectangle r = _right.RectangleToScreen(_right.ClientRectangle);

            r.Inflate(8, 8);
            Rectangle t = _top.RectangleToScreen(_top.ClientRectangle);

            t.Inflate(8, 8);
            Rectangle b = _bottom.RectangleToScreen(_bottom.ClientRectangle);

            b.Inflate(8, 8);

            if (t.Contains(ptScreen))
            {
                return(_top);
            }
            if (b.Contains(ptScreen))
            {
                return(_bottom);
            }
            if (l.Contains(ptScreen))
            {
                return(_left);
            }
            if (r.Contains(ptScreen))
            {
                return(_right);
            }

            return(null);
        }
예제 #6
0
        public ToolBarDockHolder(ToolBarManager dm, Control c, DockStyle style)
        {
            InitializeComponent();
            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.DoubleBuffer, true);

            _panel.Controls.AddRange(new Control[] { c });
            DockManager = dm;
            if (style == DockStyle.Left)
            {
                _preferredDockedArea = dm.Left;
            }
            else if (style == DockStyle.Right)
            {
                _preferredDockedArea = dm.Right;
            }
            else if (style == DockStyle.Bottom)
            {
                _preferredDockedArea = dm.Bottom;
            }
            else
            {
                _preferredDockedArea = dm.Top;
            }
            _control                  = c;
            FloatForm.Visible         = false;
            FloatForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            FloatForm.MaximizeBox     = false;
            FloatForm.MinimizeBox     = false;
            FloatForm.ShowInTaskbar   = false;
            FloatForm.ClientSize      = new Size(10, 10);
            // Added by mav
            DockManager.MainForm.AddOwnedForm(FloatForm);
            DockStyle    = style;
            ToolbarTitle = c.Text;
//			_control.TextChanged += new EventHandler(control_TextChanged);
        }
예제 #7
0
        public ToolBarDockHolder(ToolBarManager dm, Control c, DockStyle style)
        {
            InitializeComponent();
            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.DoubleBuffer, true);

            _panel.Controls.AddRange(new Control[]{c});
            DockManager = dm;
            if(style == DockStyle.Left)
            {
                _preferredDockedArea = dm.Left;
            }
            else if(style == DockStyle.Right)
            {
                _preferredDockedArea = dm.Right;
            }
            else if(style == DockStyle.Bottom)
            {
                _preferredDockedArea = dm.Bottom;
            }
            else
            {
                _preferredDockedArea = dm.Top;
            }
            _control = c;
            FloatForm.Visible = false;
            FloatForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            FloatForm.MaximizeBox = false;
            FloatForm.MinimizeBox = false;
            FloatForm.ShowInTaskbar = false;
            FloatForm.ClientSize = new Size(10,10);
            // Added by mav
            DockManager.MainForm.AddOwnedForm(FloatForm);
            DockStyle = style;
            ToolbarTitle = c.Text;
            //			_control.TextChanged += new EventHandler(control_TextChanged);
        }
예제 #8
0
        protected ToolBarDockArea GetClosestArea(Point ptScreen, ToolBarDockArea preferred)
        {
            if(preferred != null)
            {
                Rectangle p = preferred.RectangleToScreen(preferred.ClientRectangle);
                p.Inflate(8,8);
                if(p.Contains(ptScreen)) return preferred;
            }

            Rectangle l = _left.RectangleToScreen(_left.ClientRectangle);
            l.Inflate(8,8);
            Rectangle r = _right.RectangleToScreen(_right.ClientRectangle);
            r.Inflate(8,8);
            Rectangle t = _top.RectangleToScreen(_top.ClientRectangle);
            t.Inflate(8,8);
            Rectangle b = _bottom.RectangleToScreen(_bottom.ClientRectangle);
            b.Inflate(8,8);

            if(t.Contains(ptScreen)) return _top;
            if(b.Contains(ptScreen)) return _bottom;
            if(l.Contains(ptScreen)) return _left;
            if(r.Contains(ptScreen)) return _right;

            return null;
        }
예제 #9
0
        private void ToolBarMouseMove(object sender, MouseEventArgs e)
        {
            Point ptPos = new Point(e.X, e.Y);

            if (_dragged != null)
            {
                Point ptDelta = new Point(_ptStart.X - Control.MousePosition.X, _ptStart.Y - Control.MousePosition.Y);

                Point newLoc = _dragged.PointToScreen(new Point(0, 0));
                newLoc = new Point(newLoc.X - ptDelta.X, newLoc.Y - ptDelta.Y);
                ToolBarDockArea closest = GetClosestArea(Control.MousePosition, _dragged.PreferredDockedArea);
                // Added by mav
                if (closest != null && !_dragged.IsAllowed(closest.Dock))
                {
                    closest = null;
                }

                ToolBarDockArea docked = GetDockedArea(_dragged);

                if (_ctrlDown)
                {
                    closest = null;
                }

                if (docked != null)
                {
                    if (closest == null)
                    {
                        docked.SuspendLayout();
                        _dragged.Parent             = _dragged.FloatForm;
                        _dragged.Location           = new Point(0, 0);
                        _dragged.DockStyle          = DockStyle.None;
                        _dragged.FloatForm.Visible  = true;
                        _dragged.FloatForm.Location = new Point(Control.MousePosition.X - _ptOffset.X, Control.MousePosition.Y - 8);
                        _dragged.FloatForm.Size     = _dragged.Size;
                        docked.ResumeLayout();
                        docked.PerformLayout();
                    }
                    else if (closest != docked)
                    {
                        closest.SuspendLayout();
                        newLoc             = closest.PointToClient(Control.MousePosition);
                        _dragged.DockStyle = closest.Dock;
                        _dragged.Parent    = closest;
                        _dragged.PreferredDockedLocation = newLoc;
                        _dragged.FloatForm.Visible       = false;
                        _dragged.PreferredDockedArea     = closest;
                        closest.ResumeLayout();
                        closest.PerformLayout();
                    }
                    else
                    {
                        closest.SuspendLayout();
                        newLoc = closest.PointToClient(Control.MousePosition);
//						if(closest.Horizontal)
//							newLoc = new Point(newLoc.X - 4, newLoc.Y - _dragged.Height/2);
//						else
//							newLoc = new Point(newLoc.X - _dragged.Width/2, newLoc.Y - 4);
                        _dragged.PreferredDockedLocation = newLoc;
                        closest.ResumeLayout();
                        closest.PerformLayout();
                    }
                }
                else
                {
                    if (closest == null)
                    {
                        _dragged.FloatForm.Location = newLoc;
                    }
                    else
                    {
                        closest.SuspendLayout();
                        newLoc             = closest.PointToClient(Control.MousePosition);
                        _dragged.DockStyle = closest.Dock;
                        _dragged.Parent    = closest;
                        _dragged.PreferredDockedLocation = newLoc;
                        _dragged.FloatForm.Visible       = false;
                        _dragged.PreferredDockedArea     = closest;
                        closest.ResumeLayout();
                        closest.PerformLayout();
                    }
                }
                _ptStart = Control.MousePosition;
            }
        }