1
/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
3
* Copyright (C) 2012 Canonical Ltd
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.
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.
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/>.
17
* Authors: Michael Terry <michael.terry@canonical.com>
20
public class ToggleBox : Gtk.Box
22
public string default_key {get; construct;}
23
public string starting_key {get; construct;}
24
public string selected_key {get; protected set;}
26
public ToggleBox (string? default_key, string? starting_key)
28
Object (default_key: default_key, starting_key: starting_key,
29
selected_key: starting_key);
32
public void add_item (string key, string label, Gdk.Pixbuf? icon)
34
var item = make_button (key, label, icon);
36
if (get_children () == null ||
37
(starting_key == null && default_key == key) ||
45
private Gtk.Button selected_button;
49
orientation = Gtk.Orientation.VERTICAL;
52
public override bool draw (Cairo.Context c)
54
Gtk.Allocation allocation;
55
get_allocation (out allocation);
57
DashBox.cairo_rounded_rectangle (c, 0, 0, allocation.width,
58
allocation.height, 0.1 * grid_size);
59
c.set_source_rgba (0.5, 0.5, 0.5, 0.5);
66
private void select (Gtk.Button button)
68
if (selected_button != null)
69
selected_button.relief = Gtk.ReliefStyle.NONE;
70
selected_button = button;
71
selected_button.relief = Gtk.ReliefStyle.NORMAL;
72
selected_key = selected_button.get_data<string> ("toggle-list-key");
75
private Gtk.Button make_button (string key, string name_in, Gdk.Pixbuf? icon)
77
var item = new FlatButton ();
78
item.relief = Gtk.ReliefStyle.NONE;
79
item.clicked.connect (button_clicked_cb);
81
var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
85
var image = new CachedImage (icon);
86
hbox.pack_start (image, false, false, 0);
90
if (key == default_key)
92
/* Translators: %s is a session name like KDE or Ubuntu */
93
name = _("%s (Default)").printf (name);
96
var label = new Gtk.Label (null);
97
label.set_markup ("<span font=\"Ubuntu 13\">%s</span>".printf (name));
98
label.halign = Gtk.Align.START;
99
hbox.pack_start (label, true, true, 0);
107
/* Tighten padding on buttons to not be so large */
108
var style = new Gtk.CssProvider ();
109
style.load_from_data ("* {padding: 8px;}", -1);
110
item.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
114
debug ("Internal error loading session chooser style: %s", e.message);
117
item.set_data<string> ("toggle-list-key", key);
121
private void button_clicked_cb (Gtk.Button button)
123
selected_key = button.get_data<string> ("toggle-list-key");
126
public override void grab_focus ()
128
if (selected_button != null)
129
selected_button.grab_focus ();