コード例 #1
0
        /// <summary>
        /// Registers a new shape.
        /// </summary>
        /// <param name="shape">The dom shape.</param>
        /// <returns>a registered <see cref="OoShapeObserver"/> for this shape</returns>
        internal OoShapeObserver RegisterNewShape(XShape shape, OoDrawPageObserver pObs = null)
        {
            OoShapeObserver sobs = null;

            if (shape != null)
            {
                // get the page to this shape
                var page = OoDrawUtils.GetPageForShape(shape);
                if (page != null)
                {
                    if (pObs == null || !page.Equals(pObs.DrawPage))
                    {
                        pObs = GetRegisteredPageObserver(page);
                    }

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

            return(sobs);
        }
コード例 #2
0
        /// <summary>
        /// Tries to get the parent of an XShape.
        /// </summary>
        /// <param name="parent">The parent.
        /// Can be <c>NULL</c> if no parent is available - could bee the case when the
        /// shape was deleted but not disposed for keeping it in undo/history</param>
        /// <param name="shape">The shape.</param>
        /// <returns><c>true</c> if the parent could been get, otherwise <c>false</c></returns>
        /// <remarks>This function is time limited to 200 ms.</remarks>
        bool tryGetParentByXShape(out XShapes parent, XShape shape = null)
        {
            bool    success = false;
            XShapes par     = null;

            TimeLimitExecutor.WaitForExecuteWithTimeLimit(200, () =>
            {
                if (shape == null)
                {
                    shape = Shape;
                }
                if (shape != null && shape is XChild)
                {
                    var Parent = ((XChild)shape).getParent();
                    if (Parent != null)
                    {
                        par     = Parent as XShapes;
                        success = true;
                    }
                }
            }, "GetParent");

            parent = par;
            return(success);
        }
コード例 #3
0
        /// <summary>
        /// Gets the parent by X shape.
        /// </summary>
        XShapes getParentByXShape(XShape shape = null)
        {
            XShapes parent;
            bool    successs = tryGetParentByXShape(out parent, shape);

            return(parent);
        }
コード例 #4
0
        private bool tryGetSelection(OoAccessibleDocWnd doc, out List <OoShapeObserver> selectedShapesList)
        {
            //System.Diagnostics.Debug.WriteLine("  ---> try Get Selection (inner critical Call)");
            selectedShapesList = new List <OoShapeObserver>();
            bool success = false;

            // check the global selection supplier
            if (doc != null)
            {
                try
                {
                    var controller = doc.Controller;
                    if (controller != null && controller is XSelectionSupplier)
                    {
                        Object  selection      = OoSelectionObserver.GetSelection(controller as XSelectionSupplier);
                        XShapes selectedShapes = selection as XShapes;

                        OoDrawPagesObserver pagesObserver = doc.DrawPagesObs;
                        if (selectedShapes != null && pagesObserver != null)
                        {
                            int count = selectedShapes.getCount();
                            for (int i = 0; i < count; i++)
                            {
                                XShape shape = selectedShapes.getByIndex(i).Value as XShape;
                                if (shape != null)
                                {
                                    OoShapeObserver shapeObserver = pagesObserver.GetRegisteredShapeObserver(shape, null);
                                    if (shapeObserver != null)
                                    {
                                        selectedShapesList.Add(shapeObserver);
                                    }
                                }
                            }
                            success = true;
                        }
                        else
                        {
                            // no selection
                            if (selection is bool && ((bool)selection) == false)
                            {
                                success = false;
                            }
                            else if (pagesObserver != null)
                            {
                                success = true;
                            }
                        }
                    }
                }
                catch (unoidl.com.sun.star.lang.DisposedException ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Source + " " + ex.Message);
                }
            }

            //System.Diagnostics.Debug.WriteLine("  ---> ~~~~~~~~~ (" + success + ") GET Selection for WND: " + doc + " result in " + selectedShapesList.Count + " selected Items.");

            return(success);
        }
コード例 #5
0
        public void DrawShape3Times()
        {
            var testShape = new XShape(3);

            Assert.AreEqual("x x\n x \nx x", testShape.GetShape());
            Assert.AreEqual("x x\n x \nx x", testShape.GetShape());
            Assert.AreEqual("x x\n x \nx x", testShape.GetShape());
        }
コード例 #6
0
 /// <summary>
 /// Goes to the child at given index in DOM if possible.
 /// </summary>
 /// <param name="number">The number. Will be handled by modulo child count.
 /// So this should not get invalid. It is also possible to receive the
 /// last child by asking for '-1'</param>
 /// <returns>The observer for the child at given index (infinite child loop by modulu of child count) or <c>null</c> if no child could be found.</returns>
 virtual public OoShapeObserver GetChild(int number)
 {
     if (this.Page != null && this.Page.PagesObserver != null)
     {
         XShape s = getChildByXShape(number);
         return(getShapeObserverFromXShape(s));
     }
     return(null);
 }
コード例 #7
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);
        }
