[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / PropertyManager.cs
blob64392af1ff2c1eab348f86811e5d21c317b15571
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.
11 //
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.
22 // Authors:
23 // Jackson Harper jackson@ximian.com
25 using System;
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)
65 return;
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 {
85 get { return 0; }
86 set { /* Doesn't do anything on MS" */ }
89 public override int Count {
90 get { return 1; }
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)
102 return;
103 editable.CancelEdit ();
105 PushData ();
108 public override void EndCurrentEdit ()
110 PullData ();
112 IEditableObject editable = data_source as IEditableObject;
113 if (editable == null)
114 return;
115 editable.EndEdit ();
118 // Hide this method from the 2.0 public API
119 internal override PropertyDescriptorCollection GetItemPropertiesInternal ()
121 return TypeDescriptor.GetProperties (data_source);
124 public override void RemoveAt (int index)
126 throw new NotSupportedException ("RemoveAt is not supported for property to property binding");
129 public override void ResumeBinding ()
133 public override void SuspendBinding ()
137 internal override bool IsSuspended {
138 get { return data_source == null; }
141 protected internal override string GetListName (ArrayList listAccessors)
143 return String.Empty;
146 [MonoTODO ("Stub, does nothing")]
147 protected override void UpdateIsBinding ()
151 protected internal override void OnCurrentChanged (EventArgs ea)
153 PushData ();
155 if (onCurrentChangedHandler != null) {
156 onCurrentChangedHandler (this, ea);
160 protected override void OnCurrentItemChanged (EventArgs ea)
162 throw new NotImplementedException ();