5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.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
30
namespace MonoDevelop.Components
32
public class MiniButton: Gtk.EventBox
34
public event EventHandler Clicked;
35
Gdk.Color normalColor;
41
Events |= Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask;
44
public MiniButton (Gtk.Widget label): this ()
50
public bool ToggleMode { get; set; }
57
if (ToggleMode && pressed != value) {
59
SetBg (value || highligted);
64
protected virtual void OnClicked ()
69
Clicked (this, EventArgs.Empty);
72
protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
76
return base.OnButtonPressEvent (evnt);
79
protected override void OnRealized ()
82
normalColor = Style.Background (Gtk.StateType.Normal);
85
protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
88
if (!ToggleMode || !pressed)
90
return base.OnEnterNotifyEvent (evnt);
93
protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
96
if (!ToggleMode || !pressed)
98
return base.OnLeaveNotifyEvent (evnt);
101
void SetBg (bool hilight)
104
ModifyBg (StateType.Normal, Style.Base (Gtk.StateType.Normal));
106
ModifyBg (StateType.Normal, normalColor);