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. 19 // 20 // Copyright (c) 2004-2005 Novell, Inc. 21 // 22 // Authors: 23 // Peter Bartok pbartok@novell.com 24 // Jackson Harper jackson@ximian.com 25 // 26 27 28 // NOT COMPLETE 29 30 using System.ComponentModel; 31 using System.Collections; 32 33 namespace System.Windows.Forms 34 { 35 public abstract class BindingManagerBase 36 { 37 private BindingsCollection bindings; 38 internal bool transfering_data; /* true if we're pushing or pulling data */ 39 40 #region Public Constructors BindingManagerBase()41 public BindingManagerBase() 42 { 43 } 44 #endregion // Public Constructors 45 46 #region Protected Instance Fields 47 protected EventHandler onCurrentChangedHandler; 48 protected EventHandler onPositionChangedHandler; 49 internal EventHandler onCurrentItemChangedHandler; 50 #endregion // Protected Instance Fields 51 52 #region Public Instance Properties 53 public BindingsCollection Bindings { 54 get { 55 if (bindings == null) { 56 bindings = new BindingsCollection (); 57 } 58 return bindings; 59 } 60 } 61 62 public abstract int Count { 63 get; 64 } 65 66 public abstract object Current { 67 get; 68 } 69 70 public bool IsBindingSuspended { 71 get { 72 return IsSuspended; 73 } 74 } 75 76 public abstract int Position { 77 get; set; 78 } 79 #endregion // Public Instance Properties 80 81 #region Public Instance Methods AddNew()82 public abstract void AddNew(); 83 CancelCurrentEdit()84 public abstract void CancelCurrentEdit(); 85 EndCurrentEdit()86 public abstract void EndCurrentEdit(); 87 GetItemProperties()88 public virtual PropertyDescriptorCollection GetItemProperties() 89 { 90 return GetItemPropertiesInternal (); 91 } 92 GetItemPropertiesInternal()93 internal virtual PropertyDescriptorCollection GetItemPropertiesInternal () 94 { 95 throw new NotImplementedException (); 96 } 97 RemoveAt(int index)98 public abstract void RemoveAt(int index); 99 ResumeBinding()100 public abstract void ResumeBinding(); 101 SuspendBinding()102 public abstract void SuspendBinding(); 103 #endregion // Public Instance Methods 104 105 internal virtual bool IsSuspended { 106 get { 107 return false; 108 } 109 } 110 111 #region Protected Instance Methods 112 [MonoTODO ("Not implemented, will throw NotImplementedException")] GetItemProperties(ArrayList dataSources, ArrayList listAccessors)113 protected internal virtual PropertyDescriptorCollection GetItemProperties (ArrayList dataSources, ArrayList listAccessors) 114 { 115 throw new NotImplementedException(); 116 } 117 118 [MonoTODO ("Not implemented, will throw NotImplementedException")] GetItemProperties(Type listType, int offset, ArrayList dataSources, ArrayList listAccessors)119 protected virtual PropertyDescriptorCollection GetItemProperties (Type listType, int offset, ArrayList dataSources, ArrayList listAccessors) 120 { 121 throw new NotImplementedException(); 122 } 123 GetListName(ArrayList listAccessors)124 protected internal abstract string GetListName (ArrayList listAccessors); 125 OnCurrentChanged(EventArgs e)126 protected internal abstract void OnCurrentChanged (EventArgs e); 127 PullData()128 protected void PullData() 129 { 130 try { 131 if (!transfering_data) { 132 transfering_data = true; 133 UpdateIsBinding (); 134 } 135 foreach (Binding binding in Bindings) { 136 binding.PullData (); 137 } 138 } finally { 139 transfering_data = false; 140 } 141 } 142 PushData()143 protected void PushData() 144 { 145 try { 146 if (!transfering_data) { 147 transfering_data = true; 148 UpdateIsBinding (); 149 } 150 foreach (Binding binding in Bindings) { 151 binding.PushData (); 152 } 153 } finally { 154 transfering_data = false; 155 } 156 } 157 158 OnBindingComplete(BindingCompleteEventArgs args)159 protected void OnBindingComplete (BindingCompleteEventArgs args) 160 { 161 if (BindingComplete != null) 162 BindingComplete (this, args); 163 } 164 OnCurrentItemChanged(EventArgs e)165 protected abstract void OnCurrentItemChanged (EventArgs e); 166 OnDataError(Exception e)167 protected void OnDataError (Exception e) 168 { 169 if (DataError != null) 170 DataError (this, new BindingManagerDataErrorEventArgs (e)); 171 } 172 UpdateIsBinding()173 protected abstract void UpdateIsBinding(); 174 #endregion // Protected Instance Methods 175 AddBinding(Binding binding)176 internal void AddBinding (Binding binding) 177 { 178 if (Bindings.Contains (binding)) 179 return; 180 Bindings.Add (binding); 181 } 182 183 #region Events 184 public event EventHandler CurrentChanged { 185 add { onCurrentChangedHandler += value; } 186 remove { onCurrentChangedHandler -= value; } 187 } 188 189 public event EventHandler PositionChanged { 190 add { onPositionChangedHandler += value; } 191 remove { onPositionChangedHandler -= value; } 192 } 193 194 public event EventHandler CurrentItemChanged { 195 add { onCurrentItemChangedHandler += value; } 196 remove { onCurrentItemChangedHandler -= value; } 197 } 198 199 public event BindingCompleteEventHandler BindingComplete; 200 public event BindingManagerDataErrorEventHandler DataError; 201 #endregion // Events 202 } 203 } 204