/// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the first child of the current page.
        /// </summary>
        /// <returns></returns>
        public OoShapeObserver GetFirstChild()
        {
            OoShapeObserver shapeObs = null;

            if (DrawPage != null && PagesObserver != null)
            {
                if (DrawPage is XDrawPage)
                {
                    TimeLimitExecutor.WaitForExecuteWithTimeLimit(500, () => {
                        try
                        {
                            int childCount = ((XDrawPage)DrawPage).getCount();
                            if (childCount > 0)
                            {
                                var anyFirstChild = ((XDrawPage)DrawPage).getByIndex(0);
                                if (anyFirstChild.hasValue())
                                {
                                    var firstChild = anyFirstChild.Value;

                                    if (firstChild is XShape)
                                    {
                                        shapeObs = PagesObserver.GetRegisteredShapeObserver(firstChild as XShape, this);
                                        if (shapeObs != null)
                                        {
                                            if (shapeObs.AcccessibleCounterpart == null)
                                            {
                                                shapeObs.Update();
                                            }
                                        }
                                        else
                                        {
                                            //TODO: register this shape
                                            OoShapeObserver newShapeObserver = OoShapeObserverFactory.BuildShapeObserver(firstChild, this); //new OoShapeObserver(firstChild as XShape, this);
                                            PagesObserver.RegisterUniqueShape(newShapeObserver);
                                            shapeObs = newShapeObserver;
                                        }
                                    }
                                    else
                                    {
                                        //util.Debug.GetAllInterfacesOfObject(firstChild);
                                        Logger.Instance.Log(LogPriority.DEBUG, this, "[UNEXPECTED] The first child of a page is not a shape!: ");
                                    }
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            Logger.Instance.Log(LogPriority.IMPORTANT, this, "[ERROR] Can't get first child: " + ex);
                        }
                    }, "GetFirstChild");
                }
            }

            return(shapeObs);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
        /// <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);
        }
Ejemplo n.º 6
0
        private void handleChild(int i, XIndexAccess ia)
        {
            //System.Diagnostics.Debug.WriteLine("[UPDATE] --- handle child [" + i + "]");
            try
            {
                if (PagesObserver != null)
                {
                    lock (_childHandleLock)
                    {
                        var anyShape = ia.getByIndex(i);
                        if (anyShape.hasValue() && anyShape.Value is XShape)
                        {
                            if (PagesObserver.ShapeAlreadyRegistered(anyShape.Value as XShape, this))
                            {
                                //System.Diagnostics.Debug.WriteLine("[UPDATE] Shape " + anyShape.Value + " already exists ");

                                OoShapeObserver so = PagesObserver.GetRegisteredShapeObserver(anyShape.Value as XShape, this);
                                if (so != null)
                                {
                                    so.UpdateChildren();
                                }
                                else
                                {
                                    Logger.Instance.Log(LogPriority.DEBUG, this, "[ERROR] Shape should exist but could not been found!!!");

                                    so = OoShapeObserverFactory.BuildShapeObserver(anyShape.Value, this);  //new OoShapeObserver(anyShape.Value as XShape, this);
                                    //shapeList.Add(so);
                                }
                            }
                            else
                            {
                                //System.Diagnostics.Debug.WriteLine("[UPDATE] New Shape " + anyShape.Value + " will be registered ");
                                OoShapeObserver so = null;
                                try
                                {
                                    if (OoUtils.ElementSupportsService(anyShape.Value, OO.Services.DRAW_SHAPE_TEXT))
                                    {
                                        so = OoShapeObserverFactory.BuildShapeObserver(anyShape.Value, this);  //new OoShapeObserver(anyShape.Value as XShape, this);
                                    }
                                    else
                                    {
                                        so = OoShapeObserverFactory.BuildShapeObserver(anyShape.Value, this);  //new OoShapeObserver(anyShape.Value as XShape, this);
                                        //System.Diagnostics.Debug.WriteLine("[UPDATE] Shape: " + so.Name + " will be registered");
                                    }
                                }
                                catch (unoidl.com.sun.star.uno.RuntimeException ex)
                                {
                                    Logger.Instance.Log(LogPriority.IMPORTANT, this, "[ERROR]  internal while register ShapeObserver", ex);
                                }
                                catch (Exception ex)
                                {
                                    Logger.Instance.Log(LogPriority.IMPORTANT, this, "[FATAL ERROR] can not register ShapeObserver", ex);
                                }
                                //finally
                                //{
                                //    if (so != null) shapeList.Add(so);
                                //}
                            }
                        }
                    }
                }
                else
                {
                    Logger.Instance.Log(LogPriority.DEBUG, this, "[ERROR] PagesObserver is null");
                }
            }
            catch (System.Threading.ThreadAbortException ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "[OO Deadlock] can't get access to children via child handling in DrawPageObserver", ex); }
            catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "can't get access to children via child handling in DrawPageObserver", ex); }
        }