~ubuntu-branches/ubuntu/utopic/unity-greeter/utopic

« back to all changes in this revision

Viewing changes to src/flat-button.vala

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2013-01-04 10:37:29 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: package-import@ubuntu.com-20130104103729-ydal31wfuhirb8zb
Tags: upstream-13.04.0
ImportĀ upstreamĀ versionĀ 13.04.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
 *
 
3
 * Copyright (C) 2012 Canonical Ltd
 
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 version 3 as
 
7
 * published by the Free Software Foundation.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Authors: Michael Terry <michael.terry@canonical.com>
 
18
 */
 
19
 
 
20
public class FlatButton : Gtk.Button
 
21
{
 
22
    private bool did_press;
 
23
 
 
24
    construct
 
25
    {
 
26
        UnityGreeter.add_style_class (this);
 
27
        try
 
28
        {
 
29
            var style = new Gtk.CssProvider ();
 
30
            style.load_from_data ("* {-GtkButton-child-displacement-x: 0px;
 
31
                                      -GtkButton-child-displacement-y: 0px;
 
32
                                      -GtkWidget-focus-line-width: 1px;
 
33
                                      }", -1);
 
34
            get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
 
35
        }
 
36
        catch (Error e)
 
37
        {
 
38
            debug ("Internal error loading session chooser style: %s", e.message);
 
39
        }
 
40
    }
 
41
 
 
42
    public override bool draw (Cairo.Context c)
 
43
    {
 
44
        // Make sure we don't react to mouse hovers
 
45
        unset_state_flags (Gtk.StateFlags.PRELIGHT);
 
46
        return base.draw (c);
 
47
    }
 
48
 
 
49
    public override void pressed ()
 
50
    {
 
51
        // Do nothing.  The normal handler sets priv->button_down which
 
52
        // internally causes draw() to draw a special border and background
 
53
        // that we don't want.
 
54
        did_press = true;
 
55
    }
 
56
 
 
57
    public override void released ()
 
58
    {
 
59
        if (did_press)
 
60
        {
 
61
            base.pressed (); // fake an insta-click
 
62
            did_press = false;
 
63
        }
 
64
        base.released ();
 
65
    }
 
66
}