ClearCanvas.Desktop.View.WinForms.DesktopWindowView.AddShelfView C# (CSharp) Method

AddShelfView() private method

private AddShelfView ( ShelfView shelfView, Control control, string title, ShelfDisplayHint hint, MemoryStream shelfRestoreStream ) : Content
shelfView ShelfView
control System.Windows.Forms.Control
title string
hint ShelfDisplayHint
shelfRestoreStream System.IO.MemoryStream
return Content
        internal Content AddShelfView(ShelfView shelfView, Control control, string title, ShelfDisplayHint hint, MemoryStream shelfRestoreStream)
        {
        	// Forcing this makes the control resize *before* adding it to the DotNetMagic control, 
        	// so the shelf will be the correct size.  This would be done automatically when the
			// control gets added - we're just doing it a bit prematurely in order to get the correct size.
        	control.Font = _form.DockingManager.TabControlFont;
        	var displaySize = control.Size;

			var content = _form.DockingManager.Contents.Add(control, title);
			content.Tag = shelfView;

			if (shelfRestoreStream != null)
			{
				content.LoadContentFromStream(shelfRestoreStream);

				// #4183 - the shelf restore stream includes the shelf title, which is supposed to be determined by the model/localization and not persisted
				content.Title = content.FullTitle = title;

				_form.DockingManager.ShowContent(content);
				if (content.IsAutoHidden && hint != ShelfDisplayHint.HideOnWorkspaceOpen)
					_form.DockingManager.BringAutoHideIntoView(content);

				return content;
			}

        	content.DisplaySize = displaySize;
        	content.AutoHideSize = displaySize;
        	content.FloatingSize = displaySize;

        	if ((hint & ShelfDisplayHint.DockAutoHide) != 0)
        		_form.DockingManager.Container.SuspendLayout();

        	// Dock the window on the correct edge
        	if ((hint & ShelfDisplayHint.DockTop) != 0)
        	{
        		_form.DockingManager.AddContentWithState(content, State.DockTop);
        	}
        	else if ((hint & ShelfDisplayHint.DockBottom) != 0)
        	{
        		_form.DockingManager.AddContentWithState(content, State.DockBottom);
        	}
        	else if ((hint & ShelfDisplayHint.DockLeft) != 0)
        	{
        		_form.DockingManager.AddContentWithState(content, State.DockLeft);
        	}
        	else if ((hint & ShelfDisplayHint.DockRight) != 0)
        	{
        		_form.DockingManager.AddContentWithState(content, State.DockRight);
        	}
        	else
        	{
				if ((hint & ShelfDisplayHint.ShowNearMouse) == ShelfDisplayHint.ShowNearMouse)
				{
					content.DisplayLocation = Control.MousePosition;
				}

        		_form.DockingManager.AddContentWithState(content, State.Floating);
        	}

		    if ((hint & ShelfDisplayHint.DockAutoHide) != 0)
            {
                _form.DockingManager.ToggleContentAutoHide(content);
                _form.DockingManager.Container.ResumeLayout();
                _form.DockingManager.BringAutoHideIntoView(content);
            }

            return content;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Opens this shelf view.
        /// </summary>
        public override void Open()
        {
            IApplicationComponentView componentView = (IApplicationComponentView)ViewFactory.CreateAssociatedView(_shelf.Component.GetType());

            componentView.SetComponent((IApplicationComponent)_shelf.Component);

            XmlDocument restoreDocument;

            if (DesktopViewSettings.Default.GetShelfState(_desktopView.DesktopWindowName, _shelf.Name, out restoreDocument))
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    using (XmlTextWriter writer = new XmlTextWriter(memoryStream, Encoding.UTF8))
                    {
                        restoreDocument.WriteContentTo(writer);
                        writer.Flush();
                        memoryStream.Position = 0;

                        _content = _desktopView.AddShelfView(this, (Control)componentView.GuiElement, _shelf.Title, _shelf.DisplayHint, memoryStream);

                        writer.Close();
                        memoryStream.Close();
                    }
                }
            }
            else
            {
                _content = _desktopView.AddShelfView(this, (Control)componentView.GuiElement, _shelf.Title, _shelf.DisplayHint, null);
            }
        }