context: // ---------------------------------------------------------------------------------
  //  Copyright (C) 2007-2010 Chillisoft Solutions
  //  
  //  This file is part of the Habanero framework.
  //  
  //      Habanero is a free framework: you can redistribute it and/or modify
  //      it under the terms of the GNU Lesser General Public License as published by
  //      the Free Software Foundation, either version 3 of the License, or
  //      (at your option) any later version.
  //  
  //      The Habanero framework is distributed in the hope that it will be useful,
  //      but WITHOUT ANY WARRANTY; without even the implied warranty of
  //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  //      GNU Lesser General Public License for more details.
  //  
  //      You should have received a copy of the GNU Lesser General Public License
  //      along with the Habanero framework.  If not, see <http://www.gnu.org/licenses/>.
  // ---------------------------------------------------------------------------------
  using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.Drawing;
  using Gizmox.WebGUI.Forms;
  using Habanero.Base;
  using Habanero.Faces.Base;
  using DockStyle=Habanero.Faces.Base.DockStyle;
  
  namespace Habanero.Faces.VWG
  {
      /// <summary>
      /// A collection of <see cref="CollapsibleMenuItemVWG"/>s used by the CollapsibleMenu.
      /// </summary>
      [MetadataTag("P")]
      public class CollapsibleMenuItemCollectionVWG : IMenuItemCollection
      {
          private readonly IMenuItem _ownerMenuItem;
  
          private readonly IList<IMenuItem> _list = new List<IMenuItem>();
          private ColumnLayoutManager _columnLayoutManager;
  
          /// <summary>
          /// Creates a <see cref="CollapsibleMenuItemCollectionVWG"/>
          /// </summary>
          /// <param name="menu"></param>
          public CollapsibleMenuItemCollectionVWG(IMenuItem menu)
          {
              _ownerMenuItem = menu;
              this.ControlFactory = GlobalUIRegistry.ControlFactory;
          }
  
          private IControlFactory ControlFactory { get; set; }
  
          #region Implementation of IMenuItemCollection
  
          /// <summary>
          /// Adds a Menu item to the <see cref="T:Habanero.Faces.Base.IMenuItemCollection" />.
          /// </summary>
          /// <param name="menuItem"></param>
          public void Add(IMenuItem menuItem)
          {
              _list.Add(menuItem);
              ICollapsiblePanelGroupControl cpGroupMenuItem = _ownerMenuItem as ICollapsiblePanelGroupControl;
              if (cpGroupMenuItem != null && menuItem is CollapsibleSubMenuItemVWG)
              {
                  CollapsibleSubMenuItemVWG outlookStyleSubMenuItem = (CollapsibleSubMenuItemVWG) menuItem;
                  cpGroupMenuItem.AddControl(outlookStyleSubMenuItem);
                  return;
              }
              ICollapsiblePanel cpMenuItem = _ownerMenuItem as ICollapsiblePanel;
              if (cpMenuItem != null && menuItem is CollapsibleMenuItemVWG)
              {
                  if (cpMenuItem.ContentControl == null)
                  {
                      cpMenuItem.ContentControl = this.ControlFactory.CreatePanel();
                      _columnLayoutManager = new ColumnLayoutManager(cpMenuItem.ContentControl, this.ControlFactory);
                          // this.ControlFactory.CreateBorderLayoutManager(cpMenuItem);
                      _columnLayoutManager.HorizontalGapSize = 0;
                      _columnLayoutManager.VerticalGapSize = 0;
                      _columnLayoutManager.BorderSize = 0;
                  }
                  _columnLayoutManager.AddControl((CollapsibleMenuItemVWG) menuItem);
                  cpMenuItem.Height += ((CollapsibleMenuItemVWG) menuItem).Height;
                  cpMenuItem.ExpandedHeight = cpMenuItem.Height;
              }
          }
  
          /// <summary>
          ///The number of <see cref="IMenuItem"/>s in this <see cref="IMenuItemCollection"/>
          /// </summary>
          public int Count
          {
              get { return _list.Count; }
          }
  
          /// <summary>
          /// The Menu Item that owns this colleciton of Menu Items.
          /// </summary>
          public IMenuItem OwnerMenuItem
          {
              get { return _ownerMenuItem; }
          }
  
          /// <summary>
          /// Returns the Actual Menu item identified by the index.
          /// </summary>
          /// <param name="index"></param>
          public IMenuItem this[int index]
          {
              get { return _list[index]; }
          }
  
          #endregion
  
          #region Implementation of IEnumerable
  
          IEnumerator IEnumerable.GetEnumerator()
          {
              return _list.GetEnumerator();
          }
  
          #endregion
  
          #region Implementation of IEnumerable<IMenuItem>
  
          IEnumerator<IMenuItem> IEnumerable<IMenuItem>.GetEnumerator()
          {
              return _list.GetEnumerator();
          }
  
          #endregion
      }
  
      /// <summary>
      /// The Collapsible Menu is essentially a <see cref="ICollapsiblePanelGroupControl"/>
      /// that has Collapsible Panels (See <see cref="ICollapsiblePanel"/>) placed inside of it.
      /// The Collapsible Panels have menu Items (Leaf menu Items) which when clicked will
      /// perform the Doclick of the Habanero Menu Item.
      /// The CollapsibleMenu is built from a Habanero Menu (see <see cref="HabaneroMenu"/>) using
      ///  the <see cref="CollapsibleMenuBuilderVWG"/>
      /// </summary>
      [MetadataTag("P")]
      public class CollapsibleMenuVWG : CollapsiblePanelGroupControlVWG, IMainMenuHabanero, IMenuItem
      {
          private readonly IMenuItemCollection _menuItemCollection;
          private ISplitContainer _splitContainer;
          private MainEditorPanelVWG _mainEditorPanel;
  
          /// <summary>
          /// Constructs a <see cref="CollapsibleMenuVWG"/>
          /// </summary>
          public CollapsibleMenuVWG()
          {
              _menuItemCollection = new CollapsibleMenuItemCollectionVWG(this);
          }
  
          /// <summary>
          /// Constructs a <see cref="CollapsibleMenuVWG"/>
          /// </summary>
          public CollapsibleMenuVWG(HabaneroMenu habaneroMenu) : this()
          {
              if (habaneroMenu != null) this.Name = habaneroMenu.Name;
          }
  
          #region Implementation of IMainMenuHabanero
  
          /// <summary>
          ///This method sets up the form so that the menu is displayed and the form is able to 
          ///display the controls loaded when the menu item is clicked.
          /// </summary>
          /// <param name="form">The form to set up with the menu</param>
          public void DockInForm(IControlHabanero form)
          {
              DockInForm(form, 250);
          }
          /// <summary>
          ///This method sets up the form so that the menu is displayed and the form is able to 
          ///display the controls loaded when the menu item is clicked.
          /// </summary>
          /// <param name="form">The form to set up with the menu</param>
          /// <param name="menuWidth">The width of the menu - configurable to so that each application can set its menu width</param>
          public virtual void DockInForm(IControlHabanero form, int menuWidth)
          {
              if (form == null) throw new ArgumentNullException("form");
              _splitContainer = this.ControlFactory.CreateSplitContainer();
              _splitContainer.Name = "SplitContainer";
              BorderLayoutManager layoutManager = this.ControlFactory.CreateBorderLayoutManager(form);
              layoutManager.AddControl(_splitContainer, BorderLayoutManager.Position.Centre);
              SplitContainer splitContainer1 = (SplitContainer) _splitContainer;
              //splitContainer1.IsSplitterFixed = true;
              splitContainer1.FixedPanel = FixedPanel.Panel1;
              splitContainer1.Size = new System.Drawing.Size(400, 450);
              splitContainer1.SplitterDistance = menuWidth;
              splitContainer1.Panel1MinSize = menuWidth;
              splitContainer1.Orientation = Gizmox.WebGUI.Forms.Orientation.Vertical;
              this.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
              splitContainer1.Panel1.Controls.Add(this);
              _mainEditorPanel = new MainEditorPanelVWG(this.ControlFactory);
              _mainEditorPanel.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
              splitContainer1.Panel2.Controls.Add(_mainEditorPanel);
          }
  
          /// <summary>
          /// Performs the Click event for this <see cref="T:Habanero.Faces.Base.IMenuItem" />.
          /// </summary>
          public void PerformClick()
          {
          }
  
          /// <summary>
          ///             This actually executes the Code when PerformClick is selected <see cref="T:Habanero.Faces.Base.IMenuItem" />.
          /// </summary>
          public void DoClick()
          {
          }
  
          /// <summary>
          ///              The collection of menu items for this menu
          /// </summary>
          public IMenuItemCollection MenuItems
          {
              get { return _menuItemCollection; }
          }
          /// <summary>
          /// This is to set the text of the main title.
          /// </summary>
          public string MainTitleText
          {
              get { return _mainEditorPanel.MainTitleIconControl.Title.Text; }
  
gt:             set { _mainEditorPanel.MainTitleIconControl.Title.Text = value;}