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