/// <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);
        }
Esempio n. 2
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);
        }