Пример #1
0
 /// <summary>
 /// Creates a new instance of an ItemMouseEventArgs
 /// </summary>
 /// <param name="inButton">The Mouse Buttons</param>
 /// <param name="inClicks">The number of clicks</param>
 /// <param name="inX">The X coordinate</param>
 /// <param name="inY">The Y coordinate</param>
 /// <param name="inDelta">The delta of the mouse wheel</param>
 /// <param name="inItemBox">A LegendBox for comparision</param>
 public ItemMouseEventArgs(MouseButtons inButton, int inClicks, int inX, int inY, int inDelta, LegendBox inItemBox)
     : base(inButton, inClicks, inX, inY, inDelta)
 {
     _box = inItemBox;
 }
Пример #2
0
 /// <summary>
 /// Creates a new instance of ItemMouseEventArgs from an existing MouseEventArgs.
 /// </summary>
 /// <param name="args">The existing arguments</param>
 /// <param name="inItemBox">A LegendBox for comparison</param>
 public ItemMouseEventArgs(MouseEventArgs args, LegendBox inItemBox)
     : base(args.Button, args.Clicks, args.X, args.Y, args.Delta)
 {
     _box = inItemBox;
 }
Пример #3
0
        // Draw the symbol for a particualr item
        private void DrawSymbol(Graphics g, ref PointF topLeft, LegendBox itemBox)
        {
            ILegendItem item = itemBox.Item;
            // Align symbols so that their right side is about 20 pixels left
            // of the top-left X, but allow up to 128x128 sized symbols
            Size s = item.GetLegendSymbolSize();
            int h = s.Height;
            if (h < 1) h = 1;
            if (h > 128) h = 128;
            int w = s.Width;
            if (w < 1) w = 1;
            if (w > 128) w = 128;

            int tH = ItemHeight;
            int x = (int)topLeft.X + tH - w;
            int y = (int)topLeft.Y;
            if (tH > h) y += (tH - h) / 2;
            Rectangle box = new Rectangle(x, y, w, h);
            itemBox.SymbolBox = box;
            item.LegendSymbol_Painted(g, box);
            topLeft.X += tH + 6;
        }
Пример #4
0
 // Draw the plus or minus visible for controlling expansion
 private void DrawPlusMinus(Graphics g, ref PointF topLeft, LegendBox itemBox)
 {
     ILegendItem item = itemBox.Item;
     if (item == null) return;
     if (item.LegendSymbolMode == SymbolMode.Symbol) return; // don't allow symbols to expand
     Point tl = new Point((int)topLeft.X, (int)topLeft.Y);
     tl.Y += (ItemHeight - 8) / 2;
     tl.X += 3;
     Rectangle box = new Rectangle(tl.X, tl.Y, 8, 8);
     itemBox.ExpandBox = box;
     Point center = new Point(tl.X + 4, (int)topLeft.Y + ItemHeight / 2);
     g.FillRectangle(Brushes.White, box);
     g.DrawRectangle(Pens.Gray, box);
     if (item.IsExpanded)
     {
         g.DrawRectangle(Pens.Gray, box);
     }
     else if (item.LegendItems != null && item.LegendItems.Any())
     {
         g.DrawLine(Pens.Black, center.X, center.Y - 2, center.X, center.Y + 2);
     }
     g.DrawLine(Pens.Black, center.X - 2, center.Y, center.X + 2, center.Y);
     topLeft.X += 13;
 }
