Inheritance: System.ComponentModel.TypeConverter
Ejemplo n.º 1
0
        /// <summary>
        /// Load the application config file and restore form position
        /// </summary>
        private void LoadConfigFile()
        {
            TextReader reader = null;
            Rectangle formBounds = Rectangle.Empty;
            try
            {
                string configFolder = Path.GetDirectoryName(InstallPadApp.ConfigFilePath);
                if (!Directory.Exists(configFolder))
                    Directory.CreateDirectory(configFolder);

                reader = new StreamReader(InstallPadApp.ConfigFilePath);
                RectangleConverter converter = new RectangleConverter();
                formBounds = (Rectangle)converter.ConvertFromString(reader.ReadLine());
            }
            catch (NotSupportedException)
            {
                // Error in the configure file. Ignore
            }
            catch (IOException)
            {
                // No config file found. Ignore
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
            if (formBounds != Rectangle.Empty)
            {
                // If the bounds are outside of the screen's work area, move the form so it's not outside
                // of the work area. This can happen if the user changes their resolution 
                // and we then restore the applicationto its position -- it may be off screen and 
                // then they can't see it or move it.

                // Get the working area of the monitor that contains this rectangle (in case it's a
                // multi-display system
                Rectangle workingArea = Screen.GetWorkingArea(formBounds);
                if (formBounds.Left < workingArea.Left)
                    formBounds.Location = new Point(workingArea.Location.X, formBounds.Location.Y);
                if (formBounds.Top < workingArea.Top)
                    formBounds.Location = new Point(formBounds.Location.X, workingArea.Location.Y);
                if (formBounds.Right > workingArea.Right)
                    formBounds.Location = new Point(formBounds.X - (formBounds.Right - workingArea.Right),
                        formBounds.Location.Y);
                if (formBounds.Bottom > workingArea.Bottom)
                    formBounds.Location = new Point(formBounds.X,
                        formBounds.Y - (formBounds.Bottom - workingArea.Bottom));

                this.Bounds = formBounds;
            }

        }
Ejemplo n.º 2
0
		public void SetUp ()
		{
			rect = new Rectangle (10, 10, 20, 30);
			rectStrInvariant = rect.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " +
			rect.Y + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " +
			rect.Width + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + 
			rect.Height;

			rectneg = new Rectangle (-10, -10, 20, 30);
			rectnegStrInvariant = rectneg.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " 
			+ rectneg.Y + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + 
			rectneg.Width + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + rectneg.Height;

			rconv = (RectangleConverter) TypeDescriptor.GetConverter (rect);
		}
Ejemplo n.º 3
0
            private static FloatWindowStruct[] LoadFloatWindows(XmlTextReader xmlIn)
            {
                EnumConverter dockAlignmentConverter = new EnumConverter(typeof(DockAlignment));
                RectangleConverter rectConverter = new RectangleConverter();
                int countOfFloatWindows = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
                FloatWindowStruct[] floatWindows = new FloatWindowStruct[countOfFloatWindows];
                MoveToNextElement(xmlIn);
                for (int i = 0; i < countOfFloatWindows; i++)
                {
                    int id = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
                    if (xmlIn.Name != "FloatWindow" || id != i)
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);

                    floatWindows[i].Bounds = (Rectangle)rectConverter.ConvertFromInvariantString(xmlIn.GetAttribute("Bounds"));
                    floatWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"), CultureInfo.InvariantCulture);
                    MoveToNextElement(xmlIn);
                    if (xmlIn.Name != "DockList" && xmlIn.Name != "NestedPanes")
                        throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                    int countOfNestedPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"), CultureInfo.InvariantCulture);
                    floatWindows[i].NestedPanes = new NestedPane[countOfNestedPanes];
                    MoveToNextElement(xmlIn);
                    for (int j = 0; j < countOfNestedPanes; j++)
                    {
                        int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"), CultureInfo.InvariantCulture);
                        if (xmlIn.Name != "Pane" || id2 != j)
                            throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
                        floatWindows[i].NestedPanes[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"), CultureInfo.InvariantCulture);
                        floatWindows[i].NestedPanes[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"), CultureInfo.InvariantCulture);
                        floatWindows[i].NestedPanes[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
                        floatWindows[i].NestedPanes[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
                        MoveToNextElement(xmlIn);
                    }
                }

                return floatWindows;
            }
Ejemplo n.º 4
0
            public static void SaveAsXml(DockPanel dockPanel, Stream stream, Encoding encoding, bool upstream)
            {
                XmlTextWriter xmlOut = new XmlTextWriter(stream, encoding);

                // Use indenting for readability
                xmlOut.Formatting = Formatting.Indented;

                if (!upstream)
                    xmlOut.WriteStartDocument();

                // Always begin file with identification and warning
                xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment1);
                xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment2);

                // Associate a version number with the root element so that future version of the code
                // will be able to be backwards compatible or at least recognise out of date versions
                xmlOut.WriteStartElement("DockPanel");
                xmlOut.WriteAttributeString("FormatVersion", ConfigFileVersion);
                xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
                xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
                xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
                xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));

                if (!Win32Helper.IsRunningOnMono)
                {
                    xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString(CultureInfo.InvariantCulture));
                }                

                // Contents
                xmlOut.WriteStartElement("Contents");
                xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString(CultureInfo.InvariantCulture));
                foreach (IDockContent content in dockPanel.Contents)
                {
                    xmlOut.WriteStartElement("Content");
                    xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("PersistString", content.DockHandler.PersistString);
                    xmlOut.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();

                // Panes
                xmlOut.WriteStartElement("Panes");
                xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString(CultureInfo.InvariantCulture));
                foreach (DockPane pane in dockPanel.Panes)
                {
                    xmlOut.WriteStartElement("Pane");
                    xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
                    xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteStartElement("Contents");
                    xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString(CultureInfo.InvariantCulture));
                    foreach (IDockContent content in pane.Contents)
                    {
                        xmlOut.WriteStartElement("Content");
                        xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();

                // DockWindows
                xmlOut.WriteStartElement("DockWindows");
                int dockWindowId = 0;
                foreach (DockWindow dw in dockPanel.DockWindows)
                {
                    xmlOut.WriteStartElement("DockWindow");
                    xmlOut.WriteAttributeString("ID", dockWindowId.ToString(CultureInfo.InvariantCulture));
                    dockWindowId++;
                    xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
                    xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteStartElement("NestedPanes");
                    xmlOut.WriteAttributeString("Count", dw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
                    foreach (DockPane pane in dw.NestedPanes)
                    {
                        xmlOut.WriteStartElement("Pane");
                        xmlOut.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                        NestedDockingStatus status = pane.NestedDockingStatus;
                        xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
                        xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();

                // FloatWindows
                RectangleConverter rectConverter = new RectangleConverter();
                xmlOut.WriteStartElement("FloatWindows");
                xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString(CultureInfo.InvariantCulture));
                foreach (FloatWindow fw in dockPanel.FloatWindows)
                {
                    xmlOut.WriteStartElement("FloatWindow");
                    xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
                    xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
                    xmlOut.WriteStartElement("NestedPanes");
                    xmlOut.WriteAttributeString("Count", fw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
                    foreach (DockPane pane in fw.NestedPanes)
                    {
                        xmlOut.WriteStartElement("Pane");
                        xmlOut.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                        NestedDockingStatus status = pane.NestedDockingStatus;
                        xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
                        xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();	//	</FloatWindows>

                xmlOut.WriteEndElement();

                if (!upstream)
                {
                    xmlOut.WriteEndDocument();
                    xmlOut.Close();
                }
                else
                    xmlOut.Flush();
            }
Ejemplo n.º 5
0
		public static void LoadFromXml(DockPanel dockPanel, Stream stream, DeserializeDockContent deserializeContent)
		{

			if (dockPanel.Contents.Count != 0)
				throw new InvalidOperationException(ResourceHelper.GetString("DockPanel.LoadFromXml.AlreadyInitialized"));

			EnumConverter dockStateConverter = new EnumConverter(typeof(DockState));
			EnumConverter dockAlignmentConverter = new EnumConverter(typeof(DockAlignment));
			RectangleConverter rectConverter = new RectangleConverter();

			XmlTextReader xmlIn = new XmlTextReader(stream);
			xmlIn.WhitespaceHandling = WhitespaceHandling.None;
			xmlIn.MoveToContent();

			if (xmlIn.Name != "DockPanel")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

			string formatVersion = xmlIn.GetAttribute("FormatVersion");
			if (formatVersion != ConfigFileVersion)
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidFormatVersion"));
			DockPanelStruct dockPanelStruct = new DockPanelStruct();
			dockPanelStruct.DockLeftPortion = Convert.ToDouble(xmlIn.GetAttribute("DockLeftPortion"), CultureInfo.InvariantCulture);
			dockPanelStruct.DockRightPortion = Convert.ToDouble(xmlIn.GetAttribute("DockRightPortion"), CultureInfo.InvariantCulture);
			dockPanelStruct.DockTopPortion = Convert.ToDouble(xmlIn.GetAttribute("DockTopPortion"), CultureInfo.InvariantCulture);
			dockPanelStruct.DockBottomPortion = Convert.ToDouble(xmlIn.GetAttribute("DockBottomPortion"), CultureInfo.InvariantCulture);
			dockPanelStruct.IndexActiveDocumentPane = Convert.ToInt32(xmlIn.GetAttribute("ActiveDocumentPane"));
			dockPanelStruct.IndexActivePane = Convert.ToInt32(xmlIn.GetAttribute("ActivePane"));

			// Load Contents
			MoveToNextElement(xmlIn);
			if (xmlIn.Name != "Contents")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
			int countOfContents = Convert.ToInt32(xmlIn.GetAttribute("Count"));
			ContentStruct[] contents = new ContentStruct[countOfContents];
			MoveToNextElement(xmlIn);
			for (int i=0; i<countOfContents; i++)
			{
				int id = Convert.ToInt32(xmlIn.GetAttribute("ID"));
				if (xmlIn.Name != "Content" || id != i)
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

				contents[i].PersistString = xmlIn.GetAttribute("PersistString");
				contents[i].AutoHidePortion = Convert.ToDouble(xmlIn.GetAttribute("AutoHidePortion"), CultureInfo.InvariantCulture);
				contents[i].IsHidden = Convert.ToBoolean(xmlIn.GetAttribute("IsHidden"));
				contents[i].IsFloat = Convert.ToBoolean(xmlIn.GetAttribute("IsFloat"));
				MoveToNextElement(xmlIn);
			}

			// Load Panes
			if (xmlIn.Name != "Panes")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
			int countOfPanes = Convert.ToInt32(xmlIn.GetAttribute("Count"));
			PaneStruct[] panes = new PaneStruct[countOfPanes];
			MoveToNextElement(xmlIn);
			for (int i=0; i<countOfPanes; i++)
			{
				int id = Convert.ToInt32(xmlIn.GetAttribute("ID"));
				if (xmlIn.Name != "Pane" || id != i)
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

				panes[i].DockState = (DockState)dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
				panes[i].IndexActiveContent = Convert.ToInt32(xmlIn.GetAttribute("ActiveContent"));
				panes[i].ZOrderIndex = -1;

				MoveToNextElement(xmlIn);
				if (xmlIn.Name != "Contents")
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
				int countOfPaneContents = Convert.ToInt32(xmlIn.GetAttribute("Count"));
				panes[i].IndexContents = new int[countOfPaneContents];
				MoveToNextElement(xmlIn);
				for (int j=0; j<countOfPaneContents; j++)
				{
					int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"));
					if (xmlIn.Name != "Content" || id2 != j)
						throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

					panes[i].IndexContents[j] = Convert.ToInt32(xmlIn.GetAttribute("RefID"));
					MoveToNextElement(xmlIn);
				}
			}

			// Load DockWindows
			if (xmlIn.Name != "DockWindows")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
			int countOfDockWindows = Convert.ToInt32(xmlIn.GetAttribute("Count"));
			DockWindowStruct[] dockWindows = new DockWindowStruct[countOfDockWindows];
			MoveToNextElement(xmlIn);
			for (int i=0; i<countOfDockWindows; i++)
			{
				int id = Convert.ToInt32(xmlIn.GetAttribute("ID"));
				if (xmlIn.Name != "DockWindow" || id != i)
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

				dockWindows[i].DockState = (DockState)dockStateConverter.ConvertFrom(xmlIn.GetAttribute("DockState"));
				dockWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"));
				MoveToNextElement(xmlIn);
				if (xmlIn.Name != "DockList")
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
				int countOfDockList = Convert.ToInt32(xmlIn.GetAttribute("Count"));
				dockWindows[i].DockList = new DockListItem[countOfDockList];
				MoveToNextElement(xmlIn);
				for (int j=0; j<countOfDockList; j++)
				{
					int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"));
					if (xmlIn.Name != "Pane" || id2 != j)
						throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
					dockWindows[i].DockList[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"));
					dockWindows[i].DockList[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"));
					dockWindows[i].DockList[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
					dockWindows[i].DockList[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
					MoveToNextElement(xmlIn);
				}
			}

			// Load FloatWindows
			if (xmlIn.Name != "FloatWindows")
				throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
			int countOfFloatWindows = Convert.ToInt32(xmlIn.GetAttribute("Count"));
			FloatWindowStruct[] floatWindows = new FloatWindowStruct[countOfFloatWindows];
			MoveToNextElement(xmlIn);
			for (int i=0; i<countOfFloatWindows; i++)
			{
				int id = Convert.ToInt32(xmlIn.GetAttribute("ID"));
				if (xmlIn.Name != "FloatWindow" || id != i)
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));

				floatWindows[i].Bounds = (Rectangle)rectConverter.ConvertFromInvariantString(xmlIn.GetAttribute("Bounds"));
				floatWindows[i].AllowRedocking = Convert.ToBoolean(xmlIn.GetAttribute("AllowRedocking"));
				floatWindows[i].ZOrderIndex = Convert.ToInt32(xmlIn.GetAttribute("ZOrderIndex"));
				MoveToNextElement(xmlIn);
				if (xmlIn.Name != "DockList")
					throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
				int countOfDockList = Convert.ToInt32(xmlIn.GetAttribute("Count"));
				floatWindows[i].DockList = new DockListItem[countOfDockList];
				MoveToNextElement(xmlIn);
				for (int j=0; j<countOfDockList; j++)
				{
					int id2 = Convert.ToInt32(xmlIn.GetAttribute("ID"));
					if (xmlIn.Name != "Pane" || id2 != j)
						throw new ArgumentException(ResourceHelper.GetString("DockPanel.LoadFromXml.InvalidXmlFormat"));
					floatWindows[i].DockList[j].IndexPane = Convert.ToInt32(xmlIn.GetAttribute("RefID"));
					floatWindows[i].DockList[j].IndexPrevPane = Convert.ToInt32(xmlIn.GetAttribute("PrevPane"));
					floatWindows[i].DockList[j].Alignment = (DockAlignment)dockAlignmentConverter.ConvertFrom(xmlIn.GetAttribute("Alignment"));
					floatWindows[i].DockList[j].Proportion = Convert.ToDouble(xmlIn.GetAttribute("Proportion"), CultureInfo.InvariantCulture);
					MoveToNextElement(xmlIn);
				}
			}
			xmlIn.Close();
					
			dockPanel.DockLeftPortion = dockPanelStruct.DockLeftPortion;
			dockPanel.DockRightPortion = dockPanelStruct.DockRightPortion;
			dockPanel.DockTopPortion = dockPanelStruct.DockTopPortion;
			dockPanel.DockBottomPortion = dockPanelStruct.DockBottomPortion;

			// Create Contents
			for (int i=0; i<contents.Length; i++)
			{
				DockContent content = deserializeContent(contents[i].PersistString);
				if (content == null)
					content = new DummyContent();
				content.DockPanel = dockPanel;
				content.AutoHidePortion = contents[i].AutoHidePortion;
				content.IsHidden = true;
				content.IsFloat = contents[i].IsFloat;
			}

			// Create panes
			for (int i=0; i<panes.Length; i++)
			{
				DockPane pane = null;
				for (int j=0; j<panes[i].IndexContents.Length; j++)
				{
					DockContent content = dockPanel.Contents[panes[i].IndexContents[j]];
					if (j==0)
						pane = dockPanel.DockPaneFactory.CreateDockPane(content, panes[i].DockState, false);
					else if (panes[i].DockState == DockState.Float)
						content.FloatPane = pane;
					else
						content.PanelPane = pane;
				}
			}

			// Assign Panes to DockWindows
			for (int i=0; i<dockWindows.Length; i++)
			{
				for (int j=0; j<dockWindows[i].DockList.Length; j++)
				{
					DockWindow dw = dockPanel.DockWindows[dockWindows[i].DockState];
					int indexPane = dockWindows[i].DockList[j].IndexPane;
					DockPane pane = dockPanel.Panes[indexPane];
					int indexPrevPane = dockWindows[i].DockList[j].IndexPrevPane;
					DockPane prevPane = (indexPrevPane == -1) ? dw.DockList.GetDefaultPrevPane(pane) : dockPanel.Panes[indexPrevPane];
					DockAlignment alignment = dockWindows[i].DockList[j].Alignment;
					double proportion = dockWindows[i].DockList[j].Proportion;
					pane.AddToDockList(dw, prevPane, alignment, proportion);
					if (panes[indexPane].DockState == dw.DockState)
						panes[indexPane].ZOrderIndex = dockWindows[i].ZOrderIndex;
				}
			}

			// Create float windows
			for (int i=0; i<floatWindows.Length; i++)
			{
				FloatWindow fw = null;
				for (int j=0; j<floatWindows[i].DockList.Length; j++)
				{
					int indexPane = floatWindows[i].DockList[j].IndexPane;
					DockPane pane = dockPanel.Panes[indexPane];
					if (j == 0)
						fw = dockPanel.FloatWindowFactory.CreateFloatWindow(dockPanel, pane, floatWindows[i].Bounds);
					else
					{
						int indexPrevPane = floatWindows[i].DockList[j].IndexPrevPane;
						DockPane prevPane = indexPrevPane == -1 ? null : dockPanel.Panes[indexPrevPane];
						DockAlignment alignment = floatWindows[i].DockList[j].Alignment;
						double proportion = floatWindows[i].DockList[j].Proportion;
						pane.AddToDockList(fw, prevPane, alignment, proportion);
						if (panes[indexPane].DockState == fw.DockState)
							panes[indexPane].ZOrderIndex = floatWindows[i].ZOrderIndex;
					}
				}
			}

			// sort DockContent by its Pane's ZOrder
			int[] sortedContents = null;
			if (contents.Length > 0)
			{
				sortedContents = new int[contents.Length];
				for (int i=0; i<contents.Length; i++)
					sortedContents[i] = i;

				int lastDocument = contents.Length;
				for (int i=0; i<contents.Length - 1; i++)
				{
					for (int j=i+1; j<contents.Length; j++)
					{
						DockPane pane1 = dockPanel.Contents[sortedContents[i]].Pane;
						int ZOrderIndex1 = pane1 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane1)].ZOrderIndex;
						DockPane pane2 = dockPanel.Contents[sortedContents[j]].Pane;
						int ZOrderIndex2 = pane2 == null ? 0 : panes[dockPanel.Panes.IndexOf(pane2)].ZOrderIndex;
						if (ZOrderIndex1 > ZOrderIndex2)
						{
							int temp = sortedContents[i];
							sortedContents[i] = sortedContents[j];
							sortedContents[j] = temp;
						}
					}
				}
			}

			// show non-document DockContent first to avoid screen flickers
			for (int i=0; i<contents.Length; i++)
			{
				DockContent content = dockPanel.Contents[sortedContents[i]];
				if (content.Pane != null && content.Pane.DockState != DockState.Document)
					content.IsHidden = contents[sortedContents[i]].IsHidden;
			}

			// after all non-document DockContent, show document DockContent
			for (int i=0; i<contents.Length; i++)
			{
				DockContent content = dockPanel.Contents[sortedContents[i]];
				if (content.Pane != null && content.Pane.DockState == DockState.Document)
					content.IsHidden = contents[sortedContents[i]].IsHidden;
			}

			for (int i=0; i<panes.Length; i++)
				dockPanel.Panes[i].ActiveContent = panes[i].IndexActiveContent == -1 ? null : dockPanel.Contents[panes[i].IndexActiveContent];

			if (dockPanelStruct.IndexActiveDocumentPane != -1)
				dockPanel.Panes[dockPanelStruct.IndexActiveDocumentPane].Activate();

			if (dockPanelStruct.IndexActivePane != -1)
				dockPanel.Panes[dockPanelStruct.IndexActivePane].Activate();

			for (int i=dockPanel.Contents.Count-1; i>=0; i--)
				if (dockPanel.Contents[i] is DummyContent)
					dockPanel.Contents[i].Close();
		}
Ejemplo n.º 6
0
		public static void SaveAsXml(DockPanel dockPanel, Stream stream, Encoding encoding)
		{
			XmlTextWriter xmlOut = new XmlTextWriter(stream, encoding); 

			// Use indenting for readability
			xmlOut.Formatting = Formatting.Indented;
			
			// Always begin file with identification and warning
			xmlOut.WriteStartDocument();
			xmlOut.WriteComment(" DockPanel configuration file. Author: Weifen Luo, all rights reserved. ");
			xmlOut.WriteComment(" !!! AUTOMATICALLY GENERATED FILE. DO NOT MODIFY !!! ");

			// Associate a version number with the root element so that future version of the code
			// will be able to be backwards compatible or at least recognise out of date versions
			xmlOut.WriteStartElement("DockPanel");
			xmlOut.WriteAttributeString("FormatVersion", ConfigFileVersion);
			xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
			xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
			xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
			xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));
			xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString());
			xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString());

			// Contents
			xmlOut.WriteStartElement("Contents");
			xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString());
			foreach (DockContent content in dockPanel.Contents)
			{
				xmlOut.WriteStartElement("Content");
				xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString());
				xmlOut.WriteAttributeString("PersistString", content.PersistString);
				xmlOut.WriteAttributeString("AutoHidePortion", content.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
				xmlOut.WriteAttributeString("IsHidden", content.IsHidden.ToString());
				xmlOut.WriteAttributeString("IsFloat", content.IsFloat.ToString());
				xmlOut.WriteEndElement();
			}
			xmlOut.WriteEndElement();

			// Panes
			xmlOut.WriteStartElement("Panes");
			xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString());
			foreach (DockPane pane in dockPanel.Panes)
			{
				xmlOut.WriteStartElement("Pane");
				xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString());
				xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
				xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString());
				xmlOut.WriteStartElement("Contents");
				xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString());
				foreach (DockContent content in pane.Contents)
				{
					xmlOut.WriteStartElement("Content");
					xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString());
					xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString());
					xmlOut.WriteEndElement();
				}
				xmlOut.WriteEndElement();
				xmlOut.WriteEndElement();
			}
			xmlOut.WriteEndElement();

			// DockWindows
			xmlOut.WriteStartElement("DockWindows");
			int count = 0;
			foreach (DockWindow dw in dockPanel.DockWindows)
				if (dw.DockList.Count > 0)
					count++;
			xmlOut.WriteAttributeString("Count", count.ToString());
			int i = 0;
			foreach (DockWindow dw in dockPanel.DockWindows)
			{
				if (dw.DockList.Count == 0)
					continue;
				xmlOut.WriteStartElement("DockWindow");
				xmlOut.WriteAttributeString("ID", i.ToString());
				xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
				xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString());
				xmlOut.WriteStartElement("DockList");
				xmlOut.WriteAttributeString("Count", dw.DockList.Count.ToString());
				foreach (DockPane pane in dw.DockList)
				{
					xmlOut.WriteStartElement("Pane");
					xmlOut.WriteAttributeString("ID", dw.DockList.IndexOf(pane).ToString());
					xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString());
					NestedDockingStatus status = pane.NestedDockingStatus;
					xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PrevPane).ToString());
					xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
					xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
					xmlOut.WriteEndElement();
				}
				xmlOut.WriteEndElement();
				xmlOut.WriteEndElement();
				i++;
			}
			xmlOut.WriteEndElement();

			// FloatWindows
			RectangleConverter rectConverter = new RectangleConverter();
			xmlOut.WriteStartElement("FloatWindows");
			xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString());
			foreach (FloatWindow fw in dockPanel.FloatWindows)
			{
				xmlOut.WriteStartElement("FloatWindow");
				xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString());
				xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
				xmlOut.WriteAttributeString("AllowRedocking", fw.AllowRedocking.ToString());
				xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString());
				xmlOut.WriteStartElement("DockList");
				xmlOut.WriteAttributeString("Count", fw.DockList.Count.ToString());
				foreach (DockPane pane in fw.DockList)
				{
					xmlOut.WriteStartElement("Pane");
					xmlOut.WriteAttributeString("ID", fw.DockList.IndexOf(pane).ToString());
					xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString());
					NestedDockingStatus status = pane.NestedDockingStatus;
					xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PrevPane).ToString());
					xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
					xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
					xmlOut.WriteEndElement();
				}
				xmlOut.WriteEndElement();
				xmlOut.WriteEndElement();
			}
			xmlOut.WriteEndElement();	//	</FloatWindows>
			
			xmlOut.WriteEndElement();
			xmlOut.WriteEndDocument();

			// This should flush all actions and close the file
			xmlOut.Close();
		}
