public bool Contains(ContentCollection values)
        {
            foreach(Content c in values)
            {
                // Use base class to process actual collection operation
                if (Contains(c))
                    return true;
            }

            return false;
        }
예제 #2
0
        public ContentCollection Copy()
        {
            ContentCollection clone = new ContentCollection();

            // Copy each reference across
            foreach (Content c in base.List)
            {
                clone.Add(c);
            }

            return(clone);
        }
예제 #3
0
        public bool Contains(ContentCollection values)
        {
            foreach (Content c in values)
            {
                // Use base class to process actual collection operation
                if (Contains(c))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        public WindowContent(DockingManager manager, VisualStyle vs)
            : base(manager)
        {
            // Remember state
            _style = vs;

            // Create collection of window details
            _contents = new ContentCollection();

            // We want notification when contents are added/removed/cleared
            _contents.Clearing += new CollectionClear(OnContentsClearing);
            _contents.Inserted += new CollectionChange(OnContentInserted);
            _contents.Removing += new CollectionChange(OnContentRemoving);
            _contents.Removed += new CollectionChange(OnContentRemoved);
        }
예제 #5
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();
        }
예제 #6
0
        protected virtual void OnRestore(object sender, EventArgs e)
        {
            WindowDetailCaption wdc = sender as WindowDetailCaption;

            // Was Restore generated by a Caption detail?
            if (wdc != null)
            {
                RemoveAnyFillStyle();

                WindowContent wc = wdc.ParentWindow as WindowContent;

                // Is the Caption part of a WindowContent object?
                if (wc != null)
                {
                    ContentCollection copy = new ContentCollection();

                    // Make every Content of the WindowContent record its
                    // current position and remember it for when the future
                    foreach(Content c in wc.Contents)
                    {
                        c.RecordRestore();

                        // Invert docked status
                        c.Docked = (c.Docked == false);

                        copy.Add(c);
                    }

                    int copyCount = copy.Count;

                    // Must have at least one!
                    if (copyCount >= 1)
                    {
                        // Remove from current WindowContent and restore its position
                        HideContent(copy[0], false, true);
                        ShowContent(copy[0]);

                        // Any other content to be moved along with it?
                        if (copyCount >= 2)
                        {
                            WindowContent newWC = copy[0].ParentWindowContent;

                            if (newWC != null)
                            {
                                // Transfer each one to its new location
                                for(int index=1; index<copyCount; index++)
                                {
                                    HideContent(copy[index], false, true);
                                    newWC.Contents.Add(copy[index]);
                                }
                            }
                        }
                    }
                }

                AddInnerFillStyle();
            }
        }
예제 #7
0
        protected virtual void InvertAutoHideWindowContent(WindowContent wc)
        {
            // Do not generate hiding/hidden/shown events
            _surpressVisibleEvents++;

            // Create a collection of the Content in the same window
            ContentCollection cc = new ContentCollection();

            // Add all Content into collection
            foreach(Content c in wc.Contents)
                cc.Add(c);

            // Add to the correct AutoHidePanel
            AutoHideContents(cc, wc.State);

            // Enable generate hiding/hidden/shown events
            _surpressVisibleEvents--;
        }
예제 #8
0
        internal void AutoHideContents(ContentCollection cc, State state)
        {
            // Hide all the Content instances. This will cause the restore objects to be
            // created and so remember the docking positions for when they are restored
            foreach(Content c in cc)
                HideContent(c);

            AutoHidePanel ahp = AutoHidePanelForState(state);

            // Pass management of Contents into the panel
            ahp.AddContentsAsGroup(cc);
        }
예제 #9
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();
        }
