예제 #1
0
        internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild)
        {
            WindowsToolbar wtv = null;

            // By calling Accessible.CreateNativeFromEvent() instead of AccessibleObjectFromWindow() only controls with a native
            // implementation of IAccessible will be found.  OleAcc will not create a IAccessible proxy, since
            // Accessible.CreateNativeFromEvent() by passes OleAcc by sending a WM_GETOBJECT directly to the control and creating
            // IAccessible from the return, if it can.
            Accessible acc = Accessible.CreateNativeFromEvent(hwnd, NativeMethods.OBJID_CLIENT, NativeMethods.CHILD_SELF);

            if (acc != null)
            {
                AccessibleRole role = acc.Role;
                if (role == AccessibleRole.MenuBar || role == AccessibleRole.MenuPopup)
                {
                    wtv = new WindowsToolbarAsMenu(hwnd, null, 0, acc);
                }
            }

            if (wtv == null)
            {
                wtv = new WindowsToolbar(hwnd, null, 0);
            }

            return(idChild == 0 ? wtv : wtv.CreateToolbarItem(idChild - 1));
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Find the child window with the specified name and/or role. This method recursively
        /// goes down the hierarchy until it finds the window.
        /// </summary>
        /// <param name="name">Accessibility name of the matching window, or <c>null</c></param>
        /// <param name="role">Accessibility role of the matching window, or
        /// <see cref="AccessibleRole.None"/>.</param>
        /// <returns>A new <see cref="AccessibilityHelper"/> object that wraps the matched
        /// window.</returns>
        /// <remarks>If you provide only one parameter, it matches only that parameter.
        /// If you specify both parameters it tries to match both. </remarks>
        /// ------------------------------------------------------------------------------------
        public AccessibilityHelper FindChild(string name, AccessibleRole role)
        {
            if (name == null && role == AccessibleRole.None)
            {
                return(null);
            }

            AccessibilityHelper ah = null;

            foreach (AccessibilityHelper child in this)
            {
                if (child == null)
                {
                    continue;
                }
                // does this object match?
                if ((name == null || name == child.Name) &&
                    (role == AccessibleRole.None || role == child.Role))
                {
                    return(child);
                }
                if (child.m_fRealAccessibleObject)
                {
                    // look through the child objects
                    ah = child.FindChild(name, role);
                    if (ah != null)
                    {
                        return(ah);
                    }
                }
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// A linked list node that represents one step in a GUI path.
        /// A step in the typedPath is represented by this node.
        /// Following steps generate subsequent GuiPath nodes recursively.
        /// </summary>
        /// <param name="typedPath">a typed path</param>
        public GuiPath(string typedPath)
        {
            // remove the first step from the typedPath and process it
            int last = 0;
            string step = Utilities.GetFirstStep(typedPath, out last);
            Utilities.SplitTypedToken(step, out m_name, out m_type);
            if (m_type == "value" && (m_name == null || m_name == ""))
                m_name = ""; // want it to be empty
            else if (m_name == null || m_name == "") m_name = "NAMELESS";
            try
            {
                int roleValue = Convert.ToInt32(m_type);
                m_role = (AccessibleRole)roleValue;
            }
            catch (Exception)
            {
                m_role = Utilities.TypeToRole(m_type);
            }

            // Parse the name
            string name;
            string varId;
            m_Nth = parseIndex(m_name, out name, out varId);
            if (m_name == name) m_Nth = 1;
            m_name = name;
            m_varId = varId;

            // if not consumed, split off the end of the path as a child path
            if (1 + last < typedPath.Length)
            {
                m_child = new GuiPath(typedPath.Substring(last + 1));
                m_child.m_parent = this;
            }
        }
예제 #4
0
        /// <summary>
        /// A linked list node that represents one step in a GUI path.
        /// A step in the typedPath is represented by this node.
        /// Following steps generate subsequent GuiPath nodes recursively.
        /// </summary>
        /// <param name="typedPath">a typed path</param>
        public GuiPath(string typedPath)
        {
            // remove the first step from the typedPath and process it
            int    last = 0;
            string step = Utilities.GetFirstStep(typedPath, out last);

            Utilities.SplitTypedToken(step, out m_name, out m_type);
            if (m_type == "value" && (m_name == null || m_name == ""))
            {
                m_name = "";                 // want it to be empty
            }
            else if (m_name == null || m_name == "")
            {
                m_name = "NAMELESS";
            }
            try
            {
                int roleValue = Convert.ToInt32(m_type);
                m_role = (AccessibleRole)roleValue;
            }
            catch (Exception)
            {
                m_role = Utilities.TypeToRole(m_type);
            }

            // Parse the name
            string name;
            string varId;

            m_Nth = parseIndex(m_name, out name, out varId);
            if (m_name == name)
            {
                m_Nth = 1;
            }
            m_name  = name;
            m_varId = varId;

            if (m_type == "para" || m_type == "line")
            {
                try { m_Nth = Convert.ToInt32(m_name); }
                catch (System.FormatException)
                { Assert.Fail(m_type + ": needs to be followed by an integer, not " + m_name); }
                if (m_type == "para")
                {
                    m_name = "Paragraph";
                }
                if (m_type == "line")
                {
                    m_name = "Srting";
                }
            }

            // if not consumed, split off the end of the path as a child path
            if (1 + last < typedPath.Length)
            {
                m_child          = new GuiPath(typedPath.Substring(last + 1));
                m_child.m_parent = this;
            }
        }
        public static void SetExceptionControl(Control control, string text, AccessibleRole role, bool autoSize)
        {
            var nameControl = control;

            nameControl.Text           = text;
            nameControl.AccessibleRole = role;
            nameControl.AutoSize       = autoSize;
        }
        public void AccessibleRoleControlTypeMap_GetControlType_ReturnsExpectedValue(AccessibleRole role, int expectedType)
        {
            // UIA is less accessible than the test
            // so we have to use "int" type for "expectedType" argument
            UIA actual = AccessibleRoleControlTypeMap.GetControlType(role);

            Assert.Equal((UIA)expectedType, actual);
        }
        public void AccessibleRoleControlTypeMap_Contains_AllRoles(AccessibleRole role)
        {
            // Check if the map contains the role
            // If so the map returns an exist UIA_ControlTypeId
            UIA actual = AccessibleRoleControlTypeMap.GetControlType(role);

            Assert.True(actual >= UIA.ButtonControlTypeId && actual <= UIA.AppBarControlTypeId);
        }
        public void ToolStripDropDownButtonAccessibleObject_Role_IsMenuItem_ByDefault()
        {
            using ToolStripDropDownButton toolStripDropDownButton = new ToolStripDropDownButton();
            // AccessibleRole is not set = Default

            AccessibleRole actual = toolStripDropDownButton.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.MenuItem, actual);
        }
        public void VScrollBarFirstPageButtonAccessibleObject_Role_ReturnNotNull(bool createControl, RightToLeft rightToLeft, int minimum, int maximum, int value)
        {
            using VScrollBar scrollBar = GetVScrollBar(createControl, rightToLeft, minimum, maximum, value);
            ScrollBarFirstPageButtonAccessibleObject accessibleObject = GetFirstPageButton(scrollBar);
            AccessibleRole expectedRole = createControl ? AccessibleRole.PushButton : AccessibleRole.None;

            Assert.Equal(expectedRole, accessibleObject.Role);
            Assert.Equal(createControl, scrollBar.IsHandleCreated);
        }
예제 #10
0
        public void TrackBarFirstButtonAccessibleObject_Role_ReturnExpected(Orientation orientation, RightToLeft rightToLeft, bool rightToLeftLayout, bool createControl, int minimum, int maximum, int value)
        {
            using TrackBar trackBar = GetTrackBar(orientation, rightToLeft, rightToLeftLayout, createControl, value, minimum, maximum);
            TrackBar.TrackBarFirstButtonAccessibleObject accessibleObject = GetTrackBarFirstButton(trackBar);
            AccessibleRole accessibleRole = createControl ? AccessibleRole.PushButton : AccessibleRole.None;

            Assert.Equal(accessibleRole, accessibleObject.Role);
            Assert.Equal(createControl, trackBar.IsHandleCreated);
        }
        public void ToolStripMenuItemAccessibleObject_Role_IsMenuItem_ByDefault()
        {
            using ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
            // AccessibleRole is not set = Default

            AccessibleRole actual = toolStripMenuItem.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.MenuItem, actual);
        }
예제 #12
0
        public void ToolStripButtonAccessibleObject_Role_IsPushButton_ByDefault()
        {
            using ToolStripButton toolStripButton = new ToolStripButton();
            // AccessibleRole is not set = Default

            AccessibleRole actual = toolStripButton.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.PushButton, actual);
        }
        public void ToolStripSeparatorAccessibleObect_Role_IsSeparator_ByDefault()
        {
            using ToolStripSeparator toolStripSeparator = new ToolStripSeparator();
            // AccessibleRole is not set = Default

            AccessibleRole actual = toolStripSeparator.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.Separator, actual);
        }
        public void ToolStripGripAccessibleObject_Role_IsGrip_ByDefault()
        {
            using ToolStripGrip toolStripGrip = new ToolStripGrip();
            // AccessibleRole is not set = Default

            AccessibleRole actual = toolStripGrip.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.Grip, actual);
        }
