yangyin
2024-10-14 af90d73f1740a8e15fe2c76282fb7e2ccad5df5d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// *********************************
// Message from Original Author:
//
// 2008 Jose Menendez Poo
// Please give me credit if you use this code. It's all I ask.
// Contact me for more info: menendezpoo@gmail.com
// *********************************
//
// Original project from http://ribbon.codeplex.com/
// Continue to support and maintain by http://officeribbon.codeplex.com/
 
 
using System.ComponentModel;
using System.Windows.Forms.Classes.Collections;
 
namespace System.Windows.Forms
{
    /// <summary>
    /// Represents a collection of RibbonPanel objects
    /// </summary>
    public sealed class RibbonPanelCollection
        : RibbonCollectionBase<RibbonPanel>
    {
        /// <summary>
        /// Creates a new RibbonPanelCollection
        /// </summary>
        /// <param name="ownerTab">RibbonTab that contains this panel collection</param>
        /// <exception cref="ArgumentNullException">ownerTab is null</exception>
        public RibbonPanelCollection(RibbonTab ownerTab)
           : base(null)
        {
            OwnerTab = ownerTab ?? throw new ArgumentNullException(nameof(ownerTab));
        }
 
        /// <summary>
        /// Gets the Ribbon that contains this panel collection
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Ribbon Owner => base.Owner ?? OwnerTab.Owner;
 
        /// <summary>
        /// Gets the RibbonTab that contains this panel collection
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public RibbonTab OwnerTab { get; private set; }
 
        internal override void SetOwner(RibbonPanel item)
        {
            item.SetOwner(Owner);
            item.SetOwnerTab(OwnerTab);
        }
 
        internal override void ClearOwner(RibbonPanel item)
        {
            item.ClearOwner();
        }
 
        /// <summary>
        /// Notifies the <see cref="OwnerTab"/> and <see cref="Owner"/> about changes in the <see cref="RibbonItemCollection"/>.
        /// </summary>
        internal override void UpdateRegions()
        {
            try
            {
                OwnerTab.UpdatePanelsRegions();
                if (Owner != null && Owner.IsDisposed == false)
                {
                    Owner.UpdateRegions();
                    Owner.Invalidate();
                }
            }
            catch
            {
                // ignored
            }
        }
 
        /// <summary>
        /// Sets the value of the Owner Property
        /// </summary>
        internal override void SetOwner(Ribbon owner)
        {
            base.SetOwner(owner);
            foreach (RibbonPanel panel in this)
            {
                panel.SetOwner(owner);
            }
        }
 
        /// <summary>
        /// Sets the value of the OwnerTab Property
        /// </summary>
        internal void SetOwnerTab(RibbonTab ownerTab)
        {
            OwnerTab = ownerTab;
 
            foreach (RibbonPanel panel in this)
            {
                panel.SetOwnerTab(OwnerTab);
            }
        }
    }
}