Esempio n. 1
0
        protected XDrawPagesSupplier UseDraw()
        {
            try
            {
                //create new draw document and insert rectangle shape
                XComponent         xDrawComponent     = NewDocComponent("sdraw");
                XDrawPagesSupplier xDrawPagesSupplier = xDrawComponent as XDrawPagesSupplier;

                Object       drawPages         = xDrawPagesSupplier.getDrawPages();
                XIndexAccess xIndexedDrawPages = drawPages as XIndexAccess;

                Object drawPage = xIndexedDrawPages.getByIndex(0).Value;

                System.Diagnostics.Debug.WriteLine(xIndexedDrawPages.getCount());

                if (drawPage is XDrawPage)
                {
                    XDrawPage xDrawPage = (XDrawPage)drawPage;

                    if (xDrawPage is XComponent)
                    {
                        (xDrawPage as XComponent).addEventListener(new TestOOoEventListerner());
                    }

                    // get internal service factory of the document
                    XMultiServiceFactory xDrawFactory = xDrawComponent as XMultiServiceFactory;

                    Object drawShape = xDrawFactory.createInstance(
                        "com.sun.star.drawing.RectangleShape");
                    XShape xDrawShape = drawShape as XShape;
                    xDrawShape.setSize(new Size(10000, 20000));
                    xDrawShape.setPosition(new Point(5000, 5000));
                    xDrawPage.add(xDrawShape);

                    // XText xShapeText = (XText)drawShape // COMMENTED BY CODEIT.RIGHT;
                    XPropertySet xShapeProps = (XPropertySet)drawShape;

                    // wrap text inside shape
                    xShapeProps.setPropertyValue("TextContourFrame", new uno.Any(true));
                    return(xDrawPagesSupplier);
                }
                else
                {
                    //TODO: handle if no drwapage was found
                    System.Diagnostics.Debug.WriteLine("no XDrawPage found");
                    System.Diagnostics.Debug.WriteLine(drawPage);
                }
            }
            catch (unoidl.com.sun.star.lang.DisposedException e)
            { //works from Patch 1
                MXContext = null;
                throw e;
            }

            return(null);
        }
