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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/* Paned Widgets
*
* The GtkHPaned and GtkVPaned Widgets divide their content
* area into two panes with a divider in between that the
* user can adjust. A separate child is placed into each
* pane.
*
* There are a number of options that can be set for each pane.
* This test contains both a horizontal (HPaned) and a vertical
* (VPaned) widget, and allows you to adjust the options for
* each side of each widget.
*/
#include <gtkmm.h>
namespace
{
class Example_Panes : public Gtk::Window
{
public:
Example_Panes();
virtual ~Example_Panes();
};
class PaneOptions : public Gtk::Frame
{
public:
PaneOptions(Gtk::Paned& paned, const Glib::ustring& frame_label,
const Glib::ustring& label1, const Glib::ustring& label2);
virtual ~PaneOptions();
private:
// member widgets:
Gtk::Paned* m_pPaned;
Gtk::CheckButton m_CheckButton_resize1;
Gtk::CheckButton m_CheckButton_shrink1;
Gtk::CheckButton m_CheckButton_resize2;
Gtk::CheckButton m_CheckButton_shrink2;
// signal handlers:
void on_checkbutton1();
void on_checkbutton2();
};
Example_Panes::Example_Panes()
{
set_title("Panes");
set_border_width(0);
Gtk::Box *const pVBox = new Gtk::Box(Gtk::ORIENTATION_VERTICAL);
add(*Gtk::manage(pVBox));
Gtk::Paned *const pVPaned = new Gtk::Paned(Gtk::ORIENTATION_VERTICAL);
pVBox->pack_start(*Gtk::manage(pVPaned));
pVPaned->set_border_width(5);
Gtk::Paned *const pHPaned = new Gtk::Paned(Gtk::ORIENTATION_HORIZONTAL);
pVPaned->add1(*Gtk::manage(pHPaned));
Gtk::Frame *const pFrame1 = new Gtk::Frame();
pHPaned->add1(*Gtk::manage(pFrame1));
pFrame1->set_shadow_type(Gtk::SHADOW_IN);
pFrame1->set_size_request(60, 60);
pFrame1->add(*Gtk::manage(new Gtk::Button("_Hi there", true)));
Gtk::Frame *const pFrame2 = new Gtk::Frame();
pHPaned->add2(*Gtk::manage(pFrame2));
pFrame2->set_shadow_type(Gtk::SHADOW_IN);
pFrame2->set_size_request(80, 60);
Gtk::Frame *const pFrame3 = new Gtk::Frame();
pVPaned->add2(*Gtk::manage(pFrame3));
pFrame3->set_shadow_type(Gtk::SHADOW_IN);
pFrame3->set_size_request(60, 80);
// Now create check buttons to control sizing
pVBox->pack_start(*Gtk::manage(new PaneOptions(*pHPaned, "Horizontal", "Left", "Right")), Gtk::PACK_SHRINK);
pVBox->pack_start(*Gtk::manage(new PaneOptions(*pVPaned, "Vertical", "Top", "Bottom")), Gtk::PACK_SHRINK);
show_all();
}
Example_Panes::~Example_Panes()
{}
PaneOptions::PaneOptions(Gtk::Paned& paned, const Glib::ustring& frame_label,
const Glib::ustring& label1, const Glib::ustring& label2)
:
Gtk::Frame (frame_label),
m_pPaned (&paned),
m_CheckButton_resize1 ("_Resize", true),
m_CheckButton_shrink1 ("_Shrink", true),
m_CheckButton_resize2 ("_Resize", true),
m_CheckButton_shrink2 ("_Shrink", true)
{
set_border_width(4);
Gtk::Grid *const pGrid = new Gtk::Grid();
add(*Gtk::manage(pGrid));
pGrid->attach(*Gtk::manage(new Gtk::Label(label1)), 0, 0, 1, 1);
pGrid->attach(*Gtk::manage(new Gtk::Label(label2)), 1, 0, 1, 1);
pGrid->attach(m_CheckButton_resize1, 0, 1, 1, 1);
pGrid->attach(m_CheckButton_shrink1, 0, 2, 1, 1);
pGrid->attach(m_CheckButton_resize2, 1, 1, 1, 1);
pGrid->attach(m_CheckButton_shrink2, 1, 2, 1, 1);
m_CheckButton_resize1.set_active(false);
m_CheckButton_shrink1.set_active(true);
m_CheckButton_resize2.set_active(true);
m_CheckButton_shrink2.set_active(true);
m_CheckButton_resize1.signal_toggled().connect(sigc::mem_fun(*this, &PaneOptions::on_checkbutton1));
m_CheckButton_shrink1.signal_toggled().connect(sigc::mem_fun(*this, &PaneOptions::on_checkbutton1));
m_CheckButton_resize2.signal_toggled().connect(sigc::mem_fun(*this, &PaneOptions::on_checkbutton2));
m_CheckButton_shrink2.signal_toggled().connect(sigc::mem_fun(*this, &PaneOptions::on_checkbutton2));
// Sync Gtk::Paned options with the CheckButtons' state. Actually, the
// preset state of the buttons should match the Gtk::Paned default settings,
// but it is definitely cleaner this way.
on_checkbutton1();
on_checkbutton2();
}
PaneOptions::~PaneOptions()
{}
void PaneOptions::on_checkbutton1()
{
Gtk::AttachOptions options = Gtk::AttachOptions(0);
if(m_CheckButton_resize1.get_active()) options = (options | Gtk::EXPAND);
if(m_CheckButton_shrink1.get_active()) options = (options | Gtk::SHRINK);
Gtk::Widget *const pChild = m_pPaned->get_child1();
m_pPaned->remove(*pChild);
m_pPaned->pack1(*pChild, options);
}
void PaneOptions::on_checkbutton2()
{
Gtk::AttachOptions options = Gtk::AttachOptions(0);
if(m_CheckButton_resize2.get_active()) options = (options | Gtk::EXPAND);
if(m_CheckButton_shrink2.get_active()) options = (options | Gtk::SHRINK);
Gtk::Widget *const pChild = m_pPaned->get_child2();
m_pPaned->remove(*pChild);
m_pPaned->pack2(*pChild, options);
}
} // anonymous namespace
// called by DemoWindow
Gtk::Window* do_panes()
{
return new Example_Panes();
}
|