Exemplo n.º 1
0
		internal void LoadDefinition(System.Xml.XmlDocument xmlDoc)
		{
            System.Xml.XmlElement xmlDotNetBar=xmlDoc.FirstChild as System.Xml.XmlElement;

            // Do not load old uncompatible definitions
            if (xmlDotNetBar != null && (!xmlDotNetBar.HasAttribute(DocumentSerializationXml.Version) ||
               XmlConvert.ToInt32(xmlDotNetBar.GetAttribute(DocumentSerializationXml.Version)) < 6))
                return;

			bool bSuspendLayout=false;

            // Creates serialization context
            ItemSerializationContext context = new ItemSerializationContext();
            context.Serializer = this;
            context.HasDeserializeItemHandlers = ((ICustomSerialization)this).HasDeserializeItemHandlers;
            context.HasSerializeItemHandlers = ((ICustomSerialization)this).HasSerializeItemHandlers;

            // Cache content of DockContainerItem objects so it can be loaded by new definition if they match
            context.DockControls = GetDockControls();

			try
			{
				m_LoadingDefinition=true;

				if(!this.SuspendLayout)
				{
					bSuspendLayout=true;
					this.SuspendLayout=true;
				}

				try
				{
					IgnoreLoadedControlDispose=true;
					m_Items.Clear();
					if(m_IncludeDockDocumentsInDefinition)
						m_Bars.Clear();
					else
						m_Bars.ClearNonDocumentBars();
					m_ContextMenus.Clear();
					m_ShortcutTable.Clear();
				}
				finally
				{
					IgnoreLoadedControlDispose=false;
				}
				
				// Destroy auto-hide sites
				DestroyAutoHidePanels();			

				if(xmlDotNetBar==null)
				{
					if(bSuspendLayout)
						this.SuspendLayout=false;
					return;
				}

				if(xmlDotNetBar.Name!="dotnetbar")
					throw new System.InvalidOperationException("Invalid file format (dotnetbar).");

//				if(xmlDotNetBar.HasAttribute("zorder"))
//					RestoreDockSiteZOrder(xmlDotNetBar.GetAttribute("zorder"));
			
				// Load user defined settings
				if(xmlDotNetBar.HasAttribute("fullmenus"))
					m_AlwaysShowFullMenus=System.Xml.XmlConvert.ToBoolean(xmlDotNetBar.GetAttribute("fullmenus"));
				else
					m_AlwaysShowFullMenus=false;
				if(xmlDotNetBar.HasAttribute("fullmenushover"))
					m_ShowFullMenusOnHover=System.Xml.XmlConvert.ToBoolean(xmlDotNetBar.GetAttribute("fullmenushover"));
				else
					m_ShowFullMenusOnHover=true;
				if(xmlDotNetBar.HasAttribute("tooltips"))
					m_ShowToolTips=System.Xml.XmlConvert.ToBoolean(xmlDotNetBar.GetAttribute("tooltips"));
				else
					m_ShowToolTips=true;
				if(xmlDotNetBar.HasAttribute("scintooltip"))
					m_ShowShortcutKeysInToolTips=System.Xml.XmlConvert.ToBoolean(xmlDotNetBar.GetAttribute("scintooltip"));
				else
					m_ShowShortcutKeysInToolTips=false;
				if(xmlDotNetBar.HasAttribute("animation"))
				{
					if((ePopupAnimation)System.Xml.XmlConvert.ToInt32(xmlDotNetBar.GetAttribute("animation"))!=ePopupAnimation.SystemDefault)
						m_PopupAnimation=(ePopupAnimation)System.Xml.XmlConvert.ToInt32(xmlDotNetBar.GetAttribute("animation"));
				}
				else
					m_PopupAnimation=ePopupAnimation.SystemDefault;
				
				foreach(System.Xml.XmlElement xmlElem in xmlDotNetBar.ChildNodes)
				{
					if(xmlElem.Name=="items")
					{
						foreach(System.Xml.XmlElement xmlItem in xmlElem.ChildNodes)
						{
							BaseItem objItem=BarFunctions.CreateItemFromXml(xmlItem);
							if(objItem==null)
								throw new System.InvalidOperationException("Invalid Item in file found ("+BarFunctions.GetItemErrorInfo(xmlItem)+").");
							// Do not change this order. Item should be Deserialized first and then added to the items
							// collection. See GlobalItem property for performace reasons...
                            context.ItemXmlElement = xmlItem;
							objItem.Deserialize(context);
							m_Items.Add(objItem);
						}
					}
					else if(xmlElem.Name=="bars")
					{
						foreach(System.Xml.XmlElement xmlBar in xmlElem.ChildNodes)
						{
							DevComponents.DotNetBar.Bar bar=new DevComponents.DotNetBar.Bar();
							bar.Visible=false;
							bar.SetDesignMode(this.DesignMode);
							m_Bars.Add(bar);
							bar.Deserialize(xmlBar);
							IOwnerBarSupport ownersupport=this as IOwnerBarSupport;
							ownersupport.AddShortcutsFromBar(bar);
						}
					}
					else if(xmlElem.Name=="popups")
					{
						foreach(System.Xml.XmlElement xmlItem in xmlElem.ChildNodes)
						{
							BaseItem objItem=BarFunctions.CreateItemFromXml(xmlItem);
							if(objItem==null)
								throw new System.InvalidOperationException("Invalid Item in file found ("+BarFunctions.GetItemErrorInfo(xmlItem)+").");
							// Do not change this order. Item should be Deserialized first and then added to the items
							// collection. See GlobalItem property for performace reasons...
                            context.ItemXmlElement = xmlItem;
							objItem.Deserialize(context);
							m_ContextMenus.Add(objItem);
						}
					}
					else if(xmlElem.Name==DocumentSerializationXml.Documents && m_IncludeDockDocumentsInDefinition)
					{
                        context.ItemXmlElement = xmlElem;
						if(m_FillDockSite!=null)
							m_FillDockSite.GetDocumentUIManager().DeserializeDefinition(context);
					}
                    else if (xmlElem.Name == DocumentSerializationXml.DockSite)
                    {
                        context.ItemXmlElement = xmlElem;

                        DockStyle dockingSide = (DockStyle)Enum.Parse(typeof(DockStyle), xmlElem.GetAttribute(DocumentSerializationXml.DockingSide));
                        if (dockingSide == DockStyle.Left)
                        {
                            if (m_LeftDockSite != null) m_LeftDockSite.GetDocumentUIManager().DeserializeDefinition(context);
                        }
                        else if (dockingSide == DockStyle.Right)
                        {
                            if (m_RightDockSite != null) m_RightDockSite.GetDocumentUIManager().DeserializeDefinition(context);
                        }
                        else if (dockingSide == DockStyle.Top)
                        {
                            if (m_TopDockSite != null) m_TopDockSite.GetDocumentUIManager().DeserializeDefinition(context);
                        }
                        else if (dockingSide == DockStyle.Bottom)
                        {
                            if (m_BottomDockSite != null) m_BottomDockSite.GetDocumentUIManager().DeserializeDefinition(context);
                        }
                    }
				}
			}
			finally
			{
				m_LoadingDefinition=false;
				if(bSuspendLayout) this.SuspendLayout=false;
			}

            if (context.DockControls != null && context.DockControls.Count > 0)
            {
                foreach (Control c in context.DockControls.Values)
                    c.Dispose();
            }

			((IOwner)this).InvokeDefinitionLoaded(this,new EventArgs());

			if(m_ActiveMdiChild!=null && m_MdiChildMaximized)
			{
				m_MdiChildMaximized=false;
                this.OnMdiChildResize(m_ActiveMdiChild,new EventArgs());
			}
        }