Esempio n. 2
0
        private System.Timers.Timer refreshPagePropertiesTimer;  // e.g. every 2.5s

        #endregion
        #endregion

        #region Constructor / Destructor

        /// <summary>
        /// Initializes a new instance of the <see cref="OoDrawPageObserver"/> class.
        /// </summary>
        /// <param name="dp">The DOM page object to observe</param>
        /// <param name="parent">The parent obeserver for all pages in this DRAW document.</param>
        public OoDrawPageObserver(XDrawPage dp, OoDrawPagesObserver parent)
            : base()
        {
            Logger.Instance.Log(LogPriority.DEBUG, this, "Create new PageObserver");
            DrawPage      = dp;
            PagesObserver = parent;

            setAccessibleCounterpart();
            handleChildren();

            registerListeners();
        }
        private System.Timers.Timer refreshPagePropertiesTimer;  // e.g. every 2.5s

        #endregion
        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="OoDrawPageObserver"/> class.
        /// </summary>
        /// <param name="dp">The DOM page object to observe</param>
        /// <param name="parent">The parent obeserver for all pages in this DRAW document.</param>
        public OoDrawPageObserver(XDrawPage dp, OoDrawPagesObserver parent)
            : base()
        {
            Logger.Instance.Log(LogPriority.DEBUG, this, "Create new PageObserver");
            DrawPage = dp;
            PagesObserver = parent;

            setAccessibleCounterpart();
            handleChildren();

            registerListeners();

        }
        /// <summary>
        /// Gets the registered page observer to the DOM page object.
        /// </summary>
        /// <param name="dp">The DOM draw page.</param>
        /// <returns>The already registered page observer or register a new one and return it.</returns>
        internal OoDrawPageObserver GetRegisteredPageObserver(XDrawPage dp)
        {
            OoDrawPageObserver dpobs = null;

            if (dp != null)
            {
                if (DrawPageobservers.ContainsKey(dp))
                {
                    dpobs = DrawPageobservers[dp];
                }
                else
                {
                    dpobs = new OoDrawPageObserver(dp, this);
                    RegisterDrawPage(dpobs);
                }
            }
            return(dpobs);
        }
        /// <summary>
        /// Get a registered shape observer.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <returns>the already registered shape observer to the shape or <c>null</c></returns>
        internal OoShapeObserver GetRegisteredShapeObserver(XShape shape, OoDrawPageObserver page)
        {
            if (domshapes.ContainsKey(shape))
            {
                OoShapeObserver sobs = domshapes[shape];
                if (sobs != null && sobs.Shape == shape)
                {
                    return(sobs);
                }
            }

            String          name = OoUtils.GetStringProperty(shape, "Name");
            OoShapeObserver sObs = getRegisteredShapeObserver(name);

            if (sObs == null)
            {
                if (page == null)
                {
                    XDrawPage pageShape = OoDrawUtils.GetPageForShape(shape);
                    if (pageShape == null)
                    {
                        Logger.Instance.Log(LogPriority.DEBUG, this, "[EROR] Can't get page to requested NEW shape");
                        page = this.DocWnd.GetActivePage();
                    }
                    else
                    {
                        page = GetRegisteredPageObserver(pageShape as XDrawPage);
                    }
                }

                if (page != null)
                {
                    sObs = OoShapeObserverFactory.BuildShapeObserver(shape, page); //new OoShapeObserver(shape, page);
                    RegisterUniqueShape(sObs);
                }
            }

            if (sObs != null && sObs.Shape != shape)
            {
                sObs = RegisterNewShape(shape, page);
            }

            return(sObs);
        }
 /// <summary>
 /// Gets the registered page observer to the DOM page object.
 /// </summary>
 /// <param name="dp">The DOM draw page.</param>
 /// <returns>The already registered page observer or register a new one and return it.</returns>
 internal OoDrawPageObserver GetRegisteredPageObserver(XDrawPage dp)
 {
     OoDrawPageObserver dpobs = null;
     if (dp != null)
     {
         if (DrawPageobservers.ContainsKey(dp))
         {
             dpobs = DrawPageobservers[dp];
         }
         else
         {
             dpobs = new OoDrawPageObserver(dp, this);
             RegisterDrawPage(dpobs);
         }
     }
     return dpobs;
 }
 private List <Object> GetAllDrawShapesOnPage(XDrawPage xDrawPage)
 {
     return(GetAllObjectsFromXIndexAccess(xDrawPage as XIndexAccess) as List <Object>);
 }
 protected static List<Object> GetAllDrawShapesOnPage(XDrawPage xDrawPage)
 {
     return GetAllObjectsFromXIndexAccess(xDrawPage as XIndexAccess) as List<Object>;
 }
 /// <summary>
 /// Removes the page from drawing.
 /// </summary>
 /// <param name="drawDocXDrawPages">The draw doc X draw pages.</param>
 /// <param name="xDrawPage">The x draw page.</param>
 public static void RemovePageFromDrawing(XDrawPages drawDocXDrawPages, XDrawPage xDrawPage)
 {
     if (drawDocXDrawPages != null && xDrawPage != null)
     {
         drawDocXDrawPages.remove(xDrawPage);
     }
 }
 /// <summary>
 /// Removes the page from the drawing.
 /// </summary>
 /// <param name="drawDoc">The draw doc.</param>
 /// <param name="xDrawPage">The x draw page.</param>
 public static void RemovePageFromDrawing(Object drawDoc, XDrawPage xDrawPage)
 {
     XDrawPages xDrawPages = DrawDocGetXDrawPages(drawDoc);
     if (xDrawPages != null && xDrawPage != null)
     {
         xDrawPages.remove(xDrawPage);
     }
 }
        /// <summary>
        /// Gets the document position without screen position.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="drawView">The draw view.</param>
        /// <param name="coords1">The coords1.</param>
        /// <param name="coords2">The coords2.</param>
        internal static void GetDocumentPositionWithoutScreenPosition(XDrawPage page, XDrawView drawView, out Point coords1, out Point coords2)
        {
            var zoom = OoUtils.GetProperty(drawView, "ZoomValue");
            var viewOffset = OoUtils.GetProperty(drawView, "ViewOffset");
            var width = OoUtils.GetProperty(page, "Width");
            var height = OoUtils.GetProperty(page, "Height");

            double zoomInPercent = Int32.Parse(zoom.ToString());
            double pageHeight = Int32.Parse(height.ToString());
            double pageWidth = Int32.Parse(width.ToString());

            Point viewOffsetAsPoint = viewOffset is Point ? (Point)viewOffset : new Point(0, 0);
            double zoomFactor = (zoomInPercent / 100.0);

            double xZoomedOffset = zoomFactor * viewOffsetAsPoint.X;
            double yZoomedOffset = zoomFactor * viewOffsetAsPoint.Y;

            double x1 = Math.Abs(xZoomedOffset) + pageWidth / 3;
            double y1 = Math.Abs(yZoomedOffset) + pageHeight / 3;
            double x2 = Math.Abs(xZoomedOffset) + pageWidth * 2 / 3;
            double y2 = Math.Abs(yZoomedOffset) + pageHeight * 2 / 3;

            int xOffsetZoomed = (int)Math.Round(x1 + xZoomedOffset, 0, MidpointRounding.AwayFromZero);
            int yOffsetZoomed = (int)Math.Round(y1 + yZoomedOffset, 0, MidpointRounding.AwayFromZero); ;
            int x2OffsetZoomed = (int)Math.Round(x2 + xZoomedOffset, 0, MidpointRounding.AwayFromZero); ;
            int y2OffsetZoomed = (int)Math.Round(y2 + yZoomedOffset, 0, MidpointRounding.AwayFromZero); ;

            coords1 = new Point(xOffsetZoomed, yOffsetZoomed);
            coords2 = new Point(x2OffsetZoomed, y2OffsetZoomed);
        }
        /// <summary>
        /// Gets the document position from a screen position.
        /// </summary>
        /// <param name="x">The x position.</param>
        /// <param name="y">The y position.</param>
        /// <param name="currentPage">The current page [XDrawPage].</param>
        /// <param name="currentView">The current view [XDrawView].</param>
        /// <returns>
        /// The position on the page based on document page position and current zoom level.
        /// </returns>
        internal static Point GetDocumentPositionFromScreenPosition(double x, double y, XDrawPage currentPage, XDrawView currentView)
        {
            if (currentPage != null && currentView != null)
            {
                var zoom = OoUtils.GetProperty(currentView, "ZoomValue");
                var viewOffset = OoUtils.GetProperty(currentView, "ViewOffset");

                int zoomInPercent = Int32.Parse(zoom.ToString());

                Point viewOffsetAsPoint = viewOffset is Point ? (Point)viewOffset : new Point(0, 0);
                double zoomFactor = ((double)zoomInPercent / 100.0);

                double xOffsetZoomed = zoomFactor * viewOffsetAsPoint.X;
                double yOffsetZoomed = zoomFactor * viewOffsetAsPoint.Y;

                double xIn100thmm = ConvertPixelTo100thmm(x) + xOffsetZoomed;
                double yIn100thmm = ConvertPixelTo100thmm(y) + yOffsetZoomed;

                int xZoomed = (int)Math.Round(xIn100thmm / zoomFactor, 0, MidpointRounding.AwayFromZero);
                int yZoomed = (int)Math.Round(yIn100thmm / zoomFactor, 0, MidpointRounding.AwayFromZero);

                Point p = new Point(xZoomed, yZoomed);
                return p;
            }
            return null;
        }