void ExecutePaste(object sender, EventArgs e) { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host != null) { IDesignerSerializationService dss = (IDesignerSerializationService)this.GetService(typeof(IDesignerSerializationService)); if (dss != null) { object v = System.Windows.Forms.Clipboard.GetData("DesignObject"); if (v != null) { ICollection cc = dss.Deserialize(v); if (cc != null) { using (DesignerTransaction trans = host.CreateTransaction("Paste")) { foreach (object x in cc) { if (x is IComponent) { host.Container.Add((IComponent)x); } } ISelectionService selSvc = (ISelectionService)GetService(typeof(ISelectionService)); if (selSvc != null) { selSvc.SetSelectedComponents(cc, SelectionTypes.Replace); } trans.Commit(); enableUndoMenu(); } } } } } }
private void OnDeleteTab(object sender, EventArgs e) { if ((_ribbonTab != null) && (_ribbonTab.Ribbon != null) && _ribbonTab.Ribbon.RibbonTabs.Contains(_ribbonTab)) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonTab DeleteTab"); try { // Get access to the RibbonTabs property MemberDescriptor propertyTabs = TypeDescriptor.GetProperties(_ribbonTab.Ribbon)["RibbonTabs"]; // Remove the ribbon tab from the ribbon RaiseComponentChanging(null); RaiseComponentChanging(propertyTabs); // Remove the page from the ribbon _ribbonTab.Ribbon.RibbonTabs.Remove(_ribbonTab); // Get designer to destroy it _designerHost.DestroyComponent(_ribbonTab); RaiseComponentChanged(propertyTabs, null, null); RaiseComponentChanged(null, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
/// <summary> /// This performs the actual drop, which just moves all of our components /// to the drop location. /// </summary> /// <param name="x"></param> /// <param name="y"></param> public void Drop(int x, int y) { System.Console.WriteLine("\tDragObject:Drop"); ClearFeedback(); Point pt = new Point(x, y); pt = m_dragControl.PointToClient(pt); x = pt.X - m_initialX; y = pt.Y - m_initialY; // If we have more than one shape, we need to wrap // in a designer transaction. // if (m_dragShapes.Count > 1) { IDesignerHost host = this.m_designer.Host; if (host != null) { using (DesignerTransaction trans = host.CreateTransaction("Drag " + m_dragShapes.Count + " components")) { foreach (ItemDesigner sd in m_dragShapes) { sd.Drag(m_hitObject, x, y); } trans.Commit(); } } } else { foreach (ItemDesigner sd in m_dragShapes) { sd.Drag(m_hitObject, x, y); } } }
private void OnMoveNext(object sender, EventArgs e) { if ((_ribbonTab != null) && (_ribbonTab.Ribbon != null) && _ribbonTab.Ribbon.RibbonTabs.Contains(_ribbonTab)) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonTab MovePrevious"); try { // Get access to the RibbonTabs property MemberDescriptor propertyTabs = TypeDescriptor.GetProperties(_ribbonTab.Ribbon)["RibbonTabs"]; RaiseComponentChanging(propertyTabs); // Move position of the tab KryptonRibbon ribbon = _ribbonTab.Ribbon; int index = ribbon.RibbonTabs.IndexOf(_ribbonTab) + 1; index = Math.Min(index, ribbon.RibbonTabs.Count - 1); ribbon.RibbonTabs.Remove(_ribbonTab); ribbon.RibbonTabs.Insert(index, _ribbonTab); ribbon.SelectedTab = _ribbonTab; UpdateVerbStatus(); RaiseComponentChanged(propertyTabs, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
private void OnDeleteTrackBar(object sender, EventArgs e) { if ((_ribbonTrackBar != null) && (_ribbonTrackBar.Ribbon != null)) { // Get access to the parent collection of items TypedRestrictCollection <KryptonRibbonGroupItem> items = ParentItems; // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupTrackBar DeleteTrackBar"); try { // Get access to the Items property MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonTrackBar.RibbonContainer)["Items"]; RaiseComponentChanging(null); RaiseComponentChanging(propertyItems); // Remove the trackbar from the group items.Remove(_ribbonTrackBar); // Get designer to destroy it _designerHost.DestroyComponent(_ribbonTrackBar); RaiseComponentChanged(propertyItems, null, null); RaiseComponentChanged(null, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
private void OnDeleteGallery(object sender, EventArgs e) { if ((_ribbonGallery != null) && (_ribbonGallery.Ribbon != null) && _ribbonGallery.RibbonGroup.Items.Contains(_ribbonGallery)) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupGallery DeleteGallery"); try { // Get access to the Items property MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonGallery.RibbonGroup)["Items"]; // Remove the ribbon group from the ribbon tab RaiseComponentChanging(null); RaiseComponentChanging(propertyItems); // Remove the gallery from the group _ribbonGallery.RibbonGroup.Items.Remove(_ribbonGallery); // Get designer to destroy it _designerHost.DestroyComponent(_ribbonGallery); RaiseComponentChanged(propertyItems, null, null); RaiseComponentChanged(null, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
private void OnClearItems(object sender, EventArgs e) { if ((_ribbonCluster != null) && (_ribbonCluster.Ribbon != null)) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupCluster ClearItems"); try { // Get access to the Items property MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonCluster)["Items"]; RaiseComponentChanging(propertyItems); // Need access to host in order to delete a component IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); // We need to remove all the buttons from the cluster group for (int i = _ribbonCluster.Items.Count - 1; i >= 0; i--) { KryptonRibbonGroupItem item = _ribbonCluster.Items[i]; _ribbonCluster.Items.Remove(item); host.DestroyComponent(item); } RaiseComponentChanged(propertyItems, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
private void OnMoveNext(object sender, EventArgs e) { if ((_ribbonGallery != null) && (_ribbonGallery.Ribbon != null) && _ribbonGallery.RibbonGroup.Items.Contains(_ribbonGallery)) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupGallery MoveNext"); try { // Get access to the Items property MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonGallery.RibbonGroup)["Items"]; RaiseComponentChanging(propertyItems); // Move position of the gallery KryptonRibbonGroup ribbonGroup = _ribbonGallery.RibbonGroup; int index = ribbonGroup.Items.IndexOf(_ribbonGallery) + 1; index = Math.Min(index, ribbonGroup.Items.Count - 1); ribbonGroup.Items.Remove(_ribbonGallery); ribbonGroup.Items.Insert(index, _ribbonGallery); UpdateVerbStatus(); RaiseComponentChanged(propertyItems, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
private void OnMovePrevious(object sender, EventArgs e) { if ((_ribbonCluster != null) && (_ribbonCluster.Ribbon != null)) { // Cast container to the correct type KryptonRibbonGroupLines lines = (KryptonRibbonGroupLines)_ribbonCluster.RibbonContainer; // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupCluster MovePrevious"); try { // Get access to the Items property MemberDescriptor propertyItems = TypeDescriptor.GetProperties(lines)["Items"]; RaiseComponentChanging(propertyItems); // Move position of the cluster int index = lines.Items.IndexOf(_ribbonCluster) - 1; index = Math.Max(index, 0); lines.Items.Remove(_ribbonCluster); lines.Items.Insert(index, _ribbonCluster); UpdateVerbStatus(); RaiseComponentChanged(propertyItems, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
private void OnAddLabel(object sender, System.EventArgs e) { if (m_owner == null) { return; } Label label = m_owner.Label; if (label == null) { IDesignerHost h = (IDesignerHost)GetService(typeof(IDesignerHost)); DesignerTransaction dt = h.CreateTransaction("Add MyLabel"); IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService)); label = (MyLabel)h.CreateComponent(typeof(MyLabel)); label.Text = "БъЬт"; c.OnComponentChanging(m_owner, null); m_owner.Label = label; c.OnComponentChanged(m_owner, null, null, null); dt.Commit(); m_owner.ResetLayout(); } }
public override void ResetValue(object component) { object invokee = MemberDescriptor.GetInvokee(_componentType, component); DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)Attributes[typeof(DefaultValueAttribute)]; if (defaultValueAttribute != null) { SetValue(invokee, defaultValueAttribute.Value); } DesignerTransaction tran = CreateTransaction(component, "Reset Property '" + Name + "'"); object value = GetValue(invokee); try { FindPropertyMethod(invokee, "Reset")?.Invoke(invokee, null); EndTransaction(component, tran, value, GetValue(invokee), commit: true); } catch { EndTransaction(component, tran, value, GetValue(invokee), commit: false); throw; IL_00a9 :; } }
private void OnClearPages(object sender, EventArgs e) { if (MessageBox.Show("Are you sure that all pages should be removed?", "Clear Pages", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonNavigator RemovePage"); try { // Get access to the Pages property MemberDescriptor propertyPages = TypeDescriptor.GetProperties(_navigator)["Pages"]; // Remove all pages from the navigator RaiseComponentChanging(propertyPages); // Get the designer to destroy each page in turn for (int i = _navigator.Pages.Count; i > 0; i--) { _designerHost.DestroyComponent(_navigator.Pages[0]); } RaiseComponentChanged(propertyPages, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
private void AddDataControl(System.Type type) { if (m_owner == null) { return; } System.Windows.Forms.Control control = m_owner.Control; if (control != null) { m_owner.Control = null; control.Dispose(); } IDesignerHost h = (IDesignerHost)GetService(typeof(IDesignerHost)); DesignerTransaction dt = h.CreateTransaction("Add DataControl"); IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService)); control = (System.Windows.Forms.Control)h.CreateComponent(type); c.OnComponentChanging(m_owner, null); m_owner.Control = control; c.OnComponentChanged(m_owner, null, null, null); dt.Commit(); }
private void OnMovePrevious(object sender, EventArgs e) { if ((_ribbonGroup != null) && (_ribbonGroup.Ribbon != null) && _ribbonGroup.RibbonTab.Groups.Contains(_ribbonGroup)) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroup MovePrevious"); try { // Get access to the Group property MemberDescriptor propertyGroups = TypeDescriptor.GetProperties(_ribbonGroup.RibbonTab)["Groups"]; RaiseComponentChanging(propertyGroups); // Move position of the group KryptonRibbonTab ribbonTab = _ribbonGroup.RibbonTab; int index = ribbonTab.Groups.IndexOf(_ribbonGroup) - 1; index = Math.Max(index, 0); ribbonTab.Groups.Remove(_ribbonGroup); ribbonTab.Groups.Insert(index, _ribbonGroup); UpdateVerbStatus(); RaiseComponentChanged(propertyGroups, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
//protected void OnActivate(object s, EventArgs e) {} public override void InitializeNewComponent(System.Collections.IDictionary defaultValues) { base.InitializeNewComponent(defaultValues); if (DesignerHost != null) { DesignerTransaction trans = DesignerHost.CreateTransaction( "Adding Syntaxdocument"); var sd = DesignerHost.CreateComponent (typeof(SyntaxDocument)) as SyntaxDocument; var sb = Control as SyntaxBoxControl; if (sb == null) { trans.Cancel(); } else { sb.Document = sd; trans.Commit(); } } }
private void OnAddTabPanel() { IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); if (host != null) { TabContainer tc = TabContainer; using (DesignerTransaction dt = host.CreateTransaction("Add new TabPanel")) { TabPanel tp = (TabPanel)host.CreateComponent(typeof(TabPanel)); if (tp != null) { // set up the inital state // tp.ID = GetUniqueName(typeof(TabPanel), tc); tp.HeaderText = tp.ID; IComponentChangeService changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); try { changeService.OnComponentChanging(tc, TypeDescriptor.GetProperties(tc)["Tabs"]); tc.Tabs.Add(tp); } finally { changeService.OnComponentChanged(tc, TypeDescriptor.GetProperties(tc)["Tabs"], tc.Tabs, tc.Tabs); } TypeDescriptor.GetProperties(tc)["ActiveTab"].SetValue(tc, tp); CurrentTabID = tp.ID; } dt.Commit(); } } }
private void OnClearGroups(object sender, EventArgs e) { if ((_ribbonTab != null) && (_ribbonTab.Ribbon != null) && _ribbonTab.Ribbon.RibbonTabs.Contains(_ribbonTab)) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonTab ClearGroups"); try { // Get access to the Groups property MemberDescriptor propertyGroups = TypeDescriptor.GetProperties(_ribbonTab)["Groups"]; RaiseComponentChanging(propertyGroups); // Need access to host in order to delete a component IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); // We need to remove all the groups from the tab for (int i = _ribbonTab.Groups.Count - 1; i >= 0; i--) { KryptonRibbonGroup group = _ribbonTab.Groups[i]; _ribbonTab.Groups.Remove(group); host.DestroyComponent(group); } RaiseComponentChanged(propertyGroups, null, null); } finally { // If we managed to create the transaction, then do it transaction?.Commit(); } } }
protected override void OnDragDrop(DragEventArgs drgevent) { if (drgevent.Effect == DragDropEffects.Copy) { (designerHost.RootComponent as Control).SuspendLayout(); IToolboxService tbsvc = designerHost.GetService(typeof(IToolboxService)) as IToolboxService; IToolboxUser tbu = designerHost.GetDesigner(designerHost.RootComponent) as IToolboxUser; ISelectionService selsvc = designerHost.GetService(typeof(ISelectionService)) as ISelectionService; DesignerTransaction transaction = designerHost.CreateTransaction("DoDragDrop"); //避免当前有选中控件,会把新创建的控件放到选中控件中 selsvc.SetSelectedComponents(null); ToolboxItem item = drgevent.Data.GetData(typeof(ToolboxItem)) as ToolboxItem; tbu.ToolPicked(item); ICollection components = item.CreateComponents(); tbsvc.SelectedToolboxItemUsed(); Control createdControl = selsvc.PrimarySelection as Control; Point location1 = PointToScreen(this.Location); createdControl.Location = new Point(drgevent.X - location1.X + this.Left, drgevent.Y - location1.Y + this.Top); selsvc.SetSelectedComponents(null); selsvc.SetSelectedComponents(new Control[] { createdControl }); transaction.Commit(); ((IDisposable)transaction).Dispose(); (designerHost.RootComponent as Control).ResumeLayout(); } else { base.OnDragDrop(drgevent); } }
private void OnClearTabs(object sender, EventArgs e) { // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbon ClearTabs"); try { // Get access to the tabs property MemberDescriptor propertyPages = TypeDescriptor.GetProperties(_ribbon)["RibbonTabs"]; RaiseComponentChanging(propertyPages); // Need access to host in order to delete a component IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); // We need to remove all the tabs from the ribbon for (int i = _ribbon.RibbonTabs.Count - 1; i >= 0; i--) { KryptonRibbonTab tab = _ribbon.RibbonTabs[i]; _ribbon.RibbonTabs.Remove(tab); host.DestroyComponent(tab); } RaiseComponentChanged(propertyPages, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } UpdateVerbStatus(); } }
private void OnMoveNext(object sender, EventArgs e) { if (_ribbonButton?.Ribbon != null) { // Cast container to the correct type KryptonRibbonGroupCluster cluster = (KryptonRibbonGroupCluster)_ribbonButton.RibbonContainer; // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupClusterButton MoveNext"); try { // Get access to the Items property MemberDescriptor propertyItems = TypeDescriptor.GetProperties(cluster)["Items"]; RaiseComponentChanging(propertyItems); // Move position of the triple int index = cluster.Items.IndexOf(_ribbonButton) + 1; index = Math.Min(index, cluster.Items.Count - 1); cluster.Items.Remove(_ribbonButton); cluster.Items.Insert(index, _ribbonButton); UpdateVerbStatus(); RaiseComponentChanged(propertyItems, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
// container coordinates // public void DragDrop(bool cancel, Control container, int x, int y) { // Console.WriteLine ("UISelectionService.DragDrop: in " + container.Site.Name); if (_dragging) { int dx = x - _prevMousePosition.X; int dy = y - _prevMousePosition.Y; MoveSelection(container, dx, dy); _dragging = false; // Repaint everything // IDesignerHost host = this.GetService(typeof(IDesignerHost)) as IDesignerHost; if (host != null && host.RootComponent != null) { ((Control)host.RootComponent).Refresh(); } // Send mouse up message to the primary selection // Else for parentcontroldesigner there is no mouseup event and it doesn't set allow drop back to false // Native.SendMessage(((Control)this.SelectionService.PrimarySelection).Handle, Native.Msg.WM_LBUTTONUP, (IntPtr)0, (IntPtr)0); if (_transaction != null) { if (cancel) { _transaction.Cancel(); } else { _transaction.Commit(); } _transaction = null; } } }
internal static void SetValue(IComponent component, string propertyName, object value) { PropertyDescriptor propertyDescriptor = GetPropertyDescriptor(component, propertyName); IComponentChangeService svc = GetChangeService(component); IDesignerHost host = GetDesignerHost(component); DesignerTransaction txn = host.CreateTransaction(); try { svc.OnComponentChanging(component, propertyDescriptor); propertyDescriptor.SetValue(component, value); svc.OnComponentChanged(component, propertyDescriptor, null, null); txn.Commit(); txn = null; } finally { if (txn != null) { txn.Cancel(); } } }
internal override bool NotifyChildValue(GridEntry pe, int type) { bool success = false; IDesignerHost host = DesignerHost; DesignerTransaction trans = null; if (host != null) { trans = host.CreateTransaction(); } try { success = base.NotifyChildValue(pe, type); } finally { if (trans != null) { trans.Commit(); } } return(success); }
private void OnMoveNext(object sender, EventArgs e) { if ((_ribbonColorButton != null) && (_ribbonColorButton.Ribbon != null)) { // Get access to the parent collection of items TypedRestrictCollection <KryptonRibbonGroupItem> items = ParentItems; // Use a transaction to support undo/redo actions DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupColorButton MoveNext"); try { // Get access to the Items property MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonColorButton.RibbonContainer)["Items"]; RaiseComponentChanging(propertyItems); // Move position of the triple int index = items.IndexOf(_ribbonColorButton) + 1; index = Math.Min(index, items.Count - 1); items.Remove(_ribbonColorButton); items.Insert(index, _ribbonColorButton); UpdateVerbStatus(); RaiseComponentChanged(propertyItems, null, null); } finally { // If we managed to create the transaction, then do it if (transaction != null) { transaction.Commit(); } } } }
/// <summary> /// this method is called when dragging a TabStrip off the toolbox. /// </summary> /// <param name="host"></param> /// <returns></returns> protected override IComponent[] CreateComponentsCore(IDesignerHost host) { IComponent[] components = base.CreateComponentsCore(host); Control parentControl = null; ControlDesigner parentControlDesigner = null; TabStrip tabStrip = null; IComponentChangeService changeSvc = (IComponentChangeService)host.GetService(typeof(IComponentChangeService)); // fish out the parent we're adding the TabStrip to. if (components.Length > 0 && components[0] is TabStrip) { tabStrip = components[0] as TabStrip; ITreeDesigner tabStripDesigner = host.GetDesigner(tabStrip) as ITreeDesigner; parentControlDesigner = tabStripDesigner.Parent as ControlDesigner; if (parentControlDesigner != null) { parentControl = parentControlDesigner.Control; } } // Create a ControlSwitcher on the same parent. if (host != null) { TabPageSwitcher controlSwitcher = null; DesignerTransaction t = null; try { try { t = host.CreateTransaction("add tabswitcher"); } catch (CheckoutException ex) { if (ex == CheckoutException.Canceled) { return(components); } throw ex; } // create a TabPageSwitcher and add it to the same parent as the TabStrip MemberDescriptor controlsMember = TypeDescriptor.GetProperties(parentControlDesigner)["Controls"]; controlSwitcher = host.CreateComponent(typeof(TabPageSwitcher)) as TabPageSwitcher; if (changeSvc != null) { changeSvc.OnComponentChanging(parentControl, controlsMember); changeSvc.OnComponentChanged(parentControl, controlsMember, null, null); } // specify default values for our TabStrip Dictionary <string, object> propertyValues = new Dictionary <string, object>(); propertyValues["Location"] = new Point(tabStrip.Left, tabStrip.Bottom + 3); propertyValues["TabStrip"] = tabStrip; // set the property values SetProperties(controlSwitcher, propertyValues, host); } finally { if (t != null) { t.Commit(); } } // add the TabPageSwitcher to the list of components that we've created if (controlSwitcher != null) { IComponent[] newComponents = new IComponent[components.Length + 1]; Array.Copy(components, newComponents, components.Length); newComponents[newComponents.Length - 1] = controlSwitcher; return(newComponents); } } return(components); }
internal override bool NotifyValueGivenParent(object obj, int type) { if (obj is ICustomTypeDescriptor) { obj = ((ICustomTypeDescriptor)obj).GetPropertyOwner(_propertyInfo); } switch (type) { case NOTIFY_RESET: object[] objects = (object[])obj; if (objects != null && objects.Length > 0) { IDesignerHost host = DesignerHost; DesignerTransaction trans = null; if (host != null) { trans = host.CreateTransaction(string.Format(SR.PropertyGridResetValue, PropertyName)); } try { bool needChangeNotify = !(objects[0] is IComponent) || ((IComponent)objects[0]).Site is null; if (needChangeNotify) { if (!OnComponentChanging()) { if (trans != null) { trans.Cancel(); trans = null; } return(false); } } mergedPd.ResetValue(obj); if (needChangeNotify) { OnComponentChanged(); } NotifyParentChange(this); } finally { if (trans != null) { trans.Commit(); } } } return(false); case NOTIFY_DBL_CLICK: case NOTIFY_RETURN: Debug.Assert(_propertyInfo is MergePropertyDescriptor, "Did not get a MergePropertyDescriptor!!!"); Debug.Assert(obj is object[], "Did not get an array of objects!!"); if (_propertyInfo is MergePropertyDescriptor mpd) { object[] objs = (object[])obj; if (_eventBindings is null) { _eventBindings = (IEventBindingService)GetService(typeof(IEventBindingService)); } if (_eventBindings != null) { EventDescriptor descriptor = _eventBindings.GetEvent(mpd[0]); if (descriptor != null) { return(ViewEvent(obj, null, descriptor, true)); } } return(false); } else { return(base.NotifyValueGivenParent(obj, type)); } } return(base.NotifyValueGivenParent(obj, type)); }
/// <summary> /// When the verb is invoked, change the parent of the ToolStrip. /// </summary> // This is actually called... public void ChangeParent() { Cursor current = Cursor.Current; // create a transaction so this happens as an atomic unit. DesignerTransaction changeParent = _host.CreateTransaction("Add ToolStripContainer Transaction"); try { Cursor.Current = Cursors.WaitCursor; //Add a New ToolStripContainer to the RootComponent ... Control root = _host.RootComponent as Control; if (_host.GetDesigner(root) is ParentControlDesigner rootDesigner) { // close the DAP first - this is so that the autoshown panel on drag drop here is not conflicting with the currently opened panel // if the verb was called from the panel ToolStrip toolStrip = _designer.Component as ToolStrip; if (toolStrip != null && _designer != null && _designer.Component != null && _provider != null) { DesignerActionUIService dapuisvc = _provider.GetService(typeof(DesignerActionUIService)) as DesignerActionUIService; dapuisvc.HideUI(toolStrip); } // Get OleDragHandler ... ToolboxItem tbi = new ToolboxItem(typeof(ToolStripContainer)); OleDragDropHandler ddh = rootDesigner.GetOleDragHandler(); if (ddh != null) { IComponent[] newComp = ddh.CreateTool(tbi, root, 0, 0, 0, 0, false, false); if (newComp[0] is ToolStripContainer tsc) { if (toolStrip != null) { var changeService = _provider.GetService <IComponentChangeService>(); Control newParent = GetParent(tsc, toolStrip); PropertyDescriptor controlsProp = TypeDescriptor.GetProperties(newParent)["Controls"]; Control oldParent = toolStrip.Parent; if (oldParent != null) { changeService.OnComponentChanging(oldParent, controlsProp); //remove control from the old parent oldParent.Controls.Remove(toolStrip); } if (newParent != null) { changeService.OnComponentChanging(newParent, controlsProp); //finally add & relocate the control with the new parent newParent.Controls.Add(toolStrip); } //fire our comp changed events if (changeService != null && oldParent != null && newParent != null) { changeService.OnComponentChanged(oldParent, controlsProp); changeService.OnComponentChanged(newParent, controlsProp); } //Set the Selection on the new Parent ... so that the selection is restored to the new item, if (_provider.GetService(typeof(ISelectionService)) is ISelectionService selSvc) { selSvc.SetSelectedComponents(new IComponent[] { tsc }); } } } } } } catch (Exception e) { if (e is InvalidOperationException) { IUIService uiService = (IUIService)_provider.GetService(typeof(IUIService)); uiService.ShowError(e.Message); } if (changeParent != null) { changeParent.Cancel(); changeParent = null; } } finally { if (changeParent != null) { changeParent.Commit(); } Cursor.Current = current; } }
protected override bool OnDragDrop(DragEventArgs eventArgs) { //Invalidate the entire rectangle so that we draw active placement glyphs on connectors WorkflowView parentView = ParentView; parentView.InvalidateClientRectangle(Rectangle.Empty); //By default we do not allow any drag drop operation eventArgs.Effect = DragDropEffects.None; DestroyDragFeedbackImages(); //Get the coordinates Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); //Now we check if the drag drop was in any valid area, if not then do not proceed further if (!parentView.IsClientPointInActiveLayout(clientPoint)) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.wasCtrlKeyPressed = false; this.dropTargetDesigner = null; this.draggedActivities.Clear(); return(false); } //Now we have a potential for successful drag drop, so construct drag event arguments with logical coordinates this.wasCtrlKeyPressed = ((eventArgs.KeyState & 8) == 8); ActivityDragEventArgs dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, this.draggedActivities); //Now check which designer is under the cursor, if we have the same designer as the old one //If not then we set the new one as drop target and pump in messages HitTestInfo hitTestInfo = MessageHitTestContext; if (this.dropTargetDesigner != hitTestInfo.AssociatedDesigner) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); this.dropTargetDesigner = null; } if (hitTestInfo.AssociatedDesigner != null) { this.dropTargetDesigner = hitTestInfo.AssociatedDesigner; if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(dragdropEventArgs); } } } //We now have appropriate droptarget designer try { if (this.dropTargetDesigner != null) { //We do not allow recursive drag and drop if (!this.wasCtrlKeyPressed && IsRecursiveDropOperation(this.dropTargetDesigner) || (this.dropTargetDesigner is CompositeActivityDesigner && !((CompositeActivityDesigner)this.dropTargetDesigner).IsEditable)) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); dragdropEventArgs.Effect = DragDropEffects.None; } else { // IMPORTANT: Don't use draggedActivities variable, because components which are // there may not be created using the assembly references added to ITypeResultionService // this.workflowView.time the components will be created using the assembly references got added to the project List <Activity> droppedActivities = new List <Activity>(); string transactionDescription = SR.GetString(SR.DragDropActivities); //This means that we are trying to move activities so we use the same activities for drop if (!this.wasCtrlKeyPressed && this.existingDraggedActivities.Count > 0) { droppedActivities.AddRange(this.existingDraggedActivities); if (droppedActivities.Count > 1) { transactionDescription = SR.GetString(SR.MoveMultipleActivities, droppedActivities.Count); } else if (droppedActivities.Count == 1) { transactionDescription = SR.GetString(SR.MoveSingleActivity, droppedActivities[0].GetType()); } } else { droppedActivities.AddRange(CompositeActivityDesigner.DeserializeActivitiesFromDataObject(ParentView, eventArgs.Data, true)); if (droppedActivities.Count > 0) { transactionDescription = SR.GetString(SR.CreateActivityFromToolbox, droppedActivities[0].GetType()); } } //Now that we have what needs to be dropped, we start the actual drag and drop IDesignerHost designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if (droppedActivities.Count > 0) { transaction = designerHost.CreateTransaction(transactionDescription); } dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, droppedActivities); try { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragDrop(dragdropEventArgs); if (dragdropEventArgs.Effect == DragDropEffects.Move) { this.existingDraggedActivities.Clear(); } if (transaction != null) { transaction.Commit(); } } catch (Exception e) { if (transaction != null) { transaction.Cancel(); } throw e; } //We deserialize the designers and try to store the designer states if (droppedActivities.Count > 0) { Stream componentStateStream = eventArgs.Data.GetData(DragDropManager.CF_DESIGNERSTATE) as Stream; if (componentStateStream != null) { Helpers.DeserializeDesignersFromStream(droppedActivities, componentStateStream); } //Set the current selection ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService)); if (selectionService != null) { selectionService.SetSelectedComponents(droppedActivities, SelectionTypes.Replace); } } //Active the design surface if (designerHost != null) { designerHost.Activate(); } } } } catch (Exception ex) { //We purposely consume application thrown exception which are result of user cancelling the action //during dragdrop where we popup UI Wizards during drag drop. Ref: InvokeWebService ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); dragdropEventArgs.Effect = DragDropEffects.None; string dragDropException = ex.Message; if (ex.InnerException != null && !String.IsNullOrEmpty(ex.InnerException.Message)) { dragDropException = ex.InnerException.Message; } string errorMessage = DR.GetString(DR.Error_FailedToDeserializeComponents); errorMessage += "\r\n" + DR.GetString(DR.Error_Reason, dragDropException); DesignerHelpers.ShowError(ParentView, errorMessage); if (ex != CheckoutException.Canceled) { throw new Exception(errorMessage, ex); } } finally { //Make sure that mouse over designer is set to null this.wasCtrlKeyPressed = false; this.draggedActivities.Clear(); this.dropTargetDesigner = null; this.exceptionInDragDrop = false; eventArgs.Effect = dragdropEventArgs.Effect; } return(true); }
public void DoOleDragDrop(DragEventArgs de) { // ASURT 43757: By the time we come here, it means that the user completed the drag-drop and // we compute the new location/size of the controls if needed and set the property values. // We have to stop freezePainting right here, so that controls can get a chance to validate // their new rects. // freezePainting = false; if (selectionHandler == null) { Debug.Fail("selectionHandler should not be null"); de.Effect = DragDropEffects.None; return; } // make sure we've actually moved if ((localDrag && de.X == dragBase.X && de.Y == dragBase.Y) || de.AllowedEffect == DragDropEffects.None || (!localDrag && !dragOk)) { de.Effect = DragDropEffects.None; return; } bool localMoveOnly = ((int)de.AllowedEffect & AllowLocalMoveOnly) != 0 && localDragInside; // if we are dragging inside the local dropsource/target, and and AllowLocalMoveOnly flag is set, // we just consider this a normal move. // bool moveAllowed = (de.AllowedEffect & DragDropEffects.Move) != DragDropEffects.None || localMoveOnly; bool copyAllowed = (de.AllowedEffect & DragDropEffects.Copy) != DragDropEffects.None; if ((de.Effect & DragDropEffects.Move) != 0 && !moveAllowed) { // Try copy instead? de.Effect = DragDropEffects.Copy; } // make sure the copy is allowed if ((de.Effect & DragDropEffects.Copy) != 0 && !copyAllowed) { // if copy isn't allowed, don't do anything de.Effect = DragDropEffects.None; return; } if (localMoveOnly && (de.Effect & DragDropEffects.Move) != 0) { de.Effect |= (DragDropEffects)AllowLocalMoveOnly | DragDropEffects.Move; } else if ((de.Effect & DragDropEffects.Copy) != 0) { de.Effect = DragDropEffects.Copy; } if (forceDrawFrames || localDragInside) { // undraw the drag rect localDragOffset = DrawDragFrames(dragComps, localDragOffset, localDragEffect, Point.Empty, DragDropEffects.None, forceDrawFrames); forceDrawFrames = false; } Cursor oldCursor = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; if (dragOk || (localDragInside && de.Effect == DragDropEffects.Copy)) { // add em to this parent. IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); IContainer container = host.RootComponent.Site.Container; object[] components; IDataObject dataObj = de.Data; bool updateLocation = false; if (dataObj is ComponentDataObjectWrapper) { dataObj = ((ComponentDataObjectWrapper)dataObj).InnerData; ComponentDataObject cdo = (ComponentDataObject)dataObj; // if we're moving ot a different container, do a full serialization // to make sure we pick up design time props, etc. // IComponent dragOwner = GetDragOwnerComponent(de.Data); bool newContainer = dragOwner == null || client.Component == null || dragOwner.Site.Container != client.Component.Site.Container; bool collapseChildren = false; if (de.Effect == DragDropEffects.Copy || newContainer) { // this causes new elements to be created // cdo.Deserialize(serviceProvider, (de.Effect & DragDropEffects.Copy) == 0); } else { collapseChildren = true; } updateLocation = true; components = cdo.Components; if (collapseChildren) { components = GetTopLevelComponents(components); } } else { object serializationData = dataObj.GetData(DataFormat, true); if (serializationData == null) { Debug.Fail("data object didn't return any data, so how did we allow the drop?"); components = Array.Empty <IComponent>(); } else { dataObj = new ComponentDataObject(client, serviceProvider, serializationData); components = ((ComponentDataObject)dataObj).Components; updateLocation = true; } } // now we need to offset the components locations from the drop mouse // point to the parent, since their current locations are relative // the the mouse pointer if (components != null && components.Length > 0) { Debug.Assert(container != null, "Didn't get a container from the site!"); string name; IComponent comp = null; DesignerTransaction trans = null; try { trans = host.CreateTransaction(SR.DragDropDropComponents); if (!localDrag) { host.Activate(); } ArrayList selectComps = new ArrayList(); for (int i = 0; i < components.Length; i++) { comp = components[i] as IComponent; if (comp == null) { comp = null; continue; } try { name = null; if (comp.Site != null) { name = comp.Site.Name; } Control oldDesignerControl = null; if (updateLocation) { oldDesignerControl = client.GetDesignerControl(); User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW); } Point dropPt = client.GetDesignerControl().PointToClient(new Point(de.X, de.Y)); // First check if the component we are dropping have a TrayLocation, and if so, use it PropertyDescriptor loc = TypeDescriptor.GetProperties(comp)["TrayLocation"]; if (loc == null) { // it didn't, so let's check for the regular Location loc = TypeDescriptor.GetProperties(comp)["Location"]; } if (loc != null && !loc.IsReadOnly) { Rectangle bounds = new Rectangle(); Point pt = (Point)loc.GetValue(comp); bounds.X = dropPt.X + pt.X; bounds.Y = dropPt.Y + pt.Y; bounds = selectionHandler.GetUpdatedRect(Rectangle.Empty, bounds, false); } if (!client.AddComponent(comp, name, false)) { // this means that we just moved the control // around in the same designer. de.Effect = DragDropEffects.None; } else { // make sure the component was added to this client if (client.GetControlForComponent(comp) == null) { updateLocation = false; } } if (updateLocation) { ParentControlDesigner parentDesigner = client as ParentControlDesigner; if (parentDesigner != null) { Control c = client.GetControlForComponent(comp); dropPt = parentDesigner.GetSnappedPoint(c.Location); c.Location = dropPt; } } if (oldDesignerControl != null) { //((ComponentDataObject)dataObj).ShowControls(); User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW, (IntPtr)1); oldDesignerControl.Invalidate(true); } if (TypeDescriptor.GetAttributes(comp).Contains(DesignTimeVisibleAttribute.Yes)) { selectComps.Add(comp); } } catch (CheckoutException ceex) { if (ceex == CheckoutException.Canceled) { break; } throw; } } if (host != null) { host.Activate(); } // select the newly added components ISelectionService selService = (ISelectionService)GetService(typeof(ISelectionService)); selService.SetSelectedComponents((object[])selectComps.ToArray(typeof(IComponent)), SelectionTypes.Replace); localDragInside = false; } finally { if (trans != null) { trans.Commit(); } } } } if (localDragInside) { ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService)); Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control"); if (selectionUISvc != null) { // We must check to ensure that UI service is still in drag mode. It is // possible that the user hit escape, which will cancel drag mode. // if (selectionUISvc.Dragging && moveAllowed) { Rectangle offset = new Rectangle(de.X - dragBase.X, de.Y - dragBase.Y, 0, 0); selectionUISvc.DragMoved(offset); } } } dragOk = false; } finally { Cursor.Current = oldCursor; } }
public bool DoBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY) { // if we're in a sizing operation, or the mouse isn't down, don't do this! if ((rules & SelectionRules.AllSizeable) != SelectionRules.None || Control.MouseButtons == MouseButtons.None) { return(true); } Control c = client.GetDesignerControl(); localDrag = true; localDragInside = false; dragComps = components; dragBase = new Point(initialX, initialY); localDragOffset = Point.Empty; c.PointToClient(new Point(initialX, initialY)); DragDropEffects allowedEffects = DragDropEffects.Copy | DragDropEffects.None | DragDropEffects.Move; // check to see if any of the components are inherhited. if so, don't allow them to be moved. // We replace DragDropEffects.Move with a local bit called AllowLocalMoveOnly which means it // can be moved around on the current dropsource/target, but not to another target. Since only // we understand this bit, other drop targets will not allow the move to occur // for (int i = 0; i < components.Length; i++) { InheritanceAttribute attr = (InheritanceAttribute)TypeDescriptor.GetAttributes(components[i])[typeof(InheritanceAttribute)]; if (!attr.Equals(InheritanceAttribute.NotInherited) && !attr.Equals(InheritanceAttribute.InheritedReadOnly)) { allowedEffects &= ~DragDropEffects.Move; allowedEffects |= (DragDropEffects)AllowLocalMoveOnly; } } DataObject data = new ComponentDataObjectWrapper(new ComponentDataObject(client, serviceProvider, components, initialX, initialY)); // We make sure we're painted before we start the drag. Then, we disable window painting to // ensure that the drag can proceed without leaving artifacts lying around. We should be caling LockWindowUpdate, // but that causes a horrible flashing because GDI+ uses direct draw. // User32.MSG msg = default; while (User32.PeekMessageW(ref msg, IntPtr.Zero, User32.WM.PAINT, User32.WM.PAINT, User32.PM.REMOVE).IsTrue()) { User32.TranslateMessage(ref msg); User32.DispatchMessageW(ref msg); } // don't do any new painting... bool oldFreezePainting = freezePainting; // asurt 90345 -- this causes some subtle bugs, so i'm turning it off to see if we really need it, and if we do // if we can find a better way. // //freezePainting = true; AddCurrentDrag(data, client.Component); // Walk through all the children recursively and disable drag-drop // for each of them. This way, we will not accidentally try to drop // ourselves into our own children. // ArrayList allowDropChanged = new ArrayList(); foreach (object comp in components) { Control ctl = comp as Control; if (ctl != null && ctl.HasChildren) { DisableDragDropChildren(ctl.Controls, allowDropChanged); } } DragDropEffects effect = DragDropEffects.None; IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction trans = null; if (host != null) { trans = host.CreateTransaction(string.Format(SR.DragDropDragComponents, components.Length)); } try { effect = c.DoDragDrop(data, allowedEffects); if (trans != null) { trans.Commit(); } } finally { RemoveCurrentDrag(data); // Reset the AllowDrop for the components being dragged. // foreach (Control ctl in allowDropChanged) { ctl.AllowDrop = true; } freezePainting = oldFreezePainting; if (trans != null) { ((IDisposable)trans).Dispose(); } } bool isMove = (effect & DragDropEffects.Move) != 0 || ((int)effect & AllowLocalMoveOnly) != 0; // since the EndDrag will clear this bool isLocalMove = isMove && localDragInside; ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService)); Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control"); if (selectionUISvc != null) { // We must check to ensure that UI service is still in drag mode. It is // possible that the user hit escape, which will cancel drag mode. // if (selectionUISvc.Dragging) { // cancel the drag if we aren't doing a local move selectionUISvc.EndDrag(!isLocalMove); } } if (!localDragOffset.IsEmpty && effect != DragDropEffects.None) { DrawDragFrames(dragComps, localDragOffset, localDragEffect, Point.Empty, DragDropEffects.None, false); } localDragOffset = Point.Empty; dragComps = null; localDrag = localDragInside = false; dragBase = Point.Empty; /*if (!isLocalMove && isMove){ * IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); * IUndoService undoService = (IUndoService)GetService(typeof(IUndoService)); * IActionUnit unit = null; * * if (host != null) { * DesignerTransaction trans = host.CreateTransaction("Drag/drop"); * try{ * // delete the components * try{ * for (int i = 0; i < components.Length; i++){ * if (components[i] is IComponent){ * if (undoService != null){ * unit = new CreateControlActionUnit(host, (IComponent)components[i], true); * } * host.DestroyComponent((IComponent)components[i]); * if (undoService != null){ * undoService.AddAction(unit, false); * } * } * } * }catch(CheckoutException ex){ * if (ex != CheckoutException.Canceled){ * throw ex; * } * } * } * finally{ * trans.Commit(); * } * } * }*/ return(false); }