예제 #1
0
        /// <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);
            }
        }
예제 #2
0
 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
 }
예제 #3
0
            protected sealed override void OnSelectedIndexChanged(EventArgs e)
            {
                base.OnSelectedIndexChanged(e);
                DiagramTabPage tabPage = SelectedDiagramTab;

                if (tabPage != null)
                {
                    DiagramView designer = tabPage.Designer;
                    DocView.SetSelectedComponents(designer.Selection.RepresentedElements);
                    designer.DiagramClientView.Focus();
                }
                else
                {
                    DocView.SetSelectedComponents(null);
                }
            }
예제 #4
0
            private void RenameTab(DiagramTabPage tabPage)
            {
                if (tabPage != null)
                {
                    InlineTabRenameTextBox renamingTextBox;

                    if (null != (renamingTextBox = myRenamingTextBox) &&
                        renamingTextBox.RenamingTabPage == tabPage)
                    {
                        // If we already have an InlineTabRenameTextBox for this tab page, do nothing
                        return;
                    }
                    new InlineTabRenameTextBox(this, tabPage);
                    base.Invalidate(false);
                }
            }
예제 #5
0
            /// <summary>
            /// Verify that the tab pages are in the correct order
            /// </summary>
            public void VerifyDiagramOrder(IList <Diagram> diagrams)
            {
                TabControl.TabPageCollection pages = TabPages;
                int pageCount    = pages.Count;
                int diagramCount = diagrams.Count;

                for (int i = 0; i < pageCount; ++i)
                {
                    DiagramTabPage tabPage = (DiagramTabPage)pages[i];
                    if (i < diagramCount && tabPage.Diagram == diagrams[i])
                    {
                        continue;
                    }

                    SuspendLayout();
                    // We're out of sync, pull remaining tabs and readd in diagram order
                    DiagramTabPage reselectPage = SelectedDiagramTab;
                    Dictionary <Diagram, DiagramTabPage> keyedPages = new Dictionary <Diagram, DiagramTabPage>(pageCount - i + 1);
                    for (int j = pageCount - 1; j >= i; --j)
                    {
                        tabPage = (DiagramTabPage)pages[j];
                        keyedPages.Add(tabPage.Diagram, tabPage);
                        tabPage.Parent = null;
                    }

                    // Add the diagram pages back in order
                    for (int j = i; j < diagramCount; ++j)
                    {
                        Diagram diagram = diagrams[j];
                        if (keyedPages.TryGetValue(diagram, out tabPage))
                        {
                            pages.Add(tabPage);
                            keyedPages.Remove(diagram);
                        }
                    }

                    // Dispose any remaining pages
                    foreach (DiagramTabPage unboundPage in keyedPages.Values)
                    {
                        unboundPage.Dispose();
                    }
                    SelectedTab = reselectPage;
                    ResumeLayout(false);
                    break;
                }
            }
예제 #6
0
            protected sealed override void WndProc(ref Message m)
            {
                const int WM_CONTEXTMENU = 0x007B;

                bool contextMenuMessage;

                if (contextMenuMessage = (m.Msg == WM_CONTEXTMENU))
                {
                    uint lParam = (uint)m.LParam;
                    // Convert to short instead of int to get the sign correct
                    // for multi-monitor systems with negative mouse positions.
                    int            x = (short)(lParam & 0xFFFF);
                    int            y = (short)((lParam >> 16) & 0xFFFF);
                    DiagramTabPage diagramTabPage = (x == -1 && y == -1) ? SelectedDiagramTab : GetTabAtPoint(base.PointToClient(new Point(x, y)));
                    myTrustDesignerForContextMenu = true;
                    myDesignerForContextMenu      = (diagramTabPage != null) ? diagramTabPage.Designer : null;
                }
                base.WndProc(ref m);
                if (contextMenuMessage)
                {
                    myTrustDesignerForContextMenu = false;
                }
            }
예제 #7
0
        private void RemoveAt(int index)
        {
            DiagramTabPage tabPage = (DiagramTabPage)myDocViewControl.TabPages[index];
            Diagram        diagram = tabPage.Diagram;

            if (diagram != null)
            {
                Dictionary <Diagram, int> diagramRefCounts = myDiagramRefCounts;
                int refCount = diagramRefCounts[diagram] - 1;
                if (refCount <= 0)
                {
                    diagram.DiagramRemoved -= DiagramRemoved;
                    diagramRefCounts.Remove(diagram);
                }
                else
                {
                    diagramRefCounts[diagram] = refCount;
                }
            }
            // HACK: Set Parent to null rather than removing the TabPage from the Parent's TabPages collection.
            // If we do the latter, for some reason another TabPage gets removed in addition to the TabPage we are processing.
            tabPage.Parent = null;
            tabPage.Dispose();
        }
예제 #8
0
            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;
            }
예제 #9
0
				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();
				}
예제 #10
0
			private void RenameTab(DiagramTabPage tabPage)
			{
				if (tabPage != null)
				{
					InlineTabRenameTextBox renamingTextBox = myRenamingTextBox;
					
					if (renamingTextBox != null)
					{
						if (renamingTextBox.RenamingTabPage == tabPage)
						{
							// If we already have an InlineTabRenameTextBox for this tab page, do nothing
							return;
						}
						else
						{
							// If we already have an InlineTabRenameTextBox for a different tab page, save the changes and close it
							renamingTextBox.Close(true);
						}
					}
					myRenamingTextBox = new InlineTabRenameTextBox(this, tabPage);
					base.Invalidate(false);
				}
			}
예제 #11
0
		/// <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);
			}
		}