2007-03-19 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / GridEntry.cs
blobc42ddb70a1e691f45df4747969f6b097a69437e5
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:
8 //
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.
22 // Authors:
23 // Jonathan Chambers (jonathan.chambers@ansys.com)
26 // NOT COMPLETE
28 using System;
29 using System.Windows.Forms;
30 using System.ComponentModel;
31 using System.Drawing;
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;
43 private int top;
44 private Rectangle plus_minus_bounds;
45 private Rectangle bounds;
46 private PropertyGridView property_grid_view;
47 #endregion // Local Variables
49 #region Contructors
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);
55 top = -1;
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
68 get {
69 return grid_items.Count > 0;
73 public override bool Expanded
75 get {
76 return expanded;
79 set {
80 if (expanded == value)
81 return;
83 expanded = value;
84 property_grid_view.RedrawBelowItemOnExpansion (this);
88 public override GridItemCollection GridItems
90 get {
91 return grid_items;
95 public override GridItemType GridItemType
97 get {
98 return GridItemType.Property;
102 public override string Label
104 get {
105 return property_descriptor.Name;
109 public override GridItem Parent
111 get {
112 return parent;
116 public override PropertyDescriptor PropertyDescriptor
118 get {
119 return property_descriptor;
123 public bool CanResetValue ()
125 if (Value == null) /* not sure if this is always right.. */
126 return false;
128 return PropertyDescriptor.CanResetValue(selected_objects[0]);
131 public override object Value
133 get {
134 /* we should probably put this logic
135 * someplace else, maybe when we're
136 * initially populating the
137 * PropertyGrid? */
138 if (selected_objects == null || selected_objects.Length == 0)
139 return 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])))
144 return null;
147 return v;
150 #endregion // Public Instance Properties
152 #region Public Instance Methods
153 [MonoTODO]
154 public override bool Select ()
156 property_grid_view.property_grid.SelectedGridItem = this;
157 return true;
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 {
169 get {
170 return property_grid_view as IContainer;
174 bool ITypeDescriptorContext.OnComponentChanging() {
175 // TODO: Add SystemComp.OnComponentChanging implementation
176 return false;
179 object ITypeDescriptorContext.Instance {
180 get {
181 return Value;
185 PropertyDescriptor ITypeDescriptorContext.PropertyDescriptor {
186 get {
187 return PropertyDescriptor;
191 #endregion
193 #region IServiceProvider Members
195 object IServiceProvider.GetService(Type serviceType) {
196 // TODO: Add SystemComp.GetService implementation
197 return null;
200 #endregion
202 internal object[] SelectedObjects {
203 get {
204 return selected_objects;
208 internal override int Top {
209 get {
210 return top;
212 set {
213 if (top == value)
214 return;
216 top = value;
217 if (property_grid_view.property_grid.SelectedGridItem == this)
218 property_grid_view.grid_textbox_Show (this);
222 internal override Rectangle PlusMinusBounds {
223 get{
224 return plus_minus_bounds;
226 set{
227 plus_minus_bounds = value;
231 internal override Rectangle Bounds
235 return bounds;
239 if (bounds == value)
240 return;
242 bounds = value;
243 if (property_grid_view.property_grid.SelectedGridItem == this)
244 property_grid_view.grid_textbox_Show (this);
248 internal void SetParent (GridItem parent)
250 this.parent = parent;