private void DoItemMouseUp(ItemMouseEventArgs e) { Point loc = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top); if (e.Button == MouseButtons.Left) { if (e.ItemBox.Item.LegendSymbolMode == SymbolModes.Checkbox) { if (e.ItemBox.CheckBox.Contains(loc)) { IRenderableLegendItem rendItem = e.ItemBox.Item as IRenderableLegendItem; if (rendItem != null) { // force a re-draw in the case where we are talking about layers. rendItem.IsVisible = !rendItem.IsVisible; } else { e.ItemBox.Item.Checked = !e.ItemBox.Item.Checked; } if (CheckBoxMouseUp != null) CheckBoxMouseUp(this, e); IsInitialized = false; Invalidate(); } } if (e.ItemBox.Textbox.Contains(loc)) { if (e.ItemBox == _previousMouseDown) { _isDragging = false; // Edit via text box _editBox.Left = e.ItemBox.Textbox.Left; _editBox.Width = e.ItemBox.Textbox.Width + 10; _editBox.Top = e.ItemBox.Bounds.Top; _editBox.Height = e.ItemBox.Bounds.Height; _editBox.SelectedText = e.ItemBox.Item.LegendText; _editBox.Font = Font; _editBox.Visible = true; } } } if (e.Button == MouseButtons.Right) { if (e.ItemBox.Item.ContextMenuItems == null) return; foreach (MenuItem mi in e.ItemBox.Item.ContextMenuItems) { _contextMenu.MenuItems.Add(mi); } _contextMenu.Show(this, e.Location); _contextMenu.MenuItems.Clear(); } }
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; } } }
/// <summary> /// Fires the ItemMouseMove Event, which handles the mouse moving over one of the legend items. /// </summary> /// <param name="e">An ItemMouseEventArgs</param> protected virtual void OnItemMouseMove(ItemMouseEventArgs e) { if (ItemMouseMove != null) ItemMouseMove(this, e); }
private void DoItemMouseMove(ItemMouseEventArgs e) { OnItemMouseMove(e); }
/// <summary> /// The coordinates are in legend coordinates, but a LegendBox is provided to define the /// coordinates of the specified object. /// </summary> /// <param name="e">An ItemMouseEventArgs</param> protected virtual void OnItemMouseDown(ItemMouseEventArgs e) { if (ItemMouseDown != null) ItemMouseDown(this, e); }
/// <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); }
/// <summary> /// Checks for checkbox changes and fires the ItemMouseUp event. /// </summary> /// <param name="e"></param> protected virtual void OnItemMouseUp(ItemMouseEventArgs e) { if (ItemMouseUp != null) ItemMouseUp(this, e); }
/// <summary> /// Checks the Mouse Up event to see if it occurs inside a legend item. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(MouseEventArgs e) { Point loc = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top); if (!_wasDoubleClick) { foreach (LegendBox box in _legendBoxes) { if (!box.Bounds.Contains(loc)) continue; ItemMouseEventArgs args = new ItemMouseEventArgs(e, box); DoItemMouseUp(args); } } if (_isDragging && _dragItem != null) { if (_dragTarget != null && _dragTarget.Item != _dragItem.Item) { ILegendItem potentialParent = _dragTarget.Item.GetValidContainerFor(_dragItem.Item); if (potentialParent != null) { potentialParent.ParentMapFrame().SuspendEvents(); // A dragable container must be a group, and the item must be a layer. ILayer lyr = _dragItem.Item as ILayer; if (lyr != null) { IGroup grp = _dragItem.Item.GetParentItem() as IGroup; if (grp != null) grp.Remove(lyr); int index = _dragTarget.Item.InsertIndex(_dragItem.Item); if (index == -1) index = 0; grp = potentialParent as IGroup; if (grp != null) grp.Insert(index, lyr); } potentialParent.ParentMapFrame().ResumeEvents(); OnOrderChanged(); } } Cursor = Cursors.Arrow; _isDragging = false; Invalidate(); } _wasDoubleClick = false; base.OnMouseUp(e); }
/// <summary> /// Handles the case where the mouse down occurs. /// </summary> /// <param name="e">A MouseEventArgs</param> protected override void OnMouseDown(MouseEventArgs e) { HideEditBox(); if (_legendBoxes == null || _legendBoxes.Count == 0) return; Point loc = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top); foreach (LegendBox box in _legendBoxes) { if (box.Bounds.Contains(loc)) { ItemMouseEventArgs args = new ItemMouseEventArgs(e, box); DoItemMouseDown(args); } } base.OnMouseDown(e); }