Example #1
0
        /// <summary>
        /// Handle mouse down over a button on the toolbar when we're customising.
        /// </summary>
        private void ToolbarOnMouseDown(object sender, MouseEventArgs mouseEventArgs)
        {
            if (Customising)
            {
                // Find the corresponding button on the customisation panel and use
                // that as the drag source control.
                Control       dragButton = (Control)sender;
                CRToolbarItem dragitem   = (CRToolbarItem)dragButton.Tag;

                Control button = (from control in _customPanel.Controls.Cast <Control>().Where(control => control is CRRoundButton)
                                  let item = (ToolbarDataItem)control.Tag
                                             where item.name == dragitem.Name
                                             select control).FirstOrDefault();

                if (button != null)
                {
                    _draggedButton = new CRToolbarItem(dragitem.DataItem)
                    {
                        Control = button
                    };
                }
                _hasDragItem = false;
                _dragSource  = dragitem;
            }
        }
Example #2
0
        /// <summary>
        /// Handles a toolbar button click.
        /// </summary>
        private void OnToolbarItemClick(object sender, EventArgs e)
        {
            Control control = sender as Control;

            if (control != null && ActionToolbarItem != null && !Customising)
            {
                CRToolbarItem item = control.Tag as CRToolbarItem;
                if (item != null)
                {
                    ActionToolbarItem(this, new CRToolbarItemEventArgs {
                        Item = item
                    });
                }
            }
        }
Example #3
0
        /// <summary>
        /// Handle mouse down over a button on the customisation panel.
        /// </summary>
        private void CustomizePanelOnMouseDown(object sender, MouseEventArgs mouseEventArgs)
        {
            CRRoundButton button = sender as CRRoundButton;

            if (button != null)
            {
                // Make a copy of the item being dragged.
                ToolbarDataItem item = (ToolbarDataItem)button.Tag;
                _draggedButton = new CRToolbarItem(item)
                {
                    Control = button
                };
                _hasDragItem = false;
                _dragSource  = null;
            }
        }
Example #4
0
        /// <summary>
        /// Return the toolbar button that corresponds to the specified Action ID or
        /// null if no such button exists.
        /// </summary>
        public int IndexOfItemWithPoint(Point pos)
        {
            CRToolbarItemCollection collection = CRToolbarItemCollection.DefaultCollection;

            for (int index = 0; index < collection.Buttons.Count; ++index)
            {
                CRToolbarItem item = collection.Buttons[index];
                if (item.Control != null)
                {
                    int       halfWidth     = item.Control.Width / 2;
                    Rectangle leftPosition  = new Rectangle(item.Control.Left - halfWidth, item.Control.Top, item.Control.Width, item.Control.Height);
                    Rectangle rightPosition = new Rectangle(item.Control.Right - halfWidth, item.Control.Top, item.Control.Width, item.Control.Height);
                    if (leftPosition.Contains(pos))
                    {
                        return(index);
                    }
                    if (rightPosition.Contains(pos))
                    {
                        return(index + 1);
                    }
                }
            }
            return(collection.Buttons.Count);
        }
 /// <summary>
 /// Remove the specified item from the collection.
 /// </summary>
 public void Remove(CRToolbarItem button)
 {
     _buttons.Remove(button);
 }
 /// <summary>
 /// Insert the item at the specified index.
 /// </summary>
 public void Insert(int index, CRToolbarItem button)
 {
     _buttons.Insert(index, button);
 }
Example #7
0
        /// <summary>
        /// Handle mouse down over a button on the toolbar when we're customising.
        /// </summary>
        private void ToolbarOnMouseDown(object sender, MouseEventArgs mouseEventArgs)
        {
            if (Customising)
            {
                // Find the corresponding button on the customisation panel and use
                // that as the drag source control.
                Control dragButton = (Control)sender;
                CRToolbarItem dragitem = (CRToolbarItem)dragButton.Tag;

                Control button = (from control in _customPanel.Controls.Cast<Control>().Where(control => control is CRRoundButton)
                                  let item = (ToolbarDataItem) control.Tag
                                  where item.name == dragitem.Name
                                  select control).FirstOrDefault();

                if (button != null)
                {
                    _draggedButton = new CRToolbarItem(dragitem.DataItem)
                    {
                        Control = button
                    };
                }
                _hasDragItem = false;
                _dragSource = dragitem;
            }
        }
