5
// Lluis Sanchez Gual <lluis@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
27
using MonoDevelop.Ide;
29
namespace MonoDevelop.Components
31
public class ImageButton: Gtk.EventBox
34
Gdk.Pixbuf inactiveImage;
35
Gtk.Image imageWidget;
36
bool hasInactiveImage;
42
Events |= Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask | Gdk.EventMask.ButtonReleaseMask;
43
VisibleWindow = false;
44
imageWidget = new Gtk.Image ();
49
public Gdk.Pixbuf Image {
53
Gdk.Pixbuf oldInactive = null;
54
if (!hasInactiveImage) {
55
oldInactive = inactiveImage;
56
inactiveImage = image != null ? ImageService.MakeTransparent (image, 0.5) : null;
59
if (oldInactive != null)
60
oldInactive.Dispose ();
64
public Gdk.Pixbuf InactiveImage {
65
get { return hasInactiveImage ? inactiveImage : null; }
67
if (!hasInactiveImage && inactiveImage != null)
68
inactiveImage.Dispose ();
69
hasInactiveImage = true;
70
inactiveImage = value;
75
protected override void OnDestroyed ()
77
if (!hasInactiveImage && inactiveImage != null)
78
inactiveImage.Dispose ();
86
imageWidget.Pixbuf = image;
88
imageWidget.Pixbuf = inactiveImage;
90
imageWidget.Pixbuf = null;
94
protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
98
return base.OnEnterNotifyEvent (evnt);
101
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
105
return base.OnLeaveNotifyEvent (evnt);
108
protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
110
pressed = image != null;
111
return base.OnButtonPressEvent (evnt);
114
protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
116
if (pressed && evnt.Button == 1 && new Gdk.Rectangle (0, 0, Allocation.Width, Allocation.Height).Contains ((int)evnt.X, (int)evnt.Y)) {
120
Clicked (this, EventArgs.Empty);
123
return base.OnButtonReleaseEvent (evnt);
126
public event EventHandler Clicked;