Пример #1
0
		private DocumentDockContainer GetContainer(DocumentDockContainer parent, int x, int y)
		{
			if(parent==null || !parent.DisplayBounds.Contains(x,y) || !parent.Visible)
				return null;
			DocumentDockContainer ret=null;
			foreach(DocumentBaseContainer doc in parent.Documents)
			{
				if(doc is DocumentDockContainer)
				{
					ret=this.GetContainer((DocumentDockContainer)doc,x,y);
					if(ret!=null)
						break;
				}
			}

            if (ret == null)
                ret = parent;
			return ret;
		}
Пример #2
0
		public void OnMouseUp(MouseEventArgs e)
		{
			if(m_ResizeDockContainer!=null && !m_MouseDownPoint.IsEmpty)
			{
				ResizeTo(e.X,e.Y);
			}

			m_MouseDownPoint=Point.Empty;
			m_ResizeDockContainer=null;
			m_ResizeDocument=null;
			DestroySplitter();
		}
Пример #3
0
		private DocumentBaseContainer GetClosestDocument(DocumentDockContainer parent, int x, int y)
		{
			DocumentBaseContainer ret=null;
			eOrientation orientation=parent.Orientation;
			foreach(DocumentBaseContainer doc in parent.Documents)
			{
				if(orientation==eOrientation.Horizontal && doc.DisplayBounds.X>x && doc.Visible)
                    break;
                else if(orientation==eOrientation.Vertical && doc.DisplayBounds.Y>y && doc.Visible)
					break;
                if(doc.Visible)
				    ret=doc;
			}
			return ret;
		}
Пример #4
0
		private DocumentDockContainer CreateDocumentDockContainer()
		{
			DocumentDockContainer dock=new DocumentDockContainer();
			return dock;
		}
Пример #5
0
		public void OnMouseDown(MouseEventArgs e)
		{
			int x=e.X, y=e.Y;
			if(e.Button==MouseButtons.Left)
			{
				m_MouseDownPoint=new Point(x,y);
				DocumentDockContainer context=this.GetContainerFromRoot(x,y);
                
                if(context!=null)
				{
					m_ResizeDocument=this.GetClosestDocument(context,x,y);
					if(m_ResizeDocument==null)
						return;
					m_ResizeDockContainer=context;
					if(!m_ResizePreview)
					{
						CreateSplitter();
						SplitterMouseMove(x,y);
					}
				}
                else if (m_Container != null && m_Container.Dock != DockStyle.Fill)
                {
                    m_ResizeDockContainer = m_DocumentDockContainer;
                    if (!m_ResizePreview)
                    {
                        CreateSplitter();
                        SplitterMouseMove(x, y);
                    }
                }
			}
		}
