//TODO: unfinished
        private OoShapeObserver searchUnregisteredShapeByAccessible(string accName, XAccessibleContext cont)
        {
            Update();
            var obs = searchRegisterdSapeObserverByAccessibleName(accName, cont, false);

            if (obs != null)
            {
                return(obs);
            }

            XDrawPages pages = PagesSupplier.getDrawPages();

            if (pages != null)
            {
                try
                {
                    for (int i = 0; i < pages.getCount(); i++)
                    {
                        var anyPage = pages.getByIndex(i);
                        if (anyPage.hasValue())
                        {
                            var page = anyPage.Value;
                            if (page != null && page is XShapes)
                            {
                                for (int j = 0; j < ((XShapes)page).getCount(); j++)
                                {
                                    var anyShape = ((XShapes)page).getByIndex(j);
                                    if (anyShape.hasValue())
                                    {
                                        var    shape  = anyShape.Value;
                                        string name   = OoUtils.GetStringProperty(shape, "Name");
                                        string UIname = OoUtils.GetStringProperty(shape, "UINameSingular");
                                        string Title  = OoUtils.GetStringProperty(shape, "Title");

                                        //if (accName.Equals(UIname))
                                        //{

                                        //}
                                        //else if (accName.Equals(name))
                                        //{

                                        //}
                                        //else if (accName.Equals(name + " " + Title))
                                        //{

                                        //}
                                        //else
                                        //{

                                        //}
                                    }
                                }
                            }
                        }
                    }
                }
                catch (System.Exception) { }
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// find the corresponding accessible counterpart object for this page in the accessible tree
        /// </summary>
        private void setAccessibleCounterpart()
        {
            String name = OoUtils.GetStringProperty(DrawPage, "LinkDisplayName");

            name = "PageShape: " + name; //TODO: find a more general way

            XAccessible accCounter = OoAccessibility.GetAccessibleChildWithName(name, PagesObserver.Document.AccComp as unoidl.com.sun.star.accessibility.XAccessibleContext);

            if (accCounter != null)
            {
                AcccessibleCounterpart = accCounter;
            }
        }
        /// <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);
        }
        private bool setStringProperty(string name, string value)
        {
            string val = OoUtils.GetStringProperty(Shape as XPropertySet, name);

            if (val.Equals(value))
            {
                return(true);
            }
            try
            {
                //OoUtils.SetPropertyUndoable(Shape, name, value, getDocument() as XUndoManagerSupplier);
                OoUtils.SetStringProperty(Shape as XPropertySet, name, value);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write("exception during setting property " + ex);
            }
            string newVal = getStringProperty(name);

            return(newVal.Equals(value));
        }
        /// <summary>
        /// Registers a unique shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <returns>the unique identifier (Name) to which the shape is registered</returns>
        public string RegisterUniqueShape(OoShapeObserver shape)
        {
            String          uid = String.Empty;
            OoShapeObserver trash;

            //TODO: check if name already exists
            if (shape != null && shape.IsValid())
            {
                // TODO: use the tud.mci.tangram.models.Interfaces.INameBuilder interface


                // register for disposing element
                shape.ObserverDisposing += new EventHandler(shape_ObserverDisposing);

                uid = OoUtils.GetStringProperty(shape, "Name");
                if (!String.IsNullOrWhiteSpace(uid))
                {
                    // check if name exists
                    if (shapes.ContainsKey(uid))
                    {
                        OoShapeObserver sObs = shapes[uid];
                        if (sObs != null)
                        {
                            if (sObs.IsValid())
                            {
                                // already valid registered
                                if (sObs.Shape == shape.Shape)
                                {
                                    return(uid);
                                }
                                else // valid different observer with the same name exist
                                {
                                    if (!uid.Equals(sObs.Name)) // update the registered name in the list if the name has changed
                                    {
                                        shapes.TryRemove(uid, out trash);
                                        uid = sObs.Name;
                                        shapes.TryAdd(uid, shape);
                                    }
                                }
                            }
                            else
                            {
                                sObs.Dispose();
                            }
                        }
                        else
                        {
                            shapes.TryRemove(uid, out trash);
                        }
                    }

                    // check if shape is already registered
                    if (domshapes.ContainsKey(shape.Shape))
                    {
                        OoShapeObserver sObs = domshapes[shape.Shape];
                        if (sObs != null)
                        {
                            if (sObs.IsValid())
                            {
                                domshapes[shape.Shape] = shape;
                                return(uid);
                            }
                            else
                            {
                                sObs.Dispose();
                            }
                        }
                        else
                        {
                            domshapes.TryRemove(shape.Shape, out trash);
                        }
                    }
                }
                else
                {
                    uid = GetUniqueId(shape);
                }

                while (shapes.ContainsKey(uid))
                {
                    uid += "*";
                }
                shape.Name  = uid;
                shapes[uid] = shape;
                if (shape.Shape != null)
                {
                    domshapes[shape.Shape] = shape;
                }
                if (shape.AcccessibleCounterpart != null)
                {
                    accshapes[shape.AcccessibleCounterpart.getAccessibleContext()] = shape;
                }
            }
            return(uid);
        }