Ejemplo n.º 7
0
        void InstallPad_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Serialize form position to file, so we can restore it later.
            RectangleConverter convert = new RectangleConverter();
            string formPosition = convert.ConvertToString(this.Bounds);

            TextWriter writer = null;
            try
            {
                string configFolder = Path.GetDirectoryName(InstallPadApp.ConfigFilePath);
                if (!Directory.Exists(configFolder))
                    Directory.CreateDirectory(configFolder);
                writer = new StreamWriter(InstallPadApp.ConfigFilePath);
                writer.Write(formPosition);
            }
            // We can get here if InstallPad.form_load had a problem,
            // so just eat exceptions rather than throwing more of them.
            catch (Exception ex) { }
            finally
            {
                if (writer != null)
                    writer.Close();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Save ECell window settings.
        /// </summary>
        /// <param name="window">MainWindow object.</param>
        /// <param name="filename">the file name.</param>
        /// <param name="isClosing">whether this file is closed.</param>
        public static void SaveAsXML(MainWindow window, string filename, bool isClosing)
        {
            DockPanel dockPanel = window.DockPanel;
            CheckUnsavableWindows(dockPanel, isClosing);
            CheckFilePath(filename);
            FileStream fs = null;
            XmlTextWriter xmlOut = null;
            try
            {
                // Create xml file
                fs = new FileStream(filename, FileMode.Create);
                xmlOut = new XmlTextWriter(fs, Encoding.UTF8);

                // Use indenting for readability
                xmlOut.Formatting = Formatting.Indented;
                xmlOut.WriteStartDocument();

                // Always begin file with identification and warning
                xmlOut.WriteComment(Constants.xPathFileHeader1);
                xmlOut.WriteComment(Constants.xPathFileHeader2);

                // Application settings
                xmlOut.WriteStartElement("Application");
                xmlOut.WriteAttributeString("Name", Application.ProductName);
                xmlOut.WriteAttributeString("Version", Application.ProductVersion);
                xmlOut.WriteAttributeString("ConfigFileVersion", ConfigFileVersion);

                // Form settings
                xmlOut.WriteStartElement("Form");
                xmlOut.WriteAttributeString("WindowState", window.WindowState.ToString());
                xmlOut.WriteAttributeString("Screen", GetScreenNum(window) );
                if (window.WindowState == FormWindowState.Maximized)
                {
                    xmlOut.WriteAttributeString("Top", window.RestoreBounds.Top.ToString());
                    xmlOut.WriteAttributeString("Left", window.RestoreBounds.Left.ToString());
                    xmlOut.WriteAttributeString("Height", window.RestoreBounds.Height.ToString());
                    xmlOut.WriteAttributeString("Width", window.RestoreBounds.Width.ToString());
                }
                else
                {
                    xmlOut.WriteAttributeString("Top", window.DesktopBounds.Top.ToString());
                    xmlOut.WriteAttributeString("Left", window.DesktopBounds.Left.ToString());
                    xmlOut.WriteAttributeString("Height", window.DesktopBounds.Height.ToString());
                    xmlOut.WriteAttributeString("Width", window.DesktopBounds.Width.ToString());
                }
                xmlOut.WriteEndElement();   //</Form>

                // DockPanel settings
                xmlOut.WriteStartElement("DockPanel");//	<DockPanel>
                xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString());
                xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString());
                xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString());
                xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString());
                xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString());
                xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString());

                // Contents
                xmlOut.WriteStartElement("Contents");//	<Contents>
                xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString());
                foreach (DockContent content in dockPanel.Contents)
                {
                    xmlOut.WriteStartElement("Content");
                    xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString());
                    xmlOut.WriteAttributeString("Name", content.Name.ToString());
                    xmlOut.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString());
                    xmlOut.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString());
                    xmlOut.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString());
                    xmlOut.WriteEndElement();
                }
                xmlOut.WriteEndElement();//	</Contents>

                // Panes
                xmlOut.WriteStartElement("Panes");//	<Panes>
                xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString());
                foreach (DockPane pane in dockPanel.Panes)
                {
                    xmlOut.WriteStartElement("Pane");//	<Panes>
                    xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString());
                    xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
                    xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString());
                    xmlOut.WriteStartElement("Contents");//	<Contents>
                    xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString());
                    foreach (DockContent content in pane.Contents)
                    {
                        xmlOut.WriteStartElement("Content");//	<Content>
                        xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString());
                        xmlOut.WriteAttributeString("Name", content.Name);
                        xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString());
                        xmlOut.WriteEndElement();//	</Content>
                    }
                    xmlOut.WriteEndElement();//	</Contents>
                    xmlOut.WriteEndElement();//	</Pane>
                }
                xmlOut.WriteEndElement();//	</Panes>

                // DockWindows
                xmlOut.WriteStartElement("DockWindows");
                int dockWindowId = 0;
                foreach (DockWindow dw in dockPanel.DockWindows)
                {
                    xmlOut.WriteStartElement("DockWindow");
                    xmlOut.WriteAttributeString("ID", dockWindowId.ToString());
                    dockWindowId++;
                    xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
                    xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString());
                    xmlOut.WriteStartElement("NestedPanes");
                    xmlOut.WriteAttributeString("Count", dw.NestedPanes.Count.ToString());
                    foreach (DockPane pane in dw.NestedPanes)
                    {
                        xmlOut.WriteStartElement("Pane");
                        xmlOut.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString());
                        xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString());
                        NestedDockingStatus status = pane.NestedDockingStatus;
                        xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString());
                        xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
                        xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString());
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();//	</NestedPanes>
                    xmlOut.WriteEndElement();//	</DockWindow>
                }
                xmlOut.WriteEndElement();//	</DockWindows>

                // FloatWindows
                RectangleConverter rectConverter = new RectangleConverter();
                xmlOut.WriteStartElement("FloatWindows");
                xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString());
                foreach (FloatWindow fw in dockPanel.FloatWindows)
                {
                    xmlOut.WriteStartElement("FloatWindow");
                    xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString());
                    xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
                    xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString());
                    xmlOut.WriteAttributeString("Screen", GetScreenNum(fw));
                    xmlOut.WriteStartElement("NestedPanes");
                    xmlOut.WriteAttributeString("Count", fw.NestedPanes.Count.ToString());
                    foreach (DockPane pane in fw.NestedPanes)
                    {
                        xmlOut.WriteStartElement("Pane");
                        xmlOut.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString());
                        xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString());
                        NestedDockingStatus status = pane.NestedDockingStatus;
                        xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString());
                        xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
                        xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString());
                        xmlOut.WriteEndElement();
                    }
                    xmlOut.WriteEndElement();//	</NestedPanes>
                    xmlOut.WriteEndElement();//	</FloatWindow>
                }
                xmlOut.WriteEndElement();	//	</FloatWindows>

                xmlOut.WriteEndElement();   //	</DockPanel>
                xmlOut.WriteEndElement();   //	</Application>

                //xmlOut.WriteEndDocument();
                xmlOut.WriteEndDocument();
            }
            finally
            {
                if (xmlOut != null) xmlOut.Close();
                if (fs != null) fs.Close();
            }
        }
