Ejemplo n.º 1
0
            private void ViewGotFocus(object sender, EventArgs e)
            {
                DiagramClientView             view;
                Diagram                       diagram;
                DiagramDisplayHasDiagramOrder link;

                if (null != (view = sender as DiagramClientView) &&
                    null != (diagram = view.Diagram) &&
                    null != (link = DiagramDisplayHasDiagramOrder.GetLinkToDiagramDisplay(diagram)))
                {
                    if (myTurnOffResizeEventInFocusEvent)
                    {
                        // Use the cached until the view has been focused once, then
                        // the view gets control of the settings
                        myTurnOffResizeEventInFocusEvent = false;
                        view.Resize -= new EventHandler(InitialViewResize);
                    }
                    link.UpdatePosition(view.ViewBounds.Center, view.ZoomFactor);
                    link.Activate();
                    view.ScrollPositionChanged += new ScrollPositionChangedEventHandler(ViewDisplayChanged);
                    view.ZoomChanged           += new ZoomChangedEventHandler(ViewDisplayChanged);
                    view.Resize    += new EventHandler(ViewSizeChanged);
                    view.LostFocus += new EventHandler(ViewLostFocus);
                }
            }
Ejemplo n.º 2
0
            private static void InitialViewResize(object sender, EventArgs e)
            {
                DiagramClientView             view;
                Diagram                       diagram;
                DiagramDisplayHasDiagramOrder link;

                if (null != (view = sender as DiagramClientView) &&
                    null != (diagram = view.Diagram))
                {
                    if (null != (link = DiagramDisplayHasDiagramOrder.GetLinkToDiagramDisplay(diagram)))
                    {
                        // Update the display position from the diagram display information
                        float desiredZoomFactor = link.ZoomFactor;
                        if (desiredZoomFactor != view.ZoomFactor)
                        {
                            view.SetZoomFactor(desiredZoomFactor, link.CenterPoint, true);
                        }
                        else
                        {
                            // No longer auto scroll to the center on opening a diagram, this was causing a problem when a diagram was created on a high resolution monitor and sent to a lower resolution monitor.
                            //view.ScrollTo(new PointD(link.CenterPoint.X - view.ViewBounds.Width / 2, link.CenterPoint.Y - view.ViewBounds.Height / 2));
                        }
                    }
                }
            }
Ejemplo n.º 3
0
        /// <summary>
        /// DeleteRule: typeof(DiagramDisplayHasDiagramOrder), FireTime=LocalCommit, Priority=FrameworkDomainModel.BeforeDelayValidateRulePriority;
        /// Make sure that deletion of a diagram order results in a reorder
        /// </summary>
        private static void DiagramOrderDeletedRule(ElementDeletedEventArgs e)
        {
            DiagramDisplayHasDiagramOrder link = (DiagramDisplayHasDiagramOrder)e.ModelElement;
            Diagram diagram = link.Diagram;

            if (!diagram.IsDeleted)
            {
                Store store = diagram.Store;
                if (diagram.Partition == store.DefaultPartition)                 // This should never happen, but it is easy to check
                {
                    if (null == DiagramDisplayHasDiagramOrder.GetDiagramDisplay(diagram))
                    {
                        DiagramDisplay displayContainer = link.DiagramDisplay;
                        if (displayContainer.IsDeleted)
                        {
                            ReadOnlyCollection <DiagramDisplay> displays = store.ElementDirectory.FindElements <DiagramDisplay>(false);
                            displayContainer = (displays.Count != 0) ? displays[0] : new DiagramDisplay(store);
                        }
                        new DiagramDisplayHasDiagramOrder(displayContainer, diagram);
                    }
                }
            }
            else
            {
                DiagramDisplay displayContainer = link.DiagramDisplay;
                if (!displayContainer.IsDeleted && displayContainer.OrderedDiagramCollection.Count == 0)
                {
                    // No more diagrams, don't need the container
                    displayContainer.Delete();
                }
            }
        }
Ejemplo n.º 4
0
            private static void ViewDisplayChanged(object sender, DiagramEventArgs e)
            {
                DiagramClientView             view = e.DiagramClientView;
                Diagram                       diagram;
                DiagramDisplayHasDiagramOrder link;

                if (null != (diagram = view.Diagram) &&
                    null != (link = DiagramDisplayHasDiagramOrder.GetLinkToDiagramDisplay(diagram)))
                {
                    link.UpdatePosition(view.ViewBounds.Center, view.ZoomFactor);
                }
            }
Ejemplo n.º 5
0
 /// <summary>
 /// Make this the active view for the display
 /// </summary>
 public void Activate()
 {
     if (!myIsActive)
     {
         DiagramDisplay container = DiagramDisplay;
         foreach (DiagramDisplayHasDiagramOrder link in DiagramDisplayHasDiagramOrder.GetLinksToOrderedDiagramCollection(DiagramDisplay))
         {
             link.myIsActive = false;                     // Doesn't matter if we set ours
         }
         myIsActive = true;
     }
 }
