public override void MouseDown(MouseEventArgs e, System.Drawing.Point location)
        {
            if (!docView.EditPermission)
            {
                return;
            }
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            int pageNum = docView.GetPageByCoord(location);

            if (!captured && pageNum == -1)
            {
                return;
            }

            if (!captured) // first click, start point
            {
                captured     = true;
                capturedPage = pageNum;

                // create initial rectangle
                Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, capturedPage);
                Datalogics.PDFL.Rect  rect     = new Datalogics.PDFL.Rect(pdfPoint.H - 1, pdfPoint.V - 1, pdfPoint.H, pdfPoint.V);

                properties.BoundingRect = rect;
                BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties);

                capturedGuide = editor.Guides[2]; // guide: bottom-right corner of rectangle
                docView.Invalidate();
            }
        }
        public override void MouseDown(MouseEventArgs e, System.Drawing.Point location)
        {
            if (!docView.EditPermission)
            {
                return;
            }
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            int pageNum = docView.GetPageByCoord(location);

            if (!captured && pageNum == -1)
            {
                return;
            }

            if (!captured) // first click, add start & end points, stick end-point to cursor
            {
                captured     = true;
                capturedPage = pageNum;

                // create 2 initial points
                pointCount = 2;

                IList <Datalogics.PDFL.Point> vertices = new List <Datalogics.PDFL.Point>();
                Datalogics.PDFL.Point         pdfPoint = docView.ViewToPdf(location, capturedPage);
                vertices.Add(pdfPoint);
                vertices.Add(pdfPoint); // end point is equal to start point

                Datalogics.PDFL.Rect rect = new Datalogics.PDFL.Rect(pdfPoint.H, pdfPoint.V, pdfPoint.H, pdfPoint.V);

                properties.BoundingRect = rect;
                properties.Vertices     = vertices;
                BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties);
                capturedGuide = editor.Guides[9]; // endpoint guide
                docView.Invalidate();
            }
            else // every next click - add new point
            {
                Datalogics.PDFL.Point newVertex = docView.ViewToPdf(location, capturedPage);
                ++pointCount;
                Page page = docView.Document.GetPage(capturedPage);
                BaseAnnotationEditor          editor   = docView.ActiveAnnotation;
                IList <Datalogics.PDFL.Point> vertices = editor.Properties.Vertices;
                vertices.Add(newVertex);
                editor.Properties.Vertices = vertices;
                capturedGuide = editor.Guides[8 + pointCount - 1];
                docView.Invalidate();
            }
        }
