Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: fc43e5c4e4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 159 lines (133 sloc) 3.861 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
using System;
using System.Collections.Generic;
using Gtk;
using Cairo;

namespace Ribbons
{
/// <summary>
/// Displays several widgets (typical shortcuts to common functionalities) next to the application button.
/// </summary>
public class QuickAccessToolbar : Container
{
private List<Widget> widgets;
private List<KeyTip> keyTips;
private int[] widths;
private Theme theme = Theme.DefaultTheme;

public QuickAccessToolbar()
{
// This is a No Window widget => it does not have its own Gdk Window => it can be transparent
this.SetFlag (WidgetFlags.NoWindow);

this.AddEvents ((int)(Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask));

this.widgets = new List<Widget> ();
this.keyTips = new List<KeyTip> ();
}

/// <summary>Adds a widget before all existing widgets.</summary>
/// <param name="w">The widget to add.</param>
public void Prepend (Widget w)
{
Insert (w, 0);
}

/// <summary>Adds a widget after all existing widgets.</summary>
/// <param name="w">The widget to add.</param>
public void Append (Widget w)
{
Insert (w, -1);
}

/// <summary>Inserts a widget at the specified location.</summary>
/// <param name="w">The widget to add.</param>
/// <param name="WidgetIndex">The index (starting at 0) at which the widget must be inserted, or -1 to insert the widget after all existing widgets.</param>
public void Insert (Widget w, int WidgetIndex)
{
w.Parent = this;
w.Visible = true;

if(WidgetIndex == -1)
widgets.Add (w);
else
widgets.Insert (WidgetIndex, w);

ShowAll ();
}

/// <summary>Removes the widget at the specified index.</summary>
/// <param name="WidgetIndex">Index of the widget to remove.</param>
public void Remove (int WidgetIndex)
{
if(WidgetIndex == -1) WidgetIndex = widgets.Count - 1;

widgets[WidgetIndex].Parent = null;
widgets.RemoveAt (WidgetIndex);

ShowAll ();
}

public void AddKeyTip (KeyTip kt)
{
keyTips.Add (kt);
}

public void RemoveKeyTip (KeyTip kt)
{
keyTips.Remove (kt);
}

public void ClearKeyTips ()
{
keyTips.Clear ();
}

protected override void ForAll (bool include_internals, Callback callback)
{
foreach(Widget w in widgets)
{
if(w.Visible) callback (w);
}
}

protected override void OnSizeRequested (ref Requisition requisition)
{
base.OnSizeRequested (ref requisition);

if(widths == null || widths.Length != widgets.Count)
{
widths = new int[widgets.Count];
}

requisition.Height = 16;
requisition.Width = 0;

int i = 0;
foreach(BaseButton b in widgets)
{
//b.HeightRequest = requisition.Height;
Gtk.Requisition req = b.SizeRequest ();
if(req.Height > requisition.Height) requisition.Height = req.Height;
requisition.Width += req.Width;
widths[i++] = req.Width;
}
if(HeightRequest != -1) requisition.Height = HeightRequest;
if(WidthRequest != -1) requisition.Width = WidthRequest;
}

protected override void OnSizeAllocated (Gdk.Rectangle allocation)
{
base.OnSizeAllocated (allocation);

int i = 0, x = allocation.X;
foreach(BaseButton b in widgets)
{
Gdk.Rectangle r;
r.X = x;
r.Y = allocation.Y;
r.Width = widths[i];
r.Height = allocation.Height;
b.SizeAllocate (r);
x += r.Width;
++i;
}
}

public void ShowKeyTips ()
{
int x, y;
GdkWindow.GetOrigin (out x, out y);
int lineY = y + Allocation.Y + (int)(0.66666 * Allocation.Height);

foreach(KeyTip kt in keyTips)
{
Gdk.Rectangle alloc = kt.Target.Allocation;
kt.ShowAt (x + alloc.X + (alloc.Width >> 1), lineY, 0.5, 0.0);
}
}

public void HideKeyTips ()
{
foreach(KeyTip kt in keyTips)
{
kt.Hide ();
}
}
}
}
Something went wrong with that request. Please try again.