Ejemplo n.º 9
0
        public void LoadConfig(bool def = false)
        {
            if (def)
            {
                tabletOffset = new Point(0, 0);
                overrideBounds = new Rectangle(0, 0, 0, 0);
                smoothingStrength = 30;
                smoothingInterpolation = 4;
                overlayScreen = 0;
                tolerance = 300;
                manualInterpolation = false;
                stayOnTop = false;
                disableOverlay = false;
                allScreens = false;
                manualOverlayOverride = false;
                disableCatchUp = false;
                snapToCursor = false;
                smoothOnDraw = false;
                tabletOffsetOverride = false;
                disableAutoDetection = false;
                hotkeys[0] = "None";
                hotkeys[1] = "None";
                hotkeys[2] = "None";
                hotkeys[3] = "None";
                hotkeys[4] = "None";
                hotkeys[5] = "None";

                // Main window resetting
                mainForm.checkBox_smoothOnDraw.Checked = false;
                mainForm.checkBox_stayOnTop.Checked = false;
                mainForm.checkBox_tabletMode.Checked = false;
                mainForm.checkBox_tabletMode.Enabled = false;
                mainForm.checkBox_manualInterpolation.Checked = false;
                mainForm.trackBar_smoothingInterpolation.Enabled = false;
                mainForm.textBox_smoothingInterpolation.Enabled = false;
                mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString();
                mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString();
                mainForm.checkBox_smoothOnDraw.Checked = false;
                mainForm.TopMost = false;

                // Cursor and overlay resetting
                overlayForm.cursorColor = Color.FromArgb(128, 128, 128);
                overlayForm.cursorFillColor = Color.FromArgb(255, 255, 254);
                overlayForm.cursorType = Overlay.CursorType.Bullseye;
                overlayForm.Show();
                overlayForm.Bounds = Screen.PrimaryScreen.Bounds;
                mainForm.button_colorDialog.BackColor = overlayForm.cursorColor;

                // Hotkey resetting
                for (int i = 0; i < mainForm.hotKeyHandling.Count(); i++)
                {
                    try
                    {
                        mainForm.hotKeyHandling[i].Dispose();
                    }
                    catch
                    {
                        // Nothing to dispose!
                    }
                }
            }
            else
            {
                try
                {
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    // Main window loading
                    smoothingStrength = int.Parse(config.AppSettings.Settings["Strength"].Value);
                    smoothingInterpolation = int.Parse(config.AppSettings.Settings["Interpolation"].Value);
                    manualInterpolation = bool.Parse(config.AppSettings.Settings["Manual Interpolation"].Value);
                    smoothOnDraw = bool.Parse(config.AppSettings.Settings["Smooth On Draw"].Value);
                    stayOnTop = bool.Parse(config.AppSettings.Settings["Stay On Top"].Value);
                    disableAutoDetection = bool.Parse(config.AppSettings.Settings["Disable Auto Detection"].Value);
                    mainForm.tabletMode = bool.Parse(config.AppSettings.Settings["Tablet Mode"].Value);
                    mainForm.checkBox_tabletMode.Enabled = disableAutoDetection;
                    mainForm.checkBox_tabletMode.Checked = mainForm.tabletMode;
                    mainForm.checkBox_smoothOnDraw.Checked = smoothOnDraw;
                    if (manualInterpolation)
                    {
                        mainForm.checkBox_manualInterpolation.Checked = true;
                        mainForm.trackBar_smoothingInterpolation.Enabled = true;
                        mainForm.textBox_smoothingInterpolation.Enabled = true;
                    }
                    mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString();
                    mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString();
                    if (stayOnTop)
                    {
                        mainForm.checkBox_stayOnTop.Checked = true;
                        mainForm.TopMost = true;
                        overlayForm.TopMost = true;
                    }

                    // Cursor and overlay loading
                    overlayForm.cursorType = (Overlay.CursorType)Enum.Parse(typeof(Overlay.CursorType), config.AppSettings.Settings["Cursor Graphic"].Value);
                    overlayForm.cursorColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Main Color"].Value);
                    overlayForm.cursorFillColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Fill Color"].Value);
                    overlayScreen = int.Parse(config.AppSettings.Settings["Overlay Screen"].Value);
                    disableOverlay = bool.Parse(config.AppSettings.Settings["Disable Overlay"].Value);
                    allScreens = bool.Parse(config.AppSettings.Settings["All Screens"].Value);
                    manualOverlayOverride = bool.Parse(config.AppSettings.Settings["Manual Overlay Override"].Value);
                    RectangleConverter r = new RectangleConverter();
                    overrideBounds = (Rectangle)r.ConvertFromString(config.AppSettings.Settings["Override Bounds"].Value);
                    if (disableOverlay) overlayForm.Hide();
                    overlayForm.Bounds = Screen.AllScreens[overlayScreen].Bounds;
                    if (allScreens) overlayForm.Bounds = new Rectangle(0, 0, SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
                    if (manualOverlayOverride) overlayForm.Bounds = overrideBounds;
                    mainForm.button_colorDialog.BackColor = overlayForm.cursorColor;

                    // ...and everything else
                    disableCatchUp = bool.Parse(config.AppSettings.Settings["Disable Catch Up"].Value);
                    snapToCursor = bool.Parse(config.AppSettings.Settings["Snap To Cursor"].Value);
                    tolerance = int.Parse(config.AppSettings.Settings["Tolerance"].Value);
                    tabletOffsetOverride = bool.Parse(config.AppSettings.Settings["Tablet Offset Override"].Value);
                    PointConverter p = new PointConverter();
                    tabletOffset = (Point)p.ConvertFromString(config.AppSettings.Settings["Tablet Offset"].Value);
                    KeysConverter c = new KeysConverter();
                    Keys k;
                    Hotkey.KeyModifiers m;
                    hotkeys[0] = config.AppSettings.Settings["Hotkey 1"].Value;
                    if (hotkeys[0] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 1"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 0, m, k);
                        }
                    }
                    hotkeys[1] = config.AppSettings.Settings["Hotkey 2"].Value;
                    if (hotkeys[1] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 2"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 1, m, k);
                        }
                    }
                    hotkeys[2] = config.AppSettings.Settings["Hotkey 3"].Value;
                    if (hotkeys[2] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 3"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 2, m, k);
                        }
                    }
                    hotkeys[3] = config.AppSettings.Settings["Hotkey 4"].Value;
                    if (hotkeys[3] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 4"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 3, m, k);
                        }
                    }
                    hotkeys[4] = config.AppSettings.Settings["Hotkey 5"].Value;
                    if (hotkeys[4] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 5"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 4, m, k);
                        }
                    }
                    hotkeys[5] = config.AppSettings.Settings["Hotkey 6"].Value;
                    if (hotkeys[5] != "None")
                    {
                        k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 6"].Value);
                        m = Hotkey.GetModifiers(k, out k);
                        if (k != Keys.None)
                        {
                            mainForm.RegisterHotkey(mainForm.Handle, 5, m, k);
                        }
                    }
                }
                catch
                {
                    // Quietly fail loading bad configs or no configs
                }
            }
        }
