aboutsummaryrefslogtreecommitdiff
path: root/source/ShiftUI/Internal/ControlBindingsCollection.cs
diff options
context:
space:
mode:
authorMichaelTheShifter <[email protected]>2016-07-20 09:40:36 -0400
committerMichaelTheShifter <[email protected]>2016-07-20 09:40:36 -0400
commitd40fed5ce2bc806a91245adb18039634eac13ed0 (patch)
treef1d7168aee6db109ac2c738ad18c9db667a6ba69 /source/ShiftUI/Internal/ControlBindingsCollection.cs
parentf1856e8ed30ed882229fd3fa2a4038122a5fb441 (diff)
downloadshiftos-c--d40fed5ce2bc806a91245adb18039634eac13ed0.tar.gz
shiftos-c--d40fed5ce2bc806a91245adb18039634eac13ed0.tar.bz2
shiftos-c--d40fed5ce2bc806a91245adb18039634eac13ed0.zip
Move ShiftUI source code to ShiftOS
This'll be a lot easier to work on.
Diffstat (limited to 'source/ShiftUI/Internal/ControlBindingsCollection.cs')
-rw-r--r--source/ShiftUI/Internal/ControlBindingsCollection.cs204
1 files changed, 204 insertions, 0 deletions
diff --git a/source/ShiftUI/Internal/ControlBindingsCollection.cs b/source/ShiftUI/Internal/ControlBindingsCollection.cs
new file mode 100644
index 0000000..345efee
--- /dev/null
+++ b/source/ShiftUI/Internal/ControlBindingsCollection.cs
@@ -0,0 +1,204 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2004-2005 Novell, Inc.
+//
+// Authors:
+// Jackson Harper ([email protected])
+
+
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Reflection;
+
+
+namespace ShiftUI {
+ [DefaultEvent("CollectionChanged")]
+ public class WidgetBindingsCollection : BindingsCollection {
+ #region Fields
+ private Widget control;
+ private IBindableComponent bindable_component;
+ private DataSourceUpdateMode default_datasource_update_mode;
+ #endregion // Fields
+
+ #region Constructors
+ internal WidgetBindingsCollection (Widget control) {
+ this.control = control;
+ bindable_component = this.control as IBindableComponent;
+ default_datasource_update_mode = DataSourceUpdateMode.OnValidation;
+ }
+
+ public WidgetBindingsCollection (IBindableComponent control)
+ {
+ bindable_component = control;
+ control = control as Widget;
+ default_datasource_update_mode = DataSourceUpdateMode.OnValidation;
+ }
+ #endregion // Constructors
+
+ #region Public Instance Properties
+ public Widget Widget {
+ get {
+ return control;
+ }
+ }
+
+ public Binding this[string propertyName] {
+ get {
+ foreach (Binding b in base.List) {
+ if (b.PropertyName == propertyName) {
+ return b;
+ }
+ }
+ return null;
+ }
+ }
+
+ public IBindableComponent BindableComponent {
+ get {
+ return bindable_component;
+ }
+ }
+
+ public DataSourceUpdateMode DefaultDataSourceUpdateMode {
+ get {
+ return default_datasource_update_mode;
+ }
+ set {
+ default_datasource_update_mode = value;
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ public new void Add (Binding binding)
+ {
+ AddCore (binding);
+ OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, binding));
+ }
+
+ public Binding Add (string propertyName, object dataSource, string dataMember)
+ {
+ if (dataSource == null)
+ throw new ArgumentNullException ("dataSource");
+
+ Binding res = new Binding (propertyName, dataSource, dataMember);
+ res.DataSourceUpdateMode = default_datasource_update_mode;
+ Add (res);
+ return res;
+ }
+
+ public Binding Add (string propertyName, object dataSource, string dataMember, bool formattingEnabled)
+ {
+ return Add (propertyName, dataSource, dataMember, formattingEnabled, default_datasource_update_mode, null, String.Empty, null);
+ }
+
+ public Binding Add (string propertyName, object dataSource, string dataMember, bool formattingEnabled, DataSourceUpdateMode updateMode)
+ {
+ return Add (propertyName, dataSource, dataMember, formattingEnabled, updateMode, null, String.Empty, null);
+ }
+
+ public Binding Add (string propertyName, object dataSource, string dataMember, bool formattingEnabled, DataSourceUpdateMode updateMode,
+ object nullValue)
+ {
+ return Add (propertyName, dataSource, dataMember, formattingEnabled, updateMode, nullValue, String.Empty, null);
+ }
+
+ public Binding Add (string propertyName, object dataSource, string dataMember, bool formattingEnabled, DataSourceUpdateMode updateMode,
+ object nullValue, string formatString)
+ {
+ return Add (propertyName, dataSource, dataMember, formattingEnabled, updateMode, nullValue, formatString, null);
+ }
+
+ public Binding Add (string propertyName, object dataSource, string dataMember, bool formattingEnabled, DataSourceUpdateMode updateMode,
+ object nullValue, string formatString, IFormatProvider formatInfo)
+ {
+ if (dataSource == null)
+ throw new ArgumentNullException ("dataSource");
+
+ Binding res = new Binding (propertyName, dataSource, dataMember);
+ res.FormattingEnabled = formattingEnabled;
+ res.DataSourceUpdateMode = updateMode;
+ res.NullValue = nullValue;
+ res.FormatString = formatString;
+ res.FormatInfo = formatInfo;
+
+ Add (res);
+ return res;
+ }
+
+ public new void Clear() {
+ base.Clear();
+ }
+
+ public new void Remove (Binding binding) {
+ if (binding == null)
+ throw new NullReferenceException("The binding is null");
+
+ base.Remove(binding);
+ }
+
+ public new void RemoveAt(int index) {
+ if (index < 0 || index >= base.List.Count)
+ throw new ArgumentOutOfRangeException("index");
+
+ base.RemoveAt(index);
+ }
+ #endregion // Public Instance Methods
+
+ #region Protected Instance Methods
+ protected override void AddCore (Binding dataBinding)
+ {
+ if (dataBinding == null)
+ throw new ArgumentNullException ("dataBinding");
+
+ if (dataBinding.Widget != null && dataBinding.BindableComponent != bindable_component)
+ throw new ArgumentException ("dataBinding belongs to another BindingsCollection");
+
+ for (int i = 0; i < Count; i++) {
+ Binding bnd = this [i];
+ if (bnd == null || bnd.PropertyName.Length == 0 || dataBinding.PropertyName.Length == 0) {
+ continue;
+ }
+
+ if (String.Compare (bnd.PropertyName, dataBinding.PropertyName, true) == 0) {
+ throw new ArgumentException ("The binding is already in the collection");
+ }
+ }
+
+ dataBinding.SetWidget (bindable_component);
+ dataBinding.Check ();
+ base.AddCore (dataBinding);
+ }
+
+ protected override void ClearCore() {
+ base.ClearCore ();
+ }
+
+ protected override void RemoveCore (Binding dataBinding) {
+ if (dataBinding == null)
+ throw new ArgumentNullException ("dataBinding");
+
+ base.RemoveCore (dataBinding);
+ }
+ #endregion // Protected Instance Methods
+ }
+}
+