Exemple #1
0
        /// <summary>
        /// Performs custom actions on adaptable control MouseMove events; base method should
        /// be called first</summary>
        /// <param name="sender">Adaptable control</param>
        /// <param name="e">Mouse event args</param>
        protected override void OnMouseMove(object sender, MouseEventArgs e)
        {
            base.OnMouseMove(sender, e);

            if (e.Button == MouseButtons.None)
            {
                AnnotationHitEventArgs hitRecord = Pick(CurrentPoint);
                if ((hitRecord.Annotation != null && hitRecord.Label == null) &&
                    AdaptedControl.Cursor == Cursors.Default)
                {
                    AdaptedControl.Cursor = Cursors.SizeAll;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Performs hit test for a point, in client coordinates</summary>
        /// <param name="p">Pick point, in client coordinates</param>
        /// <returns>Hit record for a point, in client coordinates</returns>
        DiagramHitRecord IPickingAdapter2.Pick(Point p)
        {
            if (m_annotatedDiagram != null && !PickingDisabled)
            {
                if (m_transformAdapter != null)
                    p = GdiUtil.InverseTransform(m_transformAdapter.Transform, p);

                foreach (IAnnotation annotation in m_annotatedDiagram.Annotations.Reverse())
                {

                    TextEditor textEditor;
                    m_annotationEditors.TryGetValue(annotation, out textEditor);
                    Rectangle bounds = GetBounds(annotation);
                    if (bounds.IsEmpty && textEditor == null)
                        continue;
                    var inflated = bounds;
                    int tolerance = m_theme.PickTolerance;
                    inflated.Inflate(tolerance, tolerance);

                    if (!inflated.Contains(p)) continue;

                    Rectangle contentRect = bounds;
                    contentRect.X += Margin.Left;
                    contentRect.Y += Margin.Right;
                    contentRect.Size -= Margin.Size;
                    if (contentRect.Contains(p))
                    {
                        
                        // check scroll bar
                        if (textEditor != null && textEditor.VerticalScrollBarVisibe)
                        {
                            var scrollbarRect = new Rectangle(bounds.Right - Margin.Right - ScrollBarWidth - 2 * ScrollBarMargin, bounds.Y,
                                ScrollBarWidth + 2 * ScrollBarMargin, bounds.Height);
                            if (scrollbarRect.Contains(p))
                                return new AnnotationHitEventArgs(annotation, new DiagramScrollBar(annotation, Orientation.Vertical));
                        }

                        //var textBounds = new Rectangle(contentRect.X, contentRect.Y,
                        //    contentRect.Width, contentRect.Height);

                        var textBounds = contentRect;
                        DiagramLabel label = new DiagramLabel(textBounds, TextFormatFlags.LeftAndRightPadding);

                        PointF origin = textEditor != null ?
                            new PointF(contentRect.X, contentRect.Y - textEditor.GetLineYOffset(textEditor.TopLine))
                        : contentRect.Location;
                        var result = new AnnotationHitEventArgs(annotation, label);
                        result.Position = new PointF(p.X - origin.X, p.Y - origin.Y);
                        return result;
                    }

                    //// check titlebar
                    //var titlebarRect = new RectangleF(bounds.Left + 2 * tolerance, bounds.Y - tolerance,
                    //    bounds.Width - 4 * tolerance, Margin.Top + tolerance);
                    //if (titlebarRect.Contains(p))
                    //{
                    //    return new AnnotationHitEventArgs(annotation, new DiagramTitleBar(annotation));
                    //}

                    // margin between inflated bounds and content bound.
                    int leftPad = contentRect.X - inflated.X;
                    int rightPad = inflated.Right - contentRect.Right;
                    int topPad = contentRect.Y - inflated.Y;
                    int bottomPad = inflated.Bottom - contentRect.Bottom;


                    // lower right
                    var corner = new Rectangle(contentRect.Right, contentRect.Bottom, rightPad, bottomPad);
                    if (corner.Contains(p))
                    {
                        var borderPart = new DiagramBorder(annotation)
                        {
                            Border = DiagramBorder.BorderType.LowerRightCorner
                        };
                        return new AnnotationHitEventArgs(annotation, borderPart);
                    }

                    
                    // upper left
                    corner = new Rectangle(inflated.X, inflated.Y, leftPad, topPad);
                    if (corner.Contains(p))
                    {
                        var borderPart = new DiagramBorder(annotation)
                        {
                            Border = DiagramBorder.BorderType.UpperLeftCorner
                        };
                        return new AnnotationHitEventArgs(annotation, borderPart);
                    }

                    
                    // upper right
                    corner = new Rectangle(contentRect.Right, inflated.Y, rightPad, topPad);
                    if (corner.Contains(p))
                    {
                        var borderPart = new DiagramBorder(annotation)
                        {
                            Border = DiagramBorder.BorderType.UpperRightCorner
                        };
                        return new AnnotationHitEventArgs(annotation, borderPart);
                    }

                    // lower left.
                    corner = new Rectangle(inflated.X, contentRect.Bottom, leftPad, bottomPad);
                    if (corner.Contains(p))
                    {
                        var borderPart = new DiagramBorder(annotation)
                        {
                            Border = DiagramBorder.BorderType.LowerLeftCorner
                        };
                        return new AnnotationHitEventArgs(annotation, borderPart);
                    }


                    // right border.
                    if (p.X >= contentRect.Right)
                    {
                        var borderPart = new DiagramBorder(annotation)
                        {
                            Border = DiagramBorder.BorderType.Right
                        };
                        return new AnnotationHitEventArgs(annotation, borderPart);
                    }
                    // bottom border
                    if (p.Y >= contentRect.Bottom)
                    {
                        var borderPart = new DiagramBorder(annotation)
                        {
                            Border = DiagramBorder.BorderType.Bottom
                        };
                        return new AnnotationHitEventArgs(annotation, borderPart);
                    }

                    // left border
                    if (p.X <= contentRect.X)
                    {
                        var borderPart = new DiagramBorder(annotation)
                        {
                            Border = DiagramBorder.BorderType.Left
                        };
                        return new AnnotationHitEventArgs(annotation, borderPart);
                    }


                    // top border
                    if (p.Y <= contentRect.Y)
                    {
                        var borderPart = new DiagramBorder(annotation)
                        {
                            Border = DiagramBorder.BorderType.Top
                        };
                        return new AnnotationHitEventArgs(annotation, borderPart);

                    }                
                }
            }

            return new AnnotationHitEventArgs();
        }
        /// <summary>
        /// Performs a pick operation on the diagram annotations</summary>
        /// <param name="p">Picking point</param>
        /// <returns>Information about which annotation, if any, was hit by point</returns>
        public AnnotationHitEventArgs Pick(Point p)
        {           
            if (m_annotatedDiagram != null)
            {
                if (m_transformAdapter != null)
                   p = GdiUtil.InverseTransform(m_transformAdapter.Transform, p);

                foreach (IAnnotation annotation in m_annotatedDiagram.Annotations.Reverse())
                {
                    Rectangle bounds = GetBounds(annotation);
                    if (bounds.IsEmpty)
                        continue;
                    var inflated = bounds;
                    int tolerance = m_theme.PickTolerance;
                    inflated.Inflate(tolerance, tolerance);
                    if (inflated.Contains(p) && m_annotationEditors.ContainsKey(annotation))
                    {
                        // check titlebar
                        var titlebarRect = new RectangleF(bounds.Left + 2 * tolerance, bounds.Y - tolerance,
                            bounds.Width -  4 * tolerance, Margin.Top + tolerance);
                        if (titlebarRect.Contains(p))
                        {                          
                            return new AnnotationHitEventArgs(annotation, new DiagramTitleBar(annotation));
                        }

                        var annotationData = m_annotationEditors[annotation];
                        // check scroll bar
                        if (annotationData.VerticalScrollBarVisibe)
                        {
                            var scrollbarRect = new RectangleF(bounds.Right - Margin.Right - ScrollBarWidth - 2 * ScrollBarMargin, bounds.Y,
                                ScrollBarWidth + 2 * ScrollBarMargin, bounds.Height);
                            if (scrollbarRect.Contains(p))
                                return new AnnotationHitEventArgs(annotation, new DiagramScrollBar(annotation, Orientation.Vertical));
                        }
                       

                        // check borders
                        // check corners first
                        var border = new RectangleF(bounds.Right - 2 * tolerance, bounds.Bottom - 2 * tolerance, 4 * tolerance, 4 * tolerance);
                        if (border.Contains(p))
                        {
                            var borderPart = new DiagramBorder(annotation)
                            {
                                Border = DiagramBorder.BorderType.LowerRightCorner
                            };
                            return new AnnotationHitEventArgs(annotation, borderPart);
                        }

                        border = new RectangleF(bounds.Left - 2 * tolerance, bounds.Top - 2 * m_theme.PickTolerance, 4 * tolerance, 4 * tolerance);
                        if (border.Contains(p))
                        {
                            var borderPart = new DiagramBorder(annotation)
                            {
                                Border = DiagramBorder.BorderType.UpperLeftCorner
                            };
                            return new AnnotationHitEventArgs(annotation, borderPart);
                        }

                        border = new RectangleF(bounds.Right - 2 * m_theme.PickTolerance, bounds.Top - 2 * m_theme.PickTolerance, 4 * tolerance, 4 * tolerance);
                        if (border.Contains(p))
                        {
                            var borderPart = new DiagramBorder(annotation)
                            {
                                Border = DiagramBorder.BorderType.UpperRightCorner
                            };
                            return new AnnotationHitEventArgs(annotation, borderPart);
                        }

                        border = new RectangleF(bounds.Left - 2 * m_theme.PickTolerance, bounds.Bottom - 2 * m_theme.PickTolerance, 4 * tolerance, 4 * tolerance);
                        if (border.Contains(p))
                        {
                            var borderPart = new DiagramBorder(annotation)
                            {
                                Border = DiagramBorder.BorderType.LowerLeftCorner
                            };
                            return new AnnotationHitEventArgs(annotation, borderPart);
                        }

                        border = new RectangleF(bounds.Left - m_theme.PickTolerance, bounds.Y, 2 * m_theme.PickTolerance, bounds.Height);
                        if (border.Contains(p))
                        {
                            var borderPart = new DiagramBorder(annotation)
                                {
                                    Border = DiagramBorder.BorderType.Left
                                };
                            return new AnnotationHitEventArgs(annotation, borderPart);
                        }
                        border.Offset(bounds.Width, 0);
                        if (border.Contains(p))
                        {
                            var borderPart = new DiagramBorder(annotation)
                                {
                                    Border = DiagramBorder.BorderType.Right
                                };
                            return new AnnotationHitEventArgs(annotation, borderPart);
                        }
                        border = new RectangleF(bounds.Left, bounds.Y - m_theme.PickTolerance, bounds.Width, 2 * m_theme.PickTolerance);
                        if (border.Contains(p))
                        {
                            var borderPart = new DiagramBorder(annotation)
                                {
                                    Border = DiagramBorder.BorderType.Top
                                };
                            return new AnnotationHitEventArgs(annotation, borderPart);
                        }
                        border.Offset(0, bounds.Height);
                        if (border.Contains(p))
                        {
                            var borderPart = new DiagramBorder(annotation)
                                {
                                    Border = DiagramBorder.BorderType.Bottom
                                };
                            return new AnnotationHitEventArgs(annotation, borderPart);
                        }

                        // check label
                        inflated.Inflate(tolerance, tolerance);
                        DiagramLabel label = null;
                        if (inflated.Contains(p))
                        {
                            var textBounds = new Rectangle(bounds.X + Margin.Left, bounds.Y + Margin.Top,
                                (int)annotationData.TextLayout.LayoutWidth + SystemInformation.VerticalScrollBarWidth, (int)annotationData.TextLayout.LayoutHeight);
                            label = new DiagramLabel(textBounds, TextFormatFlags.LeftAndRightPadding);

                            // set initial editing position
                            var contentBounds = new RectangleF(bounds.X + Margin.Left, bounds.Y + Margin.Top,
                                               bounds.Width - Margin.Size.Width, bounds.Height - Margin.Size.Height);
                            contentBounds.Width = Math.Max(contentBounds.Width, MinimumWidth);
                            contentBounds.Height = Math.Max(contentBounds.Height, MinimumHeight);

                            PointF origin = new PointF(contentBounds.Location.X, contentBounds.Location.Y - annotationData.TopLine * m_theme.TextFormat.FontHeight);
                            var result = new AnnotationHitEventArgs(annotation, label);
                            result.Position = new PointF(p.X - origin.X, p.Y - origin.Y);
                            return result;
                            
                        }
                                                
                        
                    }
                }
            }

            return new AnnotationHitEventArgs();
        }
Exemple #4
0
 /// <summary>
 /// Pick using all bound IPickingAdapter2s</summary>        
 private AnnotationHitEventArgs PickAll(Point p)
 {
     DiagramHitRecord hitRecord = null;
     if (AdaptedControl.Context != null)
     {
         foreach (IPickingAdapter2 pickingAdapter in m_pickingAdapters)
         {
             hitRecord = pickingAdapter.Pick(p);
             if (hitRecord != null && hitRecord.Item != null)
                 break;
         }
     }
     AnnotationHitEventArgs annotHit = hitRecord as AnnotationHitEventArgs;
     if (annotHit == null) annotHit = new AnnotationHitEventArgs();
     return annotHit;
 }