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) 2005 Novell, Inc.
23 // Jackson Harper jackson@ximian.com
26 using System
.Collections
;
27 using System
.ComponentModel
;
29 namespace System
.Windows
.Forms
{
31 public class PropertyManager
: BindingManagerBase
{
33 internal string property_name
;
34 private PropertyDescriptor prop_desc
;
35 private object data_source
;
36 private EventDescriptor changed_event
;
37 private EventHandler property_value_changed_handler
;
39 public PropertyManager() {
42 internal PropertyManager (object data_source
)
44 SetDataSource (data_source
);
47 internal PropertyManager (object data_source
, string property_name
)
49 this.property_name
= property_name
;
51 SetDataSource (data_source
);
54 internal void SetDataSource (object new_data_source
)
56 if (changed_event
!= null)
57 changed_event
.RemoveEventHandler (data_source
, property_value_changed_handler
);
59 data_source
= new_data_source
;
61 if (property_name
!= null) {
62 prop_desc
= TypeDescriptor
.GetProperties (data_source
).Find (property_name
, true);
64 if (prop_desc
== null)
67 changed_event
= TypeDescriptor
.GetEvents (data_source
).Find (property_name
+ "Changed", false);
68 if (changed_event
!= null) {
69 property_value_changed_handler
= new EventHandler (PropertyValueChanged
);
70 changed_event
.AddEventHandler (data_source
, property_value_changed_handler
);
75 void PropertyValueChanged (object sender
, EventArgs args
)
77 OnCurrentChanged (args
);
80 public override object Current
{
81 get { return prop_desc == null ? data_source : prop_desc.GetValue (data_source); }
84 public override int Position
{
86 set { /* Doesn't do anything on MS" */ }
89 public override int Count
{
93 public override void AddNew ()
95 throw new NotSupportedException ("AddNew is not supported for property to property binding");
98 public override void CancelCurrentEdit ()
100 IEditableObject editable
= data_source
as IEditableObject
;
101 if (editable
== null)
103 editable
.CancelEdit ();
108 public override void EndCurrentEdit ()
112 IEditableObject editable
= data_source
as IEditableObject
;
113 if (editable
== null)
118 public override PropertyDescriptorCollection
GetItemProperties ()
120 return TypeDescriptor
.GetProperties (data_source
);
123 public override void RemoveAt (int idx
)
125 throw new NotSupportedException ("RemoveAt is not supported for property to property binding");
128 public override void ResumeBinding ()
132 public override void SuspendBinding ()
136 internal override bool IsSuspended
{
137 get { return data_source == null; }
140 protected internal override string GetListName (ArrayList list
)
146 protected override void UpdateIsBinding ()
150 protected internal override void OnCurrentChanged (EventArgs e
)
154 if (onCurrentChangedHandler
!= null) {
155 onCurrentChangedHandler (this, e
);
160 protected override void OnCurrentItemChanged (EventArgs e
)
162 throw new NotImplementedException ();