7
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using System.Collections.Generic;
34
namespace MonoDevelop.Components.DockToolbars
36
public class DockToolbar: Toolbar, IDockToolbar
39
DockToolbarFrame parentFrame;
41
FloatingDock floatingDock;
49
// Offset requested by the user. It is used to know where the
50
// toolbar is expected to move when the window is expanded.
54
DockToolbarPosition lastPosition;
55
DockToolbarStatus defaultStatus;
61
Dictionary<Gtk.Widget,int> calculatedSizes = new Dictionary<Gtk.Widget, int> ();
63
public DockToolbar (string id, string title)
65
grip = new DockGrip ();
73
internal void SetParentFrame (DockToolbarFrame frame)
87
public bool Floating {
88
get { return floatingDock != null; }
91
bool IDockToolbar.Visible {
92
get { return Parent != null; }
94
if (value == ((IDockToolbar)this).Visible)
98
if (lastPosition != null)
99
lastPosition.RestorePosition (parentFrame, this);
101
defaultStatus.Position.RestorePosition (parentFrame, this);
103
lastPosition = DockToolbarPosition.Create (this);
105
FloatingDock win = FloatingDock;
110
DockPanel.RemoveBar (this);
115
internal DockToolbarPosition Position {
117
if (((IDockToolbar)this).Visible) return DockToolbarPosition.Create (this);
118
else if (lastPosition != null) return lastPosition;
119
else return defaultStatus.Position;
123
internal DockToolbarStatus Status {
125
return new DockToolbarStatus (id, ((IDockToolbar)this).Visible, Position);
129
((IDockToolbar)this).Visible = false;
130
lastPosition = value.Position;
131
((IDockToolbar)this).Visible = true;
133
((IDockToolbar)this).Visible = false;
134
lastPosition = value.Position;
140
internal DockToolbarStatus DefaultStatus {
141
get { return defaultStatus; }
142
set { defaultStatus = value; }
145
internal int DockRow {
151
/// The current offset of the toolbar
153
internal int DockOffset {
154
get { return offset; }
155
set { offset = value; }
158
internal int DockShiftOffset {
159
get { return shiftOffset; }
160
set { shiftOffset = value; }
164
/// The ideal offset of the toolbar. It may not be the real offset if the
165
/// toolbar has been forced to move to make room for other toolbars
167
internal int AnchorOffset {
168
get { return anchorOffset; }
169
set { anchorOffset = value; }
172
internal int DefaultSize {
174
if (!gotSize) CalcSizes ();
179
public int DefaultHeight {
181
if (!gotSize) CalcSizes ();
182
return defaultHeight;
186
internal void CalcSizes ()
188
// Calculates the real size of the toolbar. ShowArrow=false is
189
// needed, since SizeRequest reports 0 size requested if not.
192
bool olda = ShowArrow;
193
int oldw = WidthRequest;
194
int oldh = HeightRequest;
199
Requisition r = SizeRequest ();
200
if (Orientation == Orientation.Horizontal) {
201
defaultSize = r.Width;
202
defaultHeight = r.Height;
205
defaultSize = r.Height;
206
defaultHeight = r.Width;
209
calculatedSizes.Clear ();
210
foreach (Widget w in Children) {
213
if (Orientation == Orientation.Horizontal)
214
calculatedSizes [w] = w.Allocation.Width;
216
calculatedSizes [w] = w.Allocation.Height;
220
HeightRequest = oldh;
226
internal bool CanDockTo (DockToolbarPanel panel)
231
internal FloatingDock FloatingDock {
232
get { return floatingDock; }
233
set { floatingDock = value; }
236
internal DockToolbarPanel DockPanel {
237
get { return Parent as DockToolbarPanel; }
240
internal Animation Animation {
241
get { return animation; }
242
set { animation = value; }
245
protected override bool OnButtonPressEvent (EventButton e)
247
if (parentFrame != null && e.Button == 1) {
248
if (Orientation == Orientation.Horizontal && e.X <= 10) {
250
parentFrame.StartDragBar (this, (int)e.X, (int)e.Y, e.Time);
253
else if (Orientation == Orientation.Vertical && e.Y <= 10) {
255
parentFrame.StartDragBar (this, (int)e.X, (int)e.Y, e.Time);
259
return base.OnButtonPressEvent (e);
262
protected override bool OnButtonReleaseEvent (EventButton e)
264
if (e.Button == 1 && dragging) {
266
parentFrame.EndDragBar (this, e.Time);
268
return base.OnButtonReleaseEvent (e);
271
/* protected override bool OnExposeEvent (EventExpose evnt)
273
//use the base class to paint the background like a toolbar, which may be a gradient
274
// but only if horizontal, else the gradient usually looks really ugly
275
if (this.Orientation == Orientation.Horizontal){
276
//the WIMP theme engine's rendering is a bit off, need to force it to render wider
277
int widen = MonoDevelop.Core.PropertyService.IsWindows? 1 : 0;
279
var shadowType = (ShadowType)StyleGetProperty ("shadow-type");
280
Style.PaintBox (Style, evnt.Window, State, shadowType, evnt.Area, this, "toolbar",
281
Allocation.X - widen, Allocation.Y, Allocation.Width + widen + widen, Allocation.Height);
283
//else we paint a plain flat background to make everything even - see DockToolbarPanel.OnExposeEvent
284
GdkWindow.DrawRectangle (Style.BackgroundGC (State), true, Allocation);
287
foreach (Widget child in Children) {
288
PropagateExpose (child, evnt);
295
protected override void OnRealized ()
298
if (!firstRealized) {
299
OnItemChange (null, null);
300
firstRealized = true;
305
internal void ResetSize ()
314
if (Orientation == Orientation.Horizontal) {
315
if (value >= DefaultSize)
318
WidthRequest = value;
321
if (value >= DefaultSize)
324
HeightRequest = value;
325
HeightRequest = value;
329
if (Orientation == Orientation.Horizontal)
330
return SizeRequest ().Width;
332
return SizeRequest ().Height;
336
public new Orientation Orientation {
338
return base.Orientation;
341
if (value == base.Orientation)
344
if (FloatingDock != null) {
345
// I create a new dock window because resizing the
346
// current one has lots of issues (mainly synchronization
347
// problems between the size change of the window and
351
FloatingDock w = FloatingDock;
352
w.GetPosition (out x, out y);
355
base.Orientation = value;
357
FloatingDock fdock = new FloatingDock (parentFrame);
362
base.Orientation = value;
367
protected override void OnAdded (Widget w)
371
if (DefaultSizeChanged != null)
372
DefaultSizeChanged (this, EventArgs.Empty);
373
w.Shown += OnItemChange;
374
w.Hidden += OnItemChange;
375
w.SizeAllocated += OnItemSizeChange;
378
protected override void OnRemoved (Widget w)
382
if (DefaultSizeChanged != null)
383
DefaultSizeChanged (this, EventArgs.Empty);
384
w.Shown -= OnItemChange;
385
w.Hidden -= OnItemChange;
386
w.SizeAllocated -= OnItemSizeChange;
389
void OnItemSizeChange (object o, SizeAllocatedArgs args)
391
if (gettingSize || !gotSize)
394
if (calculatedSizes.TryGetValue ((Gtk.Widget) o, out os)) {
395
int ns = (Orientation == Orientation.Horizontal ? args.Allocation.Width : args.Allocation.Height);
397
Gtk.Application.Invoke (delegate {
398
OnItemChange (null, null);
404
void OnItemChange (object o, EventArgs args)
406
// This notifies changes in the size of the toolbar
408
if (DefaultSizeChanged != null)
409
DefaultSizeChanged (this, EventArgs.Empty);
412
internal event EventHandler DefaultSizeChanged;