Example #1
0
        //---------------------------------------------------------------------------
        public bool AffichePagePrecedenteSansHistorisation()
        {
            if (EntreeEnCours == null || EntreeEnCours.EntreePrecedente == null)
            {
                if (m_tabs.RootSequence.Count == 1)
                {
                    TabGroupLeaf leaf = m_tabs.FirstLeaf();
                    if (leaf.TabPages.Count == 1)
                    {
                        AffichePageAccueil();
                        return(true);
                    }
                    else
                    {
                        if (TabPageCible != null)
                        {
                            return(DeleteOnglet(TabPageCible));
                        }
                    }
                }
            }

            bool result = AffichePage(EntreeEnCours.EntreePrecedente, false, false);

            return(result);
        }
Example #2
0
        private void OnTabTitleDoubleClicked(object sender, EventArgs e)
        {
            Crownwood.DotNetMagic.Controls.TitleBar titleBar = (Crownwood.DotNetMagic.Controls.TitleBar)sender;
            TabGroupLeaf tgl = GetLeafForTitleBar(titleBar);

            ToggleLeaf(tgl);
        }
Example #3
0
        private void EditorDisposed(object sender, EventArgs e)
        {
            Editor editor = (Editor)sender;

            if (editor is TestEditor)
            {
                editingTests.Remove(editor.Id);
            }
            else
            {
                editingQuestionSets.Remove(editor.Id);
            }

            TabPage tp = (TabPage)editor.Tag;

            //locate and remove the tab page
            for (int i = 0; i < tabbedGroups.RootSequence.Count; ++i)
            {
                TabGroupLeaf tgl = (TabGroupLeaf)tabbedGroups.RootSequence[i];
                foreach (TabPage tabPage in tgl.TabPages)
                {
                    if (tabPage == tp)
                    {
                        tgl.TabPages.Remove(tp);
                        return;
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Initialize a new instance of the TargetArea class.
        /// </summary>
        /// <param name="squares">Showing as squares or diamonds.</param>
        /// <param name="host">Hosting tabbed groups instance.</param>
        /// <param name="leaf">Leaf that is being dragged.</param>
        public TargetAreaSides(bool squares, TabbedGroups host, TabGroupLeaf leaf)
        {
            // Remember host for later
            _squares = squares;

            // Get the total size of the tabbed groups control itself in screen coordinates
            _screenRect = host.RectangleToScreen(host.ClientRectangle);

            int horzThird = _screenRect.Width / 3;
            int vertThird = _screenRect.Height / 3;

            // Create the four display rectangles
            Rectangle leftDisplay   = new Rectangle(_screenRect.X, _screenRect.Y, horzThird, _screenRect.Height);
            Rectangle rightDisplay  = new Rectangle(_screenRect.Right - horzThird, _screenRect.Y, horzThird, _screenRect.Height);
            Rectangle topDisplay    = new Rectangle(_screenRect.X, _screenRect.Y, _screenRect.Width, vertThird);
            Rectangle bottomDisplay = new Rectangle(_screenRect.X, _screenRect.Bottom - vertThird, _screenRect.Width, vertThird);

            // Create the four default targets which represent each control edge
            _left   = new Target(leftDisplay, leftDisplay, leaf, Target.TargetActions.ControlLeft);
            _right  = new Target(rightDisplay, rightDisplay, leaf, Target.TargetActions.ControlRight);
            _top    = new Target(topDisplay, topDisplay, leaf, Target.TargetActions.ControlTop);
            _bottom = new Target(bottomDisplay, bottomDisplay, leaf, Target.TargetActions.ControlBottom);

            // Not currently inside the hot area
            _hotInside = false;
        }
Example #5
0
        private void RecalculateTabSizes()
        {
            // The space of each leaf can only be set after each leaf is created
            // Open up only the first leaf and close all others
            for (int i = 0; i < _stackTabControl.RootSequence.Count; i++)
            {
                TabGroupLeaf tgl = (TabGroupLeaf)_stackTabControl.RootSequence[i];

                if (_component.StackStyle == StackStyle.ShowMultiple && _component.OpenAllTabsInitially)
                {
                    OpenLeaf(tgl, (decimal)100 / _stackTabControl.RootSequence.Count);
                }
                else
                {
                    if (tgl == _stackTabControl.RootSequence[0])
                    {
                        OpenLeaf(tgl, 100);
                        HighlightLeaf(tgl, true);
                    }
                    else
                    {
                        CloseLeaf(tgl);
                    }
                }
            }

            // Reflect spacing changes immediately
            _stackTabControl.RootSequence.Reposition();
        }
Example #6
0
        private void OpenLeaf(TabGroupLeaf tgl, decimal space)
        {
            if (tgl == null)
            {
                return;
            }

            // Only open the leaf visually, it does not set a leaf active
            Crownwood.DotNetMagic.Controls.TabPage tabPageUI = tgl.TabPages[0];
            StackTabPage page     = (StackTabPage)tabPageUI.Tag;
            StackTab     stackTab = (StackTab)tabPageUI.Control;

            if (page.Component.IsStarted == false)
            {
                page.Component.Start();
            }

            if (stackTab.ApplicationComponentControl == null)
            {
                stackTab.ApplicationComponentControl      = (Control)_component.GetPageView(page).GuiElement;
                stackTab.ApplicationComponentControl.Dock = DockStyle.Fill;
            }

            SetArrowState(stackTab.TitleBar, true);

            tgl.Space = space;
        }
Example #7
0
        private void CreateStackTab(StackTabPage page)
        {
            StackTab stackTab = new StackTab(page, DockStyle.Top);

            if (_component.StackStyle == StackStyle.ShowMultiple)
            {
                stackTab.TitleBar.ActAsButton = ActAsButton.JustArrow;
                stackTab.TitleBar.ArrowButton = ArrowButton.DownArrow;
            }
            else
            {
                stackTab.TitleBar.ActAsButton = ActAsButton.WholeControl;
                stackTab.TitleBar.ArrowButton = ArrowButton.None;
            }

            stackTab.ButtonClicked      += OnTabButtonClick;
            stackTab.TitleClicked       += OnTabTitleClicked;
            stackTab.TitleDoubleClicked += OnTabTitleDoubleClicked;

            TabGroupLeaf tgl = _stackTabControl.RootSequence.AddNewLeaf();

            tgl.MinimumSize = stackTab.MinimumRequestedSize;

            // Prevent user from resizing
            tgl.ResizeBarLock = _component.StackStyle == StackStyle.ShowMultiple ? false : true;

            Crownwood.DotNetMagic.Controls.TabPage tabPageUI = new Crownwood.DotNetMagic.Controls.TabPage(page.Name, stackTab);
            tabPageUI.Tag = page;
            tgl.TabPages.Add(tabPageUI);

            RecalculateTabSizes();
        }
Example #8
0
        private void CreateControlTargets(TabbedGroups host, TabGroupLeaf leaf)
        {
            // Get the total size of the tabbed groups control itself in screen coordinates
            Rectangle totalSize = host.RectangleToScreen(host.ClientRectangle);

            int horzThird = totalSize.Width / 3;
            int vertThird = totalSize.Height / 3;

            // Create the four display rectangles
            Rectangle leftDisplay   = new Rectangle(totalSize.X, totalSize.Y, horzThird, totalSize.Height);
            Rectangle rightDisplay  = new Rectangle(totalSize.Right - horzThird, totalSize.Y, horzThird, totalSize.Height);
            Rectangle topDisplay    = new Rectangle(totalSize.X, totalSize.Y, totalSize.Width, vertThird);
            Rectangle bottomDisplay = new Rectangle(totalSize.X, totalSize.Bottom - vertThird, totalSize.Width, vertThird);

            // Create the four hot rectangles
            Rectangle leftHot   = new Rectangle(totalSize.X, totalSize.Y, _hotVector, totalSize.Height);
            Rectangle rightHot  = new Rectangle(totalSize.Right - _hotVector, totalSize.Y, _hotVector, totalSize.Height);
            Rectangle topHot    = new Rectangle(totalSize.X, totalSize.Y, totalSize.Width, _hotVector);
            Rectangle bottomHot = new Rectangle(totalSize.X, totalSize.Bottom - _hotVector, totalSize.Width, _hotVector);

            // Create the four default targets which represent each control edge
            _targets.Add(new Target(leftHot, leftDisplay, leaf, Target.TargetActions.ControlLeft));
            _targets.Add(new Target(rightHot, rightDisplay, leaf, Target.TargetActions.ControlRight));
            _targets.Add(new Target(topHot, topDisplay, leaf, Target.TargetActions.ControlTop));
            _targets.Add(new Target(bottomHot, bottomDisplay, leaf, Target.TargetActions.ControlBottom));
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the TargetManagerZones class.
 /// </summary>
 /// <param name="squares">Show as squares or diamonds.</param>
 /// <param name="host">Control that is requesting target management.</param>
 /// <param name="leaf">Source leaf causing drag operation.</param>
 /// <param name="source">Source TabControl of drag operation.</param>
 public TargetManagerZones(bool squares,
                           TabbedGroups host,
                           TabGroupLeaf leaf,
                           Controls.TabControl source)
     : base(squares, host, leaf, source)
 {
 }
Example #10
0
 private void OnComponentCurrentPageChanged(object sender, EventArgs e)
 {
     if (_component.CurrentPage != null)
     {
         TabGroupLeaf tgl = GetLeafForStackPage(_component.CurrentPage);
         HighlightLeaf(tgl, true);
     }
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the TGContextMenuEventArgs class.
 /// </summary>
 /// <param name="tgl">Source TabGroupLeaf for event.</param>
 /// <param name="tc">Source TabControl for event.</param>
 /// <param name="tp">Source TabPage for event.</param>
 /// <param name="contextMenu">Source PopupMenu for event.</param>
 public TGContextMenuEventArgs(TabGroupLeaf tgl,
                               Controls.TabControl tc,
                               Controls.TabPage tp,
                               PopupMenu contextMenu)
     : base(tgl, tc, tp)
 {
     // Definie initial state
     _contextMenu = contextMenu;
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the TGCloseRequestEventArgs class.
 /// </summary>
 /// <param name="tgl">Source TabGroupLeaf for event.</param>
 /// <param name="tc">Source TabControl for the event.</param>
 /// <param name="tp">Source TabPage for the event.</param>
 public TGCloseRequestEventArgs(TabGroupLeaf tgl,
                                Controls.TabControl tc,
                                Controls.TabPage tp)
 {
     // Definie initial state
     _tgl    = tgl;
     _tc     = tc;
     _tp     = tp;
     _cancel = false;
 }
Example #13
0
        private void OnTabTitleClicked(object sender, EventArgs e)
        {
            Crownwood.DotNetMagic.Controls.TitleBar titleBar = (Crownwood.DotNetMagic.Controls.TitleBar)sender;
            TabGroupLeaf selectedLeaf = GetLeafForTitleBar(titleBar);

            if (IsLeafExpanded(selectedLeaf))
            {
                ChangeComponentPageFromLeaf(selectedLeaf);
            }
        }
Example #14
0
        private void CloseLeaf(TabGroupLeaf tgl)
        {
            if (tgl == null)
            {
                return;
            }

            SetArrowState(GetTitleBarForPage(tgl.TabPages[0]), false);
            tgl.Space = 0;
            HighlightLeaf(tgl, false);
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the Target class.
 /// </summary>
 /// <param name="hotRect">Rectangle that represents active area of target.</param>
 /// <param name="drawRect">Rectangle that should be drawn when active.</param>
 /// <param name="leaf">Source leaf associated with target.</param>
 /// <param name="action">Action to be performed if target selected.</param>
 public Target(Rectangle hotRect,
               Rectangle drawRect,
               TabGroupLeaf leaf,
               TargetActions action)
 {
     // Define state
     _hotRect  = hotRect;
     _drawRect = drawRect;
     _leaf     = leaf;
     _action   = action;
 }
Example #16
0
        protected void CreateInitialPagesGroup2()
        {
            // Access the default leaf group
            TabGroupLeaf tgl1 = tabbedGroups2.RootSequence[0] as TabGroupLeaf;

            // Add a new leaf group in the same sequence
            TabGroupLeaf tgl2 = tabbedGroups2.RootSequence.AddNewLeaf();

            // Add a two pages to the leaf
            tgl1.TabPages.Add(NewTabPage());
            tgl2.TabPages.Add(NewTabPage());
        }
Example #17
0
        private void CreateLeafTargets(TabGroupLeaf leaf)
        {
            // Grab the underlying tab control
            Controls.TabControl tc = leaf.GroupControl as Controls.TabControl;

            // Get the total size of the tab control itself in screen coordinates
            Rectangle totalSize = tc.RectangleToScreen(tc.ClientRectangle);

            // We do not allow a page to be transfered to its own leaf!
            if (leaf != Leaf)
            {
                // Is the destination leaf allowed to accept a drop?
                if (leaf.AllowDrop)
                {
                    Rectangle tabsSize = tc.RectangleToScreen(tc.TabsAreaRect);

                    // Give priority to the tabs area being used to transfer page
                    _targets.Add(new Target(tabsSize, totalSize, leaf, Target.TargetActions.Transfer));
                }
            }

            // Can only create new groups if moving relative to a new group
            // or we have more than one page in the originating group
            if ((leaf != Leaf) || ((leaf == Leaf) && Leaf.TabPages.Count > 1))
            {
                int horzThird = totalSize.Width / 3;
                int vertThird = totalSize.Height / 3;

                // Create the four spacing rectangle
                Rectangle leftRect   = new Rectangle(totalSize.X, totalSize.Y, horzThird, totalSize.Height);
                Rectangle rightRect  = new Rectangle(totalSize.Right - horzThird, totalSize.Y, horzThird, totalSize.Height);
                Rectangle topRect    = new Rectangle(totalSize.X, totalSize.Y, totalSize.Width, vertThird);
                Rectangle bottomRect = new Rectangle(totalSize.X, totalSize.Bottom - vertThird, totalSize.Width, vertThird);

                // Add each new target
                _targets.Add(new Target(leftRect, leftRect, leaf, Target.TargetActions.GroupLeft));
                _targets.Add(new Target(rightRect, rightRect, leaf, Target.TargetActions.GroupRight));
                _targets.Add(new Target(topRect, topRect, leaf, Target.TargetActions.GroupTop));
                _targets.Add(new Target(bottomRect, bottomRect, leaf, Target.TargetActions.GroupBottom));
            }

            // We do not allow a page to be transfered to its own leaf!
            if (leaf != Leaf)
            {
                // Is the destination leaf allowed to accept a drop?
                if (leaf.AllowDrop)
                {
                    // Any remaining space is used to
                    _targets.Add(new Target(totalSize, totalSize, leaf, Target.TargetActions.Transfer));
                }
            }
        }
Example #18
0
        protected void CreateInitialPagesGroup1()
        {
            // Access the default leaf group
            TabGroupLeaf tgl = tabbedGroups1.RootSequence[0] as TabGroupLeaf;

            // Create two pages for the leaf
            Crownwood.Magic.Controls.TabPage tp1 = new Crownwood.Magic.Controls.TabPage("Page" + _count++, new RichTextBox(), NextImage());
            Crownwood.Magic.Controls.TabPage tp2 = new Crownwood.Magic.Controls.TabPage("Page" + _count++, new RichTextBox(), NextImage());

            // Add a two pages to the leaf
            tgl.TabPages.Add(tp1);
            tgl.TabPages.Add(tp2);
        }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the TargetManager class.
        /// </summary>
        /// <param name="squares">Show as squares or diamonds.</param>
        /// <param name="host">Control that is requesting target management.</param>
        /// <param name="leaf">Source leaf causing drag operation.</param>
        /// <param name="source">Source TabControl of drag operation.</param>
        public TargetManager(bool squares,
                             TabbedGroups host,
                             TabGroupLeaf leaf,
                             Controls.TabControl source)
        {
            // Define state
            _squares    = squares;
            _host       = host;
            _leaf       = leaf;
            _source     = source;
            _lastTarget = null;

            // Setup targets
            Initialize();
        }
Example #20
0
        protected void CreateInitialPagesGroup3()
        {
            // Change direction to opposite
            tabbedGroups3.RootSequence.Direction = Direction.Vertical;

            // Access the default leaf group
            TabGroupLeaf tgl1 = tabbedGroups3.RootSequence[0] as TabGroupLeaf;

            // Add a new leaf group in the same sequence
            TabGroupLeaf tgl2 = tabbedGroups3.RootSequence.AddNewLeaf();

            // Add a two pages to the leaf
            tgl1.TabPages.Add(NewTabPage());
            tgl2.TabPages.Add(NewTabPage());
        }
Example #21
0
        private TabGroupLeaf GetFirstExpandedLeaf()
        {
            TabGroupLeaf tgl = _stackTabControl.FirstLeaf();

            while (tgl != null)
            {
                if (IsLeafExpanded(tgl))
                {
                    break;
                }

                tgl = _stackTabControl.NextLeaf(tgl);
            }

            return(tgl);
        }
Example #22
0
 private void m_tabs_PageCloseRequest(Crownwood.Magic.Controls.TabbedGroups tg, Crownwood.Magic.Controls.TGCloseRequestEventArgs e)
 {
     if (m_tabs.RootSequence.Count == 1)
     {
         TabGroupLeaf leaf = m_tabs.FirstLeaf();
         if (leaf.TabPages.Count == 1)
         {
             CFormAlerte.Afficher(I.T("Impossible to close the unique thumbnail of the application|100"), EFormAlerteType.Erreur);
             e.Cancel = true;
         }
         else
         {
             e.Cancel = false;
         }
     }
 }
Example #23
0
        private void RemoveStackTab(StackTabPage page)
        {
            for (int i = 0; i < _stackTabControl.RootSequence.Count; i++)
            {
                TabGroupLeaf tgl = (TabGroupLeaf)_stackTabControl.RootSequence[i];
                Crownwood.DotNetMagic.Controls.TabPage tabPageUI = CollectionUtils.FirstElement <Crownwood.DotNetMagic.Controls.TabPage>(tgl.TabPages);
                if (tabPageUI.Tag == page)
                {
                    // remove the tab page
                    // note that this automatically removes the parent leaf, since it is the only tab
                    tgl.TabPages.Remove(tabPageUI);
                    break;
                }
            }

            RecalculateTabSizes();
        }
Example #24
0
        private TabPage CreatePage(Editor c, string name)
        {
            c.Disposed += new EventHandler(EditorDisposed);
            TabPage tp = new TabPage();

            tp.Dock       = DockStyle.Fill;
            tp.Title      = name;
            tp.ImageIndex = c is TestEditor ? 9 : 10;

            c.Tag = tp;
            tp.Controls.Add(c);

            TabGroupLeaf tgl = GetFirstLeaf();

            tgl.TabPages.Add(tp);
            return(tp);
        }
Example #25
0
        private void ChangeComponentPageFromLeaf(TabGroupLeaf tgl)
        {
            StackTabPage page = (StackTabPage)tgl.TabPages[0].Tag;

            if (_component.CurrentPage != page)
            {
                TabGroupLeaf previousLeaf = GetLeafForStackPage(_component.CurrentPage);
                HighlightLeaf(previousLeaf, false);

                if (_component.CurrentPage != page)
                {
                    _component.CurrentPage = page;
                }
            }

            HighlightLeaf(tgl, true);
        }
Example #26
0
        private void ToggleLeaf(TabGroupLeaf tgl)
        {
            ExpandCollapseLeaf(tgl);
            if (IsLeafExpanded(tgl))
            {
                ChangeComponentPageFromLeaf(tgl);
            }
            else
            {
                TabGroupLeaf firstExpandedLeaf = GetFirstExpandedLeaf();

                if (firstExpandedLeaf != null)
                {
                    ChangeComponentPageFromLeaf(firstExpandedLeaf);
                }
            }
        }
Example #27
0
        /// <summary>
        /// Initialize a new instance of the TargetAreaLeaf class.
        /// </summary>
        /// <param name="squares">Showing as squares or diamonds.</param>
        /// <param name="source">Leaf that is being dragged.</param>
        /// <param name="leaf">Leaf that is a potential target.</param>
        public TargetAreaLeaf(bool squares, TabGroupLeaf source, TabGroupLeaf leaf)
        {
            // Remember host for later
            _squares = squares;

            // Grab the underlying tab control
            Controls.TabControl tc = leaf.GroupControl as Controls.TabControl;

            // Get the total size of the tab control itself in screen coordinates
            _screenRect = tc.RectangleToScreen(tc.ClientRectangle);

            // Can only create new groups if moving relative to a new group
            // or we have more than one page in the originating group
            if ((leaf != source) || ((leaf == source) && source.TabPages.Count > 1))
            {
                int horzThird = _screenRect.Width / 3;
                int vertThird = _screenRect.Height / 3;

                // Create the four spacing rectangle
                Rectangle leftRect   = new Rectangle(_screenRect.X, _screenRect.Y, horzThird, _screenRect.Height);
                Rectangle rightRect  = new Rectangle(_screenRect.Right - horzThird, _screenRect.Y, horzThird, _screenRect.Height);
                Rectangle topRect    = new Rectangle(_screenRect.X, _screenRect.Y, _screenRect.Width, vertThird);
                Rectangle bottomRect = new Rectangle(_screenRect.X, _screenRect.Bottom - vertThird, _screenRect.Width, vertThird);

                // Add each new target
                _left   = new Target(leftRect, leftRect, leaf, Target.TargetActions.GroupLeft);
                _right  = new Target(rightRect, rightRect, leaf, Target.TargetActions.GroupRight);
                _top    = new Target(topRect, topRect, leaf, Target.TargetActions.GroupTop);
                _bottom = new Target(bottomRect, bottomRect, leaf, Target.TargetActions.GroupBottom);
            }

            // We do not allow a page to be transfered to its own leaf!
            if (leaf != source)
            {
                // Is the destination leaf allowed to accept a drop?
                if (leaf.AllowDrop)
                {
                    // Any remaining space is used to
                    _tabbed = new Target(_screenRect, _screenRect, leaf, Target.TargetActions.Transfer);
                }
            }

            // Not currently inside the hot area
            _hotInside = false;
        }
Example #28
0
        private void HighlightLeaf(TabGroupLeaf tgl, bool highlight)
        {
            Crownwood.DotNetMagic.Controls.TabPage tabPageUI = tgl.TabPages[0];
            StackTab stackTab = (StackTab)tabPageUI.Control;

            if (highlight)
            {
                stackTab.TitleBar.Style     = _activeStyle;
                _stackTabControl.ActiveLeaf = tgl;

                stackTab.Select();
                stackTab.Focus();
            }
            else
            {
                stackTab.TitleBar.Style = _inactiveStyle;
            }
        }
Example #29
0
        private TabGroupLeaf GetLeafForStackPage(StackTabPage page)
        {
            TabGroupLeaf tgl = _stackTabControl.FirstLeaf();

            while (tgl != null)
            {
                StackTabPage p = (StackTabPage)tgl.TabPages[0].Tag;

                if (p == page)
                {
                    break;
                }

                tgl = _stackTabControl.NextLeaf(tgl);
            }

            return(tgl);
        }
Example #30
0
        private TabGroupLeaf GetLeafForTitleBar(Crownwood.DotNetMagic.Controls.TitleBar titleBar)
        {
            TabGroupLeaf tgl = _stackTabControl.FirstLeaf();

            while (tgl != null)
            {
                // Extract the StackTabTitleBar instance from page
                Crownwood.DotNetMagic.Controls.TitleBar tb = GetTitleBarForPage(tgl.TabPages[0]);
                if (tb == titleBar)
                {
                    break;
                }

                tgl = _stackTabControl.NextLeaf(tgl);
            }

            return(tgl);
        }
		private static bool IsLeafExpanded(TabGroupLeaf tgl)
		{
			return tgl.Space > 0;
		}
		private void ChangeComponentPageFromLeaf(TabGroupLeaf tgl)
		{
			StackTabPage page = (StackTabPage) tgl.TabPages[0].Tag;
			if (_component.CurrentPage != page)
			{
				TabGroupLeaf previousLeaf = GetLeafForStackPage(_component.CurrentPage);
				HighlightLeaf(previousLeaf, false);

				if (_component.CurrentPage != page)
					_component.CurrentPage = page;
			}

			HighlightLeaf(tgl, true);
		}
		private void ExpandCollapseLeaf(TabGroupLeaf selectedLeaf)
		{
			if (selectedLeaf == null)
				return;

			if (_component.StackStyle == StackStyle.ShowMultiple)
			{
				// Remember which title bar sent message
				List<TabGroupLeaf> openedLeaves = new List<TabGroupLeaf>();
				TabGroupLeaf tgl = _stackTabControl.FirstLeaf();
				while (tgl != null)
				{
					// Remember which leaf is opened
					if (IsLeafExpanded(tgl))
						openedLeaves.Add(tgl);

					HighlightLeaf(tgl, false);
					tgl = _stackTabControl.NextLeaf(tgl);
				}

				// Add to openedLeaf because we want to open this
				if (IsLeafExpanded(selectedLeaf))
				{
					openedLeaves.Remove(selectedLeaf);
					CloseLeaf(selectedLeaf);
				}
				else
				{
					openedLeaves.Add(selectedLeaf);
				}

				// Open each leaf with evenly distributed space
				Decimal leafSpace = openedLeaves.Count == 0 ? 100 : (decimal)100 / openedLeaves.Count;
				Decimal spaceRemained = 100;
				foreach (TabGroupLeaf leaf in openedLeaves)
				{
					OpenLeaf(leaf, leafSpace);
					spaceRemained -= leafSpace;
				}

				if (openedLeaves.Count == 0)
				{
					// We need at least one leaf open, so keep the current leaf open if it was the only one opened
					OpenLeaf(selectedLeaf, spaceRemained);
				}
				else
				{
					openedLeaves[0].Space += spaceRemained;
				}
			}
			else
			{
				TabGroupLeaf tgl = _stackTabControl.FirstLeaf();
				while (tgl != null)
				{
					// Is the source of the click?
					if (tgl != selectedLeaf)
						CloseLeaf(tgl);

					HighlightLeaf(tgl, false);
					tgl = _stackTabControl.NextLeaf(tgl);
				}

				OpenLeaf(selectedLeaf, 100);
			}

			// Reflect changes immediately
			_stackTabControl.RootSequence.Reposition();
		}
		private void HighlightLeaf(TabGroupLeaf tgl, bool highlight)
		{
			Crownwood.DotNetMagic.Controls.TabPage tabPageUI = tgl.TabPages[0];
			StackTab stackTab = (StackTab) tabPageUI.Control;
			
			if (highlight)
			{
				stackTab.TitleBar.Style = _activeStyle;
				_stackTabControl.ActiveLeaf = tgl;

				stackTab.Select();
				stackTab.Focus();
			}
			else
			{
				stackTab.TitleBar.Style = _inactiveStyle;
			}
		}
		private void OpenLeaf(TabGroupLeaf tgl, decimal space)
		{
			if (tgl == null)
				return;

			// Only open the leaf visually, it does not set a leaf active
			Crownwood.DotNetMagic.Controls.TabPage tabPageUI = tgl.TabPages[0];
			StackTabPage page = (StackTabPage) tabPageUI.Tag;
			StackTab stackTab = (StackTab) tabPageUI.Control;

			if (page.Component.IsStarted == false)
				page.Component.Start();

			if ( stackTab.ApplicationComponentControl == null)
			{
				stackTab.ApplicationComponentControl = (Control)_component.GetPageView(page).GuiElement;
				stackTab.ApplicationComponentControl.Dock = DockStyle.Fill;
			}

			SetArrowState(stackTab.TitleBar, true);

			tgl.Space = space;
		}
		private void ToggleLeaf(TabGroupLeaf tgl)
		{
			ExpandCollapseLeaf(tgl);
			if (IsLeafExpanded(tgl))
			{
				ChangeComponentPageFromLeaf(tgl);
			}
			else
			{
				TabGroupLeaf firstExpandedLeaf = GetFirstExpandedLeaf();

				if (firstExpandedLeaf != null)
					ChangeComponentPageFromLeaf(firstExpandedLeaf);
			}
		}
		private void CloseLeaf(TabGroupLeaf tgl)
		{
			if (tgl == null)
				return;

			SetArrowState(GetTitleBarForPage(tgl.TabPages[0]), false);
			tgl.Space = 0;
			HighlightLeaf(tgl, false);
		}