Exemple #1
0
 public void ISupportErrorInfo_Supported_ButNoIErrorInfoGiven()
 {
     ExecuteWithActivationContext(
         "App.manifest",
         () =>
     {
         using PropertyGrid propertyGrid = new PropertyGrid();
         var target = CreateComObjectWithStandardIErrorInfoUsage();
         propertyGrid.SelectedObject = target;
         var entries       = propertyGrid.GetCurrentEntries();
         var encodingEntry = entries[0].Children.First(_ => _.PropertyName == "Int_Property");
         try
         {
             encodingEntry.SetPropertyTextValue("333");
             Assert.False(true, "Invalid set values should produce ExternalException which will be presenttted to the user.");
         }
         catch (ExternalException ex)
         {
             // Most default C++ implementation when Invoke return error code
             // implementation consults IErrorInfo object and populates EXCEPINFO structure.
             // From EXCEPINFO grid entry reads error code and message.
             // IErrorInfo consulted too, but it does not hold error message anymore.
             Assert.Equal((int)HRESULT.DISP_E_MEMBERNOTFOUND, ex.HResult);
             Assert.Equal("Error From StandardErrorInfoUsageTest", ex.Message);
         }
         finally
         {
             propertyGrid.SelectedObject = null;
             Marshal.ReleaseComObject(target);
         }
     });
 }
Exemple #2
0
 public void ISupportErrorInfo_Supported_WithIErrorInfoGiven()
 {
     ExecuteWithActivationContext(
         "App.manifest",
         () =>
     {
         using PropertyGrid propertyGrid = new PropertyGrid();
         var target = CreateComObjectWithRawIErrorInfoUsage();
         propertyGrid.SelectedObject = target;
         var entries       = propertyGrid.GetCurrentEntries();
         var encodingEntry = entries[0].Children.First(_ => _.PropertyName == "Int_Property");
         try
         {
             encodingEntry.SetPropertyTextValue("123");
             Assert.False(true, "Invalid set values should produce ExternalException which will be presenttted to the user.");
         }
         catch (ExternalException ex)
         {
             // If C++ implementation of Invoke did not populate EXCEPINFO structure
             // from IErrorInfo, then we read that information about error call and display that error message to the user.
             Assert.Equal("Error From RawErrorInfoUsageTest", ex.Message);
         }
         finally
         {
             propertyGrid.SelectedObject = null;
             Marshal.ReleaseComObject(target);
         }
     });
 }
Exemple #3
0
        public void PropertyGridViewAccessibleObject_GetItem_ReturnsCorrectValue()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            propertyGrid.CreateControl();
            using ComboBox comboBox     = new ComboBox();
            propertyGrid.SelectedObject = comboBox;
            AccessibleObject accessibleObject = propertyGrid.GridViewAccessibleObject;

            int i = 0;

            foreach (GridEntry category in propertyGrid.GetCurrentEntries())
            {
                AccessibleObject categoryAccessibilityObject = category.AccessibilityObject;
                AccessibleObject categoryItem = (AccessibleObject)accessibleObject.GetItem(i, 1);
                Assert.Equal(categoryAccessibilityObject, categoryItem);
                i++;

                foreach (GridEntry entry in category.Children)
                {
                    AccessibleObject entryAccessibilityObject = entry.AccessibilityObject;
                    AccessibleObject entryItem = (AccessibleObject)accessibleObject.GetItem(i, 1);
                    Assert.Equal(categoryAccessibilityObject, categoryItem);
                    i++;
                }
            }
        }
Exemple #4
0
        public void PropertyGridViewAccessibleObject_GetSelected_ReturnsCorrectValue()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            using ComboBox comboBox         = new ComboBox();
            propertyGrid.SelectedObject     = comboBox;
            GridEntry entry = (GridEntry)((GridEntry)propertyGrid.GetCurrentEntries()[0]).Children[2];

            entry.HasFocus = true;
            entry.Select();
            Assert.Equal(entry, propertyGrid.SelectedGridItem);

            AccessibleObject focusedEntry = propertyGrid.GridViewAccessibleObject.GetSelected();

            Assert.Equal(entry.AccessibilityObject, focusedEntry);
        }