예제 #15
0
        public void LinkLabelAccessibleObject_Role_IsStaticText_ByDefault()
        {
            using LinkLabel linkLabel = new LinkLabel();
            // AccessibleRole is not set = Default

            AccessibleRole actual = linkLabel.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.StaticText, actual);
            Assert.False(linkLabel.IsHandleCreated);
        }
예제 #16
0
        public void DateTimePickerAccessibleObject_Role_IsComboBox_ByDefault()
        {
            using DateTimePicker dateTimePicker = new();
            // AccessibleRole is not set = Default

            AccessibleRole actual = dateTimePicker.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.ComboBox, actual);
            Assert.False(dateTimePicker.IsHandleCreated);
        }
예제 #17
0
        public void FormAccessibleObject_Role_IsClient_ByDefault()
        {
            using Form form = new Form();
            // AccessibleRole is not set = Default

            AccessibleRole actual = form.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.Client, actual);
            Assert.False(form.IsHandleCreated);
        }
        public void ToolStripStatusLabelAccessibleObject_Role_IsExpected_ByDefault(bool isLink, AccessibleRole expectedRole)
        {
            using ToolStripStatusLabel toolStripStatusLabel = new ToolStripStatusLabel();
            toolStripStatusLabel.IsLink = isLink;
            // AccessibleRole is not set = Default

            AccessibleRole actual = toolStripStatusLabel.AccessibilityObject.Role;

            Assert.Equal(expectedRole, actual);
        }
        public void CalendarRowAccessibleObject_Role_IsRow()
        {
            using MonthCalendar control = new();
            CalendarRowAccessibleObject rowAccessibleObject = CreateCalendarRowAccessibleObject(control);

            AccessibleRole actual = rowAccessibleObject.Role;

            Assert.Equal(AccessibleRole.Row, actual);
            Assert.False(control.IsHandleCreated);
        }
