protected override bool OnButtonPressEvent(Gdk.EventButton evnt)
        {
            if (evnt.TriggersContextMenu())
            {
                ITabStrip tabStrip = null;
                if (Parent is ITabStripBox)
                {
                    tabStrip = ((ITabStripBox)Parent).TabStrip as ITabStrip;
                }
                item.ShowDockPopupMenu(evnt.Time, tabStrip);
                return(false);
            }
            else if (evnt.Button == Mouse.LEFT_MOUSE_BUTTON)
            {
                if (evnt.Type == Gdk.EventType.ButtonPress)
                {
                    tabPressed = true;
                    pressX     = evnt.X;
                    pressY     = evnt.Y;
                }
#if false
                else if (evnt.Type == Gdk.EventType.TwoButtonPress)
                {
                    tabActivated = true;
                }
#endif
            }
            return(base.OnButtonPressEvent(evnt));
        }
 void ClearNotebooks()
 {
     for (int n = notebooks.Count - 1; n >= 0; n--)
     {
         ITabStrip ts = notebooks[n];
         notebooks.RemoveAt(n);
         ts.Clear();
         ts.Unparent();
         ts.Destroy();
     }
 }
        void DrawAsBrowser(Gdk.EventExpose evnt)
        {
            var alloc = Allocation;

            Gdk.GC bgc = new Gdk.GC(GdkWindow);
            var    c   = new HslColor(VisualStyle.PadBackgroundColor.Value);

            c.L           *= 0.7;
            bgc.RgbFgColor = c;
            bool      first    = true;
            bool      last     = true;
            ITabStrip tabStrip = null;

            if (Parent is ITabStripBox)
            {
                var tsb = (ITabStripBox)Parent;
                var cts = tsb.Children;
                first    = cts[0] == this;
                last     = cts[cts.Length - 1] == this;
                tabStrip = tsb.TabStrip as ITabStrip;
            }

            if (Active || (first && last))
            {
                Gdk.GC gc = new Gdk.GC(GdkWindow);
                gc.RgbFgColor = VisualStyle.PadBackgroundColor.Value;
                evnt.Window.DrawRectangle(gc, true, alloc);
                if (!first)
                {
                    evnt.Window.DrawLine(bgc, alloc.X, alloc.Y, alloc.X, alloc.Y + alloc.Height - 1);
                }
                if (!(last && first) && !(tabStrip != null && tabStrip.VisualStyle.ExpandedTabs.Value && last))
                {
                    evnt.Window.DrawLine(bgc, alloc.X + alloc.Width - 1, alloc.Y, alloc.X + alloc.Width - 1, alloc.Y + alloc.Height - 1);
                }
                gc.Dispose();
            }
            else
            {
                Gdk.GC gc = new Gdk.GC(GdkWindow);
                gc.RgbFgColor = tabStrip != null ? tabStrip.VisualStyle.InactivePadBackgroundColor.Value : frame.DefaultVisualStyle.InactivePadBackgroundColor.Value;
                evnt.Window.DrawRectangle(gc, true, alloc);
                gc.Dispose();
                evnt.Window.DrawLine(bgc, alloc.X, alloc.Y + alloc.Height - 1, alloc.X + alloc.Width - 1, alloc.Y + alloc.Height - 1);
            }
            bgc.Dispose();
        }
        internal void ShowDockPopupMenu(uint time, ITabStrip tabstrip = null)
        {
            Menu menu = new Menu();

            MenuItem citem;

            // Close menuitem
            if ((Behavior & DockItemBehavior.CantClose) == 0)
            {
                citem            = new MenuItem(Catalog.GetString("Close"));
                citem.Activated += delegate { Close(); };
                menu.Append(citem);
            }

            {
                citem = new MenuItem(this.Status == DockItemStatus.AutoHide
                                 ? Catalog.GetString("Restore")
                                 : Catalog.GetString("Minimize"));
                citem.Activated += (o, e) =>
                {
                    TitleTab.OnClickDock(o, e);
                    if (this.Status == DockItemStatus.AutoHide)
                    {
                        (o as MenuItem).Name = this.Status == DockItemStatus.AutoHide
                                       ? Catalog.GetString("Restore")
                                       : Catalog.GetString("Minimize");
                    }
                };
                menu.Append(citem);
            }

#if false
            // Hide menuitem
            if ((Behavior & DockItemBehavior.CantClose) == 0 &&
                (Behavior & DockItemBehavior.CloseOnHide) == 0)
            {
                citem            = new MenuItem(Catalog.GetString("Hide"));
                citem.Activated += delegate { Visible = false; };
                menu.Append(citem);
            }

            // Auto Hide menuitem
            if ((Behavior & DockItemBehavior.CantAutoHide) == 0 && Status != DockItemStatus.AutoHide)
            {
                citem            = new MenuItem(Catalog.GetString("Minimize"));
                citem.Activated += delegate { Status = DockItemStatus.AutoHide; };
                menu.Append(citem);
            }
#endif

            if (Status != DockItemStatus.Dockable)
            {
                // Dockable menuitem
                citem            = new MenuItem(Catalog.GetString("Dock"));
                citem.Activated += delegate { Status = DockItemStatus.Dockable; };
                menu.Append(citem);
            }

            // Floating menuitem
            if ((Behavior & DockItemBehavior.NeverFloating) == 0 && Status != DockItemStatus.Floating)
            {
                citem            = new MenuItem(Catalog.GetString("Undock"));
                citem.Activated += delegate { Status = DockItemStatus.Floating; };
                menu.Append(citem);
            }

            // flip tab menuitem
            if (tabstrip != null && (Behavior & DockItemBehavior.NeverFloating) == 0 && Status != DockItemStatus.Floating &&
                (Status == DockItemStatus.Dockable || Status == DockItemStatus.AutoHide))
            {
                citem            = new MenuItem(Catalog.GetString("Toggle Horizontal/Vertical Tab Layout"));
                citem.Activated += (o, e) =>
                {
                    tabstrip.Flip();
                };
                menu.Append(citem);
            }

            if (menu.Children.Length == 0)
            {
                menu.Destroy();
                return;
            }

            ShowingContextMemu = true;

            menu.ShowAll();
            menu.Hidden += (o, e) =>
            {
                ShowingContextMemu = false;
            };
            menu.Popup(null, null, null, 3, time);
        }
        void LayoutWidgets()
        {
            if (!needsRelayout)
            {
                return;
            }
            needsRelayout = false;

            // RemoveNotebooks();

            // Create the needed notebooks and place the widgets in there

            List <DockGroup> tabbedGroups = new List <DockGroup>();

            GetTabbedGroups(layout, tabbedGroups);

            for (int n = 0; n < tabbedGroups.Count; n++)
            {
                DockGroup grp = tabbedGroups[n];
                ITabStrip ts  = null;
                if (n < notebooks.Count)
                {
                    ts = notebooks[n];
                }
                else
                {
                    switch (frame.TabType)
                    {
                    case DockFrame.TabAlgorithm.Proven:
                        ts = new TabStrip();
                        break;

                    case DockFrame.TabAlgorithm.Smooth:
                        ts = new TabSelector(false);
                        break;

                    case DockFrame.TabAlgorithm.Active:
                        ts = new TabSelector(true);
                        break;
                    }

                    ts.Show();
                    notebooks.Add(ts);
                    ts.Parent = this;
                }
                frame.UpdateRegionStyle(grp);
                ts.VisualStyle = grp.VisualStyle;
                grp.UpdateNotebook(ts);
            }

            // Remove spare tab strips
            for (int n = notebooks.Count - 1; n >= tabbedGroups.Count; n--)
            {
                ITabStrip ts = notebooks[n];
                notebooks.RemoveAt(n);
                ts.Clear();
                ts.Unparent();
                ts.Destroy();
            }

            // Create and add the required splitters

            int reqSpliters = CountRequiredSplitters(layout);

            for (int n = 0; n < splitters.Count; n++)
            {
                var s = splitters[n];
                if (s.Parent != null)
                {
                    Remove(s);
                }
            }

            // Hide the splitters that are not required

            for (int n = reqSpliters; n < splitters.Count; n++)
            {
                splitters[n].Hide();
            }

            // Add widgets to the container

            layout.LayoutWidgets();

            // Create and add the required splitters

            for (int n = 0; n < reqSpliters; n++)
            {
                if (n < splitters.Count)
                {
                    var s = splitters[n];
                    if (!s.Visible)
                    {
                        s.Show();
                    }
                    Add(s);
                }
                else
                {
                    var s = new SplitterWidget();
                    splitters.Add(s);
                    s.Show();
                    Add(s);
                }
            }
        }