1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Jonathan Chambers (jonathan.chambers@ansys.com)
29 using System.Windows.Forms;
30 using System.ComponentModel;
33 namespace System.Windows.Forms.PropertyGridInternal
35 internal class GridEntry : GridItem, ITypeDescriptorContext
37 #region Local Variables
38 private bool expanded = true;
39 private GridItemCollection grid_items;
40 private GridItem parent;
41 private PropertyDescriptor property_descriptor;
42 private object[] selected_objects;
44 private Rectangle plus_minus_bounds;
45 private Rectangle bounds;
46 private PropertyGridView property_grid_view;
47 #endregion // Local Variables
50 protected GridEntry (PropertyGridView view)
52 property_grid_view = view;
53 plus_minus_bounds = new Rectangle(0,0,0,0);
54 bounds = new Rectangle(0,0,0,0);
56 grid_items = new GridItemCollection();
59 public GridEntry(PropertyGridView view, object[] objs, PropertyDescriptor prop_desc) : this (view) {
60 selected_objects = objs;
61 property_descriptor = prop_desc;
63 #endregion // Constructors
65 #region Public Instance Properties
66 public override bool Expandable
69 return grid_items.Count > 0;
73 public override bool Expanded
80 if (expanded == value)
84 property_grid_view.RedrawBelowItemOnExpansion (this);
88 public override GridItemCollection GridItems
95 public override GridItemType GridItemType
98 return GridItemType.Property;
102 public override string Label
105 return property_descriptor.Name;
109 public override GridItem Parent
116 public override PropertyDescriptor PropertyDescriptor
119 return property_descriptor;
123 public bool CanResetValue ()
125 if (Value == null) /* not sure if this is always right.. */
128 return PropertyDescriptor.CanResetValue(selected_objects[0]);
131 public override object Value
134 /* we should probably put this logic
135 * someplace else, maybe when we're
136 * initially populating the
138 if (selected_objects == null || selected_objects.Length == 0 || property_descriptor == null)
141 object v = property_descriptor.GetValue(selected_objects[0]);
142 for (int i = 1; i < selected_objects.Length; i ++) {
143 if (!Object.Equals (v, property_descriptor.GetValue(selected_objects[i])))
150 #endregion // Public Instance Properties
152 #region Public Instance Methods
154 public override bool Select ()
156 property_grid_view.property_grid.SelectedGridItem = this;
159 #endregion // Public Instance Methods
161 #region ITypeDescriptorContext Members
163 void ITypeDescriptorContext.OnComponentChanged() {
164 // TODO: Add SystemComp.OnComponentChanged implementation
167 [MonoTODO ("this is broken, as PropertyGridView doesn't implement IContainer")]
168 IContainer ITypeDescriptorContext.Container {
170 return property_grid_view as IContainer;
174 bool ITypeDescriptorContext.OnComponentChanging() {
175 // TODO: Add SystemComp.OnComponentChanging implementation
179 object ITypeDescriptorContext.Instance {
185 PropertyDescriptor ITypeDescriptorContext.PropertyDescriptor {
187 return PropertyDescriptor;
193 #region IServiceProvider Members
195 object IServiceProvider.GetService(Type serviceType) {
196 IComponent selectedComponent = property_grid_view.property_grid.SelectedObject as IComponent;
197 if (selectedComponent != null && selectedComponent.Site != null)
198 return selectedComponent.Site.GetService (serviceType);
204 internal object[] SelectedObjects {
206 return selected_objects;
209 selected_objects = value;
213 internal override int Top {
222 if (property_grid_view.property_grid.SelectedGridItem == this)
223 property_grid_view.grid_textbox_Show (this);
227 internal override Rectangle PlusMinusBounds {
229 return plus_minus_bounds;
232 plus_minus_bounds = value;
236 internal override Rectangle Bounds
248 if (property_grid_view.property_grid.SelectedGridItem == this)
249 property_grid_view.grid_textbox_Show (this);
253 internal void SetParent (GridItem parent)
255 this.parent = parent;