//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);
        }
        /// <summary>
        /// Gets the accessible role of the XAccessible obj if possible.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns>AccessibleRole or AccessibleRole.UNKNOWN</returns>
        public static AccessibleRole GetAccessibleRole(XAccessibleContext obj)
        {
            if (obj != null)
            {
                AccessibleRole r = AccessibleRole.UNKNOWN;
                try
                {
                    r = tryGetAccessibleRole(obj);
                    return r;
                }
                catch (unoidl.com.sun.star.lang.DisposedException)
                {
                    return AccessibleRole.INVALID;
                    //Logger.Instance.Log(LogPriority.DEBUG, "can't get accessibility role - the object is already disposed", ex); 
                }

                catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, "can't get accessibility role", ex); }
            }
            return AccessibleRole.UNKNOWN;
        }
 private static AccessibleRole tryGetAccessibleRole(XAccessibleContext obj)
 {
     AccessibleRole r = AccessibleRole.UNKNOWN;
     try
     {
         TimeLimitExecutor.WaitForExecuteWithTimeLimit(100,
                      () =>
                      {
                          try
                          {
                              short role = obj.getAccessibleRole();
                              r = GetRoleFromShort(role);
                          }
                          catch (unoidl.com.sun.star.lang.DisposedException)
                          {
                              r = AccessibleRole.INVALID;
                          }
                          catch (ThreadAbortException) { r = AccessibleRole.UNKNOWN; }
                      }, "GetAccRole4XAccCont");
     }
     catch (System.Threading.ThreadAbortException) { }
     return r;
 }
        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) { }
        }
        public static XAccessible GetAccessibleChildDescriptionStartsWith(String descriptionStart, XAccessibleContext haystack)
        {
            try
            {
                if (haystack != null && !String.IsNullOrWhiteSpace(descriptionStart))
                {
                    string desc = GetAccessibleDesc(haystack);
                    if (desc != null && desc.StartsWith(descriptionStart))
                    {
                        return haystack as XAccessible;
                    }

                    if (haystack.getAccessibleChildCount() > 0)
                    {
                        int childCount = haystack.getAccessibleChildCount();
                        for (int i = 0; i < childCount; i++)
                        {
                            var c = haystack.getAccessibleChild(i);
                            if (c != null)
                            {
                                if (c.Equals(haystack)) continue;
                                var child = GetAccessibleChildDescriptionStartsWith(descriptionStart, c.getAccessibleContext());
                                if (child != null) return child;
                            }
                        }
                    }
                }
            }
            catch { }
            return null;
        }
        /// <summary>
        /// Gets the name of the accessible child with.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="haystack">The haystack.</param>
        /// <returns>The first found XAccessible with a partly equal name or NULL</returns>
        public static XAccessible GetAccessibleChildWithName(String name, XAccessibleContext haystack)
        {
            try
            {
                if (haystack != null && !String.IsNullOrWhiteSpace(name))
                {
                    if (GetAccessibleName(haystack).Equals(name))
                    {
                        return haystack as XAccessible;
                    }

                    if (haystack.getAccessibleChildCount() > 0)
                    {
                        int childCount = haystack.getAccessibleChildCount();
                        for (int i = 0; i < childCount; i++)
                        {
                            var c = haystack.getAccessibleChild(i);
                            if (c != null)
                            {
                                if (c.Equals(haystack)) continue;
                                var child = GetAccessibleChildWithName(name, c);
                                if (child != null) return child;
                            }
                        }
                    }
                }
            }
            catch { }
            return null;
        }
        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;
        }
        /// <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;
        }
        /// <summary>
        /// Prints some accessible infos into the Debug Output.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public static String PrintAccessibleInfos(XAccessibleContext accessibleContext, bool printStates = false)
        {
            String output = "";
            if (accessibleContext != null)
            {
                var role = GetRoleFromShort(accessibleContext.getAccessibleRole());

                var name = accessibleContext.getAccessibleName();

                var desc = accessibleContext.getAccessibleDescription();
                output += "Role: " + role + " | Name: '" + name + "' Description: '" + desc + "'";

                var child = accessibleContext.getAccessibleChildCount();
                output += " (has " + child + " children)";

                if (printStates)
                {
                    var states = GetAccessibleStates(accessibleContext.getAccessibleStateSet());
                    foreach (var item in states)
                    {
                        output += "\r\nState: " + item;
                    }
                }
            }
            return output;
        }
        private OoShapeObserver searchRegisterdSapeObserverByAccessibleName(string accName, XAccessibleContext cont, bool searchUnregistered = true)
        {
            if (accshapes.ContainsKey(cont))
            {
                return(accshapes[cont]);
            }

            // if the name contains spaces - e.g. for text frames etc.
            if (accName.Contains(" "))
            {
                System.Diagnostics.Debug.WriteLine("problem in finding the correct shape - name contains space characters");
                var    tokens = accName.Split(' ');
                string sName  = String.Empty;
                foreach (var token in tokens)
                {
                    sName += (String.IsNullOrEmpty(sName) ? "" : " ") + token;
                    OoShapeObserver _so = getRegisteredShapeObserver(sName);
                    if (AccCorrespondsToShapeObserver(cont as XAccessible, _so))
                    {
                        return(_so);
                    }
                }
            }

            // if name is already registered
            OoShapeObserver so = getRegisteredShapeObserver(accName);

            if (AccCorrespondsToShapeObserver(cont as XAccessible, so))
            {
                return(so);
            }

            // search through all registered shapes
            so = searchRegisteredShapeByAccessible(accName, cont as XAccessible);
            if (AccCorrespondsToShapeObserver(cont as XAccessible, so))
            {
                return(so);
            }


            if (searchUnregistered)
            {
                so = searchUnregisteredShapeByAccessible(accName, cont);
            }

            return(null);
        }
 /// <summary>
 /// Gets the 'Name' part of the accessible name.
 /// The accessible name is a combination of 'Name' + " " + 'Title' [or Text] + [...]
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <returns>The first part of the accessible name up to the first appearence of an space character</returns>
 public static String GetAccessibleNamePart(XAccessibleContext obj)
 {
     String name = String.Empty;
     String accName = GetAccessibleName(obj);
     if (!String.IsNullOrWhiteSpace(accName))
     {
         int deviderPos = accName.IndexOf(' ');
         if (deviderPos > 0)
         {
             name = accName.Substring(0, deviderPos);
         }
         else
         {
             name = accName;
         }
     }
     return name;
 }
 /// <summary>
 /// Gets the name of the accessible.
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <returns></returns>
 public static String GetAccessibleName(XAccessibleContext obj)
 {
     try
     {
         string name = obj != null ? obj.getAccessibleName() : String.Empty;
         return name;
     }
     catch (System.Exception ex)
     {
         try
         {
             Logger.Instance.Log(LogPriority.DEBUG, "OoAccessibility", "Could not get the Accessible name for object: " + ex);
             //System.Diagnostics.Debug.WriteLine("------------- ERROR FOR ELEMENT ---------------");
             //util.Debug.GetAllServicesOfObject(obj);
             //util.Debug.GetAllInterfacesOfObject(obj);
             //System.Diagnostics.Debug.WriteLine("------------- END OF ERROR MESSAGE ---------------");
         }
         catch { }
         return String.Empty;
     }
 }
        //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;
        }
        private OoShapeObserver searchRegisterdSapeObserverByAccessibleName(string accName, XAccessibleContext cont, bool searchUnregistered = true)
        {
            if (accshapes.ContainsKey(cont))
                return accshapes[cont];

            // if the name contains spaces - e.g. for text frames etc.
            if (accName.Contains(" "))
            {
                System.Diagnostics.Debug.WriteLine("problem in finding the correct shape - name contains space characters");
                var tokens = accName.Split(' ');
                string sName = String.Empty;
                foreach (var token in tokens)
                {
                    sName += (String.IsNullOrEmpty(sName) ? "" : " ") + token;
                    OoShapeObserver _so = getRegisteredShapeObserver(sName);
                    if (AccCorrespondsToShapeObserver(cont as XAccessible, _so))
                    {
                        return _so;
                    }
                }
            }

            // if name is already registered
            OoShapeObserver so = getRegisteredShapeObserver(accName);
            if (AccCorrespondsToShapeObserver(cont as XAccessible, so))
                return so;

            // search through all registered shapes
            so = searchRegisteredShapeByAccessible(accName, cont as XAccessible);
            if (AccCorrespondsToShapeObserver(cont as XAccessible, so))
                return so;


            if (searchUnregistered) so = searchUnregisteredShapeByAccessible(accName, cont);

            return null;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OoAccComponent"/> struct.
 /// </summary>
 /// <param name="accComp">The base XAccessibleComponent that shoulb be wraped.</param>
 private OoAccComponent(XAccessibleComponent accComp)
 {
     this.AccComp = accComp;
     AccCont = (AccComp != null && AccComp is XAccessibleContext) ? AccComp as XAccessibleContext :
         AccComp is XAccessible ? ((XAccessible)AccComp).getAccessibleContext() : null;
 }
Exemple #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OoAccComponent"/> struct.
 /// </summary>
 /// <param name="accComp">The base XAccessibleComponent that shoulb be wraped.</param>
 private OoAccComponent(XAccessibleComponent accComp)
 {
     this.AccComp = accComp;
     AccCont      = (AccComp != null && AccComp is XAccessibleContext) ? AccComp as XAccessibleContext :
                    AccComp is XAccessible ? ((XAccessible)AccComp).getAccessibleContext() : null;
 }
 /// <summary>
 /// Gets the accessible description.
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <returns></returns>
 public static String GetAccessibleDesc(XAccessibleContext obj) { return obj != null ? obj.getAccessibleDescription() : String.Empty; }