예제 #20
0
        public void PropertyGridViewAccessibleObject_Role_IsTable_ByDefault()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            // AccessibleRole is not set = Default

            AccessibleRole actual = propertyGrid.GridViewAccessibleObject.Role;

            Assert.Equal(AccessibleRole.Table, actual);
            Assert.False(propertyGrid.IsHandleCreated);
        }
        public void DropDownButtonAccessibleObject_Role_IsPushButton_ByDefault()
        {
            using DropDownButton dropDownButton = new DropDownButton();
            // AccessibleRole is not set = Default

            AccessibleRole actual = dropDownButton.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.PushButton, actual);
            Assert.False(dropDownButton.IsHandleCreated);
        }
예제 #22
0
        public void CalendarWeekNumberCellAccessibleObject_Role_IsRowHeader()
        {
            using MonthCalendar control = new();
            CalendarWeekNumberCellAccessibleObject cellAccessibleObject = CreateCalendarWeekNumberCellAccessibleObject(control);

            AccessibleRole actual = cellAccessibleObject.Role;

            Assert.Equal(AccessibleRole.RowHeader, actual);
            Assert.False(control.IsHandleCreated);
        }
예제 #23
0
        public void MonthCalendarAccessibleObject_Role_IsExpected_ByDefault()
        {
            using MonthCalendar monthCalendar = new MonthCalendar();
            // AccessibleRole is not set = Default

            AccessibleRole actual = monthCalendar.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.Table, actual);
            Assert.False(monthCalendar.IsHandleCreated);
        }
예제 #24
0
 bool IsGridRole(IAccessible instance)
 {
     try {
         AccessibleRole role = (AccessibleRole)instance.accRole;
         return(role == AccessibleRole.Cell || role == AccessibleRole.Row || role == AccessibleRole.RowHeader || role == AccessibleRole.Column || role == AccessibleRole.ColumnHeader);
     }
     catch {
         return(false);
     }
 }
예제 #25
0
        public void ToolStripDropDownItemAccessibleObject_Role_ReturnsExpected_ControlHasNotDefaultRole()
        {
            AccessibleRole testRole = AccessibleRole.Cell;

            using SubToolStripDropDownItem control = new();
            control.AccessibleRole = testRole;
            var accessibleObject = (ToolStripDropDownItemAccessibleObject)control.AccessibilityObject;

            Assert.Equal(testRole, accessibleObject.Role);
        }
        public void MenuStripAccessibleObject_Role_IsMenuBar_ByDefault()
        {
            using MenuStrip menuStrip = new MenuStrip();
            // AccessibleRole is not set = Default

            AccessibleRole actual = menuStrip.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.MenuBar, actual);
            Assert.False(menuStrip.IsHandleCreated);
        }
        public void LinkAccessibleObject_Role_IsLink()
        {
            using LinkLabel linkLabel = new();
            LinkAccessibleObject accessibleObject = linkLabel.Links[0].AccessibleObject;

            AccessibleRole actual = accessibleObject.Role;

            Assert.Equal(AccessibleRole.Link, actual);
            Assert.False(linkLabel.IsHandleCreated);
        }