Ejemplo n.º 10
0
 public void SaveConfig()
 {
     Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     config.AppSettings.Settings.Remove("Strength");
     config.AppSettings.Settings.Add("Strength", smoothingStrength.ToString());
     config.AppSettings.Settings.Remove("Interpolation");
     config.AppSettings.Settings.Add("Interpolation", smoothingInterpolation.ToString());
     config.AppSettings.Settings.Remove("Manual Interpolation");
     config.AppSettings.Settings.Add("Manual Interpolation", manualInterpolation.ToString());
     config.AppSettings.Settings.Remove("Smooth On Draw");
     config.AppSettings.Settings.Add("Smooth On Draw", smoothOnDraw.ToString());
     config.AppSettings.Settings.Remove("Stay On Top");
     config.AppSettings.Settings.Add("Stay On Top", stayOnTop.ToString());
     config.AppSettings.Settings.Remove("Tablet Mode");
     config.AppSettings.Settings.Add("Tablet Mode", mainForm.tabletMode.ToString());
     config.AppSettings.Settings.Remove("Overlay Screen");
     config.AppSettings.Settings.Add("Overlay Screen", overlayScreen.ToString());
     config.AppSettings.Settings.Remove("Disable Overlay");
     config.AppSettings.Settings.Add("Disable Overlay", disableOverlay.ToString());
     config.AppSettings.Settings.Remove("All Screens");
     config.AppSettings.Settings.Add("All Screens", allScreens.ToString());
     config.AppSettings.Settings.Remove("Manual Overlay Override");
     config.AppSettings.Settings.Add("Manual Overlay Override", manualOverlayOverride.ToString());
     config.AppSettings.Settings.Remove("Override Bounds");
     RectangleConverter r = new RectangleConverter();
     config.AppSettings.Settings.Add("Override Bounds", r.ConvertToString(overrideBounds));
     config.AppSettings.Settings.Remove("Disable Catch Up");
     config.AppSettings.Settings.Add("Disable Catch Up", disableCatchUp.ToString());
     config.AppSettings.Settings.Remove("Snap to Cursor");
     config.AppSettings.Settings.Add("Snap to Cursor", snapToCursor.ToString());
     config.AppSettings.Settings.Remove("Cursor Graphic");
     config.AppSettings.Settings.Add("Cursor Graphic", overlayForm.cursorType.ToString());
     config.AppSettings.Settings.Remove("Main Color");
     config.AppSettings.Settings.Add("Main Color", ColorTranslator.ToHtml(overlayForm.cursorColor));
     config.AppSettings.Settings.Remove("Fill Color");
     config.AppSettings.Settings.Add("Fill Color", ColorTranslator.ToHtml(overlayForm.cursorFillColor));
     config.AppSettings.Settings.Remove("Disable Auto Detection");
     config.AppSettings.Settings.Add("Disable Auto Detection", disableAutoDetection.ToString());
     config.AppSettings.Settings.Remove("Tolerance");
     config.AppSettings.Settings.Add("Tolerance", tolerance.ToString());
     config.AppSettings.Settings.Remove("Tablet Offset Override");
     config.AppSettings.Settings.Add("Tablet Offset Override", tabletOffsetOverride.ToString());
     config.AppSettings.Settings.Remove("Tablet Offset");
     PointConverter p = new PointConverter();
     config.AppSettings.Settings.Add("Tablet Offset", p.ConvertToString(tabletOffset));
     config.AppSettings.Settings.Remove("Hotkey 1");
     config.AppSettings.Settings.Add("Hotkey 1", hotkeys[0].ToString());
     config.AppSettings.Settings.Remove("Hotkey 2");
     config.AppSettings.Settings.Add("Hotkey 2", hotkeys[1].ToString());
     config.AppSettings.Settings.Remove("Hotkey 3");
     config.AppSettings.Settings.Add("Hotkey 3", hotkeys[2].ToString());
     config.AppSettings.Settings.Remove("Hotkey 4");
     config.AppSettings.Settings.Add("Hotkey 4", hotkeys[3].ToString());
     config.AppSettings.Settings.Remove("Hotkey 5");
     config.AppSettings.Settings.Add("Hotkey 5", hotkeys[4].ToString());
     config.AppSettings.Settings.Remove("Hotkey 6");
     config.AppSettings.Settings.Add("Hotkey 6", hotkeys[5].ToString());
     config.Save(ConfigurationSaveMode.Modified);
 }
