| 1 |
/* gtkmm example Copyright (C) 2002 gtkmm development team |
| 2 |
* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License as published by |
| 5 |
* the Free Software Foundation; either version 2 of the License, or |
| 6 |
* (at your option) any later version. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License along |
| 14 |
* with this program; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "radiobuttons.h" |
| 18 |
|
| 19 |
RadioButtons::RadioButtons() : |
| 20 |
m_Box_Top(Gtk::Orientation::VERTICAL), |
| 21 |
m_Box1(Gtk::Orientation::VERTICAL, 10), |
| 22 |
m_Box2(Gtk::Orientation::VERTICAL, 10), |
| 23 |
m_RadioButton1("button1"), |
| 24 |
m_RadioButton2("button2"), |
| 25 |
m_RadioButton3("button3"), |
| 26 |
m_Button_Close("close") |
| 27 |
{ |
| 28 |
// Set title and border of the window |
| 29 |
set_title("radio buttons"); |
| 30 |
|
| 31 |
// Gtk::CheckButton and Gtk::ToggleButton have set_group() methods. |
| 32 |
// They act as radio buttons, if they are included in a group. |
| 33 |
|
| 34 |
// Put radio buttons 2 and 3 in the same group as 1: |
| 35 |
m_RadioButton2.set_group(m_RadioButton1); |
| 36 |
m_RadioButton3.set_group(m_RadioButton1); |
| 37 |
|
| 38 |
// Add outer box to the window (because the window |
| 39 |
// can only contain a single widget) |
| 40 |
set_child(m_Box_Top); |
| 41 |
|
| 42 |
//Put the inner boxes and the separator in the outer box: |
| 43 |
m_Box_Top.append(m_Box1); |
| 44 |
m_Box_Top.append(m_Separator); |
| 45 |
m_Box_Top.append(m_Box2); |
| 46 |
m_Separator.set_expand(); |
| 47 |
|
| 48 |
// Set the inner boxes' margins |
| 49 |
m_Box1.set_margin(10); |
| 50 |
m_Box2.set_margin(10); |
| 51 |
|
| 52 |
// Put the radio buttons in Box1: |
| 53 |
m_Box1.append(m_RadioButton1); |
| 54 |
m_Box1.append(m_RadioButton2); |
| 55 |
m_Box1.append(m_RadioButton3); |
| 56 |
m_RadioButton1.set_expand(); |
| 57 |
m_RadioButton2.set_expand(); |
| 58 |
m_RadioButton3.set_expand(); |
| 59 |
|
| 60 |
// Set the second button active |
| 61 |
m_RadioButton2.set_active(true); |
| 62 |
|
| 63 |
// Put Close button in Box2: |
| 64 |
m_Box2.append(m_Button_Close); |
| 65 |
m_Button_Close.set_expand(); |
| 66 |
|
| 67 |
// Make the button the default widget |
| 68 |
set_default_widget(m_Button_Close); |
| 69 |
|
| 70 |
// Connect the toggled signal of the button to |
| 71 |
// RadioButtons::on_button_toggled() |
| 72 |
m_Button_Close.signal_clicked().connect(sigc::mem_fun(*this, |
| 73 |
&RadioButtons::on_button_clicked) ); |
| 74 |
} |
| 75 |
|
| 76 |
RadioButtons::~RadioButtons() |
| 77 |
{ |
| 78 |
} |
| 79 |
|
| 80 |
void RadioButtons::on_button_clicked() |
| 81 |
{ |
| 82 |
close(); |
| 83 |
} |