Пример #5
0
        /// <summary>
        /// Performs the default handling for mouse movememnt, and decides
        /// whether or not to fire an ItemMouseMove event.
        /// </summary>
        /// <param name="e">A MouseEventArgs</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (_legendBoxes == null) return;
            bool cursorHandled = false;
            LegendBox currentBox = null;
            Point loc = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top);
            foreach (LegendBox box in _legendBoxes)
            {
                if (box.Bounds.Contains(loc))
                {
                    currentBox = box;
                    ItemMouseEventArgs args = new ItemMouseEventArgs(e, box);
                    DoItemMouseMove(args);
                }
            }
            if (_isDragging)
            {
                _dragTarget = null;
                if (currentBox != null) _dragTarget = currentBox;
                if (ClientRectangle.Contains(e.Location))
                {
                    if (currentBox == null) _dragTarget = BottomBox;
                }
                if (_previousLine.IsEmpty == false) Invalidate(_previousLine);
                _previousLine = Rectangle.Empty;

                if (_dragTarget != null && _dragItem != null && _dragTarget != _dragItem)
                {
                    LegendBox boxOverLine;
                    int left = 0;
                    LegendBox container = BoxFromItem(_dragTarget.Item.GetValidContainerFor(_dragItem.Item));
                    if (container != null)
                    {
                        left = (container.Indent + 1) * _indentation;
                    }
                    if (_dragTarget.Item.CanReceiveItem(_dragItem.Item))
                    {
                        boxOverLine = _dragTarget;
                    }
                    else
                    {
                        boxOverLine = BoxFromItem(_dragTarget.Item.BottomMember());
                    }
                    if (boxOverLine == null)
                    {
                        _previousLine = Rectangle.Empty;
                        Cursor = Cursors.No;
                        cursorHandled = true;
                    }
                    else
                    {
                        _previousLine = new Rectangle(left, boxOverLine.Bounds.Bottom, Width - left, 4);
                        Cursor = Cursors.Hand;
                        cursorHandled = true;
                        Invalidate(_previousLine);
                    }
                }
                if (cursorHandled == false)
                {
                    Cursor = Cursors.No;
                    cursorHandled = true;
                }
            }
            if (cursorHandled == false)
            {
                Cursor = Cursors.Arrow;
            }
            base.OnMouseMove(e);
        }
Пример #6
0
        private void DoItemMouseDown(ItemMouseEventArgs e)
        {
            Point loc = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top);
            // Toggle expansion
            if (e.ItemBox.ExpandBox.Contains(loc))
            {
                e.ItemBox.Item.IsExpanded = !e.ItemBox.Item.IsExpanded;
                if (ExpandBoxMouseDown != null) ExpandBoxMouseDown(this, e);
                IsInitialized = false;
                SizePage();
                ResetScroll();
                Invalidate();
                return;
            }

            if (e.ItemBox.Item.IsSelected)
            {
                // if we are already selected, prepare to edit in textbox
                _previousMouseDown = e.ItemBox;

                // Start dragging
                if (e.Button == MouseButtons.Left)
                {
                    _isDragging = true;
                    ILegendItem li = e.ItemBox.Item;
                    while (li != null && li as ILayer == null)
                    {
                        li = li.GetParentItem();
                    }
                    ILayer lyr = li as ILayer;
                    if (lyr != null)
                    {
                        _dragItem = BoxFromItem(lyr);
                    }
                    else
                    {
                        _isDragging = false;
                    }
                }
            }
            else
            {
                // Check for textbox clicking
                if (e.ItemBox.Textbox.Contains(loc))
                {
                    if (ModifierKeys != Keys.Shift)
                    {
                        ClearSelection();
                    }
                    e.ItemBox.Item.IsSelected = true;
                    //_selection.Add(e.ItemBox);
                    //IsInitialized = false;
                    //Invalidate();
                    //return;
                }
            }
        }