Exemple #5
0
        public void PropertyGridViewAccessibleObject_Entry_IsOffscreen_ReturnsCorrectValue()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            propertyGrid.Size     = new Size(300, 500);
            propertyGrid.Location = new Point(0, 0);
            propertyGrid.CreateControl();
            using ComboBox comboBox     = new ComboBox();
            propertyGrid.SelectedObject = comboBox;
            ControlAccessibleObject accessibleObject = (ControlAccessibleObject)propertyGrid.GridViewAccessibleObject;
            PropertyGridView        propertyGridView = (PropertyGridView)accessibleObject.Owner;

            Rectangle gridViewRectangle = accessibleObject.Bounds;

            int ROWLABEL = 1;
            int ROWVALUE = 2;

            foreach (GridEntry category in propertyGrid.GetCurrentEntries())
            {
                AccessibleObject categoryAccessibilityObject = category.AccessibilityObject;
                int       row  = propertyGridView.GetRowFromGridEntry(category);
                Rectangle rect = propertyGridView.GetRectangle(row, ROWVALUE | ROWLABEL);
                rect = propertyGridView.RectangleToScreen(rect);

                bool visible = rect.Height > 0 &&
                               ((rect.Y > gridViewRectangle.Y + 1 && rect.Y < gridViewRectangle.Bottom - 1) ||
                                (rect.Y <gridViewRectangle.Bottom - 1 && rect.Bottom> gridViewRectangle.Y + 1)); // +-1 are borders

                Assert.Equal(!visible, (bool)categoryAccessibilityObject.GetPropertyValue(UiaCore.UIA.IsOffscreenPropertyId));

                foreach (GridEntry entry in category.Children)
                {
                    AccessibleObject entryAccessibilityObject = entry.AccessibilityObject;
                    row  = propertyGridView.GetRowFromGridEntry(entry);
                    rect = propertyGridView.GetRectangle(row, ROWVALUE | ROWLABEL);
                    rect = propertyGridView.RectangleToScreen(rect);

                    visible = rect.Height > 0 &&
                              ((rect.Y > gridViewRectangle.Y + 1 && rect.Y < gridViewRectangle.Bottom - 1) ||
                               (rect.Y <gridViewRectangle.Bottom - 1 && rect.Bottom> gridViewRectangle.Y + 1));  // +-1 are borders

                    Assert.Equal(!visible, (bool)entryAccessibilityObject.GetPropertyValue(UiaCore.UIA.IsOffscreenPropertyId));
                }
            }
        }
Exemple #6
0
        public ScenarioResult PropertyGridViewRowsAccessibleObject_Ctor_Default(TParams p)
        {
            _propertyGrid.SelectedObject = _domainUpDown;
            int heightSum      = 0;
            int entriesBorders = 0;

            GridEntryCollection entries          = _propertyGrid.GetCurrentEntries();
            PropertyGridView    propertyGridView = (PropertyGridView)_propertyGrid.ActiveControl;

            foreach (GridEntry entry in entries)
            {
                int entryHeight = propertyGridView.AccessibilityGetGridEntryBounds(entry).Height;
                heightSum += entryHeight;
                if (entryHeight > 0)
                {
                    entriesBorders++;
                }

                foreach (GridEntry item in entry.GridItems)
                {
                    int itemHeight = propertyGridView.AccessibilityGetGridEntryBounds(item).Height;
                    heightSum += itemHeight;
                    if (itemHeight > 0)
                    {
                        entriesBorders++;
                    }
                }
            }

            if (heightSum != propertyGridView.AccessibilityObject.Bounds.Height - topBorder - bottomBorder - entriesBorders)
            {
                return(new ScenarioResult(false, "Incorrect dimensions"));
            }

            return(new ScenarioResult(true));
        }
Exemple #7
0
        public void PropertyGridViewAccessibleObject_GetChildCount_ReturnsCorrectValue()
        {
            using PropertyGrid propertyGrid = new PropertyGrid();
            AccessibleObject accessibleObject = propertyGrid.GridViewAccessibleObject;

            Assert.Equal(0, accessibleObject.GetChildCount()); // propertyGrid doesn't have an item

            using ComboBox comboBox     = new ComboBox();
            propertyGrid.SelectedObject = comboBox;

            int count = 0;

            foreach (GridEntry category in propertyGrid.GetCurrentEntries())
            {
                count++;

                foreach (GridEntry entry in category.Children)
                {
                    count++;
                }
            }

            Assert.Equal(count, accessibleObject.GetChildCount()); // Properties
        }