예제 #28
0
        public void GroupBoxAccessibleObject_Role_IsGrouping_ByDefault()
        {
            using GroupBox groupBox = new GroupBox();
            // AccessibleRole is not set = Default

            AccessibleRole actual = groupBox.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.Grouping, actual);
            Assert.False(groupBox.IsHandleCreated);
        }
        public void StatusStripAccessibleObject_Role_IsStatusBar_ByDefault()
        {
            using StatusStrip statusStrip = new StatusStrip();
            // AccessibleRole is not set = Default

            AccessibleRole actual = statusStrip.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.StatusBar, actual);
            Assert.False(statusStrip.IsHandleCreated);
        }
예제 #30
0
        public void NumericUpDownAccessibleObject_Role_IsSpinButton_ByDefault()
        {
            using NumericUpDown numericUpDown = new NumericUpDown();
            // AccessibleRole is not set = Default

            AccessibleRole actual = numericUpDown.AccessibilityObject.Role;

            Assert.Equal(AccessibleRole.SpinButton, actual);
            Assert.False(numericUpDown.IsHandleCreated);
        }
예제 #31
0
 public AccessibleObject FindChildByRole(AccessibleRole role)
 {
     foreach (SystemAccessible child in GetChildren())
     {
         if (child.Role == role)
         {
             return(child);
         }
     }
     return(null);
 }
예제 #32
0
		public AccessibleObject() {
			this.owner = null;
			this.value = null;
			this.name = null;
			this.role = AccessibleRole.Default;
			this.default_action = null;
			this.description = null;
			this.help = null;
			this.keyboard_shortcut = null;
			this.state = AccessibleStates.None;
		}
예제 #33
0
		public void OverviewPage()
		{
			Assert.IsNotNull(m_dialog, "Didn't get an Import dialog");

			AccessibilityHelper overviewWnd = m_dialog.FindChild("Overview",
				AccessibleRole.Window);

			// make sure the step that contains the overview is visible
			AccessibilityHelper step = overviewWnd.Parent;
			Assert.IsTrue((step.States & AccessibleStates.Invisible) != AccessibleStates.Invisible,
				"Overview step is not visible");

			// make sure it displays the language project name
			bool fFoundLangProjName = false;
			foreach (AccessibilityHelper child in step)
			{
				if ((child.States & AccessibleStates.Invisible) == AccessibleStates.Invisible)
					continue;

				if (child.Value.IndexOf("DEB-Debug") > -1)
					fFoundLangProjName = true;
			}

			Assert.IsTrue(fFoundLangProjName, "Can't see Language Project name on dialog");

			// make sure there are no other controls in the step except text boxes
			AccessibleRole[] roles =
				new AccessibleRole[] { AccessibleRole.Text,
										AccessibleRole.Client, AccessibleRole.Window,
										AccessibleRole.StaticText};
			Array.Sort(roles);

			Assert.IsTrue(CheckControls(step, roles), "Overview page contains unexpected controls");


		}
예제 #34
0
			public static void TestAccessibility(Control c, string Default, string Description, string Name, AccessibleRole Role)
			{
				Assert.IsNotNull (c.AccessibilityObject, "Acc1");
				Assert.AreEqual (Default, c.AccessibleDefaultActionDescription, "Acc2");
				Assert.AreEqual (Description, c.AccessibleDescription, "Acc3");
				Assert.AreEqual (Name, c.AccessibleName, "Acc4");
				Assert.AreEqual (Role, c.AccessibleRole, "Acc5");
			}
예제 #35
0
 /// <summary>
 /// Most likely pairings of role to type
 /// </summary>
 /// <param name="role"></param>
 /// <returns></returns>
 private string RoleToType(AccessibleRole role)
 {
     string type = null;
     switch (role)
     {
         case AccessibleRole.Grouping:	 type = view; break;
         case AccessibleRole.List:		 type = list; break;
         case AccessibleRole.ListItem:	 type = item; break;
         case AccessibleRole.MenuBar:	 type = menubar; break;
         case AccessibleRole.MenuItem:    type = menu; break;
         case AccessibleRole.None:		 type = none; break;
         case AccessibleRole.OutlineItem: type = olitem; break;
         case AccessibleRole.PageTab:	 type = tab; break;
         case AccessibleRole.PageTabList: type = tabs; break;
         case AccessibleRole.MenuPopup:	 type = pop; break;
         case AccessibleRole.PushButton:  type = button; break;
         case AccessibleRole.RadioButton: type = radio; break;
         case AccessibleRole.Separator:	 type = sep; break;
         case AccessibleRole.StatusBar:	 type = statusbar; break;
         case AccessibleRole.Text:		 type = line; break;
         case AccessibleRole.TitleBar:	 type = titlebar; break;
         case AccessibleRole.ToolBar:	 type = toolbar; break;
         case AccessibleRole.Window:		 type = window; break;
         default :						 type = none; break;
     }
     return type;
 }