Пример #6
0
        /// <summary>
        /// Docks specified bar by appending it to the container. Bar will be added according to the container's orientation.
        /// </summary>
        /// <param name="barToDock">Bar to dock.</param>
        /// <param name="dockSide">Side to dock bar at.</param>
		public void Dock(Bar referenceBar, Bar barToDock, eDockSide dockSide)
		{
			if(dockSide==eDockSide.None && barToDock.Parent==m_Container)
			{
				ApplyBarStyle(barToDock);
				return;
			}

			if(barToDock.Parent is DockSite && ((DockSite)barToDock.Parent).DocumentDockContainer!=null)
				((DockSite)barToDock.Parent).GetDocumentUIManager().UnDock(barToDock);
			else if(barToDock.Parent is DockSite && barToDock.Parent!=m_Container)
				((DockSite)barToDock.Parent).RemoveBar(barToDock);
            else if (barToDock.Parent != null && barToDock.Parent != m_Container)
            {
                if (barToDock.Parent is FloatingContainer)
                {
                    barToDock.RemoveFromFloatingContainer();
                    barToDock.SetBarState(eBarState.Docked);
                }
                else
                    barToDock.Parent.Controls.Remove(barToDock);
            }

			if(!m_LoadingLayout)
			{
				// TODO: Add Docking as Document, i.e. add DockContainerItems from barToDock...
				DocumentBarContainer doc=this.CreateDocumentBarContainer(barToDock);
                DocumentBaseContainer referenceDoc = this.GetDocumentFromBar(referenceBar);

                if (referenceBar == null || dockSide == eDockSide.None || referenceBar == barToDock || referenceDoc == null)
				{
                    if (m_Container.Dock == DockStyle.Fill)
                        m_DocumentDockContainer.Documents.Add(doc);
                    else
                    {
                        eOrientation containerOrientation = eOrientation.Horizontal; // Needed container orientation
                        if (m_Container.Dock == DockStyle.Top || m_Container.Dock == DockStyle.Bottom)
                            containerOrientation = eOrientation.Vertical;

                        // Switch orientation when adding new bar if possible
                        if (m_DocumentDockContainer.Orientation != containerOrientation)
                        {
                            if (m_DocumentDockContainer.Documents.Count <= 1)
                            {
                                m_DocumentDockContainer.Orientation = containerOrientation;
                                if (IsAddedInFront(dockSide))
                                    m_DocumentDockContainer.Documents.Insert(0, doc);
                                else
                                    m_DocumentDockContainer.Documents.Add(doc);
                            }
                            else
                            {
                                DocumentBaseContainer[] docs = new DocumentBaseContainer[m_DocumentDockContainer.Documents.Count];
                                m_DocumentDockContainer.Documents.CopyTo(docs);
                                m_DocumentDockContainer.Documents.Clear();

                                DocumentDockContainer newParent = new DocumentDockContainer(docs, m_DocumentDockContainer.Orientation);
								newParent.SetLayoutBounds(m_DocumentDockContainer.DisplayBounds);
                                m_DocumentDockContainer.Orientation = containerOrientation;
                                m_DocumentDockContainer.Documents.Add(newParent);
                                if (IsAddedInFront(dockSide))
                                    m_DocumentDockContainer.Documents.Insert(0, doc);
                                else
                                    m_DocumentDockContainer.Documents.Add(doc);
                            }
                        }
                        else
                        {
                            if (IsAddedInFront(dockSide))
                                m_DocumentDockContainer.Documents.Insert(0, doc);
                            else
                                m_DocumentDockContainer.Documents.Add(doc);
                        }
                    }
				}
				else
				{
					DocumentDockContainer parent=referenceDoc.Parent as DocumentDockContainer;

					referenceDoc.SetLayoutBounds(Rectangle.Empty);
					doc.SetLayoutBounds(Rectangle.Empty);

					if((parent.Orientation==eOrientation.Horizontal && (dockSide==eDockSide.Left || dockSide==eDockSide.Right)) ||
						(parent.Orientation==eOrientation.Vertical && (dockSide==eDockSide.Top || dockSide==eDockSide.Bottom)))
					{
						if(dockSide==eDockSide.Right || dockSide==eDockSide.Bottom)
							parent.Documents.Insert(parent.Documents.IndexOf(referenceDoc)+1,doc);
						else
							parent.Documents.Insert(parent.Documents.IndexOf(referenceDoc),doc);
					}
					else if(parent.Documents.Count==1)
					{
						// Orientation of the parent dock container can be changed
						if(parent.Orientation==eOrientation.Vertical)
							parent.Orientation=eOrientation.Horizontal;
						else
							parent.Orientation=eOrientation.Vertical;

						if(dockSide==eDockSide.Right || dockSide==eDockSide.Bottom)
							parent.Documents.Insert(parent.Documents.IndexOf(referenceDoc)+1,doc);
						else
							parent.Documents.Insert(parent.Documents.IndexOf(referenceDoc),doc);
					}
					else
					{
						// New DocumentDockContainer needs to be inserted with appropriate orientation and referenceBar needs
						// to be moved into it.
						DocumentDockContainer newParent=new DocumentDockContainer();
						if(parent.Orientation==eOrientation.Horizontal)
							newParent.Orientation=eOrientation.Vertical;
						else
							newParent.Orientation=eOrientation.Horizontal;

						parent.Documents.Insert(parent.Documents.IndexOf(referenceDoc),newParent);
						parent.Documents.Remove(referenceDoc);
	                    
						if(dockSide==eDockSide.Right || dockSide==eDockSide.Bottom)
						{
							newParent.Documents.Add(referenceDoc);
							newParent.Documents.Add(doc);
						}
						else
						{
							newParent.Documents.Add(doc);
							newParent.Documents.Add(referenceDoc);
						}
					}
				}

                AdjustContainerSize(barToDock, false);
			}

			if(m_Container!=null)
			{
				if(barToDock.Parent==null)
					m_Container.Controls.Add(barToDock);
                ApplyBarStyle(barToDock);	
				m_Container.RecalcLayout();
			}
			else
				ApplyBarStyle(barToDock);
		}
