/// <summary>
 /// Sets the current bounding box by shape.
 /// </summary>
 /// <param name="currentSelectedShape">The current selected shape.</param>
 public void SetCurrentBoundingBoxByShape(OoShapeObserver currentSelectedShape)
 {
     if (currentSelectedShape != null && currentSelectedShape.IsValid())
     {
         CurrentBoundingBox = currentSelectedShape.GetAbsoluteScreenBoundsByDom();
     }
     else CurrentBoundingBox = new Rectangle(-1, -1, 0, 0);
 }
 /// <summary>
 /// Gets the audio text for the given element and send it immediately to the audio renderer.
 /// </summary>
 /// <param name="element">The element to get the text of.</param>
 /// <param name="additionalText">An additional text, that is put behind the element properties and befor the label (if available).</param>
 /// <returns>The describing string of the element in the following form: [ROLE] [NAME] [TITLE] (addintionalText) [TEXT]</returns>
 public static string PlayElementImmediately(OoShapeObserver element, string additionalText = "")
 {
     String text = GetElementAudioText(element, additionalText);
     if (!String.IsNullOrWhiteSpace(text))
     {
         audio.PlaySoundImmediately(text);
     }
     return text;
 }
 public static string PlayElementTitleAndDescriptionImmediately(OoShapeObserver element)
 {
     String text = GetElementAudioText(element);
     if (!String.IsNullOrWhiteSpace(element.Description)) text += " - " + LL.GetTrans("tangram.oomanipulation.element_speaker.description", element.Description);
     if (!String.IsNullOrWhiteSpace(text))
     {
         audio.PlaySoundImmediately(text);
     }
     return text;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OoPolygonPointsObserver" /> class.
        /// </summary>
        /// <param name="shape">The corresponding shape.</param>
        /// <exception cref="ArgumentNullException">shape</exception>
        /// <exception cref="ArgumentException">shape must be a polygon or a bezier curve;shape</exception>
        public OoPolygonPointsObserver(OoShapeObserver shape)
        {
            if (shape == null) throw new ArgumentNullException("shape");
            if (!PolygonHelper.IsFreeform(shape.Shape)) throw new ArgumentException("shape must be a polygon or a bezier curve", "shape");

            Shape = shape;
            Shape.BoundRectChangeEventHandlers += Shape_BoundRectChangeEventHandlers;
            Shape.ObserverDisposing += Shape_ObserverDisposing;
            Update();

        }
示例#5
0
        /// <summary>
        /// Gets the last child on the current.
        /// </summary>
        /// <returns></returns>
        public OoShapeObserver GetLastChild()
        {
            OoShapeObserver child = null;

            if (DrawPage != null && PagesObserver != null)
            {
                if (DrawPage is XDrawPage)
                {
                    TimeLimitExecutor.WaitForExecuteWithTimeLimit(500, () =>
                    {
                        try
                        {
                            int childCount = ((XDrawPage)DrawPage).getCount();
                            if (childCount > 0)
                            {
                                var anyLastChild = ((XDrawPage)DrawPage).getByIndex(childCount - 1);
                                if (anyLastChild.hasValue())
                                {
                                    var lastChild = anyLastChild.Value;
                                    //util.Debug.GetAllInterfacesOfObject(lastChild);

                                    if (lastChild is XShape)
                                    {
                                        child = PagesObserver.GetRegisteredShapeObserver(lastChild as XShape, this);
                                    }
                                    else
                                    {
                                        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 last child: " + ex);
                        }
                    }, "GetLastChild");
                }
            }

            return(child);
        }
        /// <summary>
        /// Moves to the next element.
        /// </summary>
        /// <param name="shape">The shape to get the next sibling.</param>
        /// <returns>
        /// The next shape on the screen if possible otherwise the next in the DOM if possible otherwise <c>null</c>
        /// </returns>
        public static OoShapeObserver MoveToNext(OoShapeObserver shape)
        {
            if (shape != null && shape.IsValid())
            {
                // move thought the Accessible tree because this elements should be visible on the screen and the tree navigation is faster
                // TODO remove false to use search in accessibility tree again. Currently accessing the page AccessibleShape element during search crashes openoffice!
                if (false && shape.AccComponent != null && shape.AccComponent.IsValid())
                {
                    OoAccComponent comp = shape.AccComponent;

                    while (true)
                    {
                        OoAccComponent next = moveToNextComponent(comp);

                        if (next != null && next != comp && next.IsValid())
                        {
                            if (acceptAsUsableShape(next))
                            {
                                OoShapeObserver obs = getObserverForAccessible(next, shape.Page);
                                if (obs != null) return obs;
                                else break;
                            }
                            else
                            {
                                comp = next;
                                continue;
                            }
                        }
                        break;
                    }
                }
                
                // go through the dom tree
                {
                    return moveToNextShape(shape);
                }
            }

            return null;
        }
        /// <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();
        }
        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) { }
        }
        /// <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();
        }
        /// <summary>
        /// Check if the accessible object is corresponding to the  given shape observer.
        /// </summary>
        /// <param name="acc">The accessible object to test.</param>
        /// <param name="sObs">The shape observer to test.</param>
        /// <returns><c>true</c> if the acc is related to changes in the observer. If this is true,
        /// the AccessibleCounterpart field of the OoShapeObserver is updated as well</returns>
        internal static bool AccCorrespondsToShapeObserver(XAccessible acc, OoShapeObserver sObs)
        {
            bool result = false;

            if (acc != null && sObs != null)
            {
                String hash = sObs.GetHashCode().ToString() + "_";
                if (sObs.IsText)
                {
                    // use description
                    string oldDescription = sObs.Description;
                    sObs.Description = hash + oldDescription;
                    if (OoAccessibility.GetAccessibleDesc(acc).StartsWith(hash))
                    {
                        result = true;
                    }
                    sObs.Description = oldDescription;
                }
                else
                {
                    // use name
                    string oldName = sObs.Name;
                    sObs.Name = hash + oldName;
                    if (OoAccessibility.GetAccessibleName(acc).StartsWith(hash))
                    {
                        result = true;
                    }
                    sObs.Name = oldName;
                }
            }
            if (result)
            {
                sObs.AcccessibleCounterpart = acc;
            }
            return(result);
        }
        private void setAccessibleCounterpart(OoShapeObserver shape)
        {
            if (shape != null)
            {
                string oldName = shape.Name;
                string newName = shape.Name + "_" + shape.GetHashCode() + " ";
                shape.Name = newName;
                unoidl.com.sun.star.accessibility.XAccessible counterpart = null;
                if (shape.Parent != null && shape.Parent.AcccessibleCounterpart != null)
                {
                    counterpart = OoAccessibility.GetAccessibleCounterpartFromHash(shape.Shape, shape.Parent.AcccessibleCounterpart as unoidl.com.sun.star.accessibility.XAccessibleContext);
                }
                else
                {
                    counterpart = OoAccessibility.GetAccessibleCounterpartFromHash(shape.Shape, Document.AccComp as unoidl.com.sun.star.accessibility.XAccessibleContext);
                }
                if (counterpart != null)
                {
                    shape.AcccessibleCounterpart = counterpart;
                }

                shape.Name = oldName;
            }
        }
 /// <summary>
 /// Moves to the parent of the shape in the DOM.
 /// </summary>
 /// <param name="shape">The child shape.</param>
 /// <returns>the parent or <c>null</c></returns>
 private static OoShapeObserver moveToParentShape(OoShapeObserver shape)
 {
     if (shape != null)
     {
         return shape.GetParent();
     }
     return null;
 }
 /// <summary>
 /// Moves to next sibling shape in the DOM.
 /// </summary>
 /// <param name="shape">The shape to start.</param>
 /// <returns></returns>
 private static OoShapeObserver moveToPreviousShape(OoShapeObserver shape)
 {
     if (shape != null )
     {
         return shape.GetPreviousSibling();
     }
     return null;
 }
        /// <summary>
        /// Moves to a child element.
        /// </summary>
        /// <param name="shape">The parent shape to get the child of.</param>
        /// <param name="index">The index of the child to get (infinite loop by modulo child count).</param>
        /// <returns>
        /// The child shape on the screen if possible otherwise the child in the DOM if possible otherwise <c>null</c>
        /// </returns>
        public static OoShapeObserver MoveToChild(OoShapeObserver shape, ref int index)
        {
            if (shape != null && shape.IsValid())
            {
                // move thought the Accessible tree because this elements should be visible on the screen and the tree navigation is faster
                // TODO remove false to use search in accessibility tree again. Currently accessing the page AccessibleShape element during search crashes openoffice!
                if (false && shape.AccComponent != null && shape.AccComponent.IsValid())
                {
                    OoAccComponent comp = shape.AccComponent;

                    while (true)
                    {
                        OoAccComponent child = moveToChildComponent(comp, ref index);

                        if (child != null && child != comp)
                        {
                            if (acceptAsUsableShape(child))
                            {
                                return getObserverForAccessible(child, shape.Page);
                            }
                            else
                            {
                                child = moveToChildComponent(child, ref index);
                            }
                        }
                        break;
                    }
                }
                else // go through the dom tree
                {
                    return moveToChildShape(shape, ref index);
                }
            }
            return null;
        }
        void Instance_DrawSelectionChanged(object sender, OoAccessibilitySelectionEventArgs e)
        {
            if (e != null && e.SelectedItems != null)
            {
                if (e.SelectedItems.Count > 0 && !e.SelectionBounds.IsEmpty)
                {
                    if (!e.Silent) Logger.Instance.Log(LogPriority.MIDDLE, this, "[GUI INTERACTION] selection changed, count: " + e.SelectedItems.Count.ToString());
                    SelectedBoundingBox = e.SelectionBounds;
                }
                else
                {
                    Logger.Instance.Log(LogPriority.MIDDLE, this, "[GUI INTERACTION] deselection");
                    SelectedItem = null;
                    SelectedBoundingBox = new Rectangle(-1, -1, 0, 0);
                    this.DrawSelectFocusRenderer.CurrentBoundingBox = new System.Drawing.Rectangle(-1, -1, 0, 0);
                }

                if (windowManager.FocusMode == FollowFocusModes.FOLLOW_MOUSE_FOCUS)
                {
                    if (e.SelectedItems.Count > 0)
                    {
                        SelectedBoundingBox = e.SelectionBounds;
                        if (e.Source != null && e.Source.DrawPagesObs != null)
                        {
                            SelectedItem = e.SelectedItems[0];
                        }
                        if (shapeManipulatorFunctionProxy != null && shapeManipulatorFunctionProxy.Active && this.DrawSelectFocusRenderer != null)
                        {
                            StartDrawSelectFocusHighlightingMode();
                        }
                    }

                    if (e != null && !e.Silent)
                    {
                        if (e.SelectedItems.Count > 0)
                        {
                            windowManager.MoveToObject(e.SelectionBounds); // sync view box on pin device
                        }
                        if ((e.SelectedItems.Count > 0) &&
                            (e.SelectedItems.Count > 1 || currentSelection.Count > 1 ||
                            currentSelection.Count == 0 ||
                            (currentSelection.Count > 0 && !e.SelectedItems[0].Equals(currentSelection[0])))
                            )
                        {
                            CommunicateSelection(e.SelectedItems);
                        }
                    }
                }
            }
            currentSelection = e != null && e.SelectedItems != null ? e.SelectedItems : new List<OoShapeObserver>();
        }
 private void renewRegistrationOfShape(String key, String newKey, OoShapeObserver _so, XAccessible acc)
 {
     OoShapeObserver _trash;
     shapes.TryRemove(key, out _trash);
     if (!shapes.ContainsKey(newKey)) { shapes[newKey] = _so; }
     else
     {
         //TODO: renew the name to a unique one?
         Logger.Instance.Log(LogPriority.IMPORTANT, this, "Shape with name '" + newKey + "' already registered. Cannot add this shape to list of Shapes");
     }
 }
        /// <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;
        }
        /// <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>
        public OoShapeObserver GetPreviousSibling()
        {
            if (this.Page != null && this.Page.PagesObserver != null)
            {
                XShape s = getPreviousSiblingByXShape();
                OoShapeObserver sobs = getShapeObserverFromXShape(s);

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

                return sobs;
            }
            return null;
        }
        ///// <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;
        }
        /// <summary>
        /// Gets the first child of the current page.
        /// </summary>
        /// <returns></returns>
        public OoShapeObserver GetFirstChild()
        {
            if (DrawPage != null && PagesObserver != null)
            {
                if (DrawPage is XDrawPage)
                {
                    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)
                                {
                                    var shapeObs = PagesObserver.GetRegisteredShapeObserver(firstChild as XShape, this);
                                    if (shapeObs != null)
                                    {
                                        if (shapeObs.AcccessibleCounterpart == null)
                                        {
                                            shapeObs.Update();
                                        }
                                    }
                                    else
                                    {
                                        //TODO: register this shape
                                        OoShapeObserver newShapeObserver = new OoShapeObserver(firstChild as XShape, this);
                                        PagesObserver.RegisterUniqueShape(newShapeObserver);
                                        return newShapeObserver;
                                    }
                                    return shapeObs;
                                }
                                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);
                    }
                }
            }

            return null;
        }
        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 = 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 = new OoShapeObserver(anyShape.Value as XShape, this);
                                    }
                                    else
                                    {
                                        so = 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); }
        }
 public TextElemet(OoShapeObserver shape)
 {
     Shape = shape;
     if (shape != null)
     {
         Text = shape.Text;
         ScreenPosition = shape.GetRelativeScreenBoundsByDom();
         ObjectBoundingBox = BrailleTextView.MakeZoomBoundingBox(ScreenPosition, WindowManager.GetPrintZoomLevel());
         Matrix = BrailleTextView.BrailleRenderer.RenderMatrix(ObjectBoundingBox.Width, Text);
         Position = new Point(ObjectBoundingBox.X, ObjectBoundingBox.Y);
         Center = new Point(ObjectBoundingBox.X + (ObjectBoundingBox.Width / 2), ObjectBoundingBox.Y + (ObjectBoundingBox.Height / 2));
     }
     else
     {
         Center = Position = new Point();
         Matrix = new bool[0, 0];
         ObjectBoundingBox = ScreenPosition = new Rectangle();
         Text = String.Empty;
     }
 }
        /// <summary>
        /// Determines whether [is elements bounding box visible in view] [the specified visible area].
        /// </summary>
        /// <param name="visibleArea">The visible area.</param>
        /// <param name="shape">The shape.</param>
        /// <returns>
        /// 	<c>true</c> if [is elements bounding box visible in view] [the specified visible area]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsElementsBoundingBoxVisibleInView(Rectangle visibleArea, OoShapeObserver shape, double zoomFactor = 1)
        {
            if (visibleArea != null && !visibleArea.IsEmpty && shape != null)
            {
                Rectangle screenPos = shape.GetRelativeScreenBoundsByDom();
                Rectangle relativeScreenPos = MakeZoomBoundingBox(screenPos, zoomFactor);
                return DoBoundingBoxesCollide(visibleArea, relativeScreenPos);
            }

            return false;
        }
        /// <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())
            {
                // 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;
        }
        /// <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;
        }
 void Shape_ObserverDisposing(object sender, EventArgs e)
 {
     Shape = null;
     CachedPolyPointList = null;
 }
 /// <summary>
 /// Check if the accessible object is corresponding to the  given shape observer.
 /// </summary>
 /// <param name="acc">The accessible object to test.</param>
 /// <param name="sObs">The shape observer to test.</param>
 /// <returns><c>true</c> if the acc is related to changes in the observer. If this is true, 
 /// the AccessibleCounterpart field of the OoShapeObserver is updated as well</returns>
 internal static bool AccCorrespondsToShapeObserver(XAccessible acc, OoShapeObserver sObs)
 {
     bool result = false;
     if (acc != null && sObs != null)
     {
         String hash = sObs.GetHashCode().ToString() + "_";
         if (sObs.IsText)
         {
             // use description
             string oldDescription = sObs.Description;
             sObs.Description = hash + oldDescription;
             if (OoAccessibility.GetAccessibleDesc(acc).StartsWith(hash))
             {
                 result = true;
             }
             sObs.Description = oldDescription;
         }
         else
         {
             // use name
             string oldName = sObs.Name;
             sObs.Name = hash + oldName;
             if (OoAccessibility.GetAccessibleName(acc).StartsWith(hash))
             {
                 result = true;
             }
             sObs.Name = oldName;
         }
     }
     if (result)
     {
         sObs.AcccessibleCounterpart = acc;
     }
     return result;
 }
        /// <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);
        }
        private void setAccessibleCounterpart(OoShapeObserver shape)
        {
            if (shape != null)
            {
                string oldName = shape.Name;
                string newName = shape.Name + "_" + shape.GetHashCode() + " ";
                shape.Name = newName;
                unoidl.com.sun.star.accessibility.XAccessible counterpart = null;
                if (shape.Parent != null && shape.Parent.AcccessibleCounterpart != null)
                {
                    counterpart = OoAccessibility.GetAccessibleCounterpartFromHash(shape.Shape, shape.Parent.AcccessibleCounterpart as unoidl.com.sun.star.accessibility.XAccessibleContext);
                }
                else
                {
                    counterpart = OoAccessibility.GetAccessibleCounterpartFromHash(shape.Shape, Document.AccComp as unoidl.com.sun.star.accessibility.XAccessibleContext);
                }
                if (counterpart != null) shape.AcccessibleCounterpart = counterpart;

                shape.Name = oldName;
            }
        }
 void Shape_ObserverDisposing(object sender, EventArgs e)
 {
     Shape = null;
     CachedPolyPointList = null;
 }
 /// <summary>
 /// Gets the current GUI selection.
 /// </summary>
 /// <returns></returns>
 public OoShapeObserver GetCurrentSelection()
 {
     if (OoDrawAccessibilityObserver.Instance != null && OoDrawAccessibilityObserver.Instance.LastSelection != null && OoDrawAccessibilityObserver.Instance.LastSelection.SelectedItems != null && OoDrawAccessibilityObserver.Instance.LastSelection.SelectedItems.Count > 0)
     {
         this.SelectedItem = OoDrawAccessibilityObserver.Instance.LastSelection.SelectedItems[0];
         this.SelectedBoundingBox = OoDrawAccessibilityObserver.Instance.LastSelection.SelectionBounds;
         return this.SelectedItem;
     }
     return null;
 }
        /// <summary>
        /// Removes the child and his children from the shapes list.
        /// </summary>
        /// <param name="sObs">The s obs.</param>
        void removeChild(OoShapeObserver sObs)
        {
            if (sObs != null && shapes.ContainsKey(sObs.Name))
            {
                OoShapeObserver trash;
                shapes.TryRemove(sObs.Name, out trash);

                String trashName = sObs.Name;
                shapeIds.TryTake(out trashName);

                if (trash != null)
                {
                    foreach (var item in trash.GetChilderen())
                    {
                        removeChild(item);
                    }
                }
            }
        }
 /// <summary>
 /// Moves to next sibling shape in the DOM.
 /// </summary>
 /// <param name="shape">The shape to start.</param>
 /// <returns></returns>
 private static OoShapeObserver moveToNextShape(OoShapeObserver shape)
 {
     if (shape != null)
     {
         return shape.GetNextSibling();
     }
     return null;
 }
        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) { }

        }
 /// <summary>
 /// Moves to the requested child  of the shape in the DOM.
 /// </summary>
 /// <param name="shape">The parent shape.</param>
 /// <param name="number">The childs' index.</param>
 /// <returns>the child or <c>null</c></returns>
 private static OoShapeObserver moveToChildShape(OoShapeObserver shape, ref int number)
 {
     if (shape != null)
     {
         return shape.GetChild(number);
     }
     return null;
 }
        /// <summary>
        /// Try to generate an unique id.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <returns></returns>
        public string GetUniqueId(OoShapeObserver shape)
        {
            int uidCount = 0;
            String uid = String.Empty;
            if (shape != null && shape.Shape != null)
            {
                if (OoUtils.ElementSupportsService(shape.Shape, OO.Services.DRAW_SHAPE_TEXT))
                {
                    uid = shape.Name;
                    if (String.IsNullOrWhiteSpace(uid)
                        || uid.Contains('\'')
                        || uid.Contains(' '))
                    {
                        uid = shape.UINamePlural;
                        System.Diagnostics.Debug.WriteLine("______the start name for the text shape is now : '" + uid + "'");
                    }
                }
                else
                {
                    uid = shape.Name;
                }
                if (String.IsNullOrWhiteSpace(uid))
                {
                    uid = shape.UINameSingular + "_" + (++uidCount);
                }

                while (shapeIds.Contains(uid))
                {
                    int i_ = uid.LastIndexOf('_');
                    if (i_ >= 0) { uid = uid.Substring(0, i_ + 1); }
                    else { uid += "_"; }
                    uid += ++uidCount;
                }
                shapeIds.Add(uid);
            }
            Logger.Instance.Log(LogPriority.DEBUG, this, "new Shape with name: " + uid + " registered");
            return uid;
        }
        private void handleSelectionChanged(OoAccessibleDocWnd doc, AccessibleEventObject aEvent)
        {
            // check the global selection supplier
            if (doc != null)
            {
                try
                {
                    var controller = doc.Controller;
                    if (controller != null && controller is XSelectionSupplier)
                    {
                        XShapes selectedShapes = OoSelectionObserver.GetSelection(controller as XSelectionSupplier) as XShapes;

                        OoDrawPagesObserver pagesObserver = doc.DrawPagesObs;
                        if (selectedShapes != null && pagesObserver != null)
                        {
                            List<OoShapeObserver> selectedShapesList = new List<OoShapeObserver>();
                            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
                                        //&& shapeObserver.IsValid()
                                        )
                                    {
                                        if (shapeObserver.IsValid())
                                        {
                                            selectedShapesList.Add(shapeObserver);
                                        }
                                        else
                                        {
                                            shapeObserver.Dispose();
                                            XDrawPage page = OoDrawUtils.GetPageForShape(shape);
                                            OoDrawPageObserver dpObs = pagesObserver.GetRegisteredPageObserver(page);
                                            OoShapeObserver so = new OoShapeObserver(shape, dpObs);
                                            pagesObserver.RegisterUniqueShape(so);
                                        }

                                    }
                                }
                            }
                            fireDrawSelectionChangedEvent(doc, selectedShapesList, aEvent == null);
                        }
                        else
                        {
                            // no selection
                            fireDrawSelectionChangedEvent(doc, new List<OoShapeObserver>(), aEvent == null);
                            return;
                        }
                    }
                }
                catch (unoidl.com.sun.star.lang.DisposedException ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Source + " " + ex.Message);
                }
            }
        }
示例#38
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); }
        }