コード例 #8
0
    // Use this for initialization
    void Start()
    {
        VisitorCube visitor = new VisitorCube();
        Cube        cube    = new Cube();

        cube.RunVisitor(visitor);
        XShape xshape = new XShape();

        xshape.RunVisitor(visitor);
    }
コード例 #9
0
        public void TesScaling()
        {
            var testShape = new XShape(100);

            var splitShape     = testShape.GetShape().Split("\n");
            var actualLastLine = splitShape[splitShape.Length - 1];

            var expectedLastLine = "x" + new String(' ', 98) + "x";

            Assert.AreEqual(expectedLastLine, actualLastLine);
        }
コード例 #10
0
        public void AddRandomX()
        {
            Random rnd = new Random();
            int    x   = rnd.Next(100, 1000);
            int    y   = rnd.Next(100, 600);

            XShape xShape = new XShape(new Rectangle(x, y, 200, 100));

            xShape.BorderColor = Color.Black;

            ShapeList.Add(xShape);
        }
コード例 #11
0
        /// <summary>
        /// Builds an Observer class for the specific shape type.
        /// </summary>
        /// <param name="s">The shape to observe.</param>
        /// <param name="page">The page the shape is placed on.</param>
        /// <param name="parent">The parent shape if the shape is part of a group.</param>
        /// <returns>
        /// An shape observer class for the specific shape type.
        /// </returns>
        internal static OoShapeObserver BuildShapeObserver(XShape s, OoDrawPageObserver page, OoShapeObserver parent)
        {
            if (s != null && page != null)
            {
                if (OoUtils.ElementSupportsService(s, OO.Services.DRAW_SHAPE_CUSTOM))
                {
                    return(new OoCustomShapeObserver(s, page, parent));
                }

                // normal shape
                return(new OoShapeObserver(s, page, parent));
            }
            return(null);
        }
コード例 #12
0
        ///// <summary>
        ///// Determine if the XShape child is already known as a child.
        ///// </summary>
        ///// <param name="shape">The shape.</param>
        ///// <returns> the releated ShapeObserver to the known child otherwise <c>null</c></returns>
        //OoShapeObserver childListContainsXShape(XShape shape)
        //{
        //    foreach (var child in Children)
        //    {
        //        if (child.Equals(shape)) return child;
        //    }
        //    return null;
        //}

        #endregion

        #region DOM Tree Handling

        /// <summary>
        /// gets an OoShapeObserver for the given shape.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <returns>An already registered or a new observer for the shape</returns>
        private OoShapeObserver getShapeObserverFromXShape(XShape s)
        {
            if (s != null)
            {
                OoShapeObserver sObs = this.Page.PagesObserver.GetRegisteredShapeObserver(s, this.Page);
                if (sObs == null && this.Page != null && this.Page.PagesObserver != null)
                {
                    sObs = OoShapeObserverFactory.BuildShapeObserver( //new OoShapeObserver(
                        s,
                        this.Page.PagesObserver.GetRegisteredPageObserver(
                            OoDrawUtils.GetPageForShape(s)));
                    this.Page.PagesObserver.RegisterUniqueShape(sObs);
                }
                return(sObs);
            }
            return(null);
        }
コード例 #13
0
        /// <summary>
        /// Goes to the previous DOM sibling if possible
        /// </summary>
        /// <returns>The observer for the previous sibling (infinite child loop) or the same if there is only on child or <c>null</c> if no sibling could be found.</returns>
        virtual public OoShapeObserver GetPreviousSibling()
        {
            if (this.Page != null && this.Page.PagesObserver != null)
            {
                XShape          s    = getPreviousSiblingByXShape();
                OoShapeObserver sobs = getShapeObserverFromXShape(s);

                if (sobs == null || sobs.Disposed)
                {
                    sobs = OoShapeObserverFactory.BuildShapeObserver(s, Page); // new OoShapeObserver(s, Page);
                    Page.PagesObserver.RegisterUniqueShape(sobs);
                }

                return(sobs);
            }
            return(null);
        }
