track-color chooser works
[ardour.git] / libs / gtkmm2ext / choice.cc
1 /*
2     Copyright (C) 1998-99 Paul Barton-Davis
3  
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
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, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #include <gtkmm2ext/choice.h>
22
23 using namespace std;
24 using namespace Gtkmm2ext;
25 using namespace sigc;
26 using namespace Gtk;
27
28 Choice::Choice (string prompt,
29                 vector<string> choices)
30         : Gtk::Window (WINDOW_TOPLEVEL),
31           prompt_label (prompt)
32 {
33         int n;
34         vector<string>::iterator i;
35
36         set_position (Gtk::WIN_POS_CENTER);
37         set_name ("ChoiceWindow");
38         add (packer);
39         
40         packer.set_spacing (10);
41         packer.set_border_width (10);
42         packer.pack_start (prompt_label);
43         packer.pack_start (button_packer);
44         prompt_label.set_name ("ChoicePrompt");
45         
46         for (n = 0, i = choices.begin(); i != choices.end(); ++i, ++n) {
47                 Button *button = manage (new Gtk::Button (*i));
48                 button->set_name ("ChoiceButton");
49
50                 button_packer.set_spacing (5);
51                 button_packer.set_homogeneous (true);
52                 button_packer.pack_start (*button, false, true);
53
54                 button->signal_clicked().connect (bind (mem_fun (*this, &Choice::_choice_made), n));
55                 buttons.push_back (button);
56         }
57
58         signal_delete_event().connect(mem_fun(*this, &Choice::closed));
59
60         packer.show_all ();
61         which_choice = -1;
62 }
63
64 void
65 Choice::on_realize ()
66 {
67         Gtk::Window::on_realize();
68         get_window()->set_decorations (Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH));
69 }
70
71 Choice::~Choice ()
72 {
73 }
74
75 void
76 Choice::_choice_made (int nbutton)
77 {
78         which_choice = nbutton;
79         choice_made (which_choice);
80         chosen ();
81 }
82
83 gint
84 Choice::closed (GdkEventAny *ev)
85 {
86         which_choice = -1;
87         choice_made (which_choice);
88         chosen ();
89         return TRUE;
90 }
91
92 int
93 Choice::get_choice ()
94 {
95         return which_choice;
96 }