コード例 #1
0
        protected override void OnParse(ConvertEventArgs e)
        {
            base.OnParse(e);

            bool b = (bool)e.Value;

            if (b)
            {
                e.Value = TrueValue;
            }
            else
            {
                e.Cancel = true;
            }
        }
コード例 #2
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
        private void SetPropertyValue(object data)
        {
            PropertyDescriptor pd = TypeDescriptor.GetProperties(manager.Current).Find(binding_member_info.BindingField, true);

            if (pd.IsReadOnly)
            {
                return;
            }
            ConvertEventArgs e = new ConvertEventArgs(data, pd.PropertyType);

            data = ParseData(e);
            if (!e.Cancel)
            {
                pd.SetValue(manager.Current, data);
            }
        }
コード例 #3
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
        void PushData(bool force, bool force_control_update)
        {
            if (manager == null || manager.IsSuspended || manager.Count == 0 || manager.Position == -1)
            {
                if (manager != null)
                {
                    Console.WriteLine("PushData return : manager.IsSuspended = {0}, manager.Count = {1}, managet.Position = {2}",
                                      manager.IsSuspended, manager.Count, manager.Position);
                }
                else
                {
                    Console.WriteLine("PushData return : manager = null");
                }
                return;
            }

            if (!force && control_update_mode == ControlUpdateMode.Never)
            {
                return;
            }

            if (is_null_desc != null)
            {
                bool is_null = (bool)is_null_desc.GetValue(manager.Current);
                if (is_null)
                {
                    data = Convert.DBNull;
                    return;
                }
            }

            PropertyDescriptor pd = TypeDescriptor.GetProperties(manager.Current).Find(binding_member_info.BindingField, true);

            if (pd == null)
            {
                data = manager.Current;
            }
            else
            {
                data = pd.GetValue(manager.Current);
            }

            if ((data == null || data == DBNull.Value) && null_value != null)
            {
                data = null_value;
            }

            try {
                ConvertEventArgs e = new ConvertEventArgs(data, data_type);
                data = FormatData(e);
                Console.WriteLine("PushData : data = {0}, e.Cancel = {1}",
                                  data, e.Cancel);
                if (!e.Cancel)
                {
                    SetControlValue(data, force_control_update);
                }
            } catch (Exception e) {
                if (formatting_enabled)
                {
                    FireBindingComplete(BindingCompleteContext.ControlUpdate, e, e.Message);
                    return;
                }

                throw e;
            }


            if (formatting_enabled)
            {
                FireBindingComplete(BindingCompleteContext.ControlUpdate, null, null);
            }
        }
コード例 #4
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
        private void SetControlValue(object data, bool force_control_update)
        {
            if (!force_control_update) {
                //Set control property value only if differs from data
                PropertyDescriptor pd = TypeDescriptor.GetProperties (manager.Current).Find (binding_member_info.BindingField, true);
                object control_data = control_property.GetValue (source);
                if (control_data == null)
                    control_data = datasource_null_value;
                ConvertEventArgs e = new ConvertEventArgs (control_data, pd.PropertyType);
                control_data = ParseData (e);
                //We need to compare different types eg. Decimal and string
                if (StringComparer.InvariantCultureIgnoreCase.Compare ((control_data ?? (pd.PropertyType.IsValueType ? (Activator.CreateInstance (pd.PropertyType) ?? string.Empty) : string.Empty)).ToString (),
                                                                       (data ?? string.Empty).ToString())== 0) {
                        if (data == null || control_data == null) {
                            return;
                        }
                }

                //fallback for object that are different but have same ToString values
                if (data != null && control_data != null) {
                    if (data.GetHashCode () == control_data.GetHashCode ()) {
                        return;
                    }
                }
            }

            control_property.SetValue (source, data);
        }
コード例 #5
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
 private void SetPropertyValue(object data)
 {
     PropertyDescriptor pd = TypeDescriptor.GetProperties (manager.Current).Find (binding_member_info.BindingField, true);
     if (pd.IsReadOnly)
         return;
     ConvertEventArgs e = new ConvertEventArgs (data, pd.PropertyType);
     data = ParseData (e);
     if (!e.Cancel)
         pd.SetValue (manager.Current, data);
 }
コード例 #6
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
        void PushData(bool force, bool force_control_update)
        {
            if (manager == null || manager.IsSuspended || manager.Count == 0 || manager.Position == -1) {
                if (manager != null) {
                    Console.WriteLine ("PushData return : manager.IsSuspended = {0}, manager.Count = {1}, managet.Position = {2}",
                                   manager.IsSuspended, manager.Count, manager.Position);
                }
                else {
                    Console.WriteLine ("PushData return : manager = null");
                }
                return;
            }

            if (!force && control_update_mode == ControlUpdateMode.Never)
                return;

            if (is_null_desc != null) {
                bool is_null = (bool) is_null_desc.GetValue (manager.Current);
                if (is_null) {
                    data = Convert.DBNull;
                    return;
                }
            }

            PropertyDescriptor pd = TypeDescriptor.GetProperties (manager.Current).Find (binding_member_info.BindingField, true);
            if (pd == null) {
                data = manager.Current;
            } else {
                data = pd.GetValue (manager.Current);
            }

            if ((data == null || data == DBNull.Value) && null_value != null)
                data = null_value;

            try {
                ConvertEventArgs e = new ConvertEventArgs (data, data_type);
                data = FormatData (e);
                Console.WriteLine ("PushData : data = {0}, e.Cancel = {1}",
                                   data, e.Cancel);
                if (!e.Cancel)
                    SetControlValue (data, force_control_update);
            } catch (Exception e) {

                if (formatting_enabled) {
                    FireBindingComplete (BindingCompleteContext.ControlUpdate, e, e.Message);
                    return;
                }

                throw e;
            }

            if (formatting_enabled)
                FireBindingComplete (BindingCompleteContext.ControlUpdate, null, null);
        }
コード例 #7
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
        private object ParseData(ConvertEventArgs e)
        {
            object data = e.Value;
            Type data_type = e.DesiredType;

            OnParse (e);

            if (e.Cancel)
                return data;
            if (data_type.IsInstanceOfType (e.Value))
                return e.Value;
            if (e.Value == Convert.DBNull)
                return e.Value;

            if (e.Value == null) {
                bool nullable = data_type.IsGenericType && !data_type.ContainsGenericParameters &&
                    data_type.GetGenericTypeDefinition () == typeof (Nullable<>);
                return data_type.IsValueType && !nullable ? Convert.DBNull : null;
            }

            return ConvertData (e.Value, data_type);
        }
コード例 #8
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
        private object FormatData(ConvertEventArgs e)
        {
            object data = e.Value;

            OnFormat (e);
            if (data_type.IsInstanceOfType (e.Value))
                return e.Value;

            if (formatting_enabled) {
                if ((e.Value == null || e.Value == Convert.DBNull) && null_value != null)
                    return null_value;

                if (e.Value is IFormattable && data_type == typeof (string)) {
                    IFormattable formattable = (IFormattable) e.Value;
                    return formattable.ToString (format_string, format_info);
                }
            }

            if (e.Value == null && data_type == typeof (object))
                return Convert.DBNull;

            return ConvertData (data, data_type);
        }
コード例 #9
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
 protected virtual void OnParse(ConvertEventArgs cevent)
 {
     if (Parse!=null)
         Parse (this, cevent);
 }
コード例 #10
0
ファイル: Binding.cs プロジェクト: pzsysa/gtk-sharp-forms
 protected virtual void OnFormat(ConvertEventArgs cevent)
 {
     if (Format!=null)
         Format (this, cevent);
 }