~ubuntu-branches/ubuntu/precise/gnome-do/precise-backports

« back to all changes in this revision

Viewing changes to Do.Interface.Linux.Docky/src/Docky.Interface/DockPopupMenu.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers, Christopher James Halse Rogers, Iain Lane
  • Date: 2009-02-04 15:30:25 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090204153025-dhb2pm7dgbtmoib6
Tags: 0.8.0-1~ubuntu1
[ Christopher James Halse Rogers ]
* New upstream release.  (LP: #323048)
  + Fixes text input problems (LP: #288517)
  + No longer grabs plugins from internet repositories (LP: #294808)
  + Preferences dialog is resizable (LP: #305419)
* Build against gtk, gnome mono packages from Experimental. (Closes: #510836)
* debian/control:
  + Bump versioned dep on libgtk2.0-cil to ensure
    Gdk.Screen.IsComposited exists (Closes: #510973)
  + Add libwnck2.20-cil build-dep
  + gnome-sharp2 transition.
* debian/patches/04_fix_locale_dir
* debian/patches/05_fix_localised_theme_setting
* debian/patches/06_expand_homedir_in_open
  + Drop; fixed in new upstream  
* debian/patches/02_use_cli_for_wrapper
  + Update for new upstream
  + Add dpatch comments
* debian/gnome-do.1
  + Fix broken formatting (LP: #291654).  Thank you to Frédéric Grosshans
    for spotting it, and the patch.
  + Update for new version.

[ Iain Lane ]
* Tag pkg-cli-apps SVN revision into Jaunty, to get in before Feature
  Freeze. Should be a sync after the next Debian upload.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// DockPopupMenu.cs
 
2
// 
 
3
// Copyright (C) 2008 GNOME Do
 
4
//
 
5
// This program is free software: you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation, either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
//
 
18
 
 
19
using System;
 
20
using System.Collections.Generic;
 
21
using System.Linq;
 
22
 
 
23
using Cairo;
 
24
using Gdk;
 
25
using Gtk;
 
26
 
 
27
using Do.Interface;
 
28
using Do.Interface.CairoUtils;
 
29
using Do.Platform;
 
30
 
 
31
using Docky.Utilities;
 
32
 
 
33
namespace Docky.Interface
 
34
{
 
35
        
 
36
        
 
37
        public class DockPopupMenu : Gtk.Window
 
38
        {
 
39
                const int TailHeight = 25;
 
40
                new const int BorderWidth = 2;
 
41
                const int Radius = 10;
 
42
                const int Width = 230;
 
43
                const int TailOffset = 2;
 
44
                const double Pointiness = 2;
 
45
                const double BaseCurviness = 1.2;
 
46
                const double TailCurviness = .8;
 
47
                
 
48
                int horizontal_offset;
 
49
                
 
50
                public Gtk.VBox Container { get; private set; } 
 
51
                
 
52
                public DockPopupMenu() : base (Gtk.WindowType.Popup)
 
53
                {
 
54
                        Decorated = false;
 
55
                        KeepAbove = true;
 
56
                        AppPaintable = true;
 
57
                        SkipPagerHint = true;
 
58
                        SkipTaskbarHint = true;
 
59
                        Resizable = false;
 
60
                        Modal = true;
 
61
                        TypeHint = WindowTypeHint.PopupMenu;
 
62
                        
 
63
                        WidthRequest = Width;
 
64
                        
 
65
                        this.SetCompositeColormap ();
 
66
                        
 
67
                        AddEvents ((int) EventMask.PointerMotionMask | 
 
68
                                   (int) EventMask.LeaveNotifyMask |
 
69
                                   (int) EventMask.ButtonPressMask | 
 
70
                                   (int) EventMask.ButtonReleaseMask |
 
71
                                   (int) EventMask.FocusChangeMask);
 
72
                        
 
73
                        Container = new Gtk.VBox ();
 
74
                        Build ();
 
75
                }
 
76
                
 
77
                protected virtual void Build ()
 
78
                {
 
79
                        VBox space = new VBox ();
 
80
                        space.Add (Container);
 
81
                        space.Add (new Label (" "));
 
82
                        Container.BorderWidth = 5;
 
83
                        Add (space);
 
84
                        space.ShowAll ();
 
85
                }
 
86
 
 
87
                
 
88
                public virtual void PopUp (IEnumerable<AbstractMenuButtonArgs> args, int x, int y)
 
89
                {
 
90
                        ShowAll ();
 
91
                        Gdk.Rectangle geo = LayoutUtils.MonitorGemonetry ();
 
92
                        Gtk.Requisition req = SizeRequest ();
 
93
                        
 
94
                        int posx = Math.Min (Math.Max (0, x - req.Width / TailOffset), geo.X + geo.Width - req.Width);
 
95
                        horizontal_offset = (x - req.Width / TailOffset) - posx;
 
96
                        Move (posx, y - req.Height);
 
97
                        
 
98
                        Do.Interface.Windowing.PresentWindow (this);
 
99
                }
 
100
                
 
101
                protected override bool OnExposeEvent (Gdk.EventExpose evnt)
 
102
                {
 
103
                        using (Context cr = Gdk.CairoHelper.Create (GdkWindow)) {
 
104
                                cr.AlphaFill ();
 
105
                                DrawBackground (cr);
 
106
                        }
 
107
                        
 
108
                        return base.OnExposeEvent (evnt);
 
109
                }
 
110
                
 
111
                protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
 
112
                {
 
113
                        Gdk.Rectangle rect;
 
114
                        GetSize (out rect.Width, out rect.Height);
 
115
                        
 
116
                        if (evnt.X < 0 || evnt.Y < 0 || evnt.X > rect.Width || evnt.Y > rect.Height)
 
117
                                Hide ();
 
118
                        return base.OnButtonReleaseEvent (evnt);
 
119
                }
 
120
                
 
121
                protected override bool OnKeyReleaseEvent (Gdk.EventKey evnt)
 
122
                {
 
123
                        if (evnt.Key == Gdk.Key.Escape)
 
124
                                Hide ();
 
125
                        return base.OnKeyReleaseEvent (evnt);
 
126
                }
 
127
 
 
128
 
 
129
                void DrawBackground (Context cr)
 
130
                {
 
131
                        Gdk.Rectangle rect;
 
132
                        GetSize (out rect.Width, out rect.Height);
 
133
                        
 
134
                        cr.MoveTo (BorderWidth + Radius, BorderWidth);
 
135
                        cr.Arc (rect.Width - BorderWidth - Radius, BorderWidth + Radius, Radius, Math.PI * 1.5, Math.PI * 2);
 
136
 
 
137
                        Cairo.PointD rightCurveStart = new Cairo.PointD (rect.Width - BorderWidth, rect.Height - BorderWidth - TailHeight);
 
138
                        Cairo.PointD leftCurveStart = new Cairo.PointD (BorderWidth, rect.Height - BorderWidth - TailHeight);
 
139
                        Cairo.PointD apex = new Cairo.PointD (rect.Width / 2 + horizontal_offset, rect.Height - BorderWidth);
 
140
                        cr.LineTo (rightCurveStart);
 
141
                        
 
142
                        cr.CurveTo (rightCurveStart.X, rightCurveStart.Y + TailHeight * BaseCurviness, 
 
143
                                    apex.X + 10 * Pointiness, apex.Y - TailHeight * TailCurviness, 
 
144
                                    apex.X, apex.Y);
 
145
                        
 
146
                        cr.CurveTo (apex.X - 10 * Pointiness, 
 
147
                                    apex.Y - TailHeight * TailCurviness, 
 
148
                                    leftCurveStart.X, leftCurveStart.Y + TailHeight * BaseCurviness, 
 
149
                                    leftCurveStart.X, leftCurveStart.Y);
 
150
                        
 
151
                        cr.Arc (BorderWidth + Radius, BorderWidth + Radius, Radius, Math.PI, Math.PI * 1.5);
 
152
                        
 
153
                        cr.Color = new Cairo.Color (0.1, 0.1, 0.1, .9);
 
154
                        cr.FillPreserve ();
 
155
                        
 
156
                        cr.Color = new Cairo.Color (.2, .2, .2, .8);
 
157
                        cr.Stroke ();
 
158
                }
 
159
        }
 
160
}