Ejemplo n.º 11
0
        public static void SaveApplication(DockPanel dockPanel, XmlTextWriter xmlWriter)
        {
            // Associate a version number with the root element so that future version of the code
            // will be able to be backwards compatible or at least recognise out of date versions
            xmlWriter.WriteStartElement("DockPanel");
            xmlWriter.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
            xmlWriter.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
            xmlWriter.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
            xmlWriter.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));

            if (!Win32Helper.IsRunningOnMono)
            {
                xmlWriter.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString(CultureInfo.InvariantCulture));
            }

            // Contents
            xmlWriter.WriteStartElement("Contents");
            xmlWriter.WriteAttributeString("Count", dockPanel.Contents.Count.ToString(CultureInfo.InvariantCulture));
            foreach (WorkItemDockContent content in dockPanel.Contents)
            {
                xmlWriter.WriteStartElement("Content");
                xmlWriter.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString(CultureInfo.InvariantCulture));

                content.Save(xmlWriter);

                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();

            // Panes
            xmlWriter.WriteStartElement("Panes");
            xmlWriter.WriteAttributeString("Count", dockPanel.Panes.Count.ToString(CultureInfo.InvariantCulture));
            foreach (DockPane pane in dockPanel.Panes)
            {
                xmlWriter.WriteStartElement("Pane");
                xmlWriter.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("DockState", pane.DockState.ToString());
                xmlWriter.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteStartElement("Contents");
                xmlWriter.WriteAttributeString("Count", pane.Contents.Count.ToString(CultureInfo.InvariantCulture));
                foreach (IDockContent content in pane.Contents)
                {
                    xmlWriter.WriteStartElement("Content");
                    xmlWriter.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();

            // DockWindows
            xmlWriter.WriteStartElement("DockWindows");
            int dockWindowId = 0;
            foreach (DockWindow dw in dockPanel.DockWindows)
            {
                xmlWriter.WriteStartElement("DockWindow");
                xmlWriter.WriteAttributeString("ID", dockWindowId.ToString(CultureInfo.InvariantCulture));
                dockWindowId++;
                xmlWriter.WriteAttributeString("DockState", dw.DockState.ToString());
                xmlWriter.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteStartElement("NestedPanes");
                xmlWriter.WriteAttributeString("Count", dw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
                foreach (DockPane pane in dw.NestedPanes)
                {
                    xmlWriter.WriteStartElement("Pane");
                    xmlWriter.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    NestedDockingStatus status = pane.NestedDockingStatus;
                    xmlWriter.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("Alignment", status.Alignment.ToString());
                    xmlWriter.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();

            // FloatWindows
            var rectConverter = new RectangleConverter();
            xmlWriter.WriteStartElement("FloatWindows");
            xmlWriter.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString(CultureInfo.InvariantCulture));
            foreach (FloatWindow fw in dockPanel.FloatWindows)
            {
                xmlWriter.WriteStartElement("FloatWindow");
                xmlWriter.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
                xmlWriter.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
                xmlWriter.WriteStartElement("NestedPanes");
                xmlWriter.WriteAttributeString("Count", fw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
                foreach (DockPane pane in fw.NestedPanes)
                {
                    xmlWriter.WriteStartElement("Pane");
                    xmlWriter.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
                    NestedDockingStatus status = pane.NestedDockingStatus;
                    xmlWriter.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteAttributeString("Alignment", status.Alignment.ToString());
                    xmlWriter.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
            }
            xmlWriter.WriteEndElement();	//	</FloatWindows>

            xmlWriter.WriteEndElement();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates XML string from instance of module
        /// </summary>
        /// <param name="module">Module</param>
        /// <returns>XML Node of module</returns>
        public HtmlNode GetNodeFromModule(AModule module)
        {
            Type moduleType = module.GetType();
            Type setupType = module.setup.GetType();

            // Create root node
            String moduleName = (String)moduleType.GetField("name", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy).GetValue(null);

            HtmlDocument htmlDoc = new HtmlDocument();
            HtmlNode node = htmlDoc.CreateElement("module");

            // Save all setup_* members to attributes
            MemberInfo[] setupMembers = setupType.GetMember("setup_*", BindingFlags.Public | BindingFlags.Instance);
            foreach (MemberInfo setupMember in setupMembers)
            {
                HtmlAttribute attribute = htmlDoc.CreateAttribute(setupMember.Name);
                attribute.Value = (String)setupType.InvokeMember(setupMember.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty, null, module.setup, null);
                node.Attributes.Append(attribute);
            }

            // Save name(type) of module
            HtmlAttribute nameAttr = htmlDoc.CreateAttribute("name");
            nameAttr.Value = moduleName;
            node.Attributes.Append(nameAttr);

            // Save position as attr
            Rectangle location = (Rectangle)setupType.GetField("location", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy).GetValue(module.setup);
            HtmlAttribute locationAttr = htmlDoc.CreateAttribute("location");
            RectangleConverter converter = new RectangleConverter();
            locationAttr.Value = converter.ConvertToString(location);
            node.Attributes.Append(locationAttr);

            return node;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates instance of module from HTML node
        /// </summary>
        /// <param name="node">Module HTML node</param>
        /// <returns>Instance of AModule with UserSetup</returns>
        public AModule GetModuleFromNode(HtmlNode node)
        {
            if (node.Attributes["name"] == null)
            {
                return null;
            }

            AModule module = CModuleReader.Instance.GetModuleInstanceFromName(node.Attributes["name"].Value);

            // Set attributes
            foreach (HtmlAttribute attribute in node.Attributes)
            {
                try
                {
                    Object[] args = new Object[] { attribute.Value };
                    module.setup.GetType().InvokeMember(attribute.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty, null, module.setup, args);
                }
                catch (Exception)
                {
                    // Attribute not found, ignoring
                }
            }
            // And location
            RectangleConverter converter = new RectangleConverter();
            module.setup.location = (Rectangle)converter.ConvertFromString(node.Attributes["location"].Value);

            return module;
        }