9
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
11
// Permission is hereby granted, free of charge, to any person obtaining
12
// a copy of this software and associated documentation files (the
13
// "Software"), to deal in the Software without restriction, including
14
// without limitation the rights to use, copy, modify, merge, publish,
15
// distribute, sublicense, and/or sell copies of the Software, and to
16
// permit persons to whom the Software is furnished to do so, subject to
17
// the following conditions:
19
// The above copyright notice and this permission notice shall be
20
// included in all copies or substantial portions of the Software.
22
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
namespace MonoDevelop.Components.Docking
41
DockItemContainer widget;
42
string defaultLocation;
43
bool defaultVisible = true;
44
DockItemStatus defaultStatus = DockItemStatus.Dockable;
47
int defaultWidth = -1;
48
int defaultHeight = -1;
52
bool drawFrame = true;
53
DockItemBehavior behavior;
54
Gtk.Window floatingWindow;
55
DockBarItem dockBarItem;
56
bool lastVisibleStatus;
57
bool lastContentVisibleStatus;
59
bool isPositionMarker;
61
IDockItemLabelProvider dockLabelProvider;
62
DockItemToolbar toolbarTop;
63
DockItemToolbar toolbarBottom;
64
DockItemToolbar toolbarLeft;
65
DockItemToolbar toolbarRight;
67
public event EventHandler VisibleChanged;
68
public event EventHandler ContentVisibleChanged;
69
public event EventHandler ContentRequired;
71
internal DockItem (DockFrame frame, string id)
77
internal DockItem (DockFrame frame, Widget w, string id)
88
internal bool StickyVisible {
89
get { return stickyVisible; }
90
set { stickyVisible = value; }
94
get { return label ?? string.Empty; }
99
frame.UpdateTitle (this);
100
if (floatingWindow != null)
101
floatingWindow.Title = GetWindowTitle ();
105
public bool Visible {
107
return frame.GetVisible (this);
110
stickyVisible = value;
111
frame.SetVisible (this, value);
112
UpdateVisibleStatus ();
116
public bool VisibleInLayout (string layout)
118
return frame.GetVisible (this, layout);
121
public DockItemStatus Status {
123
return frame.GetStatus (this);
126
frame.SetStatus (this, value);
130
public IDockItemLabelProvider DockLabelProvider {
131
get { return this.dockLabelProvider; }
132
set { this.dockLabelProvider = value; }
135
internal DockItemContainer Widget {
137
if (widget == null) {
138
widget = new DockItemContainer (frame, this);
139
widget.Visible = false; // Required to ensure that the Shown event is fired
140
widget.Label = label;
141
widget.Shown += SetupContent;
147
void SetupContent (object ob, EventArgs args)
149
widget.Shown -= SetupContent;
151
if (ContentRequired != null) {
152
gettingContent = true;
154
ContentRequired (this, EventArgs.Empty);
156
gettingContent = false;
160
widget.UpdateContent ();
161
widget.Shown += delegate {
162
UpdateContentVisibleStatus ();
164
widget.Hidden += delegate {
165
UpdateContentVisibleStatus ();
167
widget.ParentSet += delegate {
168
UpdateContentVisibleStatus ();
170
UpdateContentVisibleStatus ();
173
public Widget Content {
179
if (!gettingContent && widget != null)
180
widget.UpdateContent ();
184
public DockItemToolbar GetToolbar (PositionType position)
187
case PositionType.Top:
188
if (toolbarTop == null)
189
toolbarTop = new DockItemToolbar (this, PositionType.Top);
191
case PositionType.Bottom:
192
if (toolbarBottom == null)
193
toolbarBottom = new DockItemToolbar (this, PositionType.Bottom);
194
return toolbarBottom;
195
case PositionType.Left:
196
if (toolbarLeft == null)
197
toolbarLeft = new DockItemToolbar (this, PositionType.Left);
199
case PositionType.Right:
200
if (toolbarRight == null)
201
toolbarRight = new DockItemToolbar (this, PositionType.Right);
203
default: throw new ArgumentException ();
207
internal bool HasWidget {
208
get { return widget != null; }
211
public string DefaultLocation {
212
get { return defaultLocation; }
213
set { defaultLocation = value; }
216
public bool DefaultVisible {
217
get { return defaultVisible; }
218
set { defaultVisible = value; }
221
public DockItemStatus DefaultStatus {
222
get { return defaultStatus; }
223
set { defaultStatus = value; }
226
public int DefaultWidth {
231
defaultWidth = value;
235
public int DefaultHeight {
237
return defaultHeight;
240
defaultHeight = value;
244
public Gdk.Pixbuf Icon {
253
public DockItemBehavior Behavior {
260
widget.UpdateBehavior ();
273
public bool DrawFrame {
282
public void Present (bool giveFocus)
284
if (dockBarItem != null)
285
dockBarItem.Present (Status == DockItemStatus.AutoHide || giveFocus);
287
frame.Present (this, Status == DockItemStatus.AutoHide || giveFocus);
290
public bool ContentVisible {
294
return widget.Parent != null && widget.Visible;
298
public void SetDockLocation (string location)
300
frame.SetDockLocation (this, location);
303
internal void SetFocus ()
308
internal static void SetFocus (Widget w)
310
w.ChildFocus (DirectionType.Down);
312
Window win = w.Toplevel as Gtk.Window;
316
// Make sure focus is not given to internal children
317
if (win.Focus != null) {
318
Container c = win.Focus.Parent as Container;
319
if (c.Children.Length == 0)
324
internal void UpdateVisibleStatus ()
326
bool vis = frame.GetVisible (this);
327
if (vis != lastVisibleStatus) {
328
lastVisibleStatus = vis;
329
if (VisibleChanged != null)
330
VisibleChanged (this, EventArgs.Empty);
332
UpdateContentVisibleStatus ();
335
internal void UpdateContentVisibleStatus ()
337
bool vis = ContentVisible;
338
if (vis != lastContentVisibleStatus) {
339
lastContentVisibleStatus = vis;
340
if (ContentVisibleChanged != null)
341
ContentVisibleChanged (this, EventArgs.Empty);
345
internal void ShowWidget ()
347
if (floatingWindow != null)
348
floatingWindow.Show ();
349
if (dockBarItem != null)
354
internal void HideWidget ()
356
if (floatingWindow != null)
357
floatingWindow.Hide ();
358
else if (dockBarItem != null)
360
else if (widget != null)
364
internal void SetFloatMode (Gdk.Rectangle rect)
366
ResetBarUndockMode ();
367
if (floatingWindow == null) {
368
if (Widget.Parent != null)
370
floatingWindow = new Window (GetWindowTitle ());
371
floatingWindow.TransientFor = frame.Toplevel as Gtk.Window;
372
floatingWindow.TypeHint = Gdk.WindowTypeHint.Utility;
373
floatingWindow.Add (Widget);
374
floatingWindow.DeleteEvent += delegate (object o, DeleteEventArgs a) {
375
if (behavior == DockItemBehavior.CantClose)
376
Status = DockItemStatus.Dockable;
382
floatingWindow.Move (rect.X, rect.Y);
383
floatingWindow.Resize (rect.Width, rect.Height);
384
floatingWindow.Show ();
385
Widget.UpdateBehavior ();
389
internal void ResetFloatMode ()
391
if (floatingWindow != null) {
392
floatingWindow.Remove (Widget);
393
floatingWindow.Destroy ();
394
floatingWindow = null;
395
widget.UpdateBehavior ();
399
internal Gdk.Rectangle FloatingPosition {
401
if (floatingWindow != null) {
403
floatingWindow.GetPosition (out x, out y);
404
floatingWindow.GetSize (out w, out h);
405
return new Gdk.Rectangle (x,y,w,h);
408
return Gdk.Rectangle.Zero;
412
internal void ResetMode ()
415
ResetBarUndockMode ();
418
internal void SetAutoHideMode (Gtk.PositionType pos, int size)
421
if (widget != null) {
422
widget.Hide (); // Avoids size allocation warning
425
dockBarItem = frame.BarDock (pos, this, size);
427
widget.UpdateBehavior ();
430
void ResetBarUndockMode ()
432
if (dockBarItem != null) {
433
dockBarItem.Close ();
436
widget.UpdateBehavior ();
440
internal int AutoHideSize {
442
if (dockBarItem != null)
443
return dockBarItem.Size;
449
internal bool IsPositionMarker {
451
return isPositionMarker;
454
isPositionMarker = value;
458
string GetWindowTitle ()
460
if (Label.IndexOf ('<') == -1)
463
XmlDocument doc = new XmlDocument ();
464
doc.LoadXml ("<a>" + Label + "</a>");
465
return doc.InnerText;
471
internal void ShowDockPopupMenu (uint time)
473
Menu menu = new Menu ();
476
if ((Behavior & DockItemBehavior.CantClose) == 0) {
477
MenuItem mitem = new MenuItem (Catalog.GetString("Hide"));
478
mitem.Activated += delegate { Visible = false; };
485
citem = new CheckMenuItem (Catalog.GetString("Dockable"));
486
citem.Active = Status == DockItemStatus.Dockable;
487
citem.DrawAsRadio = true;
488
citem.Toggled += delegate { Status = DockItemStatus.Dockable; };
492
if ((Behavior & DockItemBehavior.NeverFloating) == 0) {
493
citem = new CheckMenuItem (Catalog.GetString("Floating"));
494
citem.Active = Status == DockItemStatus.Floating;
495
citem.DrawAsRadio = true;
496
citem.Toggled += delegate { Status = DockItemStatus.Floating; };
500
// Auto Hide menuitem
501
if ((Behavior & DockItemBehavior.CantAutoHide) == 0) {
502
citem = new CheckMenuItem (Catalog.GetString("Auto Hide"));
503
citem.Active = Status == DockItemStatus.AutoHide;
504
citem.DrawAsRadio = true;
505
citem.Toggled += delegate { Status = DockItemStatus.AutoHide; };
510
menu.Popup (null, null, null, 3, time);
514
public interface IDockItemLabelProvider
516
Gtk.Widget CreateLabel (Orientation orientation);