| 1 |
// -*- Mode: csharp; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|---|
| 2 |
|
|---|
| 3 |
using System; |
|---|
| 4 |
using System.Collections; |
|---|
| 5 |
using System.Collections.Generic; |
|---|
| 6 |
using System.Text; |
|---|
| 7 |
using Mono.Unix; |
|---|
| 8 |
using System.Runtime.InteropServices; |
|---|
| 9 |
|
|---|
| 10 |
namespace Sterling |
|---|
| 11 |
{ |
|---|
| 12 |
public enum PanelOrientation { Horizontal, Vertical }; |
|---|
| 13 |
|
|---|
| 14 |
public class SterlingSpringboard : Gtk.EventBox |
|---|
| 15 |
{ |
|---|
| 16 |
Gtk.Tooltips tips; |
|---|
| 17 |
Gtk.Image image; |
|---|
| 18 |
Gtk.Menu recent_menu; |
|---|
| 19 |
bool menu_added = false; |
|---|
| 20 |
int panel_size; |
|---|
| 21 |
|
|---|
| 22 |
public SterlingSpringboard (/* NoteManager manager */) |
|---|
| 23 |
: base () |
|---|
| 24 |
{ |
|---|
| 25 |
// this.manager = manager; |
|---|
| 26 |
// Load a 16x16-sized icon to ensure we don't end up with a |
|---|
| 27 |
// 1x1 pixel. |
|---|
| 28 |
panel_size = 16; |
|---|
| 29 |
this.image = new Gtk.Image (GuiUtils.GetIcon ("sterling", panel_size)); |
|---|
| 30 |
|
|---|
| 31 |
this.CanFocus = true; |
|---|
| 32 |
this.Add (image); |
|---|
| 33 |
this.ShowAll (); |
|---|
| 34 |
|
|---|
| 35 |
string tip_text = Catalog.GetString ("Sterling Accounting"); |
|---|
| 36 |
|
|---|
| 37 |
tips = new Gtk.Tooltips (); |
|---|
| 38 |
tips.SetTip (this, tip_text, null); |
|---|
| 39 |
tips.Enable (); |
|---|
| 40 |
tips.Sink (); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
void MenuHidden (object sender, EventArgs args) |
|---|
| 44 |
{ |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
bool MenuOpensUpward () |
|---|
| 48 |
{ |
|---|
| 49 |
int x, y; |
|---|
| 50 |
this.GdkWindow.GetOrigin (out x, out y); |
|---|
| 51 |
return y > 100; // FIXME: This can be better, I'm sure |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
// Used by SterlingApplet to modify the icon background. |
|---|
| 55 |
public Gtk.Image Image |
|---|
| 56 |
{ |
|---|
| 57 |
get |
|---|
| 58 |
{ |
|---|
| 59 |
return image; |
|---|
| 60 |
} |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
void InitPixbuf () |
|---|
| 64 |
{ |
|---|
| 65 |
// For some reason, the first time we ask for the allocation, |
|---|
| 66 |
// it's a 1x1 pixel. Prevent against this by returning a |
|---|
| 67 |
// reasonable default. Setting the icon causes OnSizeAllocated |
|---|
| 68 |
// to be called again anyhow. |
|---|
| 69 |
|
|---|
| 70 |
if (panel_size < 16) |
|---|
| 71 |
panel_size = 16; |
|---|
| 72 |
|
|---|
| 73 |
// Control specifically which icon is used at the smaller sizes |
|---|
| 74 |
// so that no scaling occurs. In the case of the panel applet, |
|---|
| 75 |
// add a couple extra pixels of padding so it matches the behavior |
|---|
| 76 |
// of the notification area tray icon. |
|---|
| 77 |
|
|---|
| 78 |
int icon_size = panel_size; |
|---|
| 79 |
|
|---|
| 80 |
if (Sterling.IsPanelApplet) |
|---|
| 81 |
icon_size = panel_size - 2; // padding |
|---|
| 82 |
if (icon_size <= 21) |
|---|
| 83 |
icon_size = 16; |
|---|
| 84 |
else if (icon_size <= 31) |
|---|
| 85 |
icon_size = 22; |
|---|
| 86 |
else if (icon_size <= 47) |
|---|
| 87 |
icon_size = 32; |
|---|
| 88 |
|
|---|
| 89 |
Gdk.Pixbuf new_icon = GuiUtils.GetIcon ("sterling", icon_size); |
|---|
| 90 |
image.Pixbuf = new_icon; |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
/// |
|---|
| 94 |
/// Determine whether the springboard is inside a horizontal or vertical |
|---|
| 95 |
/// panel so the size of the icon can adjust correctly. |
|---|
| 96 |
/// |
|---|
| 97 |
PanelOrientation GetPanelOrientation () |
|---|
| 98 |
{ |
|---|
| 99 |
if (this.ParentWindow == null) |
|---|
| 100 |
return PanelOrientation.Horizontal; |
|---|
| 101 |
|
|---|
| 102 |
Gdk.Window top_level_window = this.ParentWindow.Toplevel; |
|---|
| 103 |
Gdk.Rectangle rect = top_level_window.FrameExtents; |
|---|
| 104 |
|
|---|
| 105 |
if (rect.Width < rect.Height) |
|---|
| 106 |
return PanelOrientation.Vertical; |
|---|
| 107 |
|
|---|
| 108 |
return PanelOrientation.Horizontal; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
protected override void OnSizeAllocated (Gdk.Rectangle rect) |
|---|
| 112 |
{ |
|---|
| 113 |
base.OnSizeAllocated (rect); |
|---|
| 114 |
|
|---|
| 115 |
// Determine the orientation |
|---|
| 116 |
|
|---|
| 117 |
if (GetPanelOrientation () == PanelOrientation.Horizontal) |
|---|
| 118 |
{ |
|---|
| 119 |
if (panel_size == Allocation.Height) |
|---|
| 120 |
return; |
|---|
| 121 |
|
|---|
| 122 |
panel_size = Allocation.Height; |
|---|
| 123 |
} |
|---|
| 124 |
else |
|---|
| 125 |
{ |
|---|
| 126 |
if (panel_size == Allocation.Width) |
|---|
| 127 |
return; |
|---|
| 128 |
|
|---|
| 129 |
panel_size = Allocation.Width; |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
InitPixbuf (); |
|---|
| 133 |
} |
|---|
| 134 |
} |
|---|
| 135 |
} |
|---|