Example #8
0
        /// <summary>
        /// Handle a toolbar button being dropped, either from the customisation panel onto the
        /// toolbar or from the toolbar itself.
        /// </summary>
        private void InternalHandleCustomDrop()
        {
            Point screenDropLocation = Cursor.Position;
            Control form = TopLevelControl;
            if (form == null || !form.Bounds.Contains(screenDropLocation))
            {
                return;
            }
            Control dropControl = WindowFromPoint(form, form.PointToClient(screenDropLocation));
            if (dropControl != null)
            {
                // Change parent if we dropped on the search field's text box or icon.
                if (dropControl.Parent is CRSearchField)
                {
                    dropControl = dropControl.Parent;
                }

                // If we dropped on a toolbar button, separator control or the search field, switch to
                // the parent for consistency.
                if (dropControl is CRRoundButton || dropControl is PictureBox || dropControl is CRSearchField)
                {
                    dropControl = dropControl.Parent;
                }

                // Dropping on the toolbar at this point means the new button is being inserted.
                // Otherwise it is being deleted.
                Point dropLocation = dropControl.PointToClient(screenDropLocation);
                CRToolbarItemCollection collection = CRToolbarItemCollection.DefaultCollection;

                if (dropControl is CRToolbar)
                {
                    if (_dragSource != null)
                    {
                        collection.Remove(_dragSource);
                        Controls.Remove(_dragSource.Control);
                        Relayout();
                    }
                    else
                    {
                        CRToolbarItem button = MatchingItem(_draggedButton);
                        if (button != null && button.Type != CRToolbarItemType.Space && button.Type != CRToolbarItemType.FlexibleSpace)
                        {
                            collection.Remove(button);
                            Relayout();
                        }
                    }

                    // Find the index of where to insert the button.
                    int index = IndexOfItemWithPoint(dropLocation);

                    // Add to the collection at the index.
                    collection.Insert(index, _draggedButton);

                    // Reload the toolbar.
                    Load();
                    Update();
                }
                else if (_dragSource != null)
                {
                    collection.Remove(_dragSource);
                    Controls.Remove(_dragSource.Control);
                    Relayout();
                    Update();
                }
            }

            _draggedButton.Control.Capture = false;

            _hasDragItem = false;
            _draggedButton = null;
        }
Example #9
0
 /// <summary>
 /// Handle mouse down over a button on the customisation panel.
 /// </summary>
 private void CustomizePanelOnMouseDown(object sender, MouseEventArgs mouseEventArgs)
 {
     CRRoundButton button = sender as CRRoundButton;
     if (button != null)
     {
         // Make a copy of the item being dragged.
         ToolbarDataItem item = (ToolbarDataItem)button.Tag;
         _draggedButton = new CRToolbarItem(item)
         {
             Control = button
         };
         _hasDragItem = false;
         _dragSource = null;
     }
 }
Example #10
0
 /// <summary>
 /// Return the toolbar button that corresponds to the specified one or
 /// null if no such button exists.
 /// </summary>
 public CRToolbarItem MatchingItem(CRToolbarItem match)
 {
     return (from CRToolbarItem item in CRToolbarItemCollection.DefaultCollection.Buttons where item.Name == match.Name && item.Tooltip == match.Tooltip select item).FirstOrDefault();
 }
 /// <summary>
 /// Insert the item at the specified index.
 /// </summary>
 public void Insert(int index, CRToolbarItem button)
 {
     _buttons.Insert(index, button);
 }
 /// <summary>
 /// Remove the specified item from the collection.
 /// </summary>
 public void Remove(CRToolbarItem button)
 {
     _buttons.Remove(button);
 }
Example #13
0
        /// <summary>
        /// Handle a toolbar button being dropped, either from the customisation panel onto the
        /// toolbar or from the toolbar itself.
        /// </summary>
        private void InternalHandleCustomDrop()
        {
            Point   screenDropLocation = Cursor.Position;
            Control form = TopLevelControl;

            if (form == null || !form.Bounds.Contains(screenDropLocation))
            {
                return;
            }
            Control dropControl = WindowFromPoint(form, form.PointToClient(screenDropLocation));

            if (dropControl != null)
            {
                // Change parent if we dropped on the search field's text box or icon.
                if (dropControl.Parent is CRSearchField)
                {
                    dropControl = dropControl.Parent;
                }

                // If we dropped on a toolbar button, separator control or the search field, switch to
                // the parent for consistency.
                if (dropControl is CRRoundButton || dropControl is PictureBox || dropControl is CRSearchField)
                {
                    dropControl = dropControl.Parent;
                }

                // Dropping on the toolbar at this point means the new button is being inserted.
                // Otherwise it is being deleted.
                Point dropLocation = dropControl.PointToClient(screenDropLocation);
                CRToolbarItemCollection collection = CRToolbarItemCollection.DefaultCollection;

                if (dropControl is CRToolbar)
                {
                    if (_dragSource != null)
                    {
                        collection.Remove(_dragSource);
                        Controls.Remove(_dragSource.Control);
                        Relayout();
                    }
                    else
                    {
                        CRToolbarItem button = MatchingItem(_draggedButton);
                        if (button != null && button.Type != CRToolbarItemType.Space && button.Type != CRToolbarItemType.FlexibleSpace)
                        {
                            collection.Remove(button);
                            Relayout();
                        }
                    }

                    // Find the index of where to insert the button.
                    int index = IndexOfItemWithPoint(dropLocation);

                    // Add to the collection at the index.
                    collection.Insert(index, _draggedButton);

                    // Reload the toolbar.
                    Load();
                    Update();
                }
                else if (_dragSource != null)
                {
                    collection.Remove(_dragSource);
                    Controls.Remove(_dragSource.Control);
                    Relayout();
                    Update();
                }
            }

            _draggedButton.Control.Capture = false;

            _hasDragItem   = false;
            _draggedButton = null;
        }
Example #14
0
 /// <summary>
 /// Return the toolbar button that corresponds to the specified one or
 /// null if no such button exists.
 /// </summary>
 public CRToolbarItem MatchingItem(CRToolbarItem match)
 {
     return((from CRToolbarItem item in CRToolbarItemCollection.DefaultCollection.Buttons where item.Name == match.Name && item.Tooltip == match.Tooltip select item).FirstOrDefault());
 }