Пример #7
0
 private void HideEditBox()
 {
     if (_editBox.Visible && _ignoreHide == false)
     {
         _ignoreHide = true;
         _previousMouseDown.Item.LegendText = _editBox.Text;
         _previousMouseDown = null;
         _editBox.Visible = false;
         _editBox.Text = string.Empty;
         _ignoreHide = false;
         IsInitialized = false;
         Invalidate();
     }
 }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected virtual PointF OnInitializeItem(DrawLegendItemArgs e)
        {
            if (e.Item.LegendItemVisible == false) return e.TopLeft;
            PointF topLeft = e.TopLeft;
            PointF tempTopLeft = topLeft;
            if (topLeft.Y > ControlRectangle.Bottom)
            {
                return topLeft; // drawing would be below the screen
            }
            if (topLeft.Y > ControlRectangle.Top - ItemHeight)
            {
                // Draw the item itself
                // Point tl = new Point((int)topLeft.X, (int)topLeft.Y);
                LegendBox itemBox = new LegendBox();
                _legendBoxes.Add(itemBox);
                itemBox.Item = e.Item;
                itemBox.Bounds = new Rectangle(0, (int)topLeft.Y, Width, ItemHeight);
                itemBox.Indent = (int)topLeft.X / _indentation;

                DrawPlusMinus(e.Graphics, ref tempTopLeft, itemBox);

                int ih = ItemHeight;

                if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
                {
                    Size s = e.Item.GetLegendSymbolSize();
                    if (s.Height > ih) tempTopLeft.Y += 3;
                }
                if (e.Item.LegendSymbolMode == SymbolMode.Symbol || e.Item.LegendSymbolMode == SymbolMode.GroupSymbol)
                {
                    DrawSymbol(e.Graphics, ref tempTopLeft, itemBox);
                }

                if (e.Item.LegendSymbolMode == SymbolMode.Checkbox)
                {
                    DrawCheckBoxes(e.Graphics, ref tempTopLeft, itemBox);
                }

                int width = (int)e.Graphics.MeasureString(e.Item.LegendText, Font).Width;
                int dY = 0;
                if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
                {
                    Size s = e.Item.GetLegendSymbolSize();
                    if (s.Height > ih) dY = (s.Height - ih) / 2;
                    tempTopLeft.Y += dY;
                }
                tempTopLeft.Y += (ih - Font.Height) / (float)2;

                itemBox.Textbox = new Rectangle((int)tempTopLeft.X, (int)topLeft.Y + dY, width, ItemHeight);
                if (itemBox.Item.IsSelected)
                {
                    if (_selection.Contains(itemBox) == false) _selection.Add(itemBox);
                    Rectangle innerBox = itemBox.Textbox;
                    innerBox.Inflate(-1, -1);
                    Brush b = HighlightBrush(innerBox);
                    e.Graphics.FillRectangle(b, innerBox);
                    b.Dispose();

                    SymbologyGlobal.DrawRoundedRectangle(e.Graphics, _highlightBorderPen, itemBox.Textbox);

                    e.Graphics.DrawString(e.Item.LegendText, Font, _selectionFontBrush, tempTopLeft);
                }
                else
                {
                    e.Graphics.DrawString(e.Item.LegendText, Font, Brushes.Black, tempTopLeft);
                }
            }
            int h = ItemHeight;
            if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
            {
                Size s = e.Item.GetLegendSymbolSize();
                if (s.Height > h) h = s.Height + 6;
            }
            topLeft.Y += h;

            if (e.Item.IsExpanded)
            {
                topLeft.X += _indentation;
                if (e.Item.LegendItems != null)
                {
                    List<ILegendItem> items = e.Item.LegendItems.ToList();
                    if (e.Item is IGroup) items.Reverse(); // reverse layers because of drawing order, don't bother reversing categories.
                    foreach (ILegendItem item in items)
                    {
                        DrawLegendItemArgs args = new DrawLegendItemArgs(e.Graphics, item, e.ClipRectangle, topLeft);
                        topLeft = OnInitializeItem(args);
                        if (topLeft.Y > ControlRectangle.Bottom) break;
                    }
                }
                topLeft.X -= _indentation;
            }
            return topLeft;
        }
Пример #9
0
        /// <summary>
        /// Given the current list of Maps or 3DMaps, it
        /// rebuilds the treeview nodes
        /// </summary>
        public void RefreshNodes()
        {
            // do any code that needs to happen if content changes
            _previousMouseDown = null; // to avoid memory leaks, because LegendBox contains reference to Layer

            IsInitialized = false;
            Invalidate();
        }
Пример #10
0
        // Draw the checkbox for an item
        private void DrawCheckBoxes(Graphics g, ref PointF topLeft, LegendBox itemBox)
        {
            ILegendItem item = itemBox.Item;
            if (item == null) return;
            if (item.LegendSymbolMode != SymbolMode.Checkbox) return;

            if (item.Checked)
            {
                int top = (int)topLeft.Y + (ItemHeight - _icoChecked.Height) / 2;
                int left = (int)topLeft.X + 6;
                g.DrawIcon(_icoChecked, left, top);
                Rectangle box = new Rectangle(left, top, _icoChecked.Width, _icoChecked.Height);
                itemBox.CheckBox = box;
            }
            else
            {
                int top = (int)topLeft.Y + (ItemHeight - _icoUnchecked.Height) / 2;
                int left = (int)topLeft.X + 6;
                g.DrawIcon(_icoUnchecked, left, top);
                Rectangle box = new Rectangle(left, top, _icoChecked.Width, _icoChecked.Height);
                itemBox.CheckBox = box;
            }
            topLeft.X += 22;
        }