예제 #36
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Find the child window with the specified name and/or role. This method only looks
		/// in the direct children for the window (no recursion).
		/// </summary>
		/// <param name="name">Accessibility name of the matching window, or <c>null</c></param>
		/// <param name="role">Accessibility role of the matching window, or
		/// <see cref="AccessibleRole.None"/>.</param>
		/// <returns>A new <see cref="AccessibilityHelper"/> object that wraps the matched
		/// window.</returns>
		/// <remarks>If you provide only one parameter, it matches only that parameter.
		/// If you specify both parameters it tries to match both. </remarks>
		/// ------------------------------------------------------------------------------------
		public AccessibilityHelper FindDirectChild(string name, AccessibleRole role)
		{
			if (name == null && role == AccessibleRole.None)
				return null;
			Log log = Log.getOnly();
			log.writeElt("FindDirectChild");
			log.writeAttr("target", role + ":" + name);
			log.endElt();

			foreach(AccessibilityHelper child in this)
			{
				if (child == null)
					continue;
				log.writeElt("FindDirectChild");
				log.writeAttr("viewed", child.Role + ":" + child.Name);
				log.endElt();

				// does this object match?
				if (MatchNameAndRole(name, role, child))
					return child;
			}
			return null;
		}
예제 #37
0
        /// <summary>
        /// Like FindChild with nLevelsToRecurse (depth) but it builds a coded path
        /// vector that indicates exactly where the child is in the subtree.
        /// example: If the vector is [2,1,4] the window was found three levels down
        /// as the 2nd child's first child's 4th child. Note, array position 0 is level 1.
        /// If the vector has a 0, the child was not at that level or had no ancestor there.
        /// pathCode must be zeroed before calling.
        /// </summary>
        /// <param name="name">Accessibility name of the matching control, or <c>null</c></param>
        /// <param name="role">Accessibility role of the matching control, or
        /// <see cref="AccessibleRole.None"/>.</param>
        /// <param name="level">This node's level and place in pathCode. First is 1.</param>
        /// <param name="depth">Maximum number of levels to search and
        /// the size of the pathCode array. 1 is the first level (unlike nLevelsToRecurse).</param>
        /// <param name="pathCode">The path coded as child number per level downward.</param>
        /// <returns>A new <see cref="AccessibilityHelper"/> object that wraps the matched
        /// control.</returns>
        public AccessibilityHelper LocateChild(string name, AccessibleRole role, int level, int depth, ref int[] pathCode)
        {
            if (name == null && role == AccessibleRole.None || level <= 0 || depth <= 0 || level > depth)
                return null;

            AccessibilityHelper ah = null;
            int  count = 0;
            //bool found = false;

            foreach(AccessibilityHelper child in this)
            {
                count++;
                if (child == null)
                    continue;
                // does this object match?
                // treat name == "" and child.Name == null as a match
                // Note: a null string shows as "" in the debugger!
                if (MatchNameAndRole(name, role, child))
                {
                    ah = child;
                    break; // found
                }
                if (child.m_fRealAccessibleObject && depth > 1)
                {
                    // look through the child objects
                    ah = child.LocateChild(name, role, level+1, depth, ref pathCode);
                    if (ah != null)
                        break; // found
                }
            }
            pathCode[level-1] = count;
            return ah;
        }
예제 #38
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Find the child window with the specified name and/or role. This method recursively
		/// goes down the hierarchy until it finds the window.
		/// </summary>
		/// <param name="name">Accessibility name of the matching window, or <c>null</c></param>
		/// <param name="role">Accessibility role of the matching window, or
		/// <see cref="AccessibleRole.None"/>.</param>
		/// <returns>A new <see cref="AccessibilityHelper"/> object that wraps the matched
		/// window.</returns>
		/// <remarks>If you provide only one parameter, it matches only that parameter.
		/// If you specify both parameters it tries to match both. </remarks>
		/// ------------------------------------------------------------------------------------
		public AccessibilityHelper FindChild(string name, AccessibleRole role)
		{
			if (name == null && role == AccessibleRole.None)
				return null;

			AccessibilityHelper ah = null;

			foreach(AccessibilityHelper child in this)
			{
				if (child == null)
					continue;
				// does this object match?
				if ((name == null || name == child.Name) &&
					(role == AccessibleRole.None || role == child.Role))
					return child;
				if (child.m_fRealAccessibleObject)
				{
					// look through the child objects
					ah = child.FindChild(name, role);
					if (ah != null)
						return ah;
				}
			}
			return null;
		}