Пример #7
0
		private void RemoveEmptyContainers(DocumentDockContainer parent)
		{
			while(parent.Documents.Count==0 && parent.Parent!=null && parent.Parent is DocumentDockContainer ||
				parent.Parent!=null && parent.Parent is DocumentDockContainer && ((DocumentDockContainer)parent.Parent).Documents.Count==1)
			{
				if(parent.Parent!=null && parent.Parent is DocumentDockContainer && ((DocumentDockContainer)parent.Parent).Documents.Count==1)
				{
					// Removes the instances where DocumentDockContainer hosts another one and only one DocumentDockContainer object
					DocumentDockContainer p=parent.Parent as DocumentDockContainer;
					p.Documents.Remove(parent);
					p.Orientation=parent.Orientation;
					DocumentBaseContainer[] documents=new DocumentBaseContainer[parent.Documents.Count];
					parent.Documents.CopyTo(documents);
					p.Documents.AddRange(documents);
					parent=p;
				}
				else
				{
					DocumentDockContainer p=parent.Parent as DocumentDockContainer;
					p.Documents.Remove(parent);
					parent=p;
				}
			}
		}
Пример #8
0
		private void DeserializeDocumentDockContainer(ItemSerializationContext context, DocumentDockContainer instance, bool deserializeDefinition)
		{
            XmlElement docElement = context.ItemXmlElement;
			if(docElement.Name!=DocumentSerializationXml.DockContainer)
				return;

			instance.Documents.Clear();
			instance.Orientation=(eOrientation)XmlConvert.ToInt32(docElement.GetAttribute(DocumentSerializationXml.Orientation));
            if (docElement.HasAttribute(DocumentSerializationXml.Width) && docElement.HasAttribute(DocumentSerializationXml.Height))
            {
                instance.SetLayoutBounds(new Rectangle(0,0,
                    XmlConvert.ToInt32(docElement.GetAttribute(DocumentSerializationXml.Width)),
                    XmlConvert.ToInt32(docElement.GetAttribute(DocumentSerializationXml.Height))));
            }

			foreach(XmlElement elem in docElement.ChildNodes)
			{
				bool add=true;
				DocumentBaseContainer doc=DocumentSerializationXml.CreateDocument(elem.Name);
                context.ItemXmlElement = elem;
				if(doc is DocumentDockContainer)
					DeserializeDocumentDockContainer(context,(DocumentDockContainer)doc,deserializeDefinition);
				else if(doc is DocumentBarContainer)
                    add=DeserializeDocumentBarContainer(context,(DocumentBarContainer)doc,deserializeDefinition);
				if(add)
					instance.Documents.Add(doc);
			}
		}
Пример #9
0
		private DocumentBaseContainer GetDocumentFromBar(Bar bar, DocumentDockContainer dockContainer)
		{
			foreach(DocumentBaseContainer doc in dockContainer.Documents)
			{
				if(doc is DocumentBarContainer && ((DocumentBarContainer)doc).Bar==bar)
					return doc;
				else if(doc is DocumentDockContainer)
				{
					DocumentBaseContainer d=GetDocumentFromBar(bar,doc as DocumentDockContainer);
					if(d!=null)
						return d;
				}
			}
			return null;
		}