예제 #10
0
        public override void PerformRestore(DockingManager dm)
        {
            // Create collection of Contents to auto hide
            ContentCollection cc = new ContentCollection();

            // In this case, there is only one
            cc.Add(_content);

            // Add to appropriate AutoHidePanel based on _state
            dm.AutoHideContents(cc, _state);
        }
        public ContentCollection Copy()
        {
            ContentCollection clone = new ContentCollection();

            // Copy each reference across
            foreach(Content c in base.List)
                clone.Add(c);

            return clone;
        }
        protected void OnPageClose(object sender, EventArgs e)
        {
            try
                    {

            // Find the TabStub instance for the showing WCT
            foreach(TabStub ts in this.Controls)
            {
                // Does this stub match the one showing?
                if (ts.WindowContentTabbed == _currentWCT)
                {
                    ContentCollection cc = new ContentCollection();

                    // Get access to Content instance being hidden
                    Content current = _currentWCT.Contents[ts.SelectedIndex];

                    // Check if the hide button is allowed to work
                    if (!_manager.OnContentHiding(current))
                    {
                        // Are we removing the last entry in the WCT?
                        if (ts.TabPages.Count == 1)
                        {
                            // We need to update AutoHide property for all of them
                            foreach(Content c in _currentWCT.Contents)
                                cc.Add(c);

                            // Remove Panel/WCT from display and stop timers
                            KillDisplayedWindow();

                            // Remove the WCT from the WCT
                            ControlHelper.Remove(ts.Controls, ts.WindowContentTabbed);

                            // Remove the stub from this panel
                            ControlHelper.Remove(this.Controls, ts);

                            // Cleanup gracefully
                            ts.Dispose();
                        }
                        else
                        {
                            // Which entry in the stub is currently selected?
                            int index = ts.SelectedIndex;

                            // Need to update AutoHide property for removed content
                            cc.Add(_currentWCT.Contents[index]);

                            // Remove just the selected entry from stub
                            ts.TabPages.RemoveAt(index);

                            // Remove the selected entry from WCT
                            _currentWCT.Contents.RemoveAt(index);
                        }

                        // Content instances no longer in AutoHidden state
                        foreach(Content c in cc)
                        {
                            // Remember this AutoHide state for persistence
                            c.RecordAutoHideRestore();

                            // No longer in the auto hidden mode
                            c.AutoHidden = false;
                            c.AutoHidePanel = null;
                        }
                    }

                    // Generate hidden event now content is not visible
                    _manager.OnContentHidden(current);

                    break;
                }
            }

            // If no more contents remain then hide
            if (this.Controls.Count == 0)
                this.Hide();
                    }
                    catch(System.Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
        }
        public void AddContentsAsGroup(ContentCollection contents, int index)
        {
            // Create new TabStub to represent the Contents
            TabStub ts = new TabStub(_manager.Style);

            // Set manager requested settings
            ts.Font = _manager.CaptionFont;
            ts.BackColor = _manager.BackColor;
            ts.ForeColor = _manager.InactiveTextColor;

            // Hook into events
            ts.PageOver += new TabStub.TabStubIndexHandler(OnPageOver);
            ts.PageClicked += new TabStub.TabStubIndexHandler(OnPageClicked);
            ts.PagesLeave += new TabStub.TabStubHandler(OnPagesLeave);

            // Add a page for each Content instance
            foreach(Content c in contents)
            {
                // Create page object
                Crownwood.Magic.Controls.TabPage page = new Crownwood.Magic.Controls.TabPage();

                // Copy across the visual properties
                page.Title = c.Title;
                page.ImageList = c.ImageList;
                page.ImageIndex = c.ImageIndex;

                // Remember reference to Content it represents
                page.Tag = c;

                // Add into the stub
                ts.TabPages.Add(page);

                // Mark Content as being in AutoHide mode
                c.AutoHidePanel = this;
                c.AutoHidden = true;
            }

            State windowState = State.DockLeft;

            // Define stub settings based on our docking position
            switch(this.Dock)
            {
                case DockStyle.Left:
                    windowState = State.DockLeft;
                    ts.Edging = Edge.Left;
                    ts.Dock = DockStyle.Top;
                    break;
                case DockStyle.Right:
                    windowState = State.DockRight;
                    ts.Edging = Edge.Right;
                    ts.Dock = DockStyle.Top;
                    break;
                case DockStyle.Top:
                    windowState = State.DockTop;
                    ts.Edging = Edge.Top;
                    ts.Dock = DockStyle.Left;
                    break;
                case DockStyle.Bottom:
                    windowState = State.DockBottom;
                    ts.Edging = Edge.Bottom;
                    ts.Dock = DockStyle.Left;
                    break;
            }

            // Add stub into the view
            Controls.Add(ts);

            // Set correct new position
            Controls.SetChildIndex(ts, index);

            // Each TabStub has a WCT created and ready to be shown when needed
            WindowContentTabbed wct = _manager.CreateWindowForContent(null, new EventHandler(OnPageClose),
                                                                      null, new EventHandler(OnPageAutoHide),
                                                                      new ContextHandler(OnPageContextMenu)) as WindowContentTabbed;

            // Add each Content instance in turn
            foreach(Content c in contents)
                wct.Contents.Add(c);

            // By default the first Content added to a WCT will define the size
            // of the WCT control. We need to override this to use the AutoHideSize
            // from the first Content instead.
            wct.Size = contents[0].AutoHideSize;

            // Ensure Window caption bar reflects correct docking status
            wct.State = windowState;

            // Inform Window it should not allow user initiated redocking
            wct.RedockAllowed = false;

            // Hide tab selection from user
            wct.TabControl.HideTabsMode = Magic.Controls.TabControl.HideTabsModes.HideAlways;

            // Associate WCT with matching TabStub
            ts.WindowContentTabbed = wct;

            // Make sure this AutoHidePanel is visible
            if (!this.Visible)
                this.Show();

            Invalidate();
        }
 public void AddContentsAsGroup(ContentCollection contents)
 {
     // By default, insert new group at the end of display which is start of list
     AddContentsAsGroup(contents, 0);
 }
        public void AddContent(Content content, 
            StringCollection next,
            StringCollection previous,
            StringCollection nextAll,
            StringCollection previousAll)
        {
            int nextIndex = 0;
            int previousIndex = 0;
            TabStub nextTabStub = null;
            TabStub previousTabStub = null;
            TabStub nextAllTabStub = null;
            TabStub previousAllTabStub = null;

            int controlCount = this.Controls.Count;

            // Process each TabStub in turn
            for(int controlIndex=controlCount-1; controlIndex>=0; controlIndex--)
            {
                TabStub ts = this.Controls[controlIndex] as TabStub;

                // Process each Page in the TabStub
                foreach(Crownwood.Magic.Controls.TabPage page in ts.TabPages)
                {
                    Content c = page.Tag as Content;

                    // Always use the last 'previous' discovered
                    if (previous.Contains(c.Title))
                    {
                        previousIndex = ts.TabPages.IndexOf(page);
                        previousTabStub = ts;
                    }

                    // Only remember the first 'next' discovered
                    if (next.Contains(c.Title))
                    {
                        if (nextTabStub == null)
                        {
                            nextIndex = ts.TabPages.IndexOf(page);
                            nextTabStub = ts;
                        }
                    }

                    // Always use the last 'previousAll' discovered
                    if (previousAll.Contains(c.Title))
                        previousAllTabStub = ts;

                    // Only remember the first 'next' discovered
                    if (nextAll.Contains(c.Title))
                    {
                        if (nextAllTabStub == null)
                            nextAllTabStub = ts;
                    }
                }
            }

            // If no matches at all found
            if ((previousTabStub == null) && (nextTabStub == null))
            {
                // Default to inserting at end of list
                int insertIndex = Controls.Count;

                // If found some friends contents, then insert relative to them
                if (previousAllTabStub != null)
                    insertIndex = Controls.IndexOf(previousAllTabStub);
                else
                {
                    if (nextAllTabStub != null)
                        insertIndex = Controls.IndexOf(nextAllTabStub) + 1;
                }

                ContentCollection cs = new ContentCollection();

                cs.Add(content);

                // Add at end of current list of TabStubs
                AddContentsAsGroup(cs, insertIndex);
            }
            else
            {
                if (previousTabStub != null)
                    AddContentIntoTabStub(content, previousTabStub, previousIndex + 1);
                else
                    AddContentIntoTabStub(content, nextTabStub, nextIndex);
            }
        }
예제 #16
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);
            }
        }
        public static ContentCollection Contents(Zone z)
        {
            // Container for returned group of found Content objects
            ContentCollection cc = new ContentCollection();

            // Process each Window in the Zone
            foreach(Window w in z.Windows)
            {
                WindowContent wc = w as WindowContent;

                // Is the Zone a Content derived variation?
                if (wc != null)
                {
                    // Add each Content into the collection
                    foreach(Content c in wc.Contents)
                        cc.Add(c);
                }
            }

            return cc;
        }
예제 #18
0
        protected virtual void OnInvertAutoHide(object sender, EventArgs e)
        {
            // Do not generate hiding/hidden/shown events
            _surpressVisibleEvents++;

            WindowDetail detail = sender as WindowDetail;

            // Get access to Content that initiated AutoHide for its Window
            WindowContent wc = detail.ParentWindow as WindowContent;

            // Create a collection of the Content in the same window
            ContentCollection cc = new ContentCollection();

            // Add all Content into collection
            foreach(Content c in wc.Contents)
                cc.Add(c);

            // Add to the correct AutoHidePanel
            AutoHideContents(cc, wc.State);

            // Enable generate hiding/hidden/shown events
            _surpressVisibleEvents--;
        }