예제 #39
0
		/// <summary>
		/// Matches legal name and role combinations to their ah counterparts.
		/// They can match on both.
		/// Match NAMELESS to a null ah.name.
		/// Match name to ah.value when role is Alert and ah.role is anything.
		/// Match anything when name is null or #ANY.
		/// Match any ah.role when role is None.
		/// One name match and one role match must be true.
		/// </summary>
		/// <param name="name">The text to match, can be null</param>
		/// <param name="role">The Accessible role - some like Alert are special</param>
		/// <param name="ah">The accessible object</param>
		/// <returns>true if a name and a role matched</returns>
		private bool MatchNameAndRole(string name, AccessibleRole role, AccessibilityHelper ah)
		{
			bool result = false;
			bool NameResult = false;
			// check if the name is a regular expression
			if (name != null && name.StartsWith("rexp#"))
			{
				Regex rx = new Regex(name.Substring(5));
				string MatchItem = "";
				if (ah.Role == AccessibleRole.Alert) MatchItem = ah.Value;
				else                                 MatchItem = ah.Name;
				NameResult = rx.IsMatch(MatchItem);
				Log log = Log.getOnly();
				log.writeElt("match-reg-exp");
				log.writeAttr("pattern", name.Substring(5));
				log.writeAttr("to", MatchItem);
				log.writeAttr("result", result.ToString());
				log.endElt();
			}
			else if (ah.Role == AccessibleRole.Alert)
				NameResult = name == ah.Value;

			result =
				(
					NameResult
					|| name == ah.Name
					|| (name == "NAMELESS" && ah.Name == null) // should never be null, but "" instead
					|| (name == "NAMELESS" && ah.Name == "")
					|| name == null
					|| name == "#ANY"
				)
				&& (role == ah.Role || role == AccessibleRole.None
					|| role == AccessibleRole.Alert);
			return result;
		}
예제 #40
0
        /// <summary>
        /// Matches legal name and role combinations to their ah counterparts.
        /// They can match on both.
        /// Match NAMELESS to a null ah.name.
        /// Match name to ah.value when role is Alert and ah.role is anything.
        /// Match anything when name is null or #ANY.
        /// Match any ah.role when role is None.
        /// One name match and one role match must be true.
        /// </summary>
        /// <param name="name">The text to match, can be null</param>
        /// <param name="role">The Accessible role - some like Alert are special</param>
        /// <param name="ah">The accessible object</param>
        /// <returns>true if a name and a role matched</returns>
        private bool MatchNameAndRole(string name, AccessibleRole role, AccessibilityHelper ah)
        {
            bool result = false;
            bool NameResult = false;
            // check if the name is a regular expression
            if (name != null && name.StartsWith("rexp#"))
            {
                Regex rx = null;
                try { rx = new Regex(name.Substring(5)); }
                catch (ArgumentException e)
                {
                    Logger.getOnly().paragraph("Path name reg exp [" + name.Substring(5)
                          + "] " + e.Message);
                }
                if (rx != null)
                {
                    string MatchItem = "";
                    if (ah.Role == AccessibleRole.Alert) MatchItem = ah.Value;
                    else MatchItem = ah.Name;
                    NameResult = rx.IsMatch(MatchItem);
                    Logger.getOnly().paragraph("Path name reg exp [" + name.Substring(5)
                        + "] on [" + MatchItem + "] was " + NameResult.ToString());
                }
            }
            else if (ah.Role == AccessibleRole.Alert)
                NameResult = name == ah.Value;

            result =
                (
                    NameResult
                    || name == ah.Name
                    || (name == "NAMELESS" && ah.Name == null) // should never be null, but "" instead
                    || (name == "NAMELESS" && ah.Name.Length == 0) // "" empty doesn't always match
                    || name == null
                    || name == "#ANY"
                )
                && (role == ah.Role || role == AccessibleRole.None
                    || role == AccessibleRole.Alert);
            return result;
        }