Пример #11
0
 private void HideEditBox()
 {
     if (_editBox.Visible && _ignoreHide == false)
     {
         _ignoreHide = true;
         _previousMouseDown.Item.LegendText = _editBox.Text;
         _previousMouseDown = null;
         _editBox.Visible = false;
         _editBox.Text = string.Empty;
         _ignoreHide = false;
         RefreshNodes();
     }
 }
Пример #12
0
        /// <summary>
        /// Performs the default handling for mouse movememnt, and decides
        /// whether or not to fire an ItemMouseMove event.
        /// </summary>
        /// <param name="e">A MouseEventArgs</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (_legendBoxes == null)
            {
                return;
            }
            bool      cursorHandled = false;
            LegendBox currentBox    = null;
            Point     loc           = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top);

            foreach (LegendBox box in _legendBoxes)
            {
                if (box.Bounds.Contains(loc))
                {
                    currentBox = box;
                    ItemMouseEventArgs args = new ItemMouseEventArgs(e, box);
                    DoItemMouseMove(args);
                }
            }
            if (_isDragging)
            {
                _dragTarget = null;
                if (currentBox != null)
                {
                    _dragTarget = currentBox;
                }
                if (ClientRectangle.Contains(e.Location))
                {
                    if (currentBox == null)
                    {
                        _dragTarget = BottomBox;
                    }
                }
                if (_previousLine.IsEmpty == false)
                {
                    Invalidate(_previousLine);
                }
                _previousLine = Rectangle.Empty;

                if (_dragTarget != null && _dragItem != null && _dragTarget != _dragItem)
                {
                    LegendBox boxOverLine;
                    int       left      = 0;
                    LegendBox container = BoxFromItem(_dragTarget.Item.GetValidContainerFor(_dragItem.Item));
                    if (container != null)
                    {
                        left = (container.Indent + 1) * Indentation;
                    }
                    if (_dragTarget.Item.CanReceiveItem(_dragItem.Item))
                    {
                        boxOverLine = _dragTarget;
                    }
                    else
                    {
                        boxOverLine = BoxFromItem(_dragTarget.Item.BottomMember());
                    }
                    if (boxOverLine == null)
                    {
                        _previousLine = Rectangle.Empty;
                        Cursor        = Cursors.No;
                        cursorHandled = true;
                    }
                    else
                    {
                        _previousLine = new Rectangle(left, boxOverLine.Bounds.Bottom, Width - left, 4);
                        Cursor        = Cursors.Hand;
                        cursorHandled = true;
                        Invalidate(_previousLine);
                    }
                }
                if (cursorHandled == false)
                {
                    Cursor        = Cursors.No;
                    cursorHandled = true;
                }
            }
            if (cursorHandled == false)
            {
                Cursor = Cursors.Arrow;
            }
            base.OnMouseMove(e);
        }