Example #3
0
        /**
         * Creates annotation editor class by given annotation info
         */
        public static BaseAnnotationEditor CreateAnnotationEditor(Document doc, Page page, int index)
        {
            Annotation ann = page.GetAnnotation(index);

            System.Drawing.Color underlineSelectionColor = System.Drawing.Color.FromArgb(128, 0, 0, 128);
            System.Drawing.Color highlightSelectionColor = System.Drawing.Color.FromArgb(128, 0, 128, 0);
            BaseAnnotationEditor editor = null;

            switch (ann.Subtype)
            {
            case "Circle": editor = new CircleAnnotationEditor(); break;

            case "Square": editor = new SquareAnnotationEditor(); break;

            case "Line": editor = new LineAnnotationEditor(); break;

            case "PolyLine": editor = new PolyLineAnnotationEditor(); break;

            case "Polygon": editor = new PolygonAnnotationEditor(); break;

            case "Link": editor = new LinkAnnotationEditor(); break;

            case "Ink": editor = new InkAnnotationEditor(); break;

            case "Underline": editor = new MarkupAnnotationEditor(underlineSelectionColor); break;

            case "Highlight": editor = new MarkupAnnotationEditor(highlightSelectionColor); break;

            case "FreeText": editor = new FreeTextAnnotationEditor(); break;

            default: editor = new BaseAnnotationEditor(); break;
            }

            if (editor != null)
            {
                editor.Init(doc, page, ann, index);
            }
            return(editor);
        }
        public override void MouseDown(MouseEventArgs e, System.Drawing.Point location)
        {
            int pageNum = docView.GetPageByCoord(location);

            if (!captured && pageNum == -1)
            {
                return;
            }
            if (!captured)
            {
                captured     = true;
                capturedPage = pageNum;
                Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, pageNum);
                Datalogics.PDFL.Rect  rect     = new Datalogics.PDFL.Rect(pdfPoint.H - 1, pdfPoint.V - 1, pdfPoint.H, pdfPoint.V);

                properties.BoundingRect = rect;
                BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties);

                capturedGuide = editor.Guides[2]; // guide: bottom-right corner of rectangle
                docView.Invalidate();
            }
            done = true;
        }
        public override void MouseDown(MouseEventArgs e, System.Drawing.Point location)
        {
            if (!docView.EditPermission)
            {
                return;
            }
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            int pageNum = docView.GetPageByCoord(location);

            if (!captured && pageNum == -1)
            {
                return;
            }

            if (!captured) // first click, put start point, stick endpoint to cursor
            {
                captured     = true;
                capturedPage = pageNum;

                Datalogics.PDFL.Point pdfStartPoint = docView.ViewToPdf(location, pageNum);
                Datalogics.PDFL.Point pdfEndPoint   = new Point(pdfStartPoint.H + 1, pdfStartPoint.V + 1);
                Datalogics.PDFL.Rect  rect          = new Datalogics.PDFL.Rect(pdfStartPoint.H, pdfStartPoint.V, pdfEndPoint.H, pdfEndPoint.V);

                properties.BoundingRect = rect;
                properties.StartPoint   = pdfStartPoint;
                properties.EndPoint     = pdfEndPoint;
                BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties);

                capturedGuide = editor.Guides[1]; // endpoint guide
                docView.Invalidate();
            }
        }
        /**
         * Double click handler. Used only for FreeText annotation editing: opens annotation's rich text box.
         */
        public override void MouseDoubleClick(MouseEventArgs e, System.Drawing.Point location)
        {
            if (!docView.EditPermission)
            {
                return;
            }

            BaseAnnotationEditor editor = docView.ActiveAnnotation;

            if (editor == null)
            {
                return;
            }
            switch (editor.Properties.Subtype)
            {
            // we have clicked on free text annotation: create rich text box
            case "FreeText": CreateRichTextBox(); return;

            // we have clicked on link annotation: switch to target view mode to select link target
            case "Link":
                docView.FunctionMode = ApplicationFunctionMode.TargetMode;
                return;
            }
        }
        /**
         * Mouse up handler.
         * All annotation transformation is performed in mouse move handler.
         * This handler is for context menu calls, and for finishing annotation tracking.
         */
        public override void MouseUp(MouseEventArgs e, System.Drawing.Point location)
        {
            captured = false;
            if (!docView.EditPermission)
            {
                return;
            }

            if (e.Button == MouseButtons.Right)
            {
                if (docView.ActiveAnnotation != null)
                {
                    ContextMenu currentContextMenu = null;

                    switch (docView.ActiveAnnotation.Properties.Subtype)
                    {
                    case "FreeText":
                        currentContextMenu = textAnnotationContextMenu;
                        break;

                    case "Link":
                        currentContextMenu = linkAnnotationContextMenu;
                        break;

                    default:
                        currentContextMenu = shapeAnnotationContextMenu;
                        break;
                    }
                    if (currentContextMenu != null)
                    {
                        UpdateMenuItems(currentContextMenu);
                        currentContextMenu.Show(docView.Parent, e.Location);
                    }
                }
            }
            else
            {
                docView.EditCheckPoint();
                if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control && (docView.ActiveAnnotation != null || cachedIndex != -1))
                {
                    BaseAnnotationEditor editor = docView.EditAnnotations[cachedIndex];
                    if (editor is LinkAnnotationEditor)
                    {
                        LinkAnnotation annot = editor.Annotation as LinkAnnotation;
                        if (annot.Action is URIAction)
                        {
                            URIAction act = annot.Action as URIAction;
                            System.Diagnostics.Process.Start(act.URI);
                        }
                        else if (annot.Action is RemoteGoToAction)
                        {
                            RemoteGoToAction  action = annot.Action as RemoteGoToAction;
                            FileSpecification spec   = action.FileSpecification;

                            string fullPath = System.IO.Path.GetFullPath(spec.Path);
                            if (System.IO.File.Exists(fullPath))
                            {
                                System.Diagnostics.Process.Start(fullPath);
                            }
                        }
                        else if (annot.Action is GoToAction || annot.Destination != null)
                        {
                            GoToAction      action = (annot.Action as GoToAction);
                            ViewDestination dest   = action == null ? annot.Destination : action.Destination;

                            if (dest != null)
                            {
                                docView.GoToDestionation(dest);
                            }
                        }
                    }
                }
            }
        }
        /**
         * Mouse move handler, tracks a guide rect movings.
         */
        public override void MouseMove(MouseEventArgs e, System.Drawing.Point location)
        {
            // if no annotation is currently selected then just drag view like in ScrollViewMode
            if (captured && docView.ActiveAnnotation == null)
            {
                // drag page like in ScrollViewMode
                System.Drawing.Point delta = location;
                delta.X -= capturedPoint.X;
                delta.Y -= capturedPoint.Y;
                System.Drawing.Point scroll = docView.Scroll;
                scroll.X      -= delta.X;
                scroll.Y      -= delta.Y;
                docView.Scroll = scroll;
                docView.Cursor = Cursors.Default;
                return;
            }

            if (!docView.EditPermission ||
                docView.EditPage == -1 ||
                docView.EditAnnotations == null ||
                docView.EditAnnotations.Count == 0)
            {
                docView.Cursor = Cursors.Default;
                return;
            }

            // calculate pdf coordinate on the page
            Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, docView.EditPage);

            // left mouse button dragging: move or resize annotation
            if (e.Button == MouseButtons.Left && docView.ActiveAnnotation != null)
            {
                if (capturedGuide != null) // if guide is selected - move it
                {
                    Datalogics.PDFL.Point newGuideLocation = new Datalogics.PDFL.Point(pdfPoint.H + capturedOffset.H, pdfPoint.V + capturedOffset.V);
                    capturedGuide  = docView.MoveGuide(capturedGuide, newGuideLocation);
                    docView.Cursor = capturedGuide.CursorForRotation(docView.Document.GetPage(docView.EditPage).Rotation);
                }
                else // if no guides is selected - move the whole annotation
                {
                    if (capturedPoint.Equals(location))
                    {
                        return;
                    }
                    Datalogics.PDFL.Point  oldPdfPoint = docView.ViewToPdf(capturedPoint, docView.EditPage);
                    Datalogics.PDFL.Matrix matrix      = new Datalogics.PDFL.Matrix()
                                                         .Translate(pdfPoint.H - oldPdfPoint.H, pdfPoint.V - oldPdfPoint.V);
                    capturedPoint = location;
                    docView.TransformAnnotation(matrix);
                    docView.Cursor = Cursors.Hand;
                }
                docView.IsDocumentChanged = true;
                return;
            }

            // no left mouse button down, just process cursor
            int index = FindAnnotation(pdfPoint, cachedIndex);

            if (index == -1)
            {
                docView.HoverAnnotation = null;
                docView.Cursor          = Cursors.Default;
            }
            else // when no mouse dragging, we track annotation under cursor just to draw it's bounding rectangle
            {
                BaseAnnotationEditor anno = docView.EditAnnotations[index];
                Hit hit = anno.TestHit(pdfPoint);
                if (anno == docView.ActiveAnnotation && (hit.flags & HitFlags.GuideHit) != 0)
                {
                    docView.Cursor = hit.guide.CursorForRotation(docView.Document.GetPage(docView.EditPage).Rotation);
                }
                else if ((hit.flags & (HitFlags.BorderHit | HitFlags.RectHit)) != 0)
                {
                    docView.Cursor = Cursors.Hand;
                }
                else
                {
                    docView.Cursor = Cursors.Default;
                }
                docView.HoverAnnotation = anno;
            }
        }