| 1 |
/* Button Boxes |
| 2 |
* |
| 3 |
* The Button Box widgets are used to arrange buttons with padding. |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <gtkmm.h> |
| 7 |
#include <gtk/gtk.h> |
| 8 |
|
| 9 |
class Example_ButtonBox : public Gtk::Window |
| 10 |
{ |
| 11 |
public: |
| 12 |
Example_ButtonBox(); |
| 13 |
~Example_ButtonBox() override; |
| 14 |
|
| 15 |
protected: |
| 16 |
Gtk::Frame* create_button_box(bool horizontal, const Glib::ustring& title, |
| 17 |
int spacing, Gtk::ButtonBoxStyle layout); |
| 18 |
|
| 19 |
//Member widgets: |
| 20 |
Gtk::Frame m_Frame_Horizontal, m_Frame_Vertical; |
| 21 |
Gtk::Box m_VBox_Main, m_VBox; |
| 22 |
Gtk::Box m_HBox; |
| 23 |
}; |
| 24 |
|
| 25 |
//Called by DemoWindow; |
| 26 |
Gtk::Window* do_buttonbox() |
| 27 |
{ |
| 28 |
return new Example_ButtonBox(); |
| 29 |
} |
| 30 |
|
| 31 |
Example_ButtonBox::Example_ButtonBox() |
| 32 |
: m_Frame_Horizontal("Horizontal Button Boxes"), |
| 33 |
m_Frame_Vertical("Vertical Button Boxes"), |
| 34 |
m_VBox_Main(Gtk::ORIENTATION_VERTICAL), |
| 35 |
m_VBox(Gtk::ORIENTATION_VERTICAL), |
| 36 |
m_HBox(Gtk::ORIENTATION_HORIZONTAL) |
| 37 |
{ |
| 38 |
set_title("Button Boxes"); |
| 39 |
set_border_width(10); |
| 40 |
|
| 41 |
add(m_VBox_Main); |
| 42 |
|
| 43 |
m_VBox_Main.pack_start(m_Frame_Horizontal, Gtk::PACK_EXPAND_WIDGET, 10); |
| 44 |
|
| 45 |
m_VBox.set_border_width(10); |
| 46 |
m_Frame_Horizontal.add(m_VBox); |
| 47 |
|
| 48 |
m_VBox.pack_start( *(create_button_box(true, "Spread", 40, Gtk::BUTTONBOX_SPREAD)) ); |
| 49 |
m_VBox.pack_start( *(create_button_box(true, "Edge", 40, Gtk::BUTTONBOX_EDGE)) ); |
| 50 |
m_VBox.pack_start( *(create_button_box(true, "Start", 40, Gtk::BUTTONBOX_START)) ); |
| 51 |
m_VBox.pack_start( *(create_button_box(true, "End", 40, Gtk::BUTTONBOX_END)) ); |
| 52 |
|
| 53 |
m_VBox_Main.pack_start(m_Frame_Vertical, Gtk::PACK_EXPAND_WIDGET, 10); |
| 54 |
|
| 55 |
m_VBox.set_border_width(10); |
| 56 |
m_Frame_Vertical.add(m_HBox); |
| 57 |
|
| 58 |
m_HBox.pack_start( *(create_button_box(false, "Spread", 30, Gtk::BUTTONBOX_SPREAD)) ); |
| 59 |
m_HBox.pack_start( *(create_button_box(false, "Edge", 30, Gtk::BUTTONBOX_EDGE)) ); |
| 60 |
m_HBox.pack_start( *(create_button_box(false, "Start", 30, Gtk::BUTTONBOX_START)) ); |
| 61 |
m_HBox.pack_start( *(create_button_box(false, "End", 30, Gtk::BUTTONBOX_END)) ); |
| 62 |
|
| 63 |
show_all(); |
| 64 |
} |
| 65 |
|
| 66 |
Example_ButtonBox::~Example_ButtonBox() |
| 67 |
{ |
| 68 |
} |
| 69 |
|
| 70 |
Gtk::Frame* Example_ButtonBox::create_button_box(bool horizontal, const Glib::ustring& title, gint spacing, Gtk::ButtonBoxStyle layout) |
| 71 |
{ |
| 72 |
Gtk::Frame* pFrame = Gtk::make_managed<Gtk::Frame>(title); |
| 73 |
|
| 74 |
Gtk::ButtonBox* pButtonBox = nullptr; |
| 75 |
if (horizontal) |
| 76 |
pButtonBox = Gtk::make_managed<Gtk::ButtonBox>(Gtk::ORIENTATION_HORIZONTAL); |
| 77 |
else |
| 78 |
pButtonBox = Gtk::make_managed<Gtk::ButtonBox>(Gtk::ORIENTATION_VERTICAL); |
| 79 |
|
| 80 |
pButtonBox->set_border_width(5); |
| 81 |
pFrame->add(*pButtonBox); |
| 82 |
|
| 83 |
pButtonBox->set_layout(layout); |
| 84 |
pButtonBox->set_spacing(spacing); |
| 85 |
|
| 86 |
Gtk::Button* pButton = Gtk::make_managed<Gtk::Button>("_OK", true); |
| 87 |
pButtonBox->add(*pButton); |
| 88 |
|
| 89 |
pButton = Gtk::make_managed<Gtk::Button>("_Cancel", true); |
| 90 |
pButtonBox->add(*pButton); |
| 91 |
|
| 92 |
pButton = Gtk::make_managed<Gtk::Button>(); |
| 93 |
Gtk::Image* pImage = Gtk::make_managed<Gtk::Image>(); |
| 94 |
pImage->set_from_icon_name("help-browser", Gtk::ICON_SIZE_BUTTON); |
| 95 |
pButton->add(*pImage); |
| 96 |
pButtonBox->add(*pButton); |
| 97 |
|
| 98 |
return pFrame; |
| 99 |
} |
| 100 |
|