Пример #10
0
 private bool SerializeDocument(DocumentDockContainer instance)
 {
     if (instance.Documents.Count == 0) return false;
     foreach (DocumentBaseContainer doc in instance.Documents)
     {
         DocumentBarContainer bar = doc as DocumentBarContainer;
         if (bar != null)
         {
             if (bar.Bar != null && bar.Bar.SaveLayoutChanges) return true;
         }
         else
             return true;
     }
     return false;
 }
Пример #11
0
		private void SerializeDocumentDockContainer(XmlElement parent, DocumentDockContainer instance, bool definitionSerialization)
		{
            if (!SerializeDocument(instance))
				return;
            XmlElement document = null;
			
            document=parent.OwnerDocument.CreateElement(DocumentSerializationXml.DockContainer);
			parent.AppendChild(document);
			document.SetAttribute(DocumentSerializationXml.Orientation,XmlConvert.ToString((int)instance.Orientation));
            document.SetAttribute(DocumentSerializationXml.Width, instance.LayoutBounds.Width.ToString());
            document.SetAttribute(DocumentSerializationXml.Height, instance.LayoutBounds.Height.ToString());

			foreach(DocumentBaseContainer doc in instance.Documents)
			{
				if(doc is DocumentDockContainer)
                    SerializeDocumentDockContainer(document,(DocumentDockContainer)doc,definitionSerialization);
				else if(doc is DocumentBarContainer)
					SerializeDocumentBarContainer(document,(DocumentBarContainer)doc,definitionSerialization);
			}
		}
Пример #12
0
 private DocumentBaseContainer GetPreviousDocument(DocumentDockContainer parent, int refIndex)
 {
     int count = parent.Documents.Count;
     for (int i = refIndex - 1; i >= 0; i--)
     {
         if (parent.Documents[i].Visible)
             return parent.Documents[i];
     }
     return null;
 }
Пример #13
0
		private DocumentBaseContainer GetNextDocument(DocumentDockContainer parent, int refIndex)
		{
			int count=parent.Documents.Count;
			for(int i=refIndex+1;i<count;i++)
			{
				if(parent.Documents[i].Visible)
					return parent.Documents[i];
			}
			return null;
		}
Пример #14
0
		private void ResetLayoutBounds(DocumentDockContainer doc)
		{
			foreach(DocumentBaseContainer d in doc.Documents)
				d.SetLayoutBounds(Rectangle.Empty);
		}
Пример #15
0
        internal Size GetContainerMinimumSize(DocumentDockContainer dockContainer)
        {
            Size minimumSize = Size.Empty;

            foreach (DocumentBaseContainer d in dockContainer.Documents)
            {
                Size dm = Size.Empty;

                if (d is DocumentBarContainer)
                {
                    if (!((DocumentBarContainer)d).Visible) continue;
                    dm = d.MinimumSize;
                }
                else if (d is DocumentDockContainer)
                {
                    dm = GetContainerMinimumSize(d as DocumentDockContainer);
                }

                if (dockContainer.Orientation == eOrientation.Horizontal)
                {
                    minimumSize.Width += dm.Width + dockContainer.SplitterSize;
                    if (dm.Height < minimumSize.Height || minimumSize.Height == 0)
                        minimumSize.Height = dm.Height;
                }
                else
                {
                    minimumSize.Height += dm.Height + dockContainer.SplitterSize;
                    if (dm.Width < minimumSize.Width || minimumSize.Width == 0)
                        minimumSize.Width = dm.Width;
                }
            }

            if (minimumSize.Width > 0 && dockContainer.Orientation == eOrientation.Horizontal)
                minimumSize.Width += dockContainer.SplitterSize;
            else if (minimumSize.Height > 0 && dockContainer.Orientation == eOrientation.Vertical)
                minimumSize.Height += dockContainer.SplitterSize;

            if (minimumSize.Width == 0)
                minimumSize.Width = 32;
            if (minimumSize.Height == 0)
                minimumSize.Height = 32;

            return minimumSize;
        }
