Esempio n. 1
0
        public void SaveConfigToStream(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(" Magic, The User Interface library for .NET (www.dotnetmagic.com) ");
            xmlOut.WriteComment(" Modifying this generated file will probably render it invalid ");

            // 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("DockingConfig");
            xmlOut.WriteAttributeString("FormatVersion", "5");
            xmlOut.WriteAttributeString("InsideFill", _insideFill.ToString());
            xmlOut.WriteAttributeString("InnerMinimum", ConversionHelper.SizeToString(_innerMinimum));

            // We need to hide all content during the saving process, but then restore
            // them back again before leaving so the user does not see any change
            _container.SuspendLayout();

            // Store a list of those content hidden during processing
            ContentCollection hideContent = new ContentCollection();

            // Let create a copy of the current contents in current order, because
            // we cannot 'foreach' a collection that is going to be altered during its
            // processing by the 'HideContent'.
            ContentCollection origContents = _contents.Copy();

            // Do not generate hiding/hidden/shown events
            _surpressVisibleEvents++;

            int count = origContents.Count;

            // Hide in reverse order so that a ShowAll in forward order gives accurate restore
            for(int index=count-1; index>=0; index--)
            {
                Content c = origContents[index];

                c.RecordRestore();
                c.SaveToXml(xmlOut);

                // If visible then need to hide so that subsequent attempts to
                // RecordRestore will not take its position into account
                if (c.Visible)
                {
                    hideContent.Insert(0, c);
                    HideContent(c);
                }
            }

            // Allow an event handler a chance to add custom information after ours
            OnSaveCustomConfig(xmlOut);

            // Put content we hide back again
            foreach(Content c in hideContent)
                ShowContent(c);

            // Enable generation of hiding/hidden/shown events
            _surpressVisibleEvents--;

            // Reapply any fill style required
            AddInnerFillStyle();

            _container.ResumeLayout();

            // Terminate the root element and document
            xmlOut.WriteEndElement();
            xmlOut.WriteEndDocument();

            // This should flush all actions and close the file
            xmlOut.Close();
        }
Esempio n. 2
0
        public void LoadConfigFromStream(Stream stream)
        {
            XmlTextReader xmlIn = new XmlTextReader(stream);

            // Ignore whitespace, not interested
            xmlIn.WhitespaceHandling = WhitespaceHandling.None;

            // Moves the reader to the root element.
            xmlIn.MoveToContent();

            // Double check this has the correct element name
            if (xmlIn.Name != "DockingConfig")
                throw new ArgumentException("Root element must be 'DockingConfig'");

            // Load the format version number
            string version = xmlIn.GetAttribute(0);
            string insideFill = xmlIn.GetAttribute(1);
            string innerSize = xmlIn.GetAttribute(2);

            // Convert format version from string to double
            int formatVersion = (int)Convert.ToDouble(version);

            // We can only load 3 upward version formats
            if (formatVersion < 3)
                throw new ArgumentException("Can only load Version 3 and upwards Docking Configuration files");

            // Convert from string to proper types
            _insideFill = (bool)Convert.ToBoolean(insideFill);
            _innerMinimum = ConversionHelper.StringToSize(innerSize);

            ContentCollection cc = new ContentCollection();

            do
            {
                // Read the next Element
                if (!xmlIn.Read())
                    throw new ArgumentException("An element was expected but could not be read in");

                // Have we reached the end of root element?
                if ((xmlIn.NodeType == XmlNodeType.EndElement) && (xmlIn.Name == "DockingConfig"))
                    break;

                // Is the element name 'Content'
                if (xmlIn.Name == "Content")
                {
                    // Process this Content element
                    cc.Insert(0, new Content(xmlIn, formatVersion));
                }
                else
                {
                    // Must have reached end of our code, let the custom handler deal with this
                    OnLoadCustomConfig(xmlIn);

                    // Ignore anything else that might be in the XML
                    xmlIn.Close();

                    // Exit
                    break;
                }

            } while(!xmlIn.EOF);

            xmlIn.Close();

            // Reduce flicker during window operations
            _container.SuspendLayout();

            // Hide all the current content items
            HideAllContents();

            // Attempt to apply loaded settings
            foreach(Content loaded in cc)
            {
                Content c = _contents[loaded.Title];

                // Do we have any loaded information for this item?
                if (c != null)
                {
                    // Copy across the loaded values of interest
                    c.Docked = loaded.Docked;
                    c.AutoHidden = loaded.AutoHidden;
                    c.CaptionBar = loaded.CaptionBar;
                    c.CloseButton = loaded.CloseButton;
                    c.DisplaySize = loaded.DisplaySize;
                    c.DisplayLocation = loaded.DisplayLocation;
                    c.AutoHideSize = loaded.AutoHideSize;
                    c.FloatingSize = loaded.FloatingSize;
                    c.DefaultRestore = loaded.DefaultRestore;
                    c.AutoHideRestore = loaded.AutoHideRestore;
                    c.DockingRestore = loaded.DockingRestore;
                    c.FloatingRestore = loaded.FloatingRestore;

                    // Allow the Restore objects a chance to rehook into object instances
                    c.ReconnectRestore();

                    // Was the loaded item visible?
                    if (loaded.Visible)
                    {
                        // Make it visible now
                        ShowContent(c);
                    }
                }
            }

            // Reapply any fill style required
            AddInnerFillStyle();

            // Reduce flicker during window operations
            _container.ResumeLayout();

            // If any AutoHostPanel's have become visible we need to force a repaint otherwise
            // the area not occupied by the TabStub instances will be painted the correct color
            _ahpLeft.Invalidate();
            _ahpRight.Invalidate();
            _ahpTop.Invalidate();
            _ahpBottom.Invalidate();
        }
Esempio n. 3
0
        public virtual void OnShowContextMenu(Point screenPos)
        {
            PopupMenu context = new PopupMenu();

            // The order of Content displayed in the context menu is not the same as
            // the order of Content in the _contents collection. The latter has its
            // ordering changed to enable Restore functionality to work.
            ContentCollection temp = new ContentCollection();

            foreach(Content c in _contents)
            {
                int count = temp.Count;
                int index = 0;

                // Find best place to add into the temp collection
                for(; index<count; index++)
                {
                    if (c.Order < temp[index].Order)
                        break;
                }

                temp.Insert(index, c);
            }

            // Create a context menu entry per Content
            foreach(Content t in temp)
            {
                MenuCommand mc = new MenuCommand(t.Title, new EventHandler(OnToggleContentVisibility));
                mc.Checked = t.Visible;
                mc.Tag = t;

                context.MenuCommands.Add(mc);
            }

            // Add a separator
            context.MenuCommands.Add(new MenuCommand("-"));

            // Add fixed entries to end to effect all content objects
            context.MenuCommands.Add(new MenuCommand("Show All", new EventHandler(OnShowAll)));
            context.MenuCommands.Add(new MenuCommand("Hide All", new EventHandler(OnHideAll)));

            // Ensure menu has same style as the docking windows
            context.Style = _visualStyle;

            if (OnContextMenu(context))
            {
                // Show it!
                context.TrackPopup(screenPos, true);
            }
        }