Пример #13
0
        /// <summary>
        /// Draws the legend item from the DrawLegendItemArgs with all its child items.
        /// </summary>
        /// <param name="e">DrawLegendItemArgs that are needed to draw the legend item.</param>
        /// <returns>The position where the next LegendItem can be drawn.</returns>
        protected virtual PointF OnInitializeItem(DrawLegendItemArgs e)
        {
            if (e.Item.LegendItemVisible == false)
            {
                return(e.TopLeft);
            }

            UpdateActions(e.Item);

            PointF topLeft     = e.TopLeft;
            PointF tempTopLeft = topLeft;

            if (topLeft.Y > ControlRectangle.Bottom)
            {
                return(topLeft); // drawing would be below the screen
            }
            if (topLeft.Y > ControlRectangle.Top - ItemHeight)
            {
                // Draw the item itself
                // Point tl = new Point((int)topLeft.X, (int)topLeft.Y);
                var itemBox = new LegendBox();
                _legendBoxes.Add(itemBox);
                itemBox.Item   = e.Item;
                itemBox.Bounds = new Rectangle(0, (int)topLeft.Y, Width, ItemHeight);
                itemBox.Indent = (int)topLeft.X / Indentation;

                DrawPlusMinus(e.Graphics, ref tempTopLeft, itemBox);

                int ih = ItemHeight;

                if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
                {
                    Size s = e.Item.GetLegendSymbolSize();
                    if (s.Height > ih)
                    {
                        tempTopLeft.Y += 3;
                    }
                }
                if (e.Item.LegendSymbolMode == SymbolMode.Symbol || e.Item.LegendSymbolMode == SymbolMode.GroupSymbol)
                {
                    DrawSymbol(e.Graphics, ref tempTopLeft, itemBox);
                }

                if (e.Item.LegendSymbolMode == SymbolMode.Checkbox)
                {
                    DrawCheckBoxes(e.Graphics, ref tempTopLeft, itemBox);
                }

                int width = (int)e.Graphics.MeasureString(e.Item.LegendText, Font).Width;
                int dY    = 0;
                if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
                {
                    Size s = e.Item.GetLegendSymbolSize();
                    if (s.Height > ih)
                    {
                        dY = (s.Height - ih) / 2;
                    }
                    tempTopLeft.Y += dY;
                }
                tempTopLeft.Y += (ih - Font.Height) / (float)2;

                itemBox.Textbox = new Rectangle((int)tempTopLeft.X, (int)topLeft.Y + dY, width, ItemHeight);
                if (itemBox.Item.IsSelected)
                {
                    _selection.Add(itemBox.Item);
                    Rectangle innerBox = itemBox.Textbox;
                    innerBox.Inflate(-1, -1);
                    using (var b = HighlightBrush(innerBox))
                    {
                        e.Graphics.FillRectangle(b, innerBox);
                    }

                    SymbologyGlobal.DrawRoundedRectangle(e.Graphics, _highlightBorderPen, itemBox.Textbox);
                    e.Graphics.DrawString(e.Item.LegendText, Font, _selectionFontBrush, tempTopLeft);
                }
                else
                {
                    e.Graphics.DrawString(e.Item.LegendText, Font, Brushes.Black, tempTopLeft);
                }
            }
            int h = ItemHeight;

            if (e.Item.LegendSymbolMode == SymbolMode.Symbol)
            {
                Size s = e.Item.GetLegendSymbolSize();
                if (s.Height > h)
                {
                    h = s.Height + 6;
                }
            }
            topLeft.Y += h;

            if (e.Item.IsExpanded)
            {
                topLeft.X += Indentation;
                if (e.Item.LegendItems != null)
                {
                    List <ILegendItem> items = e.Item.LegendItems.ToList();
                    if (e.Item is IGroup)
                    {
                        items.Reverse();                   // reverse layers because of drawing order, don't bother reversing categories.
                    }
                    foreach (var item in items)
                    {
                        var args = new DrawLegendItemArgs(e.Graphics, item, e.ClipRectangle, topLeft);
                        topLeft = OnInitializeItem(args);
                        if (topLeft.Y > ControlRectangle.Bottom)
                        {
                            break;
                        }
                    }
                }
                topLeft.X -= Indentation;
            }
            return(topLeft);
        }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ItemMouseEventArgs"/> class from an existing MouseEventArgs.
 /// </summary>
 /// <param name="args">The existing arguments</param>
 /// <param name="inItemBox">A LegendBox for comparison</param>
 public ItemMouseEventArgs(MouseEventArgs args, LegendBox inItemBox)
     : base(args.Button, args.Clicks, args.X, args.Y, args.Delta)
 {
     ItemBox = inItemBox;
 }
Пример #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ItemMouseEventArgs"/> class.
 /// </summary>
 /// <param name="inButton">The Mouse Buttons</param>
 /// <param name="inClicks">The number of clicks</param>
 /// <param name="inX">The X coordinate</param>
 /// <param name="inY">The Y coordinate</param>
 /// <param name="inDelta">The delta of the mouse wheel</param>
 /// <param name="inItemBox">A LegendBox for comparision</param>
 public ItemMouseEventArgs(MouseButtons inButton, int inClicks, int inX, int inY, int inDelta, LegendBox inItemBox)
     : base(inButton, inClicks, inX, inY, inDelta)
 {
     ItemBox = inItemBox;
 }