Пример #16
0
		private void OnEnableDocumentDocking(object sender, EventArgs e)
		{
			DotNetBarManager m=this.Component as DotNetBarManager;
			if(m.FillDockSite==null)
			{
				IDesignerHost dh=(IDesignerHost)GetService(typeof(IDesignerHost));
				if(dh==null)
					return;

				System.Windows.Forms.Control parent=dh.RootComponent as System.Windows.Forms.Control;
				if(parent==null)
					return;

				IComponentChangeService cc=(IComponentChangeService)GetService(typeof(IComponentChangeService));
				if(cc==null)
					return;

				DesignerTransaction trans=dh.CreateTransaction("Document Docking Enabled");
				
                DockSite fillDock=dh.CreateComponent(typeof(DockSite)) as DockSite;
                fillDock.Dock=System.Windows.Forms.DockStyle.Fill;

				cc.OnComponentChanging(parent,TypeDescriptor.GetProperties(typeof(System.Windows.Forms.Control))["Controls"]);
				parent.Controls.Add(fillDock);
				fillDock.BringToFront();
				cc.OnComponentChanged(parent,TypeDescriptor.GetProperties(typeof(System.Windows.Forms.Control))["Controls"],null,null);

				cc.OnComponentChanging(m,TypeDescriptor.GetProperties(typeof(DotNetBarManager))["FillDockSite"]);
				m.FillDockSite=fillDock;
				cc.OnComponentChanged(m,TypeDescriptor.GetProperties(typeof(DotNetBarManager))["FillDockSite"],null,fillDock);

				DocumentDockContainer dockContainer=new DocumentDockContainer();
				cc.OnComponentChanging(fillDock,TypeDescriptor.GetProperties(typeof(DockSite))["DocumentDockContainer"]);
				fillDock.DocumentDockContainer=dockContainer;
				cc.OnComponentChanged(fillDock,TypeDescriptor.GetProperties(typeof(DockSite))["DocumentDockContainer"],null,dockContainer);
				
				Bar bar=dh.CreateComponent(typeof(Bar)) as Bar;
				BarUtilities.InitializeDocumentBar(bar);
//				bar.LayoutType=eLayoutType.DockContainer;
//				bar.DockTabAlignment=eTabStripAlignment.Top;
//				bar.AlwaysDisplayDockTab=true;
//				bar.Stretch=true;
//				bar.GrabHandleStyle=eGrabHandleStyle.None;
				TypeDescriptor.GetProperties(bar)["Style"].SetValue(bar,m.Style);
//				bar.Style=m.Style;
//				bar.CanDockBottom=false;
//				bar.CanDockTop=false;
//				bar.CanDockLeft=false;
//				bar.CanDockRight=false;
//				bar.CanDockDocument=true;
//				bar.CanUndock=false;
//				bar.CanHide=true;
//				bar.CanCustomize=false;

				DockContainerItem item=dh.CreateComponent(typeof(DockContainerItem)) as DockContainerItem;
				item.Text=item.Name;
				cc.OnComponentChanging(bar,TypeDescriptor.GetProperties(typeof(Bar))["Items"]);
				bar.Items.Add(item);
				PanelDockContainer panel=dh.CreateComponent(typeof(PanelDockContainer)) as PanelDockContainer;
				cc.OnComponentChanging(bar, TypeDescriptor.GetProperties(typeof(Bar))["Controls"]);
				item.Control=panel;                
				cc.OnComponentChanged(bar, TypeDescriptor.GetProperties(typeof(Bar))["Controls"], null, null);
                //bar.Controls.Add(panel);
				panel.ColorSchemeStyle=m.Style;
				panel.ApplyLabelStyle();
				cc.OnComponentChanged(bar,TypeDescriptor.GetProperties(typeof(Bar))["Items"],null,null);

				DocumentBarContainer doc=new DocumentBarContainer(bar);
				dockContainer.Documents.Add(doc);
                
				cc.OnComponentChanging(fillDock,TypeDescriptor.GetProperties(typeof(DockSite))["Controls"]);
				fillDock.Controls.Add(bar);
				cc.OnComponentChanged(fillDock,TypeDescriptor.GetProperties(typeof(DockSite))["Controls"],null,null);

				fillDock.RecalcLayout();
				
				trans.Commit();
			}
		}