コード例 #14
0
 /// <summary>
 /// Determine if the shapes is already registered.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <returns><c>true</c> if the shape is allready known otherwise <c>false</c> </returns>
 public bool ShapeAlreadyRegistered(XShape shape, OoDrawPageObserver page = null)
 {
     if (shape != null)
     {
         if (domshapes.ContainsKey(shape))
         {
             OoShapeObserver sobs = domshapes[shape];
             if (sobs != null)
             {
                 if (sobs.Shape == shape)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
コード例 #15
0
        /// <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);
        }
コード例 #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OoShapeObserver"/> class.
        /// </summary>
        /// <param name="s">The XShape to observe.</param>
        /// <param name="page">The observer for the page the shape is located on.</param>
        /// <param name="parent">The observer for the parent shape.</param>
        public OoShapeObserver(XShape s, OoDrawPageObserver page, OoShapeObserver parent)
            : base()
        {
            Shape = s;
            Page = page;
            Parent = parent;
            if (Shape != null)
            {
                //if (IsGroup)
                //{
                //    util.Debug.GetAllInterfacesOfObject(Shape);
                //}

                if (Page != null && Page.PagesObserver != null) Page.PagesObserver.RegisterUniqueShape(this);

                handleChildren();
                registerListeners();

            }

            registerShapeOnPageShapeList();
        }
コード例 #17
0
        /// <summary>
        /// Gets the previous sibling by X shape.
        /// </summary>
        XShape getPreviousSiblingByXShape()
        {
            if (Shape != null && Shape is XChild)
            {
                XShapes parent = getParentByXShape();
                if (parent != null && parent.hasElements())
                {
                    int childCount = parent.getCount();
                    if (childCount > 0)
                    {
                        //string current_name = Name;

                        XShape lastChild = null;
                        //find this child
                        for (int i = 0; i < childCount; i++)
                        {
                            var c = ((XShapes)parent).getByIndex(i).Value;

                            if (c == Shape)
                            {
                                if (lastChild != null)
                                {
                                    return(lastChild);
                                }
                            }
                            else if (c is XShape)
                            {
                                lastChild = c as XShape;
                            }
                        }

                        // if no child was in front, return the las child at all
                        return(getChildByXShape(-1, parent as XShapes));
                    }
                }
            }
            return(null);
        }
コード例 #18
0
        internal void UpdateObserverLists(OoShapeObserver obs)
        {
            String             name  = obs.Name;
            XShape             shape = obs.Shape;
            XAccessible        acc   = obs.AcccessibleCounterpart;
            XAccessibleContext cont  = acc != null?acc.getAccessibleContext() : null;

            //TODO: maybe do this softer?!

            try { shapes[name] = obs; }
            catch (Exception) { }
            if (cont != null)
            {
                try { accshapes[cont] = obs; }
                catch (Exception) { }
            }
            else
            {
                // search for a relation?
            }
            try { domshapes[shape] = obs; }
            catch (Exception) { }
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OoShapeObserver"/> class.
        /// </summary>
        /// <param name="s">The XShape to observe.</param>
        /// <param name="page">The observer for the page the shape is located on.</param>
        /// <param name="parent">The observer for the parent shape.</param>
        public OoShapeObserver(XShape s, OoDrawPageObserver page, OoShapeObserver parent)
            : base()
        {
            Shape  = s;
            Page   = page;
            Parent = parent;
            if (Shape != null)
            {
                //if (IsGroup)
                //{
                //    util.Debug.GetAllInterfacesOfObject(Shape);
                //}

                if (Page != null && Page.PagesObserver != null)
                {
                    Page.PagesObserver.RegisterUniqueShape(this);
                }

                handleChildren();
                registerListeners();
            }

            registerShapeOnPageShapeList();
        }
コード例 #20
0
ファイル: UnitTestAnyShape.cs プロジェクト: planetoxod/XShape
        public void TestMethod_AreaShape()
        {
            double   a        = 3;
            double   b        = 4;
            double   c        = 5;
            Triangle triangle = new Triangle(a, b, c);
            XShape   xShape   = new XShape(triangle);
            double   Sactual  = xShape.Area;                // area actual
            double   p        = (a + b + c) / 2;            // polperimetra
            double   t        = p * (p - a) * (p - b) * (p - c);
            double   Sexpected;

            if (t >= 0)
            {
                Sexpected = Math.Sqrt(t);
            }
            else
            {
                Sexpected = 0;                                             // area expected
            }
            double delta = 0.001;

            Assert.AreEqual(Sexpected, Sactual, delta, "The area of the triangle is not calculated correctly");
        }
コード例 #21
0
 private void Identify(XShape item)
 {
     item.ToType <XShape>().IsSelected = true;
 }
コード例 #22
0
        /// <summary>
        /// Get a registered shape observer.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <returns>the already registerd 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 = new OoShapeObserver(shape, page);
                    RegisterUniqueShape(sObs);
                }
            }

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

            return sObs;
        }
コード例 #23
0
        public void TestCreation()
        {
            var testShape = new XShape(2);

            Assert.IsNotNull(testShape);
        }
コード例 #24
0
        public void TestDrawSize1()
        {
            var testShape = new XShape(1);

            Assert.AreEqual("x", testShape.GetShape());
        }
コード例 #25
0
        ///// <summary>
        ///// a list of observers for the children - the order must not corresponding to the order in the DOM
        ///// </summary>
        //public ConcurrentBag<OoShapeObserver> Children = new ConcurrentBag<OoShapeObserver>();


        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="OoShapeObserver"/> class.
        /// </summary>
        /// <param name="s">The XShape to observe.</param>
        /// <param name="page">The observer for the page the shape is located on.</param>
        public OoShapeObserver(XShape s, OoDrawPageObserver page) : this(s, page, null)
        {
        }
コード例 #26
0
        /// <summary>
        /// Adds the points to a poly polygon descriptor.
        /// </summary>
        /// <param name="shape">The shape to change the points.</param>
        /// <param name="coodinates">The complete coordinates to set.</param>
        /// <param name="geometry">if set to <c>true</c> the 'Geometry' property is used (these are the untransformed bezier coordinates of the polygon). 
        /// Normally you should use the absolute coordinates on the page! So use the default value <c>false</c>.</param>
        /// <param name="doc">The document [unoidl.com.sun.star.document.XUndoManagerSupplier]. If this is set, the manipulation will be added to the undo/redo history</param>
        /// <returns><c>true</c> if the property could be set successfully</returns>
        internal static bool AddPointsToPolygon(XShape shape, List<List<PolyPointDescriptor>> coordinates, bool geometry = false, object doc = null)
        {
            // Geometry         [][].awt.Point     -Sequence-   NOTE: is empty if not a poly!
            // PolyPolygon      [][].awt.Point     -Sequence-   NOTE: is empty if not a poly!  
            // Polygon          [].awt.Point       -Sequence-     

            if (coordinates.Count > 1) // poly polygon
            {
                return AddPolyPointsToPolyPolygonDescriptor(shape, coordinates, geometry, doc);
            }
            else // polygon
            {
                if (coordinates[0] != null)
                {
                    return AddPointsToPolyPolygonDescriptor(shape, coordinates, geometry, doc);
                }
                return false;
            }
        }
コード例 #27
0
 /// <summary>
 /// Removes the shape from the draw page or an other shape group.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="page">The page.</param>
 internal static void RemoveShapeFromDrawPage(XShape shape, XShapes page)
 {
     if (shape != null && page != null)
     {
         try
         {
             ((XShapes)page).remove(shape);
         }
         catch { }
     }
 }
コード例 #28
0
 /// <summary>
 /// Adds a shape to a draw page or an other shape group.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="page">The page.</param>
 internal static void AddShapeToDrawPage(XShape shape, XShapes page)
 {
     if (shape != null && page != null)
     {
         try
         {
             ((XShapes)page).add(shape);
         }
         catch { }
     }
 }
コード例 #29
0
 /// <summary>
 /// Adds a shape to a draw page or an other shape group.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="page">The page.</param>
 internal static void AddShapeToDrawPage(XShape shape, XDrawPagesSupplier drawDoc)
 {
     if (shape != null && drawDoc != null)
     {
         try
         {
             AddShapeToDrawPage(shape, GetCurrentPage(drawDoc));
         }
         catch { }
     }
 }
コード例 #30
0
 /// <summary>
 /// Adds a shape to a draw page or an other shape group.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="drawDoc">The draw document [XDrawPagesSupplier].</param>
 internal static void AddShapeToDrawPage(XShape shape, Object drawDoc) { AddShapeToDrawPage(shape, drawDoc as XDrawPagesSupplier); }
コード例 #31
0
 internal static XShapes GetParentShape(XShape shape)
 {
     XShapes parent = null;
     if (shape != null && shape is XChild)
     {
         TimeLimitExecutor.WaitForExecuteWithTimeLimit(500, () =>
         {
             parent = ((XChild)shape).getParent() as XShapes;
         }, "GetParentShape");
     }
     return parent;
 }
コード例 #32
0
        /// <summary>
        /// Gets the poly points of a free form shape.
        /// </summary>
        /// <param name="shape">The shape [XShape].</param>
        /// <param name="getGeometry">if set to <c>true</c> the 'Geometry' property is used (these are the untransformed bezier coordinates of the polygon). 
        /// <returns>List of lists containing the point descriptors for polygon points</returns>
        internal static List<List<PolyPointDescriptor>> GetPolyPoints(XShape shape, bool getGeometry = false)
        {
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            //watch.Restart();

            //try
            //{
                if (shape != null && IsFreeform(shape))
                {
                    try
                    {
                        // check for the right type
                        if (getGeometry)
                        {
                            // Geometry         [][].awt.Point      -Sequence-
                            Point[][] geometry = OoUtils.GetProperty(shape, "Geometry") as Point[][];
                        }
                        else
                        {
                            // PolyPolygon      [][].awt.Point      -Sequence-
                            Point[][] points = new Point[0][];
                            points = OoUtils.GetProperty(shape, "PolyPolygon") as Point[][];

                            // PolyPolygonBezier    .drawing.PolyPolygonBezierCoords  -STRUCT-
                            if (points == null)
                            {
                                PolyPolygonBezierCoords coords = OoUtils.GetProperty(shape, "PolyPolygonBezier") as PolyPolygonBezierCoords;
                                return GetPolyPoints(coords);
                            }
                            else
                            {
                               return GetPolyPoints(points);
                            }
                        }
                    }
                    catch { }
                }
                return null;
            //}
            //finally
            //{
            //    watch.Stop();
            //    System.Diagnostics.Debug.WriteLine("Ticks for handling Polygon getting event:" + watch.ElapsedTicks + " / Milliseconds:" + watch.ElapsedMilliseconds);
            //}
        }
コード例 #33
0
        public static XAccessible GetAccessibleCounterpartFromHash(XShape needle, XAccessibleContext haystack)
        {
            XAccessible counterpart = null;
            if (haystack != null && needle != null)
            {
                string hash = "###" + needle.GetHashCode().ToString() + "###";
                try
                {
                    string desc = OoUtils.GetStringProperty(needle, "Description");
                    bool success = OoUtils.SetStringProperty(needle, "Description", hash + desc);

                    if (success)
                    {

                        // find the accessible counterpart with the description
                        // starting with the corresponding hash pattern
                        counterpart = GetAccessibleChildDescriptionStartsWith(hash, haystack);

                        if (counterpart == null)
                        {
                            Logger.Instance.Log(LogPriority.DEBUG, "OoAccessibility", "[ERORR] could not find ax XAccessible width the given Description");
                        }

                    }
                    else
                    {
                        // FIXME: what todo if no description could been set
                    }


                    // if found reset the Description
                    success = OoUtils.SetStringProperty(needle, "Description", desc);
                    if (!success)
                    {
                        Logger.Instance.Log(LogPriority.DEBUG, "OoAccessibility", "[ERROR] Could not revert Description change for XShape while searching for their counterpart");
                    }


                }
                catch { }


            }
            return counterpart;
        }
コード例 #34
0
 protected override void ReadShapes(DefineShapeTag tag, XElement xShape)
 {
     XShape.FromXml(xShape, tag.ShapeRecords);
 }
コード例 #35
0
        internal static XDrawPage GetPageForShape(XShape shape)
        {
            XDrawPage page = null;
            if (shape != null && shape is XChild)
            {
                XShapes lastParent = null;
                XShapes par = GetParentShape(shape);
                while (true)
                {
                    if (par == null || lastParent == par) break;
                    //check if par is page shape
                    if (par is XDrawPage)
                    {
                        page = par as XDrawPage;
                        break;
                    }

                    lastParent = par;
                    par = GetParentShape(lastParent as XShape);
                }
            }
            return page;
        }
コード例 #36
0
 /// <summary>
 /// Determines whether the specified shape is freeform.
 /// Freeforms are polygons, polylines and Bezier curves.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <returns>
 ///   <c>true</c> if the specified shape is a freeform; otherwise, <c>false</c>.
 /// </returns>
 internal static bool IsFreeform(XShape shape)
 {
     return OoUtils.ElementSupportsService(shape, OO.Services.DRAW_POLY_POLYGON_DESCRIPTOR)
         || OoUtils.ElementSupportsService(shape, OO.Services.DRAW_POLY_POLYGON_BEZIER_DESCRIPTOR)
         || OoUtils.ElementSupportsService(shape, OO.Services.DRAW_SHAPE_BEZIER_CLOSED)
         || OoUtils.ElementSupportsService(shape, OO.Services.DRAW_SHAPE_BEZIER_OPEN)
         || OoUtils.ElementSupportsService(shape, OO.Services.DRAW_SHAPE_POLYLINE)
         || OoUtils.ElementSupportsService(shape, OO.Services.DRAW_SHAPE_POLYPOLYGON)
         ;
 }
コード例 #37
0
 /// <summary>
 /// Sets the position of the shape.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="x">The x position.</param>
 /// <param name="y">The y position.</param>
 internal static void SetShapePosition(XShape shape, int x, int y)
 {
     if (shape != null)
     {
         var position = new Point(x, y);
         shape.setPosition(position);
     }
 }
コード例 #38
0
 /// <summary>
 /// Sets the size of the shape.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="width">The width of the shape.</param>
 /// <param name="height">The height of the shape.</param>
 internal static void SetShapeSize(XShape shape, int width, int height)
 {
     if (shape != null)
     {
         var size = new Size(width, height);
         shape.setSize(size);
     }
 }
        ///// <summary>
        ///// Determine if the XShape child is already known as a child.
        ///// </summary>
        ///// <param name="shape">The shape.</param>
        ///// <returns> the releated ShapeObserver to the known child otherwise <c>null</c></returns>
        //OoShapeObserver childListContainsXShape(XShape shape)
        //{
        //    foreach (var child in Children)
        //    {
        //        if (child.Equals(shape)) return child;
        //    }
        //    return null;
        //}

        #endregion

        #region DOM Tree Handling

        /// <summary>
        /// gets an OoShapeObserver for the given shape.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <returns>An already registered or a new observer for the shape</returns>
        private OoShapeObserver getShapeObserverFromXShape(XShape s)
        {
            if (s != null)
            {
                OoShapeObserver sObs = this.Page.PagesObserver.GetRegisteredShapeObserver(s, this.Page);
                if (sObs == null && this.Page != null && this.Page.PagesObserver != null)
                {
                    sObs = new OoShapeObserver(s,
                        this.Page.PagesObserver.GetRegisteredPageObserver(
                            OoDrawUtils.GetPageForShape(s)));
                    this.Page.PagesObserver.RegisterUniqueShape(sObs);
                }
                return sObs;
            }
            return null;
        }
コード例 #40
0
        public void TestDrawSize5()
        {
            var testShape = new XShape(5);

            Assert.AreEqual("x   x\n x x \n  x  \n x x \nx   x", testShape.GetShape());
        }
 /// <summary>
 /// Gets the parent by X shape.
 /// </summary>
 XShapes getParentByXShape(XShape shape = null)
 {
     XShapes parent;
     bool successs = tryGetParentByXShape(out parent, shape);
     return parent;
 }
コード例 #42
0
        ///// <summary>
        ///// a list of observers for the children - the order must not corresponding to the order in the DOM
        ///// </summary>
        //public ConcurrentBag<OoShapeObserver> Children = new ConcurrentBag<OoShapeObserver>();


        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="OoShapeObserver"/> class.
        /// </summary>
        /// <param name="s">The XShape to observe.</param>
        /// <param name="page">The observer for the page the shape is located on.</param>
        public OoShapeObserver(XShape s, OoDrawPageObserver page) : this(s, page, null) { }
        /// <summary>
        /// Tries to get the parent of an XShape.
        /// </summary>
        /// <param name="parent">The parent. 
        /// Can be <c>NULL</c> if no parent is available - could bee the case when the 
        /// shape was deleted but not disposed for keeping it in undo/history</param>
        /// <param name="shape">The shape.</param>
        /// <returns><c>true</c> if the parent could been get, otherwise <c>false</c></returns>
        bool tryGetParentByXShape(out XShapes parent, XShape shape = null)
        {
            bool success = false;
            XShapes par = null;

            TimeLimitExecutor.WaitForExecuteWithTimeLimit(200, () =>
            {
                if (shape == null) shape = Shape;
                if (shape != null && shape is XChild)
                {
                    var Parent = ((XChild)shape).getParent();
                    if (Parent != null)
                    {
                        par = Parent as XShapes;
                        success = true;
                    }
                }
            }, "GetParent");

            parent = par;
            return success;
        }
コード例 #44
0
 /// <summary>
 /// Determine if the shapes is already registered.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <returns><c>true</c> if the shape is allready known otherwise <c>false</c> </returns>
 public bool ShapeAlreadyRegistered(XShape shape, OoDrawPageObserver page = null)
 {
     if (shape != null)
     {
         if (domshapes.ContainsKey(shape))
         {
             OoShapeObserver sobs = domshapes[shape];
             if (sobs != null)
             {
                 if (sobs.Shape == shape) return true;
             }
         }
     }
     return false;
 }
コード例 #45
0
 /// <summary>
 /// Adds the points to a poly polygon descriptor.
 /// </summary>
 /// <param name="shape">The shape[XShape] to change the points.</param>
 /// <param name="coordinates">The coordinates.</param>
 /// <param name="geometry">if set to <c>true</c> the 'Geometry' property is used (these are the untransformed bezier coordinates of the polygon).
 /// Normally you should use the absolute coordinates on the page! So use the default value <c>false</c>.</param>
 /// <param name="doc">The document [unoidl.com.sun.star.document.XUndoManagerSupplier]. If this is set, the manipulation will be added to the undo/redo history</param>
 /// <returns>
 ///   <c>true</c> if the property could be set successfully
 /// </returns>
 internal static bool AddPolyPointsToPolyPolygonDescriptor(XShape shape, List<List<PolyPointDescriptor>> coordinates, bool geometry = false, object doc = null)
 {
     int i = 0;
     Point[][] ps = new Point[coordinates.Count][];
     unodrawing.PolygonFlags[] f;
     foreach (var polygon in coordinates)
     {
         Point[] p;
         bool success = TransformToCoordinateAndFlagSequence(coordinates[0], out p, out f, true);
         ps[i] = p;
         i++;
     }
     if (geometry)
     {
         return OoUtils.SetPropertyUndoable(shape, "Geometry", ps, doc as unoidl.com.sun.star.document.XUndoManagerSupplier);
     }
     else
     {
         return OoUtils.SetPropertyUndoable(shape, "PolyPolygon", ps, doc as unoidl.com.sun.star.document.XUndoManagerSupplier);
     }
 }
コード例 #46
0
        /// <summary>
        /// Registers a new shape.
        /// </summary>
        /// <param name="shape">The dom shape.</param>
        /// <returns>a registered <see cref="OoShapeObserver"/> for this shape</returns>
        internal OoShapeObserver RegisterNewShape(XShape shape, OoDrawPageObserver pObs = null)
        {
            OoShapeObserver sobs = null;

            if (shape != null)
            {
                // get the page to this shape
                var page = OoDrawUtils.GetPageForShape(shape);
                if (page != null)
                {
                    if(pObs == null || !page.Equals(pObs.DrawPage)) 
                        pObs = GetRegisteredPageObserver(page);

                    if (pObs != null)
                    {
                        sobs = new OoShapeObserver(shape, pObs);
                        RegisterUniqueShape(sobs);
                    }
                }
            }

            return sobs;
        }
コード例 #47
0
 /// <summary>
 /// Builds an Observer class for the specific shape type.
 /// </summary>
 /// <param name="s">The shape to observe.</param>
 /// <param name="page">The page the shape is placed on.</param>
 /// <returns>An shape observer class for the specific shape type.</returns>
 internal static OoShapeObserver BuildShapeObserver(XShape s, OoDrawPageObserver page)
 {
     return(BuildShapeObserver(s, page, null));
 }
コード例 #48
0
        /// <summary>
        /// Try to find the accessible counterpart to a XShape in the document.
        /// </summary>
        /// <param name="needle">The needle.</param>
        /// <param name="haystack">The XAccessible haystack (parent or document).</param>
        /// <returns>The accessible counterpart (if the name is equal) or NULL</returns>
        public static XAccessible _GetAccessibleCounterpart(XShape needle, XAccessibleContext haystack)
        {
            if (haystack != null && needle != null)
            {
                String name = OoUtils.GetStringProperty(needle, "Name");
                String title = OoUtils.GetStringProperty(needle, "Title");
                String search = (String.IsNullOrWhiteSpace(name) ? "" : name)
                    + (String.IsNullOrWhiteSpace(title) ? "" : " " + title);

                return GetAccessibleChildWithName(search, haystack);
            }
            return null;
        }
コード例 #49
0
        /// <summary>
        /// Adds the points to a poly polygon bezier descriptor.
        /// </summary>
        /// <param name="shape">The shape to change the points.</param>
        /// <param name="coordinates">The coordinates.</param>
        /// <param name="geometry">if set to <c>true</c> the 'Geometry' property is used (these are the untransformed bezier coordinates of the polygon).
        /// Normally you should use the absolute coordinates on the page! So use the default value <c>false</c>.</param>
        /// <param name="doc">The document [unoidl.com.sun.star.document.XUndoManagerSupplier]. If this is set, the manipulation will be added to the undo/redo history</param>
        /// <returns>
        ///   <c>true</c> if the property could be set successfully
        /// </returns>
        internal static bool AddPointsToPolyPolygonBezierDescriptor(XShape shape, List<List<PolyPointDescriptor>> coordinates, bool geometry = false, object doc = null)
        {
            // Geometry           .drawing.PolyPolygonBezierCoords  -STRUCT-
            // PolyPolygonBezier  .drawing.PolyPolygonBezierCoords  -STRUCT-
            //      Coordinates   [].drawing.PointSequence          -Sequence- 
            //                          [].awt.Point                -Sequence- 
            //      Flags         [].drawing.FlagSequence           -Sequence-
            //                           [].drawing.Flag            -Sequence-

            PolyPolygonBezierCoords ppc = BuildPolyPolygonBezierCoords(coordinates);
            return OoUtils.SetPropertyUndoable(shape, geometry ? "Geometry" : "PolyPolygonBezier", ppc, doc as unoidl.com.sun.star.document.XUndoManagerSupplier);
        }
コード例 #50
0
 protected override XElement FormatShape(DefineShapeTag tag)
 {
     return(XShape.ToXml(tag.ShapeRecords));
 }
コード例 #51
0
        /// <summary>
        /// Sets the poly points.
        /// </summary>
        /// <param name="shape">The shape to change the points.</param>
        /// <param name="coodinates">The complete coordinates to set.</param>
        /// <param name="geometry">if set to <c>true</c> the 'Geometry' property is used (these are the untransformed bezier coordinates of the polygon). 
        /// Normally you should use the absolute coordinates on the page! So use the default value <c>false</c>.</param>
        /// <param name="doc">The document [unoidl.com.sun.star.document.XUndoManagerSupplier]. If this is set, the manipulation will be added to the undo/redo history</param>
        /// <returns><c>true</c> if the property could be set successfully</returns>
        internal static bool SetPolyPoints(XShape shape, List<List<PolyPointDescriptor>> coordinates, bool geometry = false, object doc = null)
        {
            if (shape != null && coordinates != null && coordinates.Count > 0)
            {
                #region Polygon
                if (OoUtils.ElementSupportsService(shape, OO.Services.DRAW_POLY_POLYGON_DESCRIPTOR))
                {

                    return AddPointsToPolygon(shape, coordinates, geometry, doc);
                }
                #endregion

                #region Bezier
                // Bezier
                else if (OoUtils.ElementSupportsService(shape, OO.Services.DRAW_POLY_POLYGON_BEZIER_DESCRIPTOR))
                {
                    return AddPointsToPolyPolygonBezierDescriptor(shape, coordinates, geometry, doc);
                }
                #endregion
                else
                {
                } // not a polygon or bezier 
            }

            return false;
        }
コード例 #52
0
 /// <summary>
 /// Sets the size and position of the shape.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="x">The x position.</param>
 /// <param name="y">The y position.</param>
 /// <param name="width">The width of the shape.</param>
 /// <param name="height">The height of the shape.</param>
 internal static void SetShapePositionAndSize(XShape shape, int x, int y, int width, int height)
 {
     SetShapePosition(shape, x, y);
     SetShapeSize(shape, width, height);
 }
コード例 #53
0
 /// <summary>
 /// Adds the points to a polygon descriptor.
 /// </summary>
 /// <param name="shape">The shape to change the points.</param>
 /// <param name="coodinates">The complete coordinates to set.</param>
 /// <param name="geometry">if set to <c>true</c> the 'Geometry' property is used (these are the untransformed bezier coordinates of the polygon). 
 /// Normally you should use the absolute coordinates on the page! So use the default value <c>false</c>.</param>
 /// <param name="doc">The document [unoidl.com.sun.star.document.XUndoManagerSupplier]. If this is set, the manipulation will be added to the undo/redo history</param>
 /// <returns><c>true</c> if the property could be set successfully</returns>
 internal static bool AddPointsToPolyPolygonDescriptor(XShape shape, List<List<PolyPointDescriptor>> coordinates, bool geometry = false, object doc = null)
 {
     Point[] p;
     unodrawing.PolygonFlags[] f;
     bool success = TransformToCoordinateAndFlagSequence(coordinates[0], out p, out f, true);
     if (success)
     {
         if (geometry)
         {
             return OoUtils.SetPropertyUndoable(shape, "Geometry", new Point[][] { p }, doc as unoidl.com.sun.star.document.XUndoManagerSupplier);
         }
         else
         {
             return OoUtils.SetPropertyUndoable(shape, "PolyPolygon", new Point[][] { p }, doc as unoidl.com.sun.star.document.XUndoManagerSupplier);
         }
     }
     return false;
 }