Ejemplo n.º 6
0
            /// <summary>
            /// Use the first element as the active diagram if one is not specified
            /// </summary>
            protected override void PhaseCompleted(Store store)
            {
                DiagramDisplay container;

                if (!mySeenActive &&
                    null != (container = myDiagramDisplay))
                {
                    foreach (DiagramDisplayHasDiagramOrder link in DiagramDisplayHasDiagramOrder.GetLinksToOrderedDiagramCollection(container))
                    {
                        link.IsActiveDiagram = true;
                        break;
                    }
                }
            }
Ejemplo n.º 7
0
        /// <summary>
        /// AddRule: typeof(Microsoft.VisualStudio.Modeling.Diagrams.Diagram), FireTime=LocalCommit, Priority=FrameworkDomainModel.BeforeDelayValidateRulePriority;
        /// Make sure a diagram is included in the ordered list
        /// </summary>
        private static void DiagramAddedRule(ElementAddedEventArgs e)
        {
            Diagram diagram = (Diagram)e.ModelElement;

            if (!diagram.IsDeleted)
            {
                Store store = diagram.Store;
                if (diagram.Partition == store.DefaultPartition)
                {
                    DiagramDisplay displayContainer = DiagramDisplayHasDiagramOrder.GetDiagramDisplay(diagram);
                    if (displayContainer == null)
                    {
                        ReadOnlyCollection <DiagramDisplay> displays = store.ElementDirectory.FindElements <DiagramDisplay>(false);
                        displayContainer = (displays.Count != 0) ? displays[0] : new DiagramDisplay(store);
                        new DiagramDisplayHasDiagramOrder(displayContainer, diagram);
                    }
                }
            }
        }
Ejemplo n.º 8
0
            private static void InitialViewResize(object sender, EventArgs e)
            {
                DiagramClientView             view;
                Diagram                       diagram;
                DiagramDisplayHasDiagramOrder link;

                if (null != (view = sender as DiagramClientView) &&
                    null != (diagram = view.Diagram))
                {
                    if (null != (link = DiagramDisplayHasDiagramOrder.GetLinkToDiagramDisplay(diagram)))
                    {
                        // Update the display position from the diagram display information
                        float desiredZoomFactor = link.ZoomFactor;
                        if (desiredZoomFactor != view.ZoomFactor)
                        {
                            view.SetZoomFactor(desiredZoomFactor, link.CenterPoint, true);
                        }
                        else
                        {
                            view.ScrollTo(new PointD(link.CenterPoint.X - view.ViewBounds.Width / 2, link.CenterPoint.Y - view.ViewBounds.Height / 2));
                        }
                    }
                }
            }
Ejemplo n.º 9
0
            /// <summary>
            /// Process diagram items to make sure they have a current ordering representation
            /// </summary>
            protected sealed override void ProcessElement(Diagram element, Store store, INotifyElementAdded notifyAdded)
            {
                DiagramDisplayHasDiagramOrder link = DiagramDisplayHasDiagramOrder.GetLinkToDiagramDisplay(element);
                DiagramDisplay container           = myDiagramDisplay;

                if (container == null)
                {
                    if (link != null)
                    {
                        container = link.DiagramDisplay;
                    }

                    // Make sure we only have one container, use the one we've already grabbed
                    ReadOnlyCollection <DiagramDisplay> containers = store.ElementDirectory.FindElements <DiagramDisplay>(false);
                    int containerCount = containers.Count;
                    for (int i = containerCount - 1; i >= 0; --i)
                    {
                        DiagramDisplay testContainer = containers[i];
                        if (container != null)
                        {
                            if (testContainer != container)
                            {
                                testContainer.Delete();
                            }
                        }
                        else if (i == 0)
                        {
                            container = testContainer;
                        }
                        else
                        {
                            testContainer.Delete();
                        }
                    }
                    if (container == null)
                    {
                        container = new DiagramDisplay(store);
                        notifyAdded.ElementAdded(container, false);
                    }
                    myDiagramDisplay = container;
                    if (link != null)
                    {
                        // There is nothing else to do, the element has been validated
                        if (link.IsActiveDiagram)
                        {
                            if (mySeenActive)
                            {
                                link.IsActiveDiagram = false;
                            }
                            else
                            {
                                mySeenActive = true;
                            }
                        }
                        return;
                    }
                }
                if (link == null)
                {
                    // This will add to the end of the existing collection
                    link = new DiagramDisplayHasDiagramOrder(container, element);
                    notifyAdded.ElementAdded(link, false);
                }
                else
                {
                    if (link.DiagramDisplay != container)
                    {
                        link.DiagramDisplay = container;
                    }
                    if (link.IsActiveDiagram)
                    {
                        if (mySeenActive)
                        {
                            link.IsActiveDiagram = false;
                        }
                        else
                        {
                            mySeenActive = true;
                        }
                    }
                }
            }
Ejemplo n.º 10
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;
            }