1 /* Paned Widgets
2 *
3 * The GtkHPaned and GtkVPaned Widgets divide their content
4 * area into two panes with a divider in between that the
5 * user can adjust. A separate child is placed into each
6 * pane.
7 *
8 * There are a number of options that can be set for each pane.
9 * This test contains both a horizontal (HPaned) and a vertical
10 * (VPaned) widget, and allows you to adjust the options for
11 * each side of each widget.
12 */
13
14 #include <gtkmm.h>
15
16 namespace
17 {
18
19 class Example_Panes : public Gtk::Window
20 {
21 public:
22 Example_Panes();
23 virtual ~Example_Panes();
24 };
25
26 class PaneOptions : public Gtk::Frame
27 {
28 public:
29 PaneOptions(Gtk::Paned& paned, const Glib::ustring& frame_label,
30 const Glib::ustring& label1, const Glib::ustring& label2);
31 virtual ~PaneOptions();
32
33 private:
34 // member widgets:
35 Gtk::Paned* m_pPaned;
36 Gtk::CheckButton m_CheckButton_resize1;
37 Gtk::CheckButton m_CheckButton_shrink1;
38 Gtk::CheckButton m_CheckButton_resize2;
39 Gtk::CheckButton m_CheckButton_shrink2;
40
41 // signal handlers:
42 void on_checkbutton1();
43 void on_checkbutton2();
44 };
45
46
Example_Panes()47 Example_Panes::Example_Panes()
48 {
49 set_title("Panes");
50 set_border_width(0);
51
52 Gtk::VBox *const pVBox = new Gtk::VBox();
53 add(*Gtk::manage(pVBox));
54
55 Gtk::VPaned *const pVPaned = new Gtk::VPaned();
56 pVBox->pack_start(*Gtk::manage(pVPaned));
57 pVPaned->set_border_width(5);
58
59 Gtk::HPaned *const pHPaned = new Gtk::HPaned();
60 pVPaned->add1(*Gtk::manage(pHPaned));
61
62 Gtk::Frame *const pFrame1 = new Gtk::Frame();
63 pHPaned->add1(*Gtk::manage(pFrame1));
64 pFrame1->set_shadow_type(Gtk::SHADOW_IN);
65 pFrame1->set_size_request(60, 60);
66 pFrame1->add(*Gtk::manage(new Gtk::Button("_Hi there", true)));
67
68 Gtk::Frame *const pFrame2 = new Gtk::Frame();
69 pHPaned->add2(*Gtk::manage(pFrame2));
70 pFrame2->set_shadow_type(Gtk::SHADOW_IN);
71 pFrame2->set_size_request(80, 60);
72
73 Gtk::Frame *const pFrame3 = new Gtk::Frame();
74 pVPaned->add2(*Gtk::manage(pFrame3));
75 pFrame3->set_shadow_type(Gtk::SHADOW_IN);
76 pFrame3->set_size_request(60, 80);
77
78 // Now create check buttons to control sizing
79 pVBox->pack_start(*Gtk::manage(new PaneOptions(*pHPaned, "Horizontal", "Left", "Right")), Gtk::PACK_SHRINK);
80 pVBox->pack_start(*Gtk::manage(new PaneOptions(*pVPaned, "Vertical", "Top", "Bottom")), Gtk::PACK_SHRINK);
81
82 show_all();
83 }
84
~Example_Panes()85 Example_Panes::~Example_Panes()
86 {}
87
88
PaneOptions(Gtk::Paned & paned,const Glib::ustring & frame_label,const Glib::ustring & label1,const Glib::ustring & label2)89 PaneOptions::PaneOptions(Gtk::Paned& paned, const Glib::ustring& frame_label,
90 const Glib::ustring& label1, const Glib::ustring& label2)
91 :
92 Gtk::Frame (frame_label),
93 m_pPaned (&paned),
94 m_CheckButton_resize1 ("_Resize", true),
95 m_CheckButton_shrink1 ("_Shrink", true),
96 m_CheckButton_resize2 ("_Resize", true),
97 m_CheckButton_shrink2 ("_Shrink", true)
98 {
99 set_border_width(4);
100
101 Gtk::Table *const pTable = new Gtk::Table(3, 2, true);
102 add(*Gtk::manage(pTable));
103
104 pTable->attach(*Gtk::manage(new Gtk::Label(label1)), 0, 1, 0, 1);
105 pTable->attach(*Gtk::manage(new Gtk::Label(label2)), 1, 2, 0, 1);
106
107 pTable->attach(m_CheckButton_resize1, 0, 1, 1, 2);
108 pTable->attach(m_CheckButton_shrink1, 0, 1, 2, 3);
109 pTable->attach(m_CheckButton_resize2, 1, 2, 1, 2);
110 pTable->attach(m_CheckButton_shrink2, 1, 2, 2, 3);
111
112 m_CheckButton_resize1.set_active(false);
113 m_CheckButton_shrink1.set_active(true);
114 m_CheckButton_resize2.set_active(true);
115 m_CheckButton_shrink2.set_active(true);
116
117 m_CheckButton_resize1.signal_toggled().connect(sigc::mem_fun(*this, &PaneOptions::on_checkbutton1));
118 m_CheckButton_shrink1.signal_toggled().connect(sigc::mem_fun(*this, &PaneOptions::on_checkbutton1));
119 m_CheckButton_resize2.signal_toggled().connect(sigc::mem_fun(*this, &PaneOptions::on_checkbutton2));
120 m_CheckButton_shrink2.signal_toggled().connect(sigc::mem_fun(*this, &PaneOptions::on_checkbutton2));
121
122 // Sync Gtk::Paned options with the CheckButtons' state. Actually, the
123 // preset state of the buttons should match the Gtk::Paned default settings,
124 // but it is definitely cleaner this way.
125 on_checkbutton1();
126 on_checkbutton2();
127 }
128
~PaneOptions()129 PaneOptions::~PaneOptions()
130 {}
131
on_checkbutton1()132 void PaneOptions::on_checkbutton1()
133 {
134 Gtk::AttachOptions options = Gtk::AttachOptions(0);
135
136 if(m_CheckButton_resize1.get_active()) options = (options | Gtk::EXPAND);
137 if(m_CheckButton_shrink1.get_active()) options = (options | Gtk::SHRINK);
138
139 Gtk::Widget *const pChild = m_pPaned->get_child1();
140
141 m_pPaned->remove(*pChild);
142 m_pPaned->pack1(*pChild, options);
143 }
144
on_checkbutton2()145 void PaneOptions::on_checkbutton2()
146 {
147 Gtk::AttachOptions options = Gtk::AttachOptions(0);
148
149 if(m_CheckButton_resize2.get_active()) options = (options | Gtk::EXPAND);
150 if(m_CheckButton_shrink2.get_active()) options = (options | Gtk::SHRINK);
151
152 Gtk::Widget *const pChild = m_pPaned->get_child2();
153
154 m_pPaned->remove(*pChild);
155 m_pPaned->pack2(*pChild, options);
156 }
157
158 } // anonymous namespace
159
160
161 // called by DemoWindow
do_panes()162 Gtk::Window* do_panes()
163 {
164 return new Example_Panes();
165 }
166
167