/// <summary> /// Adds the <see cref="DiagramView"/> specified by <paramref name="designer"/> to this <see cref="MultiDiagramDocView"/>. /// </summary> /// <param name="designer">The <see cref="DiagramView"/> to be added to this <see cref="MultiDiagramDocView"/>.</param> /// <param name="selectAsCurrent">Indicates whether focus should be given to the new <see cref="DiagramView"/>.</param> public void AddDesigner(DiagramView designer, bool selectAsCurrent) { if (designer == null) { throw new ArgumentNullException("designer"); } myVerifyPageOrder = true; MultiDiagramDocViewControl docViewControl = DocViewControl; int tabCount = docViewControl.TabCount; DiagramTabPage tabPage = new DiagramTabPage(docViewControl, designer); Diagram diagram = designer.Diagram; Dictionary <Diagram, int> diagramRefCounts = myDiagramRefCounts; int refCount; if (!diagramRefCounts.TryGetValue(diagram, out refCount) || refCount <= 0) { diagram.DiagramRemoved += DiagramRemoved; } diagramRefCounts[diagram] = refCount + 1; if (selectAsCurrent) { // If this is not here then the tab is not correctly activated. docViewControl.SelectedIndex = -1; docViewControl.SelectTab(tabPage); } }
/// <summary> /// Associates the <see cref="Image"/> specified by <paramref name="image"/> with the <see cref="Type"/> /// of <see cref="Diagram"/> specified by <paramref name="diagramType"/>. /// </summary> /// <param name="diagramType"> /// The <see cref="Type"/> of <see cref="Diagram"/> for which <paramref name="image"/> is being registered. /// </param> /// <param name="image"> /// The <see cref="Image"/> to be associated with <paramref name="diagramType"/>, or <see langword="null"/> /// to only remove all previous associated <see cref="Image"/>s for <paramref name="diagramType"/> without /// associating a new <see cref="Image"/>. /// </param> /// <remarks> /// Any and all previously associated <see cref="Image"/>s for <paramref name="diagramType"/> will be /// replaced by <paramref name="image"/> if it is not <see langword="null"/>. /// </remarks> public void RegisterImageForDiagramType(Type diagramType, Image image) { if (diagramType == null) { throw new ArgumentNullException("diagramType"); } MultiDiagramDocViewControl docViewControl = DocViewControl; ImageList imageList = docViewControl.ImageList; if (imageList == null) { // If we don't have an ImageList and the caller only wants to clear existing images, we don't need to do anything if (image == null) { return; } imageList = docViewControl.ImageList = new ImageList(); imageList.ColorDepth = ColorDepth.Depth32Bit; imageList.TransparentColor = Color.Transparent; imageList.ImageSize = DiagramImageSize; } string key = diagramType.GUID.ToString("N", null); ImageList.ImageCollection images = imageList.Images; int oldIndex; while ((oldIndex = images.IndexOfKey(key)) >= 0) { images.RemoveAt(oldIndex); } if (image != null) { images.Add(key, image); } }
public ParentControl(MultiDiagramDocViewControl docViewControl) { myDocViewControl = docViewControl; base.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ContainerControl | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true); base.SetStyle(ControlStyles.Selectable | ControlStyles.UserPaint, false); base.TabStop = false; base.BackColor = Color.Transparent; }
public ParentControl(MultiDiagramDocViewControl docViewControl) { myDocViewControl = docViewControl; base.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ContainerControl | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true); base.SetStyle(ControlStyles.Selectable | ControlStyles.UserPaint, false); base.TabStop = false; base.BackColor = Color.Transparent; }
/// <summary>See <see cref="ToolStripDropDown.OnOpening"/>.</summary> protected override void OnOpening(System.ComponentModel.CancelEventArgs e) { MultiDiagramDocViewControl docViewControl = base.SourceControl as MultiDiagramDocViewControl; if (docViewControl != null) { mySelectedDesigner = docViewControl.AcquireContextMenuDesigner; } base.OnOpening(e); }
/// <summary> /// Removes all <see cref="Diagram"/>s from this <see cref="MultiDiagramDocView"/>. /// </summary> public void RemoveAllDiagrams() { MultiDiagramDocViewControl control = myDocViewControl; if (control == null) { return; } int tabCount; while ((tabCount = control.TabCount) > 0) { RemoveAt(tabCount - 1); } }
public InlineTabRenameTextBox(MultiDiagramDocViewControl docViewControl, DiagramTabPage renamingTabPage) { myDocViewControl = docViewControl; docViewControl.RenamingTextBox = null; // Close anything existing prior to initialization RenamingTabPage = renamingTabPage; base.Parent = docViewControl.Parent; base.Visible = false; base.TabStop = false; base.Font = docViewControl.Font; base.BorderStyle = BorderStyle.None; base.SelectedText = renamingTabPage.Name; base.TextAlign = HorizontalAlignment.Center; base.BringToFront(); base.Focus(); docViewControl.RenamingTextBox = this; // Associate the existing tab }
/// <summary> /// Selects the <see cref="DiagramView"/> specified by <paramref name="designer"/> for this <see cref="MultiDiagramDocView"/>. /// </summary> /// <param name="designer">The <see cref="DiagramView"/> to be selected.</param> /// <returns> /// <see langword="true"/> if the <see cref="DiagramView"/> is successfully selected; otherwise, <see langword="false"/>. /// </returns> public bool SelectDesigner(DiagramView designer) { if (designer == null) { throw new ArgumentNullException("designer"); } MultiDiagramDocViewControl control = myDocViewControl; int index; if (control != null && (index = control.IndexOf(designer, 0)) >= 0) { // Although a single DiagramView could theoretically appear on multiple tabs, // we only need to activate one. control.SelectedIndex = index; return(true); } return(false); }
/// <summary> /// Removes the <see cref="DiagramView"/> specified by <paramref name="designer"/> from this <see cref="MultiDiagramDocView"/>. /// </summary> /// <param name="designer">The <see cref="DiagramView"/> to be removed.</param> public void RemoveDesigner(DiagramView designer) { if (designer == null) { throw new ArgumentNullException("designer"); } MultiDiagramDocViewControl control = myDocViewControl; if (control == null) { return; } int lastIndex = 0; while ((lastIndex = control.IndexOf(designer, lastIndex)) >= 0) { RemoveAt(lastIndex); } }
/// <summary> /// Removes the <see cref="Diagram"/> specified by <paramref name="diagram"/> from this <see cref="MultiDiagramDocView"/>. /// </summary> /// <param name="diagram">The <see cref="Diagram"/> to be removed.</param> public void RemoveDiagram(Diagram diagram) { if (diagram == null) { throw new ArgumentNullException("diagram"); } MultiDiagramDocViewControl control = myDocViewControl; if (control == null) { return; } int lastIndex = 0; while ((lastIndex = control.IndexOf(diagram, lastIndex)) >= 0) { RemoveAt(lastIndex); } }
public DiagramTabPage(MultiDiagramDocViewControl docViewControl, DiagramView designer) { myDocViewControl = docViewControl; Designer = designer; base.SuspendLayout(); base.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true); base.UseVisualStyleBackColor = false; Diagram diagram = designer.Diagram; base.Text = base.Name = diagram.Name; base.Controls.Add(designer); // Find the correct tab location for this diagram, depending on the diagram order and the // pages that have already been added TabControl.TabPageCollection pages = docViewControl.TabPages; bool inserted = false; Store store = diagram.Store; bool useDiagramDisplay = store.FindDomainModel(DiagramDisplayDomainModel.DomainModelId) != null; if (useDiagramDisplay) { DiagramDisplay display = DiagramDisplayHasDiagramOrder.GetDiagramDisplay(diagram); if (display != null) { // Walk the existing pages and match up the expected display order. Note that // there is no guarantee that all of the preceding diagrams have tab pages already. // If the previous pages are out of order, then we will get a reorder event later on // that puts them in the correct order. This will add them in an unpredictable order // if the sequences are different. IList <Diagram> orderedDiagrams = display.OrderedDiagramCollection; int diagramCount = orderedDiagrams.Count; int nextDiagramIndex = 0; Diagram nextDiagram = orderedDiagrams[nextDiagramIndex]; int pageCount = pages.Count; if (nextDiagram == diagram) { if (pageCount != 0) { // The new diagram is first, insert at the beginning pages.Insert(0, this); inserted = true; } } else { for (int pageIndex = 0; pageIndex < pageCount && !inserted; ++pageIndex) { DiagramTabPage page = (DiagramTabPage)pages[pageIndex]; Diagram pageDiagram = page.Diagram; bool getNextDiagram = false; if (pageDiagram == nextDiagram) { getNextDiagram = true; } else { // Keep walking diagrams until we get a match while (nextDiagramIndex < diagramCount) { nextDiagram = orderedDiagrams[++nextDiagramIndex]; if (pageDiagram == nextDiagram) { getNextDiagram = true; } else if (nextDiagram == diagram) { if ((pageIndex + 1) < pageCount) { pages.Insert(pageIndex + 1, this); inserted = true; break; } } } } if (getNextDiagram) { if (nextDiagramIndex < diagramCount) { nextDiagram = orderedDiagrams[++nextDiagramIndex]; if (nextDiagram == diagram) { // Insert immediately after the current page if ((pageIndex + 1) < pageCount) { pages.Insert(pageIndex + 1, this); inserted = true; } break; } } else { break; } } } } } } if (!inserted) { pages.Add(this); } // If the image key is set before the page is inserted then the tab size is incorrect // and nothing draws property. I have no idea why. base.ImageKey = diagram.GetType().GUID.ToString("N", null); base.ResumeLayout(false); store.EventManagerDirectory.ElementPropertyChanged.Add(diagram.GetDomainClass().NameDomainProperty, diagram.Id, (EventHandler <ElementPropertyChangedEventArgs>)DiagramNameChanged); if (useDiagramDisplay) { designer.DiagramClientView.GotFocus += new EventHandler(ViewGotFocus); designer.DiagramClientView.Resize += new EventHandler(InitialViewResize); myTurnOffResizeEventInFocusEvent = true; } designer.DiagramClientView.DiagramDisassociating += DiagramDisassociating; }
public DiagramTabPage(MultiDiagramDocViewControl docViewControl, DiagramView designer) { myDocViewControl = docViewControl; Designer = designer; base.SuspendLayout(); base.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true); base.UseVisualStyleBackColor = false; Diagram diagram = designer.Diagram; base.Text = base.Name = diagram.Name; base.Controls.Add(designer); // Find the correct tab location for this diagram, depending on the diagram order and the // pages that have already been added TabControl.TabPageCollection pages = docViewControl.TabPages; bool inserted = false; Store store = diagram.Store; bool useDiagramDisplay = store.FindDomainModel(DiagramDisplayDomainModel.DomainModelId) != null; if (useDiagramDisplay) { DiagramDisplay display = DiagramDisplayHasDiagramOrder.GetDiagramDisplay(diagram); if (display != null) { // Walk the existing pages and match up the expected display order. Note that // there is no guarantee that all of the preceding diagrams have tab pages already. // If the previous pages are out of order, then we will get a reorder event later on // that puts them in the correct order. This will add them in an unpredictable order // if the sequences are different. IList<Diagram> orderedDiagrams = display.OrderedDiagramCollection; int diagramCount = orderedDiagrams.Count; int nextDiagramIndex = 0; Diagram nextDiagram = orderedDiagrams[nextDiagramIndex]; int pageCount = pages.Count; if (nextDiagram == diagram) { if (pageCount != 0) { // The new diagram is first, insert at the beginning pages.Insert(0, this); inserted = true; } } else { for (int pageIndex = 0; pageIndex < pageCount && !inserted; ++pageIndex) { DiagramTabPage page = (DiagramTabPage)pages[pageIndex]; Diagram pageDiagram = page.Diagram; bool getNextDiagram = false; if (pageDiagram == nextDiagram) { getNextDiagram = true; } else { // Keep walking diagrams until we get a match while (nextDiagramIndex < diagramCount) { nextDiagram = orderedDiagrams[++nextDiagramIndex]; if (pageDiagram == nextDiagram) { getNextDiagram = true; } else if (nextDiagram == diagram) { if ((pageIndex + 1) < pageCount) { pages.Insert(pageIndex + 1, this); inserted = true; break; } } } } if (getNextDiagram) { if (nextDiagramIndex < diagramCount) { nextDiagram = orderedDiagrams[++nextDiagramIndex]; if (nextDiagram == diagram) { // Insert immediately after the current page if ((pageIndex + 1) < pageCount) { pages.Insert(pageIndex + 1, this); inserted = true; } break; } } else { break; } } } } } } if (!inserted) { pages.Add(this); } // If the image key is set before the page is inserted then the tab size is incorrect // and nothing draws property. I have no idea why. base.ImageKey = diagram.GetType().GUID.ToString("N", null); base.ResumeLayout(false); store.EventManagerDirectory.ElementPropertyChanged.Add(diagram.GetDomainClass().NameDomainProperty, diagram.Id, (EventHandler<ElementPropertyChangedEventArgs>)DiagramNameChanged); if (useDiagramDisplay) { designer.DiagramClientView.GotFocus += new EventHandler(ViewGotFocus); designer.DiagramClientView.Resize += new EventHandler(InitialViewResize); myTurnOffResizeEventInFocusEvent = true; } designer.DiagramClientView.DiagramDisassociating += DiagramDisassociating; }
public InlineTabRenameTextBox(MultiDiagramDocViewControl docViewControl, DiagramTabPage renamingTabPage) { myDocViewControl = docViewControl; RenamingTabPage = renamingTabPage; base.Parent = docViewControl.Parent; base.Visible = false; base.TabStop = false; base.Font = docViewControl.Font; base.BorderStyle = BorderStyle.None; base.SelectedText = renamingTabPage.Name; base.TextAlign = HorizontalAlignment.Center; base.BringToFront(); base.Focus(); }