~ubuntu-branches/debian/sid/f-spot/sid

« back to all changes in this revision

Viewing changes to lib/Hyena/src/Hyena.Gui/Hyena.Widgets/MenuButton.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-24 10:35:57 UTC
  • mfrom: (2.4.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20100524103557-1j0i8f66caybci2n
* New upstream release 0.7.0
 + First release of the unstable 0.7 development series. Massive changes.
 + Reparenting and detaching support (Anton Keks) (Closes: #559745)
 + A new Mallard-based documentation (Harold Schreckengost)
 + No longer embeds flickrnet, uses distribution copy (Iain Lane)
 + Adoption of a large amount of Hyena functionality (Paul Lange, Peter
   Goetz)
 + No longer embeds gnome-keyring-sharp
 + Completely rewritten import, much faster and less memory hungry (Ruben
   Vermeersch) (Closes: #559080, #492658, #341790, #357811, #426017) (LP:
   #412091)
 + No longer use gphoto2-sharp, now uses gvfs which is less crash-pron
   (Ruben Vermeersch)
 + Fix Facebook support (Ruben Vermeersch)
 + Modernized unit tests
 + Revamped build (Mike Gemünde)
 + Much improved duplicate detection (much faster too) (Ruben Vermeersch)
 + Mouse selection in Iconview (Vincent Pomey)
 + Image panning support using middle mouse button (Wojciech Dzierżanowski)
 + Timeline slider now restricted to the size of the window (Iain Churcher)
 + Over 100 bugs closed (http://bit.ly/cyVjnD)
   - No more warnings about schema defaults (Closes: #584215) (LP: #586132)
* debian/control: Clean up build deps to match configure checks
* debian/rules: Don't run dh_makeshilbs as we don't ship any shared
  libraries. There are some private ones though, which get picked up and
  result in a useless postinst/postrm call to ldconfig. Thanks, lintian.
* debian/patches/debian_fix-distclean.patch,
  debian/patches/debian_fix_f-spot.exe.config.patch,
  debian/patches/debian_link-system-flickrnet.patch,
  debian/patches/debian_link-system-gnome-keyring.patch,
  debian/patches/debian_disable-unit-tests,
  debian/patches/git_transition_duration.patch,
  debian/patches/ubuntu_fix_folder_export_hang.patch:
  Clean up obsolete patches which are no longer necessary 
* debian/patches/*: Temporarily disable patches which originated from Ubuntu
  and no longer apply cleanly. We will get these back in a future upstream
  development release.
* debian/patches/*: Refresh to apply cleanly 
* debian/rules: Add new include dir to autoreconf call to pick up f-spot
  macros 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// MenuButton.cs
 
3
//
 
4
// Author:
 
5
//   Scott Peterson <lunchtimemama@gmail.com>
 
6
//
 
7
// Copyright (c) 2008 Scott Peterson
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
//
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
//
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
//
 
27
 
 
28
using System;
 
29
using Gtk;
 
30
using Gdk;
 
31
 
 
32
namespace Hyena.Widgets
 
33
{
 
34
    public class MenuButton : Container
 
35
    {
 
36
        private ToggleButton toggle_button = new ToggleButton ();
 
37
        private HBox box = new HBox ();
 
38
        private Alignment alignment;
 
39
        private Arrow arrow;
 
40
        private Widget button_widget;
 
41
        private Menu menu;
 
42
        private Widget size_widget;
 
43
 
 
44
        protected MenuButton (IntPtr ptr) : base (ptr) {}
 
45
 
 
46
        public MenuButton ()
 
47
        {
 
48
        }
 
49
 
 
50
        public MenuButton (Widget buttonWidget, Menu menu, bool showArrow)
 
51
        {
 
52
            Construct (buttonWidget, menu, showArrow);
 
53
        }
 
54
 
 
55
        protected void Construct (Widget buttonWidget, Menu menu, bool showArrow)
 
56
        {
 
57
            WidgetFlags |= WidgetFlags.NoWindow;
 
58
 
 
59
            button_widget = buttonWidget;
 
60
            Menu = menu;
 
61
 
 
62
            toggle_button.Parent = this;
 
63
            toggle_button.FocusOnClick = false;
 
64
            toggle_button.Relief = ReliefStyle.None;
 
65
            toggle_button.Pressed += delegate { ShowMenu (); toggle_button.Active = true; };
 
66
            toggle_button.Activated += delegate { ShowMenu (); };
 
67
 
 
68
            box.Parent = this;
 
69
 
 
70
            if (showArrow) {
 
71
                box.PackStart (button_widget, true, true, 0);
 
72
                alignment = new Alignment (0f, 0.5f, 0f, 0f);
 
73
                arrow = new Arrow (ArrowType.Down, ShadowType.None);
 
74
                alignment.Add (arrow);
 
75
                box.PackStart (alignment, false, false, 5);
 
76
                size_widget = box;
 
77
                FocusChain = new Widget[] {toggle_button, box};
 
78
            } else {
 
79
                toggle_button.Add (button_widget);
 
80
                size_widget = toggle_button;
 
81
            }
 
82
 
 
83
            ShowAll ();
 
84
        }
 
85
 
 
86
        public Widget ButtonWidget {
 
87
            get { return button_widget; }
 
88
        }
 
89
 
 
90
        public Menu Menu {
 
91
            get { return menu; }
 
92
            set {
 
93
                if (menu == value)
 
94
                    return;
 
95
 
 
96
                if (menu != null)
 
97
                    menu.Deactivated -= OnMenuDeactivated;
 
98
 
 
99
                menu = value;
 
100
                menu.Deactivated += OnMenuDeactivated;
 
101
            }
 
102
        }
 
103
 
 
104
        private void OnMenuDeactivated (object o, EventArgs args)
 
105
        {
 
106
            toggle_button.Active = false;
 
107
        }
 
108
 
 
109
        public ToggleButton ToggleButton {
 
110
            get { return toggle_button; }
 
111
        }
 
112
 
 
113
        public Arrow Arrow {
 
114
            get { return arrow; }
 
115
        }
 
116
 
 
117
        protected override void OnSizeRequested (ref Requisition requisition)
 
118
        {
 
119
            requisition = size_widget.SizeRequest ();
 
120
        }
 
121
 
 
122
        protected override void OnSizeAllocated (Rectangle allocation)
 
123
        {
 
124
            box.SizeAllocate (allocation);
 
125
            toggle_button.SizeAllocate (allocation);
 
126
            base.OnSizeAllocated (allocation);
 
127
        }
 
128
 
 
129
        protected override void ForAll (bool include_internals, Callback callback)
 
130
        {
 
131
            callback (toggle_button);
 
132
            callback (box);
 
133
        }
 
134
 
 
135
        protected override void OnAdded (Widget widget)
 
136
        {
 
137
        }
 
138
 
 
139
        protected override void OnRemoved (Widget widget)
 
140
        {
 
141
        }
 
142
 
 
143
        protected void ShowMenu ()
 
144
        {
 
145
            menu.Popup (null, null, PositionMenu, 1, Gtk.Global.CurrentEventTime);
 
146
        }
 
147
 
 
148
        private void PositionMenu (Menu menu, out int x, out int y, out bool push_in)
 
149
        {
 
150
            Gtk.Requisition menu_req = menu.SizeRequest ();
 
151
            int monitor_num = Screen.GetMonitorAtWindow (GdkWindow);
 
152
            Gdk.Rectangle monitor = Screen.GetMonitorGeometry (monitor_num < 0 ? 0 : monitor_num);
 
153
 
 
154
            GdkWindow.GetOrigin (out x, out y);
 
155
 
 
156
            y += Allocation.Y;
 
157
            x += Allocation.X + (Direction == TextDirection.Ltr
 
158
                ? Math.Max (Allocation.Width - menu_req.Width, 0)
 
159
                : - (menu_req.Width - Allocation.Width));
 
160
 
 
161
            if (y + Allocation.Height + menu_req.Height <= monitor.Y + monitor.Height) {
 
162
                y += Allocation.Height;
 
163
            } else if (y - menu_req.Height >= monitor.Y) {
 
164
                y -= menu_req.Height;
 
165
            } else if (monitor.Y + monitor.Height - (y + Allocation.Height) > y) {
 
166
                y += Allocation.Height;
 
167
            } else {
 
168
                y -= menu_req.Height;
 
169
            }
 
170
 
 
171
            push_in = false;
 
172
        }
 
173
    }
 
174
}