From 621861ed04cbf255c8389250bc8d31712ef292f5 Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Tue, 20 Feb 2024 14:27:06 +0800 Subject: [PATCH 01/11] Add unimplemented types for deprecated UI controls --- .../Obsolete/ContextMenu/ContextMenu.cs | 124 +++ .../Controls/Obsolete/ContextMenu/Menu.cs | 464 +++++++++ .../Controls/Obsolete/ContextMenu/MenuItem.cs | 607 ++++++++++++ .../Obsolete/ContextMenu/MenuMerge.cs | 42 + .../Controls/Obsolete/MainMenu/MainMenu.cs | 114 +++ .../Controls/Obsolete/ToolBar/ToolBar.cs | 884 ++++++++++++++++++ .../Obsolete/ToolBar/ToolBarAppearance.cs | 17 + .../Obsolete/ToolBar/ToolBarButton.cs | 430 +++++++++ .../ToolBar/ToolBarButtonClickEventArgs.cs | 23 + .../ToolBar/ToolBarButtonClickEventHandler.cs | 11 + .../Obsolete/ToolBar/ToolBarButtonStyle.cs | 23 + .../Obsolete/ToolBar/ToolBarTextAlign.cs | 17 + 12 files changed, 2756 insertions(+) create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuMerge.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs new file mode 100644 index 00000000000..b0da6e5029a --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs @@ -0,0 +1,124 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +#nullable disable +[Obsolete("ContextMenu has been deprecated. Use ContextMenuStrip instead.")] +public class ContextMenu : Menu +{ + private EventHandler onPopup; + private EventHandler onCollapse; + internal Control sourceControl; + + private RightToLeft rightToLeft = System.Windows.Forms.RightToLeft.Inherit; + + /// + /// Creates a new ContextMenu object with no items in it by default. + /// + public ContextMenu() + : base(null) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Creates a ContextMenu object with the given MenuItems. + /// + public ContextMenu(MenuItem[] menuItems) + : base(menuItems) + { + throw new PlatformNotSupportedException(); + } + + /// + /// The last control that was acted upon that resulted in this context + /// menu being displayed. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public Control SourceControl + { + get + { + return sourceControl; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Popup + { + add => onPopup += value; + remove => onPopup -= value; + } + + /// + /// Fires when the context menu collapses. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Collapse + { + add => onCollapse += value; + remove => onCollapse -= value; + } + + /// + /// This is used for international applications where the language + /// is written from RightToLeft. When this property is true, + /// text alignment and reading order will be from right to left. + /// + // Add a DefaultValue attribute so that the Reset context menu becomes + // available in the Property Grid but the default value remains No. + [Localizable(true), DefaultValue(RightToLeft.No), + Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual RightToLeft RightToLeft + { + get + { + if (rightToLeft == RightToLeft.Inherit) + { + if (sourceControl is not null) + { + return sourceControl.RightToLeft; + } + else + { + return RightToLeft.No; + } + } + else + { + return rightToLeft; + } + } + set + { + if (RightToLeft != value) + { + rightToLeft = value; + } + } + } + + /// + /// Displays the context menu at the specified position. This method + /// doesn't return until the menu is dismissed. + /// + public void Show(Control control, Point pos) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Displays the context menu at the specified position. This method + /// doesn't return until the menu is dismissed. + /// + public void Show(Control control, Point pos, LeftRightAlignment alignment) + { + throw new PlatformNotSupportedException(); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs new file mode 100644 index 00000000000..4288be66d3b --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs @@ -0,0 +1,464 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; + +namespace System.Windows.Forms; +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("Menu has been deprecated.")] +public abstract class Menu : Component +{ + #nullable disable + internal const int CHANGE_ITEMS = 0; // item(s) added or removed + internal const int CHANGE_VISIBLE = 1; // item(s) hidden or shown + internal const int CHANGE_MDI = 2; // mdi item changed + internal const int CHANGE_MERGE = 3; // mergeType or mergeOrder changed + internal const int CHANGE_ITEMADDED = 4; // mergeType or mergeOrder changed + + /// + /// Used by findMenuItem + /// + public const int FindHandle = 0; + /// + /// Used by findMenuItem + /// + public const int FindShortcut = 1; + + private MenuItemCollection itemsCollection; + internal MenuItem[] items; + internal IntPtr handle; + internal bool created; + private object userData; + private string name; + + /// + /// This is an abstract class. Instances cannot be created, so the constructor + /// is only called from derived classes. + /// + protected Menu(MenuItem[] items) + { + throw new PlatformNotSupportedException(); + } + + /// + /// The HMENU handle corresponding to this menu. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), + SRDescription(nameof(SR.ControlHandleDescr))] + public IntPtr Handle + { + get + { + return handle; + } + } + + /// + /// Specifies whether this menu contains any items. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public virtual bool IsParent + { + get + { + return items is not null; + } + } + + /// + /// The MenuItem that contains the list of MDI child windows. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public MenuItem MdiListItem + { + get + { + return null; + } + } + + /// + /// Name of this control. The designer will set this to the same + /// as the programatic Id "(name)" of the control - however this + /// property has no bearing on the runtime aspects of this control. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name + { + get => WindowsFormsUtils.GetComponentName(this, name); + set + { + if (value is null || value.Length == 0) + { + name = null; + } + else + { + name = value; + } + + if (Site is not null) + { + Site.Name = name; + } + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + DesignerSerializationVisibility(DesignerSerializationVisibility.Content), + MergableProperty(false)] + public MenuItemCollection MenuItems + { + get + { + if (itemsCollection is null) + { + itemsCollection = new MenuItemCollection(this); + } + + return itemsCollection; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + SRCategory(nameof(SR.CatData)), + Localizable(false), + Bindable(true), + SRDescription(nameof(SR.ControlTagDescr)), + DefaultValue(null), + TypeConverter(typeof(StringConverter))] + public object Tag + { + get + { + return userData; + } + set + { + userData = value; + } + } + + public MenuItem FindMenuItem(int type, IntPtr value) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Returns the ContextMenu that contains this menu. The ContextMenu + /// is at the top of this menu's parent chain. + /// Returns null if this menu is not contained in a ContextMenu. + /// This can occur if it's contained in a MainMenu or if it isn't + /// currently contained in any menu at all. + /// + public ContextMenu GetContextMenu() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Returns the MainMenu item that contains this menu. The MainMenu + /// is at the top of this menu's parent chain. + /// Returns null if this menu is not contained in a MainMenu. + /// This can occur if it's contained in a ContextMenu or if it isn't + /// currently contained in any menu at all. + /// + public MainMenu GetMainMenu() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Merges another menu's items with this one's. Menu items are merged according to their + /// mergeType and mergeOrder properties. This function is typically used to + /// merge an MDI container's menu with that of its active MDI child. + /// + public virtual void MergeMenu(Menu menuSrc) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Returns a string representation for this control. + /// + public override string ToString() + { + throw new PlatformNotSupportedException(); + } + + [ListBindable(false)] + [Obsolete("MenuItemCollection has been deprecated.")] + public class MenuItemCollection : IList + { + private readonly Menu owner; + + /// A caching mechanism for key accessor + /// We use an index here rather than control so that we don't have lifetime + /// issues by holding on to extra references. + // private int lastAccessedIndex = -1; + + public MenuItemCollection(Menu owner) + { + this.owner = owner; + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual MenuItem this[int index] + { + get + { + if (index < 0) + { + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); + } + + return owner.items[index]; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + object IList.this[int index] + { + get + { + return this[index]; + } + set + { + throw new NotSupportedException(); + } + } + + /// + /// Retrieves the child control with the specified key. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual MenuItem this[string key] + { + get + { + // We do not support null and empty string as valid keys. + if (string.IsNullOrEmpty(key)) + { + return null; + } + + // Search for the key in our collection + int index = IndexOfKey(key); + if (IsValidIndex(index)) + { + return this[index]; + } + else + { + return null; + } + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int Count + { + get + { + return 0; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + object ICollection.SyncRoot + { + get + { + return this; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + bool ICollection.IsSynchronized + { + get + { + return false; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + bool IList.IsFixedSize + { + get + { + return false; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool IsReadOnly + { + get + { + return false; + } + } + + /// + /// Adds a new MenuItem to the end of this menu with the specified caption. + /// + public virtual MenuItem Add(string caption) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Adds a new MenuItem to the end of this menu with the specified caption, + /// and click handler. + /// + public virtual MenuItem Add(string caption, EventHandler onClick) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Adds a new MenuItem to the end of this menu with the specified caption, + /// click handler, and items. + /// + public virtual MenuItem Add(string caption, MenuItem[] items) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Adds a MenuItem to the end of this menu + /// MenuItems can only be contained in one menu at a time, and may not be added + /// more than once to the same menu. + /// + public virtual int Add(object item) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Adds a MenuItem to this menu at the specified index. The item currently at + /// that index, and all items after it, will be moved up one slot. + /// MenuItems can only be contained in one menu at a time, and may not be added + /// more than once to the same menu. + /// + public virtual int Add(int index, MenuItem item) + { + throw new PlatformNotSupportedException(); + } + + public virtual void AddRange(MenuItem[] items) + { + throw new PlatformNotSupportedException(); + } + + public bool Contains(object value) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Returns true if the collection contains an item with the specified key, false otherwise. + /// + public virtual bool ContainsKey(string key) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Searches for Controls by their Name property, builds up an array + /// of all the controls that match. + /// + public MenuItem[] Find(string key, bool searchAllChildren) + { + throw new PlatformNotSupportedException(); + } + + public int IndexOf(MenuItem value) + { + throw new PlatformNotSupportedException(); + } + + int IList.IndexOf(object value) + { + throw new PlatformNotSupportedException(); + } + + /// + /// The zero-based index of the first occurrence of value within the entire CollectionBase, if found; otherwise, -1. + /// + public virtual int IndexOfKey(string key) + { + throw new PlatformNotSupportedException(); + } + + void IList.Insert(int index, object value) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Determines if the index is valid for the collection. + /// + private bool IsValidIndex(int index) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Removes all existing MenuItems from this menu + /// + public virtual void Clear() + { + throw new PlatformNotSupportedException(); + } + + public void CopyTo(Array dest, int index) + { + throw new PlatformNotSupportedException(); + } + + public IEnumerator GetEnumerator() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Removes the item at the specified index in this menu. All subsequent + /// items are moved up one slot. + /// + public virtual void RemoveAt(int index) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Removes the menu iteml with the specified key. + /// + public virtual void RemoveByKey(string key) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Removes the specified item from this menu. All subsequent + /// items are moved down one slot. + /// + public virtual void Remove(MenuItem item) + { + throw new PlatformNotSupportedException(); + } + + void IList.Remove(object value) + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs new file mode 100644 index 00000000000..c40487ef6a8 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs @@ -0,0 +1,607 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +#nullable disable +[Obsolete("MenuItem has been deprecated. Use ToolStripMenuItem instead.")] +public class MenuItem : Menu +{ + private const int StateBarBreak = 0x00000020; + private const int StateBreak = 0x00000040; + private const int StateChecked = 0x00000008; + private const int StateDefault = 0x00001000; + private const int StateDisabled = 0x00000003; + private const int StateRadioCheck = 0x00000200; + private const int StateHidden = 0x00010000; + private const int StateMdiList = 0x00020000; + private const int StateOwnerDraw = 0x00000100; + +#pragma warning disable CS0649 + private MenuItemData _data; +#pragma warning restore CS0649 + + /// + /// Initializes a with a blank caption. + /// + public MenuItem() : this(MenuMerge.Add, 0, 0, null, null, null, null, null) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Initializes a new instance of the class + /// with a specified caption for the menu item. + /// + public MenuItem(string text) : this(MenuMerge.Add, 0, 0, text, null, null, null, null) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Initializes a new instance of the class with a specified caption and event handler + /// for the menu item. + /// + public MenuItem(string text, EventHandler onClick) : this(MenuMerge.Add, 0, 0, text, onClick, null, null, null) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Initializes a new instance of the class with a specified caption, event handler, + /// and associated shorcut key for the menu item. + /// + public MenuItem(string text, EventHandler onClick, Shortcut shortcut) : this(MenuMerge.Add, 0, shortcut, text, onClick, null, null, null) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Initializes a new instance of the class with a specified caption and an array of + /// submenu items defined for the menu item. + /// + public MenuItem(string text, MenuItem[] items) : this(MenuMerge.Add, 0, 0, text, null, null, null, items) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Initializes a new instance of the class with a specified caption, defined + /// event-handlers for the Click, Select and Popup events, a shortcut key, + /// a merge type, and order specified for the menu item. + /// + public MenuItem(MenuMerge mergeType, int mergeOrder, Shortcut shortcut, + string text, EventHandler onClick, EventHandler onPopup, + EventHandler onSelect, MenuItem[] items) : base(items) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Gets or sets a value indicating whether the item is placed on a new line (for a + /// menu item added to a object) or in a + /// new column (for a submenu or menu displayed in a ). + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [DefaultValue(false)] + public bool BarBreak + { + get + { + return StateBarBreak != 0; + } + set + { + _data.SetState(StateBreak, value); + } + } + + /// + /// Gets or sets a value indicating whether the item is placed on a new line (for a + /// menu item added to a object) or in a + /// new column (for a submenu or menu displayed in a ). + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [DefaultValue(false)] + public bool Break + { + get + { + return StateBreak != 0; + } + set + { + _data.SetState(StateBarBreak, value); + } + } + + /// + /// Gets or sets a value indicating whether a checkmark appears beside the text of + /// the menu item. + /// + [DefaultValue(false)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [SRDescription("Indicates whether the item is checked.")] + public bool Checked + { + get + { + return StateChecked != 0; + } + set + { + _data.SetState(StateChecked, value); + } + } + + /// + /// Gets or sets a value indicating whether the menu item is the default. + /// + [DefaultValue(false)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [SRDescription("Indicates whether the item is the default item.")] + public bool DefaultItem + { + get + { + return StateDefault != 0; + } + set + { + _data.SetState(StateDefault, value); + } + } + + /// + /// Gets or sets a value indicating whether code that you provide draws the menu + /// item or Windows draws the menu item. + /// + [SRCategory(nameof(SR.CatBehavior))] + [DefaultValue(false)] + [SRDescription("Indicates if Windows will draw the menu item or if the user will handle the painting.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool OwnerDraw + { + get + { + return StateOwnerDraw != 0; + } + set + { + _data.SetState(StateOwnerDraw, value); + } + } + + /// + /// Gets or sets a value indicating whether the menu item is enabled. + /// + [Localizable(true)] + [DefaultValue(true)] + [SRDescription("Indicates whether the item is enabled.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool Enabled + { + get + { + return StateDisabled == 0; + } + set + { + _data.SetState(StateDisabled, value); + } + } + + /// + /// Gets or sets the menu item's position in its parent menu. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int Index + { + get + { + return -1; + } + set + { + int oldIndex = Index; + if (oldIndex >= 0) + { + if (value != oldIndex) + { + // The menu reverts to null when we're removed, so hold onto it in a + // local variable + Menu parent = Parent; + parent.MenuItems.RemoveAt(oldIndex); + parent.MenuItems.Add(value, this); + } + } + } + } + + /// + /// Gets a value indicating whether the menu item contains child menu items. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override bool IsParent + { + get + { + return base.IsParent; + } + } + + /// + /// Gets or sets a value indicating whether the menu item will be populated with a + /// list of the MDI child windows that are displayed within the associated form. + /// + [DefaultValue(false)] + [SRDescription("Determines whether the MDI child window list is appended to this item.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool MdiList + { + get + { + return StateMdiList != 0; + } + set + { + _data.SetState(StateMdiList, value); + } + } + + /// + /// Gets or sets a value that indicates the behavior of this + /// menu item when its menu is merged with another. + /// + [DefaultValue(MenuMerge.Add)] + [SRDescription("Determines how the item is handled when menus are merged.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public MenuMerge MergeType + { + get + { + return _data._mergeType; + } + set + { + _data._mergeType = value; + } + } + + /// + /// Gets or sets the relative position the menu item when its + /// menu is merged with another. + /// + [DefaultValue(0)] + [SRDescription("Determines the merge order of the item.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int MergeOrder + { + get + { + return _data._mergeOrder; + } + set + { + _data._mergeOrder = value; + } + } + + /// + /// Retrieves the hotkey mnemonic that is associated with this menu item. + /// The mnemonic is the first character after an ampersand symbol in the menu's text + /// that is not itself an ampersand symbol. If no such mnemonic is defined this + /// will return zero. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public char Mnemonic => '\0'; + + /// + /// Gets the menu in which this menu item appears. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Menu Parent { get; internal set; } + + /// + /// Gets or sets a value that indicates whether the menu item, if checked, + /// displays a radio-button mark instead of a check mark. + /// + [DefaultValue(false)] + [SRDescription("If the item is checked, this value will determine whether the check style is a radio button.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool RadioCheck + { + get + { + return StateRadioCheck != 0; + } + set + { + _data.SetState(StateRadioCheck, value); + } + } + + /// + /// Gets or sets the text of the menu item. + /// + [Localizable(true)] + [SRDescription("The caption displayed by the item.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string Text + { + get + { + return _data._caption; + } + set + { + _data.SetCaption(value); + } + } + + /// + /// Gets or sets the shortcut key associated with the menu item. + /// + [Localizable(true)] + [DefaultValue(Shortcut.None)] + [SRDescription(nameof(SR.MenuItemShortCutDescr))] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Shortcut Shortcut + { + get + { + return _data._shortcut; + } + set + { + _data._shortcut = value; + } + } + + /// + /// Gets or sets a value that indicates whether the shortcut key that is associated + /// with the menu item is displayed next to the menu item caption. + /// + [DefaultValue(true), Localizable(true)] + [SRDescription(nameof(SR.MenuItemShowShortCutDescr))] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool ShowShortcut + { + get + { + return _data._showShortcut; + } + set + { + _data._showShortcut = value; + } + } + + /// + /// Gets or sets a value that indicates whether the menu item is visible on its + /// parent menu. + /// + [Localizable(true)] + [DefaultValue(true)] + [SRDescription("Indicates whether the item is visible.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool Visible + { + get + { + return StateHidden == 0; + } + } + + /// + /// Occurs when the menu item is clicked or selected using a shortcut key defined + /// for the menu item. + /// + [SRDescription("Occurs when the menu item is selected.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Click + { + add + { + _data._onClick += value; + } + remove + { + _data._onClick -= value; + } + } + + /// + /// Occurs when when the property of a menu item is set to and + /// a request is made to draw the menu item. + /// + [SRCategory(nameof(SR.CatBehavior)), SRDescription(nameof(SR.drawItemEventDescr))] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event DrawItemEventHandler DrawItem + { + add + { + _data._onDrawItem += value; + } + remove + { + _data._onDrawItem -= value; + } + } + + /// + /// Occurs when when the menu needs to know the size of a menu item before drawing it. + /// + [SRCategory(nameof(SR.CatBehavior)), SRDescription(nameof(SR.measureItemEventDescr))] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event MeasureItemEventHandler MeasureItem + { + add + { + _data._onMeasureItem += value; + } + remove + { + _data._onMeasureItem -= value; + } + } + + /// + /// Occurs before a menu item's list of menu items is displayed. + /// + [SRDescription("Occurs before the containing menu is displayed.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Popup + { + add + { + _data._onPopup += value; + } + remove + { + _data._onPopup -= value; + } + } + + /// + /// Occurs when the user hovers their mouse over a menu item or selects it with the + /// keyboard but has not activated it. + /// + [SRDescription("Occurs when the menu item is selected.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Select + { + add + { + _data._onSelect += value; + } + remove + { + _data._onSelect -= value; + } + } + + /// + /// Creates and returns an identical copy of this menu item. + /// + public virtual MenuItem CloneMenu() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Merges this menu item with another menu item and returns the resulting merged + /// . + /// + public virtual MenuItem MergeMenu() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Merges another menu item with this menu item. + /// + public void MergeMenu(MenuItem itemSrc) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Generates a event for the MenuItem, + /// simulating a click by a user. + /// + public void PerformClick() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Raises the event for this menu item. + /// + public virtual void PerformSelect() + { + throw new PlatformNotSupportedException(); + } + + public override string ToString() + { + throw new PlatformNotSupportedException(); + } + + [Obsolete("MenuItemData has been deprecated.")] + internal class MenuItemData : ICommandExecutor + { + internal MenuItem baseItem; + internal MenuItem firstItem; + internal int _version; + internal MenuMerge _mergeType; + internal int _mergeOrder; + internal string _caption; + internal short _mnemonic; + internal Shortcut _shortcut; + internal bool _showShortcut; + internal EventHandler _onClick; + internal EventHandler _onPopup; + internal EventHandler _onSelect; + internal DrawItemEventHandler _onDrawItem; + internal MeasureItemEventHandler _onMeasureItem; + + public void Execute() + { + throw new PlatformNotSupportedException(); + } + + internal void SetState(int flag, bool value) + { + throw new PlatformNotSupportedException(); + } + + internal void SetCaption(string value) + { + throw new PlatformNotSupportedException(); + } + } + + private class MdiListUserData + { + public virtual void OnClick(EventArgs e) + { + throw new PlatformNotSupportedException(); + } + } + + private class MdiListFormData : MdiListUserData + { + private readonly MenuItem _parent; + private readonly int _boundIndex; + + public MdiListFormData(MenuItem parentItem, int boundFormIndex) + { + _boundIndex = boundFormIndex; + _parent = parentItem; + } + + public override void OnClick(EventArgs e) + { + throw new PlatformNotSupportedException(); + } + } + + private class MdiListMoreWindowsData : MdiListUserData + { + private readonly MenuItem _parent; + + public MdiListMoreWindowsData(MenuItem parent) + { + _parent = parent; + } + + public override void OnClick(EventArgs e) + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuMerge.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuMerge.cs new file mode 100644 index 00000000000..461e1205a4d --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuMerge.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("MenuMerge has been deprecated.")] +public enum MenuMerge +{ + /// + /// The is added to the + /// existing objects in a + /// merged menu. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Add = 0, + + /// + /// The replaces the + /// existing at the same + /// position in a merged menu. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Replace = 1, + + /// + /// Subitems of this are merged + /// with those of existing + /// objects at the same position in a merged menu. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + MergeItems = 2, + + /// + /// The is not included in a + /// merged menu. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Remove = 3, +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs new file mode 100644 index 00000000000..9223d0f1425 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs @@ -0,0 +1,114 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("MainMenu has been deprecated. Use MenuStrip instead.")] +public class MainMenu : Menu +{ +#nullable disable + internal Form form; + internal Form ownerForm; // this is the form that created this menu, and is the only form allowed to dispose it. + private RightToLeft rightToLeft = System.Windows.Forms.RightToLeft.Inherit; + private EventHandler onCollapse; + + /// + /// Creates a new MainMenu control. + /// + public MainMenu() + : base(null) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Initializes a new instance of the class with the specified container. + /// + public MainMenu(IContainer container) : this() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Creates a new MainMenu control with the given items to start + /// with. + /// + public MainMenu(MenuItem[] items) + : base(items) + { + throw new PlatformNotSupportedException(); + } + + [SRDescription("Occurs when the main menu collapses.")] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Collapse + { + add => onCollapse += value; + remove => onCollapse -= value; + } + + /// + /// This is used for international applications where the language + /// is written from RightToLeft. When this property is true, + /// text alignment and reading order will be from right to left. + /// + // Add an AmbientValue attribute so that the Reset context menu becomes available in the Property Grid. + [Localizable(true), AmbientValue(RightToLeft.Inherit), + SRDescription("Indicates if this menu should display right to left"), + Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual RightToLeft RightToLeft + { + get + { + if (rightToLeft == RightToLeft.Inherit) + { + if (form is not null) + { + return form.RightToLeft; + } + else + { + return RightToLeft.Inherit; + } + } + else + { + return rightToLeft; + } + } + set + { + if (rightToLeft != value) + { + rightToLeft = value; + } + } + } + + /// + /// Creates a new MainMenu object which is a dupliate of this one. + /// + public virtual MainMenu CloneMenu() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Indicates which form in which we are currently residing [if any] + /// + public Form GetForm() + { + throw new PlatformNotSupportedException(); + } + + /// + /// Returns a string representation for this control. + /// + public override string ToString() + { + throw new PlatformNotSupportedException(); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs new file mode 100644 index 00000000000..cad69f15425 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs @@ -0,0 +1,884 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.Drawing; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +#nullable disable +[Obsolete("ToolBar has been deprecated. Use ToolStrip instead.")] +public class ToolBar : Control +{ + private readonly ToolBarButtonCollection buttonsCollection; + + /// + /// The size of a button in the ToolBar + /// + internal Size buttonSize = System.Drawing.Size.Empty; + /// + /// This represents the width of the drop down arrow we have if the + /// DropDownArrows property is true. this value is used by the ToolBarButton + /// objects to compute their size + /// + internal const int DDARROW_WIDTH = 15; + + /// + /// Indicates what our appearance will be. This will either be normal + /// or flat. + /// + private ToolBarAppearance appearance = ToolBarAppearance.Normal; + + /// + /// Indicates whether or not we have a border + /// + private BorderStyle borderStyle = System.Windows.Forms.BorderStyle.None; + + /// + /// The array of buttons we're working with. + /// + private ToolBarButton[] buttons; + + /// + /// The number of buttons we're working with + /// + private int buttonCount; + + /// + /// Indicates if text captions should go underneath images in buttons or + /// to the right of them + /// + private ToolBarTextAlign textAlign = ToolBarTextAlign.Underneath; + + /// + /// The ImageList object that contains the main images for our control. + /// + private ImageList imageList; + + private const int TOOLBARSTATE_wrappable = 0x00000001; + private const int TOOLBARSTATE_dropDownArrows = 0x00000002; + private const int TOOLBARSTATE_divider = 0x00000004; + private const int TOOLBARSTATE_showToolTips = 0x00000008; + private const int TOOLBARSTATE_autoSize = 0x00000010; + + // PERF: take all the bools and put them into a state variable + private Collections.Specialized.BitVector32 toolBarState; // see TOOLBARSTATE_ consts above + + // event handlers + // + private ToolBarButtonClickEventHandler onButtonClick; + private ToolBarButtonClickEventHandler onButtonDropDown; + + /// + /// Initializes a new instance of the class. + /// + public ToolBar() + : base() + { + buttonsCollection = new ToolBarButtonCollection(this); + throw new PlatformNotSupportedException(); + } + + /// + /// Gets or sets the appearance of the toolbar + /// control and its buttons. + /// + [SRCategory(nameof(SR.CatBehavior)), DefaultValue(ToolBarAppearance.Normal), + Localizable(true), Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public ToolBarAppearance Appearance + { + get + { + return appearance; + } + + set + { + if (value != appearance) + { + appearance = value; + RecreateHandle(); + } + } + } + + /// + /// Indicates whether the toolbar + /// adjusts its size automatically based on the size of the buttons and the + /// dock style. + /// + [SRCategory(nameof(SR.CatBehavior)), + DefaultValue(true), + Localizable(true), + Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public override bool AutoSize + { + get + { + return toolBarState[TOOLBARSTATE_autoSize]; + } + + set + { + // Note that we intentionally do not call base. Toolbars size themselves by + // overriding SetBoundsCore (old RTM code). We let CommonProperties.GetAutoSize + // continue to return false to keep our LayoutEngines from messing with TextBoxes. + // This is done for backwards compatibility since the new AutoSize behavior differs. + if (AutoSize != value) + { + toolBarState[TOOLBARSTATE_autoSize] = value; + if (Dock == DockStyle.Left || Dock == DockStyle.Right) + { + SetStyle(ControlStyles.FixedWidth, AutoSize); + SetStyle(ControlStyles.FixedHeight, false); + } + else + { + SetStyle(ControlStyles.FixedHeight, AutoSize); + SetStyle(ControlStyles.FixedWidth, false); + } + + OnAutoSizeChanged(EventArgs.Empty); + } + } + } + + [SRCategory(nameof(SR.CatPropertyChanged)), SRDescription(nameof(SR.ControlOnAutoSizeChangedDescr))] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler AutoSizeChanged + { + add => base.AutoSizeChanged += value; + remove => base.AutoSizeChanged -= value; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Color BackColor + { + get + { + return base.BackColor; + } + set + { + base.BackColor = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackColorChanged + { + add => base.BackColorChanged += value; + remove => base.BackColorChanged -= value; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Image BackgroundImage + { + get + { + return base.BackgroundImage; + } + set + { + base.BackgroundImage = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackgroundImageChanged + { + add => base.BackgroundImageChanged += value; + remove => base.BackgroundImageChanged -= value; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override ImageLayout BackgroundImageLayout + { + get + { + return base.BackgroundImageLayout; + } + set + { + base.BackgroundImageLayout = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackgroundImageLayoutChanged + { + add => base.BackgroundImageLayoutChanged += value; + remove => base.BackgroundImageLayoutChanged -= value; + } + + /// + /// Gets or sets + /// the border style of the toolbar control. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public BorderStyle BorderStyle + { + get + { + return borderStyle; + } + + set + { + if (borderStyle != value) + { + borderStyle = value; + + RecreateHandle(); // Looks like we need to recreate the handle to avoid painting glitches + } + } + } + + /// + /// A collection of controls assigned to the + /// toolbar control. The property is read-only. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public ToolBarButtonCollection Buttons + { + get + { + return buttonsCollection; + } + } + + /// + /// Gets or sets + /// the size of the buttons on the toolbar control. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Size ButtonSize + { + get + { + if (buttonSize.IsEmpty) + { + if (TextAlign == ToolBarTextAlign.Underneath) + { + return new Size(39, 36); // Default button size + } + else + { + return new Size(23, 22); // Default button size + } + } + else + { + return buttonSize; + } + } + + set + { + if (value.Width < 0 || value.Height < 0) + { + throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(ButtonSize), value)); + } + + if (buttonSize != value) + { + buttonSize = value; + RecreateHandle(); + } + } + } + + /// + /// Gets or sets a value indicating + /// whether the toolbar displays a divider. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool Divider + { + get + { + return toolBarState[TOOLBARSTATE_divider]; + } + + set + { + if (Divider != value) + { + toolBarState[TOOLBARSTATE_divider] = value; + RecreateHandle(); + } + } + } + + /// + /// Sets the way in which this ToolBar is docked to its parent. We need to + /// override this to ensure autoSizing works correctly + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override DockStyle Dock + { + get { return base.Dock; } + + set + { + if (Dock != value) + { + if (value == DockStyle.Left || value == DockStyle.Right) + { + SetStyle(ControlStyles.FixedWidth, AutoSize); + SetStyle(ControlStyles.FixedHeight, false); + } + else + { + SetStyle(ControlStyles.FixedHeight, AutoSize); + SetStyle(ControlStyles.FixedWidth, false); + } + + base.Dock = value; + } + } + } + + /// + /// Gets or sets a value indicating whether drop-down buttons on a + /// toolbar display down arrows. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool DropDownArrows + { + get + { + return toolBarState[TOOLBARSTATE_dropDownArrows]; + } + + set + { + if (DropDownArrows != value) + { + toolBarState[TOOLBARSTATE_dropDownArrows] = value; + RecreateHandle(); + } + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Color ForeColor + { + get + { + return base.ForeColor; + } + set + { + base.ForeColor = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler ForeColorChanged + { + add => base.ForeColorChanged += value; + remove => base.ForeColorChanged -= value; + } + + /// + /// Gets or sets the collection of images available to the toolbar button + /// controls. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public ImageList ImageList + { + get + { + return imageList; + } + set + { + if (value != imageList) + { + if (IsHandleCreated) + { + RecreateHandle(); + } + } + } + } + + /// + /// Gets the size of the images in the image list assigned to the + /// toolbar. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Size ImageSize + { + get + { + if (imageList is not null) + { + return imageList.ImageSize; + } + else + { + return new Size(0, 0); + } + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public ImeMode ImeMode + { + get + { + return base.ImeMode; + } + set + { + base.ImeMode = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public new event EventHandler ImeModeChanged + { + add => base.ImeModeChanged += value; + remove => base.ImeModeChanged -= value; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override RightToLeft RightToLeft + { + get + { + return base.RightToLeft; + } + set + { + base.RightToLeft = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public new event EventHandler RightToLeftChanged + { + add => base.RightToLeftChanged += value; + remove => base.RightToLeftChanged -= value; + } + + /// + /// Gets or sets a value indicating whether the toolbar displays a + /// tool tip for each button. + /// + [SRCategory(nameof(SR.CatBehavior)), + DefaultValue(false), + Localizable(true)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool ShowToolTips + { + get + { + return toolBarState[TOOLBARSTATE_showToolTips]; + } + set + { + if (ShowToolTips != value) + { + toolBarState[TOOLBARSTATE_showToolTips] = value; + RecreateHandle(); + } + } + } + + [DefaultValue(false)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public bool TabStop + { + get + { + return base.TabStop; + } + set + { + base.TabStop = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), + Bindable(false), + DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public override string Text + { + get + { + return base.Text; + } + set + { + base.Text = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler TextChanged + { + add => base.TextChanged += value; + remove => base.TextChanged -= value; + } + + /// + /// Gets or sets the alignment of text in relation to each + /// image displayed on + /// the toolbar button controls. + /// + [SRCategory(nameof(SR.CatAppearance)), + DefaultValue(ToolBarTextAlign.Underneath), + Localizable(true)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public ToolBarTextAlign TextAlign + { + get + { + return textAlign; + } + set + { + if (textAlign == value) + { + return; + } + + textAlign = value; + RecreateHandle(); + } + } + + /// + /// Gets + /// or sets a value + /// indicating whether the toolbar buttons wrap to the next line if the + /// toolbar becomes too small to display all the buttons + /// on the same line. + /// + [SRCategory(nameof(SR.CatBehavior)), + DefaultValue(true), + Localizable(true)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool Wrappable + { + get + { + return toolBarState[TOOLBARSTATE_wrappable]; + } + set + { + if (Wrappable != value) + { + toolBarState[TOOLBARSTATE_wrappable] = value; + RecreateHandle(); + } + } + } + + /// + /// Occurs when a on the is clicked. + /// + [SRCategory(nameof(SR.CatBehavior))] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event ToolBarButtonClickEventHandler ButtonClick + { + add => onButtonClick += value; + remove => onButtonClick -= value; + } + + /// + /// Occurs when a drop-down style or its down arrow is clicked. + /// + [SRCategory(nameof(SR.CatBehavior))] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event ToolBarButtonClickEventHandler ButtonDropDown + { + add => onButtonDropDown += value; + remove => onButtonDropDown -= value; + } + + /// + /// ToolBar Onpaint. + /// + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public new event PaintEventHandler Paint + { + add => base.Paint += value; + remove => base.Paint -= value; + } + + /// + /// Returns a string representation for this control. + /// + public override string ToString() + { + buttonCount++; + buttons = new ToolBarButton[buttonCount]; + imageList = new ImageList(); + throw new PlatformNotSupportedException(); + } + + /// + /// Encapsulates a collection of controls for use by the + /// class. + /// + [Obsolete("ToolBarButtonCollection has been deprecated.")] + public class ToolBarButtonCollection : IList + { + private readonly ToolBar owner; + + /// + /// Initializes a new instance of the class and assigns it to the specified toolbar. + /// + public ToolBarButtonCollection(ToolBar owner) + { + this.owner = owner; + throw new PlatformNotSupportedException(); + } + + /// + /// Gets or sets the toolbar button at the specified indexed location in the + /// toolbar button collection. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual ToolBarButton this[int index] + { + get + { + if (index < 0 || ((owner.buttons is not null) && (index >= owner.buttonCount))) + { + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); + } + + return owner.buttons[index]; + } + set + { + if (index < 0 || ((owner.buttons is not null) && index >= owner.buttonCount)) + { + throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); + } + + if (value is null) + { + throw new ArgumentNullException(nameof(value)); + } + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + object IList.this[int index] + { + get + { + return this[index]; + } + set + { + if (value is ToolBarButton) + { + this[index] = (ToolBarButton)value; + } + else + { + throw new ArgumentException(); + } + } + } + + /// + /// Retrieves the child control with the specified key. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual ToolBarButton this[string key] + { + get + { + // We do not support null and empty string as valid keys. + if (string.IsNullOrEmpty(key)) + { + return null; + } + + // Search for the key in our collection + int index = IndexOfKey(key); + return this[index]; + } + } + + /// + /// Gets the number of buttons in the toolbar button collection. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int Count + { + get + { + return owner.buttonCount; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + object ICollection.SyncRoot + { + get + { + return this; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + bool ICollection.IsSynchronized + { + get + { + return false; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + bool IList.IsFixedSize + { + get + { + return false; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool IsReadOnly + { + get + { + return false; + } + } + + /// + /// Adds a new toolbar button to + /// the end of the toolbar button collection. + /// + public int Add(ToolBarButton button) + { + throw new PlatformNotSupportedException(); + } + + public int Add(string text) + { + throw new PlatformNotSupportedException(); + } + + int IList.Add(object button) + { + throw new PlatformNotSupportedException(); + } + + public void AddRange(ToolBarButton[] buttons) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Removes + /// all buttons from the toolbar button collection. + /// + public void Clear() + { + throw new PlatformNotSupportedException(); + } + + public bool Contains(ToolBarButton button) + { + throw new PlatformNotSupportedException(); + } + + bool IList.Contains(object button) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Returns true if the collection contains an item with the specified key, false otherwise. + /// + public virtual bool ContainsKey(string key) + { + throw new PlatformNotSupportedException(); + } + + void ICollection.CopyTo(Array dest, int index) + { + throw new PlatformNotSupportedException(); + } + + public int IndexOf(ToolBarButton button) + { + throw new PlatformNotSupportedException(); + } + + int IList.IndexOf(object button) + { + throw new PlatformNotSupportedException(); + } + + /// + /// The zero-based index of the first occurrence of value within the entire CollectionBase, if found; otherwise, -1. + /// + public virtual int IndexOfKey(string key) + { + throw new PlatformNotSupportedException(); + } + + public void Insert(int index, ToolBarButton button) + { + throw new PlatformNotSupportedException(); + } + + void IList.Insert(int index, object button) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Removes + /// a given button from the toolbar button collection. + /// + public void RemoveAt(int index) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Removes the child control with the specified key. + /// + public virtual void RemoveByKey(string key) + { + throw new PlatformNotSupportedException(); + } + + public void Remove(ToolBarButton button) + { + throw new PlatformNotSupportedException(); + } + + void IList.Remove(object button) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Returns an enumerator that can be used to iterate + /// through the toolbar button collection. + /// + public IEnumerator GetEnumerator() + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs new file mode 100644 index 00000000000..73477853565 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +[Obsolete("ToolBarAppearance has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API +public enum ToolBarAppearance +{ + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Normal = 0, + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Flat = 1, +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs new file mode 100644 index 00000000000..2497ead49ca --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs @@ -0,0 +1,430 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +#nullable disable +[Obsolete("ToolBarButton has been deprecated. Use ToolStripButton instead.")] +public class ToolBarButton : Component +{ + private string text; + private string name; + private string tooltipText; + private bool enabled = true; + private bool visible = true; + private bool pushed; + private bool partialPush; + private ToolBarButtonImageIndexer imageIndexer; + private ToolBarButtonStyle style = ToolBarButtonStyle.PushButton; + private object userData; + + // These variables below are used by the ToolBar control to help + // it manage some information about us. + + /// + /// If this button has a string, what it's index is in the ToolBar's + /// internal list of strings. Needs to be package protected. + /// + internal IntPtr stringIndex = (IntPtr)(-1); + + /// + /// Our parent ToolBar control. + /// + internal ToolBar parent; + + /// + /// For DropDown buttons, we can optionally show a + /// context menu when the button is dropped down. + /// + internal Menu dropDownMenu; + + /// + /// Initializes a new instance of the class. + /// + public ToolBarButton() + { + throw new PlatformNotSupportedException(); + } + + public ToolBarButton(string text) : base() + { + throw new PlatformNotSupportedException(); + } + + // We need a special way to defer to the ToolBar's image + // list for indexing purposes. + [Obsolete("ToolBarButtonImageIndexer has been deprecated.")] + internal class ToolBarButtonImageIndexer : ImageList.Indexer + { + private readonly ToolBarButton owner; + + public ToolBarButtonImageIndexer(ToolBarButton button) + { + owner = button; + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override ImageList ImageList + { + get + { + if ((owner is not null) && (owner.parent is not null)) + { + return owner.parent.ImageList; + } + + return null; + } + set { Debug.Assert(false, "We should never set the image list"); } + } + } + + /// + /// + /// Indicates the menu to be displayed in + /// the drop-down toolbar button. + /// + [DefaultValue(null), TypeConverter(typeof(ReferenceConverter))] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Menu DropDownMenu + { + get + { + return dropDownMenu; + } + + set + { + if (value is not null && !(value is ContextMenu)) + { + throw new ArgumentException(); + } + + dropDownMenu = value; + } + } + + /// + /// Indicates whether the button is enabled or not. + /// + [DefaultValue(true), Localizable(true)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool Enabled + { + get + { + return enabled; + } + + set + { + if (enabled != value) + { + enabled = value; + } + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + internal ToolBarButtonImageIndexer ImageIndexer + { + get + { + if (imageIndexer is null) + { + imageIndexer = new ToolBarButtonImageIndexer(this); + } + + return imageIndexer; + } + } + + /// + /// Indicates the index + /// value of the image assigned to the button. + /// + [TypeConverter(typeof(ImageIndexConverter)), + DefaultValue(-1), + RefreshProperties(RefreshProperties.Repaint), Localizable(true)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int ImageIndex + { + get + { + return ImageIndexer.Index; + } + set + { + if (ImageIndexer.Index != value) + { + if (value < -1) + { + throw new ArgumentOutOfRangeException(); + } + + ImageIndexer.Index = value; + } + } + } + + /// + /// Indicates the index + /// value of the image assigned to the button. + /// + [TypeConverter(typeof(ImageKeyConverter)), + DefaultValue(""), Localizable(true), + RefreshProperties(RefreshProperties.Repaint)] + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string ImageKey + { + get + { + return ImageIndexer.Key; + } + set + { + if (ImageIndexer.Key != value) + { + ImageIndexer.Key = value; + } + } + } + + /// + /// Name of this control. The designer will set this to the same + /// as the programatic Id "(name)" of the control - however this + /// property has no bearing on the runtime aspects of this control. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string Name + { + get + { + return WindowsFormsUtils.GetComponentName(this, name); + } + set + { + if (value is null || value.Length == 0) + { + name = null; + } + else + { + name = value; + } + + if (Site is not null) + { + Site.Name = name; + } + } + } + + /// + /// Indicates the toolbar control that the toolbar button is assigned to. This property is + /// read-only. + /// + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public ToolBar Parent + { + get + { + return parent; + } + } + + /// + /// + /// Indicates whether a toggle-style toolbar button + /// is partially pushed. + /// + [DefaultValue(false), Browsable(false), + EditorBrowsable(EditorBrowsableState.Never)] + public bool PartialPush + { + get + { + if (parent is null || !parent.IsHandleCreated) + { + return partialPush; + } + else + { + return partialPush; + } + } + set + { + if (partialPush != value) + { + partialPush = value; + } + } + } + + /// + /// Indicates whether a toggle-style toolbar button is currently in the pushed state. + /// + [DefaultValue(false), Browsable(false), + EditorBrowsable(EditorBrowsableState.Never)] + public bool Pushed + { + get + { + if (parent is null || !parent.IsHandleCreated) + { + return pushed; + } + else + { + return false; + } + } + set + { + if (value != Pushed) + { // Getting property Pushed updates pushed member variable + pushed = value; + } + } + } + + /// + /// Indicates the bounding rectangle for a toolbar button. This property is + /// read-only. + /// Browsable(false), + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Rectangle Rectangle + { + get + { + if (parent is not null) + { + RECT rc = default(RECT); + return Rectangle.FromLTRB(rc.left, rc.top, rc.right, rc.bottom); + } + + return Rectangle.Empty; + } + } + + /// + /// Indicates the style of the + /// toolbar button. + /// + [DefaultValue(ToolBarButtonStyle.PushButton), + RefreshProperties(RefreshProperties.Repaint), + Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public ToolBarButtonStyle Style + { + get + { + return style; + } + set + { + if (style == value) + { + return; + } + + style = value; + } + } + + [SRCategory(nameof(SR.CatData)), + Localizable(false), + Bindable(true), + SRDescription(nameof(SR.ControlTagDescr)), + DefaultValue(null), + TypeConverter(typeof(StringConverter)), + Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public object Tag + { + get + { + return userData; + } + set + { + userData = value; + } + } + + /// + /// Indicates the text that is displayed on the toolbar button. + /// + [Localizable(true), DefaultValue(""), + Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string Text + { + get + { + return text ?? ""; + } + set + { + if (string.IsNullOrEmpty(value)) + { + value = null; + } + + if ((value is null && text is not null) || + (value is not null && (text is null || !text.Equals(value)))) + { + text = value; + } + } + } + + /// + /// + /// Indicates + /// the text that appears as a tool tip for a control. + /// + [Localizable(true), DefaultValue(""), + Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string ToolTipText + { + get + { + return tooltipText ?? ""; + } + set + { + tooltipText = value; + } + } + + /// + /// + /// Indicates whether the toolbar button + /// is visible. + /// + [DefaultValue(true), Localizable(true), + Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool Visible + { + get + { + return visible; + } + set + { + if (visible != value) + { + visible = value; + } + } + } + + public override string ToString() + { + throw new PlatformNotSupportedException(); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs new file mode 100644 index 00000000000..6c85434f123 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +[Obsolete("ToolBarButtonStyle has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API +public class ToolBarButtonClickEventArgs : EventArgs +{ + /// + /// Initializes a new instance of the + /// class. + /// + public ToolBarButtonClickEventArgs(ToolBarButton button) + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public ToolBarButton Button { get; set; } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs new file mode 100644 index 00000000000..b8bb5c932a3 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("ToolBarButtonStyle has been deprecated.")] +[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] +public delegate void ToolBarButtonClickEventHandler(object sender, ToolBarButtonClickEventArgs e); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs new file mode 100644 index 00000000000..6dba397fe42 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +[Obsolete("ToolBarButtonStyle has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API +public enum ToolBarButtonStyle +{ + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + PushButton = 1, + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + ToggleButton = 2, + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Separator = 3, + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + DropDownButton = 4, +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs new file mode 100644 index 00000000000..ccd8beda3fe --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +[Obsolete("ToolBarTextAlign has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API +public enum ToolBarTextAlign +{ + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Underneath = 0, + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Right = 1, +} From 57c4b45fcc726a1b786f5c461a8005ae02e43c42 Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Tue, 5 Mar 2024 09:29:15 +0800 Subject: [PATCH 02/11] Add obsolete controls --- .../Obsolete/ContextMenu/ContextMenu.cs | 39 +- .../Controls/Obsolete/ContextMenu/Menu.cs | 117 +- .../Controls/Obsolete/ContextMenu/MenuItem.cs | 241 +- .../Controls/Obsolete/DataGrid/DataGrid.cs | 8124 +++++++++++++++++ .../Obsolete/DataGrid/DataGridAddNewRow.cs | 79 + .../Obsolete/DataGrid/DataGridBoolColumn.cs | 422 + .../Obsolete/DataGrid/DataGridCaption.cs | 889 ++ .../Obsolete/DataGrid/DataGridCell.cs | 73 + .../Obsolete/DataGrid/DataGridColumn.cs | 721 ++ .../Obsolete/DataGrid/DataGridLineStyle.cs | 16 + .../Obsolete/DataGrid/DataGridParentRows.cs | 1136 +++ .../DataGrid/DataGridParentRowsLabel.cs | 20 + ...taGridPreferredColumnWidthTypeConverter.cs | 19 + .../DataGrid/DataGridRelationshipRow.cs | 776 ++ .../Controls/Obsolete/DataGrid/DataGridRow.cs | 682 ++ .../Obsolete/DataGrid/DataGridState.cs | 153 + .../Obsolete/DataGrid/DataGridTable.cs | 1369 +++ .../DataGrid/DataGridTableCollection.cs | 188 + .../DataGrid/DataGridTablesFactory.cs | 17 + .../Obsolete/DataGrid/DataGridTextBox.cs | 162 + .../DataGrid/DataGridTextBoxColumn.cs | 408 + .../Obsolete/DataGrid/DataGridToolTip.cs | 40 + .../DataGrid/GridColumnStylesCollection.cs | 264 + .../DataGrid/IDataGridEditingService.cs | 14 + .../Controls/Obsolete/MainMenu/MainMenu.cs | 27 +- .../Controls/Obsolete/StatusBar/StatusBar.cs | 1328 +++ .../StatusBar/StatusBarDrawItemEvent.cs | 33 + .../StatusBarDrawItemEventHandler.cs | 11 + .../Obsolete/StatusBar/StatusBarPanel.cs | 371 + .../StatusBar/StatusBarPanelAutoSize.cs | 18 + .../StatusBar/StatusBarPanelBorderStyle.cs | 15 + .../StatusBar/StatusBarPanelClickEvent.cs | 25 + .../StatusBarPanelClickEventHandler.cs | 10 + .../Obsolete/StatusBar/StatusBarPanelStyle.cs | 13 + .../Controls/Obsolete/ToolBar/ToolBar.cs | 288 +- 35 files changed, 17542 insertions(+), 566 deletions(-) create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridLineStyle.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/IDataGridEditingService.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelBorderStyle.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEventHandler.cs create mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelStyle.cs diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs index b0da6e5029a..c807ce0fca9 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs @@ -6,17 +6,15 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API +// Add public types and members to the declared APIto simplify porting of applications from .NET Framework to .NET. These types will not work, +// but if they are not accessed, other features in the application will work. +#pragma warning disable RS0016 #nullable disable [Obsolete("ContextMenu has been deprecated. Use ContextMenuStrip instead.")] public class ContextMenu : Menu { - private EventHandler onPopup; - private EventHandler onCollapse; internal Control sourceControl; - private RightToLeft rightToLeft = System.Windows.Forms.RightToLeft.Inherit; - /// /// Creates a new ContextMenu object with no items in it by default. /// @@ -45,15 +43,15 @@ public Control SourceControl { get { - return sourceControl; + throw new PlatformNotSupportedException(); } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Popup { - add => onPopup += value; - remove => onPopup -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -62,8 +60,8 @@ public Control SourceControl [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Collapse { - add => onCollapse += value; - remove => onCollapse -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -79,28 +77,11 @@ public virtual RightToLeft RightToLeft { get { - if (rightToLeft == RightToLeft.Inherit) - { - if (sourceControl is not null) - { - return sourceControl.RightToLeft; - } - else - { - return RightToLeft.No; - } - } - else - { - return rightToLeft; - } + throw new PlatformNotSupportedException(); } set { - if (RightToLeft != value) - { - rightToLeft = value; - } + throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs index 4288be66d3b..ceb6736c5ec 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs @@ -24,13 +24,9 @@ public abstract class Menu : Component /// Used by findMenuItem /// public const int FindShortcut = 1; - - private MenuItemCollection itemsCollection; internal MenuItem[] items; internal IntPtr handle; internal bool created; - private object userData; - private string name; /// /// This is an abstract class. Instances cannot be created, so the constructor @@ -51,7 +47,7 @@ public IntPtr Handle { get { - return handle; + throw new PlatformNotSupportedException(); } } @@ -64,7 +60,7 @@ public virtual bool IsParent { get { - return items is not null; + throw new PlatformNotSupportedException(); } } @@ -77,7 +73,7 @@ public MenuItem MdiListItem { get { - return null; + throw new PlatformNotSupportedException(); } } @@ -90,23 +86,8 @@ public MenuItem MdiListItem DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public string Name { - get => WindowsFormsUtils.GetComponentName(this, name); - set - { - if (value is null || value.Length == 0) - { - name = null; - } - else - { - name = value; - } - - if (Site is not null) - { - Site.Name = name; - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), @@ -114,15 +95,7 @@ public string Name MergableProperty(false)] public MenuItemCollection MenuItems { - get - { - if (itemsCollection is null) - { - itemsCollection = new MenuItemCollection(this); - } - - return itemsCollection; - } + get => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), @@ -134,14 +107,8 @@ public MenuItemCollection MenuItems TypeConverter(typeof(StringConverter))] public object Tag { - get - { - return userData; - } - set - { - userData = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public MenuItem FindMenuItem(int type, IntPtr value) @@ -195,8 +162,6 @@ public override string ToString() [Obsolete("MenuItemCollection has been deprecated.")] public class MenuItemCollection : IList { - private readonly Menu owner; - /// A caching mechanism for key accessor /// We use an index here rather than control so that we don't have lifetime /// issues by holding on to extra references. @@ -204,35 +169,20 @@ public class MenuItemCollection : IList public MenuItemCollection(Menu owner) { - this.owner = owner; throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public virtual MenuItem this[int index] { - get - { - if (index < 0) - { - throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); - } - - return owner.items[index]; - } + get => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] object IList.this[int index] { - get - { - return this[index]; - } - set - { - throw new NotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -241,70 +191,37 @@ public MenuItemCollection(Menu owner) [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public virtual MenuItem this[string key] { - get - { - // We do not support null and empty string as valid keys. - if (string.IsNullOrEmpty(key)) - { - return null; - } - - // Search for the key in our collection - int index = IndexOfKey(key); - if (IsValidIndex(index)) - { - return this[index]; - } - else - { - return null; - } - } + get => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public int Count { - get - { - return 0; - } + get => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] object ICollection.SyncRoot { - get - { - return this; - } + get => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] bool ICollection.IsSynchronized { - get - { - return false; - } + get => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] bool IList.IsFixedSize { - get - { - return false; - } + get => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool IsReadOnly { - get - { - return false; - } + get => throw new PlatformNotSupportedException(); } /// diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs index c40487ef6a8..30d74beed56 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs @@ -10,20 +10,6 @@ namespace System.Windows.Forms; [Obsolete("MenuItem has been deprecated. Use ToolStripMenuItem instead.")] public class MenuItem : Menu { - private const int StateBarBreak = 0x00000020; - private const int StateBreak = 0x00000040; - private const int StateChecked = 0x00000008; - private const int StateDefault = 0x00001000; - private const int StateDisabled = 0x00000003; - private const int StateRadioCheck = 0x00000200; - private const int StateHidden = 0x00010000; - private const int StateMdiList = 0x00020000; - private const int StateOwnerDraw = 0x00000100; - -#pragma warning disable CS0649 - private MenuItemData _data; -#pragma warning restore CS0649 - /// /// Initializes a with a blank caption. /// @@ -89,14 +75,8 @@ public MenuItem(string text, MenuItem[] items) : this(MenuMerge.Add, 0, 0, text, [DefaultValue(false)] public bool BarBreak { - get - { - return StateBarBreak != 0; - } - set - { - _data.SetState(StateBreak, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -108,14 +88,8 @@ public bool BarBreak [DefaultValue(false)] public bool Break { - get - { - return StateBreak != 0; - } - set - { - _data.SetState(StateBarBreak, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -127,14 +101,8 @@ public bool Break [SRDescription("Indicates whether the item is checked.")] public bool Checked { - get - { - return StateChecked != 0; - } - set - { - _data.SetState(StateChecked, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -145,14 +113,8 @@ public bool Checked [SRDescription("Indicates whether the item is the default item.")] public bool DefaultItem { - get - { - return StateDefault != 0; - } - set - { - _data.SetState(StateDefault, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -165,14 +127,8 @@ public bool DefaultItem [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool OwnerDraw { - get - { - return StateOwnerDraw != 0; - } - set - { - _data.SetState(StateOwnerDraw, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -184,14 +140,8 @@ public bool OwnerDraw [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool Enabled { - get - { - return StateDisabled == 0; - } - set - { - _data.SetState(StateDisabled, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -200,25 +150,8 @@ public bool Enabled [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public int Index { - get - { - return -1; - } - set - { - int oldIndex = Index; - if (oldIndex >= 0) - { - if (value != oldIndex) - { - // The menu reverts to null when we're removed, so hold onto it in a - // local variable - Menu parent = Parent; - parent.MenuItems.RemoveAt(oldIndex); - parent.MenuItems.Add(value, this); - } - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -227,10 +160,7 @@ public int Index [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override bool IsParent { - get - { - return base.IsParent; - } + get => throw new PlatformNotSupportedException(); } /// @@ -242,14 +172,8 @@ public override bool IsParent [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool MdiList { - get - { - return StateMdiList != 0; - } - set - { - _data.SetState(StateMdiList, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -261,14 +185,8 @@ public bool MdiList [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public MenuMerge MergeType { - get - { - return _data._mergeType; - } - set - { - _data._mergeType = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -280,14 +198,8 @@ public MenuMerge MergeType [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public int MergeOrder { - get - { - return _data._mergeOrder; - } - set - { - _data._mergeOrder = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -303,7 +215,11 @@ public int MergeOrder /// Gets the menu in which this menu item appears. /// [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Menu Parent { get; internal set; } + public Menu Parent + { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); + } /// /// Gets or sets a value that indicates whether the menu item, if checked, @@ -314,14 +230,8 @@ public int MergeOrder [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool RadioCheck { - get - { - return StateRadioCheck != 0; - } - set - { - _data.SetState(StateRadioCheck, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -332,14 +242,8 @@ public bool RadioCheck [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public string Text { - get - { - return _data._caption; - } - set - { - _data.SetCaption(value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -351,14 +255,8 @@ public string Text [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public Shortcut Shortcut { - get - { - return _data._shortcut; - } - set - { - _data._shortcut = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -370,14 +268,8 @@ public Shortcut Shortcut [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool ShowShortcut { - get - { - return _data._showShortcut; - } - set - { - _data._showShortcut = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } /// @@ -390,10 +282,7 @@ public bool ShowShortcut [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool Visible { - get - { - return StateHidden == 0; - } + get => throw new PlatformNotSupportedException(); } /// @@ -404,14 +293,8 @@ public bool Visible [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Click { - add - { - _data._onClick += value; - } - remove - { - _data._onClick -= value; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -422,14 +305,8 @@ public bool Visible [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event DrawItemEventHandler DrawItem { - add - { - _data._onDrawItem += value; - } - remove - { - _data._onDrawItem -= value; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -439,14 +316,8 @@ public bool Visible [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event MeasureItemEventHandler MeasureItem { - add - { - _data._onMeasureItem += value; - } - remove - { - _data._onMeasureItem -= value; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -456,14 +327,8 @@ public bool Visible [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Popup { - add - { - _data._onPopup += value; - } - remove - { - _data._onPopup -= value; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -474,14 +339,8 @@ public bool Visible [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Select { - add - { - _data._onSelect += value; - } - remove - { - _data._onSelect -= value; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -575,13 +434,9 @@ public virtual void OnClick(EventArgs e) private class MdiListFormData : MdiListUserData { - private readonly MenuItem _parent; - private readonly int _boundIndex; - public MdiListFormData(MenuItem parentItem, int boundFormIndex) { - _boundIndex = boundFormIndex; - _parent = parentItem; + throw new PlatformNotSupportedException(); } public override void OnClick(EventArgs e) @@ -592,11 +447,9 @@ public override void OnClick(EventArgs e) private class MdiListMoreWindowsData : MdiListUserData { - private readonly MenuItem _parent; - public MdiListMoreWindowsData(MenuItem parent) { - _parent = parent; + throw new PlatformNotSupportedException(); } public override void OnClick(EventArgs e) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs new file mode 100644 index 00000000000..06cdd72c3e0 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs @@ -0,0 +1,8124 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Globalization; +using System.Security.Permissions; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("DataGrid has been deprecated. Use DataGridView instead.")] +public class DataGrid : Control, ISupportInitialize, IDataGridEditingService +{ +#if DEBUG + internal TraceSwitch DataGridAcc = new TraceSwitch("DataGridAcc", "Trace Windows Forms DataGrid Accessibility"); +#else + internal TraceSwitch DataGridAcc = null; +#endif + + private const int GRIDSTATE_trackColResize = 0x00000008; + private const int GRIDSTATE_trackRowResize = 0x00000010; + private const int GRIDSTATE_isLedgerStyle = 0x00000020; + private const int GRIDSTATE_listHasErrors = 0x00000080; + private const int GRIDSTATE_dragging = 0x00000100; + private const int GRIDSTATE_inListAddNew = 0x00000200; + private const int GRIDSTATE_inDeleteRow = 0x00000400; + private const int GRIDSTATE_canFocus = 0x00000800; + private const int GRIDSTATE_isNavigating = 0x00004000; + private const int GRIDSTATE_isEditing = 0x00008000; + private const int GRIDSTATE_editControlChanging = 0x00010000; + private const int GRIDSTATE_isScrolling = 0x00020000; + private const int GRIDSTATE_overCaption = 0x00040000; + private const int GRIDSTATE_childLinkFocused = 0x00080000; + private const int GRIDSTATE_inAddNewRow = 0x00100000; + private const int GRIDSTATE_inSetListManager = 0x00200000; + private const int GRIDSTATE_metaDataChanged = 0x00400000; + private const int GRIDSTATE_exceptionInPaint = 0x00800000; + private const int GRIDSTATE_layoutSuspended = 0x01000000; + + // PERF: take all the bools and put them into a state variable + private Collections.Specialized.BitVector32 gridState; // see GRIDSTATE_ consts above + + private const int errorRowBitmapWidth = 15; + + private const DataGridParentRowsLabelStyle defaultParentRowsLabelStyle = DataGridParentRowsLabelStyle.Both; + private const bool defaultCaptionVisible = true; + + private const bool defaultParentRowsVisible = true; + + private DataGridTableStyle defaultTableStyle = new DataGridTableStyle(true); + + // private bool allowSorting = true; + + private SolidBrush alternatingBackBrush = DefaultAlternatingBackBrush; + + // private bool columnHeadersVisible = true; + + private SolidBrush gridLineBrush = DefaultGridLineBrush; + private SolidBrush headerBackBrush = DefaultHeaderBackBrush; + + private Font headerFont; // this is ambient property to Font value + + private SolidBrush headerForeBrush = DefaultHeaderForeBrush; + private Pen headerForePen = DefaultHeaderForePen; + + private SolidBrush linkBrush = DefaultLinkBrush; + private static int defaultFontHeight = DefaultFont.Height; + private int prefferedRowHeight = defaultFontHeight + 3; + private int minRowHeaderWidth; + + private SolidBrush selectionBackBrush = DefaultSelectionBackBrush; + private SolidBrush selectionForeBrush = DefaultSelectionForeBrush; + + // parent rows + private DataGridParentRows parentRows; + // Set_ListManager uses the originalState to determine + // if the grid should disconnect from all the MetaDataChangedEvents + // keep "originalState is not null" when navigating back and forth in the grid + // and use Add/RemoveMetaDataChanged methods. + private DataGridState originalState; + + // ui state + // Don't use dataGridRows, use the accessor!!! + private DataGridRow[] dataGridRows = []; + private int dataGridRowsLength; + + // for toolTip + private int toolTipId; + private DataGridToolTip toolTipProvider; + + private DataGridAddNewRow addNewRow; + private LayoutData layout = new LayoutData(); + private RECT[] cachedScrollableRegion; + + // header namespace goo + + // these are actually get/set by ColumnBehavior + internal bool allowColumnResize = true; + + internal bool allowRowResize = true; + + internal DataGridParentRowsLabelStyle parentRowsLabels = defaultParentRowsLabelStyle; + + // information for col/row resizing + // private bool trackColResize = false; + private int trackColAnchor; + private int trackColumn; + // private bool trackRowResize = false; + private int trackRowAnchor; + private int trackRow; + private PropertyDescriptor trackColumnHeader; + private MouseEventArgs lastSplitBar; + + // private bool isLedgerStyle = true; + // private bool isFlatMode = false; + private Font linkFont; + + private SolidBrush backBrush = DefaultBackBrush; + private SolidBrush foreBrush = DefaultForeBrush; + private SolidBrush backgroundBrush = DefaultBackgroundBrush; + + // font cacheing info + private int fontHeight = -1; + private int linkFontHeight = -1; + private int captionFontHeight = -1; + private int headerFontHeight = -1; + + // the preffered height of the row. + + // if the list has items with errors + + // private bool listHasErrors = false; + + // caption + private DataGridCaption caption; + + // data binding + // + private object dataSource; + private string dataMember = ""; + private CurrencyManager listManager; + + // currently focused control + // we want to unparent it either when rebinding the grid or when the grid is disposed + private Control toBeDisposedEditingControl; + + // persistent data state + // + internal GridTableStylesCollection dataGridTables; + // SET myGridTable in SetDataGridTable ONLY + internal DataGridTableStyle myGridTable; + internal bool checkHierarchy = true; + internal bool inInit; + + // Selection + internal int currentRow; + internal int currentCol; + private int numSelectedRows; + private int lastRowSelected = -1; + + // Policy + // private bool readOnlyMode = false; + private Policy policy = new Policy(); + private DataGridColumnStyle editColumn; + private DataGridRow editRow; + + // scrolling + private ScrollBar horizScrollBar = new HScrollBar(); + private ScrollBar vertScrollBar = new VScrollBar(); + + // the sum of the widths of the columns preceding the firstVisibleColumn + private int horizontalOffset; + + // the number of pixels of the firstVisibleColumn which are not visible + // + private int negOffset; + + private int wheelDelta; + // private bool isScrolling = false; + + // Visibility + // + internal int firstVisibleRow; + internal int firstVisibleCol; + private int numVisibleRows; + // the number of columns which are visible + private int numVisibleCols; + private int numTotallyVisibleRows; + // lastTotallyVisibleCol == -1 means that the data grid does not show any column in its entirety + private int lastTotallyVisibleCol; + + // mouse move hot-tracking + // + private int oldRow = -1; + private static readonly object EVENT_CURRENTCELLCHANGED = new object(); + // private static readonly object EVENT_COLUMNRESIZE = new object(); + // private static readonly object EVENT_LINKCLICKED = new object(); + private static readonly object EVENT_NODECLICKED = new object(); + // private static readonly object EVENT_ROWRESIZE = new object(); + private static readonly object EVENT_SCROLL = new object(); + private static readonly object EVENT_BACKBUTTONCLICK = new object(); + private static readonly object EVENT_DOWNBUTTONCLICK = new object(); + + private EventHandler onRowHeaderClick; + + public DataGrid() : base() + { + parentRows = new DataGridParentRows(this); + caption = new DataGridCaption(this); + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool AllowSorting + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color AlternatingBackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + public void ResetAlternatingBackColor() + { + throw new PlatformNotSupportedException(); + } + + protected virtual bool ShouldSerializeAlternatingBackColor() + { + return !AlternatingBackBrush.Equals(DefaultAlternatingBackBrush); + } + + internal Brush AlternatingBackBrush + { + get + { + return alternatingBackBrush; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Color BackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + public override void ResetBackColor() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Color ForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + public override void ResetForeColor() + { + throw new PlatformNotSupportedException(); + } + + internal SolidBrush BackBrush + { + get + { + return backBrush; + } + } + + internal SolidBrush ForeBrush + { + get + { + return foreBrush; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public BorderStyle BorderStyle + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_BORDERSTYLECHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler BorderStyleChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + private int BorderWidth + { + get + { + if (BorderStyle == BorderStyle.Fixed3D) + { + return SystemInformation.Border3DSize.Width; + } + else if (BorderStyle == BorderStyle.FixedSingle) + { + return 2; + } + else + { + return 0; + } + } + } + + protected override Size DefaultSize + { + get + { + return new Size(130, 80); + } + } + + private static SolidBrush DefaultSelectionBackBrush + { + get + { + return (SolidBrush)SystemBrushes.ActiveCaption; + } + } + + private static SolidBrush DefaultSelectionForeBrush + { + get + { + return (SolidBrush)SystemBrushes.ActiveCaptionText; + } + } + + internal static SolidBrush DefaultBackBrush + { + get + { + return (SolidBrush)SystemBrushes.Window; + } + } + + internal static SolidBrush DefaultForeBrush + { + get + { + return (SolidBrush)SystemBrushes.WindowText; + } + } + + private static SolidBrush DefaultBackgroundBrush + { + get + { + return (SolidBrush)SystemBrushes.AppWorkspace; + } + } + + internal static SolidBrush DefaultParentRowsForeBrush + { + get + { + return (SolidBrush)SystemBrushes.WindowText; + } + } + + internal static SolidBrush DefaultParentRowsBackBrush + { + get + { + return (SolidBrush)SystemBrushes.Control; + } + } + + internal static SolidBrush DefaultAlternatingBackBrush + { + get + { + return (SolidBrush)SystemBrushes.Window; + } + } + + private static SolidBrush DefaultGridLineBrush + { + get + { + return (SolidBrush)SystemBrushes.Control; + } + } + + private static SolidBrush DefaultHeaderBackBrush + { + get + { + return (SolidBrush)SystemBrushes.Control; + } + } + + private static SolidBrush DefaultHeaderForeBrush + { + get + { + return (SolidBrush)SystemBrushes.ControlText; + } + } + + private static Pen DefaultHeaderForePen + { + get + { + return new Pen(SystemColors.ControlText); + } + } + + private static SolidBrush DefaultLinkBrush + { + get + { + return (SolidBrush)SystemBrushes.HotTrack; + } + } + + private bool ListHasErrors + { + get + { + return gridState[GRIDSTATE_listHasErrors]; + } + set + { + if (ListHasErrors != value) + { + gridState[GRIDSTATE_listHasErrors] = value; + ComputeMinimumRowHeaderWidth(); + if (!layout.RowHeadersVisible) + return; + if (value) + { + if (myGridTable.IsDefault) + RowHeaderWidth += errorRowBitmapWidth; + else + myGridTable.RowHeaderWidth += errorRowBitmapWidth; + } + else + { + if (myGridTable.IsDefault) + RowHeaderWidth -= errorRowBitmapWidth; + else + myGridTable.RowHeaderWidth -= errorRowBitmapWidth; + } + } + } + } + + private bool Bound + { + get + { + return !(listManager is null || myGridTable is null); + } + } + + internal DataGridCaption Caption + { + get + { + return caption; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color CaptionBackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private void ResetCaptionBackColor() + { + Caption.ResetBackColor(); + } + + protected virtual bool ShouldSerializeCaptionBackColor() + { + return Caption.ShouldSerializeBackColor(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color CaptionForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private void ResetCaptionForeColor() + { + Caption.ResetForeColor(); + } + + protected virtual bool ShouldSerializeCaptionForeColor() + { + return Caption.ShouldSerializeForeColor(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Font CaptionFont + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private bool ShouldSerializeCaptionFont() + { + return Caption.ShouldSerializeFont(); + } + + private void ResetCaptionFont() + { + Caption.ResetFont(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string CaptionText + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool CaptionVisible + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_CAPTIONVISIBLECHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler CaptionVisibleChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public DataGridCell CurrentCell + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal int CurrentCellAccIndex + { + get + { + int currentCellAccIndex = 0; + currentCellAccIndex++; // ParentRowsAccessibleObject + currentCellAccIndex += myGridTable.GridColumnStyles.Count; // ColumnHeaderAccessibleObject + currentCellAccIndex += DataGridRows.Length; // DataGridRowAccessibleObject + if (horizScrollBar.Visible) // Horizontal Scroll Bar Accessible Object + currentCellAccIndex++; + if (vertScrollBar.Visible) // Vertical Scroll Bar Accessible Object + currentCellAccIndex++; + currentCellAccIndex += (currentRow * myGridTable.GridColumnStyles.Count) + currentCol; + return currentCellAccIndex; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler CurrentCellChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + private int CurrentColumn + { + get + { + return CurrentCell.ColumnNumber; + } + set + { + CurrentCell = new DataGridCell(currentRow, value); + } + } + + private int CurrentRow + { + get + { + return CurrentCell.RowNumber; + } + set + { + CurrentCell = new DataGridCell(value, currentCol); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color SelectionBackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal SolidBrush SelectionBackBrush + { + get + { + return selectionBackBrush; + } + } + + internal SolidBrush SelectionForeBrush + { + get + { + return selectionForeBrush; + } + } + + protected bool ShouldSerializeSelectionBackColor() + { + return !DefaultSelectionBackBrush.Equals(selectionBackBrush); + } + + public void ResetSelectionBackColor() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color SelectionForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual bool ShouldSerializeSelectionForeColor() + { + return !SelectionForeBrush.Equals(DefaultSelectionForeBrush); + } + + public void ResetSelectionForeColor() + { + throw new PlatformNotSupportedException(); + } + + internal override bool ShouldSerializeForeColor() + { + return !DefaultForeBrush.Color.Equals(this.ForeColor); + } + + internal override bool ShouldSerializeBackColor() + { + return !DefaultBackBrush.Color.Equals(this.BackColor); + } + + // Don't use dataGridRows, use the accessor!!! + internal DataGridRow[] DataGridRows + { + get + { + if (dataGridRows is null) + CreateDataGridRows(); + return dataGridRows; + } + } + + // ToolTipping + internal DataGridToolTip ToolTipProvider + { + get + { + return toolTipProvider; + } + } + + internal int ToolTipId + { + get + { + return toolTipId; + } + set + { + toolTipId = value; + } + } + + private void ResetToolTip() + { + // remove all the tool tips which are stored + for (int i = 0; i < ToolTipId; i++) + { + DataGridToolTip.RemoveToolTip(new IntPtr(i)); + } + + if (!parentRows.IsEmpty()) + { + bool alignRight = isRightToLeft(); + int detailsButtonWidth = DataGridCaption.GetDetailsButtonWidth(); + Rectangle backButton = DataGridCaption.GetBackButtonRect(layout.Caption, alignRight, detailsButtonWidth); + Rectangle detailsButton = DataGridCaption.GetDetailsButtonRect(layout.Caption, alignRight); + + // mirror the buttons wrt RTL property + backButton.X = MirrorRectangle(backButton, layout.Inside, isRightToLeft()); + detailsButton.X = MirrorRectangle(detailsButton, layout.Inside, isRightToLeft()); + + DataGridToolTip.AddToolTip("SR.GetString(SR.DataGridCaptionBackButtonToolTip)", new IntPtr(0), backButton); + DataGridToolTip.AddToolTip("SR.GetString(SR.DataGridCaptionDetailsButtonToolTip)", new IntPtr(1), detailsButton); + ToolTipId = 2; + } + else + { + ToolTipId = 0; + } + } + + private void CreateDataGridRows() + { + CurrencyManager listManager = ListManager; + DataGridTableStyle dgt = myGridTable; + InitializeColumnWidths(); + + if (listManager is null) + { + SetDataGridRows(Array.Empty(), 0); + return; + } + + int nDataGridRows = listManager.Count; + if (policy.AllowAdd) + nDataGridRows++; + + DataGridRow[] rows = new DataGridRow[nDataGridRows]; + for (int r = 0; r < listManager.Count; r++) + { + rows[r] = new DataGridRelationshipRow(this, dgt, r); + } + + if (policy.AllowAdd) + { + addNewRow = new DataGridAddNewRow(this, dgt, nDataGridRows - 1); + rows[nDataGridRows - 1] = addNewRow; + } + else + { + addNewRow = null; + } + + SetDataGridRows(rows, nDataGridRows); + } + + private void RecreateDataGridRows() + { + int nDataGridRows = 0; + CurrencyManager listManager = ListManager; + + if (listManager is not null) + { + nDataGridRows = listManager.Count; + if (policy.AllowAdd) + { + nDataGridRows++; + } + } + + SetDataGridRows(null, nDataGridRows); + } + + /// + /// Sets the array of DataGridRow objects used for + /// all row-related logic in the DataGrid. + /// + internal void SetDataGridRows(DataGridRow[] newRows, int newRowsLength) + { + dataGridRows = newRows; + dataGridRowsLength = newRowsLength; + + // update the vertical scroll bar + vertScrollBar.Maximum = Math.Max(0, DataGridRowsLength - 1); + if (firstVisibleRow > newRowsLength) + { + vertScrollBar.Value = 0; + firstVisibleRow = 0; + } + + ResetUIState(); +#if DEBUG + // sanity check: all the rows should have the same + // dataGridTable + if (newRows is not null && newRowsLength > 0) + { + DataGridTableStyle dgTable = newRows[0].DataGridTableStyle; + for (int i = 0; i < newRowsLength; i++) + { + Debug.Assert(dgTable == newRows[i].DataGridTableStyle, "how can two rows have different tableStyles?"); + } + } +#endif // DEBUG + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: There are now " + DataGridRowsLength.ToString(CultureInfo.InvariantCulture) + " rows."); + } + + internal int DataGridRowsLength + { + get + { + return dataGridRowsLength; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public object DataSource + { + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_DATASOURCECHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler DataSourceChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string DataMember + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + public void SetDataBinding(object dataSource, string dataMember) + { + throw new PlatformNotSupportedException(); + } + + internal protected CurrencyManager ListManager + { + get + { + if (listManager is null && BindingContext is not null && DataSource is not null) + return (CurrencyManager)BindingContext[DataSource, DataMember]; + else + return listManager; + } + set + { + throw new NotSupportedException("SR.GetString(SR.DataGridSetListManager)"); + } + } + + internal void Set_ListManager(object newDataSource, string newDataMember, bool force) + { + Set_ListManager(newDataSource, newDataMember, force, true); // true for forcing column creation + } + + // + // prerequisite: the dataMember and the dataSource should be set to the new values + // + // will do the following: + // call EndEdit on the current listManager, will unWire the listManager events, will set the listManager to the new + // reality, will wire the new listManager, will update the policy, will set the dataGridTable, will reset the ui state. + // + internal void Set_ListManager(object newDataSource, string newDataMember, bool force, bool forceColumnCreation) + { + bool dataSourceChanged = DataSource != newDataSource; + bool dataMemberChanged = DataMember != newDataMember; + + // if nothing happened, then why do any work? + if (!force && !dataSourceChanged && !dataMemberChanged && gridState[GRIDSTATE_inSetListManager]) + return; + + gridState[GRIDSTATE_inSetListManager] = true; + if (toBeDisposedEditingControl is not null) + { + Debug.Assert(Controls.Contains(toBeDisposedEditingControl)); + Controls.Remove(toBeDisposedEditingControl); + toBeDisposedEditingControl = null; + } + + bool beginUpdateInternal = true; + try + { + // will endEdit on the current listManager + UpdateListManager(); + + // unwire the events: + if (listManager is not null) + UnWireDataSource(); + + CurrencyManager oldListManager = listManager; + bool listManagerChanged = false; + // set up the new listManager + // CAUTION: we need to set up the listManager in the grid before setting the dataSource/dataMember props + // in the grid. the reason is that if the BindingContext was not yet requested, and it is created in the BindingContext prop + // then the grid will call Set_ListManager again, and eventually that means that the dataGrid::listManager will + // be hooked up twice to all the events (PositionChanged, ItemChanged, CurrentChanged) + if (newDataSource is not null && BindingContext is not null && !(newDataSource == Convert.DBNull)) + listManager = (CurrencyManager)BindingContext[newDataSource, newDataMember]; + else + listManager = null; + + // update the dataSource and the dateMember + dataSource = newDataSource; + dataMember = newDataMember is null ? "" : newDataMember; + + listManagerChanged = (listManager != oldListManager); + + // wire the events + if (listManager is not null) + { + WireDataSource(); + // update the policy + policy.UpdatePolicy(listManager, ReadOnly); + } + + if (!Initializing) + { + if (listManager is null) + { + if (ContainsFocus && ParentInternal is null) + { + Debug.Assert(toBeDisposedEditingControl is null, "we should have removed the toBeDisposedEditingControl already"); + // if we unparent the active control then the form won't close + for (int i = 0; i < Controls.Count; i++) + { + if (Controls[i].Focused) + { + toBeDisposedEditingControl = Controls[i]; + break; + } + } + + if (toBeDisposedEditingControl == horizScrollBar || toBeDisposedEditingControl == vertScrollBar) + { + toBeDisposedEditingControl = null; + } + +#if DEBUG + else + { + Debug.Assert(toBeDisposedEditingControl is not null, "if the grid contains the focus, then the active control should be in the children of data grid control"); + Debug.Assert(editColumn is not null, "if we have an editing control should be a control in the data grid column"); + if (editColumn is DataGridTextBoxColumn) + { + Debug.Assert(((DataGridTextBoxColumn)editColumn).TextBox == toBeDisposedEditingControl, "if we have an editing control should be a control in the data grid column"); + } + } +#endif // debug; + + } + + SetDataGridRows(null, 0); + defaultTableStyle.GridColumnStyles.Clear(); + SetDataGridTable(defaultTableStyle, forceColumnCreation); + + if (toBeDisposedEditingControl is not null) + { + Controls.Add(toBeDisposedEditingControl); + } + } + } + + // PERF: if the listManager did not change, then do not: + // 1. create new rows + // 2. create new columns + // 3. compute the errors in the list + // + // when the metaDataChanges, we need to recreate + // the rows and the columns + // + if (listManagerChanged || gridState[GRIDSTATE_metaDataChanged]) + { + if (Visible) + BeginUpdateInternal(); + + if (listManager is not null) + { + // get rid of the old gridColumns + // we need to clear the old column collection even when navigating to + // a list that has a table style associated w/ it. Why? because the + // old column collection will be used by the parent rows to paint + defaultTableStyle.GridColumnStyles.ResetDefaultColumnCollection(); + + DataGridTableStyle newGridTable = dataGridTables[listManager.GetListName()]; + if (newGridTable is null) + { + SetDataGridTable(defaultTableStyle, forceColumnCreation); + } + else + { + SetDataGridTable(newGridTable, forceColumnCreation); + } + + // set the currentRow in ssync w/ the position in the listManager + currentRow = listManager.Position == -1 ? 0 : listManager.Position; + } + + // when we create the rows we need to use the current dataGridTable + // + RecreateDataGridRows(); + if (Visible) + EndUpdateInternal(); + beginUpdateInternal = false; + + ComputeMinimumRowHeaderWidth(); + if (myGridTable.IsDefault) + RowHeaderWidth = Math.Max(minRowHeaderWidth, RowHeaderWidth); + else + myGridTable.RowHeaderWidth = Math.Max(minRowHeaderWidth, RowHeaderWidth); + + ListHasErrors = DataGridSourceHasErrors(); + + // build the list of columns and relationships + // wipe out the now invalid states + // ResetMouseState(); + + ResetUIState(); + + // layout.CaptionVisible = dataCursor is null ? false : true; + + OnDataSourceChanged(EventArgs.Empty); + } + } + finally + { + gridState[GRIDSTATE_inSetListManager] = false; + // start painting again + if (beginUpdateInternal && Visible) + EndUpdateInternal(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int CurrentRowIndex + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public GridTableStylesCollection TableStyles + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal new int FontHeight + { + get + { + return fontHeight; + } + } + + internal AccessibleObject ParentRowsAccessibleObject + { + get + { + return parentRows.AccessibleObject; + } + } + + internal Rectangle ParentRowsBounds + { + get + { + return layout.ParentRows; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color GridLineColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual bool ShouldSerializeGridLineColor() + { + return !GridLineBrush.Equals(DefaultGridLineBrush); + } + + public void ResetGridLineColor() + { + throw new PlatformNotSupportedException(); + } + + internal SolidBrush GridLineBrush + { + get + { + return gridLineBrush; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public DataGridLineStyle GridLineStyle + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal int GridLineWidth + { + get + { + Debug.Assert(GridLineStyle == DataGridLineStyle.Solid || GridLineStyle == DataGridLineStyle.None, "are there any other styles?"); + return GridLineStyle == DataGridLineStyle.Solid ? 1 : 0; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public DataGridParentRowsLabelStyle ParentRowsLabelStyle + { + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_PARENTROWSLABELSTYLECHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ParentRowsLabelStyleChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + internal bool Initializing + { + get + { + return inInit; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int FirstVisibleColumn + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool FlatMode + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_FLATMODECHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler FlatModeChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color HeaderBackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal SolidBrush HeaderBackBrush + { + get + { + return headerBackBrush; + } + } + + protected virtual bool ShouldSerializeHeaderBackColor() + { + return !HeaderBackBrush.Equals(DefaultHeaderBackBrush); + } + + public void ResetHeaderBackColor() + { + throw new PlatformNotSupportedException(); + } + + internal SolidBrush BackgroundBrush + { + get + { + return backgroundBrush; + } + } + + private void ResetBackgroundColor() + { + if (backgroundBrush is not null && BackgroundBrush != DefaultBackgroundBrush) + { + backgroundBrush.Dispose(); + backgroundBrush = null; + } + + backgroundBrush = DefaultBackgroundBrush; + } + + protected virtual bool ShouldSerializeBackgroundColor() + { + return !BackgroundBrush.Equals(DefaultBackgroundBrush); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color BackgroundColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_BACKGROUNDCOLORCHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler BackgroundColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Font HeaderFont + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + headerFont = value; + throw new PlatformNotSupportedException(); + } + } + + protected bool ShouldSerializeHeaderFont() + { + return (headerFont is not null); + } + + public void ResetHeaderFont() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color HeaderForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual bool ShouldSerializeHeaderForeColor() + { + return !HeaderForePen.Equals(DefaultHeaderForePen); + } + + public void ResetHeaderForeColor() + { + throw new PlatformNotSupportedException(); + } + + internal SolidBrush HeaderForeBrush + { + get + { + return headerForeBrush; + } + } + + internal Pen HeaderForePen + { + get + { + return headerForePen; + } + } + + private void ResetHorizontalOffset() + { + horizontalOffset = 0; + negOffset = 0; + firstVisibleCol = 0; + numVisibleCols = 0; + lastTotallyVisibleCol = -1; + } + + internal int HorizontalOffset + { + get + { + return horizontalOffset; + } + set + { + if (value < 0) + value = 0; + + int totalWidth = GetColumnWidthSum(); + int widthNotVisible = totalWidth - layout.Data.Width; + if (value > widthNotVisible && widthNotVisible > 0) + value = widthNotVisible; + + if (value == horizontalOffset) + return; + + int change = horizontalOffset - value; + horizScrollBar.Value = value; + Rectangle scroll = layout.Data; + if (layout.ColumnHeadersVisible) + scroll = Rectangle.Union(scroll, layout.ColumnHeaders); + horizontalOffset = value; + + firstVisibleCol = ComputeFirstVisibleColumn(); + // update the lastTotallyVisibleCol + ComputeVisibleColumns(); + + if (gridState[GRIDSTATE_isScrolling]) + { + // if the user did not click on the grid yet, then do not put the edit + // control when scrolling + if (currentCol >= firstVisibleCol && currentCol < firstVisibleCol + numVisibleCols - 1 && (gridState[GRIDSTATE_isEditing] || gridState[GRIDSTATE_isNavigating])) + Edit(); + else + EndEdit(); + + // isScrolling is set to TRUE when the user scrolls. + // once we move the edit box, we finished processing the scroll event, so set isScrolling to FALSE + // to set isScrolling to TRUE, we need another scroll event. + gridState[GRIDSTATE_isScrolling] = false; + } + else + { + EndEdit(); + } + + RECT[] rects = CreateScrollableRegion(scroll); + ScrollRectangles(rects, change); + OnScroll(EventArgs.Empty); + } + } + + private void ScrollRectangles(RECT[] rects, int change) + { + if (rects is not null) + { + RECT scroll; + if (isRightToLeft()) + change = -change; + for (int r = 0; r < rects.Length; r++) + { + scroll = rects[r]; + } + } + } + + protected ScrollBar HorizScrollBar + { + get + { + return horizScrollBar; + } + } + + /// + /// + /// Retrieves a value indicating whether odd and even + /// rows are painted using a different background color. + /// + /// + // CUT by 53973 - Cleanup eventually to be static. + internal bool LedgerStyle + { + get + { + return gridState[GRIDSTATE_isLedgerStyle]; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color LinkColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + /// + /// [To be supplied.] + /// + internal virtual bool ShouldSerializeLinkColor() + { + return !LinkBrush.Equals(DefaultLinkBrush); + } + + public void ResetLinkColor() + { + throw new PlatformNotSupportedException(); + } + + internal Brush LinkBrush + { + get + { + return linkBrush; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color LinkHoverColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + } + } + + protected virtual bool ShouldSerializeLinkHoverColor() + { + return false; + } + + public void ResetLinkHoverColor() + { + throw new PlatformNotSupportedException(); + } + + internal Font LinkFont + { + get + { + return linkFont; + } + } + + internal int LinkFontHeight + { + get + { + return linkFontHeight; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool AllowNavigation + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_ALLOWNAVIGATIONCHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler AllowNavigationChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Cursor Cursor + { + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler CursorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Image BackgroundImage + { + // get the BackgroundImage out of the propertyGrid. + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override ImageLayout BackgroundImageLayout + { + // get the BackgroundImage out of the propertyGrid. + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackgroundImageChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackgroundImageLayoutChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color ParentRowsBackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal SolidBrush ParentRowsBackBrush + { + get + { + return parentRows.BackBrush; + } + } + + protected virtual bool ShouldSerializeParentRowsBackColor() + { + return !ParentRowsBackBrush.Equals(DefaultParentRowsBackBrush); + } + + private void ResetParentRowsBackColor() + { + if (ShouldSerializeParentRowsBackColor()) + parentRows.BackBrush = DefaultParentRowsBackBrush; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color ParentRowsForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal SolidBrush ParentRowsForeBrush + { + get + { + return parentRows.ForeBrush; + } + } + + protected virtual bool ShouldSerializeParentRowsForeColor() + { + return !ParentRowsForeBrush.Equals(DefaultParentRowsForeBrush); + } + + private void ResetParentRowsForeColor() + { + if (ShouldSerializeParentRowsForeColor()) + parentRows.ForeBrush = DefaultParentRowsForeBrush; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int PreferredColumnWidth + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int PreferredRowHeight + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private void ResetPreferredRowHeight() + { + prefferedRowHeight = defaultFontHeight + 3; + } + + protected bool ShouldSerializePreferredRowHeight() + { + return prefferedRowHeight != defaultFontHeight + 3; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool ReadOnly + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_READONLYCHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ReadOnlyChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool ColumnHeadersVisible + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool ParentRowsVisible + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private static readonly object EVENT_PARENTROWSVISIBLECHANGED = new object(); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ParentRowsVisibleChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + internal bool ParentRowsIsEmpty() + { + return parentRows.IsEmpty(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool RowHeadersVisible + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int RowHeaderWidth + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Text + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler TextChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected ScrollBar VertScrollBar + { + get + { + return vertScrollBar; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int VisibleColumnCount + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int VisibleRowCount + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public object this[int rowIndex, int columnIndex] + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public object this[DataGridCell cell] + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private void WireTableStylePropChanged(DataGridTableStyle gridTable) + { + gridTable.GridLineColorChanged += new EventHandler(GridLineColorChanged); + gridTable.GridLineStyleChanged += new EventHandler(GridLineStyleChanged); + gridTable.HeaderBackColorChanged += new EventHandler(HeaderBackColorChanged); + gridTable.HeaderFontChanged += new EventHandler(HeaderFontChanged); + gridTable.HeaderForeColorChanged += new EventHandler(HeaderForeColorChanged); + gridTable.LinkColorChanged += new EventHandler(LinkColorChanged); + gridTable.LinkHoverColorChanged += new EventHandler(LinkHoverColorChanged); + gridTable.PreferredColumnWidthChanged += new EventHandler(PreferredColumnWidthChanged); + gridTable.RowHeadersVisibleChanged += new EventHandler(RowHeadersVisibleChanged); + gridTable.ColumnHeadersVisibleChanged += new EventHandler(ColumnHeadersVisibleChanged); + gridTable.RowHeaderWidthChanged += new EventHandler(RowHeaderWidthChanged); + gridTable.AllowSortingChanged += new EventHandler(AllowSortingChanged); + } + + private void UnWireTableStylePropChanged(DataGridTableStyle gridTable) + { + gridTable.GridLineColorChanged -= new EventHandler(GridLineColorChanged); + gridTable.GridLineStyleChanged -= new EventHandler(GridLineStyleChanged); + gridTable.HeaderBackColorChanged -= new EventHandler(HeaderBackColorChanged); + gridTable.HeaderFontChanged -= new EventHandler(HeaderFontChanged); + gridTable.HeaderForeColorChanged -= new EventHandler(HeaderForeColorChanged); + gridTable.LinkColorChanged -= new EventHandler(LinkColorChanged); + gridTable.LinkHoverColorChanged -= new EventHandler(LinkHoverColorChanged); + gridTable.PreferredColumnWidthChanged -= new EventHandler(PreferredColumnWidthChanged); + gridTable.RowHeadersVisibleChanged -= new EventHandler(RowHeadersVisibleChanged); + gridTable.ColumnHeadersVisibleChanged -= new EventHandler(ColumnHeadersVisibleChanged); + gridTable.RowHeaderWidthChanged -= new EventHandler(RowHeaderWidthChanged); + gridTable.AllowSortingChanged -= new EventHandler(AllowSortingChanged); + } + + /// + /// DataSource events are handled + /// + private void WireDataSource() + { + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: WireDataSource"); + Debug.Assert(listManager is not null, "Can't wire up to a null DataSource"); + } + + private void UnWireDataSource() + { + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: UnWireDataSource"); + Debug.Assert(listManager is not null, "Can't un wire from a null DataSource"); + } + + // This is called after a row has been added. And I think whenever + // a row gets deleted, etc. + // We recreate our datagrid rows at this point. + private void DataSource_Changed(object sender, EventArgs ea) + { + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: DataSource_Changed"); + + // the grid will receive the dataSource_Changed event when + // allowAdd changes on the dataView. + policy.UpdatePolicy(ListManager, ReadOnly); + if (gridState[GRIDSTATE_inListAddNew]) + { + // we are adding a new row + // keep the old rows, w/ their height, expanded/collapsed information + // + Debug.Assert(policy.AllowAdd, "how can we add a new row if the policy does not allow this?"); + Debug.Assert(DataGridRowsLength == DataGridRows.Length, "how can this fail?"); + + DataGridRow[] gridRows = DataGridRows; + int currentRowCount = DataGridRowsLength; + // put the added row: + // + gridRows[currentRowCount - 1] = new DataGridRelationshipRow(this, myGridTable, currentRowCount - 1); + SetDataGridRows(gridRows, currentRowCount); + } + else if (gridState[GRIDSTATE_inAddNewRow] && !gridState[GRIDSTATE_inDeleteRow]) + { + // when the backEnd adds a row and we are still inAddNewRow + listManager.CancelCurrentEdit(); + gridState[GRIDSTATE_inAddNewRow] = false; + RecreateDataGridRows(); + } + else if (!gridState[GRIDSTATE_inDeleteRow]) + { + RecreateDataGridRows(); + currentRow = Math.Min(currentRow, listManager.Count); + } + + bool oldListHasErrors = ListHasErrors; + ListHasErrors = DataGridSourceHasErrors(); + // if we changed the ListHasErrors, then the grid is already invalidated + if (oldListHasErrors == ListHasErrors) + InvalidateInside(); + } + + private void GridLineColorChanged(object sender, EventArgs e) + { + Invalidate(layout.Data); + } + + private void GridLineStyleChanged(object sender, EventArgs e) + { + this.myGridTable.ResetRelationsUI(); + Invalidate(layout.Data); + } + + private void HeaderBackColorChanged(object sender, EventArgs e) + { + if (layout.RowHeadersVisible) + Invalidate(layout.RowHeaders); + if (layout.ColumnHeadersVisible) + Invalidate(layout.ColumnHeaders); + Invalidate(layout.TopLeftHeader); + } + + private void HeaderFontChanged(object sender, EventArgs e) + { + RecalculateFonts(); + PerformLayout(); + Invalidate(layout.Inside); + } + + private void HeaderForeColorChanged(object sender, EventArgs e) + { + if (layout.RowHeadersVisible) + Invalidate(layout.RowHeaders); + if (layout.ColumnHeadersVisible) + Invalidate(layout.ColumnHeaders); + Invalidate(layout.TopLeftHeader); + } + + private void LinkColorChanged(object sender, EventArgs e) + { + Invalidate(layout.Data); + } + + private void LinkHoverColorChanged(object sender, EventArgs e) + { + Invalidate(layout.Data); + } + + private void PreferredColumnWidthChanged(object sender, EventArgs e) + { + // reset the dataGridRows + SetDataGridRows(null, this.DataGridRowsLength); + // layout the horizontal scroll bar + PerformLayout(); + // invalidate everything + Invalidate(); + } + + private void RowHeadersVisibleChanged(object sender, EventArgs e) + { + layout.RowHeadersVisible = myGridTable is null ? false : myGridTable.RowHeadersVisible; + PerformLayout(); + InvalidateInside(); + } + + private void ColumnHeadersVisibleChanged(object sender, EventArgs e) + { + layout.ColumnHeadersVisible = myGridTable is null ? false : myGridTable.ColumnHeadersVisible; + PerformLayout(); + InvalidateInside(); + } + + private void RowHeaderWidthChanged(object sender, EventArgs e) + { + if (layout.RowHeadersVisible) + { + PerformLayout(); + InvalidateInside(); + } + } + + private void AllowSortingChanged(object sender, EventArgs e) + { + if (!myGridTable.AllowSorting && listManager is not null) + { + IList list = listManager.List; + if (list is IBindingList) + ((IBindingList)list).RemoveSort(); + } + } + + private void DataSource_RowChanged(object sender, EventArgs ea) + { + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: DataSource_RowChanged"); + // it may be the case that our cache was not updated + // to the latest changes in the list : CurrentChanged is fired before + // ListChanged. + // So invalidate the row if there is something to invalidate + DataGridRow[] rows = DataGridRows; + if (currentRow < DataGridRowsLength) + { + InvalidateRow(currentRow); + } + } + + /// + /// + /// Fired by the DataSource when row position moves. + /// + /// + private void DataSource_PositionChanged(object sender, EventArgs ea) + { + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: DataSource_PositionChanged to " + listManager.Position.ToString(CultureInfo.InvariantCulture)); + // the grid will get the PositionChanged event + // before the OnItemChanged event when a row will be deleted in the backEnd; + // we still want to keep the old rows when the user deletes the rows using the grid + // and we do not want to do the same work twice when the user adds a row via the grid + if (DataGridRowsLength > listManager.Count + (policy.AllowAdd ? 1 : 0) && !gridState[GRIDSTATE_inDeleteRow]) + { + Debug.Assert(!gridState[GRIDSTATE_inAddNewRow] && !gridState[GRIDSTATE_inListAddNew], "how can the list decrease when we are adding a row?"); + RecreateDataGridRows(); + } + + if (ListManager.Position != currentRow) + { + CurrentCell = new DataGridCell(listManager.Position, currentCol); + } + } + + internal void DataSource_MetaDataChanged(object sender, EventArgs e) + { + MetaDataChanged(); + } + + private bool DataGridSourceHasErrors() + { + if (listManager is null) + return false; + for (int i = 0; i < listManager.Count; i++) + { + object errObj = listManager[i]; + if (errObj is IDataErrorInfo) + { + string errString = ((IDataErrorInfo)errObj).Error; + if (errString is not null && errString.Length != 0) + return true; + } + } + + return false; + } + + private void TableStylesCollectionChanged(object sender, CollectionChangeEventArgs ccea) + { + // if the users changed the collection of tableStyles + if (sender != dataGridTables) + return; + if (listManager is null) + return; + + if (ccea.Action == CollectionChangeAction.Add) + { + DataGridTableStyle tableStyle = (DataGridTableStyle)ccea.Element; + if (listManager.GetListName().Equals(tableStyle.MappingName)) + { + Debug.Assert(myGridTable.IsDefault, "if the table is not default, then it had a name. how can one add another table to the collection w/ the same name and not throw an exception"); + SetDataGridTable(tableStyle, true); // true for forcing column creation + SetDataGridRows(null, 0); + } + } + else if (ccea.Action == CollectionChangeAction.Remove) + { + DataGridTableStyle tableStyle = (DataGridTableStyle)ccea.Element; + if (myGridTable.MappingName.Equals(tableStyle.MappingName)) + { + Debug.Assert(myGridTable.IsDefault, "if the table is not default, then it had a name. how can one add another table to the collection w/ the same name and not throw an exception"); + defaultTableStyle.GridColumnStyles.ResetDefaultColumnCollection(); + SetDataGridTable(defaultTableStyle, true); // true for forcing column creation + SetDataGridRows(null, 0); + } + } + else + { + Debug.Assert(ccea.Action == CollectionChangeAction.Refresh, "what else is possible?"); + // we have to search to see if the collection of table styles contains one + // w/ the same name as the list in the dataGrid + + DataGridTableStyle newGridTable = dataGridTables[listManager.GetListName()]; + if (newGridTable is null) + { + if (!myGridTable.IsDefault) + { + // get rid of the old gridColumns + defaultTableStyle.GridColumnStyles.ResetDefaultColumnCollection(); + SetDataGridTable(defaultTableStyle, true); // true for forcing column creation + SetDataGridRows(null, 0); + } + } + else + { + SetDataGridTable(newGridTable, true); // true for forcing column creation + SetDataGridRows(null, 0); + } + } + } + + private void DataSource_ItemChanged(object sender, ItemChangedEventArgs ea) + { + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: DataSource_ItemChanged at index " + ea.Index.ToString(CultureInfo.InvariantCulture)); + + // if ea.Index == -1, then we invalidate all rows. + if (ea.Index == -1) + { + DataSource_Changed(sender, EventArgs.Empty); + } + else + { + // let's see how we are doing w/ the errors + object errObj = this.listManager[ea.Index]; + bool oldListHasErrors = ListHasErrors; + if (errObj is IDataErrorInfo) + { + if (((IDataErrorInfo)errObj).Error.Length != 0) + ListHasErrors = true; + else if (ListHasErrors) + { + // maybe there was an error that now is fixed + ListHasErrors = DataGridSourceHasErrors(); + } + } + + // Invalidate the row only if we did not change the ListHasErrors + if (oldListHasErrors == ListHasErrors) + InvalidateRow(ea.Index); + + // we need to update the edit box: + // we update the text in the edit box only when the currentRow + // equals the ea.Index + if (editColumn is not null && ea.Index == currentRow) + editColumn.UpdateUI(ListManager, ea.Index, null); + } + } + + protected virtual void OnBorderStyleChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_BORDERSTYLECHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected virtual void OnCaptionVisibleChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_CAPTIONVISIBLECHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected virtual void OnCurrentCellChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_CURRENTCELLCHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected virtual void OnFlatModeChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_FLATMODECHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected virtual void OnBackgroundColorChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_BACKGROUNDCOLORCHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected virtual void OnAllowNavigationChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_ALLOWNAVIGATIONCHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected virtual void OnParentRowsVisibleChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_PARENTROWSVISIBLECHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected virtual void OnParentRowsLabelStyleChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_PARENTROWSLABELSTYLECHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected virtual void OnReadOnlyChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_READONLYCHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected void OnNavigate(NavigateEventArgs e) + { + } + + internal void OnNodeClick(EventArgs e) + { + PerformLayout(); + + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + if (firstVisibleCol > -1 && firstVisibleCol < columns.Count && columns[firstVisibleCol] == editColumn) + Edit(); + + // Raise the event for the event listeners + EventHandler handler = (EventHandler)Events[EVENT_NODECLICKED]; + if (handler is not null) + { + handler(this, e); + } + } + + protected void OnRowHeaderClick(EventArgs e) + { + if (onRowHeaderClick is not null) + onRowHeaderClick(this, e); + } + + protected void OnScroll(EventArgs e) + { + // reset the toolTip information + if (ToolTipProvider is not null) + ResetToolTip(); + + EventHandler handler = (EventHandler)Events[EVENT_SCROLL]; + if (handler is not null) + { + handler(this, e); + } + } + + protected virtual void GridHScrolled(object sender, ScrollEventArgs se) + { + if (!Enabled) + return; + if (DataSource is null) + { + Debug.Fail("Horizontal Scrollbar should be disabled without a DataSource."); + return; + } + + gridState[GRIDSTATE_isScrolling] = true; + +#if DEBUG + + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: in GridHScrolled: the scroll event type:"); + switch (se.Type) + { + case ScrollEventType.SmallIncrement: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "small increment"); + break; + case ScrollEventType.SmallDecrement: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "small decrement"); + break; + case ScrollEventType.LargeIncrement: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "Large decrement"); + break; + case ScrollEventType.LargeDecrement: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "small decrement"); + break; + case ScrollEventType.ThumbPosition: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "Thumb Position"); + break; + case ScrollEventType.ThumbTrack: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "Thumb Track"); + break; + case ScrollEventType.First: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "First"); + break; + case ScrollEventType.Last: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "Last"); + break; + case ScrollEventType.EndScroll: + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "EndScroll"); + break; + } + +#endif // DEBUG + + if (se.Type == ScrollEventType.SmallIncrement || + se.Type == ScrollEventType.SmallDecrement) + { + int dCols = (se.Type == ScrollEventType.SmallIncrement) ? 1 : -1; + if (se.Type == ScrollEventType.SmallDecrement && negOffset == 0) + { + GridColumnStylesCollection cols = myGridTable.GridColumnStyles; + // if the column before the first visible column has width == 0 then skip it + for (int i = firstVisibleCol - 1; i >= 0 && cols[i].Width == 0; i--) + { + dCols--; + } + } + + if (se.Type == ScrollEventType.SmallIncrement && negOffset == 0) + { + GridColumnStylesCollection cols = myGridTable.GridColumnStyles; + for (int i = firstVisibleCol; i > -1 && i < cols.Count && cols[i].Width == 0; i++) + { + dCols++; + } + } + + ScrollRight(dCols); + se.NewValue = HorizontalOffset; + } + else if (se.Type != ScrollEventType.EndScroll) + { + HorizontalOffset = se.NewValue; + } + + gridState[GRIDSTATE_isScrolling] = false; + } + + protected virtual void GridVScrolled(object sender, ScrollEventArgs se) + { + if (!Enabled) + return; + if (DataSource is null) + { + Debug.Fail("Vertical Scrollbar should be disabled without a DataSource."); + return; + } + + gridState[GRIDSTATE_isScrolling] = true; + + try + { + se.NewValue = Math.Min(se.NewValue, DataGridRowsLength - numTotallyVisibleRows); + int dRows = se.NewValue - firstVisibleRow; + ScrollDown(dRows); + } + finally + { + gridState[GRIDSTATE_isScrolling] = false; + } + } + + private void HandleEndCurrentEdit() + { + int currentRowSaved = currentRow; + int currentColSaved = currentCol; + + string errorMessage = null; + + try + { + listManager.EndCurrentEdit(); + } + catch (Exception e) + { + errorMessage = e.Message; + } + + if (errorMessage is not null) + { + DialogResult result = RTLAwareMessageBox.Show(null, + "SR.GetString(SR.DataGridPushedIncorrectValueIntoColumn, errorMessage)", + "SR.GetString(SR.DataGridErrorMessageBoxCaption)", + MessageBoxButtons.YesNo, + MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); + + if (result == DialogResult.Yes) + { + currentRow = currentRowSaved; + currentCol = currentColSaved; + Debug.Assert(currentRow == ListManager.Position || listManager.Position == -1, "the position in the list manager (" + ListManager.Position + ") is out of sync with the currentRow (" + currentRow + ")" + " and the exception is '" + errorMessage + "'"); + // also, make sure that we get the row selector on the currentrow, too + InvalidateRowHeader(currentRow); + Edit(); + } + else + { + Debug.Assert(result == DialogResult.No, "we only put cancel and ok on the error message box"); + listManager.CancelCurrentEdit(); + listManager.Position = currentRow; + } + } + } + + protected void OnBackButtonClicked(object sender, EventArgs e) + { + NavigateBack(); + + EventHandler handler = (EventHandler)Events[EVENT_BACKBUTTONCLICK]; + if (handler is not null) + handler(this, e); + } + + protected override void OnBackColorChanged(EventArgs e) + { + backBrush = new SolidBrush(BackColor); + Invalidate(); + + base.OnBackColorChanged(e); + } + + protected override void OnBindingContextChanged(EventArgs e) + { + if (DataSource is not null && !gridState[GRIDSTATE_inSetListManager]) + try + { + Set_ListManager(DataSource, DataMember, true, false); + } + catch + { + // at runtime we will rethrow the exception + if (Site is null || !Site.DesignMode) + throw; + + RTLAwareMessageBox.Show(null, "SR.GetString(SR.DataGridExceptionInPaint)", null, + MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); + + if (Visible) + BeginUpdateInternal(); + + ResetParentRows(); + + Set_ListManager(null, string.Empty, true); + if (Visible) + EndUpdateInternal(); + } + + base.OnBindingContextChanged(e); + } + + protected virtual void OnDataSourceChanged(EventArgs e) + { + EventHandler eh = Events[EVENT_DATASOURCECHANGED] as EventHandler; + if (eh is not null) + { + eh(this, e); + } + } + + protected void OnShowParentDetailsButtonClicked(object sender, EventArgs e) + { + ParentRowsVisible = !caption.ToggleDownButtonDirection(); + + EventHandler handler = (EventHandler)Events[EVENT_DOWNBUTTONCLICK]; + if (handler is not null) + handler(this, e); + } + + protected override void OnForeColorChanged(EventArgs e) + { + foreBrush = new SolidBrush(ForeColor); + Invalidate(); + + base.OnForeColorChanged(e); + } + + protected override void OnFontChanged(EventArgs e) + { + // let the caption know about the event changed + // + Caption.OnGridFontChanged(); + RecalculateFonts(); + RecreateDataGridRows(); + // get all the rows in the parentRows stack, and modify their height + if (originalState is not null) + { + Debug.Assert(!parentRows.IsEmpty(), "if the originalState is not null, then parentRows contains at least one row"); + Stack parentStack = new Stack(); + while (!parentRows.IsEmpty()) + { + DataGridState dgs = parentRows.PopTop(); + int rowCount = dgs.DataGridRowsLength; + + for (int i = 0; i < rowCount; i++) + { + // performance hit: this will cause to invalidate a bunch of + // stuff + + dgs.DataGridRows[i].Height = dgs.DataGridRows[i].MinimumRowHeight(dgs.GridColumnStyles); + } + + parentStack.Push(dgs); + } + + while (parentStack.Count != 0) + { + parentRows.AddParent((DataGridState)parentStack.Pop()); + } + } + + base.OnFontChanged(e); + } + + protected override void OnPaintBackground(PaintEventArgs ebe) + { + } + + protected override void OnLayout(LayoutEventArgs levent) + { + if (gridState[GRIDSTATE_editControlChanging]) + return; + + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: OnLayout"); + base.OnLayout(levent); + + if (gridState[GRIDSTATE_layoutSuspended]) + return; + + gridState[GRIDSTATE_canFocus] = false; + try + { + if (IsHandleCreated) + { + if (layout.ParentRowsVisible) + parentRows.OnLayout(); + + // reset the toolTip information + if (ToolTipProvider is not null) + ResetToolTip(); + + ComputeLayout(); + } + } + finally + { + gridState[GRIDSTATE_canFocus] = true; + } + } + + protected override void OnHandleCreated(EventArgs e) + { + base.OnHandleCreated(e); + + toolTipProvider = new DataGridToolTip(this); + DataGridToolTip.CreateToolTipHandle(); + toolTipId = 0; + + PerformLayout(); + } + + protected override void OnHandleDestroyed(EventArgs e) + { + base.OnHandleDestroyed(e); + + // toolTipping + if (toolTipProvider is not null) + { + DataGridToolTip.Destroy(); + toolTipProvider = null; + } + + toolTipId = 0; + } + + protected override void OnEnter(EventArgs e) + { + if (gridState[GRIDSTATE_canFocus] && !gridState[GRIDSTATE_editControlChanging]) + { + if (Bound) + { + Edit(); + } + + base.OnEnter(e); + } + } + + protected override void OnLeave(EventArgs e) + { + OnLeave_Grid(); + base.OnLeave(e); + } + + private void OnLeave_Grid() + { + gridState[GRIDSTATE_canFocus] = false; + try + { + EndEdit(); + if (listManager is not null && !gridState[GRIDSTATE_editControlChanging]) + { + if (gridState[GRIDSTATE_inAddNewRow]) + { + // if the user did not type anything + // in the addNewRow, then cancel the currentedit + listManager.CancelCurrentEdit(); + // set the addNewRow back + DataGridRow[] localGridRows = DataGridRows; + localGridRows[DataGridRowsLength - 1] = new DataGridAddNewRow(this, myGridTable, DataGridRowsLength - 1); + SetDataGridRows(localGridRows, DataGridRowsLength); + } + else + { + // this.listManager.EndCurrentEdit(); + HandleEndCurrentEdit(); + } + } + } + finally + { + gridState[GRIDSTATE_canFocus] = true; + // inAddNewRow should be set to false if the control was + // not changing + if (!gridState[GRIDSTATE_editControlChanging]) + gridState[GRIDSTATE_inAddNewRow] = false; + } + } + + protected override void OnKeyDown(KeyEventArgs ke) + { + Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: OnKeyDown "); + base.OnKeyDown(ke); + ProcessGridKey(ke); + } + + protected override void OnKeyPress(KeyPressEventArgs kpe) + { + Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: OnKeyPress " + TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(kpe.KeyChar)); + + base.OnKeyPress(kpe); + GridColumnStylesCollection coll = myGridTable.GridColumnStyles; + if (coll is not null && currentCol > 0 && currentCol < coll.Count) + { + if (!coll[currentCol].ReadOnly) + if (kpe.KeyChar > 32) + { + Edit(new string(new char[] { kpe.KeyChar })); + } + } + } + + protected override void OnMouseDown(MouseEventArgs e) + { + base.OnMouseDown(e); + + gridState[GRIDSTATE_childLinkFocused] = false; + gridState[GRIDSTATE_dragging] = false; + if (listManager is null) + return; + + HitTestInfo location = HitTest(e.X, e.Y); + Keys nModifier = ModifierKeys; + bool isControlDown = (nModifier & Keys.Control) == Keys.Control && (nModifier & Keys.Alt) == 0; + bool isShiftDown = (nModifier & Keys.Shift) == Keys.Shift; + + // Only left clicks for now + if (e.Button != MouseButtons.Left) + return; + + // Check column resize + if (location.type == HitTestType.ColumnResize) + { + if (e.Clicks > 1) + { + ColAutoResize(location.col); + } + else + ColResizeBegin(e, location.col); + return; + } + + // Check row resize + if (location.type == HitTestType.RowResize) + { + if (e.Clicks > 1) + { + RowAutoResize(location.row); + } + else + { + RowResizeBegin(e, location.row); + } + + return; + } + + // Check column headers + if (location.type == HitTestType.ColumnHeader) + { + trackColumnHeader = myGridTable.GridColumnStyles[location.col].PropertyDescriptor; + return; + } + + if (location.type == HitTestType.Caption) + { + Rectangle captionRect = layout.Caption; + caption.MouseDown(e.X - captionRect.X, e.Y - captionRect.Y); + return; + } + + if (layout.Data.Contains(e.X, e.Y) || layout.RowHeaders.Contains(e.X, e.Y)) + { + // Check with the row underneath the mouse + int row = GetRowFromY(e.Y); + if (row > -1) + { + Point p = NormalizeToRow(e.X, e.Y, row); + DataGridRow[] localGridRows = DataGridRows; + if (localGridRows[row].OnMouseDown(p.X, p.Y, + layout.RowHeaders, + isRightToLeft())) + { + CommitEdit(); + + localGridRows = DataGridRows; + if (row < DataGridRowsLength && (localGridRows[row] is DataGridRelationshipRow) && ((DataGridRelationshipRow)localGridRows[row]).Expanded) + EnsureVisible(row, 0); + + Edit(); + return; + } + } + } + + if (location.type == HitTestType.RowHeader) + { + EndEdit(); + if (!(DataGridRows[location.row] is DataGridAddNewRow)) + { + int savedCurrentRow = currentRow; + CurrentCell = new DataGridCell(location.row, currentCol); + if (location.row != savedCurrentRow && + currentRow != location.row && + currentRow == savedCurrentRow) + { + // The data grid was not able to move away from its previous current row. + // Be defensive and don't select the row. + return; + } + } + + if (isControlDown) + { + if (IsSelected(location.row)) + UnSelect(location.row); + else + Select(location.row); + } + else + { + if (lastRowSelected == -1 || !isShiftDown) + { + ResetSelection(); + Select(location.row); + } + else + { + int lowerRow = Math.Min(lastRowSelected, location.row); + int upperRow = Math.Max(lastRowSelected, location.row); + + // we need to reset the old SelectedRows. + // ResetSelection() will also reset lastRowSelected, so we + // need to save it + int saveLastRowSelected = lastRowSelected; + ResetSelection(); + lastRowSelected = saveLastRowSelected; + + DataGridRow[] rows = DataGridRows; + for (int i = lowerRow; i <= upperRow; i++) + { + rows[i].Selected = true; + numSelectedRows++; + } + + EndEdit(); + return; + } + } + + lastRowSelected = location.row; + // OnRowHeaderClick(EventArgs.Empty); + return; + } + + // Check parentRows + if (location.type == HitTestType.ParentRows) + { + EndEdit(); + parentRows.OnMouseDown(e.X, e.Y, isRightToLeft()); + } + + // Check cell clicks + if (location.type == HitTestType.Cell) + { + if (myGridTable.GridColumnStyles[location.col].MouseDown(location.row, e.X, e.Y)) + return; + DataGridCell target = new DataGridCell(location.row, location.col); + if (policy.AllowEdit && CurrentCell.Equals(target)) + { + ResetSelection(); + // what if only a part of the current cell is visible? + EnsureVisible(currentRow, currentCol); + Edit(); + } + else + { + ResetSelection(); + CurrentCell = target; + } + } + } + + protected override void OnMouseLeave(EventArgs e) + { + base.OnMouseLeave(e); + if (oldRow != -1) + { + DataGridRow[] localGridRows = DataGridRows; + localGridRows[oldRow].OnMouseLeft(layout.RowHeaders, isRightToLeft()); + } + + if (gridState[GRIDSTATE_overCaption]) + { + caption.MouseLeft(); + } + + Cursor = null; + } + + internal void TextBoxOnMouseWheel(MouseEventArgs e) + { + OnMouseWheel(e); + } + + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + if (listManager is null) + return; + + HitTestInfo location = HitTest(e.X, e.Y); + + bool alignToRight = isRightToLeft(); + + // We need to give UI feedback when the user is resizing a column + if (gridState[GRIDSTATE_trackColResize]) + { + ColResizeMove(e); + } + + if (gridState[GRIDSTATE_trackRowResize]) + { + RowResizeMove(e); + } + + if (gridState[GRIDSTATE_trackColResize] || location.type == HitTestType.ColumnResize) + { + Cursor = Cursors.SizeWE; + return; + } + else if (gridState[GRIDSTATE_trackRowResize] || location.type == HitTestType.RowResize) + { + Cursor = Cursors.SizeNS; + return; + } + else + { + Cursor = null; + } + + if ((layout.Data.Contains(e.X, e.Y) + || (layout.RowHeadersVisible && layout.RowHeaders.Contains(e.X, e.Y)))) + { + // && (isNavigating || isEditing)) { + DataGridRow[] localGridRows = DataGridRows; + // If we are over a row, let it know about the mouse move. + int rowOver = GetRowFromY(e.Y); + // set the dragging bit: + if (lastRowSelected != -1 && !gridState[GRIDSTATE_dragging]) + { + int topRow = GetRowTop(lastRowSelected); + int bottomRow = topRow + localGridRows[lastRowSelected].Height; + int dragHeight = SystemInformation.DragSize.Height; + gridState[GRIDSTATE_dragging] = ((e.Y - topRow < dragHeight && topRow - e.Y < dragHeight) || (e.Y - bottomRow < dragHeight && bottomRow - e.Y < dragHeight)); + } + + if (rowOver > -1) + { + Point p = NormalizeToRow(e.X, e.Y, rowOver); + if (!localGridRows[rowOver].OnMouseMove(p.X, p.Y, layout.RowHeaders, alignToRight) && gridState[GRIDSTATE_dragging]) + { + // if the row did not use this, see if selection can use it + MouseButtons mouse = MouseButtons; + if (lastRowSelected != -1 && (mouse & MouseButtons.Left) == MouseButtons.Left + && !(((Control.ModifierKeys & Keys.Control) == Keys.Control) && (Control.ModifierKeys & Keys.Alt) == 0)) + { + // ResetSelection() will reset the lastRowSelected too + // + int saveLastRowSelected = lastRowSelected; + ResetSelection(); + lastRowSelected = saveLastRowSelected; + + int lowerRow = Math.Min(lastRowSelected, rowOver); + int upperRow = Math.Max(lastRowSelected, rowOver); + + DataGridRow[] rows = DataGridRows; + for (int i = lowerRow; i <= upperRow; i++) + { + rows[i].Selected = true; + numSelectedRows++; + } + } + } + } + + if (oldRow != rowOver && oldRow != -1) + { + localGridRows[oldRow].OnMouseLeft(layout.RowHeaders, alignToRight); + } + + oldRow = rowOver; + } + + // check parentRows + if (location.type == HitTestType.ParentRows) + { + if (parentRows is not null) + { + parentRows.OnMouseMove(e.X, e.Y); + } + } + + if (location.type == HitTestType.Caption) + { + gridState[GRIDSTATE_overCaption] = true; + Rectangle captionRect = layout.Caption; + caption.MouseOver(e.X - captionRect.X, e.Y - captionRect.Y); + return; + } + else + { + if (gridState[GRIDSTATE_overCaption]) + { + gridState[GRIDSTATE_overCaption] = false; + caption.MouseLeft(); + } + } + } + + protected override void OnMouseUp(MouseEventArgs e) + { + base.OnMouseUp(e); + gridState[GRIDSTATE_dragging] = false; + if (listManager is null || myGridTable is null) + return; + if (gridState[GRIDSTATE_trackColResize]) + { + ColResizeEnd(e); + } + + if (gridState[GRIDSTATE_trackRowResize]) + { + RowResizeEnd(e); + } + + gridState[GRIDSTATE_trackColResize] = false; + gridState[GRIDSTATE_trackRowResize] = false; + + HitTestInfo ci = HitTest(e.X, e.Y); + if ((ci.type & HitTestType.Caption) == HitTestType.Caption) + { + caption.MouseUp(e.X, e.Y); + } + + // Check column headers + if (ci.type == HitTestType.ColumnHeader) + { + PropertyDescriptor prop = myGridTable.GridColumnStyles[ci.col].PropertyDescriptor; + if (prop == trackColumnHeader) + { + ColumnHeaderClicked(trackColumnHeader); + } + } + + trackColumnHeader = null; + } + + protected override void OnMouseWheel(MouseEventArgs e) + { + base.OnMouseWheel(e); + + if (e is HandledMouseEventArgs) + { + if (((HandledMouseEventArgs)e).Handled) + { + // The application event handler handled the scrolling - don't do anything more. + return; + } + + ((HandledMouseEventArgs)e).Handled = true; + } + + bool wheelingDown = true; + if ((ModifierKeys & Keys.Control) != 0) + wheelingDown = false; + + if (listManager is null || myGridTable is null) + return; + ScrollBar sb = wheelingDown ? vertScrollBar : horizScrollBar; + if (!sb.Visible) + return; + + // so we scroll. we have to know this, cause otherwise we will call EndEdit + // and that would be wrong. + gridState[GRIDSTATE_isScrolling] = true; + wheelDelta += e.Delta; + float movePerc = (float)wheelDelta / PInvoke.WHEEL_DELTA; + int move = (int)(SystemInformation.MouseWheelScrollLines * movePerc); + if (move != 0) + { + wheelDelta = 0; + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: OnMouseWheel move=" + move.ToString(CultureInfo.InvariantCulture)); + if (wheelingDown) + { + int newRow = firstVisibleRow - move; + newRow = Math.Max(0, Math.Min(newRow, DataGridRowsLength - numTotallyVisibleRows)); + ScrollDown(newRow - firstVisibleRow); + } + else + { + int newValue = horizScrollBar.Value + (move < 0 ? 1 : -1) * horizScrollBar.LargeChange; + HorizontalOffset = newValue; + } + } + + gridState[GRIDSTATE_isScrolling] = false; + } + + protected override void OnPaint(PaintEventArgs pe) + { + try + { + CheckHierarchyState(); + + if (layout.dirty) + ComputeLayout(); + + Graphics g = pe.Graphics; + + Region clipRegion = g.Clip; + if (layout.CaptionVisible) + caption.Paint(g, layout.Caption, isRightToLeft()); + + if (layout.ParentRowsVisible) + { + Debug.WriteLineIf(CompModSwitches.DataGridParents.TraceVerbose, "DataGridParents: Painting ParentRows " + layout.ParentRows.ToString()); + g.FillRectangle(SystemBrushes.AppWorkspace, layout.ParentRows); + parentRows.Paint(g, layout.ParentRows, isRightToLeft()); + } + + Rectangle gridRect = layout.Data; + if (layout.RowHeadersVisible) + gridRect = Rectangle.Union(gridRect, layout.RowHeaders); + if (layout.ColumnHeadersVisible) + gridRect = Rectangle.Union(gridRect, layout.ColumnHeaders); + + g.SetClip(gridRect); + PaintGrid(g, gridRect); + g.Clip = clipRegion; + clipRegion.Dispose(); + PaintBorder(g, layout.ClientRectangle); + + g.FillRectangle(DefaultHeaderBackBrush, layout.ResizeBoxRect); + + base.OnPaint(pe); // raise paint event + } + catch + { + // at runtime we will rethrow the exception + if (Site is null || !Site.DesignMode) + throw; + gridState[GRIDSTATE_exceptionInPaint] = true; + try + { + RTLAwareMessageBox.Show(null, "SR.GetString(SR.DataGridExceptionInPaint)", null, MessageBoxButtons.OK, + MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); + + if (Visible) + BeginUpdateInternal(); + + ResetParentRows(); + + Set_ListManager(null, string.Empty, true); + } + finally + { + gridState[GRIDSTATE_exceptionInPaint] = false; + if (Visible) + EndUpdateInternal(); + } + } + } + + protected override void OnResize(EventArgs e) + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: OnResize"); + + if (layout.CaptionVisible) + Invalidate(layout.Caption); + if (layout.ParentRowsVisible) + parentRows.OnResize(layout.ParentRows); + + int borderWidth = BorderWidth; + Rectangle right; + Rectangle bottom; + Rectangle oldClientRectangle = layout.ClientRectangle; + + right = new Rectangle(oldClientRectangle.X + oldClientRectangle.Width - borderWidth, + oldClientRectangle.Y, + borderWidth, + oldClientRectangle.Height); + bottom = new Rectangle(oldClientRectangle.X, + oldClientRectangle.Y + oldClientRectangle.Height - borderWidth, + oldClientRectangle.Width, + borderWidth); + + Rectangle newClientRectangle = ClientRectangle; + if (newClientRectangle.Width != oldClientRectangle.Width) + { + Invalidate(right); + right = new Rectangle(newClientRectangle.X + newClientRectangle.Width - borderWidth, + newClientRectangle.Y, + borderWidth, + newClientRectangle.Height); + Invalidate(right); + } + + if (newClientRectangle.Height != oldClientRectangle.Height) + { + Invalidate(bottom); + bottom = new Rectangle(newClientRectangle.X, + newClientRectangle.Y + newClientRectangle.Height - borderWidth, + newClientRectangle.Width, + borderWidth); + Invalidate(bottom); + } + + // also, invalidate the ResizeBoxRect + if (!layout.ResizeBoxRect.IsEmpty) + Invalidate(layout.ResizeBoxRect); + + layout.ClientRectangle = newClientRectangle; + + int oldFirstVisibleRow = firstVisibleRow; + base.OnResize(e); + if (isRightToLeft() || oldFirstVisibleRow != firstVisibleRow) + Invalidate(); + } + + internal void OnRowHeightChanged(DataGridRow row) + { + ClearRegionCache(); + int cy = GetRowTop(row.RowNumber); + if (cy > 0) + { + Rectangle refresh = new Rectangle + { + Y = cy, + X = layout.Inside.X, + Width = layout.Inside.Width, + Height = layout.Inside.Bottom - cy + }; + Invalidate(refresh); + } + } + + internal void ParentRowsDataChanged() + { + Debug.Assert(originalState is not null, "how can we get a list changed event from another listmanager/list while not navigating"); + + // do the reset work that is done in SetDataBindings, set_DataSource, set_DataMember; + parentRows.Clear(); + caption.BackButtonActive = caption.DownButtonActive = caption.BackButtonVisible = false; + caption.SetDownButtonDirection(!layout.ParentRowsVisible); + object dSource = originalState.DataSource; + string dMember = originalState.DataMember; + // we don't need to set the GRIDSTATE_metaDataChanged bit, cause + // the listManager from the originalState should be different from the current listManager + // set the originalState to null so that Set_ListManager knows that + // it has to unhook the MetaDataChanged events + originalState = null; + Set_ListManager(dSource, dMember, true); + } + + private void AbortEdit() + { + Debug.WriteLineIf(CompModSwitches.DataGridEditing.TraceVerbose, "DataGridEditing: \t! AbortEdit"); + Debug.Assert(gridState[GRIDSTATE_isEditing], "Can't abort an edit that is not happening!"); + + // the same rules from editColumn.OnEdit + // while changing the editControl's visibility, do not + // PerformLayout on the entire DataGrid + gridState[GRIDSTATE_editControlChanging] = true; + + editColumn.Abort(editRow.RowNumber); + + // reset the editControl flag: + gridState[GRIDSTATE_editControlChanging] = false; + + gridState[GRIDSTATE_isEditing] = false; + editRow = null; + editColumn = null; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event NavigateEventHandler Navigate + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected event EventHandler RowHeaderClick + { + add + { + onRowHeaderClick += value; + } + remove + { + onRowHeaderClick -= value; + } + } + + internal event EventHandler NodeClick + { + add + { + Events.AddHandler(EVENT_NODECLICKED, value); + } + remove + { + Events.RemoveHandler(EVENT_NODECLICKED, value); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Scroll + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override ISite Site + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal void AddNewRow() + { + EnsureBound(); + ResetSelection(); + // EndEdit(); + UpdateListManager(); + gridState[GRIDSTATE_inListAddNew] = true; + gridState[GRIDSTATE_inAddNewRow] = true; + try + { + ListManager.AddNew(); + } + catch + { + gridState[GRIDSTATE_inListAddNew] = false; + gridState[GRIDSTATE_inAddNewRow] = false; + PerformLayout(); + InvalidateInside(); + throw; + } + + gridState[GRIDSTATE_inListAddNew] = false; + } + + public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) + { + throw new PlatformNotSupportedException(); + } + + public void BeginInit() + { + throw new PlatformNotSupportedException(); + } + + private Rectangle CalcRowResizeFeedbackRect(MouseEventArgs e) + { + Rectangle inside = layout.Data; + Rectangle r = new Rectangle(inside.X, e.Y, inside.Width, 3); + r.Y = Math.Min(inside.Bottom - 3, r.Y); + r.Y = Math.Max(r.Y, 0); + return r; + } + + private Rectangle CalcColResizeFeedbackRect(MouseEventArgs e) + { + Rectangle inside = layout.Data; + Rectangle r = new Rectangle(e.X, inside.Y, 3, inside.Height); + r.X = Math.Min(inside.Right - 3, r.X); + r.X = Math.Max(r.X, 0); + return r; + } + + private void CancelCursorUpdate() + { + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: Requesting CancelEdit()"); + if (listManager is not null) + { + EndEdit(); + listManager.CancelCurrentEdit(); + } + } + + private void CheckHierarchyState() + { + if (checkHierarchy && listManager is not null && myGridTable is not null) + { + if (myGridTable is null) + return; + + for (int j = 0; j < myGridTable.GridColumnStyles.Count; j++) + { + DataGridColumnStyle gridColumn = myGridTable.GridColumnStyles[j]; + } + + checkHierarchy = false; + } + } + + /// + /// The DataGrid caches an array of rectangular areas + /// which represent the area which scrolls left to right. + /// This method is invoked whenever the DataGrid's + /// scrollable regions change in such a way as to require + /// a re-recalculation. + /// + private void ClearRegionCache() + { + cachedScrollableRegion = null; + } + + /// + /// Determines the best fit size for the given column. + /// + private void ColAutoResize(int col) + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ColAutoResize"); + EndEdit(); + CurrencyManager listManager = this.listManager; + if (listManager is null) + return; + + int size; + Graphics g = CreateGraphicsInternal(); + try + { + DataGridColumnStyle column = myGridTable.GridColumnStyles[col]; + string columnName = column.HeaderText; + + Font headerFont; + if (myGridTable.IsDefault) + headerFont = HeaderFont; + else + headerFont = myGridTable.HeaderFont; + size = (int)g.MeasureString(columnName, headerFont).Width + layout.ColumnHeaders.Height + 1; // This is not a bug, the sort triangle's width is equal to it's height. + int rowCount = listManager.Count; + for (int row = 0; row < rowCount; ++row) + { + object value = column.GetColumnValueAtRow(listManager, row); + int width = 0; + if (width > size) + size = width; + } + + if (column.Width != size) + { + column.width = size; + + ComputeVisibleColumns(); + + bool lastColumnIsLastTotallyVisibleCol = true; + if (lastTotallyVisibleCol != -1) + { + for (int i = lastTotallyVisibleCol + 1; i < myGridTable.GridColumnStyles.Count; i++) + { + if (myGridTable.GridColumnStyles[i].PropertyDescriptor is not null) + { + lastColumnIsLastTotallyVisibleCol = false; + break; + } + } + } + else + { + lastColumnIsLastTotallyVisibleCol = false; + } + + // if the column shrank and the last totally visible column was the last column + // then we need to recompute the horizontalOffset, firstVisibleCol, negOffset. + // lastTotallyVisibleCol remains the last column + if (lastColumnIsLastTotallyVisibleCol && + (negOffset != 0 || horizontalOffset != 0)) + { + // update the column width + column.width = size; + + int cx = 0; + int colCount = myGridTable.GridColumnStyles.Count; + int visibleWidth = layout.Data.Width; + GridColumnStylesCollection cols = myGridTable.GridColumnStyles; + + // assume everything fits + negOffset = 0; + horizontalOffset = 0; + firstVisibleCol = 0; + + for (int i = colCount - 1; i >= 0; i--) + { + if (cols[i].PropertyDescriptor is null) + { + continue; + } + + cx += cols[i].Width; + if (cx > visibleWidth) + { + if (negOffset == 0) + { + firstVisibleCol = i; + negOffset = cx - visibleWidth; + horizontalOffset = negOffset; + numVisibleCols++; + } + else + { + horizontalOffset += cols[i].Width; + } + } + else + { + numVisibleCols++; + } + } + + // refresh the horizontal scrollbar + PerformLayout(); + + // we need to invalidate the layout.Data and layout.ColumnHeaders + Invalidate(Rectangle.Union(layout.Data, layout.ColumnHeaders)); + } + else + { + // need to refresh the scroll bar + PerformLayout(); + + Rectangle rightArea = layout.Data; + if (layout.ColumnHeadersVisible) + rightArea = Rectangle.Union(rightArea, layout.ColumnHeaders); + + int left = GetColBeg(col); + + if (!isRightToLeft()) + { + rightArea.Width -= left - rightArea.X; + rightArea.X = left; + } + else + { + rightArea.Width = rightArea.Width - left; + } + + Invalidate(rightArea); + } + } + } + finally + { + g.Dispose(); + } + + if (horizScrollBar.Visible) + { + horizScrollBar.Value = HorizontalOffset; + } + } + + public void Collapse(int row) + { + throw new PlatformNotSupportedException(); + } + + private void ColResizeBegin(MouseEventArgs e, int col) + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ColResizeBegin"); + Debug.Assert(myGridTable is not null, "Column resizing operations can't be called when myGridTable is null."); + + int x = e.X; + EndEdit(); + Rectangle clip = Rectangle.Union(layout.ColumnHeaders, layout.Data); + if (isRightToLeft()) + { + clip.Width = GetColBeg(col) - layout.Data.X - 2; + } + else + { + int leftEdge = GetColBeg(col); + clip.X = leftEdge + 3; + clip.Width = layout.Data.X + layout.Data.Width - leftEdge - 2; + } + + gridState[GRIDSTATE_trackColResize] = true; + trackColAnchor = x; + trackColumn = col; + + DrawColSplitBar(e); + lastSplitBar = e; + } + + private void ColResizeMove(MouseEventArgs e) + { + if (lastSplitBar is not null) + { + DrawColSplitBar(lastSplitBar); + lastSplitBar = e; + } + + DrawColSplitBar(e); + } + + private void ColResizeEnd(MouseEventArgs e) + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ColResizeEnd"); + Debug.Assert(myGridTable is not null, "Column resizing operations can't be called when myGridTable is null."); + + gridState[GRIDSTATE_layoutSuspended] = true; + try + { + if (lastSplitBar is not null) + { + DrawColSplitBar(lastSplitBar); + lastSplitBar = null; + } + + bool rightToLeft = isRightToLeft(); + + int x = rightToLeft ? Math.Max(e.X, layout.Data.X) : Math.Min(e.X, layout.Data.Right + 1); + int delta = x - GetColEnd(trackColumn); + if (rightToLeft) + delta = -delta; + + if (trackColAnchor != x && delta != 0) + { + DataGridColumnStyle column = myGridTable.GridColumnStyles[trackColumn]; + int proposed = column.Width + delta; + proposed = Math.Max(proposed, 3); + column.Width = proposed; + + // refresh scrolling data: horizontalOffset, negOffset, firstVisibleCol, numVisibleCols, lastTotallyVisibleCol + ComputeVisibleColumns(); + + bool lastColumnIsLastTotallyVisibleCol = true; + for (int i = lastTotallyVisibleCol + 1; i < myGridTable.GridColumnStyles.Count; i++) + { + if (myGridTable.GridColumnStyles[i].PropertyDescriptor is not null) + { + lastColumnIsLastTotallyVisibleCol = false; + break; + } + } + + if (lastColumnIsLastTotallyVisibleCol && + (negOffset != 0 || horizontalOffset != 0)) + { + int cx = 0; + int colCount = myGridTable.GridColumnStyles.Count; + int visibleWidth = layout.Data.Width; + GridColumnStylesCollection cols = myGridTable.GridColumnStyles; + + // assume everything fits + negOffset = 0; + horizontalOffset = 0; + firstVisibleCol = 0; + + for (int i = colCount - 1; i > -1; i--) + { + if (cols[i].PropertyDescriptor is null) + { + continue; + } + + cx += cols[i].Width; + + if (cx > visibleWidth) + { + if (negOffset == 0) + { + negOffset = cx - visibleWidth; + firstVisibleCol = i; + horizontalOffset = negOffset; + numVisibleCols++; + } + else + { + horizontalOffset += cols[i].Width; + } + } + else + { + numVisibleCols++; + } + } + + // and invalidate pretty much everything + Invalidate(Rectangle.Union(layout.Data, layout.ColumnHeaders)); + } + else + { + Rectangle rightArea = Rectangle.Union(layout.ColumnHeaders, layout.Data); + int left = GetColBeg(trackColumn); + rightArea.Width -= rightToLeft ? rightArea.Right - left : left - rightArea.X; + rightArea.X = rightToLeft ? layout.Data.X : left; + Invalidate(rightArea); + } + } + } + finally + { + gridState[GRIDSTATE_layoutSuspended] = false; + } + + PerformLayout(); + + if (horizScrollBar.Visible) + { + horizScrollBar.Value = HorizontalOffset; + } + } + + private void MetaDataChanged() + { + // when we reset the Binding in the grid, we need to clear the parent rows. + // the same goes for all the caption UI: reset it when the datasource changes. + parentRows.Clear(); + caption.BackButtonActive = caption.DownButtonActive = caption.BackButtonVisible = false; + caption.SetDownButtonDirection(!layout.ParentRowsVisible); + + gridState[GRIDSTATE_metaDataChanged] = true; + try + { + if (originalState is not null) + { + // set the originalState to null so that Set_ListManager knows that + // it has to unhook the MetaDataChanged events + Set_ListManager(originalState.DataSource, originalState.DataMember, true); + originalState = null; + } + else + { + Set_ListManager(DataSource, DataMember, true); + } + } + finally + { + gridState[GRIDSTATE_metaDataChanged] = false; + } + } + + private void RowAutoResize(int row) + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: RowAutoResize"); + + EndEdit(); + CurrencyManager listManager = ListManager; + if (listManager is null) + return; + + Graphics g = CreateGraphicsInternal(); + try + { + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + DataGridRow resizeRow = DataGridRows[row]; + int rowCount = listManager.Count; + int resizeHeight = 0; + + // compute the height that we should resize to: + int columnsCount = columns.Count; + for (int col = 0; col < columnsCount; col++) + { + object value = columns[col].GetColumnValueAtRow(listManager, row); + resizeHeight = 0; + } + + if (resizeRow.Height != resizeHeight) + { + resizeRow.Height = resizeHeight; + + // needed to refresh scrollbar properties + PerformLayout(); + + Rectangle rightArea = layout.Data; + if (layout.RowHeadersVisible) + rightArea = Rectangle.Union(rightArea, layout.RowHeaders); + int top = GetRowTop(row); + rightArea.Height -= rightArea.Y - top; + rightArea.Y = top; + Invalidate(rightArea); + } + } + finally + { + g.Dispose(); + } + + return; + } + + private void RowResizeBegin(MouseEventArgs e, int row) + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: RowResizeBegin"); + Debug.Assert(myGridTable is not null, "Row resizing operations can't be called when myGridTable is null."); + + int y = e.Y; + EndEdit(); + Rectangle clip = Rectangle.Union(layout.RowHeaders, layout.Data); + int topEdge = GetRowTop(row); + clip.Y = topEdge + 3; + clip.Height = layout.Data.Y + layout.Data.Height - topEdge - 2; + + gridState[GRIDSTATE_trackRowResize] = true; + trackRowAnchor = y; + trackRow = row; + + DrawRowSplitBar(e); + lastSplitBar = e; + } + + private void RowResizeMove(MouseEventArgs e) + { + if (lastSplitBar is not null) + { + DrawRowSplitBar(lastSplitBar); + lastSplitBar = e; + } + + DrawRowSplitBar(e); + } + + private void RowResizeEnd(MouseEventArgs e) + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: RowResizeEnd"); + Debug.Assert(myGridTable is not null, "Row resizing operations can't be called when myGridTable is null."); + + try + { + if (lastSplitBar is not null) + { + DrawRowSplitBar(lastSplitBar); + lastSplitBar = null; + } + + int y = Math.Min(e.Y, layout.Data.Y + layout.Data.Height + 1); + int delta = y - GetRowBottom(trackRow); + if (trackRowAnchor != y && delta != 0) + { + DataGridRow row = DataGridRows[trackRow]; + int proposed = row.Height + delta; + proposed = Math.Max(proposed, 3); + row.Height = proposed; + + // needed to refresh scrollbar properties + PerformLayout(); + + Rectangle rightArea = Rectangle.Union(layout.RowHeaders, layout.Data); + int top = GetRowTop(trackRow); + rightArea.Height -= rightArea.Y - top; + rightArea.Y = top; + Invalidate(rightArea); + } + } + finally + { + } + } + + /// + /// Fires the ColumnHeaderClicked event and handles column + /// sorting. + /// + private void ColumnHeaderClicked(PropertyDescriptor prop) + { + if (!CommitEdit()) + return; + + // OnColumnHeaderClick(EventArgs.Empty); + bool allowSorting; + if (myGridTable.IsDefault) + allowSorting = AllowSorting; + else + allowSorting = myGridTable.AllowSorting; + + if (!allowSorting) + return; + + // if (CompModSwitches.DataGridCursor.OutputVerbose) Debug.WriteLine("DataGridCursor: We are about to sort column " + col.ToString()); + ListSortDirection direction = ListManager.GetSortDirection(); + PropertyDescriptor sortColumn = ListManager.GetSortProperty(); + if (sortColumn is not null && sortColumn.Equals(prop)) + direction = (direction == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending; + else + // defaultSortDirection : ascending + direction = ListSortDirection.Ascending; + + if (listManager.Count == 0) + return; + + ListManager.SetSort(prop, direction); + ResetSelection(); + + InvalidateInside(); + } + + /// + /// Attempts to commit editing if a cell is being edited. + /// Return true if successfully commited editing. + /// Return false if editing can not be completed and the gird must + /// remain in our current Edit state. + /// + private bool CommitEdit() + { + Debug.WriteLineIf(CompModSwitches.DataGridEditing.TraceVerbose, "DataGridEditing: \t CommitEdit " + (editRow is null ? "" : editRow.RowNumber.ToString(CultureInfo.InvariantCulture))); + // we want to commit the editing if + // 1. the user was editing or navigating around the data grid and + // 2. this is not the result of moving focus inside the data grid and + // 3. if the user was scrolling + if ((!gridState[GRIDSTATE_isEditing] && !gridState[GRIDSTATE_isNavigating]) || (gridState[GRIDSTATE_editControlChanging] && !gridState[GRIDSTATE_isScrolling])) + return true; + + // the same rules from editColumn.OnEdit + // flag that we are editing the Edit control, so if we get a OnLayout on the + // datagrid side of things while the edit control changes its visibility and bounds + // the datagrid does not perform a layout + gridState[GRIDSTATE_editControlChanging] = true; + + if (editColumn.ReadOnly || gridState[GRIDSTATE_inAddNewRow]) + { + bool focusTheGrid = false; + if (ContainsFocus) + { + focusTheGrid = true; + } + + if (focusTheGrid && gridState[GRIDSTATE_canFocus]) + FocusInternal(); + editColumn.ConcedeFocus(); + + // set the focus back to the grid + if (focusTheGrid && gridState[GRIDSTATE_canFocus] && CanFocus && !Focused) + FocusInternal(); + + // reset the editControl flag + gridState[GRIDSTATE_editControlChanging] = false; + return true; + } + + bool retVal = editColumn.Commit(ListManager, currentRow); + + // reset the editControl flag + gridState[GRIDSTATE_editControlChanging] = false; + + if (retVal) + gridState[GRIDSTATE_isEditing] = false; + + return retVal; + } + + /// + /// Figure out how many rows we need to scroll down + /// to move targetRow into visibility. + /// + private int ComputeDeltaRows(int targetRow) + { + if (firstVisibleRow == targetRow) + return 0; + + int dRows = 0; + int firstVisibleRowLogicalTop = -1; + int targetRowLogicalTop = -1; + int nRows = DataGridRowsLength; + int cy = 0; + DataGridRow[] localGridRows = DataGridRows; + + for (int row = 0; row < nRows; ++row) + { + if (row == firstVisibleRow) + firstVisibleRowLogicalTop = cy; + if (row == targetRow) + targetRowLogicalTop = cy; + if (targetRowLogicalTop != -1 && firstVisibleRowLogicalTop != -1) + break; + cy += localGridRows[row].Height; + } + + int targetRowLogicalBottom = targetRowLogicalTop + localGridRows[targetRow].Height; + int dataLogicalBottom = layout.Data.Height + firstVisibleRowLogicalTop; + if (targetRowLogicalBottom > dataLogicalBottom) + { + // we need to move down. + int downDelta = targetRowLogicalBottom - dataLogicalBottom; + firstVisibleRowLogicalTop += downDelta; + } + else if (firstVisibleRowLogicalTop < targetRowLogicalTop) + { + // we don't need to move + return 0; + } + else + { + // we need to move up. + int upDelta = firstVisibleRowLogicalTop - targetRowLogicalTop; + firstVisibleRowLogicalTop -= upDelta; + } + + int newFirstRow = ComputeFirstVisibleRow(firstVisibleRowLogicalTop); + dRows = (newFirstRow - firstVisibleRow); + return dRows; + } + + /// + /// Given the a logical vertical offset, figure out + /// which row number should be the first fully visible + /// row on or after the offset. + /// + private int ComputeFirstVisibleRow(int firstVisibleRowLogicalTop) + { + int first; + int nRows = DataGridRowsLength; + int cy = 0; + DataGridRow[] localGridRows = DataGridRows; + for (first = 0; first < nRows; ++first) + { + if (cy >= firstVisibleRowLogicalTop) + break; + cy += localGridRows[first].Height; + } + + return first; + } + + /// + /// Constructs an updated Layout object. + /// + private void ComputeLayout() + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ComputeLayout"); + + bool alignLeft = !isRightToLeft(); + Rectangle oldResizeRect = layout.ResizeBoxRect; + + // hide the EditBox + EndEdit(); + + ClearRegionCache(); + + // NOTE : Since Rectangles are structs, then assignment is a + // : copy. Therefore, after saying "Rectangle inside = newLayout.Inside", + // : we must always assign back to newLayout.Inside. + // + + // Important since all of the visibility flags will move + // to the new layout here. + LayoutData newLayout = new LayoutData(layout); + + // Inside + newLayout.Inside = ClientRectangle; + Rectangle inside = newLayout.Inside; + int borderWidth = BorderWidth; + inside.Inflate(-borderWidth, -borderWidth); + + Rectangle insideLeft = inside; + + // Caption + if (layout.CaptionVisible) + { + int captionHeight = captionFontHeight + 6; + Rectangle cap = newLayout.Caption; + cap = insideLeft; + cap.Height = captionHeight; + insideLeft.Y += captionHeight; + insideLeft.Height -= captionHeight; + + newLayout.Caption = cap; + } + else + { + newLayout.Caption = Rectangle.Empty; + } + + // Parent Rows + if (layout.ParentRowsVisible) + { + Rectangle parents = newLayout.ParentRows; + int parentHeight = parentRows.Height; + parents = insideLeft; + parents.Height = parentHeight; + insideLeft.Y += parentHeight; + insideLeft.Height -= parentHeight; + + newLayout.ParentRows = parents; + } + else + { + newLayout.ParentRows = Rectangle.Empty; + } + + // Headers + // + int columnHeaderHeight = headerFontHeight + 6; + if (layout.ColumnHeadersVisible) + { + Rectangle colHeaders = newLayout.ColumnHeaders; + colHeaders = insideLeft; + colHeaders.Height = columnHeaderHeight; + insideLeft.Y += columnHeaderHeight; + insideLeft.Height -= columnHeaderHeight; + + newLayout.ColumnHeaders = colHeaders; + } + else + { + newLayout.ColumnHeaders = Rectangle.Empty; + } + + bool newRowHeadersVisible = myGridTable.IsDefault ? RowHeadersVisible : myGridTable.RowHeadersVisible; + int newRowHeaderWidth = myGridTable.IsDefault ? RowHeaderWidth : myGridTable.RowHeaderWidth; + newLayout.RowHeadersVisible = newRowHeadersVisible; + if (myGridTable is not null && newRowHeadersVisible) + { + Rectangle rowHeaders = newLayout.RowHeaders; + if (alignLeft) + { + rowHeaders = insideLeft; + rowHeaders.Width = newRowHeaderWidth; + insideLeft.X += newRowHeaderWidth; + insideLeft.Width -= newRowHeaderWidth; + } + else + { + rowHeaders = insideLeft; + rowHeaders.Width = newRowHeaderWidth; + rowHeaders.X = insideLeft.Right - newRowHeaderWidth; + insideLeft.Width -= newRowHeaderWidth; + } + + newLayout.RowHeaders = rowHeaders; + + if (layout.ColumnHeadersVisible) + { + Rectangle topLeft = newLayout.TopLeftHeader; + Rectangle colHeaders = newLayout.ColumnHeaders; + if (alignLeft) + { + topLeft = colHeaders; + topLeft.Width = newRowHeaderWidth; + colHeaders.Width -= newRowHeaderWidth; + colHeaders.X += newRowHeaderWidth; + } + else + { + topLeft = colHeaders; + topLeft.Width = newRowHeaderWidth; + topLeft.X = colHeaders.Right - newRowHeaderWidth; + colHeaders.Width -= newRowHeaderWidth; + } + + newLayout.TopLeftHeader = topLeft; + newLayout.ColumnHeaders = colHeaders; + } + else + { + newLayout.TopLeftHeader = Rectangle.Empty; + } + } + else + { + newLayout.RowHeaders = Rectangle.Empty; + newLayout.TopLeftHeader = Rectangle.Empty; + } + + // The Data region + newLayout.Data = insideLeft; + newLayout.Inside = inside; + + layout = newLayout; + + LayoutScrollBars(); + + // if the user shrank the grid client area, then OnResize invalidated the old + // resize area. however, we need to invalidate the left upper corner in the new ResizeArea + // note that we can't take the Invalidate call from the OnResize method, because if the + // user enlarges the form then the old area will not be invalidated. + if (!oldResizeRect.Equals(layout.ResizeBoxRect) && !layout.ResizeBoxRect.IsEmpty) + Invalidate(layout.ResizeBoxRect); + + layout.dirty = false; + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: " + layout.ToString()); + } + + /// + /// Computes the number of pixels to scroll to scroll from one + /// row to another. + /// + private int ComputeRowDelta(int from, int to) + { + int first = from; + int last = to; + int sign = -1; + if (first > last) + { + first = to; + last = from; + sign = 1; + } + + DataGridRow[] localGridRows = DataGridRows; + int delta = 0; + for (int row = first; row < last; ++row) + { + delta += localGridRows[row].Height; + } + + return sign * delta; + } + + internal int MinimumRowHeaderWidth() + { + return minRowHeaderWidth; + } + + internal void ComputeMinimumRowHeaderWidth() + { + minRowHeaderWidth = errorRowBitmapWidth; // the size of the pencil, star and row selector images are the same as the image for the error bitmap + if (ListHasErrors) + minRowHeaderWidth += errorRowBitmapWidth; + if (myGridTable is not null && myGridTable.RelationsList.Count != 0) + minRowHeaderWidth += 15; // the size of the plus/minus glyph and spacing around it + } + + /// + /// + /// Updates the internal variables with the number of columns visible + /// inside the Grid's client rectangle. + /// + private void ComputeVisibleColumns() + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ComputeVisibleColumns"); + EnsureBound(); + + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + + int nGridCols = columns.Count; + int cx = -negOffset; + int visibleColumns = 0; + int visibleWidth = layout.Data.Width; + int curCol = firstVisibleCol; + + // the same problem with negative numbers: + // if the width passed in is negative, then return 0 + // + // added the check for the columns.Count == 0 ( danielhe, November 14, 2000) + // + if (visibleWidth < 0 || columns.Count == 0) + { + numVisibleCols = firstVisibleCol = 0; + lastTotallyVisibleCol = -1; + return; + } + + while (cx < visibleWidth && curCol < nGridCols) + { + // if (columns.Visible && columns.PropertyDescriptor is not null) + if (columns[curCol].PropertyDescriptor is not null) + cx += columns[curCol].Width; + curCol++; + visibleColumns++; + } + + numVisibleCols = visibleColumns; + + // if we inflate the data area + // then we paint columns to the left of firstVisibleColumn + if (cx < visibleWidth) + { + for (int i = firstVisibleCol - 1; i > 0; i--) + { + if (cx + columns[i].Width > visibleWidth) + break; + // if (columns.Visible && columns.PropertyDescriptor is not null) + if (columns[i].PropertyDescriptor is not null) + cx += columns[i].Width; + visibleColumns++; + firstVisibleCol--; + } + + if (numVisibleCols != visibleColumns) + { + Debug.Assert(numVisibleCols < visibleColumns, "the number of visible columns can only grow"); + // is there space for more columns than were visible? + // if so, then we need to repaint Data and ColumnHeaders + Invalidate(layout.Data); + Invalidate(layout.ColumnHeaders); + + // update the number of visible columns to the new reality + numVisibleCols = visibleColumns; + } + } + + lastTotallyVisibleCol = firstVisibleCol + numVisibleCols - 1; + if (cx > visibleWidth) + { + if (numVisibleCols <= 1 || (numVisibleCols == 2 && negOffset != 0)) + { + // no column is entirely visible + lastTotallyVisibleCol = -1; + } + else + { + lastTotallyVisibleCol--; + } + } + } + + /// + /// Determines which column is the first visible given + /// the object's horizontalOffset. + /// + private int ComputeFirstVisibleColumn() + { + int first = 0; + if (horizontalOffset == 0) + { + negOffset = 0; + return 0; + } + + // we will check to see if myGridTables.GridColumns.Count != 0 + // because when we reset the dataGridTable, we don't have any columns, and we still + // call HorizontalOffset = 0, and that will call ComputeFirstVisibleColumn with an empty collection of columns. + if (myGridTable is not null && myGridTable.GridColumnStyles is not null && myGridTable.GridColumnStyles.Count != 0) + { + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + int cx = 0; + int nGridCols = columns.Count; + + if (columns[0].Width == -1) + { + // the columns are not initialized yet + // +#if DEBUG + for (int i = 0; i < nGridCols; i++) + { + Debug.Assert(columns[i].Width == -1, "the columns' widths should not be initialized"); + } +#endif // DEBUG + negOffset = 0; + return 0; + } + + for (first = 0; first < nGridCols; first++) + { + // if (columns[first].Visible && columns[first].PropertyDescriptor is not null); + if (columns[first].PropertyDescriptor is not null) + cx += columns[first].Width; + if (cx > horizontalOffset) + break; + } + + // first may actually be the number of columns + // in that case all the columns fit in the layout data + if (first == nGridCols) + { + Debug.Assert(cx <= horizontalOffset, "look at the for loop before: we only exit that loop early if the cx is over the horizontal offset"); + negOffset = 0; + return 0; + } + + negOffset = columns[first].Width - (cx - horizontalOffset); + // Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: ComputeFirstVisibleColumn, ret = " + first.ToString() + ", negOffset = " + negOffset.ToString()); + } + + return first; + } + + /// + /// Updates the internal variables with the number of rows visible + /// in a given DataGrid Layout. + /// + private void ComputeVisibleRows() + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ComputeVisibleRows"); + EnsureBound(); + + Rectangle data = layout.Data; + int visibleHeight = data.Height; + int cy = 0; + int visibleRows = 0; + DataGridRow[] localGridRows = DataGridRows; + int numRows = DataGridRowsLength; + + // when minimizing the dataGrid window, we will get negative values for the + // layout.Data.Width and layout.Data.Height ( is this a bug or not? if layout.Data.Height == 0 in that case, + // the old code would have worked ) + // + // if this is the case, then set numVisibleRows = numTotallyVisibleRows = 0; + // + if (visibleHeight < 0) + { + numVisibleRows = numTotallyVisibleRows = 0; + return; + } + + for (int i = firstVisibleRow; i < numRows; ++i) + { + if (cy > visibleHeight) + break; + cy += localGridRows[i].Height; + visibleRows++; + } + + if (cy < visibleHeight) + { + for (int i = firstVisibleRow - 1; i >= 0; i--) + { + int height = localGridRows[i].Height; + if (cy + height > visibleHeight) + break; + cy += height; + firstVisibleRow--; + visibleRows++; + } + } + + numVisibleRows = numTotallyVisibleRows = visibleRows; + if (cy > visibleHeight) + numTotallyVisibleRows--; + + Debug.Assert(numVisibleRows >= 0, "the number of visible rows can't be negative"); + Debug.Assert(numTotallyVisibleRows >= 0, "the number of totally visible rows can't be negative"); + } + + protected override AccessibleObject CreateAccessibilityInstance() + { + return new DataGridAccessibleObject(this); + } + + private DataGridState CreateChildState(string relationName, DataGridRow source) + { + DataGridState dgs = new DataGridState(); + + string newDataMember; + if (string.IsNullOrEmpty(DataMember)) + { + newDataMember = relationName; + } + else + { + newDataMember = DataMember + "." + relationName; + } + + CurrencyManager childLM = (CurrencyManager)BindingContext[DataSource, newDataMember]; + + dgs.DataSource = DataSource; + dgs.DataMember = newDataMember; + dgs.ListManager = childLM; + + dgs.DataGridRows = null; + dgs.DataGridRowsLength = childLM.Count + (policy.AllowAdd ? 1 : 0); + + return dgs; + } + + /// + /// Constructs a Layout object containing the state + /// for a newly constructed DataGrid. + /// + private LayoutData CreateInitialLayoutState() + { + Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: CreateInitialLayoutState"); + LayoutData newLayout = new LayoutData(); + newLayout.Inside = default; + newLayout.TopLeftHeader = default; + newLayout.ColumnHeaders = default; + newLayout.RowHeaders = default; + newLayout.Data = default; + newLayout.Caption = default; + newLayout.ParentRows = default; + newLayout.ResizeBoxRect = default; + newLayout.ColumnHeadersVisible = true; + newLayout.RowHeadersVisible = true; + newLayout.CaptionVisible = defaultCaptionVisible; + newLayout.ParentRowsVisible = defaultParentRowsVisible; + newLayout.ClientRectangle = ClientRectangle; + return newLayout; + } + + /// + /// The DataGrid caches an array of rectangular areas + /// which represent the area which scrolls left to right. + /// This method is invoked whenever the DataGrid needs + /// this scrollable region. + /// + private RECT[] CreateScrollableRegion(Rectangle scroll) + { + if (cachedScrollableRegion is not null) + { + return cachedScrollableRegion; + } + + bool alignToRight = isRightToLeft(); + + using (Region region = new Region(scroll)) + { + int nRows = numVisibleRows; + int cy = layout.Data.Y; + int cx = layout.Data.X; + DataGridRow[] localGridRows = DataGridRows; + for (int r = firstVisibleRow; r < nRows; r++) + { + int rowHeight = localGridRows[r].Height; + Rectangle rowExclude = localGridRows[r].GetNonScrollableArea(); + rowExclude.X += cx; + rowExclude.X = MirrorRectangle(rowExclude, layout.Data, alignToRight); + if (!rowExclude.IsEmpty) + { + region.Exclude(new Rectangle(rowExclude.X, + rowExclude.Y + cy, + rowExclude.Width, + rowExclude.Height)); + } + + cy += rowHeight; + } + } + + return cachedScrollableRegion; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (vertScrollBar is not null) + vertScrollBar.Dispose(); + if (horizScrollBar is not null) + horizScrollBar.Dispose(); + + if (toBeDisposedEditingControl is not null) + { + toBeDisposedEditingControl.Dispose(); + toBeDisposedEditingControl = null; + } + + GridTableStylesCollection tables = TableStyles; + if (tables is not null) + { +#if DEBUG + Debug.Assert(myGridTable is null || myGridTable.IsDefault || tables.Contains(myGridTable), "how come that the currentTable is not in the list of tables?"); +#endif // DEBUG + for (int i = 0; i < tables.Count; i++) + tables[i].Dispose(); + } + } + + base.Dispose(disposing); + } + + /// + /// Draws an XOR region to give UI feedback for Column Resizing. + /// This looks just like the Splitter control's UI when resizing. + /// + private void DrawColSplitBar(MouseEventArgs e) + { + Rectangle r = CalcColResizeFeedbackRect(e); + DrawSplitBar(r); + } + + /// + /// Draws an XOR region to give UI feedback for Row Resizing. + /// This looks just like the Splitter control's UI when resizing. + /// + private void DrawRowSplitBar(MouseEventArgs e) + { + Rectangle r = CalcRowResizeFeedbackRect(e); + DrawSplitBar(r); + } + + /// + /// Draws an XOR region to give UI feedback for Column/Row Resizing. + /// This looks just like the Splitter control's UI when resizing. + /// + private void DrawSplitBar(Rectangle r) + { + IntPtr parentHandle = Handle; + } + + /// + /// Begin in-place editing of a cell. Any editing is commited + /// before the new edit takes place. + /// + /// This will always edit the currentCell + /// If you want to edit another cell than the current one, just reset CurrentCell + /// + private void Edit() + { + Edit(null); + } + + private void Edit(string displayText) + { + EnsureBound(); + + // whoever needs to call ResetSelection should not rely on + // Edit() to call it; + // + // ResetSelection(); + + EndEdit(); + + Debug.WriteLineIf(CompModSwitches.DataGridEditing.TraceVerbose, "DataGridEditing: Edit, currentRow = " + currentRow.ToString(CultureInfo.InvariantCulture) + + ", currentCol = " + currentCol.ToString(CultureInfo.InvariantCulture) + (displayText is not null ? ", displayText= " + displayText : "")); + + /* allow navigation even if the policy does not allow editing + if (!policy.AllowEdit) + return; + */ + + DataGridRow[] localGridRows = DataGridRows; + + // what do you want to edit when there are no rows? + if (DataGridRowsLength == 0) + return; + + localGridRows[currentRow].OnEdit(); + editRow = localGridRows[currentRow]; + + // if the list has no columns, then what good is an edit? + if (myGridTable.GridColumnStyles.Count == 0) + return; + + // what if the currentCol does not have a propDesc? + editColumn = myGridTable.GridColumnStyles[currentCol]; + if (editColumn.PropertyDescriptor is null) + return; + + Rectangle cellBounds = Rectangle.Empty; + if (currentRow < firstVisibleRow || currentRow > firstVisibleRow + numVisibleRows || + currentCol < firstVisibleCol || currentCol > firstVisibleCol + numVisibleCols - 1 || + (currentCol == firstVisibleCol && negOffset != 0)) + { + } + else + { + cellBounds = GetCellBounds(currentRow, currentCol); + } + + gridState[GRIDSTATE_isNavigating] = true; + gridState[GRIDSTATE_isEditing] = false; + + // once we call editColumn.Edit on a DataGridTextBoxColumn + // the edit control will become visible, and its bounds will get set. + // both actions cause Edit.Parent.OnLayout + // so we flag this change, cause we don't want to PerformLayout on the entire DataGrid + // everytime the edit column gets edited + gridState[GRIDSTATE_editControlChanging] = true; + + // reset the editControlChanging to false + gridState[GRIDSTATE_editControlChanging] = false; + } + + public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Ends any editing in progress by attempting to commit and then + /// aborting if not possible. + /// + private void EndEdit() + { + Debug.WriteLineIf(CompModSwitches.DataGridEditing.TraceVerbose, "DataGridEditing: EndEdit"); + + if (!gridState[GRIDSTATE_isEditing] && !gridState[GRIDSTATE_isNavigating]) + return; + + if (!CommitEdit()) + { + AbortEdit(); + } + } + + // PERF: we attempt to create a ListManager for the DataSource/DateMember combination + // we do this in order to check for a valid DataMember + // if the check succeeds, then it means that we actully put the listManager in the BindingContext's + // list of BindingManagers. this is fine, cause if the check succeds, then Set_ListManager + // will be called, and this will get the listManager from the bindingManagerBase hashTable kept in the BindingContext + // + // this will work if the dataMember does not contain any dots ('.') + // if the dataMember contains dots, then it will be more complicated: maybe part of the binding path + // is valid w/ the new dataSource + // but we can leave w/ this, cause in the designer the dataMember will be only a column name. and the DataSource/DataMember + // properties are for use w/ the designer. + // + private void EnforceValidDataMember(object value) + { + Debug.Assert(value is not null, "we should not have a null dataSource when we want to check for a valid dataMember"); + if (DataMember is null || DataMember.Length == 0) + return; + if (BindingContext is null) + return; + // + try + { + BindingManagerBase bm = BindingContext[value, dataMember]; + } + catch + { + dataMember = ""; + } + } + + internal protected virtual void ColumnStartedEditing(Rectangle bounds) + { + Debug.Assert(currentRow >= firstVisibleRow && currentRow <= firstVisibleRow + numVisibleRows, "how can one edit a row which is invisible?"); + DataGridRow[] localGridRows = DataGridRows; + + if (bounds.IsEmpty && editColumn is DataGridTextBoxColumn && currentRow != -1 && currentCol != -1) + { + // set the bounds on the control + // this will only work w/ our DataGridTexBox control + DataGridTextBoxColumn col = editColumn as DataGridTextBoxColumn; + Rectangle editBounds = GetCellBounds(currentRow, currentCol); + + gridState[GRIDSTATE_editControlChanging] = true; + try + { + col.TextBox.Bounds = editBounds; + } + finally + { + gridState[GRIDSTATE_editControlChanging] = false; + } + } + + if (gridState[GRIDSTATE_inAddNewRow]) + { + int currentRowCount = DataGridRowsLength; + DataGridRow[] newDataGridRows = new DataGridRow[currentRowCount + 1]; + for (int i = 0; i < currentRowCount; i++) + { + newDataGridRows[i] = localGridRows[i]; + } + + // put the AddNewRow + newDataGridRows[currentRowCount] = new DataGridAddNewRow(this, myGridTable, currentRowCount); + SetDataGridRows(newDataGridRows, currentRowCount + 1); + + Edit(); + // put this after the call to edit so that + // CommitEdit knows that the inAddNewRow is true; + gridState[GRIDSTATE_inAddNewRow] = false; + gridState[GRIDSTATE_isEditing] = true; + gridState[GRIDSTATE_isNavigating] = false; + return; + } + + gridState[GRIDSTATE_isEditing] = true; + gridState[GRIDSTATE_isNavigating] = false; + InvalidateRowHeader(currentRow); + + // tell the current row to lose the childFocuse + localGridRows[currentRow].LoseChildFocus(layout.RowHeaders, isRightToLeft()); + } + + internal protected virtual void ColumnStartedEditing(Control editingControl) + { + ColumnStartedEditing(editingControl.Bounds); + } + + public void Expand(int row) + { + throw new PlatformNotSupportedException(); + } + + protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop, bool isDefault) + { + return myGridTable is null ? null : myGridTable.CreateGridColumn(prop, isDefault); + } + + protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop) + { + return myGridTable is null ? null : myGridTable.CreateGridColumn(prop); + } + +#if PARENT_LINKS + + private ListManager ListManagerForChildColumn(ListManager childListManager, PropertyDescriptor prop) + { + /* + DataKey key; + RelationsCollection relCollection = dataColumn.Table.ParentRelations; + */ + + // this will give us the list of properties of the child + PropertyDescriptorCollection propCollection = childListManager.GetItemProperties(); + + int relCount = propCollection.Count; + for (int i=0;i + /// Given a x coordinate, returns the column it is over. + /// + private int GetColFromX(int x) + { + if (myGridTable is null) + return -1; + + Rectangle inside = layout.Data; + Debug.Assert(x >= inside.X && x < inside.Right, "x must be inside the horizontal bounds of layout.Data"); + + x = MirrorPoint(x, inside, isRightToLeft()); + + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + int columnCount = columns.Count; + + int cx = inside.X - negOffset; + int col = firstVisibleCol; + while (cx < inside.Width + inside.X && col < columnCount) + { + // if (columns[col].Visible && columns[col].PropertyDescriptor is not null) + if (columns[col].PropertyDescriptor is not null) + cx += columns[col].Width; + if (cx > x) + return col; + ++col; + } + + return -1; + } + + /// + /// Returns the coordinate of the left edge of the given column + /// Bi-Di: if the grid has the RightToLeft property set to RightToLeft.Yes, this will + /// return what appears as the right edge of the column + /// + internal int GetColBeg(int col) + { + Debug.Assert(myGridTable is not null, "GetColBeg can't be called when myGridTable is null."); + + int offset = layout.Data.X - negOffset; + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + + int lastCol = Math.Min(col, columns.Count); + for (int i = firstVisibleCol; i < lastCol; ++i) + { + // if (columns[i].Visible && columns[i].PropertyDescriptor is not null) + if (columns[i].PropertyDescriptor is not null) + offset += columns[i].Width; + } + + return MirrorPoint(offset, layout.Data, isRightToLeft()); + } + + /// + /// Returns the coordinate of the right edge of the given column + /// Bi-Di: if the grid has the RightToLeft property set to RightToLeft.Yes, this will + /// return what appears as the left edge of the column + /// + internal int GetColEnd(int col) + { + int colBeg = GetColBeg(col); + Debug.Assert(myGridTable.GridColumnStyles[col].PropertyDescriptor is not null, "why would we need the coordinate of a column that is not visible?"); + int width = myGridTable.GridColumnStyles[col].Width; + return isRightToLeft() ? colBeg - width : colBeg + width; + } + + private int GetColumnWidthSum() + { + int sum = 0; + if (myGridTable is not null && myGridTable.GridColumnStyles is not null) + { + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + + int columnsCount = columns.Count; + for (int i = 0; i < columnsCount; i++) + if (columns[i].PropertyDescriptor is not null) + sum += columns[i].Width; + } + + return sum; + } + + /// + /// Not all rows in the DataGrid are expandable, + /// this computes which ones are and returns an array + /// of references to them. + /// + private DataGridRelationshipRow[] GetExpandableRows() + { + int nExpandableRows = DataGridRowsLength; + DataGridRow[] localGridRows = DataGridRows; + if (policy.AllowAdd) + nExpandableRows = Math.Max(nExpandableRows - 1, 0); + DataGridRelationshipRow[] expandableRows = new DataGridRelationshipRow[nExpandableRows]; + for (int i = 0; i < nExpandableRows; i++) + expandableRows[i] = (DataGridRelationshipRow)localGridRows[i]; + return expandableRows; + } + + /// + /// Returns the row number underneath the given y coordinate. + /// + /// + private int GetRowFromY(int y) + { + Rectangle inside = layout.Data; + Debug.Assert(y >= inside.Y && y < inside.Bottom, "y must be inside the vertical bounds of the data"); + + int cy = inside.Y; + int row = firstVisibleRow; + int rowCount = DataGridRowsLength; + DataGridRow[] localGridRows = DataGridRows; + int bottom = inside.Bottom; + while (cy < bottom && row < rowCount) + { + cy += localGridRows[row].Height; + if (cy > y) + { + return row; + } + + ++row; + } + + return -1; + } + + internal Rectangle GetRowHeaderRect() + { + return layout.RowHeaders; + } + + internal Rectangle GetColumnHeadersRect() + { + return layout.ColumnHeaders; + } + + /// + /// Determines where on the control's ClientRectangle a given row is + /// painting to. + /// + private Rectangle GetRowRect(int rowNumber) + { + Rectangle inside = layout.Data; + int cy = inside.Y; + DataGridRow[] localGridRows = DataGridRows; + for (int row = firstVisibleRow; row <= rowNumber; ++row) + { + if (cy > inside.Bottom) + { + break; + } + + if (row == rowNumber) + { + Rectangle rowRect = new Rectangle(inside.X, + cy, + inside.Width, + localGridRows[row].Height); + if (layout.RowHeadersVisible) + { + rowRect.Width += layout.RowHeaders.Width; + rowRect.X -= isRightToLeft() ? 0 : layout.RowHeaders.Width; + } + + return rowRect; + } + + cy += localGridRows[row].Height; + } + + return Rectangle.Empty; + } + + /// + /// Returns the coordinate of the top edge of the given row + /// + private int GetRowTop(int row) + { + DataGridRow[] localGridRows = DataGridRows; + int offset = layout.Data.Y; + int lastRow = Math.Min(row, DataGridRowsLength); + for (int i = firstVisibleRow; i < lastRow; ++i) + { + offset += localGridRows[i].Height; + } + + for (int i = firstVisibleRow; i > lastRow; i--) + { + offset -= localGridRows[i].Height; + } + + return offset; + } + + /// + /// Returns the coordinate of the bottom edge of the given row + /// + private int GetRowBottom(int row) + { + DataGridRow[] localGridRows = DataGridRows; + + return GetRowTop(row) + localGridRows[row].Height; + } + + /// + /// This method is called on methods that need the grid + /// to be bound to a DataTable to work. + /// + private void EnsureBound() + { + if (!Bound) + { + throw new InvalidOperationException("SR.GetString(SR.DataGridUnbound)"); + } + } + + private void EnsureVisible(int row, int col) + { + if (row < firstVisibleRow + || row >= firstVisibleRow + numTotallyVisibleRows) + { + int dRows = ComputeDeltaRows(row); + ScrollDown(dRows); + } + + if (firstVisibleCol == 0 && numVisibleCols == 0 && lastTotallyVisibleCol == -1) + { + // no columns are displayed whatsoever + // some sanity checks + Debug.Assert(negOffset == 0, " no columns are displayed so the negative offset should be 0"); + return; + } + + int previousFirstVisibleCol = firstVisibleCol; + int previousNegOffset = negOffset; + int previousLastTotallyVisibleCol = lastTotallyVisibleCol; + + while (col < firstVisibleCol + || (col == firstVisibleCol && negOffset != 0) + || (lastTotallyVisibleCol == -1 && col > firstVisibleCol) + || (lastTotallyVisibleCol > -1 && col > lastTotallyVisibleCol)) + { + ScrollToColumn(col); + + if (previousFirstVisibleCol == firstVisibleCol && + previousNegOffset == negOffset && + previousLastTotallyVisibleCol == lastTotallyVisibleCol) + { + // nothing changed since the last iteration + // don't get into an infinite loop + break; + } + + previousFirstVisibleCol = firstVisibleCol; + previousNegOffset = negOffset; + previousLastTotallyVisibleCol = lastTotallyVisibleCol; + + // continue to scroll to the right until the scrollTo column is the totally last visible column or it is the first visible column + } + } + + public Rectangle GetCurrentCellBounds() + { + throw new PlatformNotSupportedException(); + } + + public Rectangle GetCellBounds(int row, int col) + { + throw new PlatformNotSupportedException(); + } + + public Rectangle GetCellBounds(DataGridCell dgc) + { + throw new PlatformNotSupportedException(); + } + + // UNDONE : ChrisAn, 10/27/00 - using internal hack to expose data for + // : Accessibility, is there a cleaner way to do this? + internal Rectangle GetRowBounds(DataGridRow row) + { + Rectangle rowBounds = default; + rowBounds.Y = GetRowTop(row.RowNumber); + rowBounds.X = layout.Data.X; + rowBounds.Height = row.Height; + rowBounds.Width = layout.Data.Width; + return rowBounds; + } + + public HitTestInfo HitTest(int x, int y) + { + throw new PlatformNotSupportedException(); + } + + public HitTestInfo HitTest(Point position) + { + throw new PlatformNotSupportedException(); + } + + /// + /// + /// Initializes the values for column widths in the table. + /// + private void InitializeColumnWidths() + { + if (myGridTable is null) + return; + + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + int numCols = columns.Count; + + // Resize the columns to a approximation of a best fit. + // We find the best fit width of NumRowsForAutoResize rows + // and use it for each column. + int preferredColumnWidth = this.myGridTable.IsDefault ? this.PreferredColumnWidth : this.myGridTable.PreferredColumnWidth; + // if we set the PreferredColumnWidth to something else than AutoColumnSize + // then use that value + // + for (int col = 0; col < numCols; col++) + { + // if the column width is not -1, then this column was initialized already + if (columns[col].width != -1) + continue; + + columns[col].width = preferredColumnWidth; + } + } + + /// + /// Invalidates the scrollable area of the DataGrid. + /// + internal void InvalidateInside() + { + Invalidate(layout.Inside); + } + + /// + /// Invalidates the caption area of the DataGrid. + /// + internal void InvalidateCaption() + { + if (layout.CaptionVisible) + Invalidate(layout.Caption); + } + + /// + /// Invalidates a rectangle normalized to the caption's + /// visual bounds. + /// + internal void InvalidateCaptionRect(Rectangle r) + { + if (layout.CaptionVisible) + { + Invalidate(r); + } + } + + /// + /// Invalidates the display region of a given DataGridColumn. + /// + internal void InvalidateColumn(int column) + { + GridColumnStylesCollection gridColumns = myGridTable.GridColumnStyles; + if (column < 0 || gridColumns is null || gridColumns.Count <= column) + return; + + Debug.Assert(gridColumns[column].PropertyDescriptor is not null, "how can we invalidate a column that is invisible?"); + // bail if the column is not visible. + if (column < firstVisibleCol || column > firstVisibleCol + numVisibleCols - 1) + return; + + Rectangle columnArea = default; + columnArea.Height = layout.Data.Height; + columnArea.Width = gridColumns[column].Width; + columnArea.Y = layout.Data.Y; + + int x = layout.Data.X - negOffset; + int gridColumnsCount = gridColumns.Count; + for (int i = firstVisibleCol; i < gridColumnsCount; ++i) + { + if (i == column) + break; + x += gridColumns[i].Width; + } + + columnArea.X = x; + columnArea.X = MirrorRectangle(columnArea, layout.Data, isRightToLeft()); + Invalidate(columnArea); + } + + /// + /// Invalidates the parent rows area of the DataGrid + /// + internal void InvalidateParentRows() + { + if (layout.ParentRowsVisible) + Invalidate(layout.ParentRows); + } + + /// + /// Invalidates a rectangle normalized to the parent + /// rows area's visual bounds. + /// + internal void InvalidateParentRowsRect(Rectangle r) + { + Rectangle parentRowsRect = layout.ParentRows; + Invalidate(r); + if (!parentRowsRect.IsEmpty) + { + // Invalidate(new Rectangle(parentRowsRect.X + r.X, parentRowsRect.Y + r.Y, + // r.Width, r.Height)); + } + } + + /// + /// Invalidate the painting region for the row specified. + /// + internal void InvalidateRow(int rowNumber) + { + Rectangle rowRect = GetRowRect(rowNumber); + if (!rowRect.IsEmpty) + { + Debug.WriteLineIf(CompModSwitches.DataGridPainting.TraceVerbose, "DataGridPainting: Invalidating row " + rowNumber.ToString(CultureInfo.InvariantCulture)); + Invalidate(rowRect); + } + } + + private void InvalidateRowHeader(int rowNumber) + { + if (rowNumber >= firstVisibleRow && rowNumber < firstVisibleRow + numVisibleRows) + { + if (!layout.RowHeadersVisible) + return; + + Rectangle invalid = default; + invalid.Y = GetRowTop(rowNumber); + invalid.X = layout.RowHeaders.X; + invalid.Width = layout.RowHeaders.Width; + invalid.Height = this.DataGridRows[rowNumber].Height; + Invalidate(invalid); + } + } + + // NOTE: + // because of Rtl, we assume that the only place that calls InvalidateRowRect is + // the DataGridRelationshipRow + internal void InvalidateRowRect(int rowNumber, Rectangle r) + { + Rectangle rowRect = GetRowRect(rowNumber); + if (!rowRect.IsEmpty) + { + Debug.WriteLineIf(CompModSwitches.DataGridPainting.TraceVerbose, "DataGridPainting: Invalidating a rect in row " + rowNumber.ToString(CultureInfo.InvariantCulture)); + Rectangle inner = new Rectangle(rowRect.X + r.X, rowRect.Y + r.Y, r.Width, r.Height); + if (vertScrollBar.Visible && isRightToLeft()) + inner.X -= vertScrollBar.Width; + Invalidate(inner); + } + } + + public bool IsExpanded(int rowNumber) + { + throw new PlatformNotSupportedException(); + } + + public bool IsSelected(int row) + { + throw new PlatformNotSupportedException(); + } + + internal static bool IsTransparentColor(Color color) + { + return color.A < 255; + } + + /// + /// Determines if Scrollbars should be visible, + /// updates their bounds and the bounds of all + /// other regions in the DataGrid's Layout. + /// + private void LayoutScrollBars() + { + // if we set the dataSource to null, then take away the scrollbars. + if (listManager is null || myGridTable is null) + { + horizScrollBar.Visible = false; + vertScrollBar.Visible = false; + return; + } + + // Scrollbars are a tricky issue. + // We need to see if we can cram our columns and rows + // in without scrollbars and if they don't fit, we make + // scrollbars visible and then fixup our regions for the + // data and headers. + bool needHorizScrollbar = false; + bool needVertScrollbar = false; + bool recountRows = false; + bool alignToRight = isRightToLeft(); + + int nGridCols = myGridTable.GridColumnStyles.Count; + + // if we call LayoutScrollBars before CreateDataGridRows + // then the columns will have their default width ( 100 ) + // CreateDataGridRows will possibly change the columns' width + // and anyway, ComputeVisibleRows will call the DataGridRows accessor + DataGridRow[] gridRows = this.DataGridRows; + + // at this stage, the data grid columns may have their width set to -1 ( ie, their width is uninitialized ) + // make sure that the totalWidth is at least 0 + int totalWidth = Math.Max(0, GetColumnWidthSum()); + + if (totalWidth > layout.Data.Width && !needHorizScrollbar) + { + int horizHeight = horizScrollBar.Height; + layout.Data.Height -= horizHeight; + if (layout.RowHeadersVisible) + layout.RowHeaders.Height -= horizHeight; + needHorizScrollbar = true; + } + + int oldFirstVisibleRow = firstVisibleRow; + + ComputeVisibleRows(); + if (numTotallyVisibleRows != DataGridRowsLength && !needVertScrollbar) + { + int vertWidth = vertScrollBar.Width; + layout.Data.Width -= vertWidth; + if (layout.ColumnHeadersVisible) + { + if (alignToRight) + layout.ColumnHeaders.X += vertWidth; + + layout.ColumnHeaders.Width -= vertWidth; + } + + needVertScrollbar = true; + } + + firstVisibleCol = ComputeFirstVisibleColumn(); + // we compute the number of visible columns only after we set up the vertical scroll bar. + ComputeVisibleColumns(); + + if (needVertScrollbar && totalWidth > layout.Data.Width && !needHorizScrollbar) + { + firstVisibleRow = oldFirstVisibleRow; + int horizHeight = horizScrollBar.Height; + layout.Data.Height -= horizHeight; + if (layout.RowHeadersVisible) + layout.RowHeaders.Height -= horizHeight; + needHorizScrollbar = true; + recountRows = true; + } + + if (recountRows) + { + ComputeVisibleRows(); + if (numTotallyVisibleRows != DataGridRowsLength && !needVertScrollbar) + { + int vertWidth = vertScrollBar.Width; + layout.Data.Width -= vertWidth; + if (layout.ColumnHeadersVisible) + { + if (alignToRight) + layout.ColumnHeaders.X += vertWidth; + + layout.ColumnHeaders.Width -= vertWidth; + } + + needVertScrollbar = true; + } + } + + layout.ResizeBoxRect = default; + if (needVertScrollbar && needHorizScrollbar) + { + Rectangle data = layout.Data; + layout.ResizeBoxRect = new Rectangle(alignToRight ? data.X : data.Right, + data.Bottom, + vertScrollBar.Width, + horizScrollBar.Height); + } + + if (needHorizScrollbar && nGridCols > 0) + { + // Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: foo"); + + int widthNotVisible = totalWidth - layout.Data.Width; + + horizScrollBar.Minimum = 0; + horizScrollBar.Maximum = totalWidth; + horizScrollBar.SmallChange = 1; + horizScrollBar.LargeChange = Math.Max(totalWidth - widthNotVisible, 0); + horizScrollBar.Enabled = Enabled; + horizScrollBar.RightToLeft = RightToLeft; + horizScrollBar.Bounds = new Rectangle(alignToRight ? layout.Inside.X + layout.ResizeBoxRect.Width : layout.Inside.X, + layout.Data.Bottom, + layout.Inside.Width - layout.ResizeBoxRect.Width, + horizScrollBar.Height); + horizScrollBar.Visible = true; + } + else + { + HorizontalOffset = 0; + horizScrollBar.Visible = false; + } + + if (needVertScrollbar) + { + int vertScrollBarTop = layout.Data.Y; + if (layout.ColumnHeadersVisible) + vertScrollBarTop = layout.ColumnHeaders.Y; + // if numTotallyVisibleRows == 0 ( the height of the row is bigger than the height of + // the grid ) then scroll in increments of 1. + vertScrollBar.LargeChange = numTotallyVisibleRows != 0 ? numTotallyVisibleRows : 1; + vertScrollBar.Bounds = new Rectangle(alignToRight ? layout.Data.X : layout.Data.Right, + vertScrollBarTop, + vertScrollBar.Width, + layout.Data.Height + layout.ColumnHeaders.Height); + vertScrollBar.Enabled = Enabled; + vertScrollBar.Visible = true; + if (alignToRight) + layout.Data.X += vertScrollBar.Width; + } + else + { + vertScrollBar.Visible = false; + } + } + + public void NavigateBack() + { + throw new PlatformNotSupportedException(); + } + + public void NavigateTo(int rowNumber, string relationName) + { + throw new PlatformNotSupportedException(); + } + + internal void NavigateTo(string relationName, DataGridRow source, bool fromRow) + { + // do not navigate if AllowNavigation is set to false + if (!AllowNavigation) + return; + // Commit the edit if possible + if (!CommitEdit()) + return; + + DataGridState childState; + try + { + childState = CreateChildState(relationName, source); + } + catch + { + // if we get an error when creating the RelatedCurrencyManager + // then navigateBack and ignore the exception. + NavigateBack(); + return; + } + + // call EndCurrentEdit before navigating. + // if we get an exception, we do not navigate. + try + { + listManager.EndCurrentEdit(); + } + catch + { + return; + } + + // Preserve our current state + // we need to do this after the EndCurrentEdit, otherwise the + // DataGridState will get the listChanged event from the EndCurrentEdit + DataGridState dgs = new DataGridState(this); + dgs.LinkingRow = source; + + // we need to update the Position in the ListManager + // ( the RelatedListManager uses only the position in the parentManager + // to create the childRows + // before the code was calling CurrentCell = this and such + // we should only call EndCurrentEdit ( which the code was doing anyway ) + // and then set the position in the listManager to the new row. + if (source.RowNumber != CurrentRow) + listManager.Position = source.RowNumber; + + // We save our state if the parent rows stack is empty. + if (parentRows.GetTopParent() is null) + { + originalState = dgs; + } + + parentRows.AddParent(dgs); + + NavigateTo(childState); + + if (fromRow) + { + // OnLinkClick(EventArgs.Empty); + } + } + + private void NavigateTo(DataGridState childState) + { + // we are navigating... better stop editing. + EndEdit(); + + // also, we are no longer in editOrNavigate mode either + gridState[GRIDSTATE_isNavigating] = false; + + // reset hot tracking + ResetMouseState(); + + // Retrieve the child state + childState.PullState(this, true); // true for creating columns when we navigate to child rows + + if (listManager.Position != currentRow) + { + currentRow = listManager.Position == -1 ? 0 : listManager.Position; + } + + if (parentRows.GetTopParent() is not null) + { + caption.BackButtonActive = AllowNavigation; + caption.BackButtonVisible = caption.BackButtonActive; + caption.DownButtonActive = true; + } + + HorizontalOffset = 0; + PerformLayout(); + Invalidate(); + } + + /// + /// Given a coordinate in the control this method returns + /// the equivalent point for a row. + /// + private Point NormalizeToRow(int x, int y, int row) + { + Debug.Assert(row >= firstVisibleRow && row < firstVisibleRow + numVisibleRows, + "Row " + row.ToString(CultureInfo.InvariantCulture) + "is not visible! firstVisibleRow = " + + firstVisibleRow.ToString(CultureInfo.InvariantCulture) + ", numVisibleRows = " + + numVisibleRows.ToString(CultureInfo.InvariantCulture)); + Point origin = new Point(0, layout.Data.Y); + + DataGridRow[] localGridRows = DataGridRows; + for (int r = firstVisibleRow; r < row; ++r) + { + origin.Y += localGridRows[r].Height; + } + + // when hittesting for the PlusMinus, the code in the DataGridRelationshipRow + // will use real X coordinate ( the one from layout.RowHeaders ) to paint the glyph + return new Point(x, y - origin.Y); + } + + internal void OnColumnCollectionChanged(object sender, CollectionChangeEventArgs e) + { + DataGridTableStyle table = (DataGridTableStyle)sender; + if (table.Equals(myGridTable)) + { + // if we changed the column collection, then we need to set the property + // descriptors in the column collection. + // unless the user set the propertyDescriptor in the columnCollection + if (!myGridTable.IsDefault) + { + // if the element in the collectionChangeEventArgs is not null + // and the action is refresh, then it means that the user + // set the propDesc. we do not want to override this. + if (e.Action != CollectionChangeAction.Refresh || e.Element is null) + PairTableStylesAndGridColumns(listManager, myGridTable, false); + } + + Invalidate(); + PerformLayout(); + } + } + + /// + /// Paints column headers. + /// + private void PaintColumnHeaders(Graphics g) + { + bool alignToLeft = isRightToLeft(); + Rectangle boundingRect = layout.ColumnHeaders; + if (!alignToLeft) + boundingRect.X -= negOffset; + boundingRect.Width += negOffset; + + int columnHeaderWidth = PaintColumnHeaderText(g, boundingRect); + + if (alignToLeft) + boundingRect.X = boundingRect.Right - columnHeaderWidth; + + boundingRect.Width = columnHeaderWidth; + if (!FlatMode) + { + ControlPaint.DrawBorder3D(g, boundingRect, Border3DStyle.RaisedInner); + boundingRect.Inflate(-1, -1); + // g.SetPen(OldSystemPens.Control); + // g.OldBrush = (OldSystemBrushes.Hollow); + boundingRect.Width--; + boundingRect.Height--; + g.DrawRectangle(SystemPens.Control, boundingRect); + } + } + + private int PaintColumnHeaderText(Graphics g, Rectangle boundingRect) + { + int cx = 0; + Rectangle textBounds = boundingRect; + GridColumnStylesCollection gridColumns = myGridTable.GridColumnStyles; + bool alignRight = isRightToLeft(); + + int nGridCols = gridColumns.Count; + // for sorting + PropertyDescriptor sortProperty = null; + sortProperty = ListManager.GetSortProperty(); + + // Now paint the column header text! + for (int col = firstVisibleCol; col < nGridCols; ++col) + { + if (gridColumns[col].PropertyDescriptor is null) + continue; + + if (cx > boundingRect.Width) + break; + + bool columnSorted = sortProperty is not null && sortProperty.Equals(gridColumns[col].PropertyDescriptor); + + if (alignRight) + { + textBounds.Width = gridColumns[col].Width - + (columnSorted ? textBounds.Height : 0); + textBounds.X = boundingRect.Right - cx - textBounds.Width; + } + else + { + textBounds.X = boundingRect.X + cx; + textBounds.Width = gridColumns[col].Width - + (columnSorted ? textBounds.Height : 0); + } + + // at the moment we paint some pixels twice. + // we should not call FilLRectangle, once the real GDI+ is there, we will have no need to do that + + // if the user set the HeaderBackBrush property on the + // dataGrid, then use that property + Brush headerBrush; + if (myGridTable.IsDefault) + headerBrush = HeaderBackBrush; + else + headerBrush = myGridTable.HeaderBackBrush; + + g.FillRectangle(headerBrush, textBounds); + // granted, the code would be a lot cleaner if we were using a "new Rectangle" + // but like this will be faster + if (alignRight) + { + textBounds.X -= 2; + textBounds.Y += 2; + } + else + { + textBounds.X += 2; + textBounds.Y += 2; + } + + StringFormat format = new StringFormat(); + + // the columnHeaderText alignment should be the same as + // the alignment in the column + // + HorizontalAlignment colAlignment = gridColumns[col].Alignment; + format.Alignment = colAlignment == HorizontalAlignment.Right ? StringAlignment.Far : + colAlignment == HorizontalAlignment.Center ? StringAlignment.Center : + StringAlignment.Near; + + // part 1, section 1: the column headers should not wrap + format.FormatFlags |= StringFormatFlags.NoWrap; + + if (alignRight) + { + format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; + format.Alignment = StringAlignment.Near; + } + + g.DrawString(gridColumns[col].HeaderText, + myGridTable.IsDefault ? HeaderFont : myGridTable.HeaderFont, + myGridTable.IsDefault ? HeaderForeBrush : myGridTable.HeaderForeBrush, + textBounds, + format); + format.Dispose(); + + if (alignRight) + { + textBounds.X += 2; + textBounds.Y -= 2; + } + else + { + textBounds.X -= 2; + textBounds.Y -= 2; + } + + if (columnSorted) + { + // CONSIDER: This triangle painting is pretty unclean + // perhaps this should be a bitmap? + Rectangle triBounds = new Rectangle(alignRight ? textBounds.X - textBounds.Height : textBounds.Right, + textBounds.Y, + textBounds.Height, + textBounds.Height); + + g.FillRectangle(headerBrush, triBounds); + int deflateValue = Math.Max(0, (textBounds.Height - 5) / 2); + triBounds.Inflate(-deflateValue, -deflateValue); + + Pen pen1 = new Pen(BackgroundBrush); + Pen pen2 = new Pen(myGridTable.BackBrush); + pen1.Dispose(); + pen2.Dispose(); + } + + int paintedWidth = textBounds.Width + (columnSorted ? textBounds.Height : 0); + + if (!FlatMode) + { + if (alignRight && columnSorted) + textBounds.X -= textBounds.Height; + textBounds.Width = paintedWidth; + + ControlPaint.DrawBorder3D(g, textBounds, Border3DStyle.RaisedInner); + } + + cx += paintedWidth; + } + + // paint the possible exposed portion to the right ( or left, as the case may be) + if (cx < boundingRect.Width) + { + textBounds = boundingRect; + + if (!alignRight) + textBounds.X += cx; + + textBounds.Width -= cx; + g.FillRectangle(backgroundBrush, textBounds); + } + + return cx; + } + + /// + /// Paints a border around the bouding rectangle given + /// + private void PaintBorder(Graphics g, Rectangle bounds) + { + if (BorderStyle == BorderStyle.None) + return; + if (BorderStyle == BorderStyle.Fixed3D) + { + Border3DStyle style = Border3DStyle.Sunken; + ControlPaint.DrawBorder3D(g, bounds, style); + } + else if (BorderStyle == BorderStyle.FixedSingle) + { + Brush br; + + if (myGridTable.IsDefault) + br = HeaderForeBrush; + else + br = myGridTable.HeaderForeBrush; + g.FillRectangle(br, bounds.X, bounds.Y, bounds.Width + 2, 2); + g.FillRectangle(br, bounds.Right - 2, bounds.Y, 2, bounds.Height + 2); + g.FillRectangle(br, bounds.X, bounds.Bottom - 2, bounds.Width + 2, 2); + g.FillRectangle(br, bounds.X, bounds.Y, 2, bounds.Height + 2); + } + else + { + Pen pen = SystemPens.WindowFrame; + bounds.Width--; + bounds.Height--; + g.DrawRectangle(pen, bounds); + } + } + + /// + /// Paints the grid in the bounding rectangle given. + /// This includes the column headers and each visible row. + /// + private void PaintGrid(Graphics g, Rectangle gridBounds) + { + Debug.WriteLineIf(CompModSwitches.DataGridPainting.TraceVerbose, "DataGridPainting: PaintGrid on " + gridBounds.ToString()); + + Rectangle rc = gridBounds; + + if (listManager is not null) + { + if (layout.ColumnHeadersVisible) + { + Region r = g.Clip; + g.SetClip(layout.ColumnHeaders); + PaintColumnHeaders(g); + g.Clip = r; + r.Dispose(); + int columnHeaderHeight = layout.ColumnHeaders.Height; + rc.Y += columnHeaderHeight; + rc.Height -= columnHeaderHeight; + } + + if (layout.TopLeftHeader.Width > 0) + { + if (myGridTable.IsDefault) + g.FillRectangle(HeaderBackBrush, layout.TopLeftHeader); + else + g.FillRectangle(myGridTable.HeaderBackBrush, layout.TopLeftHeader); + + if (!FlatMode) + { + ControlPaint.DrawBorder3D(g, layout.TopLeftHeader, Border3DStyle.RaisedInner); + } + } + + PaintRows(g, ref rc); + } + + // paint the possible exposed portion below + if (rc.Height > 0) + { + g.FillRectangle(backgroundBrush, rc); + } + } + + private void DeleteDataGridRows(int deletedRows) + { + if (deletedRows == 0) + return; + + int currentRowCount = DataGridRowsLength; + int newDataGridRowsLength = currentRowCount - deletedRows + (gridState[GRIDSTATE_inAddNewRow] ? 1 : 0); + DataGridRow[] newDataGridRows = new DataGridRow[newDataGridRowsLength]; + DataGridRow[] gridRows = DataGridRows; + + // the number of selected entries so far in the array + int selectedEntries = 0; + + for (int i = 0; i < currentRowCount; i++) + { + if (gridRows[i].Selected) + { + selectedEntries++; + } + else + { + newDataGridRows[i - selectedEntries] = gridRows[i]; + newDataGridRows[i - selectedEntries].number = i - selectedEntries; + } + } + + if (gridState[GRIDSTATE_inAddNewRow]) + { + newDataGridRows[currentRowCount - selectedEntries] = new DataGridAddNewRow(this, myGridTable, currentRowCount - selectedEntries); + gridState[GRIDSTATE_inAddNewRow] = false; + } + + Debug.Assert(selectedEntries == deletedRows, "all the rows that would have been deleted should have been selected: selectedGridEntries " + selectedEntries.ToString(CultureInfo.InvariantCulture) + " deletedRows " + deletedRows.ToString(CultureInfo.InvariantCulture)); + + SetDataGridRows(newDataGridRows, newDataGridRowsLength); + } + + /// + /// Paints the visible rows on the grid. + /// + private void PaintRows(Graphics g, ref Rectangle boundingRect) + { + int cy = 0; + bool alignRight = isRightToLeft(); + Rectangle rowBounds = boundingRect; + Rectangle dataBounds = Rectangle.Empty; + bool paintRowHeaders = layout.RowHeadersVisible; + Rectangle headerBounds = Rectangle.Empty; + + int numRows = DataGridRowsLength; + DataGridRow[] localGridRows = DataGridRows; + int numCols = myGridTable.GridColumnStyles.Count - firstVisibleCol; + + for (int row = firstVisibleRow; row < numRows; row++) + { + if (cy > boundingRect.Height) + break; + + rowBounds = boundingRect; + rowBounds.Height = localGridRows[row].Height; + rowBounds.Y = boundingRect.Y + cy; + + // will add some errors +#if false + if (forDebug == 0 || forDebug == 1) + { + object dRowView = listManager[row]; + DataRow dRow= ((DataRowView) dRowView).Row; + // dRow.RowError = "Error " + forDebug.ToString(); + dRow.SetColumnError(forDebug, "another error " + forDebug.ToString()); + + /* + if (localGridRows[row].DataRow is not null) + { + localGridRows[row].DataRow.RowError = "error " + forDebug.ToString(); + localGridRows[row].DataRow.SetColumnError(forDebug, "another error " + forDebug.ToString()); + } + */ + forDebug ++; + } +#endif // false + if (paintRowHeaders) + { + headerBounds = rowBounds; + headerBounds.Width = layout.RowHeaders.Width; + + if (alignRight) + { + headerBounds.X = rowBounds.Right - headerBounds.Width; + } + + if (g.IsVisible(headerBounds)) + { + localGridRows[row].PaintHeader(g, headerBounds, alignRight, gridState[GRIDSTATE_isEditing]); + g.ExcludeClip(headerBounds); + } + + if (!alignRight) + rowBounds.X += headerBounds.Width; + rowBounds.Width -= headerBounds.Width; + } + + if (g.IsVisible(rowBounds)) + { + dataBounds = rowBounds; + if (!alignRight) + dataBounds.X -= negOffset; + dataBounds.Width += negOffset; + + localGridRows[row].Paint(g, dataBounds, rowBounds, firstVisibleCol, numCols, alignRight); + } + + cy += rowBounds.Height; + } + + boundingRect.Y += cy; + boundingRect.Height -= cy; + } + + protected override bool ProcessDialogKey(Keys keyData) + { + Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: ProcessDialogKey " + TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(keyData)); + DataGridRow[] localGridRows = DataGridRows; + if (listManager is not null && DataGridRowsLength > 0 && localGridRows[currentRow].OnKeyPress(keyData)) + { + Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: Current Row ate the keystroke"); + return true; + } + + switch (keyData & Keys.KeyCode) + { + case Keys.Tab: + case Keys.Up: + case Keys.Down: + case Keys.Left: + case Keys.Right: + case Keys.Next: + case Keys.Prior: + case Keys.Enter: + case Keys.Escape: + case Keys.Oemplus: + case Keys.Add: + case Keys.OemMinus: + case Keys.Subtract: + case Keys.Space: + case Keys.Delete: + case Keys.A: + KeyEventArgs ke = new KeyEventArgs(keyData); + if (ProcessGridKey(ke)) + return true; + break; + + case Keys.C: + if ((keyData & Keys.Control) != 0 && (keyData & Keys.Alt) == 0) + { + // the user pressed Ctrl-C + if (!Bound) + break; + + // need to distinguish between selecting a set of rows, and + // selecting just one column. + if (numSelectedRows == 0) + { + // copy the data from one column only + if (currentRow < ListManager.Count) + { + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + if (currentCol >= 0 && currentCol < columns.Count) + { + DataGridColumnStyle column = columns[currentCol]; + string text = column.GetDisplayText(column.GetColumnValueAtRow(ListManager, currentRow)); + + // copy the data to the clipboard + Clipboard.SetDataObject(text); + return true; + } + } + } + else + { + // the user selected a set of rows to copy the data from + + int numRowsOutputted = 0; // the number of rows written to "text" + string text = ""; + + for (int i = 0; i < DataGridRowsLength; ++i) + { + if (localGridRows[i].Selected) + { + GridColumnStylesCollection columns = myGridTable.GridColumnStyles; + int numCols = columns.Count; + for (int j = 0; j < numCols; j++) + { + DataGridColumnStyle column = columns[j]; + text += column.GetDisplayText(column.GetColumnValueAtRow(ListManager, i)); + + // do not put the delimiter at the end of the last column + if (j < numCols - 1) + { + text += GetOutputTextDelimiter(); + } + } + + // put the hard enter "\r\n" only if this is not the last selected row + if (numRowsOutputted < numSelectedRows - 1) + { + text += "\r\n"; + } + + numRowsOutputted++; + } + } + + // copy the data to the clipboard + Clipboard.SetDataObject(text); + return true; + } + } + + break; + } + + return base.ProcessDialogKey(keyData); + } + + private void DeleteRows(DataGridRow[] localGridRows) + { + int rowsDeleted = 0; + + int currentRowsCount = listManager is null ? 0 : listManager.Count; + + if (Visible) + BeginUpdateInternal(); + try + { + if (ListManager is not null) + { + for (int i = 0; i < DataGridRowsLength; i++) + { + if (localGridRows[i].Selected) + { + if (localGridRows[i] is DataGridAddNewRow) + { + Debug.Assert(i == DataGridRowsLength - 1, "the location of addNewRow is " + i.ToString(CultureInfo.InvariantCulture) + " and there are " + DataGridRowsLength.ToString(CultureInfo.InvariantCulture) + " rows "); + localGridRows[i].Selected = false; + } + else + { + ListManager.RemoveAt(i - rowsDeleted); + rowsDeleted++; + } + } + } + } + } + catch + { + // if we got an exception from the back end + // when deleting the rows then we should reset + // our rows and re-throw the exception + RecreateDataGridRows(); + gridState[GRIDSTATE_inDeleteRow] = false; + if (Visible) + EndUpdateInternal(); + throw; + } + + // keep the copy of the old rows in place + // it may be the case that deleting one row could cause multiple rows to be deleted in the same list + if (listManager is not null && currentRowsCount == listManager.Count + rowsDeleted) + { + DeleteDataGridRows(rowsDeleted); + } + else + { + RecreateDataGridRows(); + } + + gridState[GRIDSTATE_inDeleteRow] = false; + if (Visible) + EndUpdateInternal(); + + if (listManager is not null && currentRowsCount != listManager.Count + rowsDeleted) + { + Invalidate(); + } + } + + // convention: + // if we return -1 it means that the user was going left and there were no visible columns to the left of the current one + // if we return cols.Count + 1 it means that the user was going right and there were no visible columns to the right of the currrent + private static int MoveLeftRight(GridColumnStylesCollection cols, int startCol, bool goRight) + { + int i; + if (goRight) + { + for (i = startCol + 1; i < cols.Count; i++) + { + // if (cols[i].Visible && cols[i].PropertyDescriptor is not null) + if (cols[i].PropertyDescriptor is not null) + return i; + } + + return i; + } + else + { + for (i = startCol - 1; i >= 0; i--) + { + // if (cols[i].Visible && cols[i].PropertyDescriptor is not null) + if (cols[i].PropertyDescriptor is not null) + return i; + } + + return i; + } + } + + protected bool ProcessGridKey(KeyEventArgs ke) + { + Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: ProcessGridKey " + TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(ke.KeyCode)); + if (listManager is null || myGridTable is null) + return false; + + DataGridRow[] localGridRows = DataGridRows; + KeyEventArgs biDiKe = ke; + // check for Bi-Di + if (isRightToLeft()) + { + switch (ke.KeyCode) + { + case Keys.Left: + biDiKe = new KeyEventArgs((Keys.Right | ke.Modifiers)); + break; + case Keys.Right: + biDiKe = new KeyEventArgs((Keys.Left | ke.Modifiers)); + break; + default: + break; + } + } + + GridColumnStylesCollection cols = myGridTable.GridColumnStyles; + int firstColumnMarkedVisible = 0; + int lastColumnMarkedVisible = cols.Count; + for (int i = 0; i < cols.Count; i++) + { + if (cols[i].PropertyDescriptor is not null) + { + firstColumnMarkedVisible = i; + break; + } + } + + for (int i = cols.Count - 1; i >= 0; i--) + { + if (cols[i].PropertyDescriptor is not null) + { + lastColumnMarkedVisible = i; + break; + } + } + + switch (biDiKe.KeyCode) + { + case Keys.Tab: + return ProcessTabKey(biDiKe.KeyData); + case Keys.Up: + gridState[GRIDSTATE_childLinkFocused] = false; + if (dataGridRowsLength == 0) + { + return true; + } + + if (biDiKe.Control && !biDiKe.Alt) + { + if (biDiKe.Shift) + { + DataGridRow[] gridRows = DataGridRows; + + int savedCurrentRow = currentRow; + CurrentRow = 0; + + ResetSelection(); + + for (int i = 0; i <= savedCurrentRow; i++) + gridRows[i].Selected = true; + numSelectedRows = savedCurrentRow + 1; + // hide the edit box + EndEdit(); + return true; + } + + // do not make the parentRowsVisible = false; + // ParentRowsVisible = false; + ResetSelection(); + CurrentRow = 0; + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + return true; + } + else if (biDiKe.Shift) + { + DataGridRow[] gridRows = DataGridRows; + // keep a continous selected region + if (gridRows[currentRow].Selected) + { + if (currentRow >= 1) + { + if (gridRows[currentRow - 1].Selected) + { + if (currentRow >= DataGridRowsLength - 1 || !gridRows[currentRow + 1].Selected) + { + numSelectedRows--; + gridRows[currentRow].Selected = false; + } + } + else + { + numSelectedRows += gridRows[currentRow - 1].Selected ? 0 : 1; + gridRows[currentRow - 1].Selected = true; + } + + CurrentRow--; + } + } + else + { + numSelectedRows++; + gridRows[currentRow].Selected = true; + if (currentRow >= 1) + { + numSelectedRows += gridRows[currentRow - 1].Selected ? 0 : 1; + gridRows[currentRow - 1].Selected = true; + CurrentRow--; + } + } + + // hide the edit box: + EndEdit(); + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + return true; + } + else if (biDiKe.Alt) + { + // will need to collapse all child table links + // -1 is for all rows, and false is for collapsing the rows + SetRowExpansionState(-1, false); + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + return true; + } + + ResetSelection(); + CurrentRow = CurrentRow - 1; + Edit(); + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + break; + case Keys.Down: + gridState[GRIDSTATE_childLinkFocused] = false; + if (dataGridRowsLength == 0) + { + return true; + } + + if (biDiKe.Control && !biDiKe.Alt) + { + if (biDiKe.Shift) + { + int savedCurrentRow = currentRow; + CurrentRow = Math.Max(0, DataGridRowsLength - (policy.AllowAdd ? 2 : 1)); + DataGridRow[] gridRows = DataGridRows; + + ResetSelection(); + + for (int i = savedCurrentRow; i <= currentRow; i++) + gridRows[i].Selected = true; + + numSelectedRows = currentRow - savedCurrentRow + 1; + // hide the edit box + EndEdit(); + return true; + } + + // do not make the parentRowsVisible = true; + // ParentRowsVisible = true; + ResetSelection(); + CurrentRow = Math.Max(0, DataGridRowsLength - (policy.AllowAdd ? 2 : 1)); + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + return true; + } + else if (biDiKe.Shift) + { + DataGridRow[] gridRows = DataGridRows; + + // keep a continous selected region + if (gridRows[currentRow].Selected) + { + // -1 because we index from 0 + if (currentRow < DataGridRowsLength - (policy.AllowAdd ? 1 : 0) - 1) + { + if (gridRows[currentRow + 1].Selected) + { + if (currentRow == 0 || !gridRows[currentRow - 1].Selected) + { + numSelectedRows--; + gridRows[currentRow].Selected = false; + } + } + else + { + numSelectedRows += gridRows[currentRow + 1].Selected ? 0 : 1; + gridRows[currentRow + 1].Selected = true; + } + + CurrentRow++; + } + } + else + { + numSelectedRows++; + gridRows[currentRow].Selected = true; + // -1 because we index from 0, and -1 so this is not the last row + // so it adds to -2 + if (currentRow < DataGridRowsLength - (policy.AllowAdd ? 1 : 0) - 1) + { + CurrentRow++; + numSelectedRows += gridRows[currentRow].Selected ? 0 : 1; + gridRows[currentRow].Selected = true; + } + } + + // hide the edit box: + // + EndEdit(); + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + return true; + } + else if (biDiKe.Alt) + { + // will need to expande all child table links + // -1 is for all rows, and true is for expanding the rows + SetRowExpansionState(-1, true); + return true; + } + + ResetSelection(); + Edit(); + CurrentRow = CurrentRow + 1; + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + break; + case Keys.OemMinus: + case Keys.Subtract: + gridState[GRIDSTATE_childLinkFocused] = false; + if (biDiKe.Control && !biDiKe.Alt) + { + SetRowExpansionState(-1, false); + return true; + } + + return false; + case Keys.Oemplus: + case Keys.Add: + gridState[GRIDSTATE_childLinkFocused] = false; + if (biDiKe.Control) + { + SetRowExpansionState(-1, true); + // hide the edit box + EndEdit(); + return true; + } + + return false; + case Keys.Space: + gridState[GRIDSTATE_childLinkFocused] = false; + if (dataGridRowsLength == 0) + { + return true; + } + + if (biDiKe.Shift) + { + ResetSelection(); + EndEdit(); + DataGridRow[] gridRows = DataGridRows; + gridRows[currentRow].Selected = true; + numSelectedRows = 1; + + return true; + } + + return false; + case Keys.Next: + gridState[GRIDSTATE_childLinkFocused] = false; + if (dataGridRowsLength == 0) + { + return true; + } + + if (biDiKe.Shift) + { + int savedCurrentRow = currentRow; + CurrentRow = Math.Min(DataGridRowsLength - (policy.AllowAdd ? 2 : 1), currentRow + numTotallyVisibleRows); + + DataGridRow[] gridRows = DataGridRows; + for (int i = savedCurrentRow; i <= currentRow; i++) + { + if (!gridRows[i].Selected) + { + gridRows[i].Selected = true; + numSelectedRows++; + } + } + + EndEdit(); + } + else if (biDiKe.Control && !biDiKe.Alt) + { + // map ctrl-pageDown to show the parentRows + ParentRowsVisible = true; + } + else + { + ResetSelection(); + CurrentRow = Math.Min(DataGridRowsLength - (policy.AllowAdd ? 2 : 1), + CurrentRow + numTotallyVisibleRows); + } + + break; + case Keys.Prior: + if (dataGridRowsLength == 0) + { + return true; + } + + gridState[GRIDSTATE_childLinkFocused] = false; + if (biDiKe.Shift) + { + int savedCurrentRow = currentRow; + CurrentRow = Math.Max(0, CurrentRow - numTotallyVisibleRows); + + DataGridRow[] gridRows = DataGridRows; + for (int i = savedCurrentRow; i >= currentRow; i--) + { + if (!gridRows[i].Selected) + { + gridRows[i].Selected = true; + numSelectedRows++; + } + } + + EndEdit(); + } + else if (biDiKe.Control && !biDiKe.Alt) + { + // map ctrl-pageUp to hide the parentRows + ParentRowsVisible = false; + } + else + { + ResetSelection(); + CurrentRow = Math.Max(0, + CurrentRow - numTotallyVisibleRows); + } + + break; + case Keys.Left: + gridState[GRIDSTATE_childLinkFocused] = false; + ResetSelection(); + if ((biDiKe.Modifiers & Keys.Modifiers) == Keys.Alt) + { + if (Caption.BackButtonVisible) + NavigateBack(); + return true; + } + + if ((biDiKe.Modifiers & Keys.Control) == Keys.Control) + { + // we should navigate to the first visible column + CurrentColumn = firstColumnMarkedVisible; + break; + } + + if (currentCol == firstColumnMarkedVisible && currentRow != 0) + { + CurrentRow = CurrentRow - 1; + int newCol = MoveLeftRight(myGridTable.GridColumnStyles, myGridTable.GridColumnStyles.Count, false); + Debug.Assert(newCol != -1, "there should be at least a visible column, right?"); + CurrentColumn = newCol; + } + else + { + int newCol = MoveLeftRight(myGridTable.GridColumnStyles, currentCol, false); + if (newCol == -1) + { + if (currentRow == 0) + return true; + else + { + // go to the previous row: + CurrentRow = CurrentRow - 1; + CurrentColumn = lastColumnMarkedVisible; + } + } + else + { + CurrentColumn = newCol; + } + } + + break; + case Keys.Right: + gridState[GRIDSTATE_childLinkFocused] = false; + ResetSelection(); + if ((biDiKe.Modifiers & Keys.Control) == Keys.Control && !biDiKe.Alt) + { + // we should navigate to the last column that is marked as Visible + CurrentColumn = lastColumnMarkedVisible; + break; + } + + if (currentCol == lastColumnMarkedVisible && currentRow != DataGridRowsLength - 1) + { + CurrentRow = CurrentRow + 1; + // navigate to the first visible column + CurrentColumn = firstColumnMarkedVisible; + } + else + { + int newCol = MoveLeftRight(myGridTable.GridColumnStyles, currentCol, true); + if (newCol == cols.Count + 1) + { + // navigate to the first visible column + // and the next row + CurrentColumn = firstColumnMarkedVisible; + CurrentRow++; + } + else + CurrentColumn = newCol; + } + + break; + case Keys.F2: + gridState[GRIDSTATE_childLinkFocused] = false; + ResetSelection(); + Edit(); + break; +#if DEBUG + case Keys.F12: + gridState[GRIDSTATE_childLinkFocused] = false; + AddNewRow(); + break; +#endif + case Keys.Home: + gridState[GRIDSTATE_childLinkFocused] = false; + if (dataGridRowsLength == 0) + { + return true; + } + + ResetSelection(); + CurrentColumn = 0; + if (biDiKe.Control && !biDiKe.Alt) + { + int currentRowSaved = currentRow; + CurrentRow = 0; + + if (biDiKe.Shift) + { + // Ctrl-Shift-Home will select all the rows up to the first one + DataGridRow[] gridRows = DataGridRows; + for (int i = 0; i <= currentRowSaved; i++) + { + gridRows[i].Selected = true; + numSelectedRows++; + } + + EndEdit(); + } + + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + return true; + } + + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + break; + case Keys.Delete: + gridState[GRIDSTATE_childLinkFocused] = false; + if (policy.AllowRemove && numSelectedRows > 0) + { +#if DEBUG + // when the list is empty, then the position + // in the listManager is -1, and the currentPosition in the grid is 0 + if (ListManager is not null && ListManager.Count > 0) + { + Debug.Assert(ListManager.Position == currentRow, + "Current row out of sync with DataSource", + "The DataSource's Position property should be mirrored by the CurrentCell.RowNumber of the DataGrid."); + } +#endif // DEBUG + + gridState[GRIDSTATE_inDeleteRow] = true; + DeleteRows(localGridRows); + // set the currentRow to the position in the list + currentRow = listManager.Count == 0 ? 0 : listManager.Position; + numSelectedRows = 0; + } + else + { + // if we did not use the the Delete key, let the dataGridTextBox use it + return false; + } + + break; + case Keys.End: + gridState[GRIDSTATE_childLinkFocused] = false; + if (dataGridRowsLength == 0) + { + return true; + } + + ResetSelection(); + // go the the last visible column + CurrentColumn = lastColumnMarkedVisible; + + if (biDiKe.Control && !biDiKe.Alt) + { + int savedCurrentRow = currentRow; + CurrentRow = Math.Max(0, DataGridRowsLength - (policy.AllowAdd ? 2 : 1)); + + if (biDiKe.Shift) + { + // Ctrl-Shift-Home will select all the rows up to the first one + DataGridRow[] gridRows = DataGridRows; + for (int i = savedCurrentRow; i <= currentRow; i++) + { + gridRows[i].Selected = true; + } + + numSelectedRows = currentRow - savedCurrentRow + 1; + // hide the edit box + // + EndEdit(); + } + + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + return true; + } + + Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); + break; + case Keys.Enter: + gridState[GRIDSTATE_childLinkFocused] = false; + ResetSelection(); + + // yield the return key if there is no editing + if (!gridState[GRIDSTATE_isEditing]) + return false; + + // Ctrl-Enter will call EndCurrentEdit + if ((biDiKe.Modifiers & Keys.Control) != 0 && !biDiKe.Alt) + { + EndEdit(); + HandleEndCurrentEdit(); + Edit(); // put the edit box on the screen + } + else + { + // Do not commit the edit, cause reseting the + // current cell will do that + // CommitEdit(); + + CurrentRow = currentRow + 1; + } + + break; + case Keys.A: + gridState[GRIDSTATE_childLinkFocused] = false; + if (biDiKe.Control && !biDiKe.Alt) + { + DataGridRow[] gridRows = DataGridRows; + for (int i = 0; i < DataGridRowsLength; i++) + if (gridRows[i] is DataGridRelationshipRow) + gridRows[i].Selected = true; + + numSelectedRows = DataGridRowsLength - (policy.AllowAdd ? 1 : 0); + // hide the edit box + EndEdit(); + return true; + } + + return false; + case Keys.Escape: + gridState[GRIDSTATE_childLinkFocused] = false; + ResetSelection(); + if (gridState[GRIDSTATE_isEditing]) + { + // rollback + AbortEdit(); + + // we have to invalidate the row header ( make it display the row selector instead of the pencil ) + if (layout.RowHeadersVisible && currentRow > -1) + { + Rectangle rowHdrRect = GetRowRect(currentRow); + rowHdrRect.Width = layout.RowHeaders.Width; + Invalidate(rowHdrRect); + } + + // now put the edit column back on the screen + Edit(); + } + else + { + // add this protected virtual method for the XML designer team + CancelEditing(); + Edit(); + return false; + } + + break; + } + + return true; + } + + protected override bool ProcessKeyPreview(ref Message m) + { + if (m.Msg == PInvoke.WM_KEYDOWN) + { + KeyEventArgs ke = new KeyEventArgs((Keys)(unchecked((int)(long)m.WParam)) | ModifierKeys); + switch (ke.KeyCode) + { + case Keys.Up: + case Keys.Down: + case Keys.Prior: + case Keys.Next: + case Keys.Right: + case Keys.Left: + case Keys.Tab: + case Keys.Escape: + case Keys.Enter: + case Keys.OemMinus: + case Keys.Subtract: + case Keys.Oemplus: + case Keys.Add: + case Keys.Space: + case Keys.Home: + case Keys.End: + case Keys.F2: + case Keys.Delete: + case Keys.A: + return ProcessGridKey(ke); + } + } + else if (m.Msg == PInvoke.WM_KEYUP) + { + KeyEventArgs ke = new KeyEventArgs((Keys)(unchecked((int)(long)m.WParam)) | ModifierKeys); + if (ke.KeyCode == Keys.Tab) + return ProcessGridKey(ke); + } + + return base.ProcessKeyPreview(ref m); + } + + protected bool ProcessTabKey(Keys keyData) + { + if (listManager is null || myGridTable is null) + return false; + bool wasEditing = false; + int columnCount = myGridTable.GridColumnStyles.Count; + bool biDi = isRightToLeft(); + ResetSelection(); + + // Try to commit changes to cell if we were editing + if (gridState[GRIDSTATE_isEditing]) + { + wasEditing = true; + if (!CommitEdit()) + { + Edit(); // if we can't commit the value put the edit box so that the user sees where the focus is + return true; + } + } + + if ((keyData & Keys.Control) == Keys.Control) + { + // when the user hits ctrl-alt-tab just ignore it. + if ((keyData & Keys.Alt) == Keys.Alt) + return true; + + // navigate to the next control in the form + Keys ke = keyData & ~(Keys.Control); + EndEdit(); + + gridState[GRIDSTATE_editControlChanging] = true; + try + { + FocusInternal(); + } + finally + { + gridState[GRIDSTATE_editControlChanging] = false; + } + + bool ret = false; + + return ret; + } + + // see if the child relationships can use this TAB key + DataGridRow[] localRows = DataGridRows; + GridColumnStylesCollection cols = myGridTable.GridColumnStyles; + + int lastColumnMarkedVisible = 0; + int firstColumnMarkedVisible = cols.Count - 1; + // bug 70492: if we do not have any rows, then tab should move focus to the next control + if (localRows.Length == 0) + { + EndEdit(); + + bool ret = false; + ret = base.ProcessDialogKey(keyData); + + return ret; + } + + for (int i = 0; i < cols.Count; i++) + { + // if (cols[i].Visible && cols[i].PropertyDescriptor is not null) { + if (cols[i].PropertyDescriptor is not null) + { + firstColumnMarkedVisible = i; + break; + } + } + + for (int i = cols.Count - 1; i >= 0; i--) + { + // if (cols[i].Visible && cols[i].PropertyDescriptor is not null) { + if (cols[i].PropertyDescriptor is not null) + { + lastColumnMarkedVisible = i; + break; + } + } + + if (CurrentColumn == lastColumnMarkedVisible) + { + if (gridState[GRIDSTATE_childLinkFocused] || (!gridState[GRIDSTATE_childLinkFocused] && (keyData & Keys.Shift) != Keys.Shift)) + { + if (localRows[CurrentRow].ProcessTabKey(keyData, layout.RowHeaders, isRightToLeft())) + { + if (cols.Count > 0) + cols[CurrentColumn].ConcedeFocus(); + gridState[GRIDSTATE_childLinkFocused] = true; + // let the grid regain focus + // introduced because of that BeginInvoke thing in the OnLeave method.... + if (gridState[GRIDSTATE_canFocus] && CanFocus && !Focused) + FocusInternal(); + return true; + } + } + + // actually, it turns out that we should leave the + // control if we are in the last row + if ((currentRow == DataGridRowsLength - 1) && ((keyData & Keys.Shift) == 0)) + { + EndEdit(); + bool ret = false; + ret = base.ProcessDialogKey(keyData); + + return ret; + } + } + + if (CurrentColumn == firstColumnMarkedVisible) + { + // if the childLink is focused, then navigate within the relations + // in the row, otherwise expand the relations list for the row above + if (!gridState[GRIDSTATE_childLinkFocused]) + { + if (CurrentRow != 0 && (keyData & Keys.Shift) == Keys.Shift) + { + if (localRows[CurrentRow - 1].ProcessTabKey(keyData, layout.RowHeaders, isRightToLeft())) + { + CurrentRow--; + if (cols.Count > 0) + cols[CurrentColumn].ConcedeFocus(); + gridState[GRIDSTATE_childLinkFocused] = true; + // let the grid regain focus + // introduced because of that BeginInvoke thing in the OnLeave method.... + if (gridState[GRIDSTATE_canFocus] && CanFocus && !Focused) + FocusInternal(); + return true; + } + } + } + else + { + if (localRows[CurrentRow].ProcessTabKey(keyData, layout.RowHeaders, isRightToLeft())) + { + return true; + } + else + { + // we were on the firstColumn, previously the link was focused + // we have to navigate to the last column + gridState[GRIDSTATE_childLinkFocused] = false; + CurrentColumn = lastColumnMarkedVisible; + return true; + } + } + + // if we are on the first cell ( not on the addNewRow ) + // then shift - tab should move to the next control on the form + if (currentRow == 0 && ((keyData & Keys.Shift) == Keys.Shift)) + { + EndEdit(); + bool ret = false; + ret = base.ProcessDialogKey(keyData); + + return ret; + } + } + + // move + if ((keyData & Keys.Shift) != Keys.Shift) + { + // forward + if (CurrentColumn == lastColumnMarkedVisible) + { + if (CurrentRow != DataGridRowsLength - 1) + CurrentColumn = firstColumnMarkedVisible; + CurrentRow = CurrentRow + 1; + } + else + { + int nextCol = MoveLeftRight(cols, currentCol, true); // true for going right; + Debug.Assert(nextCol < cols.Count, "we already checked that we are not at the lastColumnMarkedVisible"); + CurrentColumn = nextCol; + } + } + else + { + // backward + if (CurrentColumn == firstColumnMarkedVisible) + { + if (CurrentRow != 0) + { + CurrentColumn = lastColumnMarkedVisible; + } + + if (!gridState[GRIDSTATE_childLinkFocused]) // bug 86803 + CurrentRow--; + } + else if (gridState[GRIDSTATE_childLinkFocused] && CurrentColumn == lastColumnMarkedVisible) + { + // part deux: when we hilite the childLink and then press shift-tab, we + // don't want to navigate at the second to last column + InvalidateRow(currentRow); + Edit(); + } + else + { + int prevCol = MoveLeftRight(cols, currentCol, false); // false for going left + Debug.Assert(prevCol != -1, "we already checked that we are not at the first columnMarked visible"); + CurrentColumn = prevCol; + } + } + + // if we got here, then invalidate childLinkFocused + gridState[GRIDSTATE_childLinkFocused] = false; + + // Begin another edit if we were editing before + if (wasEditing) + { + ResetSelection(); + Edit(); + } + + return true; + } + + virtual protected void CancelEditing() + { + CancelCursorUpdate(); + // yield the escape key if there is no editing + // make the last row a DataGridAddNewRow + if (gridState[GRIDSTATE_inAddNewRow]) + { + gridState[GRIDSTATE_inAddNewRow] = false; + DataGridRow[] localGridRows = DataGridRows; + + localGridRows[DataGridRowsLength - 1] = new DataGridAddNewRow(this, myGridTable, DataGridRowsLength - 1); + SetDataGridRows(localGridRows, DataGridRowsLength); + } + } + + internal void RecalculateFonts() + { + try + { + linkFont = new Font(Font, FontStyle.Underline); + } + catch + { + } + + fontHeight = Font.Height; + linkFontHeight = LinkFont.Height; + captionFontHeight = CaptionFont.Height; + + if (myGridTable is null || myGridTable.IsDefault) + headerFontHeight = HeaderFont.Height; + else + headerFontHeight = myGridTable.HeaderFont.Height; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler BackButtonClick + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ShowParentDetailsButtonClick + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + private void ResetMouseState() + { + oldRow = -1; + gridState[GRIDSTATE_overCaption] = true; + } + + protected void ResetSelection() + { + if (numSelectedRows > 0) + { + DataGridRow[] localGridRows = DataGridRows; + for (int i = 0; i < DataGridRowsLength; ++i) + if (localGridRows[i].Selected) + localGridRows[i].Selected = false; + } + + numSelectedRows = 0; + lastRowSelected = -1; + } + + private void ResetParentRows() + { + parentRows.Clear(); + originalState = null; + caption.BackButtonActive = caption.DownButtonActive = caption.BackButtonVisible = false; + caption.SetDownButtonDirection(!layout.ParentRowsVisible); + } + + /// + /// Re-initializes all UI related state. + /// + private void ResetUIState() + { + gridState[GRIDSTATE_childLinkFocused] = false; + ResetSelection(); + ResetMouseState(); + PerformLayout(); + Invalidate(); // we want to invalidate after we set up the scrollbars + + // invalidate the horizontalscrollbar and the vertical scrollbar + // + if (horizScrollBar.Visible) + horizScrollBar.Invalidate(); + if (vertScrollBar.Visible) + vertScrollBar.Invalidate(); + } + + /// + /// Scrolls the datagrid down an arbritrary number of rows. + /// + private void ScrollDown(int rows) + { + // Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: ScrollDown, rows = " + rows.ToString()); + if (rows != 0) + { + ClearRegionCache(); + + // we should put "dataGridRowsLength -1" + int newFirstRow = Math.Max(0, Math.Min(firstVisibleRow + rows, this.DataGridRowsLength - 1)); + int oldFirstRow = firstVisibleRow; + firstVisibleRow = newFirstRow; + vertScrollBar.Value = newFirstRow; + bool wasEditing = this.gridState[GRIDSTATE_isEditing]; + ComputeVisibleRows(); + + if (gridState[GRIDSTATE_isScrolling]) + { + Edit(); + // isScrolling is set to TRUE when the user scrolls. + // once we move the edit box, we finished processing the scroll event, so set isScrolling to FALSE + // to set isScrolling to TRUE, we need another scroll event. + gridState[GRIDSTATE_isScrolling] = false; + } + else + { + EndEdit(); + } + + int deltaY = ComputeRowDelta(oldFirstRow, newFirstRow); + Rectangle rowsRect = layout.Data; + if (layout.RowHeadersVisible) + rowsRect = Rectangle.Union(rowsRect, layout.RowHeaders); + RECT scrollArea = RECT.FromXYWH(rowsRect.X, rowsRect.Y, rowsRect.Width, rowsRect.Height); + // SafeNativeMethods.ScrollWindow(new HandleRef(this, Handle), 0, deltaY, ref scrollArea, ref scrollArea); + OnScroll(EventArgs.Empty); + + if (wasEditing) + { + // invalidate the rowHeader for the + InvalidateRowHeader(currentRow); + } + } + } + + /// + /// Scrolls the datagrid right an arbritrary number of columns. + /// + private void ScrollRight(int columns) + { + Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: ScrollRight, columns = " + columns.ToString(CultureInfo.InvariantCulture)); + int newCol = firstVisibleCol + columns; + + GridColumnStylesCollection gridColumns = myGridTable.GridColumnStyles; + int newColOffset = 0; + int nGridCols = gridColumns.Count; + int nVisibleCols = 0; + + // if we try to scroll past the last totally visible column, + // then the toolTips will dissapear + if (this.myGridTable.IsDefault) + nVisibleCols = nGridCols; + else + for (int i = 0; i < nGridCols; i++) + if (gridColumns[i].PropertyDescriptor is not null) + nVisibleCols++; + + if ((lastTotallyVisibleCol == nVisibleCols - 1 && columns > 0) || + (firstVisibleCol == 0 && columns < 0 && negOffset == 0)) + return; + + newCol = Math.Min(newCol, nGridCols - 1); + + for (int i = 0; i < newCol; i++) + // if (gridColumns[i].Visible && gridColumns[i].PropertyDescriptor is not null) + if (gridColumns[i].PropertyDescriptor is not null) + newColOffset += gridColumns[i].Width; + + HorizontalOffset = newColOffset; + } + + /// + /// Scrolls a given column into visibility. + /// + private void ScrollToColumn(int targetCol) + { + // do not flush the columns to the left + // so, scroll only as many columns as is necessary. + // CONSIDER: after doing a sort, maybe the user would like to have + // selected column flushed to the left + int dCols = targetCol - firstVisibleCol; + + if (targetCol > lastTotallyVisibleCol && lastTotallyVisibleCol != -1) + dCols = targetCol - lastTotallyVisibleCol; + + // if only part of the currentCol is visible + // then we should still scroll + if (dCols != 0 || negOffset != 0) + ScrollRight(dCols); + } + + public void Select(int row) + { + throw new PlatformNotSupportedException(); + } + + // this function will pair the listManager w/ a table from the TableStylesCollection. + // and for each column in the TableStylesCollection will pair them w/ a propertyDescriptor + // from the listManager + // prerequisite: the current table is either the default table, or has the same name as the + // list in the listManager. + private void PairTableStylesAndGridColumns(CurrencyManager lm, DataGridTableStyle gridTable, bool forceColumnCreation) + { + PropertyDescriptorCollection props = lm.GetItemProperties(); + GridColumnStylesCollection gridCols = gridTable.GridColumnStyles; + + // ]it is possible to have a dataTable w/ an empty string for a name. + if (!gridTable.IsDefault && string.Compare(lm.GetListName(), gridTable.MappingName, true, CultureInfo.InvariantCulture) == 0) + { + // we will force column creation only at runtime + if (gridTable.GridColumnStyles.Count == 0 && !DesignMode) + { + // we have to create some default columns for each of the propertyDescriptors + // + if (forceColumnCreation) + gridTable.SetGridColumnStylesCollection(lm); + else + gridTable.SetRelationsList(lm); + } + else + { + // it may the case that the user will have two lists w/ the same name. + // When switching binding between those different lists, we need to invalidate + // the propertyDescriptors from the current gridColumns + for (int i = 0; i < gridCols.Count; i++) + gridCols[i].PropertyDescriptor = null; + + // pair the propertyDescriptor from each column to the actual property descriptor + // from the listManager + for (int i = 0; i < props.Count; i++) + { + DataGridColumnStyle col = gridCols.MapColumnStyleToPropertyName(props[i].Name); + if (col is not null) + { + col.PropertyDescriptor = props[i]; + } + } + + // TableStyle::SetGridColumnStylesCollection will also set the + // relations list in the tableStyle. + gridTable.SetRelationsList(lm); + } + } + else + { + // we should put an assert, that this is the default Table Style +#if DEBUG + Debug.Assert(gridTable.IsDefault, "if we don't have a match, then the dataGRid should have the default table"); +#endif // DEBUG + gridTable.SetGridColumnStylesCollection(lm); + if (gridTable.GridColumnStyles.Count > 0 && gridTable.GridColumnStyles[0].Width == -1) + { +#if DEBUG + GridColumnStylesCollection cols = gridTable.GridColumnStyles; + for (int i = 0; i < cols.Count; i++) + { + Debug.Assert(cols[i].Width == -1, "if one column's width is not initialized, the same should be happening for the rest of the columns"); + } +#endif // DEBUG + InitializeColumnWidths(); + } + } + } + + /// + /// Sets the current GridTable for the DataGrid. + /// This GridTable is the table which is currently + /// being displayed on the grid. + /// + internal void SetDataGridTable(DataGridTableStyle newTable, bool forceColumnCreation) + { + // we have to listen to the dataGridTable for the propertyChangedEvent + if (myGridTable is not null) + { + // unwire the propertyChanged event + UnWireTableStylePropChanged(myGridTable); + + if (myGridTable.IsDefault) + { + // reset the propertyDescriptors on the default table. + myGridTable.GridColumnStyles.ResetPropertyDescriptors(); + + // reset the relationship list from the default table + myGridTable.ResetRelationsList(); + } + } + + myGridTable = newTable; + + WireTableStylePropChanged(myGridTable); + + layout.RowHeadersVisible = newTable.IsDefault ? RowHeadersVisible : newTable.RowHeadersVisible; + + // we need to force the grid into the dataGridTableStyle + // this way the controls in the columns will be parented + // consider this scenario: when the user finished InitializeComponent, it added + // a bunch of tables. all of those tables will have the DataGrid property set to this + // grid. however, in InitializeComponent the tables will not have parented the + // edit controls w/ the grid. + // + // the code in DataGridTextBoxColumn already checks to see if the edits are parented + // before parenting them. + // + if (newTable is not null) + newTable.DataGrid = this; + + // pair the tableStyles and GridColumns + // + if (listManager is not null) + PairTableStylesAndGridColumns(listManager, myGridTable, forceColumnCreation); + + // reset the relations UI on the newTable + if (newTable is not null) + newTable.ResetRelationsUI(); + + // set the isNavigating to false + gridState[GRIDSTATE_isNavigating] = false; + + horizScrollBar.Value = 0; + firstVisibleRow = 0; + currentCol = 0; + // if we add a tableStyle that mapps to the + // current listName, then we should set the currentRow to the + // position in the listManager + if (listManager is null) + currentRow = 0; + else + currentRow = listManager.Position == -1 ? 0 : listManager.Position; + ResetHorizontalOffset(); + negOffset = 0; + ResetUIState(); + + // check the hierarchy + checkHierarchy = true; + } + + /// + /// Scrolls the data area down to make room for the parent rows + /// and lays out the different regions of the DataGrid. + /// + internal void SetParentRowsVisibility(bool visible) + { + Rectangle parentRowsRect = layout.ParentRows; + Rectangle underParentRows = layout.Data; + + if (layout.RowHeadersVisible) + { + underParentRows.X -= isRightToLeft() ? 0 : layout.RowHeaders.Width; + underParentRows.Width += layout.RowHeaders.Width; + } + + if (layout.ColumnHeadersVisible) + { + underParentRows.Y -= layout.ColumnHeaders.Height; + underParentRows.Height += layout.ColumnHeaders.Height; + } + + // hide the Edit Box + EndEdit(); + + if (visible) + { + layout.ParentRowsVisible = true; + + PerformLayout(); + + Invalidate(); + } + else + { + RECT scrollRECT = RECT.FromXYWH(underParentRows.X, underParentRows.Y - layout.ParentRows.Height, underParentRows.Width, underParentRows.Height + layout.ParentRows.Height); + + if (vertScrollBar.Visible) + { + Rectangle fixupRect = vertScrollBar.Bounds; + fixupRect.Y -= parentRowsRect.Height; + fixupRect.Height += parentRowsRect.Height; + Invalidate(fixupRect); + } + + Debug.WriteLineIf(CompModSwitches.DataGridParents.TraceVerbose, "DataGridParents: Making parent rows invisible."); + layout.ParentRowsVisible = false; + PerformLayout(); + } + } + + /// + /// Sets whether a row is expanded or not. + /// + private void SetRowExpansionState(int row, bool expanded) + { + if (row < -1 || row > DataGridRowsLength - (policy.AllowAdd ? 2 : 1)) + { + throw new ArgumentOutOfRangeException(); + } + + DataGridRow[] localGridRows = DataGridRows; + if (row == -1) + { + DataGridRelationshipRow[] expandableRows = GetExpandableRows(); + bool repositionEditControl = false; + + for (int r = 0; r < expandableRows.Length; ++r) + { + if (expandableRows[r].Expanded != expanded) + { + expandableRows[r].Expanded = expanded; + repositionEditControl = true; + } + } + + if (repositionEditControl) + { + // we need to reposition the edit control + if (gridState[GRIDSTATE_isNavigating] || gridState[GRIDSTATE_isEditing]) + { + ResetSelection(); + Edit(); + } + } + } + else if (localGridRows[row] is DataGridRelationshipRow) + { + DataGridRelationshipRow expandableRow = (DataGridRelationshipRow)localGridRows[row]; + if (expandableRow.Expanded != expanded) + { + // we need to reposition the edit control + if (gridState[GRIDSTATE_isNavigating] || gridState[GRIDSTATE_isEditing]) + { + ResetSelection(); + Edit(); + } + + expandableRow.Expanded = expanded; + } + } + } + + private void ObjectSiteChange(IContainer container, IComponent component, bool site) + { + if (site) + { + if (component.Site is null) + { + container.Add(component); + } + } + else + { + if (component.Site is not null && component.Site.Container == container) + { + container.Remove(component); + } + } + } + + public void SubObjectsSiteChange(bool site) + { + throw new PlatformNotSupportedException(); + } + + public void UnSelect(int row) + { + throw new PlatformNotSupportedException(); + } + + /// + /// Asks the cursor to update. + /// + private void UpdateListManager() + { + Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: Requesting EndEdit()"); + try + { + if (listManager is not null) + { + EndEdit(); + listManager.EndCurrentEdit(); + } + } + catch + { + } + } + + protected virtual string GetOutputTextDelimiter() + { + return "\t"; + } + + /// + /// The accessible object class for a DataGrid. The child accessible objects + /// are accessible objects corresponding to the propertygrid entries. + /// + [Runtime.InteropServices.ComVisible(true)] + [Obsolete("DataGridAccessibleObject has been deprecated.")] + internal class DataGridAccessibleObject : ControlAccessibleObject + { + /// + /// Construct a PropertyGridViewAccessibleObject + /// + public DataGridAccessibleObject(DataGrid owner) : base(owner) + { + throw new PlatformNotSupportedException(); + } + + internal DataGrid DataGrid + { + get + { + return (DataGrid)Owner; + } + } + + private int ColumnCountPrivate + { + get + { + return ((DataGrid)Owner).myGridTable.GridColumnStyles.Count; + } + } + + private int RowCountPrivate + { + get + { + return ((DataGrid)Owner).dataGridRows.Length; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Name + { + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleRole Role + { + get + { + throw new PlatformNotSupportedException(); + } + } + + public override AccessibleObject GetChild(int index) + { + throw new PlatformNotSupportedException(); + } + + public override int GetChildCount() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject GetFocused() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject GetSelected() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject HitTest(int x, int y) + { + throw new PlatformNotSupportedException(); + } + + [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] + public override AccessibleObject Navigate(AccessibleNavigation navdir) + { + throw new PlatformNotSupportedException(); + } + } + + // + // This simple data structure holds all of the layout information + // for the DataGrid. + // + [Obsolete("LayoutData has been deprecated.")] + internal class LayoutData + { + internal bool dirty = true; + // region inside the Control's borders. + public Rectangle Inside = Rectangle.Empty; + + public Rectangle RowHeaders = Rectangle.Empty; + + public Rectangle TopLeftHeader = Rectangle.Empty; + public Rectangle ColumnHeaders = Rectangle.Empty; + public Rectangle Data = Rectangle.Empty; + + public Rectangle Caption = Rectangle.Empty; + public Rectangle ParentRows = Rectangle.Empty; + + public Rectangle ResizeBoxRect = Rectangle.Empty; + + public bool ColumnHeadersVisible; + public bool RowHeadersVisible; + public bool CaptionVisible; + public bool ParentRowsVisible; + + // used for resizing. + public Rectangle ClientRectangle = Rectangle.Empty; + + public LayoutData() + { + throw new PlatformNotSupportedException(); + } + + public LayoutData(LayoutData src) + { + throw new PlatformNotSupportedException(); + } + + private void GrabLayout(LayoutData src) + { + Inside = src.Inside; + TopLeftHeader = src.TopLeftHeader; + ColumnHeaders = src.ColumnHeaders; + RowHeaders = src.RowHeaders; + Data = src.Data; + Caption = src.Caption; + ParentRows = src.ParentRows; + ResizeBoxRect = src.ResizeBoxRect; + ColumnHeadersVisible = src.ColumnHeadersVisible; + RowHeadersVisible = src.RowHeadersVisible; + CaptionVisible = src.CaptionVisible; + ParentRowsVisible = src.ParentRowsVisible; + ClientRectangle = src.ClientRectangle; + } + + public override string ToString() + { + throw new PlatformNotSupportedException(); + } + } + + [Obsolete("HitTestInfo has been deprecated.")] + public sealed class HitTestInfo + { + internal HitTestType type = HitTestType.None; + + internal int row; + internal int col; + + public static readonly HitTestInfo Nowhere = new HitTestInfo(); + + internal HitTestInfo() + { + type = (HitTestType)0; + row = col = -1; + } + + internal HitTestInfo(HitTestType type) + { + this.type = type; + row = col = -1; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int Column + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int Row + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public HitTestType Type + { + get + { + throw new PlatformNotSupportedException(); + } + } + + public override bool Equals(object value) + { + throw new PlatformNotSupportedException(); + } + + public override int GetHashCode() + { + throw new PlatformNotSupportedException(); + } + + public override string ToString() + { + throw new PlatformNotSupportedException(); + } + } + + [Flags] + [Obsolete("HitTestType has been deprecated.")] + public enum HitTestType + { + None = 0x00000000, + + Cell = 0x00000001, + + ColumnHeader = 0x00000002, + + RowHeader = 0x00000004, + + ColumnResize = 0x00000008, + + RowResize = 0x00000010, + + Caption = 0x00000020, + + ParentRows = 0x00000040 + } + + /// + /// Holds policy information for what the grid can and cannot do. + /// + private class Policy + { + private bool allowAdd = true; + private bool allowEdit = true; + private bool allowRemove = true; + + public Policy() + { + } + + public bool AllowAdd + { + get + { + return allowAdd; + } + set + { + if (allowAdd != value) + { + allowAdd = value; + } + } + } + + public bool AllowEdit + { + get + { + return allowEdit; + } + set + { + if (allowEdit != value) + { + allowEdit = value; + } + } + } + + public bool AllowRemove + { + get + { + return allowRemove; + } + set + { + if (allowRemove != value) + { + allowRemove = value; + } + } + } + + // returns true if the UI needs to be updated (here because addnew has changed) + public bool UpdatePolicy(CurrencyManager listManager, bool gridReadOnly) + { + bool change = false; + // only IBindingList can have an AddNewRow + IBindingList bl = listManager is null ? null : listManager.List as IBindingList; + if (listManager is null) + { + if (!allowAdd) + change = true; + allowAdd = allowEdit = allowRemove = true; + } + else + { + if (AllowAdd != listManager.AllowAdd && !gridReadOnly) + change = true; + AllowAdd = listManager.AllowAdd && !gridReadOnly && bl is not null && bl.SupportsChangeNotification; + AllowEdit = listManager.AllowEdit && !gridReadOnly; + AllowRemove = listManager.AllowRemove && !gridReadOnly && bl is not null && bl.SupportsChangeNotification; // bug 86061 + } + + return change; + } + } + + private int MirrorRectangle(Rectangle R1, Rectangle rect, bool rightToLeft) + { + if (rightToLeft) + return rect.Right + rect.X - R1.Right; + else + return R1.X; + } + + private int MirrorPoint(int x, Rectangle rect, bool rightToLeft) + { + if (rightToLeft) + return rect.Right + rect.X - x; + else + return x; + } + + private bool isRightToLeft() + { + return (RightToLeft == RightToLeft.Yes); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs new file mode 100644 index 00000000000..fc54ea428c8 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs @@ -0,0 +1,79 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; + +namespace System.Windows.Forms; + +#nullable disable +[Obsolete("DataGridAddNewRow has been deprecated.")] +internal class DataGridAddNewRow : DataGridRow +{ + public DataGridAddNewRow(DataGrid dGrid, DataGridTableStyle gridTable, int rowNum) + : base(dGrid, gridTable, rowNum) + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool DataBound + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + public override void OnEdit() + { + throw new PlatformNotSupportedException(); + } + + public override void OnRowLeave() + { + throw new PlatformNotSupportedException(); + } + + internal override void LoseChildFocus(Rectangle rowHeader, bool alignToRight) + { + } + + internal override bool ProcessTabKey(Keys keyData, Rectangle rowHeaders, bool alignToRight) + { + return false; + } + + public override int Paint(Graphics g, Rectangle bounds, Rectangle trueRowBounds, int firstVisibleColumn, int columnCount) + { + throw new PlatformNotSupportedException(); + } + + public override int Paint(Graphics g, + Rectangle bounds, + Rectangle trueRowBounds, + int firstVisibleColumn, + int columnCount, + bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + protected override void PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, + Brush backBr, Brush foreBrush, bool alignToRight) + { + if (DataBound) + { + CurrencyManager listManager = DataGrid.ListManager; + column.Paint(g, cellBounds, listManager, this.RowNumber, alignToRight); + } + else + { + base.PaintCellContents(g, cellBounds, column, backBr, foreBrush, alignToRight); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs new file mode 100644 index 00000000000..489064d456f --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs @@ -0,0 +1,422 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("DataGridBoolColumn has been deprecated.")] +public class DataGridBoolColumn : DataGridColumnStyle +{ + private const int idealCheckSize = 14; + + private bool isEditing; + private bool isSelected; + private int editingRow = -1; + private object currentValue = Convert.DBNull; + + private object trueValue = true; + private object falseValue = false; + private object nullValue = Convert.DBNull; + + private static readonly object EventTrueValue = new object(); + private static readonly object EventFalseValue = new object(); + private static readonly object EventAllowNull = new object(); + + public DataGridBoolColumn() : base() + { + throw new PlatformNotSupportedException(); + } + + public DataGridBoolColumn(PropertyDescriptor prop) + : base(prop) + { + throw new PlatformNotSupportedException(); + } + + public DataGridBoolColumn(PropertyDescriptor prop, bool isDefault) + : base(prop, isDefault) + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public object TrueValue + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler TrueValueChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public object FalseValue + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler FalseValueChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public object NullValue + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + protected internal override void ConcedeFocus() + { + base.ConcedeFocus(); + isSelected = false; + isEditing = false; + } + + private Rectangle GetCheckBoxBounds(Rectangle bounds, bool alignToRight) + { + if (alignToRight) + return new Rectangle(bounds.X + ((bounds.Width - idealCheckSize) / 2), + bounds.Y + ((bounds.Height - idealCheckSize) / 2), + bounds.Width < idealCheckSize ? bounds.Width : idealCheckSize, + idealCheckSize); + else + return new Rectangle(Math.Max(0, bounds.X + ((bounds.Width - idealCheckSize) / 2)), + Math.Max(0, bounds.Y + ((bounds.Height - idealCheckSize) / 2)), + bounds.Width < idealCheckSize ? bounds.Width : idealCheckSize, + idealCheckSize); + } + + protected internal override object GetColumnValueAtRow(CurrencyManager lm, int row) + { + object baseValue = base.GetColumnValueAtRow(lm, row); + object value = Convert.DBNull; + if (baseValue.Equals(trueValue)) + { + value = true; + } + else if (baseValue.Equals(falseValue)) + { + value = false; + } + + return value; + } + + private bool IsReadOnly() + { + bool ret = ReadOnly; + if (DataGridTableStyle is not null) + { + ret = ret || DataGridTableStyle.ReadOnly; + if (DataGridTableStyle.DataGrid is not null) + ret = ret || DataGridTableStyle.DataGrid.ReadOnly; + } + + return ret; + } + + protected internal override void SetColumnValueAtRow(CurrencyManager lm, int row, object value) + { + object baseValue = null; + if (true.Equals(value)) + { + baseValue = TrueValue; + } + else if (false.Equals(value)) + { + baseValue = FalseValue; + } + else if (Convert.IsDBNull(value)) + { + baseValue = NullValue; + } + + currentValue = baseValue; + base.SetColumnValueAtRow(lm, row, baseValue); + } + + protected internal override Size GetPreferredSize(Graphics g, object value) + { + return new Size(idealCheckSize + 2, idealCheckSize + 2); + } + + protected internal override int GetMinimumHeight() + { + return idealCheckSize + 2; + } + + protected internal override int GetPreferredHeight(Graphics g, object value) + { + return idealCheckSize + 2; + } + + protected internal override void Abort(int rowNum) + { + isSelected = false; + isEditing = false; + Invalidate(); + return; + } + + protected internal override bool Commit(CurrencyManager dataSource, int rowNum) + { + isSelected = false; + // always invalidate + Invalidate(); + if (!isEditing) + return true; + + SetColumnValueAtRow(dataSource, rowNum, currentValue); + isEditing = false; + return true; + } + + protected internal override void Edit(CurrencyManager source, + int rowNum, + Rectangle bounds, + bool readOnly, + string displayText, + bool cellIsVisible) + { + // toggle state right now... + isSelected = true; + + // move the focus away from the previous column and give it to the grid + DataGrid grid = DataGridTableStyle.DataGrid; + + if (!readOnly && !IsReadOnly()) + { + editingRow = rowNum; + currentValue = GetColumnValueAtRow(source, rowNum); + } + + base.Invalidate(); + } + + internal override bool KeyPress(int rowNum, Keys keyData) + { + if (isSelected && editingRow == rowNum && !IsReadOnly()) + { + if ((keyData & Keys.KeyCode) == Keys.Space) + { + ToggleValue(); + Invalidate(); + return true; + } + } + + return base.KeyPress(rowNum, keyData); + } + + internal override bool MouseDown(int rowNum, int x, int y) + { + base.MouseDown(rowNum, x, y); + if (isSelected && editingRow == rowNum && !IsReadOnly()) + { + ToggleValue(); + Invalidate(); + return true; + } + + return false; + } + + private void OnTrueValueChanged(EventArgs e) + { + EventHandler eh = Events[EventTrueValue] as EventHandler; + if (eh is not null) + eh(this, e); + } + + private void OnFalseValueChanged(EventArgs e) + { + EventHandler eh = Events[EventFalseValue] as EventHandler; + if (eh is not null) + eh(this, e); + } + + private void OnAllowNullChanged(EventArgs e) + { + EventHandler eh = Events[EventAllowNull] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) + { + Paint(g, bounds, source, rowNum, DataGridTableStyle.BackBrush, DataGridTableStyle.ForeBrush, alignToRight); + } + + protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, + Brush backBrush, Brush foreBrush, + bool alignToRight) + { + object value = (isEditing && editingRow == rowNum) ? currentValue : GetColumnValueAtRow(source, rowNum); + ButtonState checkedState = ButtonState.Inactive; + if (!Convert.IsDBNull(value)) + { + checkedState = ((bool)value ? ButtonState.Checked : ButtonState.Normal); + } + + Rectangle box = GetCheckBoxBounds(bounds, alignToRight); + + Region r = g.Clip; + g.ExcludeClip(box); + + Brush selectionBrush = DataGridTableStyle.IsDefault ? DataGridTableStyle.DataGrid.SelectionBackBrush : DataGridTableStyle.SelectionBackBrush; + if (isSelected && editingRow == rowNum && !IsReadOnly()) + { + g.FillRectangle(selectionBrush, bounds); + } + else + g.FillRectangle(backBrush, bounds); + g.Clip = r; + + if (checkedState == ButtonState.Inactive) + { + ControlPaint.DrawMixedCheckBox(g, box, ButtonState.Checked); + } + else + { + ControlPaint.DrawCheckBox(g, box, checkedState); + } + + // if the column is read only we should still show selection + if (IsReadOnly() && isSelected && source.Position == rowNum) + { + bounds.Inflate(-1, -1); + Pen pen = new Pen(selectionBrush); + pen.DashStyle = Drawing.Drawing2D.DashStyle.Dash; + g.DrawRectangle(pen, bounds); + pen.Dispose(); + // restore the bounds rectangle + bounds.Inflate(1, 1); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool AllowNull + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler AllowNullChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected internal override void EnterNullValue() + { + // do not throw an exception when the column is marked as readOnly or + // does not allowNull + if (!AllowNull || IsReadOnly()) + return; + if (currentValue is not DBNull) + { + currentValue = Convert.DBNull; + Invalidate(); + } + } + + private void ResetNullValue() + { + NullValue = Convert.DBNull; + } + + private bool ShouldSerializeNullValue() + { + return nullValue is not DBNull; + } + + private void ToggleValue() + { + if (currentValue is bool && ((bool)currentValue) == false) + { + currentValue = true; + } + else + { + if (AllowNull) + { + if (Convert.IsDBNull(currentValue)) + { + currentValue = false; + } + else + { + currentValue = Convert.DBNull; + } + } + else + { + currentValue = false; + } + } + + // we started editing + isEditing = true; + // tell the dataGrid that things are changing + // we put Rectangle.Empty cause toggle will invalidate the row anyhow + DataGridTableStyle.DataGrid.ColumnStartedEditing(Rectangle.Empty); + } + + protected internal override void Paint(Graphics g1, Graphics g, Rectangle bounds, CurrencyManager source, int rowNum) => throw new NotImplementedException(); +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs new file mode 100644 index 00000000000..00b0611251c --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs @@ -0,0 +1,889 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Imaging; +using System.Globalization; +using System.Runtime.Versioning; + +namespace System.Windows.Forms; + +#nullable disable +internal class DataGridCaption +{ + internal EventHandlerList events; + + private const int xOffset = 3; + private const int yOffset = 1; + private const int textPadding = 2; + private const int buttonToText = 4; + private static ColorMap[] colorMap = [new ColorMap()]; + + private static readonly Point minimumBounds = new Point(50, 30); + + private DataGrid dataGrid; + private bool backButtonVisible; + private bool downButtonVisible; + + private SolidBrush backBrush = DefaultBackBrush; + private SolidBrush foreBrush = DefaultForeBrush; + private Pen textBorderPen = DefaultTextBorderPen; + + private string text = ""; + private bool textBorderVisible; + private Font textFont; + + private Font dataGridFont; + + private bool backActive; + private bool downActive; + private bool backPressed; + private bool downPressed; + + // if the downButton should point down or not + private bool downButtonDown; + + private static Bitmap leftButtonBitmap; + private static Bitmap leftButtonBitmap_bidi; + private static Bitmap magnifyingGlassBitmap; + + private Rectangle backButtonRect; + private Rectangle downButtonRect; + private Rectangle textRect; + + private CaptionLocation lastMouseLocation = CaptionLocation.Nowhere; + + private EventEntry eventList; + private static readonly object EVENT_BACKWARDCLICKED = new object(); + private static readonly object EVENT_DOWNCLICKED = new object(); + private static readonly object EVENT_CAPTIONCLICKED = new object(); + + internal DataGridCaption(DataGrid dataGrid) + { + this.dataGrid = dataGrid; + downButtonVisible = dataGrid.ParentRowsVisible; + colorMap[0].OldColor = Color.White; + colorMap[0].NewColor = ForeColor; + OnGridFontChanged(); + } + + internal void OnGridFontChanged() + { + if (dataGridFont is null || !dataGridFont.Equals(dataGrid.Font)) + { + try + { + dataGridFont = new Font(dataGrid.Font, FontStyle.Bold); + } + catch + { + } + } + } + + internal bool BackButtonActive + { + get + { + return backActive; + } + set + { + if (backActive != value) + { + backActive = value; + InvalidateCaptionRect(backButtonRect); + } + } + } + + internal bool DownButtonActive + { + get + { + return downActive; + } + set + { + if (downActive != value) + { + downActive = value; + InvalidateCaptionRect(downButtonRect); + } + } + } + + internal static SolidBrush DefaultBackBrush + { + get + { + return (SolidBrush)SystemBrushes.ActiveCaption; + } + } + + internal static Pen DefaultTextBorderPen + { + get + { + return new Pen(SystemColors.ActiveCaptionText); + } + } + + internal static SolidBrush DefaultForeBrush + { + get + { + return (SolidBrush)SystemBrushes.ActiveCaptionText; + } + } + + internal Color BackColor + { + get + { + return backBrush.Color; + } + set + { + if (!backBrush.Color.Equals(value)) + { + if (value.IsEmpty) + throw new ArgumentException("SR.GetString(SR.DataGridEmptyColor)"); + backBrush = new SolidBrush(value); + Invalidate(); + } + } + } + + internal EventHandlerList Events + { + get + { + if (events is null) + { + events = new EventHandlerList(); + } + + return events; + } + } + + internal Font Font + { + get + { + if (textFont is null) + return dataGridFont; + else + return textFont; + } + set + { + if (textFont is null || !textFont.Equals(value)) + { + textFont = value; + // this property gets called in the constructor before dataGrid has a caption + // and we don't need this special-handling then... + if (dataGrid.Caption is not null) + { + dataGrid.RecalculateFonts(); + dataGrid.PerformLayout(); + dataGrid.Invalidate(); // smaller invalidate rect? + } + } + } + } + + internal bool ShouldSerializeFont() + { + return textFont is not null && !textFont.Equals(dataGridFont); + } + + internal bool ShouldSerializeBackColor() + { + return !backBrush.Equals(DefaultBackBrush); + } + + internal void ResetBackColor() + { + if (ShouldSerializeBackColor()) + { + backBrush = DefaultBackBrush; + Invalidate(); + } + } + + internal void ResetForeColor() + { + if (ShouldSerializeForeColor()) + { + foreBrush = DefaultForeBrush; + Invalidate(); + } + } + + internal bool ShouldSerializeForeColor() + { + return !foreBrush.Equals(DefaultForeBrush); + } + + internal void ResetFont() + { + textFont = null; + Invalidate(); + } + + internal string Text + { + get + { + return text; + } + set + { + if (value is null) + text = ""; + else + text = value; + Invalidate(); + } + } + + internal bool TextBorderVisible + { + get + { + return textBorderVisible; + } + set + { + textBorderVisible = value; + Invalidate(); + } + } + + internal Color ForeColor + { + get + { + return foreBrush.Color; + } + set + { + if (value.IsEmpty) + throw new ArgumentException("SR.GetString(SR.DataGridEmptyColor)"); + foreBrush = new SolidBrush(value); + colorMap[0].NewColor = ForeColor; + Invalidate(); + } + } + + internal static Point MinimumBounds + { + get + { + return minimumBounds; + } + } + + internal bool BackButtonVisible + { + get + { + return backButtonVisible; + } + set + { + if (backButtonVisible != value) + { + backButtonVisible = value; + Invalidate(); + } + } + } + + internal bool DownButtonVisible + { + get + { + return downButtonVisible; + } + set + { + if (downButtonVisible != value) + { + downButtonVisible = value; + Invalidate(); + } + } + } + + protected virtual void AddEventHandler(object key, Delegate handler) + { + // Locking 'this' here is ok since this is an internal class. See VSW#464499. + lock (this) + { + if (handler is null) + return; + for (EventEntry e = eventList; e is not null; e = e.next) + { + if (e.key == key) + { + e.handler = Delegate.Combine(e.handler, handler); + return; + } + } + + eventList = new EventEntry(eventList, key, handler); + } + } + + /// + /// Adds a listener for the BackwardClicked event. + /// + internal event EventHandler BackwardClicked + { + add + { + Events.AddHandler(EVENT_BACKWARDCLICKED, value); + } + remove + { + Events.RemoveHandler(EVENT_BACKWARDCLICKED, value); + } + } + + /// + /// Adds a listener for the CaptionClicked event. + /// + internal event EventHandler CaptionClicked + { + add + { + Events.AddHandler(EVENT_CAPTIONCLICKED, value); + } + remove + { + Events.RemoveHandler(EVENT_CAPTIONCLICKED, value); + } + } + + internal event EventHandler DownClicked + { + add + { + Events.AddHandler(EVENT_DOWNCLICKED, value); + } + remove + { + Events.RemoveHandler(EVENT_DOWNCLICKED, value); + } + } + + private void Invalidate() + { + if (dataGrid is not null) + dataGrid.InvalidateCaption(); + } + + private void InvalidateCaptionRect(Rectangle r) + { + if (dataGrid is not null) + dataGrid.InvalidateCaptionRect(r); + } + + private void InvalidateLocation(CaptionLocation loc) + { + Rectangle r; + switch (loc) + { + case CaptionLocation.BackButton: + r = backButtonRect; + r.Inflate(1, 1); + InvalidateCaptionRect(r); + break; + case CaptionLocation.DownButton: + r = downButtonRect; + r.Inflate(1, 1); + InvalidateCaptionRect(r); + break; + } + } + + protected void OnBackwardClicked(EventArgs e) + { + if (backActive) + { + EventHandler handler = (EventHandler)Events[EVENT_BACKWARDCLICKED]; + if (handler is not null) + handler(this, e); + } + } + + protected void OnCaptionClicked(EventArgs e) + { + EventHandler handler = (EventHandler)Events[EVENT_CAPTIONCLICKED]; + if (handler is not null) + handler(this, e); + } + + protected void OnDownClicked(EventArgs e) + { + if (downActive && downButtonVisible) + { + EventHandler handler = (EventHandler)Events[EVENT_DOWNCLICKED]; + if (handler is not null) + handler(this, e); + } + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + private static Bitmap GetBitmap(string bitmapName) + { + Bitmap b = null; + try + { + b = new Bitmap(typeof(DataGridCaption), bitmapName); + b.MakeTransparent(); + } + catch (Exception e) + { + Debug.Fail("Failed to load bitmap: " + bitmapName, e.ToString()); + } + + return b; + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + private static Bitmap GetBackButtonBmp(bool alignRight) + { + if (alignRight) + { + if (leftButtonBitmap_bidi is null) + leftButtonBitmap_bidi = GetBitmap("DataGridCaption.backarrow_bidi.bmp"); + return leftButtonBitmap_bidi; + } + else + { + if (leftButtonBitmap is null) + leftButtonBitmap = GetBitmap("DataGridCaption.backarrow.bmp"); + return leftButtonBitmap; + } + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + private static Bitmap GetDetailsBmp() + { + if (magnifyingGlassBitmap is null) + magnifyingGlassBitmap = GetBitmap("DataGridCaption.Details.bmp"); + return magnifyingGlassBitmap; + } + + protected virtual Delegate GetEventHandler(object key) + { + // Locking 'this' here is ok since this is an internal class. See VSW#464499. + lock (this) + { + for (EventEntry e = eventList; e is not null; e = e.next) + { + if (e.key == key) + return e.handler; + } + + return null; + } + } + + internal static Rectangle GetBackButtonRect(Rectangle bounds, bool alignRight, int downButtonWidth) + { + Bitmap backButtonBmp = GetBackButtonBmp(false); + Size backButtonSize; + lock (backButtonBmp) + { + backButtonSize = backButtonBmp.Size; + } + + return new Rectangle(bounds.Right - xOffset * 4 - downButtonWidth - backButtonSize.Width, + bounds.Y + yOffset + textPadding, + backButtonSize.Width, + backButtonSize.Height); + } + + internal static int GetDetailsButtonWidth() + { + int width = 0; + Bitmap detailsBmp = GetDetailsBmp(); + lock (detailsBmp) + { + width = detailsBmp.Size.Width; + } + + return width; + } + + internal static Rectangle GetDetailsButtonRect(Rectangle bounds, bool alignRight) + { + Size downButtonSize; + Bitmap detailsBmp = GetDetailsBmp(); + lock (detailsBmp) + { + downButtonSize = detailsBmp.Size; + } + + int downButtonWidth = downButtonSize.Width; + return new Rectangle(bounds.Right - xOffset * 2 - downButtonWidth, + bounds.Y + yOffset + textPadding, + downButtonWidth, + downButtonSize.Height); + } + + /// + /// Called by the dataGrid when it needs the caption + /// to repaint. + /// + internal void Paint(Graphics g, Rectangle bounds, bool alignRight) + { + Size textSize = new Size((int)g.MeasureString(text, Font).Width + 2, Font.Height + 2); + + downButtonRect = GetDetailsButtonRect(bounds, alignRight); + int downButtonWidth = GetDetailsButtonWidth(); + backButtonRect = GetBackButtonRect(bounds, alignRight, downButtonWidth); + + int backButtonArea = backButtonVisible ? backButtonRect.Width + xOffset + buttonToText : 0; + int downButtonArea = downButtonVisible && !dataGrid.ParentRowsIsEmpty() ? downButtonWidth + xOffset + buttonToText : 0; + + int textWidthLeft = bounds.Width - xOffset - backButtonArea - downButtonArea; + + textRect = new Rectangle( + bounds.X, + bounds.Y + yOffset, + Math.Min(textWidthLeft, 2 * textPadding + textSize.Width), + 2 * textPadding + textSize.Height); + + // align the caption text box, downButton, and backButton + // if the RigthToLeft property is set to true + if (alignRight) + { + textRect.X = bounds.Right - textRect.Width; + backButtonRect.X = bounds.X + xOffset * 4 + downButtonWidth; + downButtonRect.X = bounds.X + xOffset * 2; + } + + Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "text size = " + textSize.ToString()); + Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "downButtonWidth = " + downButtonWidth.ToString(CultureInfo.InvariantCulture)); + Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "textWidthLeft = " + textWidthLeft.ToString(CultureInfo.InvariantCulture)); + Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "backButtonRect " + backButtonRect.ToString()); + Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "textRect " + textRect.ToString()); + Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "downButtonRect " + downButtonRect.ToString()); + + // we should use the code that is commented out + // with today's code, there are pixels on the backButtonRect and the downButtonRect + // that are getting painted twice + g.FillRectangle(backBrush, bounds); + + if (backButtonVisible) + { + PaintBackButton(g, backButtonRect, alignRight); + if (backActive) + { + if (lastMouseLocation == CaptionLocation.BackButton) + { + backButtonRect.Inflate(1, 1); + ControlPaint.DrawBorder3D(g, backButtonRect, + backPressed ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner); + } + } + } + + PaintText(g, textRect, alignRight); + + if (downButtonVisible && !dataGrid.ParentRowsIsEmpty()) + { + PaintDownButton(g, downButtonRect); + // the rules have changed, yet again. + // now: if we show the parent rows and the mouse is + // not on top of this icon, then let the icon be depressed. + // if the mouse is pressed over the icon, then show the icon pressed + // if the mouse is over the icon and not pressed, then show the icon SunkenInner; + if (lastMouseLocation == CaptionLocation.DownButton) + { + downButtonRect.Inflate(1, 1); + ControlPaint.DrawBorder3D(g, downButtonRect, + downPressed ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner); + } + } + } + + private static void PaintIcon(Graphics g, Rectangle bounds, Bitmap b) + { + ImageAttributes attr = new ImageAttributes(); + attr.SetRemapTable(colorMap, ColorAdjustType.Bitmap); + g.DrawImage(b, bounds, 0, 0, bounds.Width, bounds.Height, GraphicsUnit.Pixel, attr); + attr.Dispose(); + } + + private static void PaintBackButton(Graphics g, Rectangle bounds, bool alignRight) + { + Bitmap backButtonBmp = GetBackButtonBmp(alignRight); + lock (backButtonBmp) + { + PaintIcon(g, bounds, backButtonBmp); + } + } + + private static void PaintDownButton(Graphics g, Rectangle bounds) + { + Bitmap detailsBmp = GetDetailsBmp(); + lock (detailsBmp) + { + PaintIcon(g, bounds, detailsBmp); + } + } + + private void PaintText(Graphics g, Rectangle bounds, bool alignToRight) + { + Rectangle textBounds = bounds; + + if (textBounds.Width <= 0 || textBounds.Height <= 0) + return; + + if (textBorderVisible) + { + g.DrawRectangle(textBorderPen, textBounds.X, textBounds.Y, textBounds.Width - 1, textBounds.Height - 1); + textBounds.Inflate(-1, -1); + } + + if (textPadding > 0) + { + Rectangle border = textBounds; + border.Height = textPadding; + g.FillRectangle(backBrush, border); + + border.Y = textBounds.Bottom - textPadding; + g.FillRectangle(backBrush, border); + + border = new Rectangle(textBounds.X, textBounds.Y + textPadding, + textPadding, textBounds.Height - 2 * textPadding); + g.FillRectangle(backBrush, border); + + border.X = textBounds.Right - textPadding; + g.FillRectangle(backBrush, border); + textBounds.Inflate(-textPadding, -textPadding); + } + + g.FillRectangle(backBrush, textBounds); + + // Brush foreBrush = new SolidBrush(dataGrid.CaptionForeColor); + StringFormat format = new StringFormat(); + if (alignToRight) + { + format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; + format.Alignment = StringAlignment.Far; + } + + g.DrawString(text, Font, foreBrush, textBounds, format); + format.Dispose(); + // foreBrush.Dispose(); + } + + private CaptionLocation FindLocation(int x, int y) + { + if (!backButtonRect.IsEmpty) + { + if (backButtonRect.Contains(x, y)) + return CaptionLocation.BackButton; + } + + if (!downButtonRect.IsEmpty) + { + if (downButtonRect.Contains(x, y)) + return CaptionLocation.DownButton; + } + + if (!textRect.IsEmpty) + { + if (textRect.Contains(x, y)) + return CaptionLocation.Text; + } + + return CaptionLocation.Nowhere; + } + + private bool DownButtonDown + { + get + { + return downButtonDown; + } + set + { + if (downButtonDown != value) + { + downButtonDown = value; + InvalidateLocation(CaptionLocation.DownButton); + } + } + } + + internal bool GetDownButtonDirection() + { + return DownButtonDown; + } + + /// + /// Called by the dataGrid when the mouse is pressed + /// inside the caption. + /// + internal void MouseDown(int x, int y) + { + CaptionLocation loc = FindLocation(x, y); + switch (loc) + { + case CaptionLocation.BackButton: + backPressed = true; + InvalidateLocation(loc); + break; + case CaptionLocation.DownButton: + downPressed = true; + InvalidateLocation(loc); + break; + case CaptionLocation.Text: + OnCaptionClicked(EventArgs.Empty); + break; + } + } + + /// + /// Called by the dataGrid when the mouse is released + /// inside the caption. + /// + internal void MouseUp(int x, int y) + { + CaptionLocation loc = FindLocation(x, y); + switch (loc) + { + case CaptionLocation.DownButton: + if (downPressed) + { + downPressed = false; + OnDownClicked(EventArgs.Empty); + } + + break; + case CaptionLocation.BackButton: + if (backPressed) + { + backPressed = false; + OnBackwardClicked(EventArgs.Empty); + } + + break; + } + } + + /// + /// Called by the dataGrid when the mouse leaves + /// the caption area. + /// + internal void MouseLeft() + { + CaptionLocation oldLoc = lastMouseLocation; + lastMouseLocation = CaptionLocation.Nowhere; + InvalidateLocation(oldLoc); + } + + /// + /// Called by the dataGrid when the mouse is + /// inside the caption. + /// + internal void MouseOver(int x, int y) + { + CaptionLocation newLoc = FindLocation(x, y); + + InvalidateLocation(lastMouseLocation); + InvalidateLocation(newLoc); + lastMouseLocation = newLoc; + } + + protected virtual void RaiseEvent(object key, EventArgs e) + { + Delegate handler = GetEventHandler(key); + if (handler is not null) + ((EventHandler)handler)(this, e); + } + + protected virtual void RemoveEventHandler(object key, Delegate handler) + { + // Locking 'this' here is ok since this is an internal class. See VSW#464499. + lock (this) + { + if (handler is null) + return; + for (EventEntry e = eventList, prev = null; e is not null; prev = e, e = e.next) + { + if (e.key == key) + { + e.handler = Delegate.Remove(e.handler, handler); + if (e.handler is null) + { + if (prev is null) + { + eventList = e.next; + } + else + { + prev.next = e.next; + } + } + + return; + } + } + } + } + + protected virtual void RemoveEventHandlers() + { + eventList = null; + } + + internal void SetDownButtonDirection(bool pointDown) + { + DownButtonDown = pointDown; + } + + /// + /// Toggles the direction the "Down Button" is pointing. + /// + internal bool ToggleDownButtonDirection() + { + DownButtonDown = !DownButtonDown; + return DownButtonDown; + } + + internal enum CaptionLocation + { + Nowhere, + BackButton, + DownButton, + Text + } + + private sealed class EventEntry + { + internal EventEntry next; + internal object key; + internal Delegate handler; + + internal EventEntry(EventEntry next, object key, Delegate handler) + { + this.next = next; + this.key = key; + this.handler = handler; + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs new file mode 100644 index 00000000000..e1255252830 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs @@ -0,0 +1,73 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("DataGridCell has been deprecated.")] +public struct DataGridCell : IEquatable +{ + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int ColumnNumber + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int RowNumber + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + public DataGridCell(int r, int c) + { + throw new PlatformNotSupportedException(); + } + + public override bool Equals(object o) + { + throw new PlatformNotSupportedException(); + } + + public override int GetHashCode() + { + throw new PlatformNotSupportedException(); + } + + public override string ToString() + { + throw new PlatformNotSupportedException(); + } + + public bool Equals(DataGridCell other) + { + throw new NotImplementedException(); + } + + public static bool operator ==(DataGridCell left, DataGridCell right) + { + return left.Equals(right); + } + + public static bool operator !=(DataGridCell left, DataGridCell right) + { + return !(left == right); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs new file mode 100644 index 00000000000..682b5e4c84d --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs @@ -0,0 +1,721 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Security.Permissions; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("DataGridColumnStyle has been deprecated.")] +public abstract class DataGridColumnStyle : Component, IDataGridColumnStyleEditingNotificationService +{ + private DataGridTableStyle dataGridTableStyle; + internal int fontHeight = -1; + private string mappingName = ""; + private string headerName = ""; + private bool invalid; + private string nullText = "SR.GetString(SR.DataGridNullText)"; + private bool updating; + internal int width = -1; + private bool isDefault; + private static readonly object EventAlignment = new object(); + private static readonly object EventPropertyDescriptor = new object(); + private static readonly object EventHeaderText = new object(); + private static readonly object EventMappingName = new object(); + private static readonly object EventNullText = new object(); + private static readonly object EventReadOnly = new object(); + private static readonly object EventWidth = new object(); + + public DataGridColumnStyle() + { + throw new PlatformNotSupportedException(); + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] // Shipped like this in Everett. + public DataGridColumnStyle(PropertyDescriptor prop) : this() + { + throw new PlatformNotSupportedException(); + } + + internal DataGridColumnStyle(PropertyDescriptor prop, bool isDefault) : this(prop) + { + this.isDefault = isDefault; + if (isDefault) + { + // take the header name from the property name + headerName = prop.Name; + mappingName = prop.Name; + } + } + +#if DEBUG + internal bool IsDefault + { + get + { + return isDefault; + } + } +#endif // debug + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual HorizontalAlignment Alignment + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler AlignmentChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + // PM team has reviewed and decided on naming changes already + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] + protected internal virtual void UpdateUI(CurrencyManager source, int rowNum, string displayText) + { + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public AccessibleObject HeaderAccessibleObject + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual PropertyDescriptor PropertyDescriptor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler PropertyDescriptorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual AccessibleObject CreateHeaderAccessibleObject() + { + return new DataGridColumnHeaderAccessibleObject(this); + } + + protected virtual void SetDataGrid(DataGrid value) + { + SetDataGridInColumn(value); + } + + protected virtual void SetDataGridInColumn(DataGrid value) + { + // we need to set up the PropertyDescriptor + if (PropertyDescriptor is null && value is not null) + { + CurrencyManager lm = value.ListManager; + if (lm is null) + return; + PropertyDescriptorCollection propCollection = lm.GetItemProperties(); + int propCount = propCollection.Count; + for (int i = 0; i < propCollection.Count; i++) + { + PropertyDescriptor prop = propCollection[i]; + if (!typeof(IList).IsAssignableFrom(prop.PropertyType) && prop.Name.Equals(HeaderText)) + { + PropertyDescriptor = prop; + return; + } + } + } + } + + internal void SetDataGridInternalInColumn(DataGrid value) + { + if (value is null || value.Initializing) + return; + SetDataGridInColumn(value); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual DataGridTableStyle DataGridTableStyle + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal void SetDataGridTableInColumn(DataGridTableStyle value, bool force) + { + if (dataGridTableStyle is not null && dataGridTableStyle.Equals(value) && !force) + return; + if (value is not null) + { + if (value.DataGrid is not null && !value.DataGrid.Initializing) + { + SetDataGridInColumn(value.DataGrid); + } + } + + dataGridTableStyle = value; + } + + protected int FontHeight + { + get + { + if (fontHeight != -1) + { + return fontHeight; + } + else if (DataGridTableStyle is not null) + { + return DataGridTableStyle.DataGrid.FontHeight; + } + else + { + return DataGridTableStyle.defaultFontHeight; + } + } + } + + /// + /// + /// Indicates whether the Font property should be persisted. + /// + /// + private bool ShouldSerializeFont() + { + return false; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler FontChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual string HeaderText + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler HeaderTextChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string MappingName + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler MappingNameChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + private bool ShouldSerializeHeaderText() + { + return (headerName.Length != 0); + } + + public void ResetHeaderText() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual string NullText + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler NullTextChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual bool ReadOnly + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ReadOnlyChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + +#if false + /// + /// + /// + /// Gets or sets a value indicating whether the column is visible. + /// + /// + [DefaultValue(true)] + public virtual bool Visible { + get { + return visible; + } + set { + if (visible == value) + return; + visible = value; + RaisePropertyChanged(EventArgs.Empty"Visible"); + Invalidate(); + } + } +#endif + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual int Width + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler WidthChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected void BeginUpdate() + { + updating = true; + } + + protected void EndUpdate() + { + updating = false; + if (invalid) + { + invalid = false; + Invalidate(); + } + } + + internal virtual bool WantArrows + { + get + { + return false; + } + } + + internal virtual string GetDisplayText(object value) + { + return value.ToString(); + } + + private void ResetNullText() + { + NullText = "SR.GetString(SR.DataGridNullText)"; + } + + private bool ShouldSerializeNullText() + { + return (!"SR.GetString(SR.DataGridNullText)".Equals(nullText)); + } + + protected internal abstract Size GetPreferredSize(Graphics g, object value); + + protected internal abstract int GetMinimumHeight(); + + protected internal abstract int GetPreferredHeight(Graphics g, object value); + + // PM team has reviewed and decided on naming changes already + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] + protected internal virtual object GetColumnValueAtRow(CurrencyManager source, int rowNum) + { + CheckValidDataSource(source); + if (PropertyDescriptor is null) + { + throw new InvalidOperationException("SR.GetString(SR.DataGridColumnNoPropertyDescriptor)"); + } + + object value = PropertyDescriptor.GetValue(source[rowNum]); + return value; + } + + protected virtual void Invalidate() + { + if (updating) + { + invalid = true; + return; + } + + DataGridTableStyle table = DataGridTableStyle; + if (table is not null) + table.InvalidateColumn(this); + } + + protected void CheckValidDataSource(CurrencyManager value) + { + if (value is null) + { + throw new ArgumentNullException("DataGridColumnStyle.CheckValidDataSource(DataSource value), value is null"); + } + + PropertyDescriptor myPropDesc = PropertyDescriptor; + if (myPropDesc is null) + { + throw new InvalidOperationException("SR.GetString(SR.DataGridColumnUnbound, HeaderText)"); + } + +#if false + DataTable myDataTable = myTable.DataTable; + if (myDataColumn.Table != myDataTable) { + throw new InvalidOperationException(SR.GetString(SR.DataGridColumnDataSourceMismatch, Header)); + } + + /* FOR DEMO: danielhe: DataGridColumnStyle::CheckValidDataSource: make the check better */ + if (((DataView) value.DataSource).Table is null) { + throw new InvalidOperationException(SR.GetString(SR.DataGridColumnNoDataTable, Header)); + } + else { + /* FOR DEMO: danielhe: DataGridColumnStyle::CheckValidDataSource: make the check better */ + if (!myTable.DataTable.Equals(((DataView) value.DataSource).Table)) { + throw new InvalidOperationException(SR.GetString(SR.DataGridColumnNoDataSource, Header, myTable.DataTable.TableName)); + } + } +#endif // false + } + + // PM team has reviewed and decided on naming changes already + protected internal abstract void Abort(int rowNum); + + // PM team has reviewed and decided on naming changes already + protected internal abstract bool Commit(CurrencyManager dataSource, int rowNum); + + protected internal virtual void Edit(CurrencyManager source, + int rowNum, + Rectangle bounds, + bool readOnly) + { + Edit(source, rowNum, bounds, readOnly, null, true); + } + + protected internal virtual void Edit(CurrencyManager source, + int rowNum, + Rectangle bounds, + bool readOnly, + string displayText) + { + Edit(source, rowNum, bounds, readOnly, displayText, true); + } + + protected internal abstract void Edit(CurrencyManager source, + int rowNum, + Rectangle bounds, + bool readOnly, + string displayText, + bool cellIsVisible); + + internal virtual bool MouseDown(int rowNum, int x, int y) + { + return false; + } + + protected internal virtual void EnterNullValue() + { + } + + internal virtual bool KeyPress(int rowNum, Keys keyData) + { + // if this is read only then do not do anything + if (ReadOnly || (DataGridTableStyle is not null && DataGridTableStyle.DataGrid is not null && DataGridTableStyle.DataGrid.ReadOnly)) + return false; + if (keyData == (Keys.Control | Keys.NumPad0) || keyData == (Keys.Control | Keys.D0)) + { + EnterNullValue(); + return true; + } + + return false; + } + + protected internal virtual void ConcedeFocus() + { + } + + protected internal abstract void Paint(Drawing.Graphics g1, Graphics g, Rectangle bounds, CurrencyManager source, int rowNum); + + protected internal abstract void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight); + + protected internal virtual void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, + Brush backBrush, Brush foreBrush, bool alignToRight) + { + Paint(g, bounds, source, rowNum, alignToRight); + } + + private void OnPropertyDescriptorChanged(EventArgs e) + { + EventHandler eh = Events[EventPropertyDescriptor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + private void OnAlignmentChanged(EventArgs e) + { + EventHandler eh = Events[EventAlignment] as EventHandler; + if (eh is not null) + eh(this, e); + } + + private void OnHeaderTextChanged(EventArgs e) + { + EventHandler eh = Events[EventHeaderText] as EventHandler; + if (eh is not null) + eh(this, e); + } + + private void OnMappingNameChanged(EventArgs e) + { + EventHandler eh = Events[EventMappingName] as EventHandler; + if (eh is not null) + eh(this, e); + } + + private void OnReadOnlyChanged(EventArgs e) + { + EventHandler eh = Events[EventReadOnly] as EventHandler; + if (eh is not null) + eh(this, e); + } + + private void OnNullTextChanged(EventArgs e) + { + EventHandler eh = Events[EventNullText] as EventHandler; + if (eh is not null) + eh(this, e); + } + + private void OnWidthChanged(EventArgs e) + { + EventHandler eh = Events[EventWidth] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected internal virtual void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) + { + CheckValidDataSource(source); + + if (source.Position != rowNum) + throw new ArgumentException("SR.GetString(SR.DataGridColumnListManagerPosition)"); + if (source[rowNum] is IEditableObject) + ((IEditableObject)source[rowNum]).BeginEdit(); + PropertyDescriptor.SetValue(source[rowNum], value); + } + + internal protected virtual void ColumnStartedEditing(Control editingControl) + { + DataGridTableStyle.DataGrid.ColumnStartedEditing(editingControl); + } + + void IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control editingControl) + { + ColumnStartedEditing(editingControl); + } + + protected internal virtual void ReleaseHostedControl() + { + } + + protected class CompModSwitches + { + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public static TraceSwitch DGEditColumnEditing + { + get + { + throw new PlatformNotSupportedException(); + } + } + } + + [Runtime.InteropServices.ComVisible(true)] + [Obsolete("DataGridColumnHeaderAccessibleObject has been deprecated.")] + protected class DataGridColumnHeaderAccessibleObject : AccessibleObject + { + public DataGridColumnHeaderAccessibleObject(DataGridColumnStyle owner) : this() + { + throw new PlatformNotSupportedException(); + } + + public DataGridColumnHeaderAccessibleObject() : base() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Rectangle Bounds + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Name + { + get + { + throw new PlatformNotSupportedException(); + } + } + + protected DataGridColumnStyle Owner + { + get; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleObject Parent + { + [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] + get + { + throw new PlatformNotSupportedException(); + } + } + + private DataGrid DataGrid + { + get; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleRole Role + { + get + { + throw new PlatformNotSupportedException(); + } + } + + public override AccessibleObject Navigate(AccessibleNavigation navdir) + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridLineStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridLineStyle.cs new file mode 100644 index 00000000000..85c9da6a1e8 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridLineStyle.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +[Obsolete("DataGridLineStyle has been deprecated.")] +public enum DataGridLineStyle +{ + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + None, + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Solid +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs new file mode 100644 index 00000000000..7c5d8da6c97 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs @@ -0,0 +1,1136 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; +using System.Text; + +namespace System.Windows.Forms; + +#nullable disable +[Obsolete("DataGridParentRows has been deprecated.")] +internal class DataGridParentRows +{ + // siting + private DataGrid dataGrid; + + private SolidBrush backBrush = DataGrid.DefaultParentRowsBackBrush; + private SolidBrush foreBrush = DataGrid.DefaultParentRowsForeBrush; + + private int borderWidth = 1; + // private Color borderColor = SystemColors.WindowFrame; + private Brush borderBrush = new SolidBrush(SystemColors.WindowFrame); + + private static Bitmap rightArrow; + private static Bitmap leftArrow; + + private ColorMap[] colorMap = [new ColorMap()]; + + private Pen gridLinePen = SystemPens.Control; + + private int totalHeight; + private int textRegionHeight; + + // now that we have left and right arrows, we also have layout + private Layout layout = new Layout(); + private bool downLeftArrow; + private bool downRightArrow; + + private int horizOffset; + + // storage for parent row states + // + private ArrayList parents = new ArrayList(); + private int parentsCount; + private ArrayList rowHeights = new ArrayList(); + + internal DataGridParentRows(DataGrid dataGrid) + { + colorMap[0].OldColor = Color.Black; + this.dataGrid = dataGrid; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public AccessibleObject AccessibleObject + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal Color BackColor + { + get + { + return backBrush.Color; + } + set + { + if (value.IsEmpty) + throw new ArgumentException("SR.GetString(SR.DataGridEmptyColor)"); + if (value != backBrush.Color) + { + backBrush = new SolidBrush(value); + Invalidate(); + } + } + } + + internal SolidBrush BackBrush + { + get + { + return backBrush; + } + set + { + if (value != backBrush) + { + CheckNull(value, "BackBrush"); + backBrush = value; + Invalidate(); + } + } + } + + internal SolidBrush ForeBrush + { + get + { + return foreBrush; + } + set + { + if (value != foreBrush) + { + CheckNull(value, "BackBrush"); + foreBrush = value; + Invalidate(); + } + } + } + + internal Rectangle GetBoundsForDataGridStateAccesibility(DataGridState dgs) + { + Rectangle ret = Rectangle.Empty; + int rectY = 0; + for (int i = 0; i < parentsCount; i++) + { + int height = (int)rowHeights[i]; + if (parents[i] == dgs) + { + ret.X = layout.leftArrow.IsEmpty ? layout.data.X : layout.leftArrow.Right; + ret.Height = height; + ret.Y = rectY; + ret.Width = layout.data.Width; + return ret; + } + + rectY += height; + } + + return ret; + } + + internal Brush BorderBrush + { + get + { + return borderBrush; + } + set + { + if (value != borderBrush) + { + borderBrush = value; + Invalidate(); + } + } + } + + internal int Height + { + get + { + return totalHeight; + } + } + + internal Color ForeColor + { + get + { + return foreBrush.Color; + } + set + { + if (value.IsEmpty) + throw new ArgumentException("SR.GetString(SR.DataGridEmptyColor)"); + if (value != foreBrush.Color) + { + foreBrush = new SolidBrush(value); + Invalidate(); + } + } + } + + internal bool Visible + { + get + { + return dataGrid.ParentRowsVisible; + } + set + { + dataGrid.ParentRowsVisible = value; + } + } + + internal void AddParent(DataGridState dgs) + { + CurrencyManager childDataSource = (CurrencyManager)dataGrid.BindingContext[dgs.DataSource, dgs.DataMember]; + parents.Add(dgs); + SetParentCount(parentsCount + 1); + Debug.Assert(GetTopParent() is not null, "we should have a parent at least"); + } + + internal void Clear() + { + for (int i = 0; i < parents.Count; i++) + { + DataGridState dgs = parents[i] as DataGridState; + dgs.RemoveChangeNotification(); + } + + parents.Clear(); + rowHeights.Clear(); + totalHeight = 0; + SetParentCount(0); + } + + internal void SetParentCount(int count) + { + parentsCount = count; + dataGrid.Caption.BackButtonVisible = (parentsCount > 0) && (dataGrid.AllowNavigation); + } + + internal void CheckNull(object value, string propName) + { + if (value is null) + throw new ArgumentNullException(); + } + + internal void Dispose() + { + gridLinePen.Dispose(); + } + + internal DataGridState GetTopParent() + { + if (parentsCount < 1) + { + return null; + } + + return (DataGridState)(((ICloneable)(parents[parentsCount - 1])).Clone()); + } + + internal bool IsEmpty() + { + return parentsCount == 0; + } + + internal DataGridState PopTop() + { + if (parentsCount < 1) + { + return null; + } + + SetParentCount(parentsCount - 1); + DataGridState ret = (DataGridState)parents[parentsCount]; + ret.RemoveChangeNotification(); + parents.RemoveAt(parentsCount); + return ret; + } + + internal void Invalidate() + { + if (dataGrid is not null) + dataGrid.InvalidateParentRows(); + } + + internal void InvalidateRect(Rectangle rect) + { + if (dataGrid is not null) + { + Rectangle r = new Rectangle(rect.X, rect.Y, rect.Width + borderWidth, rect.Height + borderWidth); + dataGrid.InvalidateParentRowsRect(r); + } + } + + internal void OnLayout() + { + if (parentsCount == rowHeights.Count) + return; + + int height = 0; + if (totalHeight == 0) + { + totalHeight += 2 * borderWidth; + } + + textRegionHeight = (int)dataGrid.Font.Height + 2; + + if (parentsCount > rowHeights.Count) + { + Debug.Assert(parentsCount == rowHeights.Count + 1 || rowHeights.Count == 0, "see bug 82808 for more info, or the comment above"); + int rowHeightsCount = rowHeights.Count; + for (int i = rowHeightsCount; i < parentsCount; i++) + { + DataGridState dgs = (DataGridState)parents[i]; + GridColumnStylesCollection cols = dgs.GridColumnStyles; + + int colsHeight = 0; + + for (int j = 0; j < cols.Count; j++) + { + colsHeight = Math.Max(colsHeight, cols[j].GetMinimumHeight()); + } + + height = Math.Max(colsHeight, textRegionHeight); + + // the height of the bottom border + height++; + rowHeights.Add(height); + + totalHeight += height; + } + } + else + { + Debug.Assert(parentsCount == rowHeights.Count - 1, "we do layout only for push/popTop"); + if (parentsCount == 0) + totalHeight = 0; + else + totalHeight -= (int)rowHeights[rowHeights.Count - 1]; + rowHeights.RemoveAt(rowHeights.Count - 1); + } + } + + private int CellCount() + { + int cellCount = 0; + cellCount = ColsCount(); + + if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.TableName || + dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) + { + cellCount++; + } + + return cellCount; + } + + private void ResetMouseInfo() + { + downLeftArrow = false; + downRightArrow = false; + } + + private void LeftArrowClick(int cellCount) + { + if (horizOffset > 0) + { + ResetMouseInfo(); + horizOffset -= 1; + Invalidate(); + } + else + { + ResetMouseInfo(); + InvalidateRect(layout.leftArrow); + } + } + + private void RightArrowClick(int cellCount) + { + if (horizOffset < cellCount - 1) + { + ResetMouseInfo(); + horizOffset += 1; + Invalidate(); + } + else + { + ResetMouseInfo(); + InvalidateRect(layout.rightArrow); + } + } + + internal void OnMouseDown(int x, int y, bool alignToRight) + { + if (layout.rightArrow.IsEmpty) + { + Debug.Assert(layout.leftArrow.IsEmpty, "we can't have the leftArrow w/o the rightArrow"); + return; + } + + int cellCount = CellCount(); + + if (layout.rightArrow.Contains(x, y)) + { + downRightArrow = true; + + if (alignToRight) + LeftArrowClick(cellCount); + else + RightArrowClick(cellCount); + } + else if (layout.leftArrow.Contains(x, y)) + { + downLeftArrow = true; + + if (alignToRight) + RightArrowClick(cellCount); + else + LeftArrowClick(cellCount); + } + else + { + if (downLeftArrow) + { + downLeftArrow = false; + InvalidateRect(layout.leftArrow); + } + + if (downRightArrow) + { + downRightArrow = false; + InvalidateRect(layout.rightArrow); + } + } + } + + internal void OnMouseLeave() + { + if (downLeftArrow) + { + downLeftArrow = false; + InvalidateRect(layout.leftArrow); + } + + if (downRightArrow) + { + downRightArrow = false; + InvalidateRect(layout.rightArrow); + } + } + + internal void OnMouseMove(int x, int y) + { + if (downLeftArrow) + { + downLeftArrow = false; + InvalidateRect(layout.leftArrow); + } + + if (downRightArrow) + { + downRightArrow = false; + InvalidateRect(layout.rightArrow); + } + } + + internal void OnMouseUp(int x, int y) + { + ResetMouseInfo(); + if (!layout.rightArrow.IsEmpty && layout.rightArrow.Contains(x, y)) + { + InvalidateRect(layout.rightArrow); + return; + } + + if (!layout.leftArrow.IsEmpty && layout.leftArrow.Contains(x, y)) + { + InvalidateRect(layout.leftArrow); + return; + } + } + + internal void OnResize(Rectangle oldBounds) + { + Invalidate(); + } + + internal void Paint(Graphics g, Rectangle visualbounds, bool alignRight) + { + Rectangle bounds = visualbounds; + // Paint the border around our bounds + if (borderWidth > 0) + { + PaintBorder(g, bounds); + bounds.Inflate(-borderWidth, -borderWidth); + } + + PaintParentRows(g, bounds, alignRight); + } + + private void PaintBorder(Graphics g, Rectangle bounds) + { + Rectangle border = bounds; + + // top + border.Height = borderWidth; + g.FillRectangle(borderBrush, border); + + // bottom + border.Y = bounds.Bottom - borderWidth; + g.FillRectangle(borderBrush, border); + + // left + border = new Rectangle(bounds.X, bounds.Y + borderWidth, + borderWidth, bounds.Height - 2 * borderWidth); + g.FillRectangle(borderBrush, border); + + // right + border.X = bounds.Right - borderWidth; + g.FillRectangle(borderBrush, border); + } + + private int GetTableBoxWidth(Graphics g, Font font) + { + // try to make the font BOLD + Font textFont = font; + try + { + textFont = new Font(font, FontStyle.Bold); + } + catch + { + } + + int width = 0; + for (int row = 0; row < parentsCount; row++) + { + DataGridState dgs = (DataGridState)parents[row]; + // Graphics.MeasureString(...) returns different results for ": " than for " :" + // + string displayTableName = dgs.ListManager.GetListName() + " :"; + int size = (int)g.MeasureString(displayTableName, textFont).Width; + width = Math.Max(size, width); + } + + return width; + } + + private int GetColBoxWidth(Graphics g, Font font, int colNum) + { + int width = 0; + + for (int row = 0; row < parentsCount; row++) + { + DataGridState dgs = (DataGridState)parents[row]; + GridColumnStylesCollection columns = dgs.GridColumnStyles; + if (colNum < columns.Count) + { + // Graphics.MeasureString(...) returns different results for ": " than for " :" + string colName = columns[colNum].HeaderText + " :"; + int size = (int)g.MeasureString(colName, font).Width; + width = Math.Max(size, width); + } + } + + return width; + } + + private int GetColDataBoxWidth(Graphics g, int colNum) + { + int width = 0; + for (int row = 0; row < parentsCount; row++) + { + DataGridState dgs = (DataGridState)parents[row]; + GridColumnStylesCollection columns = dgs.GridColumnStyles; + if (colNum < columns.Count) + { + object value = columns[colNum].GetColumnValueAtRow((CurrencyManager)dataGrid.BindingContext[dgs.DataSource, dgs.DataMember], + dgs.LinkingRow.RowNumber); + int size = columns[colNum].GetPreferredSize(g, value).Width; + width = Math.Max(size, width); + } + } + + return width; + } + + private int ColsCount() + { + int colNum = 0; + for (int row = 0; row < parentsCount; row++) + { + DataGridState dgs = (DataGridState)parents[row]; + colNum = Math.Max(colNum, dgs.GridColumnStyles.Count); + } + + return colNum; + } + + private int TotalWidth(int tableNameBoxWidth, int[] colsNameWidths, int[] colsDataWidths) + { + int totalWidth = 0; + totalWidth += tableNameBoxWidth; + Debug.Assert(colsNameWidths.Length == colsDataWidths.Length, "both arrays are as long as the largest column count in dgs"); + for (int i = 0; i < colsNameWidths.Length; i++) + { + totalWidth += colsNameWidths[i]; + totalWidth += colsDataWidths[i]; + } + + totalWidth += 3 * (colsNameWidths.Length - 1); + return totalWidth; + } + + private void ComputeLayout(Rectangle bounds, int tableNameBoxWidth, int[] colsNameWidths, int[] colsDataWidths) + { + int totalWidth = TotalWidth(tableNameBoxWidth, colsNameWidths, colsDataWidths); + if (totalWidth > bounds.Width) + { + layout.leftArrow = new Rectangle(bounds.X, bounds.Y, 15, bounds.Height); + layout.data = new Rectangle(layout.leftArrow.Right, bounds.Y, bounds.Width - 30, bounds.Height); + layout.rightArrow = new Rectangle(layout.data.Right, bounds.Y, 15, bounds.Height); + } + else + { + layout.data = bounds; + layout.leftArrow = Rectangle.Empty; + layout.rightArrow = Rectangle.Empty; + } + } + + private void PaintParentRows(Graphics g, Rectangle bounds, bool alignToRight) + { + int tableNameBoxWidth = 0; + int numCols = ColsCount(); + int[] colsNameWidths = new int[numCols]; + int[] colsDataWidths = new int[numCols]; + + if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.TableName || + dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) + { + tableNameBoxWidth = GetTableBoxWidth(g, dataGrid.Font); + } + + for (int i = 0; i < numCols; i++) + { + if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.ColumnName || + dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) + { + colsNameWidths[i] = GetColBoxWidth(g, dataGrid.Font, i); + } + else + { + colsNameWidths[i] = 0; + } + + colsDataWidths[i] = GetColDataBoxWidth(g, i); + } + + ComputeLayout(bounds, tableNameBoxWidth, colsNameWidths, colsDataWidths); + + if (!layout.leftArrow.IsEmpty) + { + g.FillRectangle(BackBrush, layout.leftArrow); + PaintLeftArrow(g, layout.leftArrow, alignToRight); + } + + Rectangle rowBounds = layout.data; + for (int row = 0; row < parentsCount; ++row) + { + rowBounds.Height = (int)rowHeights[row]; + if (rowBounds.Y > bounds.Bottom) + break; + int paintedWidth = PaintRow(g, rowBounds, row, dataGrid.Font, alignToRight, tableNameBoxWidth, colsNameWidths, colsDataWidths); + if (row == parentsCount - 1) + break; + + // draw the grid line below + g.DrawLine(gridLinePen, rowBounds.X, rowBounds.Bottom, + rowBounds.X + paintedWidth, + rowBounds.Bottom); + rowBounds.Y += rowBounds.Height; + } + + if (!layout.rightArrow.IsEmpty) + { + g.FillRectangle(BackBrush, layout.rightArrow); + PaintRightArrow(g, layout.rightArrow, alignToRight); + } + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] + private Bitmap GetBitmap(string bitmapName, Color transparentColor) + { + Bitmap b = null; + try + { + b = new Bitmap(typeof(DataGridParentRows), bitmapName); + b.MakeTransparent(transparentColor); + } + catch (Exception e) + { + Debug.Fail("Failed to load bitmap: " + bitmapName, e.ToString()); + } + + return b; + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + private Bitmap GetRightArrowBitmap() + { + if (rightArrow is null) + rightArrow = GetBitmap("DataGridParentRows.RightArrow.bmp", Color.White); + return rightArrow; + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + private Bitmap GetLeftArrowBitmap() + { + if (leftArrow is null) + leftArrow = GetBitmap("DataGridParentRows.LeftArrow.bmp", Color.White); + return leftArrow; + } + + private void PaintBitmap(Graphics g, Bitmap b, Rectangle bounds) + { + // center the bitmap in the bounds: + int bmpX = bounds.X + (bounds.Width - b.Width) / 2; + int bmpY = bounds.Y + (bounds.Height - b.Height) / 2; + Rectangle bmpRect = new Rectangle(bmpX, bmpY, b.Width, b.Height); + + g.FillRectangle(BackBrush, bmpRect); + + // now draw the bitmap + ImageAttributes attr = new ImageAttributes(); + colorMap[0].NewColor = ForeColor; + attr.SetRemapTable(colorMap, ColorAdjustType.Bitmap); + g.DrawImage(b, bmpRect, 0, 0, bmpRect.Width, bmpRect.Height, GraphicsUnit.Pixel, attr); + attr.Dispose(); + } + + private void PaintDownButton(Graphics g, Rectangle bounds) + { + g.DrawLine(Pens.Black, bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y); // the top + g.DrawLine(Pens.White, bounds.X + bounds.Width, bounds.Y, bounds.X + bounds.Width, bounds.Y + bounds.Height); // the right side + g.DrawLine(Pens.White, bounds.X + bounds.Width, bounds.Y + bounds.Height, bounds.X, bounds.Y + bounds.Height); // the right side + g.DrawLine(Pens.Black, bounds.X, bounds.Y + bounds.Height, bounds.X, bounds.Y); // the left side + } + + private void PaintLeftArrow(Graphics g, Rectangle bounds, bool alignToRight) + { + Bitmap bmp = GetLeftArrowBitmap(); + if (downLeftArrow) + { + PaintDownButton(g, bounds); + layout.leftArrow.Inflate(-1, -1); + lock (bmp) + { + PaintBitmap(g, bmp, bounds); + } + + layout.leftArrow.Inflate(1, 1); + } + else + { + lock (bmp) + { + PaintBitmap(g, bmp, bounds); + } + } + } + + private void PaintRightArrow(Graphics g, Rectangle bounds, bool alignToRight) + { + Bitmap bmp = GetRightArrowBitmap(); + if (downRightArrow) + { + PaintDownButton(g, bounds); + layout.rightArrow.Inflate(-1, -1); + lock (bmp) + { + PaintBitmap(g, bmp, bounds); + } + + layout.rightArrow.Inflate(1, 1); + } + else + { + lock (bmp) + { + PaintBitmap(g, bmp, bounds); + } + } + } + + private int PaintRow(Graphics g, Rectangle bounds, int row, Font font, bool alignToRight, + int tableNameBoxWidth, int[] colsNameWidths, int[] colsDataWidths) + { + DataGridState dgs = (DataGridState)parents[row]; + Rectangle paintBounds = bounds; + Rectangle rowBounds = bounds; + paintBounds.Height = (int)rowHeights[row]; + rowBounds.Height = (int)rowHeights[row]; + + int paintedWidth = 0; + // used for scrolling: when paiting, we will skip horizOffset cells in the dataGrid ParentRows + int skippedCells = 0; + + // paint the table name + if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.TableName || + dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) + { + if (skippedCells < horizOffset) + { + // skip this + skippedCells++; + } + else + { + paintBounds.Width = Math.Min(paintBounds.Width, tableNameBoxWidth); + paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); + string displayTableName = dgs.ListManager.GetListName() + ": "; + PaintText(g, paintBounds, displayTableName, font, true, alignToRight); // true is for painting bold + paintedWidth += paintBounds.Width; + } + } + + if (paintedWidth >= bounds.Width) + return bounds.Width; // we painted everything + + rowBounds.Width -= paintedWidth; + rowBounds.X += alignToRight ? 0 : paintedWidth; + paintedWidth += PaintColumns(g, rowBounds, dgs, font, alignToRight, colsNameWidths, colsDataWidths, skippedCells); + + // paint the possible space left after columns + if (paintedWidth < bounds.Width) + { + paintBounds.X = bounds.X + paintedWidth; + paintBounds.Width = bounds.Width - paintedWidth; + paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); + g.FillRectangle(BackBrush, paintBounds); + } + + return paintedWidth; + } + + private int PaintColumns(Graphics g, Rectangle bounds, DataGridState dgs, Font font, bool alignToRight, + int[] colsNameWidths, int[] colsDataWidths, int skippedCells) + { + Rectangle paintBounds = bounds; + Rectangle rowBounds = bounds; + GridColumnStylesCollection cols = dgs.GridColumnStyles; + int cx = 0; + + for (int i = 0; i < cols.Count; i++) + { + if (cx >= bounds.Width) + break; + + // paint the column name, if we have to + if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.ColumnName || + dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) + { + if (skippedCells < horizOffset) + { + // skip this column + } + else + { + paintBounds.X = bounds.X + cx; + paintBounds.Width = Math.Min(bounds.Width - cx, colsNameWidths[i]); + paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); + + string colName = cols[i].HeaderText + ": "; + PaintText(g, paintBounds, colName, font, false, alignToRight); // false is for not painting bold + + cx += paintBounds.Width; + } + } + + if (cx >= bounds.Width) + break; + + if (skippedCells < horizOffset) + { + // skip this cell + skippedCells++; + } + else + { + // paint the cell contents + paintBounds.X = bounds.X + cx; + paintBounds.Width = Math.Min(bounds.Width - cx, colsDataWidths[i]); + paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); + + // when we paint the data grid parent rows, we want to paint the data at the position + // stored in the currency manager. + cols[i].Paint(g, paintBounds, (CurrencyManager)dataGrid.BindingContext[dgs.DataSource, dgs.DataMember], + dataGrid.BindingContext[dgs.DataSource, dgs.DataMember].Position, BackBrush, ForeBrush, alignToRight); + + cx += paintBounds.Width; + + // draw the line to the right (or left, according to alignRight) + // + g.DrawLine(new Pen(SystemColors.ControlDark), + alignToRight ? paintBounds.X : paintBounds.Right, + paintBounds.Y, + alignToRight ? paintBounds.X : paintBounds.Right, + paintBounds.Bottom); + + // this is how wide the line is.... + cx++; + + // put 3 pixels in between columns + // see DonnaWa + // + if (i < cols.Count - 1) + { + paintBounds.X = bounds.X + cx; + paintBounds.Width = Math.Min(bounds.Width - cx, 3); + paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); + + g.FillRectangle(BackBrush, paintBounds); + cx += 3; + } + } + } + + return cx; + } + + private int PaintText(Graphics g, Rectangle textBounds, string text, Font font, bool bold, bool alignToRight) + { + Font textFont = font; + if (bold) + try + { + textFont = new Font(font, FontStyle.Bold); + } + catch { } + else + textFont = font; + + // right now, we paint the entire box, cause it will be used anyway + g.FillRectangle(BackBrush, textBounds); + StringFormat format = new StringFormat(); + if (alignToRight) + { + format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; + format.Alignment = StringAlignment.Far; + } + + format.FormatFlags |= StringFormatFlags.NoWrap; + // part 1, section 3: put the table and the column name in the + // parent rows at the same height as the dataGridTextBoxColumn draws the string + textBounds.Offset(0, 2); + textBounds.Height -= 2; + g.DrawString(text, textFont, ForeBrush, textBounds, format); + format.Dispose(); + return textBounds.Width; + } + + private int MirrorRect(Rectangle surroundingRect, Rectangle containedRect, bool alignToRight) + { + Debug.Assert(containedRect.X >= surroundingRect.X && containedRect.Right <= surroundingRect.Right, "containedRect is not contained in surroundingRect"); + if (alignToRight) + return surroundingRect.Right - containedRect.Right + surroundingRect.X; + else + return containedRect.X; + } + + private class Layout + { + public Rectangle data; + public Rectangle leftArrow; + public Rectangle rightArrow; + + public Layout() + { + data = Rectangle.Empty; + leftArrow = Rectangle.Empty; + rightArrow = Rectangle.Empty; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(200); + sb.Append("ParentRows Layout: \n"); + sb.Append("data = "); + sb.Append(data.ToString()); + sb.Append("\n leftArrow = "); + sb.Append(leftArrow.ToString()); + sb.Append("\n rightArrow = "); + sb.Append(rightArrow.ToString()); + sb.Append('\n'); + + return sb.ToString(); + } + } + + [ComVisible(true)] + [Obsolete("DataGridParentRowsAccessibleObject has been deprecated.")] + protected internal class DataGridParentRowsAccessibleObject : AccessibleObject + { + public DataGridParentRowsAccessibleObject(DataGridParentRows owner) : base() + { + throw new PlatformNotSupportedException(); + } + + internal DataGridParentRows Owner + { + get; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Rectangle Bounds + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string DefaultAction + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Name + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleObject Parent + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleRole Role + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleStates State + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Value + { + get + { + throw new PlatformNotSupportedException(); + } + } + + public override void DoDefaultAction() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject GetChild(int index) + { + throw new PlatformNotSupportedException(); + } + + public override int GetChildCount() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject GetFocused() + { + throw new PlatformNotSupportedException(); + } + + internal AccessibleObject GetNext(AccessibleObject child) + { + int children = GetChildCount(); + bool hit = false; + + for (int i = 0; i < children; i++) + { + if (hit) + { + return GetChild(i); + } + + if (GetChild(i) == child) + { + hit = true; + } + } + + return null; + } + + internal AccessibleObject GetPrev(AccessibleObject child) + { + int children = GetChildCount(); + bool hit = false; + + for (int i = children - 1; i >= 0; i--) + { + if (hit) + { + return GetChild(i); + } + + if (GetChild(i) == child) + { + hit = true; + } + } + + return null; + } + + public override AccessibleObject Navigate(AccessibleNavigation navdir) + { + throw new PlatformNotSupportedException(); + } + + public override void Select(AccessibleSelection flags) + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs new file mode 100644 index 00000000000..ceb306b73d9 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +[Obsolete("DataGridParentRowsLabelStyle has been deprecated.")] +public enum DataGridParentRowsLabelStyle +{ + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + None = 0, + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + TableName = 1, + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + ColumnName = 2, + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Both = 3, +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs new file mode 100644 index 00000000000..78c0f6a207c --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Globalization; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +[Obsolete("DataGridPreferredColumnWidthTypeConverter has been deprecated.")] +#nullable disable +public class DataGridPreferredColumnWidthTypeConverter : TypeConverter +{ + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => throw new PlatformNotSupportedException(); + + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) => throw new PlatformNotSupportedException(); + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) => throw new PlatformNotSupportedException(); +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs new file mode 100644 index 00000000000..185d50287aa --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs @@ -0,0 +1,776 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Security.Permissions; + +namespace System.Windows.Forms; + +#nullable disable +[Obsolete("DataGridRelationshipRow has been deprecated.")] +internal class DataGridRelationshipRow : DataGridRow +{ + private const bool defaultOpen = false; + private const int expandoBoxWidth = 14; + private bool expanded = defaultOpen; + + public DataGridRelationshipRow(DataGrid dataGrid, DataGridTableStyle dgTable, int rowNumber) + : base(dataGrid, dgTable, rowNumber) + { + throw new PlatformNotSupportedException(); + } + + internal protected override int MinimumRowHeight(GridColumnStylesCollection cols) + { + return base.MinimumRowHeight(cols) + (expanded ? GetRelationshipRect().Height : 0); + } + + internal protected override int MinimumRowHeight(DataGridTableStyle dgTable) + { + return base.MinimumRowHeight(dgTable) + (expanded ? GetRelationshipRect().Height : 0); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual bool Expanded + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + +#if FALSE + private int BorderWidth { + get { + DataGrid dataGrid = DataGrid; + if (dataGrid == null) + return 0; + // if the user set the GridLineStyle property on the dataGrid. + // then use the value of that property + DataGridLineStyle gridStyle; + int gridLineWidth; + if (dgTable.IsDefault) { + gridStyle = DataGrid.GridLineStyle; + gridLineWidth = DataGrid.GridLineWidth; + } else { + gridStyle = dgTable.GridLineStyle; + gridLineWidth = dgTable.GridLineWidth; + } + + if (gridStyle == DataGridLineStyle.None) + return 0; + + return gridLineWidth; + } + } +#endif //FALSE + + private int FocusedRelation + { + get + { + return dgTable.FocusedRelation; + } + set + { + dgTable.FocusedRelation = value; + } + } + + // =------------------------------------------------------------------ + // = Methods + // =------------------------------------------------------------------ + + private void Collapse() + { + Debug.Assert(dgTable.DataGrid.AllowNavigation, "how can the user collapse the relations if the grid does not allow navigation?"); + if (expanded) + { + expanded = false; + // relationshipRect = Rectangle.Empty; + FocusedRelation = -1; + DataGrid.OnRowHeightChanged(this); + } + } + + protected override AccessibleObject CreateAccessibleObject() + { + return new DataGridRelationshipRowAccessibleObject(this); + } + + private void Expand() + { + Debug.Assert(dgTable.DataGrid.AllowNavigation, "how can the user expand the relations if the grid does not allow navigation?"); + if (expanded == false + && DataGrid is not null + && dgTable is not null + && dgTable.RelationsList.Count > 0) + { + expanded = true; + FocusedRelation = -1; + + // relationshipRect = Rectangle.Empty; + DataGrid.OnRowHeightChanged(this); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override int Height + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + // so the edit box will not paint under the + // grid line of the row + public override Rectangle GetCellBounds(int col) + { + throw new PlatformNotSupportedException(); + } + + private Rectangle GetOutlineRect(int xOrigin, int yOrigin) + { + Rectangle outline = new Rectangle(xOrigin + 2, + yOrigin + 2, + 9, + 9); + return outline; + } + + public override Rectangle GetNonScrollableArea() + { + throw new PlatformNotSupportedException(); + } + + private Rectangle GetRelationshipRect() + { + Debug.Assert(expanded, "we should need this rectangle only when the row is expanded"); + Rectangle ret = dgTable.RelationshipRect; + ret.Y = base.Height - dgTable.BorderWidth; + return ret; + } + +#if FALSE + private Rectangle GetRelationshipRect() { + if (relationshipRect.IsEmpty) { + Debug.WriteLineIf(CompModSwitches.DGRelationShpRowLayout.TraceVerbose, "GetRelationshipRect grinding away"); + if (!expanded) { + return(relationshipRect = new Rectangle(0,0,0,0)); + } + Graphics g = DataGrid.CreateGraphicsInternal(); + relationshipRect = new Rectangle(); + relationshipRect.X = 0; //indentWidth; + relationshipRect.Y = base.Height - dgTable.BorderWidth; + + // Determine the width of the widest relationship name + int longestRelationship = 0; + for (int r = 0; r < dgTable.RelationsList.Count; ++r) { + int rwidth = (int) Math.Ceiling(g.MeasureString(((string) dgTable.RelationsList[r]), DataGrid.LinkFont).Width); + if (rwidth > longestRelationship) + longestRelationship = rwidth; + } + + g.Dispose(); + + relationshipRect.Width = longestRelationship + 5; + relationshipRect.Width += 2; // relationshipRect border; + relationshipRect.Height = dgTable.BorderWidth + relationshipHeight * dgTable.RelationsList.Count; + relationshipRect.Height += 2; // relationship border + if (dgTable.RelationsList.Count > 0) + relationshipRect.Height += 2 * System.Windows.Forms.DataGridTableStyle.relationshipSpacing; + } + return relationshipRect; + } + +#endif// FALSE + + private Rectangle GetRelationshipRectWithMirroring() + { + Rectangle relRect = GetRelationshipRect(); + bool rowHeadersVisible = dgTable.IsDefault ? DataGrid.RowHeadersVisible : dgTable.RowHeadersVisible; + if (rowHeadersVisible) + { + int rowHeaderWidth = dgTable.IsDefault ? DataGrid.RowHeaderWidth : dgTable.RowHeaderWidth; + relRect.X += DataGrid.GetRowHeaderRect().X + rowHeaderWidth; + } + + relRect.X = MirrorRelationshipRectangle(relRect, DataGrid.GetRowHeaderRect(), DataGrid.RightToLeft == RightToLeft.Yes); + return relRect; + } + + private bool PointOverPlusMinusGlyph(int x, int y, Rectangle rowHeaders, bool alignToRight) + { + if (dgTable is null || dgTable.DataGrid is null || !dgTable.DataGrid.AllowNavigation) + return false; + Rectangle insideRowHeaders = rowHeaders; + if (!DataGrid.FlatMode) + { + insideRowHeaders.Inflate(-1, -1); + } + + Rectangle outline = GetOutlineRect(insideRowHeaders.Right - expandoBoxWidth, 0); + + outline.X = MirrorRectangle(outline.X, outline.Width, insideRowHeaders, alignToRight); + + return outline.Contains(x, y); + } + + public override bool OnMouseDown(int x, int y, Rectangle rowHeaders, bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + public override bool OnMouseMove(int x, int y, Rectangle rowHeaders, bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + // this function will not invalidate all of the row + public override void OnMouseLeft(Rectangle rowHeaders, bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + public override void OnMouseLeft() + { + throw new PlatformNotSupportedException(); + } + + public override bool OnKeyPress(Keys keyData) + { + throw new PlatformNotSupportedException(); + } + + // will reset the FocusedRelation and will invalidate the + // rectangle so that the linkFont is no longer shown + internal override void LoseChildFocus(Rectangle rowHeaders, bool alignToRight) + { + // we only invalidate stuff if the row is expanded. + if (FocusedRelation == -1 || !expanded) + return; + + FocusedRelation = -1; + Rectangle relRect = GetRelationshipRect(); + relRect.X += rowHeaders.X + dgTable.RowHeaderWidth; + relRect.X = MirrorRelationshipRectangle(relRect, rowHeaders, alignToRight); + InvalidateRowRect(relRect); + } + + // here is the logic for FOCUSED: + // + // first the dataGrid gets the KeyPress. + // the dataGrid passes it to the currentRow. if it is anything other + // than Enter or TAB, the currentRow resets the FocusedRelation variable. + // + // Then the dataGrid takes another look at the TAB key and if it is the case + // it passes it to the row. If the dataRelationshipRow can become focused, + // then it eats the TAB key, otherwise it will give it back to the dataGrid. + // + internal override bool ProcessTabKey(Keys keyData, Rectangle rowHeaders, bool alignToRight) + { + Debug.Assert((keyData & Keys.Control) != Keys.Control, "the DataGridRelationshipRow only handles TAB and TAB-SHIFT"); + Debug.Assert((keyData & Keys.Alt) != Keys.Alt, "the DataGridRelationshipRow only handles TAB and TAB-SHIFT"); + + // if there are no relationships, this row can't do anything with the key + if (dgTable.RelationsList.Count == 0 || dgTable.DataGrid is null || !dgTable.DataGrid.AllowNavigation) + return false; + + // expand the relationship box + if (!expanded) + Expand(); + + if ((keyData & Keys.Shift) == Keys.Shift) + { + if (FocusedRelation == 0) + { + // if user hits TAB-SHIFT and the focus was on the first relationship then + // reset FocusedRelation and let the dataGrid use the key + // + // consider: DANIELHE: if the relationships box is expanded, should we collapse it on leave? + FocusedRelation = -1; + return false; + } + + // we need to invalidate the relationshipRectangle, and cause the linkFont to move + // to the next relation + Rectangle relRect = GetRelationshipRect(); + relRect.X += rowHeaders.X + dgTable.RowHeaderWidth; + relRect.X = MirrorRelationshipRectangle(relRect, rowHeaders, alignToRight); + InvalidateRowRect(relRect); + + if (FocusedRelation == -1) + // is the first time that the user focuses on this + // set of relationships + FocusedRelation = dgTable.RelationsList.Count - 1; + else + FocusedRelation--; + return true; + } + else + { + if (FocusedRelation == dgTable.RelationsList.Count - 1) + { + // if the user hits TAB and the focus was on the last relationship then + // reset FocusedRelation and let the dataGrid use the key + // + // consider: DANIELHE: if the relationships box is expanded, should we collapse it on leave? + FocusedRelation = -1; + return false; + } + + // we need to invalidate the relationshipRectangle, and cause the linkFont to move + // to the next relation + Rectangle relRect = GetRelationshipRect(); + relRect.X += rowHeaders.X + dgTable.RowHeaderWidth; + relRect.X = MirrorRelationshipRectangle(relRect, rowHeaders, alignToRight); + InvalidateRowRect(relRect); + + FocusedRelation++; + return true; + } + } + + public override int Paint(Graphics g, Rectangle bounds, Rectangle trueRowBounds, int firstVisibleColumn, int numVisibleColumns) + { + throw new PlatformNotSupportedException(); + } + + public override int Paint(Graphics g, + Rectangle bounds, // negative offsetted row bounds + Rectangle trueRowBounds, // real row bounds. + int firstVisibleColumn, + int numVisibleColumns, + bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + protected override void PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, + Brush backBr, Brush foreBrush, bool alignToRight) + { + CurrencyManager listManager = DataGrid.ListManager; + + // painting the error.. + // + string errString = string.Empty; + Rectangle bounds = cellBounds; + object errInfo = DataGrid.ListManager[number]; + if (errInfo is IDataErrorInfo) + errString = ((IDataErrorInfo)errInfo)[column.PropertyDescriptor.Name]; + + if (!string.IsNullOrEmpty(errString)) + { + Bitmap bmp = GetErrorBitmap(); + Rectangle errRect; + lock (bmp) + { + errRect = PaintIcon(g, bounds, true, alignToRight, bmp, backBr); + } + + // paint the errors correctly when RTL = true + if (alignToRight) + bounds.Width -= errRect.Width + xOffset; + else + bounds.X += errRect.Width + xOffset; + DataGridToolTip.AddToolTip(errString, (IntPtr)(DataGrid.ToolTipId++), errRect); + } + + column.Paint(g, bounds, listManager, RowNumber, backBr, foreBrush, alignToRight); + } + + public override void PaintHeader(Graphics g, Rectangle bounds, bool alignToRight, bool isDirty) + { + throw new PlatformNotSupportedException(); + } + + public void PaintHeaderInside(Graphics g, Rectangle bounds, Brush backBr, bool alignToRight, bool isDirty) + { + throw new PlatformNotSupportedException(); + } + + private void PaintRelations(Graphics g, Rectangle bounds, Rectangle trueRowBounds, + int dataWidth, int firstCol, int nCols, bool alignToRight) + { + // Calculate the relationship rect. + // relationshipRect = Rectangle.Empty; + Rectangle relRect = GetRelationshipRect(); + // relRect.Offset(trueRowBounds.X, trueRowBounds.Y); + relRect.X = alignToRight ? bounds.Right - relRect.Width : bounds.X; + relRect.Y = bounds.Y; + int paintedWidth = Math.Max(dataWidth, relRect.Width); + + // Paint the stuff to the right , or left (Bi-Di) of the relationship rect. + Region r = g.Clip; + g.ExcludeClip(relRect); + + g.FillRectangle(GetBackBrush(), + alignToRight ? bounds.Right - dataWidth : bounds.X, + bounds.Y, + dataWidth, + bounds.Height); + + // Paint the relations' text + g.SetClip(bounds); + + relRect.Height -= dgTable.BorderWidth; // use bWidth not 1 + g.DrawRectangle(SystemPens.ControlText, relRect.X, relRect.Y, relRect.Width - 1, relRect.Height - 1); + relRect.Inflate(-1, -1); + + int cy = PaintRelationText(g, relRect, alignToRight); + + if (cy < relRect.Height) + { + g.FillRectangle(GetBackBrush(), relRect.X, relRect.Y + cy, relRect.Width, relRect.Height - cy); + } + + g.Clip = r; + + // paint any exposed area to the right or to the left (BI-DI) + if (paintedWidth < bounds.Width) + { + int bWidth; + if (dgTable.IsDefault) + bWidth = DataGrid.GridLineWidth; + else + bWidth = dgTable.GridLineWidth; + g.FillRectangle(DataGrid.BackgroundBrush, + alignToRight ? bounds.X : bounds.X + paintedWidth, + bounds.Y, + bounds.Width - paintedWidth - bWidth + 1, // + 1 cause the relationship rectangle was deflated + bounds.Height); + + // Paint the border to the right of each cell + if (bWidth > 0) + { + Brush br; + // if the user changed the gridLineColor on the dataGrid + // from the defaultValue, then use that value; + if (dgTable.IsDefault) + br = DataGrid.GridLineBrush; + else + br = dgTable.GridLineBrush; + g.FillRectangle(br, + alignToRight ? bounds.Right - bWidth - paintedWidth : bounds.X + paintedWidth - bWidth, + bounds.Y, + bWidth, + bounds.Height); + } + } + } + + private int PaintRelationText(Graphics g, Rectangle bounds, bool alignToRight) + { + g.FillRectangle(GetBackBrush(), bounds.X, bounds.Y, bounds.Width, System.Windows.Forms.DataGridTableStyle.relationshipSpacing); + + int relationshipHeight = dgTable.RelationshipHeight; + Rectangle textBounds = new Rectangle(bounds.X, bounds.Y + System.Windows.Forms.DataGridTableStyle.relationshipSpacing, + bounds.Width, + relationshipHeight); + int cy = System.Windows.Forms.DataGridTableStyle.relationshipSpacing; + for (int r = 0; r < dgTable.RelationsList.Count; ++r) + { + if (cy > bounds.Height) + break; + + Brush textBrush = dgTable.IsDefault ? DataGrid.LinkBrush : dgTable.LinkBrush; + + Font textFont = DataGrid.Font; + textBrush = dgTable.IsDefault ? DataGrid.LinkBrush : dgTable.LinkBrush; + textFont = DataGrid.LinkFont; + + g.FillRectangle(GetBackBrush(), textBounds); + + StringFormat format = new StringFormat(); + if (alignToRight) + { + format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; + format.Alignment = StringAlignment.Far; + } + + g.DrawString(((string)dgTable.RelationsList[r]), textFont, textBrush, textBounds, + format); + if (r == FocusedRelation && number == DataGrid.CurrentCell.RowNumber) + { + textBounds.Width = dgTable.FocusedTextWidth; + ControlPaint.DrawFocusRectangle(g, textBounds, ((SolidBrush)textBrush).Color, ((SolidBrush)GetBackBrush()).Color); + textBounds.Width = bounds.Width; + } + + format.Dispose(); + + textBounds.Y += relationshipHeight; + cy += textBounds.Height; + } + + return cy; + } + + private void PaintPlusMinusGlyph(Graphics g, Rectangle bounds, Brush backBr, bool alignToRight) + { + if (CompModSwitches.DGRelationShpRowPaint.TraceVerbose) + Debug.WriteLine("PlusMinusGlyph painting in bounds -> " + bounds.ToString()); + Rectangle outline = GetOutlineRect(bounds.X, bounds.Y); + + outline = Rectangle.Intersect(bounds, outline); + if (outline.IsEmpty) + return; + + g.FillRectangle(backBr, bounds); + + if (CompModSwitches.DGRelationShpRowPaint.TraceVerbose) + Debug.WriteLine("Painting PlusMinusGlyph with outline -> " + outline.ToString()); + // draw the +/- box + Pen drawPen = dgTable.IsDefault ? DataGrid.HeaderForePen : dgTable.HeaderForePen; + g.DrawRectangle(drawPen, outline.X, outline.Y, outline.Width - 1, outline.Height - 1); + + int indent = 2; + // draw the - + g.DrawLine(drawPen, + outline.X + indent, outline.Y + outline.Width / 2, + outline.Right - indent - 1, outline.Y + outline.Width / 2); // -1 on the y coordinate + + if (!expanded) + { + // draw the vertical line to make + + g.DrawLine(drawPen, + outline.X + outline.Height / 2, outline.Y + indent, + outline.X + outline.Height / 2, outline.Bottom - indent - 1); // -1... hinting + } + else + { + Point[] points = new Point[3]; + points[0] = new Point(outline.X + outline.Height / 2, outline.Bottom); + + points[1] = new Point(points[0].X, bounds.Y + 2 * indent + base.Height); + + points[2] = new Point(alignToRight ? bounds.X : bounds.Right, + points[1].Y); + g.DrawLines(drawPen, points); + } + } + + private int RelationFromY(int y) + { + int relation = -1; + int relationshipHeight = dgTable.RelationshipHeight; + Rectangle relRect = GetRelationshipRect(); + int cy = base.Height - dgTable.BorderWidth + System.Windows.Forms.DataGridTableStyle.relationshipSpacing; + while (cy < relRect.Bottom) + { + if (cy > y) + break; + cy += relationshipHeight; + relation++; + } + + if (relation >= dgTable.RelationsList.Count) + return -1; + return relation; + } + + // given the relRect and the rowHeader, this function will return the + // X coordinate of the relationship rectangle as it should appear on the screen + private int MirrorRelationshipRectangle(Rectangle relRect, Rectangle rowHeader, bool alignToRight) + { + if (alignToRight) + return rowHeader.X - relRect.Width; + else + return relRect.X; + } + + // given the X and Width of a rectangle R1 contained in rect, + // this will return the X coordinate of the rectangle that corresponds to R1 in Bi-Di transformation + private int MirrorRectangle(int x, int width, Rectangle rect, bool alignToRight) + { + if (alignToRight) + return rect.Right + rect.X - width - x; + else + return x; + } + + [ComVisible(true)] + [Obsolete("DataGridRelationshipRowAccessibleObject has been deprecated.")] + protected class DataGridRelationshipRowAccessibleObject : DataGridRowAccessibleObject + { + public DataGridRelationshipRowAccessibleObject(DataGridRow owner) : base(owner) + { + throw new PlatformNotSupportedException(); + } + + protected override void AddChildAccessibleObjects(IList children) + { + base.AddChildAccessibleObjects(children); + DataGridRelationshipRow row = (DataGridRelationshipRow)Owner; + if (row.dgTable.RelationsList is not null) + { + for (int i = 0; i < row.dgTable.RelationsList.Count; i++) + { + children.Add(new DataGridRelationshipAccessibleObject(row, i)); + } + } + } + + private DataGridRelationshipRow RelationshipRow + { + get + { + return (DataGridRelationshipRow)Owner; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string DefaultAction + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleStates State + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] + public override void DoDefaultAction() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject GetFocused() + { + throw new PlatformNotSupportedException(); + } + } + + [ComVisible(true)] + [Obsolete("DataGridRelationshipAccessibleObject has been deprecated.")] + protected class DataGridRelationshipAccessibleObject : AccessibleObject + { + public DataGridRelationshipAccessibleObject(DataGridRelationshipRow owner, int relationship) : base() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Rectangle Bounds + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Name + { + get + { + throw new PlatformNotSupportedException(); + } + } + + protected DataGridRelationshipRow Owner + { + get; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleObject Parent + { + [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] + get + { + throw new PlatformNotSupportedException(); + } + } + + protected DataGrid DataGrid + { + get; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleRole Role + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleStates State + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Value + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string DefaultAction + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] + public override void DoDefaultAction() + { + throw new PlatformNotSupportedException(); + } + + private void ResetAccessibilityLayer() + { + ((DataGrid.DataGridAccessibleObject)DataGrid.AccessibilityObject).NotifyClients(AccessibleEvents.Reorder, 0); + ((DataGrid.DataGridAccessibleObject)DataGrid.AccessibilityObject).NotifyClients(AccessibleEvents.Focus, DataGrid.CurrentCellAccIndex); + ((DataGrid.DataGridAccessibleObject)DataGrid.AccessibilityObject).NotifyClients(AccessibleEvents.Selection, DataGrid.CurrentCellAccIndex); + } + + [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] + public override AccessibleObject Navigate(AccessibleNavigation navdir) + { + throw new PlatformNotSupportedException(); + } + + [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] + public override void Select(AccessibleSelection flags) + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs new file mode 100644 index 00000000000..e9376c49362 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs @@ -0,0 +1,682 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; + +namespace System.Windows.Forms; + +#nullable disable +[Obsolete("DataGridRow has been deprecated.")] +internal abstract class DataGridRow : MarshalByRefObject +{ + internal protected int number; + protected DataGridTableStyle dgTable; + + // we will be mapping only the black color to + // the HeaderForeColor + private static ColorMap[] colorMap = [new ColorMap()]; + + // bitmaps + private static Bitmap rightArrow; + private static Bitmap leftArrow; + private static Bitmap errorBmp; + private static Bitmap pencilBmp; + private static Bitmap starBmp; + protected const int xOffset = 3; + protected const int yOffset = 2; + + public DataGridRow(DataGrid dataGrid, DataGridTableStyle dgTable, int rowNumber) + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public AccessibleObject AccessibleObject + { + get + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual AccessibleObject CreateAccessibleObject() + { + return new DataGridRowAccessibleObject(this); + } + + internal protected virtual int MinimumRowHeight(DataGridTableStyle dgTable) + { + return MinimumRowHeight(dgTable.GridColumnStyles); + } + + internal protected virtual int MinimumRowHeight(GridColumnStylesCollection columns) + { + int h = dgTable.IsDefault ? DataGrid.PreferredRowHeight : dgTable.PreferredRowHeight; + + try + { + if (dgTable.DataGrid.DataSource is not null) + { + int nCols = columns.Count; + for (int i = 0; i < nCols; ++i) + { + // if (columns[i].Visible && columns[i].PropertyDescriptor is not null) + if (columns[i].PropertyDescriptor is not null) + h = Math.Max(h, columns[i].GetMinimumHeight()); + } + } + } + catch + { + } + + return h; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public DataGrid DataGrid + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal DataGridTableStyle DataGridTableStyle + { + get + { + return dgTable; + } + set + { + dgTable = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual int Height + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int RowNumber + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual bool Selected + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + protected Bitmap GetBitmap(string bitmapName) + { + Bitmap b = null; + try + { + b = new Bitmap(typeof(DataGridCaption), bitmapName); + b.MakeTransparent(); + } + catch (Exception e) + { + Debug.Fail("Failed to load bitmap: " + bitmapName, e.ToString()); + throw; + } + + return b; + } + + public virtual Rectangle GetCellBounds(int col) + { + throw new PlatformNotSupportedException(); + } + + public virtual Rectangle GetNonScrollableArea() + { + throw new PlatformNotSupportedException(); + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + protected Bitmap GetStarBitmap() + { + if (starBmp is null) + starBmp = GetBitmap("DataGridRow.star.bmp"); + return starBmp; + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + protected Bitmap GetPencilBitmap() + { + if (pencilBmp is null) + pencilBmp = GetBitmap("DataGridRow.pencil.bmp"); + return pencilBmp; + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + protected Bitmap GetErrorBitmap() + { + if (errorBmp is null) + errorBmp = GetBitmap("DataGridRow.error.bmp"); + errorBmp.MakeTransparent(); + return errorBmp; + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + protected Bitmap GetLeftArrowBitmap() + { + if (leftArrow is null) + leftArrow = GetBitmap("DataGridRow.left.bmp"); + return leftArrow; + } + + [ResourceExposure(ResourceScope.Machine)] + [ResourceConsumption(ResourceScope.Machine)] + protected Bitmap GetRightArrowBitmap() + { + if (rightArrow is null) + rightArrow = GetBitmap("DataGridRow.right.bmp"); + return rightArrow; + } + + public virtual void InvalidateRow() + { + throw new PlatformNotSupportedException(); + } + + public virtual void InvalidateRowRect(Rectangle r) + { + throw new PlatformNotSupportedException(); + } + + public virtual void OnEdit() + { + throw new PlatformNotSupportedException(); + } + + public virtual bool OnKeyPress(Keys keyData) + { + throw new PlatformNotSupportedException(); + } + + public virtual bool OnMouseDown(int x, int y, Rectangle rowHeaders) + { + throw new PlatformNotSupportedException(); + } + + public virtual bool OnMouseDown(int x, int y, Rectangle rowHeaders, bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + public virtual bool OnMouseMove(int x, int y, Rectangle rowHeaders) + { + throw new PlatformNotSupportedException(); + } + + public virtual bool OnMouseMove(int x, int y, Rectangle rowHeaders, bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + public virtual void OnMouseLeft(Rectangle rowHeaders, bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + public virtual void OnMouseLeft() + { + throw new PlatformNotSupportedException(); + } + + public virtual void OnRowEnter() + { + throw new PlatformNotSupportedException(); + } + + public virtual void OnRowLeave() + { + throw new PlatformNotSupportedException(); + } + + internal abstract bool ProcessTabKey(Keys keyData, Rectangle rowHeaders, bool alignToRight); + + internal abstract void LoseChildFocus(Rectangle rowHeaders, bool alignToRight); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public abstract int Paint(Graphics g, + Rectangle dataBounds, + Rectangle rowBounds, + int firstVisibleColumn, + int numVisibleColumns); + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public abstract int Paint(Graphics g, + Rectangle dataBounds, + Rectangle rowBounds, + int firstVisibleColumn, + int numVisibleColumns, + bool alignToRight); + + protected virtual void PaintBottomBorder(Graphics g, Rectangle bounds, int dataWidth) + { + PaintBottomBorder(g, bounds, dataWidth, dgTable.GridLineWidth, false); + } + + protected virtual void PaintBottomBorder(Graphics g, Rectangle bounds, int dataWidth, int borderWidth, bool alignToRight) + { + // paint bottom border + Rectangle bottomBorder = new Rectangle(alignToRight ? bounds.Right - dataWidth : bounds.X, + bounds.Bottom - borderWidth, + dataWidth, + borderWidth); + + g.FillRectangle(dgTable.IsDefault ? DataGrid.GridLineBrush : dgTable.GridLineBrush, bottomBorder); + + // paint any exposed region to the right + if (dataWidth < bounds.Width) + { + g.FillRectangle(dgTable.DataGrid.BackgroundBrush, + alignToRight ? bounds.X : bottomBorder.Right, + bottomBorder.Y, + bounds.Width - bottomBorder.Width, + borderWidth); + } + } + + public virtual int PaintData(Graphics g, + Rectangle bounds, + int firstVisibleColumn, + int columnCount) + { + throw new PlatformNotSupportedException(); + } + + public virtual int PaintData(Graphics g, + Rectangle bounds, + int firstVisibleColumn, + int columnCount, + bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + protected virtual void PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, + Brush backBr, Brush foreBrush) + { + PaintCellContents(g, cellBounds, column, backBr, foreBrush, false); + } + + protected virtual void PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, + Brush backBr, Brush foreBrush, bool alignToRight) + { + g.FillRectangle(backBr, cellBounds); + } + + protected Rectangle PaintIcon(Graphics g, Rectangle visualBounds, bool paintIcon, bool alignToRight, Bitmap bmp) + { + return PaintIcon(g, visualBounds, paintIcon, alignToRight, bmp, + dgTable.IsDefault ? DataGrid.HeaderBackBrush : dgTable.HeaderBackBrush); + } + + protected Rectangle PaintIcon(Graphics g, Rectangle visualBounds, bool paintIcon, bool alignToRight, Bitmap bmp, Brush backBrush) + { + Size bmpSize = bmp.Size; + Rectangle bmpRect = new Rectangle(alignToRight ? visualBounds.Right - xOffset - bmpSize.Width : visualBounds.X + xOffset, + visualBounds.Y + yOffset, + bmpSize.Width, + bmpSize.Height); + g.FillRectangle(backBrush, visualBounds); + if (paintIcon) + { + colorMap[0].NewColor = dgTable.IsDefault ? DataGrid.HeaderForeColor : dgTable.HeaderForeColor; + colorMap[0].OldColor = Color.Black; + ImageAttributes attr = new ImageAttributes(); + attr.SetRemapTable(colorMap, ColorAdjustType.Bitmap); + g.DrawImage(bmp, bmpRect, 0, 0, bmpRect.Width, bmpRect.Height, GraphicsUnit.Pixel, attr); + attr.Dispose(); + } + + return bmpRect; + } + + public virtual void PaintHeader(Graphics g, Rectangle visualBounds) + { + throw new PlatformNotSupportedException(); + } + + public virtual void PaintHeader(Graphics g, Rectangle visualBounds, bool alignToRight) + { + throw new PlatformNotSupportedException(); + } + + public virtual void PaintHeader(Graphics g, Rectangle visualBounds, bool alignToRight, bool rowIsDirty) + { + throw new PlatformNotSupportedException(); + } + + protected Brush GetBackBrush() + { + Brush br = dgTable.IsDefault ? DataGrid.BackBrush : dgTable.BackBrush; + if (DataGrid.LedgerStyle && (RowNumber % 2 == 1)) + { + br = dgTable.IsDefault ? DataGrid.AlternatingBackBrush : dgTable.AlternatingBackBrush; + } + + return br; + } + + protected Brush BackBrushForDataPaint(ref DataGridCell current, DataGridColumnStyle gridColumn, int column) + { + Brush backBr = GetBackBrush(); + + if (Selected) + { + backBr = dgTable.IsDefault ? DataGrid.SelectionBackBrush : dgTable.SelectionBackBrush; + } + + return backBr; + } + + protected Brush ForeBrushForDataPaint(ref DataGridCell current, DataGridColumnStyle gridColumn, int column) + { + Brush foreBrush = dgTable.IsDefault ? DataGrid.ForeBrush : dgTable.ForeBrush; + + if (Selected) + { + foreBrush = dgTable.IsDefault ? DataGrid.SelectionForeBrush : dgTable.SelectionForeBrush; + } + + return foreBrush; + } + + [ComVisible(true)] + [Obsolete("DataGridRowAccessibleObject has been deprecated.")] + protected class DataGridRowAccessibleObject : AccessibleObject + { + private ArrayList cells; + + internal static string CellToDisplayString(DataGrid grid, int row, int column) + { + if (column < grid.myGridTable.GridColumnStyles.Count) + { + return grid.myGridTable.GridColumnStyles[column].PropertyDescriptor.Converter.ConvertToString(grid[row, column]); + } + else + { + return ""; + } + } + + internal static object DisplayStringToCell(DataGrid grid, int row, int column, string value) + { + if (column < grid.myGridTable.GridColumnStyles.Count) + { + return grid.myGridTable.GridColumnStyles[column].PropertyDescriptor.Converter.ConvertFromString(value); + } + + return null; + } + + public DataGridRowAccessibleObject(DataGridRow owner) : base() + { + throw new PlatformNotSupportedException(); + } + + private void EnsureChildren() + { + if (cells is null) + { + cells = new ArrayList(DataGrid.myGridTable.GridColumnStyles.Count + 2); + AddChildAccessibleObjects(cells); + } + } + + protected virtual void AddChildAccessibleObjects(IList children) + { + Debug.WriteLineIf(DataGrid.DataGridAcc.TraceVerbose, "Create row's accessible children"); + Debug.Indent(); + GridColumnStylesCollection cols = DataGrid.myGridTable.GridColumnStyles; + int len = cols.Count; + Debug.WriteLineIf(DataGrid.DataGridAcc.TraceVerbose, len + " columns present"); + for (int i = 0; i < len; i++) + { + children.Add(CreateCellAccessibleObject(i)); + } + + Debug.Unindent(); + } + + protected virtual AccessibleObject CreateCellAccessibleObject(int column) + { + return new AccessibleObject(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Rectangle Bounds + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Name + { + get + { + throw new PlatformNotSupportedException(); + } + } + + protected DataGridRow Owner + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleObject Parent + { + get + { + throw new PlatformNotSupportedException(); + } + } + + private DataGrid DataGrid + { + get; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleRole Role + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleStates State + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Value + { + get + { + throw new PlatformNotSupportedException(); + } + } + + public override AccessibleObject GetChild(int index) + { + throw new PlatformNotSupportedException(); + } + + public override int GetChildCount() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject GetFocused() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject Navigate(AccessibleNavigation navdir) + { + throw new PlatformNotSupportedException(); + } + + public override void Select(AccessibleSelection flags) + { + throw new PlatformNotSupportedException(); + } + } + + [ComVisible(true)] + [Obsolete("DataGridCellAccessibleObject has been deprecated.")] + protected class DataGridCellAccessibleObject : AccessibleObject + { + public DataGridCellAccessibleObject(DataGridRow owner, int column) : base() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Rectangle Bounds + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Name + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleObject Parent + { + get + { + throw new PlatformNotSupportedException(); + } + } + + protected DataGrid DataGrid + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string DefaultAction + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleRole Role + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleStates State + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Value + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + public override void DoDefaultAction() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject GetFocused() + { + throw new PlatformNotSupportedException(); + } + + public override AccessibleObject Navigate(AccessibleNavigation navdir) + { + throw new PlatformNotSupportedException(); + } + + public override void Select(AccessibleSelection flags) + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs new file mode 100644 index 00000000000..10ff0f5a820 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs @@ -0,0 +1,153 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace System.Windows.Forms; + +#nullable disable +[Obsolete("DataGridState is obsolete. Use the DataGrid control and the System.Windows.Forms.DataGridView control instead.")] +internal sealed class DataGridState : ICloneable +{ + public object DataSource; + public string DataMember; + public CurrencyManager ListManager; + public DataGridRow[] DataGridRows = Array.Empty(); + public DataGrid DataGrid; + public int DataGridRowsLength; + public GridColumnStylesCollection GridColumnStyles; + + public int FirstVisibleRow; + public int FirstVisibleCol; + + public int CurrentRow; + public int CurrentCol; + + public DataGridRow LinkingRow; + private AccessibleObject parentRowAccessibleObject; + + public DataGridState() + { + throw new PlatformNotSupportedException(); + } + + public DataGridState(DataGrid dataGrid) + { + throw new PlatformNotSupportedException(); + } + + internal AccessibleObject ParentRowAccessibleObject + { + get + { + if (parentRowAccessibleObject is null) + { + parentRowAccessibleObject = new DataGridStateParentRowAccessibleObject(this); + } + + return parentRowAccessibleObject; + } + } + + public object Clone() + { + throw new PlatformNotSupportedException(); + } + + public void PushState(DataGrid dataGrid) + { + throw new PlatformNotSupportedException(); + } + + public void RemoveChangeNotification() + { + throw new PlatformNotSupportedException(); + } + + public void PullState(DataGrid dataGrid, bool createColumn) + { + throw new PlatformNotSupportedException(); + } + + private void DataSource_Changed(object sender, ItemChangedEventArgs e) + { + if (DataGrid is not null && ListManager.Position == e.Index) + { + DataGrid.InvalidateParentRows(); + return; + } + + if (DataGrid is not null) + DataGrid.ParentRowsDataChanged(); + } + + private void DataSource_MetaDataChanged(object sender, EventArgs e) + { + if (DataGrid is not null) + { + DataGrid.ParentRowsDataChanged(); + } + } + + [ComVisible(true)] + internal class DataGridStateParentRowAccessibleObject : AccessibleObject + { + public DataGridStateParentRowAccessibleObject(DataGridState owner) : base() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Rectangle Bounds + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Name + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleObject Parent + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleRole Role + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Value + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleObject Navigate(AccessibleNavigation navdir) + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs new file mode 100644 index 00000000000..733451fbcac --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs @@ -0,0 +1,1369 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.Drawing; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("DataGridTableStyle has been deprecated.")] +public class DataGridTableStyle : Component, IDataGridEditingService +{ + internal DataGrid dataGrid; + + // relationship UI + private int relationshipHeight; + internal const int relationshipSpacing = 1; + private Rectangle relationshipRect = Rectangle.Empty; + private int focusedRelation = -1; + private int focusedTextWidth; + + // will contain a list of relationships that this table has + private ArrayList relationsList = new ArrayList(2); + + private static readonly object EventAllowSorting = new object(); + private static readonly object EventGridLineColor = new object(); + private static readonly object EventGridLineStyle = new object(); + private static readonly object EventHeaderBackColor = new object(); + private static readonly object EventHeaderForeColor = new object(); + private static readonly object EventHeaderFont = new object(); + private static readonly object EventLinkColor = new object(); + private static readonly object EventLinkHoverColor = new object(); + private static readonly object EventPreferredColumnWidth = new object(); + private static readonly object EventPreferredRowHeight = new object(); + private static readonly object EventColumnHeadersVisible = new object(); + private static readonly object EventRowHeaderWidth = new object(); + private static readonly object EventSelectionBackColor = new object(); + private static readonly object EventSelectionForeColor = new object(); + private static readonly object EventMappingName = new object(); + private static readonly object EventAlternatingBackColor = new object(); + private static readonly object EventBackColor = new object(); + private static readonly object EventForeColor = new object(); + private static readonly object EventReadOnly = new object(); + private static readonly object EventRowHeadersVisible = new object(); + private const int defaultPreferredColumnWidth = 75; + internal static readonly Font defaultFont = Control.DefaultFont; + internal static readonly int defaultFontHeight = defaultFont.Height; + private SolidBrush alternatingBackBrush = DefaultAlternatingBackBrush; + private SolidBrush backBrush = DefaultBackBrush; + private SolidBrush foreBrush = DefaultForeBrush; + private SolidBrush gridLineBrush = DefaultGridLineBrush; + internal SolidBrush headerBackBrush = DefaultHeaderBackBrush; + internal Font headerFont; // this is ambient property to Font value. + internal SolidBrush headerForeBrush = DefaultHeaderForeBrush; + internal Pen headerForePen = DefaultHeaderForePen; + private SolidBrush linkBrush = DefaultLinkBrush; + internal int preferredColumnWidth = defaultPreferredColumnWidth; + private int prefferedRowHeight = defaultFontHeight + 3; + private SolidBrush selectionBackBrush = DefaultSelectionBackBrush; + private SolidBrush selectionForeBrush = DefaultSelectionForeBrush; + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool AllowSorting + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler AllowSortingChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color AlternatingBackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler AlternatingBackColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public void ResetAlternatingBackColor() + { + throw new PlatformNotSupportedException(); + } + + protected virtual bool ShouldSerializeAlternatingBackColor() + { + return !AlternatingBackBrush.Equals(DefaultAlternatingBackBrush); + } + + internal SolidBrush AlternatingBackBrush + { + get + { + return alternatingBackBrush; + } + } + + protected bool ShouldSerializeBackColor() + { + return !DefaultBackBrush.Equals(backBrush); + } + + protected bool ShouldSerializeForeColor() + { + return DefaultForeBrush.Equals(foreBrush); + } + + internal SolidBrush BackBrush + { + get + { + return backBrush; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color BackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler BackColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + public void ResetBackColor() + { + throw new PlatformNotSupportedException(); + } + + internal int BorderWidth + { + get + { + DataGrid dataGrid = DataGrid; + if (dataGrid is null) + return 0; + // if the user set the GridLineStyle property on the dataGrid. + // then use the value of that property + DataGridLineStyle gridStyle; + int gridLineWidth; + if (IsDefault) + { + gridStyle = DataGrid.GridLineStyle; + gridLineWidth = DataGrid.GridLineWidth; + } + else + { + gridStyle = GridLineStyle; + gridLineWidth = GridLineWidth; + } + + if (gridStyle == DataGridLineStyle.None) + return 0; + + return gridLineWidth; + } + } + + internal static SolidBrush DefaultAlternatingBackBrush + { + get + { + return (SolidBrush)SystemBrushes.Window; + } + } + + internal static SolidBrush DefaultBackBrush + { + get + { + return (SolidBrush)SystemBrushes.Window; + } + } + + internal static SolidBrush DefaultForeBrush + { + get + { + return (SolidBrush)SystemBrushes.WindowText; + } + } + + private static SolidBrush DefaultGridLineBrush + { + get + { + return (SolidBrush)SystemBrushes.Control; + } + } + + private static SolidBrush DefaultHeaderBackBrush + { + get + { + return (SolidBrush)SystemBrushes.Control; + } + } + + private static SolidBrush DefaultHeaderForeBrush + { + get + { + return (SolidBrush)SystemBrushes.ControlText; + } + } + + private static Pen DefaultHeaderForePen + { + get + { + return new Pen(SystemColors.ControlText); + } + } + + private static SolidBrush DefaultLinkBrush + { + get + { + return (SolidBrush)SystemBrushes.HotTrack; + } + } + + private static SolidBrush DefaultSelectionBackBrush + { + get + { + return (SolidBrush)SystemBrushes.ActiveCaption; + } + } + + private static SolidBrush DefaultSelectionForeBrush + { + get + { + return (SolidBrush)SystemBrushes.ActiveCaptionText; + } + } + + internal int FocusedRelation + { + get + { + return focusedRelation; + } + set + { + if (focusedRelation != value) + { + focusedRelation = value; + if (focusedRelation == -1) + { + focusedTextWidth = 0; + } + else + { + Graphics g = DataGrid.CreateGraphicsInternal(); + focusedTextWidth = (int)Math.Ceiling(g.MeasureString(((string)RelationsList[focusedRelation]), DataGrid.LinkFont).Width); + g.Dispose(); + } + } + } + } + + internal int FocusedTextWidth + { + get + { + return focusedTextWidth; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color ForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ForeColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + internal SolidBrush ForeBrush + { + get + { + return foreBrush; + } + } + + public void ResetForeColor() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color GridLineColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler GridLineColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual bool ShouldSerializeGridLineColor() + { + return !GridLineBrush.Equals(DefaultGridLineBrush); + } + + public void ResetGridLineColor() + { + throw new PlatformNotSupportedException(); + } + + internal SolidBrush GridLineBrush + { + get + { + return gridLineBrush; + } + } + + internal int GridLineWidth + { + get + { + Debug.Assert(GridLineStyle == DataGridLineStyle.Solid || GridLineStyle == DataGridLineStyle.None, "are there any other styles?"); + return GridLineStyle == DataGridLineStyle.Solid ? 1 : 0; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public DataGridLineStyle GridLineStyle + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler GridLineStyleChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color HeaderBackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler HeaderBackColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + internal SolidBrush HeaderBackBrush + { + get + { + return headerBackBrush; + } + } + + protected virtual bool ShouldSerializeHeaderBackColor() + { + return !HeaderBackBrush.Equals(DefaultHeaderBackBrush); + } + + public void ResetHeaderBackColor() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Font HeaderFont + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler HeaderFontChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + private bool ShouldSerializeHeaderFont() + { + return (headerFont is not null); + } + + public void ResetHeaderFont() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color HeaderForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler HeaderForeColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual bool ShouldSerializeHeaderForeColor() + { + return !HeaderForePen.Equals(DefaultHeaderForePen); + } + + public void ResetHeaderForeColor() + { + throw new PlatformNotSupportedException(); + } + + internal SolidBrush HeaderForeBrush + { + get + { + return headerForeBrush; + } + } + + internal Pen HeaderForePen + { + get + { + return headerForePen; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color LinkColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler LinkColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual bool ShouldSerializeLinkColor() + { + return !LinkBrush.Equals(DefaultLinkBrush); + } + + public void ResetLinkColor() + { + throw new PlatformNotSupportedException(); + } + + internal Brush LinkBrush + { + get + { + return linkBrush; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color LinkHoverColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler LinkHoverColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual bool ShouldSerializeLinkHoverColor() + { + return false; + } + + internal Rectangle RelationshipRect + { + get + { + if (relationshipRect.IsEmpty) + { + ComputeRelationshipRect(); + } + + return relationshipRect; + } + } + + private Rectangle ComputeRelationshipRect() + { + if (relationshipRect.IsEmpty && DataGrid.AllowNavigation) + { + Debug.WriteLineIf(CompModSwitches.DGRelationShpRowLayout.TraceVerbose, "GetRelationshipRect grinding away"); + Graphics g = DataGrid.CreateGraphicsInternal(); + relationshipRect = default(Rectangle); + relationshipRect.X = 0; // indentWidth; + // relationshipRect.Y = base.Height - BorderWidth; + + // Determine the width of the widest relationship name + int longestRelationship = 0; + for (int r = 0; r < RelationsList.Count; ++r) + { + int rwidth = (int)Math.Ceiling(g.MeasureString(((string)RelationsList[r]), DataGrid.LinkFont).Width) +; + if (rwidth > longestRelationship) + longestRelationship = rwidth; + } + + g.Dispose(); + + relationshipRect.Width = longestRelationship + 5; + relationshipRect.Width += 2; // relationshipRect border; + relationshipRect.Height = BorderWidth + relationshipHeight * RelationsList.Count; + relationshipRect.Height += 2; // relationship border + if (RelationsList.Count > 0) + relationshipRect.Height += 2 * relationshipSpacing; + } + + return relationshipRect; + } + + internal void ResetRelationsUI() + { + relationshipRect = Rectangle.Empty; + focusedRelation = -1; + relationshipHeight = dataGrid.LinkFontHeight + relationshipSpacing; + } + + internal int RelationshipHeight + { + get + { + return relationshipHeight; + } + } + + public void ResetLinkHoverColor() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int PreferredColumnWidth + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler PreferredColumnWidthChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int PreferredRowHeight + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler PreferredRowHeightChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + private void ResetPreferredRowHeight() + { + PreferredRowHeight = defaultFontHeight + 3; + } + + protected bool ShouldSerializePreferredRowHeight() + { + return prefferedRowHeight != defaultFontHeight + 3; + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool ColumnHeadersVisible + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ColumnHeadersVisibleChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool RowHeadersVisible + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler RowHeadersVisibleChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int RowHeaderWidth + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler RowHeaderWidthChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color SelectionBackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler SelectionBackColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + internal SolidBrush SelectionBackBrush + { + get + { + return selectionBackBrush; + } + } + + internal SolidBrush SelectionForeBrush + { + get + { + return selectionForeBrush; + } + } + + protected bool ShouldSerializeSelectionBackColor() + { + return !DefaultSelectionBackBrush.Equals(selectionBackBrush); + } + + public void ResetSelectionBackColor() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Color SelectionForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler SelectionForeColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected virtual bool ShouldSerializeSelectionForeColor() + { + return !SelectionForeBrush.Equals(DefaultSelectionForeBrush); + } + + public void ResetSelectionForeColor() + { + throw new PlatformNotSupportedException(); + } + + private void InvalidateInside() + { + if (DataGrid is not null) + { + DataGrid.InvalidateInside(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public static readonly DataGridTableStyle DefaultTableStyle = new DataGridTableStyle(true); + + public DataGridTableStyle(bool isDefaultTableStyle) + { + throw new PlatformNotSupportedException(); + } + + public DataGridTableStyle() : this(false) + { + throw new PlatformNotSupportedException(); + } + + public DataGridTableStyle(CurrencyManager listManager) : this() + { + throw new PlatformNotSupportedException(); + } + + internal void SetRelationsList(CurrencyManager listManager) + { + PropertyDescriptorCollection propCollection = listManager.GetItemProperties(); + Debug.Assert(!IsDefault, "the grid can set the relations only on a table that was manually added by the user"); + int propCount = propCollection.Count; + if (relationsList.Count > 0) + relationsList.Clear(); + for (int i = 0; i < propCount; i++) + { + PropertyDescriptor prop = propCollection[i]; + Debug.Assert(prop is not null, "prop is null: how that happened?"); + if (PropertyDescriptorIsARelation(prop)) + { + // relation + relationsList.Add(prop.Name); + } + } + } + + internal void SetGridColumnStylesCollection(CurrencyManager listManager) + { + PropertyDescriptorCollection propCollection = listManager.GetItemProperties(); + + // we need to clear the relations list + if (relationsList.Count > 0) + relationsList.Clear(); + + Debug.Assert(propCollection is not null, "propCollection is null: how that happened?"); + int propCount = propCollection.Count; + for (int i = 0; i < propCount; i++) + { + PropertyDescriptor prop = propCollection[i]; + Debug.Assert(prop is not null, "prop is null: how that happened?"); + // do not take into account the properties that are browsable. + if (!prop.IsBrowsable) + continue; + if (PropertyDescriptorIsARelation(prop)) + { + // relation + relationsList.Add(prop.Name); + } + else + { + // column + DataGridColumnStyle col = CreateGridColumn(prop); + } + } + } + + private static bool PropertyDescriptorIsARelation(PropertyDescriptor prop) + { + return typeof(IList).IsAssignableFrom(prop.PropertyType) && !typeof(Array).IsAssignableFrom(prop.PropertyType); + } + + internal protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop) + { + return CreateGridColumn(prop, false); + } + + internal protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop, bool isDefault) + { + DataGridColumnStyle ret = null; + Type dataType = prop.PropertyType; + + if (dataType.Equals(typeof(bool))) + ret = new DataGridBoolColumn(prop, isDefault); + else if (dataType.Equals(typeof(string))) + ret = new DataGridTextBoxColumn(prop, isDefault); + else if (dataType.Equals(typeof(DateTime))) + ret = new DataGridTextBoxColumn(prop, "d", isDefault); + + else if (dataType.Equals(typeof(short)) || + dataType.Equals(typeof(int)) || + dataType.Equals(typeof(long)) || + dataType.Equals(typeof(ushort)) || + dataType.Equals(typeof(uint)) || + dataType.Equals(typeof(ulong)) || + dataType.Equals(typeof(decimal)) || + dataType.Equals(typeof(double)) || + dataType.Equals(typeof(float)) || + dataType.Equals(typeof(byte)) || + dataType.Equals(typeof(sbyte))) + { + ret = new DataGridTextBoxColumn(prop, "G", isDefault); + } + else + { + ret = new DataGridTextBoxColumn(prop, isDefault); + } + + return ret; + } + + internal void ResetRelationsList() + { + relationsList.Clear(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string MappingName + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler MappingNameChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + internal ArrayList RelationsList + { + get + { + return relationsList; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual GridColumnStylesCollection GridColumnStyles + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal void SetInternalDataGrid(DataGrid dG, bool force) + { + if (dataGrid is not null && dataGrid.Equals(dG) && !force) + return; + else + { + dataGrid = dG; + if (dG is not null && dG.Initializing) + return; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual DataGrid DataGrid + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual bool ReadOnly + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ReadOnlyChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) + { + throw new PlatformNotSupportedException(); + } + + public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) + { + throw new PlatformNotSupportedException(); + } + + internal void InvalidateColumn(DataGridColumnStyle column) + { + int index = GridColumnStyles.IndexOf(column); + if (index >= 0 && DataGrid is not null) + DataGrid.InvalidateColumn(index); + } + + private void OnColumnCollectionChanged(object sender, CollectionChangeEventArgs e) + { + try + { + DataGrid grid = DataGrid; + DataGridColumnStyle col = e.Element as DataGridColumnStyle; + if (e.Action == CollectionChangeAction.Add) + { + if (col is not null) + col.SetDataGridInternalInColumn(grid); + } + else if (e.Action == CollectionChangeAction.Remove) + { + if (col is not null) + col.SetDataGridInternalInColumn(null); + } + else + { + // refresh + Debug.Assert(e.Action == CollectionChangeAction.Refresh, "there are only Add, Remove and Refresh in the CollectionChangeAction"); + } + + if (grid is not null) + grid.OnColumnCollectionChanged(this, e); + } + finally + { + } + } + + protected virtual void OnReadOnlyChanged(EventArgs e) + { + EventHandler eh = Events[EventReadOnly] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnMappingNameChanged(EventArgs e) + { + EventHandler eh = Events[EventMappingName] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnAlternatingBackColorChanged(EventArgs e) + { + EventHandler eh = Events[EventAlternatingBackColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnForeColorChanged(EventArgs e) + { + EventHandler eh = Events[EventBackColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnBackColorChanged(EventArgs e) + { + EventHandler eh = Events[EventForeColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnAllowSortingChanged(EventArgs e) + { + EventHandler eh = Events[EventAllowSorting] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnGridLineColorChanged(EventArgs e) + { + EventHandler eh = Events[EventGridLineColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnGridLineStyleChanged(EventArgs e) + { + EventHandler eh = Events[EventGridLineStyle] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnHeaderBackColorChanged(EventArgs e) + { + EventHandler eh = Events[EventHeaderBackColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnHeaderFontChanged(EventArgs e) + { + EventHandler eh = Events[EventHeaderFont] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnHeaderForeColorChanged(EventArgs e) + { + EventHandler eh = Events[EventHeaderForeColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnLinkColorChanged(EventArgs e) + { + EventHandler eh = Events[EventLinkColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnLinkHoverColorChanged(EventArgs e) + { + EventHandler eh = Events[EventLinkHoverColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnPreferredRowHeightChanged(EventArgs e) + { + EventHandler eh = Events[EventPreferredRowHeight] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnPreferredColumnWidthChanged(EventArgs e) + { + EventHandler eh = Events[EventPreferredColumnWidth] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnColumnHeadersVisibleChanged(EventArgs e) + { + EventHandler eh = Events[EventColumnHeadersVisible] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnRowHeadersVisibleChanged(EventArgs e) + { + EventHandler eh = Events[EventRowHeadersVisible] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnRowHeaderWidthChanged(EventArgs e) + { + EventHandler eh = Events[EventRowHeaderWidth] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnSelectionForeColorChanged(EventArgs e) + { + EventHandler eh = Events[EventSelectionForeColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected virtual void OnSelectionBackColorChanged(EventArgs e) + { + EventHandler eh = Events[EventSelectionBackColor] as EventHandler; + if (eh is not null) + eh(this, e); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + GridColumnStylesCollection cols = GridColumnStyles; + if (cols is not null) + { + for (int i = 0; i < cols.Count; i++) + cols[i].Dispose(); + } + } + + base.Dispose(disposing); + } + + internal bool IsDefault + { + get; + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs new file mode 100644 index 00000000000..d4840618b99 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs @@ -0,0 +1,188 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("GridTableStylesCollection has been deprecated.")] +public class GridTableStylesCollection : BaseCollection, IList +{ + private DataGrid owner; + + int IList.Add(object value) + { + return Add((DataGridTableStyle)value); + } + + void IList.Clear() + { + Clear(); + } + + bool IList.Contains(object value) + { + return default; + } + + int IList.IndexOf(object value) + { + return default; + } + + void IList.Insert(int index, object value) + { + throw new NotSupportedException(); + } + + void IList.Remove(object value) + { + Remove((DataGridTableStyle)value); + } + + void IList.RemoveAt(int index) + { + RemoveAt(index); + } + + bool IList.IsFixedSize + { + get { return false; } + } + + bool IList.IsReadOnly + { + get { return false; } + } + + object IList.this[int index] + { + get { return default; } + set { throw new NotSupportedException(); } + } + + void ICollection.CopyTo(Array array, int index) + { + } + + int ICollection.Count + { + get { return default; } + } + + bool ICollection.IsSynchronized + { + get { return false; } + } + + object ICollection.SyncRoot + { + get { return this; } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return default; + } + + internal GridTableStylesCollection(DataGrid grid) + { + owner = grid; + } + + protected override ArrayList List + { + get + { + return default; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public DataGridTableStyle this[int index] + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public DataGridTableStyle this[string tableName] + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal void CheckForMappingNameDuplicates(DataGridTableStyle table) + { + if (string.IsNullOrEmpty(table.MappingName)) + return; + } + + public virtual int Add(DataGridTableStyle table) + { + throw new PlatformNotSupportedException(); + } + + private void TableStyleMappingNameChanged(object sender, EventArgs pcea) + { + OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, null)); + } + + public virtual void AddRange(DataGridTableStyle[] tables) + { + throw new PlatformNotSupportedException(); + } + + public event CollectionChangeEventHandler CollectionChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + public void Clear() + { + throw new PlatformNotSupportedException(); + } + + public bool Contains(DataGridTableStyle table) + { + throw new PlatformNotSupportedException(); + } + + public bool Contains(string name) + { + throw new PlatformNotSupportedException(); + } + + protected void OnCollectionChanged(CollectionChangeEventArgs e) + { + DataGrid grid = owner; + if (grid is not null) + { + grid.checkHierarchy = true; + } + } + + public void Remove(DataGridTableStyle table) + { + throw new PlatformNotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new PlatformNotSupportedException(); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs new file mode 100644 index 00000000000..c808df79fde --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +public sealed class GridTablesFactory +{ + private GridTablesFactory() + { + } + + public static DataGridTableStyle[] CreateGridTables(DataGridTableStyle gridTable, object dataSource, string dataMember, BindingContext bindingManager) + { + throw new PlatformNotSupportedException(); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs new file mode 100644 index 00000000000..4f0c62620ce --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs @@ -0,0 +1,162 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("DataGridTextBox has been deprecated.")] +public class DataGridTextBox : TextBox +{ + public DataGridTextBox() : base() + { + throw new PlatformNotSupportedException(); + } + + public void SetDataGrid(DataGrid parentGrid) + { + throw new PlatformNotSupportedException(); + } + + protected override void WndProc(ref Message m) + { + // but what if we get a CtrlV? + // what about deleting from the menu? + if (m.Msg == PInvoke.WM_PASTE || m.Msg == PInvoke.WM_CUT || m.Msg == PInvoke.WM_CLEAR) + { + IsInEditOrNavigateMode = false; + } + + base.WndProc(ref m); + } + + protected override void OnMouseWheel(MouseEventArgs e) + { + } + + protected override void OnKeyPress(KeyPressEventArgs e) + { + base.OnKeyPress(e); + + if (e.KeyChar == ' ' && (ModifierKeys & Keys.Shift) == Keys.Shift) + return; + + if (ReadOnly) + return; + + if ((ModifierKeys & Keys.Control) == Keys.Control && ((ModifierKeys & Keys.Alt) == 0)) + return; + IsInEditOrNavigateMode = false; + } + + protected internal override bool ProcessKeyMessage(ref Message m) + { + Keys key = (Keys)unchecked((int)(long)m.WParam); + Keys modifierKeys = ModifierKeys; + + if ((key | modifierKeys) == Keys.Enter || + (key | modifierKeys) == Keys.Escape || + ((key | modifierKeys) == (Keys.Enter | Keys.Control))) + { + return ProcessKeyPreview(ref m); + } + + Keys keyData = key & Keys.KeyCode; + + switch (keyData) + { + case Keys.Right: + if (SelectionStart + SelectionLength == Text.Length) + return ProcessKeyPreview(ref m); + return ProcessKeyEventArgs(ref m); + case Keys.Left: + if (SelectionStart + SelectionLength == 0 || + (IsInEditOrNavigateMode && SelectionLength == Text.Length)) + return ProcessKeyPreview(ref m); + return ProcessKeyEventArgs(ref m); + case Keys.Down: + int end = SelectionStart + SelectionLength; + if (Text.IndexOf("\r\n", end) == -1) + return ProcessKeyPreview(ref m); + return ProcessKeyEventArgs(ref m); + case Keys.Up: + if (Text.IndexOf("\r\n") < 0 || SelectionStart + SelectionLength < Text.IndexOf("\r\n")) + return ProcessKeyPreview(ref m); + return ProcessKeyEventArgs(ref m); + case Keys.Home: + case Keys.End: + if (SelectionLength == Text.Length) + return ProcessKeyPreview(ref m); + else + return ProcessKeyEventArgs(ref m); + case Keys.Prior: + case Keys.Next: + case Keys.Oemplus: + case Keys.Add: + case Keys.OemMinus: + case Keys.Subtract: + if (IsInEditOrNavigateMode) + { + return ProcessKeyPreview(ref m); + } + else + { + return ProcessKeyEventArgs(ref m); + } + + case Keys.Space: + if (IsInEditOrNavigateMode && (ModifierKeys & Keys.Shift) == Keys.Shift) + { + return ProcessKeyPreview(ref m); + } + + return ProcessKeyEventArgs(ref m); + case Keys.A: + if (IsInEditOrNavigateMode && (ModifierKeys & Keys.Control) == Keys.Control) + { + return ProcessKeyPreview(ref m); + } + + return ProcessKeyEventArgs(ref m); + case Keys.F2: + IsInEditOrNavigateMode = false; + SelectionStart = Text.Length; + return true; + case Keys.Delete: + if (IsInEditOrNavigateMode) + { + if (ProcessKeyPreview(ref m)) + return true; + else + { + IsInEditOrNavigateMode = false; + return ProcessKeyEventArgs(ref m); + } + } + else + return ProcessKeyEventArgs(ref m); + case Keys.Tab: + if ((ModifierKeys & Keys.Control) == Keys.Control) + return ProcessKeyPreview(ref m); + else + return ProcessKeyEventArgs(ref m); + default: + return ProcessKeyEventArgs(ref m); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool IsInEditOrNavigateMode + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs new file mode 100644 index 00000000000..c8f56b1f1a7 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs @@ -0,0 +1,408 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; +using System.Globalization; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("DataGridTextBoxColumn has been deprecated. Use DataGridViewTextBoxColumn instead. http://go.microsoft.com/fwlink/?linkid=14202")] +public class DataGridTextBoxColumn : DataGridColumnStyle +{ + private int xMargin = 2; + private int yMargin = 1; + + private DataGridTextBox edit; + + private string oldValue; + private int editRow = -1; + + public DataGridTextBoxColumn() : this(null, null) + { + edit = new DataGridTextBox(); + throw new PlatformNotSupportedException(); + } + + public DataGridTextBoxColumn(PropertyDescriptor prop) + : this(prop, null, false) + { + throw new PlatformNotSupportedException(); + } + + public DataGridTextBoxColumn(PropertyDescriptor prop, string format) : this(prop, format, false) + { + throw new PlatformNotSupportedException(); + } + + public DataGridTextBoxColumn(PropertyDescriptor prop, string format, bool isDefault) : base(prop, isDefault) + { + throw new PlatformNotSupportedException(); + } + + public DataGridTextBoxColumn(PropertyDescriptor prop, bool isDefault) : this(prop, null, isDefault) + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual TextBox TextBox + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal override bool KeyPress(int rowNum, Keys keyData) + { + if (edit.IsInEditOrNavigateMode) + return base.KeyPress(rowNum, keyData); + + return false; + } + + protected override void SetDataGridInColumn(DataGrid value) + { + base.SetDataGridInColumn(value); + if (edit.ParentInternal is not null) + { + edit.ParentInternal.Controls.Remove(edit); + } + + if (value is not null) + { + value.Controls.Add(edit); + } + + // we have to tell the edit control about its dataGrid + edit.SetDataGrid(value); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override PropertyDescriptor PropertyDescriptor + { + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string Format + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public IFormatProvider FormatInfo + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override bool ReadOnly + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + private static void DebugOut(string s) + { + Debug.WriteLineIf(CompModSwitches.DGEditColumnEditing.TraceVerbose, "DGEditColumnEditing: " + s); + } + + protected internal override void ConcedeFocus() + { + edit.Bounds = Rectangle.Empty; + } + + protected void HideEditBox() + { + bool wasFocused = edit.Focused; + edit.Visible = false; + + if (wasFocused && DataGridTableStyle is not null && DataGridTableStyle.DataGrid is not null && DataGridTableStyle.DataGrid.CanFocus) + { + Debug.Assert(!edit.Focused, "the edit control just conceeded focus to the dataGrid"); + } + } + + protected internal override void UpdateUI(CurrencyManager source, int rowNum, string displayText) + { + edit.Text = GetText(GetColumnValueAtRow(source, rowNum)); + if (!edit.ReadOnly && displayText is not null) + edit.Text = displayText; + } + + protected void EndEdit() + { + edit.IsInEditOrNavigateMode = true; + DebugOut("Ending Edit"); + Invalidate(); + } + + protected internal override Size GetPreferredSize(Graphics g, object value) + { + Size extents = Size.Ceiling(g.MeasureString(GetText(value), DataGridTableStyle.DataGrid.Font)); + extents.Width += xMargin * 2 + this.DataGridTableStyle.GridLineWidth; + extents.Height += yMargin; + return extents; + } + + protected internal override int GetMinimumHeight() + { + // why + 3? cause we have to give some way to the edit box. + return FontHeight + yMargin + 3; + } + + protected internal override int GetPreferredHeight(Graphics g, object value) + { + int newLineIndex = 0; + int newLines = 0; + string valueString = GetText(value); + while (newLineIndex != -1 && newLineIndex < valueString.Length) + { + newLineIndex = valueString.IndexOf("\r\n", newLineIndex + 1); + newLines++; + } + + return FontHeight * newLines + yMargin; + } + + protected internal override void Abort(int rowNum) + { + RollBack(); + HideEditBox(); + EndEdit(); + } + + protected internal override void EnterNullValue() + { + if (ReadOnly) + return; + + // if the edit box is not visible, then + // do not put the edit text in it + if (!edit.Visible) + return; + + // if we are editing, then we should be able to enter alt-0 in a cell. + // + if (!edit.IsInEditOrNavigateMode) + return; + + edit.Text = NullText; + // edit.Visible = true; + edit.IsInEditOrNavigateMode = false; + // tell the dataGrid that there is an edit: + if (DataGridTableStyle is not null && DataGridTableStyle.DataGrid is not null) + DataGridTableStyle.DataGrid.ColumnStartedEditing(edit.Bounds); + } + + protected internal override bool Commit(CurrencyManager dataSource, int rowNum) + { + // always hide the edit box + // HideEditBox(); + edit.Bounds = Rectangle.Empty; + + if (edit.IsInEditOrNavigateMode) + return true; + + try + { + object value = edit.Text; + if (NullText.Equals(value)) + { + value = Convert.DBNull; + edit.Text = NullText; + } + else if (FormatInfo is not null) + { + edit.Text = value.ToString(); + } + + SetColumnValueAtRow(dataSource, rowNum, value); + } + catch + { + RollBack(); + return false; + } + + DebugOut("OnCommit completed without Exception."); + EndEdit(); + return true; + } + + protected internal override void Edit(CurrencyManager source, + int rowNum, + Rectangle bounds, + bool readOnly, + string displayText, + bool cellIsVisible) + { + DebugOut("Begining Edit, rowNum :" + rowNum.ToString(CultureInfo.InvariantCulture)); + + Rectangle originalBounds = bounds; + + edit.ReadOnly = readOnly || ReadOnly || DataGridTableStyle.ReadOnly; + + edit.Text = GetText(GetColumnValueAtRow(source, rowNum)); + if (!edit.ReadOnly && displayText is not null) + { + // tell the grid that we are changing stuff + DataGridTableStyle.DataGrid.ColumnStartedEditing(bounds); + // tell the edit control that the user changed it + edit.IsInEditOrNavigateMode = false; + edit.Text = displayText; + } + + if (cellIsVisible) + { + bounds.Offset(xMargin, 2 * yMargin); + bounds.Width -= xMargin; + bounds.Height -= 2 * yMargin; + DebugOut("edit bounds: " + bounds.ToString()); + edit.Bounds = bounds; + + edit.Visible = true; + + edit.TextAlign = Alignment; + } + else + { + edit.Bounds = Rectangle.Empty; + // edit.Bounds = originalBounds; + // edit.Visible = false; + } + + edit.RightToLeft = this.DataGridTableStyle.DataGrid.RightToLeft; + + editRow = rowNum; + + if (!edit.ReadOnly) + { + oldValue = edit.Text; + } + + // select the text even if the text box is read only + // because the navigation code in the DataGridTextBox::ProcessKeyMessage + // uses the SelectedText property + if (displayText is null) + edit.SelectAll(); + else + { + int end = edit.Text.Length; + edit.Select(end, 0); + } + + if (edit.Visible) + DataGridTableStyle.DataGrid.Invalidate(originalBounds); + } + + internal override string GetDisplayText(object value) + { + return GetText(value); + } + + private string GetText(object value) + { + if (value is DBNull) + return NullText; + else if (value is IFormattable) + { + try + { + return ((IFormattable)value).ToString(); + } + catch + { + // CONSIDER: maybe we should fall back to using the typeConverter? + } + } + + return (value is not null ? value.ToString() : ""); + } + + protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) + { + string text = GetText(GetColumnValueAtRow(source, rowNum)); + PaintText(g, bounds, text, alignToRight); + } + + protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, + Brush backBrush, Brush foreBrush, bool alignToRight) + { + string text = GetText(GetColumnValueAtRow(source, rowNum)); + PaintText(g, bounds, text, backBrush, foreBrush, alignToRight); + } + + protected void PaintText(Graphics g, Rectangle bounds, string text, bool alignToRight) + { + PaintText(g, bounds, text, DataGridTableStyle.BackBrush, DataGridTableStyle.ForeBrush, alignToRight); + } + + protected void PaintText(Graphics g, Rectangle textBounds, string text, Brush backBrush, Brush foreBrush, bool alignToRight) + { + Rectangle rect = textBounds; + + StringFormat format = new StringFormat(); + if (alignToRight) + { + format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; + } + + format.Alignment = Alignment == HorizontalAlignment.Left ? StringAlignment.Near : Alignment == HorizontalAlignment.Center ? StringAlignment.Center : StringAlignment.Far; + + // do not wrap the text + // + format.FormatFlags |= StringFormatFlags.NoWrap; + + g.FillRectangle(backBrush, rect); + // by design, painting leaves a little padding around the rectangle. + // so do not deflate the rectangle. + rect.Offset(0, 2 * yMargin); + rect.Height -= 2 * yMargin; + g.DrawString(text, DataGridTableStyle.DataGrid.Font, foreBrush, rect, format); + format.Dispose(); + } + + private void RollBack() + { + Debug.Assert(!edit.IsInEditOrNavigateMode, "Must be editing to rollback changes..."); + edit.Text = oldValue; + } + + protected internal override void ReleaseHostedControl() + { + if (edit.ParentInternal is not null) + { + edit.ParentInternal.Controls.Remove(edit); + } + } + + protected internal override void Paint(Graphics g1, Graphics g, Rectangle bounds, CurrencyManager source, int rowNum) => throw new NotImplementedException(); +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs new file mode 100644 index 00000000000..1d09b6c8f00 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; + +namespace System.Windows.Forms; + +#nullable disable +internal class DataGridToolTip : MarshalByRefObject +{ + // CONSTRUCTOR + public DataGridToolTip(DataGrid dataGrid) + { + throw new PlatformNotSupportedException(); + } + + // will ensure that the toolTip window was created + public static void CreateToolTipHandle() + { + throw new PlatformNotSupportedException(); + } + + // this function will add a toolTip to the + // windows system + public static void AddToolTip(string toolTipString, IntPtr toolTipId, Rectangle iconBounds) + { + throw new PlatformNotSupportedException(); + } + + public static void RemoveToolTip(IntPtr toolTipId) + { + throw new PlatformNotSupportedException(); + } + + // will destroy the tipWindow + public static void Destroy() + { + throw new PlatformNotSupportedException(); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs new file mode 100644 index 00000000000..b6f55b5deab --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs @@ -0,0 +1,264 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("GridColumnStylesCollection has been deprecated.")] +public class GridColumnStylesCollection : BaseCollection, IList +{ + private ArrayList items = new ArrayList(); + private DataGridTableStyle owner; + private bool isDefault; + + int IList.Add(object value) + { + return Add((DataGridColumnStyle)value); + } + + void IList.Clear() + { + Clear(); + } + + bool IList.Contains(object value) + { + return items.Contains(value); + } + + int IList.IndexOf(object value) + { + return items.IndexOf(value); + } + + void IList.Insert(int index, object value) + { + throw new NotSupportedException(); + } + + void IList.Remove(object value) + { + Remove((DataGridColumnStyle)value); + } + + void IList.RemoveAt(int index) + { + RemoveAt(index); + } + + bool IList.IsFixedSize + { + get { return false; } + } + + bool IList.IsReadOnly + { + get { return false; } + } + + object IList.this[int index] + { + get { return items[index]; } + set { throw new NotSupportedException(); } + } + + void ICollection.CopyTo(Array array, int index) + { + items.CopyTo(array, index); + } + + int ICollection.Count + { + get { return items.Count; } + } + + bool ICollection.IsSynchronized + { + get { return false; } + } + + object ICollection.SyncRoot + { + get { return this; } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return items.GetEnumerator(); + } + + internal GridColumnStylesCollection(DataGridTableStyle table) + { + owner = table; + } + + internal GridColumnStylesCollection(DataGridTableStyle table, bool isDefault) : this(table) + { + this.isDefault = isDefault; + } + + protected override ArrayList List + { + get + { + return items; + } + } + + public DataGridColumnStyle this[int index] + { + get + { + throw new PlatformNotSupportedException(); + } + } + + public DataGridColumnStyle this[string columnName] + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal DataGridColumnStyle MapColumnStyleToPropertyName(string mappingName) + { + int itemCount = items.Count; + for (int i = 0; i < itemCount; ++i) + { + DataGridColumnStyle column = (DataGridColumnStyle)items[i]; + // NOTE: case-insensitive + if (string.Equals(column.MappingName, mappingName, StringComparison.OrdinalIgnoreCase)) + return column; + } + + return null; + } + + public DataGridColumnStyle this[PropertyDescriptor propertyDesciptor] + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal DataGridTableStyle DataGridTableStyle + { + get + { + return owner; + } + } + + internal void CheckForMappingNameDuplicates(DataGridColumnStyle column) + { + if (string.IsNullOrEmpty(column.MappingName)) + return; + for (int i = 0; i < items.Count; i++) + if (((DataGridColumnStyle)items[i]).MappingName.Equals(column.MappingName) && column != items[i]) + throw new ArgumentException("Data grid column styles collection already contains a column style with the same mapping name."); + } + + private void ColumnStyleMappingNameChanged(object sender, EventArgs pcea) + { + OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, null)); + } + + private void ColumnStylePropDescChanged(object sender, EventArgs pcea) + { + OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, (DataGridColumnStyle)sender)); + } + + public virtual int Add(DataGridColumnStyle column) + { + throw new PlatformNotSupportedException(); + } + + public void AddRange(DataGridColumnStyle[] columns) + { + throw new PlatformNotSupportedException(); + } + + internal void AddDefaultColumn(DataGridColumnStyle column) + { + column.SetDataGridTableInColumn(owner, true); + items.Add(column); + } + + internal void ResetDefaultColumnCollection() + { + for (int i = 0; i < Count; i++) + { + this[i].ReleaseHostedControl(); + } + + items.Clear(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event CollectionChangeEventHandler CollectionChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + public void Clear() + { + throw new PlatformNotSupportedException(); + } + + public bool Contains(PropertyDescriptor propertyDescriptor) + { + throw new PlatformNotSupportedException(); + } + + public bool Contains(DataGridColumnStyle column) + { + throw new PlatformNotSupportedException(); + } + + public bool Contains(string name) + { + throw new PlatformNotSupportedException(); + } + + public int IndexOf(DataGridColumnStyle element) + { + throw new PlatformNotSupportedException(); + } + + protected void OnCollectionChanged(CollectionChangeEventArgs e) + { + DataGrid grid = owner.DataGrid; + if (grid is not null) + { + grid.checkHierarchy = true; + } + } + + public void Remove(DataGridColumnStyle column) + { + throw new PlatformNotSupportedException(); + } + + public void RemoveAt(int index) + { + throw new PlatformNotSupportedException(); + } + + public void ResetPropertyDescriptors() + { + throw new PlatformNotSupportedException(); + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/IDataGridEditingService.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/IDataGridEditingService.cs new file mode 100644 index 00000000000..a44c7654fa1 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/IDataGridEditingService.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("IDataGridEditingService has been deprecated.")] +public interface IDataGridEditingService +{ + bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber); + + bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort); +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs index 9223d0f1425..80c4ed8adcb 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs @@ -12,8 +12,6 @@ public class MainMenu : Menu #nullable disable internal Form form; internal Form ownerForm; // this is the form that created this menu, and is the only form allowed to dispose it. - private RightToLeft rightToLeft = System.Windows.Forms.RightToLeft.Inherit; - private EventHandler onCollapse; /// /// Creates a new MainMenu control. @@ -46,8 +44,8 @@ public MainMenu(MenuItem[] items) [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Collapse { - add => onCollapse += value; - remove => onCollapse -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -63,28 +61,11 @@ public virtual RightToLeft RightToLeft { get { - if (rightToLeft == RightToLeft.Inherit) - { - if (form is not null) - { - return form.RightToLeft; - } - else - { - return RightToLeft.Inherit; - } - } - else - { - return rightToLeft; - } + throw new PlatformNotSupportedException(); } set { - if (rightToLeft != value) - { - rightToLeft = value; - } + throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs new file mode 100644 index 00000000000..533c8b67e2e --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs @@ -0,0 +1,1328 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Globalization; +using System.Windows.Forms.VisualStyles; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("StatusBar is obsolete. Use the StatusStrip control instead. StatusBar will be removed in a future release.")] +public class StatusBar : Control +{ + private int sizeGripWidth; + private static readonly object EVENT_PANELCLICK = new object(); + private static readonly object EVENT_SBDRAWITEM = new object(); + + private bool layoutDirty; + private int panelsRealized; + private bool sizeGrip = true; + private Point lastClick = new Point(0, 0); + private IList panels = new ArrayList(); + private ControlToolTip tooltips; + + private ToolTip mainToolTip; + private bool toolTipSet; + + public StatusBar() + : base() + { + throw new PlatformNotSupportedException(); + } + + private static VisualStyleRenderer renderer; + + /// + /// A VisualStyleRenderer we can use to get information about the current UI theme + /// + private static VisualStyleRenderer VisualStyleRenderer + { + get + { + if (VisualStyleRenderer.IsSupported) + { + if (renderer is null) + { + renderer = new VisualStyleRenderer(VisualStyleElement.ToolBar.Button.Normal); + } + } + else + { + renderer = null; + } + + return renderer; + } + } + + private int SizeGripWidth + { + get + { + if (sizeGripWidth == 0) + { + if (Application.RenderWithVisualStyles && VisualStyleRenderer is not null) + { + // VSWhidbey 207045: need to build up accurate gripper width to avoid cutting off other panes. + VisualStyleRenderer vsRenderer = VisualStyleRenderer; + VisualStyleElement thisElement; + Size elementSize; + + // gripper pane width... + thisElement = VisualStyleElement.Status.GripperPane.Normal; + vsRenderer.SetParameters(thisElement); + elementSize = vsRenderer.GetPartSize(Graphics.FromHwndInternal(Handle), ThemeSizeType.True); + sizeGripWidth = elementSize.Width; + + // ...plus gripper width + thisElement = VisualStyleElement.Status.Gripper.Normal; + vsRenderer.SetParameters(thisElement); + elementSize = vsRenderer.GetPartSize(Graphics.FromHwndInternal(Handle), ThemeSizeType.True); + sizeGripWidth += elementSize.Width; + + // Either GetPartSize could have returned a width of zero, so make sure we have a reasonable number: + sizeGripWidth = Math.Max(sizeGripWidth, 16); + } + else + { + sizeGripWidth = 16; + } + } + + return sizeGripWidth; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Color BackColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Image BackgroundImage + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackgroundImageChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override ImageLayout BackgroundImageLayout + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackgroundImageLayoutChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + return cp; + } + } + + protected override ImeMode DefaultImeMode + { + get + { + return ImeMode.Disable; + } + } + + protected override Size DefaultSize + { + get + { + return new Size(100, 22); + } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + protected override bool DoubleBuffered + { + get + { + return base.DoubleBuffered; + } + set + { + base.DoubleBuffered = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override DockStyle Dock + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Font Font + { + get { throw new PlatformNotSupportedException(); } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override Color ForeColor + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler ForeColorChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public ImeMode ImeMode + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public new event EventHandler ImeModeChanged + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public StatusBarPanelCollection Panels + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public override string Text + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool ShowPanels + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool SizingGrip + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + new public bool TabStop + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal bool ToolTipSet + { + get + { + return toolTipSet; + } + } + + internal ToolTip MainToolTip + { + get + { + return mainToolTip; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event StatusBarDrawItemEventHandler DrawItem + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public event StatusBarPanelClickEventHandler PanelClick + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public new event PaintEventHandler Paint + { + add + { + throw new PlatformNotSupportedException(); + } + remove + { + throw new PlatformNotSupportedException(); + } + } + + internal bool ArePanelsRealized() + { + return IsHandleCreated; + } + + internal void DirtyLayout() + { + layoutDirty = true; + } + + private void ApplyPanelWidths() + { + // This forces handle creation every time any time the StatusBar + // has to be re-laidout. + if (!IsHandleCreated) + return; + + StatusBarPanel panel = null; + int length = panels.Count; + + if (length == 0) + { + Size sz = Size; + int[] offsets = new int[1]; + offsets[0] = sz.Width; + if (sizeGrip) + { + offsets[0] -= SizeGripWidth; + } + + return; + } + + int[] offsets2 = new int[length]; + int currentOffset = 0; + for (int i = 0; i < length; i++) + { + panel = (StatusBarPanel)this.panels[i]; + currentOffset += panel.Width; + offsets2[i] = currentOffset; + panel.Right = offsets2[i]; + } + + // Tooltip setup... + // + for (int i = 0; i < length; i++) + { + panel = (StatusBarPanel)this.panels[i]; + UpdateTooltip(panel); + } + + layoutDirty = false; + } + + protected override void CreateHandle() + { + base.CreateHandle(); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + } + + private void ForcePanelUpdate() + { + if (ArePanelsRealized()) + { + layoutDirty = true; + SetPanelContentsWidths(true); + PerformLayout(); + RealizePanels(); + } + } + + protected override void OnHandleCreated(EventArgs e) + { + base.OnHandleCreated(e); + if (!DesignMode) + { + tooltips = new ControlToolTip(this); + } + + ForcePanelUpdate(); + } + + protected override void OnHandleDestroyed(EventArgs e) + { + base.OnHandleDestroyed(e); + if (tooltips is not null) + { + tooltips.Dispose(); + tooltips = null; + } + } + + protected override void OnMouseDown(MouseEventArgs e) + { + lastClick.X = e.X; + lastClick.Y = e.Y; + base.OnMouseDown(e); + } + + protected virtual void OnPanelClick(StatusBarPanelClickEventArgs e) + { + StatusBarPanelClickEventHandler handler = (StatusBarPanelClickEventHandler)Events[EVENT_PANELCLICK]; + if (handler is not null) + handler(this, e); + } + + protected override void OnLayout(LayoutEventArgs levent) + { + base.OnLayout(levent); + } + + internal void RealizePanels() + { + StatusBarPanel panel = null; + int length = panels.Count; + int old = panelsRealized; + + panelsRealized = 0; + + int i; + for (i = 0; i < length; i++) + { + panel = (StatusBarPanel)panels[i]; + try + { + panel.Realize(); + panelsRealized++; + } + catch + { + } + } + } + + internal void RemoveAllPanelsWithoutUpdate() + { + int size = panels.Count; + // remove the parent reference + for (int i = 0; i < size; i++) + { + StatusBarPanel sbp = (StatusBarPanel)panels[i]; + sbp.ParentInternal = null; + } + + panels.Clear(); + } + + internal void SetPanelContentsWidths(bool newPanels) + { + int size = panels.Count; + bool changed = false; + for (int i = 0; i < size; i++) + { + StatusBarPanel sbp = (StatusBarPanel)panels[i]; + if (sbp.AutoSize == StatusBarPanelAutoSize.Contents) + { + int newWidth = sbp.GetContentsWidth(newPanels); + if (sbp.Width != newWidth) + { + sbp.Width = newWidth; + changed = true; + } + } + } + + if (changed) + { + DirtyLayout(); + PerformLayout(); + } + } + + private void SetSimpleText(string simpleText) + { + } + + private void LayoutPanels() + { + StatusBarPanel panel = null; + int barPanelWidth = 0; + int springNum = 0; + StatusBarPanel[] pArray = new StatusBarPanel[panels.Count]; + bool changed = false; + + for (int i = 0; i < pArray.Length; i++) + { + panel = (StatusBarPanel)this.panels[i]; + if (panel.AutoSize == StatusBarPanelAutoSize.Spring) + { + pArray[springNum] = panel; + springNum++; + } + else + barPanelWidth += panel.Width; + } + + if (springNum > 0) + { + Rectangle rect = Bounds; + int springPanelsLeft = springNum; + int leftoverWidth = rect.Width - barPanelWidth; + if (sizeGrip) + { + leftoverWidth -= SizeGripWidth; + } + + int copyOfLeftoverWidth = unchecked((int)0x80000000); + while (springPanelsLeft > 0) + { + int widthOfSpringPanel = (leftoverWidth) / springPanelsLeft; + if (leftoverWidth == copyOfLeftoverWidth) + break; + copyOfLeftoverWidth = leftoverWidth; + + for (int i = 0; i < springNum; i++) + { + panel = pArray[i]; + if (panel is null) + continue; + + if (widthOfSpringPanel < panel.MinWidth) + { + if (panel.Width != panel.MinWidth) + { + changed = true; + } + + panel.Width = panel.MinWidth; + pArray[i] = null; + springPanelsLeft--; + leftoverWidth -= panel.MinWidth; + } + else + { + if (panel.Width != widthOfSpringPanel) + { + changed = true; + } + + panel.Width = widthOfSpringPanel; + } + } + } + } + + if (changed || layoutDirty) + { + ApplyPanelWidths(); + } + } + + protected virtual void OnDrawItem(StatusBarDrawItemEventArgs sbdievent) + { + StatusBarDrawItemEventHandler handler = (StatusBarDrawItemEventHandler)Events[EVENT_SBDRAWITEM]; + if (handler is not null) + handler(this, sbdievent); + } + + protected override void OnResize(EventArgs e) + { + Invalidate(); + base.OnResize(e); + } + + public override string ToString() + { + string s = base.ToString(); + if (Panels is not null) + { + s += ", Panels.Count: " + Panels.Count.ToString(CultureInfo.CurrentCulture); + if (Panels.Count > 0) + s += ", Panels[0]: " + Panels[0].ToString(); + } + + return s; + } + + new internal void SetToolTip(ToolTip t) + { + mainToolTip = t; + toolTipSet = true; + } + + internal void UpdateTooltip(StatusBarPanel panel) + { + if (tooltips is null) + { + if (IsHandleCreated && !DesignMode) + { + tooltips = new ControlToolTip(this); + } + else + { + return; + } + } + + if (panel.Parent == this && panel.ToolTipText.Length > 0) + { + int border = SystemInformation.Border3DSize.Width; + ControlToolTip.Tool t = tooltips.GetTool(panel); + if (t is null) + { + t = new ControlToolTip.Tool(); + } + + t.text = panel.ToolTipText; + t.rect = new Rectangle(panel.Right - panel.Width + border, 0, panel.Width - border, Height); + tooltips.SetTool(panel, t); + } + else + { + tooltips.SetTool(panel, null); + } + } + + private void UpdatePanelIndex() + { + int length = panels.Count; + for (int i = 0; i < length; i++) + { + ((StatusBarPanel)panels[i]).Index = i; + } + } + + private void WmDrawItem(ref Message m) + { + DRAWITEMSTRUCT dis = (DRAWITEMSTRUCT)m.GetLParam(typeof(DRAWITEMSTRUCT)); + + int length = panels.Count; + if (dis.itemID < 0 || dis.itemID >= length) + Debug.Fail("OwnerDraw item out of range"); + + StatusBarPanel panel = (StatusBarPanel) + panels[0]; + + Graphics g = Graphics.FromHdcInternal(dis.hDC); + Rectangle r = Rectangle.FromLTRB(dis.rcItem.left, dis.rcItem.top, dis.rcItem.right, dis.rcItem.bottom); + + g.Dispose(); + } + + private void WmNotifyNMClick(NMHDR note) + { + int size = panels.Count; + int currentOffset = 0; + int index = -1; + for (int i = 0; i < size; i++) + { + StatusBarPanel panel = (StatusBarPanel)panels[i]; + currentOffset += panel.Width; + if (lastClick.X < currentOffset) + { + // this is where the mouse was clicked. + index = i; + break; + } + } + + if (index != -1) + { + MouseButtons button = MouseButtons.Left; + int clicks = 0; + switch (note.code) + { + case PInvoke.NM_CLICK: + button = MouseButtons.Left; + clicks = 1; + break; + case PInvoke.NM_RCLICK: + button = MouseButtons.Right; + clicks = 1; + break; + case PInvoke.NM_DBLCLK: + button = MouseButtons.Left; + clicks = 2; + break; + case PInvoke.NM_RDBLCLK: + button = MouseButtons.Right; + clicks = 2; + break; + } + + Point pt = lastClick; + StatusBarPanel panel = (StatusBarPanel)panels[index]; + + StatusBarPanelClickEventArgs sbpce = new StatusBarPanelClickEventArgs(panel, + button, clicks, pt.X, pt.Y); + OnPanelClick(sbpce); + } + } + + private void WmNCHitTest(ref Message m) + { + int x = PARAM.LOWORD(m.LParam); + Rectangle bounds = Bounds; + bool callSuper = true; + + // The default implementation of the statusbar + // : will let you size the form when it is docked on the bottom, + // : but when it is anywhere else, the statusbar will be resized. + // : to prevent that we provide a little bit a sanity to only + // : allow resizing, when it would resize the form. + // + if (x > bounds.X + bounds.Width - SizeGripWidth) + { + Control parent = ParentInternal; + if (parent is not null && parent is Form) + { + FormBorderStyle bs = ((Form)parent).FormBorderStyle; + + if (bs != FormBorderStyle.Sizable + && bs != FormBorderStyle.SizableToolWindow) + { + callSuper = false; + } + + if (!((Form)parent).TopLevel + || Dock != DockStyle.Bottom) + { + callSuper = false; + } + + if (callSuper) + { + Control.ControlCollection children = parent.Controls; + int c = children.Count; + for (int i = 0; i < c; i++) + { + Control ctl = children[i]; + if (ctl != this && ctl.Dock == DockStyle.Bottom) + { + if (ctl.Top > Top) + { + callSuper = false; + break; + } + } + } + } + } + else + { + callSuper = false; + } + } + + if (callSuper) + { + base.WndProc(ref m); + } + else + { + m.Result = (IntPtr)PInvoke.HTCLIENT; + } + } + + protected override void WndProc(ref Message m) + { + switch (m.MsgInternal) + { + case PInvoke.WM_NCHITTEST: + WmNCHitTest(ref m); + break; + case MessageId.WM_REFLECT + PInvoke.WM_DRAWITEM: + WmDrawItem(ref m); + break; + case PInvoke.WM_NOTIFY: + case PInvoke.WM_NOTIFY + MessageId.WM_REFLECT: + NMHDR note = (NMHDR)m.GetLParam(typeof(NMHDR)); + switch (note.code) + { + case PInvoke.NM_CLICK: + case PInvoke.NM_RCLICK: + case PInvoke.NM_DBLCLK: + case PInvoke.NM_RDBLCLK: + WmNotifyNMClick(note); + break; + default: + base.WndProc(ref m); + break; + } + + break; + + default: + base.WndProc(ref m); + break; + } + } + + [Obsolete("StatusBarPanelCollection has been deprecated.")] + public class StatusBarPanelCollection : IList + { + private StatusBar owner; + + public StatusBarPanelCollection(StatusBar owner) + { + this.owner = owner; + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual StatusBarPanel this[int index] + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + object IList.this[int index] + { + get + { + return this[index]; + } + set + { + if (value is StatusBarPanel) + { + this[index] = (StatusBarPanel)value; + } + else + { + throw new ArgumentException("SR.GetString(SR.StatusBarBadStatusBarPanel)"); + } + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public virtual StatusBarPanel this[string key] + { + get + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int Count + { + get + { + throw new PlatformNotSupportedException(); + } + } + + object ICollection.SyncRoot + { + get + { + return this; + } + } + + bool ICollection.IsSynchronized + { + get + { + return false; + } + } + + bool IList.IsFixedSize + { + get + { + return false; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public bool IsReadOnly + { + get + { + throw new PlatformNotSupportedException(); + } + } + + public virtual StatusBarPanel Add(string text) + { + throw new PlatformNotSupportedException(); + } + + public virtual int Add(StatusBarPanel value) + { + throw new PlatformNotSupportedException(); + } + + int IList.Add(object value) + { + if (value is StatusBarPanel) + { + return Add((StatusBarPanel)value); + } + else + { + throw new ArgumentException("SR.GetString(SR.StatusBarBadStatusBarPanel)"); + } + } + + public virtual void AddRange(StatusBarPanel[] panels) + { + throw new PlatformNotSupportedException(); + } + + public bool Contains(StatusBarPanel panel) + { + throw new PlatformNotSupportedException(); + } + + bool IList.Contains(object panel) + { + if (panel is StatusBarPanel) + { + return Contains((StatusBarPanel)panel); + } + else + { + return false; + } + } + + public virtual bool ContainsKey(string key) + { + throw new PlatformNotSupportedException(); + } + + public int IndexOf(StatusBarPanel panel) + { + throw new PlatformNotSupportedException(); + } + + int IList.IndexOf(object panel) + { + if (panel is StatusBarPanel) + { + return IndexOf((StatusBarPanel)panel); + } + else + { + return -1; + } + } + + public virtual int IndexOfKey(string key) + { + throw new PlatformNotSupportedException(); + } + + public virtual void Insert(int index, StatusBarPanel value) + { + throw new PlatformNotSupportedException(); + } + + void IList.Insert(int index, object value) + { + if (value is StatusBarPanel) + { + Insert(index, (StatusBarPanel)value); + } + else + { + throw new ArgumentException("SR.GetString(SR.StatusBarBadStatusBarPanel)"); + } + } + + private bool IsValidIndex(int index) + { + return ((index >= 0) && (index < Count)); + } + + public virtual void Clear() + { + throw new PlatformNotSupportedException(); + } + + public virtual void Remove(StatusBarPanel value) + { + throw new PlatformNotSupportedException(); + } + + void IList.Remove(object value) + { + if (value is StatusBarPanel) + { + Remove((StatusBarPanel)value); + } + } + + public virtual void RemoveAt(int index) + { + throw new PlatformNotSupportedException(); + } + + public virtual void RemoveByKey(string key) + { + throw new PlatformNotSupportedException(); + } + + void ICollection.CopyTo(Array dest, int index) + { + owner.panels.CopyTo(dest, index); + } + + public IEnumerator GetEnumerator() + { + throw new PlatformNotSupportedException(); + } + } + + private class ControlToolTip + { + public class Tool + { + public Rectangle rect = Rectangle.Empty; + public string text; + internal IntPtr id = new IntPtr(-1); + } + + private Hashtable tools = new Hashtable(); + private ToolTipNativeWindow window; + private Control parent; + private int nextId; + + public ControlToolTip(Control parent) + { + window = new ToolTipNativeWindow(this); + this.parent = parent; + } + + protected CreateParams CreateParams + { + get + { + INITCOMMONCONTROLSEX icc = default; + icc.dwICC = INITCOMMONCONTROLSEX_ICC.ICC_TAB_CLASSES; + PInvoke.InitCommonControlsEx(icc); + CreateParams cp = new CreateParams(); + cp.Parent = IntPtr.Zero; + cp.ClassName = PInvoke.TOOLTIPS_CLASS; + cp.Style |= (int)PInvoke.TTS_ALWAYSTIP; + cp.ExStyle = 0; + cp.Caption = null; + return cp; + } + } + + public IntPtr Handle + { + get + { + if (window.Handle == IntPtr.Zero) + { + CreateHandle(); + } + + return window.Handle; + } + } + + private bool IsHandleCreated + { + get { return window.Handle != IntPtr.Zero; } + } + + private void AssignId(Tool tool) + { + tool.id = (IntPtr)nextId; + nextId++; + } + + public void SetTool(object key, Tool tool) + { + bool remove = false; + bool add = false; + bool update = false; + + Tool toRemove = null; + if (tools.ContainsKey(key)) + { + toRemove = (Tool)tools[key]; + } + + if (toRemove is not null) + { + remove = true; + } + + if (tool is not null) + { + add = true; + } + + if (tool is not null && toRemove is not null + && tool.id == toRemove.id) + { + update = true; + } + + if (update) + { + UpdateTool(tool); + } + else + { + if (remove) + { + RemoveTool(toRemove); + } + + if (add) + { + AddTool(tool); + } + } + + if (tool is not null) + { + tools[key] = tool; + } + else + { + tools.Remove(key); + } + } + + public Tool GetTool(object key) + { + return (Tool)tools[key]; + } + + private void AddTool(Tool tool) + { + if (tool is not null && tool.text is not null && tool.text.Length > 0) + { + StatusBar p = (StatusBar)parent; + } + } + + private void RemoveTool(Tool tool) + { + } + + private void UpdateTool(Tool tool) + { + } + + protected void CreateHandle() + { + if (IsHandleCreated) + { + return; + } + + window.CreateHandle(CreateParams); + } + + protected void DestroyHandle() + { + if (IsHandleCreated) + { + window.DestroyHandle(); + tools.Clear(); + } + } + + public void Dispose() + { + DestroyHandle(); + } + + ~ControlToolTip() + { + DestroyHandle(); + } + + protected void WndProc(ref Message msg) + { + switch (msg.MsgInternal) + { + case PInvoke.WM_SETFOCUS: + // bug 120872, the COMCTL StatusBar passes WM_SETFOCUS on to the DefWndProc, so + // it will take keyboard focus. We don't want it doing this, so we eat + // the message. + // + return; + default: + window.DefWndProc(ref msg); + break; + } + } + + private class ToolTipNativeWindow : NativeWindow + { + private ControlToolTip control; + + internal ToolTipNativeWindow(ControlToolTip control) + { + this.control = control; + } + + protected override void WndProc(ref Message m) + { + if (control is not null) + { + control.WndProc(ref m); + } + } + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs new file mode 100644 index 00000000000..470eea44077 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("StatusBarDrawItemEventArgs has been deprecated. Use DrawItemEventArgs instead. https://go.microsoft.com/fwlink/?linkid=14202")] +public class StatusBarDrawItemEventArgs : DrawItemEventArgs +{ + public StatusBarDrawItemEventArgs(Graphics g, Font font, Rectangle r, int itemId, + DrawItemState itemState, StatusBarPanel panel) : base(g, font, r, itemId, itemState) + { + throw new PlatformNotSupportedException(); + } + + public StatusBarDrawItemEventArgs(System.Drawing.Graphics g, Font font, Rectangle r, int itemId, + DrawItemState itemState, StatusBarPanel panel, Color foreColor, Color backColor) : base(g, font, r, itemId, itemState, foreColor, backColor) + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public StatusBarPanel Panel + { + get + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs new file mode 100644 index 00000000000..add3d9c4a7e --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +[Obsolete("StatusBarDrawItemEventHandler has been deprecated. Use DrawItemEventHandler instead. https://go.microsoft.com/fwlink/?linkid=14202")] +[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] +public delegate void StatusBarDrawItemEventHandler(object sender, StatusBarDrawItemEventArgs sbdevent); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs new file mode 100644 index 00000000000..57f2a23b2b9 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs @@ -0,0 +1,371 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Drawing; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 +#nullable disable +[Obsolete("StatusBarPanel has been deprecated. Use the StatusStrip control instead. http://go.microsoft.com/fwlink/?linkid=14202")] +public class StatusBarPanel : Component, ISupportInitialize +{ + private const int DEFAULTMINWIDTH = 10; + private const int PANELTEXTINSET = 3; + private const int PANELGAP = 2; + + private string text = ""; + + private HorizontalAlignment alignment = HorizontalAlignment.Left; + private StatusBarPanelStyle style = StatusBarPanelStyle.Text; + + // these are package scope so the parent can get at them. + private StatusBar parent; + private int right; + private int minWidth = DEFAULTMINWIDTH; + private int index; + private StatusBarPanelAutoSize autoSize = StatusBarPanelAutoSize.None; + + public StatusBarPanel() + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public HorizontalAlignment Alignment + { + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public StatusBarPanelAutoSize AutoSize + { + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public StatusBarPanelBorderStyle BorderStyle + { + get + { + throw new PlatformNotSupportedException(); + } + + set + { + throw new PlatformNotSupportedException(); + } + } + + internal bool Created + { + get + { + return parent is not null && parent.ArePanelsRealized(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public Icon Icon + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + internal int Index + { + get + { + return index; + } + set + { + index = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int MinWidth + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string Name + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public StatusBar Parent + { + get + { + throw new PlatformNotSupportedException(); + } + } + + internal StatusBar ParentInternal + { + set + { + parent = value; + } + } + + internal int Right + { + get + { + return right; + } + set + { + right = value; + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public StatusBarPanelStyle Style + { + get { throw new PlatformNotSupportedException(); } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public object Tag + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string Text + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public string ToolTipText + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public int Width + { + get + { + throw new PlatformNotSupportedException(); + } + set + { + throw new PlatformNotSupportedException(); + } + } + + public void BeginInit() + { + throw new PlatformNotSupportedException(); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (parent is not null) + { + int index = GetIndex(); + if (index != -1) + { + parent.Panels.RemoveAt(index); + } + } + } + + base.Dispose(disposing); + } + + public void EndInit() + { + throw new PlatformNotSupportedException(); + } + + internal int GetContentsWidth(bool newPanel) + { + string text; + if (newPanel) + { + if (this.text is null) + text = ""; + else + text = this.text; + } + else + text = Text; + + Graphics g = parent.CreateGraphicsInternal(); + Size sz = Size.Ceiling(g.MeasureString(text, parent.Font)); + + g.Dispose(); + + int width = sz.Width + SystemInformation.BorderSize.Width * 2 + PANELTEXTINSET * 2 + PANELGAP; + return Math.Max(width, minWidth); + } + + private int GetIndex() + { + return index; + } + + internal void Realize() + { + if (Created) + { + string text; + string sendText; + + if (this.text is null) + { + text = ""; + } + else + { + text = this.text; + } + + HorizontalAlignment align = alignment; + // Translate the alignment for Rtl apps + if (parent.RightToLeft == RightToLeft.Yes) + { + switch (align) + { + case HorizontalAlignment.Left: + align = HorizontalAlignment.Right; + break; + case HorizontalAlignment.Right: + align = HorizontalAlignment.Left; + break; + } + } + + switch (align) + { + case HorizontalAlignment.Center: + sendText = "\t" + text; + break; + case HorizontalAlignment.Right: + sendText = "\t\t" + text; + break; + default: + sendText = text; + break; + } + + switch (style) + { + case StatusBarPanelStyle.Text: + break; + } + } + } + + private void UpdateSize() + { + if (autoSize == StatusBarPanelAutoSize.Contents) + { + ApplyContentSizing(); + } + else + { + if (Created) + { + parent.DirtyLayout(); + parent.PerformLayout(); + } + } + } + + private void ApplyContentSizing() + { + if (autoSize == StatusBarPanelAutoSize.Contents && + parent is not null) + { + int newWidth = GetContentsWidth(false); + if (newWidth != Width) + { + Width = newWidth; + if (Created) + { + parent.DirtyLayout(); + parent.PerformLayout(); + } + } + } + } + + public override string ToString() + { + return "StatusBarPanel: {" + Text + "}"; + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs new file mode 100644 index 00000000000..b34c63385a3 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("StatusBarPanelAutoSize has been deprecated.")] +public enum StatusBarPanelAutoSize +{ + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + None = 1, + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Spring = 2, + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + Contents = 3, +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelBorderStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelBorderStyle.cs new file mode 100644 index 00000000000..24c7a67a29f --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelBorderStyle.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("StatusBarPanelBorderStyle is obsolete. Use the BorderStyle property of the StatusBarPanel class to change the border style of the StatusBarPanel.")] +public enum StatusBarPanelBorderStyle +{ + None = 1, + + Raised = 2, + + Sunken = 3, +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs new file mode 100644 index 00000000000..92ec4ec6266 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("StatusBarPanelClickEventArgs has been deprecated.")] +public class StatusBarPanelClickEventArgs : MouseEventArgs +{ + public StatusBarPanelClickEventArgs(StatusBarPanel statusBarPanel, MouseButtons button, int clicks, int x, int y) + : base(button, clicks, x, y, 0) + { + throw new PlatformNotSupportedException(); + } + + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public StatusBarPanel StatusBarPanel + { + get + { + throw new PlatformNotSupportedException(); + } + } +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEventHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEventHandler.cs new file mode 100644 index 00000000000..224e2e204e4 --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEventHandler.cs @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; + +namespace System.Windows.Forms; +#pragma warning disable RS0016 +[Obsolete("StatusBarPanelStyle has been deprecated. Use the StatusBarPanel.Style property instead. http://go.microsoft.com/fwlink/?linkid=14202")] +[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] +public delegate void StatusBarPanelClickEventHandler(object sender, StatusBarPanelClickEventArgs e); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelStyle.cs new file mode 100644 index 00000000000..18d3dd2bcfe --- /dev/null +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelStyle.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Windows.Forms; + +#pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete("StatusBarPanelStyle has been deprecated.")] +public enum StatusBarPanelStyle +{ + Text = 1, + + OwnerDraw = 2, +} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs index cad69f15425..6fdf8b79659 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs @@ -17,7 +17,7 @@ public class ToolBar : Control /// /// The size of a button in the ToolBar /// - internal Size buttonSize = System.Drawing.Size.Empty; + internal Size buttonSize = Size.Empty; /// /// This represents the width of the drop down arrow we have if the /// DropDownArrows property is true. this value is used by the ToolBarButton @@ -25,17 +25,6 @@ public class ToolBar : Control /// internal const int DDARROW_WIDTH = 15; - /// - /// Indicates what our appearance will be. This will either be normal - /// or flat. - /// - private ToolBarAppearance appearance = ToolBarAppearance.Normal; - - /// - /// Indicates whether or not we have a border - /// - private BorderStyle borderStyle = System.Windows.Forms.BorderStyle.None; - /// /// The array of buttons we're working with. /// @@ -46,31 +35,11 @@ public class ToolBar : Control /// private int buttonCount; - /// - /// Indicates if text captions should go underneath images in buttons or - /// to the right of them - /// - private ToolBarTextAlign textAlign = ToolBarTextAlign.Underneath; - /// /// The ImageList object that contains the main images for our control. /// private ImageList imageList; - private const int TOOLBARSTATE_wrappable = 0x00000001; - private const int TOOLBARSTATE_dropDownArrows = 0x00000002; - private const int TOOLBARSTATE_divider = 0x00000004; - private const int TOOLBARSTATE_showToolTips = 0x00000008; - private const int TOOLBARSTATE_autoSize = 0x00000010; - - // PERF: take all the bools and put them into a state variable - private Collections.Specialized.BitVector32 toolBarState; // see TOOLBARSTATE_ consts above - - // event handlers - // - private ToolBarButtonClickEventHandler onButtonClick; - private ToolBarButtonClickEventHandler onButtonDropDown; - /// /// Initializes a new instance of the class. /// @@ -91,16 +60,12 @@ public ToolBarAppearance Appearance { get { - return appearance; + throw new PlatformNotSupportedException(); } set { - if (value != appearance) - { - appearance = value; - RecreateHandle(); - } + throw new PlatformNotSupportedException(); } } @@ -118,31 +83,12 @@ public override bool AutoSize { get { - return toolBarState[TOOLBARSTATE_autoSize]; + throw new PlatformNotSupportedException(); } set { - // Note that we intentionally do not call base. Toolbars size themselves by - // overriding SetBoundsCore (old RTM code). We let CommonProperties.GetAutoSize - // continue to return false to keep our LayoutEngines from messing with TextBoxes. - // This is done for backwards compatibility since the new AutoSize behavior differs. - if (AutoSize != value) - { - toolBarState[TOOLBARSTATE_autoSize] = value; - if (Dock == DockStyle.Left || Dock == DockStyle.Right) - { - SetStyle(ControlStyles.FixedWidth, AutoSize); - SetStyle(ControlStyles.FixedHeight, false); - } - else - { - SetStyle(ControlStyles.FixedHeight, AutoSize); - SetStyle(ControlStyles.FixedWidth, false); - } - - OnAutoSizeChanged(EventArgs.Empty); - } + throw new PlatformNotSupportedException(); } } @@ -150,8 +96,8 @@ public override bool AutoSize [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler AutoSizeChanged { - add => base.AutoSizeChanged += value; - remove => base.AutoSizeChanged -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] @@ -159,19 +105,19 @@ public override Color BackColor { get { - return base.BackColor; + throw new PlatformNotSupportedException(); } set { - base.BackColor = value; + throw new PlatformNotSupportedException(); } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackColorChanged { - add => base.BackColorChanged += value; - remove => base.BackColorChanged -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] @@ -179,19 +125,19 @@ public override Image BackgroundImage { get { - return base.BackgroundImage; + throw new PlatformNotSupportedException(); } set { - base.BackgroundImage = value; + throw new PlatformNotSupportedException(); } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageChanged { - add => base.BackgroundImageChanged += value; - remove => base.BackgroundImageChanged -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] @@ -199,19 +145,19 @@ public override ImageLayout BackgroundImageLayout { get { - return base.BackgroundImageLayout; + throw new PlatformNotSupportedException(); } set { - base.BackgroundImageLayout = value; + throw new PlatformNotSupportedException(); } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageLayoutChanged { - add => base.BackgroundImageLayoutChanged += value; - remove => base.BackgroundImageLayoutChanged -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -223,17 +169,12 @@ public BorderStyle BorderStyle { get { - return borderStyle; + throw new PlatformNotSupportedException(); } set { - if (borderStyle != value) - { - borderStyle = value; - - RecreateHandle(); // Looks like we need to recreate the handle to avoid painting glitches - } + throw new PlatformNotSupportedException(); } } @@ -246,7 +187,7 @@ public ToolBarButtonCollection Buttons { get { - return buttonsCollection; + throw new PlatformNotSupportedException(); } } @@ -259,35 +200,12 @@ public Size ButtonSize { get { - if (buttonSize.IsEmpty) - { - if (TextAlign == ToolBarTextAlign.Underneath) - { - return new Size(39, 36); // Default button size - } - else - { - return new Size(23, 22); // Default button size - } - } - else - { - return buttonSize; - } + throw new PlatformNotSupportedException(); } set { - if (value.Width < 0 || value.Height < 0) - { - throw new ArgumentOutOfRangeException(nameof(value), value, string.Format(SR.InvalidArgument, nameof(ButtonSize), value)); - } - - if (buttonSize != value) - { - buttonSize = value; - RecreateHandle(); - } + throw new PlatformNotSupportedException(); } } @@ -300,16 +218,12 @@ public bool Divider { get { - return toolBarState[TOOLBARSTATE_divider]; + throw new PlatformNotSupportedException(); } set { - if (Divider != value) - { - toolBarState[TOOLBARSTATE_divider] = value; - RecreateHandle(); - } + throw new PlatformNotSupportedException(); } } @@ -320,25 +234,11 @@ public bool Divider [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public override DockStyle Dock { - get { return base.Dock; } + get { throw new PlatformNotSupportedException(); } set { - if (Dock != value) - { - if (value == DockStyle.Left || value == DockStyle.Right) - { - SetStyle(ControlStyles.FixedWidth, AutoSize); - SetStyle(ControlStyles.FixedHeight, false); - } - else - { - SetStyle(ControlStyles.FixedHeight, AutoSize); - SetStyle(ControlStyles.FixedWidth, false); - } - - base.Dock = value; - } + throw new PlatformNotSupportedException(); } } @@ -351,16 +251,12 @@ public bool DropDownArrows { get { - return toolBarState[TOOLBARSTATE_dropDownArrows]; + throw new PlatformNotSupportedException(); } set { - if (DropDownArrows != value) - { - toolBarState[TOOLBARSTATE_dropDownArrows] = value; - RecreateHandle(); - } + throw new PlatformNotSupportedException(); } } @@ -369,19 +265,19 @@ public override Color ForeColor { get { - return base.ForeColor; + throw new PlatformNotSupportedException(); } set { - base.ForeColor = value; + throw new PlatformNotSupportedException(); } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler ForeColorChanged { - add => base.ForeColorChanged += value; - remove => base.ForeColorChanged -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -393,17 +289,11 @@ public ImageList ImageList { get { - return imageList; + throw new PlatformNotSupportedException(); } set { - if (value != imageList) - { - if (IsHandleCreated) - { - RecreateHandle(); - } - } + throw new PlatformNotSupportedException(); } } @@ -416,14 +306,7 @@ public Size ImageSize { get { - if (imageList is not null) - { - return imageList.ImageSize; - } - else - { - return new Size(0, 0); - } + throw new PlatformNotSupportedException(); } } @@ -432,19 +315,19 @@ public Size ImageSize { get { - return base.ImeMode; + throw new PlatformNotSupportedException(); } set { - base.ImeMode = value; + throw new PlatformNotSupportedException(); } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler ImeModeChanged { - add => base.ImeModeChanged += value; - remove => base.ImeModeChanged -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] @@ -452,19 +335,19 @@ public override RightToLeft RightToLeft { get { - return base.RightToLeft; + throw new PlatformNotSupportedException(); } set { - base.RightToLeft = value; + throw new PlatformNotSupportedException(); } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler RightToLeftChanged { - add => base.RightToLeftChanged += value; - remove => base.RightToLeftChanged -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -479,15 +362,11 @@ public bool ShowToolTips { get { - return toolBarState[TOOLBARSTATE_showToolTips]; + throw new PlatformNotSupportedException(); } set { - if (ShowToolTips != value) - { - toolBarState[TOOLBARSTATE_showToolTips] = value; - RecreateHandle(); - } + throw new PlatformNotSupportedException(); } } @@ -497,11 +376,11 @@ public bool ShowToolTips { get { - return base.TabStop; + throw new PlatformNotSupportedException(); } set { - base.TabStop = value; + throw new PlatformNotSupportedException(); } } @@ -512,19 +391,19 @@ public override string Text { get { - return base.Text; + throw new PlatformNotSupportedException(); } set { - base.Text = value; + throw new PlatformNotSupportedException(); } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler TextChanged { - add => base.TextChanged += value; - remove => base.TextChanged -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -540,17 +419,11 @@ public ToolBarTextAlign TextAlign { get { - return textAlign; + throw new PlatformNotSupportedException(); } set { - if (textAlign == value) - { - return; - } - - textAlign = value; - RecreateHandle(); + throw new PlatformNotSupportedException(); } } @@ -569,15 +442,11 @@ public bool Wrappable { get { - return toolBarState[TOOLBARSTATE_wrappable]; + throw new PlatformNotSupportedException(); } set { - if (Wrappable != value) - { - toolBarState[TOOLBARSTATE_wrappable] = value; - RecreateHandle(); - } + throw new PlatformNotSupportedException(); } } @@ -588,8 +457,8 @@ public bool Wrappable [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event ToolBarButtonClickEventHandler ButtonClick { - add => onButtonClick += value; - remove => onButtonClick -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -599,8 +468,8 @@ public bool Wrappable [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public event ToolBarButtonClickEventHandler ButtonDropDown { - add => onButtonDropDown += value; - remove => onButtonDropDown -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -610,8 +479,8 @@ public bool Wrappable [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new event PaintEventHandler Paint { - add => base.Paint += value; - remove => base.Paint -= value; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } /// @@ -652,24 +521,11 @@ public ToolBarButtonCollection(ToolBar owner) { get { - if (index < 0 || ((owner.buttons is not null) && (index >= owner.buttonCount))) - { - throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); - } - - return owner.buttons[index]; + throw new PlatformNotSupportedException(); } set { - if (index < 0 || ((owner.buttons is not null) && index >= owner.buttonCount)) - { - throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index)); - } - - if (value is null) - { - throw new ArgumentNullException(nameof(value)); - } + throw new PlatformNotSupportedException(); } } @@ -701,15 +557,7 @@ public ToolBarButtonCollection(ToolBar owner) { get { - // We do not support null and empty string as valid keys. - if (string.IsNullOrEmpty(key)) - { - return null; - } - - // Search for the key in our collection - int index = IndexOfKey(key); - return this[index]; + throw new PlatformNotSupportedException(); } } @@ -721,7 +569,7 @@ public int Count { get { - return owner.buttonCount; + throw new PlatformNotSupportedException(); } } @@ -757,7 +605,7 @@ public bool IsReadOnly { get { - return false; + throw new PlatformNotSupportedException(); } } From 8c05aa15089783ba0be38eaeb1b2d7538c76aad1 Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Mon, 11 Mar 2024 14:22:33 +0800 Subject: [PATCH 03/11] Fix failure test cases --- .../Obsolete/DataGrid/DataGridColumn.cs | 2 +- .../DataGrid/DataGridRelationshipRow.cs | 4 +- .../Controls/Obsolete/DataGrid/DataGridRow.cs | 4 +- .../Obsolete/DataGrid/DataGridState.cs | 1 + .../Obsolete/ObsoleteControls.Designer.cs | 128 +++++++++++ .../Obsolete/ObsoleteControls.cs | 211 ++++++++++++++++++ .../Obsolete/ObsoleteControls.resx | 64 ++++++ .../AccessibleObjectTests.cs | 10 +- .../Control.ControlAccessibleObjectTests.cs | 11 +- 9 files changed, 428 insertions(+), 7 deletions(-) create mode 100644 src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.Designer.cs create mode 100644 src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs create mode 100644 src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.resx diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs index 682b5e4c84d..3feff3cf676 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs @@ -654,7 +654,7 @@ public static TraceSwitch DGEditColumnEditing [Runtime.InteropServices.ComVisible(true)] [Obsolete("DataGridColumnHeaderAccessibleObject has been deprecated.")] - protected class DataGridColumnHeaderAccessibleObject : AccessibleObject + internal class DataGridColumnHeaderAccessibleObject : AccessibleObject { public DataGridColumnHeaderAccessibleObject(DataGridColumnStyle owner) : this() { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs index 185d50287aa..af93be8479d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs @@ -603,7 +603,7 @@ private int MirrorRectangle(int x, int width, Rectangle rect, bool alignToRight) [ComVisible(true)] [Obsolete("DataGridRelationshipRowAccessibleObject has been deprecated.")] - protected class DataGridRelationshipRowAccessibleObject : DataGridRowAccessibleObject + internal class DataGridRelationshipRowAccessibleObject : DataGridRowAccessibleObject { public DataGridRelationshipRowAccessibleObject(DataGridRow owner) : base(owner) { @@ -663,7 +663,7 @@ public override AccessibleObject GetFocused() [ComVisible(true)] [Obsolete("DataGridRelationshipAccessibleObject has been deprecated.")] - protected class DataGridRelationshipAccessibleObject : AccessibleObject + internal class DataGridRelationshipAccessibleObject : AccessibleObject { public DataGridRelationshipAccessibleObject(DataGridRelationshipRow owner, int relationship) : base() { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs index e9376c49362..efc4f16bb5c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs @@ -422,7 +422,7 @@ protected Brush ForeBrushForDataPaint(ref DataGridCell current, DataGridColumnSt [ComVisible(true)] [Obsolete("DataGridRowAccessibleObject has been deprecated.")] - protected class DataGridRowAccessibleObject : AccessibleObject + internal class DataGridRowAccessibleObject : AccessibleObject { private ArrayList cells; @@ -577,7 +577,7 @@ public override void Select(AccessibleSelection flags) [ComVisible(true)] [Obsolete("DataGridCellAccessibleObject has been deprecated.")] - protected class DataGridCellAccessibleObject : AccessibleObject + internal class DataGridCellAccessibleObject : AccessibleObject { public DataGridCellAccessibleObject(DataGridRow owner, int column) : base() { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs index 10ff0f5a820..68959fa4dfd 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs @@ -92,6 +92,7 @@ private void DataSource_MetaDataChanged(object sender, EventArgs e) } [ComVisible(true)] + [Obsolete("DataGridStateParentRowAccessibleObject has been deprecated.")] internal class DataGridStateParentRowAccessibleObject : AccessibleObject { public DataGridStateParentRowAccessibleObject(DataGridState owner) : base() diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.Designer.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.Designer.cs new file mode 100644 index 00000000000..b7926bde39d --- /dev/null +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.Designer.cs @@ -0,0 +1,128 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; + +namespace WinformsControlsTest; + +partial class ObsoleteControls +{ + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { +#pragma warning disable CS0618 // Type or member is obsolete + this.components = new System.ComponentModel.Container(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.dataGrid1 = new System.Windows.Forms.DataGrid(); + this.contextMenu1 = new System.Windows.Forms.ContextMenu(); + this.menuItem1 = new System.Windows.Forms.MenuItem(); + this.toolBar1 = new System.Windows.Forms.ToolBar(); + this.toolBarButton1 = new System.Windows.Forms.ToolBarButton(); + this.toolBarButton2 = new System.Windows.Forms.ToolBarButton(); + this.statusBar1 = new System.Windows.Forms.StatusBar(); + this.panel1 = new System.Windows.Forms.StatusBarPanel(); + this.panel2 = new System.Windows.Forms.StatusBarPanel(); + this.SuspendLayout(); + // + // button1 + // + button1.Location = new Point(24, 16); + button1.Size = new System.Drawing.Size(120, 24); + button1.Text = "Change Appearance"; + button1.Click += new System.EventHandler(button1_Click); + // + // button2 + // + button2.Location = new Point(150, 16); + button2.Size = new System.Drawing.Size(120, 24); + button2.Text = "Get Binding Manager"; + button2.Click += new System.EventHandler(button2_Click); + // + // dataGrid1 + // + dataGrid1.Location = new Point(24, 50); + dataGrid1.Size = new Size(300, 200); + dataGrid1.CaptionText = "Microsoft DataGrid Control"; + dataGrid1.MouseUp += new MouseEventHandler(Grid_MouseUp); + // dataGrid1.ContextMenu = this.contextMenu1; + // + // contextMenu1 + // + this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.menuItem1}); + // + // menuItem1 + // + this.menuItem1.Index = 0; + this.menuItem1.Text = "New"; + this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); + // + // toolBar1 + // + this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] { this.toolBarButton1, this.toolBarButton2 }); + this.toolBar1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.toolBarButton1.Text = "Save"; + this.toolBarButton2.Text = "Open"; + // + // statusBar1 + // + this.statusBar1.Location = new System.Drawing.Point(4, 300); + this.statusBar1.Size = new System.Drawing.Size(50, 50); + this.statusBar1.ShowPanels = true; + this.panel1.Text = "Ready"; + this.panel2.Text = "Loading..."; + this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] { this.panel1, this.panel2 }); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button1); + this.Controls.Add(this.button2); + this.Controls.Add(this.dataGrid1); + this.Name = "Obsolete-DataGrid"; + this.Text = "Obsolete-DataGrid"; + this.ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.DataGrid dataGrid1; + private System.Data.DataSet myDataSet; + private System.Windows.Forms.ContextMenu contextMenu1; + private System.Windows.Forms.MenuItem menuItem1; + private System.Windows.Forms.ToolBar toolBar1; + private System.Windows.Forms.ToolBarButton toolBarButton1; + private System.Windows.Forms.ToolBarButton toolBarButton2; + private System.Windows.Forms.StatusBar statusBar1; + private System.Windows.Forms.StatusBarPanel panel1; + private System.Windows.Forms.StatusBarPanel panel2; +#pragma warning restore CS0618 // Type or member is obsolete +} diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs new file mode 100644 index 00000000000..dd949e00b3f --- /dev/null +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs @@ -0,0 +1,211 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Data; +using System.Drawing; +#pragma warning disable CS0618 +using static System.Windows.Forms.DataGrid; + +namespace WinformsControlsTest; + +public partial class ObsoleteControls : Form +{ + private bool TablesAlreadyAdded; + public ObsoleteControls() + { + InitializeComponent(); + CreateMainMenu(); + SetUp(); + } + + private void CreateMainMenu() + { + MainMenu mainMenu = new MainMenu(); + MenuItem fileMenuItem = new MenuItem("File", new EventHandler(menuItem2_Click)); + mainMenu.MenuItems.Add(fileMenuItem); + } + + void menuItem1_Click(object sender, System.EventArgs e) + { + MessageBox.Show("New menu item clicked", "DataGrid"); + } + + void menuItem2_Click(object sender, System.EventArgs e) + { + MessageBox.Show("New menu item clicked", "MainMenu"); + } + + private void button1_Click(object sender, System.EventArgs e) + { + if (TablesAlreadyAdded) + return; + AddCustomDataTableStyle(); + } + + private void button2_Click(object sender, System.EventArgs e) + { + BindingManagerBase bmGrid; + bmGrid = BindingContext[myDataSet, "Customers"]; + MessageBox.Show("Current BindingManager Position: " + bmGrid.Position); + } + + private void Grid_MouseUp(object sender, MouseEventArgs e) + { + HitTestInfo myHitInfo = dataGrid1.HitTest(e.X, e.Y); + Console.WriteLine(myHitInfo); + Console.WriteLine(myHitInfo.Type); + Console.WriteLine(myHitInfo.Row); + Console.WriteLine(myHitInfo.Column); + } + + private void AddCustomDataTableStyle() + { + DataGridTableStyle ts1 = new DataGridTableStyle(); + ts1.MappingName = "Customers"; + // Set other properties. + ts1.AlternatingBackColor = Color.LightGray; + + /* Add a GridColumnStyle and set its MappingName + to the name of a DataColumn in the DataTable. + Set the HeaderText and Width properties. */ + + DataGridColumnStyle boolCol = new DataGridBoolColumn(); + boolCol.MappingName = "Current"; + boolCol.HeaderText = "IsCurrent Customer"; + boolCol.Width = 150; + ts1.GridColumnStyles.Add(boolCol); + + // Add a second column style. + DataGridColumnStyle TextCol = new DataGridTextBoxColumn(); + TextCol.MappingName = "custName"; + TextCol.HeaderText = "Customer Name"; + TextCol.Width = 250; + ts1.GridColumnStyles.Add(TextCol); + + // Create the second table style with columns. + DataGridTableStyle ts2 = new DataGridTableStyle(); + ts2.MappingName = "Orders"; + + // Set other properties. + ts2.AlternatingBackColor = Color.LightBlue; + + // Create new ColumnStyle objects + DataGridColumnStyle cOrderDate = + new DataGridTextBoxColumn(); + cOrderDate.MappingName = "OrderDate"; + cOrderDate.HeaderText = "Order Date"; + cOrderDate.Width = 100; + ts2.GridColumnStyles.Add(cOrderDate); + + /* Use a PropertyDescriptor to create a formatted + column. First get the PropertyDescriptorCollection + for the data source and data member. */ + PropertyDescriptorCollection pcol = this.BindingContext + [myDataSet, "Customers.custToOrders"].GetItemProperties(); + + /* Create a formatted column using a PropertyDescriptor. + The formatting character "c" specifies a currency format. */ + DataGridColumnStyle csOrderAmount = + new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true); + csOrderAmount.MappingName = "OrderAmount"; + csOrderAmount.HeaderText = "Total"; + csOrderAmount.Width = 100; + ts2.GridColumnStyles.Add(csOrderAmount); + + /* Add the DataGridTableStyle instances to + the GridTableStylesCollection. */ + dataGrid1.TableStyles.Add(ts1); + dataGrid1.TableStyles.Add(ts2); + + // Sets the TablesAlreadyAdded to true so this doesn't happen again. + TablesAlreadyAdded = true; + } + + private void SetUp() + { + // Create a DataSet with two tables and one relation. + MakeDataSet(); + /* Bind the DataGrid to the DataSet. The dataMember + specifies that the Customers table should be displayed.*/ + dataGrid1.SetDataBinding(myDataSet, "Customers"); + } + + // Create a DataSet with two tables and populate it. + private void MakeDataSet() + { + // Create a DataSet. + myDataSet = new DataSet("myDataSet"); + + // Create two DataTables. + DataTable tCust = new DataTable("Customers"); + DataTable tOrders = new DataTable("Orders"); + + // Create two columns, and add them to the first table. + DataColumn cCustID = new DataColumn("CustID", typeof(int)); + DataColumn cCustName = new DataColumn("CustName"); + DataColumn cCurrent = new DataColumn("Current", typeof(bool)); + tCust.Columns.Add(cCustID); + tCust.Columns.Add(cCustName); + tCust.Columns.Add(cCurrent); + + // Create three columns, and add them to the second table. + DataColumn cID = + new DataColumn("CustID", typeof(int)); + DataColumn cOrderDate = + new DataColumn("orderDate", typeof(DateTime)); + DataColumn cOrderAmount = + new DataColumn("OrderAmount", typeof(decimal)); + tOrders.Columns.Add(cOrderAmount); + tOrders.Columns.Add(cID); + tOrders.Columns.Add(cOrderDate); + + // Add the tables to the DataSet. + myDataSet.Tables.Add(tCust); + myDataSet.Tables.Add(tOrders); + + // Create a DataRelation, and add it to the DataSet. + DataRelation dr = new DataRelation + ("custToOrders", cCustID, cID); + myDataSet.Relations.Add(dr); + + /* Populates the tables. For each customer and order, + creates two DataRow variables. */ + DataRow newRow1; + DataRow newRow2; + + // Create three customers in the Customers Table. + for (int i = 1; i < 4; i++) + { + newRow1 = tCust.NewRow(); + newRow1["custID"] = i; + // Add the row to the Customers table. + tCust.Rows.Add(newRow1); + } + + // Give each customer a distinct name. + tCust.Rows[0]["custName"] = "Customer1"; + tCust.Rows[1]["custName"] = "Customer2"; + tCust.Rows[2]["custName"] = "Customer3"; + + // Give the Current column a value. + tCust.Rows[0]["Current"] = true; + tCust.Rows[1]["Current"] = true; + tCust.Rows[2]["Current"] = false; + + // For each customer, create five rows in the Orders table. + for (int i = 1; i < 4; i++) + { + for (int j = 1; j < 6; j++) + { + newRow2 = tOrders.NewRow(); + newRow2["CustID"] = i; + newRow2["orderDate"] = new DateTime(2001, i, j * 2); + newRow2["OrderAmount"] = i * 10 + j * .1; + // Add the row to the Orders table. + tOrders.Rows.Add(newRow2); + } + } + } +} +#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.resx b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.resx new file mode 100644 index 00000000000..2a5e6f3c363 --- /dev/null +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.resx @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs index 64d28395640..bc7e2bb7fee 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs @@ -2690,6 +2690,14 @@ public void AccessibleObject_GetPropertyValue_ReturnsNull_IfExpected(int propert public static IEnumerable AccessibleObject_RuntimeId_IsOverriden_TestData() { +#pragma warning disable CS0618 // Type or member is obsolete + var typesToIgnore = new[] + { + typeof(ComboBox.ChildAccessibleObject), typeof(DataGridState.DataGridStateParentRowAccessibleObject), typeof(DataGridRow.DataGridCellAccessibleObject), + typeof(DataGridRow.DataGridRowAccessibleObject), typeof(DataGridRelationshipRow.DataGridRelationshipRowAccessibleObject), typeof(DataGridRelationshipRow.DataGridRelationshipAccessibleObject), + typeof(DataGridParentRows.DataGridParentRowsAccessibleObject), typeof(DataGridColumnStyle.DataGridColumnHeaderAccessibleObject), + }; +#pragma warning restore CS0618 // Type or member is obsolete Assembly assembly = typeof(AccessibleObject).Assembly; foreach (Type type in assembly.GetTypes()) { @@ -2699,7 +2707,7 @@ public static IEnumerable AccessibleObject_RuntimeId_IsOverriden_TestD continue; } - if (type == typeof(ComboBox.ChildAccessibleObject)) + if (typesToIgnore.Contains(type)) { continue; } diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs index 2192dc5982d..79719de7862 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs @@ -1219,7 +1219,16 @@ public void ControlAccessibleObject_Supports_LegacyIAccessiblePattern_IfOwnerSup public static IEnumerable ControlAccessibleObject_TestData() { - return ReflectionHelper.GetPublicNotAbstractClasses().Select(type => new object[] { type }); +#pragma warning disable CS0618 // Type or member is obsolete + var typesToIgnore = new[] + { + typeof(DataGrid), typeof(StatusBar), typeof(ToolBar), typeof(DataGridTextBox) + }; + #pragma warning restore CS0618 // Type or member is obsolete + + return ReflectionHelper.GetPublicNotAbstractClasses() + .Where(t => !typesToIgnore.Contains(t)) + .Select(type => new object[] { type }); } [WinFormsTheory] From 71912aed95c00619b45c0b8b3f10197b48a490bf Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Mon, 11 Mar 2024 15:13:38 +0800 Subject: [PATCH 04/11] Fix failure test case --- .../Control.ControlAccessibleObjectTests.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs index 79719de7862..95ec2bfef31 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs @@ -1341,8 +1341,20 @@ public static IEnumerable ControlAccessibleObject_DefaultName_TestData { typeof(MaskedTextBox), string.Empty} }; +#pragma warning disable CS0618 // Type or member is obsolete + var typesToIgnore = new[] + { + typeof(DataGrid), typeof(StatusBar), typeof(ToolBar), typeof(DataGridTextBox) + }; +#pragma warning restore CS0618 // Type or member is obsolete + foreach (Type type in ReflectionHelper.GetPublicNotAbstractClasses()) { + if (typesToIgnore.Contains(type)) + { + continue; + } + yield return new object[] { type, From 9e97dbd83d22f51a5df6dfdb3ec4280dff95320c Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Mon, 11 Mar 2024 15:48:13 +0800 Subject: [PATCH 05/11] Fix failure test case --- .../Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs index 06cdd72c3e0..48e85b96d12 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs @@ -14,11 +14,7 @@ namespace System.Windows.Forms; [Obsolete("DataGrid has been deprecated. Use DataGridView instead.")] public class DataGrid : Control, ISupportInitialize, IDataGridEditingService { -#if DEBUG internal TraceSwitch DataGridAcc = new TraceSwitch("DataGridAcc", "Trace Windows Forms DataGrid Accessibility"); -#else - internal TraceSwitch DataGridAcc = null; -#endif private const int GRIDSTATE_trackColResize = 0x00000008; private const int GRIDSTATE_trackRowResize = 0x00000010; From 8dc151f377adec5eb05fd3ea5f4c96197606dfbe Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Tue, 2 Apr 2024 09:40:28 +0800 Subject: [PATCH 06/11] Remove non-essential codes and reformat codes --- docs/list-of-diagnostics.md | 56 + src/Common/src/Obsoletions.cs | 249 + .../Obsolete/ContextMenu/ContextMenu.cs | 93 +- .../Controls/Obsolete/ContextMenu/Menu.cs | 302 +- .../Controls/Obsolete/ContextMenu/MenuItem.cs | 393 +- .../Obsolete/ContextMenu/MenuMerge.cs | 37 +- .../Controls/Obsolete/DataGrid/DataGrid.cs | 8413 ++--------------- .../Obsolete/DataGrid/DataGridAddNewRow.cs | 86 +- .../Obsolete/DataGrid/DataGridBoolColumn.cs | 441 +- .../Obsolete/DataGrid/DataGridCaption.cs | 878 +- .../Obsolete/DataGrid/DataGridCell.cs | 71 +- .../Obsolete/DataGrid/DataGridColumn.cs | 644 +- .../Obsolete/DataGrid/DataGridLineStyle.cs | 10 +- .../Obsolete/DataGrid/DataGridParentRows.cs | 1115 +-- .../DataGrid/DataGridParentRowsLabel.cs | 12 +- ...taGridPreferredColumnWidthTypeConverter.cs | 18 +- .../DataGrid/DataGridRelationshipRow.cs | 748 +- .../Controls/Obsolete/DataGrid/DataGridRow.cs | 623 +- .../Obsolete/DataGrid/DataGridState.cs | 126 +- .../Obsolete/DataGrid/DataGridTable.cs | 1305 +-- .../DataGrid/DataGridTableCollection.cs | 143 +- .../DataGrid/DataGridTablesFactory.cs | 14 +- .../Obsolete/DataGrid/DataGridTextBox.cs | 137 +- .../DataGrid/DataGridTextBoxColumn.cs | 414 +- .../Obsolete/DataGrid/DataGridToolTip.cs | 30 +- .../DataGrid/GridColumnStylesCollection.cs | 217 +- .../DataGrid/IDataGridEditingService.cs | 10 +- .../Controls/Obsolete/MainMenu/MainMenu.cs | 87 +- .../Controls/Obsolete/StatusBar/StatusBar.cs | 1256 +-- .../StatusBar/StatusBarDrawItemEvent.cs | 40 +- .../StatusBarDrawItemEventHandler.cs | 9 +- .../Obsolete/StatusBar/StatusBarPanel.cs | 362 +- .../StatusBar/StatusBarPanelAutoSize.cs | 11 +- .../StatusBar/StatusBarPanelBorderStyle.cs | 11 +- .../StatusBar/StatusBarPanelClickEvent.cs | 28 +- .../StatusBarPanelClickEventHandler.cs | 13 +- .../Obsolete/StatusBar/StatusBarPanelStyle.cs | 10 +- .../Controls/Obsolete/ToolBar/ToolBar.cs | 651 +- .../Obsolete/ToolBar/ToolBarAppearance.cs | 11 +- .../Obsolete/ToolBar/ToolBarButton.cs | 422 +- .../ToolBar/ToolBarButtonClickEventArgs.cs | 21 +- .../ToolBar/ToolBarButtonClickEventHandler.cs | 9 +- .../Obsolete/ToolBar/ToolBarButtonStyle.cs | 15 +- .../Obsolete/ToolBar/ToolBarTextAlign.cs | 10 +- .../MainFormControlsTabOrder.cs | 3 +- .../WinformsControlsTest/MainForm.cs | 2 +- .../Obsolete/ObsoleteControls.Designer.cs | 4 +- .../Obsolete/ObsoleteControls.cs | 80 +- .../AccessibleObjectTests.cs | 4 +- .../Control.ControlAccessibleObjectTests.cs | 8 +- 50 files changed, 2787 insertions(+), 16865 deletions(-) diff --git a/docs/list-of-diagnostics.md b/docs/list-of-diagnostics.md index a64334ad409..8473d5a28eb 100644 --- a/docs/list-of-diagnostics.md +++ b/docs/list-of-diagnostics.md @@ -38,6 +38,62 @@ The acceptance criteria for adding an obsoletion includes: | __`WFDEV001`__ | Casting to/from IntPtr is unsafe, use `ResultInternal`. | | __`WFDEV002`__ | `DomainUpDown.DomainUpDownAccessibleObject` is no longer used to provide accessible support for `DomainUpDown` controls. Use `ControlAccessibleObject` instead. | | __`WFDEV003`__ | `DomainUpDown.DomainItemAccessibleObject` is no longer used to provide accessible support for `DomainUpDown` items. | +| __`WFDEV004`__ | `ContextMenu` has been deprecated. Use `ContextMenuStrip` instead. | +| __`WFDEV005`__ | `Menu` has been deprecated. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead. | +| __`WFDEV006`__ | `Menu.MenuItemCollection` has been deprecated. | +| __`WFDEV007`__ | `MenuItem` has been deprecated. Use `ToolStripMenuItem` instead. | +| __`WFDEV008`__ | `MenuMerge` has been deprecated. | +| __`WFDEV009`__ | `DataGrid` has been deprecated. Use `DataGridView` instead. | +| __`WFDEV010`__ | `DataGrid.HitTestInfo` has been deprecated. | +| __`WFDEV011`__ | `DataGrid.HitTestType` has been deprecated. | +| __`WFDEV012`__ | `DataGrid.DataGridAccessibleObject` has been deprecated. | +| __`WFDEV013`__ | `DataGridAddNewRow` has been deprecated. | +| __`WFDEV014`__ | `DataGridBoolColumn` has been deprecated. | +| __`WFDEV015`__ | `DataGridCaption` has been deprecated. | +| __`WFDEV016`__ | `DataGridCell` has been deprecated. | +| __`WFDEV017`__ | `DataGridColumnStyle` has been deprecated. | +| __`WFDEV018`__ | `DataGridColumnHeaderAccessibleObject` has been deprecated. | +| __`WFDEV019`__ | `DataGridLineStyle` has been deprecated. | +| __`WFDEV020`__ | `DataGridParentRows` has been deprecated. | +| __`WFDEV021`__ | `DataGridParentRowsAccessibleObject` has been deprecated. | +| __`WFDEV022`__ | `DataGridParentRowsLabelStyle` has been deprecated. | +| __`WFDEV023`__ | `DataGridPreferredColumnWidthTypeConverter` has been deprecated. | +| __`WFDEV024`__ | `DataGridRelationshipRow` has been deprecated. | +| __`WFDEV025`__ | `DataGridRelationshipRowAccessibleObject` has been deprecated. | +| __`WFDEV026`__ | `DataGridRelationshipAccessibleObject` has been deprecated. | +| __`WFDEV027`__ | `DataGridRow` has been deprecated. | +| __`WFDEV028`__ | `DataGridRowAccessibleObject` has been deprecated. | +| __`WFDEV029`__ | `DataGridCellAccessibleObject` has been deprecated. | +| __`WFDEV030`__ | `DataGridState` has been deprecated. | +| __`WFDEV031`__ | `DataGridStateParentRowAccessibleObject` has been deprecated. | +| __`WFDEV032`__ | `DataGridTableStyle` has been deprecated. | +| __`WFDEV033`__ | `GridTableStylesCollection` has been deprecated. | +| __`WFDEV034`__ | `GridTablesFactory` has been deprecated. | +| __`WFDEV035`__ | `DataGridTextBox` has been deprecated. | +| __`WFDEV036`__ | `DataGridTextBoxColumn` has been deprecated. | +| __`WFDEV037`__ | `DataGridToolTip` has been deprecated. | +| __`WFDEV038`__ | `GridColumnStylesCollection` has been deprecated. | +| __`WFDEV039`__ | `IDataGridEditingService` has been deprecated. | +| __`WFDEV040`__ | `MainMenu` has been deprecated. Use `MenuStrip` instead. | +| __`WFDEV041`__ | `StatusBar` has been deprecated. Use `StatusStrip` instead. | +| __`WFDEV042`__ | `StatusBarPanelCollection` has been deprecated. | +| __`WFDEV043`__ | `StatusBarDrawItemEventArgs` has been deprecated. Use `DrawItemEventArgs` instead. | +| __`WFDEV044`__ | `StatusBarDrawItemEventHandler` has been deprecated. Use `DrawItemEventHandler` instead. | +| __`WFDEV045`__ | `StatusBarPanel` has been deprecated. Use `StatusStrip` instead. | +| __`WFDEV046`__ | `StatusBarPanelAutoSize` has been deprecated. | +| __`WFDEV047`__ | `StatusBarPanelBorderStyle` has been deprecated. Use the `BorderStyle` property of the `StatusBarPanel` class instead. | +| __`WFDEV048`__ | `StatusBarPanelClickEventArgs` has been deprecated. | +| __`WFDEV049`__ | `StatusBarPanelStyle` has been deprecated. Use `StatusBarPanel.Style` instead. | +| __`WFDEV050`__ | `StatusBarPanelClickEventHandler` has been deprecated. | +| __`WFDEV051`__ | `ToolBar` has been deprecated. Use `ToolStrip` instead. | +| __`WFDEV052`__ | `ToolBarButtonCollection` has been deprecated. | +| __`WFDEV053`__ | `ToolBarAppearance` has been deprecated. | +| __`WFDEV054`__ | `ToolBarButton` has been deprecated. Use `ToolStripButton` instead. | +| __`WFDEV055`__ | `ToolBarButtonClickEventArgs` has been deprecated. | +| __`WFDEV056`__ | `ToolBarButtonClickEventHandler` has been deprecated. | +| __`WFDEV057`__ | `ToolBarButtonStyle` has been deprecated. | +| __`WFDEV058`__ | `ToolBarTextAlign` has been deprecated. | + ## Analyzer Warnings diff --git a/src/Common/src/Obsoletions.cs b/src/Common/src/Obsoletions.cs index 0d665bb009b..eb6bc66ade2 100644 --- a/src/Common/src/Obsoletions.cs +++ b/src/Common/src/Obsoletions.cs @@ -21,4 +21,253 @@ internal static class Obsoletions internal const string DomainItemAccessibleObjectMessage = $"{nameof(DomainUpDown.DomainItemAccessibleObject)} is no longer used to provide accessible support for {nameof(DomainUpDown)} items."; #pragma warning restore WFDEV003 // Type or member is obsolete internal const string DomainItemAccessibleObjectDiagnosticId = "WFDEV003"; + +#pragma warning disable WFDEV004 // Type or member is obsolete + internal const string ContextMenuMessage = $"{nameof(ContextMenu)} has been deprecated. Use {nameof(ContextMenuStrip)} instead."; +#pragma warning restore WFDEV004 // Type or member is obsolete + internal const string ContextMenuDiagnosticId = "WFDEV004"; + +#pragma warning disable WFDEV005 // Type or member is obsolete + internal const string MenuMessage = $"{nameof(Menu)} has been deprecated. Use {nameof(ToolStripDropDown)} and {nameof(ToolStripDropDownMenu)} instead."; +#pragma warning restore WFDEV005 // Type or member is obsolete + internal const string MenuDiagnosticId = "WFDEV005"; + + internal const string MenuItemCollectionMessage = $"Menu.MenuItemCollection has been deprecated."; + internal const string MenuItemCollectionDiagnosticId = "WFDEV006"; + +#pragma warning disable WFDEV007 // Type or member is obsolete + internal const string MenuItemMessage = $"{nameof(MenuItem)} has been deprecated. Use {nameof(ToolStripMenuItem)} instead."; +#pragma warning restore WFDEV007 // Type or member is obsolete + internal const string MenuItemDiagnosticId = "WFDEV007"; + +#pragma warning disable WFDEV008 // Type or member is obsolete + internal const string MenuMergeMessage = $"{nameof(MenuMerge)} has been deprecated."; +#pragma warning restore WFDEV008 // Type or member is obsolete + internal const string MenuMergeDiagnosticId = "WFDEV008"; + +#pragma warning disable WFDEV009 // Type or member is obsolete + internal const string DataGridMessage = $"{nameof(DataGrid)} has been deprecated. Use {nameof(DataGridView)} instead."; +#pragma warning restore WFDEV009 // Type or member is obsolete + internal const string DataGridDiagnosticId = "WFDEV009"; + + internal const string DataGridHitTestInfoMessage = $"DataGrid.HitTestInfo has been deprecated."; + internal const string DataGridHitTestInfoDiagnosticId = "WFDEV010"; + + internal const string DataGridHitTestTypeMessage = $"DataGrid.HitTestType has been deprecated."; + internal const string DataGridHitTestTypeDiagnosticId = "WFDEV011"; + + internal const string DataGridAccessibleObjectMessage = $"DataGrid.DataGridAccessibleObject has been deprecated."; + internal const string DataGridAccessibleObjectDiagnosticId = "WFDEV012"; + +#pragma warning disable WFDEV013 // Type or member is obsolete + internal const string DataGridAddNewRowMessage = $"{nameof(DataGridAddNewRow)} has been deprecated."; +#pragma warning restore WFDEV013 // Type or member is obsolete + internal const string DataGridAddNewRowDiagnosticId = "WFDEV013"; + +#pragma warning disable WFDEV014 // Type or member is obsolete + internal const string DataGridBoolColumnMessage = $"{nameof(DataGridBoolColumn)} has been deprecated."; +#pragma warning restore WFDEV014 // Type or member is obsolete + internal const string DataGridBoolColumnDiagnosticId = "WFDEV014"; + +#pragma warning disable WFDEV015 // Type or member is obsolete + internal const string DataGridCaptionMessage = $"{nameof(DataGridCaption)} has been deprecated."; +#pragma warning restore WFDEV015 // Type or member is obsolete + internal const string DataGridCaptionDiagnosticId = "WFDEV015"; + +#pragma warning disable WFDEV016 // Type or member is obsolete + internal const string DataGridCellMessage = $"{nameof(DataGridCell)} has been deprecated."; +#pragma warning restore WFDEV016 // Type or member is obsolete + internal const string DataGridCellDiagnosticId = "WFDEV016"; + +#pragma warning disable WFDEV017 // Type or member is obsolete + internal const string DataGridColumnStyleMessage = $"{nameof(DataGridColumnStyle)} has been deprecated."; +#pragma warning restore WFDEV017 // Type or member is obsolete + internal const string DataGridColumnStyleDiagnosticId = "WFDEV017"; + + internal const string DataGridColumnHeaderAccessibleObjectMessage = $"DataGridColumnHeaderAccessibleObject has been deprecated."; + internal const string DataGridColumnHeaderAccessibleObjectDiagnosticId = "WFDEV018"; + +#pragma warning disable WFDEV019 // Type or member is obsolete + internal const string DataGridLineStyleMessage = $"{nameof(DataGridLineStyle)} has been deprecated."; +#pragma warning restore WFDEV019 // Type or member is obsolete + internal const string DataGridLineStyleDiagnosticId = "WFDEV019"; + +#pragma warning disable WFDEV020 // Type or member is obsolete + internal const string DataGridParentRowsMessage = $"{nameof(DataGridParentRows)} has been deprecated."; +#pragma warning restore WFDEV020 // Type or member is obsolete + internal const string DataGridParentRowsDiagnosticId = "WFDEV020"; + + internal const string DataGridParentRowsAccessibleObjectMessage = $"DataGridParentRowsAccessibleObject has been deprecated."; + internal const string DataGridParentRowsAccessibleObjectDiagnosticId = "WFDEV021"; + +#pragma warning disable WFDEV022 // Type or member is obsolete + internal const string DataGridParentRowsLabelStyleMessage = $"{nameof(DataGridParentRowsLabelStyle)} has been deprecated."; +#pragma warning restore WFDEV022 // Type or member is obsolete + internal const string DataGridParentRowsLabelStyleDiagnosticId = "WFDEV022"; + +#pragma warning disable WFDEV023 // Type or member is obsolete + internal const string DataGridPreferredColumnWidthTypeConverterMessage = $"{nameof(DataGridPreferredColumnWidthTypeConverter)} has been deprecated."; +#pragma warning restore WFDEV023 // Type or member is obsolete + internal const string DataGridPreferredColumnWidthTypeConverterDiagnosticId = "WFDEV023"; + +#pragma warning disable WFDEV024 // Type or member is obsolete + internal const string DataGridRelationshipRowMessage = $"{nameof(DataGridRelationshipRow)} has been deprecated."; +#pragma warning restore WFDEV024 // Type or member is obsolete + internal const string DataGridRelationshipRowDiagnosticId = "WFDEV024"; + + internal const string DataGridRelationshipRowAccessibleObjectMessage = $"DataGridRelationshipRowAccessibleObject has been deprecated."; + internal const string DataGridRelationshipRowAccessibleObjectDiagnosticId = "WFDEV025"; + + internal const string DataGridRelationshipAccessibleObjectMessage = $"DataGridRelationshipAccessibleObject has been deprecated."; + internal const string DataGridRelationshipAccessibleObjectDiagnosticId = "WFDEV026"; + +#pragma warning disable WFDEV027 // Type or member is obsolete + internal const string DataGridRowMessage = $"{nameof(DataGridRow)} has been deprecated."; +#pragma warning restore WFDEV027 // Type or member is obsolete + internal const string DataGridRowDiagnosticId = "WFDEV027"; + + internal const string DataGridRowAccessibleObjectMessage = $"DataGridRowAccessibleObject has been deprecated."; + internal const string DataGridRowAccessibleObjectDiagnosticId = "WFDEV028"; + + internal const string DataGridCellAccessibleObjectMessage = $"DataGridCellAccessibleObject has been deprecated."; + internal const string DataGridCellAccessibleObjectDiagnosticId = "WFDEV029"; + +#pragma warning disable WFDEV030 // Type or member is obsolete + internal const string DataGridStateMessage = $"{nameof(DataGridState)} has been deprecated."; +#pragma warning restore WFDEV030 // Type or member is obsolete + internal const string DataGridStateDiagnosticId = "WFDEV030"; + + internal const string DataGridStateParentRowAccessibleObjectMessage = $"DataGridStateParentRowAccessibleObject has been deprecated."; + internal const string DataGridStateParentRowAccessibleObjectDiagnosticId = "WFDEV031"; + +#pragma warning disable WFDEV032 // Type or member is obsolete + internal const string DataGridTableStyleMessage = $"{nameof(DataGridTableStyle)} has been deprecated."; +#pragma warning restore WFDEV032 // Type or member is obsolete + internal const string DataGridTableStyleDiagnosticId = "WFDEV032"; + +#pragma warning disable WFDEV033 // Type or member is obsolete + internal const string GridTableStylesCollectionMessage = $"{nameof(GridTableStylesCollection)} has been deprecated."; +#pragma warning restore WFDEV033 // Type or member is obsolete + internal const string GridTableStylesCollectionDiagnosticId = "WFDEV033"; + +#pragma warning disable WFDEV034 // Type or member is obsolete + internal const string GridTablesFactoryMessage = $"{nameof(GridTablesFactory)} has been deprecated."; +#pragma warning restore WFDEV034 // Type or member is obsolete + internal const string GridTablesFactoryDiagnosticId = "WFDEV034"; + +#pragma warning disable WFDEV035 // Type or member is obsolete + internal const string DataGridTextBoxMessage = $"{nameof(DataGridTextBox)} has been deprecated."; +#pragma warning restore WFDEV035 // Type or member is obsolete + internal const string DataGridTextBoxDiagnosticId = "WFDEV035"; + +#pragma warning disable WFDEV036 // Type or member is obsolete + internal const string DataGridTextBoxColumnMessage = $"{nameof(DataGridTextBoxColumn)} has been deprecated."; +#pragma warning restore WFDEV036 // Type or member is obsolete + internal const string DataGridTextBoxColumnDiagnosticId = "WFDEV036"; + +#pragma warning disable WFDEV037 // Type or member is obsolete + internal const string DataGridToolTipMessage = $"{nameof(DataGridToolTip)} has been deprecated."; +#pragma warning restore WFDEV037 // Type or member is obsolete + internal const string DataGridToolTipDiagnosticId = "WFDEV037"; + +#pragma warning disable WFDEV038 // Type or member is obsolete + internal const string GridColumnStylesCollectionMessage = $"{nameof(GridColumnStylesCollection)} has been deprecated."; +#pragma warning restore WFDEV038 // Type or member is obsolete + internal const string GridColumnStylesCollectionDiagnosticId = "WFDEV038"; + +#pragma warning disable WFDEV039 // Type or member is obsolete + internal const string IDataGridEditingServiceMessage = $"{nameof(IDataGridEditingService)} has been deprecated."; +#pragma warning restore WFDEV039 // Type or member is obsolete + internal const string IDataGridEditingServiceDiagnosticId = "WFDEV039"; + +#pragma warning disable WFDEV040 // Type or member is obsolete + internal const string MainMenuMessage = $"{nameof(MainMenu)} has been deprecated. Use {nameof(MenuStrip)} instead."; +#pragma warning restore WFDEV040 // Type or member is obsolete + internal const string MainMenuDiagnosticId = "WFDEV040"; + +#pragma warning disable WFDEV041 // Type or member is obsolete + internal const string StatusBarMessage = $"{nameof(StatusBar)} has been deprecated. Use {nameof(StatusStrip)} instead."; +#pragma warning restore WFDEV041 // Type or member is obsolete + internal const string StatusBarDiagnosticId = "WFDEV041"; + + internal const string StatusBarPanelCollectionMessage = $"StatusBarPanelCollection has been deprecated."; + internal const string StatusBarPanelCollectionDiagnosticId = "WFDEV042"; + +#pragma warning disable WFDEV043 // Type or member is obsolete + internal const string StatusBarDrawItemEventArgsMessage = $"{nameof(StatusBarDrawItemEventArgs)} has been deprecated. Use {nameof(DrawItemEventArgs)} instead."; +#pragma warning restore WFDEV043 // Type or member is obsolete + internal const string StatusBarDrawItemEventArgsDiagnosticId = "WFDEV043"; + +#pragma warning disable WFDEV044 // Type or member is obsolete + internal const string StatusBarDrawItemEventHandlerMessage = $"{nameof(StatusBarDrawItemEventHandler)} has been deprecated. Use {nameof(DrawItemEventHandler)} instead."; +#pragma warning restore WFDEV044 // Type or member is obsolete + internal const string StatusBarDrawItemEventHandlerDiagnosticId = "WFDEV044"; + +#pragma warning disable WFDEV045 // Type or member is obsolete + internal const string StatusBarPanelMessage = $"{nameof(StatusBarPanel)} has been deprecated. Use {nameof(StatusStrip)} instead."; +#pragma warning restore WFDEV045 // Type or member is obsolete + internal const string StatusBarPanelDiagnosticId = "WFDEV045"; + +#pragma warning disable WFDEV046 // Type or member is obsolete + internal const string StatusBarPanelAutoSizeMessage = $"{nameof(StatusBarPanelAutoSize)} has been deprecated."; +#pragma warning restore WFDEV046 // Type or member is obsolete + internal const string StatusBarPanelAutoSizeDiagnosticId = "WFDEV046"; + +#pragma warning disable WFDEV047 // Type or member is obsolete + internal const string StatusBarPanelBorderStyleMessage = $"{nameof(StatusBarPanelBorderStyle)} has been deprecated."; +#pragma warning restore WFDEV047 // Type or member is obsolete + internal const string StatusBarPanelBorderStyleDiagnosticId = "WFDEV047"; + +#pragma warning disable WFDEV048 // Type or member is obsolete + internal const string StatusBarPanelClickEventArgsMessage = $"{nameof(StatusBarPanelClickEventArgs)} has been deprecated."; +#pragma warning restore WFDEV048 // Type or member is obsolete + internal const string StatusBarPanelClickEventArgsDiagnosticId = "WFDEV048"; + +#pragma warning disable WFDEV049 // Type or member is obsolete + internal const string StatusBarPanelStyleMessage = $"{nameof(StatusBarPanelStyle)} has been deprecated."; +#pragma warning restore WFDEV049 // Type or member is obsolete + internal const string StatusBarPanelStyleDiagnosticId = "WFDEV049"; + +#pragma warning disable WFDEV050 // Type or member is obsolete + internal const string StatusBarPanelClickEventHandlerMessage = $"{nameof(StatusBarPanelClickEventHandler)} has been deprecated."; +#pragma warning restore WFDEV050 // Type or member is obsolete + internal const string StatusBarPanelClickEventHandlerDiagnosticId = "WFDEV050"; + +#pragma warning disable WFDEV051 // Type or member is obsolete + internal const string ToolBarMessage = $"{nameof(ToolBar)} has been deprecated. Use {nameof(ToolStrip)} instead."; +#pragma warning restore WFDEV051 // Type or member is obsolete + internal const string ToolBarDiagnosticId = "WFDEV051"; + + internal const string ToolBarButtonCollectionMessage = $"ToolBarButtonCollection has been deprecated."; + internal const string ToolBarButtonCollectionDiagnosticId = "WFDEV052"; + +#pragma warning disable WFDEV053 // Type or member is obsolete + internal const string ToolBarAppearanceMessage = $"{nameof(ToolBarAppearance)} has been deprecated."; +#pragma warning restore WFDEV053 // Type or member is obsolete + internal const string ToolBarAppearanceDiagnosticId = "WFDEV053"; + +#pragma warning disable WFDEV054 // Type or member is obsolete + internal const string ToolBarButtonMessage = $"{nameof(ToolBarButton)} has been deprecated. Use {nameof(ToolStripButton)} instead."; +#pragma warning restore WFDEV054 // Type or member is obsolete + internal const string ToolBarButtonDiagnosticId = "WFDEV054"; + +#pragma warning disable WFDEV055 // Type or member is obsolete + internal const string ToolBarButtonClickEventArgsMessage = $"{nameof(ToolBarButtonClickEventArgs)} has been deprecated."; +#pragma warning restore WFDEV055 // Type or member is obsolete + internal const string ToolBarButtonClickEventArgsDiagnosticId = "WFDEV055"; + +#pragma warning disable WFDEV056 // Type or member is obsolete + internal const string ToolBarButtonClickEventHandlerMessage = $"{nameof(ToolBarButtonClickEventHandler)} has been deprecated."; +#pragma warning restore WFDEV056 // Type or member is obsolete + internal const string ToolBarButtonClickEventHandlerDiagnosticId = "WFDEV056"; + +#pragma warning disable WFDEV057 // Type or member is obsolete + internal const string ToolBarButtonStyleMessage = $"{nameof(ToolBarButtonStyle)} has been deprecated."; +#pragma warning restore WFDEV057 // Type or member is obsolete + internal const string ToolBarButtonStyleDiagnosticId = "WFDEV057"; + +#pragma warning disable WFDEV058 // Type or member is obsolete + internal const string ToolBarTextAlignMessage = $"{nameof(ToolBarTextAlign)} has been deprecated."; +#pragma warning restore WFDEV058 // Type or member is obsolete + internal const string ToolBarTextAlignDiagnosticId = "WFDEV058"; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs index c807ce0fca9..ba9803ad985 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs @@ -6,100 +6,55 @@ namespace System.Windows.Forms; -// Add public types and members to the declared APIto simplify porting of applications from .NET Framework to .NET. These types will not work, -// but if they are not accessed, other features in the application will work. -#pragma warning disable RS0016 -#nullable disable -[Obsolete("ContextMenu has been deprecated. Use ContextMenuStrip instead.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.ContextMenuMessage, + error: false, + DiagnosticId = Obsoletions.ContextMenuDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class ContextMenu : Menu { - internal Control sourceControl; + public ContextMenu() : base(null) + => throw new PlatformNotSupportedException(); - /// - /// Creates a new ContextMenu object with no items in it by default. - /// - public ContextMenu() - : base(null) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Creates a ContextMenu object with the given MenuItems. - /// - public ContextMenu(MenuItem[] menuItems) - : base(menuItems) - { - throw new PlatformNotSupportedException(); - } + public ContextMenu(MenuItem[] menuItems) : base(menuItems) + => throw new PlatformNotSupportedException(); - /// - /// The last control that was acted upon that resulted in this context - /// menu being displayed. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Control SourceControl { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Popup { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Fires when the context menu collapses. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Collapse { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// This is used for international applications where the language - /// is written from RightToLeft. When this property is true, - /// text alignment and reading order will be from right to left. - /// - // Add a DefaultValue attribute so that the Reset context menu becomes - // available in the Property Grid but the default value remains No. - [Localizable(true), DefaultValue(RightToLeft.No), - Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual RightToLeft RightToLeft { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Displays the context menu at the specified position. This method - /// doesn't return until the menu is dismissed. - /// public void Show(Control control, Point pos) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Displays the context menu at the specified position. This method - /// doesn't return until the menu is dismissed. - /// public void Show(Control control, Point pos, LeftRightAlignment alignment) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs index ceb6736c5ec..8f5d591c56c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs @@ -5,106 +5,60 @@ using System.ComponentModel; namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("Menu has been deprecated.")] +#nullable disable +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.MenuMessage, + error: false, + DiagnosticId = Obsoletions.MenuDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public abstract class Menu : Component { - #nullable disable - internal const int CHANGE_ITEMS = 0; // item(s) added or removed - internal const int CHANGE_VISIBLE = 1; // item(s) hidden or shown - internal const int CHANGE_MDI = 2; // mdi item changed - internal const int CHANGE_MERGE = 3; // mergeType or mergeOrder changed - internal const int CHANGE_ITEMADDED = 4; // mergeType or mergeOrder changed - - /// - /// Used by findMenuItem - /// public const int FindHandle = 0; - /// - /// Used by findMenuItem - /// public const int FindShortcut = 1; - internal MenuItem[] items; - internal IntPtr handle; - internal bool created; - - /// - /// This is an abstract class. Instances cannot be created, so the constructor - /// is only called from derived classes. - /// + protected Menu(MenuItem[] items) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// The HMENU handle corresponding to this menu. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), - SRDescription(nameof(SR.ControlHandleDescr))] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public IntPtr Handle { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - /// - /// Specifies whether this menu contains any items. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual bool IsParent { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - /// - /// The MenuItem that contains the list of MDI child windows. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public MenuItem MdiListItem { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - /// - /// Name of this control. The designer will set this to the same - /// as the programatic Id "(name)" of the control - however this - /// property has no bearing on the runtime aspects of this control. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string Name { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - DesignerSerializationVisibility(DesignerSerializationVisibility.Content), - MergableProperty(false)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public MenuItemCollection MenuItems { get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - SRCategory(nameof(SR.CatData)), - Localizable(false), - Bindable(true), - SRDescription(nameof(SR.ControlTagDescr)), - DefaultValue(null), - TypeConverter(typeof(StringConverter))] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public object Tag { get => throw new PlatformNotSupportedException(); @@ -112,270 +66,130 @@ public object Tag } public MenuItem FindMenuItem(int type, IntPtr value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Returns the ContextMenu that contains this menu. The ContextMenu - /// is at the top of this menu's parent chain. - /// Returns null if this menu is not contained in a ContextMenu. - /// This can occur if it's contained in a MainMenu or if it isn't - /// currently contained in any menu at all. - /// public ContextMenu GetContextMenu() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Returns the MainMenu item that contains this menu. The MainMenu - /// is at the top of this menu's parent chain. - /// Returns null if this menu is not contained in a MainMenu. - /// This can occur if it's contained in a ContextMenu or if it isn't - /// currently contained in any menu at all. - /// public MainMenu GetMainMenu() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Merges another menu's items with this one's. Menu items are merged according to their - /// mergeType and mergeOrder properties. This function is typically used to - /// merge an MDI container's menu with that of its active MDI child. - /// public virtual void MergeMenu(Menu menuSrc) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Returns a string representation for this control. - /// public override string ToString() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [ListBindable(false)] - [Obsolete("MenuItemCollection has been deprecated.")] + [Obsolete( + Obsoletions.MenuItemCollectionMessage, + error: false, + DiagnosticId = Obsoletions.MenuItemCollectionDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class MenuItemCollection : IList { - /// A caching mechanism for key accessor - /// We use an index here rather than control so that we don't have lifetime - /// issues by holding on to extra references. - // private int lastAccessedIndex = -1; - public MenuItemCollection(Menu owner) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public virtual MenuItem this[int index] { get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] object IList.this[int index] { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Retrieves the child control with the specified key. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public virtual MenuItem this[string key] { get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public int Count { get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] object ICollection.SyncRoot { get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] bool ICollection.IsSynchronized { get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] bool IList.IsFixedSize { get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool IsReadOnly { get => throw new PlatformNotSupportedException(); } - /// - /// Adds a new MenuItem to the end of this menu with the specified caption. - /// public virtual MenuItem Add(string caption) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Adds a new MenuItem to the end of this menu with the specified caption, - /// and click handler. - /// public virtual MenuItem Add(string caption, EventHandler onClick) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Adds a new MenuItem to the end of this menu with the specified caption, - /// click handler, and items. - /// public virtual MenuItem Add(string caption, MenuItem[] items) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Adds a MenuItem to the end of this menu - /// MenuItems can only be contained in one menu at a time, and may not be added - /// more than once to the same menu. - /// - public virtual int Add(object item) - { - throw new PlatformNotSupportedException(); - } + public virtual int Add(object value) + => throw new PlatformNotSupportedException(); - /// - /// Adds a MenuItem to this menu at the specified index. The item currently at - /// that index, and all items after it, will be moved up one slot. - /// MenuItems can only be contained in one menu at a time, and may not be added - /// more than once to the same menu. - /// public virtual int Add(int index, MenuItem item) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void AddRange(MenuItem[] items) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool Contains(object value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Returns true if the collection contains an item with the specified key, false otherwise. - /// public virtual bool ContainsKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Searches for Controls by their Name property, builds up an array - /// of all the controls that match. - /// public MenuItem[] Find(string key, bool searchAllChildren) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public int IndexOf(MenuItem value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); int IList.IndexOf(object value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// The zero-based index of the first occurrence of value within the entire CollectionBase, if found; otherwise, -1. - /// public virtual int IndexOfKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); void IList.Insert(int index, object value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Determines if the index is valid for the collection. - /// - private bool IsValidIndex(int index) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Removes all existing MenuItems from this menu - /// public virtual void Clear() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - public void CopyTo(Array dest, int index) - { - throw new PlatformNotSupportedException(); - } + public void CopyTo(Array array, int index) + => throw new PlatformNotSupportedException(); public IEnumerator GetEnumerator() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Removes the item at the specified index in this menu. All subsequent - /// items are moved up one slot. - /// public virtual void RemoveAt(int index) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Removes the menu iteml with the specified key. - /// public virtual void RemoveByKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Removes the specified item from this menu. All subsequent - /// items are moved down one slot. - /// public virtual void Remove(MenuItem item) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); void IList.Remove(object value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs index 30d74beed56..cf481821148 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs @@ -5,456 +5,237 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API #nullable disable -[Obsolete("MenuItem has been deprecated. Use ToolStripMenuItem instead.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.MenuItemMessage, + error: false, + DiagnosticId = Obsoletions.MenuItemDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class MenuItem : Menu { - /// - /// Initializes a with a blank caption. - /// - public MenuItem() : this(MenuMerge.Add, 0, 0, null, null, null, null, null) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Initializes a new instance of the class - /// with a specified caption for the menu item. - /// - public MenuItem(string text) : this(MenuMerge.Add, 0, 0, text, null, null, null, null) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Initializes a new instance of the class with a specified caption and event handler - /// for the menu item. - /// - public MenuItem(string text, EventHandler onClick) : this(MenuMerge.Add, 0, 0, text, onClick, null, null, null) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Initializes a new instance of the class with a specified caption, event handler, - /// and associated shorcut key for the menu item. - /// - public MenuItem(string text, EventHandler onClick, Shortcut shortcut) : this(MenuMerge.Add, 0, shortcut, text, onClick, null, null, null) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Initializes a new instance of the class with a specified caption and an array of - /// submenu items defined for the menu item. - /// - public MenuItem(string text, MenuItem[] items) : this(MenuMerge.Add, 0, 0, text, null, null, null, items) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Initializes a new instance of the class with a specified caption, defined - /// event-handlers for the Click, Select and Popup events, a shortcut key, - /// a merge type, and order specified for the menu item. - /// - public MenuItem(MenuMerge mergeType, int mergeOrder, Shortcut shortcut, - string text, EventHandler onClick, EventHandler onPopup, - EventHandler onSelect, MenuItem[] items) : base(items) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Gets or sets a value indicating whether the item is placed on a new line (for a - /// menu item added to a object) or in a - /// new column (for a submenu or menu displayed in a ). - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - [DefaultValue(false)] + public MenuItem() + : this(MenuMerge.Add, 0, 0, null, null, null, null, null) + => throw new PlatformNotSupportedException(); + + public MenuItem(string text) + : this(MenuMerge.Add, 0, 0, text, null, null, null, null) + => throw new PlatformNotSupportedException(); + + public MenuItem(string text, EventHandler onClick) + : this(MenuMerge.Add, 0, 0, text, onClick, null, null, null) + => throw new PlatformNotSupportedException(); + + public MenuItem(string text, EventHandler onClick, Shortcut shortcut) + : this(MenuMerge.Add, 0, shortcut, text, onClick, null, null, null) + => throw new PlatformNotSupportedException(); + + public MenuItem(string text, MenuItem[] items) + : this(MenuMerge.Add, 0, 0, text, null, null, null, items) + => throw new PlatformNotSupportedException(); + + public MenuItem(MenuMerge mergeType, + int mergeOrder, + Shortcut shortcut, + string text, + EventHandler onClick, + EventHandler onPopup, + EventHandler onSelect, + MenuItem[] items) : base(items) + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool BarBreak { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating whether the item is placed on a new line (for a - /// menu item added to a object) or in a - /// new column (for a submenu or menu displayed in a ). - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - [DefaultValue(false)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Break { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating whether a checkmark appears beside the text of - /// the menu item. - /// - [DefaultValue(false)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - [SRDescription("Indicates whether the item is checked.")] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Checked { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating whether the menu item is the default. - /// - [DefaultValue(false)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - [SRDescription("Indicates whether the item is the default item.")] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool DefaultItem { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating whether code that you provide draws the menu - /// item or Windows draws the menu item. - /// - [SRCategory(nameof(SR.CatBehavior))] - [DefaultValue(false)] - [SRDescription("Indicates if Windows will draw the menu item or if the user will handle the painting.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool OwnerDraw { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating whether the menu item is enabled. - /// - [Localizable(true)] - [DefaultValue(true)] - [SRDescription("Indicates whether the item is enabled.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Enabled { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets the menu item's position in its parent menu. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int Index { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets a value indicating whether the menu item contains child menu items. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override bool IsParent { get => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating whether the menu item will be populated with a - /// list of the MDI child windows that are displayed within the associated form. - /// - [DefaultValue(false)] - [SRDescription("Determines whether the MDI child window list is appended to this item.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool MdiList { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value that indicates the behavior of this - /// menu item when its menu is merged with another. - /// - [DefaultValue(MenuMerge.Add)] - [SRDescription("Determines how the item is handled when menus are merged.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public MenuMerge MergeType { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets the relative position the menu item when its - /// menu is merged with another. - /// - [DefaultValue(0)] - [SRDescription("Determines the merge order of the item.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int MergeOrder { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Retrieves the hotkey mnemonic that is associated with this menu item. - /// The mnemonic is the first character after an ampersand symbol in the menu's text - /// that is not itself an ampersand symbol. If no such mnemonic is defined this - /// will return zero. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public char Mnemonic => '\0'; - /// - /// Gets the menu in which this menu item appears. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Menu Parent { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value that indicates whether the menu item, if checked, - /// displays a radio-button mark instead of a check mark. - /// - [DefaultValue(false)] - [SRDescription("If the item is checked, this value will determine whether the check style is a radio button.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool RadioCheck { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets the text of the menu item. - /// - [Localizable(true)] - [SRDescription("The caption displayed by the item.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string Text { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets the shortcut key associated with the menu item. - /// - [Localizable(true)] - [DefaultValue(Shortcut.None)] - [SRDescription(nameof(SR.MenuItemShortCutDescr))] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Shortcut Shortcut { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value that indicates whether the shortcut key that is associated - /// with the menu item is displayed next to the menu item caption. - /// - [DefaultValue(true), Localizable(true)] - [SRDescription(nameof(SR.MenuItemShowShortCutDescr))] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool ShowShortcut { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value that indicates whether the menu item is visible on its - /// parent menu. - /// - [Localizable(true)] - [DefaultValue(true)] - [SRDescription("Indicates whether the item is visible.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Visible { get => throw new PlatformNotSupportedException(); } - /// - /// Occurs when the menu item is clicked or selected using a shortcut key defined - /// for the menu item. - /// - [SRDescription("Occurs when the menu item is selected.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Click { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Occurs when when the property of a menu item is set to and - /// a request is made to draw the menu item. - /// - [SRCategory(nameof(SR.CatBehavior)), SRDescription(nameof(SR.drawItemEventDescr))] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event DrawItemEventHandler DrawItem { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Occurs when when the menu needs to know the size of a menu item before drawing it. - /// - [SRCategory(nameof(SR.CatBehavior)), SRDescription(nameof(SR.measureItemEventDescr))] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event MeasureItemEventHandler MeasureItem { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Occurs before a menu item's list of menu items is displayed. - /// - [SRDescription("Occurs before the containing menu is displayed.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Popup { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Occurs when the user hovers their mouse over a menu item or selects it with the - /// keyboard but has not activated it. - /// - [SRDescription("Occurs when the menu item is selected.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Select { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Creates and returns an identical copy of this menu item. - /// public virtual MenuItem CloneMenu() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Merges this menu item with another menu item and returns the resulting merged - /// . - /// public virtual MenuItem MergeMenu() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Merges another menu item with this menu item. - /// public void MergeMenu(MenuItem itemSrc) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Generates a event for the MenuItem, - /// simulating a click by a user. - /// public void PerformClick() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Raises the event for this menu item. - /// public virtual void PerformSelect() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override string ToString() - { - throw new PlatformNotSupportedException(); - } - - [Obsolete("MenuItemData has been deprecated.")] - internal class MenuItemData : ICommandExecutor - { - internal MenuItem baseItem; - internal MenuItem firstItem; - internal int _version; - internal MenuMerge _mergeType; - internal int _mergeOrder; - internal string _caption; - internal short _mnemonic; - internal Shortcut _shortcut; - internal bool _showShortcut; - internal EventHandler _onClick; - internal EventHandler _onPopup; - internal EventHandler _onSelect; - internal DrawItemEventHandler _onDrawItem; - internal MeasureItemEventHandler _onMeasureItem; - - public void Execute() - { - throw new PlatformNotSupportedException(); - } - - internal void SetState(int flag, bool value) - { - throw new PlatformNotSupportedException(); - } - - internal void SetCaption(string value) - { - throw new PlatformNotSupportedException(); - } - } - - private class MdiListUserData - { - public virtual void OnClick(EventArgs e) - { - throw new PlatformNotSupportedException(); - } - } - - private class MdiListFormData : MdiListUserData - { - public MdiListFormData(MenuItem parentItem, int boundFormIndex) - { - throw new PlatformNotSupportedException(); - } - - public override void OnClick(EventArgs e) - { - throw new PlatformNotSupportedException(); - } - } - - private class MdiListMoreWindowsData : MdiListUserData - { - public MdiListMoreWindowsData(MenuItem parent) - { - throw new PlatformNotSupportedException(); - } - - public override void OnClick(EventArgs e) - { - throw new PlatformNotSupportedException(); - } - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuMerge.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuMerge.cs index 461e1205a4d..a26bd593147 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuMerge.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuMerge.cs @@ -1,42 +1,19 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("MenuMerge has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.MenuMergeMessage, + error: false, + DiagnosticId = Obsoletions.MenuMergeDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public enum MenuMerge { - /// - /// The is added to the - /// existing objects in a - /// merged menu. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Add = 0, - - /// - /// The replaces the - /// existing at the same - /// position in a merged menu. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Replace = 1, - - /// - /// Subitems of this are merged - /// with those of existing - /// objects at the same position in a merged menu. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] MergeItems = 2, - - /// - /// The is not included in a - /// merged menu. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Remove = 3, } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs index 48e85b96d12..60fa71c996c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs @@ -1,8120 +1,933 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections; using System.ComponentModel; using System.Drawing; -using System.Globalization; -using System.Security.Permissions; namespace System.Windows.Forms; -#pragma warning disable RS0016 #nullable disable -[Obsolete("DataGrid has been deprecated. Use DataGridView instead.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.DataGridMessage, + error: false, + DiagnosticId = Obsoletions.DataGridDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGrid : Control, ISupportInitialize, IDataGridEditingService { - internal TraceSwitch DataGridAcc = new TraceSwitch("DataGridAcc", "Trace Windows Forms DataGrid Accessibility"); - - private const int GRIDSTATE_trackColResize = 0x00000008; - private const int GRIDSTATE_trackRowResize = 0x00000010; - private const int GRIDSTATE_isLedgerStyle = 0x00000020; - private const int GRIDSTATE_listHasErrors = 0x00000080; - private const int GRIDSTATE_dragging = 0x00000100; - private const int GRIDSTATE_inListAddNew = 0x00000200; - private const int GRIDSTATE_inDeleteRow = 0x00000400; - private const int GRIDSTATE_canFocus = 0x00000800; - private const int GRIDSTATE_isNavigating = 0x00004000; - private const int GRIDSTATE_isEditing = 0x00008000; - private const int GRIDSTATE_editControlChanging = 0x00010000; - private const int GRIDSTATE_isScrolling = 0x00020000; - private const int GRIDSTATE_overCaption = 0x00040000; - private const int GRIDSTATE_childLinkFocused = 0x00080000; - private const int GRIDSTATE_inAddNewRow = 0x00100000; - private const int GRIDSTATE_inSetListManager = 0x00200000; - private const int GRIDSTATE_metaDataChanged = 0x00400000; - private const int GRIDSTATE_exceptionInPaint = 0x00800000; - private const int GRIDSTATE_layoutSuspended = 0x01000000; - - // PERF: take all the bools and put them into a state variable - private Collections.Specialized.BitVector32 gridState; // see GRIDSTATE_ consts above - - private const int errorRowBitmapWidth = 15; - - private const DataGridParentRowsLabelStyle defaultParentRowsLabelStyle = DataGridParentRowsLabelStyle.Both; - private const bool defaultCaptionVisible = true; - - private const bool defaultParentRowsVisible = true; - - private DataGridTableStyle defaultTableStyle = new DataGridTableStyle(true); - - // private bool allowSorting = true; - - private SolidBrush alternatingBackBrush = DefaultAlternatingBackBrush; - - // private bool columnHeadersVisible = true; - - private SolidBrush gridLineBrush = DefaultGridLineBrush; - private SolidBrush headerBackBrush = DefaultHeaderBackBrush; - - private Font headerFont; // this is ambient property to Font value - - private SolidBrush headerForeBrush = DefaultHeaderForeBrush; - private Pen headerForePen = DefaultHeaderForePen; - - private SolidBrush linkBrush = DefaultLinkBrush; - private static int defaultFontHeight = DefaultFont.Height; - private int prefferedRowHeight = defaultFontHeight + 3; - private int minRowHeaderWidth; - - private SolidBrush selectionBackBrush = DefaultSelectionBackBrush; - private SolidBrush selectionForeBrush = DefaultSelectionForeBrush; - - // parent rows - private DataGridParentRows parentRows; - // Set_ListManager uses the originalState to determine - // if the grid should disconnect from all the MetaDataChangedEvents - // keep "originalState is not null" when navigating back and forth in the grid - // and use Add/RemoveMetaDataChanged methods. - private DataGridState originalState; - - // ui state - // Don't use dataGridRows, use the accessor!!! - private DataGridRow[] dataGridRows = []; - private int dataGridRowsLength; - - // for toolTip - private int toolTipId; - private DataGridToolTip toolTipProvider; - - private DataGridAddNewRow addNewRow; - private LayoutData layout = new LayoutData(); - private RECT[] cachedScrollableRegion; - - // header namespace goo - - // these are actually get/set by ColumnBehavior - internal bool allowColumnResize = true; - - internal bool allowRowResize = true; - - internal DataGridParentRowsLabelStyle parentRowsLabels = defaultParentRowsLabelStyle; - - // information for col/row resizing - // private bool trackColResize = false; - private int trackColAnchor; - private int trackColumn; - // private bool trackRowResize = false; - private int trackRowAnchor; - private int trackRow; - private PropertyDescriptor trackColumnHeader; - private MouseEventArgs lastSplitBar; - - // private bool isLedgerStyle = true; - // private bool isFlatMode = false; - private Font linkFont; - - private SolidBrush backBrush = DefaultBackBrush; - private SolidBrush foreBrush = DefaultForeBrush; - private SolidBrush backgroundBrush = DefaultBackgroundBrush; - - // font cacheing info - private int fontHeight = -1; - private int linkFontHeight = -1; - private int captionFontHeight = -1; - private int headerFontHeight = -1; - - // the preffered height of the row. - - // if the list has items with errors - - // private bool listHasErrors = false; - - // caption - private DataGridCaption caption; - - // data binding - // - private object dataSource; - private string dataMember = ""; - private CurrencyManager listManager; - - // currently focused control - // we want to unparent it either when rebinding the grid or when the grid is disposed - private Control toBeDisposedEditingControl; - - // persistent data state - // - internal GridTableStylesCollection dataGridTables; - // SET myGridTable in SetDataGridTable ONLY - internal DataGridTableStyle myGridTable; - internal bool checkHierarchy = true; - internal bool inInit; - - // Selection - internal int currentRow; - internal int currentCol; - private int numSelectedRows; - private int lastRowSelected = -1; - - // Policy - // private bool readOnlyMode = false; - private Policy policy = new Policy(); - private DataGridColumnStyle editColumn; - private DataGridRow editRow; - - // scrolling - private ScrollBar horizScrollBar = new HScrollBar(); - private ScrollBar vertScrollBar = new VScrollBar(); - - // the sum of the widths of the columns preceding the firstVisibleColumn - private int horizontalOffset; - - // the number of pixels of the firstVisibleColumn which are not visible - // - private int negOffset; - - private int wheelDelta; - // private bool isScrolling = false; - - // Visibility - // - internal int firstVisibleRow; - internal int firstVisibleCol; - private int numVisibleRows; - // the number of columns which are visible - private int numVisibleCols; - private int numTotallyVisibleRows; - // lastTotallyVisibleCol == -1 means that the data grid does not show any column in its entirety - private int lastTotallyVisibleCol; - - // mouse move hot-tracking - // - private int oldRow = -1; - private static readonly object EVENT_CURRENTCELLCHANGED = new object(); - // private static readonly object EVENT_COLUMNRESIZE = new object(); - // private static readonly object EVENT_LINKCLICKED = new object(); - private static readonly object EVENT_NODECLICKED = new object(); - // private static readonly object EVENT_ROWRESIZE = new object(); - private static readonly object EVENT_SCROLL = new object(); - private static readonly object EVENT_BACKBUTTONCLICK = new object(); - private static readonly object EVENT_DOWNBUTTONCLICK = new object(); - - private EventHandler onRowHeaderClick; - public DataGrid() : base() - { - parentRows = new DataGridParentRows(this); - caption = new DataGridCaption(this); - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool AllowSorting { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color AlternatingBackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public void ResetAlternatingBackColor() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected virtual bool ShouldSerializeAlternatingBackColor() - { - return !AlternatingBackBrush.Equals(DefaultAlternatingBackBrush); - } - - internal Brush AlternatingBackBrush - { - get - { - return alternatingBackBrush; - } - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Color BackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public override void ResetBackColor() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Color ForeColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public override void ResetForeColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public BorderStyle BorderStyle { - throw new PlatformNotSupportedException(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - internal SolidBrush BackBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler BorderStyleChanged { - get - { - return backBrush; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - internal SolidBrush ForeBrush + protected override Size DefaultSize { - get - { - return foreBrush; - } + get => new Size(130, 80); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public BorderStyle BorderStyle + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color CaptionBackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private static readonly object EVENT_BORDERSTYLECHANGED = new object(); + protected virtual bool ShouldSerializeCaptionBackColor() + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler BorderStyleChanged + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color CaptionForeColor { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private int BorderWidth - { - get - { - if (BorderStyle == BorderStyle.Fixed3D) - { - return SystemInformation.Border3DSize.Width; - } - else if (BorderStyle == BorderStyle.FixedSingle) - { - return 2; - } - else - { - return 0; - } - } - } + protected virtual bool ShouldSerializeCaptionForeColor() + => throw new PlatformNotSupportedException(); - protected override Size DefaultSize + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Font CaptionFont { - get - { - return new Size(130, 80); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private static SolidBrush DefaultSelectionBackBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public string CaptionText { - get - { - return (SolidBrush)SystemBrushes.ActiveCaption; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private static SolidBrush DefaultSelectionForeBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public bool CaptionVisible { - get - { - return (SolidBrush)SystemBrushes.ActiveCaptionText; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - internal static SolidBrush DefaultBackBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler CaptionVisibleChanged { - get - { - return (SolidBrush)SystemBrushes.Window; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - internal static SolidBrush DefaultForeBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public DataGridCell CurrentCell { - get - { - return (SolidBrush)SystemBrushes.WindowText; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private static SolidBrush DefaultBackgroundBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler CurrentCellChanged { - get - { - return (SolidBrush)SystemBrushes.AppWorkspace; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - internal static SolidBrush DefaultParentRowsForeBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color SelectionBackColor { - get - { - return (SolidBrush)SystemBrushes.WindowText; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - internal static SolidBrush DefaultParentRowsBackBrush + protected bool ShouldSerializeSelectionBackColor() + => throw new PlatformNotSupportedException(); + + public void ResetSelectionBackColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color SelectionForeColor { - get - { - return (SolidBrush)SystemBrushes.Control; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - internal static SolidBrush DefaultAlternatingBackBrush + protected virtual bool ShouldSerializeSelectionForeColor() + => throw new PlatformNotSupportedException(); + + public void ResetSelectionForeColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public object DataSource { - get - { - return (SolidBrush)SystemBrushes.Window; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private static SolidBrush DefaultGridLineBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler DataSourceChanged { - get - { - return (SolidBrush)SystemBrushes.Control; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - private static SolidBrush DefaultHeaderBackBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public string DataMember { - get - { - return (SolidBrush)SystemBrushes.Control; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private static SolidBrush DefaultHeaderForeBrush + public void SetDataBinding(object dataSource, string dataMember) + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public int CurrentRowIndex { - get - { - return (SolidBrush)SystemBrushes.ControlText; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private static Pen DefaultHeaderForePen + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public GridTableStylesCollection TableStyles { - get - { - return new Pen(SystemColors.ControlText); - } + get => throw new PlatformNotSupportedException(); } - private static SolidBrush DefaultLinkBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color GridLineColor { - get - { - return (SolidBrush)SystemBrushes.HotTrack; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private bool ListHasErrors + protected virtual bool ShouldSerializeGridLineColor() + => throw new PlatformNotSupportedException(); + + public void ResetGridLineColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public DataGridLineStyle GridLineStyle { - get - { - return gridState[GRIDSTATE_listHasErrors]; - } - set - { - if (ListHasErrors != value) - { - gridState[GRIDSTATE_listHasErrors] = value; - ComputeMinimumRowHeaderWidth(); - if (!layout.RowHeadersVisible) - return; - if (value) - { - if (myGridTable.IsDefault) - RowHeaderWidth += errorRowBitmapWidth; - else - myGridTable.RowHeaderWidth += errorRowBitmapWidth; - } - else - { - if (myGridTable.IsDefault) - RowHeaderWidth -= errorRowBitmapWidth; - else - myGridTable.RowHeaderWidth -= errorRowBitmapWidth; - } - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private bool Bound + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public DataGridParentRowsLabelStyle ParentRowsLabelStyle { - get - { - return !(listManager is null || myGridTable is null); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - internal DataGridCaption Caption + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ParentRowsLabelStyleChanged { - get - { - return caption; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color CaptionBackColor + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public int FirstVisibleColumn { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - private void ResetCaptionBackColor() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public bool FlatMode { - Caption.ResetBackColor(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeCaptionBackColor() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler FlatModeChanged { - return Caption.ShouldSerializeBackColor(); + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color CaptionForeColor + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color HeaderBackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private void ResetCaptionForeColor() + protected virtual bool ShouldSerializeHeaderBackColor() + => throw new PlatformNotSupportedException(); + + public void ResetHeaderBackColor() + => throw new PlatformNotSupportedException(); + + protected virtual bool ShouldSerializeBackgroundColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color BackgroundColor { - Caption.ResetForeColor(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeCaptionForeColor() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler BackgroundColorChanged { - return Caption.ShouldSerializeForeColor(); + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Font CaptionFont + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Font HeaderFont { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private bool ShouldSerializeCaptionFont() + protected bool ShouldSerializeHeaderFont() + => throw new PlatformNotSupportedException(); + + public void ResetHeaderFont() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color HeaderForeColor { - return Caption.ShouldSerializeFont(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private void ResetCaptionFont() + protected virtual bool ShouldSerializeHeaderForeColor() + => throw new PlatformNotSupportedException(); + + public void ResetHeaderForeColor() + => throw new PlatformNotSupportedException(); + + protected ScrollBar HorizScrollBar { - Caption.ResetFont(); + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public string CaptionText + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color LinkColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public bool CaptionVisible + public void ResetLinkColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color LinkHoverColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private static readonly object EVENT_CAPTIONVISIBLECHANGED = new object(); + protected virtual bool ShouldSerializeLinkHoverColor() + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler CaptionVisibleChanged + public void ResetLinkHoverColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public bool AllowNavigation { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public DataGridCell CurrentCell + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler AllowNavigationChanged { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - internal int CurrentCellAccIndex + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public override Cursor Cursor { - get - { - int currentCellAccIndex = 0; - currentCellAccIndex++; // ParentRowsAccessibleObject - currentCellAccIndex += myGridTable.GridColumnStyles.Count; // ColumnHeaderAccessibleObject - currentCellAccIndex += DataGridRows.Length; // DataGridRowAccessibleObject - if (horizScrollBar.Visible) // Horizontal Scroll Bar Accessible Object - currentCellAccIndex++; - if (vertScrollBar.Visible) // Vertical Scroll Bar Accessible Object - currentCellAccIndex++; - currentCellAccIndex += (currentRow * myGridTable.GridColumnStyles.Count) + currentCol; - return currentCellAccIndex; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler CurrentCellChanged + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler CursorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - private int CurrentColumn + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public override Image BackgroundImage { - get - { - return CurrentCell.ColumnNumber; - } - set - { - CurrentCell = new DataGridCell(currentRow, value); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private int CurrentRow + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public override ImageLayout BackgroundImageLayout { - get - { - return CurrentCell.RowNumber; - } - set - { - CurrentCell = new DataGridCell(value, currentCol); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color SelectionBackColor + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackgroundImageChanged { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - internal SolidBrush SelectionBackBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler BackgroundImageLayoutChanged { - get - { - return selectionBackBrush; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - internal SolidBrush SelectionForeBrush + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color ParentRowsBackColor { - get - { - return selectionForeBrush; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - protected bool ShouldSerializeSelectionBackColor() + protected virtual bool ShouldSerializeParentRowsBackColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public Color ParentRowsForeColor { - return !DefaultSelectionBackBrush.Equals(selectionBackBrush); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - public void ResetSelectionBackColor() + protected virtual bool ShouldSerializeParentRowsForeColor() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public int PreferredColumnWidth { - throw new PlatformNotSupportedException(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color SelectionForeColor + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public int PreferredRowHeight { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeSelectionForeColor() + protected bool ShouldSerializePreferredRowHeight() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public bool ReadOnly { - return !SelectionForeBrush.Equals(DefaultSelectionForeBrush); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - public void ResetSelectionForeColor() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ReadOnlyChanged { - throw new PlatformNotSupportedException(); + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - internal override bool ShouldSerializeForeColor() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public bool ColumnHeadersVisible { - return !DefaultForeBrush.Color.Equals(this.ForeColor); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - internal override bool ShouldSerializeBackColor() - { - return !DefaultBackBrush.Color.Equals(this.BackColor); - } - - // Don't use dataGridRows, use the accessor!!! - internal DataGridRow[] DataGridRows - { - get - { - if (dataGridRows is null) - CreateDataGridRows(); - return dataGridRows; - } - } - - // ToolTipping - internal DataGridToolTip ToolTipProvider - { - get - { - return toolTipProvider; - } - } - - internal int ToolTipId - { - get - { - return toolTipId; - } - set - { - toolTipId = value; - } - } - - private void ResetToolTip() - { - // remove all the tool tips which are stored - for (int i = 0; i < ToolTipId; i++) - { - DataGridToolTip.RemoveToolTip(new IntPtr(i)); - } - - if (!parentRows.IsEmpty()) - { - bool alignRight = isRightToLeft(); - int detailsButtonWidth = DataGridCaption.GetDetailsButtonWidth(); - Rectangle backButton = DataGridCaption.GetBackButtonRect(layout.Caption, alignRight, detailsButtonWidth); - Rectangle detailsButton = DataGridCaption.GetDetailsButtonRect(layout.Caption, alignRight); - - // mirror the buttons wrt RTL property - backButton.X = MirrorRectangle(backButton, layout.Inside, isRightToLeft()); - detailsButton.X = MirrorRectangle(detailsButton, layout.Inside, isRightToLeft()); - - DataGridToolTip.AddToolTip("SR.GetString(SR.DataGridCaptionBackButtonToolTip)", new IntPtr(0), backButton); - DataGridToolTip.AddToolTip("SR.GetString(SR.DataGridCaptionDetailsButtonToolTip)", new IntPtr(1), detailsButton); - ToolTipId = 2; - } - else - { - ToolTipId = 0; - } - } - - private void CreateDataGridRows() - { - CurrencyManager listManager = ListManager; - DataGridTableStyle dgt = myGridTable; - InitializeColumnWidths(); - - if (listManager is null) - { - SetDataGridRows(Array.Empty(), 0); - return; - } - - int nDataGridRows = listManager.Count; - if (policy.AllowAdd) - nDataGridRows++; - - DataGridRow[] rows = new DataGridRow[nDataGridRows]; - for (int r = 0; r < listManager.Count; r++) - { - rows[r] = new DataGridRelationshipRow(this, dgt, r); - } - - if (policy.AllowAdd) - { - addNewRow = new DataGridAddNewRow(this, dgt, nDataGridRows - 1); - rows[nDataGridRows - 1] = addNewRow; - } - else - { - addNewRow = null; - } - - SetDataGridRows(rows, nDataGridRows); - } - - private void RecreateDataGridRows() - { - int nDataGridRows = 0; - CurrencyManager listManager = ListManager; - - if (listManager is not null) - { - nDataGridRows = listManager.Count; - if (policy.AllowAdd) - { - nDataGridRows++; - } - } - - SetDataGridRows(null, nDataGridRows); - } - - /// - /// Sets the array of DataGridRow objects used for - /// all row-related logic in the DataGrid. - /// - internal void SetDataGridRows(DataGridRow[] newRows, int newRowsLength) - { - dataGridRows = newRows; - dataGridRowsLength = newRowsLength; - - // update the vertical scroll bar - vertScrollBar.Maximum = Math.Max(0, DataGridRowsLength - 1); - if (firstVisibleRow > newRowsLength) - { - vertScrollBar.Value = 0; - firstVisibleRow = 0; - } - - ResetUIState(); -#if DEBUG - // sanity check: all the rows should have the same - // dataGridTable - if (newRows is not null && newRowsLength > 0) - { - DataGridTableStyle dgTable = newRows[0].DataGridTableStyle; - for (int i = 0; i < newRowsLength; i++) - { - Debug.Assert(dgTable == newRows[i].DataGridTableStyle, "how can two rows have different tableStyles?"); - } - } -#endif // DEBUG - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: There are now " + DataGridRowsLength.ToString(CultureInfo.InvariantCulture) + " rows."); - } - - internal int DataGridRowsLength - { - get - { - return dataGridRowsLength; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public object DataSource - { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } - } - - private static readonly object EVENT_DATASOURCECHANGED = new object(); - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler DataSourceChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public string DataMember - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - public void SetDataBinding(object dataSource, string dataMember) - { - throw new PlatformNotSupportedException(); - } - - internal protected CurrencyManager ListManager - { - get - { - if (listManager is null && BindingContext is not null && DataSource is not null) - return (CurrencyManager)BindingContext[DataSource, DataMember]; - else - return listManager; - } - set - { - throw new NotSupportedException("SR.GetString(SR.DataGridSetListManager)"); - } - } - - internal void Set_ListManager(object newDataSource, string newDataMember, bool force) - { - Set_ListManager(newDataSource, newDataMember, force, true); // true for forcing column creation - } - - // - // prerequisite: the dataMember and the dataSource should be set to the new values - // - // will do the following: - // call EndEdit on the current listManager, will unWire the listManager events, will set the listManager to the new - // reality, will wire the new listManager, will update the policy, will set the dataGridTable, will reset the ui state. - // - internal void Set_ListManager(object newDataSource, string newDataMember, bool force, bool forceColumnCreation) - { - bool dataSourceChanged = DataSource != newDataSource; - bool dataMemberChanged = DataMember != newDataMember; - - // if nothing happened, then why do any work? - if (!force && !dataSourceChanged && !dataMemberChanged && gridState[GRIDSTATE_inSetListManager]) - return; - - gridState[GRIDSTATE_inSetListManager] = true; - if (toBeDisposedEditingControl is not null) - { - Debug.Assert(Controls.Contains(toBeDisposedEditingControl)); - Controls.Remove(toBeDisposedEditingControl); - toBeDisposedEditingControl = null; - } - - bool beginUpdateInternal = true; - try - { - // will endEdit on the current listManager - UpdateListManager(); - - // unwire the events: - if (listManager is not null) - UnWireDataSource(); - - CurrencyManager oldListManager = listManager; - bool listManagerChanged = false; - // set up the new listManager - // CAUTION: we need to set up the listManager in the grid before setting the dataSource/dataMember props - // in the grid. the reason is that if the BindingContext was not yet requested, and it is created in the BindingContext prop - // then the grid will call Set_ListManager again, and eventually that means that the dataGrid::listManager will - // be hooked up twice to all the events (PositionChanged, ItemChanged, CurrentChanged) - if (newDataSource is not null && BindingContext is not null && !(newDataSource == Convert.DBNull)) - listManager = (CurrencyManager)BindingContext[newDataSource, newDataMember]; - else - listManager = null; - - // update the dataSource and the dateMember - dataSource = newDataSource; - dataMember = newDataMember is null ? "" : newDataMember; - - listManagerChanged = (listManager != oldListManager); - - // wire the events - if (listManager is not null) - { - WireDataSource(); - // update the policy - policy.UpdatePolicy(listManager, ReadOnly); - } - - if (!Initializing) - { - if (listManager is null) - { - if (ContainsFocus && ParentInternal is null) - { - Debug.Assert(toBeDisposedEditingControl is null, "we should have removed the toBeDisposedEditingControl already"); - // if we unparent the active control then the form won't close - for (int i = 0; i < Controls.Count; i++) - { - if (Controls[i].Focused) - { - toBeDisposedEditingControl = Controls[i]; - break; - } - } - - if (toBeDisposedEditingControl == horizScrollBar || toBeDisposedEditingControl == vertScrollBar) - { - toBeDisposedEditingControl = null; - } - -#if DEBUG - else - { - Debug.Assert(toBeDisposedEditingControl is not null, "if the grid contains the focus, then the active control should be in the children of data grid control"); - Debug.Assert(editColumn is not null, "if we have an editing control should be a control in the data grid column"); - if (editColumn is DataGridTextBoxColumn) - { - Debug.Assert(((DataGridTextBoxColumn)editColumn).TextBox == toBeDisposedEditingControl, "if we have an editing control should be a control in the data grid column"); - } - } -#endif // debug; - - } - - SetDataGridRows(null, 0); - defaultTableStyle.GridColumnStyles.Clear(); - SetDataGridTable(defaultTableStyle, forceColumnCreation); - - if (toBeDisposedEditingControl is not null) - { - Controls.Add(toBeDisposedEditingControl); - } - } - } - - // PERF: if the listManager did not change, then do not: - // 1. create new rows - // 2. create new columns - // 3. compute the errors in the list - // - // when the metaDataChanges, we need to recreate - // the rows and the columns - // - if (listManagerChanged || gridState[GRIDSTATE_metaDataChanged]) - { - if (Visible) - BeginUpdateInternal(); - - if (listManager is not null) - { - // get rid of the old gridColumns - // we need to clear the old column collection even when navigating to - // a list that has a table style associated w/ it. Why? because the - // old column collection will be used by the parent rows to paint - defaultTableStyle.GridColumnStyles.ResetDefaultColumnCollection(); - - DataGridTableStyle newGridTable = dataGridTables[listManager.GetListName()]; - if (newGridTable is null) - { - SetDataGridTable(defaultTableStyle, forceColumnCreation); - } - else - { - SetDataGridTable(newGridTable, forceColumnCreation); - } - - // set the currentRow in ssync w/ the position in the listManager - currentRow = listManager.Position == -1 ? 0 : listManager.Position; - } - - // when we create the rows we need to use the current dataGridTable - // - RecreateDataGridRows(); - if (Visible) - EndUpdateInternal(); - beginUpdateInternal = false; - - ComputeMinimumRowHeaderWidth(); - if (myGridTable.IsDefault) - RowHeaderWidth = Math.Max(minRowHeaderWidth, RowHeaderWidth); - else - myGridTable.RowHeaderWidth = Math.Max(minRowHeaderWidth, RowHeaderWidth); - - ListHasErrors = DataGridSourceHasErrors(); - - // build the list of columns and relationships - // wipe out the now invalid states - // ResetMouseState(); - - ResetUIState(); - - // layout.CaptionVisible = dataCursor is null ? false : true; - - OnDataSourceChanged(EventArgs.Empty); - } - } - finally - { - gridState[GRIDSTATE_inSetListManager] = false; - // start painting again - if (beginUpdateInternal && Visible) - EndUpdateInternal(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public int CurrentRowIndex - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public GridTableStylesCollection TableStyles - { - get - { - throw new PlatformNotSupportedException(); - } - } - - internal new int FontHeight - { - get - { - return fontHeight; - } - } - - internal AccessibleObject ParentRowsAccessibleObject - { - get - { - return parentRows.AccessibleObject; - } - } - - internal Rectangle ParentRowsBounds - { - get - { - return layout.ParentRows; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color GridLineColor - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - protected virtual bool ShouldSerializeGridLineColor() - { - return !GridLineBrush.Equals(DefaultGridLineBrush); - } - - public void ResetGridLineColor() - { - throw new PlatformNotSupportedException(); - } - - internal SolidBrush GridLineBrush - { - get - { - return gridLineBrush; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public DataGridLineStyle GridLineStyle - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - internal int GridLineWidth - { - get - { - Debug.Assert(GridLineStyle == DataGridLineStyle.Solid || GridLineStyle == DataGridLineStyle.None, "are there any other styles?"); - return GridLineStyle == DataGridLineStyle.Solid ? 1 : 0; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public DataGridParentRowsLabelStyle ParentRowsLabelStyle - { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } - } - - private static readonly object EVENT_PARENTROWSLABELSTYLECHANGED = new object(); - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler ParentRowsLabelStyleChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - internal bool Initializing - { - get - { - return inInit; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public int FirstVisibleColumn - { - get - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public bool FlatMode - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - private static readonly object EVENT_FLATMODECHANGED = new object(); - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler FlatModeChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color HeaderBackColor - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - internal SolidBrush HeaderBackBrush - { - get - { - return headerBackBrush; - } - } - - protected virtual bool ShouldSerializeHeaderBackColor() - { - return !HeaderBackBrush.Equals(DefaultHeaderBackBrush); - } - - public void ResetHeaderBackColor() - { - throw new PlatformNotSupportedException(); - } - - internal SolidBrush BackgroundBrush - { - get - { - return backgroundBrush; - } - } - - private void ResetBackgroundColor() - { - if (backgroundBrush is not null && BackgroundBrush != DefaultBackgroundBrush) - { - backgroundBrush.Dispose(); - backgroundBrush = null; - } - - backgroundBrush = DefaultBackgroundBrush; - } - - protected virtual bool ShouldSerializeBackgroundColor() - { - return !BackgroundBrush.Equals(DefaultBackgroundBrush); - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color BackgroundColor - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - private static readonly object EVENT_BACKGROUNDCOLORCHANGED = new object(); - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler BackgroundColorChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Font HeaderFont - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - headerFont = value; - throw new PlatformNotSupportedException(); - } - } - - protected bool ShouldSerializeHeaderFont() - { - return (headerFont is not null); - } - - public void ResetHeaderFont() - { - throw new PlatformNotSupportedException(); - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color HeaderForeColor - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - protected virtual bool ShouldSerializeHeaderForeColor() - { - return !HeaderForePen.Equals(DefaultHeaderForePen); - } - - public void ResetHeaderForeColor() - { - throw new PlatformNotSupportedException(); - } - - internal SolidBrush HeaderForeBrush - { - get - { - return headerForeBrush; - } - } - - internal Pen HeaderForePen - { - get - { - return headerForePen; - } - } - - private void ResetHorizontalOffset() - { - horizontalOffset = 0; - negOffset = 0; - firstVisibleCol = 0; - numVisibleCols = 0; - lastTotallyVisibleCol = -1; - } - - internal int HorizontalOffset - { - get - { - return horizontalOffset; - } - set - { - if (value < 0) - value = 0; - - int totalWidth = GetColumnWidthSum(); - int widthNotVisible = totalWidth - layout.Data.Width; - if (value > widthNotVisible && widthNotVisible > 0) - value = widthNotVisible; - - if (value == horizontalOffset) - return; - - int change = horizontalOffset - value; - horizScrollBar.Value = value; - Rectangle scroll = layout.Data; - if (layout.ColumnHeadersVisible) - scroll = Rectangle.Union(scroll, layout.ColumnHeaders); - horizontalOffset = value; - - firstVisibleCol = ComputeFirstVisibleColumn(); - // update the lastTotallyVisibleCol - ComputeVisibleColumns(); - - if (gridState[GRIDSTATE_isScrolling]) - { - // if the user did not click on the grid yet, then do not put the edit - // control when scrolling - if (currentCol >= firstVisibleCol && currentCol < firstVisibleCol + numVisibleCols - 1 && (gridState[GRIDSTATE_isEditing] || gridState[GRIDSTATE_isNavigating])) - Edit(); - else - EndEdit(); - - // isScrolling is set to TRUE when the user scrolls. - // once we move the edit box, we finished processing the scroll event, so set isScrolling to FALSE - // to set isScrolling to TRUE, we need another scroll event. - gridState[GRIDSTATE_isScrolling] = false; - } - else - { - EndEdit(); - } - - RECT[] rects = CreateScrollableRegion(scroll); - ScrollRectangles(rects, change); - OnScroll(EventArgs.Empty); - } - } - - private void ScrollRectangles(RECT[] rects, int change) - { - if (rects is not null) - { - RECT scroll; - if (isRightToLeft()) - change = -change; - for (int r = 0; r < rects.Length; r++) - { - scroll = rects[r]; - } - } - } - - protected ScrollBar HorizScrollBar - { - get - { - return horizScrollBar; - } - } - - /// - /// - /// Retrieves a value indicating whether odd and even - /// rows are painted using a different background color. - /// - /// - // CUT by 53973 - Cleanup eventually to be static. - internal bool LedgerStyle - { - get - { - return gridState[GRIDSTATE_isLedgerStyle]; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color LinkColor - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - /// - /// [To be supplied.] - /// - internal virtual bool ShouldSerializeLinkColor() - { - return !LinkBrush.Equals(DefaultLinkBrush); - } - - public void ResetLinkColor() - { - throw new PlatformNotSupportedException(); - } - - internal Brush LinkBrush - { - get - { - return linkBrush; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color LinkHoverColor - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - } - } - - protected virtual bool ShouldSerializeLinkHoverColor() - { - return false; - } - - public void ResetLinkHoverColor() - { - throw new PlatformNotSupportedException(); - } - - internal Font LinkFont - { - get - { - return linkFont; - } - } - - internal int LinkFontHeight - { - get - { - return linkFontHeight; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public bool AllowNavigation - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - private static readonly object EVENT_ALLOWNAVIGATIONCHANGED = new object(); - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler AllowNavigationChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public override Cursor Cursor - { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - new public event EventHandler CursorChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public override Image BackgroundImage - { - // get the BackgroundImage out of the propertyGrid. - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public override ImageLayout BackgroundImageLayout - { - // get the BackgroundImage out of the propertyGrid. - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - new public event EventHandler BackgroundImageChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - new public event EventHandler BackgroundImageLayoutChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color ParentRowsBackColor - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - internal SolidBrush ParentRowsBackBrush - { - get - { - return parentRows.BackBrush; - } - } - - protected virtual bool ShouldSerializeParentRowsBackColor() - { - return !ParentRowsBackBrush.Equals(DefaultParentRowsBackBrush); - } - - private void ResetParentRowsBackColor() - { - if (ShouldSerializeParentRowsBackColor()) - parentRows.BackBrush = DefaultParentRowsBackBrush; - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public Color ParentRowsForeColor - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - internal SolidBrush ParentRowsForeBrush - { - get - { - return parentRows.ForeBrush; - } - } - - protected virtual bool ShouldSerializeParentRowsForeColor() - { - return !ParentRowsForeBrush.Equals(DefaultParentRowsForeBrush); - } - - private void ResetParentRowsForeColor() - { - if (ShouldSerializeParentRowsForeColor()) - parentRows.ForeBrush = DefaultParentRowsForeBrush; - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public int PreferredColumnWidth - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public int PreferredRowHeight - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - private void ResetPreferredRowHeight() - { - prefferedRowHeight = defaultFontHeight + 3; - } - - protected bool ShouldSerializePreferredRowHeight() - { - return prefferedRowHeight != defaultFontHeight + 3; - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public bool ReadOnly - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - private static readonly object EVENT_READONLYCHANGED = new object(); - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler ReadOnlyChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public bool ColumnHeadersVisible - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public bool ParentRowsVisible - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - private static readonly object EVENT_PARENTROWSVISIBLECHANGED = new object(); - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler ParentRowsVisibleChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - internal bool ParentRowsIsEmpty() - { - return parentRows.IsEmpty(); - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public bool RowHeadersVisible - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public int RowHeaderWidth - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public override string Text - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - new public event EventHandler TextChanged - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - protected ScrollBar VertScrollBar - { - get - { - return vertScrollBar; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public int VisibleColumnCount - { - get - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public int VisibleRowCount - { - get - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public object this[int rowIndex, int columnIndex] - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public object this[DataGridCell cell] - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - private void WireTableStylePropChanged(DataGridTableStyle gridTable) - { - gridTable.GridLineColorChanged += new EventHandler(GridLineColorChanged); - gridTable.GridLineStyleChanged += new EventHandler(GridLineStyleChanged); - gridTable.HeaderBackColorChanged += new EventHandler(HeaderBackColorChanged); - gridTable.HeaderFontChanged += new EventHandler(HeaderFontChanged); - gridTable.HeaderForeColorChanged += new EventHandler(HeaderForeColorChanged); - gridTable.LinkColorChanged += new EventHandler(LinkColorChanged); - gridTable.LinkHoverColorChanged += new EventHandler(LinkHoverColorChanged); - gridTable.PreferredColumnWidthChanged += new EventHandler(PreferredColumnWidthChanged); - gridTable.RowHeadersVisibleChanged += new EventHandler(RowHeadersVisibleChanged); - gridTable.ColumnHeadersVisibleChanged += new EventHandler(ColumnHeadersVisibleChanged); - gridTable.RowHeaderWidthChanged += new EventHandler(RowHeaderWidthChanged); - gridTable.AllowSortingChanged += new EventHandler(AllowSortingChanged); - } - - private void UnWireTableStylePropChanged(DataGridTableStyle gridTable) - { - gridTable.GridLineColorChanged -= new EventHandler(GridLineColorChanged); - gridTable.GridLineStyleChanged -= new EventHandler(GridLineStyleChanged); - gridTable.HeaderBackColorChanged -= new EventHandler(HeaderBackColorChanged); - gridTable.HeaderFontChanged -= new EventHandler(HeaderFontChanged); - gridTable.HeaderForeColorChanged -= new EventHandler(HeaderForeColorChanged); - gridTable.LinkColorChanged -= new EventHandler(LinkColorChanged); - gridTable.LinkHoverColorChanged -= new EventHandler(LinkHoverColorChanged); - gridTable.PreferredColumnWidthChanged -= new EventHandler(PreferredColumnWidthChanged); - gridTable.RowHeadersVisibleChanged -= new EventHandler(RowHeadersVisibleChanged); - gridTable.ColumnHeadersVisibleChanged -= new EventHandler(ColumnHeadersVisibleChanged); - gridTable.RowHeaderWidthChanged -= new EventHandler(RowHeaderWidthChanged); - gridTable.AllowSortingChanged -= new EventHandler(AllowSortingChanged); - } - - /// - /// DataSource events are handled - /// - private void WireDataSource() - { - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: WireDataSource"); - Debug.Assert(listManager is not null, "Can't wire up to a null DataSource"); - } - - private void UnWireDataSource() - { - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: UnWireDataSource"); - Debug.Assert(listManager is not null, "Can't un wire from a null DataSource"); - } - - // This is called after a row has been added. And I think whenever - // a row gets deleted, etc. - // We recreate our datagrid rows at this point. - private void DataSource_Changed(object sender, EventArgs ea) - { - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: DataSource_Changed"); - - // the grid will receive the dataSource_Changed event when - // allowAdd changes on the dataView. - policy.UpdatePolicy(ListManager, ReadOnly); - if (gridState[GRIDSTATE_inListAddNew]) - { - // we are adding a new row - // keep the old rows, w/ their height, expanded/collapsed information - // - Debug.Assert(policy.AllowAdd, "how can we add a new row if the policy does not allow this?"); - Debug.Assert(DataGridRowsLength == DataGridRows.Length, "how can this fail?"); - - DataGridRow[] gridRows = DataGridRows; - int currentRowCount = DataGridRowsLength; - // put the added row: - // - gridRows[currentRowCount - 1] = new DataGridRelationshipRow(this, myGridTable, currentRowCount - 1); - SetDataGridRows(gridRows, currentRowCount); - } - else if (gridState[GRIDSTATE_inAddNewRow] && !gridState[GRIDSTATE_inDeleteRow]) - { - // when the backEnd adds a row and we are still inAddNewRow - listManager.CancelCurrentEdit(); - gridState[GRIDSTATE_inAddNewRow] = false; - RecreateDataGridRows(); - } - else if (!gridState[GRIDSTATE_inDeleteRow]) - { - RecreateDataGridRows(); - currentRow = Math.Min(currentRow, listManager.Count); - } - - bool oldListHasErrors = ListHasErrors; - ListHasErrors = DataGridSourceHasErrors(); - // if we changed the ListHasErrors, then the grid is already invalidated - if (oldListHasErrors == ListHasErrors) - InvalidateInside(); - } - - private void GridLineColorChanged(object sender, EventArgs e) - { - Invalidate(layout.Data); - } - - private void GridLineStyleChanged(object sender, EventArgs e) - { - this.myGridTable.ResetRelationsUI(); - Invalidate(layout.Data); - } - - private void HeaderBackColorChanged(object sender, EventArgs e) - { - if (layout.RowHeadersVisible) - Invalidate(layout.RowHeaders); - if (layout.ColumnHeadersVisible) - Invalidate(layout.ColumnHeaders); - Invalidate(layout.TopLeftHeader); - } - - private void HeaderFontChanged(object sender, EventArgs e) - { - RecalculateFonts(); - PerformLayout(); - Invalidate(layout.Inside); - } - - private void HeaderForeColorChanged(object sender, EventArgs e) - { - if (layout.RowHeadersVisible) - Invalidate(layout.RowHeaders); - if (layout.ColumnHeadersVisible) - Invalidate(layout.ColumnHeaders); - Invalidate(layout.TopLeftHeader); - } - - private void LinkColorChanged(object sender, EventArgs e) - { - Invalidate(layout.Data); - } - - private void LinkHoverColorChanged(object sender, EventArgs e) - { - Invalidate(layout.Data); - } - - private void PreferredColumnWidthChanged(object sender, EventArgs e) - { - // reset the dataGridRows - SetDataGridRows(null, this.DataGridRowsLength); - // layout the horizontal scroll bar - PerformLayout(); - // invalidate everything - Invalidate(); - } - - private void RowHeadersVisibleChanged(object sender, EventArgs e) - { - layout.RowHeadersVisible = myGridTable is null ? false : myGridTable.RowHeadersVisible; - PerformLayout(); - InvalidateInside(); - } - - private void ColumnHeadersVisibleChanged(object sender, EventArgs e) - { - layout.ColumnHeadersVisible = myGridTable is null ? false : myGridTable.ColumnHeadersVisible; - PerformLayout(); - InvalidateInside(); - } - - private void RowHeaderWidthChanged(object sender, EventArgs e) - { - if (layout.RowHeadersVisible) - { - PerformLayout(); - InvalidateInside(); - } - } - - private void AllowSortingChanged(object sender, EventArgs e) - { - if (!myGridTable.AllowSorting && listManager is not null) - { - IList list = listManager.List; - if (list is IBindingList) - ((IBindingList)list).RemoveSort(); - } - } - - private void DataSource_RowChanged(object sender, EventArgs ea) - { - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: DataSource_RowChanged"); - // it may be the case that our cache was not updated - // to the latest changes in the list : CurrentChanged is fired before - // ListChanged. - // So invalidate the row if there is something to invalidate - DataGridRow[] rows = DataGridRows; - if (currentRow < DataGridRowsLength) - { - InvalidateRow(currentRow); - } - } - - /// - /// - /// Fired by the DataSource when row position moves. - /// - /// - private void DataSource_PositionChanged(object sender, EventArgs ea) - { - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: DataSource_PositionChanged to " + listManager.Position.ToString(CultureInfo.InvariantCulture)); - // the grid will get the PositionChanged event - // before the OnItemChanged event when a row will be deleted in the backEnd; - // we still want to keep the old rows when the user deletes the rows using the grid - // and we do not want to do the same work twice when the user adds a row via the grid - if (DataGridRowsLength > listManager.Count + (policy.AllowAdd ? 1 : 0) && !gridState[GRIDSTATE_inDeleteRow]) - { - Debug.Assert(!gridState[GRIDSTATE_inAddNewRow] && !gridState[GRIDSTATE_inListAddNew], "how can the list decrease when we are adding a row?"); - RecreateDataGridRows(); - } - - if (ListManager.Position != currentRow) - { - CurrentCell = new DataGridCell(listManager.Position, currentCol); - } - } - - internal void DataSource_MetaDataChanged(object sender, EventArgs e) - { - MetaDataChanged(); - } - - private bool DataGridSourceHasErrors() - { - if (listManager is null) - return false; - for (int i = 0; i < listManager.Count; i++) - { - object errObj = listManager[i]; - if (errObj is IDataErrorInfo) - { - string errString = ((IDataErrorInfo)errObj).Error; - if (errString is not null && errString.Length != 0) - return true; - } - } - - return false; - } - - private void TableStylesCollectionChanged(object sender, CollectionChangeEventArgs ccea) - { - // if the users changed the collection of tableStyles - if (sender != dataGridTables) - return; - if (listManager is null) - return; - - if (ccea.Action == CollectionChangeAction.Add) - { - DataGridTableStyle tableStyle = (DataGridTableStyle)ccea.Element; - if (listManager.GetListName().Equals(tableStyle.MappingName)) - { - Debug.Assert(myGridTable.IsDefault, "if the table is not default, then it had a name. how can one add another table to the collection w/ the same name and not throw an exception"); - SetDataGridTable(tableStyle, true); // true for forcing column creation - SetDataGridRows(null, 0); - } - } - else if (ccea.Action == CollectionChangeAction.Remove) - { - DataGridTableStyle tableStyle = (DataGridTableStyle)ccea.Element; - if (myGridTable.MappingName.Equals(tableStyle.MappingName)) - { - Debug.Assert(myGridTable.IsDefault, "if the table is not default, then it had a name. how can one add another table to the collection w/ the same name and not throw an exception"); - defaultTableStyle.GridColumnStyles.ResetDefaultColumnCollection(); - SetDataGridTable(defaultTableStyle, true); // true for forcing column creation - SetDataGridRows(null, 0); - } - } - else - { - Debug.Assert(ccea.Action == CollectionChangeAction.Refresh, "what else is possible?"); - // we have to search to see if the collection of table styles contains one - // w/ the same name as the list in the dataGrid - - DataGridTableStyle newGridTable = dataGridTables[listManager.GetListName()]; - if (newGridTable is null) - { - if (!myGridTable.IsDefault) - { - // get rid of the old gridColumns - defaultTableStyle.GridColumnStyles.ResetDefaultColumnCollection(); - SetDataGridTable(defaultTableStyle, true); // true for forcing column creation - SetDataGridRows(null, 0); - } - } - else - { - SetDataGridTable(newGridTable, true); // true for forcing column creation - SetDataGridRows(null, 0); - } - } - } - - private void DataSource_ItemChanged(object sender, ItemChangedEventArgs ea) - { - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: DataSource_ItemChanged at index " + ea.Index.ToString(CultureInfo.InvariantCulture)); - - // if ea.Index == -1, then we invalidate all rows. - if (ea.Index == -1) - { - DataSource_Changed(sender, EventArgs.Empty); - } - else - { - // let's see how we are doing w/ the errors - object errObj = this.listManager[ea.Index]; - bool oldListHasErrors = ListHasErrors; - if (errObj is IDataErrorInfo) - { - if (((IDataErrorInfo)errObj).Error.Length != 0) - ListHasErrors = true; - else if (ListHasErrors) - { - // maybe there was an error that now is fixed - ListHasErrors = DataGridSourceHasErrors(); - } - } - - // Invalidate the row only if we did not change the ListHasErrors - if (oldListHasErrors == ListHasErrors) - InvalidateRow(ea.Index); - - // we need to update the edit box: - // we update the text in the edit box only when the currentRow - // equals the ea.Index - if (editColumn is not null && ea.Index == currentRow) - editColumn.UpdateUI(ListManager, ea.Index, null); - } - } - - protected virtual void OnBorderStyleChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_BORDERSTYLECHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected virtual void OnCaptionVisibleChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_CAPTIONVISIBLECHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected virtual void OnCurrentCellChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_CURRENTCELLCHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected virtual void OnFlatModeChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_FLATMODECHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected virtual void OnBackgroundColorChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_BACKGROUNDCOLORCHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected virtual void OnAllowNavigationChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_ALLOWNAVIGATIONCHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected virtual void OnParentRowsVisibleChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_PARENTROWSVISIBLECHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected virtual void OnParentRowsLabelStyleChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_PARENTROWSLABELSTYLECHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected virtual void OnReadOnlyChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_READONLYCHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected void OnNavigate(NavigateEventArgs e) - { - } - - internal void OnNodeClick(EventArgs e) - { - PerformLayout(); - - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - if (firstVisibleCol > -1 && firstVisibleCol < columns.Count && columns[firstVisibleCol] == editColumn) - Edit(); - - // Raise the event for the event listeners - EventHandler handler = (EventHandler)Events[EVENT_NODECLICKED]; - if (handler is not null) - { - handler(this, e); - } - } - - protected void OnRowHeaderClick(EventArgs e) - { - if (onRowHeaderClick is not null) - onRowHeaderClick(this, e); - } - - protected void OnScroll(EventArgs e) - { - // reset the toolTip information - if (ToolTipProvider is not null) - ResetToolTip(); - - EventHandler handler = (EventHandler)Events[EVENT_SCROLL]; - if (handler is not null) - { - handler(this, e); - } - } - - protected virtual void GridHScrolled(object sender, ScrollEventArgs se) - { - if (!Enabled) - return; - if (DataSource is null) - { - Debug.Fail("Horizontal Scrollbar should be disabled without a DataSource."); - return; - } - - gridState[GRIDSTATE_isScrolling] = true; - -#if DEBUG - - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: in GridHScrolled: the scroll event type:"); - switch (se.Type) - { - case ScrollEventType.SmallIncrement: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "small increment"); - break; - case ScrollEventType.SmallDecrement: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "small decrement"); - break; - case ScrollEventType.LargeIncrement: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "Large decrement"); - break; - case ScrollEventType.LargeDecrement: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "small decrement"); - break; - case ScrollEventType.ThumbPosition: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "Thumb Position"); - break; - case ScrollEventType.ThumbTrack: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "Thumb Track"); - break; - case ScrollEventType.First: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "First"); - break; - case ScrollEventType.Last: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "Last"); - break; - case ScrollEventType.EndScroll: - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "EndScroll"); - break; - } - -#endif // DEBUG - - if (se.Type == ScrollEventType.SmallIncrement || - se.Type == ScrollEventType.SmallDecrement) - { - int dCols = (se.Type == ScrollEventType.SmallIncrement) ? 1 : -1; - if (se.Type == ScrollEventType.SmallDecrement && negOffset == 0) - { - GridColumnStylesCollection cols = myGridTable.GridColumnStyles; - // if the column before the first visible column has width == 0 then skip it - for (int i = firstVisibleCol - 1; i >= 0 && cols[i].Width == 0; i--) - { - dCols--; - } - } - - if (se.Type == ScrollEventType.SmallIncrement && negOffset == 0) - { - GridColumnStylesCollection cols = myGridTable.GridColumnStyles; - for (int i = firstVisibleCol; i > -1 && i < cols.Count && cols[i].Width == 0; i++) - { - dCols++; - } - } - - ScrollRight(dCols); - se.NewValue = HorizontalOffset; - } - else if (se.Type != ScrollEventType.EndScroll) - { - HorizontalOffset = se.NewValue; - } - - gridState[GRIDSTATE_isScrolling] = false; - } - - protected virtual void GridVScrolled(object sender, ScrollEventArgs se) - { - if (!Enabled) - return; - if (DataSource is null) - { - Debug.Fail("Vertical Scrollbar should be disabled without a DataSource."); - return; - } - - gridState[GRIDSTATE_isScrolling] = true; - - try - { - se.NewValue = Math.Min(se.NewValue, DataGridRowsLength - numTotallyVisibleRows); - int dRows = se.NewValue - firstVisibleRow; - ScrollDown(dRows); - } - finally - { - gridState[GRIDSTATE_isScrolling] = false; - } - } - - private void HandleEndCurrentEdit() - { - int currentRowSaved = currentRow; - int currentColSaved = currentCol; - - string errorMessage = null; - - try - { - listManager.EndCurrentEdit(); - } - catch (Exception e) - { - errorMessage = e.Message; - } - - if (errorMessage is not null) - { - DialogResult result = RTLAwareMessageBox.Show(null, - "SR.GetString(SR.DataGridPushedIncorrectValueIntoColumn, errorMessage)", - "SR.GetString(SR.DataGridErrorMessageBoxCaption)", - MessageBoxButtons.YesNo, - MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); - - if (result == DialogResult.Yes) - { - currentRow = currentRowSaved; - currentCol = currentColSaved; - Debug.Assert(currentRow == ListManager.Position || listManager.Position == -1, "the position in the list manager (" + ListManager.Position + ") is out of sync with the currentRow (" + currentRow + ")" + " and the exception is '" + errorMessage + "'"); - // also, make sure that we get the row selector on the currentrow, too - InvalidateRowHeader(currentRow); - Edit(); - } - else - { - Debug.Assert(result == DialogResult.No, "we only put cancel and ok on the error message box"); - listManager.CancelCurrentEdit(); - listManager.Position = currentRow; - } - } - } - - protected void OnBackButtonClicked(object sender, EventArgs e) - { - NavigateBack(); - - EventHandler handler = (EventHandler)Events[EVENT_BACKBUTTONCLICK]; - if (handler is not null) - handler(this, e); - } - - protected override void OnBackColorChanged(EventArgs e) - { - backBrush = new SolidBrush(BackColor); - Invalidate(); - - base.OnBackColorChanged(e); - } - - protected override void OnBindingContextChanged(EventArgs e) - { - if (DataSource is not null && !gridState[GRIDSTATE_inSetListManager]) - try - { - Set_ListManager(DataSource, DataMember, true, false); - } - catch - { - // at runtime we will rethrow the exception - if (Site is null || !Site.DesignMode) - throw; - - RTLAwareMessageBox.Show(null, "SR.GetString(SR.DataGridExceptionInPaint)", null, - MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); - - if (Visible) - BeginUpdateInternal(); - - ResetParentRows(); - - Set_ListManager(null, string.Empty, true); - if (Visible) - EndUpdateInternal(); - } - - base.OnBindingContextChanged(e); - } - - protected virtual void OnDataSourceChanged(EventArgs e) - { - EventHandler eh = Events[EVENT_DATASOURCECHANGED] as EventHandler; - if (eh is not null) - { - eh(this, e); - } - } - - protected void OnShowParentDetailsButtonClicked(object sender, EventArgs e) - { - ParentRowsVisible = !caption.ToggleDownButtonDirection(); - - EventHandler handler = (EventHandler)Events[EVENT_DOWNBUTTONCLICK]; - if (handler is not null) - handler(this, e); - } - - protected override void OnForeColorChanged(EventArgs e) - { - foreBrush = new SolidBrush(ForeColor); - Invalidate(); - - base.OnForeColorChanged(e); - } - - protected override void OnFontChanged(EventArgs e) - { - // let the caption know about the event changed - // - Caption.OnGridFontChanged(); - RecalculateFonts(); - RecreateDataGridRows(); - // get all the rows in the parentRows stack, and modify their height - if (originalState is not null) - { - Debug.Assert(!parentRows.IsEmpty(), "if the originalState is not null, then parentRows contains at least one row"); - Stack parentStack = new Stack(); - while (!parentRows.IsEmpty()) - { - DataGridState dgs = parentRows.PopTop(); - int rowCount = dgs.DataGridRowsLength; - - for (int i = 0; i < rowCount; i++) - { - // performance hit: this will cause to invalidate a bunch of - // stuff - - dgs.DataGridRows[i].Height = dgs.DataGridRows[i].MinimumRowHeight(dgs.GridColumnStyles); - } - - parentStack.Push(dgs); - } - - while (parentStack.Count != 0) - { - parentRows.AddParent((DataGridState)parentStack.Pop()); - } - } - - base.OnFontChanged(e); - } - - protected override void OnPaintBackground(PaintEventArgs ebe) - { - } - - protected override void OnLayout(LayoutEventArgs levent) - { - if (gridState[GRIDSTATE_editControlChanging]) - return; - - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: OnLayout"); - base.OnLayout(levent); - - if (gridState[GRIDSTATE_layoutSuspended]) - return; - - gridState[GRIDSTATE_canFocus] = false; - try - { - if (IsHandleCreated) - { - if (layout.ParentRowsVisible) - parentRows.OnLayout(); - - // reset the toolTip information - if (ToolTipProvider is not null) - ResetToolTip(); - - ComputeLayout(); - } - } - finally - { - gridState[GRIDSTATE_canFocus] = true; - } - } - - protected override void OnHandleCreated(EventArgs e) - { - base.OnHandleCreated(e); - - toolTipProvider = new DataGridToolTip(this); - DataGridToolTip.CreateToolTipHandle(); - toolTipId = 0; - - PerformLayout(); - } - - protected override void OnHandleDestroyed(EventArgs e) - { - base.OnHandleDestroyed(e); - - // toolTipping - if (toolTipProvider is not null) - { - DataGridToolTip.Destroy(); - toolTipProvider = null; - } - - toolTipId = 0; - } - - protected override void OnEnter(EventArgs e) - { - if (gridState[GRIDSTATE_canFocus] && !gridState[GRIDSTATE_editControlChanging]) - { - if (Bound) - { - Edit(); - } - - base.OnEnter(e); - } - } - - protected override void OnLeave(EventArgs e) - { - OnLeave_Grid(); - base.OnLeave(e); - } - - private void OnLeave_Grid() - { - gridState[GRIDSTATE_canFocus] = false; - try - { - EndEdit(); - if (listManager is not null && !gridState[GRIDSTATE_editControlChanging]) - { - if (gridState[GRIDSTATE_inAddNewRow]) - { - // if the user did not type anything - // in the addNewRow, then cancel the currentedit - listManager.CancelCurrentEdit(); - // set the addNewRow back - DataGridRow[] localGridRows = DataGridRows; - localGridRows[DataGridRowsLength - 1] = new DataGridAddNewRow(this, myGridTable, DataGridRowsLength - 1); - SetDataGridRows(localGridRows, DataGridRowsLength); - } - else - { - // this.listManager.EndCurrentEdit(); - HandleEndCurrentEdit(); - } - } - } - finally - { - gridState[GRIDSTATE_canFocus] = true; - // inAddNewRow should be set to false if the control was - // not changing - if (!gridState[GRIDSTATE_editControlChanging]) - gridState[GRIDSTATE_inAddNewRow] = false; - } - } - - protected override void OnKeyDown(KeyEventArgs ke) - { - Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: OnKeyDown "); - base.OnKeyDown(ke); - ProcessGridKey(ke); - } - - protected override void OnKeyPress(KeyPressEventArgs kpe) - { - Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: OnKeyPress " + TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(kpe.KeyChar)); - - base.OnKeyPress(kpe); - GridColumnStylesCollection coll = myGridTable.GridColumnStyles; - if (coll is not null && currentCol > 0 && currentCol < coll.Count) - { - if (!coll[currentCol].ReadOnly) - if (kpe.KeyChar > 32) - { - Edit(new string(new char[] { kpe.KeyChar })); - } - } - } - - protected override void OnMouseDown(MouseEventArgs e) - { - base.OnMouseDown(e); - - gridState[GRIDSTATE_childLinkFocused] = false; - gridState[GRIDSTATE_dragging] = false; - if (listManager is null) - return; - - HitTestInfo location = HitTest(e.X, e.Y); - Keys nModifier = ModifierKeys; - bool isControlDown = (nModifier & Keys.Control) == Keys.Control && (nModifier & Keys.Alt) == 0; - bool isShiftDown = (nModifier & Keys.Shift) == Keys.Shift; - - // Only left clicks for now - if (e.Button != MouseButtons.Left) - return; - - // Check column resize - if (location.type == HitTestType.ColumnResize) - { - if (e.Clicks > 1) - { - ColAutoResize(location.col); - } - else - ColResizeBegin(e, location.col); - return; - } - - // Check row resize - if (location.type == HitTestType.RowResize) - { - if (e.Clicks > 1) - { - RowAutoResize(location.row); - } - else - { - RowResizeBegin(e, location.row); - } - - return; - } - - // Check column headers - if (location.type == HitTestType.ColumnHeader) - { - trackColumnHeader = myGridTable.GridColumnStyles[location.col].PropertyDescriptor; - return; - } - - if (location.type == HitTestType.Caption) - { - Rectangle captionRect = layout.Caption; - caption.MouseDown(e.X - captionRect.X, e.Y - captionRect.Y); - return; - } - - if (layout.Data.Contains(e.X, e.Y) || layout.RowHeaders.Contains(e.X, e.Y)) - { - // Check with the row underneath the mouse - int row = GetRowFromY(e.Y); - if (row > -1) - { - Point p = NormalizeToRow(e.X, e.Y, row); - DataGridRow[] localGridRows = DataGridRows; - if (localGridRows[row].OnMouseDown(p.X, p.Y, - layout.RowHeaders, - isRightToLeft())) - { - CommitEdit(); - - localGridRows = DataGridRows; - if (row < DataGridRowsLength && (localGridRows[row] is DataGridRelationshipRow) && ((DataGridRelationshipRow)localGridRows[row]).Expanded) - EnsureVisible(row, 0); - - Edit(); - return; - } - } - } - - if (location.type == HitTestType.RowHeader) - { - EndEdit(); - if (!(DataGridRows[location.row] is DataGridAddNewRow)) - { - int savedCurrentRow = currentRow; - CurrentCell = new DataGridCell(location.row, currentCol); - if (location.row != savedCurrentRow && - currentRow != location.row && - currentRow == savedCurrentRow) - { - // The data grid was not able to move away from its previous current row. - // Be defensive and don't select the row. - return; - } - } - - if (isControlDown) - { - if (IsSelected(location.row)) - UnSelect(location.row); - else - Select(location.row); - } - else - { - if (lastRowSelected == -1 || !isShiftDown) - { - ResetSelection(); - Select(location.row); - } - else - { - int lowerRow = Math.Min(lastRowSelected, location.row); - int upperRow = Math.Max(lastRowSelected, location.row); - - // we need to reset the old SelectedRows. - // ResetSelection() will also reset lastRowSelected, so we - // need to save it - int saveLastRowSelected = lastRowSelected; - ResetSelection(); - lastRowSelected = saveLastRowSelected; - - DataGridRow[] rows = DataGridRows; - for (int i = lowerRow; i <= upperRow; i++) - { - rows[i].Selected = true; - numSelectedRows++; - } - - EndEdit(); - return; - } - } - - lastRowSelected = location.row; - // OnRowHeaderClick(EventArgs.Empty); - return; - } - - // Check parentRows - if (location.type == HitTestType.ParentRows) - { - EndEdit(); - parentRows.OnMouseDown(e.X, e.Y, isRightToLeft()); - } - - // Check cell clicks - if (location.type == HitTestType.Cell) - { - if (myGridTable.GridColumnStyles[location.col].MouseDown(location.row, e.X, e.Y)) - return; - DataGridCell target = new DataGridCell(location.row, location.col); - if (policy.AllowEdit && CurrentCell.Equals(target)) - { - ResetSelection(); - // what if only a part of the current cell is visible? - EnsureVisible(currentRow, currentCol); - Edit(); - } - else - { - ResetSelection(); - CurrentCell = target; - } - } - } - - protected override void OnMouseLeave(EventArgs e) - { - base.OnMouseLeave(e); - if (oldRow != -1) - { - DataGridRow[] localGridRows = DataGridRows; - localGridRows[oldRow].OnMouseLeft(layout.RowHeaders, isRightToLeft()); - } - - if (gridState[GRIDSTATE_overCaption]) - { - caption.MouseLeft(); - } - - Cursor = null; - } - - internal void TextBoxOnMouseWheel(MouseEventArgs e) - { - OnMouseWheel(e); - } - - protected override void OnMouseMove(MouseEventArgs e) - { - base.OnMouseMove(e); - if (listManager is null) - return; - - HitTestInfo location = HitTest(e.X, e.Y); - - bool alignToRight = isRightToLeft(); - - // We need to give UI feedback when the user is resizing a column - if (gridState[GRIDSTATE_trackColResize]) - { - ColResizeMove(e); - } - - if (gridState[GRIDSTATE_trackRowResize]) - { - RowResizeMove(e); - } - - if (gridState[GRIDSTATE_trackColResize] || location.type == HitTestType.ColumnResize) - { - Cursor = Cursors.SizeWE; - return; - } - else if (gridState[GRIDSTATE_trackRowResize] || location.type == HitTestType.RowResize) - { - Cursor = Cursors.SizeNS; - return; - } - else - { - Cursor = null; - } - - if ((layout.Data.Contains(e.X, e.Y) - || (layout.RowHeadersVisible && layout.RowHeaders.Contains(e.X, e.Y)))) - { - // && (isNavigating || isEditing)) { - DataGridRow[] localGridRows = DataGridRows; - // If we are over a row, let it know about the mouse move. - int rowOver = GetRowFromY(e.Y); - // set the dragging bit: - if (lastRowSelected != -1 && !gridState[GRIDSTATE_dragging]) - { - int topRow = GetRowTop(lastRowSelected); - int bottomRow = topRow + localGridRows[lastRowSelected].Height; - int dragHeight = SystemInformation.DragSize.Height; - gridState[GRIDSTATE_dragging] = ((e.Y - topRow < dragHeight && topRow - e.Y < dragHeight) || (e.Y - bottomRow < dragHeight && bottomRow - e.Y < dragHeight)); - } - - if (rowOver > -1) - { - Point p = NormalizeToRow(e.X, e.Y, rowOver); - if (!localGridRows[rowOver].OnMouseMove(p.X, p.Y, layout.RowHeaders, alignToRight) && gridState[GRIDSTATE_dragging]) - { - // if the row did not use this, see if selection can use it - MouseButtons mouse = MouseButtons; - if (lastRowSelected != -1 && (mouse & MouseButtons.Left) == MouseButtons.Left - && !(((Control.ModifierKeys & Keys.Control) == Keys.Control) && (Control.ModifierKeys & Keys.Alt) == 0)) - { - // ResetSelection() will reset the lastRowSelected too - // - int saveLastRowSelected = lastRowSelected; - ResetSelection(); - lastRowSelected = saveLastRowSelected; - - int lowerRow = Math.Min(lastRowSelected, rowOver); - int upperRow = Math.Max(lastRowSelected, rowOver); - - DataGridRow[] rows = DataGridRows; - for (int i = lowerRow; i <= upperRow; i++) - { - rows[i].Selected = true; - numSelectedRows++; - } - } - } - } - - if (oldRow != rowOver && oldRow != -1) - { - localGridRows[oldRow].OnMouseLeft(layout.RowHeaders, alignToRight); - } - - oldRow = rowOver; - } - - // check parentRows - if (location.type == HitTestType.ParentRows) - { - if (parentRows is not null) - { - parentRows.OnMouseMove(e.X, e.Y); - } - } - - if (location.type == HitTestType.Caption) - { - gridState[GRIDSTATE_overCaption] = true; - Rectangle captionRect = layout.Caption; - caption.MouseOver(e.X - captionRect.X, e.Y - captionRect.Y); - return; - } - else - { - if (gridState[GRIDSTATE_overCaption]) - { - gridState[GRIDSTATE_overCaption] = false; - caption.MouseLeft(); - } - } - } - - protected override void OnMouseUp(MouseEventArgs e) - { - base.OnMouseUp(e); - gridState[GRIDSTATE_dragging] = false; - if (listManager is null || myGridTable is null) - return; - if (gridState[GRIDSTATE_trackColResize]) - { - ColResizeEnd(e); - } - - if (gridState[GRIDSTATE_trackRowResize]) - { - RowResizeEnd(e); - } - - gridState[GRIDSTATE_trackColResize] = false; - gridState[GRIDSTATE_trackRowResize] = false; - - HitTestInfo ci = HitTest(e.X, e.Y); - if ((ci.type & HitTestType.Caption) == HitTestType.Caption) - { - caption.MouseUp(e.X, e.Y); - } - - // Check column headers - if (ci.type == HitTestType.ColumnHeader) - { - PropertyDescriptor prop = myGridTable.GridColumnStyles[ci.col].PropertyDescriptor; - if (prop == trackColumnHeader) - { - ColumnHeaderClicked(trackColumnHeader); - } - } - - trackColumnHeader = null; - } - - protected override void OnMouseWheel(MouseEventArgs e) - { - base.OnMouseWheel(e); - - if (e is HandledMouseEventArgs) - { - if (((HandledMouseEventArgs)e).Handled) - { - // The application event handler handled the scrolling - don't do anything more. - return; - } - - ((HandledMouseEventArgs)e).Handled = true; - } - - bool wheelingDown = true; - if ((ModifierKeys & Keys.Control) != 0) - wheelingDown = false; - - if (listManager is null || myGridTable is null) - return; - ScrollBar sb = wheelingDown ? vertScrollBar : horizScrollBar; - if (!sb.Visible) - return; - - // so we scroll. we have to know this, cause otherwise we will call EndEdit - // and that would be wrong. - gridState[GRIDSTATE_isScrolling] = true; - wheelDelta += e.Delta; - float movePerc = (float)wheelDelta / PInvoke.WHEEL_DELTA; - int move = (int)(SystemInformation.MouseWheelScrollLines * movePerc); - if (move != 0) - { - wheelDelta = 0; - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: OnMouseWheel move=" + move.ToString(CultureInfo.InvariantCulture)); - if (wheelingDown) - { - int newRow = firstVisibleRow - move; - newRow = Math.Max(0, Math.Min(newRow, DataGridRowsLength - numTotallyVisibleRows)); - ScrollDown(newRow - firstVisibleRow); - } - else - { - int newValue = horizScrollBar.Value + (move < 0 ? 1 : -1) * horizScrollBar.LargeChange; - HorizontalOffset = newValue; - } - } - - gridState[GRIDSTATE_isScrolling] = false; - } - - protected override void OnPaint(PaintEventArgs pe) - { - try - { - CheckHierarchyState(); - - if (layout.dirty) - ComputeLayout(); - - Graphics g = pe.Graphics; - - Region clipRegion = g.Clip; - if (layout.CaptionVisible) - caption.Paint(g, layout.Caption, isRightToLeft()); - - if (layout.ParentRowsVisible) - { - Debug.WriteLineIf(CompModSwitches.DataGridParents.TraceVerbose, "DataGridParents: Painting ParentRows " + layout.ParentRows.ToString()); - g.FillRectangle(SystemBrushes.AppWorkspace, layout.ParentRows); - parentRows.Paint(g, layout.ParentRows, isRightToLeft()); - } - - Rectangle gridRect = layout.Data; - if (layout.RowHeadersVisible) - gridRect = Rectangle.Union(gridRect, layout.RowHeaders); - if (layout.ColumnHeadersVisible) - gridRect = Rectangle.Union(gridRect, layout.ColumnHeaders); - - g.SetClip(gridRect); - PaintGrid(g, gridRect); - g.Clip = clipRegion; - clipRegion.Dispose(); - PaintBorder(g, layout.ClientRectangle); - - g.FillRectangle(DefaultHeaderBackBrush, layout.ResizeBoxRect); - - base.OnPaint(pe); // raise paint event - } - catch - { - // at runtime we will rethrow the exception - if (Site is null || !Site.DesignMode) - throw; - gridState[GRIDSTATE_exceptionInPaint] = true; - try - { - RTLAwareMessageBox.Show(null, "SR.GetString(SR.DataGridExceptionInPaint)", null, MessageBoxButtons.OK, - MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); - - if (Visible) - BeginUpdateInternal(); - - ResetParentRows(); - - Set_ListManager(null, string.Empty, true); - } - finally - { - gridState[GRIDSTATE_exceptionInPaint] = false; - if (Visible) - EndUpdateInternal(); - } - } - } - - protected override void OnResize(EventArgs e) - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: OnResize"); - - if (layout.CaptionVisible) - Invalidate(layout.Caption); - if (layout.ParentRowsVisible) - parentRows.OnResize(layout.ParentRows); - - int borderWidth = BorderWidth; - Rectangle right; - Rectangle bottom; - Rectangle oldClientRectangle = layout.ClientRectangle; - - right = new Rectangle(oldClientRectangle.X + oldClientRectangle.Width - borderWidth, - oldClientRectangle.Y, - borderWidth, - oldClientRectangle.Height); - bottom = new Rectangle(oldClientRectangle.X, - oldClientRectangle.Y + oldClientRectangle.Height - borderWidth, - oldClientRectangle.Width, - borderWidth); - - Rectangle newClientRectangle = ClientRectangle; - if (newClientRectangle.Width != oldClientRectangle.Width) - { - Invalidate(right); - right = new Rectangle(newClientRectangle.X + newClientRectangle.Width - borderWidth, - newClientRectangle.Y, - borderWidth, - newClientRectangle.Height); - Invalidate(right); - } - - if (newClientRectangle.Height != oldClientRectangle.Height) - { - Invalidate(bottom); - bottom = new Rectangle(newClientRectangle.X, - newClientRectangle.Y + newClientRectangle.Height - borderWidth, - newClientRectangle.Width, - borderWidth); - Invalidate(bottom); - } - - // also, invalidate the ResizeBoxRect - if (!layout.ResizeBoxRect.IsEmpty) - Invalidate(layout.ResizeBoxRect); - - layout.ClientRectangle = newClientRectangle; - - int oldFirstVisibleRow = firstVisibleRow; - base.OnResize(e); - if (isRightToLeft() || oldFirstVisibleRow != firstVisibleRow) - Invalidate(); - } - - internal void OnRowHeightChanged(DataGridRow row) - { - ClearRegionCache(); - int cy = GetRowTop(row.RowNumber); - if (cy > 0) - { - Rectangle refresh = new Rectangle - { - Y = cy, - X = layout.Inside.X, - Width = layout.Inside.Width, - Height = layout.Inside.Bottom - cy - }; - Invalidate(refresh); - } - } - - internal void ParentRowsDataChanged() - { - Debug.Assert(originalState is not null, "how can we get a list changed event from another listmanager/list while not navigating"); - - // do the reset work that is done in SetDataBindings, set_DataSource, set_DataMember; - parentRows.Clear(); - caption.BackButtonActive = caption.DownButtonActive = caption.BackButtonVisible = false; - caption.SetDownButtonDirection(!layout.ParentRowsVisible); - object dSource = originalState.DataSource; - string dMember = originalState.DataMember; - // we don't need to set the GRIDSTATE_metaDataChanged bit, cause - // the listManager from the originalState should be different from the current listManager - // set the originalState to null so that Set_ListManager knows that - // it has to unhook the MetaDataChanged events - originalState = null; - Set_ListManager(dSource, dMember, true); - } - - private void AbortEdit() - { - Debug.WriteLineIf(CompModSwitches.DataGridEditing.TraceVerbose, "DataGridEditing: \t! AbortEdit"); - Debug.Assert(gridState[GRIDSTATE_isEditing], "Can't abort an edit that is not happening!"); - - // the same rules from editColumn.OnEdit - // while changing the editControl's visibility, do not - // PerformLayout on the entire DataGrid - gridState[GRIDSTATE_editControlChanging] = true; - - editColumn.Abort(editRow.RowNumber); - - // reset the editControl flag: - gridState[GRIDSTATE_editControlChanging] = false; - - gridState[GRIDSTATE_isEditing] = false; - editRow = null; - editColumn = null; - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event NavigateEventHandler Navigate - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - protected event EventHandler RowHeaderClick - { - add - { - onRowHeaderClick += value; - } - remove - { - onRowHeaderClick -= value; - } - } - - internal event EventHandler NodeClick - { - add - { - Events.AddHandler(EVENT_NODECLICKED, value); - } - remove - { - Events.RemoveHandler(EVENT_NODECLICKED, value); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler Scroll - { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public override ISite Site - { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - internal void AddNewRow() - { - EnsureBound(); - ResetSelection(); - // EndEdit(); - UpdateListManager(); - gridState[GRIDSTATE_inListAddNew] = true; - gridState[GRIDSTATE_inAddNewRow] = true; - try - { - ListManager.AddNew(); - } - catch - { - gridState[GRIDSTATE_inListAddNew] = false; - gridState[GRIDSTATE_inAddNewRow] = false; - PerformLayout(); - InvalidateInside(); - throw; - } - - gridState[GRIDSTATE_inListAddNew] = false; - } - - public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) - { - throw new PlatformNotSupportedException(); - } - - public void BeginInit() - { - throw new PlatformNotSupportedException(); - } - - private Rectangle CalcRowResizeFeedbackRect(MouseEventArgs e) - { - Rectangle inside = layout.Data; - Rectangle r = new Rectangle(inside.X, e.Y, inside.Width, 3); - r.Y = Math.Min(inside.Bottom - 3, r.Y); - r.Y = Math.Max(r.Y, 0); - return r; - } - - private Rectangle CalcColResizeFeedbackRect(MouseEventArgs e) - { - Rectangle inside = layout.Data; - Rectangle r = new Rectangle(e.X, inside.Y, 3, inside.Height); - r.X = Math.Min(inside.Right - 3, r.X); - r.X = Math.Max(r.X, 0); - return r; - } - - private void CancelCursorUpdate() - { - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: Requesting CancelEdit()"); - if (listManager is not null) - { - EndEdit(); - listManager.CancelCurrentEdit(); - } - } - - private void CheckHierarchyState() - { - if (checkHierarchy && listManager is not null && myGridTable is not null) - { - if (myGridTable is null) - return; - - for (int j = 0; j < myGridTable.GridColumnStyles.Count; j++) - { - DataGridColumnStyle gridColumn = myGridTable.GridColumnStyles[j]; - } - - checkHierarchy = false; - } - } - - /// - /// The DataGrid caches an array of rectangular areas - /// which represent the area which scrolls left to right. - /// This method is invoked whenever the DataGrid's - /// scrollable regions change in such a way as to require - /// a re-recalculation. - /// - private void ClearRegionCache() - { - cachedScrollableRegion = null; - } - - /// - /// Determines the best fit size for the given column. - /// - private void ColAutoResize(int col) - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ColAutoResize"); - EndEdit(); - CurrencyManager listManager = this.listManager; - if (listManager is null) - return; - - int size; - Graphics g = CreateGraphicsInternal(); - try - { - DataGridColumnStyle column = myGridTable.GridColumnStyles[col]; - string columnName = column.HeaderText; - - Font headerFont; - if (myGridTable.IsDefault) - headerFont = HeaderFont; - else - headerFont = myGridTable.HeaderFont; - size = (int)g.MeasureString(columnName, headerFont).Width + layout.ColumnHeaders.Height + 1; // This is not a bug, the sort triangle's width is equal to it's height. - int rowCount = listManager.Count; - for (int row = 0; row < rowCount; ++row) - { - object value = column.GetColumnValueAtRow(listManager, row); - int width = 0; - if (width > size) - size = width; - } - - if (column.Width != size) - { - column.width = size; - - ComputeVisibleColumns(); - - bool lastColumnIsLastTotallyVisibleCol = true; - if (lastTotallyVisibleCol != -1) - { - for (int i = lastTotallyVisibleCol + 1; i < myGridTable.GridColumnStyles.Count; i++) - { - if (myGridTable.GridColumnStyles[i].PropertyDescriptor is not null) - { - lastColumnIsLastTotallyVisibleCol = false; - break; - } - } - } - else - { - lastColumnIsLastTotallyVisibleCol = false; - } - - // if the column shrank and the last totally visible column was the last column - // then we need to recompute the horizontalOffset, firstVisibleCol, negOffset. - // lastTotallyVisibleCol remains the last column - if (lastColumnIsLastTotallyVisibleCol && - (negOffset != 0 || horizontalOffset != 0)) - { - // update the column width - column.width = size; - - int cx = 0; - int colCount = myGridTable.GridColumnStyles.Count; - int visibleWidth = layout.Data.Width; - GridColumnStylesCollection cols = myGridTable.GridColumnStyles; - - // assume everything fits - negOffset = 0; - horizontalOffset = 0; - firstVisibleCol = 0; - - for (int i = colCount - 1; i >= 0; i--) - { - if (cols[i].PropertyDescriptor is null) - { - continue; - } - - cx += cols[i].Width; - if (cx > visibleWidth) - { - if (negOffset == 0) - { - firstVisibleCol = i; - negOffset = cx - visibleWidth; - horizontalOffset = negOffset; - numVisibleCols++; - } - else - { - horizontalOffset += cols[i].Width; - } - } - else - { - numVisibleCols++; - } - } - - // refresh the horizontal scrollbar - PerformLayout(); - - // we need to invalidate the layout.Data and layout.ColumnHeaders - Invalidate(Rectangle.Union(layout.Data, layout.ColumnHeaders)); - } - else - { - // need to refresh the scroll bar - PerformLayout(); - - Rectangle rightArea = layout.Data; - if (layout.ColumnHeadersVisible) - rightArea = Rectangle.Union(rightArea, layout.ColumnHeaders); - - int left = GetColBeg(col); - - if (!isRightToLeft()) - { - rightArea.Width -= left - rightArea.X; - rightArea.X = left; - } - else - { - rightArea.Width = rightArea.Width - left; - } - - Invalidate(rightArea); - } - } - } - finally - { - g.Dispose(); - } - - if (horizScrollBar.Visible) - { - horizScrollBar.Value = HorizontalOffset; - } - } - - public void Collapse(int row) - { - throw new PlatformNotSupportedException(); - } - - private void ColResizeBegin(MouseEventArgs e, int col) - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ColResizeBegin"); - Debug.Assert(myGridTable is not null, "Column resizing operations can't be called when myGridTable is null."); - - int x = e.X; - EndEdit(); - Rectangle clip = Rectangle.Union(layout.ColumnHeaders, layout.Data); - if (isRightToLeft()) - { - clip.Width = GetColBeg(col) - layout.Data.X - 2; - } - else - { - int leftEdge = GetColBeg(col); - clip.X = leftEdge + 3; - clip.Width = layout.Data.X + layout.Data.Width - leftEdge - 2; - } - - gridState[GRIDSTATE_trackColResize] = true; - trackColAnchor = x; - trackColumn = col; - - DrawColSplitBar(e); - lastSplitBar = e; - } - - private void ColResizeMove(MouseEventArgs e) - { - if (lastSplitBar is not null) - { - DrawColSplitBar(lastSplitBar); - lastSplitBar = e; - } - - DrawColSplitBar(e); - } - - private void ColResizeEnd(MouseEventArgs e) - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ColResizeEnd"); - Debug.Assert(myGridTable is not null, "Column resizing operations can't be called when myGridTable is null."); - - gridState[GRIDSTATE_layoutSuspended] = true; - try - { - if (lastSplitBar is not null) - { - DrawColSplitBar(lastSplitBar); - lastSplitBar = null; - } - - bool rightToLeft = isRightToLeft(); - - int x = rightToLeft ? Math.Max(e.X, layout.Data.X) : Math.Min(e.X, layout.Data.Right + 1); - int delta = x - GetColEnd(trackColumn); - if (rightToLeft) - delta = -delta; - - if (trackColAnchor != x && delta != 0) - { - DataGridColumnStyle column = myGridTable.GridColumnStyles[trackColumn]; - int proposed = column.Width + delta; - proposed = Math.Max(proposed, 3); - column.Width = proposed; - - // refresh scrolling data: horizontalOffset, negOffset, firstVisibleCol, numVisibleCols, lastTotallyVisibleCol - ComputeVisibleColumns(); - - bool lastColumnIsLastTotallyVisibleCol = true; - for (int i = lastTotallyVisibleCol + 1; i < myGridTable.GridColumnStyles.Count; i++) - { - if (myGridTable.GridColumnStyles[i].PropertyDescriptor is not null) - { - lastColumnIsLastTotallyVisibleCol = false; - break; - } - } - - if (lastColumnIsLastTotallyVisibleCol && - (negOffset != 0 || horizontalOffset != 0)) - { - int cx = 0; - int colCount = myGridTable.GridColumnStyles.Count; - int visibleWidth = layout.Data.Width; - GridColumnStylesCollection cols = myGridTable.GridColumnStyles; - - // assume everything fits - negOffset = 0; - horizontalOffset = 0; - firstVisibleCol = 0; - - for (int i = colCount - 1; i > -1; i--) - { - if (cols[i].PropertyDescriptor is null) - { - continue; - } - - cx += cols[i].Width; - - if (cx > visibleWidth) - { - if (negOffset == 0) - { - negOffset = cx - visibleWidth; - firstVisibleCol = i; - horizontalOffset = negOffset; - numVisibleCols++; - } - else - { - horizontalOffset += cols[i].Width; - } - } - else - { - numVisibleCols++; - } - } - - // and invalidate pretty much everything - Invalidate(Rectangle.Union(layout.Data, layout.ColumnHeaders)); - } - else - { - Rectangle rightArea = Rectangle.Union(layout.ColumnHeaders, layout.Data); - int left = GetColBeg(trackColumn); - rightArea.Width -= rightToLeft ? rightArea.Right - left : left - rightArea.X; - rightArea.X = rightToLeft ? layout.Data.X : left; - Invalidate(rightArea); - } - } - } - finally - { - gridState[GRIDSTATE_layoutSuspended] = false; - } - - PerformLayout(); - - if (horizScrollBar.Visible) - { - horizScrollBar.Value = HorizontalOffset; - } - } - - private void MetaDataChanged() - { - // when we reset the Binding in the grid, we need to clear the parent rows. - // the same goes for all the caption UI: reset it when the datasource changes. - parentRows.Clear(); - caption.BackButtonActive = caption.DownButtonActive = caption.BackButtonVisible = false; - caption.SetDownButtonDirection(!layout.ParentRowsVisible); - - gridState[GRIDSTATE_metaDataChanged] = true; - try - { - if (originalState is not null) - { - // set the originalState to null so that Set_ListManager knows that - // it has to unhook the MetaDataChanged events - Set_ListManager(originalState.DataSource, originalState.DataMember, true); - originalState = null; - } - else - { - Set_ListManager(DataSource, DataMember, true); - } - } - finally - { - gridState[GRIDSTATE_metaDataChanged] = false; - } - } - - private void RowAutoResize(int row) - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: RowAutoResize"); - - EndEdit(); - CurrencyManager listManager = ListManager; - if (listManager is null) - return; - - Graphics g = CreateGraphicsInternal(); - try - { - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - DataGridRow resizeRow = DataGridRows[row]; - int rowCount = listManager.Count; - int resizeHeight = 0; - - // compute the height that we should resize to: - int columnsCount = columns.Count; - for (int col = 0; col < columnsCount; col++) - { - object value = columns[col].GetColumnValueAtRow(listManager, row); - resizeHeight = 0; - } - - if (resizeRow.Height != resizeHeight) - { - resizeRow.Height = resizeHeight; - - // needed to refresh scrollbar properties - PerformLayout(); - - Rectangle rightArea = layout.Data; - if (layout.RowHeadersVisible) - rightArea = Rectangle.Union(rightArea, layout.RowHeaders); - int top = GetRowTop(row); - rightArea.Height -= rightArea.Y - top; - rightArea.Y = top; - Invalidate(rightArea); - } - } - finally - { - g.Dispose(); - } - - return; - } - - private void RowResizeBegin(MouseEventArgs e, int row) - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: RowResizeBegin"); - Debug.Assert(myGridTable is not null, "Row resizing operations can't be called when myGridTable is null."); - - int y = e.Y; - EndEdit(); - Rectangle clip = Rectangle.Union(layout.RowHeaders, layout.Data); - int topEdge = GetRowTop(row); - clip.Y = topEdge + 3; - clip.Height = layout.Data.Y + layout.Data.Height - topEdge - 2; - - gridState[GRIDSTATE_trackRowResize] = true; - trackRowAnchor = y; - trackRow = row; - - DrawRowSplitBar(e); - lastSplitBar = e; - } - - private void RowResizeMove(MouseEventArgs e) - { - if (lastSplitBar is not null) - { - DrawRowSplitBar(lastSplitBar); - lastSplitBar = e; - } - - DrawRowSplitBar(e); - } - - private void RowResizeEnd(MouseEventArgs e) - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: RowResizeEnd"); - Debug.Assert(myGridTable is not null, "Row resizing operations can't be called when myGridTable is null."); - - try - { - if (lastSplitBar is not null) - { - DrawRowSplitBar(lastSplitBar); - lastSplitBar = null; - } - - int y = Math.Min(e.Y, layout.Data.Y + layout.Data.Height + 1); - int delta = y - GetRowBottom(trackRow); - if (trackRowAnchor != y && delta != 0) - { - DataGridRow row = DataGridRows[trackRow]; - int proposed = row.Height + delta; - proposed = Math.Max(proposed, 3); - row.Height = proposed; - - // needed to refresh scrollbar properties - PerformLayout(); - - Rectangle rightArea = Rectangle.Union(layout.RowHeaders, layout.Data); - int top = GetRowTop(trackRow); - rightArea.Height -= rightArea.Y - top; - rightArea.Y = top; - Invalidate(rightArea); - } - } - finally - { - } - } - - /// - /// Fires the ColumnHeaderClicked event and handles column - /// sorting. - /// - private void ColumnHeaderClicked(PropertyDescriptor prop) - { - if (!CommitEdit()) - return; - - // OnColumnHeaderClick(EventArgs.Empty); - bool allowSorting; - if (myGridTable.IsDefault) - allowSorting = AllowSorting; - else - allowSorting = myGridTable.AllowSorting; - - if (!allowSorting) - return; - - // if (CompModSwitches.DataGridCursor.OutputVerbose) Debug.WriteLine("DataGridCursor: We are about to sort column " + col.ToString()); - ListSortDirection direction = ListManager.GetSortDirection(); - PropertyDescriptor sortColumn = ListManager.GetSortProperty(); - if (sortColumn is not null && sortColumn.Equals(prop)) - direction = (direction == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending; - else - // defaultSortDirection : ascending - direction = ListSortDirection.Ascending; - - if (listManager.Count == 0) - return; - - ListManager.SetSort(prop, direction); - ResetSelection(); - - InvalidateInside(); - } - - /// - /// Attempts to commit editing if a cell is being edited. - /// Return true if successfully commited editing. - /// Return false if editing can not be completed and the gird must - /// remain in our current Edit state. - /// - private bool CommitEdit() - { - Debug.WriteLineIf(CompModSwitches.DataGridEditing.TraceVerbose, "DataGridEditing: \t CommitEdit " + (editRow is null ? "" : editRow.RowNumber.ToString(CultureInfo.InvariantCulture))); - // we want to commit the editing if - // 1. the user was editing or navigating around the data grid and - // 2. this is not the result of moving focus inside the data grid and - // 3. if the user was scrolling - if ((!gridState[GRIDSTATE_isEditing] && !gridState[GRIDSTATE_isNavigating]) || (gridState[GRIDSTATE_editControlChanging] && !gridState[GRIDSTATE_isScrolling])) - return true; - - // the same rules from editColumn.OnEdit - // flag that we are editing the Edit control, so if we get a OnLayout on the - // datagrid side of things while the edit control changes its visibility and bounds - // the datagrid does not perform a layout - gridState[GRIDSTATE_editControlChanging] = true; - - if (editColumn.ReadOnly || gridState[GRIDSTATE_inAddNewRow]) - { - bool focusTheGrid = false; - if (ContainsFocus) - { - focusTheGrid = true; - } - - if (focusTheGrid && gridState[GRIDSTATE_canFocus]) - FocusInternal(); - editColumn.ConcedeFocus(); - - // set the focus back to the grid - if (focusTheGrid && gridState[GRIDSTATE_canFocus] && CanFocus && !Focused) - FocusInternal(); - - // reset the editControl flag - gridState[GRIDSTATE_editControlChanging] = false; - return true; - } - - bool retVal = editColumn.Commit(ListManager, currentRow); - - // reset the editControl flag - gridState[GRIDSTATE_editControlChanging] = false; - - if (retVal) - gridState[GRIDSTATE_isEditing] = false; - - return retVal; - } - - /// - /// Figure out how many rows we need to scroll down - /// to move targetRow into visibility. - /// - private int ComputeDeltaRows(int targetRow) - { - if (firstVisibleRow == targetRow) - return 0; - - int dRows = 0; - int firstVisibleRowLogicalTop = -1; - int targetRowLogicalTop = -1; - int nRows = DataGridRowsLength; - int cy = 0; - DataGridRow[] localGridRows = DataGridRows; - - for (int row = 0; row < nRows; ++row) - { - if (row == firstVisibleRow) - firstVisibleRowLogicalTop = cy; - if (row == targetRow) - targetRowLogicalTop = cy; - if (targetRowLogicalTop != -1 && firstVisibleRowLogicalTop != -1) - break; - cy += localGridRows[row].Height; - } - - int targetRowLogicalBottom = targetRowLogicalTop + localGridRows[targetRow].Height; - int dataLogicalBottom = layout.Data.Height + firstVisibleRowLogicalTop; - if (targetRowLogicalBottom > dataLogicalBottom) - { - // we need to move down. - int downDelta = targetRowLogicalBottom - dataLogicalBottom; - firstVisibleRowLogicalTop += downDelta; - } - else if (firstVisibleRowLogicalTop < targetRowLogicalTop) - { - // we don't need to move - return 0; - } - else - { - // we need to move up. - int upDelta = firstVisibleRowLogicalTop - targetRowLogicalTop; - firstVisibleRowLogicalTop -= upDelta; - } - - int newFirstRow = ComputeFirstVisibleRow(firstVisibleRowLogicalTop); - dRows = (newFirstRow - firstVisibleRow); - return dRows; - } - - /// - /// Given the a logical vertical offset, figure out - /// which row number should be the first fully visible - /// row on or after the offset. - /// - private int ComputeFirstVisibleRow(int firstVisibleRowLogicalTop) - { - int first; - int nRows = DataGridRowsLength; - int cy = 0; - DataGridRow[] localGridRows = DataGridRows; - for (first = 0; first < nRows; ++first) - { - if (cy >= firstVisibleRowLogicalTop) - break; - cy += localGridRows[first].Height; - } - - return first; - } - - /// - /// Constructs an updated Layout object. - /// - private void ComputeLayout() - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ComputeLayout"); - - bool alignLeft = !isRightToLeft(); - Rectangle oldResizeRect = layout.ResizeBoxRect; - - // hide the EditBox - EndEdit(); - - ClearRegionCache(); - - // NOTE : Since Rectangles are structs, then assignment is a - // : copy. Therefore, after saying "Rectangle inside = newLayout.Inside", - // : we must always assign back to newLayout.Inside. - // - - // Important since all of the visibility flags will move - // to the new layout here. - LayoutData newLayout = new LayoutData(layout); - - // Inside - newLayout.Inside = ClientRectangle; - Rectangle inside = newLayout.Inside; - int borderWidth = BorderWidth; - inside.Inflate(-borderWidth, -borderWidth); - - Rectangle insideLeft = inside; - - // Caption - if (layout.CaptionVisible) - { - int captionHeight = captionFontHeight + 6; - Rectangle cap = newLayout.Caption; - cap = insideLeft; - cap.Height = captionHeight; - insideLeft.Y += captionHeight; - insideLeft.Height -= captionHeight; - - newLayout.Caption = cap; - } - else - { - newLayout.Caption = Rectangle.Empty; - } - - // Parent Rows - if (layout.ParentRowsVisible) - { - Rectangle parents = newLayout.ParentRows; - int parentHeight = parentRows.Height; - parents = insideLeft; - parents.Height = parentHeight; - insideLeft.Y += parentHeight; - insideLeft.Height -= parentHeight; - - newLayout.ParentRows = parents; - } - else - { - newLayout.ParentRows = Rectangle.Empty; - } - - // Headers - // - int columnHeaderHeight = headerFontHeight + 6; - if (layout.ColumnHeadersVisible) - { - Rectangle colHeaders = newLayout.ColumnHeaders; - colHeaders = insideLeft; - colHeaders.Height = columnHeaderHeight; - insideLeft.Y += columnHeaderHeight; - insideLeft.Height -= columnHeaderHeight; - - newLayout.ColumnHeaders = colHeaders; - } - else - { - newLayout.ColumnHeaders = Rectangle.Empty; - } - - bool newRowHeadersVisible = myGridTable.IsDefault ? RowHeadersVisible : myGridTable.RowHeadersVisible; - int newRowHeaderWidth = myGridTable.IsDefault ? RowHeaderWidth : myGridTable.RowHeaderWidth; - newLayout.RowHeadersVisible = newRowHeadersVisible; - if (myGridTable is not null && newRowHeadersVisible) - { - Rectangle rowHeaders = newLayout.RowHeaders; - if (alignLeft) - { - rowHeaders = insideLeft; - rowHeaders.Width = newRowHeaderWidth; - insideLeft.X += newRowHeaderWidth; - insideLeft.Width -= newRowHeaderWidth; - } - else - { - rowHeaders = insideLeft; - rowHeaders.Width = newRowHeaderWidth; - rowHeaders.X = insideLeft.Right - newRowHeaderWidth; - insideLeft.Width -= newRowHeaderWidth; - } - - newLayout.RowHeaders = rowHeaders; - - if (layout.ColumnHeadersVisible) - { - Rectangle topLeft = newLayout.TopLeftHeader; - Rectangle colHeaders = newLayout.ColumnHeaders; - if (alignLeft) - { - topLeft = colHeaders; - topLeft.Width = newRowHeaderWidth; - colHeaders.Width -= newRowHeaderWidth; - colHeaders.X += newRowHeaderWidth; - } - else - { - topLeft = colHeaders; - topLeft.Width = newRowHeaderWidth; - topLeft.X = colHeaders.Right - newRowHeaderWidth; - colHeaders.Width -= newRowHeaderWidth; - } - - newLayout.TopLeftHeader = topLeft; - newLayout.ColumnHeaders = colHeaders; - } - else - { - newLayout.TopLeftHeader = Rectangle.Empty; - } - } - else - { - newLayout.RowHeaders = Rectangle.Empty; - newLayout.TopLeftHeader = Rectangle.Empty; - } - - // The Data region - newLayout.Data = insideLeft; - newLayout.Inside = inside; - - layout = newLayout; - - LayoutScrollBars(); - - // if the user shrank the grid client area, then OnResize invalidated the old - // resize area. however, we need to invalidate the left upper corner in the new ResizeArea - // note that we can't take the Invalidate call from the OnResize method, because if the - // user enlarges the form then the old area will not be invalidated. - if (!oldResizeRect.Equals(layout.ResizeBoxRect) && !layout.ResizeBoxRect.IsEmpty) - Invalidate(layout.ResizeBoxRect); - - layout.dirty = false; - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: " + layout.ToString()); - } - - /// - /// Computes the number of pixels to scroll to scroll from one - /// row to another. - /// - private int ComputeRowDelta(int from, int to) - { - int first = from; - int last = to; - int sign = -1; - if (first > last) - { - first = to; - last = from; - sign = 1; - } - - DataGridRow[] localGridRows = DataGridRows; - int delta = 0; - for (int row = first; row < last; ++row) - { - delta += localGridRows[row].Height; - } - - return sign * delta; - } - - internal int MinimumRowHeaderWidth() - { - return minRowHeaderWidth; - } - - internal void ComputeMinimumRowHeaderWidth() - { - minRowHeaderWidth = errorRowBitmapWidth; // the size of the pencil, star and row selector images are the same as the image for the error bitmap - if (ListHasErrors) - minRowHeaderWidth += errorRowBitmapWidth; - if (myGridTable is not null && myGridTable.RelationsList.Count != 0) - minRowHeaderWidth += 15; // the size of the plus/minus glyph and spacing around it - } - - /// - /// - /// Updates the internal variables with the number of columns visible - /// inside the Grid's client rectangle. - /// - private void ComputeVisibleColumns() - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ComputeVisibleColumns"); - EnsureBound(); - - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - - int nGridCols = columns.Count; - int cx = -negOffset; - int visibleColumns = 0; - int visibleWidth = layout.Data.Width; - int curCol = firstVisibleCol; - - // the same problem with negative numbers: - // if the width passed in is negative, then return 0 - // - // added the check for the columns.Count == 0 ( danielhe, November 14, 2000) - // - if (visibleWidth < 0 || columns.Count == 0) - { - numVisibleCols = firstVisibleCol = 0; - lastTotallyVisibleCol = -1; - return; - } - - while (cx < visibleWidth && curCol < nGridCols) - { - // if (columns.Visible && columns.PropertyDescriptor is not null) - if (columns[curCol].PropertyDescriptor is not null) - cx += columns[curCol].Width; - curCol++; - visibleColumns++; - } - - numVisibleCols = visibleColumns; - - // if we inflate the data area - // then we paint columns to the left of firstVisibleColumn - if (cx < visibleWidth) - { - for (int i = firstVisibleCol - 1; i > 0; i--) - { - if (cx + columns[i].Width > visibleWidth) - break; - // if (columns.Visible && columns.PropertyDescriptor is not null) - if (columns[i].PropertyDescriptor is not null) - cx += columns[i].Width; - visibleColumns++; - firstVisibleCol--; - } - - if (numVisibleCols != visibleColumns) - { - Debug.Assert(numVisibleCols < visibleColumns, "the number of visible columns can only grow"); - // is there space for more columns than were visible? - // if so, then we need to repaint Data and ColumnHeaders - Invalidate(layout.Data); - Invalidate(layout.ColumnHeaders); - - // update the number of visible columns to the new reality - numVisibleCols = visibleColumns; - } - } - - lastTotallyVisibleCol = firstVisibleCol + numVisibleCols - 1; - if (cx > visibleWidth) - { - if (numVisibleCols <= 1 || (numVisibleCols == 2 && negOffset != 0)) - { - // no column is entirely visible - lastTotallyVisibleCol = -1; - } - else - { - lastTotallyVisibleCol--; - } - } - } - - /// - /// Determines which column is the first visible given - /// the object's horizontalOffset. - /// - private int ComputeFirstVisibleColumn() - { - int first = 0; - if (horizontalOffset == 0) - { - negOffset = 0; - return 0; - } - - // we will check to see if myGridTables.GridColumns.Count != 0 - // because when we reset the dataGridTable, we don't have any columns, and we still - // call HorizontalOffset = 0, and that will call ComputeFirstVisibleColumn with an empty collection of columns. - if (myGridTable is not null && myGridTable.GridColumnStyles is not null && myGridTable.GridColumnStyles.Count != 0) - { - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - int cx = 0; - int nGridCols = columns.Count; - - if (columns[0].Width == -1) - { - // the columns are not initialized yet - // -#if DEBUG - for (int i = 0; i < nGridCols; i++) - { - Debug.Assert(columns[i].Width == -1, "the columns' widths should not be initialized"); - } -#endif // DEBUG - negOffset = 0; - return 0; - } - - for (first = 0; first < nGridCols; first++) - { - // if (columns[first].Visible && columns[first].PropertyDescriptor is not null); - if (columns[first].PropertyDescriptor is not null) - cx += columns[first].Width; - if (cx > horizontalOffset) - break; - } - - // first may actually be the number of columns - // in that case all the columns fit in the layout data - if (first == nGridCols) - { - Debug.Assert(cx <= horizontalOffset, "look at the for loop before: we only exit that loop early if the cx is over the horizontal offset"); - negOffset = 0; - return 0; - } - - negOffset = columns[first].Width - (cx - horizontalOffset); - // Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: ComputeFirstVisibleColumn, ret = " + first.ToString() + ", negOffset = " + negOffset.ToString()); - } - - return first; - } - - /// - /// Updates the internal variables with the number of rows visible - /// in a given DataGrid Layout. - /// - private void ComputeVisibleRows() - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: ComputeVisibleRows"); - EnsureBound(); - - Rectangle data = layout.Data; - int visibleHeight = data.Height; - int cy = 0; - int visibleRows = 0; - DataGridRow[] localGridRows = DataGridRows; - int numRows = DataGridRowsLength; - - // when minimizing the dataGrid window, we will get negative values for the - // layout.Data.Width and layout.Data.Height ( is this a bug or not? if layout.Data.Height == 0 in that case, - // the old code would have worked ) - // - // if this is the case, then set numVisibleRows = numTotallyVisibleRows = 0; - // - if (visibleHeight < 0) - { - numVisibleRows = numTotallyVisibleRows = 0; - return; - } - - for (int i = firstVisibleRow; i < numRows; ++i) - { - if (cy > visibleHeight) - break; - cy += localGridRows[i].Height; - visibleRows++; - } - - if (cy < visibleHeight) - { - for (int i = firstVisibleRow - 1; i >= 0; i--) - { - int height = localGridRows[i].Height; - if (cy + height > visibleHeight) - break; - cy += height; - firstVisibleRow--; - visibleRows++; - } - } - - numVisibleRows = numTotallyVisibleRows = visibleRows; - if (cy > visibleHeight) - numTotallyVisibleRows--; - - Debug.Assert(numVisibleRows >= 0, "the number of visible rows can't be negative"); - Debug.Assert(numTotallyVisibleRows >= 0, "the number of totally visible rows can't be negative"); - } - - protected override AccessibleObject CreateAccessibilityInstance() - { - return new DataGridAccessibleObject(this); - } - - private DataGridState CreateChildState(string relationName, DataGridRow source) - { - DataGridState dgs = new DataGridState(); - - string newDataMember; - if (string.IsNullOrEmpty(DataMember)) - { - newDataMember = relationName; - } - else - { - newDataMember = DataMember + "." + relationName; - } - - CurrencyManager childLM = (CurrencyManager)BindingContext[DataSource, newDataMember]; - - dgs.DataSource = DataSource; - dgs.DataMember = newDataMember; - dgs.ListManager = childLM; - - dgs.DataGridRows = null; - dgs.DataGridRowsLength = childLM.Count + (policy.AllowAdd ? 1 : 0); - - return dgs; - } - - /// - /// Constructs a Layout object containing the state - /// for a newly constructed DataGrid. - /// - private LayoutData CreateInitialLayoutState() - { - Debug.WriteLineIf(CompModSwitches.DataGridLayout.TraceVerbose, "DataGridLayout: CreateInitialLayoutState"); - LayoutData newLayout = new LayoutData(); - newLayout.Inside = default; - newLayout.TopLeftHeader = default; - newLayout.ColumnHeaders = default; - newLayout.RowHeaders = default; - newLayout.Data = default; - newLayout.Caption = default; - newLayout.ParentRows = default; - newLayout.ResizeBoxRect = default; - newLayout.ColumnHeadersVisible = true; - newLayout.RowHeadersVisible = true; - newLayout.CaptionVisible = defaultCaptionVisible; - newLayout.ParentRowsVisible = defaultParentRowsVisible; - newLayout.ClientRectangle = ClientRectangle; - return newLayout; - } - - /// - /// The DataGrid caches an array of rectangular areas - /// which represent the area which scrolls left to right. - /// This method is invoked whenever the DataGrid needs - /// this scrollable region. - /// - private RECT[] CreateScrollableRegion(Rectangle scroll) - { - if (cachedScrollableRegion is not null) - { - return cachedScrollableRegion; - } - - bool alignToRight = isRightToLeft(); - - using (Region region = new Region(scroll)) - { - int nRows = numVisibleRows; - int cy = layout.Data.Y; - int cx = layout.Data.X; - DataGridRow[] localGridRows = DataGridRows; - for (int r = firstVisibleRow; r < nRows; r++) - { - int rowHeight = localGridRows[r].Height; - Rectangle rowExclude = localGridRows[r].GetNonScrollableArea(); - rowExclude.X += cx; - rowExclude.X = MirrorRectangle(rowExclude, layout.Data, alignToRight); - if (!rowExclude.IsEmpty) - { - region.Exclude(new Rectangle(rowExclude.X, - rowExclude.Y + cy, - rowExclude.Width, - rowExclude.Height)); - } - - cy += rowHeight; - } - } - - return cachedScrollableRegion; - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - if (vertScrollBar is not null) - vertScrollBar.Dispose(); - if (horizScrollBar is not null) - horizScrollBar.Dispose(); - - if (toBeDisposedEditingControl is not null) - { - toBeDisposedEditingControl.Dispose(); - toBeDisposedEditingControl = null; - } - - GridTableStylesCollection tables = TableStyles; - if (tables is not null) - { -#if DEBUG - Debug.Assert(myGridTable is null || myGridTable.IsDefault || tables.Contains(myGridTable), "how come that the currentTable is not in the list of tables?"); -#endif // DEBUG - for (int i = 0; i < tables.Count; i++) - tables[i].Dispose(); - } - } - - base.Dispose(disposing); - } - - /// - /// Draws an XOR region to give UI feedback for Column Resizing. - /// This looks just like the Splitter control's UI when resizing. - /// - private void DrawColSplitBar(MouseEventArgs e) - { - Rectangle r = CalcColResizeFeedbackRect(e); - DrawSplitBar(r); - } - - /// - /// Draws an XOR region to give UI feedback for Row Resizing. - /// This looks just like the Splitter control's UI when resizing. - /// - private void DrawRowSplitBar(MouseEventArgs e) - { - Rectangle r = CalcRowResizeFeedbackRect(e); - DrawSplitBar(r); - } - - /// - /// Draws an XOR region to give UI feedback for Column/Row Resizing. - /// This looks just like the Splitter control's UI when resizing. - /// - private void DrawSplitBar(Rectangle r) - { - IntPtr parentHandle = Handle; - } - - /// - /// Begin in-place editing of a cell. Any editing is commited - /// before the new edit takes place. - /// - /// This will always edit the currentCell - /// If you want to edit another cell than the current one, just reset CurrentCell - /// - private void Edit() - { - Edit(null); - } - - private void Edit(string displayText) - { - EnsureBound(); - - // whoever needs to call ResetSelection should not rely on - // Edit() to call it; - // - // ResetSelection(); - - EndEdit(); - - Debug.WriteLineIf(CompModSwitches.DataGridEditing.TraceVerbose, "DataGridEditing: Edit, currentRow = " + currentRow.ToString(CultureInfo.InvariantCulture) + - ", currentCol = " + currentCol.ToString(CultureInfo.InvariantCulture) + (displayText is not null ? ", displayText= " + displayText : "")); - - /* allow navigation even if the policy does not allow editing - if (!policy.AllowEdit) - return; - */ - - DataGridRow[] localGridRows = DataGridRows; - - // what do you want to edit when there are no rows? - if (DataGridRowsLength == 0) - return; - - localGridRows[currentRow].OnEdit(); - editRow = localGridRows[currentRow]; - - // if the list has no columns, then what good is an edit? - if (myGridTable.GridColumnStyles.Count == 0) - return; - - // what if the currentCol does not have a propDesc? - editColumn = myGridTable.GridColumnStyles[currentCol]; - if (editColumn.PropertyDescriptor is null) - return; - - Rectangle cellBounds = Rectangle.Empty; - if (currentRow < firstVisibleRow || currentRow > firstVisibleRow + numVisibleRows || - currentCol < firstVisibleCol || currentCol > firstVisibleCol + numVisibleCols - 1 || - (currentCol == firstVisibleCol && negOffset != 0)) - { - } - else - { - cellBounds = GetCellBounds(currentRow, currentCol); - } - - gridState[GRIDSTATE_isNavigating] = true; - gridState[GRIDSTATE_isEditing] = false; - - // once we call editColumn.Edit on a DataGridTextBoxColumn - // the edit control will become visible, and its bounds will get set. - // both actions cause Edit.Parent.OnLayout - // so we flag this change, cause we don't want to PerformLayout on the entire DataGrid - // everytime the edit column gets edited - gridState[GRIDSTATE_editControlChanging] = true; - - // reset the editControlChanging to false - gridState[GRIDSTATE_editControlChanging] = false; - } - - public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Ends any editing in progress by attempting to commit and then - /// aborting if not possible. - /// - private void EndEdit() - { - Debug.WriteLineIf(CompModSwitches.DataGridEditing.TraceVerbose, "DataGridEditing: EndEdit"); - - if (!gridState[GRIDSTATE_isEditing] && !gridState[GRIDSTATE_isNavigating]) - return; - - if (!CommitEdit()) - { - AbortEdit(); - } - } - - // PERF: we attempt to create a ListManager for the DataSource/DateMember combination - // we do this in order to check for a valid DataMember - // if the check succeeds, then it means that we actully put the listManager in the BindingContext's - // list of BindingManagers. this is fine, cause if the check succeds, then Set_ListManager - // will be called, and this will get the listManager from the bindingManagerBase hashTable kept in the BindingContext - // - // this will work if the dataMember does not contain any dots ('.') - // if the dataMember contains dots, then it will be more complicated: maybe part of the binding path - // is valid w/ the new dataSource - // but we can leave w/ this, cause in the designer the dataMember will be only a column name. and the DataSource/DataMember - // properties are for use w/ the designer. - // - private void EnforceValidDataMember(object value) - { - Debug.Assert(value is not null, "we should not have a null dataSource when we want to check for a valid dataMember"); - if (DataMember is null || DataMember.Length == 0) - return; - if (BindingContext is null) - return; - // - try - { - BindingManagerBase bm = BindingContext[value, dataMember]; - } - catch - { - dataMember = ""; - } - } - - internal protected virtual void ColumnStartedEditing(Rectangle bounds) - { - Debug.Assert(currentRow >= firstVisibleRow && currentRow <= firstVisibleRow + numVisibleRows, "how can one edit a row which is invisible?"); - DataGridRow[] localGridRows = DataGridRows; - - if (bounds.IsEmpty && editColumn is DataGridTextBoxColumn && currentRow != -1 && currentCol != -1) - { - // set the bounds on the control - // this will only work w/ our DataGridTexBox control - DataGridTextBoxColumn col = editColumn as DataGridTextBoxColumn; - Rectangle editBounds = GetCellBounds(currentRow, currentCol); - - gridState[GRIDSTATE_editControlChanging] = true; - try - { - col.TextBox.Bounds = editBounds; - } - finally - { - gridState[GRIDSTATE_editControlChanging] = false; - } - } - - if (gridState[GRIDSTATE_inAddNewRow]) - { - int currentRowCount = DataGridRowsLength; - DataGridRow[] newDataGridRows = new DataGridRow[currentRowCount + 1]; - for (int i = 0; i < currentRowCount; i++) - { - newDataGridRows[i] = localGridRows[i]; - } - - // put the AddNewRow - newDataGridRows[currentRowCount] = new DataGridAddNewRow(this, myGridTable, currentRowCount); - SetDataGridRows(newDataGridRows, currentRowCount + 1); - - Edit(); - // put this after the call to edit so that - // CommitEdit knows that the inAddNewRow is true; - gridState[GRIDSTATE_inAddNewRow] = false; - gridState[GRIDSTATE_isEditing] = true; - gridState[GRIDSTATE_isNavigating] = false; - return; - } - - gridState[GRIDSTATE_isEditing] = true; - gridState[GRIDSTATE_isNavigating] = false; - InvalidateRowHeader(currentRow); - - // tell the current row to lose the childFocuse - localGridRows[currentRow].LoseChildFocus(layout.RowHeaders, isRightToLeft()); - } - - internal protected virtual void ColumnStartedEditing(Control editingControl) - { - ColumnStartedEditing(editingControl.Bounds); - } - - public void Expand(int row) - { - throw new PlatformNotSupportedException(); - } - - protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop, bool isDefault) - { - return myGridTable is null ? null : myGridTable.CreateGridColumn(prop, isDefault); - } - - protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop) - { - return myGridTable is null ? null : myGridTable.CreateGridColumn(prop); - } - -#if PARENT_LINKS - - private ListManager ListManagerForChildColumn(ListManager childListManager, PropertyDescriptor prop) - { - /* - DataKey key; - RelationsCollection relCollection = dataColumn.Table.ParentRelations; - */ - - // this will give us the list of properties of the child - PropertyDescriptorCollection propCollection = childListManager.GetItemProperties(); - - int relCount = propCollection.Count; - for (int i=0;i - /// Given a x coordinate, returns the column it is over. - /// - private int GetColFromX(int x) - { - if (myGridTable is null) - return -1; - - Rectangle inside = layout.Data; - Debug.Assert(x >= inside.X && x < inside.Right, "x must be inside the horizontal bounds of layout.Data"); - - x = MirrorPoint(x, inside, isRightToLeft()); - - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - int columnCount = columns.Count; - - int cx = inside.X - negOffset; - int col = firstVisibleCol; - while (cx < inside.Width + inside.X && col < columnCount) - { - // if (columns[col].Visible && columns[col].PropertyDescriptor is not null) - if (columns[col].PropertyDescriptor is not null) - cx += columns[col].Width; - if (cx > x) - return col; - ++col; - } - - return -1; - } - - /// - /// Returns the coordinate of the left edge of the given column - /// Bi-Di: if the grid has the RightToLeft property set to RightToLeft.Yes, this will - /// return what appears as the right edge of the column - /// - internal int GetColBeg(int col) - { - Debug.Assert(myGridTable is not null, "GetColBeg can't be called when myGridTable is null."); - - int offset = layout.Data.X - negOffset; - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - - int lastCol = Math.Min(col, columns.Count); - for (int i = firstVisibleCol; i < lastCol; ++i) - { - // if (columns[i].Visible && columns[i].PropertyDescriptor is not null) - if (columns[i].PropertyDescriptor is not null) - offset += columns[i].Width; - } - - return MirrorPoint(offset, layout.Data, isRightToLeft()); - } - - /// - /// Returns the coordinate of the right edge of the given column - /// Bi-Di: if the grid has the RightToLeft property set to RightToLeft.Yes, this will - /// return what appears as the left edge of the column - /// - internal int GetColEnd(int col) - { - int colBeg = GetColBeg(col); - Debug.Assert(myGridTable.GridColumnStyles[col].PropertyDescriptor is not null, "why would we need the coordinate of a column that is not visible?"); - int width = myGridTable.GridColumnStyles[col].Width; - return isRightToLeft() ? colBeg - width : colBeg + width; - } - - private int GetColumnWidthSum() - { - int sum = 0; - if (myGridTable is not null && myGridTable.GridColumnStyles is not null) - { - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - - int columnsCount = columns.Count; - for (int i = 0; i < columnsCount; i++) - if (columns[i].PropertyDescriptor is not null) - sum += columns[i].Width; - } - - return sum; - } - - /// - /// Not all rows in the DataGrid are expandable, - /// this computes which ones are and returns an array - /// of references to them. - /// - private DataGridRelationshipRow[] GetExpandableRows() - { - int nExpandableRows = DataGridRowsLength; - DataGridRow[] localGridRows = DataGridRows; - if (policy.AllowAdd) - nExpandableRows = Math.Max(nExpandableRows - 1, 0); - DataGridRelationshipRow[] expandableRows = new DataGridRelationshipRow[nExpandableRows]; - for (int i = 0; i < nExpandableRows; i++) - expandableRows[i] = (DataGridRelationshipRow)localGridRows[i]; - return expandableRows; - } - - /// - /// Returns the row number underneath the given y coordinate. - /// - /// - private int GetRowFromY(int y) - { - Rectangle inside = layout.Data; - Debug.Assert(y >= inside.Y && y < inside.Bottom, "y must be inside the vertical bounds of the data"); - - int cy = inside.Y; - int row = firstVisibleRow; - int rowCount = DataGridRowsLength; - DataGridRow[] localGridRows = DataGridRows; - int bottom = inside.Bottom; - while (cy < bottom && row < rowCount) - { - cy += localGridRows[row].Height; - if (cy > y) - { - return row; - } - - ++row; - } - - return -1; - } - - internal Rectangle GetRowHeaderRect() - { - return layout.RowHeaders; - } - - internal Rectangle GetColumnHeadersRect() - { - return layout.ColumnHeaders; - } - - /// - /// Determines where on the control's ClientRectangle a given row is - /// painting to. - /// - private Rectangle GetRowRect(int rowNumber) - { - Rectangle inside = layout.Data; - int cy = inside.Y; - DataGridRow[] localGridRows = DataGridRows; - for (int row = firstVisibleRow; row <= rowNumber; ++row) - { - if (cy > inside.Bottom) - { - break; - } - - if (row == rowNumber) - { - Rectangle rowRect = new Rectangle(inside.X, - cy, - inside.Width, - localGridRows[row].Height); - if (layout.RowHeadersVisible) - { - rowRect.Width += layout.RowHeaders.Width; - rowRect.X -= isRightToLeft() ? 0 : layout.RowHeaders.Width; - } - - return rowRect; - } - - cy += localGridRows[row].Height; - } - - return Rectangle.Empty; - } - - /// - /// Returns the coordinate of the top edge of the given row - /// - private int GetRowTop(int row) - { - DataGridRow[] localGridRows = DataGridRows; - int offset = layout.Data.Y; - int lastRow = Math.Min(row, DataGridRowsLength); - for (int i = firstVisibleRow; i < lastRow; ++i) - { - offset += localGridRows[i].Height; - } - - for (int i = firstVisibleRow; i > lastRow; i--) - { - offset -= localGridRows[i].Height; - } - - return offset; - } - - /// - /// Returns the coordinate of the bottom edge of the given row - /// - private int GetRowBottom(int row) - { - DataGridRow[] localGridRows = DataGridRows; - - return GetRowTop(row) + localGridRows[row].Height; - } - - /// - /// This method is called on methods that need the grid - /// to be bound to a DataTable to work. - /// - private void EnsureBound() - { - if (!Bound) - { - throw new InvalidOperationException("SR.GetString(SR.DataGridUnbound)"); - } - } - - private void EnsureVisible(int row, int col) - { - if (row < firstVisibleRow - || row >= firstVisibleRow + numTotallyVisibleRows) - { - int dRows = ComputeDeltaRows(row); - ScrollDown(dRows); - } - - if (firstVisibleCol == 0 && numVisibleCols == 0 && lastTotallyVisibleCol == -1) - { - // no columns are displayed whatsoever - // some sanity checks - Debug.Assert(negOffset == 0, " no columns are displayed so the negative offset should be 0"); - return; - } - - int previousFirstVisibleCol = firstVisibleCol; - int previousNegOffset = negOffset; - int previousLastTotallyVisibleCol = lastTotallyVisibleCol; - - while (col < firstVisibleCol - || (col == firstVisibleCol && negOffset != 0) - || (lastTotallyVisibleCol == -1 && col > firstVisibleCol) - || (lastTotallyVisibleCol > -1 && col > lastTotallyVisibleCol)) - { - ScrollToColumn(col); - - if (previousFirstVisibleCol == firstVisibleCol && - previousNegOffset == negOffset && - previousLastTotallyVisibleCol == lastTotallyVisibleCol) - { - // nothing changed since the last iteration - // don't get into an infinite loop - break; - } - - previousFirstVisibleCol = firstVisibleCol; - previousNegOffset = negOffset; - previousLastTotallyVisibleCol = lastTotallyVisibleCol; - - // continue to scroll to the right until the scrollTo column is the totally last visible column or it is the first visible column - } - } - - public Rectangle GetCurrentCellBounds() - { - throw new PlatformNotSupportedException(); - } - - public Rectangle GetCellBounds(int row, int col) - { - throw new PlatformNotSupportedException(); - } - - public Rectangle GetCellBounds(DataGridCell dgc) - { - throw new PlatformNotSupportedException(); - } - - // UNDONE : ChrisAn, 10/27/00 - using internal hack to expose data for - // : Accessibility, is there a cleaner way to do this? - internal Rectangle GetRowBounds(DataGridRow row) - { - Rectangle rowBounds = default; - rowBounds.Y = GetRowTop(row.RowNumber); - rowBounds.X = layout.Data.X; - rowBounds.Height = row.Height; - rowBounds.Width = layout.Data.Width; - return rowBounds; - } - - public HitTestInfo HitTest(int x, int y) - { - throw new PlatformNotSupportedException(); - } - - public HitTestInfo HitTest(Point position) - { - throw new PlatformNotSupportedException(); - } - - /// - /// - /// Initializes the values for column widths in the table. - /// - private void InitializeColumnWidths() - { - if (myGridTable is null) - return; - - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - int numCols = columns.Count; - - // Resize the columns to a approximation of a best fit. - // We find the best fit width of NumRowsForAutoResize rows - // and use it for each column. - int preferredColumnWidth = this.myGridTable.IsDefault ? this.PreferredColumnWidth : this.myGridTable.PreferredColumnWidth; - // if we set the PreferredColumnWidth to something else than AutoColumnSize - // then use that value - // - for (int col = 0; col < numCols; col++) - { - // if the column width is not -1, then this column was initialized already - if (columns[col].width != -1) - continue; - - columns[col].width = preferredColumnWidth; - } - } - - /// - /// Invalidates the scrollable area of the DataGrid. - /// - internal void InvalidateInside() - { - Invalidate(layout.Inside); - } - - /// - /// Invalidates the caption area of the DataGrid. - /// - internal void InvalidateCaption() - { - if (layout.CaptionVisible) - Invalidate(layout.Caption); - } - - /// - /// Invalidates a rectangle normalized to the caption's - /// visual bounds. - /// - internal void InvalidateCaptionRect(Rectangle r) - { - if (layout.CaptionVisible) - { - Invalidate(r); - } - } - - /// - /// Invalidates the display region of a given DataGridColumn. - /// - internal void InvalidateColumn(int column) - { - GridColumnStylesCollection gridColumns = myGridTable.GridColumnStyles; - if (column < 0 || gridColumns is null || gridColumns.Count <= column) - return; - - Debug.Assert(gridColumns[column].PropertyDescriptor is not null, "how can we invalidate a column that is invisible?"); - // bail if the column is not visible. - if (column < firstVisibleCol || column > firstVisibleCol + numVisibleCols - 1) - return; - - Rectangle columnArea = default; - columnArea.Height = layout.Data.Height; - columnArea.Width = gridColumns[column].Width; - columnArea.Y = layout.Data.Y; - - int x = layout.Data.X - negOffset; - int gridColumnsCount = gridColumns.Count; - for (int i = firstVisibleCol; i < gridColumnsCount; ++i) - { - if (i == column) - break; - x += gridColumns[i].Width; - } - - columnArea.X = x; - columnArea.X = MirrorRectangle(columnArea, layout.Data, isRightToLeft()); - Invalidate(columnArea); - } - - /// - /// Invalidates the parent rows area of the DataGrid - /// - internal void InvalidateParentRows() - { - if (layout.ParentRowsVisible) - Invalidate(layout.ParentRows); - } - - /// - /// Invalidates a rectangle normalized to the parent - /// rows area's visual bounds. - /// - internal void InvalidateParentRowsRect(Rectangle r) - { - Rectangle parentRowsRect = layout.ParentRows; - Invalidate(r); - if (!parentRowsRect.IsEmpty) - { - // Invalidate(new Rectangle(parentRowsRect.X + r.X, parentRowsRect.Y + r.Y, - // r.Width, r.Height)); - } - } - - /// - /// Invalidate the painting region for the row specified. - /// - internal void InvalidateRow(int rowNumber) - { - Rectangle rowRect = GetRowRect(rowNumber); - if (!rowRect.IsEmpty) - { - Debug.WriteLineIf(CompModSwitches.DataGridPainting.TraceVerbose, "DataGridPainting: Invalidating row " + rowNumber.ToString(CultureInfo.InvariantCulture)); - Invalidate(rowRect); - } - } - - private void InvalidateRowHeader(int rowNumber) - { - if (rowNumber >= firstVisibleRow && rowNumber < firstVisibleRow + numVisibleRows) - { - if (!layout.RowHeadersVisible) - return; - - Rectangle invalid = default; - invalid.Y = GetRowTop(rowNumber); - invalid.X = layout.RowHeaders.X; - invalid.Width = layout.RowHeaders.Width; - invalid.Height = this.DataGridRows[rowNumber].Height; - Invalidate(invalid); - } - } - - // NOTE: - // because of Rtl, we assume that the only place that calls InvalidateRowRect is - // the DataGridRelationshipRow - internal void InvalidateRowRect(int rowNumber, Rectangle r) - { - Rectangle rowRect = GetRowRect(rowNumber); - if (!rowRect.IsEmpty) - { - Debug.WriteLineIf(CompModSwitches.DataGridPainting.TraceVerbose, "DataGridPainting: Invalidating a rect in row " + rowNumber.ToString(CultureInfo.InvariantCulture)); - Rectangle inner = new Rectangle(rowRect.X + r.X, rowRect.Y + r.Y, r.Width, r.Height); - if (vertScrollBar.Visible && isRightToLeft()) - inner.X -= vertScrollBar.Width; - Invalidate(inner); - } - } - - public bool IsExpanded(int rowNumber) - { - throw new PlatformNotSupportedException(); - } - - public bool IsSelected(int row) - { - throw new PlatformNotSupportedException(); - } - - internal static bool IsTransparentColor(Color color) - { - return color.A < 255; - } - - /// - /// Determines if Scrollbars should be visible, - /// updates their bounds and the bounds of all - /// other regions in the DataGrid's Layout. - /// - private void LayoutScrollBars() - { - // if we set the dataSource to null, then take away the scrollbars. - if (listManager is null || myGridTable is null) - { - horizScrollBar.Visible = false; - vertScrollBar.Visible = false; - return; - } - - // Scrollbars are a tricky issue. - // We need to see if we can cram our columns and rows - // in without scrollbars and if they don't fit, we make - // scrollbars visible and then fixup our regions for the - // data and headers. - bool needHorizScrollbar = false; - bool needVertScrollbar = false; - bool recountRows = false; - bool alignToRight = isRightToLeft(); - - int nGridCols = myGridTable.GridColumnStyles.Count; - - // if we call LayoutScrollBars before CreateDataGridRows - // then the columns will have their default width ( 100 ) - // CreateDataGridRows will possibly change the columns' width - // and anyway, ComputeVisibleRows will call the DataGridRows accessor - DataGridRow[] gridRows = this.DataGridRows; - - // at this stage, the data grid columns may have their width set to -1 ( ie, their width is uninitialized ) - // make sure that the totalWidth is at least 0 - int totalWidth = Math.Max(0, GetColumnWidthSum()); - - if (totalWidth > layout.Data.Width && !needHorizScrollbar) - { - int horizHeight = horizScrollBar.Height; - layout.Data.Height -= horizHeight; - if (layout.RowHeadersVisible) - layout.RowHeaders.Height -= horizHeight; - needHorizScrollbar = true; - } - - int oldFirstVisibleRow = firstVisibleRow; - - ComputeVisibleRows(); - if (numTotallyVisibleRows != DataGridRowsLength && !needVertScrollbar) - { - int vertWidth = vertScrollBar.Width; - layout.Data.Width -= vertWidth; - if (layout.ColumnHeadersVisible) - { - if (alignToRight) - layout.ColumnHeaders.X += vertWidth; - - layout.ColumnHeaders.Width -= vertWidth; - } - - needVertScrollbar = true; - } - - firstVisibleCol = ComputeFirstVisibleColumn(); - // we compute the number of visible columns only after we set up the vertical scroll bar. - ComputeVisibleColumns(); - - if (needVertScrollbar && totalWidth > layout.Data.Width && !needHorizScrollbar) - { - firstVisibleRow = oldFirstVisibleRow; - int horizHeight = horizScrollBar.Height; - layout.Data.Height -= horizHeight; - if (layout.RowHeadersVisible) - layout.RowHeaders.Height -= horizHeight; - needHorizScrollbar = true; - recountRows = true; - } - - if (recountRows) - { - ComputeVisibleRows(); - if (numTotallyVisibleRows != DataGridRowsLength && !needVertScrollbar) - { - int vertWidth = vertScrollBar.Width; - layout.Data.Width -= vertWidth; - if (layout.ColumnHeadersVisible) - { - if (alignToRight) - layout.ColumnHeaders.X += vertWidth; - - layout.ColumnHeaders.Width -= vertWidth; - } - - needVertScrollbar = true; - } - } - - layout.ResizeBoxRect = default; - if (needVertScrollbar && needHorizScrollbar) - { - Rectangle data = layout.Data; - layout.ResizeBoxRect = new Rectangle(alignToRight ? data.X : data.Right, - data.Bottom, - vertScrollBar.Width, - horizScrollBar.Height); - } - - if (needHorizScrollbar && nGridCols > 0) - { - // Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: foo"); - - int widthNotVisible = totalWidth - layout.Data.Width; - - horizScrollBar.Minimum = 0; - horizScrollBar.Maximum = totalWidth; - horizScrollBar.SmallChange = 1; - horizScrollBar.LargeChange = Math.Max(totalWidth - widthNotVisible, 0); - horizScrollBar.Enabled = Enabled; - horizScrollBar.RightToLeft = RightToLeft; - horizScrollBar.Bounds = new Rectangle(alignToRight ? layout.Inside.X + layout.ResizeBoxRect.Width : layout.Inside.X, - layout.Data.Bottom, - layout.Inside.Width - layout.ResizeBoxRect.Width, - horizScrollBar.Height); - horizScrollBar.Visible = true; - } - else - { - HorizontalOffset = 0; - horizScrollBar.Visible = false; - } - - if (needVertScrollbar) - { - int vertScrollBarTop = layout.Data.Y; - if (layout.ColumnHeadersVisible) - vertScrollBarTop = layout.ColumnHeaders.Y; - // if numTotallyVisibleRows == 0 ( the height of the row is bigger than the height of - // the grid ) then scroll in increments of 1. - vertScrollBar.LargeChange = numTotallyVisibleRows != 0 ? numTotallyVisibleRows : 1; - vertScrollBar.Bounds = new Rectangle(alignToRight ? layout.Data.X : layout.Data.Right, - vertScrollBarTop, - vertScrollBar.Width, - layout.Data.Height + layout.ColumnHeaders.Height); - vertScrollBar.Enabled = Enabled; - vertScrollBar.Visible = true; - if (alignToRight) - layout.Data.X += vertScrollBar.Width; - } - else - { - vertScrollBar.Visible = false; - } - } - - public void NavigateBack() - { - throw new PlatformNotSupportedException(); - } - - public void NavigateTo(int rowNumber, string relationName) - { - throw new PlatformNotSupportedException(); - } - - internal void NavigateTo(string relationName, DataGridRow source, bool fromRow) - { - // do not navigate if AllowNavigation is set to false - if (!AllowNavigation) - return; - // Commit the edit if possible - if (!CommitEdit()) - return; - - DataGridState childState; - try - { - childState = CreateChildState(relationName, source); - } - catch - { - // if we get an error when creating the RelatedCurrencyManager - // then navigateBack and ignore the exception. - NavigateBack(); - return; - } - - // call EndCurrentEdit before navigating. - // if we get an exception, we do not navigate. - try - { - listManager.EndCurrentEdit(); - } - catch - { - return; - } - - // Preserve our current state - // we need to do this after the EndCurrentEdit, otherwise the - // DataGridState will get the listChanged event from the EndCurrentEdit - DataGridState dgs = new DataGridState(this); - dgs.LinkingRow = source; - - // we need to update the Position in the ListManager - // ( the RelatedListManager uses only the position in the parentManager - // to create the childRows - // before the code was calling CurrentCell = this and such - // we should only call EndCurrentEdit ( which the code was doing anyway ) - // and then set the position in the listManager to the new row. - if (source.RowNumber != CurrentRow) - listManager.Position = source.RowNumber; - - // We save our state if the parent rows stack is empty. - if (parentRows.GetTopParent() is null) - { - originalState = dgs; - } - - parentRows.AddParent(dgs); - - NavigateTo(childState); - - if (fromRow) - { - // OnLinkClick(EventArgs.Empty); - } - } - - private void NavigateTo(DataGridState childState) - { - // we are navigating... better stop editing. - EndEdit(); - - // also, we are no longer in editOrNavigate mode either - gridState[GRIDSTATE_isNavigating] = false; - - // reset hot tracking - ResetMouseState(); - - // Retrieve the child state - childState.PullState(this, true); // true for creating columns when we navigate to child rows - - if (listManager.Position != currentRow) - { - currentRow = listManager.Position == -1 ? 0 : listManager.Position; - } - - if (parentRows.GetTopParent() is not null) - { - caption.BackButtonActive = AllowNavigation; - caption.BackButtonVisible = caption.BackButtonActive; - caption.DownButtonActive = true; - } - - HorizontalOffset = 0; - PerformLayout(); - Invalidate(); - } - - /// - /// Given a coordinate in the control this method returns - /// the equivalent point for a row. - /// - private Point NormalizeToRow(int x, int y, int row) - { - Debug.Assert(row >= firstVisibleRow && row < firstVisibleRow + numVisibleRows, - "Row " + row.ToString(CultureInfo.InvariantCulture) + "is not visible! firstVisibleRow = " + - firstVisibleRow.ToString(CultureInfo.InvariantCulture) + ", numVisibleRows = " + - numVisibleRows.ToString(CultureInfo.InvariantCulture)); - Point origin = new Point(0, layout.Data.Y); - - DataGridRow[] localGridRows = DataGridRows; - for (int r = firstVisibleRow; r < row; ++r) - { - origin.Y += localGridRows[r].Height; - } - - // when hittesting for the PlusMinus, the code in the DataGridRelationshipRow - // will use real X coordinate ( the one from layout.RowHeaders ) to paint the glyph - return new Point(x, y - origin.Y); - } - - internal void OnColumnCollectionChanged(object sender, CollectionChangeEventArgs e) - { - DataGridTableStyle table = (DataGridTableStyle)sender; - if (table.Equals(myGridTable)) - { - // if we changed the column collection, then we need to set the property - // descriptors in the column collection. - // unless the user set the propertyDescriptor in the columnCollection - if (!myGridTable.IsDefault) - { - // if the element in the collectionChangeEventArgs is not null - // and the action is refresh, then it means that the user - // set the propDesc. we do not want to override this. - if (e.Action != CollectionChangeAction.Refresh || e.Element is null) - PairTableStylesAndGridColumns(listManager, myGridTable, false); - } - - Invalidate(); - PerformLayout(); - } - } - - /// - /// Paints column headers. - /// - private void PaintColumnHeaders(Graphics g) - { - bool alignToLeft = isRightToLeft(); - Rectangle boundingRect = layout.ColumnHeaders; - if (!alignToLeft) - boundingRect.X -= negOffset; - boundingRect.Width += negOffset; - - int columnHeaderWidth = PaintColumnHeaderText(g, boundingRect); - - if (alignToLeft) - boundingRect.X = boundingRect.Right - columnHeaderWidth; - - boundingRect.Width = columnHeaderWidth; - if (!FlatMode) - { - ControlPaint.DrawBorder3D(g, boundingRect, Border3DStyle.RaisedInner); - boundingRect.Inflate(-1, -1); - // g.SetPen(OldSystemPens.Control); - // g.OldBrush = (OldSystemBrushes.Hollow); - boundingRect.Width--; - boundingRect.Height--; - g.DrawRectangle(SystemPens.Control, boundingRect); - } - } - - private int PaintColumnHeaderText(Graphics g, Rectangle boundingRect) - { - int cx = 0; - Rectangle textBounds = boundingRect; - GridColumnStylesCollection gridColumns = myGridTable.GridColumnStyles; - bool alignRight = isRightToLeft(); - - int nGridCols = gridColumns.Count; - // for sorting - PropertyDescriptor sortProperty = null; - sortProperty = ListManager.GetSortProperty(); - - // Now paint the column header text! - for (int col = firstVisibleCol; col < nGridCols; ++col) - { - if (gridColumns[col].PropertyDescriptor is null) - continue; - - if (cx > boundingRect.Width) - break; - - bool columnSorted = sortProperty is not null && sortProperty.Equals(gridColumns[col].PropertyDescriptor); - - if (alignRight) - { - textBounds.Width = gridColumns[col].Width - - (columnSorted ? textBounds.Height : 0); - textBounds.X = boundingRect.Right - cx - textBounds.Width; - } - else - { - textBounds.X = boundingRect.X + cx; - textBounds.Width = gridColumns[col].Width - - (columnSorted ? textBounds.Height : 0); - } - - // at the moment we paint some pixels twice. - // we should not call FilLRectangle, once the real GDI+ is there, we will have no need to do that - - // if the user set the HeaderBackBrush property on the - // dataGrid, then use that property - Brush headerBrush; - if (myGridTable.IsDefault) - headerBrush = HeaderBackBrush; - else - headerBrush = myGridTable.HeaderBackBrush; - - g.FillRectangle(headerBrush, textBounds); - // granted, the code would be a lot cleaner if we were using a "new Rectangle" - // but like this will be faster - if (alignRight) - { - textBounds.X -= 2; - textBounds.Y += 2; - } - else - { - textBounds.X += 2; - textBounds.Y += 2; - } - - StringFormat format = new StringFormat(); - - // the columnHeaderText alignment should be the same as - // the alignment in the column - // - HorizontalAlignment colAlignment = gridColumns[col].Alignment; - format.Alignment = colAlignment == HorizontalAlignment.Right ? StringAlignment.Far : - colAlignment == HorizontalAlignment.Center ? StringAlignment.Center : - StringAlignment.Near; - - // part 1, section 1: the column headers should not wrap - format.FormatFlags |= StringFormatFlags.NoWrap; - - if (alignRight) - { - format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; - format.Alignment = StringAlignment.Near; - } - - g.DrawString(gridColumns[col].HeaderText, - myGridTable.IsDefault ? HeaderFont : myGridTable.HeaderFont, - myGridTable.IsDefault ? HeaderForeBrush : myGridTable.HeaderForeBrush, - textBounds, - format); - format.Dispose(); - - if (alignRight) - { - textBounds.X += 2; - textBounds.Y -= 2; - } - else - { - textBounds.X -= 2; - textBounds.Y -= 2; - } - - if (columnSorted) - { - // CONSIDER: This triangle painting is pretty unclean - // perhaps this should be a bitmap? - Rectangle triBounds = new Rectangle(alignRight ? textBounds.X - textBounds.Height : textBounds.Right, - textBounds.Y, - textBounds.Height, - textBounds.Height); - - g.FillRectangle(headerBrush, triBounds); - int deflateValue = Math.Max(0, (textBounds.Height - 5) / 2); - triBounds.Inflate(-deflateValue, -deflateValue); - - Pen pen1 = new Pen(BackgroundBrush); - Pen pen2 = new Pen(myGridTable.BackBrush); - pen1.Dispose(); - pen2.Dispose(); - } - - int paintedWidth = textBounds.Width + (columnSorted ? textBounds.Height : 0); - - if (!FlatMode) - { - if (alignRight && columnSorted) - textBounds.X -= textBounds.Height; - textBounds.Width = paintedWidth; - - ControlPaint.DrawBorder3D(g, textBounds, Border3DStyle.RaisedInner); - } - - cx += paintedWidth; - } - - // paint the possible exposed portion to the right ( or left, as the case may be) - if (cx < boundingRect.Width) - { - textBounds = boundingRect; - - if (!alignRight) - textBounds.X += cx; - - textBounds.Width -= cx; - g.FillRectangle(backgroundBrush, textBounds); - } - - return cx; - } - - /// - /// Paints a border around the bouding rectangle given - /// - private void PaintBorder(Graphics g, Rectangle bounds) - { - if (BorderStyle == BorderStyle.None) - return; - if (BorderStyle == BorderStyle.Fixed3D) - { - Border3DStyle style = Border3DStyle.Sunken; - ControlPaint.DrawBorder3D(g, bounds, style); - } - else if (BorderStyle == BorderStyle.FixedSingle) - { - Brush br; - - if (myGridTable.IsDefault) - br = HeaderForeBrush; - else - br = myGridTable.HeaderForeBrush; - g.FillRectangle(br, bounds.X, bounds.Y, bounds.Width + 2, 2); - g.FillRectangle(br, bounds.Right - 2, bounds.Y, 2, bounds.Height + 2); - g.FillRectangle(br, bounds.X, bounds.Bottom - 2, bounds.Width + 2, 2); - g.FillRectangle(br, bounds.X, bounds.Y, 2, bounds.Height + 2); - } - else - { - Pen pen = SystemPens.WindowFrame; - bounds.Width--; - bounds.Height--; - g.DrawRectangle(pen, bounds); - } - } - - /// - /// Paints the grid in the bounding rectangle given. - /// This includes the column headers and each visible row. - /// - private void PaintGrid(Graphics g, Rectangle gridBounds) - { - Debug.WriteLineIf(CompModSwitches.DataGridPainting.TraceVerbose, "DataGridPainting: PaintGrid on " + gridBounds.ToString()); - - Rectangle rc = gridBounds; - - if (listManager is not null) - { - if (layout.ColumnHeadersVisible) - { - Region r = g.Clip; - g.SetClip(layout.ColumnHeaders); - PaintColumnHeaders(g); - g.Clip = r; - r.Dispose(); - int columnHeaderHeight = layout.ColumnHeaders.Height; - rc.Y += columnHeaderHeight; - rc.Height -= columnHeaderHeight; - } - - if (layout.TopLeftHeader.Width > 0) - { - if (myGridTable.IsDefault) - g.FillRectangle(HeaderBackBrush, layout.TopLeftHeader); - else - g.FillRectangle(myGridTable.HeaderBackBrush, layout.TopLeftHeader); - - if (!FlatMode) - { - ControlPaint.DrawBorder3D(g, layout.TopLeftHeader, Border3DStyle.RaisedInner); - } - } - - PaintRows(g, ref rc); - } - - // paint the possible exposed portion below - if (rc.Height > 0) - { - g.FillRectangle(backgroundBrush, rc); - } - } - - private void DeleteDataGridRows(int deletedRows) - { - if (deletedRows == 0) - return; - - int currentRowCount = DataGridRowsLength; - int newDataGridRowsLength = currentRowCount - deletedRows + (gridState[GRIDSTATE_inAddNewRow] ? 1 : 0); - DataGridRow[] newDataGridRows = new DataGridRow[newDataGridRowsLength]; - DataGridRow[] gridRows = DataGridRows; - - // the number of selected entries so far in the array - int selectedEntries = 0; - - for (int i = 0; i < currentRowCount; i++) - { - if (gridRows[i].Selected) - { - selectedEntries++; - } - else - { - newDataGridRows[i - selectedEntries] = gridRows[i]; - newDataGridRows[i - selectedEntries].number = i - selectedEntries; - } - } - - if (gridState[GRIDSTATE_inAddNewRow]) - { - newDataGridRows[currentRowCount - selectedEntries] = new DataGridAddNewRow(this, myGridTable, currentRowCount - selectedEntries); - gridState[GRIDSTATE_inAddNewRow] = false; - } - - Debug.Assert(selectedEntries == deletedRows, "all the rows that would have been deleted should have been selected: selectedGridEntries " + selectedEntries.ToString(CultureInfo.InvariantCulture) + " deletedRows " + deletedRows.ToString(CultureInfo.InvariantCulture)); - - SetDataGridRows(newDataGridRows, newDataGridRowsLength); - } - - /// - /// Paints the visible rows on the grid. - /// - private void PaintRows(Graphics g, ref Rectangle boundingRect) - { - int cy = 0; - bool alignRight = isRightToLeft(); - Rectangle rowBounds = boundingRect; - Rectangle dataBounds = Rectangle.Empty; - bool paintRowHeaders = layout.RowHeadersVisible; - Rectangle headerBounds = Rectangle.Empty; - - int numRows = DataGridRowsLength; - DataGridRow[] localGridRows = DataGridRows; - int numCols = myGridTable.GridColumnStyles.Count - firstVisibleCol; - - for (int row = firstVisibleRow; row < numRows; row++) - { - if (cy > boundingRect.Height) - break; - - rowBounds = boundingRect; - rowBounds.Height = localGridRows[row].Height; - rowBounds.Y = boundingRect.Y + cy; - - // will add some errors -#if false - if (forDebug == 0 || forDebug == 1) - { - object dRowView = listManager[row]; - DataRow dRow= ((DataRowView) dRowView).Row; - // dRow.RowError = "Error " + forDebug.ToString(); - dRow.SetColumnError(forDebug, "another error " + forDebug.ToString()); - - /* - if (localGridRows[row].DataRow is not null) - { - localGridRows[row].DataRow.RowError = "error " + forDebug.ToString(); - localGridRows[row].DataRow.SetColumnError(forDebug, "another error " + forDebug.ToString()); - } - */ - forDebug ++; - } -#endif // false - if (paintRowHeaders) - { - headerBounds = rowBounds; - headerBounds.Width = layout.RowHeaders.Width; - - if (alignRight) - { - headerBounds.X = rowBounds.Right - headerBounds.Width; - } - - if (g.IsVisible(headerBounds)) - { - localGridRows[row].PaintHeader(g, headerBounds, alignRight, gridState[GRIDSTATE_isEditing]); - g.ExcludeClip(headerBounds); - } - - if (!alignRight) - rowBounds.X += headerBounds.Width; - rowBounds.Width -= headerBounds.Width; - } - - if (g.IsVisible(rowBounds)) - { - dataBounds = rowBounds; - if (!alignRight) - dataBounds.X -= negOffset; - dataBounds.Width += negOffset; - - localGridRows[row].Paint(g, dataBounds, rowBounds, firstVisibleCol, numCols, alignRight); - } - - cy += rowBounds.Height; - } - - boundingRect.Y += cy; - boundingRect.Height -= cy; - } - - protected override bool ProcessDialogKey(Keys keyData) - { - Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: ProcessDialogKey " + TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(keyData)); - DataGridRow[] localGridRows = DataGridRows; - if (listManager is not null && DataGridRowsLength > 0 && localGridRows[currentRow].OnKeyPress(keyData)) - { - Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: Current Row ate the keystroke"); - return true; - } - - switch (keyData & Keys.KeyCode) - { - case Keys.Tab: - case Keys.Up: - case Keys.Down: - case Keys.Left: - case Keys.Right: - case Keys.Next: - case Keys.Prior: - case Keys.Enter: - case Keys.Escape: - case Keys.Oemplus: - case Keys.Add: - case Keys.OemMinus: - case Keys.Subtract: - case Keys.Space: - case Keys.Delete: - case Keys.A: - KeyEventArgs ke = new KeyEventArgs(keyData); - if (ProcessGridKey(ke)) - return true; - break; - - case Keys.C: - if ((keyData & Keys.Control) != 0 && (keyData & Keys.Alt) == 0) - { - // the user pressed Ctrl-C - if (!Bound) - break; - - // need to distinguish between selecting a set of rows, and - // selecting just one column. - if (numSelectedRows == 0) - { - // copy the data from one column only - if (currentRow < ListManager.Count) - { - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - if (currentCol >= 0 && currentCol < columns.Count) - { - DataGridColumnStyle column = columns[currentCol]; - string text = column.GetDisplayText(column.GetColumnValueAtRow(ListManager, currentRow)); - - // copy the data to the clipboard - Clipboard.SetDataObject(text); - return true; - } - } - } - else - { - // the user selected a set of rows to copy the data from - - int numRowsOutputted = 0; // the number of rows written to "text" - string text = ""; - - for (int i = 0; i < DataGridRowsLength; ++i) - { - if (localGridRows[i].Selected) - { - GridColumnStylesCollection columns = myGridTable.GridColumnStyles; - int numCols = columns.Count; - for (int j = 0; j < numCols; j++) - { - DataGridColumnStyle column = columns[j]; - text += column.GetDisplayText(column.GetColumnValueAtRow(ListManager, i)); - - // do not put the delimiter at the end of the last column - if (j < numCols - 1) - { - text += GetOutputTextDelimiter(); - } - } - - // put the hard enter "\r\n" only if this is not the last selected row - if (numRowsOutputted < numSelectedRows - 1) - { - text += "\r\n"; - } - - numRowsOutputted++; - } - } - - // copy the data to the clipboard - Clipboard.SetDataObject(text); - return true; - } - } - - break; - } - - return base.ProcessDialogKey(keyData); - } - - private void DeleteRows(DataGridRow[] localGridRows) - { - int rowsDeleted = 0; - - int currentRowsCount = listManager is null ? 0 : listManager.Count; - - if (Visible) - BeginUpdateInternal(); - try - { - if (ListManager is not null) - { - for (int i = 0; i < DataGridRowsLength; i++) - { - if (localGridRows[i].Selected) - { - if (localGridRows[i] is DataGridAddNewRow) - { - Debug.Assert(i == DataGridRowsLength - 1, "the location of addNewRow is " + i.ToString(CultureInfo.InvariantCulture) + " and there are " + DataGridRowsLength.ToString(CultureInfo.InvariantCulture) + " rows "); - localGridRows[i].Selected = false; - } - else - { - ListManager.RemoveAt(i - rowsDeleted); - rowsDeleted++; - } - } - } - } - } - catch - { - // if we got an exception from the back end - // when deleting the rows then we should reset - // our rows and re-throw the exception - RecreateDataGridRows(); - gridState[GRIDSTATE_inDeleteRow] = false; - if (Visible) - EndUpdateInternal(); - throw; - } - - // keep the copy of the old rows in place - // it may be the case that deleting one row could cause multiple rows to be deleted in the same list - if (listManager is not null && currentRowsCount == listManager.Count + rowsDeleted) - { - DeleteDataGridRows(rowsDeleted); - } - else - { - RecreateDataGridRows(); - } - - gridState[GRIDSTATE_inDeleteRow] = false; - if (Visible) - EndUpdateInternal(); - - if (listManager is not null && currentRowsCount != listManager.Count + rowsDeleted) - { - Invalidate(); - } - } - - // convention: - // if we return -1 it means that the user was going left and there were no visible columns to the left of the current one - // if we return cols.Count + 1 it means that the user was going right and there were no visible columns to the right of the currrent - private static int MoveLeftRight(GridColumnStylesCollection cols, int startCol, bool goRight) - { - int i; - if (goRight) - { - for (i = startCol + 1; i < cols.Count; i++) - { - // if (cols[i].Visible && cols[i].PropertyDescriptor is not null) - if (cols[i].PropertyDescriptor is not null) - return i; - } - - return i; - } - else - { - for (i = startCol - 1; i >= 0; i--) - { - // if (cols[i].Visible && cols[i].PropertyDescriptor is not null) - if (cols[i].PropertyDescriptor is not null) - return i; - } - - return i; - } - } - - protected bool ProcessGridKey(KeyEventArgs ke) - { - Debug.WriteLineIf(CompModSwitches.DataGridKeys.TraceVerbose, "DataGridKeys: ProcessGridKey " + TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(ke.KeyCode)); - if (listManager is null || myGridTable is null) - return false; - - DataGridRow[] localGridRows = DataGridRows; - KeyEventArgs biDiKe = ke; - // check for Bi-Di - if (isRightToLeft()) - { - switch (ke.KeyCode) - { - case Keys.Left: - biDiKe = new KeyEventArgs((Keys.Right | ke.Modifiers)); - break; - case Keys.Right: - biDiKe = new KeyEventArgs((Keys.Left | ke.Modifiers)); - break; - default: - break; - } - } - - GridColumnStylesCollection cols = myGridTable.GridColumnStyles; - int firstColumnMarkedVisible = 0; - int lastColumnMarkedVisible = cols.Count; - for (int i = 0; i < cols.Count; i++) - { - if (cols[i].PropertyDescriptor is not null) - { - firstColumnMarkedVisible = i; - break; - } - } - - for (int i = cols.Count - 1; i >= 0; i--) - { - if (cols[i].PropertyDescriptor is not null) - { - lastColumnMarkedVisible = i; - break; - } - } - - switch (biDiKe.KeyCode) - { - case Keys.Tab: - return ProcessTabKey(biDiKe.KeyData); - case Keys.Up: - gridState[GRIDSTATE_childLinkFocused] = false; - if (dataGridRowsLength == 0) - { - return true; - } - - if (biDiKe.Control && !biDiKe.Alt) - { - if (biDiKe.Shift) - { - DataGridRow[] gridRows = DataGridRows; - - int savedCurrentRow = currentRow; - CurrentRow = 0; - - ResetSelection(); - - for (int i = 0; i <= savedCurrentRow; i++) - gridRows[i].Selected = true; - numSelectedRows = savedCurrentRow + 1; - // hide the edit box - EndEdit(); - return true; - } - - // do not make the parentRowsVisible = false; - // ParentRowsVisible = false; - ResetSelection(); - CurrentRow = 0; - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - return true; - } - else if (biDiKe.Shift) - { - DataGridRow[] gridRows = DataGridRows; - // keep a continous selected region - if (gridRows[currentRow].Selected) - { - if (currentRow >= 1) - { - if (gridRows[currentRow - 1].Selected) - { - if (currentRow >= DataGridRowsLength - 1 || !gridRows[currentRow + 1].Selected) - { - numSelectedRows--; - gridRows[currentRow].Selected = false; - } - } - else - { - numSelectedRows += gridRows[currentRow - 1].Selected ? 0 : 1; - gridRows[currentRow - 1].Selected = true; - } - - CurrentRow--; - } - } - else - { - numSelectedRows++; - gridRows[currentRow].Selected = true; - if (currentRow >= 1) - { - numSelectedRows += gridRows[currentRow - 1].Selected ? 0 : 1; - gridRows[currentRow - 1].Selected = true; - CurrentRow--; - } - } - - // hide the edit box: - EndEdit(); - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - return true; - } - else if (biDiKe.Alt) - { - // will need to collapse all child table links - // -1 is for all rows, and false is for collapsing the rows - SetRowExpansionState(-1, false); - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - return true; - } - - ResetSelection(); - CurrentRow = CurrentRow - 1; - Edit(); - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - break; - case Keys.Down: - gridState[GRIDSTATE_childLinkFocused] = false; - if (dataGridRowsLength == 0) - { - return true; - } - - if (biDiKe.Control && !biDiKe.Alt) - { - if (biDiKe.Shift) - { - int savedCurrentRow = currentRow; - CurrentRow = Math.Max(0, DataGridRowsLength - (policy.AllowAdd ? 2 : 1)); - DataGridRow[] gridRows = DataGridRows; - - ResetSelection(); - - for (int i = savedCurrentRow; i <= currentRow; i++) - gridRows[i].Selected = true; - - numSelectedRows = currentRow - savedCurrentRow + 1; - // hide the edit box - EndEdit(); - return true; - } - - // do not make the parentRowsVisible = true; - // ParentRowsVisible = true; - ResetSelection(); - CurrentRow = Math.Max(0, DataGridRowsLength - (policy.AllowAdd ? 2 : 1)); - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - return true; - } - else if (biDiKe.Shift) - { - DataGridRow[] gridRows = DataGridRows; - - // keep a continous selected region - if (gridRows[currentRow].Selected) - { - // -1 because we index from 0 - if (currentRow < DataGridRowsLength - (policy.AllowAdd ? 1 : 0) - 1) - { - if (gridRows[currentRow + 1].Selected) - { - if (currentRow == 0 || !gridRows[currentRow - 1].Selected) - { - numSelectedRows--; - gridRows[currentRow].Selected = false; - } - } - else - { - numSelectedRows += gridRows[currentRow + 1].Selected ? 0 : 1; - gridRows[currentRow + 1].Selected = true; - } - - CurrentRow++; - } - } - else - { - numSelectedRows++; - gridRows[currentRow].Selected = true; - // -1 because we index from 0, and -1 so this is not the last row - // so it adds to -2 - if (currentRow < DataGridRowsLength - (policy.AllowAdd ? 1 : 0) - 1) - { - CurrentRow++; - numSelectedRows += gridRows[currentRow].Selected ? 0 : 1; - gridRows[currentRow].Selected = true; - } - } - - // hide the edit box: - // - EndEdit(); - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - return true; - } - else if (biDiKe.Alt) - { - // will need to expande all child table links - // -1 is for all rows, and true is for expanding the rows - SetRowExpansionState(-1, true); - return true; - } - - ResetSelection(); - Edit(); - CurrentRow = CurrentRow + 1; - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - break; - case Keys.OemMinus: - case Keys.Subtract: - gridState[GRIDSTATE_childLinkFocused] = false; - if (biDiKe.Control && !biDiKe.Alt) - { - SetRowExpansionState(-1, false); - return true; - } - - return false; - case Keys.Oemplus: - case Keys.Add: - gridState[GRIDSTATE_childLinkFocused] = false; - if (biDiKe.Control) - { - SetRowExpansionState(-1, true); - // hide the edit box - EndEdit(); - return true; - } - - return false; - case Keys.Space: - gridState[GRIDSTATE_childLinkFocused] = false; - if (dataGridRowsLength == 0) - { - return true; - } - - if (biDiKe.Shift) - { - ResetSelection(); - EndEdit(); - DataGridRow[] gridRows = DataGridRows; - gridRows[currentRow].Selected = true; - numSelectedRows = 1; - - return true; - } - - return false; - case Keys.Next: - gridState[GRIDSTATE_childLinkFocused] = false; - if (dataGridRowsLength == 0) - { - return true; - } - - if (biDiKe.Shift) - { - int savedCurrentRow = currentRow; - CurrentRow = Math.Min(DataGridRowsLength - (policy.AllowAdd ? 2 : 1), currentRow + numTotallyVisibleRows); - - DataGridRow[] gridRows = DataGridRows; - for (int i = savedCurrentRow; i <= currentRow; i++) - { - if (!gridRows[i].Selected) - { - gridRows[i].Selected = true; - numSelectedRows++; - } - } - - EndEdit(); - } - else if (biDiKe.Control && !biDiKe.Alt) - { - // map ctrl-pageDown to show the parentRows - ParentRowsVisible = true; - } - else - { - ResetSelection(); - CurrentRow = Math.Min(DataGridRowsLength - (policy.AllowAdd ? 2 : 1), - CurrentRow + numTotallyVisibleRows); - } - - break; - case Keys.Prior: - if (dataGridRowsLength == 0) - { - return true; - } - - gridState[GRIDSTATE_childLinkFocused] = false; - if (biDiKe.Shift) - { - int savedCurrentRow = currentRow; - CurrentRow = Math.Max(0, CurrentRow - numTotallyVisibleRows); - - DataGridRow[] gridRows = DataGridRows; - for (int i = savedCurrentRow; i >= currentRow; i--) - { - if (!gridRows[i].Selected) - { - gridRows[i].Selected = true; - numSelectedRows++; - } - } - - EndEdit(); - } - else if (biDiKe.Control && !biDiKe.Alt) - { - // map ctrl-pageUp to hide the parentRows - ParentRowsVisible = false; - } - else - { - ResetSelection(); - CurrentRow = Math.Max(0, - CurrentRow - numTotallyVisibleRows); - } - - break; - case Keys.Left: - gridState[GRIDSTATE_childLinkFocused] = false; - ResetSelection(); - if ((biDiKe.Modifiers & Keys.Modifiers) == Keys.Alt) - { - if (Caption.BackButtonVisible) - NavigateBack(); - return true; - } - - if ((biDiKe.Modifiers & Keys.Control) == Keys.Control) - { - // we should navigate to the first visible column - CurrentColumn = firstColumnMarkedVisible; - break; - } - - if (currentCol == firstColumnMarkedVisible && currentRow != 0) - { - CurrentRow = CurrentRow - 1; - int newCol = MoveLeftRight(myGridTable.GridColumnStyles, myGridTable.GridColumnStyles.Count, false); - Debug.Assert(newCol != -1, "there should be at least a visible column, right?"); - CurrentColumn = newCol; - } - else - { - int newCol = MoveLeftRight(myGridTable.GridColumnStyles, currentCol, false); - if (newCol == -1) - { - if (currentRow == 0) - return true; - else - { - // go to the previous row: - CurrentRow = CurrentRow - 1; - CurrentColumn = lastColumnMarkedVisible; - } - } - else - { - CurrentColumn = newCol; - } - } - - break; - case Keys.Right: - gridState[GRIDSTATE_childLinkFocused] = false; - ResetSelection(); - if ((biDiKe.Modifiers & Keys.Control) == Keys.Control && !biDiKe.Alt) - { - // we should navigate to the last column that is marked as Visible - CurrentColumn = lastColumnMarkedVisible; - break; - } - - if (currentCol == lastColumnMarkedVisible && currentRow != DataGridRowsLength - 1) - { - CurrentRow = CurrentRow + 1; - // navigate to the first visible column - CurrentColumn = firstColumnMarkedVisible; - } - else - { - int newCol = MoveLeftRight(myGridTable.GridColumnStyles, currentCol, true); - if (newCol == cols.Count + 1) - { - // navigate to the first visible column - // and the next row - CurrentColumn = firstColumnMarkedVisible; - CurrentRow++; - } - else - CurrentColumn = newCol; - } - - break; - case Keys.F2: - gridState[GRIDSTATE_childLinkFocused] = false; - ResetSelection(); - Edit(); - break; -#if DEBUG - case Keys.F12: - gridState[GRIDSTATE_childLinkFocused] = false; - AddNewRow(); - break; -#endif - case Keys.Home: - gridState[GRIDSTATE_childLinkFocused] = false; - if (dataGridRowsLength == 0) - { - return true; - } - - ResetSelection(); - CurrentColumn = 0; - if (biDiKe.Control && !biDiKe.Alt) - { - int currentRowSaved = currentRow; - CurrentRow = 0; - - if (biDiKe.Shift) - { - // Ctrl-Shift-Home will select all the rows up to the first one - DataGridRow[] gridRows = DataGridRows; - for (int i = 0; i <= currentRowSaved; i++) - { - gridRows[i].Selected = true; - numSelectedRows++; - } - - EndEdit(); - } - - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - return true; - } - - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - break; - case Keys.Delete: - gridState[GRIDSTATE_childLinkFocused] = false; - if (policy.AllowRemove && numSelectedRows > 0) - { -#if DEBUG - // when the list is empty, then the position - // in the listManager is -1, and the currentPosition in the grid is 0 - if (ListManager is not null && ListManager.Count > 0) - { - Debug.Assert(ListManager.Position == currentRow, - "Current row out of sync with DataSource", - "The DataSource's Position property should be mirrored by the CurrentCell.RowNumber of the DataGrid."); - } -#endif // DEBUG - - gridState[GRIDSTATE_inDeleteRow] = true; - DeleteRows(localGridRows); - // set the currentRow to the position in the list - currentRow = listManager.Count == 0 ? 0 : listManager.Position; - numSelectedRows = 0; - } - else - { - // if we did not use the the Delete key, let the dataGridTextBox use it - return false; - } - - break; - case Keys.End: - gridState[GRIDSTATE_childLinkFocused] = false; - if (dataGridRowsLength == 0) - { - return true; - } - - ResetSelection(); - // go the the last visible column - CurrentColumn = lastColumnMarkedVisible; - - if (biDiKe.Control && !biDiKe.Alt) - { - int savedCurrentRow = currentRow; - CurrentRow = Math.Max(0, DataGridRowsLength - (policy.AllowAdd ? 2 : 1)); - - if (biDiKe.Shift) - { - // Ctrl-Shift-Home will select all the rows up to the first one - DataGridRow[] gridRows = DataGridRows; - for (int i = savedCurrentRow; i <= currentRow; i++) - { - gridRows[i].Selected = true; - } - - numSelectedRows = currentRow - savedCurrentRow + 1; - // hide the edit box - // - EndEdit(); - } - - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - return true; - } - - Debug.Assert(ListManager.Position == CurrentCell.RowNumber || listManager.Count == 0, "current row out of ssync with DataSource"); - break; - case Keys.Enter: - gridState[GRIDSTATE_childLinkFocused] = false; - ResetSelection(); - - // yield the return key if there is no editing - if (!gridState[GRIDSTATE_isEditing]) - return false; - - // Ctrl-Enter will call EndCurrentEdit - if ((biDiKe.Modifiers & Keys.Control) != 0 && !biDiKe.Alt) - { - EndEdit(); - HandleEndCurrentEdit(); - Edit(); // put the edit box on the screen - } - else - { - // Do not commit the edit, cause reseting the - // current cell will do that - // CommitEdit(); - - CurrentRow = currentRow + 1; - } - - break; - case Keys.A: - gridState[GRIDSTATE_childLinkFocused] = false; - if (biDiKe.Control && !biDiKe.Alt) - { - DataGridRow[] gridRows = DataGridRows; - for (int i = 0; i < DataGridRowsLength; i++) - if (gridRows[i] is DataGridRelationshipRow) - gridRows[i].Selected = true; - - numSelectedRows = DataGridRowsLength - (policy.AllowAdd ? 1 : 0); - // hide the edit box - EndEdit(); - return true; - } - - return false; - case Keys.Escape: - gridState[GRIDSTATE_childLinkFocused] = false; - ResetSelection(); - if (gridState[GRIDSTATE_isEditing]) - { - // rollback - AbortEdit(); - - // we have to invalidate the row header ( make it display the row selector instead of the pencil ) - if (layout.RowHeadersVisible && currentRow > -1) - { - Rectangle rowHdrRect = GetRowRect(currentRow); - rowHdrRect.Width = layout.RowHeaders.Width; - Invalidate(rowHdrRect); - } - - // now put the edit column back on the screen - Edit(); - } - else - { - // add this protected virtual method for the XML designer team - CancelEditing(); - Edit(); - return false; - } - - break; - } - - return true; - } - - protected override bool ProcessKeyPreview(ref Message m) - { - if (m.Msg == PInvoke.WM_KEYDOWN) - { - KeyEventArgs ke = new KeyEventArgs((Keys)(unchecked((int)(long)m.WParam)) | ModifierKeys); - switch (ke.KeyCode) - { - case Keys.Up: - case Keys.Down: - case Keys.Prior: - case Keys.Next: - case Keys.Right: - case Keys.Left: - case Keys.Tab: - case Keys.Escape: - case Keys.Enter: - case Keys.OemMinus: - case Keys.Subtract: - case Keys.Oemplus: - case Keys.Add: - case Keys.Space: - case Keys.Home: - case Keys.End: - case Keys.F2: - case Keys.Delete: - case Keys.A: - return ProcessGridKey(ke); - } - } - else if (m.Msg == PInvoke.WM_KEYUP) - { - KeyEventArgs ke = new KeyEventArgs((Keys)(unchecked((int)(long)m.WParam)) | ModifierKeys); - if (ke.KeyCode == Keys.Tab) - return ProcessGridKey(ke); - } - - return base.ProcessKeyPreview(ref m); - } - - protected bool ProcessTabKey(Keys keyData) - { - if (listManager is null || myGridTable is null) - return false; - bool wasEditing = false; - int columnCount = myGridTable.GridColumnStyles.Count; - bool biDi = isRightToLeft(); - ResetSelection(); - - // Try to commit changes to cell if we were editing - if (gridState[GRIDSTATE_isEditing]) - { - wasEditing = true; - if (!CommitEdit()) - { - Edit(); // if we can't commit the value put the edit box so that the user sees where the focus is - return true; - } - } - - if ((keyData & Keys.Control) == Keys.Control) - { - // when the user hits ctrl-alt-tab just ignore it. - if ((keyData & Keys.Alt) == Keys.Alt) - return true; - - // navigate to the next control in the form - Keys ke = keyData & ~(Keys.Control); - EndEdit(); - - gridState[GRIDSTATE_editControlChanging] = true; - try - { - FocusInternal(); - } - finally - { - gridState[GRIDSTATE_editControlChanging] = false; - } - - bool ret = false; - - return ret; - } - - // see if the child relationships can use this TAB key - DataGridRow[] localRows = DataGridRows; - GridColumnStylesCollection cols = myGridTable.GridColumnStyles; - - int lastColumnMarkedVisible = 0; - int firstColumnMarkedVisible = cols.Count - 1; - // bug 70492: if we do not have any rows, then tab should move focus to the next control - if (localRows.Length == 0) - { - EndEdit(); - - bool ret = false; - ret = base.ProcessDialogKey(keyData); - - return ret; - } - - for (int i = 0; i < cols.Count; i++) - { - // if (cols[i].Visible && cols[i].PropertyDescriptor is not null) { - if (cols[i].PropertyDescriptor is not null) - { - firstColumnMarkedVisible = i; - break; - } - } - - for (int i = cols.Count - 1; i >= 0; i--) - { - // if (cols[i].Visible && cols[i].PropertyDescriptor is not null) { - if (cols[i].PropertyDescriptor is not null) - { - lastColumnMarkedVisible = i; - break; - } - } - - if (CurrentColumn == lastColumnMarkedVisible) - { - if (gridState[GRIDSTATE_childLinkFocused] || (!gridState[GRIDSTATE_childLinkFocused] && (keyData & Keys.Shift) != Keys.Shift)) - { - if (localRows[CurrentRow].ProcessTabKey(keyData, layout.RowHeaders, isRightToLeft())) - { - if (cols.Count > 0) - cols[CurrentColumn].ConcedeFocus(); - gridState[GRIDSTATE_childLinkFocused] = true; - // let the grid regain focus - // introduced because of that BeginInvoke thing in the OnLeave method.... - if (gridState[GRIDSTATE_canFocus] && CanFocus && !Focused) - FocusInternal(); - return true; - } - } - - // actually, it turns out that we should leave the - // control if we are in the last row - if ((currentRow == DataGridRowsLength - 1) && ((keyData & Keys.Shift) == 0)) - { - EndEdit(); - bool ret = false; - ret = base.ProcessDialogKey(keyData); - - return ret; - } - } - - if (CurrentColumn == firstColumnMarkedVisible) - { - // if the childLink is focused, then navigate within the relations - // in the row, otherwise expand the relations list for the row above - if (!gridState[GRIDSTATE_childLinkFocused]) - { - if (CurrentRow != 0 && (keyData & Keys.Shift) == Keys.Shift) - { - if (localRows[CurrentRow - 1].ProcessTabKey(keyData, layout.RowHeaders, isRightToLeft())) - { - CurrentRow--; - if (cols.Count > 0) - cols[CurrentColumn].ConcedeFocus(); - gridState[GRIDSTATE_childLinkFocused] = true; - // let the grid regain focus - // introduced because of that BeginInvoke thing in the OnLeave method.... - if (gridState[GRIDSTATE_canFocus] && CanFocus && !Focused) - FocusInternal(); - return true; - } - } - } - else - { - if (localRows[CurrentRow].ProcessTabKey(keyData, layout.RowHeaders, isRightToLeft())) - { - return true; - } - else - { - // we were on the firstColumn, previously the link was focused - // we have to navigate to the last column - gridState[GRIDSTATE_childLinkFocused] = false; - CurrentColumn = lastColumnMarkedVisible; - return true; - } - } - - // if we are on the first cell ( not on the addNewRow ) - // then shift - tab should move to the next control on the form - if (currentRow == 0 && ((keyData & Keys.Shift) == Keys.Shift)) - { - EndEdit(); - bool ret = false; - ret = base.ProcessDialogKey(keyData); - - return ret; - } - } - - // move - if ((keyData & Keys.Shift) != Keys.Shift) - { - // forward - if (CurrentColumn == lastColumnMarkedVisible) - { - if (CurrentRow != DataGridRowsLength - 1) - CurrentColumn = firstColumnMarkedVisible; - CurrentRow = CurrentRow + 1; - } - else - { - int nextCol = MoveLeftRight(cols, currentCol, true); // true for going right; - Debug.Assert(nextCol < cols.Count, "we already checked that we are not at the lastColumnMarkedVisible"); - CurrentColumn = nextCol; - } - } - else - { - // backward - if (CurrentColumn == firstColumnMarkedVisible) - { - if (CurrentRow != 0) - { - CurrentColumn = lastColumnMarkedVisible; - } - - if (!gridState[GRIDSTATE_childLinkFocused]) // bug 86803 - CurrentRow--; - } - else if (gridState[GRIDSTATE_childLinkFocused] && CurrentColumn == lastColumnMarkedVisible) - { - // part deux: when we hilite the childLink and then press shift-tab, we - // don't want to navigate at the second to last column - InvalidateRow(currentRow); - Edit(); - } - else - { - int prevCol = MoveLeftRight(cols, currentCol, false); // false for going left - Debug.Assert(prevCol != -1, "we already checked that we are not at the first columnMarked visible"); - CurrentColumn = prevCol; - } - } - - // if we got here, then invalidate childLinkFocused - gridState[GRIDSTATE_childLinkFocused] = false; - - // Begin another edit if we were editing before - if (wasEditing) - { - ResetSelection(); - Edit(); - } - - return true; - } - - virtual protected void CancelEditing() - { - CancelCursorUpdate(); - // yield the escape key if there is no editing - // make the last row a DataGridAddNewRow - if (gridState[GRIDSTATE_inAddNewRow]) - { - gridState[GRIDSTATE_inAddNewRow] = false; - DataGridRow[] localGridRows = DataGridRows; - - localGridRows[DataGridRowsLength - 1] = new DataGridAddNewRow(this, myGridTable, DataGridRowsLength - 1); - SetDataGridRows(localGridRows, DataGridRowsLength); - } - } - - internal void RecalculateFonts() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public bool ParentRowsVisible { - try - { - linkFont = new Font(Font, FontStyle.Underline); - } - catch - { - } - - fontHeight = Font.Height; - linkFontHeight = LinkFont.Height; - captionFontHeight = CaptionFont.Height; - - if (myGridTable is null || myGridTable.IsDefault) - headerFontHeight = HeaderFont.Height; - else - headerFontHeight = myGridTable.HeaderFont.Height; + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler BackButtonClick + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ParentRowsVisibleChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public event EventHandler ShowParentDetailsButtonClick + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public bool RowHeadersVisible { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private void ResetMouseState() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public int RowHeaderWidth { - oldRow = -1; - gridState[GRIDSTATE_overCaption] = true; + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - protected void ResetSelection() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public override string Text { - if (numSelectedRows > 0) - { - DataGridRow[] localGridRows = DataGridRows; - for (int i = 0; i < DataGridRowsLength; ++i) - if (localGridRows[i].Selected) - localGridRows[i].Selected = false; - } - - numSelectedRows = 0; - lastRowSelected = -1; + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - private void ResetParentRows() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + new public event EventHandler TextChanged { - parentRows.Clear(); - originalState = null; - caption.BackButtonActive = caption.DownButtonActive = caption.BackButtonVisible = false; - caption.SetDownButtonDirection(!layout.ParentRowsVisible); + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - /// - /// Re-initializes all UI related state. - /// - private void ResetUIState() + protected ScrollBar VertScrollBar { - gridState[GRIDSTATE_childLinkFocused] = false; - ResetSelection(); - ResetMouseState(); - PerformLayout(); - Invalidate(); // we want to invalidate after we set up the scrollbars - - // invalidate the horizontalscrollbar and the vertical scrollbar - // - if (horizScrollBar.Visible) - horizScrollBar.Invalidate(); - if (vertScrollBar.Visible) - vertScrollBar.Invalidate(); + get => throw new PlatformNotSupportedException(); } - /// - /// Scrolls the datagrid down an arbritrary number of rows. - /// - private void ScrollDown(int rows) + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public int VisibleColumnCount { - // Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: ScrollDown, rows = " + rows.ToString()); - if (rows != 0) - { - ClearRegionCache(); - - // we should put "dataGridRowsLength -1" - int newFirstRow = Math.Max(0, Math.Min(firstVisibleRow + rows, this.DataGridRowsLength - 1)); - int oldFirstRow = firstVisibleRow; - firstVisibleRow = newFirstRow; - vertScrollBar.Value = newFirstRow; - bool wasEditing = this.gridState[GRIDSTATE_isEditing]; - ComputeVisibleRows(); - - if (gridState[GRIDSTATE_isScrolling]) - { - Edit(); - // isScrolling is set to TRUE when the user scrolls. - // once we move the edit box, we finished processing the scroll event, so set isScrolling to FALSE - // to set isScrolling to TRUE, we need another scroll event. - gridState[GRIDSTATE_isScrolling] = false; - } - else - { - EndEdit(); - } - - int deltaY = ComputeRowDelta(oldFirstRow, newFirstRow); - Rectangle rowsRect = layout.Data; - if (layout.RowHeadersVisible) - rowsRect = Rectangle.Union(rowsRect, layout.RowHeaders); - RECT scrollArea = RECT.FromXYWH(rowsRect.X, rowsRect.Y, rowsRect.Width, rowsRect.Height); - // SafeNativeMethods.ScrollWindow(new HandleRef(this, Handle), 0, deltaY, ref scrollArea, ref scrollArea); - OnScroll(EventArgs.Empty); - - if (wasEditing) - { - // invalidate the rowHeader for the - InvalidateRowHeader(currentRow); - } - } + get => throw new PlatformNotSupportedException(); } - /// - /// Scrolls the datagrid right an arbritrary number of columns. - /// - private void ScrollRight(int columns) + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public int VisibleRowCount { - Debug.WriteLineIf(CompModSwitches.DataGridScrolling.TraceVerbose, "DataGridScrolling: ScrollRight, columns = " + columns.ToString(CultureInfo.InvariantCulture)); - int newCol = firstVisibleCol + columns; - - GridColumnStylesCollection gridColumns = myGridTable.GridColumnStyles; - int newColOffset = 0; - int nGridCols = gridColumns.Count; - int nVisibleCols = 0; - - // if we try to scroll past the last totally visible column, - // then the toolTips will dissapear - if (this.myGridTable.IsDefault) - nVisibleCols = nGridCols; - else - for (int i = 0; i < nGridCols; i++) - if (gridColumns[i].PropertyDescriptor is not null) - nVisibleCols++; - - if ((lastTotallyVisibleCol == nVisibleCols - 1 && columns > 0) || - (firstVisibleCol == 0 && columns < 0 && negOffset == 0)) - return; - - newCol = Math.Min(newCol, nGridCols - 1); - - for (int i = 0; i < newCol; i++) - // if (gridColumns[i].Visible && gridColumns[i].PropertyDescriptor is not null) - if (gridColumns[i].PropertyDescriptor is not null) - newColOffset += gridColumns[i].Width; - - HorizontalOffset = newColOffset; + get => throw new PlatformNotSupportedException(); } - /// - /// Scrolls a given column into visibility. - /// - private void ScrollToColumn(int targetCol) + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public object this[int rowIndex, int columnIndex] { - // do not flush the columns to the left - // so, scroll only as many columns as is necessary. - // CONSIDER: after doing a sort, maybe the user would like to have - // selected column flushed to the left - int dCols = targetCol - firstVisibleCol; - - if (targetCol > lastTotallyVisibleCol && lastTotallyVisibleCol != -1) - dCols = targetCol - lastTotallyVisibleCol; - - // if only part of the currentCol is visible - // then we should still scroll - if (dCols != 0 || negOffset != 0) - ScrollRight(dCols); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - public void Select(int row) + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public object this[DataGridCell cell] { - throw new PlatformNotSupportedException(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - // this function will pair the listManager w/ a table from the TableStylesCollection. - // and for each column in the TableStylesCollection will pair them w/ a propertyDescriptor - // from the listManager - // prerequisite: the current table is either the default table, or has the same name as the - // list in the listManager. - private void PairTableStylesAndGridColumns(CurrencyManager lm, DataGridTableStyle gridTable, bool forceColumnCreation) - { - PropertyDescriptorCollection props = lm.GetItemProperties(); - GridColumnStylesCollection gridCols = gridTable.GridColumnStyles; + protected virtual void OnBorderStyleChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - // ]it is possible to have a dataTable w/ an empty string for a name. - if (!gridTable.IsDefault && string.Compare(lm.GetListName(), gridTable.MappingName, true, CultureInfo.InvariantCulture) == 0) - { - // we will force column creation only at runtime - if (gridTable.GridColumnStyles.Count == 0 && !DesignMode) - { - // we have to create some default columns for each of the propertyDescriptors - // - if (forceColumnCreation) - gridTable.SetGridColumnStylesCollection(lm); - else - gridTable.SetRelationsList(lm); - } - else - { - // it may the case that the user will have two lists w/ the same name. - // When switching binding between those different lists, we need to invalidate - // the propertyDescriptors from the current gridColumns - for (int i = 0; i < gridCols.Count; i++) - gridCols[i].PropertyDescriptor = null; - - // pair the propertyDescriptor from each column to the actual property descriptor - // from the listManager - for (int i = 0; i < props.Count; i++) - { - DataGridColumnStyle col = gridCols.MapColumnStyleToPropertyName(props[i].Name); - if (col is not null) - { - col.PropertyDescriptor = props[i]; - } - } - - // TableStyle::SetGridColumnStylesCollection will also set the - // relations list in the tableStyle. - gridTable.SetRelationsList(lm); - } - } - else - { - // we should put an assert, that this is the default Table Style -#if DEBUG - Debug.Assert(gridTable.IsDefault, "if we don't have a match, then the dataGRid should have the default table"); -#endif // DEBUG - gridTable.SetGridColumnStylesCollection(lm); - if (gridTable.GridColumnStyles.Count > 0 && gridTable.GridColumnStyles[0].Width == -1) - { -#if DEBUG - GridColumnStylesCollection cols = gridTable.GridColumnStyles; - for (int i = 0; i < cols.Count; i++) - { - Debug.Assert(cols[i].Width == -1, "if one column's width is not initialized, the same should be happening for the rest of the columns"); - } -#endif // DEBUG - InitializeColumnWidths(); - } - } - } + protected virtual void OnCaptionVisibleChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - /// - /// Sets the current GridTable for the DataGrid. - /// This GridTable is the table which is currently - /// being displayed on the grid. - /// - internal void SetDataGridTable(DataGridTableStyle newTable, bool forceColumnCreation) - { - // we have to listen to the dataGridTable for the propertyChangedEvent - if (myGridTable is not null) - { - // unwire the propertyChanged event - UnWireTableStylePropChanged(myGridTable); + protected virtual void OnCurrentCellChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - if (myGridTable.IsDefault) - { - // reset the propertyDescriptors on the default table. - myGridTable.GridColumnStyles.ResetPropertyDescriptors(); + protected virtual void OnFlatModeChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - // reset the relationship list from the default table - myGridTable.ResetRelationsList(); - } - } + protected virtual void OnBackgroundColorChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - myGridTable = newTable; - - WireTableStylePropChanged(myGridTable); - - layout.RowHeadersVisible = newTable.IsDefault ? RowHeadersVisible : newTable.RowHeadersVisible; - - // we need to force the grid into the dataGridTableStyle - // this way the controls in the columns will be parented - // consider this scenario: when the user finished InitializeComponent, it added - // a bunch of tables. all of those tables will have the DataGrid property set to this - // grid. however, in InitializeComponent the tables will not have parented the - // edit controls w/ the grid. - // - // the code in DataGridTextBoxColumn already checks to see if the edits are parented - // before parenting them. - // - if (newTable is not null) - newTable.DataGrid = this; - - // pair the tableStyles and GridColumns - // - if (listManager is not null) - PairTableStylesAndGridColumns(listManager, myGridTable, forceColumnCreation); - - // reset the relations UI on the newTable - if (newTable is not null) - newTable.ResetRelationsUI(); - - // set the isNavigating to false - gridState[GRIDSTATE_isNavigating] = false; - - horizScrollBar.Value = 0; - firstVisibleRow = 0; - currentCol = 0; - // if we add a tableStyle that mapps to the - // current listName, then we should set the currentRow to the - // position in the listManager - if (listManager is null) - currentRow = 0; - else - currentRow = listManager.Position == -1 ? 0 : listManager.Position; - ResetHorizontalOffset(); - negOffset = 0; - ResetUIState(); - - // check the hierarchy - checkHierarchy = true; - } + protected virtual void OnAllowNavigationChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - /// - /// Scrolls the data area down to make room for the parent rows - /// and lays out the different regions of the DataGrid. - /// - internal void SetParentRowsVisibility(bool visible) - { - Rectangle parentRowsRect = layout.ParentRows; - Rectangle underParentRows = layout.Data; + protected virtual void OnParentRowsVisibleChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - if (layout.RowHeadersVisible) - { - underParentRows.X -= isRightToLeft() ? 0 : layout.RowHeaders.Width; - underParentRows.Width += layout.RowHeaders.Width; - } + protected virtual void OnParentRowsLabelStyleChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - if (layout.ColumnHeadersVisible) - { - underParentRows.Y -= layout.ColumnHeaders.Height; - underParentRows.Height += layout.ColumnHeaders.Height; - } + protected virtual void OnReadOnlyChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - // hide the Edit Box - EndEdit(); + protected void OnNavigate(NavigateEventArgs e) + => throw new PlatformNotSupportedException(); - if (visible) - { - layout.ParentRowsVisible = true; + protected void OnRowHeaderClick(EventArgs e) + => throw new PlatformNotSupportedException(); - PerformLayout(); + protected void OnScroll(EventArgs e) + => throw new PlatformNotSupportedException(); - Invalidate(); - } - else - { - RECT scrollRECT = RECT.FromXYWH(underParentRows.X, underParentRows.Y - layout.ParentRows.Height, underParentRows.Width, underParentRows.Height + layout.ParentRows.Height); - - if (vertScrollBar.Visible) - { - Rectangle fixupRect = vertScrollBar.Bounds; - fixupRect.Y -= parentRowsRect.Height; - fixupRect.Height += parentRowsRect.Height; - Invalidate(fixupRect); - } - - Debug.WriteLineIf(CompModSwitches.DataGridParents.TraceVerbose, "DataGridParents: Making parent rows invisible."); - layout.ParentRowsVisible = false; - PerformLayout(); - } - } + protected virtual void GridHScrolled(object sender, ScrollEventArgs se) + => throw new PlatformNotSupportedException(); - /// - /// Sets whether a row is expanded or not. - /// - private void SetRowExpansionState(int row, bool expanded) - { - if (row < -1 || row > DataGridRowsLength - (policy.AllowAdd ? 2 : 1)) - { - throw new ArgumentOutOfRangeException(); - } + protected virtual void GridVScrolled(object sender, ScrollEventArgs se) + => throw new PlatformNotSupportedException(); - DataGridRow[] localGridRows = DataGridRows; - if (row == -1) - { - DataGridRelationshipRow[] expandableRows = GetExpandableRows(); - bool repositionEditControl = false; - - for (int r = 0; r < expandableRows.Length; ++r) - { - if (expandableRows[r].Expanded != expanded) - { - expandableRows[r].Expanded = expanded; - repositionEditControl = true; - } - } - - if (repositionEditControl) - { - // we need to reposition the edit control - if (gridState[GRIDSTATE_isNavigating] || gridState[GRIDSTATE_isEditing]) - { - ResetSelection(); - Edit(); - } - } - } - else if (localGridRows[row] is DataGridRelationshipRow) - { - DataGridRelationshipRow expandableRow = (DataGridRelationshipRow)localGridRows[row]; - if (expandableRow.Expanded != expanded) - { - // we need to reposition the edit control - if (gridState[GRIDSTATE_isNavigating] || gridState[GRIDSTATE_isEditing]) - { - ResetSelection(); - Edit(); - } - - expandableRow.Expanded = expanded; - } - } - } + protected void OnBackButtonClicked(object sender, EventArgs e) + => throw new PlatformNotSupportedException(); - private void ObjectSiteChange(IContainer container, IComponent component, bool site) - { - if (site) - { - if (component.Site is null) - { - container.Add(component); - } - } - else - { - if (component.Site is not null && component.Site.Container == container) - { - container.Remove(component); - } - } - } + protected override void OnBackColorChanged(EventArgs e) + => throw new PlatformNotSupportedException(); - public void SubObjectsSiteChange(bool site) + protected override void OnBindingContextChanged(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected virtual void OnDataSourceChanged(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected void OnShowParentDetailsButtonClicked(object sender, EventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnForeColorChanged(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnFontChanged(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnPaintBackground(PaintEventArgs pevent) + => throw new PlatformNotSupportedException(); + + protected override void OnLayout(LayoutEventArgs levent) + => throw new PlatformNotSupportedException(); + + protected override void OnHandleCreated(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnHandleDestroyed(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnEnter(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnLeave(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnKeyDown(KeyEventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnKeyPress(KeyPressEventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnMouseDown(MouseEventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnMouseLeave(EventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnMouseMove(MouseEventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnMouseUp(MouseEventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnMouseWheel(MouseEventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnPaint(PaintEventArgs e) + => throw new PlatformNotSupportedException(); + + protected override void OnResize(EventArgs e) + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event NavigateEventHandler Navigate { - throw new PlatformNotSupportedException(); + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - public void UnSelect(int row) + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + protected event EventHandler RowHeaderClick { - throw new PlatformNotSupportedException(); + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - /// - /// Asks the cursor to update. - /// - private void UpdateListManager() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Scroll { - Debug.WriteLineIf(CompModSwitches.DataGridCursor.TraceVerbose, "DataGridCursor: Requesting EndEdit()"); - try - { - if (listManager is not null) - { - EndEdit(); - listManager.EndCurrentEdit(); - } - } - catch - { - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - protected virtual string GetOutputTextDelimiter() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public override ISite Site { - return "\t"; + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// The accessible object class for a DataGrid. The child accessible objects - /// are accessible objects corresponding to the propertygrid entries. - /// - [Runtime.InteropServices.ComVisible(true)] - [Obsolete("DataGridAccessibleObject has been deprecated.")] - internal class DataGridAccessibleObject : ControlAccessibleObject - { - /// - /// Construct a PropertyGridViewAccessibleObject - /// - public DataGridAccessibleObject(DataGrid owner) : base(owner) - { - throw new PlatformNotSupportedException(); - } + public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) + => throw new PlatformNotSupportedException(); - internal DataGrid DataGrid - { - get - { - return (DataGrid)Owner; - } - } + public void BeginInit() + => throw new PlatformNotSupportedException(); - private int ColumnCountPrivate - { - get - { - return ((DataGrid)Owner).myGridTable.GridColumnStyles.Count; - } - } + public void Collapse(int row) + => throw new PlatformNotSupportedException(); - private int RowCountPrivate - { - get - { - return ((DataGrid)Owner).dataGridRows.Length; - } - } + protected override AccessibleObject CreateAccessibilityInstance() + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public override string Name - { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } - } + protected override void Dispose(bool disposing) + => base.Dispose(disposing); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleRole Role - { - get - { - throw new PlatformNotSupportedException(); - } - } + public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) + => throw new PlatformNotSupportedException(); - public override AccessibleObject GetChild(int index) - { - throw new PlatformNotSupportedException(); - } + public void Expand(int row) + => throw new PlatformNotSupportedException(); - public override int GetChildCount() - { - throw new PlatformNotSupportedException(); - } + protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop, bool isDefault) + => throw new PlatformNotSupportedException(); - public override AccessibleObject GetFocused() - { - throw new PlatformNotSupportedException(); - } + protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop) + => throw new PlatformNotSupportedException(); - public override AccessibleObject GetSelected() - { - throw new PlatformNotSupportedException(); - } + public void EndInit() + => throw new PlatformNotSupportedException(); - public override AccessibleObject HitTest(int x, int y) - { - throw new PlatformNotSupportedException(); - } + public Rectangle GetCurrentCellBounds() + => throw new PlatformNotSupportedException(); - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] - public override AccessibleObject Navigate(AccessibleNavigation navdir) - { - throw new PlatformNotSupportedException(); - } - } + public Rectangle GetCellBounds(int row, int col) + => throw new PlatformNotSupportedException(); - // - // This simple data structure holds all of the layout information - // for the DataGrid. - // - [Obsolete("LayoutData has been deprecated.")] - internal class LayoutData - { - internal bool dirty = true; - // region inside the Control's borders. - public Rectangle Inside = Rectangle.Empty; + public Rectangle GetCellBounds(DataGridCell dgc) + => throw new PlatformNotSupportedException(); - public Rectangle RowHeaders = Rectangle.Empty; + public HitTestInfo HitTest(int x, int y) + => throw new PlatformNotSupportedException(); - public Rectangle TopLeftHeader = Rectangle.Empty; - public Rectangle ColumnHeaders = Rectangle.Empty; - public Rectangle Data = Rectangle.Empty; + public HitTestInfo HitTest(Point position) + => throw new PlatformNotSupportedException(); - public Rectangle Caption = Rectangle.Empty; - public Rectangle ParentRows = Rectangle.Empty; + public bool IsExpanded(int rowNumber) + => throw new PlatformNotSupportedException(); - public Rectangle ResizeBoxRect = Rectangle.Empty; + public bool IsSelected(int row) + => throw new PlatformNotSupportedException(); - public bool ColumnHeadersVisible; - public bool RowHeadersVisible; - public bool CaptionVisible; - public bool ParentRowsVisible; + public void NavigateBack() + => throw new PlatformNotSupportedException(); - // used for resizing. - public Rectangle ClientRectangle = Rectangle.Empty; + public void NavigateTo(int rowNumber, string relationName) + => throw new PlatformNotSupportedException(); - public LayoutData() - { - throw new PlatformNotSupportedException(); - } + protected override bool ProcessDialogKey(Keys keyData) + => throw new PlatformNotSupportedException(); - public LayoutData(LayoutData src) - { - throw new PlatformNotSupportedException(); - } + protected bool ProcessGridKey(KeyEventArgs ke) + => throw new PlatformNotSupportedException(); - private void GrabLayout(LayoutData src) - { - Inside = src.Inside; - TopLeftHeader = src.TopLeftHeader; - ColumnHeaders = src.ColumnHeaders; - RowHeaders = src.RowHeaders; - Data = src.Data; - Caption = src.Caption; - ParentRows = src.ParentRows; - ResizeBoxRect = src.ResizeBoxRect; - ColumnHeadersVisible = src.ColumnHeadersVisible; - RowHeadersVisible = src.RowHeadersVisible; - CaptionVisible = src.CaptionVisible; - ParentRowsVisible = src.ParentRowsVisible; - ClientRectangle = src.ClientRectangle; - } + protected override bool ProcessKeyPreview(ref Message m) + => throw new PlatformNotSupportedException(); - public override string ToString() - { - throw new PlatformNotSupportedException(); - } + protected bool ProcessTabKey(Keys keyData) + => throw new PlatformNotSupportedException(); + + virtual protected void CancelEditing() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler BackButtonClick + { + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Obsolete("HitTestInfo has been deprecated.")] - public sealed class HitTestInfo + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ShowParentDetailsButtonClick { - internal HitTestType type = HitTestType.None; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); + } - internal int row; - internal int col; + protected void ResetSelection() + => throw new PlatformNotSupportedException(); - public static readonly HitTestInfo Nowhere = new HitTestInfo(); + public void Select(int row) + => throw new PlatformNotSupportedException(); - internal HitTestInfo() - { - type = (HitTestType)0; - row = col = -1; - } + public void SubObjectsSiteChange(bool site) + => throw new PlatformNotSupportedException(); - internal HitTestInfo(HitTestType type) - { - this.type = type; - row = col = -1; - } + public void UnSelect(int row) + => throw new PlatformNotSupportedException(); + + protected virtual string GetOutputTextDelimiter() + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete( + Obsoletions.DataGridHitTestInfoMessage, + error: false, + DiagnosticId = Obsoletions.DataGridHitTestInfoDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] + public sealed class HitTestInfo + { + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int Column { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int Row { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public HitTestType Type { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - public override bool Equals(object value) - { - throw new PlatformNotSupportedException(); - } + public override bool Equals(object obj) + => throw new PlatformNotSupportedException(); public override int GetHashCode() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override string ToString() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } [Flags] - [Obsolete("HitTestType has been deprecated.")] + [Obsolete( + Obsoletions.DataGridHitTestTypeMessage, + error: false, + DiagnosticId = Obsoletions.DataGridHitTestTypeDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public enum HitTestType { None = 0x00000000, - Cell = 0x00000001, - ColumnHeader = 0x00000002, - RowHeader = 0x00000004, - ColumnResize = 0x00000008, - RowResize = 0x00000010, - Caption = 0x00000020, - ParentRows = 0x00000040 } - /// - /// Holds policy information for what the grid can and cannot do. - /// - private class Policy + [Obsolete( + Obsoletions.DataGridAccessibleObjectMessage, + error: false, + DiagnosticId = Obsoletions.DataGridAccessibleObjectDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] + internal class DataGridAccessibleObject : ControlAccessibleObject { - private bool allowAdd = true; - private bool allowEdit = true; - private bool allowRemove = true; + public DataGridAccessibleObject(DataGrid owner) : base(owner) + => throw new PlatformNotSupportedException(); - public Policy() + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public override string Name { + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - public bool AllowAdd + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public override AccessibleRole Role { - get - { - return allowAdd; - } - set - { - if (allowAdd != value) - { - allowAdd = value; - } - } + get => throw new PlatformNotSupportedException(); } - public bool AllowEdit - { - get - { - return allowEdit; - } - set - { - if (allowEdit != value) - { - allowEdit = value; - } - } - } + public override AccessibleObject GetChild(int index) + => throw new PlatformNotSupportedException(); - public bool AllowRemove - { - get - { - return allowRemove; - } - set - { - if (allowRemove != value) - { - allowRemove = value; - } - } - } + public override int GetChildCount() + => throw new PlatformNotSupportedException(); - // returns true if the UI needs to be updated (here because addnew has changed) - public bool UpdatePolicy(CurrencyManager listManager, bool gridReadOnly) - { - bool change = false; - // only IBindingList can have an AddNewRow - IBindingList bl = listManager is null ? null : listManager.List as IBindingList; - if (listManager is null) - { - if (!allowAdd) - change = true; - allowAdd = allowEdit = allowRemove = true; - } - else - { - if (AllowAdd != listManager.AllowAdd && !gridReadOnly) - change = true; - AllowAdd = listManager.AllowAdd && !gridReadOnly && bl is not null && bl.SupportsChangeNotification; - AllowEdit = listManager.AllowEdit && !gridReadOnly; - AllowRemove = listManager.AllowRemove && !gridReadOnly && bl is not null && bl.SupportsChangeNotification; // bug 86061 - } - - return change; - } - } + public override AccessibleObject GetFocused() + => throw new PlatformNotSupportedException(); - private int MirrorRectangle(Rectangle R1, Rectangle rect, bool rightToLeft) - { - if (rightToLeft) - return rect.Right + rect.X - R1.Right; - else - return R1.X; - } + public override AccessibleObject GetSelected() + => throw new PlatformNotSupportedException(); - private int MirrorPoint(int x, Rectangle rect, bool rightToLeft) - { - if (rightToLeft) - return rect.Right + rect.X - x; - else - return x; - } + public override AccessibleObject HitTest(int x, int y) + => throw new PlatformNotSupportedException(); - private bool isRightToLeft() - { - return (RightToLeft == RightToLeft.Yes); + public override AccessibleObject Navigate(AccessibleNavigation navdir) + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs index fc54ea428c8..2991ca768ba 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs @@ -7,73 +7,51 @@ namespace System.Windows.Forms; #nullable disable -[Obsolete("DataGridAddNewRow has been deprecated.")] +[Obsolete( + Obsoletions.DataGridAddNewRowMessage, + error: false, + DiagnosticId = Obsoletions.DataGridAddNewRowDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridAddNewRow : DataGridRow { public DataGridAddNewRow(DataGrid dGrid, DataGridTableStyle gridTable, int rowNum) : base(dGrid, gridTable, rowNum) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool DataBound { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public override void OnEdit() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override void OnRowLeave() - { - throw new PlatformNotSupportedException(); - } - - internal override void LoseChildFocus(Rectangle rowHeader, bool alignToRight) - { - } - - internal override bool ProcessTabKey(Keys keyData, Rectangle rowHeaders, bool alignToRight) - { - return false; - } - - public override int Paint(Graphics g, Rectangle bounds, Rectangle trueRowBounds, int firstVisibleColumn, int columnCount) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override int Paint(Graphics g, - Rectangle bounds, - Rectangle trueRowBounds, - int firstVisibleColumn, - int columnCount, - bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + Rectangle bounds, + Rectangle trueRowBounds, + int firstVisibleColumn, + int columnCount) + => throw new PlatformNotSupportedException(); - protected override void PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, - Brush backBr, Brush foreBrush, bool alignToRight) - { - if (DataBound) - { - CurrencyManager listManager = DataGrid.ListManager; - column.Paint(g, cellBounds, listManager, this.RowNumber, alignToRight); - } - else - { - base.PaintCellContents(g, cellBounds, column, backBr, foreBrush, alignToRight); - } - } + public override int Paint(Graphics g, + Rectangle bounds, + Rectangle trueRowBounds, + int firstVisibleColumn, + int columnCount, + bool alignToRight) + => throw new PlatformNotSupportedException(); + + protected override void PaintCellContents(Graphics g, + Rectangle cellBounds, + DataGridColumnStyle column, + Brush backBr, + Brush foreBrush, + bool alignToRight) + => base.PaintCellContents(g, cellBounds, column, backBr, foreBrush, alignToRight); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs index 489064d456f..fd3a90d76aa 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs @@ -6,417 +6,136 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 -#nullable disable -[Obsolete("DataGridBoolColumn has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.DataGridBoolColumnMessage, + error: false, + DiagnosticId = Obsoletions.DataGridBoolColumnDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridBoolColumn : DataGridColumnStyle { - private const int idealCheckSize = 14; - - private bool isEditing; - private bool isSelected; - private int editingRow = -1; - private object currentValue = Convert.DBNull; - - private object trueValue = true; - private object falseValue = false; - private object nullValue = Convert.DBNull; - - private static readonly object EventTrueValue = new object(); - private static readonly object EventFalseValue = new object(); - private static readonly object EventAllowNull = new object(); - public DataGridBoolColumn() : base() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - public DataGridBoolColumn(PropertyDescriptor prop) - : base(prop) - { - throw new PlatformNotSupportedException(); - } + public DataGridBoolColumn(PropertyDescriptor prop) : base(prop) + => throw new PlatformNotSupportedException(); public DataGridBoolColumn(PropertyDescriptor prop, bool isDefault) : base(prop, isDefault) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public object TrueValue { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler TrueValueChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public object FalseValue { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler FalseValueChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public object NullValue { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } protected internal override void ConcedeFocus() - { - base.ConcedeFocus(); - isSelected = false; - isEditing = false; - } - - private Rectangle GetCheckBoxBounds(Rectangle bounds, bool alignToRight) - { - if (alignToRight) - return new Rectangle(bounds.X + ((bounds.Width - idealCheckSize) / 2), - bounds.Y + ((bounds.Height - idealCheckSize) / 2), - bounds.Width < idealCheckSize ? bounds.Width : idealCheckSize, - idealCheckSize); - else - return new Rectangle(Math.Max(0, bounds.X + ((bounds.Width - idealCheckSize) / 2)), - Math.Max(0, bounds.Y + ((bounds.Height - idealCheckSize) / 2)), - bounds.Width < idealCheckSize ? bounds.Width : idealCheckSize, - idealCheckSize); - } - - protected internal override object GetColumnValueAtRow(CurrencyManager lm, int row) - { - object baseValue = base.GetColumnValueAtRow(lm, row); - object value = Convert.DBNull; - if (baseValue.Equals(trueValue)) - { - value = true; - } - else if (baseValue.Equals(falseValue)) - { - value = false; - } - - return value; - } - - private bool IsReadOnly() - { - bool ret = ReadOnly; - if (DataGridTableStyle is not null) - { - ret = ret || DataGridTableStyle.ReadOnly; - if (DataGridTableStyle.DataGrid is not null) - ret = ret || DataGridTableStyle.DataGrid.ReadOnly; - } + => throw new PlatformNotSupportedException(); - return ret; - } - - protected internal override void SetColumnValueAtRow(CurrencyManager lm, int row, object value) - { - object baseValue = null; - if (true.Equals(value)) - { - baseValue = TrueValue; - } - else if (false.Equals(value)) - { - baseValue = FalseValue; - } - else if (Convert.IsDBNull(value)) - { - baseValue = NullValue; - } + protected internal override object GetColumnValueAtRow(CurrencyManager source, int rowNum) + => throw new PlatformNotSupportedException(); - currentValue = baseValue; - base.SetColumnValueAtRow(lm, row, baseValue); - } + protected internal override void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) + => throw new PlatformNotSupportedException(); protected internal override Size GetPreferredSize(Graphics g, object value) - { - return new Size(idealCheckSize + 2, idealCheckSize + 2); - } + => throw new PlatformNotSupportedException(); protected internal override int GetMinimumHeight() - { - return idealCheckSize + 2; - } + => throw new PlatformNotSupportedException(); protected internal override int GetPreferredHeight(Graphics g, object value) - { - return idealCheckSize + 2; - } + => throw new PlatformNotSupportedException(); protected internal override void Abort(int rowNum) - { - isSelected = false; - isEditing = false; - Invalidate(); - return; - } + => throw new PlatformNotSupportedException(); protected internal override bool Commit(CurrencyManager dataSource, int rowNum) - { - isSelected = false; - // always invalidate - Invalidate(); - if (!isEditing) - return true; - - SetColumnValueAtRow(dataSource, rowNum, currentValue); - isEditing = false; - return true; - } + => throw new PlatformNotSupportedException(); protected internal override void Edit(CurrencyManager source, - int rowNum, - Rectangle bounds, - bool readOnly, - string displayText, - bool cellIsVisible) - { - // toggle state right now... - isSelected = true; - - // move the focus away from the previous column and give it to the grid - DataGrid grid = DataGridTableStyle.DataGrid; - - if (!readOnly && !IsReadOnly()) - { - editingRow = rowNum; - currentValue = GetColumnValueAtRow(source, rowNum); - } - - base.Invalidate(); - } - - internal override bool KeyPress(int rowNum, Keys keyData) - { - if (isSelected && editingRow == rowNum && !IsReadOnly()) - { - if ((keyData & Keys.KeyCode) == Keys.Space) - { - ToggleValue(); - Invalidate(); - return true; - } - } - - return base.KeyPress(rowNum, keyData); - } - - internal override bool MouseDown(int rowNum, int x, int y) - { - base.MouseDown(rowNum, x, y); - if (isSelected && editingRow == rowNum && !IsReadOnly()) - { - ToggleValue(); - Invalidate(); - return true; - } - - return false; - } - - private void OnTrueValueChanged(EventArgs e) - { - EventHandler eh = Events[EventTrueValue] as EventHandler; - if (eh is not null) - eh(this, e); - } - - private void OnFalseValueChanged(EventArgs e) - { - EventHandler eh = Events[EventFalseValue] as EventHandler; - if (eh is not null) - eh(this, e); - } - - private void OnAllowNullChanged(EventArgs e) - { - EventHandler eh = Events[EventAllowNull] as EventHandler; - if (eh is not null) - eh(this, e); - } - - protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) - { - Paint(g, bounds, source, rowNum, DataGridTableStyle.BackBrush, DataGridTableStyle.ForeBrush, alignToRight); - } - - protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, - Brush backBrush, Brush foreBrush, - bool alignToRight) - { - object value = (isEditing && editingRow == rowNum) ? currentValue : GetColumnValueAtRow(source, rowNum); - ButtonState checkedState = ButtonState.Inactive; - if (!Convert.IsDBNull(value)) - { - checkedState = ((bool)value ? ButtonState.Checked : ButtonState.Normal); - } - - Rectangle box = GetCheckBoxBounds(bounds, alignToRight); - - Region r = g.Clip; - g.ExcludeClip(box); - - Brush selectionBrush = DataGridTableStyle.IsDefault ? DataGridTableStyle.DataGrid.SelectionBackBrush : DataGridTableStyle.SelectionBackBrush; - if (isSelected && editingRow == rowNum && !IsReadOnly()) - { - g.FillRectangle(selectionBrush, bounds); - } - else - g.FillRectangle(backBrush, bounds); - g.Clip = r; - - if (checkedState == ButtonState.Inactive) - { - ControlPaint.DrawMixedCheckBox(g, box, ButtonState.Checked); - } - else - { - ControlPaint.DrawCheckBox(g, box, checkedState); - } - - // if the column is read only we should still show selection - if (IsReadOnly() && isSelected && source.Position == rowNum) - { - bounds.Inflate(-1, -1); - Pen pen = new Pen(selectionBrush); - pen.DashStyle = Drawing.Drawing2D.DashStyle.Dash; - g.DrawRectangle(pen, bounds); - pen.Dispose(); - // restore the bounds rectangle - bounds.Inflate(1, 1); - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + int rowNum, + Rectangle bounds, + bool readOnly, + string displayText, + bool cellIsVisible) + => throw new PlatformNotSupportedException(); + + protected internal override void Paint(Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum, + bool alignToRight) + => throw new PlatformNotSupportedException(); + + protected internal override void Paint(Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum, + Brush backBrush, + Brush foreBrush, + bool alignToRight) + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool AllowNull { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler AllowNullChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected internal override void EnterNullValue() - { - // do not throw an exception when the column is marked as readOnly or - // does not allowNull - if (!AllowNull || IsReadOnly()) - return; - if (currentValue is not DBNull) - { - currentValue = Convert.DBNull; - Invalidate(); - } - } - - private void ResetNullValue() - { - NullValue = Convert.DBNull; - } - - private bool ShouldSerializeNullValue() - { - return nullValue is not DBNull; - } - - private void ToggleValue() - { - if (currentValue is bool && ((bool)currentValue) == false) - { - currentValue = true; - } - else - { - if (AllowNull) - { - if (Convert.IsDBNull(currentValue)) - { - currentValue = false; - } - else - { - currentValue = Convert.DBNull; - } - } - else - { - currentValue = false; - } - } - - // we started editing - isEditing = true; - // tell the dataGrid that things are changing - // we put Rectangle.Empty cause toggle will invalidate the row anyhow - DataGridTableStyle.DataGrid.ColumnStartedEditing(Rectangle.Empty); - } - - protected internal override void Paint(Graphics g1, Graphics g, Rectangle bounds, CurrencyManager source, int rowNum) => throw new NotImplementedException(); + => throw new PlatformNotSupportedException(); + + protected internal override void Paint(Graphics g1, + Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum) + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs index 00b0611251c..d323ffaad8f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs @@ -1,813 +1,30 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; -using System.Drawing; -using System.Drawing.Imaging; -using System.Globalization; -using System.Runtime.Versioning; - namespace System.Windows.Forms; #nullable disable +[Obsolete( + Obsoletions.DataGridCaptionMessage, + error: false, + DiagnosticId = Obsoletions.DataGridCaptionDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridCaption { - internal EventHandlerList events; - - private const int xOffset = 3; - private const int yOffset = 1; - private const int textPadding = 2; - private const int buttonToText = 4; - private static ColorMap[] colorMap = [new ColorMap()]; - - private static readonly Point minimumBounds = new Point(50, 30); - - private DataGrid dataGrid; - private bool backButtonVisible; - private bool downButtonVisible; - - private SolidBrush backBrush = DefaultBackBrush; - private SolidBrush foreBrush = DefaultForeBrush; - private Pen textBorderPen = DefaultTextBorderPen; - - private string text = ""; - private bool textBorderVisible; - private Font textFont; - - private Font dataGridFont; - - private bool backActive; - private bool downActive; - private bool backPressed; - private bool downPressed; - - // if the downButton should point down or not - private bool downButtonDown; - - private static Bitmap leftButtonBitmap; - private static Bitmap leftButtonBitmap_bidi; - private static Bitmap magnifyingGlassBitmap; - - private Rectangle backButtonRect; - private Rectangle downButtonRect; - private Rectangle textRect; - - private CaptionLocation lastMouseLocation = CaptionLocation.Nowhere; - - private EventEntry eventList; - private static readonly object EVENT_BACKWARDCLICKED = new object(); - private static readonly object EVENT_DOWNCLICKED = new object(); - private static readonly object EVENT_CAPTIONCLICKED = new object(); - - internal DataGridCaption(DataGrid dataGrid) - { - this.dataGrid = dataGrid; - downButtonVisible = dataGrid.ParentRowsVisible; - colorMap[0].OldColor = Color.White; - colorMap[0].NewColor = ForeColor; - OnGridFontChanged(); - } - - internal void OnGridFontChanged() - { - if (dataGridFont is null || !dataGridFont.Equals(dataGrid.Font)) - { - try - { - dataGridFont = new Font(dataGrid.Font, FontStyle.Bold); - } - catch - { - } - } - } - - internal bool BackButtonActive - { - get - { - return backActive; - } - set - { - if (backActive != value) - { - backActive = value; - InvalidateCaptionRect(backButtonRect); - } - } - } - - internal bool DownButtonActive - { - get - { - return downActive; - } - set - { - if (downActive != value) - { - downActive = value; - InvalidateCaptionRect(downButtonRect); - } - } - } - - internal static SolidBrush DefaultBackBrush - { - get - { - return (SolidBrush)SystemBrushes.ActiveCaption; - } - } - - internal static Pen DefaultTextBorderPen - { - get - { - return new Pen(SystemColors.ActiveCaptionText); - } - } - - internal static SolidBrush DefaultForeBrush - { - get - { - return (SolidBrush)SystemBrushes.ActiveCaptionText; - } - } - - internal Color BackColor - { - get - { - return backBrush.Color; - } - set - { - if (!backBrush.Color.Equals(value)) - { - if (value.IsEmpty) - throw new ArgumentException("SR.GetString(SR.DataGridEmptyColor)"); - backBrush = new SolidBrush(value); - Invalidate(); - } - } - } - - internal EventHandlerList Events - { - get - { - if (events is null) - { - events = new EventHandlerList(); - } - - return events; - } - } - - internal Font Font - { - get - { - if (textFont is null) - return dataGridFont; - else - return textFont; - } - set - { - if (textFont is null || !textFont.Equals(value)) - { - textFont = value; - // this property gets called in the constructor before dataGrid has a caption - // and we don't need this special-handling then... - if (dataGrid.Caption is not null) - { - dataGrid.RecalculateFonts(); - dataGrid.PerformLayout(); - dataGrid.Invalidate(); // smaller invalidate rect? - } - } - } - } - - internal bool ShouldSerializeFont() - { - return textFont is not null && !textFont.Equals(dataGridFont); - } - - internal bool ShouldSerializeBackColor() - { - return !backBrush.Equals(DefaultBackBrush); - } - - internal void ResetBackColor() - { - if (ShouldSerializeBackColor()) - { - backBrush = DefaultBackBrush; - Invalidate(); - } - } - - internal void ResetForeColor() - { - if (ShouldSerializeForeColor()) - { - foreBrush = DefaultForeBrush; - Invalidate(); - } - } - - internal bool ShouldSerializeForeColor() - { - return !foreBrush.Equals(DefaultForeBrush); - } - - internal void ResetFont() - { - textFont = null; - Invalidate(); - } - - internal string Text - { - get - { - return text; - } - set - { - if (value is null) - text = ""; - else - text = value; - Invalidate(); - } - } - - internal bool TextBorderVisible - { - get - { - return textBorderVisible; - } - set - { - textBorderVisible = value; - Invalidate(); - } - } - - internal Color ForeColor - { - get - { - return foreBrush.Color; - } - set - { - if (value.IsEmpty) - throw new ArgumentException("SR.GetString(SR.DataGridEmptyColor)"); - foreBrush = new SolidBrush(value); - colorMap[0].NewColor = ForeColor; - Invalidate(); - } - } - - internal static Point MinimumBounds - { - get - { - return minimumBounds; - } - } - - internal bool BackButtonVisible - { - get - { - return backButtonVisible; - } - set - { - if (backButtonVisible != value) - { - backButtonVisible = value; - Invalidate(); - } - } - } - - internal bool DownButtonVisible - { - get - { - return downButtonVisible; - } - set - { - if (downButtonVisible != value) - { - downButtonVisible = value; - Invalidate(); - } - } - } - protected virtual void AddEventHandler(object key, Delegate handler) - { - // Locking 'this' here is ok since this is an internal class. See VSW#464499. - lock (this) - { - if (handler is null) - return; - for (EventEntry e = eventList; e is not null; e = e.next) - { - if (e.key == key) - { - e.handler = Delegate.Combine(e.handler, handler); - return; - } - } - - eventList = new EventEntry(eventList, key, handler); - } - } - - /// - /// Adds a listener for the BackwardClicked event. - /// - internal event EventHandler BackwardClicked - { - add - { - Events.AddHandler(EVENT_BACKWARDCLICKED, value); - } - remove - { - Events.RemoveHandler(EVENT_BACKWARDCLICKED, value); - } - } - - /// - /// Adds a listener for the CaptionClicked event. - /// - internal event EventHandler CaptionClicked - { - add - { - Events.AddHandler(EVENT_CAPTIONCLICKED, value); - } - remove - { - Events.RemoveHandler(EVENT_CAPTIONCLICKED, value); - } - } - - internal event EventHandler DownClicked - { - add - { - Events.AddHandler(EVENT_DOWNCLICKED, value); - } - remove - { - Events.RemoveHandler(EVENT_DOWNCLICKED, value); - } - } - - private void Invalidate() - { - if (dataGrid is not null) - dataGrid.InvalidateCaption(); - } + => throw new PlatformNotSupportedException(); - private void InvalidateCaptionRect(Rectangle r) - { - if (dataGrid is not null) - dataGrid.InvalidateCaptionRect(r); - } + protected static void OnBackwardClicked(EventArgs e) + => throw new PlatformNotSupportedException(); - private void InvalidateLocation(CaptionLocation loc) - { - Rectangle r; - switch (loc) - { - case CaptionLocation.BackButton: - r = backButtonRect; - r.Inflate(1, 1); - InvalidateCaptionRect(r); - break; - case CaptionLocation.DownButton: - r = downButtonRect; - r.Inflate(1, 1); - InvalidateCaptionRect(r); - break; - } - } + protected static void OnCaptionClicked(EventArgs e) + => throw new PlatformNotSupportedException(); - protected void OnBackwardClicked(EventArgs e) - { - if (backActive) - { - EventHandler handler = (EventHandler)Events[EVENT_BACKWARDCLICKED]; - if (handler is not null) - handler(this, e); - } - } - - protected void OnCaptionClicked(EventArgs e) - { - EventHandler handler = (EventHandler)Events[EVENT_CAPTIONCLICKED]; - if (handler is not null) - handler(this, e); - } - - protected void OnDownClicked(EventArgs e) - { - if (downActive && downButtonVisible) - { - EventHandler handler = (EventHandler)Events[EVENT_DOWNCLICKED]; - if (handler is not null) - handler(this, e); - } - } - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - private static Bitmap GetBitmap(string bitmapName) - { - Bitmap b = null; - try - { - b = new Bitmap(typeof(DataGridCaption), bitmapName); - b.MakeTransparent(); - } - catch (Exception e) - { - Debug.Fail("Failed to load bitmap: " + bitmapName, e.ToString()); - } - - return b; - } - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - private static Bitmap GetBackButtonBmp(bool alignRight) - { - if (alignRight) - { - if (leftButtonBitmap_bidi is null) - leftButtonBitmap_bidi = GetBitmap("DataGridCaption.backarrow_bidi.bmp"); - return leftButtonBitmap_bidi; - } - else - { - if (leftButtonBitmap is null) - leftButtonBitmap = GetBitmap("DataGridCaption.backarrow.bmp"); - return leftButtonBitmap; - } - } - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - private static Bitmap GetDetailsBmp() - { - if (magnifyingGlassBitmap is null) - magnifyingGlassBitmap = GetBitmap("DataGridCaption.Details.bmp"); - return magnifyingGlassBitmap; - } + protected static void OnDownClicked(EventArgs e) + => throw new PlatformNotSupportedException(); protected virtual Delegate GetEventHandler(object key) - { - // Locking 'this' here is ok since this is an internal class. See VSW#464499. - lock (this) - { - for (EventEntry e = eventList; e is not null; e = e.next) - { - if (e.key == key) - return e.handler; - } - - return null; - } - } - - internal static Rectangle GetBackButtonRect(Rectangle bounds, bool alignRight, int downButtonWidth) - { - Bitmap backButtonBmp = GetBackButtonBmp(false); - Size backButtonSize; - lock (backButtonBmp) - { - backButtonSize = backButtonBmp.Size; - } - - return new Rectangle(bounds.Right - xOffset * 4 - downButtonWidth - backButtonSize.Width, - bounds.Y + yOffset + textPadding, - backButtonSize.Width, - backButtonSize.Height); - } - - internal static int GetDetailsButtonWidth() - { - int width = 0; - Bitmap detailsBmp = GetDetailsBmp(); - lock (detailsBmp) - { - width = detailsBmp.Size.Width; - } - - return width; - } - - internal static Rectangle GetDetailsButtonRect(Rectangle bounds, bool alignRight) - { - Size downButtonSize; - Bitmap detailsBmp = GetDetailsBmp(); - lock (detailsBmp) - { - downButtonSize = detailsBmp.Size; - } - - int downButtonWidth = downButtonSize.Width; - return new Rectangle(bounds.Right - xOffset * 2 - downButtonWidth, - bounds.Y + yOffset + textPadding, - downButtonWidth, - downButtonSize.Height); - } - - /// - /// Called by the dataGrid when it needs the caption - /// to repaint. - /// - internal void Paint(Graphics g, Rectangle bounds, bool alignRight) - { - Size textSize = new Size((int)g.MeasureString(text, Font).Width + 2, Font.Height + 2); - - downButtonRect = GetDetailsButtonRect(bounds, alignRight); - int downButtonWidth = GetDetailsButtonWidth(); - backButtonRect = GetBackButtonRect(bounds, alignRight, downButtonWidth); - - int backButtonArea = backButtonVisible ? backButtonRect.Width + xOffset + buttonToText : 0; - int downButtonArea = downButtonVisible && !dataGrid.ParentRowsIsEmpty() ? downButtonWidth + xOffset + buttonToText : 0; - - int textWidthLeft = bounds.Width - xOffset - backButtonArea - downButtonArea; - - textRect = new Rectangle( - bounds.X, - bounds.Y + yOffset, - Math.Min(textWidthLeft, 2 * textPadding + textSize.Width), - 2 * textPadding + textSize.Height); - - // align the caption text box, downButton, and backButton - // if the RigthToLeft property is set to true - if (alignRight) - { - textRect.X = bounds.Right - textRect.Width; - backButtonRect.X = bounds.X + xOffset * 4 + downButtonWidth; - downButtonRect.X = bounds.X + xOffset * 2; - } - - Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "text size = " + textSize.ToString()); - Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "downButtonWidth = " + downButtonWidth.ToString(CultureInfo.InvariantCulture)); - Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "textWidthLeft = " + textWidthLeft.ToString(CultureInfo.InvariantCulture)); - Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "backButtonRect " + backButtonRect.ToString()); - Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "textRect " + textRect.ToString()); - Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "downButtonRect " + downButtonRect.ToString()); - - // we should use the code that is commented out - // with today's code, there are pixels on the backButtonRect and the downButtonRect - // that are getting painted twice - g.FillRectangle(backBrush, bounds); - - if (backButtonVisible) - { - PaintBackButton(g, backButtonRect, alignRight); - if (backActive) - { - if (lastMouseLocation == CaptionLocation.BackButton) - { - backButtonRect.Inflate(1, 1); - ControlPaint.DrawBorder3D(g, backButtonRect, - backPressed ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner); - } - } - } - - PaintText(g, textRect, alignRight); - - if (downButtonVisible && !dataGrid.ParentRowsIsEmpty()) - { - PaintDownButton(g, downButtonRect); - // the rules have changed, yet again. - // now: if we show the parent rows and the mouse is - // not on top of this icon, then let the icon be depressed. - // if the mouse is pressed over the icon, then show the icon pressed - // if the mouse is over the icon and not pressed, then show the icon SunkenInner; - if (lastMouseLocation == CaptionLocation.DownButton) - { - downButtonRect.Inflate(1, 1); - ControlPaint.DrawBorder3D(g, downButtonRect, - downPressed ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner); - } - } - } - - private static void PaintIcon(Graphics g, Rectangle bounds, Bitmap b) - { - ImageAttributes attr = new ImageAttributes(); - attr.SetRemapTable(colorMap, ColorAdjustType.Bitmap); - g.DrawImage(b, bounds, 0, 0, bounds.Width, bounds.Height, GraphicsUnit.Pixel, attr); - attr.Dispose(); - } - - private static void PaintBackButton(Graphics g, Rectangle bounds, bool alignRight) - { - Bitmap backButtonBmp = GetBackButtonBmp(alignRight); - lock (backButtonBmp) - { - PaintIcon(g, bounds, backButtonBmp); - } - } - - private static void PaintDownButton(Graphics g, Rectangle bounds) - { - Bitmap detailsBmp = GetDetailsBmp(); - lock (detailsBmp) - { - PaintIcon(g, bounds, detailsBmp); - } - } - - private void PaintText(Graphics g, Rectangle bounds, bool alignToRight) - { - Rectangle textBounds = bounds; - - if (textBounds.Width <= 0 || textBounds.Height <= 0) - return; - - if (textBorderVisible) - { - g.DrawRectangle(textBorderPen, textBounds.X, textBounds.Y, textBounds.Width - 1, textBounds.Height - 1); - textBounds.Inflate(-1, -1); - } - - if (textPadding > 0) - { - Rectangle border = textBounds; - border.Height = textPadding; - g.FillRectangle(backBrush, border); - - border.Y = textBounds.Bottom - textPadding; - g.FillRectangle(backBrush, border); - - border = new Rectangle(textBounds.X, textBounds.Y + textPadding, - textPadding, textBounds.Height - 2 * textPadding); - g.FillRectangle(backBrush, border); - - border.X = textBounds.Right - textPadding; - g.FillRectangle(backBrush, border); - textBounds.Inflate(-textPadding, -textPadding); - } - - g.FillRectangle(backBrush, textBounds); - - // Brush foreBrush = new SolidBrush(dataGrid.CaptionForeColor); - StringFormat format = new StringFormat(); - if (alignToRight) - { - format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; - format.Alignment = StringAlignment.Far; - } - - g.DrawString(text, Font, foreBrush, textBounds, format); - format.Dispose(); - // foreBrush.Dispose(); - } - - private CaptionLocation FindLocation(int x, int y) - { - if (!backButtonRect.IsEmpty) - { - if (backButtonRect.Contains(x, y)) - return CaptionLocation.BackButton; - } - - if (!downButtonRect.IsEmpty) - { - if (downButtonRect.Contains(x, y)) - return CaptionLocation.DownButton; - } - - if (!textRect.IsEmpty) - { - if (textRect.Contains(x, y)) - return CaptionLocation.Text; - } - - return CaptionLocation.Nowhere; - } - - private bool DownButtonDown - { - get - { - return downButtonDown; - } - set - { - if (downButtonDown != value) - { - downButtonDown = value; - InvalidateLocation(CaptionLocation.DownButton); - } - } - } - - internal bool GetDownButtonDirection() - { - return DownButtonDown; - } - - /// - /// Called by the dataGrid when the mouse is pressed - /// inside the caption. - /// - internal void MouseDown(int x, int y) - { - CaptionLocation loc = FindLocation(x, y); - switch (loc) - { - case CaptionLocation.BackButton: - backPressed = true; - InvalidateLocation(loc); - break; - case CaptionLocation.DownButton: - downPressed = true; - InvalidateLocation(loc); - break; - case CaptionLocation.Text: - OnCaptionClicked(EventArgs.Empty); - break; - } - } - - /// - /// Called by the dataGrid when the mouse is released - /// inside the caption. - /// - internal void MouseUp(int x, int y) - { - CaptionLocation loc = FindLocation(x, y); - switch (loc) - { - case CaptionLocation.DownButton: - if (downPressed) - { - downPressed = false; - OnDownClicked(EventArgs.Empty); - } - - break; - case CaptionLocation.BackButton: - if (backPressed) - { - backPressed = false; - OnBackwardClicked(EventArgs.Empty); - } - - break; - } - } - - /// - /// Called by the dataGrid when the mouse leaves - /// the caption area. - /// - internal void MouseLeft() - { - CaptionLocation oldLoc = lastMouseLocation; - lastMouseLocation = CaptionLocation.Nowhere; - InvalidateLocation(oldLoc); - } - - /// - /// Called by the dataGrid when the mouse is - /// inside the caption. - /// - internal void MouseOver(int x, int y) - { - CaptionLocation newLoc = FindLocation(x, y); - - InvalidateLocation(lastMouseLocation); - InvalidateLocation(newLoc); - lastMouseLocation = newLoc; - } + => throw new PlatformNotSupportedException(); protected virtual void RaiseEvent(object key, EventArgs e) { @@ -817,73 +34,8 @@ protected virtual void RaiseEvent(object key, EventArgs e) } protected virtual void RemoveEventHandler(object key, Delegate handler) - { - // Locking 'this' here is ok since this is an internal class. See VSW#464499. - lock (this) - { - if (handler is null) - return; - for (EventEntry e = eventList, prev = null; e is not null; prev = e, e = e.next) - { - if (e.key == key) - { - e.handler = Delegate.Remove(e.handler, handler); - if (e.handler is null) - { - if (prev is null) - { - eventList = e.next; - } - else - { - prev.next = e.next; - } - } - - return; - } - } - } - } + => throw new PlatformNotSupportedException(); protected virtual void RemoveEventHandlers() - { - eventList = null; - } - - internal void SetDownButtonDirection(bool pointDown) - { - DownButtonDown = pointDown; - } - - /// - /// Toggles the direction the "Down Button" is pointing. - /// - internal bool ToggleDownButtonDirection() - { - DownButtonDown = !DownButtonDown; - return DownButtonDown; - } - - internal enum CaptionLocation - { - Nowhere, - BackButton, - DownButton, - Text - } - - private sealed class EventEntry - { - internal EventEntry next; - internal object key; - internal Delegate handler; - - internal EventEntry(EventEntry next, object key, Delegate handler) - { - this.next = next; - this.key = key; - this.handler = handler; - } - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs index e1255252830..c2084eeeafc 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs @@ -5,69 +5,50 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 #nullable disable -[Obsolete("DataGridCell has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.DataGridCellMessage, + error: false, + DiagnosticId = Obsoletions.DataGridCellDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public struct DataGridCell : IEquatable { - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int ColumnNumber { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + readonly get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int RowNumber { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + readonly get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public DataGridCell(int r, int c) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - public override bool Equals(object o) - { - throw new PlatformNotSupportedException(); - } + public override readonly bool Equals(object obj) + => throw new PlatformNotSupportedException(); - public override int GetHashCode() - { - throw new PlatformNotSupportedException(); - } + public override readonly int GetHashCode() + => throw new PlatformNotSupportedException(); - public override string ToString() - { - throw new PlatformNotSupportedException(); - } + public override readonly string ToString() + => throw new PlatformNotSupportedException(); - public bool Equals(DataGridCell other) - { - throw new NotImplementedException(); - } + public readonly bool Equals(DataGridCell other) + => throw new PlatformNotSupportedException(); public static bool operator ==(DataGridCell left, DataGridCell right) - { - return left.Equals(right); - } + => throw new PlatformNotSupportedException(); public static bool operator !=(DataGridCell left, DataGridCell right) - { - return !(left == right); - } + => !(left == right); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs index 3feff3cf676..5a05fa81284 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs @@ -1,437 +1,192 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections; using System.ComponentModel; using System.Drawing; -using System.Security.Permissions; namespace System.Windows.Forms; -#pragma warning disable RS0016 #nullable disable -[Obsolete("DataGridColumnStyle has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.DataGridColumnStyleMessage, + error: false, + DiagnosticId = Obsoletions.DataGridColumnStyleDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public abstract class DataGridColumnStyle : Component, IDataGridColumnStyleEditingNotificationService { - private DataGridTableStyle dataGridTableStyle; - internal int fontHeight = -1; - private string mappingName = ""; - private string headerName = ""; - private bool invalid; - private string nullText = "SR.GetString(SR.DataGridNullText)"; - private bool updating; - internal int width = -1; - private bool isDefault; - private static readonly object EventAlignment = new object(); - private static readonly object EventPropertyDescriptor = new object(); - private static readonly object EventHeaderText = new object(); - private static readonly object EventMappingName = new object(); - private static readonly object EventNullText = new object(); - private static readonly object EventReadOnly = new object(); - private static readonly object EventWidth = new object(); - public DataGridColumnStyle() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] // Shipped like this in Everett. public DataGridColumnStyle(PropertyDescriptor prop) : this() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); internal DataGridColumnStyle(PropertyDescriptor prop, bool isDefault) : this(prop) - { - this.isDefault = isDefault; - if (isDefault) - { - // take the header name from the property name - headerName = prop.Name; - mappingName = prop.Name; - } - } - -#if DEBUG - internal bool IsDefault - { - get - { - return isDefault; - } - } -#endif // debug + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual HorizontalAlignment Alignment { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler AlignmentChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - // PM team has reviewed and decided on naming changes already - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] protected internal virtual void UpdateUI(CurrencyManager source, int rowNum, string displayText) { } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public AccessibleObject HeaderAccessibleObject { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual PropertyDescriptor PropertyDescriptor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler PropertyDescriptorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected virtual AccessibleObject CreateHeaderAccessibleObject() - { - return new DataGridColumnHeaderAccessibleObject(this); - } + => throw new PlatformNotSupportedException(); protected virtual void SetDataGrid(DataGrid value) - { - SetDataGridInColumn(value); - } + => SetDataGridInColumn(value); protected virtual void SetDataGridInColumn(DataGrid value) { - // we need to set up the PropertyDescriptor - if (PropertyDescriptor is null && value is not null) - { - CurrencyManager lm = value.ListManager; - if (lm is null) - return; - PropertyDescriptorCollection propCollection = lm.GetItemProperties(); - int propCount = propCollection.Count; - for (int i = 0; i < propCollection.Count; i++) - { - PropertyDescriptor prop = propCollection[i]; - if (!typeof(IList).IsAssignableFrom(prop.PropertyType) && prop.Name.Equals(HeaderText)) - { - PropertyDescriptor = prop; - return; - } - } - } - } - - internal void SetDataGridInternalInColumn(DataGrid value) - { - if (value is null || value.Initializing) - return; - SetDataGridInColumn(value); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual DataGridTableStyle DataGridTableStyle { - get - { - throw new PlatformNotSupportedException(); - } - } - - internal void SetDataGridTableInColumn(DataGridTableStyle value, bool force) - { - if (dataGridTableStyle is not null && dataGridTableStyle.Equals(value) && !force) - return; - if (value is not null) - { - if (value.DataGrid is not null && !value.DataGrid.Initializing) - { - SetDataGridInColumn(value.DataGrid); - } - } - - dataGridTableStyle = value; + get => throw new PlatformNotSupportedException(); } protected int FontHeight { - get - { - if (fontHeight != -1) - { - return fontHeight; - } - else if (DataGridTableStyle is not null) - { - return DataGridTableStyle.DataGrid.FontHeight; - } - else - { - return DataGridTableStyle.defaultFontHeight; - } - } - } - - /// - /// - /// Indicates whether the Font property should be persisted. - /// - /// - private bool ShouldSerializeFont() - { - return false; + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler FontChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual string HeaderText { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler HeaderTextChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string MappingName { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler MappingNameChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - private bool ShouldSerializeHeaderText() - { - return (headerName.Length != 0); + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } public void ResetHeaderText() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual string NullText { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler NullTextChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual bool ReadOnly { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler ReadOnlyChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } -#if false - /// - /// - /// - /// Gets or sets a value indicating whether the column is visible. - /// - /// - [DefaultValue(true)] - public virtual bool Visible { - get { - return visible; - } - set { - if (visible == value) - return; - visible = value; - RaisePropertyChanged(EventArgs.Empty"Visible"); - Invalidate(); - } - } -#endif - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual int Width { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler WidthChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected void BeginUpdate() { - updating = true; } protected void EndUpdate() { - updating = false; - if (invalid) - { - invalid = false; - Invalidate(); - } - } - - internal virtual bool WantArrows - { - get - { - return false; - } - } - - internal virtual string GetDisplayText(object value) - { - return value.ToString(); - } - - private void ResetNullText() - { - NullText = "SR.GetString(SR.DataGridNullText)"; - } - - private bool ShouldSerializeNullText() - { - return (!"SR.GetString(SR.DataGridNullText)".Equals(nullText)); } protected internal abstract Size GetPreferredSize(Graphics g, object value); @@ -440,8 +195,6 @@ private bool ShouldSerializeNullText() protected internal abstract int GetPreferredHeight(Graphics g, object value); - // PM team has reviewed and decided on naming changes already - [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] protected internal virtual object GetColumnValueAtRow(CurrencyManager source, int rowNum) { CheckValidDataSource(source); @@ -456,184 +209,73 @@ protected internal virtual object GetColumnValueAtRow(CurrencyManager source, in protected virtual void Invalidate() { - if (updating) - { - invalid = true; - return; - } - - DataGridTableStyle table = DataGridTableStyle; - if (table is not null) - table.InvalidateColumn(this); } protected void CheckValidDataSource(CurrencyManager value) { - if (value is null) - { - throw new ArgumentNullException("DataGridColumnStyle.CheckValidDataSource(DataSource value), value is null"); - } - - PropertyDescriptor myPropDesc = PropertyDescriptor; - if (myPropDesc is null) - { - throw new InvalidOperationException("SR.GetString(SR.DataGridColumnUnbound, HeaderText)"); - } - -#if false - DataTable myDataTable = myTable.DataTable; - if (myDataColumn.Table != myDataTable) { - throw new InvalidOperationException(SR.GetString(SR.DataGridColumnDataSourceMismatch, Header)); - } - - /* FOR DEMO: danielhe: DataGridColumnStyle::CheckValidDataSource: make the check better */ - if (((DataView) value.DataSource).Table is null) { - throw new InvalidOperationException(SR.GetString(SR.DataGridColumnNoDataTable, Header)); - } - else { - /* FOR DEMO: danielhe: DataGridColumnStyle::CheckValidDataSource: make the check better */ - if (!myTable.DataTable.Equals(((DataView) value.DataSource).Table)) { - throw new InvalidOperationException(SR.GetString(SR.DataGridColumnNoDataSource, Header, myTable.DataTable.TableName)); - } - } -#endif // false } - // PM team has reviewed and decided on naming changes already protected internal abstract void Abort(int rowNum); - // PM team has reviewed and decided on naming changes already protected internal abstract bool Commit(CurrencyManager dataSource, int rowNum); protected internal virtual void Edit(CurrencyManager source, - int rowNum, - Rectangle bounds, - bool readOnly) - { - Edit(source, rowNum, bounds, readOnly, null, true); - } + int rowNum, + Rectangle bounds, + bool readOnly) + => Edit(source, rowNum, bounds, readOnly, null, true); protected internal virtual void Edit(CurrencyManager source, - int rowNum, - Rectangle bounds, - bool readOnly, - string displayText) - { - Edit(source, rowNum, bounds, readOnly, displayText, true); - } + int rowNum, + Rectangle bounds, + bool readOnly, + string displayText) + => Edit(source, rowNum, bounds, readOnly, displayText, true); protected internal abstract void Edit(CurrencyManager source, - int rowNum, - Rectangle bounds, - bool readOnly, - string displayText, - bool cellIsVisible); - - internal virtual bool MouseDown(int rowNum, int x, int y) - { - return false; - } + int rowNum, + Rectangle bounds, + bool readOnly, + string displayText, + bool cellIsVisible); protected internal virtual void EnterNullValue() { } - internal virtual bool KeyPress(int rowNum, Keys keyData) - { - // if this is read only then do not do anything - if (ReadOnly || (DataGridTableStyle is not null && DataGridTableStyle.DataGrid is not null && DataGridTableStyle.DataGrid.ReadOnly)) - return false; - if (keyData == (Keys.Control | Keys.NumPad0) || keyData == (Keys.Control | Keys.D0)) - { - EnterNullValue(); - return true; - } - - return false; - } - protected internal virtual void ConcedeFocus() { } - protected internal abstract void Paint(Drawing.Graphics g1, Graphics g, Rectangle bounds, CurrencyManager source, int rowNum); + protected internal abstract void Paint(Graphics g1, + Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum); - protected internal abstract void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight); + protected internal abstract void Paint(Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum, + bool alignToRight); - protected internal virtual void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, - Brush backBrush, Brush foreBrush, bool alignToRight) - { - Paint(g, bounds, source, rowNum, alignToRight); - } - - private void OnPropertyDescriptorChanged(EventArgs e) - { - EventHandler eh = Events[EventPropertyDescriptor] as EventHandler; - if (eh is not null) - eh(this, e); - } - - private void OnAlignmentChanged(EventArgs e) - { - EventHandler eh = Events[EventAlignment] as EventHandler; - if (eh is not null) - eh(this, e); - } - - private void OnHeaderTextChanged(EventArgs e) - { - EventHandler eh = Events[EventHeaderText] as EventHandler; - if (eh is not null) - eh(this, e); - } - - private void OnMappingNameChanged(EventArgs e) - { - EventHandler eh = Events[EventMappingName] as EventHandler; - if (eh is not null) - eh(this, e); - } - - private void OnReadOnlyChanged(EventArgs e) - { - EventHandler eh = Events[EventReadOnly] as EventHandler; - if (eh is not null) - eh(this, e); - } - - private void OnNullTextChanged(EventArgs e) - { - EventHandler eh = Events[EventNullText] as EventHandler; - if (eh is not null) - eh(this, e); - } - - private void OnWidthChanged(EventArgs e) - { - EventHandler eh = Events[EventWidth] as EventHandler; - if (eh is not null) - eh(this, e); - } + protected internal virtual void Paint(Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum, + Brush backBrush, + Brush foreBrush, + bool alignToRight) + => Paint(g, bounds, source, rowNum, alignToRight); protected internal virtual void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) { CheckValidDataSource(source); - - if (source.Position != rowNum) - throw new ArgumentException("SR.GetString(SR.DataGridColumnListManagerPosition)"); - if (source[rowNum] is IEditableObject) - ((IEditableObject)source[rowNum]).BeginEdit(); PropertyDescriptor.SetValue(source[rowNum], value); } - internal protected virtual void ColumnStartedEditing(Control editingControl) - { - DataGridTableStyle.DataGrid.ColumnStartedEditing(editingControl); - } - void IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control editingControl) { - ColumnStartedEditing(editingControl); } protected internal virtual void ReleaseHostedControl() @@ -642,31 +284,29 @@ protected internal virtual void ReleaseHostedControl() protected class CompModSwitches { - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public static TraceSwitch DGEditColumnEditing { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } } - [Runtime.InteropServices.ComVisible(true)] - [Obsolete("DataGridColumnHeaderAccessibleObject has been deprecated.")] + [Obsolete( + Obsoletions.DataGridColumnHeaderAccessibleObjectMessage, + error: false, + DiagnosticId = Obsoletions.DataGridColumnHeaderAccessibleObjectDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridColumnHeaderAccessibleObject : AccessibleObject { public DataGridColumnHeaderAccessibleObject(DataGridColumnStyle owner) : this() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public DataGridColumnHeaderAccessibleObject() : base() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds { get @@ -675,47 +315,35 @@ public override Rectangle Bounds } } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Name { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] protected DataGridColumnStyle Owner { get; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent { - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] - get - { - throw new PlatformNotSupportedException(); - } - } - - private DataGrid DataGrid - { - get; + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } public override AccessibleObject Navigate(AccessibleNavigation navdir) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridLineStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridLineStyle.cs index 85c9da6a1e8..79f3e28ed84 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridLineStyle.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridLineStyle.cs @@ -1,16 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; #pragma warning disable RS0016 -[Obsolete("DataGridLineStyle has been deprecated.")] +[Obsolete( + Obsoletions.DataGridLineStyleMessage, + error: false, + DiagnosticId = Obsoletions.DataGridLineStyleDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public enum DataGridLineStyle { - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] None, - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Solid } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs index 7c5d8da6c97..dde10248a8f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs @@ -1,1136 +1,103 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections; using System.ComponentModel; using System.Drawing; -using System.Drawing.Imaging; using System.Runtime.InteropServices; -using System.Runtime.Versioning; -using System.Text; namespace System.Windows.Forms; #nullable disable -[Obsolete("DataGridParentRows has been deprecated.")] +[Obsolete( + Obsoletions.DataGridParentRowsMessage, + error: false, + DiagnosticId = Obsoletions.DataGridParentRowsDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridParentRows { - // siting - private DataGrid dataGrid; - - private SolidBrush backBrush = DataGrid.DefaultParentRowsBackBrush; - private SolidBrush foreBrush = DataGrid.DefaultParentRowsForeBrush; - - private int borderWidth = 1; - // private Color borderColor = SystemColors.WindowFrame; - private Brush borderBrush = new SolidBrush(SystemColors.WindowFrame); - - private static Bitmap rightArrow; - private static Bitmap leftArrow; - - private ColorMap[] colorMap = [new ColorMap()]; - - private Pen gridLinePen = SystemPens.Control; - - private int totalHeight; - private int textRegionHeight; - - // now that we have left and right arrows, we also have layout - private Layout layout = new Layout(); - private bool downLeftArrow; - private bool downRightArrow; - - private int horizOffset; - - // storage for parent row states - // - private ArrayList parents = new ArrayList(); - private int parentsCount; - private ArrayList rowHeights = new ArrayList(); - - internal DataGridParentRows(DataGrid dataGrid) - { - colorMap[0].OldColor = Color.Black; - this.dataGrid = dataGrid; - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public AccessibleObject AccessibleObject { - get - { - throw new PlatformNotSupportedException(); - } - } - - internal Color BackColor - { - get - { - return backBrush.Color; - } - set - { - if (value.IsEmpty) - throw new ArgumentException("SR.GetString(SR.DataGridEmptyColor)"); - if (value != backBrush.Color) - { - backBrush = new SolidBrush(value); - Invalidate(); - } - } - } - - internal SolidBrush BackBrush - { - get - { - return backBrush; - } - set - { - if (value != backBrush) - { - CheckNull(value, "BackBrush"); - backBrush = value; - Invalidate(); - } - } - } - - internal SolidBrush ForeBrush - { - get - { - return foreBrush; - } - set - { - if (value != foreBrush) - { - CheckNull(value, "BackBrush"); - foreBrush = value; - Invalidate(); - } - } - } - - internal Rectangle GetBoundsForDataGridStateAccesibility(DataGridState dgs) - { - Rectangle ret = Rectangle.Empty; - int rectY = 0; - for (int i = 0; i < parentsCount; i++) - { - int height = (int)rowHeights[i]; - if (parents[i] == dgs) - { - ret.X = layout.leftArrow.IsEmpty ? layout.data.X : layout.leftArrow.Right; - ret.Height = height; - ret.Y = rectY; - ret.Width = layout.data.Width; - return ret; - } - - rectY += height; - } - - return ret; - } - - internal Brush BorderBrush - { - get - { - return borderBrush; - } - set - { - if (value != borderBrush) - { - borderBrush = value; - Invalidate(); - } - } - } - - internal int Height - { - get - { - return totalHeight; - } - } - - internal Color ForeColor - { - get - { - return foreBrush.Color; - } - set - { - if (value.IsEmpty) - throw new ArgumentException("SR.GetString(SR.DataGridEmptyColor)"); - if (value != foreBrush.Color) - { - foreBrush = new SolidBrush(value); - Invalidate(); - } - } - } - - internal bool Visible - { - get - { - return dataGrid.ParentRowsVisible; - } - set - { - dataGrid.ParentRowsVisible = value; - } - } - - internal void AddParent(DataGridState dgs) - { - CurrencyManager childDataSource = (CurrencyManager)dataGrid.BindingContext[dgs.DataSource, dgs.DataMember]; - parents.Add(dgs); - SetParentCount(parentsCount + 1); - Debug.Assert(GetTopParent() is not null, "we should have a parent at least"); - } - - internal void Clear() - { - for (int i = 0; i < parents.Count; i++) - { - DataGridState dgs = parents[i] as DataGridState; - dgs.RemoveChangeNotification(); - } - - parents.Clear(); - rowHeights.Clear(); - totalHeight = 0; - SetParentCount(0); - } - - internal void SetParentCount(int count) - { - parentsCount = count; - dataGrid.Caption.BackButtonVisible = (parentsCount > 0) && (dataGrid.AllowNavigation); - } - - internal void CheckNull(object value, string propName) - { - if (value is null) - throw new ArgumentNullException(); - } - - internal void Dispose() - { - gridLinePen.Dispose(); - } - - internal DataGridState GetTopParent() - { - if (parentsCount < 1) - { - return null; - } - - return (DataGridState)(((ICloneable)(parents[parentsCount - 1])).Clone()); - } - - internal bool IsEmpty() - { - return parentsCount == 0; - } - - internal DataGridState PopTop() - { - if (parentsCount < 1) - { - return null; - } - - SetParentCount(parentsCount - 1); - DataGridState ret = (DataGridState)parents[parentsCount]; - ret.RemoveChangeNotification(); - parents.RemoveAt(parentsCount); - return ret; - } - - internal void Invalidate() - { - if (dataGrid is not null) - dataGrid.InvalidateParentRows(); - } - - internal void InvalidateRect(Rectangle rect) - { - if (dataGrid is not null) - { - Rectangle r = new Rectangle(rect.X, rect.Y, rect.Width + borderWidth, rect.Height + borderWidth); - dataGrid.InvalidateParentRowsRect(r); - } - } - - internal void OnLayout() - { - if (parentsCount == rowHeights.Count) - return; - - int height = 0; - if (totalHeight == 0) - { - totalHeight += 2 * borderWidth; - } - - textRegionHeight = (int)dataGrid.Font.Height + 2; - - if (parentsCount > rowHeights.Count) - { - Debug.Assert(parentsCount == rowHeights.Count + 1 || rowHeights.Count == 0, "see bug 82808 for more info, or the comment above"); - int rowHeightsCount = rowHeights.Count; - for (int i = rowHeightsCount; i < parentsCount; i++) - { - DataGridState dgs = (DataGridState)parents[i]; - GridColumnStylesCollection cols = dgs.GridColumnStyles; - - int colsHeight = 0; - - for (int j = 0; j < cols.Count; j++) - { - colsHeight = Math.Max(colsHeight, cols[j].GetMinimumHeight()); - } - - height = Math.Max(colsHeight, textRegionHeight); - - // the height of the bottom border - height++; - rowHeights.Add(height); - - totalHeight += height; - } - } - else - { - Debug.Assert(parentsCount == rowHeights.Count - 1, "we do layout only for push/popTop"); - if (parentsCount == 0) - totalHeight = 0; - else - totalHeight -= (int)rowHeights[rowHeights.Count - 1]; - rowHeights.RemoveAt(rowHeights.Count - 1); - } - } - - private int CellCount() - { - int cellCount = 0; - cellCount = ColsCount(); - - if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.TableName || - dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) - { - cellCount++; - } - - return cellCount; - } - - private void ResetMouseInfo() - { - downLeftArrow = false; - downRightArrow = false; - } - - private void LeftArrowClick(int cellCount) - { - if (horizOffset > 0) - { - ResetMouseInfo(); - horizOffset -= 1; - Invalidate(); - } - else - { - ResetMouseInfo(); - InvalidateRect(layout.leftArrow); - } - } - - private void RightArrowClick(int cellCount) - { - if (horizOffset < cellCount - 1) - { - ResetMouseInfo(); - horizOffset += 1; - Invalidate(); - } - else - { - ResetMouseInfo(); - InvalidateRect(layout.rightArrow); - } - } - - internal void OnMouseDown(int x, int y, bool alignToRight) - { - if (layout.rightArrow.IsEmpty) - { - Debug.Assert(layout.leftArrow.IsEmpty, "we can't have the leftArrow w/o the rightArrow"); - return; - } - - int cellCount = CellCount(); - - if (layout.rightArrow.Contains(x, y)) - { - downRightArrow = true; - - if (alignToRight) - LeftArrowClick(cellCount); - else - RightArrowClick(cellCount); - } - else if (layout.leftArrow.Contains(x, y)) - { - downLeftArrow = true; - - if (alignToRight) - RightArrowClick(cellCount); - else - LeftArrowClick(cellCount); - } - else - { - if (downLeftArrow) - { - downLeftArrow = false; - InvalidateRect(layout.leftArrow); - } - - if (downRightArrow) - { - downRightArrow = false; - InvalidateRect(layout.rightArrow); - } - } - } - - internal void OnMouseLeave() - { - if (downLeftArrow) - { - downLeftArrow = false; - InvalidateRect(layout.leftArrow); - } - - if (downRightArrow) - { - downRightArrow = false; - InvalidateRect(layout.rightArrow); - } - } - - internal void OnMouseMove(int x, int y) - { - if (downLeftArrow) - { - downLeftArrow = false; - InvalidateRect(layout.leftArrow); - } - - if (downRightArrow) - { - downRightArrow = false; - InvalidateRect(layout.rightArrow); - } - } - - internal void OnMouseUp(int x, int y) - { - ResetMouseInfo(); - if (!layout.rightArrow.IsEmpty && layout.rightArrow.Contains(x, y)) - { - InvalidateRect(layout.rightArrow); - return; - } - - if (!layout.leftArrow.IsEmpty && layout.leftArrow.Contains(x, y)) - { - InvalidateRect(layout.leftArrow); - return; - } - } - - internal void OnResize(Rectangle oldBounds) - { - Invalidate(); - } - - internal void Paint(Graphics g, Rectangle visualbounds, bool alignRight) - { - Rectangle bounds = visualbounds; - // Paint the border around our bounds - if (borderWidth > 0) - { - PaintBorder(g, bounds); - bounds.Inflate(-borderWidth, -borderWidth); - } - - PaintParentRows(g, bounds, alignRight); - } - - private void PaintBorder(Graphics g, Rectangle bounds) - { - Rectangle border = bounds; - - // top - border.Height = borderWidth; - g.FillRectangle(borderBrush, border); - - // bottom - border.Y = bounds.Bottom - borderWidth; - g.FillRectangle(borderBrush, border); - - // left - border = new Rectangle(bounds.X, bounds.Y + borderWidth, - borderWidth, bounds.Height - 2 * borderWidth); - g.FillRectangle(borderBrush, border); - - // right - border.X = bounds.Right - borderWidth; - g.FillRectangle(borderBrush, border); - } - - private int GetTableBoxWidth(Graphics g, Font font) - { - // try to make the font BOLD - Font textFont = font; - try - { - textFont = new Font(font, FontStyle.Bold); - } - catch - { - } - - int width = 0; - for (int row = 0; row < parentsCount; row++) - { - DataGridState dgs = (DataGridState)parents[row]; - // Graphics.MeasureString(...) returns different results for ": " than for " :" - // - string displayTableName = dgs.ListManager.GetListName() + " :"; - int size = (int)g.MeasureString(displayTableName, textFont).Width; - width = Math.Max(size, width); - } - - return width; - } - - private int GetColBoxWidth(Graphics g, Font font, int colNum) - { - int width = 0; - - for (int row = 0; row < parentsCount; row++) - { - DataGridState dgs = (DataGridState)parents[row]; - GridColumnStylesCollection columns = dgs.GridColumnStyles; - if (colNum < columns.Count) - { - // Graphics.MeasureString(...) returns different results for ": " than for " :" - string colName = columns[colNum].HeaderText + " :"; - int size = (int)g.MeasureString(colName, font).Width; - width = Math.Max(size, width); - } - } - - return width; - } - - private int GetColDataBoxWidth(Graphics g, int colNum) - { - int width = 0; - for (int row = 0; row < parentsCount; row++) - { - DataGridState dgs = (DataGridState)parents[row]; - GridColumnStylesCollection columns = dgs.GridColumnStyles; - if (colNum < columns.Count) - { - object value = columns[colNum].GetColumnValueAtRow((CurrencyManager)dataGrid.BindingContext[dgs.DataSource, dgs.DataMember], - dgs.LinkingRow.RowNumber); - int size = columns[colNum].GetPreferredSize(g, value).Width; - width = Math.Max(size, width); - } - } - - return width; - } - - private int ColsCount() - { - int colNum = 0; - for (int row = 0; row < parentsCount; row++) - { - DataGridState dgs = (DataGridState)parents[row]; - colNum = Math.Max(colNum, dgs.GridColumnStyles.Count); - } - - return colNum; - } - - private int TotalWidth(int tableNameBoxWidth, int[] colsNameWidths, int[] colsDataWidths) - { - int totalWidth = 0; - totalWidth += tableNameBoxWidth; - Debug.Assert(colsNameWidths.Length == colsDataWidths.Length, "both arrays are as long as the largest column count in dgs"); - for (int i = 0; i < colsNameWidths.Length; i++) - { - totalWidth += colsNameWidths[i]; - totalWidth += colsDataWidths[i]; - } - - totalWidth += 3 * (colsNameWidths.Length - 1); - return totalWidth; - } - - private void ComputeLayout(Rectangle bounds, int tableNameBoxWidth, int[] colsNameWidths, int[] colsDataWidths) - { - int totalWidth = TotalWidth(tableNameBoxWidth, colsNameWidths, colsDataWidths); - if (totalWidth > bounds.Width) - { - layout.leftArrow = new Rectangle(bounds.X, bounds.Y, 15, bounds.Height); - layout.data = new Rectangle(layout.leftArrow.Right, bounds.Y, bounds.Width - 30, bounds.Height); - layout.rightArrow = new Rectangle(layout.data.Right, bounds.Y, 15, bounds.Height); - } - else - { - layout.data = bounds; - layout.leftArrow = Rectangle.Empty; - layout.rightArrow = Rectangle.Empty; - } - } - - private void PaintParentRows(Graphics g, Rectangle bounds, bool alignToRight) - { - int tableNameBoxWidth = 0; - int numCols = ColsCount(); - int[] colsNameWidths = new int[numCols]; - int[] colsDataWidths = new int[numCols]; - - if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.TableName || - dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) - { - tableNameBoxWidth = GetTableBoxWidth(g, dataGrid.Font); - } - - for (int i = 0; i < numCols; i++) - { - if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.ColumnName || - dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) - { - colsNameWidths[i] = GetColBoxWidth(g, dataGrid.Font, i); - } - else - { - colsNameWidths[i] = 0; - } - - colsDataWidths[i] = GetColDataBoxWidth(g, i); - } - - ComputeLayout(bounds, tableNameBoxWidth, colsNameWidths, colsDataWidths); - - if (!layout.leftArrow.IsEmpty) - { - g.FillRectangle(BackBrush, layout.leftArrow); - PaintLeftArrow(g, layout.leftArrow, alignToRight); - } - - Rectangle rowBounds = layout.data; - for (int row = 0; row < parentsCount; ++row) - { - rowBounds.Height = (int)rowHeights[row]; - if (rowBounds.Y > bounds.Bottom) - break; - int paintedWidth = PaintRow(g, rowBounds, row, dataGrid.Font, alignToRight, tableNameBoxWidth, colsNameWidths, colsDataWidths); - if (row == parentsCount - 1) - break; - - // draw the grid line below - g.DrawLine(gridLinePen, rowBounds.X, rowBounds.Bottom, - rowBounds.X + paintedWidth, - rowBounds.Bottom); - rowBounds.Y += rowBounds.Height; - } - - if (!layout.rightArrow.IsEmpty) - { - g.FillRectangle(BackBrush, layout.rightArrow); - PaintRightArrow(g, layout.rightArrow, alignToRight); - } - } - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] - private Bitmap GetBitmap(string bitmapName, Color transparentColor) - { - Bitmap b = null; - try - { - b = new Bitmap(typeof(DataGridParentRows), bitmapName); - b.MakeTransparent(transparentColor); - } - catch (Exception e) - { - Debug.Fail("Failed to load bitmap: " + bitmapName, e.ToString()); - } - - return b; - } - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - private Bitmap GetRightArrowBitmap() - { - if (rightArrow is null) - rightArrow = GetBitmap("DataGridParentRows.RightArrow.bmp", Color.White); - return rightArrow; - } - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - private Bitmap GetLeftArrowBitmap() - { - if (leftArrow is null) - leftArrow = GetBitmap("DataGridParentRows.LeftArrow.bmp", Color.White); - return leftArrow; - } - - private void PaintBitmap(Graphics g, Bitmap b, Rectangle bounds) - { - // center the bitmap in the bounds: - int bmpX = bounds.X + (bounds.Width - b.Width) / 2; - int bmpY = bounds.Y + (bounds.Height - b.Height) / 2; - Rectangle bmpRect = new Rectangle(bmpX, bmpY, b.Width, b.Height); - - g.FillRectangle(BackBrush, bmpRect); - - // now draw the bitmap - ImageAttributes attr = new ImageAttributes(); - colorMap[0].NewColor = ForeColor; - attr.SetRemapTable(colorMap, ColorAdjustType.Bitmap); - g.DrawImage(b, bmpRect, 0, 0, bmpRect.Width, bmpRect.Height, GraphicsUnit.Pixel, attr); - attr.Dispose(); - } - - private void PaintDownButton(Graphics g, Rectangle bounds) - { - g.DrawLine(Pens.Black, bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y); // the top - g.DrawLine(Pens.White, bounds.X + bounds.Width, bounds.Y, bounds.X + bounds.Width, bounds.Y + bounds.Height); // the right side - g.DrawLine(Pens.White, bounds.X + bounds.Width, bounds.Y + bounds.Height, bounds.X, bounds.Y + bounds.Height); // the right side - g.DrawLine(Pens.Black, bounds.X, bounds.Y + bounds.Height, bounds.X, bounds.Y); // the left side - } - - private void PaintLeftArrow(Graphics g, Rectangle bounds, bool alignToRight) - { - Bitmap bmp = GetLeftArrowBitmap(); - if (downLeftArrow) - { - PaintDownButton(g, bounds); - layout.leftArrow.Inflate(-1, -1); - lock (bmp) - { - PaintBitmap(g, bmp, bounds); - } - - layout.leftArrow.Inflate(1, 1); - } - else - { - lock (bmp) - { - PaintBitmap(g, bmp, bounds); - } - } - } - - private void PaintRightArrow(Graphics g, Rectangle bounds, bool alignToRight) - { - Bitmap bmp = GetRightArrowBitmap(); - if (downRightArrow) - { - PaintDownButton(g, bounds); - layout.rightArrow.Inflate(-1, -1); - lock (bmp) - { - PaintBitmap(g, bmp, bounds); - } - - layout.rightArrow.Inflate(1, 1); - } - else - { - lock (bmp) - { - PaintBitmap(g, bmp, bounds); - } - } - } - - private int PaintRow(Graphics g, Rectangle bounds, int row, Font font, bool alignToRight, - int tableNameBoxWidth, int[] colsNameWidths, int[] colsDataWidths) - { - DataGridState dgs = (DataGridState)parents[row]; - Rectangle paintBounds = bounds; - Rectangle rowBounds = bounds; - paintBounds.Height = (int)rowHeights[row]; - rowBounds.Height = (int)rowHeights[row]; - - int paintedWidth = 0; - // used for scrolling: when paiting, we will skip horizOffset cells in the dataGrid ParentRows - int skippedCells = 0; - - // paint the table name - if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.TableName || - dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) - { - if (skippedCells < horizOffset) - { - // skip this - skippedCells++; - } - else - { - paintBounds.Width = Math.Min(paintBounds.Width, tableNameBoxWidth); - paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); - string displayTableName = dgs.ListManager.GetListName() + ": "; - PaintText(g, paintBounds, displayTableName, font, true, alignToRight); // true is for painting bold - paintedWidth += paintBounds.Width; - } - } - - if (paintedWidth >= bounds.Width) - return bounds.Width; // we painted everything - - rowBounds.Width -= paintedWidth; - rowBounds.X += alignToRight ? 0 : paintedWidth; - paintedWidth += PaintColumns(g, rowBounds, dgs, font, alignToRight, colsNameWidths, colsDataWidths, skippedCells); - - // paint the possible space left after columns - if (paintedWidth < bounds.Width) - { - paintBounds.X = bounds.X + paintedWidth; - paintBounds.Width = bounds.Width - paintedWidth; - paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); - g.FillRectangle(BackBrush, paintBounds); - } - - return paintedWidth; - } - - private int PaintColumns(Graphics g, Rectangle bounds, DataGridState dgs, Font font, bool alignToRight, - int[] colsNameWidths, int[] colsDataWidths, int skippedCells) - { - Rectangle paintBounds = bounds; - Rectangle rowBounds = bounds; - GridColumnStylesCollection cols = dgs.GridColumnStyles; - int cx = 0; - - for (int i = 0; i < cols.Count; i++) - { - if (cx >= bounds.Width) - break; - - // paint the column name, if we have to - if (dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.ColumnName || - dataGrid.ParentRowsLabelStyle == DataGridParentRowsLabelStyle.Both) - { - if (skippedCells < horizOffset) - { - // skip this column - } - else - { - paintBounds.X = bounds.X + cx; - paintBounds.Width = Math.Min(bounds.Width - cx, colsNameWidths[i]); - paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); - - string colName = cols[i].HeaderText + ": "; - PaintText(g, paintBounds, colName, font, false, alignToRight); // false is for not painting bold - - cx += paintBounds.Width; - } - } - - if (cx >= bounds.Width) - break; - - if (skippedCells < horizOffset) - { - // skip this cell - skippedCells++; - } - else - { - // paint the cell contents - paintBounds.X = bounds.X + cx; - paintBounds.Width = Math.Min(bounds.Width - cx, colsDataWidths[i]); - paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); - - // when we paint the data grid parent rows, we want to paint the data at the position - // stored in the currency manager. - cols[i].Paint(g, paintBounds, (CurrencyManager)dataGrid.BindingContext[dgs.DataSource, dgs.DataMember], - dataGrid.BindingContext[dgs.DataSource, dgs.DataMember].Position, BackBrush, ForeBrush, alignToRight); - - cx += paintBounds.Width; - - // draw the line to the right (or left, according to alignRight) - // - g.DrawLine(new Pen(SystemColors.ControlDark), - alignToRight ? paintBounds.X : paintBounds.Right, - paintBounds.Y, - alignToRight ? paintBounds.X : paintBounds.Right, - paintBounds.Bottom); - - // this is how wide the line is.... - cx++; - - // put 3 pixels in between columns - // see DonnaWa - // - if (i < cols.Count - 1) - { - paintBounds.X = bounds.X + cx; - paintBounds.Width = Math.Min(bounds.Width - cx, 3); - paintBounds.X = MirrorRect(bounds, paintBounds, alignToRight); - - g.FillRectangle(BackBrush, paintBounds); - cx += 3; - } - } - } - - return cx; - } - - private int PaintText(Graphics g, Rectangle textBounds, string text, Font font, bool bold, bool alignToRight) - { - Font textFont = font; - if (bold) - try - { - textFont = new Font(font, FontStyle.Bold); - } - catch { } - else - textFont = font; - - // right now, we paint the entire box, cause it will be used anyway - g.FillRectangle(BackBrush, textBounds); - StringFormat format = new StringFormat(); - if (alignToRight) - { - format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; - format.Alignment = StringAlignment.Far; - } - - format.FormatFlags |= StringFormatFlags.NoWrap; - // part 1, section 3: put the table and the column name in the - // parent rows at the same height as the dataGridTextBoxColumn draws the string - textBounds.Offset(0, 2); - textBounds.Height -= 2; - g.DrawString(text, textFont, ForeBrush, textBounds, format); - format.Dispose(); - return textBounds.Width; - } - - private int MirrorRect(Rectangle surroundingRect, Rectangle containedRect, bool alignToRight) - { - Debug.Assert(containedRect.X >= surroundingRect.X && containedRect.Right <= surroundingRect.Right, "containedRect is not contained in surroundingRect"); - if (alignToRight) - return surroundingRect.Right - containedRect.Right + surroundingRect.X; - else - return containedRect.X; - } - - private class Layout - { - public Rectangle data; - public Rectangle leftArrow; - public Rectangle rightArrow; - - public Layout() - { - data = Rectangle.Empty; - leftArrow = Rectangle.Empty; - rightArrow = Rectangle.Empty; - } - - public override string ToString() - { - StringBuilder sb = new StringBuilder(200); - sb.Append("ParentRows Layout: \n"); - sb.Append("data = "); - sb.Append(data.ToString()); - sb.Append("\n leftArrow = "); - sb.Append(leftArrow.ToString()); - sb.Append("\n rightArrow = "); - sb.Append(rightArrow.ToString()); - sb.Append('\n'); - - return sb.ToString(); - } + get => throw new PlatformNotSupportedException(); } [ComVisible(true)] - [Obsolete("DataGridParentRowsAccessibleObject has been deprecated.")] + [Obsolete( + Obsoletions.DataGridParentRowsAccessibleObjectMessage, + error: false, + DiagnosticId = Obsoletions.DataGridParentRowsAccessibleObjectDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] protected internal class DataGridParentRowsAccessibleObject : AccessibleObject { public DataGridParentRowsAccessibleObject(DataGridParentRows owner) : base() - { - throw new PlatformNotSupportedException(); - } - - internal DataGridParentRows Owner - { - get; - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string DefaultAction { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Name { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Value { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } public override void DoDefaultAction() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject GetChild(int index) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override int GetChildCount() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject GetFocused() - { - throw new PlatformNotSupportedException(); - } - - internal AccessibleObject GetNext(AccessibleObject child) - { - int children = GetChildCount(); - bool hit = false; - - for (int i = 0; i < children; i++) - { - if (hit) - { - return GetChild(i); - } - - if (GetChild(i) == child) - { - hit = true; - } - } - - return null; - } - - internal AccessibleObject GetPrev(AccessibleObject child) - { - int children = GetChildCount(); - bool hit = false; - - for (int i = children - 1; i >= 0; i--) - { - if (hit) - { - return GetChild(i); - } - - if (GetChild(i) == child) - { - hit = true; - } - } - - return null; - } + => throw new PlatformNotSupportedException(); public override AccessibleObject Navigate(AccessibleNavigation navdir) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override void Select(AccessibleSelection flags) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs index ceb306b73d9..0437822e690 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs @@ -1,20 +1,18 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; #pragma warning disable RS0016 -[Obsolete("DataGridParentRowsLabelStyle has been deprecated.")] +[Obsolete( + Obsoletions.DataGridParentRowsLabelStyleMessage, + error: false, + DiagnosticId = Obsoletions.DataGridParentRowsLabelStyleDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public enum DataGridParentRowsLabelStyle { - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] None = 0, - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] TableName = 1, - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] ColumnName = 2, - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Both = 3, } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs index 78c0f6a207c..fa9e26185b0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs @@ -6,14 +6,22 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 -[Obsolete("DataGridPreferredColumnWidthTypeConverter has been deprecated.")] #nullable disable +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.DataGridPreferredColumnWidthTypeConverterMessage, + error: false, + DiagnosticId = Obsoletions.DataGridPreferredColumnWidthTypeConverterDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridPreferredColumnWidthTypeConverter : TypeConverter { - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => throw new PlatformNotSupportedException(); + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + => throw new PlatformNotSupportedException(); - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) => throw new PlatformNotSupportedException(); + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + => throw new PlatformNotSupportedException(); - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) => throw new PlatformNotSupportedException(); + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs index af93be8479d..7a5dbd5c5dc 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs @@ -4,688 +4,144 @@ using System.Collections; using System.ComponentModel; using System.Drawing; -using System.Runtime.InteropServices; -using System.Security.Permissions; namespace System.Windows.Forms; #nullable disable -[Obsolete("DataGridRelationshipRow has been deprecated.")] +[Obsolete( + Obsoletions.DataGridRelationshipRowMessage, + error: false, + DiagnosticId = Obsoletions.DataGridRelationshipRowDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridRelationshipRow : DataGridRow { - private const bool defaultOpen = false; - private const int expandoBoxWidth = 14; - private bool expanded = defaultOpen; - public DataGridRelationshipRow(DataGrid dataGrid, DataGridTableStyle dgTable, int rowNumber) : base(dataGrid, dgTable, rowNumber) - { - throw new PlatformNotSupportedException(); - } - - internal protected override int MinimumRowHeight(GridColumnStylesCollection cols) - { - return base.MinimumRowHeight(cols) + (expanded ? GetRelationshipRect().Height : 0); - } + => throw new PlatformNotSupportedException(); - internal protected override int MinimumRowHeight(DataGridTableStyle dgTable) - { - return base.MinimumRowHeight(dgTable) + (expanded ? GetRelationshipRect().Height : 0); - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual bool Expanded { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - -#if FALSE - private int BorderWidth { - get { - DataGrid dataGrid = DataGrid; - if (dataGrid == null) - return 0; - // if the user set the GridLineStyle property on the dataGrid. - // then use the value of that property - DataGridLineStyle gridStyle; - int gridLineWidth; - if (dgTable.IsDefault) { - gridStyle = DataGrid.GridLineStyle; - gridLineWidth = DataGrid.GridLineWidth; - } else { - gridStyle = dgTable.GridLineStyle; - gridLineWidth = dgTable.GridLineWidth; - } - - if (gridStyle == DataGridLineStyle.None) - return 0; - - return gridLineWidth; - } - } -#endif //FALSE - - private int FocusedRelation - { - get - { - return dgTable.FocusedRelation; - } - set - { - dgTable.FocusedRelation = value; - } - } - - // =------------------------------------------------------------------ - // = Methods - // =------------------------------------------------------------------ - - private void Collapse() - { - Debug.Assert(dgTable.DataGrid.AllowNavigation, "how can the user collapse the relations if the grid does not allow navigation?"); - if (expanded) - { - expanded = false; - // relationshipRect = Rectangle.Empty; - FocusedRelation = -1; - DataGrid.OnRowHeightChanged(this); - } - } - - protected override AccessibleObject CreateAccessibleObject() - { - return new DataGridRelationshipRowAccessibleObject(this); - } - - private void Expand() - { - Debug.Assert(dgTable.DataGrid.AllowNavigation, "how can the user expand the relations if the grid does not allow navigation?"); - if (expanded == false - && DataGrid is not null - && dgTable is not null - && dgTable.RelationsList.Count > 0) - { - expanded = true; - FocusedRelation = -1; - - // relationshipRect = Rectangle.Empty; - DataGrid.OnRowHeightChanged(this); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override int Height { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - // so the edit box will not paint under the - // grid line of the row public override Rectangle GetCellBounds(int col) - { - throw new PlatformNotSupportedException(); - } - - private Rectangle GetOutlineRect(int xOrigin, int yOrigin) - { - Rectangle outline = new Rectangle(xOrigin + 2, - yOrigin + 2, - 9, - 9); - return outline; - } + => throw new PlatformNotSupportedException(); public override Rectangle GetNonScrollableArea() - { - throw new PlatformNotSupportedException(); - } - - private Rectangle GetRelationshipRect() - { - Debug.Assert(expanded, "we should need this rectangle only when the row is expanded"); - Rectangle ret = dgTable.RelationshipRect; - ret.Y = base.Height - dgTable.BorderWidth; - return ret; - } - -#if FALSE - private Rectangle GetRelationshipRect() { - if (relationshipRect.IsEmpty) { - Debug.WriteLineIf(CompModSwitches.DGRelationShpRowLayout.TraceVerbose, "GetRelationshipRect grinding away"); - if (!expanded) { - return(relationshipRect = new Rectangle(0,0,0,0)); - } - Graphics g = DataGrid.CreateGraphicsInternal(); - relationshipRect = new Rectangle(); - relationshipRect.X = 0; //indentWidth; - relationshipRect.Y = base.Height - dgTable.BorderWidth; - - // Determine the width of the widest relationship name - int longestRelationship = 0; - for (int r = 0; r < dgTable.RelationsList.Count; ++r) { - int rwidth = (int) Math.Ceiling(g.MeasureString(((string) dgTable.RelationsList[r]), DataGrid.LinkFont).Width); - if (rwidth > longestRelationship) - longestRelationship = rwidth; - } - - g.Dispose(); - - relationshipRect.Width = longestRelationship + 5; - relationshipRect.Width += 2; // relationshipRect border; - relationshipRect.Height = dgTable.BorderWidth + relationshipHeight * dgTable.RelationsList.Count; - relationshipRect.Height += 2; // relationship border - if (dgTable.RelationsList.Count > 0) - relationshipRect.Height += 2 * System.Windows.Forms.DataGridTableStyle.relationshipSpacing; - } - return relationshipRect; - } - -#endif// FALSE - - private Rectangle GetRelationshipRectWithMirroring() - { - Rectangle relRect = GetRelationshipRect(); - bool rowHeadersVisible = dgTable.IsDefault ? DataGrid.RowHeadersVisible : dgTable.RowHeadersVisible; - if (rowHeadersVisible) - { - int rowHeaderWidth = dgTable.IsDefault ? DataGrid.RowHeaderWidth : dgTable.RowHeaderWidth; - relRect.X += DataGrid.GetRowHeaderRect().X + rowHeaderWidth; - } - - relRect.X = MirrorRelationshipRectangle(relRect, DataGrid.GetRowHeaderRect(), DataGrid.RightToLeft == RightToLeft.Yes); - return relRect; - } - - private bool PointOverPlusMinusGlyph(int x, int y, Rectangle rowHeaders, bool alignToRight) - { - if (dgTable is null || dgTable.DataGrid is null || !dgTable.DataGrid.AllowNavigation) - return false; - Rectangle insideRowHeaders = rowHeaders; - if (!DataGrid.FlatMode) - { - insideRowHeaders.Inflate(-1, -1); - } - - Rectangle outline = GetOutlineRect(insideRowHeaders.Right - expandoBoxWidth, 0); - - outline.X = MirrorRectangle(outline.X, outline.Width, insideRowHeaders, alignToRight); - - return outline.Contains(x, y); - } + => throw new PlatformNotSupportedException(); public override bool OnMouseDown(int x, int y, Rectangle rowHeaders, bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override bool OnMouseMove(int x, int y, Rectangle rowHeaders, bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - // this function will not invalidate all of the row public override void OnMouseLeft(Rectangle rowHeaders, bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override void OnMouseLeft() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override bool OnKeyPress(Keys keyData) - { - throw new PlatformNotSupportedException(); - } - - // will reset the FocusedRelation and will invalidate the - // rectangle so that the linkFont is no longer shown - internal override void LoseChildFocus(Rectangle rowHeaders, bool alignToRight) - { - // we only invalidate stuff if the row is expanded. - if (FocusedRelation == -1 || !expanded) - return; - - FocusedRelation = -1; - Rectangle relRect = GetRelationshipRect(); - relRect.X += rowHeaders.X + dgTable.RowHeaderWidth; - relRect.X = MirrorRelationshipRectangle(relRect, rowHeaders, alignToRight); - InvalidateRowRect(relRect); - } - - // here is the logic for FOCUSED: - // - // first the dataGrid gets the KeyPress. - // the dataGrid passes it to the currentRow. if it is anything other - // than Enter or TAB, the currentRow resets the FocusedRelation variable. - // - // Then the dataGrid takes another look at the TAB key and if it is the case - // it passes it to the row. If the dataRelationshipRow can become focused, - // then it eats the TAB key, otherwise it will give it back to the dataGrid. - // - internal override bool ProcessTabKey(Keys keyData, Rectangle rowHeaders, bool alignToRight) - { - Debug.Assert((keyData & Keys.Control) != Keys.Control, "the DataGridRelationshipRow only handles TAB and TAB-SHIFT"); - Debug.Assert((keyData & Keys.Alt) != Keys.Alt, "the DataGridRelationshipRow only handles TAB and TAB-SHIFT"); + => throw new PlatformNotSupportedException(); - // if there are no relationships, this row can't do anything with the key - if (dgTable.RelationsList.Count == 0 || dgTable.DataGrid is null || !dgTable.DataGrid.AllowNavigation) - return false; - - // expand the relationship box - if (!expanded) - Expand(); - - if ((keyData & Keys.Shift) == Keys.Shift) - { - if (FocusedRelation == 0) - { - // if user hits TAB-SHIFT and the focus was on the first relationship then - // reset FocusedRelation and let the dataGrid use the key - // - // consider: DANIELHE: if the relationships box is expanded, should we collapse it on leave? - FocusedRelation = -1; - return false; - } - - // we need to invalidate the relationshipRectangle, and cause the linkFont to move - // to the next relation - Rectangle relRect = GetRelationshipRect(); - relRect.X += rowHeaders.X + dgTable.RowHeaderWidth; - relRect.X = MirrorRelationshipRectangle(relRect, rowHeaders, alignToRight); - InvalidateRowRect(relRect); - - if (FocusedRelation == -1) - // is the first time that the user focuses on this - // set of relationships - FocusedRelation = dgTable.RelationsList.Count - 1; - else - FocusedRelation--; - return true; - } - else - { - if (FocusedRelation == dgTable.RelationsList.Count - 1) - { - // if the user hits TAB and the focus was on the last relationship then - // reset FocusedRelation and let the dataGrid use the key - // - // consider: DANIELHE: if the relationships box is expanded, should we collapse it on leave? - FocusedRelation = -1; - return false; - } - - // we need to invalidate the relationshipRectangle, and cause the linkFont to move - // to the next relation - Rectangle relRect = GetRelationshipRect(); - relRect.X += rowHeaders.X + dgTable.RowHeaderWidth; - relRect.X = MirrorRelationshipRectangle(relRect, rowHeaders, alignToRight); - InvalidateRowRect(relRect); - - FocusedRelation++; - return true; - } - } - - public override int Paint(Graphics g, Rectangle bounds, Rectangle trueRowBounds, int firstVisibleColumn, int numVisibleColumns) - { - throw new PlatformNotSupportedException(); - } + public override int Paint(Graphics g, + Rectangle bounds, + Rectangle trueRowBounds, + int firstVisibleColumn, + int numVisibleColumns) + => throw new PlatformNotSupportedException(); public override int Paint(Graphics g, - Rectangle bounds, // negative offsetted row bounds - Rectangle trueRowBounds, // real row bounds. - int firstVisibleColumn, - int numVisibleColumns, - bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + Rectangle bounds, + Rectangle trueRowBounds, + int firstVisibleColumn, + int numVisibleColumns, + bool alignToRight) + => throw new PlatformNotSupportedException(); - protected override void PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, - Brush backBr, Brush foreBrush, bool alignToRight) + protected override void PaintCellContents(Graphics g, + Rectangle cellBounds, + DataGridColumnStyle column, + Brush backBr, + Brush foreBrush, + bool alignToRight) { - CurrencyManager listManager = DataGrid.ListManager; - - // painting the error.. - // - string errString = string.Empty; - Rectangle bounds = cellBounds; - object errInfo = DataGrid.ListManager[number]; - if (errInfo is IDataErrorInfo) - errString = ((IDataErrorInfo)errInfo)[column.PropertyDescriptor.Name]; - - if (!string.IsNullOrEmpty(errString)) - { - Bitmap bmp = GetErrorBitmap(); - Rectangle errRect; - lock (bmp) - { - errRect = PaintIcon(g, bounds, true, alignToRight, bmp, backBr); - } - - // paint the errors correctly when RTL = true - if (alignToRight) - bounds.Width -= errRect.Width + xOffset; - else - bounds.X += errRect.Width + xOffset; - DataGridToolTip.AddToolTip(errString, (IntPtr)(DataGrid.ToolTipId++), errRect); - } - - column.Paint(g, bounds, listManager, RowNumber, backBr, foreBrush, alignToRight); } public override void PaintHeader(Graphics g, Rectangle bounds, bool alignToRight, bool isDirty) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void PaintHeaderInside(Graphics g, Rectangle bounds, Brush backBr, bool alignToRight, bool isDirty) - { - throw new PlatformNotSupportedException(); - } - - private void PaintRelations(Graphics g, Rectangle bounds, Rectangle trueRowBounds, - int dataWidth, int firstCol, int nCols, bool alignToRight) - { - // Calculate the relationship rect. - // relationshipRect = Rectangle.Empty; - Rectangle relRect = GetRelationshipRect(); - // relRect.Offset(trueRowBounds.X, trueRowBounds.Y); - relRect.X = alignToRight ? bounds.Right - relRect.Width : bounds.X; - relRect.Y = bounds.Y; - int paintedWidth = Math.Max(dataWidth, relRect.Width); - - // Paint the stuff to the right , or left (Bi-Di) of the relationship rect. - Region r = g.Clip; - g.ExcludeClip(relRect); - - g.FillRectangle(GetBackBrush(), - alignToRight ? bounds.Right - dataWidth : bounds.X, - bounds.Y, - dataWidth, - bounds.Height); - - // Paint the relations' text - g.SetClip(bounds); - - relRect.Height -= dgTable.BorderWidth; // use bWidth not 1 - g.DrawRectangle(SystemPens.ControlText, relRect.X, relRect.Y, relRect.Width - 1, relRect.Height - 1); - relRect.Inflate(-1, -1); - - int cy = PaintRelationText(g, relRect, alignToRight); - - if (cy < relRect.Height) - { - g.FillRectangle(GetBackBrush(), relRect.X, relRect.Y + cy, relRect.Width, relRect.Height - cy); - } - - g.Clip = r; - - // paint any exposed area to the right or to the left (BI-DI) - if (paintedWidth < bounds.Width) - { - int bWidth; - if (dgTable.IsDefault) - bWidth = DataGrid.GridLineWidth; - else - bWidth = dgTable.GridLineWidth; - g.FillRectangle(DataGrid.BackgroundBrush, - alignToRight ? bounds.X : bounds.X + paintedWidth, - bounds.Y, - bounds.Width - paintedWidth - bWidth + 1, // + 1 cause the relationship rectangle was deflated - bounds.Height); - - // Paint the border to the right of each cell - if (bWidth > 0) - { - Brush br; - // if the user changed the gridLineColor on the dataGrid - // from the defaultValue, then use that value; - if (dgTable.IsDefault) - br = DataGrid.GridLineBrush; - else - br = dgTable.GridLineBrush; - g.FillRectangle(br, - alignToRight ? bounds.Right - bWidth - paintedWidth : bounds.X + paintedWidth - bWidth, - bounds.Y, - bWidth, - bounds.Height); - } - } - } - - private int PaintRelationText(Graphics g, Rectangle bounds, bool alignToRight) - { - g.FillRectangle(GetBackBrush(), bounds.X, bounds.Y, bounds.Width, System.Windows.Forms.DataGridTableStyle.relationshipSpacing); - - int relationshipHeight = dgTable.RelationshipHeight; - Rectangle textBounds = new Rectangle(bounds.X, bounds.Y + System.Windows.Forms.DataGridTableStyle.relationshipSpacing, - bounds.Width, - relationshipHeight); - int cy = System.Windows.Forms.DataGridTableStyle.relationshipSpacing; - for (int r = 0; r < dgTable.RelationsList.Count; ++r) - { - if (cy > bounds.Height) - break; - - Brush textBrush = dgTable.IsDefault ? DataGrid.LinkBrush : dgTable.LinkBrush; - - Font textFont = DataGrid.Font; - textBrush = dgTable.IsDefault ? DataGrid.LinkBrush : dgTable.LinkBrush; - textFont = DataGrid.LinkFont; - - g.FillRectangle(GetBackBrush(), textBounds); - - StringFormat format = new StringFormat(); - if (alignToRight) - { - format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; - format.Alignment = StringAlignment.Far; - } - - g.DrawString(((string)dgTable.RelationsList[r]), textFont, textBrush, textBounds, - format); - if (r == FocusedRelation && number == DataGrid.CurrentCell.RowNumber) - { - textBounds.Width = dgTable.FocusedTextWidth; - ControlPaint.DrawFocusRectangle(g, textBounds, ((SolidBrush)textBrush).Color, ((SolidBrush)GetBackBrush()).Color); - textBounds.Width = bounds.Width; - } - - format.Dispose(); - - textBounds.Y += relationshipHeight; - cy += textBounds.Height; - } - - return cy; - } - - private void PaintPlusMinusGlyph(Graphics g, Rectangle bounds, Brush backBr, bool alignToRight) - { - if (CompModSwitches.DGRelationShpRowPaint.TraceVerbose) - Debug.WriteLine("PlusMinusGlyph painting in bounds -> " + bounds.ToString()); - Rectangle outline = GetOutlineRect(bounds.X, bounds.Y); - - outline = Rectangle.Intersect(bounds, outline); - if (outline.IsEmpty) - return; - - g.FillRectangle(backBr, bounds); - - if (CompModSwitches.DGRelationShpRowPaint.TraceVerbose) - Debug.WriteLine("Painting PlusMinusGlyph with outline -> " + outline.ToString()); - // draw the +/- box - Pen drawPen = dgTable.IsDefault ? DataGrid.HeaderForePen : dgTable.HeaderForePen; - g.DrawRectangle(drawPen, outline.X, outline.Y, outline.Width - 1, outline.Height - 1); + => throw new PlatformNotSupportedException(); - int indent = 2; - // draw the - - g.DrawLine(drawPen, - outline.X + indent, outline.Y + outline.Width / 2, - outline.Right - indent - 1, outline.Y + outline.Width / 2); // -1 on the y coordinate - - if (!expanded) - { - // draw the vertical line to make + - g.DrawLine(drawPen, - outline.X + outline.Height / 2, outline.Y + indent, - outline.X + outline.Height / 2, outline.Bottom - indent - 1); // -1... hinting - } - else - { - Point[] points = new Point[3]; - points[0] = new Point(outline.X + outline.Height / 2, outline.Bottom); - - points[1] = new Point(points[0].X, bounds.Y + 2 * indent + base.Height); - - points[2] = new Point(alignToRight ? bounds.X : bounds.Right, - points[1].Y); - g.DrawLines(drawPen, points); - } - } - - private int RelationFromY(int y) - { - int relation = -1; - int relationshipHeight = dgTable.RelationshipHeight; - Rectangle relRect = GetRelationshipRect(); - int cy = base.Height - dgTable.BorderWidth + System.Windows.Forms.DataGridTableStyle.relationshipSpacing; - while (cy < relRect.Bottom) - { - if (cy > y) - break; - cy += relationshipHeight; - relation++; - } - - if (relation >= dgTable.RelationsList.Count) - return -1; - return relation; - } - - // given the relRect and the rowHeader, this function will return the - // X coordinate of the relationship rectangle as it should appear on the screen - private int MirrorRelationshipRectangle(Rectangle relRect, Rectangle rowHeader, bool alignToRight) - { - if (alignToRight) - return rowHeader.X - relRect.Width; - else - return relRect.X; - } - - // given the X and Width of a rectangle R1 contained in rect, - // this will return the X coordinate of the rectangle that corresponds to R1 in Bi-Di transformation - private int MirrorRectangle(int x, int width, Rectangle rect, bool alignToRight) - { - if (alignToRight) - return rect.Right + rect.X - width - x; - else - return x; - } - - [ComVisible(true)] - [Obsolete("DataGridRelationshipRowAccessibleObject has been deprecated.")] + [Obsolete( + Obsoletions.DataGridRelationshipRowAccessibleObjectMessage, + error: false, + DiagnosticId = Obsoletions.DataGridRelationshipRowAccessibleObjectDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridRelationshipRowAccessibleObject : DataGridRowAccessibleObject { public DataGridRelationshipRowAccessibleObject(DataGridRow owner) : base(owner) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected override void AddChildAccessibleObjects(IList children) - { - base.AddChildAccessibleObjects(children); - DataGridRelationshipRow row = (DataGridRelationshipRow)Owner; - if (row.dgTable.RelationsList is not null) - { - for (int i = 0; i < row.dgTable.RelationsList.Count; i++) - { - children.Add(new DataGridRelationshipAccessibleObject(row, i)); - } - } - } - - private DataGridRelationshipRow RelationshipRow - { - get - { - return (DataGridRelationshipRow)Owner; - } - } + => base.AddChildAccessibleObjects(children); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string DefaultAction { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public override void DoDefaultAction() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject GetFocused() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } - [ComVisible(true)] - [Obsolete("DataGridRelationshipAccessibleObject has been deprecated.")] + [Obsolete( + Obsoletions.DataGridRelationshipAccessibleObjectMessage, + error: false, + DiagnosticId = Obsoletions.DataGridRelationshipAccessibleObjectDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridRelationshipAccessibleObject : AccessibleObject { public DataGridRelationshipAccessibleObject(DataGridRelationshipRow owner, int relationship) : base() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Name { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } protected DataGridRelationshipRow Owner @@ -693,14 +149,11 @@ protected DataGridRelationshipRow Owner get; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent { - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } protected DataGrid DataGrid @@ -708,69 +161,42 @@ protected DataGrid DataGrid get; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Value { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string DefaultAction { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public override void DoDefaultAction() - { - throw new PlatformNotSupportedException(); - } - - private void ResetAccessibilityLayer() - { - ((DataGrid.DataGridAccessibleObject)DataGrid.AccessibilityObject).NotifyClients(AccessibleEvents.Reorder, 0); - ((DataGrid.DataGridAccessibleObject)DataGrid.AccessibilityObject).NotifyClients(AccessibleEvents.Focus, DataGrid.CurrentCellAccIndex); - ((DataGrid.DataGridAccessibleObject)DataGrid.AccessibilityObject).NotifyClients(AccessibleEvents.Selection, DataGrid.CurrentCellAccIndex); - } + => throw new PlatformNotSupportedException(); - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public override AccessibleObject Navigate(AccessibleNavigation navdir) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public override void Select(AccessibleSelection flags) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs index efc4f16bb5c..24fd67a8591 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs @@ -4,134 +4,64 @@ using System.Collections; using System.ComponentModel; using System.Drawing; -using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Runtime.Versioning; namespace System.Windows.Forms; #nullable disable -[Obsolete("DataGridRow has been deprecated.")] +[Obsolete( + Obsoletions.DataGridRowMessage, + error: false, + DiagnosticId = Obsoletions.DataGridRowDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal abstract class DataGridRow : MarshalByRefObject { - internal protected int number; protected DataGridTableStyle dgTable; - - // we will be mapping only the black color to - // the HeaderForeColor - private static ColorMap[] colorMap = [new ColorMap()]; - - // bitmaps - private static Bitmap rightArrow; - private static Bitmap leftArrow; - private static Bitmap errorBmp; - private static Bitmap pencilBmp; - private static Bitmap starBmp; - protected const int xOffset = 3; - protected const int yOffset = 2; + protected const int XOffset = 3; + protected const int YOffset = 2; public DataGridRow(DataGrid dataGrid, DataGridTableStyle dgTable, int rowNumber) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public AccessibleObject AccessibleObject { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } protected virtual AccessibleObject CreateAccessibleObject() - { - return new DataGridRowAccessibleObject(this); - } - - internal protected virtual int MinimumRowHeight(DataGridTableStyle dgTable) - { - return MinimumRowHeight(dgTable.GridColumnStyles); - } - - internal protected virtual int MinimumRowHeight(GridColumnStylesCollection columns) - { - int h = dgTable.IsDefault ? DataGrid.PreferredRowHeight : dgTable.PreferredRowHeight; - - try - { - if (dgTable.DataGrid.DataSource is not null) - { - int nCols = columns.Count; - for (int i = 0; i < nCols; ++i) - { - // if (columns[i].Visible && columns[i].PropertyDescriptor is not null) - if (columns[i].PropertyDescriptor is not null) - h = Math.Max(h, columns[i].GetMinimumHeight()); - } - } - } - catch - { - } - - return h; - } + => new DataGridRowAccessibleObject(this); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public DataGrid DataGrid { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - internal DataGridTableStyle DataGridTableStyle - { - get - { - return dgTable; - } - set - { - dgTable = value; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual int Height { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int RowNumber { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual bool Selected { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } [ResourceExposure(ResourceScope.Machine)] @@ -144,9 +74,8 @@ protected Bitmap GetBitmap(string bitmapName) b = new Bitmap(typeof(DataGridCaption), bitmapName); b.MakeTransparent(); } - catch (Exception e) + catch { - Debug.Fail("Failed to load bitmap: " + bitmapName, e.ToString()); throw; } @@ -154,529 +83,309 @@ protected Bitmap GetBitmap(string bitmapName) } public virtual Rectangle GetCellBounds(int col) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual Rectangle GetNonScrollableArea() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [ResourceExposure(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)] protected Bitmap GetStarBitmap() - { - if (starBmp is null) - starBmp = GetBitmap("DataGridRow.star.bmp"); - return starBmp; - } + => throw new PlatformNotSupportedException(); [ResourceExposure(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)] protected Bitmap GetPencilBitmap() - { - if (pencilBmp is null) - pencilBmp = GetBitmap("DataGridRow.pencil.bmp"); - return pencilBmp; - } + => throw new PlatformNotSupportedException(); [ResourceExposure(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)] protected Bitmap GetErrorBitmap() - { - if (errorBmp is null) - errorBmp = GetBitmap("DataGridRow.error.bmp"); - errorBmp.MakeTransparent(); - return errorBmp; - } + => throw new PlatformNotSupportedException(); [ResourceExposure(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)] protected Bitmap GetLeftArrowBitmap() - { - if (leftArrow is null) - leftArrow = GetBitmap("DataGridRow.left.bmp"); - return leftArrow; - } + => throw new PlatformNotSupportedException(); [ResourceExposure(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)] protected Bitmap GetRightArrowBitmap() - { - if (rightArrow is null) - rightArrow = GetBitmap("DataGridRow.right.bmp"); - return rightArrow; - } + => throw new PlatformNotSupportedException(); public virtual void InvalidateRow() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void InvalidateRowRect(Rectangle r) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void OnEdit() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual bool OnKeyPress(Keys keyData) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual bool OnMouseDown(int x, int y, Rectangle rowHeaders) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual bool OnMouseDown(int x, int y, Rectangle rowHeaders, bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual bool OnMouseMove(int x, int y, Rectangle rowHeaders) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual bool OnMouseMove(int x, int y, Rectangle rowHeaders, bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void OnMouseLeft(Rectangle rowHeaders, bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void OnMouseLeft() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void OnRowEnter() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void OnRowLeave() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - internal abstract bool ProcessTabKey(Keys keyData, Rectangle rowHeaders, bool alignToRight); - - internal abstract void LoseChildFocus(Rectangle rowHeaders, bool alignToRight); - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public abstract int Paint(Graphics g, - Rectangle dataBounds, - Rectangle rowBounds, - int firstVisibleColumn, - int numVisibleColumns); + Rectangle dataBounds, + Rectangle rowBounds, + int firstVisibleColumn, + int numVisibleColumns); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public abstract int Paint(Graphics g, - Rectangle dataBounds, - Rectangle rowBounds, - int firstVisibleColumn, - int numVisibleColumns, - bool alignToRight); + Rectangle dataBounds, + Rectangle rowBounds, + int firstVisibleColumn, + int numVisibleColumns, + bool alignToRight); protected virtual void PaintBottomBorder(Graphics g, Rectangle bounds, int dataWidth) - { - PaintBottomBorder(g, bounds, dataWidth, dgTable.GridLineWidth, false); - } + => throw new PlatformNotSupportedException(); protected virtual void PaintBottomBorder(Graphics g, Rectangle bounds, int dataWidth, int borderWidth, bool alignToRight) { - // paint bottom border - Rectangle bottomBorder = new Rectangle(alignToRight ? bounds.Right - dataWidth : bounds.X, - bounds.Bottom - borderWidth, - dataWidth, - borderWidth); - - g.FillRectangle(dgTable.IsDefault ? DataGrid.GridLineBrush : dgTable.GridLineBrush, bottomBorder); - - // paint any exposed region to the right - if (dataWidth < bounds.Width) - { - g.FillRectangle(dgTable.DataGrid.BackgroundBrush, - alignToRight ? bounds.X : bottomBorder.Right, - bottomBorder.Y, - bounds.Width - bottomBorder.Width, - borderWidth); - } } public virtual int PaintData(Graphics g, - Rectangle bounds, - int firstVisibleColumn, - int columnCount) - { - throw new PlatformNotSupportedException(); - } + Rectangle bounds, + int firstVisibleColumn, + int columnCount) + => throw new PlatformNotSupportedException(); public virtual int PaintData(Graphics g, - Rectangle bounds, - int firstVisibleColumn, - int columnCount, - bool alignToRight) - { - throw new PlatformNotSupportedException(); - } - - protected virtual void PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, - Brush backBr, Brush foreBrush) - { - PaintCellContents(g, cellBounds, column, backBr, foreBrush, false); - } - - protected virtual void PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, - Brush backBr, Brush foreBrush, bool alignToRight) - { - g.FillRectangle(backBr, cellBounds); - } - - protected Rectangle PaintIcon(Graphics g, Rectangle visualBounds, bool paintIcon, bool alignToRight, Bitmap bmp) - { - return PaintIcon(g, visualBounds, paintIcon, alignToRight, bmp, - dgTable.IsDefault ? DataGrid.HeaderBackBrush : dgTable.HeaderBackBrush); - } - - protected Rectangle PaintIcon(Graphics g, Rectangle visualBounds, bool paintIcon, bool alignToRight, Bitmap bmp, Brush backBrush) - { - Size bmpSize = bmp.Size; - Rectangle bmpRect = new Rectangle(alignToRight ? visualBounds.Right - xOffset - bmpSize.Width : visualBounds.X + xOffset, - visualBounds.Y + yOffset, - bmpSize.Width, - bmpSize.Height); - g.FillRectangle(backBrush, visualBounds); - if (paintIcon) - { - colorMap[0].NewColor = dgTable.IsDefault ? DataGrid.HeaderForeColor : dgTable.HeaderForeColor; - colorMap[0].OldColor = Color.Black; - ImageAttributes attr = new ImageAttributes(); - attr.SetRemapTable(colorMap, ColorAdjustType.Bitmap); - g.DrawImage(bmp, bmpRect, 0, 0, bmpRect.Width, bmpRect.Height, GraphicsUnit.Pixel, attr); - attr.Dispose(); - } - - return bmpRect; - } + Rectangle bounds, + int firstVisibleColumn, + int columnCount, + bool alignToRight) + => throw new PlatformNotSupportedException(); + + protected virtual void PaintCellContents(Graphics g, + Rectangle cellBounds, + DataGridColumnStyle column, + Brush backBr, + Brush foreBrush) + => PaintCellContents(g, cellBounds, column, backBr, foreBrush, false); + + protected virtual void PaintCellContents(Graphics g, + Rectangle cellBounds, + DataGridColumnStyle column, + Brush backBr, + Brush foreBrush, + bool alignToRight) + => g.FillRectangle(backBr, cellBounds); + + protected Rectangle PaintIcon(Graphics g, + Rectangle visualBounds, + bool paintIcon, + bool alignToRight, + Bitmap bmp) + => throw new PlatformNotSupportedException(); + + protected Rectangle PaintIcon(Graphics g, + Rectangle visualBounds, + bool paintIcon, + bool alignToRight, + Bitmap bmp, + Brush backBrush) + => throw new PlatformNotSupportedException(); public virtual void PaintHeader(Graphics g, Rectangle visualBounds) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void PaintHeader(Graphics g, Rectangle visualBounds, bool alignToRight) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void PaintHeader(Graphics g, Rectangle visualBounds, bool alignToRight, bool rowIsDirty) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected Brush GetBackBrush() - { - Brush br = dgTable.IsDefault ? DataGrid.BackBrush : dgTable.BackBrush; - if (DataGrid.LedgerStyle && (RowNumber % 2 == 1)) - { - br = dgTable.IsDefault ? DataGrid.AlternatingBackBrush : dgTable.AlternatingBackBrush; - } - - return br; - } + => throw new PlatformNotSupportedException(); protected Brush BackBrushForDataPaint(ref DataGridCell current, DataGridColumnStyle gridColumn, int column) - { - Brush backBr = GetBackBrush(); - - if (Selected) - { - backBr = dgTable.IsDefault ? DataGrid.SelectionBackBrush : dgTable.SelectionBackBrush; - } - - return backBr; - } + => throw new PlatformNotSupportedException(); protected Brush ForeBrushForDataPaint(ref DataGridCell current, DataGridColumnStyle gridColumn, int column) - { - Brush foreBrush = dgTable.IsDefault ? DataGrid.ForeBrush : dgTable.ForeBrush; - - if (Selected) - { - foreBrush = dgTable.IsDefault ? DataGrid.SelectionForeBrush : dgTable.SelectionForeBrush; - } - - return foreBrush; - } + => throw new PlatformNotSupportedException(); [ComVisible(true)] - [Obsolete("DataGridRowAccessibleObject has been deprecated.")] + [Obsolete( + Obsoletions.DataGridRowAccessibleObjectMessage, + error: false, + DiagnosticId = Obsoletions.DataGridRowAccessibleObjectDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridRowAccessibleObject : AccessibleObject { - private ArrayList cells; - - internal static string CellToDisplayString(DataGrid grid, int row, int column) - { - if (column < grid.myGridTable.GridColumnStyles.Count) - { - return grid.myGridTable.GridColumnStyles[column].PropertyDescriptor.Converter.ConvertToString(grid[row, column]); - } - else - { - return ""; - } - } - - internal static object DisplayStringToCell(DataGrid grid, int row, int column, string value) - { - if (column < grid.myGridTable.GridColumnStyles.Count) - { - return grid.myGridTable.GridColumnStyles[column].PropertyDescriptor.Converter.ConvertFromString(value); - } - - return null; - } - public DataGridRowAccessibleObject(DataGridRow owner) : base() - { - throw new PlatformNotSupportedException(); - } - - private void EnsureChildren() - { - if (cells is null) - { - cells = new ArrayList(DataGrid.myGridTable.GridColumnStyles.Count + 2); - AddChildAccessibleObjects(cells); - } - } + => throw new PlatformNotSupportedException(); protected virtual void AddChildAccessibleObjects(IList children) - { - Debug.WriteLineIf(DataGrid.DataGridAcc.TraceVerbose, "Create row's accessible children"); - Debug.Indent(); - GridColumnStylesCollection cols = DataGrid.myGridTable.GridColumnStyles; - int len = cols.Count; - Debug.WriteLineIf(DataGrid.DataGridAcc.TraceVerbose, len + " columns present"); - for (int i = 0; i < len; i++) - { - children.Add(CreateCellAccessibleObject(i)); - } - - Debug.Unindent(); - } + => throw new PlatformNotSupportedException(); protected virtual AccessibleObject CreateCellAccessibleObject(int column) - { - return new AccessibleObject(); - } + => new AccessibleObject(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Name { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } protected DataGridRow Owner { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent { - get - { - throw new PlatformNotSupportedException(); - } - } - - private DataGrid DataGrid - { - get; + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Value { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } public override AccessibleObject GetChild(int index) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override int GetChildCount() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject GetFocused() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject Navigate(AccessibleNavigation navdir) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override void Select(AccessibleSelection flags) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } [ComVisible(true)] - [Obsolete("DataGridCellAccessibleObject has been deprecated.")] + [Obsolete( + Obsoletions.DataGridCellAccessibleObjectMessage, + error: false, + DiagnosticId = Obsoletions.DataGridCellAccessibleObjectDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridCellAccessibleObject : AccessibleObject { public DataGridCellAccessibleObject(DataGridRow owner, int column) : base() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Name { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } protected DataGrid DataGrid { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string DefaultAction { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Value { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public override void DoDefaultAction() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject GetFocused() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject Navigate(AccessibleNavigation navdir) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override void Select(AccessibleSelection flags) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs index 68959fa4dfd..a49f50db679 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs @@ -8,147 +8,93 @@ namespace System.Windows.Forms; #nullable disable -[Obsolete("DataGridState is obsolete. Use the DataGrid control and the System.Windows.Forms.DataGridView control instead.")] +[Obsolete( + Obsoletions.DataGridStateMessage, + error: false, + DiagnosticId = Obsoletions.DataGridStateDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal sealed class DataGridState : ICloneable { public object DataSource; public string DataMember; public CurrencyManager ListManager; - public DataGridRow[] DataGridRows = Array.Empty(); + public DataGridRow[] DataGridRows = []; public DataGrid DataGrid; public int DataGridRowsLength; public GridColumnStylesCollection GridColumnStyles; - public int FirstVisibleRow; public int FirstVisibleCol; - public int CurrentRow; public int CurrentCol; - public DataGridRow LinkingRow; - private AccessibleObject parentRowAccessibleObject; public DataGridState() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public DataGridState(DataGrid dataGrid) - { - throw new PlatformNotSupportedException(); - } - - internal AccessibleObject ParentRowAccessibleObject - { - get - { - if (parentRowAccessibleObject is null) - { - parentRowAccessibleObject = new DataGridStateParentRowAccessibleObject(this); - } - - return parentRowAccessibleObject; - } - } + => throw new PlatformNotSupportedException(); public object Clone() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void PushState(DataGrid dataGrid) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void RemoveChangeNotification() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void PullState(DataGrid dataGrid, bool createColumn) - { - throw new PlatformNotSupportedException(); - } - - private void DataSource_Changed(object sender, ItemChangedEventArgs e) - { - if (DataGrid is not null && ListManager.Position == e.Index) - { - DataGrid.InvalidateParentRows(); - return; - } - - if (DataGrid is not null) - DataGrid.ParentRowsDataChanged(); - } - - private void DataSource_MetaDataChanged(object sender, EventArgs e) - { - if (DataGrid is not null) - { - DataGrid.ParentRowsDataChanged(); - } - } + => throw new PlatformNotSupportedException(); [ComVisible(true)] - [Obsolete("DataGridStateParentRowAccessibleObject has been deprecated.")] + [Obsolete( + Obsoletions.DataGridStateParentRowAccessibleObjectMessage, + error: false, + DiagnosticId = Obsoletions.DataGridStateParentRowAccessibleObjectDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridStateParentRowAccessibleObject : AccessibleObject { public DataGridStateParentRowAccessibleObject(DataGridState owner) : base() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Name { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Value { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Navigate(AccessibleNavigation navdir) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs index 733451fbcac..5a56bf7fb04 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs @@ -1,1351 +1,499 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections; using System.ComponentModel; using System.Drawing; namespace System.Windows.Forms; -#pragma warning disable RS0016 -#nullable disable -[Obsolete("DataGridTableStyle has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.DataGridTableStyleMessage, + error: false, + DiagnosticId = Obsoletions.DataGridTableStyleDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridTableStyle : Component, IDataGridEditingService { - internal DataGrid dataGrid; - - // relationship UI - private int relationshipHeight; - internal const int relationshipSpacing = 1; - private Rectangle relationshipRect = Rectangle.Empty; - private int focusedRelation = -1; - private int focusedTextWidth; - - // will contain a list of relationships that this table has - private ArrayList relationsList = new ArrayList(2); - - private static readonly object EventAllowSorting = new object(); - private static readonly object EventGridLineColor = new object(); - private static readonly object EventGridLineStyle = new object(); - private static readonly object EventHeaderBackColor = new object(); - private static readonly object EventHeaderForeColor = new object(); - private static readonly object EventHeaderFont = new object(); - private static readonly object EventLinkColor = new object(); - private static readonly object EventLinkHoverColor = new object(); - private static readonly object EventPreferredColumnWidth = new object(); - private static readonly object EventPreferredRowHeight = new object(); - private static readonly object EventColumnHeadersVisible = new object(); - private static readonly object EventRowHeaderWidth = new object(); - private static readonly object EventSelectionBackColor = new object(); - private static readonly object EventSelectionForeColor = new object(); - private static readonly object EventMappingName = new object(); - private static readonly object EventAlternatingBackColor = new object(); - private static readonly object EventBackColor = new object(); - private static readonly object EventForeColor = new object(); - private static readonly object EventReadOnly = new object(); - private static readonly object EventRowHeadersVisible = new object(); - private const int defaultPreferredColumnWidth = 75; - internal static readonly Font defaultFont = Control.DefaultFont; - internal static readonly int defaultFontHeight = defaultFont.Height; - private SolidBrush alternatingBackBrush = DefaultAlternatingBackBrush; - private SolidBrush backBrush = DefaultBackBrush; - private SolidBrush foreBrush = DefaultForeBrush; - private SolidBrush gridLineBrush = DefaultGridLineBrush; - internal SolidBrush headerBackBrush = DefaultHeaderBackBrush; - internal Font headerFont; // this is ambient property to Font value. - internal SolidBrush headerForeBrush = DefaultHeaderForeBrush; - internal Pen headerForePen = DefaultHeaderForePen; - private SolidBrush linkBrush = DefaultLinkBrush; - internal int preferredColumnWidth = defaultPreferredColumnWidth; - private int prefferedRowHeight = defaultFontHeight + 3; - private SolidBrush selectionBackBrush = DefaultSelectionBackBrush; - private SolidBrush selectionForeBrush = DefaultSelectionForeBrush; - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool AllowSorting { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler AllowSortingChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color AlternatingBackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler AlternatingBackColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public void ResetAlternatingBackColor() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected virtual bool ShouldSerializeAlternatingBackColor() - { - return !AlternatingBackBrush.Equals(DefaultAlternatingBackBrush); - } - - internal SolidBrush AlternatingBackBrush - { - get - { - return alternatingBackBrush; - } - } + => throw new PlatformNotSupportedException(); protected bool ShouldSerializeBackColor() - { - return !DefaultBackBrush.Equals(backBrush); - } + => throw new PlatformNotSupportedException(); protected bool ShouldSerializeForeColor() - { - return DefaultForeBrush.Equals(foreBrush); - } - - internal SolidBrush BackBrush - { - get - { - return backBrush; - } - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color BackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler BackColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } public void ResetBackColor() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - internal int BorderWidth - { - get - { - DataGrid dataGrid = DataGrid; - if (dataGrid is null) - return 0; - // if the user set the GridLineStyle property on the dataGrid. - // then use the value of that property - DataGridLineStyle gridStyle; - int gridLineWidth; - if (IsDefault) - { - gridStyle = DataGrid.GridLineStyle; - gridLineWidth = DataGrid.GridLineWidth; - } - else - { - gridStyle = GridLineStyle; - gridLineWidth = GridLineWidth; - } - - if (gridStyle == DataGridLineStyle.None) - return 0; - - return gridLineWidth; - } - } - - internal static SolidBrush DefaultAlternatingBackBrush - { - get - { - return (SolidBrush)SystemBrushes.Window; - } - } - - internal static SolidBrush DefaultBackBrush - { - get - { - return (SolidBrush)SystemBrushes.Window; - } - } - - internal static SolidBrush DefaultForeBrush - { - get - { - return (SolidBrush)SystemBrushes.WindowText; - } - } - - private static SolidBrush DefaultGridLineBrush - { - get - { - return (SolidBrush)SystemBrushes.Control; - } - } - - private static SolidBrush DefaultHeaderBackBrush - { - get - { - return (SolidBrush)SystemBrushes.Control; - } - } - - private static SolidBrush DefaultHeaderForeBrush - { - get - { - return (SolidBrush)SystemBrushes.ControlText; - } - } - - private static Pen DefaultHeaderForePen - { - get - { - return new Pen(SystemColors.ControlText); - } - } - - private static SolidBrush DefaultLinkBrush - { - get - { - return (SolidBrush)SystemBrushes.HotTrack; - } - } - - private static SolidBrush DefaultSelectionBackBrush - { - get - { - return (SolidBrush)SystemBrushes.ActiveCaption; - } - } - - private static SolidBrush DefaultSelectionForeBrush - { - get - { - return (SolidBrush)SystemBrushes.ActiveCaptionText; - } - } - - internal int FocusedRelation - { - get - { - return focusedRelation; - } - set - { - if (focusedRelation != value) - { - focusedRelation = value; - if (focusedRelation == -1) - { - focusedTextWidth = 0; - } - else - { - Graphics g = DataGrid.CreateGraphicsInternal(); - focusedTextWidth = (int)Math.Ceiling(g.MeasureString(((string)RelationsList[focusedRelation]), DataGrid.LinkFont).Width); - g.Dispose(); - } - } - } - } - - internal int FocusedTextWidth - { - get - { - return focusedTextWidth; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color ForeColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler ForeColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - internal SolidBrush ForeBrush - { - get - { - return foreBrush; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } public void ResetForeColor() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color GridLineColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler GridLineColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected virtual bool ShouldSerializeGridLineColor() - { - return !GridLineBrush.Equals(DefaultGridLineBrush); - } + => throw new PlatformNotSupportedException(); public void ResetGridLineColor() - { - throw new PlatformNotSupportedException(); - } - - internal SolidBrush GridLineBrush - { - get - { - return gridLineBrush; - } - } - - internal int GridLineWidth - { - get - { - Debug.Assert(GridLineStyle == DataGridLineStyle.Solid || GridLineStyle == DataGridLineStyle.None, "are there any other styles?"); - return GridLineStyle == DataGridLineStyle.Solid ? 1 : 0; - } - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public DataGridLineStyle GridLineStyle { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler GridLineStyleChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color HeaderBackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler HeaderBackColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - internal SolidBrush HeaderBackBrush - { - get - { - return headerBackBrush; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected virtual bool ShouldSerializeHeaderBackColor() - { - return !HeaderBackBrush.Equals(DefaultHeaderBackBrush); - } + => throw new PlatformNotSupportedException(); public void ResetHeaderBackColor() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Font HeaderFont { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler HeaderFontChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - private bool ShouldSerializeHeaderFont() - { - return (headerFont is not null); + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } public void ResetHeaderFont() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color HeaderForeColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler HeaderForeColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected virtual bool ShouldSerializeHeaderForeColor() - { - return !HeaderForePen.Equals(DefaultHeaderForePen); - } + => throw new PlatformNotSupportedException(); public void ResetHeaderForeColor() - { - throw new PlatformNotSupportedException(); - } - - internal SolidBrush HeaderForeBrush - { - get - { - return headerForeBrush; - } - } - - internal Pen HeaderForePen - { - get - { - return headerForePen; - } - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color LinkColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler LinkColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected virtual bool ShouldSerializeLinkColor() - { - return !LinkBrush.Equals(DefaultLinkBrush); - } + => throw new PlatformNotSupportedException(); public void ResetLinkColor() - { - throw new PlatformNotSupportedException(); - } - - internal Brush LinkBrush - { - get - { - return linkBrush; - } - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color LinkHoverColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler LinkHoverColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected virtual bool ShouldSerializeLinkHoverColor() - { - return false; - } - - internal Rectangle RelationshipRect - { - get - { - if (relationshipRect.IsEmpty) - { - ComputeRelationshipRect(); - } - - return relationshipRect; - } - } - - private Rectangle ComputeRelationshipRect() - { - if (relationshipRect.IsEmpty && DataGrid.AllowNavigation) - { - Debug.WriteLineIf(CompModSwitches.DGRelationShpRowLayout.TraceVerbose, "GetRelationshipRect grinding away"); - Graphics g = DataGrid.CreateGraphicsInternal(); - relationshipRect = default(Rectangle); - relationshipRect.X = 0; // indentWidth; - // relationshipRect.Y = base.Height - BorderWidth; - - // Determine the width of the widest relationship name - int longestRelationship = 0; - for (int r = 0; r < RelationsList.Count; ++r) - { - int rwidth = (int)Math.Ceiling(g.MeasureString(((string)RelationsList[r]), DataGrid.LinkFont).Width) -; - if (rwidth > longestRelationship) - longestRelationship = rwidth; - } - - g.Dispose(); - - relationshipRect.Width = longestRelationship + 5; - relationshipRect.Width += 2; // relationshipRect border; - relationshipRect.Height = BorderWidth + relationshipHeight * RelationsList.Count; - relationshipRect.Height += 2; // relationship border - if (RelationsList.Count > 0) - relationshipRect.Height += 2 * relationshipSpacing; - } - - return relationshipRect; - } - - internal void ResetRelationsUI() - { - relationshipRect = Rectangle.Empty; - focusedRelation = -1; - relationshipHeight = dataGrid.LinkFontHeight + relationshipSpacing; - } - - internal int RelationshipHeight - { - get - { - return relationshipHeight; - } - } + => false; public void ResetLinkHoverColor() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int PreferredColumnWidth { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler PreferredColumnWidthChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int PreferredRowHeight { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler PreferredRowHeightChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - private void ResetPreferredRowHeight() - { - PreferredRowHeight = defaultFontHeight + 3; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected bool ShouldSerializePreferredRowHeight() - { - return prefferedRowHeight != defaultFontHeight + 3; - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool ColumnHeadersVisible { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler ColumnHeadersVisibleChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool RowHeadersVisible { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler RowHeadersVisibleChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int RowHeaderWidth { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler RowHeaderWidthChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color SelectionBackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler SelectionBackColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - internal SolidBrush SelectionBackBrush - { - get - { - return selectionBackBrush; - } - } - - internal SolidBrush SelectionForeBrush - { - get - { - return selectionForeBrush; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected bool ShouldSerializeSelectionBackColor() - { - return !DefaultSelectionBackBrush.Equals(selectionBackBrush); - } + => throw new PlatformNotSupportedException(); public void ResetSelectionBackColor() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Color SelectionForeColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler SelectionForeColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected virtual bool ShouldSerializeSelectionForeColor() - { - return !SelectionForeBrush.Equals(DefaultSelectionForeBrush); - } + => throw new PlatformNotSupportedException(); public void ResetSelectionForeColor() - { - throw new PlatformNotSupportedException(); - } - - private void InvalidateInside() - { - if (DataGrid is not null) - { - DataGrid.InvalidateInside(); - } - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public static readonly DataGridTableStyle DefaultTableStyle = new DataGridTableStyle(true); + public static readonly DataGridTableStyle s_defaultTableStyle = new DataGridTableStyle(true); public DataGridTableStyle(bool isDefaultTableStyle) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public DataGridTableStyle() : this(false) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public DataGridTableStyle(CurrencyManager listManager) : this() - { - throw new PlatformNotSupportedException(); - } - - internal void SetRelationsList(CurrencyManager listManager) - { - PropertyDescriptorCollection propCollection = listManager.GetItemProperties(); - Debug.Assert(!IsDefault, "the grid can set the relations only on a table that was manually added by the user"); - int propCount = propCollection.Count; - if (relationsList.Count > 0) - relationsList.Clear(); - for (int i = 0; i < propCount; i++) - { - PropertyDescriptor prop = propCollection[i]; - Debug.Assert(prop is not null, "prop is null: how that happened?"); - if (PropertyDescriptorIsARelation(prop)) - { - // relation - relationsList.Add(prop.Name); - } - } - } - - internal void SetGridColumnStylesCollection(CurrencyManager listManager) - { - PropertyDescriptorCollection propCollection = listManager.GetItemProperties(); - - // we need to clear the relations list - if (relationsList.Count > 0) - relationsList.Clear(); - - Debug.Assert(propCollection is not null, "propCollection is null: how that happened?"); - int propCount = propCollection.Count; - for (int i = 0; i < propCount; i++) - { - PropertyDescriptor prop = propCollection[i]; - Debug.Assert(prop is not null, "prop is null: how that happened?"); - // do not take into account the properties that are browsable. - if (!prop.IsBrowsable) - continue; - if (PropertyDescriptorIsARelation(prop)) - { - // relation - relationsList.Add(prop.Name); - } - else - { - // column - DataGridColumnStyle col = CreateGridColumn(prop); - } - } - } - - private static bool PropertyDescriptorIsARelation(PropertyDescriptor prop) - { - return typeof(IList).IsAssignableFrom(prop.PropertyType) && !typeof(Array).IsAssignableFrom(prop.PropertyType); - } - - internal protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop) - { - return CreateGridColumn(prop, false); - } + => throw new PlatformNotSupportedException(); - internal protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop, bool isDefault) - { - DataGridColumnStyle ret = null; - Type dataType = prop.PropertyType; - - if (dataType.Equals(typeof(bool))) - ret = new DataGridBoolColumn(prop, isDefault); - else if (dataType.Equals(typeof(string))) - ret = new DataGridTextBoxColumn(prop, isDefault); - else if (dataType.Equals(typeof(DateTime))) - ret = new DataGridTextBoxColumn(prop, "d", isDefault); - - else if (dataType.Equals(typeof(short)) || - dataType.Equals(typeof(int)) || - dataType.Equals(typeof(long)) || - dataType.Equals(typeof(ushort)) || - dataType.Equals(typeof(uint)) || - dataType.Equals(typeof(ulong)) || - dataType.Equals(typeof(decimal)) || - dataType.Equals(typeof(double)) || - dataType.Equals(typeof(float)) || - dataType.Equals(typeof(byte)) || - dataType.Equals(typeof(sbyte))) - { - ret = new DataGridTextBoxColumn(prop, "G", isDefault); - } - else - { - ret = new DataGridTextBoxColumn(prop, isDefault); - } - - return ret; - } - - internal void ResetRelationsList() - { - relationsList.Clear(); - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string MappingName { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler MappingNameChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - internal ArrayList RelationsList - { - get - { - return relationsList; - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual GridColumnStylesCollection GridColumnStyles { - get - { - throw new PlatformNotSupportedException(); - } - } - - internal void SetInternalDataGrid(DataGrid dG, bool force) - { - if (dataGrid is not null && dataGrid.Equals(dG) && !force) - return; - else - { - dataGrid = dG; - if (dG is not null && dG.Initializing) - return; - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual DataGrid DataGrid { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual bool ReadOnly { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler ReadOnlyChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) - { - throw new PlatformNotSupportedException(); - } - - internal void InvalidateColumn(DataGridColumnStyle column) - { - int index = GridColumnStyles.IndexOf(column); - if (index >= 0 && DataGrid is not null) - DataGrid.InvalidateColumn(index); - } - - private void OnColumnCollectionChanged(object sender, CollectionChangeEventArgs e) - { - try - { - DataGrid grid = DataGrid; - DataGridColumnStyle col = e.Element as DataGridColumnStyle; - if (e.Action == CollectionChangeAction.Add) - { - if (col is not null) - col.SetDataGridInternalInColumn(grid); - } - else if (e.Action == CollectionChangeAction.Remove) - { - if (col is not null) - col.SetDataGridInternalInColumn(null); - } - else - { - // refresh - Debug.Assert(e.Action == CollectionChangeAction.Refresh, "there are only Add, Remove and Refresh in the CollectionChangeAction"); - } - - if (grid is not null) - grid.OnColumnCollectionChanged(this, e); - } - finally - { - } - } + => throw new PlatformNotSupportedException(); protected virtual void OnReadOnlyChanged(EventArgs e) - { - EventHandler eh = Events[EventReadOnly] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnMappingNameChanged(EventArgs e) - { - EventHandler eh = Events[EventMappingName] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnAlternatingBackColorChanged(EventArgs e) - { - EventHandler eh = Events[EventAlternatingBackColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnForeColorChanged(EventArgs e) - { - EventHandler eh = Events[EventBackColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnBackColorChanged(EventArgs e) - { - EventHandler eh = Events[EventForeColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnAllowSortingChanged(EventArgs e) - { - EventHandler eh = Events[EventAllowSorting] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnGridLineColorChanged(EventArgs e) - { - EventHandler eh = Events[EventGridLineColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnGridLineStyleChanged(EventArgs e) - { - EventHandler eh = Events[EventGridLineStyle] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnHeaderBackColorChanged(EventArgs e) - { - EventHandler eh = Events[EventHeaderBackColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnHeaderFontChanged(EventArgs e) - { - EventHandler eh = Events[EventHeaderFont] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnHeaderForeColorChanged(EventArgs e) - { - EventHandler eh = Events[EventHeaderForeColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnLinkColorChanged(EventArgs e) - { - EventHandler eh = Events[EventLinkColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnLinkHoverColorChanged(EventArgs e) - { - EventHandler eh = Events[EventLinkHoverColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnPreferredRowHeightChanged(EventArgs e) - { - EventHandler eh = Events[EventPreferredRowHeight] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnPreferredColumnWidthChanged(EventArgs e) - { - EventHandler eh = Events[EventPreferredColumnWidth] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnColumnHeadersVisibleChanged(EventArgs e) - { - EventHandler eh = Events[EventColumnHeadersVisible] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnRowHeadersVisibleChanged(EventArgs e) - { - EventHandler eh = Events[EventRowHeadersVisible] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnRowHeaderWidthChanged(EventArgs e) - { - EventHandler eh = Events[EventRowHeaderWidth] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnSelectionForeColorChanged(EventArgs e) - { - EventHandler eh = Events[EventSelectionForeColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void OnSelectionBackColorChanged(EventArgs e) - { - EventHandler eh = Events[EventSelectionBackColor] as EventHandler; - if (eh is not null) - eh(this, e); - } + => throw new PlatformNotSupportedException(); protected override void Dispose(bool disposing) { @@ -1361,9 +509,4 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } - - internal bool IsDefault - { - get; - } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs index d4840618b99..1f4881afbe6 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs @@ -6,62 +6,51 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 #nullable disable -[Obsolete("GridTableStylesCollection has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.GridTableStylesCollectionMessage, + error: false, + DiagnosticId = Obsoletions.GridTableStylesCollectionDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class GridTableStylesCollection : BaseCollection, IList { - private DataGrid owner; - int IList.Add(object value) - { - return Add((DataGridTableStyle)value); - } + => Add((DataGridTableStyle)value); void IList.Clear() - { - Clear(); - } + => Clear(); bool IList.Contains(object value) - { - return default; - } + => default; int IList.IndexOf(object value) - { - return default; - } + => default; void IList.Insert(int index, object value) - { - throw new NotSupportedException(); - } + => throw new NotSupportedException(); void IList.Remove(object value) - { - Remove((DataGridTableStyle)value); - } + => Remove((DataGridTableStyle)value); void IList.RemoveAt(int index) - { - RemoveAt(index); - } + => RemoveAt(index); bool IList.IsFixedSize { - get { return false; } + get => false; } bool IList.IsReadOnly { - get { return false; } + get => false; } object IList.this[int index] { - get { return default; } - set { throw new NotSupportedException(); } + get => default; + set => throw new NotSupportedException(); } void ICollection.CopyTo(Array array, int index) @@ -70,119 +59,69 @@ void ICollection.CopyTo(Array array, int index) int ICollection.Count { - get { return default; } + get => default; } bool ICollection.IsSynchronized { - get { return false; } + get => false; } object ICollection.SyncRoot { - get { return this; } - } - - IEnumerator IEnumerable.GetEnumerator() - { - return default; + get => this; } - internal GridTableStylesCollection(DataGrid grid) - { - owner = grid; - } + IEnumerator IEnumerable.GetEnumerator() => default; protected override ArrayList List { - get - { - return default; - } + get => default; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public DataGridTableStyle this[int index] { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public DataGridTableStyle this[string tableName] { - get - { - throw new PlatformNotSupportedException(); - } - } - - internal void CheckForMappingNameDuplicates(DataGridTableStyle table) - { - if (string.IsNullOrEmpty(table.MappingName)) - return; + get => throw new PlatformNotSupportedException(); } public virtual int Add(DataGridTableStyle table) - { - throw new PlatformNotSupportedException(); - } - - private void TableStyleMappingNameChanged(object sender, EventArgs pcea) - { - OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, null)); - } + => throw new PlatformNotSupportedException(); public virtual void AddRange(DataGridTableStyle[] tables) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event CollectionChangeEventHandler CollectionChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } public void Clear() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool Contains(DataGridTableStyle table) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool Contains(string name) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected void OnCollectionChanged(CollectionChangeEventArgs e) - { - DataGrid grid = owner; - if (grid is not null) - { - grid.checkHierarchy = true; - } - } + => throw new PlatformNotSupportedException(); public void Remove(DataGridTableStyle table) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void RemoveAt(int index) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs index c808df79fde..bfd21949ae4 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs @@ -4,14 +4,20 @@ namespace System.Windows.Forms; #pragma warning disable RS0016 +[Obsolete( + Obsoletions.GridTablesFactoryMessage, + error: false, + DiagnosticId = Obsoletions.GridTablesFactoryDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public sealed class GridTablesFactory { private GridTablesFactory() { } - public static DataGridTableStyle[] CreateGridTables(DataGridTableStyle gridTable, object dataSource, string dataMember, BindingContext bindingManager) - { - throw new PlatformNotSupportedException(); - } + public static DataGridTableStyle[] CreateGridTables(DataGridTableStyle gridTable, + object dataSource, + string dataMember, + BindingContext bindingManager) + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs index 4f0c62620ce..4d1f4a46786 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs @@ -5,32 +5,23 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 -#nullable disable -[Obsolete("DataGridTextBox has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.DataGridTextBoxMessage, + error: false, + DiagnosticId = Obsoletions.DataGridTextBoxDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridTextBox : TextBox { public DataGridTextBox() : base() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void SetDataGrid(DataGrid parentGrid) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected override void WndProc(ref Message m) - { - // but what if we get a CtrlV? - // what about deleting from the menu? - if (m.Msg == PInvoke.WM_PASTE || m.Msg == PInvoke.WM_CUT || m.Msg == PInvoke.WM_CLEAR) - { - IsInEditOrNavigateMode = false; - } - - base.WndProc(ref m); - } + => base.WndProc(ref m); protected override void OnMouseWheel(MouseEventArgs e) { @@ -52,111 +43,13 @@ protected override void OnKeyPress(KeyPressEventArgs e) } protected internal override bool ProcessKeyMessage(ref Message m) - { - Keys key = (Keys)unchecked((int)(long)m.WParam); - Keys modifierKeys = ModifierKeys; - - if ((key | modifierKeys) == Keys.Enter || - (key | modifierKeys) == Keys.Escape || - ((key | modifierKeys) == (Keys.Enter | Keys.Control))) - { - return ProcessKeyPreview(ref m); - } - - Keys keyData = key & Keys.KeyCode; - - switch (keyData) - { - case Keys.Right: - if (SelectionStart + SelectionLength == Text.Length) - return ProcessKeyPreview(ref m); - return ProcessKeyEventArgs(ref m); - case Keys.Left: - if (SelectionStart + SelectionLength == 0 || - (IsInEditOrNavigateMode && SelectionLength == Text.Length)) - return ProcessKeyPreview(ref m); - return ProcessKeyEventArgs(ref m); - case Keys.Down: - int end = SelectionStart + SelectionLength; - if (Text.IndexOf("\r\n", end) == -1) - return ProcessKeyPreview(ref m); - return ProcessKeyEventArgs(ref m); - case Keys.Up: - if (Text.IndexOf("\r\n") < 0 || SelectionStart + SelectionLength < Text.IndexOf("\r\n")) - return ProcessKeyPreview(ref m); - return ProcessKeyEventArgs(ref m); - case Keys.Home: - case Keys.End: - if (SelectionLength == Text.Length) - return ProcessKeyPreview(ref m); - else - return ProcessKeyEventArgs(ref m); - case Keys.Prior: - case Keys.Next: - case Keys.Oemplus: - case Keys.Add: - case Keys.OemMinus: - case Keys.Subtract: - if (IsInEditOrNavigateMode) - { - return ProcessKeyPreview(ref m); - } - else - { - return ProcessKeyEventArgs(ref m); - } - - case Keys.Space: - if (IsInEditOrNavigateMode && (ModifierKeys & Keys.Shift) == Keys.Shift) - { - return ProcessKeyPreview(ref m); - } - - return ProcessKeyEventArgs(ref m); - case Keys.A: - if (IsInEditOrNavigateMode && (ModifierKeys & Keys.Control) == Keys.Control) - { - return ProcessKeyPreview(ref m); - } - - return ProcessKeyEventArgs(ref m); - case Keys.F2: - IsInEditOrNavigateMode = false; - SelectionStart = Text.Length; - return true; - case Keys.Delete: - if (IsInEditOrNavigateMode) - { - if (ProcessKeyPreview(ref m)) - return true; - else - { - IsInEditOrNavigateMode = false; - return ProcessKeyEventArgs(ref m); - } - } - else - return ProcessKeyEventArgs(ref m); - case Keys.Tab: - if ((ModifierKeys & Keys.Control) == Keys.Control) - return ProcessKeyPreview(ref m); - else - return ProcessKeyEventArgs(ref m); - default: - return ProcessKeyEventArgs(ref m); - } - } + => base.ProcessKeyMessage(ref m); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool IsInEditOrNavigateMode { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs index c8f56b1f1a7..1b9ec360177 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs @@ -3,406 +3,162 @@ using System.ComponentModel; using System.Drawing; -using System.Globalization; namespace System.Windows.Forms; -#pragma warning disable RS0016 #nullable disable -[Obsolete("DataGridTextBoxColumn has been deprecated. Use DataGridViewTextBoxColumn instead. http://go.microsoft.com/fwlink/?linkid=14202")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.DataGridTextBoxColumnMessage, + error: false, + DiagnosticId = Obsoletions.DataGridTextBoxColumnDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridTextBoxColumn : DataGridColumnStyle { - private int xMargin = 2; - private int yMargin = 1; - - private DataGridTextBox edit; - - private string oldValue; - private int editRow = -1; - public DataGridTextBoxColumn() : this(null, null) - { - edit = new DataGridTextBox(); - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public DataGridTextBoxColumn(PropertyDescriptor prop) : this(prop, null, false) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - public DataGridTextBoxColumn(PropertyDescriptor prop, string format) : this(prop, format, false) - { - throw new PlatformNotSupportedException(); - } + public DataGridTextBoxColumn(PropertyDescriptor prop, string format) + : this(prop, format, false) + => throw new PlatformNotSupportedException(); - public DataGridTextBoxColumn(PropertyDescriptor prop, string format, bool isDefault) : base(prop, isDefault) - { - throw new PlatformNotSupportedException(); - } + public DataGridTextBoxColumn(PropertyDescriptor prop, string format, bool isDefault) + : base(prop, isDefault) + => throw new PlatformNotSupportedException(); - public DataGridTextBoxColumn(PropertyDescriptor prop, bool isDefault) : this(prop, null, isDefault) - { - throw new PlatformNotSupportedException(); - } + public DataGridTextBoxColumn(PropertyDescriptor prop, bool isDefault) + : this(prop, null, isDefault) + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual TextBox TextBox { - get - { - throw new PlatformNotSupportedException(); - } - } - - internal override bool KeyPress(int rowNum, Keys keyData) - { - if (edit.IsInEditOrNavigateMode) - return base.KeyPress(rowNum, keyData); - - return false; + get => throw new PlatformNotSupportedException(); } protected override void SetDataGridInColumn(DataGrid value) { - base.SetDataGridInColumn(value); - if (edit.ParentInternal is not null) - { - edit.ParentInternal.Controls.Remove(edit); - } - - if (value is not null) - { - value.Controls.Add(edit); - } - - // we have to tell the edit control about its dataGrid - edit.SetDataGrid(value); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override PropertyDescriptor PropertyDescriptor { - set - { - throw new PlatformNotSupportedException(); - } + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string Format { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public IFormatProvider FormatInfo { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override bool ReadOnly { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - private static void DebugOut(string s) - { - Debug.WriteLineIf(CompModSwitches.DGEditColumnEditing.TraceVerbose, "DGEditColumnEditing: " + s); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } protected internal override void ConcedeFocus() { - edit.Bounds = Rectangle.Empty; } protected void HideEditBox() { - bool wasFocused = edit.Focused; - edit.Visible = false; - - if (wasFocused && DataGridTableStyle is not null && DataGridTableStyle.DataGrid is not null && DataGridTableStyle.DataGrid.CanFocus) - { - Debug.Assert(!edit.Focused, "the edit control just conceeded focus to the dataGrid"); - } } protected internal override void UpdateUI(CurrencyManager source, int rowNum, string displayText) { - edit.Text = GetText(GetColumnValueAtRow(source, rowNum)); - if (!edit.ReadOnly && displayText is not null) - edit.Text = displayText; } protected void EndEdit() { - edit.IsInEditOrNavigateMode = true; - DebugOut("Ending Edit"); - Invalidate(); } protected internal override Size GetPreferredSize(Graphics g, object value) - { - Size extents = Size.Ceiling(g.MeasureString(GetText(value), DataGridTableStyle.DataGrid.Font)); - extents.Width += xMargin * 2 + this.DataGridTableStyle.GridLineWidth; - extents.Height += yMargin; - return extents; - } + => throw new PlatformNotSupportedException(); protected internal override int GetMinimumHeight() - { - // why + 3? cause we have to give some way to the edit box. - return FontHeight + yMargin + 3; - } + => throw new PlatformNotSupportedException(); protected internal override int GetPreferredHeight(Graphics g, object value) - { - int newLineIndex = 0; - int newLines = 0; - string valueString = GetText(value); - while (newLineIndex != -1 && newLineIndex < valueString.Length) - { - newLineIndex = valueString.IndexOf("\r\n", newLineIndex + 1); - newLines++; - } - - return FontHeight * newLines + yMargin; - } + => throw new PlatformNotSupportedException(); protected internal override void Abort(int rowNum) { - RollBack(); - HideEditBox(); - EndEdit(); } protected internal override void EnterNullValue() { - if (ReadOnly) - return; - - // if the edit box is not visible, then - // do not put the edit text in it - if (!edit.Visible) - return; - - // if we are editing, then we should be able to enter alt-0 in a cell. - // - if (!edit.IsInEditOrNavigateMode) - return; - - edit.Text = NullText; - // edit.Visible = true; - edit.IsInEditOrNavigateMode = false; - // tell the dataGrid that there is an edit: - if (DataGridTableStyle is not null && DataGridTableStyle.DataGrid is not null) - DataGridTableStyle.DataGrid.ColumnStartedEditing(edit.Bounds); } protected internal override bool Commit(CurrencyManager dataSource, int rowNum) - { - // always hide the edit box - // HideEditBox(); - edit.Bounds = Rectangle.Empty; - - if (edit.IsInEditOrNavigateMode) - return true; - - try - { - object value = edit.Text; - if (NullText.Equals(value)) - { - value = Convert.DBNull; - edit.Text = NullText; - } - else if (FormatInfo is not null) - { - edit.Text = value.ToString(); - } - - SetColumnValueAtRow(dataSource, rowNum, value); - } - catch - { - RollBack(); - return false; - } - - DebugOut("OnCommit completed without Exception."); - EndEdit(); - return true; - } + => throw new PlatformNotSupportedException(); protected internal override void Edit(CurrencyManager source, - int rowNum, - Rectangle bounds, - bool readOnly, - string displayText, - bool cellIsVisible) - { - DebugOut("Begining Edit, rowNum :" + rowNum.ToString(CultureInfo.InvariantCulture)); - - Rectangle originalBounds = bounds; - - edit.ReadOnly = readOnly || ReadOnly || DataGridTableStyle.ReadOnly; - - edit.Text = GetText(GetColumnValueAtRow(source, rowNum)); - if (!edit.ReadOnly && displayText is not null) - { - // tell the grid that we are changing stuff - DataGridTableStyle.DataGrid.ColumnStartedEditing(bounds); - // tell the edit control that the user changed it - edit.IsInEditOrNavigateMode = false; - edit.Text = displayText; - } - - if (cellIsVisible) - { - bounds.Offset(xMargin, 2 * yMargin); - bounds.Width -= xMargin; - bounds.Height -= 2 * yMargin; - DebugOut("edit bounds: " + bounds.ToString()); - edit.Bounds = bounds; - - edit.Visible = true; - - edit.TextAlign = Alignment; - } - else - { - edit.Bounds = Rectangle.Empty; - // edit.Bounds = originalBounds; - // edit.Visible = false; - } - - edit.RightToLeft = this.DataGridTableStyle.DataGrid.RightToLeft; - - editRow = rowNum; - - if (!edit.ReadOnly) - { - oldValue = edit.Text; - } - - // select the text even if the text box is read only - // because the navigation code in the DataGridTextBox::ProcessKeyMessage - // uses the SelectedText property - if (displayText is null) - edit.SelectAll(); - else - { - int end = edit.Text.Length; - edit.Select(end, 0); - } - - if (edit.Visible) - DataGridTableStyle.DataGrid.Invalidate(originalBounds); - } - - internal override string GetDisplayText(object value) - { - return GetText(value); - } - - private string GetText(object value) - { - if (value is DBNull) - return NullText; - else if (value is IFormattable) - { - try - { - return ((IFormattable)value).ToString(); - } - catch - { - // CONSIDER: maybe we should fall back to using the typeConverter? - } - } - - return (value is not null ? value.ToString() : ""); - } - - protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) - { - string text = GetText(GetColumnValueAtRow(source, rowNum)); - PaintText(g, bounds, text, alignToRight); - } - - protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, - Brush backBrush, Brush foreBrush, bool alignToRight) - { - string text = GetText(GetColumnValueAtRow(source, rowNum)); - PaintText(g, bounds, text, backBrush, foreBrush, alignToRight); - } - - protected void PaintText(Graphics g, Rectangle bounds, string text, bool alignToRight) - { - PaintText(g, bounds, text, DataGridTableStyle.BackBrush, DataGridTableStyle.ForeBrush, alignToRight); - } - - protected void PaintText(Graphics g, Rectangle textBounds, string text, Brush backBrush, Brush foreBrush, bool alignToRight) - { - Rectangle rect = textBounds; - - StringFormat format = new StringFormat(); - if (alignToRight) - { - format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; - } - - format.Alignment = Alignment == HorizontalAlignment.Left ? StringAlignment.Near : Alignment == HorizontalAlignment.Center ? StringAlignment.Center : StringAlignment.Far; - - // do not wrap the text - // - format.FormatFlags |= StringFormatFlags.NoWrap; - - g.FillRectangle(backBrush, rect); - // by design, painting leaves a little padding around the rectangle. - // so do not deflate the rectangle. - rect.Offset(0, 2 * yMargin); - rect.Height -= 2 * yMargin; - g.DrawString(text, DataGridTableStyle.DataGrid.Font, foreBrush, rect, format); - format.Dispose(); - } - - private void RollBack() - { - Debug.Assert(!edit.IsInEditOrNavigateMode, "Must be editing to rollback changes..."); - edit.Text = oldValue; - } + int rowNum, + Rectangle bounds, + bool readOnly, + string displayText, + bool cellIsVisible) + { + } + + protected internal override void Paint(Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum, + bool alignToRight) + => throw new PlatformNotSupportedException(); + + protected internal override void Paint(Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum, + Brush backBrush, + Brush foreBrush, + bool alignToRight) + => throw new PlatformNotSupportedException(); + + protected void PaintText(Graphics g, + Rectangle bounds, + string text, + bool alignToRight) + => throw new PlatformNotSupportedException(); + + protected void PaintText(Graphics g, + Rectangle textBounds, + string text, + Brush backBrush, + Brush foreBrush, + bool alignToRight) + => throw new PlatformNotSupportedException(); protected internal override void ReleaseHostedControl() - { - if (edit.ParentInternal is not null) - { - edit.ParentInternal.Controls.Remove(edit); - } - } - - protected internal override void Paint(Graphics g1, Graphics g, Rectangle bounds, CurrencyManager source, int rowNum) => throw new NotImplementedException(); + => throw new PlatformNotSupportedException(); + + protected internal override void Paint(Graphics g1, + Graphics g, + Rectangle bounds, + CurrencyManager source, + int rowNum) + => throw new NotImplementedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs index 1d09b6c8f00..44771245302 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs @@ -6,35 +6,25 @@ namespace System.Windows.Forms; #nullable disable +[Obsolete( + Obsoletions.DataGridToolTipMessage, + error: false, + DiagnosticId = Obsoletions.DataGridToolTipDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] internal class DataGridToolTip : MarshalByRefObject { - // CONSTRUCTOR public DataGridToolTip(DataGrid dataGrid) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - // will ensure that the toolTip window was created public static void CreateToolTipHandle() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - // this function will add a toolTip to the - // windows system public static void AddToolTip(string toolTipString, IntPtr toolTipId, Rectangle iconBounds) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public static void RemoveToolTip(IntPtr toolTipId) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - // will destroy the tipWindow public static void Destroy() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs index b6f55b5deab..d7cb77a4bd1 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs @@ -6,259 +6,138 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 #nullable disable -[Obsolete("GridColumnStylesCollection has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.GridColumnStylesCollectionMessage, + error: false, + DiagnosticId = Obsoletions.GridColumnStylesCollectionDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class GridColumnStylesCollection : BaseCollection, IList { - private ArrayList items = new ArrayList(); - private DataGridTableStyle owner; - private bool isDefault; - int IList.Add(object value) - { - return Add((DataGridColumnStyle)value); - } + => Add((DataGridColumnStyle)value); void IList.Clear() - { - Clear(); - } + => Clear(); bool IList.Contains(object value) - { - return items.Contains(value); - } + => throw new PlatformNotSupportedException(); int IList.IndexOf(object value) - { - return items.IndexOf(value); - } + => throw new PlatformNotSupportedException(); void IList.Insert(int index, object value) - { - throw new NotSupportedException(); - } + => throw new PlatformNotSupportedException(); void IList.Remove(object value) - { - Remove((DataGridColumnStyle)value); - } + => Remove((DataGridColumnStyle)value); void IList.RemoveAt(int index) - { - RemoveAt(index); - } + => RemoveAt(index); bool IList.IsFixedSize { - get { return false; } + get => false; } bool IList.IsReadOnly { - get { return false; } + get => false; } object IList.this[int index] { - get { return items[index]; } - set { throw new NotSupportedException(); } + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); } void ICollection.CopyTo(Array array, int index) - { - items.CopyTo(array, index); - } + => throw new PlatformNotSupportedException(); int ICollection.Count { - get { return items.Count; } + get => throw new PlatformNotSupportedException(); } bool ICollection.IsSynchronized { - get { return false; } + get => false; } object ICollection.SyncRoot { - get { return this; } + get => this; } IEnumerator IEnumerable.GetEnumerator() - { - return items.GetEnumerator(); - } - - internal GridColumnStylesCollection(DataGridTableStyle table) - { - owner = table; - } - - internal GridColumnStylesCollection(DataGridTableStyle table, bool isDefault) : this(table) - { - this.isDefault = isDefault; - } + => throw new PlatformNotSupportedException(); protected override ArrayList List { - get - { - return items; - } + get => throw new PlatformNotSupportedException(); } + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public DataGridColumnStyle this[int index] { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public DataGridColumnStyle this[string columnName] { - get - { - throw new PlatformNotSupportedException(); - } - } - - internal DataGridColumnStyle MapColumnStyleToPropertyName(string mappingName) - { - int itemCount = items.Count; - for (int i = 0; i < itemCount; ++i) - { - DataGridColumnStyle column = (DataGridColumnStyle)items[i]; - // NOTE: case-insensitive - if (string.Equals(column.MappingName, mappingName, StringComparison.OrdinalIgnoreCase)) - return column; - } - - return null; + get => throw new PlatformNotSupportedException(); } + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public DataGridColumnStyle this[PropertyDescriptor propertyDesciptor] { - get - { - throw new PlatformNotSupportedException(); - } - } - - internal DataGridTableStyle DataGridTableStyle - { - get - { - return owner; - } - } - - internal void CheckForMappingNameDuplicates(DataGridColumnStyle column) - { - if (string.IsNullOrEmpty(column.MappingName)) - return; - for (int i = 0; i < items.Count; i++) - if (((DataGridColumnStyle)items[i]).MappingName.Equals(column.MappingName) && column != items[i]) - throw new ArgumentException("Data grid column styles collection already contains a column style with the same mapping name."); - } - - private void ColumnStyleMappingNameChanged(object sender, EventArgs pcea) - { - OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, null)); - } - - private void ColumnStylePropDescChanged(object sender, EventArgs pcea) - { - OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, (DataGridColumnStyle)sender)); + get => throw new PlatformNotSupportedException(); } public virtual int Add(DataGridColumnStyle column) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void AddRange(DataGridColumnStyle[] columns) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - internal void AddDefaultColumn(DataGridColumnStyle column) - { - column.SetDataGridTableInColumn(owner, true); - items.Add(column); - } - - internal void ResetDefaultColumnCollection() - { - for (int i = 0; i < Count; i++) - { - this[i].ReleaseHostedControl(); - } - - items.Clear(); - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event CollectionChangeEventHandler CollectionChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } public void Clear() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool Contains(PropertyDescriptor propertyDescriptor) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool Contains(DataGridColumnStyle column) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool Contains(string name) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public int IndexOf(DataGridColumnStyle element) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected void OnCollectionChanged(CollectionChangeEventArgs e) - { - DataGrid grid = owner.DataGrid; - if (grid is not null) - { - grid.checkHierarchy = true; - } - } + => throw new PlatformNotSupportedException(); public void Remove(DataGridColumnStyle column) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void RemoveAt(int index) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void ResetPropertyDescriptors() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/IDataGridEditingService.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/IDataGridEditingService.cs index a44c7654fa1..b27c4d31fe4 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/IDataGridEditingService.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/IDataGridEditingService.cs @@ -3,9 +3,13 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 -#nullable disable -[Obsolete("IDataGridEditingService has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.IDataGridEditingServiceMessage, + error: false, + DiagnosticId = Obsoletions.IDataGridEditingServiceDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public interface IDataGridEditingService { bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs index 80c4ed8adcb..dd875d739c8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs @@ -5,91 +5,46 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("MainMenu has been deprecated. Use MenuStrip instead.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.MainMenuMessage, + error: false, + DiagnosticId = Obsoletions.MainMenuDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class MainMenu : Menu { -#nullable disable - internal Form form; - internal Form ownerForm; // this is the form that created this menu, and is the only form allowed to dispose it. + public MainMenu() : base(null) + => throw new PlatformNotSupportedException(); - /// - /// Creates a new MainMenu control. - /// - public MainMenu() - : base(null) - { - throw new PlatformNotSupportedException(); - } - - /// - /// Initializes a new instance of the class with the specified container. - /// public MainMenu(IContainer container) : this() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Creates a new MainMenu control with the given items to start - /// with. - /// - public MainMenu(MenuItem[] items) - : base(items) - { - throw new PlatformNotSupportedException(); - } + public MainMenu(MenuItem[] items) : base(items) + => throw new PlatformNotSupportedException(); - [SRDescription("Occurs when the main menu collapses.")] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler Collapse { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// This is used for international applications where the language - /// is written from RightToLeft. When this property is true, - /// text alignment and reading order will be from right to left. - /// - // Add an AmbientValue attribute so that the Reset context menu becomes available in the Property Grid. - [Localizable(true), AmbientValue(RightToLeft.Inherit), - SRDescription("Indicates if this menu should display right to left"), - Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual RightToLeft RightToLeft { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Creates a new MainMenu object which is a dupliate of this one. - /// public virtual MainMenu CloneMenu() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Indicates which form in which we are currently residing [if any] - /// public Form GetForm() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Returns a string representation for this control. - /// public override string ToString() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs index 533c8b67e2e..3a89b4f4de9 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs @@ -5,672 +5,228 @@ using System.ComponentModel; using System.Drawing; using System.Globalization; -using System.Windows.Forms.VisualStyles; namespace System.Windows.Forms; -#pragma warning disable RS0016 #nullable disable -[Obsolete("StatusBar is obsolete. Use the StatusStrip control instead. StatusBar will be removed in a future release.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.StatusBarMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class StatusBar : Control { - private int sizeGripWidth; - private static readonly object EVENT_PANELCLICK = new object(); - private static readonly object EVENT_SBDRAWITEM = new object(); - - private bool layoutDirty; - private int panelsRealized; - private bool sizeGrip = true; - private Point lastClick = new Point(0, 0); - private IList panels = new ArrayList(); - private ControlToolTip tooltips; - - private ToolTip mainToolTip; - private bool toolTipSet; - - public StatusBar() - : base() - { - throw new PlatformNotSupportedException(); - } - - private static VisualStyleRenderer renderer; - - /// - /// A VisualStyleRenderer we can use to get information about the current UI theme - /// - private static VisualStyleRenderer VisualStyleRenderer - { - get - { - if (VisualStyleRenderer.IsSupported) - { - if (renderer is null) - { - renderer = new VisualStyleRenderer(VisualStyleElement.ToolBar.Button.Normal); - } - } - else - { - renderer = null; - } - - return renderer; - } - } + public StatusBar() : base() + => throw new PlatformNotSupportedException(); - private int SizeGripWidth - { - get - { - if (sizeGripWidth == 0) - { - if (Application.RenderWithVisualStyles && VisualStyleRenderer is not null) - { - // VSWhidbey 207045: need to build up accurate gripper width to avoid cutting off other panes. - VisualStyleRenderer vsRenderer = VisualStyleRenderer; - VisualStyleElement thisElement; - Size elementSize; - - // gripper pane width... - thisElement = VisualStyleElement.Status.GripperPane.Normal; - vsRenderer.SetParameters(thisElement); - elementSize = vsRenderer.GetPartSize(Graphics.FromHwndInternal(Handle), ThemeSizeType.True); - sizeGripWidth = elementSize.Width; - - // ...plus gripper width - thisElement = VisualStyleElement.Status.Gripper.Normal; - vsRenderer.SetParameters(thisElement); - elementSize = vsRenderer.GetPartSize(Graphics.FromHwndInternal(Handle), ThemeSizeType.True); - sizeGripWidth += elementSize.Width; - - // Either GetPartSize could have returned a width of zero, so make sure we have a reasonable number: - sizeGripWidth = Math.Max(sizeGripWidth, 16); - } - else - { - sizeGripWidth = 16; - } - } - - return sizeGripWidth; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Color BackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Image BackgroundImage { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override ImageLayout BackgroundImageLayout { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageLayoutChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected override CreateParams CreateParams { - get - { - CreateParams cp = base.CreateParams; - return cp; - } + get => base.CreateParams; } protected override ImeMode DefaultImeMode { - get - { - return ImeMode.Disable; - } + get => ImeMode.Disable; } protected override Size DefaultSize { - get - { - return new Size(100, 22); - } + get => new Size(100, 22); } - [EditorBrowsable(EditorBrowsableState.Never)] protected override bool DoubleBuffered { - get - { - return base.DoubleBuffered; - } - set - { - base.DoubleBuffered = value; - } + get => base.DoubleBuffered; + set => base.DoubleBuffered = value; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override DockStyle Dock { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Font Font { - get { throw new PlatformNotSupportedException(); } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Color ForeColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler ForeColorChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public ImeMode ImeMode { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler ImeModeChanged { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanelCollection Panels { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Text { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool ShowPanels { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool SizingGrip { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public bool TabStop { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - internal bool ToolTipSet - { - get - { - return toolTipSet; - } - } - - internal ToolTip MainToolTip - { - get - { - return mainToolTip; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event StatusBarDrawItemEventHandler DrawItem { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event StatusBarPanelClickEventHandler PanelClick { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public new event PaintEventHandler Paint { - add - { - throw new PlatformNotSupportedException(); - } - remove - { - throw new PlatformNotSupportedException(); - } - } - - internal bool ArePanelsRealized() - { - return IsHandleCreated; - } - - internal void DirtyLayout() - { - layoutDirty = true; - } - - private void ApplyPanelWidths() - { - // This forces handle creation every time any time the StatusBar - // has to be re-laidout. - if (!IsHandleCreated) - return; - - StatusBarPanel panel = null; - int length = panels.Count; - - if (length == 0) - { - Size sz = Size; - int[] offsets = new int[1]; - offsets[0] = sz.Width; - if (sizeGrip) - { - offsets[0] -= SizeGripWidth; - } - - return; - } - - int[] offsets2 = new int[length]; - int currentOffset = 0; - for (int i = 0; i < length; i++) - { - panel = (StatusBarPanel)this.panels[i]; - currentOffset += panel.Width; - offsets2[i] = currentOffset; - panel.Right = offsets2[i]; - } - - // Tooltip setup... - // - for (int i = 0; i < length; i++) - { - panel = (StatusBarPanel)this.panels[i]; - UpdateTooltip(panel); - } - - layoutDirty = false; + add => throw new PlatformNotSupportedException(); + remove => throw new PlatformNotSupportedException(); } protected override void CreateHandle() - { - base.CreateHandle(); - } + => base.CreateHandle(); protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - } - - private void ForcePanelUpdate() - { - if (ArePanelsRealized()) - { - layoutDirty = true; - SetPanelContentsWidths(true); - PerformLayout(); - RealizePanels(); - } - } + => base.Dispose(disposing); protected override void OnHandleCreated(EventArgs e) - { - base.OnHandleCreated(e); - if (!DesignMode) - { - tooltips = new ControlToolTip(this); - } - - ForcePanelUpdate(); - } + => base.OnHandleCreated(e); protected override void OnHandleDestroyed(EventArgs e) - { - base.OnHandleDestroyed(e); - if (tooltips is not null) - { - tooltips.Dispose(); - tooltips = null; - } - } + => base.OnHandleDestroyed(e); protected override void OnMouseDown(MouseEventArgs e) - { - lastClick.X = e.X; - lastClick.Y = e.Y; - base.OnMouseDown(e); - } + => base.OnMouseDown(e); protected virtual void OnPanelClick(StatusBarPanelClickEventArgs e) - { - StatusBarPanelClickEventHandler handler = (StatusBarPanelClickEventHandler)Events[EVENT_PANELCLICK]; - if (handler is not null) - handler(this, e); - } + => throw new PlatformNotSupportedException(); protected override void OnLayout(LayoutEventArgs levent) - { - base.OnLayout(levent); - } - - internal void RealizePanels() - { - StatusBarPanel panel = null; - int length = panels.Count; - int old = panelsRealized; - - panelsRealized = 0; - - int i; - for (i = 0; i < length; i++) - { - panel = (StatusBarPanel)panels[i]; - try - { - panel.Realize(); - panelsRealized++; - } - catch - { - } - } - } - - internal void RemoveAllPanelsWithoutUpdate() - { - int size = panels.Count; - // remove the parent reference - for (int i = 0; i < size; i++) - { - StatusBarPanel sbp = (StatusBarPanel)panels[i]; - sbp.ParentInternal = null; - } - - panels.Clear(); - } - - internal void SetPanelContentsWidths(bool newPanels) - { - int size = panels.Count; - bool changed = false; - for (int i = 0; i < size; i++) - { - StatusBarPanel sbp = (StatusBarPanel)panels[i]; - if (sbp.AutoSize == StatusBarPanelAutoSize.Contents) - { - int newWidth = sbp.GetContentsWidth(newPanels); - if (sbp.Width != newWidth) - { - sbp.Width = newWidth; - changed = true; - } - } - } - - if (changed) - { - DirtyLayout(); - PerformLayout(); - } - } - - private void SetSimpleText(string simpleText) - { - } - - private void LayoutPanels() - { - StatusBarPanel panel = null; - int barPanelWidth = 0; - int springNum = 0; - StatusBarPanel[] pArray = new StatusBarPanel[panels.Count]; - bool changed = false; - - for (int i = 0; i < pArray.Length; i++) - { - panel = (StatusBarPanel)this.panels[i]; - if (panel.AutoSize == StatusBarPanelAutoSize.Spring) - { - pArray[springNum] = panel; - springNum++; - } - else - barPanelWidth += panel.Width; - } - - if (springNum > 0) - { - Rectangle rect = Bounds; - int springPanelsLeft = springNum; - int leftoverWidth = rect.Width - barPanelWidth; - if (sizeGrip) - { - leftoverWidth -= SizeGripWidth; - } - - int copyOfLeftoverWidth = unchecked((int)0x80000000); - while (springPanelsLeft > 0) - { - int widthOfSpringPanel = (leftoverWidth) / springPanelsLeft; - if (leftoverWidth == copyOfLeftoverWidth) - break; - copyOfLeftoverWidth = leftoverWidth; - - for (int i = 0; i < springNum; i++) - { - panel = pArray[i]; - if (panel is null) - continue; - - if (widthOfSpringPanel < panel.MinWidth) - { - if (panel.Width != panel.MinWidth) - { - changed = true; - } - - panel.Width = panel.MinWidth; - pArray[i] = null; - springPanelsLeft--; - leftoverWidth -= panel.MinWidth; - } - else - { - if (panel.Width != widthOfSpringPanel) - { - changed = true; - } - - panel.Width = widthOfSpringPanel; - } - } - } - } - - if (changed || layoutDirty) - { - ApplyPanelWidths(); - } - } + => base.OnLayout(levent); protected virtual void OnDrawItem(StatusBarDrawItemEventArgs sbdievent) - { - StatusBarDrawItemEventHandler handler = (StatusBarDrawItemEventHandler)Events[EVENT_SBDRAWITEM]; - if (handler is not null) - handler(this, sbdievent); - } + => throw new PlatformNotSupportedException(); protected override void OnResize(EventArgs e) - { - Invalidate(); - base.OnResize(e); - } + => base.OnResize(e); public override string ToString() { @@ -685,644 +241,124 @@ public override string ToString() return s; } - new internal void SetToolTip(ToolTip t) - { - mainToolTip = t; - toolTipSet = true; - } - - internal void UpdateTooltip(StatusBarPanel panel) - { - if (tooltips is null) - { - if (IsHandleCreated && !DesignMode) - { - tooltips = new ControlToolTip(this); - } - else - { - return; - } - } - - if (panel.Parent == this && panel.ToolTipText.Length > 0) - { - int border = SystemInformation.Border3DSize.Width; - ControlToolTip.Tool t = tooltips.GetTool(panel); - if (t is null) - { - t = new ControlToolTip.Tool(); - } - - t.text = panel.ToolTipText; - t.rect = new Rectangle(panel.Right - panel.Width + border, 0, panel.Width - border, Height); - tooltips.SetTool(panel, t); - } - else - { - tooltips.SetTool(panel, null); - } - } - - private void UpdatePanelIndex() - { - int length = panels.Count; - for (int i = 0; i < length; i++) - { - ((StatusBarPanel)panels[i]).Index = i; - } - } - - private void WmDrawItem(ref Message m) - { - DRAWITEMSTRUCT dis = (DRAWITEMSTRUCT)m.GetLParam(typeof(DRAWITEMSTRUCT)); - - int length = panels.Count; - if (dis.itemID < 0 || dis.itemID >= length) - Debug.Fail("OwnerDraw item out of range"); - - StatusBarPanel panel = (StatusBarPanel) - panels[0]; - - Graphics g = Graphics.FromHdcInternal(dis.hDC); - Rectangle r = Rectangle.FromLTRB(dis.rcItem.left, dis.rcItem.top, dis.rcItem.right, dis.rcItem.bottom); - - g.Dispose(); - } - - private void WmNotifyNMClick(NMHDR note) - { - int size = panels.Count; - int currentOffset = 0; - int index = -1; - for (int i = 0; i < size; i++) - { - StatusBarPanel panel = (StatusBarPanel)panels[i]; - currentOffset += panel.Width; - if (lastClick.X < currentOffset) - { - // this is where the mouse was clicked. - index = i; - break; - } - } - - if (index != -1) - { - MouseButtons button = MouseButtons.Left; - int clicks = 0; - switch (note.code) - { - case PInvoke.NM_CLICK: - button = MouseButtons.Left; - clicks = 1; - break; - case PInvoke.NM_RCLICK: - button = MouseButtons.Right; - clicks = 1; - break; - case PInvoke.NM_DBLCLK: - button = MouseButtons.Left; - clicks = 2; - break; - case PInvoke.NM_RDBLCLK: - button = MouseButtons.Right; - clicks = 2; - break; - } - - Point pt = lastClick; - StatusBarPanel panel = (StatusBarPanel)panels[index]; - - StatusBarPanelClickEventArgs sbpce = new StatusBarPanelClickEventArgs(panel, - button, clicks, pt.X, pt.Y); - OnPanelClick(sbpce); - } - } - - private void WmNCHitTest(ref Message m) - { - int x = PARAM.LOWORD(m.LParam); - Rectangle bounds = Bounds; - bool callSuper = true; - - // The default implementation of the statusbar - // : will let you size the form when it is docked on the bottom, - // : but when it is anywhere else, the statusbar will be resized. - // : to prevent that we provide a little bit a sanity to only - // : allow resizing, when it would resize the form. - // - if (x > bounds.X + bounds.Width - SizeGripWidth) - { - Control parent = ParentInternal; - if (parent is not null && parent is Form) - { - FormBorderStyle bs = ((Form)parent).FormBorderStyle; - - if (bs != FormBorderStyle.Sizable - && bs != FormBorderStyle.SizableToolWindow) - { - callSuper = false; - } - - if (!((Form)parent).TopLevel - || Dock != DockStyle.Bottom) - { - callSuper = false; - } - - if (callSuper) - { - Control.ControlCollection children = parent.Controls; - int c = children.Count; - for (int i = 0; i < c; i++) - { - Control ctl = children[i]; - if (ctl != this && ctl.Dock == DockStyle.Bottom) - { - if (ctl.Top > Top) - { - callSuper = false; - break; - } - } - } - } - } - else - { - callSuper = false; - } - } - - if (callSuper) - { - base.WndProc(ref m); - } - else - { - m.Result = (IntPtr)PInvoke.HTCLIENT; - } - } - protected override void WndProc(ref Message m) - { - switch (m.MsgInternal) - { - case PInvoke.WM_NCHITTEST: - WmNCHitTest(ref m); - break; - case MessageId.WM_REFLECT + PInvoke.WM_DRAWITEM: - WmDrawItem(ref m); - break; - case PInvoke.WM_NOTIFY: - case PInvoke.WM_NOTIFY + MessageId.WM_REFLECT: - NMHDR note = (NMHDR)m.GetLParam(typeof(NMHDR)); - switch (note.code) - { - case PInvoke.NM_CLICK: - case PInvoke.NM_RCLICK: - case PInvoke.NM_DBLCLK: - case PInvoke.NM_RDBLCLK: - WmNotifyNMClick(note); - break; - default: - base.WndProc(ref m); - break; - } - - break; - - default: - base.WndProc(ref m); - break; - } - } + => throw new PlatformNotSupportedException(); - [Obsolete("StatusBarPanelCollection has been deprecated.")] + [Obsolete( + Obsoletions.StatusBarPanelCollectionMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarPanelCollectionDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class StatusBarPanelCollection : IList { - private StatusBar owner; - public StatusBarPanelCollection(StatusBar owner) - { - this.owner = owner; - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual StatusBarPanel this[int index] { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } object IList.this[int index] { - get - { - return this[index]; - } - set - { - if (value is StatusBarPanel) - { - this[index] = (StatusBarPanel)value; - } - else - { - throw new ArgumentException("SR.GetString(SR.StatusBarBadStatusBarPanel)"); - } - } + get => this[index]; + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual StatusBarPanel this[string key] { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int Count { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } object ICollection.SyncRoot { - get - { - return this; - } + get => this; } bool ICollection.IsSynchronized { - get - { - return false; - } + get => false; } bool IList.IsFixedSize { - get - { - return false; - } + get => false; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool IsReadOnly { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } public virtual StatusBarPanel Add(string text) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual int Add(StatusBarPanel value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); int IList.Add(object value) - { - if (value is StatusBarPanel) - { - return Add((StatusBarPanel)value); - } - else - { - throw new ArgumentException("SR.GetString(SR.StatusBarBadStatusBarPanel)"); - } - } + => throw new PlatformNotSupportedException(); public virtual void AddRange(StatusBarPanel[] panels) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool Contains(StatusBarPanel panel) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool IList.Contains(object panel) - { - if (panel is StatusBarPanel) - { - return Contains((StatusBarPanel)panel); - } - else - { - return false; - } - } + => false; public virtual bool ContainsKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public int IndexOf(StatusBarPanel panel) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); int IList.IndexOf(object panel) - { - if (panel is StatusBarPanel) - { - return IndexOf((StatusBarPanel)panel); - } - else - { - return -1; - } - } + => throw new PlatformNotSupportedException(); public virtual int IndexOfKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void Insert(int index, StatusBarPanel value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); void IList.Insert(int index, object value) - { - if (value is StatusBarPanel) - { - Insert(index, (StatusBarPanel)value); - } - else - { - throw new ArgumentException("SR.GetString(SR.StatusBarBadStatusBarPanel)"); - } - } - - private bool IsValidIndex(int index) - { - return ((index >= 0) && (index < Count)); - } + => throw new PlatformNotSupportedException(); public virtual void Clear() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void Remove(StatusBarPanel value) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); void IList.Remove(object value) - { - if (value is StatusBarPanel) - { - Remove((StatusBarPanel)value); - } - } + => Remove((StatusBarPanel)value); public virtual void RemoveAt(int index) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual void RemoveByKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); void ICollection.CopyTo(Array dest, int index) - { - owner.panels.CopyTo(dest, index); - } + => throw new PlatformNotSupportedException(); public IEnumerator GetEnumerator() - { - throw new PlatformNotSupportedException(); - } - } - - private class ControlToolTip - { - public class Tool - { - public Rectangle rect = Rectangle.Empty; - public string text; - internal IntPtr id = new IntPtr(-1); - } - - private Hashtable tools = new Hashtable(); - private ToolTipNativeWindow window; - private Control parent; - private int nextId; - - public ControlToolTip(Control parent) - { - window = new ToolTipNativeWindow(this); - this.parent = parent; - } - - protected CreateParams CreateParams - { - get - { - INITCOMMONCONTROLSEX icc = default; - icc.dwICC = INITCOMMONCONTROLSEX_ICC.ICC_TAB_CLASSES; - PInvoke.InitCommonControlsEx(icc); - CreateParams cp = new CreateParams(); - cp.Parent = IntPtr.Zero; - cp.ClassName = PInvoke.TOOLTIPS_CLASS; - cp.Style |= (int)PInvoke.TTS_ALWAYSTIP; - cp.ExStyle = 0; - cp.Caption = null; - return cp; - } - } - - public IntPtr Handle - { - get - { - if (window.Handle == IntPtr.Zero) - { - CreateHandle(); - } - - return window.Handle; - } - } - - private bool IsHandleCreated - { - get { return window.Handle != IntPtr.Zero; } - } - - private void AssignId(Tool tool) - { - tool.id = (IntPtr)nextId; - nextId++; - } - - public void SetTool(object key, Tool tool) - { - bool remove = false; - bool add = false; - bool update = false; - - Tool toRemove = null; - if (tools.ContainsKey(key)) - { - toRemove = (Tool)tools[key]; - } - - if (toRemove is not null) - { - remove = true; - } - - if (tool is not null) - { - add = true; - } - - if (tool is not null && toRemove is not null - && tool.id == toRemove.id) - { - update = true; - } - - if (update) - { - UpdateTool(tool); - } - else - { - if (remove) - { - RemoveTool(toRemove); - } - - if (add) - { - AddTool(tool); - } - } - - if (tool is not null) - { - tools[key] = tool; - } - else - { - tools.Remove(key); - } - } - - public Tool GetTool(object key) - { - return (Tool)tools[key]; - } - - private void AddTool(Tool tool) - { - if (tool is not null && tool.text is not null && tool.text.Length > 0) - { - StatusBar p = (StatusBar)parent; - } - } - - private void RemoveTool(Tool tool) - { - } - - private void UpdateTool(Tool tool) - { - } - - protected void CreateHandle() - { - if (IsHandleCreated) - { - return; - } - - window.CreateHandle(CreateParams); - } - - protected void DestroyHandle() - { - if (IsHandleCreated) - { - window.DestroyHandle(); - tools.Clear(); - } - } - - public void Dispose() - { - DestroyHandle(); - } - - ~ControlToolTip() - { - DestroyHandle(); - } - - protected void WndProc(ref Message msg) - { - switch (msg.MsgInternal) - { - case PInvoke.WM_SETFOCUS: - // bug 120872, the COMCTL StatusBar passes WM_SETFOCUS on to the DefWndProc, so - // it will take keyboard focus. We don't want it doing this, so we eat - // the message. - // - return; - default: - window.DefWndProc(ref msg); - break; - } - } - - private class ToolTipNativeWindow : NativeWindow - { - private ControlToolTip control; - - internal ToolTipNativeWindow(ControlToolTip control) - { - this.control = control; - } - - protected override void WndProc(ref Message m) - { - if (control is not null) - { - control.WndProc(ref m); - } - } - } + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs index 470eea44077..5a64513ecb2 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs @@ -7,27 +7,35 @@ namespace System.Windows.Forms; #pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("StatusBarDrawItemEventArgs has been deprecated. Use DrawItemEventArgs instead. https://go.microsoft.com/fwlink/?linkid=14202")] +[Obsolete( + Obsoletions.StatusBarDrawItemEventArgsMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarDrawItemEventArgsDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class StatusBarDrawItemEventArgs : DrawItemEventArgs { - public StatusBarDrawItemEventArgs(Graphics g, Font font, Rectangle r, int itemId, - DrawItemState itemState, StatusBarPanel panel) : base(g, font, r, itemId, itemState) - { - throw new PlatformNotSupportedException(); - } + public StatusBarDrawItemEventArgs(Graphics g, + Font font, + Rectangle r, + int itemId, + DrawItemState itemState, + StatusBarPanel panel) : base(g, font, r, itemId, itemState) + => throw new PlatformNotSupportedException(); - public StatusBarDrawItemEventArgs(System.Drawing.Graphics g, Font font, Rectangle r, int itemId, - DrawItemState itemState, StatusBarPanel panel, Color foreColor, Color backColor) : base(g, font, r, itemId, itemState, foreColor, backColor) - { - throw new PlatformNotSupportedException(); - } + public StatusBarDrawItemEventArgs(Graphics g, + Font font, + Rectangle r, + int itemId, + DrawItemState itemState, + StatusBarPanel panel, + Color foreColor, + Color backColor) : base(g, font, r, itemId, itemState, foreColor, backColor) + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanel Panel { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs index add3d9c4a7e..39aeae50b6a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs @@ -1,11 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; #pragma warning disable RS0016 -[Obsolete("StatusBarDrawItemEventHandler has been deprecated. Use DrawItemEventHandler instead. https://go.microsoft.com/fwlink/?linkid=14202")] -[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] +[Obsolete( + Obsoletions.StatusBarDrawItemEventHandlerMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarDrawItemEventHandlerDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public delegate void StatusBarDrawItemEventHandler(object sender, StatusBarDrawItemEventArgs sbdevent); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs index 57f2a23b2b9..e758a0fb08a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs @@ -6,366 +6,122 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 -#nullable disable -[Obsolete("StatusBarPanel has been deprecated. Use the StatusStrip control instead. http://go.microsoft.com/fwlink/?linkid=14202")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.StatusBarPanelMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarPanelDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class StatusBarPanel : Component, ISupportInitialize { - private const int DEFAULTMINWIDTH = 10; - private const int PANELTEXTINSET = 3; - private const int PANELGAP = 2; - - private string text = ""; - - private HorizontalAlignment alignment = HorizontalAlignment.Left; - private StatusBarPanelStyle style = StatusBarPanelStyle.Text; - - // these are package scope so the parent can get at them. - private StatusBar parent; - private int right; - private int minWidth = DEFAULTMINWIDTH; - private int index; - private StatusBarPanelAutoSize autoSize = StatusBarPanelAutoSize.None; - public StatusBarPanel() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public HorizontalAlignment Alignment { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanelAutoSize AutoSize { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanelBorderStyle BorderStyle { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } - } - - internal bool Created - { - get - { - return parent is not null && parent.ArePanelsRealized(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Icon Icon { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } - } - - internal int Index - { - get - { - return index; - } - set - { - index = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int MinWidth { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string Name { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public StatusBar Parent { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - internal StatusBar ParentInternal - { - set - { - parent = value; - } - } - - internal int Right - { - get - { - return right; - } - set - { - right = value; - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanelStyle Style { - get { throw new PlatformNotSupportedException(); } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public object Tag { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string Text { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string ToolTipText { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int Width { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public void BeginInit() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected override void Dispose(bool disposing) - { - if (disposing) - { - if (parent is not null) - { - int index = GetIndex(); - if (index != -1) - { - parent.Panels.RemoveAt(index); - } - } - } - - base.Dispose(disposing); - } + => base.Dispose(disposing); public void EndInit() - { - throw new PlatformNotSupportedException(); - } - - internal int GetContentsWidth(bool newPanel) - { - string text; - if (newPanel) - { - if (this.text is null) - text = ""; - else - text = this.text; - } - else - text = Text; - - Graphics g = parent.CreateGraphicsInternal(); - Size sz = Size.Ceiling(g.MeasureString(text, parent.Font)); - - g.Dispose(); - - int width = sz.Width + SystemInformation.BorderSize.Width * 2 + PANELTEXTINSET * 2 + PANELGAP; - return Math.Max(width, minWidth); - } - - private int GetIndex() - { - return index; - } - - internal void Realize() - { - if (Created) - { - string text; - string sendText; - - if (this.text is null) - { - text = ""; - } - else - { - text = this.text; - } - - HorizontalAlignment align = alignment; - // Translate the alignment for Rtl apps - if (parent.RightToLeft == RightToLeft.Yes) - { - switch (align) - { - case HorizontalAlignment.Left: - align = HorizontalAlignment.Right; - break; - case HorizontalAlignment.Right: - align = HorizontalAlignment.Left; - break; - } - } - - switch (align) - { - case HorizontalAlignment.Center: - sendText = "\t" + text; - break; - case HorizontalAlignment.Right: - sendText = "\t\t" + text; - break; - default: - sendText = text; - break; - } - - switch (style) - { - case StatusBarPanelStyle.Text: - break; - } - } - } - - private void UpdateSize() - { - if (autoSize == StatusBarPanelAutoSize.Contents) - { - ApplyContentSizing(); - } - else - { - if (Created) - { - parent.DirtyLayout(); - parent.PerformLayout(); - } - } - } - - private void ApplyContentSizing() - { - if (autoSize == StatusBarPanelAutoSize.Contents && - parent is not null) - { - int newWidth = GetContentsWidth(false); - if (newWidth != Width) - { - Width = newWidth; - if (Created) - { - parent.DirtyLayout(); - parent.PerformLayout(); - } - } - } - } + => throw new PlatformNotSupportedException(); public override string ToString() - { - return "StatusBarPanel: {" + Text + "}"; - } + => "StatusBarPanel: {" + Text + "}"; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs index b34c63385a3..996dfa93904 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs @@ -1,18 +1,17 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; #pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("StatusBarPanelAutoSize has been deprecated.")] +[Obsolete( + Obsoletions.StatusBarPanelAutoSizeMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarPanelAutoSizeDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public enum StatusBarPanelAutoSize { - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] None = 1, - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Spring = 2, - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Contents = 3, } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelBorderStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelBorderStyle.cs index 24c7a67a29f..0dfcef5c08f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelBorderStyle.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelBorderStyle.cs @@ -3,13 +3,16 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("StatusBarPanelBorderStyle is obsolete. Use the BorderStyle property of the StatusBarPanel class to change the border style of the StatusBarPanel.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.StatusBarPanelBorderStyleMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarPanelBorderStyleDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public enum StatusBarPanelBorderStyle { None = 1, - Raised = 2, - Sunken = 3, } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs index 92ec4ec6266..d88329ca423 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs @@ -4,22 +4,28 @@ using System.ComponentModel; namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("StatusBarPanelClickEventArgs has been deprecated.")] + +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.StatusBarPanelClickEventArgsMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarPanelClickEventArgsDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class StatusBarPanelClickEventArgs : MouseEventArgs { - public StatusBarPanelClickEventArgs(StatusBarPanel statusBarPanel, MouseButtons button, int clicks, int x, int y) + public StatusBarPanelClickEventArgs(StatusBarPanel statusBarPanel, + MouseButtons button, + int clicks, + int x, + int y) : base(button, clicks, x, y, 0) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanel StatusBarPanel { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEventHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEventHandler.cs index 224e2e204e4..eaa07d01ef8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEventHandler.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEventHandler.cs @@ -1,10 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; -#pragma warning disable RS0016 -[Obsolete("StatusBarPanelStyle has been deprecated. Use the StatusBarPanel.Style property instead. http://go.microsoft.com/fwlink/?linkid=14202")] -[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.StatusBarPanelClickEventHandlerMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarPanelClickEventHandlerDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public delegate void StatusBarPanelClickEventHandler(object sender, StatusBarPanelClickEventArgs e); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelStyle.cs index 18d3dd2bcfe..6538ae4b5b0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelStyle.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelStyle.cs @@ -3,11 +3,15 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("StatusBarPanelStyle has been deprecated.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.StatusBarPanelStyleMessage, + error: false, + DiagnosticId = Obsoletions.StatusBarPanelStyleDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public enum StatusBarPanelStyle { Text = 1, - OwnerDraw = 2, } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs index 6fdf8b79659..cb42a3bfd35 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs @@ -7,726 +7,391 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API #nullable disable -[Obsolete("ToolBar has been deprecated. Use ToolStrip instead.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.ToolBarMessage, + error: false, + DiagnosticId = Obsoletions.ToolBarDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class ToolBar : Control { - private readonly ToolBarButtonCollection buttonsCollection; - - /// - /// The size of a button in the ToolBar - /// - internal Size buttonSize = Size.Empty; - /// - /// This represents the width of the drop down arrow we have if the - /// DropDownArrows property is true. this value is used by the ToolBarButton - /// objects to compute their size - /// - internal const int DDARROW_WIDTH = 15; - - /// - /// The array of buttons we're working with. - /// - private ToolBarButton[] buttons; - - /// - /// The number of buttons we're working with - /// - private int buttonCount; - - /// - /// The ImageList object that contains the main images for our control. - /// - private ImageList imageList; - - /// - /// Initializes a new instance of the class. - /// - public ToolBar() - : base() - { - buttonsCollection = new ToolBarButtonCollection(this); - throw new PlatformNotSupportedException(); - } - - /// - /// Gets or sets the appearance of the toolbar - /// control and its buttons. - /// - [SRCategory(nameof(SR.CatBehavior)), DefaultValue(ToolBarAppearance.Normal), - Localizable(true), Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + public ToolBar() : base() + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public ToolBarAppearance Appearance { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Indicates whether the toolbar - /// adjusts its size automatically based on the size of the buttons and the - /// dock style. - /// - [SRCategory(nameof(SR.CatBehavior)), - DefaultValue(true), - Localizable(true), - Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override bool AutoSize { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [SRCategory(nameof(SR.CatPropertyChanged)), SRDescription(nameof(SR.ControlOnAutoSizeChangedDescr))] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler AutoSizeChanged { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Color BackColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackColorChanged { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Image BackgroundImage { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageChanged { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override ImageLayout BackgroundImageLayout { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler BackgroundImageLayoutChanged { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets - /// the border style of the toolbar control. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public BorderStyle BorderStyle { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// A collection of controls assigned to the - /// toolbar control. The property is read-only. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public ToolBarButtonCollection Buttons { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets - /// the size of the buttons on the toolbar control. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Size ButtonSize { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating - /// whether the toolbar displays a divider. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Divider { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Sets the way in which this ToolBar is docked to its parent. We need to - /// override this to ensure autoSizing works correctly - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override DockStyle Dock { - get { throw new PlatformNotSupportedException(); } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating whether drop-down buttons on a - /// toolbar display down arrows. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool DropDownArrows { - get - { - throw new PlatformNotSupportedException(); - } - - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override Color ForeColor { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler ForeColorChanged { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets the collection of images available to the toolbar button - /// controls. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public ImageList ImageList { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Gets the size of the images in the image list assigned to the - /// toolbar. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Size ImageSize { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public ImeMode ImeMode { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler ImeModeChanged { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override RightToLeft RightToLeft { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler RightToLeftChanged { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets a value indicating whether the toolbar displays a - /// tool tip for each button. - /// - [SRCategory(nameof(SR.CatBehavior)), - DefaultValue(false), - Localizable(true)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool ShowToolTips { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [DefaultValue(false)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public bool TabStop { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), - Bindable(false), - DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public override string Text { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] new public event EventHandler TextChanged { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Gets or sets the alignment of text in relation to each - /// image displayed on - /// the toolbar button controls. - /// - [SRCategory(nameof(SR.CatAppearance)), - DefaultValue(ToolBarTextAlign.Underneath), - Localizable(true)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public ToolBarTextAlign TextAlign { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Gets - /// or sets a value - /// indicating whether the toolbar buttons wrap to the next line if the - /// toolbar becomes too small to display all the buttons - /// on the same line. - /// - [SRCategory(nameof(SR.CatBehavior)), - DefaultValue(true), - Localizable(true)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Wrappable { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Occurs when a on the is clicked. - /// - [SRCategory(nameof(SR.CatBehavior))] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event ToolBarButtonClickEventHandler ButtonClick { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Occurs when a drop-down style or its down arrow is clicked. - /// - [SRCategory(nameof(SR.CatBehavior))] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public event ToolBarButtonClickEventHandler ButtonDropDown { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// ToolBar Onpaint. - /// - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public new event PaintEventHandler Paint { add => throw new PlatformNotSupportedException(); remove => throw new PlatformNotSupportedException(); } - /// - /// Returns a string representation for this control. - /// public override string ToString() - { - buttonCount++; - buttons = new ToolBarButton[buttonCount]; - imageList = new ImageList(); - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Encapsulates a collection of controls for use by the - /// class. - /// - [Obsolete("ToolBarButtonCollection has been deprecated.")] + [Obsolete( + Obsoletions.ToolBarButtonCollectionMessage, + error: false, + DiagnosticId = Obsoletions.ToolBarButtonCollectionDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class ToolBarButtonCollection : IList { - private readonly ToolBar owner; - - /// - /// Initializes a new instance of the class and assigns it to the specified toolbar. - /// public ToolBarButtonCollection(ToolBar owner) - { - this.owner = owner; - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Gets or sets the toolbar button at the specified indexed location in the - /// toolbar button collection. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual ToolBarButton this[int index] { - get - { - throw new PlatformNotSupportedException(); - } - set - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] object IList.this[int index] { - get - { - return this[index]; - } - set - { - if (value is ToolBarButton) - { - this[index] = (ToolBarButton)value; - } - else - { - throw new ArgumentException(); - } - } + get => this[index]; + set => throw new PlatformNotSupportedException(); } - /// - /// Retrieves the child control with the specified key. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual ToolBarButton this[string key] { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - /// - /// Gets the number of buttons in the toolbar button collection. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int Count { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] object ICollection.SyncRoot { - get - { - return this; - } + get => this; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] bool ICollection.IsSynchronized { - get - { - return false; - } + get => false; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] bool IList.IsFixedSize { - get - { - return false; - } + get => false; } - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool IsReadOnly { - get - { - throw new PlatformNotSupportedException(); - } + get => throw new PlatformNotSupportedException(); } - /// - /// Adds a new toolbar button to - /// the end of the toolbar button collection. - /// public int Add(ToolBarButton button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public int Add(string text) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); int IList.Add(object button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void AddRange(ToolBarButton[] buttons) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Removes - /// all buttons from the toolbar button collection. - /// public void Clear() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool Contains(ToolBarButton button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool IList.Contains(object button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Returns true if the collection contains an item with the specified key, false otherwise. - /// public virtual bool ContainsKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); void ICollection.CopyTo(Array dest, int index) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public int IndexOf(ToolBarButton button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); int IList.IndexOf(object button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// The zero-based index of the first occurrence of value within the entire CollectionBase, if found; otherwise, -1. - /// public virtual int IndexOfKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void Insert(int index, ToolBarButton button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); void IList.Insert(int index, object button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Removes - /// a given button from the toolbar button collection. - /// public void RemoveAt(int index) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Removes the child control with the specified key. - /// public virtual void RemoveByKey(string key) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public void Remove(ToolBarButton button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); void IList.Remove(object button) - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); - /// - /// Returns an enumerator that can be used to iterate - /// through the toolbar button collection. - /// public IEnumerator GetEnumerator() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs index 73477853565..4355d29fad4 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs @@ -1,17 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; -[Obsolete("ToolBarAppearance has been deprecated.")] +[Obsolete( + Obsoletions.ToolBarAppearanceMessage, + error: false, + DiagnosticId = Obsoletions.ToolBarAppearanceDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] #pragma warning disable RS0016 // Add public types and members to the declared API public enum ToolBarAppearance { - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Normal = 0, - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Flat = 1, } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs index 2497ead49ca..e48bbc87a0f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs @@ -6,425 +6,131 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API -#nullable disable -[Obsolete("ToolBarButton has been deprecated. Use ToolStripButton instead.")] +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. +[Obsolete( + Obsoletions.ToolBarButtonMessage, + error: false, + DiagnosticId = Obsoletions.ToolBarButtonDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class ToolBarButton : Component { - private string text; - private string name; - private string tooltipText; - private bool enabled = true; - private bool visible = true; - private bool pushed; - private bool partialPush; - private ToolBarButtonImageIndexer imageIndexer; - private ToolBarButtonStyle style = ToolBarButtonStyle.PushButton; - private object userData; - - // These variables below are used by the ToolBar control to help - // it manage some information about us. - - /// - /// If this button has a string, what it's index is in the ToolBar's - /// internal list of strings. Needs to be package protected. - /// - internal IntPtr stringIndex = (IntPtr)(-1); - - /// - /// Our parent ToolBar control. - /// - internal ToolBar parent; - - /// - /// For DropDown buttons, we can optionally show a - /// context menu when the button is dropped down. - /// - internal Menu dropDownMenu; - - /// - /// Initializes a new instance of the class. - /// public ToolBarButton() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public ToolBarButton(string text) : base() - { - throw new PlatformNotSupportedException(); - } - - // We need a special way to defer to the ToolBar's image - // list for indexing purposes. - [Obsolete("ToolBarButtonImageIndexer has been deprecated.")] - internal class ToolBarButtonImageIndexer : ImageList.Indexer - { - private readonly ToolBarButton owner; - - public ToolBarButtonImageIndexer(ToolBarButton button) - { - owner = button; - throw new PlatformNotSupportedException(); - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public override ImageList ImageList - { - get - { - if ((owner is not null) && (owner.parent is not null)) - { - return owner.parent.ImageList; - } - - return null; - } - set { Debug.Assert(false, "We should never set the image list"); } - } - } + => throw new PlatformNotSupportedException(); - /// - /// - /// Indicates the menu to be displayed in - /// the drop-down toolbar button. - /// - [DefaultValue(null), TypeConverter(typeof(ReferenceConverter))] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Menu DropDownMenu { - get - { - return dropDownMenu; - } - - set - { - if (value is not null && !(value is ContextMenu)) - { - throw new ArgumentException(); - } - - dropDownMenu = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Indicates whether the button is enabled or not. - /// - [DefaultValue(true), Localizable(true)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Enabled { - get - { - return enabled; - } - - set - { - if (enabled != value) - { - enabled = value; - } - } - } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - internal ToolBarButtonImageIndexer ImageIndexer - { - get - { - if (imageIndexer is null) - { - imageIndexer = new ToolBarButtonImageIndexer(this); - } - - return imageIndexer; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Indicates the index - /// value of the image assigned to the button. - /// - [TypeConverter(typeof(ImageIndexConverter)), - DefaultValue(-1), - RefreshProperties(RefreshProperties.Repaint), Localizable(true)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public int ImageIndex { - get - { - return ImageIndexer.Index; - } - set - { - if (ImageIndexer.Index != value) - { - if (value < -1) - { - throw new ArgumentOutOfRangeException(); - } - - ImageIndexer.Index = value; - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Indicates the index - /// value of the image assigned to the button. - /// - [TypeConverter(typeof(ImageKeyConverter)), - DefaultValue(""), Localizable(true), - RefreshProperties(RefreshProperties.Repaint)] - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string ImageKey { - get - { - return ImageIndexer.Key; - } - set - { - if (ImageIndexer.Key != value) - { - ImageIndexer.Key = value; - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Name of this control. The designer will set this to the same - /// as the programatic Id "(name)" of the control - however this - /// property has no bearing on the runtime aspects of this control. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string Name { - get - { - return WindowsFormsUtils.GetComponentName(this, name); - } - set - { - if (value is null || value.Length == 0) - { - name = null; - } - else - { - name = value; - } - - if (Site is not null) - { - Site.Name = name; - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Indicates the toolbar control that the toolbar button is assigned to. This property is - /// read-only. - /// - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public ToolBar Parent { - get - { - return parent; - } + get => throw new PlatformNotSupportedException(); } - /// - /// - /// Indicates whether a toggle-style toolbar button - /// is partially pushed. - /// - [DefaultValue(false), Browsable(false), - EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool PartialPush { - get - { - if (parent is null || !parent.IsHandleCreated) - { - return partialPush; - } - else - { - return partialPush; - } - } - set - { - if (partialPush != value) - { - partialPush = value; - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Indicates whether a toggle-style toolbar button is currently in the pushed state. - /// - [DefaultValue(false), Browsable(false), - EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Pushed { - get - { - if (parent is null || !parent.IsHandleCreated) - { - return pushed; - } - else - { - return false; - } - } - set - { - if (value != Pushed) - { // Getting property Pushed updates pushed member variable - pushed = value; - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Indicates the bounding rectangle for a toolbar button. This property is - /// read-only. - /// Browsable(false), - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public Rectangle Rectangle { - get - { - if (parent is not null) - { - RECT rc = default(RECT); - return Rectangle.FromLTRB(rc.left, rc.top, rc.right, rc.bottom); - } - - return Rectangle.Empty; - } + get => throw new PlatformNotSupportedException(); } - /// - /// Indicates the style of the - /// toolbar button. - /// - [DefaultValue(ToolBarButtonStyle.PushButton), - RefreshProperties(RefreshProperties.Repaint), - Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public ToolBarButtonStyle Style { - get - { - return style; - } - set - { - if (style == value) - { - return; - } - - style = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - [SRCategory(nameof(SR.CatData)), - Localizable(false), - Bindable(true), - SRDescription(nameof(SR.ControlTagDescr)), - DefaultValue(null), - TypeConverter(typeof(StringConverter)), - Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public object Tag { - get - { - return userData; - } - set - { - userData = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// Indicates the text that is displayed on the toolbar button. - /// - [Localizable(true), DefaultValue(""), - Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string Text { - get - { - return text ?? ""; - } - set - { - if (string.IsNullOrEmpty(value)) - { - value = null; - } - - if ((value is null && text is not null) || - (value is not null && (text is null || !text.Equals(value)))) - { - text = value; - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// - /// Indicates - /// the text that appears as a tool tip for a control. - /// - [Localizable(true), DefaultValue(""), - Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public string ToolTipText { - get - { - return tooltipText ?? ""; - } - set - { - tooltipText = value; - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - /// - /// - /// Indicates whether the toolbar button - /// is visible. - /// - [DefaultValue(true), Localizable(true), - Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] public bool Visible { - get - { - return visible; - } - set - { - if (visible != value) - { - visible = value; - } - } + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } public override string ToString() - { - throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs index 6c85434f123..be95598dcfc 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs @@ -5,19 +5,22 @@ namespace System.Windows.Forms; -[Obsolete("ToolBarButtonStyle has been deprecated.")] #pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete( + Obsoletions.ToolBarButtonClickEventArgsMessage, + error: false, + DiagnosticId = Obsoletions.ToolBarButtonClickEventArgsDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public class ToolBarButtonClickEventArgs : EventArgs { - /// - /// Initializes a new instance of the - /// class. - /// public ToolBarButtonClickEventArgs(ToolBarButton button) + => throw new PlatformNotSupportedException(); + + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public ToolBarButton Button { - throw new PlatformNotSupportedException(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] - public ToolBarButton Button { get; set; } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs index b8bb5c932a3..9842a1b87b1 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs @@ -1,11 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; #pragma warning disable RS0016 // Add public types and members to the declared API -[Obsolete("ToolBarButtonStyle has been deprecated.")] -[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] +[Obsolete( + Obsoletions.ToolBarButtonClickEventHandlerMessage, + error: false, + DiagnosticId = Obsoletions.ToolBarButtonClickEventHandlerDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public delegate void ToolBarButtonClickEventHandler(object sender, ToolBarButtonClickEventArgs e); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs index 6dba397fe42..18a0f5847aa 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs @@ -1,23 +1,18 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; - namespace System.Windows.Forms; -[Obsolete("ToolBarButtonStyle has been deprecated.")] #pragma warning disable RS0016 // Add public types and members to the declared API +[Obsolete( + Obsoletions.ToolBarButtonStyleMessage, + error: false, + DiagnosticId = Obsoletions.ToolBarButtonStyleDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] public enum ToolBarButtonStyle { - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] PushButton = 1, - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] ToggleButton = 2, - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Separator = 3, - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] DropDownButton = 4, } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs index ccd8beda3fe..74539820c96 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs @@ -5,13 +5,15 @@ namespace System.Windows.Forms; -[Obsolete("ToolBarTextAlign has been deprecated.")] +[EditorBrowsable(EditorBrowsableState.Never)] +[Obsolete( + Obsoletions.ToolBarTextAlignMessage, + error: false, + DiagnosticId = Obsoletions.ToolBarTextAlignDiagnosticId, + UrlFormat = Obsoletions.SharedUrlFormat)] #pragma warning disable RS0016 // Add public types and members to the declared API public enum ToolBarTextAlign { - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Underneath = 0, - - [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] Right = 1, } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs b/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs index 0ee5fa0fe6b..0707f7175e9 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs @@ -47,5 +47,6 @@ public enum MainFormControlsTabOrder ChartControlButton, ToolStripSeparatorPreferredSize, CustomComCtl32Button, - ScrollableControlsButton + ScrollableControlsButton, + ObsoleteControls, } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs index c0449569f47..14f0be4ece5 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/MainForm.cs @@ -242,7 +242,7 @@ private void UpdateLayout() { MinimumSize = default; Debug.WriteLine($"MessageBoxFont: {SystemFonts.MessageBoxFont}", nameof(MainForm)); - Debug.WriteLine($"Default font: {Control.DefaultFont}", nameof(MainForm)); + Debug.WriteLine($"Default font: {DefaultFont}", nameof(MainForm)); List private void InitializeComponent() { -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable WFDEV004, WFDEV007, WFDEV009, WFDEV041, WFDEV045, WFDEV051, WFDEV054 // Type or member is obsolete this.components = new System.ComponentModel.Container(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); @@ -124,5 +124,5 @@ private void InitializeComponent() private System.Windows.Forms.StatusBar statusBar1; private System.Windows.Forms.StatusBarPanel panel1; private System.Windows.Forms.StatusBarPanel panel2; -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore WFDEV004, WFDEV007, WFDEV009, WFDEV041, WFDEV045, WFDEV051, WFDEV054 // Type or member is obsolete } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs index dd949e00b3f..53dc8914303 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs @@ -4,14 +4,17 @@ using System.ComponentModel; using System.Data; using System.Drawing; -#pragma warning disable CS0618 +#pragma warning disable WFDEV007, WFDEV009, WFDEV010, WFDEV014, WFDEV017, WFDEV032, WFDEV036, WFDEV039, WFDEV040, WFDEV044, WFDEV050, WFDEV053 // Type or member is obsolete using static System.Windows.Forms.DataGrid; namespace WinformsControlsTest; +/// +/// This is added to test compile time compatibility only. +/// public partial class ObsoleteControls : Form { - private bool TablesAlreadyAdded; + private bool _tablesAlreadyAdded; public ObsoleteControls() { InitializeComponent(); @@ -26,19 +29,19 @@ private void CreateMainMenu() mainMenu.MenuItems.Add(fileMenuItem); } - void menuItem1_Click(object sender, System.EventArgs e) + private void menuItem1_Click(object sender, System.EventArgs e) { MessageBox.Show("New menu item clicked", "DataGrid"); } - void menuItem2_Click(object sender, System.EventArgs e) + private void menuItem2_Click(object sender, System.EventArgs e) { MessageBox.Show("New menu item clicked", "MainMenu"); } private void button1_Click(object sender, System.EventArgs e) { - if (TablesAlreadyAdded) + if (_tablesAlreadyAdded) return; AddCustomDataTableStyle(); } @@ -61,56 +64,66 @@ private void Grid_MouseUp(object sender, MouseEventArgs e) private void AddCustomDataTableStyle() { - DataGridTableStyle ts1 = new DataGridTableStyle(); - ts1.MappingName = "Customers"; - // Set other properties. - ts1.AlternatingBackColor = Color.LightGray; + DataGridTableStyle ts1 = new DataGridTableStyle + { + MappingName = "Customers", + // Set other properties. + AlternatingBackColor = Color.LightGray + }; /* Add a GridColumnStyle and set its MappingName to the name of a DataColumn in the DataTable. Set the HeaderText and Width properties. */ - DataGridColumnStyle boolCol = new DataGridBoolColumn(); - boolCol.MappingName = "Current"; - boolCol.HeaderText = "IsCurrent Customer"; - boolCol.Width = 150; + DataGridColumnStyle boolCol = new DataGridBoolColumn + { + MappingName = "Current", + HeaderText = "IsCurrent Customer", + Width = 150 + }; ts1.GridColumnStyles.Add(boolCol); // Add a second column style. - DataGridColumnStyle TextCol = new DataGridTextBoxColumn(); - TextCol.MappingName = "custName"; - TextCol.HeaderText = "Customer Name"; - TextCol.Width = 250; + DataGridColumnStyle TextCol = new DataGridTextBoxColumn + { + MappingName = "custName", + HeaderText = "Customer Name", + Width = 250 + }; ts1.GridColumnStyles.Add(TextCol); // Create the second table style with columns. - DataGridTableStyle ts2 = new DataGridTableStyle(); - ts2.MappingName = "Orders"; + DataGridTableStyle ts2 = new DataGridTableStyle + { + MappingName = "Orders", - // Set other properties. - ts2.AlternatingBackColor = Color.LightBlue; + // Set other properties. + AlternatingBackColor = Color.LightBlue + }; // Create new ColumnStyle objects - DataGridColumnStyle cOrderDate = - new DataGridTextBoxColumn(); - cOrderDate.MappingName = "OrderDate"; - cOrderDate.HeaderText = "Order Date"; - cOrderDate.Width = 100; + DataGridColumnStyle cOrderDate = new DataGridTextBoxColumn + { + MappingName = "OrderDate", + HeaderText = "Order Date", + Width = 100 + }; ts2.GridColumnStyles.Add(cOrderDate); /* Use a PropertyDescriptor to create a formatted column. First get the PropertyDescriptorCollection for the data source and data member. */ - PropertyDescriptorCollection pcol = this.BindingContext + PropertyDescriptorCollection pcol = BindingContext [myDataSet, "Customers.custToOrders"].GetItemProperties(); /* Create a formatted column using a PropertyDescriptor. The formatting character "c" specifies a currency format. */ - DataGridColumnStyle csOrderAmount = - new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true); - csOrderAmount.MappingName = "OrderAmount"; - csOrderAmount.HeaderText = "Total"; - csOrderAmount.Width = 100; + DataGridColumnStyle csOrderAmount = new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true) + { + MappingName = "OrderAmount", + HeaderText = "Total", + Width = 100 + }; ts2.GridColumnStyles.Add(csOrderAmount); /* Add the DataGridTableStyle instances to @@ -119,7 +132,7 @@ private void AddCustomDataTableStyle() dataGrid1.TableStyles.Add(ts2); // Sets the TablesAlreadyAdded to true so this doesn't happen again. - TablesAlreadyAdded = true; + _tablesAlreadyAdded = true; } private void SetUp() @@ -208,4 +221,3 @@ private void MakeDataSet() } } } -#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs index bc7e2bb7fee..dabd13118d1 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs @@ -2690,14 +2690,14 @@ public void AccessibleObject_GetPropertyValue_ReturnsNull_IfExpected(int propert public static IEnumerable AccessibleObject_RuntimeId_IsOverriden_TestData() { -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable WFDEV017, WFDEV018, WFDEV019, WFDEV020, WFDEV021, WFDEV023, WFDEV024, WFDEV025, WFDEV026, WFDEV027, WFDEV028, WFDEV029, WFDEV030, WFDEV031 // Type or member is obsolete var typesToIgnore = new[] { typeof(ComboBox.ChildAccessibleObject), typeof(DataGridState.DataGridStateParentRowAccessibleObject), typeof(DataGridRow.DataGridCellAccessibleObject), typeof(DataGridRow.DataGridRowAccessibleObject), typeof(DataGridRelationshipRow.DataGridRelationshipRowAccessibleObject), typeof(DataGridRelationshipRow.DataGridRelationshipAccessibleObject), typeof(DataGridParentRows.DataGridParentRowsAccessibleObject), typeof(DataGridColumnStyle.DataGridColumnHeaderAccessibleObject), }; -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore WFDEV017, WFDEV018, WFDEV019, WFDEV020, WFDEV021, WFDEV023, WFDEV024, WFDEV025, WFDEV026, WFDEV027, WFDEV028, WFDEV029, WFDEV030, WFDEV031 // Type or member is obsolete Assembly assembly = typeof(AccessibleObject).Assembly; foreach (Type type in assembly.GetTypes()) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs index 95ec2bfef31..3c4fff0dd87 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs @@ -1219,12 +1219,12 @@ public void ControlAccessibleObject_Supports_LegacyIAccessiblePattern_IfOwnerSup public static IEnumerable ControlAccessibleObject_TestData() { -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable WFDEV009, WFDEV035, WFDEV041, WFDEV051 // Type or member is obsolete var typesToIgnore = new[] { typeof(DataGrid), typeof(StatusBar), typeof(ToolBar), typeof(DataGridTextBox) }; - #pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore WFDEV009, WFDEV035, WFDEV041, WFDEV051 // Type or member is obsolete return ReflectionHelper.GetPublicNotAbstractClasses() .Where(t => !typesToIgnore.Contains(t)) @@ -1341,12 +1341,12 @@ public static IEnumerable ControlAccessibleObject_DefaultName_TestData { typeof(MaskedTextBox), string.Empty} }; -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable WFDEV009, WFDEV035, WFDEV041, WFDEV051 // Type or member is obsolete var typesToIgnore = new[] { typeof(DataGrid), typeof(StatusBar), typeof(ToolBar), typeof(DataGridTextBox) }; -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore WFDEV009, WFDEV035, WFDEV041, WFDEV051 // Type or member is obsolete foreach (Type type in ReflectionHelper.GetPublicNotAbstractClasses()) { From 97523270939b3dc84c283bc0c0d29d21f66166df Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Tue, 2 Apr 2024 10:22:30 +0800 Subject: [PATCH 07/11] Fix code errors and remove unuseless codes --- .../Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs | 4 ++-- .../MainFormControlsTabOrder.cs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs index 60fa71c996c..1080c1ad77b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs @@ -663,10 +663,10 @@ protected override void OnHandleCreated(EventArgs e) protected override void OnHandleDestroyed(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnEnter(EventArgs e) + protected internal override void OnEnter(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnLeave(EventArgs e) + protected internal override void OnLeave(EventArgs e) => throw new PlatformNotSupportedException(); protected override void OnKeyDown(KeyEventArgs e) diff --git a/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs b/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs index 0707f7175e9..0ee5fa0fe6b 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/MainFormControlsTabOrder.cs @@ -47,6 +47,5 @@ public enum MainFormControlsTabOrder ChartControlButton, ToolStripSeparatorPreferredSize, CustomComCtl32Button, - ScrollableControlsButton, - ObsoleteControls, + ScrollableControlsButton } From 2758b16c55448baaa77adcfb1396b1c4d141e240 Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Tue, 2 Apr 2024 17:12:44 +0800 Subject: [PATCH 08/11] Make all the method throw PlatformNotSupportedException --- .../Controls/Obsolete/DataGrid/DataGrid.cs | 4 +- .../Obsolete/DataGrid/DataGridCaption.cs | 6 +-- .../Obsolete/DataGrid/DataGridCell.cs | 2 +- .../Obsolete/DataGrid/DataGridColumn.cs | 20 ++------ .../DataGrid/DataGridRelationshipRow.cs | 4 +- .../Controls/Obsolete/DataGrid/DataGridRow.cs | 21 ++------ .../Obsolete/DataGrid/DataGridTable.cs | 16 +----- .../DataGrid/DataGridTableCollection.cs | 32 ++++++------ .../Obsolete/DataGrid/DataGridTextBox.cs | 18 ++----- .../DataGrid/GridColumnStylesCollection.cs | 20 ++++---- .../Controls/Obsolete/StatusBar/StatusBar.cs | 49 +++++++------------ .../Obsolete/StatusBar/StatusBarPanel.cs | 4 +- .../Controls/Obsolete/ToolBar/ToolBar.cs | 8 +-- 13 files changed, 70 insertions(+), 134 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs index 1080c1ad77b..9bda75b8824 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs @@ -81,7 +81,7 @@ public BorderStyle BorderStyle protected override Size DefaultSize { - get => new Size(130, 80); + get => throw new PlatformNotSupportedException(); } [Browsable(false)] @@ -741,7 +741,7 @@ protected override AccessibleObject CreateAccessibilityInstance() => throw new PlatformNotSupportedException(); protected override void Dispose(bool disposing) - => base.Dispose(disposing); + => throw new PlatformNotSupportedException(); public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs index d323ffaad8f..81d8a9d80c1 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs @@ -27,11 +27,7 @@ protected virtual Delegate GetEventHandler(object key) => throw new PlatformNotSupportedException(); protected virtual void RaiseEvent(object key, EventArgs e) - { - Delegate handler = GetEventHandler(key); - if (handler is not null) - ((EventHandler)handler)(this, e); - } + => throw new PlatformNotSupportedException(); protected virtual void RemoveEventHandler(object key, Delegate handler) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs index c2084eeeafc..34b726acc9e 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs @@ -50,5 +50,5 @@ public DataGridCell(int r, int c) => throw new PlatformNotSupportedException(); public static bool operator !=(DataGridCell left, DataGridCell right) - => !(left == right); + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs index 5a05fa81284..69518d22218 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs @@ -72,7 +72,7 @@ protected virtual AccessibleObject CreateHeaderAccessibleObject() => throw new PlatformNotSupportedException(); protected virtual void SetDataGrid(DataGrid value) - => SetDataGridInColumn(value); + => throw new PlatformNotSupportedException(); protected virtual void SetDataGridInColumn(DataGrid value) { @@ -196,16 +196,7 @@ protected void EndUpdate() protected internal abstract int GetPreferredHeight(Graphics g, object value); protected internal virtual object GetColumnValueAtRow(CurrencyManager source, int rowNum) - { - CheckValidDataSource(source); - if (PropertyDescriptor is null) - { - throw new InvalidOperationException("SR.GetString(SR.DataGridColumnNoPropertyDescriptor)"); - } - - object value = PropertyDescriptor.GetValue(source[rowNum]); - return value; - } + => throw new PlatformNotSupportedException(); protected virtual void Invalidate() { @@ -269,10 +260,7 @@ protected internal virtual void ConcedeFocus() => Paint(g, bounds, source, rowNum, alignToRight); protected internal virtual void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) - { - CheckValidDataSource(source); - PropertyDescriptor.SetValue(source[rowNum], value); - } + => throw new PlatformNotSupportedException(); void IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control editingControl) { @@ -326,7 +314,7 @@ public override string Name [EditorBrowsable(EditorBrowsableState.Never)] protected DataGridColumnStyle Owner { - get; + get => throw new PlatformNotSupportedException(); } [Browsable(false)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs index 7a5dbd5c5dc..8ed852b368a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs @@ -146,7 +146,7 @@ public override string Name protected DataGridRelationshipRow Owner { - get; + get => throw new PlatformNotSupportedException(); } [Browsable(false)] @@ -158,7 +158,7 @@ public override AccessibleObject Parent protected DataGrid DataGrid { - get; + get => throw new PlatformNotSupportedException(); } [Browsable(false)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs index 24fd67a8591..f97f2481ddb 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs @@ -67,20 +67,7 @@ public virtual bool Selected [ResourceExposure(ResourceScope.Machine)] [ResourceConsumption(ResourceScope.Machine)] protected Bitmap GetBitmap(string bitmapName) - { - Bitmap b = null; - try - { - b = new Bitmap(typeof(DataGridCaption), bitmapName); - b.MakeTransparent(); - } - catch - { - throw; - } - - return b; - } + => throw new PlatformNotSupportedException(); public virtual Rectangle GetCellBounds(int col) => throw new PlatformNotSupportedException(); @@ -187,7 +174,7 @@ protected virtual void PaintBottomBorder(Graphics g, Rectangle bounds, int dataW DataGridColumnStyle column, Brush backBr, Brush foreBrush) - => PaintCellContents(g, cellBounds, column, backBr, foreBrush, false); + => throw new PlatformNotSupportedException(); protected virtual void PaintCellContents(Graphics g, Rectangle cellBounds, @@ -195,7 +182,7 @@ protected virtual void PaintBottomBorder(Graphics g, Rectangle bounds, int dataW Brush backBr, Brush foreBrush, bool alignToRight) - => g.FillRectangle(backBr, cellBounds); + => throw new PlatformNotSupportedException(); protected Rectangle PaintIcon(Graphics g, Rectangle visualBounds, @@ -245,7 +232,7 @@ protected virtual void AddChildAccessibleObjects(IList children) => throw new PlatformNotSupportedException(); protected virtual AccessibleObject CreateCellAccessibleObject(int column) - => new AccessibleObject(); + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs index 5a56bf7fb04..38fcd1de369 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs @@ -239,7 +239,7 @@ public Color LinkHoverColor } protected virtual bool ShouldSerializeLinkHoverColor() - => false; + => throw new PlatformNotSupportedException(); public void ResetLinkHoverColor() => throw new PlatformNotSupportedException(); @@ -496,17 +496,5 @@ protected virtual void OnSelectionBackColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); protected override void Dispose(bool disposing) - { - if (disposing) - { - GridColumnStylesCollection cols = GridColumnStyles; - if (cols is not null) - { - for (int i = 0; i < cols.Count; i++) - cols[i].Dispose(); - } - } - - base.Dispose(disposing); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs index 1f4881afbe6..2135e5ac1e8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs @@ -17,40 +17,40 @@ namespace System.Windows.Forms; public class GridTableStylesCollection : BaseCollection, IList { int IList.Add(object value) - => Add((DataGridTableStyle)value); + => throw new PlatformNotSupportedException(); void IList.Clear() - => Clear(); + => throw new PlatformNotSupportedException(); bool IList.Contains(object value) - => default; + => throw new PlatformNotSupportedException(); int IList.IndexOf(object value) - => default; + => throw new PlatformNotSupportedException(); void IList.Insert(int index, object value) - => throw new NotSupportedException(); + => throw new PlatformNotSupportedException(); void IList.Remove(object value) - => Remove((DataGridTableStyle)value); + => throw new PlatformNotSupportedException(); void IList.RemoveAt(int index) - => RemoveAt(index); + => throw new PlatformNotSupportedException(); bool IList.IsFixedSize { - get => false; + get => throw new PlatformNotSupportedException(); } bool IList.IsReadOnly { - get => false; + get => throw new PlatformNotSupportedException(); } object IList.this[int index] { - get => default; - set => throw new NotSupportedException(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } void ICollection.CopyTo(Array array, int index) @@ -59,24 +59,24 @@ void ICollection.CopyTo(Array array, int index) int ICollection.Count { - get => default; + get => throw new PlatformNotSupportedException(); } bool ICollection.IsSynchronized { - get => false; + get => throw new PlatformNotSupportedException(); } object ICollection.SyncRoot { - get => this; + get => throw new PlatformNotSupportedException(); } - IEnumerator IEnumerable.GetEnumerator() => default; + IEnumerator IEnumerable.GetEnumerator() => throw new PlatformNotSupportedException(); protected override ArrayList List { - get => default; + get => throw new PlatformNotSupportedException(); } [Browsable(false)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs index 4d1f4a46786..e0ab2f8e29a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs @@ -21,29 +21,17 @@ public void SetDataGrid(DataGrid parentGrid) => throw new PlatformNotSupportedException(); protected override void WndProc(ref Message m) - => base.WndProc(ref m); + => throw new PlatformNotSupportedException(); protected override void OnMouseWheel(MouseEventArgs e) { } protected override void OnKeyPress(KeyPressEventArgs e) - { - base.OnKeyPress(e); - - if (e.KeyChar == ' ' && (ModifierKeys & Keys.Shift) == Keys.Shift) - return; - - if (ReadOnly) - return; - - if ((ModifierKeys & Keys.Control) == Keys.Control && ((ModifierKeys & Keys.Alt) == 0)) - return; - IsInEditOrNavigateMode = false; - } + => throw new PlatformNotSupportedException(); protected internal override bool ProcessKeyMessage(ref Message m) - => base.ProcessKeyMessage(ref m); + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs index d7cb77a4bd1..badb072824f 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs @@ -17,10 +17,10 @@ namespace System.Windows.Forms; public class GridColumnStylesCollection : BaseCollection, IList { int IList.Add(object value) - => Add((DataGridColumnStyle)value); + => throw new PlatformNotSupportedException(); void IList.Clear() - => Clear(); + => throw new PlatformNotSupportedException(); bool IList.Contains(object value) => throw new PlatformNotSupportedException(); @@ -32,25 +32,25 @@ void IList.Insert(int index, object value) => throw new PlatformNotSupportedException(); void IList.Remove(object value) - => Remove((DataGridColumnStyle)value); + => throw new PlatformNotSupportedException(); void IList.RemoveAt(int index) - => RemoveAt(index); + => throw new PlatformNotSupportedException(); bool IList.IsFixedSize { - get => false; + get => throw new PlatformNotSupportedException(); } bool IList.IsReadOnly { - get => false; + get => throw new PlatformNotSupportedException(); } object IList.this[int index] { - get => throw new NotSupportedException(); - set => throw new NotSupportedException(); + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } void ICollection.CopyTo(Array array, int index) @@ -63,12 +63,12 @@ int ICollection.Count bool ICollection.IsSynchronized { - get => false; + get => throw new PlatformNotSupportedException(); } object ICollection.SyncRoot { - get => this; + get => throw new PlatformNotSupportedException(); } IEnumerator IEnumerable.GetEnumerator() diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs index 3a89b4f4de9..e3fe1a299d6 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs @@ -4,7 +4,6 @@ using System.Collections; using System.ComponentModel; using System.Drawing; -using System.Globalization; namespace System.Windows.Forms; @@ -71,23 +70,23 @@ public override ImageLayout BackgroundImageLayout protected override CreateParams CreateParams { - get => base.CreateParams; + get => throw new PlatformNotSupportedException(); } protected override ImeMode DefaultImeMode { - get => ImeMode.Disable; + get => throw new PlatformNotSupportedException(); } protected override Size DefaultSize { - get => new Size(100, 22); + get => throw new PlatformNotSupportedException(); } protected override bool DoubleBuffered { - get => base.DoubleBuffered; - set => base.DoubleBuffered = value; + get => throw new PlatformNotSupportedException(); + set => throw new PlatformNotSupportedException(); } [Browsable(false)] @@ -202,44 +201,34 @@ public bool SizingGrip } protected override void CreateHandle() - => base.CreateHandle(); + => throw new PlatformNotSupportedException(); protected override void Dispose(bool disposing) - => base.Dispose(disposing); + => throw new PlatformNotSupportedException(); protected override void OnHandleCreated(EventArgs e) - => base.OnHandleCreated(e); + => throw new PlatformNotSupportedException(); protected override void OnHandleDestroyed(EventArgs e) - => base.OnHandleDestroyed(e); + => throw new PlatformNotSupportedException(); protected override void OnMouseDown(MouseEventArgs e) - => base.OnMouseDown(e); + => throw new PlatformNotSupportedException(); protected virtual void OnPanelClick(StatusBarPanelClickEventArgs e) => throw new PlatformNotSupportedException(); protected override void OnLayout(LayoutEventArgs levent) - => base.OnLayout(levent); + => throw new PlatformNotSupportedException(); protected virtual void OnDrawItem(StatusBarDrawItemEventArgs sbdievent) => throw new PlatformNotSupportedException(); protected override void OnResize(EventArgs e) - => base.OnResize(e); + => throw new PlatformNotSupportedException(); public override string ToString() - { - string s = base.ToString(); - if (Panels is not null) - { - s += ", Panels.Count: " + Panels.Count.ToString(CultureInfo.CurrentCulture); - if (Panels.Count > 0) - s += ", Panels[0]: " + Panels[0].ToString(); - } - - return s; - } + => throw new PlatformNotSupportedException(); protected override void WndProc(ref Message m) => throw new PlatformNotSupportedException(); @@ -264,7 +253,7 @@ public StatusBarPanelCollection(StatusBar owner) object IList.this[int index] { - get => this[index]; + get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } @@ -284,17 +273,17 @@ public int Count object ICollection.SyncRoot { - get => this; + get => throw new PlatformNotSupportedException(); } bool ICollection.IsSynchronized { - get => false; + get => throw new PlatformNotSupportedException(); } bool IList.IsFixedSize { - get => false; + get => throw new PlatformNotSupportedException(); } [Browsable(false)] @@ -320,7 +309,7 @@ public bool Contains(StatusBarPanel panel) => throw new PlatformNotSupportedException(); bool IList.Contains(object panel) - => false; + => throw new PlatformNotSupportedException(); public virtual bool ContainsKey(string key) => throw new PlatformNotSupportedException(); @@ -347,7 +336,7 @@ public virtual void Remove(StatusBarPanel value) => throw new PlatformNotSupportedException(); void IList.Remove(object value) - => Remove((StatusBarPanel)value); + => throw new PlatformNotSupportedException(); public virtual void RemoveAt(int index) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs index e758a0fb08a..e950a387efc 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs @@ -117,11 +117,11 @@ public void BeginInit() => throw new PlatformNotSupportedException(); protected override void Dispose(bool disposing) - => base.Dispose(disposing); + => throw new PlatformNotSupportedException(); public void EndInit() => throw new PlatformNotSupportedException(); public override string ToString() - => "StatusBarPanel: {" + Text + "}"; + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs index cb42a3bfd35..be29ce5e8c0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs @@ -297,7 +297,7 @@ public ToolBarButtonCollection(ToolBar owner) object IList.this[int index] { - get => this[index]; + get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } @@ -317,17 +317,17 @@ public int Count object ICollection.SyncRoot { - get => this; + get => throw new PlatformNotSupportedException(); } bool ICollection.IsSynchronized { - get => false; + get => throw new PlatformNotSupportedException(); } bool IList.IsFixedSize { - get => false; + get => throw new PlatformNotSupportedException(); } [Browsable(false)] From 547859352fdb965706e91fe04c4d6aa4ddf51254 Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Sun, 7 Apr 2024 10:27:14 +0800 Subject: [PATCH 09/11] Use expression body for Obsolete controls --- .../Obsolete/ContextMenu/ContextMenu.cs | 4 +- .../Controls/Obsolete/ContextMenu/Menu.cs | 44 +++-------- .../Controls/Obsolete/ContextMenu/MenuItem.cs | 8 +- .../Controls/Obsolete/DataGrid/DataGrid.cs | 44 +++-------- .../Obsolete/DataGrid/DataGridAddNewRow.cs | 2 +- .../Obsolete/DataGrid/DataGridColumn.cs | 45 +++-------- .../Obsolete/DataGrid/DataGridParentRows.cs | 32 ++------ .../DataGrid/DataGridParentRowsLabel.cs | 3 +- .../DataGrid/DataGridRelationshipRow.cs | 42 +++-------- .../Controls/Obsolete/DataGrid/DataGridRow.cs | 74 +++++-------------- .../Obsolete/DataGrid/DataGridState.cs | 20 ++--- .../Obsolete/DataGrid/DataGridTable.cs | 4 +- .../DataGrid/DataGridTableCollection.cs | 32 ++------ .../DataGrid/DataGridTablesFactory.cs | 3 +- .../DataGrid/DataGridTextBoxColumn.cs | 8 +- .../DataGrid/GridColumnStylesCollection.cs | 36 +++------ .../Controls/Obsolete/StatusBar/StatusBar.cs | 36 +++------ .../StatusBar/StatusBarDrawItemEvent.cs | 11 ++- .../StatusBarDrawItemEventHandler.cs | 3 +- .../Obsolete/StatusBar/StatusBarPanel.cs | 4 +- .../StatusBar/StatusBarPanelAutoSize.cs | 3 +- .../StatusBar/StatusBarPanelClickEvent.cs | 4 +- .../Controls/Obsolete/ToolBar/ToolBar.cs | 28 ++----- .../Obsolete/ToolBar/ToolBarAppearance.cs | 3 +- .../Obsolete/ToolBar/ToolBarButton.cs | 8 +- .../ToolBar/ToolBarButtonClickEventArgs.cs | 3 +- .../ToolBar/ToolBarButtonClickEventHandler.cs | 3 +- .../Obsolete/ToolBar/ToolBarButtonStyle.cs | 3 +- .../Obsolete/ToolBar/ToolBarTextAlign.cs | 3 +- 29 files changed, 143 insertions(+), 370 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs index ba9803ad985..c5361583e84 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs @@ -24,9 +24,7 @@ public ContextMenu(MenuItem[] menuItems) : base(menuItems) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public Control SourceControl - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs index 8f5d591c56c..aef3d7a9326 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs @@ -24,23 +24,17 @@ protected Menu(MenuItem[] items) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public IntPtr Handle - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public virtual bool IsParent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public MenuItem MdiListItem - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -53,9 +47,7 @@ public string Name [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public MenuItemCollection MenuItems - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -92,9 +84,7 @@ public MenuItemCollection(Menu owner) => throw new PlatformNotSupportedException(); public virtual MenuItem this[int index] - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); object IList.this[int index] { @@ -103,34 +93,22 @@ public MenuItemCollection(Menu owner) } public virtual MenuItem this[string key] - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public int Count - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); object ICollection.SyncRoot - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool ICollection.IsSynchronized - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool IList.IsFixedSize - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public bool IsReadOnly - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual MenuItem Add(string caption) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs index cf481821148..420394c28d0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs @@ -104,9 +104,7 @@ public int Index [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override bool IsParent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -177,9 +175,7 @@ public bool ShowShortcut [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public bool Visible - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs index 9bda75b8824..5596a8b009d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs @@ -80,9 +80,7 @@ public BorderStyle BorderStyle } protected override Size DefaultSize - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -220,9 +218,7 @@ public int CurrentRowIndex [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public GridTableStylesCollection TableStyles - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -265,9 +261,7 @@ public DataGridParentRowsLabelStyle ParentRowsLabelStyle [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int FirstVisibleColumn - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -347,9 +341,7 @@ public void ResetHeaderForeColor() => throw new PlatformNotSupportedException(); protected ScrollBar HorizScrollBar - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -554,23 +546,17 @@ public override string Text } protected ScrollBar VertScrollBar - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int VisibleColumnCount - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int VisibleRowCount - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -841,23 +827,17 @@ public sealed class HitTestInfo [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int Column - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int Row - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public HitTestType Type - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override bool Equals(object obj) => throw new PlatformNotSupportedException(); @@ -908,9 +888,7 @@ public override string Name [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject GetChild(int index) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs index 2991ca768ba..8614849d23c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs @@ -53,5 +53,5 @@ public override void OnRowLeave() Brush backBr, Brush foreBrush, bool alignToRight) - => base.PaintCellContents(g, cellBounds, column, backBr, foreBrush, alignToRight); + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs index 69518d22218..fef9fdf2040 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs @@ -48,9 +48,7 @@ protected internal virtual void UpdateUI(CurrencyManager source, int rowNum, str [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public AccessibleObject HeaderAccessibleObject - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -81,14 +79,10 @@ protected virtual void SetDataGridInColumn(DataGrid value) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public virtual DataGridTableStyle DataGridTableStyle - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected int FontHeight - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -214,14 +208,14 @@ protected void CheckValidDataSource(CurrencyManager value) int rowNum, Rectangle bounds, bool readOnly) - => Edit(source, rowNum, bounds, readOnly, null, true); + => throw new PlatformNotSupportedException(); protected internal virtual void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText) - => Edit(source, rowNum, bounds, readOnly, displayText, true); + => throw new PlatformNotSupportedException(); protected internal abstract void Edit(CurrencyManager source, int rowNum, @@ -257,7 +251,7 @@ protected internal virtual void ConcedeFocus() Brush backBrush, Brush foreBrush, bool alignToRight) - => Paint(g, bounds, source, rowNum, alignToRight); + => throw new PlatformNotSupportedException(); protected internal virtual void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) => throw new PlatformNotSupportedException(); @@ -275,9 +269,7 @@ protected class CompModSwitches [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public static TraceSwitch DGEditColumnEditing - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } [Obsolete( @@ -296,40 +288,27 @@ public DataGridColumnHeaderAccessibleObject() : base() [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds - { - get - { - throw new PlatformNotSupportedException(); - } - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Name - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] protected DataGridColumnStyle Owner - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject Navigate(AccessibleNavigation navdir) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs index dde10248a8f..dee65fc5276 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs @@ -18,9 +18,7 @@ internal class DataGridParentRows [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public AccessibleObject AccessibleObject - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [ComVisible(true)] [Obsolete( @@ -36,51 +34,37 @@ public DataGridParentRowsAccessibleObject(DataGridParentRows owner) : base() [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string DefaultAction - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Name - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Value - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override void DoDefaultAction() => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs index 0437822e690..678d215808a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRowsLabel.cs @@ -3,7 +3,8 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. [Obsolete( Obsoletions.DataGridParentRowsLabelStyleMessage, error: false, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs index 8ed852b368a..c44181f3632 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs @@ -97,21 +97,17 @@ public DataGridRelationshipRowAccessibleObject(DataGridRow owner) : base(owner) => throw new PlatformNotSupportedException(); protected override void AddChildAccessibleObjects(IList children) - => base.AddChildAccessibleObjects(children); + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string DefaultAction - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override void DoDefaultAction() => throw new PlatformNotSupportedException(); @@ -133,47 +129,33 @@ public DataGridRelationshipAccessibleObject(DataGridRelationshipRow owner, int r [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Name - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected DataGridRelationshipRow Owner - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected DataGrid DataGrid - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -186,9 +168,7 @@ public override string Value [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string DefaultAction - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override void DoDefaultAction() => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs index f97f2481ddb..bf819cddb20 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs @@ -17,29 +17,21 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] internal abstract class DataGridRow : MarshalByRefObject { - protected DataGridTableStyle dgTable; - protected const int XOffset = 3; - protected const int YOffset = 2; - public DataGridRow(DataGrid dataGrid, DataGridTableStyle dgTable, int rowNumber) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public AccessibleObject AccessibleObject - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected virtual AccessibleObject CreateAccessibleObject() - => new DataGridRowAccessibleObject(this); + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public DataGrid DataGrid - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -52,9 +44,7 @@ public virtual int Height [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int RowNumber - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -237,49 +227,35 @@ protected virtual AccessibleObject CreateCellAccessibleObject(int column) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Name - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected DataGridRow Owner - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Value - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public override AccessibleObject GetChild(int index) => throw new PlatformNotSupportedException(); @@ -311,49 +287,35 @@ public DataGridCellAccessibleObject(DataGridRow owner, int column) : base() [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Name - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected DataGrid DataGrid - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string DefaultAction - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleStates State - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs index a49f50db679..2fc86ba0467 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs @@ -60,37 +60,27 @@ public DataGridStateParentRowAccessibleObject(DataGridState owner) : base() [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Rectangle Bounds - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Name - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleObject Parent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override AccessibleRole Role - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Value - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs index 38fcd1de369..0f54920562a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs @@ -401,9 +401,7 @@ public string MappingName [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public virtual GridColumnStylesCollection GridColumnStyles - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs index 2135e5ac1e8..2114b77c4ff 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs @@ -38,14 +38,10 @@ void IList.RemoveAt(int index) => throw new PlatformNotSupportedException(); bool IList.IsFixedSize - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool IList.IsReadOnly - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); object IList.this[int index] { @@ -58,40 +54,28 @@ void ICollection.CopyTo(Array array, int index) } int ICollection.Count - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool ICollection.IsSynchronized - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); object ICollection.SyncRoot - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); IEnumerator IEnumerable.GetEnumerator() => throw new PlatformNotSupportedException(); protected override ArrayList List - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public DataGridTableStyle this[int index] - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public DataGridTableStyle this[string tableName] - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual int Add(DataGridTableStyle table) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs index bfd21949ae4..766f5845356 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs @@ -3,7 +3,8 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. [Obsolete( Obsoletions.GridTablesFactoryMessage, error: false, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs index 1b9ec360177..b8608ca7887 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs @@ -38,9 +38,7 @@ public DataGridTextBoxColumn(PropertyDescriptor prop, bool isDefault) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public virtual TextBox TextBox - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected override void SetDataGridInColumn(DataGrid value) { @@ -49,9 +47,7 @@ protected override void SetDataGridInColumn(DataGrid value) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override PropertyDescriptor PropertyDescriptor - { - set => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs index badb072824f..27decbf4e45 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs @@ -38,14 +38,10 @@ void IList.RemoveAt(int index) => throw new PlatformNotSupportedException(); bool IList.IsFixedSize - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool IList.IsReadOnly - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); object IList.this[int index] { @@ -57,48 +53,34 @@ void ICollection.CopyTo(Array array, int index) => throw new PlatformNotSupportedException(); int ICollection.Count - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool ICollection.IsSynchronized - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); object ICollection.SyncRoot - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); IEnumerator IEnumerable.GetEnumerator() => throw new PlatformNotSupportedException(); protected override ArrayList List - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public DataGridColumnStyle this[int index] - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public DataGridColumnStyle this[string columnName] - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public DataGridColumnStyle this[PropertyDescriptor propertyDesciptor] - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual int Add(DataGridColumnStyle column) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs index e3fe1a299d6..75a9432aa02 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs @@ -69,19 +69,13 @@ public override ImageLayout BackgroundImageLayout } protected override CreateParams CreateParams - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected override ImeMode DefaultImeMode - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected override Size DefaultSize - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); protected override bool DoubleBuffered { @@ -140,9 +134,7 @@ public override Color ForeColor [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanelCollection Panels - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -267,31 +259,21 @@ public StatusBarPanelCollection(StatusBar owner) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int Count - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); object ICollection.SyncRoot - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool ICollection.IsSynchronized - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool IList.IsFixedSize - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public bool IsReadOnly - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public virtual StatusBarPanel Add(string text) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs index 5a64513ecb2..36bcb73b200 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs @@ -6,7 +6,8 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. [Obsolete( Obsoletions.StatusBarDrawItemEventArgsMessage, error: false, @@ -20,7 +21,7 @@ public class StatusBarDrawItemEventArgs : DrawItemEventArgs int itemId, DrawItemState itemState, StatusBarPanel panel) : base(g, font, r, itemId, itemState) - => throw new PlatformNotSupportedException(); + => throw new PlatformNotSupportedException(); public StatusBarDrawItemEventArgs(Graphics g, Font font, @@ -30,12 +31,10 @@ public class StatusBarDrawItemEventArgs : DrawItemEventArgs StatusBarPanel panel, Color foreColor, Color backColor) : base(g, font, r, itemId, itemState, foreColor, backColor) - => throw new PlatformNotSupportedException(); + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanel Panel - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs index 39aeae50b6a..a9fe74d11e7 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEventHandler.cs @@ -3,7 +3,8 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. [Obsolete( Obsoletions.StatusBarDrawItemEventHandlerMessage, error: false, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs index e950a387efc..813c74df0cf 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs @@ -69,9 +69,7 @@ public string Name [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public StatusBar Parent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs index 996dfa93904..18e66428726 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelAutoSize.cs @@ -3,7 +3,8 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. [Obsolete( Obsoletions.StatusBarPanelAutoSizeMessage, error: false, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs index d88329ca423..4244240dac3 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs @@ -25,7 +25,5 @@ public class StatusBarPanelClickEventArgs : MouseEventArgs [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public StatusBarPanel StatusBarPanel - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs index be29ce5e8c0..39d150b9fe0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs @@ -103,9 +103,7 @@ public BorderStyle BorderStyle [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public ToolBarButtonCollection Buttons - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -304,38 +302,26 @@ public ToolBarButtonCollection(ToolBar owner) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public virtual ToolBarButton this[string key] - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public int Count - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); object ICollection.SyncRoot - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool ICollection.IsSynchronized - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); bool IList.IsFixedSize - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public bool IsReadOnly - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); public int Add(ToolBarButton button) => throw new PlatformNotSupportedException(); diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs index 4355d29fad4..2cbf96ea38c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarAppearance.cs @@ -8,7 +8,8 @@ namespace System.Windows.Forms; error: false, DiagnosticId = Obsoletions.ToolBarAppearanceDiagnosticId, UrlFormat = Obsoletions.SharedUrlFormat)] -#pragma warning disable RS0016 // Add public types and members to the declared API +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. public enum ToolBarAppearance { Normal = 0, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs index e48bbc87a0f..b0a7faf65b1 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs @@ -64,9 +64,7 @@ public string Name [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public ToolBar Parent - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -87,9 +85,7 @@ public bool Pushed [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public Rectangle Rectangle - { - get => throw new PlatformNotSupportedException(); - } + => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs index be95598dcfc..3d85bb914a0 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs @@ -5,7 +5,8 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. [Obsolete( Obsoletions.ToolBarButtonClickEventArgsMessage, error: false, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs index 9842a1b87b1..5f4aa15d3c9 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventHandler.cs @@ -3,7 +3,8 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. [Obsolete( Obsoletions.ToolBarButtonClickEventHandlerMessage, error: false, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs index 18a0f5847aa..da39c470e1e 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonStyle.cs @@ -3,7 +3,8 @@ namespace System.Windows.Forms; -#pragma warning disable RS0016 // Add public types and members to the declared API +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. [Obsolete( Obsoletions.ToolBarButtonStyleMessage, error: false, diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs index 74539820c96..242a3225309 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarTextAlign.cs @@ -11,7 +11,8 @@ namespace System.Windows.Forms; error: false, DiagnosticId = Obsoletions.ToolBarTextAlignDiagnosticId, UrlFormat = Obsoletions.SharedUrlFormat)] -#pragma warning disable RS0016 // Add public types and members to the declared API +#pragma warning disable RS0016 // Add public types and members to the declared API to simplify porting of applications from .NET Framework to .NET. +// These types will not work, but if they are not accessed, other features in the application will work. public enum ToolBarTextAlign { Underneath = 0, From c915fc02a01711432a711d66cdfdc72674f7c4d6 Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Tue, 9 Apr 2024 15:57:19 +0800 Subject: [PATCH 10/11] Update code style and update the obsoletion message --- docs/list-of-diagnostics.md | 93 ++--- src/Common/src/Obsoletions.cs | 259 +++++-------- .../Obsolete/ContextMenu/ContextMenu.cs | 15 +- .../Controls/Obsolete/ContextMenu/Menu.cs | 114 ++---- .../Controls/Obsolete/ContextMenu/MenuItem.cs | 50 +-- .../Controls/Obsolete/DataGrid/DataGrid.cs | 357 ++++++------------ .../Obsolete/DataGrid/DataGridAddNewRow.cs | 57 --- .../Obsolete/DataGrid/DataGridBoolColumn.cs | 49 +-- .../Obsolete/DataGrid/DataGridCaption.cs | 37 -- .../Obsolete/DataGrid/DataGridCell.cs | 21 +- .../Obsolete/DataGrid/DataGridColumn.cs | 127 ++----- .../Obsolete/DataGrid/DataGridParentRows.cs | 87 ----- ...taGridPreferredColumnWidthTypeConverter.cs | 10 +- .../DataGrid/DataGridRelationshipRow.cs | 182 --------- .../Controls/Obsolete/DataGrid/DataGridRow.cs | 340 ----------------- .../Obsolete/DataGrid/DataGridState.cs | 90 ----- .../Obsolete/DataGrid/DataGridTable.cs | 147 +++----- .../DataGrid/DataGridTableCollection.cs | 73 ++-- .../DataGrid/DataGridTablesFactory.cs | 7 +- .../Obsolete/DataGrid/DataGridTextBox.cs | 19 +- .../DataGrid/DataGridTextBoxColumn.cs | 87 ++--- .../Obsolete/DataGrid/DataGridToolTip.cs | 30 -- .../DataGrid/GridColumnStylesCollection.cs | 87 ++--- .../Controls/Obsolete/MainMenu/MainMenu.cs | 18 +- .../Controls/Obsolete/StatusBar/StatusBar.cs | 128 +++---- .../StatusBar/StatusBarDrawItemEvent.cs | 9 +- .../Obsolete/StatusBar/StatusBarPanel.cs | 18 +- .../StatusBar/StatusBarPanelClickEvent.cs | 7 +- .../Controls/Obsolete/ToolBar/ToolBar.cs | 92 ++--- .../Obsolete/ToolBar/ToolBarButton.cs | 15 +- .../ToolBar/ToolBarButtonClickEventArgs.cs | 3 +- .../Obsolete/ObsoleteControls.Designer.cs | 4 +- .../Obsolete/ObsoleteControls.cs | 2 +- .../AccessibleObjectTests.cs | 6 +- .../Control.ControlAccessibleObjectTests.cs | 8 +- 35 files changed, 593 insertions(+), 2055 deletions(-) delete mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs delete mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs delete mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs delete mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs delete mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs delete mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs delete mode 100644 src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs diff --git a/docs/list-of-diagnostics.md b/docs/list-of-diagnostics.md index 8473d5a28eb..fc3667af10a 100644 --- a/docs/list-of-diagnostics.md +++ b/docs/list-of-diagnostics.md @@ -39,60 +39,45 @@ The acceptance criteria for adding an obsoletion includes: | __`WFDEV002`__ | `DomainUpDown.DomainUpDownAccessibleObject` is no longer used to provide accessible support for `DomainUpDown` controls. Use `ControlAccessibleObject` instead. | | __`WFDEV003`__ | `DomainUpDown.DomainItemAccessibleObject` is no longer used to provide accessible support for `DomainUpDown` items. | | __`WFDEV004`__ | `ContextMenu` has been deprecated. Use `ContextMenuStrip` instead. | -| __`WFDEV005`__ | `Menu` has been deprecated. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead. | -| __`WFDEV006`__ | `Menu.MenuItemCollection` has been deprecated. | -| __`WFDEV007`__ | `MenuItem` has been deprecated. Use `ToolStripMenuItem` instead. | -| __`WFDEV008`__ | `MenuMerge` has been deprecated. | -| __`WFDEV009`__ | `DataGrid` has been deprecated. Use `DataGridView` instead. | -| __`WFDEV010`__ | `DataGrid.HitTestInfo` has been deprecated. | -| __`WFDEV011`__ | `DataGrid.HitTestType` has been deprecated. | -| __`WFDEV012`__ | `DataGrid.DataGridAccessibleObject` has been deprecated. | -| __`WFDEV013`__ | `DataGridAddNewRow` has been deprecated. | -| __`WFDEV014`__ | `DataGridBoolColumn` has been deprecated. | -| __`WFDEV015`__ | `DataGridCaption` has been deprecated. | -| __`WFDEV016`__ | `DataGridCell` has been deprecated. | -| __`WFDEV017`__ | `DataGridColumnStyle` has been deprecated. | -| __`WFDEV018`__ | `DataGridColumnHeaderAccessibleObject` has been deprecated. | -| __`WFDEV019`__ | `DataGridLineStyle` has been deprecated. | -| __`WFDEV020`__ | `DataGridParentRows` has been deprecated. | -| __`WFDEV021`__ | `DataGridParentRowsAccessibleObject` has been deprecated. | -| __`WFDEV022`__ | `DataGridParentRowsLabelStyle` has been deprecated. | -| __`WFDEV023`__ | `DataGridPreferredColumnWidthTypeConverter` has been deprecated. | -| __`WFDEV024`__ | `DataGridRelationshipRow` has been deprecated. | -| __`WFDEV025`__ | `DataGridRelationshipRowAccessibleObject` has been deprecated. | -| __`WFDEV026`__ | `DataGridRelationshipAccessibleObject` has been deprecated. | -| __`WFDEV027`__ | `DataGridRow` has been deprecated. | -| __`WFDEV028`__ | `DataGridRowAccessibleObject` has been deprecated. | -| __`WFDEV029`__ | `DataGridCellAccessibleObject` has been deprecated. | -| __`WFDEV030`__ | `DataGridState` has been deprecated. | -| __`WFDEV031`__ | `DataGridStateParentRowAccessibleObject` has been deprecated. | -| __`WFDEV032`__ | `DataGridTableStyle` has been deprecated. | -| __`WFDEV033`__ | `GridTableStylesCollection` has been deprecated. | -| __`WFDEV034`__ | `GridTablesFactory` has been deprecated. | -| __`WFDEV035`__ | `DataGridTextBox` has been deprecated. | -| __`WFDEV036`__ | `DataGridTextBoxColumn` has been deprecated. | -| __`WFDEV037`__ | `DataGridToolTip` has been deprecated. | -| __`WFDEV038`__ | `GridColumnStylesCollection` has been deprecated. | -| __`WFDEV039`__ | `IDataGridEditingService` has been deprecated. | -| __`WFDEV040`__ | `MainMenu` has been deprecated. Use `MenuStrip` instead. | -| __`WFDEV041`__ | `StatusBar` has been deprecated. Use `StatusStrip` instead. | -| __`WFDEV042`__ | `StatusBarPanelCollection` has been deprecated. | -| __`WFDEV043`__ | `StatusBarDrawItemEventArgs` has been deprecated. Use `DrawItemEventArgs` instead. | -| __`WFDEV044`__ | `StatusBarDrawItemEventHandler` has been deprecated. Use `DrawItemEventHandler` instead. | -| __`WFDEV045`__ | `StatusBarPanel` has been deprecated. Use `StatusStrip` instead. | -| __`WFDEV046`__ | `StatusBarPanelAutoSize` has been deprecated. | -| __`WFDEV047`__ | `StatusBarPanelBorderStyle` has been deprecated. Use the `BorderStyle` property of the `StatusBarPanel` class instead. | -| __`WFDEV048`__ | `StatusBarPanelClickEventArgs` has been deprecated. | -| __`WFDEV049`__ | `StatusBarPanelStyle` has been deprecated. Use `StatusBarPanel.Style` instead. | -| __`WFDEV050`__ | `StatusBarPanelClickEventHandler` has been deprecated. | -| __`WFDEV051`__ | `ToolBar` has been deprecated. Use `ToolStrip` instead. | -| __`WFDEV052`__ | `ToolBarButtonCollection` has been deprecated. | -| __`WFDEV053`__ | `ToolBarAppearance` has been deprecated. | -| __`WFDEV054`__ | `ToolBarButton` has been deprecated. Use `ToolStripButton` instead. | -| __`WFDEV055`__ | `ToolBarButtonClickEventArgs` has been deprecated. | -| __`WFDEV056`__ | `ToolBarButtonClickEventHandler` has been deprecated. | -| __`WFDEV057`__ | `ToolBarButtonStyle` has been deprecated. | -| __`WFDEV058`__ | `ToolBarTextAlign` has been deprecated. | +| __`WFDEV005`__ | `DataGrid` has been deprecated. Use `DataGridView` instead. | +| __`WFDEV006`__ | `DataGrid.HitTestInfo` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV007`__ | `DataGrid.HitTestType` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV008`__ | `DataGridBoolColumn` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV009`__ | `DataGridCell` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV010`__ | `DataGridColumnStyle` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV011`__ | `DataGridLineStyle` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV012`__ | `DataGridParentRowsLabelStyle` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV013`__ | `DataGridPreferredColumnWidthTypeConverter` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV014`__ | `DataGridTableStyle` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV015`__ | `DataGridTextBox` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV016`__ | `DataGridTextBoxColumn` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV017`__ | `GridColumnStylesCollection` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV018`__ | `GridTableStylesCollection` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV019`__ | `GridTablesFactory` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV020`__ | `IDataGridEditingService` has been deprecated. Use `DataGridView` control and related classes in your application. | +| __`WFDEV021`__ | `MainMenu` has been deprecated. Use `MenuStrip` instead. | +| __`WFDEV022`__ | `Menu` has been deprecated. Use `ToolStripDropDown` and `ToolStripDropDownMenu` instead. | +| __`WFDEV023`__ | `Menu.MenuItemCollection` has been deprecated. Use `ToolStripDropDown` and `ToolStripDropDownMenu` control and related classes in your application. | +| __`WFDEV024`__ | `MenuItem` has been deprecated. Use `ToolStripMenuItem` instead. | +| __`WFDEV025`__ | `MenuMerge` has been deprecated. Use `ToolStripDropDown` and `ToolStripDropDownMenu` control and related classes in your application. | +| __`WFDEV026`__ | `StatusBar` has been deprecated. Use `StatusStrip` instead. | +| __`WFDEV027`__ | `StatusBarPanelCollection` has been deprecated. Use `StatusStrip` control and related classes in your application. | +| __`WFDEV028`__ | `StatusBarDrawItemEventArgs` has been deprecated. Use `DrawItemEventArgs` instead. | +| __`WFDEV029`__ | `StatusBarDrawItemEventHandler` has been deprecated. Use `DrawItemEventHandler` instead. | +| __`WFDEV030`__ | `StatusBarPanel` has been deprecated. Use `StatusStrip` control and related classes in your application. | +| __`WFDEV031`__ | `StatusBarPanelAutoSize` has been deprecated. Use `StatusStrip` control and related classes in your application. | +| __`WFDEV032`__ | `StatusBarPanelBorderStyle` has been deprecated. Use `StatusStrip` control and related classes in your application. | +| __`WFDEV033`__ | `StatusBarPanelClickEventArgs` has been deprecated. Use `StatusStrip` control and related classes in your application. | +| __`WFDEV034`__ | `StatusBarPanelStyle` has been deprecated. Use `StatusStrip` control and related classes in your application. | +| __`WFDEV035`__ | `StatusBarPanelClickEventHandler` has been deprecated. Use `StatusStrip` control and related classes in your application. | +| __`WFDEV036`__ | `ToolBar` has been deprecated. Use `ToolStrip` instead. | +| __`WFDEV037`__ | `ToolBarButtonCollection` has been deprecated. Use `ToolStrip` control and related classes in your application. | +| __`WFDEV038`__ | `ToolBarAppearance` has been deprecated. Use `ToolStrip` control and related classes in your application. | +| __`WFDEV039`__ | `ToolBarButton` has been deprecated. Use `ToolStripButton` instead. | +| __`WFDEV040`__ | `ToolBarButtonClickEventArgs` has been deprecated. Use `ToolStrip` control and related classes in your application. | +| __`WFDEV041`__ | `ToolBarButtonClickEventHandler` has been deprecated. Use `ToolStrip` control and related classes in your application. | +| __`WFDEV042`__ | `ToolBarButtonStyle` has been deprecated. Use `ToolStrip` control and related classes in your application. | +| __`WFDEV043`__ | `ToolBarTextAlign` has been deprecated. Use `ToolStrip` control and related classes in your application. | diff --git a/src/Common/src/Obsoletions.cs b/src/Common/src/Obsoletions.cs index eb6bc66ade2..1a994da9bb9 100644 --- a/src/Common/src/Obsoletions.cs +++ b/src/Common/src/Obsoletions.cs @@ -28,246 +28,187 @@ internal static class Obsoletions internal const string ContextMenuDiagnosticId = "WFDEV004"; #pragma warning disable WFDEV005 // Type or member is obsolete - internal const string MenuMessage = $"{nameof(Menu)} has been deprecated. Use {nameof(ToolStripDropDown)} and {nameof(ToolStripDropDownMenu)} instead."; + internal const string DataGridMessage = $"{nameof(DataGrid)} has been deprecated. Use {nameof(DataGridView)} instead."; #pragma warning restore WFDEV005 // Type or member is obsolete - internal const string MenuDiagnosticId = "WFDEV005"; + internal const string DataGridDiagnosticId = "WFDEV005"; - internal const string MenuItemCollectionMessage = $"Menu.MenuItemCollection has been deprecated."; - internal const string MenuItemCollectionDiagnosticId = "WFDEV006"; + internal const string DataGridHitTestInfoMessage = $"HitTestInfo has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; + internal const string DataGridHitTestInfoDiagnosticId = "WFDEV006"; -#pragma warning disable WFDEV007 // Type or member is obsolete - internal const string MenuItemMessage = $"{nameof(MenuItem)} has been deprecated. Use {nameof(ToolStripMenuItem)} instead."; -#pragma warning restore WFDEV007 // Type or member is obsolete - internal const string MenuItemDiagnosticId = "WFDEV007"; + internal const string DataGridHitTestTypeMessage = $"HitTestType has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; + internal const string DataGridHitTestTypeDiagnosticId = "WFDEV007"; #pragma warning disable WFDEV008 // Type or member is obsolete - internal const string MenuMergeMessage = $"{nameof(MenuMerge)} has been deprecated."; + internal const string DataGridBoolColumnMessage = $"{nameof(DataGridBoolColumn)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV008 // Type or member is obsolete - internal const string MenuMergeDiagnosticId = "WFDEV008"; + internal const string DataGridBoolColumnDiagnosticId = "WFDEV008"; #pragma warning disable WFDEV009 // Type or member is obsolete - internal const string DataGridMessage = $"{nameof(DataGrid)} has been deprecated. Use {nameof(DataGridView)} instead."; + internal const string DataGridCellMessage = $"{nameof(DataGridCell)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV009 // Type or member is obsolete - internal const string DataGridDiagnosticId = "WFDEV009"; + internal const string DataGridCellDiagnosticId = "WFDEV009"; - internal const string DataGridHitTestInfoMessage = $"DataGrid.HitTestInfo has been deprecated."; - internal const string DataGridHitTestInfoDiagnosticId = "WFDEV010"; +#pragma warning disable WFDEV010 // Type or member is obsolete + internal const string DataGridColumnStyleMessage = $"{nameof(DataGridColumnStyle)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; +#pragma warning restore WFDEV010 // Type or member is obsolete + internal const string DataGridColumnStyleDiagnosticId = "WFDEV010"; - internal const string DataGridHitTestTypeMessage = $"DataGrid.HitTestType has been deprecated."; - internal const string DataGridHitTestTypeDiagnosticId = "WFDEV011"; +#pragma warning disable WFDEV011 // Type or member is obsolete + internal const string DataGridLineStyleMessage = $"{nameof(DataGridLineStyle)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; +#pragma warning restore WFDEV011 // Type or member is obsolete + internal const string DataGridLineStyleDiagnosticId = "WFDEV011"; - internal const string DataGridAccessibleObjectMessage = $"DataGrid.DataGridAccessibleObject has been deprecated."; - internal const string DataGridAccessibleObjectDiagnosticId = "WFDEV012"; +#pragma warning disable WFDEV012 // Type or member is obsolete + internal const string DataGridParentRowsLabelStyleMessage = $"{nameof(DataGridParentRowsLabelStyle)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; +#pragma warning restore WFDEV012 // Type or member is obsolete + internal const string DataGridParentRowsLabelStyleDiagnosticId = "WFDEV012"; #pragma warning disable WFDEV013 // Type or member is obsolete - internal const string DataGridAddNewRowMessage = $"{nameof(DataGridAddNewRow)} has been deprecated."; + internal const string DataGridPreferredColumnWidthTypeConverterMessage = $"{nameof(DataGridPreferredColumnWidthTypeConverter)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV013 // Type or member is obsolete - internal const string DataGridAddNewRowDiagnosticId = "WFDEV013"; + internal const string DataGridPreferredColumnWidthTypeConverterDiagnosticId = "WFDEV013"; #pragma warning disable WFDEV014 // Type or member is obsolete - internal const string DataGridBoolColumnMessage = $"{nameof(DataGridBoolColumn)} has been deprecated."; + internal const string DataGridTableStyleMessage = $"{nameof(DataGridTableStyle)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV014 // Type or member is obsolete - internal const string DataGridBoolColumnDiagnosticId = "WFDEV014"; + internal const string DataGridTableStyleDiagnosticId = "WFDEV014"; #pragma warning disable WFDEV015 // Type or member is obsolete - internal const string DataGridCaptionMessage = $"{nameof(DataGridCaption)} has been deprecated."; + internal const string DataGridTextBoxMessage = $"{nameof(DataGridTextBox)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV015 // Type or member is obsolete - internal const string DataGridCaptionDiagnosticId = "WFDEV015"; + internal const string DataGridTextBoxDiagnosticId = "WFDEV015"; #pragma warning disable WFDEV016 // Type or member is obsolete - internal const string DataGridCellMessage = $"{nameof(DataGridCell)} has been deprecated."; + internal const string DataGridTextBoxColumnMessage = $"{nameof(DataGridTextBoxColumn)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV016 // Type or member is obsolete - internal const string DataGridCellDiagnosticId = "WFDEV016"; + internal const string DataGridTextBoxColumnDiagnosticId = "WFDEV016"; #pragma warning disable WFDEV017 // Type or member is obsolete - internal const string DataGridColumnStyleMessage = $"{nameof(DataGridColumnStyle)} has been deprecated."; + internal const string GridColumnStylesCollectionMessage = $"{nameof(GridColumnStylesCollection)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV017 // Type or member is obsolete - internal const string DataGridColumnStyleDiagnosticId = "WFDEV017"; + internal const string GridColumnStylesCollectionDiagnosticId = "WFDEV017"; - internal const string DataGridColumnHeaderAccessibleObjectMessage = $"DataGridColumnHeaderAccessibleObject has been deprecated."; - internal const string DataGridColumnHeaderAccessibleObjectDiagnosticId = "WFDEV018"; +#pragma warning disable WFDEV018 // Type or member is obsolete + internal const string GridTableStylesCollectionMessage = $"{nameof(GridTableStylesCollection)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; +#pragma warning restore WFDEV018 // Type or member is obsolete + internal const string GridTableStylesCollectionDiagnosticId = "WFDEV018"; #pragma warning disable WFDEV019 // Type or member is obsolete - internal const string DataGridLineStyleMessage = $"{nameof(DataGridLineStyle)} has been deprecated."; + internal const string GridTablesFactoryMessage = $"{nameof(GridTablesFactory)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV019 // Type or member is obsolete - internal const string DataGridLineStyleDiagnosticId = "WFDEV019"; + internal const string GridTablesFactoryDiagnosticId = "WFDEV019"; #pragma warning disable WFDEV020 // Type or member is obsolete - internal const string DataGridParentRowsMessage = $"{nameof(DataGridParentRows)} has been deprecated."; + internal const string IDataGridEditingServiceMessage = $"{nameof(IDataGridEditingService)} has been deprecated. Use {nameof(DataGridView)} control and related classes in your application."; #pragma warning restore WFDEV020 // Type or member is obsolete - internal const string DataGridParentRowsDiagnosticId = "WFDEV020"; + internal const string IDataGridEditingServiceDiagnosticId = "WFDEV020"; - internal const string DataGridParentRowsAccessibleObjectMessage = $"DataGridParentRowsAccessibleObject has been deprecated."; - internal const string DataGridParentRowsAccessibleObjectDiagnosticId = "WFDEV021"; +#pragma warning disable WFDEV021 // Type or member is obsolete + internal const string MainMenuMessage = $"{nameof(MainMenu)} has been deprecated. Use {nameof(MenuStrip)} instead."; +#pragma warning restore WFDEV021 // Type or member is obsolete + internal const string MainMenuDiagnosticId = "WFDEV021"; #pragma warning disable WFDEV022 // Type or member is obsolete - internal const string DataGridParentRowsLabelStyleMessage = $"{nameof(DataGridParentRowsLabelStyle)} has been deprecated."; + internal const string MenuMessage = $"{nameof(Menu)} has been deprecated. Use {nameof(ToolStripDropDown)} and {nameof(ToolStripDropDownMenu)} instead."; #pragma warning restore WFDEV022 // Type or member is obsolete - internal const string DataGridParentRowsLabelStyleDiagnosticId = "WFDEV022"; + internal const string MenuDiagnosticId = "WFDEV022"; -#pragma warning disable WFDEV023 // Type or member is obsolete - internal const string DataGridPreferredColumnWidthTypeConverterMessage = $"{nameof(DataGridPreferredColumnWidthTypeConverter)} has been deprecated."; -#pragma warning restore WFDEV023 // Type or member is obsolete - internal const string DataGridPreferredColumnWidthTypeConverterDiagnosticId = "WFDEV023"; + internal const string MenuItemCollectionMessage = $"MenuItemCollection has been deprecated. Use {nameof(ToolStripDropDown)} and {nameof(ToolStripDropDownMenu)} control and related classes in your application."; + internal const string MenuItemCollectionDiagnosticId = "WFDEV023"; #pragma warning disable WFDEV024 // Type or member is obsolete - internal const string DataGridRelationshipRowMessage = $"{nameof(DataGridRelationshipRow)} has been deprecated."; + internal const string MenuItemMessage = $"{nameof(MenuItem)} has been deprecated. Use {nameof(ToolStripMenuItem)} instead."; #pragma warning restore WFDEV024 // Type or member is obsolete - internal const string DataGridRelationshipRowDiagnosticId = "WFDEV024"; + internal const string MenuItemDiagnosticId = "WFDEV024"; - internal const string DataGridRelationshipRowAccessibleObjectMessage = $"DataGridRelationshipRowAccessibleObject has been deprecated."; - internal const string DataGridRelationshipRowAccessibleObjectDiagnosticId = "WFDEV025"; +#pragma warning disable WFDEV025 // Type or member is obsolete + internal const string MenuMergeMessage = $"{nameof(MenuMerge)} has been deprecated. Use {nameof(ToolStripDropDown)} and {nameof(ToolStripDropDownMenu)} control and related classes in your application."; +#pragma warning restore WFDEV025 // Type or member is obsolete + internal const string MenuMergeDiagnosticId = "WFDEV025"; - internal const string DataGridRelationshipAccessibleObjectMessage = $"DataGridRelationshipAccessibleObject has been deprecated."; - internal const string DataGridRelationshipAccessibleObjectDiagnosticId = "WFDEV026"; +#pragma warning disable WFDEV026 // Type or member is obsolete + internal const string StatusBarMessage = $"{nameof(StatusBar)} has been deprecated. Use {nameof(StatusStrip)} instead."; +#pragma warning restore WFDEV026 // Type or member is obsolete + internal const string StatusBarDiagnosticId = "WFDEV026"; -#pragma warning disable WFDEV027 // Type or member is obsolete - internal const string DataGridRowMessage = $"{nameof(DataGridRow)} has been deprecated."; -#pragma warning restore WFDEV027 // Type or member is obsolete - internal const string DataGridRowDiagnosticId = "WFDEV027"; + internal const string StatusBarPanelCollectionMessage = $"StatusBarPanelCollection has been deprecated. Use {nameof(StatusStrip)} control and related classes in your application."; + internal const string StatusBarPanelCollectionDiagnosticId = "WFDEV027"; - internal const string DataGridRowAccessibleObjectMessage = $"DataGridRowAccessibleObject has been deprecated."; - internal const string DataGridRowAccessibleObjectDiagnosticId = "WFDEV028"; +#pragma warning disable WFDEV028 // Type or member is obsolete + internal const string StatusBarDrawItemEventArgsMessage = $"{nameof(StatusBarDrawItemEventArgs)} has been deprecated. Use {nameof(DrawItemEventArgs)} instead."; +#pragma warning restore WFDEV028 // Type or member is obsolete + internal const string StatusBarDrawItemEventArgsDiagnosticId = "WFDEV028"; - internal const string DataGridCellAccessibleObjectMessage = $"DataGridCellAccessibleObject has been deprecated."; - internal const string DataGridCellAccessibleObjectDiagnosticId = "WFDEV029"; +#pragma warning disable WFDEV029 // Type or member is obsolete + internal const string StatusBarDrawItemEventHandlerMessage = $"{nameof(StatusBarDrawItemEventHandler)} has been deprecated. Use {nameof(DrawItemEventHandler)} instead."; +#pragma warning restore WFDEV029 // Type or member is obsolete + internal const string StatusBarDrawItemEventHandlerDiagnosticId = "WFDEV029"; #pragma warning disable WFDEV030 // Type or member is obsolete - internal const string DataGridStateMessage = $"{nameof(DataGridState)} has been deprecated."; + internal const string StatusBarPanelMessage = $"{nameof(StatusBarPanel)} has been deprecated. Use {nameof(StatusStrip)} control and related classes in your application."; #pragma warning restore WFDEV030 // Type or member is obsolete - internal const string DataGridStateDiagnosticId = "WFDEV030"; + internal const string StatusBarPanelDiagnosticId = "WFDEV030"; - internal const string DataGridStateParentRowAccessibleObjectMessage = $"DataGridStateParentRowAccessibleObject has been deprecated."; - internal const string DataGridStateParentRowAccessibleObjectDiagnosticId = "WFDEV031"; +#pragma warning disable WFDEV031 // Type or member is obsolete + internal const string StatusBarPanelAutoSizeMessage = $"{nameof(StatusBarPanelAutoSize)} has been deprecated. Use {nameof(StatusStrip)} control and related classes in your application."; +#pragma warning restore WFDEV031 // Type or member is obsolete + internal const string StatusBarPanelAutoSizeDiagnosticId = "WFDEV031"; #pragma warning disable WFDEV032 // Type or member is obsolete - internal const string DataGridTableStyleMessage = $"{nameof(DataGridTableStyle)} has been deprecated."; + internal const string StatusBarPanelBorderStyleMessage = $"{nameof(StatusBarPanelBorderStyle)} has been deprecated. Use {nameof(StatusStrip)} control and related classes in your application."; #pragma warning restore WFDEV032 // Type or member is obsolete - internal const string DataGridTableStyleDiagnosticId = "WFDEV032"; + internal const string StatusBarPanelBorderStyleDiagnosticId = "WFDEV032"; #pragma warning disable WFDEV033 // Type or member is obsolete - internal const string GridTableStylesCollectionMessage = $"{nameof(GridTableStylesCollection)} has been deprecated."; + internal const string StatusBarPanelClickEventArgsMessage = $"{nameof(StatusBarPanelClickEventArgs)} has been deprecated. Use {nameof(StatusStrip)} control and related classes in your application."; #pragma warning restore WFDEV033 // Type or member is obsolete - internal const string GridTableStylesCollectionDiagnosticId = "WFDEV033"; + internal const string StatusBarPanelClickEventArgsDiagnosticId = "WFDEV033"; #pragma warning disable WFDEV034 // Type or member is obsolete - internal const string GridTablesFactoryMessage = $"{nameof(GridTablesFactory)} has been deprecated."; + internal const string StatusBarPanelStyleMessage = $"{nameof(StatusBarPanelStyle)} has been deprecated. Use {nameof(StatusStrip)} control and related classes in your application."; #pragma warning restore WFDEV034 // Type or member is obsolete - internal const string GridTablesFactoryDiagnosticId = "WFDEV034"; + internal const string StatusBarPanelStyleDiagnosticId = "WFDEV034"; #pragma warning disable WFDEV035 // Type or member is obsolete - internal const string DataGridTextBoxMessage = $"{nameof(DataGridTextBox)} has been deprecated."; + internal const string StatusBarPanelClickEventHandlerMessage = $"{nameof(StatusBarPanelClickEventHandler)} has been deprecated. Use {nameof(StatusStrip)} control and related classes in your application."; #pragma warning restore WFDEV035 // Type or member is obsolete - internal const string DataGridTextBoxDiagnosticId = "WFDEV035"; + internal const string StatusBarPanelClickEventHandlerDiagnosticId = "WFDEV035"; #pragma warning disable WFDEV036 // Type or member is obsolete - internal const string DataGridTextBoxColumnMessage = $"{nameof(DataGridTextBoxColumn)} has been deprecated."; + internal const string ToolBarMessage = $"{nameof(ToolBar)} has been deprecated. Use {nameof(ToolStrip)} instead."; #pragma warning restore WFDEV036 // Type or member is obsolete - internal const string DataGridTextBoxColumnDiagnosticId = "WFDEV036"; + internal const string ToolBarDiagnosticId = "WFDEV036"; -#pragma warning disable WFDEV037 // Type or member is obsolete - internal const string DataGridToolTipMessage = $"{nameof(DataGridToolTip)} has been deprecated."; -#pragma warning restore WFDEV037 // Type or member is obsolete - internal const string DataGridToolTipDiagnosticId = "WFDEV037"; + internal const string ToolBarButtonCollectionMessage = $"ToolBarButtonCollection has been deprecated. Use {nameof(ToolStrip)} control and related classes in your application."; + internal const string ToolBarButtonCollectionDiagnosticId = "WFDEV037"; #pragma warning disable WFDEV038 // Type or member is obsolete - internal const string GridColumnStylesCollectionMessage = $"{nameof(GridColumnStylesCollection)} has been deprecated."; + internal const string ToolBarAppearanceMessage = $"{nameof(ToolBarAppearance)} has been deprecated. Use {nameof(ToolStrip)} control and related classes in your application."; #pragma warning restore WFDEV038 // Type or member is obsolete - internal const string GridColumnStylesCollectionDiagnosticId = "WFDEV038"; + internal const string ToolBarAppearanceDiagnosticId = "WFDEV038"; #pragma warning disable WFDEV039 // Type or member is obsolete - internal const string IDataGridEditingServiceMessage = $"{nameof(IDataGridEditingService)} has been deprecated."; + internal const string ToolBarButtonMessage = $"{nameof(ToolBarButton)} has been deprecated. Use {nameof(ToolStripButton)} instead."; #pragma warning restore WFDEV039 // Type or member is obsolete - internal const string IDataGridEditingServiceDiagnosticId = "WFDEV039"; + internal const string ToolBarButtonDiagnosticId = "WFDEV039"; #pragma warning disable WFDEV040 // Type or member is obsolete - internal const string MainMenuMessage = $"{nameof(MainMenu)} has been deprecated. Use {nameof(MenuStrip)} instead."; + internal const string ToolBarButtonClickEventArgsMessage = $"{nameof(ToolBarButtonClickEventArgs)} has been deprecated. Use {nameof(ToolStrip)} control and related classes in your application."; #pragma warning restore WFDEV040 // Type or member is obsolete - internal const string MainMenuDiagnosticId = "WFDEV040"; + internal const string ToolBarButtonClickEventArgsDiagnosticId = "WFDEV040"; #pragma warning disable WFDEV041 // Type or member is obsolete - internal const string StatusBarMessage = $"{nameof(StatusBar)} has been deprecated. Use {nameof(StatusStrip)} instead."; + internal const string ToolBarButtonClickEventHandlerMessage = $"{nameof(ToolBarButtonClickEventHandler)} has been deprecated. Use {nameof(ToolStrip)} control and related classes in your application."; #pragma warning restore WFDEV041 // Type or member is obsolete - internal const string StatusBarDiagnosticId = "WFDEV041"; + internal const string ToolBarButtonClickEventHandlerDiagnosticId = "WFDEV041"; - internal const string StatusBarPanelCollectionMessage = $"StatusBarPanelCollection has been deprecated."; - internal const string StatusBarPanelCollectionDiagnosticId = "WFDEV042"; +#pragma warning disable WFDEV042 // Type or member is obsolete + internal const string ToolBarButtonStyleMessage = $"{nameof(ToolBarButtonStyle)} has been deprecated. Use {nameof(ToolStrip)} control and related classes in your application."; +#pragma warning restore WFDEV042 // Type or member is obsolete + internal const string ToolBarButtonStyleDiagnosticId = "WFDEV042"; #pragma warning disable WFDEV043 // Type or member is obsolete - internal const string StatusBarDrawItemEventArgsMessage = $"{nameof(StatusBarDrawItemEventArgs)} has been deprecated. Use {nameof(DrawItemEventArgs)} instead."; + internal const string ToolBarTextAlignMessage = $"{nameof(ToolBarTextAlign)} has been deprecated. Use {nameof(ToolStrip)} control and related classes in your application."; #pragma warning restore WFDEV043 // Type or member is obsolete - internal const string StatusBarDrawItemEventArgsDiagnosticId = "WFDEV043"; - -#pragma warning disable WFDEV044 // Type or member is obsolete - internal const string StatusBarDrawItemEventHandlerMessage = $"{nameof(StatusBarDrawItemEventHandler)} has been deprecated. Use {nameof(DrawItemEventHandler)} instead."; -#pragma warning restore WFDEV044 // Type or member is obsolete - internal const string StatusBarDrawItemEventHandlerDiagnosticId = "WFDEV044"; - -#pragma warning disable WFDEV045 // Type or member is obsolete - internal const string StatusBarPanelMessage = $"{nameof(StatusBarPanel)} has been deprecated. Use {nameof(StatusStrip)} instead."; -#pragma warning restore WFDEV045 // Type or member is obsolete - internal const string StatusBarPanelDiagnosticId = "WFDEV045"; - -#pragma warning disable WFDEV046 // Type or member is obsolete - internal const string StatusBarPanelAutoSizeMessage = $"{nameof(StatusBarPanelAutoSize)} has been deprecated."; -#pragma warning restore WFDEV046 // Type or member is obsolete - internal const string StatusBarPanelAutoSizeDiagnosticId = "WFDEV046"; - -#pragma warning disable WFDEV047 // Type or member is obsolete - internal const string StatusBarPanelBorderStyleMessage = $"{nameof(StatusBarPanelBorderStyle)} has been deprecated."; -#pragma warning restore WFDEV047 // Type or member is obsolete - internal const string StatusBarPanelBorderStyleDiagnosticId = "WFDEV047"; - -#pragma warning disable WFDEV048 // Type or member is obsolete - internal const string StatusBarPanelClickEventArgsMessage = $"{nameof(StatusBarPanelClickEventArgs)} has been deprecated."; -#pragma warning restore WFDEV048 // Type or member is obsolete - internal const string StatusBarPanelClickEventArgsDiagnosticId = "WFDEV048"; - -#pragma warning disable WFDEV049 // Type or member is obsolete - internal const string StatusBarPanelStyleMessage = $"{nameof(StatusBarPanelStyle)} has been deprecated."; -#pragma warning restore WFDEV049 // Type or member is obsolete - internal const string StatusBarPanelStyleDiagnosticId = "WFDEV049"; - -#pragma warning disable WFDEV050 // Type or member is obsolete - internal const string StatusBarPanelClickEventHandlerMessage = $"{nameof(StatusBarPanelClickEventHandler)} has been deprecated."; -#pragma warning restore WFDEV050 // Type or member is obsolete - internal const string StatusBarPanelClickEventHandlerDiagnosticId = "WFDEV050"; - -#pragma warning disable WFDEV051 // Type or member is obsolete - internal const string ToolBarMessage = $"{nameof(ToolBar)} has been deprecated. Use {nameof(ToolStrip)} instead."; -#pragma warning restore WFDEV051 // Type or member is obsolete - internal const string ToolBarDiagnosticId = "WFDEV051"; - - internal const string ToolBarButtonCollectionMessage = $"ToolBarButtonCollection has been deprecated."; - internal const string ToolBarButtonCollectionDiagnosticId = "WFDEV052"; - -#pragma warning disable WFDEV053 // Type or member is obsolete - internal const string ToolBarAppearanceMessage = $"{nameof(ToolBarAppearance)} has been deprecated."; -#pragma warning restore WFDEV053 // Type or member is obsolete - internal const string ToolBarAppearanceDiagnosticId = "WFDEV053"; - -#pragma warning disable WFDEV054 // Type or member is obsolete - internal const string ToolBarButtonMessage = $"{nameof(ToolBarButton)} has been deprecated. Use {nameof(ToolStripButton)} instead."; -#pragma warning restore WFDEV054 // Type or member is obsolete - internal const string ToolBarButtonDiagnosticId = "WFDEV054"; - -#pragma warning disable WFDEV055 // Type or member is obsolete - internal const string ToolBarButtonClickEventArgsMessage = $"{nameof(ToolBarButtonClickEventArgs)} has been deprecated."; -#pragma warning restore WFDEV055 // Type or member is obsolete - internal const string ToolBarButtonClickEventArgsDiagnosticId = "WFDEV055"; - -#pragma warning disable WFDEV056 // Type or member is obsolete - internal const string ToolBarButtonClickEventHandlerMessage = $"{nameof(ToolBarButtonClickEventHandler)} has been deprecated."; -#pragma warning restore WFDEV056 // Type or member is obsolete - internal const string ToolBarButtonClickEventHandlerDiagnosticId = "WFDEV056"; - -#pragma warning disable WFDEV057 // Type or member is obsolete - internal const string ToolBarButtonStyleMessage = $"{nameof(ToolBarButtonStyle)} has been deprecated."; -#pragma warning restore WFDEV057 // Type or member is obsolete - internal const string ToolBarButtonStyleDiagnosticId = "WFDEV057"; - -#pragma warning disable WFDEV058 // Type or member is obsolete - internal const string ToolBarTextAlignMessage = $"{nameof(ToolBarTextAlign)} has been deprecated."; -#pragma warning restore WFDEV058 // Type or member is obsolete - internal const string ToolBarTextAlignDiagnosticId = "WFDEV058"; + internal const string ToolBarTextAlignDiagnosticId = "WFDEV043"; } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs index c5361583e84..cf2bf494f1a 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/ContextMenu.cs @@ -15,16 +15,13 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class ContextMenu : Menu { - public ContextMenu() : base(null) - => throw new PlatformNotSupportedException(); + public ContextMenu() : base(null) => throw new PlatformNotSupportedException(); - public ContextMenu(MenuItem[] menuItems) : base(menuItems) - => throw new PlatformNotSupportedException(); + public ContextMenu(MenuItem[] menuItems) : base(menuItems) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public Control SourceControl - => throw new PlatformNotSupportedException(); + public Control SourceControl => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -50,9 +47,7 @@ public virtual RightToLeft RightToLeft set => throw new PlatformNotSupportedException(); } - public void Show(Control control, Point pos) - => throw new PlatformNotSupportedException(); + public void Show(Control control, Point pos) => throw new PlatformNotSupportedException(); - public void Show(Control control, Point pos, LeftRightAlignment alignment) - => throw new PlatformNotSupportedException(); + public void Show(Control control, Point pos, LeftRightAlignment alignment) => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs index aef3d7a9326..bce9d5077bb 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/Menu.cs @@ -18,23 +18,19 @@ public abstract class Menu : Component public const int FindHandle = 0; public const int FindShortcut = 1; - protected Menu(MenuItem[] items) - => throw new PlatformNotSupportedException(); + protected Menu(MenuItem[] items) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public IntPtr Handle - => throw new PlatformNotSupportedException(); + public IntPtr Handle => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual bool IsParent - => throw new PlatformNotSupportedException(); + public virtual bool IsParent => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public MenuItem MdiListItem - => throw new PlatformNotSupportedException(); + public MenuItem MdiListItem => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -46,8 +42,7 @@ public string Name [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public MenuItemCollection MenuItems - => throw new PlatformNotSupportedException(); + public MenuItemCollection MenuItems => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -57,20 +52,15 @@ public object Tag set => throw new PlatformNotSupportedException(); } - public MenuItem FindMenuItem(int type, IntPtr value) - => throw new PlatformNotSupportedException(); + public MenuItem FindMenuItem(int type, IntPtr value) => throw new PlatformNotSupportedException(); - public ContextMenu GetContextMenu() - => throw new PlatformNotSupportedException(); + public ContextMenu GetContextMenu() => throw new PlatformNotSupportedException(); - public MainMenu GetMainMenu() - => throw new PlatformNotSupportedException(); + public MainMenu GetMainMenu() => throw new PlatformNotSupportedException(); - public virtual void MergeMenu(Menu menuSrc) - => throw new PlatformNotSupportedException(); + public virtual void MergeMenu(Menu menuSrc) => throw new PlatformNotSupportedException(); - public override string ToString() - => throw new PlatformNotSupportedException(); + public override string ToString() => throw new PlatformNotSupportedException(); [ListBindable(false)] [Obsolete( @@ -80,11 +70,9 @@ public override string ToString() UrlFormat = Obsoletions.SharedUrlFormat)] public class MenuItemCollection : IList { - public MenuItemCollection(Menu owner) - => throw new PlatformNotSupportedException(); + public MenuItemCollection(Menu owner) => throw new PlatformNotSupportedException(); - public virtual MenuItem this[int index] - => throw new PlatformNotSupportedException(); + public virtual MenuItem this[int index] => throw new PlatformNotSupportedException(); object IList.this[int index] { @@ -92,82 +80,56 @@ public MenuItemCollection(Menu owner) set => throw new PlatformNotSupportedException(); } - public virtual MenuItem this[string key] - => throw new PlatformNotSupportedException(); + public virtual MenuItem this[string key] => throw new PlatformNotSupportedException(); - public int Count - => throw new PlatformNotSupportedException(); + public int Count => throw new PlatformNotSupportedException(); - object ICollection.SyncRoot - => throw new PlatformNotSupportedException(); + object ICollection.SyncRoot => throw new PlatformNotSupportedException(); - bool ICollection.IsSynchronized - => throw new PlatformNotSupportedException(); + bool ICollection.IsSynchronized => throw new PlatformNotSupportedException(); - bool IList.IsFixedSize - => throw new PlatformNotSupportedException(); + bool IList.IsFixedSize => throw new PlatformNotSupportedException(); - public bool IsReadOnly - => throw new PlatformNotSupportedException(); + public bool IsReadOnly => throw new PlatformNotSupportedException(); - public virtual MenuItem Add(string caption) - => throw new PlatformNotSupportedException(); + public virtual MenuItem Add(string caption) => throw new PlatformNotSupportedException(); - public virtual MenuItem Add(string caption, EventHandler onClick) - => throw new PlatformNotSupportedException(); + public virtual MenuItem Add(string caption, EventHandler onClick) => throw new PlatformNotSupportedException(); - public virtual MenuItem Add(string caption, MenuItem[] items) - => throw new PlatformNotSupportedException(); + public virtual MenuItem Add(string caption, MenuItem[] items) => throw new PlatformNotSupportedException(); - public virtual int Add(object value) - => throw new PlatformNotSupportedException(); + public virtual int Add(object value) => throw new PlatformNotSupportedException(); - public virtual int Add(int index, MenuItem item) - => throw new PlatformNotSupportedException(); + public virtual int Add(int index, MenuItem item) => throw new PlatformNotSupportedException(); - public virtual void AddRange(MenuItem[] items) - => throw new PlatformNotSupportedException(); + public virtual void AddRange(MenuItem[] items) => throw new PlatformNotSupportedException(); - public bool Contains(object value) - => throw new PlatformNotSupportedException(); + public bool Contains(object value) => throw new PlatformNotSupportedException(); - public virtual bool ContainsKey(string key) - => throw new PlatformNotSupportedException(); + public virtual bool ContainsKey(string key) => throw new PlatformNotSupportedException(); - public MenuItem[] Find(string key, bool searchAllChildren) - => throw new PlatformNotSupportedException(); + public MenuItem[] Find(string key, bool searchAllChildren) => throw new PlatformNotSupportedException(); - public int IndexOf(MenuItem value) - => throw new PlatformNotSupportedException(); + public int IndexOf(MenuItem value) => throw new PlatformNotSupportedException(); - int IList.IndexOf(object value) - => throw new PlatformNotSupportedException(); + int IList.IndexOf(object value) => throw new PlatformNotSupportedException(); - public virtual int IndexOfKey(string key) - => throw new PlatformNotSupportedException(); + public virtual int IndexOfKey(string key) => throw new PlatformNotSupportedException(); - void IList.Insert(int index, object value) - => throw new PlatformNotSupportedException(); + void IList.Insert(int index, object value) => throw new PlatformNotSupportedException(); - public virtual void Clear() - => throw new PlatformNotSupportedException(); + public virtual void Clear() => throw new PlatformNotSupportedException(); - public void CopyTo(Array array, int index) - => throw new PlatformNotSupportedException(); + public void CopyTo(Array array, int index) => throw new PlatformNotSupportedException(); - public IEnumerator GetEnumerator() - => throw new PlatformNotSupportedException(); + public IEnumerator GetEnumerator() => throw new PlatformNotSupportedException(); - public virtual void RemoveAt(int index) - => throw new PlatformNotSupportedException(); + public virtual void RemoveAt(int index) => throw new PlatformNotSupportedException(); - public virtual void RemoveByKey(string key) - => throw new PlatformNotSupportedException(); + public virtual void RemoveByKey(string key) => throw new PlatformNotSupportedException(); - public virtual void Remove(MenuItem item) - => throw new PlatformNotSupportedException(); + public virtual void Remove(MenuItem item) => throw new PlatformNotSupportedException(); - void IList.Remove(object value) - => throw new PlatformNotSupportedException(); + void IList.Remove(object value) => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs index 420394c28d0..ace360bac25 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ContextMenu/MenuItem.cs @@ -15,25 +15,18 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class MenuItem : Menu { - public MenuItem() - : this(MenuMerge.Add, 0, 0, null, null, null, null, null) - => throw new PlatformNotSupportedException(); + public MenuItem() : this(MenuMerge.Add, 0, 0, null, null, null, null, null) => throw new PlatformNotSupportedException(); - public MenuItem(string text) - : this(MenuMerge.Add, 0, 0, text, null, null, null, null) - => throw new PlatformNotSupportedException(); + public MenuItem(string text) : this(MenuMerge.Add, 0, 0, text, null, null, null, null) => throw new PlatformNotSupportedException(); - public MenuItem(string text, EventHandler onClick) - : this(MenuMerge.Add, 0, 0, text, onClick, null, null, null) - => throw new PlatformNotSupportedException(); + public MenuItem(string text, EventHandler onClick) : this(MenuMerge.Add, 0, 0, text, onClick, null, null, null) => + throw new PlatformNotSupportedException(); - public MenuItem(string text, EventHandler onClick, Shortcut shortcut) - : this(MenuMerge.Add, 0, shortcut, text, onClick, null, null, null) - => throw new PlatformNotSupportedException(); + public MenuItem(string text, EventHandler onClick, Shortcut shortcut) : this(MenuMerge.Add, 0, shortcut, text, onClick, null, null, null) => + throw new PlatformNotSupportedException(); - public MenuItem(string text, MenuItem[] items) - : this(MenuMerge.Add, 0, 0, text, null, null, null, items) - => throw new PlatformNotSupportedException(); + public MenuItem(string text, MenuItem[] items) : this(MenuMerge.Add, 0, 0, text, null, null, null, items) => + throw new PlatformNotSupportedException(); public MenuItem(MenuMerge mergeType, int mergeOrder, @@ -42,8 +35,7 @@ public MenuItem(string text, MenuItem[] items) EventHandler onClick, EventHandler onPopup, EventHandler onSelect, - MenuItem[] items) : base(items) - => throw new PlatformNotSupportedException(); + MenuItem[] items) : base(items) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -103,8 +95,7 @@ public int Index [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public override bool IsParent - => throw new PlatformNotSupportedException(); + public override bool IsParent => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -174,8 +165,7 @@ public bool ShowShortcut [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public bool Visible - => throw new PlatformNotSupportedException(); + public bool Visible => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -217,21 +207,15 @@ public bool Visible remove => throw new PlatformNotSupportedException(); } - public virtual MenuItem CloneMenu() - => throw new PlatformNotSupportedException(); + public virtual MenuItem CloneMenu() => throw new PlatformNotSupportedException(); - public virtual MenuItem MergeMenu() - => throw new PlatformNotSupportedException(); + public virtual MenuItem MergeMenu() => throw new PlatformNotSupportedException(); - public void MergeMenu(MenuItem itemSrc) - => throw new PlatformNotSupportedException(); + public void MergeMenu(MenuItem itemSrc) => throw new PlatformNotSupportedException(); - public void PerformClick() - => throw new PlatformNotSupportedException(); + public void PerformClick() => throw new PlatformNotSupportedException(); - public virtual void PerformSelect() - => throw new PlatformNotSupportedException(); + public virtual void PerformSelect() => throw new PlatformNotSupportedException(); - public override string ToString() - => throw new PlatformNotSupportedException(); + public override string ToString() => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs index 5596a8b009d..415643b41bf 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGrid.cs @@ -16,8 +16,7 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGrid : Control, ISupportInitialize, IDataGridEditingService { - public DataGrid() : base() - => throw new PlatformNotSupportedException(); + public DataGrid() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -35,11 +34,9 @@ public Color AlternatingBackColor set => throw new PlatformNotSupportedException(); } - public void ResetAlternatingBackColor() - => throw new PlatformNotSupportedException(); + public void ResetAlternatingBackColor() => throw new PlatformNotSupportedException(); - protected virtual bool ShouldSerializeAlternatingBackColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeAlternatingBackColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -49,8 +46,7 @@ public override Color BackColor set => throw new PlatformNotSupportedException(); } - public override void ResetBackColor() - => throw new PlatformNotSupportedException(); + public override void ResetBackColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -60,8 +56,7 @@ public override Color ForeColor set => throw new PlatformNotSupportedException(); } - public override void ResetForeColor() - => throw new PlatformNotSupportedException(); + public override void ResetForeColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -79,8 +74,7 @@ public BorderStyle BorderStyle remove => throw new PlatformNotSupportedException(); } - protected override Size DefaultSize - => throw new PlatformNotSupportedException(); + protected override Size DefaultSize => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -90,8 +84,7 @@ public Color CaptionBackColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeCaptionBackColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeCaptionBackColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -101,8 +94,7 @@ public Color CaptionForeColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeCaptionForeColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeCaptionForeColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -160,11 +152,9 @@ public Color SelectionBackColor set => throw new PlatformNotSupportedException(); } - protected bool ShouldSerializeSelectionBackColor() - => throw new PlatformNotSupportedException(); + protected bool ShouldSerializeSelectionBackColor() => throw new PlatformNotSupportedException(); - public void ResetSelectionBackColor() - => throw new PlatformNotSupportedException(); + public void ResetSelectionBackColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -174,11 +164,9 @@ public Color SelectionForeColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeSelectionForeColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeSelectionForeColor() => throw new PlatformNotSupportedException(); - public void ResetSelectionForeColor() - => throw new PlatformNotSupportedException(); + public void ResetSelectionForeColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -204,8 +192,7 @@ public string DataMember set => throw new PlatformNotSupportedException(); } - public void SetDataBinding(object dataSource, string dataMember) - => throw new PlatformNotSupportedException(); + public void SetDataBinding(object dataSource, string dataMember) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -217,8 +204,7 @@ public int CurrentRowIndex [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public GridTableStylesCollection TableStyles - => throw new PlatformNotSupportedException(); + public GridTableStylesCollection TableStyles => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -228,11 +214,9 @@ public Color GridLineColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeGridLineColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeGridLineColor() => throw new PlatformNotSupportedException(); - public void ResetGridLineColor() - => throw new PlatformNotSupportedException(); + public void ResetGridLineColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -260,8 +244,7 @@ public DataGridParentRowsLabelStyle ParentRowsLabelStyle [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public int FirstVisibleColumn - => throw new PlatformNotSupportedException(); + public int FirstVisibleColumn => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -287,14 +270,11 @@ public Color HeaderBackColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeHeaderBackColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeHeaderBackColor() => throw new PlatformNotSupportedException(); - public void ResetHeaderBackColor() - => throw new PlatformNotSupportedException(); + public void ResetHeaderBackColor() => throw new PlatformNotSupportedException(); - protected virtual bool ShouldSerializeBackgroundColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeBackgroundColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -320,11 +300,9 @@ public Font HeaderFont set => throw new PlatformNotSupportedException(); } - protected bool ShouldSerializeHeaderFont() - => throw new PlatformNotSupportedException(); + protected bool ShouldSerializeHeaderFont() => throw new PlatformNotSupportedException(); - public void ResetHeaderFont() - => throw new PlatformNotSupportedException(); + public void ResetHeaderFont() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -334,14 +312,11 @@ public Color HeaderForeColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeHeaderForeColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeHeaderForeColor() => throw new PlatformNotSupportedException(); - public void ResetHeaderForeColor() - => throw new PlatformNotSupportedException(); + public void ResetHeaderForeColor() => throw new PlatformNotSupportedException(); - protected ScrollBar HorizScrollBar - => throw new PlatformNotSupportedException(); + protected ScrollBar HorizScrollBar => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -351,8 +326,7 @@ public Color LinkColor set => throw new PlatformNotSupportedException(); } - public void ResetLinkColor() - => throw new PlatformNotSupportedException(); + public void ResetLinkColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -362,11 +336,9 @@ public Color LinkHoverColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeLinkHoverColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeLinkHoverColor() => throw new PlatformNotSupportedException(); - public void ResetLinkHoverColor() - => throw new PlatformNotSupportedException(); + public void ResetLinkHoverColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -440,8 +412,7 @@ public Color ParentRowsBackColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeParentRowsBackColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeParentRowsBackColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -451,8 +422,7 @@ public Color ParentRowsForeColor set => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeParentRowsForeColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeParentRowsForeColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -470,8 +440,7 @@ public int PreferredRowHeight set => throw new PlatformNotSupportedException(); } - protected bool ShouldSerializePreferredRowHeight() - => throw new PlatformNotSupportedException(); + protected bool ShouldSerializePreferredRowHeight() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -545,18 +514,15 @@ public override string Text remove => throw new PlatformNotSupportedException(); } - protected ScrollBar VertScrollBar - => throw new PlatformNotSupportedException(); + protected ScrollBar VertScrollBar => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public int VisibleColumnCount - => throw new PlatformNotSupportedException(); + public int VisibleColumnCount => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public int VisibleRowCount - => throw new PlatformNotSupportedException(); + public int VisibleRowCount => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -574,113 +540,77 @@ public int VisibleRowCount set => throw new PlatformNotSupportedException(); } - protected virtual void OnBorderStyleChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnBorderStyleChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnCaptionVisibleChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnCaptionVisibleChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnCurrentCellChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnCurrentCellChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnFlatModeChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnFlatModeChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnBackgroundColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnBackgroundColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnAllowNavigationChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnAllowNavigationChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnParentRowsVisibleChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnParentRowsVisibleChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnParentRowsLabelStyleChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnParentRowsLabelStyleChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnReadOnlyChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnReadOnlyChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected void OnNavigate(NavigateEventArgs e) - => throw new PlatformNotSupportedException(); + protected void OnNavigate(NavigateEventArgs e) => throw new PlatformNotSupportedException(); - protected void OnRowHeaderClick(EventArgs e) - => throw new PlatformNotSupportedException(); + protected void OnRowHeaderClick(EventArgs e) => throw new PlatformNotSupportedException(); - protected void OnScroll(EventArgs e) - => throw new PlatformNotSupportedException(); + protected void OnScroll(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void GridHScrolled(object sender, ScrollEventArgs se) - => throw new PlatformNotSupportedException(); + protected virtual void GridHScrolled(object sender, ScrollEventArgs se) => throw new PlatformNotSupportedException(); - protected virtual void GridVScrolled(object sender, ScrollEventArgs se) - => throw new PlatformNotSupportedException(); + protected virtual void GridVScrolled(object sender, ScrollEventArgs se) => throw new PlatformNotSupportedException(); - protected void OnBackButtonClicked(object sender, EventArgs e) - => throw new PlatformNotSupportedException(); + protected void OnBackButtonClicked(object sender, EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnBackColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnBackColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnBindingContextChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnBindingContextChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnDataSourceChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnDataSourceChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected void OnShowParentDetailsButtonClicked(object sender, EventArgs e) - => throw new PlatformNotSupportedException(); + protected void OnShowParentDetailsButtonClicked(object sender, EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnForeColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnForeColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnFontChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnFontChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnPaintBackground(PaintEventArgs pevent) - => throw new PlatformNotSupportedException(); + protected override void OnPaintBackground(PaintEventArgs pevent) => throw new PlatformNotSupportedException(); - protected override void OnLayout(LayoutEventArgs levent) - => throw new PlatformNotSupportedException(); + protected override void OnLayout(LayoutEventArgs levent) => throw new PlatformNotSupportedException(); - protected override void OnHandleCreated(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnHandleCreated(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnHandleDestroyed(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnHandleDestroyed(EventArgs e) => throw new PlatformNotSupportedException(); - protected internal override void OnEnter(EventArgs e) - => throw new PlatformNotSupportedException(); + protected internal override void OnEnter(EventArgs e) => throw new PlatformNotSupportedException(); - protected internal override void OnLeave(EventArgs e) - => throw new PlatformNotSupportedException(); + protected internal override void OnLeave(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnKeyDown(KeyEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnKeyDown(KeyEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnKeyPress(KeyPressEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnKeyPress(KeyPressEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnMouseDown(MouseEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnMouseDown(MouseEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnMouseLeave(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnMouseLeave(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnMouseMove(MouseEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnMouseMove(MouseEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnMouseUp(MouseEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnMouseUp(MouseEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnMouseWheel(MouseEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnMouseWheel(MouseEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnPaint(PaintEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnPaint(PaintEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnResize(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnResize(EventArgs e) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -714,77 +644,53 @@ public override ISite Site set => throw new PlatformNotSupportedException(); } - public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) - => throw new PlatformNotSupportedException(); + public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) => throw new PlatformNotSupportedException(); - public void BeginInit() - => throw new PlatformNotSupportedException(); + public void BeginInit() => throw new PlatformNotSupportedException(); - public void Collapse(int row) - => throw new PlatformNotSupportedException(); + public void Collapse(int row) => throw new PlatformNotSupportedException(); - protected override AccessibleObject CreateAccessibilityInstance() - => throw new PlatformNotSupportedException(); + protected override AccessibleObject CreateAccessibilityInstance() => throw new PlatformNotSupportedException(); - protected override void Dispose(bool disposing) - => throw new PlatformNotSupportedException(); + protected override void Dispose(bool disposing) => throw new PlatformNotSupportedException(); - public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) - => throw new PlatformNotSupportedException(); + public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) => throw new PlatformNotSupportedException(); - public void Expand(int row) - => throw new PlatformNotSupportedException(); + public void Expand(int row) => throw new PlatformNotSupportedException(); - protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop, bool isDefault) - => throw new PlatformNotSupportedException(); + protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop, bool isDefault) => throw new PlatformNotSupportedException(); - protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop) - => throw new PlatformNotSupportedException(); + protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop) => throw new PlatformNotSupportedException(); - public void EndInit() - => throw new PlatformNotSupportedException(); + public void EndInit() => throw new PlatformNotSupportedException(); - public Rectangle GetCurrentCellBounds() - => throw new PlatformNotSupportedException(); + public Rectangle GetCurrentCellBounds() => throw new PlatformNotSupportedException(); - public Rectangle GetCellBounds(int row, int col) - => throw new PlatformNotSupportedException(); + public Rectangle GetCellBounds(int row, int col) => throw new PlatformNotSupportedException(); - public Rectangle GetCellBounds(DataGridCell dgc) - => throw new PlatformNotSupportedException(); + public Rectangle GetCellBounds(DataGridCell dgc) => throw new PlatformNotSupportedException(); - public HitTestInfo HitTest(int x, int y) - => throw new PlatformNotSupportedException(); + public HitTestInfo HitTest(int x, int y) => throw new PlatformNotSupportedException(); - public HitTestInfo HitTest(Point position) - => throw new PlatformNotSupportedException(); + public HitTestInfo HitTest(Point position) => throw new PlatformNotSupportedException(); - public bool IsExpanded(int rowNumber) - => throw new PlatformNotSupportedException(); + public bool IsExpanded(int rowNumber) => throw new PlatformNotSupportedException(); - public bool IsSelected(int row) - => throw new PlatformNotSupportedException(); + public bool IsSelected(int row) => throw new PlatformNotSupportedException(); - public void NavigateBack() - => throw new PlatformNotSupportedException(); + public void NavigateBack() => throw new PlatformNotSupportedException(); - public void NavigateTo(int rowNumber, string relationName) - => throw new PlatformNotSupportedException(); + public void NavigateTo(int rowNumber, string relationName) => throw new PlatformNotSupportedException(); - protected override bool ProcessDialogKey(Keys keyData) - => throw new PlatformNotSupportedException(); + protected override bool ProcessDialogKey(Keys keyData) => throw new PlatformNotSupportedException(); - protected bool ProcessGridKey(KeyEventArgs ke) - => throw new PlatformNotSupportedException(); + protected bool ProcessGridKey(KeyEventArgs ke) => throw new PlatformNotSupportedException(); - protected override bool ProcessKeyPreview(ref Message m) - => throw new PlatformNotSupportedException(); + protected override bool ProcessKeyPreview(ref Message m) => throw new PlatformNotSupportedException(); - protected bool ProcessTabKey(Keys keyData) - => throw new PlatformNotSupportedException(); + protected bool ProcessTabKey(Keys keyData) => throw new PlatformNotSupportedException(); - virtual protected void CancelEditing() - => throw new PlatformNotSupportedException(); + virtual protected void CancelEditing() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -802,20 +708,15 @@ virtual protected void CancelEditing() remove => throw new PlatformNotSupportedException(); } - protected void ResetSelection() - => throw new PlatformNotSupportedException(); + protected void ResetSelection() => throw new PlatformNotSupportedException(); - public void Select(int row) - => throw new PlatformNotSupportedException(); + public void Select(int row) => throw new PlatformNotSupportedException(); - public void SubObjectsSiteChange(bool site) - => throw new PlatformNotSupportedException(); + public void SubObjectsSiteChange(bool site) => throw new PlatformNotSupportedException(); - public void UnSelect(int row) - => throw new PlatformNotSupportedException(); + public void UnSelect(int row) => throw new PlatformNotSupportedException(); - protected virtual string GetOutputTextDelimiter() - => throw new PlatformNotSupportedException(); + protected virtual string GetOutputTextDelimiter() => throw new PlatformNotSupportedException(); [Obsolete( Obsoletions.DataGridHitTestInfoMessage, @@ -826,27 +727,21 @@ public sealed class HitTestInfo { [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public int Column - => throw new PlatformNotSupportedException(); + public int Column => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public int Row - => throw new PlatformNotSupportedException(); + public int Row => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public HitTestType Type - => throw new PlatformNotSupportedException(); + public HitTestType Type => throw new PlatformNotSupportedException(); - public override bool Equals(object obj) - => throw new PlatformNotSupportedException(); + public override bool Equals(object obj) => throw new PlatformNotSupportedException(); - public override int GetHashCode() - => throw new PlatformNotSupportedException(); + public override int GetHashCode() => throw new PlatformNotSupportedException(); - public override string ToString() - => throw new PlatformNotSupportedException(); + public override string ToString() => throw new PlatformNotSupportedException(); } [Flags] @@ -866,46 +761,4 @@ public enum HitTestType Caption = 0x00000020, ParentRows = 0x00000040 } - - [Obsolete( - Obsoletions.DataGridAccessibleObjectMessage, - error: false, - DiagnosticId = Obsoletions.DataGridAccessibleObjectDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] - internal class DataGridAccessibleObject : ControlAccessibleObject - { - public DataGridAccessibleObject(DataGrid owner) : base(owner) - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Name - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleRole Role - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetChild(int index) - => throw new PlatformNotSupportedException(); - - public override int GetChildCount() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetFocused() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetSelected() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject HitTest(int x, int y) - => throw new PlatformNotSupportedException(); - - public override AccessibleObject Navigate(AccessibleNavigation navdir) - => throw new PlatformNotSupportedException(); - } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs deleted file mode 100644 index 8614849d23c..00000000000 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridAddNewRow.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.ComponentModel; -using System.Drawing; - -namespace System.Windows.Forms; - -#nullable disable -[Obsolete( - Obsoletions.DataGridAddNewRowMessage, - error: false, - DiagnosticId = Obsoletions.DataGridAddNewRowDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] -internal class DataGridAddNewRow : DataGridRow -{ - public DataGridAddNewRow(DataGrid dGrid, DataGridTableStyle gridTable, int rowNum) - : base(dGrid, gridTable, rowNum) - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public bool DataBound - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - public override void OnEdit() - => throw new PlatformNotSupportedException(); - - public override void OnRowLeave() - => throw new PlatformNotSupportedException(); - - public override int Paint(Graphics g, - Rectangle bounds, - Rectangle trueRowBounds, - int firstVisibleColumn, - int columnCount) - => throw new PlatformNotSupportedException(); - - public override int Paint(Graphics g, - Rectangle bounds, - Rectangle trueRowBounds, - int firstVisibleColumn, - int columnCount, - bool alignToRight) - => throw new PlatformNotSupportedException(); - - protected override void PaintCellContents(Graphics g, - Rectangle cellBounds, - DataGridColumnStyle column, - Brush backBr, - Brush foreBrush, - bool alignToRight) - => throw new PlatformNotSupportedException(); -} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs index fd3a90d76aa..4ff19ad5e06 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridBoolColumn.cs @@ -15,15 +15,11 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridBoolColumn : DataGridColumnStyle { - public DataGridBoolColumn() : base() - => throw new PlatformNotSupportedException(); + public DataGridBoolColumn() => throw new PlatformNotSupportedException(); - public DataGridBoolColumn(PropertyDescriptor prop) : base(prop) - => throw new PlatformNotSupportedException(); + public DataGridBoolColumn(PropertyDescriptor prop) => throw new PlatformNotSupportedException(); - public DataGridBoolColumn(PropertyDescriptor prop, bool isDefault) - : base(prop, isDefault) - => throw new PlatformNotSupportedException(); + public DataGridBoolColumn(PropertyDescriptor prop, bool isDefault) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -65,44 +61,34 @@ public object NullValue set => throw new PlatformNotSupportedException(); } - protected internal override void ConcedeFocus() - => throw new PlatformNotSupportedException(); + protected internal override void ConcedeFocus() => throw new PlatformNotSupportedException(); - protected internal override object GetColumnValueAtRow(CurrencyManager source, int rowNum) - => throw new PlatformNotSupportedException(); + protected internal override object GetColumnValueAtRow(CurrencyManager source, int rowNum) => throw new PlatformNotSupportedException(); - protected internal override void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) - => throw new PlatformNotSupportedException(); + protected internal override void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) => throw new PlatformNotSupportedException(); - protected internal override Size GetPreferredSize(Graphics g, object value) - => throw new PlatformNotSupportedException(); + protected internal override Size GetPreferredSize(Graphics g, object value) => throw new PlatformNotSupportedException(); - protected internal override int GetMinimumHeight() - => throw new PlatformNotSupportedException(); + protected internal override int GetMinimumHeight() => throw new PlatformNotSupportedException(); - protected internal override int GetPreferredHeight(Graphics g, object value) - => throw new PlatformNotSupportedException(); + protected internal override int GetPreferredHeight(Graphics g, object value) => throw new PlatformNotSupportedException(); - protected internal override void Abort(int rowNum) - => throw new PlatformNotSupportedException(); + protected internal override void Abort(int rowNum) => throw new PlatformNotSupportedException(); - protected internal override bool Commit(CurrencyManager dataSource, int rowNum) - => throw new PlatformNotSupportedException(); + protected internal override bool Commit(CurrencyManager dataSource, int rowNum) => throw new PlatformNotSupportedException(); protected internal override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText, - bool cellIsVisible) - => throw new PlatformNotSupportedException(); + bool cellIsVisible) => throw new PlatformNotSupportedException(); protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, - bool alignToRight) - => throw new PlatformNotSupportedException(); + bool alignToRight) => throw new PlatformNotSupportedException(); protected internal override void Paint(Graphics g, Rectangle bounds, @@ -110,8 +96,7 @@ protected internal override bool Commit(CurrencyManager dataSource, int rowNum) int rowNum, Brush backBrush, Brush foreBrush, - bool alignToRight) - => throw new PlatformNotSupportedException(); + bool alignToRight) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -129,13 +114,11 @@ public bool AllowNull remove => throw new PlatformNotSupportedException(); } - protected internal override void EnterNullValue() - => throw new PlatformNotSupportedException(); + protected internal override void EnterNullValue() => throw new PlatformNotSupportedException(); protected internal override void Paint(Graphics g1, Graphics g, Rectangle bounds, CurrencyManager source, - int rowNum) - => throw new PlatformNotSupportedException(); + int rowNum) => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs deleted file mode 100644 index 81d8a9d80c1..00000000000 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCaption.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System.Windows.Forms; - -#nullable disable -[Obsolete( - Obsoletions.DataGridCaptionMessage, - error: false, - DiagnosticId = Obsoletions.DataGridCaptionDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] -internal class DataGridCaption -{ - protected virtual void AddEventHandler(object key, Delegate handler) - => throw new PlatformNotSupportedException(); - - protected static void OnBackwardClicked(EventArgs e) - => throw new PlatformNotSupportedException(); - - protected static void OnCaptionClicked(EventArgs e) - => throw new PlatformNotSupportedException(); - - protected static void OnDownClicked(EventArgs e) - => throw new PlatformNotSupportedException(); - - protected virtual Delegate GetEventHandler(object key) - => throw new PlatformNotSupportedException(); - - protected virtual void RaiseEvent(object key, EventArgs e) - => throw new PlatformNotSupportedException(); - - protected virtual void RemoveEventHandler(object key, Delegate handler) - => throw new PlatformNotSupportedException(); - - protected virtual void RemoveEventHandlers() - => throw new PlatformNotSupportedException(); -} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs index 34b726acc9e..2dbef0a783b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridCell.cs @@ -31,24 +31,17 @@ public int RowNumber set => throw new PlatformNotSupportedException(); } - public DataGridCell(int r, int c) - => throw new PlatformNotSupportedException(); + public DataGridCell(int r, int c) => throw new PlatformNotSupportedException(); - public override readonly bool Equals(object obj) - => throw new PlatformNotSupportedException(); + public override readonly bool Equals(object obj) => throw new PlatformNotSupportedException(); - public override readonly int GetHashCode() - => throw new PlatformNotSupportedException(); + public override readonly int GetHashCode() => throw new PlatformNotSupportedException(); - public override readonly string ToString() - => throw new PlatformNotSupportedException(); + public override readonly string ToString() => throw new PlatformNotSupportedException(); - public readonly bool Equals(DataGridCell other) - => throw new PlatformNotSupportedException(); + public readonly bool Equals(DataGridCell other) => throw new PlatformNotSupportedException(); - public static bool operator ==(DataGridCell left, DataGridCell right) - => throw new PlatformNotSupportedException(); + public static bool operator ==(DataGridCell left, DataGridCell right) => throw new PlatformNotSupportedException(); - public static bool operator !=(DataGridCell left, DataGridCell right) - => throw new PlatformNotSupportedException(); + public static bool operator !=(DataGridCell left, DataGridCell right) => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs index fef9fdf2040..7ab7700452b 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridColumn.cs @@ -16,14 +16,9 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public abstract class DataGridColumnStyle : Component, IDataGridColumnStyleEditingNotificationService { - public DataGridColumnStyle() - => throw new PlatformNotSupportedException(); + public DataGridColumnStyle() => throw new PlatformNotSupportedException(); - public DataGridColumnStyle(PropertyDescriptor prop) : this() - => throw new PlatformNotSupportedException(); - - internal DataGridColumnStyle(PropertyDescriptor prop, bool isDefault) : this(prop) - => throw new PlatformNotSupportedException(); + public DataGridColumnStyle(PropertyDescriptor prop) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -41,14 +36,11 @@ public virtual HorizontalAlignment Alignment remove => throw new PlatformNotSupportedException(); } - protected internal virtual void UpdateUI(CurrencyManager source, int rowNum, string displayText) - { - } + protected internal virtual void UpdateUI(CurrencyManager source, int rowNum, string displayText) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public AccessibleObject HeaderAccessibleObject - => throw new PlatformNotSupportedException(); + public AccessibleObject HeaderAccessibleObject => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -66,23 +58,17 @@ public virtual PropertyDescriptor PropertyDescriptor remove => throw new PlatformNotSupportedException(); } - protected virtual AccessibleObject CreateHeaderAccessibleObject() - => throw new PlatformNotSupportedException(); + protected virtual AccessibleObject CreateHeaderAccessibleObject() => throw new PlatformNotSupportedException(); - protected virtual void SetDataGrid(DataGrid value) - => throw new PlatformNotSupportedException(); + protected virtual void SetDataGrid(DataGrid value) => throw new PlatformNotSupportedException(); - protected virtual void SetDataGridInColumn(DataGrid value) - { - } + protected virtual void SetDataGridInColumn(DataGrid value) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual DataGridTableStyle DataGridTableStyle - => throw new PlatformNotSupportedException(); + public virtual DataGridTableStyle DataGridTableStyle => throw new PlatformNotSupportedException(); - protected int FontHeight - => throw new PlatformNotSupportedException(); + protected int FontHeight => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -124,8 +110,7 @@ public string MappingName remove => throw new PlatformNotSupportedException(); } - public void ResetHeaderText() - => throw new PlatformNotSupportedException(); + public void ResetHeaderText() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -175,13 +160,9 @@ public virtual int Width remove => throw new PlatformNotSupportedException(); } - protected void BeginUpdate() - { - } + protected void BeginUpdate() => throw new PlatformNotSupportedException(); - protected void EndUpdate() - { - } + protected void EndUpdate() => throw new PlatformNotSupportedException(); protected internal abstract Size GetPreferredSize(Graphics g, object value); @@ -189,16 +170,11 @@ protected void EndUpdate() protected internal abstract int GetPreferredHeight(Graphics g, object value); - protected internal virtual object GetColumnValueAtRow(CurrencyManager source, int rowNum) - => throw new PlatformNotSupportedException(); + protected internal virtual object GetColumnValueAtRow(CurrencyManager source, int rowNum) => throw new PlatformNotSupportedException(); - protected virtual void Invalidate() - { - } + protected virtual void Invalidate() => throw new PlatformNotSupportedException(); - protected void CheckValidDataSource(CurrencyManager value) - { - } + protected void CheckValidDataSource(CurrencyManager value) => throw new PlatformNotSupportedException(); protected internal abstract void Abort(int rowNum); @@ -207,15 +183,13 @@ protected void CheckValidDataSource(CurrencyManager value) protected internal virtual void Edit(CurrencyManager source, int rowNum, Rectangle bounds, - bool readOnly) - => throw new PlatformNotSupportedException(); + bool readOnly) => throw new PlatformNotSupportedException(); protected internal virtual void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, - string displayText) - => throw new PlatformNotSupportedException(); + string displayText) => throw new PlatformNotSupportedException(); protected internal abstract void Edit(CurrencyManager source, int rowNum, @@ -224,13 +198,9 @@ protected void CheckValidDataSource(CurrencyManager value) string displayText, bool cellIsVisible); - protected internal virtual void EnterNullValue() - { - } + protected internal virtual void EnterNullValue() => throw new PlatformNotSupportedException(); - protected internal virtual void ConcedeFocus() - { - } + protected internal virtual void ConcedeFocus() => throw new PlatformNotSupportedException(); protected internal abstract void Paint(Graphics g1, Graphics g, @@ -250,67 +220,18 @@ protected internal virtual void ConcedeFocus() int rowNum, Brush backBrush, Brush foreBrush, - bool alignToRight) - => throw new PlatformNotSupportedException(); + bool alignToRight) => throw new PlatformNotSupportedException(); - protected internal virtual void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) - => throw new PlatformNotSupportedException(); + protected internal virtual void SetColumnValueAtRow(CurrencyManager source, int rowNum, object value) => throw new PlatformNotSupportedException(); - void IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control editingControl) - { - } + void IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control editingControl) => throw new PlatformNotSupportedException(); - protected internal virtual void ReleaseHostedControl() - { - } + protected internal virtual void ReleaseHostedControl() => throw new PlatformNotSupportedException(); protected class CompModSwitches { [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public static TraceSwitch DGEditColumnEditing - => throw new PlatformNotSupportedException(); - } - - [Obsolete( - Obsoletions.DataGridColumnHeaderAccessibleObjectMessage, - error: false, - DiagnosticId = Obsoletions.DataGridColumnHeaderAccessibleObjectDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] - internal class DataGridColumnHeaderAccessibleObject : AccessibleObject - { - public DataGridColumnHeaderAccessibleObject(DataGridColumnStyle owner) : this() - => throw new PlatformNotSupportedException(); - - public DataGridColumnHeaderAccessibleObject() : base() - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override Rectangle Bounds - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Name - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - protected DataGridColumnStyle Owner - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleObject Parent - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleRole Role - => throw new PlatformNotSupportedException(); - - public override AccessibleObject Navigate(AccessibleNavigation navdir) - => throw new PlatformNotSupportedException(); + public static TraceSwitch DGEditColumnEditing => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs deleted file mode 100644 index dee65fc5276..00000000000 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridParentRows.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.ComponentModel; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace System.Windows.Forms; - -#nullable disable -[Obsolete( - Obsoletions.DataGridParentRowsMessage, - error: false, - DiagnosticId = Obsoletions.DataGridParentRowsDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] -internal class DataGridParentRows -{ - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public AccessibleObject AccessibleObject - => throw new PlatformNotSupportedException(); - - [ComVisible(true)] - [Obsolete( - Obsoletions.DataGridParentRowsAccessibleObjectMessage, - error: false, - DiagnosticId = Obsoletions.DataGridParentRowsAccessibleObjectDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] - protected internal class DataGridParentRowsAccessibleObject : AccessibleObject - { - public DataGridParentRowsAccessibleObject(DataGridParentRows owner) : base() - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override Rectangle Bounds - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string DefaultAction - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Name - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleObject Parent - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleRole Role - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleStates State - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Value - => throw new PlatformNotSupportedException(); - - public override void DoDefaultAction() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetChild(int index) - => throw new PlatformNotSupportedException(); - - public override int GetChildCount() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetFocused() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject Navigate(AccessibleNavigation navdir) - => throw new PlatformNotSupportedException(); - - public override void Select(AccessibleSelection flags) - => throw new PlatformNotSupportedException(); - } -} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs index fa9e26185b0..4e1ff40c51d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridPreferredColumnWidthTypeConverter.cs @@ -16,12 +16,10 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridPreferredColumnWidthTypeConverter : TypeConverter { - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) - => throw new PlatformNotSupportedException(); + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) => throw new PlatformNotSupportedException(); - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) - => throw new PlatformNotSupportedException(); + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) => + throw new PlatformNotSupportedException(); - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) - => throw new PlatformNotSupportedException(); + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs deleted file mode 100644 index c44181f3632..00000000000 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRelationshipRow.cs +++ /dev/null @@ -1,182 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections; -using System.ComponentModel; -using System.Drawing; - -namespace System.Windows.Forms; - -#nullable disable -[Obsolete( - Obsoletions.DataGridRelationshipRowMessage, - error: false, - DiagnosticId = Obsoletions.DataGridRelationshipRowDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] -internal class DataGridRelationshipRow : DataGridRow -{ - public DataGridRelationshipRow(DataGrid dataGrid, DataGridTableStyle dgTable, int rowNumber) - : base(dataGrid, dgTable, rowNumber) - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual bool Expanded - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override int Height - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - public override Rectangle GetCellBounds(int col) - => throw new PlatformNotSupportedException(); - - public override Rectangle GetNonScrollableArea() - => throw new PlatformNotSupportedException(); - - public override bool OnMouseDown(int x, int y, Rectangle rowHeaders, bool alignToRight) - => throw new PlatformNotSupportedException(); - - public override bool OnMouseMove(int x, int y, Rectangle rowHeaders, bool alignToRight) - => throw new PlatformNotSupportedException(); - - public override void OnMouseLeft(Rectangle rowHeaders, bool alignToRight) - => throw new PlatformNotSupportedException(); - - public override void OnMouseLeft() - => throw new PlatformNotSupportedException(); - - public override bool OnKeyPress(Keys keyData) - => throw new PlatformNotSupportedException(); - - public override int Paint(Graphics g, - Rectangle bounds, - Rectangle trueRowBounds, - int firstVisibleColumn, - int numVisibleColumns) - => throw new PlatformNotSupportedException(); - - public override int Paint(Graphics g, - Rectangle bounds, - Rectangle trueRowBounds, - int firstVisibleColumn, - int numVisibleColumns, - bool alignToRight) - => throw new PlatformNotSupportedException(); - - protected override void PaintCellContents(Graphics g, - Rectangle cellBounds, - DataGridColumnStyle column, - Brush backBr, - Brush foreBrush, - bool alignToRight) - { - } - - public override void PaintHeader(Graphics g, Rectangle bounds, bool alignToRight, bool isDirty) - => throw new PlatformNotSupportedException(); - - public void PaintHeaderInside(Graphics g, Rectangle bounds, Brush backBr, bool alignToRight, bool isDirty) - => throw new PlatformNotSupportedException(); - - [Obsolete( - Obsoletions.DataGridRelationshipRowAccessibleObjectMessage, - error: false, - DiagnosticId = Obsoletions.DataGridRelationshipRowAccessibleObjectDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] - internal class DataGridRelationshipRowAccessibleObject : DataGridRowAccessibleObject - { - public DataGridRelationshipRowAccessibleObject(DataGridRow owner) : base(owner) - => throw new PlatformNotSupportedException(); - - protected override void AddChildAccessibleObjects(IList children) - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string DefaultAction - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleStates State - => throw new PlatformNotSupportedException(); - - public override void DoDefaultAction() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetFocused() - => throw new PlatformNotSupportedException(); - } - - [Obsolete( - Obsoletions.DataGridRelationshipAccessibleObjectMessage, - error: false, - DiagnosticId = Obsoletions.DataGridRelationshipAccessibleObjectDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] - internal class DataGridRelationshipAccessibleObject : AccessibleObject - { - public DataGridRelationshipAccessibleObject(DataGridRelationshipRow owner, int relationship) : base() - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override Rectangle Bounds - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Name - => throw new PlatformNotSupportedException(); - - protected DataGridRelationshipRow Owner - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleObject Parent - => throw new PlatformNotSupportedException(); - - protected DataGrid DataGrid - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleRole Role - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleStates State - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Value - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string DefaultAction - => throw new PlatformNotSupportedException(); - - public override void DoDefaultAction() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject Navigate(AccessibleNavigation navdir) - => throw new PlatformNotSupportedException(); - - public override void Select(AccessibleSelection flags) - => throw new PlatformNotSupportedException(); - } -} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs deleted file mode 100644 index bf819cddb20..00000000000 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridRow.cs +++ /dev/null @@ -1,340 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections; -using System.ComponentModel; -using System.Drawing; -using System.Runtime.InteropServices; -using System.Runtime.Versioning; - -namespace System.Windows.Forms; - -#nullable disable -[Obsolete( - Obsoletions.DataGridRowMessage, - error: false, - DiagnosticId = Obsoletions.DataGridRowDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] -internal abstract class DataGridRow : MarshalByRefObject -{ - public DataGridRow(DataGrid dataGrid, DataGridTableStyle dgTable, int rowNumber) - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public AccessibleObject AccessibleObject - => throw new PlatformNotSupportedException(); - - protected virtual AccessibleObject CreateAccessibleObject() - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public DataGrid DataGrid - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual int Height - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public int RowNumber - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual bool Selected - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - protected Bitmap GetBitmap(string bitmapName) - => throw new PlatformNotSupportedException(); - - public virtual Rectangle GetCellBounds(int col) - => throw new PlatformNotSupportedException(); - - public virtual Rectangle GetNonScrollableArea() - => throw new PlatformNotSupportedException(); - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - protected Bitmap GetStarBitmap() - => throw new PlatformNotSupportedException(); - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - protected Bitmap GetPencilBitmap() - => throw new PlatformNotSupportedException(); - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - protected Bitmap GetErrorBitmap() - => throw new PlatformNotSupportedException(); - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - protected Bitmap GetLeftArrowBitmap() - => throw new PlatformNotSupportedException(); - - [ResourceExposure(ResourceScope.Machine)] - [ResourceConsumption(ResourceScope.Machine)] - protected Bitmap GetRightArrowBitmap() - => throw new PlatformNotSupportedException(); - - public virtual void InvalidateRow() - => throw new PlatformNotSupportedException(); - - public virtual void InvalidateRowRect(Rectangle r) - => throw new PlatformNotSupportedException(); - - public virtual void OnEdit() - => throw new PlatformNotSupportedException(); - - public virtual bool OnKeyPress(Keys keyData) - => throw new PlatformNotSupportedException(); - - public virtual bool OnMouseDown(int x, int y, Rectangle rowHeaders) - => throw new PlatformNotSupportedException(); - - public virtual bool OnMouseDown(int x, int y, Rectangle rowHeaders, bool alignToRight) - => throw new PlatformNotSupportedException(); - - public virtual bool OnMouseMove(int x, int y, Rectangle rowHeaders) - => throw new PlatformNotSupportedException(); - - public virtual bool OnMouseMove(int x, int y, Rectangle rowHeaders, bool alignToRight) - => throw new PlatformNotSupportedException(); - - public virtual void OnMouseLeft(Rectangle rowHeaders, bool alignToRight) - => throw new PlatformNotSupportedException(); - - public virtual void OnMouseLeft() - => throw new PlatformNotSupportedException(); - - public virtual void OnRowEnter() - => throw new PlatformNotSupportedException(); - - public virtual void OnRowLeave() - => throw new PlatformNotSupportedException(); - - public abstract int Paint(Graphics g, - Rectangle dataBounds, - Rectangle rowBounds, - int firstVisibleColumn, - int numVisibleColumns); - - public abstract int Paint(Graphics g, - Rectangle dataBounds, - Rectangle rowBounds, - int firstVisibleColumn, - int numVisibleColumns, - bool alignToRight); - - protected virtual void PaintBottomBorder(Graphics g, Rectangle bounds, int dataWidth) - => throw new PlatformNotSupportedException(); - - protected virtual void PaintBottomBorder(Graphics g, Rectangle bounds, int dataWidth, int borderWidth, bool alignToRight) - { - } - - public virtual int PaintData(Graphics g, - Rectangle bounds, - int firstVisibleColumn, - int columnCount) - => throw new PlatformNotSupportedException(); - - public virtual int PaintData(Graphics g, - Rectangle bounds, - int firstVisibleColumn, - int columnCount, - bool alignToRight) - => throw new PlatformNotSupportedException(); - - protected virtual void PaintCellContents(Graphics g, - Rectangle cellBounds, - DataGridColumnStyle column, - Brush backBr, - Brush foreBrush) - => throw new PlatformNotSupportedException(); - - protected virtual void PaintCellContents(Graphics g, - Rectangle cellBounds, - DataGridColumnStyle column, - Brush backBr, - Brush foreBrush, - bool alignToRight) - => throw new PlatformNotSupportedException(); - - protected Rectangle PaintIcon(Graphics g, - Rectangle visualBounds, - bool paintIcon, - bool alignToRight, - Bitmap bmp) - => throw new PlatformNotSupportedException(); - - protected Rectangle PaintIcon(Graphics g, - Rectangle visualBounds, - bool paintIcon, - bool alignToRight, - Bitmap bmp, - Brush backBrush) - => throw new PlatformNotSupportedException(); - - public virtual void PaintHeader(Graphics g, Rectangle visualBounds) - => throw new PlatformNotSupportedException(); - - public virtual void PaintHeader(Graphics g, Rectangle visualBounds, bool alignToRight) - => throw new PlatformNotSupportedException(); - - public virtual void PaintHeader(Graphics g, Rectangle visualBounds, bool alignToRight, bool rowIsDirty) - => throw new PlatformNotSupportedException(); - - protected Brush GetBackBrush() - => throw new PlatformNotSupportedException(); - - protected Brush BackBrushForDataPaint(ref DataGridCell current, DataGridColumnStyle gridColumn, int column) - => throw new PlatformNotSupportedException(); - - protected Brush ForeBrushForDataPaint(ref DataGridCell current, DataGridColumnStyle gridColumn, int column) - => throw new PlatformNotSupportedException(); - - [ComVisible(true)] - [Obsolete( - Obsoletions.DataGridRowAccessibleObjectMessage, - error: false, - DiagnosticId = Obsoletions.DataGridRowAccessibleObjectDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] - internal class DataGridRowAccessibleObject : AccessibleObject - { - public DataGridRowAccessibleObject(DataGridRow owner) : base() - => throw new PlatformNotSupportedException(); - - protected virtual void AddChildAccessibleObjects(IList children) - => throw new PlatformNotSupportedException(); - - protected virtual AccessibleObject CreateCellAccessibleObject(int column) - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override Rectangle Bounds - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Name - => throw new PlatformNotSupportedException(); - - protected DataGridRow Owner - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleObject Parent - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleRole Role - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleStates State - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Value - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetChild(int index) - => throw new PlatformNotSupportedException(); - - public override int GetChildCount() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetFocused() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject Navigate(AccessibleNavigation navdir) - => throw new PlatformNotSupportedException(); - - public override void Select(AccessibleSelection flags) - => throw new PlatformNotSupportedException(); - } - - [ComVisible(true)] - [Obsolete( - Obsoletions.DataGridCellAccessibleObjectMessage, - error: false, - DiagnosticId = Obsoletions.DataGridCellAccessibleObjectDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] - internal class DataGridCellAccessibleObject : AccessibleObject - { - public DataGridCellAccessibleObject(DataGridRow owner, int column) : base() - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override Rectangle Bounds - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Name - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleObject Parent - => throw new PlatformNotSupportedException(); - - protected DataGrid DataGrid - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string DefaultAction - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleRole Role - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleStates State - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Value - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - public override void DoDefaultAction() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject GetFocused() - => throw new PlatformNotSupportedException(); - - public override AccessibleObject Navigate(AccessibleNavigation navdir) - => throw new PlatformNotSupportedException(); - - public override void Select(AccessibleSelection flags) - => throw new PlatformNotSupportedException(); - } -} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs deleted file mode 100644 index 2fc86ba0467..00000000000 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridState.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.ComponentModel; -using System.Drawing; -using System.Runtime.InteropServices; - -namespace System.Windows.Forms; - -#nullable disable -[Obsolete( - Obsoletions.DataGridStateMessage, - error: false, - DiagnosticId = Obsoletions.DataGridStateDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] -internal sealed class DataGridState : ICloneable -{ - public object DataSource; - public string DataMember; - public CurrencyManager ListManager; - public DataGridRow[] DataGridRows = []; - public DataGrid DataGrid; - public int DataGridRowsLength; - public GridColumnStylesCollection GridColumnStyles; - public int FirstVisibleRow; - public int FirstVisibleCol; - public int CurrentRow; - public int CurrentCol; - public DataGridRow LinkingRow; - - public DataGridState() - => throw new PlatformNotSupportedException(); - - public DataGridState(DataGrid dataGrid) - => throw new PlatformNotSupportedException(); - - public object Clone() - => throw new PlatformNotSupportedException(); - - public void PushState(DataGrid dataGrid) - => throw new PlatformNotSupportedException(); - - public void RemoveChangeNotification() - => throw new PlatformNotSupportedException(); - - public void PullState(DataGrid dataGrid, bool createColumn) - => throw new PlatformNotSupportedException(); - - [ComVisible(true)] - [Obsolete( - Obsoletions.DataGridStateParentRowAccessibleObjectMessage, - error: false, - DiagnosticId = Obsoletions.DataGridStateParentRowAccessibleObjectDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] - internal class DataGridStateParentRowAccessibleObject : AccessibleObject - { - public DataGridStateParentRowAccessibleObject(DataGridState owner) : base() - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override Rectangle Bounds - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Name - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleObject Parent - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleRole Role - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override string Value - => throw new PlatformNotSupportedException(); - - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public override AccessibleObject Navigate(AccessibleNavigation navdir) - => throw new PlatformNotSupportedException(); - } -} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs index 0f54920562a..fa5c8f95521 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTable.cs @@ -49,17 +49,13 @@ public Color AlternatingBackColor [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public void ResetAlternatingBackColor() - => throw new PlatformNotSupportedException(); + public void ResetAlternatingBackColor() => throw new PlatformNotSupportedException(); - protected virtual bool ShouldSerializeAlternatingBackColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeAlternatingBackColor() => throw new PlatformNotSupportedException(); - protected bool ShouldSerializeBackColor() - => throw new PlatformNotSupportedException(); + protected bool ShouldSerializeBackColor() => throw new PlatformNotSupportedException(); - protected bool ShouldSerializeForeColor() - => throw new PlatformNotSupportedException(); + protected bool ShouldSerializeForeColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -77,8 +73,7 @@ public Color BackColor remove => throw new PlatformNotSupportedException(); } - public void ResetBackColor() - => throw new PlatformNotSupportedException(); + public void ResetBackColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -96,8 +91,7 @@ public Color ForeColor remove => throw new PlatformNotSupportedException(); } - public void ResetForeColor() - => throw new PlatformNotSupportedException(); + public void ResetForeColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -115,11 +109,9 @@ public Color GridLineColor remove => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeGridLineColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeGridLineColor() => throw new PlatformNotSupportedException(); - public void ResetGridLineColor() - => throw new PlatformNotSupportedException(); + public void ResetGridLineColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -153,11 +145,9 @@ public Color HeaderBackColor remove => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeHeaderBackColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeHeaderBackColor() => throw new PlatformNotSupportedException(); - public void ResetHeaderBackColor() - => throw new PlatformNotSupportedException(); + public void ResetHeaderBackColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -175,8 +165,7 @@ public Font HeaderFont remove => throw new PlatformNotSupportedException(); } - public void ResetHeaderFont() - => throw new PlatformNotSupportedException(); + public void ResetHeaderFont() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -194,11 +183,9 @@ public Color HeaderForeColor remove => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeHeaderForeColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeHeaderForeColor() => throw new PlatformNotSupportedException(); - public void ResetHeaderForeColor() - => throw new PlatformNotSupportedException(); + public void ResetHeaderForeColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -216,11 +203,9 @@ public Color LinkColor remove => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeLinkColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeLinkColor() => throw new PlatformNotSupportedException(); - public void ResetLinkColor() - => throw new PlatformNotSupportedException(); + public void ResetLinkColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -238,11 +223,9 @@ public Color LinkHoverColor remove => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeLinkHoverColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeLinkHoverColor() => throw new PlatformNotSupportedException(); - public void ResetLinkHoverColor() - => throw new PlatformNotSupportedException(); + public void ResetLinkHoverColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -276,8 +259,7 @@ public int PreferredRowHeight remove => throw new PlatformNotSupportedException(); } - protected bool ShouldSerializePreferredRowHeight() - => throw new PlatformNotSupportedException(); + protected bool ShouldSerializePreferredRowHeight() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -343,11 +325,9 @@ public Color SelectionBackColor remove => throw new PlatformNotSupportedException(); } - protected bool ShouldSerializeSelectionBackColor() - => throw new PlatformNotSupportedException(); + protected bool ShouldSerializeSelectionBackColor() => throw new PlatformNotSupportedException(); - public void ResetSelectionBackColor() - => throw new PlatformNotSupportedException(); + public void ResetSelectionBackColor() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -365,22 +345,17 @@ public Color SelectionForeColor remove => throw new PlatformNotSupportedException(); } - protected virtual bool ShouldSerializeSelectionForeColor() - => throw new PlatformNotSupportedException(); + protected virtual bool ShouldSerializeSelectionForeColor() => throw new PlatformNotSupportedException(); - public void ResetSelectionForeColor() - => throw new PlatformNotSupportedException(); + public void ResetSelectionForeColor() => throw new PlatformNotSupportedException(); public static readonly DataGridTableStyle s_defaultTableStyle = new DataGridTableStyle(true); - public DataGridTableStyle(bool isDefaultTableStyle) - => throw new PlatformNotSupportedException(); + public DataGridTableStyle(bool isDefaultTableStyle) => throw new PlatformNotSupportedException(); - public DataGridTableStyle() : this(false) - => throw new PlatformNotSupportedException(); + public DataGridTableStyle() : this(false) => throw new PlatformNotSupportedException(); - public DataGridTableStyle(CurrencyManager listManager) : this() - => throw new PlatformNotSupportedException(); + public DataGridTableStyle(CurrencyManager listManager) : this() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -400,8 +375,7 @@ public string MappingName [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual GridColumnStylesCollection GridColumnStyles - => throw new PlatformNotSupportedException(); + public virtual GridColumnStylesCollection GridColumnStyles => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -427,72 +401,49 @@ public virtual bool ReadOnly remove => throw new PlatformNotSupportedException(); } - public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) - => throw new PlatformNotSupportedException(); + public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) => throw new PlatformNotSupportedException(); - public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) - => throw new PlatformNotSupportedException(); + public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) => throw new PlatformNotSupportedException(); - protected virtual void OnReadOnlyChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnReadOnlyChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnMappingNameChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnMappingNameChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnAlternatingBackColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnAlternatingBackColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnForeColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnForeColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnBackColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnBackColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnAllowSortingChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnAllowSortingChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnGridLineColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnGridLineColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnGridLineStyleChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnGridLineStyleChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnHeaderBackColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnHeaderBackColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnHeaderFontChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnHeaderFontChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnHeaderForeColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnHeaderForeColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnLinkColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnLinkColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnLinkHoverColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnLinkHoverColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnPreferredRowHeightChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnPreferredRowHeightChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnPreferredColumnWidthChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnPreferredColumnWidthChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnColumnHeadersVisibleChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnColumnHeadersVisibleChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnRowHeadersVisibleChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnRowHeadersVisibleChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnRowHeaderWidthChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnRowHeaderWidthChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnSelectionForeColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnSelectionForeColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnSelectionBackColorChanged(EventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnSelectionBackColorChanged(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void Dispose(bool disposing) - => throw new PlatformNotSupportedException(); + protected override void Dispose(bool disposing) => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs index 2114b77c4ff..c9d93fb7266 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTableCollection.cs @@ -16,32 +16,23 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class GridTableStylesCollection : BaseCollection, IList { - int IList.Add(object value) - => throw new PlatformNotSupportedException(); + int IList.Add(object value) => throw new PlatformNotSupportedException(); - void IList.Clear() - => throw new PlatformNotSupportedException(); + void IList.Clear() => throw new PlatformNotSupportedException(); - bool IList.Contains(object value) - => throw new PlatformNotSupportedException(); + bool IList.Contains(object value) => throw new PlatformNotSupportedException(); - int IList.IndexOf(object value) - => throw new PlatformNotSupportedException(); + int IList.IndexOf(object value) => throw new PlatformNotSupportedException(); - void IList.Insert(int index, object value) - => throw new PlatformNotSupportedException(); + void IList.Insert(int index, object value) => throw new PlatformNotSupportedException(); - void IList.Remove(object value) - => throw new PlatformNotSupportedException(); + void IList.Remove(object value) => throw new PlatformNotSupportedException(); - void IList.RemoveAt(int index) - => throw new PlatformNotSupportedException(); + void IList.RemoveAt(int index) => throw new PlatformNotSupportedException(); - bool IList.IsFixedSize - => throw new PlatformNotSupportedException(); + bool IList.IsFixedSize => throw new PlatformNotSupportedException(); - bool IList.IsReadOnly - => throw new PlatformNotSupportedException(); + bool IList.IsReadOnly => throw new PlatformNotSupportedException(); object IList.this[int index] { @@ -49,39 +40,29 @@ bool IList.IsReadOnly set => throw new PlatformNotSupportedException(); } - void ICollection.CopyTo(Array array, int index) - { - } + void ICollection.CopyTo(Array array, int index) => throw new PlatformNotSupportedException(); - int ICollection.Count - => throw new PlatformNotSupportedException(); + int ICollection.Count => throw new PlatformNotSupportedException(); - bool ICollection.IsSynchronized - => throw new PlatformNotSupportedException(); + bool ICollection.IsSynchronized => throw new PlatformNotSupportedException(); - object ICollection.SyncRoot - => throw new PlatformNotSupportedException(); + object ICollection.SyncRoot => throw new PlatformNotSupportedException(); IEnumerator IEnumerable.GetEnumerator() => throw new PlatformNotSupportedException(); - protected override ArrayList List - => throw new PlatformNotSupportedException(); + protected override ArrayList List => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public DataGridTableStyle this[int index] - => throw new PlatformNotSupportedException(); + public DataGridTableStyle this[int index] => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public DataGridTableStyle this[string tableName] - => throw new PlatformNotSupportedException(); + public DataGridTableStyle this[string tableName] => throw new PlatformNotSupportedException(); - public virtual int Add(DataGridTableStyle table) - => throw new PlatformNotSupportedException(); + public virtual int Add(DataGridTableStyle table) => throw new PlatformNotSupportedException(); - public virtual void AddRange(DataGridTableStyle[] tables) - => throw new PlatformNotSupportedException(); + public virtual void AddRange(DataGridTableStyle[] tables) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -91,21 +72,15 @@ public virtual void AddRange(DataGridTableStyle[] tables) remove => throw new PlatformNotSupportedException(); } - public void Clear() - => throw new PlatformNotSupportedException(); + public void Clear() => throw new PlatformNotSupportedException(); - public bool Contains(DataGridTableStyle table) - => throw new PlatformNotSupportedException(); + public bool Contains(DataGridTableStyle table) => throw new PlatformNotSupportedException(); - public bool Contains(string name) - => throw new PlatformNotSupportedException(); + public bool Contains(string name) => throw new PlatformNotSupportedException(); - protected void OnCollectionChanged(CollectionChangeEventArgs e) - => throw new PlatformNotSupportedException(); + protected void OnCollectionChanged(CollectionChangeEventArgs e) => throw new PlatformNotSupportedException(); - public void Remove(DataGridTableStyle table) - => throw new PlatformNotSupportedException(); + public void Remove(DataGridTableStyle table) => throw new PlatformNotSupportedException(); - public void RemoveAt(int index) - => throw new PlatformNotSupportedException(); + public void RemoveAt(int index) => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs index 766f5845356..0bed141b255 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs @@ -12,13 +12,10 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public sealed class GridTablesFactory { - private GridTablesFactory() - { - } + private GridTablesFactory() => throw new PlatformNotSupportedException(); public static DataGridTableStyle[] CreateGridTables(DataGridTableStyle gridTable, object dataSource, string dataMember, - BindingContext bindingManager) - => throw new PlatformNotSupportedException(); + BindingContext bindingManager) => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs index e0ab2f8e29a..df9396b2b6c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBox.cs @@ -14,24 +14,17 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridTextBox : TextBox { - public DataGridTextBox() : base() - => throw new PlatformNotSupportedException(); + public DataGridTextBox() : base() => throw new PlatformNotSupportedException(); - public void SetDataGrid(DataGrid parentGrid) - => throw new PlatformNotSupportedException(); + public void SetDataGrid(DataGrid parentGrid) => throw new PlatformNotSupportedException(); - protected override void WndProc(ref Message m) - => throw new PlatformNotSupportedException(); + protected override void WndProc(ref Message m) => throw new PlatformNotSupportedException(); - protected override void OnMouseWheel(MouseEventArgs e) - { - } + protected override void OnMouseWheel(MouseEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnKeyPress(KeyPressEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnKeyPress(KeyPressEventArgs e) => throw new PlatformNotSupportedException(); - protected internal override bool ProcessKeyMessage(ref Message m) - => throw new PlatformNotSupportedException(); + protected internal override bool ProcessKeyMessage(ref Message m) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs index b8608ca7887..4f4b19a0df3 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTextBoxColumn.cs @@ -16,38 +16,25 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class DataGridTextBoxColumn : DataGridColumnStyle { - public DataGridTextBoxColumn() : this(null, null) - => throw new PlatformNotSupportedException(); + public DataGridTextBoxColumn() => throw new PlatformNotSupportedException(); - public DataGridTextBoxColumn(PropertyDescriptor prop) - : this(prop, null, false) - => throw new PlatformNotSupportedException(); + public DataGridTextBoxColumn(PropertyDescriptor prop) => throw new PlatformNotSupportedException(); - public DataGridTextBoxColumn(PropertyDescriptor prop, string format) - : this(prop, format, false) - => throw new PlatformNotSupportedException(); + public DataGridTextBoxColumn(PropertyDescriptor prop, string format) => throw new PlatformNotSupportedException(); - public DataGridTextBoxColumn(PropertyDescriptor prop, string format, bool isDefault) - : base(prop, isDefault) - => throw new PlatformNotSupportedException(); + public DataGridTextBoxColumn(PropertyDescriptor prop, string format, bool isDefault) => throw new PlatformNotSupportedException(); - public DataGridTextBoxColumn(PropertyDescriptor prop, bool isDefault) - : this(prop, null, isDefault) - => throw new PlatformNotSupportedException(); + public DataGridTextBoxColumn(PropertyDescriptor prop, bool isDefault) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual TextBox TextBox - => throw new PlatformNotSupportedException(); + public virtual TextBox TextBox => throw new PlatformNotSupportedException(); - protected override void SetDataGridInColumn(DataGrid value) - { - } + protected override void SetDataGridInColumn(DataGrid value) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public override PropertyDescriptor PropertyDescriptor - => throw new PlatformNotSupportedException(); + public override PropertyDescriptor PropertyDescriptor => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -73,57 +60,38 @@ public override bool ReadOnly set => throw new PlatformNotSupportedException(); } - protected internal override void ConcedeFocus() - { - } + protected internal override void ConcedeFocus() => throw new PlatformNotSupportedException(); - protected void HideEditBox() - { - } + protected void HideEditBox() => throw new PlatformNotSupportedException(); - protected internal override void UpdateUI(CurrencyManager source, int rowNum, string displayText) - { - } + protected internal override void UpdateUI(CurrencyManager source, int rowNum, string displayText) => throw new PlatformNotSupportedException(); - protected void EndEdit() - { - } + protected void EndEdit() => throw new PlatformNotSupportedException(); - protected internal override Size GetPreferredSize(Graphics g, object value) - => throw new PlatformNotSupportedException(); + protected internal override Size GetPreferredSize(Graphics g, object value) => throw new PlatformNotSupportedException(); - protected internal override int GetMinimumHeight() - => throw new PlatformNotSupportedException(); + protected internal override int GetMinimumHeight() => throw new PlatformNotSupportedException(); - protected internal override int GetPreferredHeight(Graphics g, object value) - => throw new PlatformNotSupportedException(); + protected internal override int GetPreferredHeight(Graphics g, object value) => throw new PlatformNotSupportedException(); - protected internal override void Abort(int rowNum) - { - } + protected internal override void Abort(int rowNum) => throw new PlatformNotSupportedException(); - protected internal override void EnterNullValue() - { - } + protected internal override void EnterNullValue() => throw new PlatformNotSupportedException(); - protected internal override bool Commit(CurrencyManager dataSource, int rowNum) - => throw new PlatformNotSupportedException(); + protected internal override bool Commit(CurrencyManager dataSource, int rowNum) => throw new PlatformNotSupportedException(); protected internal override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText, - bool cellIsVisible) - { - } + bool cellIsVisible) => throw new PlatformNotSupportedException(); protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, - bool alignToRight) - => throw new PlatformNotSupportedException(); + bool alignToRight) => throw new PlatformNotSupportedException(); protected internal override void Paint(Graphics g, Rectangle bounds, @@ -131,30 +99,25 @@ protected internal override bool Commit(CurrencyManager dataSource, int rowNum) int rowNum, Brush backBrush, Brush foreBrush, - bool alignToRight) - => throw new PlatformNotSupportedException(); + bool alignToRight) => throw new PlatformNotSupportedException(); protected void PaintText(Graphics g, Rectangle bounds, string text, - bool alignToRight) - => throw new PlatformNotSupportedException(); + bool alignToRight) => throw new PlatformNotSupportedException(); protected void PaintText(Graphics g, Rectangle textBounds, string text, Brush backBrush, Brush foreBrush, - bool alignToRight) - => throw new PlatformNotSupportedException(); + bool alignToRight) => throw new PlatformNotSupportedException(); - protected internal override void ReleaseHostedControl() - => throw new PlatformNotSupportedException(); + protected internal override void ReleaseHostedControl() => throw new PlatformNotSupportedException(); protected internal override void Paint(Graphics g1, Graphics g, Rectangle bounds, CurrencyManager source, - int rowNum) - => throw new NotImplementedException(); + int rowNum) => throw new NotImplementedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs deleted file mode 100644 index 44771245302..00000000000 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridToolTip.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Drawing; - -namespace System.Windows.Forms; - -#nullable disable -[Obsolete( - Obsoletions.DataGridToolTipMessage, - error: false, - DiagnosticId = Obsoletions.DataGridToolTipDiagnosticId, - UrlFormat = Obsoletions.SharedUrlFormat)] -internal class DataGridToolTip : MarshalByRefObject -{ - public DataGridToolTip(DataGrid dataGrid) - => throw new PlatformNotSupportedException(); - - public static void CreateToolTipHandle() - => throw new PlatformNotSupportedException(); - - public static void AddToolTip(string toolTipString, IntPtr toolTipId, Rectangle iconBounds) - => throw new PlatformNotSupportedException(); - - public static void RemoveToolTip(IntPtr toolTipId) - => throw new PlatformNotSupportedException(); - - public static void Destroy() - => throw new PlatformNotSupportedException(); -} diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs index 27decbf4e45..b84f9d790e1 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/GridColumnStylesCollection.cs @@ -16,32 +16,23 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class GridColumnStylesCollection : BaseCollection, IList { - int IList.Add(object value) - => throw new PlatformNotSupportedException(); + int IList.Add(object value) => throw new PlatformNotSupportedException(); - void IList.Clear() - => throw new PlatformNotSupportedException(); + void IList.Clear() => throw new PlatformNotSupportedException(); - bool IList.Contains(object value) - => throw new PlatformNotSupportedException(); + bool IList.Contains(object value) => throw new PlatformNotSupportedException(); - int IList.IndexOf(object value) - => throw new PlatformNotSupportedException(); + int IList.IndexOf(object value) => throw new PlatformNotSupportedException(); - void IList.Insert(int index, object value) - => throw new PlatformNotSupportedException(); + void IList.Insert(int index, object value) => throw new PlatformNotSupportedException(); - void IList.Remove(object value) - => throw new PlatformNotSupportedException(); + void IList.Remove(object value) => throw new PlatformNotSupportedException(); - void IList.RemoveAt(int index) - => throw new PlatformNotSupportedException(); + void IList.RemoveAt(int index) => throw new PlatformNotSupportedException(); - bool IList.IsFixedSize - => throw new PlatformNotSupportedException(); + bool IList.IsFixedSize => throw new PlatformNotSupportedException(); - bool IList.IsReadOnly - => throw new PlatformNotSupportedException(); + bool IList.IsReadOnly => throw new PlatformNotSupportedException(); object IList.this[int index] { @@ -49,44 +40,33 @@ bool IList.IsReadOnly set => throw new PlatformNotSupportedException(); } - void ICollection.CopyTo(Array array, int index) - => throw new PlatformNotSupportedException(); + void ICollection.CopyTo(Array array, int index) => throw new PlatformNotSupportedException(); - int ICollection.Count - => throw new PlatformNotSupportedException(); + int ICollection.Count => throw new PlatformNotSupportedException(); - bool ICollection.IsSynchronized - => throw new PlatformNotSupportedException(); + bool ICollection.IsSynchronized => throw new PlatformNotSupportedException(); - object ICollection.SyncRoot - => throw new PlatformNotSupportedException(); + object ICollection.SyncRoot => throw new PlatformNotSupportedException(); - IEnumerator IEnumerable.GetEnumerator() - => throw new PlatformNotSupportedException(); + IEnumerator IEnumerable.GetEnumerator() => throw new PlatformNotSupportedException(); - protected override ArrayList List - => throw new PlatformNotSupportedException(); + protected override ArrayList List => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public DataGridColumnStyle this[int index] - => throw new PlatformNotSupportedException(); + public DataGridColumnStyle this[int index] => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public DataGridColumnStyle this[string columnName] - => throw new PlatformNotSupportedException(); + public DataGridColumnStyle this[string columnName] => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public DataGridColumnStyle this[PropertyDescriptor propertyDesciptor] - => throw new PlatformNotSupportedException(); + public DataGridColumnStyle this[PropertyDescriptor propertyDesciptor] => throw new PlatformNotSupportedException(); - public virtual int Add(DataGridColumnStyle column) - => throw new PlatformNotSupportedException(); + public virtual int Add(DataGridColumnStyle column) => throw new PlatformNotSupportedException(); - public void AddRange(DataGridColumnStyle[] columns) - => throw new PlatformNotSupportedException(); + public void AddRange(DataGridColumnStyle[] columns) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -96,30 +76,21 @@ public void AddRange(DataGridColumnStyle[] columns) remove => throw new PlatformNotSupportedException(); } - public void Clear() - => throw new PlatformNotSupportedException(); + public void Clear() => throw new PlatformNotSupportedException(); - public bool Contains(PropertyDescriptor propertyDescriptor) - => throw new PlatformNotSupportedException(); + public bool Contains(PropertyDescriptor propertyDescriptor) => throw new PlatformNotSupportedException(); - public bool Contains(DataGridColumnStyle column) - => throw new PlatformNotSupportedException(); + public bool Contains(DataGridColumnStyle column) => throw new PlatformNotSupportedException(); - public bool Contains(string name) - => throw new PlatformNotSupportedException(); + public bool Contains(string name) => throw new PlatformNotSupportedException(); - public int IndexOf(DataGridColumnStyle element) - => throw new PlatformNotSupportedException(); + public int IndexOf(DataGridColumnStyle element) => throw new PlatformNotSupportedException(); - protected void OnCollectionChanged(CollectionChangeEventArgs e) - => throw new PlatformNotSupportedException(); + protected void OnCollectionChanged(CollectionChangeEventArgs e) => throw new PlatformNotSupportedException(); - public void Remove(DataGridColumnStyle column) - => throw new PlatformNotSupportedException(); + public void Remove(DataGridColumnStyle column) => throw new PlatformNotSupportedException(); - public void RemoveAt(int index) - => throw new PlatformNotSupportedException(); + public void RemoveAt(int index) => throw new PlatformNotSupportedException(); - public void ResetPropertyDescriptors() - => throw new PlatformNotSupportedException(); + public void ResetPropertyDescriptors() => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs index dd875d739c8..aa1890e9c9c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/MainMenu/MainMenu.cs @@ -14,14 +14,11 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class MainMenu : Menu { - public MainMenu() : base(null) - => throw new PlatformNotSupportedException(); + public MainMenu() : base(null) => throw new PlatformNotSupportedException(); - public MainMenu(IContainer container) : this() - => throw new PlatformNotSupportedException(); + public MainMenu(IContainer container) : this() => throw new PlatformNotSupportedException(); - public MainMenu(MenuItem[] items) : base(items) - => throw new PlatformNotSupportedException(); + public MainMenu(MenuItem[] items) : base(items) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -39,12 +36,9 @@ public virtual RightToLeft RightToLeft set => throw new PlatformNotSupportedException(); } - public virtual MainMenu CloneMenu() - => throw new PlatformNotSupportedException(); + public virtual MainMenu CloneMenu() => throw new PlatformNotSupportedException(); - public Form GetForm() - => throw new PlatformNotSupportedException(); + public Form GetForm() => throw new PlatformNotSupportedException(); - public override string ToString() - => throw new PlatformNotSupportedException(); + public override string ToString() => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs index 75a9432aa02..e7ee496809d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBar.cs @@ -17,8 +17,7 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class StatusBar : Control { - public StatusBar() : base() - => throw new PlatformNotSupportedException(); + public StatusBar() : base() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -68,14 +67,11 @@ public override ImageLayout BackgroundImageLayout remove => throw new PlatformNotSupportedException(); } - protected override CreateParams CreateParams - => throw new PlatformNotSupportedException(); + protected override CreateParams CreateParams => throw new PlatformNotSupportedException(); - protected override ImeMode DefaultImeMode - => throw new PlatformNotSupportedException(); + protected override ImeMode DefaultImeMode => throw new PlatformNotSupportedException(); - protected override Size DefaultSize - => throw new PlatformNotSupportedException(); + protected override Size DefaultSize => throw new PlatformNotSupportedException(); protected override bool DoubleBuffered { @@ -133,8 +129,7 @@ public override Color ForeColor [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public StatusBarPanelCollection Panels - => throw new PlatformNotSupportedException(); + public StatusBarPanelCollection Panels => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -192,38 +187,27 @@ public bool SizingGrip remove => throw new PlatformNotSupportedException(); } - protected override void CreateHandle() - => throw new PlatformNotSupportedException(); + protected override void CreateHandle() => throw new PlatformNotSupportedException(); - protected override void Dispose(bool disposing) - => throw new PlatformNotSupportedException(); + protected override void Dispose(bool disposing) => throw new PlatformNotSupportedException(); - protected override void OnHandleCreated(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnHandleCreated(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnHandleDestroyed(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnHandleDestroyed(EventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnMouseDown(MouseEventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnMouseDown(MouseEventArgs e) => throw new PlatformNotSupportedException(); - protected virtual void OnPanelClick(StatusBarPanelClickEventArgs e) - => throw new PlatformNotSupportedException(); + protected virtual void OnPanelClick(StatusBarPanelClickEventArgs e) => throw new PlatformNotSupportedException(); - protected override void OnLayout(LayoutEventArgs levent) - => throw new PlatformNotSupportedException(); + protected override void OnLayout(LayoutEventArgs levent) => throw new PlatformNotSupportedException(); - protected virtual void OnDrawItem(StatusBarDrawItemEventArgs sbdievent) - => throw new PlatformNotSupportedException(); + protected virtual void OnDrawItem(StatusBarDrawItemEventArgs sbdievent) => throw new PlatformNotSupportedException(); - protected override void OnResize(EventArgs e) - => throw new PlatformNotSupportedException(); + protected override void OnResize(EventArgs e) => throw new PlatformNotSupportedException(); - public override string ToString() - => throw new PlatformNotSupportedException(); + public override string ToString() => throw new PlatformNotSupportedException(); - protected override void WndProc(ref Message m) - => throw new PlatformNotSupportedException(); + protected override void WndProc(ref Message m) => throw new PlatformNotSupportedException(); [Obsolete( Obsoletions.StatusBarPanelCollectionMessage, @@ -232,8 +216,7 @@ protected override void WndProc(ref Message m) UrlFormat = Obsoletions.SharedUrlFormat)] public class StatusBarPanelCollection : IList { - public StatusBarPanelCollection(StatusBar owner) - => throw new PlatformNotSupportedException(); + public StatusBarPanelCollection(StatusBar owner) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -251,85 +234,58 @@ public StatusBarPanelCollection(StatusBar owner) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual StatusBarPanel this[string key] - { - get => throw new PlatformNotSupportedException(); - } + public virtual StatusBarPanel this[string key] => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public int Count - => throw new PlatformNotSupportedException(); + public int Count => throw new PlatformNotSupportedException(); - object ICollection.SyncRoot - => throw new PlatformNotSupportedException(); + object ICollection.SyncRoot => throw new PlatformNotSupportedException(); - bool ICollection.IsSynchronized - => throw new PlatformNotSupportedException(); + bool ICollection.IsSynchronized => throw new PlatformNotSupportedException(); - bool IList.IsFixedSize - => throw new PlatformNotSupportedException(); + bool IList.IsFixedSize => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsReadOnly - => throw new PlatformNotSupportedException(); + public bool IsReadOnly => throw new PlatformNotSupportedException(); - public virtual StatusBarPanel Add(string text) - => throw new PlatformNotSupportedException(); + public virtual StatusBarPanel Add(string text) => throw new PlatformNotSupportedException(); - public virtual int Add(StatusBarPanel value) - => throw new PlatformNotSupportedException(); + public virtual int Add(StatusBarPanel value) => throw new PlatformNotSupportedException(); - int IList.Add(object value) - => throw new PlatformNotSupportedException(); + int IList.Add(object value) => throw new PlatformNotSupportedException(); - public virtual void AddRange(StatusBarPanel[] panels) - => throw new PlatformNotSupportedException(); + public virtual void AddRange(StatusBarPanel[] panels) => throw new PlatformNotSupportedException(); - public bool Contains(StatusBarPanel panel) - => throw new PlatformNotSupportedException(); + public bool Contains(StatusBarPanel panel) => throw new PlatformNotSupportedException(); - bool IList.Contains(object panel) - => throw new PlatformNotSupportedException(); + bool IList.Contains(object panel) => throw new PlatformNotSupportedException(); - public virtual bool ContainsKey(string key) - => throw new PlatformNotSupportedException(); + public virtual bool ContainsKey(string key) => throw new PlatformNotSupportedException(); - public int IndexOf(StatusBarPanel panel) - => throw new PlatformNotSupportedException(); + public int IndexOf(StatusBarPanel panel) => throw new PlatformNotSupportedException(); - int IList.IndexOf(object panel) - => throw new PlatformNotSupportedException(); + int IList.IndexOf(object panel) => throw new PlatformNotSupportedException(); - public virtual int IndexOfKey(string key) - => throw new PlatformNotSupportedException(); + public virtual int IndexOfKey(string key) => throw new PlatformNotSupportedException(); - public virtual void Insert(int index, StatusBarPanel value) - => throw new PlatformNotSupportedException(); + public virtual void Insert(int index, StatusBarPanel value) => throw new PlatformNotSupportedException(); - void IList.Insert(int index, object value) - => throw new PlatformNotSupportedException(); + void IList.Insert(int index, object value) => throw new PlatformNotSupportedException(); - public virtual void Clear() - => throw new PlatformNotSupportedException(); + public virtual void Clear() => throw new PlatformNotSupportedException(); - public virtual void Remove(StatusBarPanel value) - => throw new PlatformNotSupportedException(); + public virtual void Remove(StatusBarPanel value) => throw new PlatformNotSupportedException(); - void IList.Remove(object value) - => throw new PlatformNotSupportedException(); + void IList.Remove(object value) => throw new PlatformNotSupportedException(); - public virtual void RemoveAt(int index) - => throw new PlatformNotSupportedException(); + public virtual void RemoveAt(int index) => throw new PlatformNotSupportedException(); - public virtual void RemoveByKey(string key) - => throw new PlatformNotSupportedException(); + public virtual void RemoveByKey(string key) => throw new PlatformNotSupportedException(); - void ICollection.CopyTo(Array dest, int index) - => throw new PlatformNotSupportedException(); + void ICollection.CopyTo(Array dest, int index) => throw new PlatformNotSupportedException(); - public IEnumerator GetEnumerator() - => throw new PlatformNotSupportedException(); + public IEnumerator GetEnumerator() => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs index 36bcb73b200..b8dab2d513c 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarDrawItemEvent.cs @@ -20,8 +20,7 @@ public class StatusBarDrawItemEventArgs : DrawItemEventArgs Rectangle r, int itemId, DrawItemState itemState, - StatusBarPanel panel) : base(g, font, r, itemId, itemState) - => throw new PlatformNotSupportedException(); + StatusBarPanel panel) : base(g, font, r, itemId, itemState) => throw new PlatformNotSupportedException(); public StatusBarDrawItemEventArgs(Graphics g, Font font, @@ -30,11 +29,9 @@ public class StatusBarDrawItemEventArgs : DrawItemEventArgs DrawItemState itemState, StatusBarPanel panel, Color foreColor, - Color backColor) : base(g, font, r, itemId, itemState, foreColor, backColor) - => throw new PlatformNotSupportedException(); + Color backColor) : base(g, font, r, itemId, itemState, foreColor, backColor) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public StatusBarPanel Panel - => throw new PlatformNotSupportedException(); + public StatusBarPanel Panel => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs index 813c74df0cf..6fd7971830d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanel.cs @@ -15,8 +15,7 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class StatusBarPanel : Component, ISupportInitialize { - public StatusBarPanel() - => throw new PlatformNotSupportedException(); + public StatusBarPanel() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -68,8 +67,7 @@ public string Name [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public StatusBar Parent - => throw new PlatformNotSupportedException(); + public StatusBar Parent => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -111,15 +109,11 @@ public int Width set => throw new PlatformNotSupportedException(); } - public void BeginInit() - => throw new PlatformNotSupportedException(); + public void BeginInit() => throw new PlatformNotSupportedException(); - protected override void Dispose(bool disposing) - => throw new PlatformNotSupportedException(); + protected override void Dispose(bool disposing) => throw new PlatformNotSupportedException(); - public void EndInit() - => throw new PlatformNotSupportedException(); + public void EndInit() => throw new PlatformNotSupportedException(); - public override string ToString() - => throw new PlatformNotSupportedException(); + public override string ToString() => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs index 4244240dac3..14543ee7b34 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/StatusBar/StatusBarPanelClickEvent.cs @@ -18,12 +18,9 @@ public class StatusBarPanelClickEventArgs : MouseEventArgs MouseButtons button, int clicks, int x, - int y) - : base(button, clicks, x, y, 0) - => throw new PlatformNotSupportedException(); + int y) : base(button, clicks, x, y, 0) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public StatusBarPanel StatusBarPanel - => throw new PlatformNotSupportedException(); + public StatusBarPanel StatusBarPanel => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs index 39d150b9fe0..90b59029653 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBar.cs @@ -17,8 +17,7 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class ToolBar : Control { - public ToolBar() : base() - => throw new PlatformNotSupportedException(); + public ToolBar() : base() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -102,8 +101,7 @@ public BorderStyle BorderStyle [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public ToolBarButtonCollection Buttons - => throw new PlatformNotSupportedException(); + public ToolBarButtonCollection Buttons => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -163,10 +161,7 @@ public ImageList ImageList [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public Size ImageSize - { - get => throw new PlatformNotSupportedException(); - } + public Size ImageSize => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -272,8 +267,7 @@ public bool Wrappable remove => throw new PlatformNotSupportedException(); } - public override string ToString() - => throw new PlatformNotSupportedException(); + public override string ToString() => throw new PlatformNotSupportedException(); [Obsolete( Obsoletions.ToolBarButtonCollectionMessage, @@ -282,8 +276,7 @@ public override string ToString() UrlFormat = Obsoletions.SharedUrlFormat)] public class ToolBarButtonCollection : IList { - public ToolBarButtonCollection(ToolBar owner) - => throw new PlatformNotSupportedException(); + public ToolBarButtonCollection(ToolBar owner) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -301,83 +294,58 @@ public ToolBarButtonCollection(ToolBar owner) [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public virtual ToolBarButton this[string key] - => throw new PlatformNotSupportedException(); + public virtual ToolBarButton this[string key] => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public int Count - => throw new PlatformNotSupportedException(); + public int Count => throw new PlatformNotSupportedException(); - object ICollection.SyncRoot - => throw new PlatformNotSupportedException(); + object ICollection.SyncRoot => throw new PlatformNotSupportedException(); - bool ICollection.IsSynchronized - => throw new PlatformNotSupportedException(); + bool ICollection.IsSynchronized => throw new PlatformNotSupportedException(); - bool IList.IsFixedSize - => throw new PlatformNotSupportedException(); + bool IList.IsFixedSize => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsReadOnly - => throw new PlatformNotSupportedException(); + public bool IsReadOnly => throw new PlatformNotSupportedException(); - public int Add(ToolBarButton button) - => throw new PlatformNotSupportedException(); + public int Add(ToolBarButton button) => throw new PlatformNotSupportedException(); - public int Add(string text) - => throw new PlatformNotSupportedException(); + public int Add(string text) => throw new PlatformNotSupportedException(); - int IList.Add(object button) - => throw new PlatformNotSupportedException(); + int IList.Add(object button) => throw new PlatformNotSupportedException(); - public void AddRange(ToolBarButton[] buttons) - => throw new PlatformNotSupportedException(); + public void AddRange(ToolBarButton[] buttons) => throw new PlatformNotSupportedException(); - public void Clear() - => throw new PlatformNotSupportedException(); + public void Clear() => throw new PlatformNotSupportedException(); - public bool Contains(ToolBarButton button) - => throw new PlatformNotSupportedException(); + public bool Contains(ToolBarButton button) => throw new PlatformNotSupportedException(); - bool IList.Contains(object button) - => throw new PlatformNotSupportedException(); + bool IList.Contains(object button) => throw new PlatformNotSupportedException(); - public virtual bool ContainsKey(string key) - => throw new PlatformNotSupportedException(); + public virtual bool ContainsKey(string key) => throw new PlatformNotSupportedException(); - void ICollection.CopyTo(Array dest, int index) - => throw new PlatformNotSupportedException(); + void ICollection.CopyTo(Array dest, int index) => throw new PlatformNotSupportedException(); - public int IndexOf(ToolBarButton button) - => throw new PlatformNotSupportedException(); + public int IndexOf(ToolBarButton button) => throw new PlatformNotSupportedException(); - int IList.IndexOf(object button) - => throw new PlatformNotSupportedException(); + int IList.IndexOf(object button) => throw new PlatformNotSupportedException(); - public virtual int IndexOfKey(string key) - => throw new PlatformNotSupportedException(); + public virtual int IndexOfKey(string key) => throw new PlatformNotSupportedException(); - public void Insert(int index, ToolBarButton button) - => throw new PlatformNotSupportedException(); + public void Insert(int index, ToolBarButton button) => throw new PlatformNotSupportedException(); - void IList.Insert(int index, object button) - => throw new PlatformNotSupportedException(); + void IList.Insert(int index, object button) => throw new PlatformNotSupportedException(); - public void RemoveAt(int index) - => throw new PlatformNotSupportedException(); + public void RemoveAt(int index) => throw new PlatformNotSupportedException(); - public virtual void RemoveByKey(string key) - => throw new PlatformNotSupportedException(); + public virtual void RemoveByKey(string key) => throw new PlatformNotSupportedException(); - public void Remove(ToolBarButton button) - => throw new PlatformNotSupportedException(); + public void Remove(ToolBarButton button) => throw new PlatformNotSupportedException(); - void IList.Remove(object button) - => throw new PlatformNotSupportedException(); + void IList.Remove(object button) => throw new PlatformNotSupportedException(); - public IEnumerator GetEnumerator() - => throw new PlatformNotSupportedException(); + public IEnumerator GetEnumerator() => throw new PlatformNotSupportedException(); } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs index b0a7faf65b1..f435b2639af 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButton.cs @@ -15,11 +15,9 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class ToolBarButton : Component { - public ToolBarButton() - => throw new PlatformNotSupportedException(); + public ToolBarButton() => throw new PlatformNotSupportedException(); - public ToolBarButton(string text) : base() - => throw new PlatformNotSupportedException(); + public ToolBarButton(string text) : base() => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -63,8 +61,7 @@ public string Name [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public ToolBar Parent - => throw new PlatformNotSupportedException(); + public ToolBar Parent => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -84,8 +81,7 @@ public bool Pushed [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] - public Rectangle Rectangle - => throw new PlatformNotSupportedException(); + public Rectangle Rectangle => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] @@ -127,6 +123,5 @@ public bool Visible set => throw new PlatformNotSupportedException(); } - public override string ToString() - => throw new PlatformNotSupportedException(); + public override string ToString() => throw new PlatformNotSupportedException(); } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs index 3d85bb914a0..a41cd6c87f8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/ToolBar/ToolBarButtonClickEventArgs.cs @@ -14,8 +14,7 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public class ToolBarButtonClickEventArgs : EventArgs { - public ToolBarButtonClickEventArgs(ToolBarButton button) - => throw new PlatformNotSupportedException(); + public ToolBarButtonClickEventArgs(ToolBarButton button) => throw new PlatformNotSupportedException(); [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.Designer.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.Designer.cs index d68b9fa3a16..751a5759963 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.Designer.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.Designer.cs @@ -33,7 +33,7 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { -#pragma warning disable WFDEV004, WFDEV007, WFDEV009, WFDEV041, WFDEV045, WFDEV051, WFDEV054 // Type or member is obsolete +#pragma warning disable WFDEV004, WFDEV005, WFDEV024, WFDEV026, WFDEV030, WFDEV036, WFDEV039 // Type or member is obsolete this.components = new System.ComponentModel.Container(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); @@ -124,5 +124,5 @@ private void InitializeComponent() private System.Windows.Forms.StatusBar statusBar1; private System.Windows.Forms.StatusBarPanel panel1; private System.Windows.Forms.StatusBarPanel panel2; -#pragma warning restore WFDEV004, WFDEV007, WFDEV009, WFDEV041, WFDEV045, WFDEV051, WFDEV054 // Type or member is obsolete +#pragma warning restore WFDEV004, WFDEV005, WFDEV024, WFDEV026, WFDEV030, WFDEV036, WFDEV039 // Type or member is obsolete } diff --git a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs index 53dc8914303..8ef31ed388c 100644 --- a/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs +++ b/src/System.Windows.Forms/tests/IntegrationTests/WinformsControlsTest/Obsolete/ObsoleteControls.cs @@ -4,7 +4,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; -#pragma warning disable WFDEV007, WFDEV009, WFDEV010, WFDEV014, WFDEV017, WFDEV032, WFDEV036, WFDEV039, WFDEV040, WFDEV044, WFDEV050, WFDEV053 // Type or member is obsolete +#pragma warning disable WFDEV005, WFDEV006, WFDEV008, WFDEV010, WFDEV014, WFDEV016, WFDEV021, WFDEV024 // Type or member is obsolete using static System.Windows.Forms.DataGrid; namespace WinformsControlsTest; diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs index dabd13118d1..dbc43d29b7e 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/AccessibleObjectTests.cs @@ -2690,14 +2690,10 @@ public void AccessibleObject_GetPropertyValue_ReturnsNull_IfExpected(int propert public static IEnumerable AccessibleObject_RuntimeId_IsOverriden_TestData() { -#pragma warning disable WFDEV017, WFDEV018, WFDEV019, WFDEV020, WFDEV021, WFDEV023, WFDEV024, WFDEV025, WFDEV026, WFDEV027, WFDEV028, WFDEV029, WFDEV030, WFDEV031 // Type or member is obsolete var typesToIgnore = new[] { - typeof(ComboBox.ChildAccessibleObject), typeof(DataGridState.DataGridStateParentRowAccessibleObject), typeof(DataGridRow.DataGridCellAccessibleObject), - typeof(DataGridRow.DataGridRowAccessibleObject), typeof(DataGridRelationshipRow.DataGridRelationshipRowAccessibleObject), typeof(DataGridRelationshipRow.DataGridRelationshipAccessibleObject), - typeof(DataGridParentRows.DataGridParentRowsAccessibleObject), typeof(DataGridColumnStyle.DataGridColumnHeaderAccessibleObject), + typeof(ComboBox.ChildAccessibleObject), }; -#pragma warning restore WFDEV017, WFDEV018, WFDEV019, WFDEV020, WFDEV021, WFDEV023, WFDEV024, WFDEV025, WFDEV026, WFDEV027, WFDEV028, WFDEV029, WFDEV030, WFDEV031 // Type or member is obsolete Assembly assembly = typeof(AccessibleObject).Assembly; foreach (Type type in assembly.GetTypes()) { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs index 3c4fff0dd87..1514271ae21 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/AccessibleObjects/Control.ControlAccessibleObjectTests.cs @@ -1219,12 +1219,12 @@ public void ControlAccessibleObject_Supports_LegacyIAccessiblePattern_IfOwnerSup public static IEnumerable ControlAccessibleObject_TestData() { -#pragma warning disable WFDEV009, WFDEV035, WFDEV041, WFDEV051 // Type or member is obsolete +#pragma warning disable WFDEV005, WFDEV015, WFDEV026, WFDEV036 // Type or member is obsolete var typesToIgnore = new[] { typeof(DataGrid), typeof(StatusBar), typeof(ToolBar), typeof(DataGridTextBox) }; -#pragma warning restore WFDEV009, WFDEV035, WFDEV041, WFDEV051 // Type or member is obsolete +#pragma warning restore WFDEV005, WFDEV015, WFDEV026, WFDEV036 // Type or member is obsolete return ReflectionHelper.GetPublicNotAbstractClasses() .Where(t => !typesToIgnore.Contains(t)) @@ -1341,12 +1341,12 @@ public static IEnumerable ControlAccessibleObject_DefaultName_TestData { typeof(MaskedTextBox), string.Empty} }; -#pragma warning disable WFDEV009, WFDEV035, WFDEV041, WFDEV051 // Type or member is obsolete +#pragma warning disable WFDEV005, WFDEV015, WFDEV026, WFDEV036 // Type or member is obsolete var typesToIgnore = new[] { typeof(DataGrid), typeof(StatusBar), typeof(ToolBar), typeof(DataGridTextBox) }; -#pragma warning restore WFDEV009, WFDEV035, WFDEV041, WFDEV051 // Type or member is obsolete +#pragma warning restore WFDEV005, WFDEV015, WFDEV026, WFDEV036 // Type or member is obsolete foreach (Type type in ReflectionHelper.GetPublicNotAbstractClasses()) { From cf386e64822b84939285bddd39f2b25954a3f252 Mon Sep 17 00:00:00 2001 From: "Simon Zhao (BEYONDSOFT CONSULTING INC)" Date: Tue, 9 Apr 2024 16:25:06 +0800 Subject: [PATCH 11/11] Remove private method --- .../Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs index 0bed141b255..325e213ab07 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/Obsolete/DataGrid/DataGridTablesFactory.cs @@ -12,8 +12,6 @@ namespace System.Windows.Forms; UrlFormat = Obsoletions.SharedUrlFormat)] public sealed class GridTablesFactory { - private GridTablesFactory() => throw new PlatformNotSupportedException(); - public static DataGridTableStyle[] CreateGridTables(DataGridTableStyle gridTable, object dataSource, string dataMember,