예제 #41
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Find the child control with the specified name and/or role, but not below the specified
        /// nLevelsToRecurse. This method recursively searches down the hierarchy until it finds
        /// the control or it has searched nLevelsToRecurse levels.
        /// </summary>
        /// <param name="name">Accessibility name of the matching control, or <c>null</c></param>
        /// <param name="role">Accessibility role of the matching control, or
        /// <see cref="AccessibleRole.None"/>.</param>
        /// <param name="nLevelsToRecurse">The number of levels to search before giving up.</param>
        /// <returns>A new <see cref="AccessibilityHelper"/> object that wraps the matched
        /// control.</returns>
        /// </returns>
        /// <remarks>If you provide only one parameter, it matches only that parameter.
        /// If you specify both parameters it tries to match both.</remarks>
        /// ------------------------------------------------------------------------------------
        public AccessibilityHelper FindChild(string name, AccessibleRole role, int nLevelsToRecurse)
        {
            if (name == null && role == AccessibleRole.None)
                return null;

            AccessibilityHelper ah = null;

            foreach(AccessibilityHelper child in this)
            {
                if (child == null)
                    continue;
                // does this object match?
                // treat name == "" and child.Name == null as a match
                // Note: a null string shows as "" in the debugger!
                if (MatchNameAndRole(name, role, child))
                    return child;
                if (child.m_fRealAccessibleObject && nLevelsToRecurse > 0)
                {
                    // look through the child objects
                    ah = child.FindChild(name, role, nLevelsToRecurse-1);
                    if (ah != null)
                        return ah;
                }
            }
            return null;
        }
예제 #42
0
        /// <inheritdoc />
        internal override IList<AssistiveTechnologyObject> GetChildrenByRole(AccessibleRole matchingRole, bool visibleChildrenOnly, bool recursiveSearch)
        {
            List<AssistiveTechnologyObject> childObjectList = new List<AssistiveTechnologyObject>();
            IList<IntPtr> childObjectPointerList = AtSpi.Instance.FindChildrenWithRole(this.accessibleObject, matchingRole, visibleChildrenOnly, recursiveSearch);
            foreach (IntPtr childObjectPointer in childObjectPointerList)
            {
                childObjectList.Add(new AtSpiObject(childObjectPointer));
            }

            return childObjectList;
        }
 public RoleCtrlType(AccessibleRole role, ControlType ctrlType)
 {
     _role = role;
     _ctrlType = ctrlType;
 }
예제 #44
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Check the controls on the step and see if there are non-excaptable controls on it,
		/// i.e. for the overview page return false if there are any check boxes.
		/// </summary>
		/// <param name="parent">The element to start with</param>
		/// <param name="acceptableRoles">Sorted array of acceptable controls</param>
		/// <returns><c>true</c> if all visible controls are acceptable, otherwise
		/// <c>false</c>.</returns>
		/// ------------------------------------------------------------------------------------
		protected bool CheckControls(AccessibilityHelper parent, AccessibleRole[] acceptableRoles)
		{
			bool fRet = true;
			foreach (AccessibilityHelper child in parent)
			{
				if ((child.States & AccessibleStates.Invisible) == AccessibleStates.Invisible)
					continue;

				if (Array.BinarySearch(acceptableRoles, child.Role) < 0)
					return false;

				if (child.IsRealAccessibleObject)
					fRet = CheckControls(child, acceptableRoles);

				if (!fRet)
					return fRet;
			}

			return fRet;

		}
예제 #45
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Find the nth child window with the specified name and/or role.
		/// </summary>
		/// <param name="name">Accessibility name of the matching window, or <c>null</c></param>
		/// <param name="role">Accessibility role of the matching window, or
		/// <see cref="AccessibleRole.None"/>.</param>
		/// <param name="nWhich">Number of specified child to find</param>
		/// <param name="nLevelsToRecurse">How much levels to go down. <c>0</c> if you want
		/// to search only in the immediate children.</param>
		/// <returns>A new <see cref="AccessibilityHelper"/> object that wraps the matched
		/// window.</returns>
		/// <remarks>If you provide only one parameter, it matches only that parameter.
		/// If you specify both parameters it tries to match both. </remarks>
		/// ------------------------------------------------------------------------------------
		public AccessibilityHelper FindNthChild(string name, AccessibleRole role, ref int nWhich,
			int nLevelsToRecurse)
		{
			if (name == null && role == AccessibleRole.None)
				return null;

			AccessibilityHelper ah = null;

			foreach(AccessibilityHelper child in this)
			{
				if (child == null)
					continue;
				// does this object match?
				if ((name == null || name == child.Name) &&
					(role == AccessibleRole.None || role == child.Role))
				{
					nWhich--;
					if (nWhich <= 0)
						return child;
				}
				if (child.m_fRealAccessibleObject)
				{
					if (nLevelsToRecurse > 0)
					{
						// look through the child objects
						ah = child.FindNthChild(name, role, ref nWhich, nLevelsToRecurse-1);
						if (ah != null)
							return ah;
					}
				}
			}
			return null;
		}
