~ubuntu-branches/ubuntu/lucid/monodevelop/lucid

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Components/MonoDevelop.Components/MiniButton.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-02-02 11:39:59 UTC
  • mfrom: (1.2.6 upstream) (1.3.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100202113959-s4exdz7er7igylz2
Tags: 2.2.1+dfsg-1
* New upstream release
* debian/control:
  + Standards version 3.8.4 (no changes needed)
* debian/patches/remove_support_for_non_debian_functionality.patch,
  debian/patches/remove_support_for_soft_debugger.patch,
  debian/patches/remove_support_for_moonlight.patch,
  debian/rules:
  + Split patch into two pieces, to make it easier to enable either
    SDB or Moonlight support with a rebuild
* debian/monodevelop-moonlight.install,
  debian/monodevelop-debugger-sdb.install,
  debian/control:
  + Create packaging data for the Soft Debugger addin and Moonlight addin -
    and comment them out of debian/control as we can't provide them on
    Debian for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// MiniButton.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
 
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
using System;
 
28
using Gtk;
 
29
 
 
30
namespace MonoDevelop.Components
 
31
{
 
32
        public class MiniButton: Gtk.EventBox
 
33
        {
 
34
                public event EventHandler Clicked;
 
35
                Gdk.Color normalColor;
 
36
                bool pressed;
 
37
                bool highligted;
 
38
                
 
39
                public MiniButton ()
 
40
                {
 
41
                        Events |= Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask;
 
42
                }
 
43
                
 
44
                public MiniButton (Gtk.Widget label): this ()
 
45
                {
 
46
                        Add (label);
 
47
                        label.Show ();
 
48
                }
 
49
                
 
50
                public bool ToggleMode { get; set; }
 
51
                
 
52
                public bool Pressed {
 
53
                        get {
 
54
                                return pressed;
 
55
                        }
 
56
                        set {
 
57
                                if (ToggleMode && pressed != value) {
 
58
                                        pressed = value;
 
59
                                        SetBg (value || highligted);
 
60
                                }
 
61
                        }
 
62
                }
 
63
                
 
64
                protected virtual void OnClicked ()
 
65
                {
 
66
                        if (ToggleMode)
 
67
                                Pressed = !pressed;
 
68
                        if (Clicked != null)
 
69
                                Clicked (this, EventArgs.Empty);
 
70
                }
 
71
                
 
72
                protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
 
73
                {
 
74
                        if (evnt.Button == 1)
 
75
                                OnClicked ();
 
76
                        return base.OnButtonPressEvent (evnt);
 
77
                }
 
78
                
 
79
                protected override void OnRealized ()
 
80
                {
 
81
                        base.OnRealized ();
 
82
                        normalColor = Style.Background (Gtk.StateType.Normal);
 
83
                }
 
84
                
 
85
                protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
 
86
                {
 
87
                        highligted = true;
 
88
                        if (!ToggleMode || !pressed)
 
89
                                SetBg (true);
 
90
                        return base.OnEnterNotifyEvent (evnt);
 
91
                }
 
92
                
 
93
                protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
 
94
                {
 
95
                        highligted = false;
 
96
                        if (!ToggleMode || !pressed)
 
97
                                SetBg (false);
 
98
                        return base.OnLeaveNotifyEvent (evnt);
 
99
                }
 
100
                
 
101
                void SetBg (bool hilight)
 
102
                {
 
103
                        if (hilight)
 
104
                                ModifyBg (StateType.Normal, Style.Base (Gtk.StateType.Normal));
 
105
                        else
 
106
                                ModifyBg (StateType.Normal, normalColor);
 
107
                }
 
108
        }
 
109
}