Esempio n. 1
0
        /// <summary>
        /// Attach a callback even to move the
        /// </summary>
        private static void AttachDropdownActivator(TypeEditorHost host)
        {
            if (!myRetrievedField)
            {
                System.Threading.Interlocked.CompareExchange <FieldInfo>(
                    ref myDropdownHolderField,
                    typeof(TypeEditorHost).GetField("dropDownHolder", BindingFlags.NonPublic | BindingFlags.Instance),
                    null);
                myRetrievedField = true;
            }
            FieldInfo dropDownHolderField = myDropdownHolderField;

            if (dropDownHolderField != null)
            {
                Form form = dropDownHolderField.GetValue(host) as Form;
                if (form != null)
                {
                    form.Activated += delegate(object sender, EventArgs e2)
                    {
                        Control   ctl    = (Control)sender;
                        Rectangle rect   = ctl.Bounds;
                        Screen    screen = Screen.FromControl(ctl);
                        int       testLeft;
                        if ((screen != null) && ((rect.X - rect.Width / 3) < (testLeft = screen.WorkingArea.Left)))
                        {
                            // With the size bar always on the left we want to leave room
                            // to resize the dropdown. Anchor it on the left edge of the
                            // dropdown button instead of the default right edge.
                            rect.X     = rect.Right - SystemInformation.VerticalScrollBarArrowHeight;
                            ctl.Bounds = rect;
                        }
                    };
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Factory method for creating the appropriate drop-down control based on the given property descriptor
        /// </summary>
        /// <param name="propertyDescriptor">
        ///     Property descriptor used to create the drop-down.  If the property descriptor supports a UITypeEditor,
        ///     that will be used first.  Otherwise, the type converter will be used.
        /// </param>
        /// <param name="instance">Instance of the object being edited.</param>
        /// <param name="editStyle">
        ///     In the case that a UITypeEditor is used, controls the style of drop-down created.  This
        ///     parameter is not used in the TypeConverter case.
        /// </param>
        /// <returns>A DropDownControl instance if the given property descriptor supports it, null otherwise.</returns>
        internal static TypeEditorHost CreateTypeEditorHost(
            PropertyDescriptor propertyDescriptor, object instance, TypeEditorHostEditControlStyle editControlStyle)
        {
            TypeEditorHost dropDown = null;

            if (propertyDescriptor != null)
            {
                var uiTypeEditor = propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
                if (uiTypeEditor != null) // UITypeEditor case
                {
                    dropDown = new TreeGridDesignerInPlaceEditDropDown(uiTypeEditor, propertyDescriptor, instance, editControlStyle);
                }
                else
                {
                    var converter = propertyDescriptor.Converter;
                    if (converter != null &&
                        converter.GetStandardValuesSupported(null))    // converter case
                    {
                        dropDown = new TreeGridDesignerInPlaceEditCombo(converter, propertyDescriptor, instance, editControlStyle);
                    }
                }
            }

            return(dropDown);
        }
Esempio n. 3
0
        /// <summary>
        /// Factory method for creating the appropriate drop-down control based on the given property descriptor.
        /// If the property descriptor supports a UITypeEditor, a TypeEditorHost will be created with that editor.
        /// If not, and the TypeConverver attached to the PropertyDescriptor supports standard values, a
        /// TypeEditorHostListBox will be created with this TypeConverter.
        /// </summary>
        /// <param name="propertyDescriptor">A property descriptor describing the property being set</param>
        /// <param name="instance">The object instance being edited</param>
        /// <param name="editControlStyle">The type of control to show in the edit area.</param>
        /// <returns>A TypeEditorHost instance if the given property descriptor supports it, null otherwise.</returns>
        public static new TypeEditorHost Create(PropertyDescriptor propertyDescriptor, object instance, TypeEditorHostEditControlStyle editControlStyle)
        {
            TypeEditorHost host = null;

            if (propertyDescriptor != null)
            {
                UITypeEditor editor = propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
                if (editor != null)
                {
                    return(new OnScreenTypeEditorHost(editor, propertyDescriptor, instance, editControlStyle));
                }
                TypeConverter typeConverter = propertyDescriptor.Converter;
                if ((typeConverter != null) && typeConverter.GetStandardValuesSupported(null))
                {
                    host = new OnScreenTypeEditorHostListBox(typeConverter, propertyDescriptor, instance, editControlStyle);
                }
            }
            return(host);
        }
                    /// <summary>
                    /// Select the kind column, activate the edit control, and
                    /// open the dropdown. Implemented as a delayed event so we
                    /// can call it indirectly from CommitLabelEdit.
                    /// </summary>
                    /// <param name="sender">VirtualTreeControl</param>
                    /// <param name="e">EventArgs</param>
                    private static void DelayActivateKindDropdown(object sender, EventArgs e)
                    {
                        VirtualTreeControl control = (VirtualTreeControl)sender;

                        Debug.Assert(!control.InLabelEdit);                         // Fires after a CommitLabelEdit, the control will be closed

                        // We only care on the first call
                        control.LabelEditControlChanged -= new EventHandler(DelayActivateKindDropdown);

                        // Select the correct column, launch the label edit control, then
                        // activate it by opening the dropdown
                        control.CurrentColumn = (int)Columns.ReferenceModeKind;
                        control.BeginLabelEdit();
                        if (control.InLabelEdit)
                        {
                            TypeEditorHost hostControl = control.LabelEditControl as TypeEditorHost;
                            if (hostControl != null)
                            {
                                hostControl.OpenDropDown();
                            }
                        }
                    }
Esempio n. 5
0
        public VirtualTreeLabelEditData BeginLabelEdit(int row, int column, VirtualTreeLabelEditActivationStyles activationStyle)
        {
            if (column != 1)
            {
                return(VirtualTreeLabelEditData.Invalid);
            }
            if (m_ReadOnly)
            {
                return(VirtualTreeLabelEditData.Invalid);
            }
            MemberInfo memberInfo             = m_Parameters[row];
            VirtualTreeLabelEditData @default = VirtualTreeLabelEditData.Default;

            if (memberInfo.Member.IsClass)
            {
                ChoiceContainer choiceContainer = new ChoiceContainer(this, row, column);
                ChoiceConverter.StaticChoices = new[] { NULL_VALUE_TEXT, memberInfo.Member.Type.FullName };
                PropertyDescriptor propertyDescriptor2 = TypeDescriptor.GetProperties(choiceContainer)["Choice"];
                @default.CustomInPlaceEdit = TypeEditorHost.Create(propertyDescriptor2, choiceContainer);
            }

            return(@default);
        }
 VirtualTreeLabelEditData IBranch.BeginLabelEdit(int row, int column, VirtualTreeLabelEditActivationStyles activationStyle)
 {
     if (column == (int)Columns.ReferenceModeKind)
     {
         ModelElement element = myCustomReferenceModesList[row];
         if (element.Store == null)
         {
             // Teardown scenario
             return(VirtualTreeLabelEditData.Invalid);
         }
         PropertyDescriptor descriptor  = ReferenceModeTypeDescriptor.KindDisplayPropertyDescriptor;
         TypeEditorHost     hostControl = OnScreenTypeEditorHost.Create(descriptor, element, TypeEditorHostEditControlStyle.TransparentEditRegion);
         hostControl.Flags = VirtualTreeInPlaceControlFlags.DisposeControl | VirtualTreeInPlaceControlFlags.SizeToText | VirtualTreeInPlaceControlFlags.DrawItemText | VirtualTreeInPlaceControlFlags.ForwardKeyEvents;
         return(new VirtualTreeLabelEditData(hostControl));
     }
     else if (0 != (activationStyle & VirtualTreeLabelEditActivationStyles.ImmediateSelection))
     {
         return(VirtualTreeLabelEditData.DeferActivation);
     }
     else if (row == myCustomReferenceModesList.Count)
     {
         return(new VirtualTreeLabelEditData(""));
     }
     else if (column == (int)Columns.Name)
     {
         return(VirtualTreeLabelEditData.Default);
     }
     else if (column == (int)Columns.FormatString)
     {
         CustomReferenceMode mode = myCustomReferenceModesList[row];
         if (mode.Kind.ReferenceModeType != ReferenceModeType.General || mode.CustomFormatString != "{1}")
         {
             return(new VirtualTreeLabelEditData(PrettyFormatString(mode, true)));
         }
     }
     return(VirtualTreeLabelEditData.Invalid);
 }
Esempio n. 7
0
		/// <summary>
		/// Attach a callback even to move the
		/// </summary>
		private static void AttachDropdownActivator(TypeEditorHost host)
		{
			if (!myRetrievedField)
			{
				System.Threading.Interlocked.CompareExchange<FieldInfo>(
					ref myDropdownHolderField,
					typeof(TypeEditorHost).GetField("dropDownHolder", BindingFlags.NonPublic | BindingFlags.Instance),
					null);
				myRetrievedField = true;
			}
			FieldInfo dropDownHolderField = myDropdownHolderField;
			if (dropDownHolderField != null)
			{
				Form form = dropDownHolderField.GetValue(host) as Form;
				if (form != null)
				{
					form.Activated += delegate(object sender, EventArgs e2)
					{
						Control ctl = (Control)sender;
						Rectangle rect = ctl.Bounds;
						Screen screen = Screen.FromControl(ctl);
						int testLeft;
						if ((screen != null) && ((rect.X - rect.Width / 3) < (testLeft = screen.WorkingArea.Left)))
						{
							// With the size bar always on the left we want to leave room
							// to resize the dropdown. Anchor it on the left edge of the
							// dropdown button instead of the default right edge.
							rect.X = rect.Right - SystemInformation.VerticalScrollBarArrowHeight;
							ctl.Bounds = rect;
						}
					};
				}
			}
		}