protected void OnStatusZoomOut(object sender, EventArgs e) { MenuCommand cmd = sender as MenuCommand; VSDiagramView designer = this.CurrentDocView != null && this.CurrentDocView.CurrentDesigner != null ? this.CurrentDocView.CurrentDesigner : null; cmd.Enabled = cmd.Visible = designer != null && designer.ZoomFactor > designer.DiagramClientView.MinimumZoom; }
/// <summary> /// Create and return a new panel displaying the /// image in the specified resource as a background /// image. /// </summary> /// <param name="imageResourceName"></param> /// <param name="view"></param> /// <returns></returns> private Panel CreatePanel(string imageResourceName, VSDiagramView view, int height, int width ) { // Create a new panel to draw the image on Panel newPanel = new Panel(); if (!string.IsNullOrEmpty(imageResourceName)) { newPanel.BackgroundImage = new Bitmap(this.GetType(), imageResourceName); newPanel.BackgroundImageLayout = ImageLayout.Center; } // Add the new control to the view and // initialise it. view.Controls.Add(newPanel); newPanel.Height = height; newPanel.Width = width; newPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; newPanel.BringToFront(); return(newPanel); }
/// <summary> /// Create and return a new panel displaying the /// image in the specified resource as a background /// image. /// </summary> /// <param name="imageResourceName"></param> /// <param name="view"></param> /// <returns></returns> private Panel CreatePanel( VSDiagramView view, int height, int width, Bitmap imageResource = null ) { // Create a new panel to draw the image on Panel newPanel = new Panel(); if (null != imageResource) { newPanel.BackgroundImage = imageResource; newPanel.BackgroundImageLayout = ImageLayout.Center; } // Add the new control to the view and // initialise it. view.Controls.Add(newPanel); newPanel.Height = height; newPanel.Width = width; newPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; newPanel.BringToFront(); newPanel.BorderStyle = BorderStyle.FixedSingle; return(newPanel); }
/// <summary> /// Get the filename in which a Store is persisted /// </summary> /// <param name="store">The store.</param> /// <returns></returns> public static string GetFileNameForStore(Store store) { foreach (Diagram diagram in store.ElementDirectory.FindElements <Diagram>(true)) { VSDiagramView view = diagram.ActiveDiagramView as VSDiagramView; if (view != null) { // Get the corresponding file return(view.DocData.FileName); } } return(null); }
/// <summary> /// Set colors, e.g. background and watermark, /// and colorize icons according to the theme /// </summary> private void UpdateTheme(VSDiagramView view) { if (view.HasWatermark) { VSHelpers.AssignLinkLabelColor(view.Watermark); } view.BackColor = VSColorTheme.GetThemedColor(EnvironmentColors.ScrollBarBackgroundColorKey); foreach (var action in _themeChangedActions) { action(); } view.Invalidate(); }
/// <summary> /// Verify compatible Dpi settings so the DiagramClientView does /// not disappear. /// </summary> public override VSDiagramView CreateDiagramView() { // On reload, the DiagramClientView and VSDiagramView windows end // up with different Dpi settings. This causes the internal Windowss // SetParent API to return a ERROR_INVALID_STATE result after Windows 10, // release 1703 and later. This effectively orphans the DiagramClientView, // which is the window the diagram shapes draw in, so all of the diagram // windows are blank. This is bad. // UNDONE: MSBUG: There is no way I should have to fix this here. The // DiagramClientView window handle is created much earlier than it // needs to be causing the window to be temporarily 'parked'. Creating the // window for the child DiagramClientView after the VSDiagramView handle is // created would eliminate all of this hacking. VSDiagramView designer = base.CreateDiagramView(); if (forceRecreate == null) { // The first one is most reliable (part of the public API), the internal less so. forceRecreate = typeof(Control).GetMethod("RecreateHandle", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); getDpiState = typeof(Control).GetMethod("get_DpiAwarenessContext", BindingFlags.Instance | BindingFlags.NonPublic); } if (getDpiState != null) { EventHandler designerHandleCreated = null; designer.HandleCreated += designerHandleCreated = delegate(object sender, EventArgs e) { VSDiagramView view = (VSDiagramView)sender; view.HandleCreated -= designerHandleCreated; // Run once DiagramClientView clientView = view.DiagramClientView; if (clientView.IsHandleCreated && (int)getDpiState.Invoke(clientView, null) != (int)getDpiState.Invoke(view, null)) { forceRecreate.Invoke(clientView, null); } }; } return(designer); }
/// <summary> /// Override the base class method so that we can /// add some new extra controls to the view (add /// controls to zoom in, zoom out, pan control, /// and zoom to 100%). /// </summary> /// <returns></returns> public override VSDiagramView CreateDiagramView() { // We are going to add four new controls to the diagram view. // The controls are added underneath the vertical scrollbar. // We need to create and site the panels. We also need to // resize the vertical scroll bar so that there is room for // our controls. // Let the base class create and initialise // the standard view. VSDiagramView view = base.CreateDiagramView(); // Get hold of the scrollbars of the view m_vscroll = GetControl <VScrollBar>(view.Controls) as VScrollBar; HScrollBar hscroll = GetControl <HScrollBar>(view.Controls) as HScrollBar; // Sanity checks Debug.Assert(m_vscroll != null, "Error - couldn't find the vertical scroll bar"); Debug.Assert(hscroll != null, "Error - couldn't find the horizontal scroll bar"); // Give up if we didn't find the scroll bars if (m_vscroll == null || hscroll == null) { return(view); } Panel zoomInPanel; Panel zoomOutPanel; Panel zoom100Panel; int panelHeight = hscroll.Height; int panelWidth = m_vscroll.Width; // Create the panels and set the event handlers m_panPanel = CreatePanel("CustomCode.PanZoom.ThumbnailView.bmp", view, panelHeight, panelWidth); m_panPanel.MouseDown += new MouseEventHandler(PanelPanelMouseDownHandler); zoomInPanel = CreatePanel("CustomCode.PanZoom.ZoomInButton.bmp", view, panelHeight, panelWidth); zoomInPanel.Click += new EventHandler(ZoomInPanelClickHandler); zoom100Panel = CreatePanel("CustomCode.PanZoom.Zoom100Button.bmp", view, panelHeight, panelWidth); zoom100Panel.Click += new EventHandler(Zoom100PanelClickHandler); zoomOutPanel = CreatePanel("CustomCode.PanZoom.ZoomOutButton.bmp", view, panelHeight, panelWidth); zoomOutPanel.Click += new EventHandler(ZoomOutPanelClickHandler); // Set the position of the panels // Stack the panels on top of each other m_panPanel.Top = view.Height - m_panPanel.Height; zoomOutPanel.Top = m_panPanel.Top - zoomOutPanel.Height; zoom100Panel.Top = zoomOutPanel.Top - zoom100Panel.Height; zoomInPanel.Top = zoom100Panel.Top - zoomInPanel.Height; // All panels have the same left position m_panPanel.Left = view.Width - m_panPanel.Width; zoomOutPanel.Left = m_panPanel.Left; zoom100Panel.Left = m_panPanel.Left; zoomInPanel.Left = m_panPanel.Left; // Work out and store the amount by which we need // to resize the vertical scroll bar. m_scrollbarHeightAdjustment = zoom100Panel.Height + zoomInPanel.Height + zoomOutPanel.Height; // Need to be able to resize the vertical scrollbar // every time the view is resized. // NB the Resize and SizeChanged events fire too // early i.e. before the VSDiagramView has resized // the vertical scroll bar. view.ClientSizeChanged += new EventHandler(ClientSizeChangedHandler); // handle Ctrl + MButton to zoom to 100% if (view.DiagramClientView != null) { view.DiagramClientView.MouseClick += new MouseEventHandler(MouseClickHandler); } return(view); }