예제 #46
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Find the child window with the specified name and/or role. This method only looks
        /// in the direct children for the window (no recursion).
        /// </summary>
        /// <param name="name">Accessibility name of the matching window, or <c>null</c></param>
        /// <param name="role">Accessibility role of the matching window, or
        /// <see cref="AccessibleRole.None"/>.</param>
        /// <returns>A new <see cref="AccessibilityHelper"/> object that wraps the matched
        /// window.</returns>
        /// <remarks>If you provide only one parameter, it matches only that parameter.
        /// If you specify both parameters it tries to match both. </remarks>
        /// ------------------------------------------------------------------------------------
        public AccessibilityHelper FindDirectChild(string name, AccessibleRole role)
        {
            if (name == null && role == AccessibleRole.None)
                return null;
            Logger log = Logger.getOnly();
            log.paragraph("FindDirectChild('"+role+"','"+name+"')");

            foreach(AccessibilityHelper child in this)
            {
                if (child == null)
                    continue;
                log.paragraph("FindDirectChild viewed ('"+child.Role+"','"+child.Name+"')");

                // does this object match?
                if (MatchNameAndRole(name, role, child))
                    return child;
            }
            return null;
        }
예제 #47
0
        /// <summary>
        /// Gets a list of child Accessible objects that match the desired AccessibleRole.
        /// </summary>
        /// <param name="parent">A pointer to the Accessible object on which to find children.</param>
        /// <param name="desiredRole">An AccessibleRole value describing the type of child to find.</param>
        /// <param name="visibleOnly"><see langword="true"/> to only find visible children; <see langword="false"/> to include invisible children.</param>
        /// <param name="recursive">True to search all children in the object tree; False to search only immediate children.</param>
        /// <returns>A list containing pointers to the Accessible objects matching the desired role.</returns>
        internal IList<IntPtr> FindChildrenWithRole(IntPtr parent, AccessibleRole desiredRole, bool visibleOnly, bool recursive)
        {
            List<IntPtr> childList = new List<IntPtr>();
            int childCount = Accessible_getChildCount(parent);
            for (int i = 0; i < childCount; i++)
            {
                IntPtr childPointer = Accessible_getChildAtIndex(parent, i);
                AccessibleRole childRole = Accessible_getRole(childPointer);
                IList<AccessibleState> stateList = this.GetStateList(childPointer);

                // If the child object has the desired role and visibility, add it to both the cached object
                // list and the returned object list.
                if ((childRole == desiredRole || desiredRole == AccessibleRole.AnyRole) && (!visibleOnly || stateList.Contains(AccessibleState.Visible)))
                {
                    referencedObjectCache.Add(childPointer);
                    childList.Add(childPointer);
                }

                // Call the function recursively to find all children at any depth.
                if (recursive)
                {
                    childList.AddRange(this.FindChildrenWithRole(childPointer, desiredRole, visibleOnly, recursive));
                }

                // If the object didn't match the desired role, we can unreference it.
                if (!childList.Contains(childPointer))
                {
                    Accessible_unref(childPointer);
                }
            }

            return childList;
        }
예제 #48
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Find the child window with the specified name and/or role. This method only looks
		/// in the direct children for the window (no recursion).
		/// </summary>
		/// <param name="name">Accessibility name of the matching window, or <c>null</c></param>
		/// <param name="role">Accessibility role of the matching window, or
		/// <see cref="AccessibleRole.None"/>.</param>
		/// <returns>A new <see cref="AccessibilityHelper"/> object that wraps the matched
		/// window.</returns>
		/// <remarks>If you provide only one parameter, it matches only that parameter.
		/// If you specify both parameters it tries to match both. </remarks>
		/// ------------------------------------------------------------------------------------
		public AccessibilityHelper FindDirectChild(string name, AccessibleRole role)
		{
			if (name == null && role == AccessibleRole.None)
				return null;

			foreach(AccessibilityHelper child in this)
			{
				if (child == null)
					continue;
				// does this object match?
				if ((name == null || name == child.Name) &&
					(role == AccessibleRole.None || role == child.Role))
					return child;
			}
			return null;
		}
	internal AccessibleObject(Control control)
			{
				this.control = control;
				this.role = AccessibleRole.Default;
			}
 /// <summary>
 /// Gets the children of this object by the specified <see cref="AccessibleRole"/>.
 /// </summary>
 /// <param name="matchingRole">The <see cref="AccessibleRole"/> of the children to get.</param>
 /// <param name="visibleChildrenOnly"><see langword="true"/> to only search visible children;
 /// <see langword="false"/> to also return hidden children.</param>
 /// <param name="recursiveSearch"><see langword="true"/> to recursively search all children of this object;
 /// <see langword="false"/> to only search immediate children.</param>
 /// <returns>A list of <see cref="AssistiveTechnologyObject"/> that meet the specified criteria.</returns>
 internal abstract IList<AssistiveTechnologyObject> GetChildrenByRole(AccessibleRole matchingRole, bool visibleChildrenOnly, bool recursiveSearch);