public DockItemGrip(DockItem item) : this() { if (item == null) throw new ArgumentNullException ("item", "A valid DockItem must be given"); Item = item; }
public void AddItem(DockItem item) { // check if already there if (items.Contains (item)) { Console.WriteLine ("WARNING: Item has already been added to the dockbar"); return; } items.Add (item); // create a button for the item DockBarButton button = new DockBarButton (item); this.PackStart (button, false, false, 0); tooltips.SetTip (button, item.Name, item.Name); item.DockBar = this; item.DockBarButton = button; button.Clicked += new EventHandler (OnDockButtonClicked); this.ShowAll (); }
public void Remove(DockObject obj) { if (obj == null) { return; } // remove from locked/unlocked hashes and property change if that's the case if (obj is DockItem && ((DockItem)obj).HasGrip) { int locked = Locked; if (lockedItems.Contains(obj)) { lockedItems.Remove(obj); if (Locked != locked) { EmitNotifyLocked(); } } if (unlockedItems.Contains(obj)) { unlockedItems.Remove(obj); if (Locked != locked) { EmitNotifyLocked(); } } } if (obj is Dock) { toplevelDocks.Remove(obj); obj.Docked -= new DockedHandler(OnItemDocked); if (obj == controller) { DockObject newController = null; // now find some other non-automatic toplevel to use as a // new controller. start from the last dock, since it's // probably a non-floating and manual ArrayList reversed = toplevelDocks; reversed.Reverse(); foreach (DockObject item in reversed) { if (!item.IsAutomatic) { newController = item; break; } } if (newController != null) { controller = newController; } else { // no controller, no master controller = null; } } } // disconnect the signals if (obj is DockItem) { DockItem item = obj as DockItem; item.Detached -= new DetachedHandler(OnItemDetached); item.Docked -= new DockedHandler(OnItemDocked); item.DockItemDragBegin -= new DockItemDragBeginHandler(OnDragBegin); item.DockItemMotion -= new DockItemMotionHandler(OnDragMotion); item.DockItemDragEnd -= new DockItemDragEndHandler(OnDragEnd); item.PropertyChanged -= new PropertyChangedHandler(OnItemPropertyChanged); } // remove the object from the hash if it is there if (obj.Name != null && dockObjects.Contains(obj.Name)) { dockObjects.Remove(obj.Name); } /* post a layout_changed emission if the item is not automatic * (since it should be removed from the items model) */ if (!obj.IsAutomatic) { EmitLayoutChangedEvent(); } }
public void Add(DockObject obj) { if (obj == null) { return; } if (!obj.IsAutomatic) { /* create a name for the object if it doesn't have one */ if (obj.Name == null) { obj.Name = "__dock_" + number++; } /* add the object to our hash list */ if (dockObjects.Contains(obj.Name)) { Console.WriteLine("Unable to add object, name \"{0}\" taken", obj.Name); } else { dockObjects.Add(obj.Name, obj); } } if (obj is Dock) { /* if this is the first toplevel we are adding, name it controller */ if (toplevelDocks.Count == 0) { controller = obj; } /* add dock to the toplevel list */ if (((Dock)obj).Floating) { toplevelDocks.Insert(0, obj); } else { toplevelDocks.Add(obj); } /* we are interested in the dock request this toplevel * receives to update the layout */ obj.Docked += new DockedHandler(OnItemDocked); } else if (obj is DockItem) { DockItem item = obj as DockItem; /* we need to connect the item's events */ item.Detached += new DetachedHandler(OnItemDetached); item.Docked += new DockedHandler(OnItemDocked); item.DockItemDragBegin += new DockItemDragBeginHandler(OnDragBegin); item.DockItemMotion += new DockItemMotionHandler(OnDragMotion); item.DockItemDragEnd += new DockItemDragEndHandler(OnDragEnd); /* register to "locked" notification if the item has a grip, * and add the item to the corresponding hash */ item.PropertyChanged += new PropertyChangedHandler(OnItemPropertyChanged); /* post a layout_changed emission if the item is not automatic * (since it should be added to the items model) */ if (!item.IsAutomatic) { EmitLayoutChangedEvent(); } } }
public void DockTo(DockItem target, DockPlacement position) { if (target == null && position != DockPlacement.Floating) return; if (position == DockPlacement.Floating || target == null) { if (!IsBound) { Console.WriteLine ("Attempting to bind an unbound item"); return; } // FIXME: save previous docking position for later re-docking? dragoffX = dragoffY = 0; ((Dock)Master.Controller).AddFloatingItem (this, 0, 0, -1, -1); } else { target.Dock (this, position, null); } }
void AddPad(IPadContent content, string placement) { DockItem item = new DockItem (content.Id, content.Title, content.Icon, DockItemBehavior.Normal); Gtk.Label label = item.TabLabel as Gtk.Label; label.UseMarkup = true; if (content is Widget) item.Add (content.Control); else { CommandRouterContainer crc = new CommandRouterContainer (content.Control, content, true); crc.Show (); item.Add (crc); } item.Show (); item.HideItem (); content.TitleChanged += new EventHandler (UpdatePad); content.IconChanged += new EventHandler (UpdatePad); DockPad (item, placement); if (!activePadCollection.Contains (content)) activePadCollection.Add (content); }
void GetPlacement(string placementString, out DockPlacement dockPlacement, out DockItem originItem) { // placementString can be: left, right, top, bottom, or a relative // position, for example: "ProjectPad/left" would show the pad at // the left of the project pad. When using // relative placements several positions can be provided. If the // pad can be placed in the first position, the next one will be // tried. For example "ProjectPad/left; bottom". dockPlacement = DockPlacement.None; string[] placementOptions = placementString.Split (';'); foreach (string placementOption in placementOptions) { int i = placementOption.IndexOf ('/'); if (i == -1) { dockPlacement = (DockPlacement) Enum.Parse (typeof(DockPlacement), placementOption, true); break; } else { string id = placementOption.Substring (0, i); originItem = dock.GetItemByName (id); if (originItem != null && originItem.IsAttached) { dockPlacement = (DockPlacement) Enum.Parse (typeof(DockPlacement), placementOption.Substring (i+1), true); return; } } } if (dockPlacement != DockPlacement.None) { // If there is a pad in the same position, place the new one // over the existing one with a new tab. foreach (IPadContent pad in activePadCollection) { string[] places = pad.DefaultPlacement.Split (';'); foreach (string p in places) if (string.Compare (p.Trim(), dockPlacement.ToString(), true) == 0) { originItem = GetDockItem (pad); if (originItem != null && originItem.IsAttached) { dockPlacement = DockPlacement.Center; return; } } } } originItem = null; }
public DockBarButton(DockItem item) { this.item = item; this.Relief = ReliefStyle.None; this.Add(new Image(item.StockId, IconSize.SmallToolbar)); }
public DockBarButton(DockItem item) { this.item = item; this.Relief = ReliefStyle.None; this.Add (new Image (item.StockId, IconSize.SmallToolbar)); }
public void AddItem(DockItem item, DockPlacement placement) { if (item == null) return; if (placement == DockPlacement.Floating) AddFloatingItem (item, 0, 0, -1, -1); else Dock (item, placement, null); }
void UpdateItemData(TreeIter iter, DockItem item) { itemsModel.SetValue (iter, NAME_COL, item.Name); itemsModel.SetValue (iter, SHOW_COL, item.IsAttached); itemsModel.SetValue (iter, LOCK_COL, item.Locked); }
public void AddFloatingItem(DockItem item, int x, int y, int width, int height) { Dock dock = new Dock (this, true, x, y, width, height); if (Visible) { dock.Show (); if (IsMapped) dock.Map (); dock.QueueResize (); } dock.AddItem (item, DockPlacement.Top); }
protected override void OnAdded(Widget widget) { DockItem child = widget as DockItem; AddItem(child, DockPlacement.Top); }
void UpdateItemData(TreeIter iter, DockItem item) { itemsModel.SetValue(iter, NAME_COL, item.Name); itemsModel.SetValue(iter, SHOW_COL, item.IsAttached); itemsModel.SetValue(iter, LOCK_COL, item.Locked); }
private void OnDragMotion(DockItem item, int rootX, int rootY) { Dock dock = null; int winX, winY; int x, y; bool mayDock = false; DockRequest myRequest = new DockRequest(request); if (item != request.Applicant) { Console.WriteLine("Dragged item is not the same as the one we started with"); return; } /* first look under the pointer */ Gdk.Window window = Gdk.Window.AtPointer(out winX, out winY); if (window != null && window.UserData != IntPtr.Zero) { /* ok, now get the widget who owns that window and see if we can * get to a Dock by walking up the hierarchy */ Widget widget = GLib.Object.GetObject(window.UserData, false) as Widget; while (widget != null && (!(widget is Dock) || (widget is DockObject && ((DockObject)widget).Master != this))) { widget = widget.Parent; } if (widget != null) { int winW, winH, depth; /* verify that the pointer is still in that dock * (the user could have moved it) */ widget.GdkWindow.GetGeometry(out winX, out winY, out winW, out winH, out depth); widget.GdkWindow.GetOrigin(out winX, out winY); if (rootX >= winX && rootX < winX + winW && rootY >= winY && rootY < winY + winH) { dock = widget as Dock; } } } if (dock != null) { /* translate root coordinates into dock object coordinates * (i.e. widget coordinates) */ dock.GdkWindow.GetOrigin(out winX, out winY); x = rootX - winX; y = rootY - winY; mayDock = dock.OnDockRequest(x, y, ref myRequest); } else { /* try to dock the item in all the docks in the ring in turn */ foreach (Dock topDock in toplevelDocks) { if (topDock.GdkWindow == null) { Console.WriteLine("Dock has no GdkWindow: {0}, {1}", topDock.Name, topDock); } /* translate root coordinates into dock object * coordinates (i.e. widget coordinates) */ topDock.GdkWindow.GetOrigin(out winX, out winY); x = rootX - winX; y = rootY - winY; mayDock = topDock.OnDockRequest(x, y, ref myRequest); if (mayDock) { break; } } } if (!mayDock) { dock = null; myRequest.Target = Dock.GetTopLevel(item); myRequest.Position = DockPlacement.Floating; Requisition preferredSize = item.PreferredSize; myRequest.Width = preferredSize.Width; myRequest.Height = preferredSize.Height; myRequest.X = rootX - item.DragOffX; myRequest.Y = rootY - item.DragOffY; Gdk.Rectangle rect = new Gdk.Rectangle(myRequest.X, myRequest.Y, myRequest.Width, myRequest.Height); // setup extra docking information myRequest.Extra = rect; } if (!(myRequest.X == request.X && myRequest.Y == request.Y && myRequest.Width == request.Width && myRequest.Height == request.Height && dock == rectOwner)) { /* erase the previous rectangle */ if (rectDrawn) { XorRect(); } } // set the new values request = myRequest; rectOwner = dock; /* draw the previous rectangle */ if (!rectDrawn) { XorRect(); } }
protected void ForeachLockUnlock(DockItem item, bool locked) { item.Locked = locked; if (item.IsCompound) { foreach (Widget w in item.Children) { DockItem i = w as DockItem; if (i != null) ForeachLockUnlock (i, locked); } } }
public void Attach(IWorkbench wb) { DefaultWorkbench workbench = (DefaultWorkbench) wb; this.workbench = workbench; wbWindow = (Window) workbench; Gtk.VBox vbox = new VBox (false, 0); rootWidget = vbox; vbox.PackStart (workbench.TopMenu, false, false, 0); toolbarFrame = new CommandFrame (Runtime.Gui.CommandService.CommandManager); vbox.PackStart (toolbarFrame, true, true, 0); if (workbench.ToolBars != null) { for (int i = 0; i < workbench.ToolBars.Length; i++) { toolbarFrame.AddBar ((DockToolbar)workbench.ToolBars[i]); } } // Create the docking widget and add it to the window. dock = new Dock (); DockBar dockBar = new DockBar (dock); Gtk.HBox dockBox = new HBox (false, 5); dockBox.PackStart (dockBar, false, true, 0); dockBox.PackStart (dock, true, true, 0); toolbarFrame.AddContent (dockBox); // Create the notebook for the various documents. tabControl = new DragNotebook (); tabControl.Scrollable = true; tabControl.SwitchPage += new SwitchPageHandler (ActiveMdiChanged); tabControl.TabsReordered += new TabsReorderedHandler (OnTabsReordered); DockItem item = new DockItem ("Documents", "Documents", DockItemBehavior.Locked | DockItemBehavior.NoGrip); item.PreferredWidth = -2; item.PreferredHeight = -2; item.Add (tabControl); item.Show (); dock.AddItem (item, DockPlacement.Center); workbench.Add (vbox); vbox.PackEnd (Runtime.Gui.StatusBar.Control, false, true, 0); workbench.ShowAll (); foreach (IViewContent content in workbench.ViewContentCollection) ShowView (content); // by default, the active pad collection is the full set // will be overriden in CreateDefaultLayout() below activePadCollection = workbench.PadContentCollection; // create DockItems for all the pads foreach (IPadContent content in workbench.PadContentCollection) { AddPad (content, content.DefaultPlacement); } CreateDefaultLayout(); //RedrawAllComponents(); wbWindow.Show (); workbench.ContextChanged += contextChangedHandler; }
private void OnDragBegin(DockItem item) { /* Set the target to itself so it won't go floating with just a click. */ request = new DockRequest (); request.Applicant = item; request.Target = item; request.Position = DockPlacement.Floating; request.Extra = IntPtr.Zero; rectDrawn = false; rectOwner = null; }
void DockPad(DockItem item, string placement) { DockPlacement dockPlacement = DockPlacement.None; DockItem ot = null; if (placement != null) GetPlacement (placement, out dockPlacement, out ot); if (dockPlacement != DockPlacement.None && dockPlacement != DockPlacement.Floating) { if (ot != null) { item.DockTo (ot, dockPlacement); } else { ot = dock.GetItemByName ("Documents"); item.DockTo (ot, dockPlacement); } } else dock.AddItem (item, dockPlacement); item.Show (); }
private void OnDragEnd(DockItem item, bool cancelled) { if (item != request.Applicant) { Console.WriteLine ("Dragged item is not the same as the one we started with"); return; } /* Erase previously drawn rectangle */ if (rectDrawn) XorRect (); /* cancel conditions */ if (cancelled || request.Applicant == request.Target) return; // dock object to the requested position request.Target.Dock (request.Applicant, request.Position, request.Extra); EmitLayoutChangedEvent (); }
protected override void OnDestroyed() { if (layout != null) layout = null; if (icon != null) icon = null; if (tooltips != null) tooltips = null; if (item != null) { // FIXME: Disconnect future signal handlers for notify. } item = null; base.OnDestroyed (); }
private void OnDragMotion(DockItem item, int rootX, int rootY) { Dock dock = null; int winX, winY; int x, y; bool mayDock = false; DockRequest myRequest = new DockRequest (request); if (item != request.Applicant) { Console.WriteLine ("Dragged item is not the same as the one we started with"); return; } /* first look under the pointer */ Gdk.Window window = Gdk.Window.AtPointer (out winX, out winY); if (window != null && window.UserData != IntPtr.Zero) { /* ok, now get the widget who owns that window and see if we can get to a Dock by walking up the hierarchy */ Widget widget = GLib.Object.GetObject (window.UserData, false) as Widget; while (widget != null && (!(widget is Dock) || (widget is DockObject && ((DockObject)widget).Master != this))) widget = widget.Parent; if (widget != null) { int winW, winH, depth; /* verify that the pointer is still in that dock (the user could have moved it) */ widget.GdkWindow.GetGeometry (out winX, out winY, out winW, out winH, out depth); widget.GdkWindow.GetOrigin (out winX, out winY); if (rootX >= winX && rootX < winX + winW && rootY >= winY && rootY < winY + winH) dock = widget as Dock; } } if (dock != null) { /* translate root coordinates into dock object coordinates (i.e. widget coordinates) */ dock.GdkWindow.GetOrigin (out winX, out winY); x = rootX - winX; y = rootY - winY; mayDock = dock.OnDockRequest (x, y, ref myRequest); } else { /* try to dock the item in all the docks in the ring in turn */ foreach (Dock topDock in toplevelDocks) { if (topDock.GdkWindow == null) Console.WriteLine ("Dock has no GdkWindow: {0}, {1}", topDock.Name, topDock); /* translate root coordinates into dock object coordinates (i.e. widget coordinates) */ topDock.GdkWindow.GetOrigin (out winX, out winY); x = rootX - winX; y = rootY - winY; mayDock = topDock.OnDockRequest (x, y, ref myRequest); if (mayDock) break; } } if (!mayDock) { dock = null; myRequest.Target = Dock.GetTopLevel (item); myRequest.Position = DockPlacement.Floating; Requisition preferredSize = item.PreferredSize; myRequest.Width = preferredSize.Width; myRequest.Height = preferredSize.Height; myRequest.X = rootX - item.DragOffX; myRequest.Y = rootY - item.DragOffY; Gdk.Rectangle rect = new Gdk.Rectangle (myRequest.X, myRequest.Y, myRequest.Width, myRequest.Height); // setup extra docking information myRequest.Extra = rect; } if (!(myRequest.X == request.X && myRequest.Y == request.Y && myRequest.Width == request.Width && myRequest.Height == request.Height && dock == rectOwner)) { /* erase the previous rectangle */ if (rectDrawn) XorRect (); } // set the new values request = myRequest; rectOwner = dock; /* draw the previous rectangle */ if (!rectDrawn) XorRect (); }
T(string[] args) { Application.Init (); Window app = new Window ("test"); app.SetDefaultSize (400, 400); app.WindowPosition = WindowPosition.Center; app.DeleteEvent += new DeleteEventHandler (OnAppDelete); Box table = new VBox (false, 5); table.BorderWidth = 10; app.Add (table); Dock dock = new Dock (); layout = new DockLayout (dock); layout.LoadFromFile ("layout.xml"); DockBar dockbar = new DockBar (dock); Box box = new HBox (false, 5); box.PackStart (dockbar, false, false, 0); box.PackEnd (dock, true, true, 0); table.PackStart (box, true, true, 0); DockItem di = new DockItem ("item1", "Item #1", DockItemBehavior.Locked); di.Add (CreateTextView ()); dock.AddItem (di, DockPlacement.Top); DockItem di2 = new DockItem ("item2", "Item #2 has some large title", Gtk.Stock.Execute, DockItemBehavior.Normal); di2.Add (new Button ("Button 2")); dock.AddItem (di2, DockPlacement.Right); DockItem di3 = new DockItem ("item3", "Item #3 has accented characters (áéíóúñ)", Gtk.Stock.Convert, DockItemBehavior.Normal | DockItemBehavior.CantClose); di3.Add (new Button ("Button 3")); dock.AddItem (di3, DockPlacement.Bottom); DockItem[] items = new DockItem[4]; items[0] = new DockItem ("item4", "Item #4", Gtk.Stock.JustifyFill, DockItemBehavior.Normal | DockItemBehavior.CantIconify); items[0].Add (CreateTextView ()); dock.AddItem (items[0], DockPlacement.Bottom); for (int i = 1; i < 3; i++) { string name = "Item #" + (i + 4); items[i] = new DockItem (name, name, Gtk.Stock.New, DockItemBehavior.Normal); items[i].Add (CreateTextView ()); items[i].Show (); items[0].Dock (items[i], DockPlacement.Center, null); } di3.DockTo (di, DockPlacement.Top); di2.DockTo (di3, DockPlacement.Right); di2.DockTo (di3, DockPlacement.Left); di2.DockTo (null, DockPlacement.Floating); box = new HBox (true, 5); table.PackEnd (box, false, false, 0); Button button = new Button (Gtk.Stock.Save); button.Clicked += new EventHandler (OnSaveLayout); box.PackEnd (button, false, true, 0); button = new Button ("Layout Manager"); button.Clicked += new EventHandler (OnRunLayoutManager); box.PackEnd (button, false, true, 0); button = new Button ("Dump XML"); button.Clicked += new EventHandler (OnDumpXML); box.PackEnd (button, false, true, 0); app.ShowAll (); // placeholders DockPlaceholder ph1 = new DockPlaceholder ("ph1", dock, DockPlacement.Top, false); DockPlaceholder ph2 = new DockPlaceholder ("ph2", dock, DockPlacement.Bottom, false); DockPlaceholder ph3 = new DockPlaceholder ("ph3", dock, DockPlacement.Left, false); DockPlaceholder ph4 = new DockPlaceholder ("ph4", dock, DockPlacement.Right, false); Application.Run (); }
public void RemoveItem(DockItem item) { // we can only remove if it is there if (items.Contains (item)) { items.Remove (item); this.Remove (item.DockBarButton); // item.DockBarButton = null; } else { Console.WriteLine ("WARNING: {0} has not been added to the dockbar", item.Name); } }