| 1 |
/* Header Bar |
| 2 |
* |
| 3 |
* Gtk::HeaderBar is a container that is suitable for implementing |
| 4 |
* window titlebars. One of its features is that it can position |
| 5 |
* a title (and optional subtitle) centered with regard to the |
| 6 |
* full width, regardless of variable-width content at the left |
| 7 |
* or right. |
| 8 |
* |
| 9 |
* It is commonly used with Gtk::Window::set_titlebar() |
| 10 |
*/ |
| 11 |
|
| 12 |
#include <gtkmm.h> |
| 13 |
|
| 14 |
class Example_HeaderBar : public Gtk::Window |
| 15 |
{ |
| 16 |
public: |
| 17 |
Example_HeaderBar(); |
| 18 |
~Example_HeaderBar() override; |
| 19 |
|
| 20 |
protected: |
| 21 |
|
| 22 |
// Widgets |
| 23 |
Gtk::Image m_send_receive_image; |
| 24 |
Gtk::Button m_send_receive_button; |
| 25 |
Gtk::Button m_left_arrow_button; |
| 26 |
Gtk::Button m_right_arrow_button; |
| 27 |
Gtk::TextView m_text_view; |
| 28 |
|
| 29 |
// Containers |
| 30 |
Gtk::HeaderBar m_header_bar; |
| 31 |
Gtk::Box m_arrow_buttons_box; |
| 32 |
|
| 33 |
private: |
| 34 |
void configure_send_receive_button(); |
| 35 |
void configure_arrow_buttons(); |
| 36 |
}; |
| 37 |
|
| 38 |
//Called by DemoWindow; |
| 39 |
Gtk::Window* do_headerbar() |
| 40 |
{ |
| 41 |
return new Example_HeaderBar(); |
| 42 |
} |
| 43 |
|
| 44 |
Example_HeaderBar::Example_HeaderBar() |
| 45 |
: m_arrow_buttons_box(Gtk::ORIENTATION_HORIZONTAL) |
| 46 |
{ |
| 47 |
// Window properties |
| 48 |
// Window title is set by header bar |
| 49 |
set_default_size(600, 400); |
| 50 |
|
| 51 |
// Configuration |
| 52 |
m_header_bar.set_show_close_button(); |
| 53 |
m_header_bar.set_title("Welcome to Facebook - Log in, sign up or learn more"); |
| 54 |
m_header_bar.set_has_subtitle(false); |
| 55 |
|
| 56 |
// Header Bar buttons |
| 57 |
configure_send_receive_button(); |
| 58 |
configure_arrow_buttons(); |
| 59 |
|
| 60 |
// Header Bar layout |
| 61 |
m_header_bar.pack_start(m_arrow_buttons_box); |
| 62 |
m_header_bar.pack_end(m_send_receive_button); |
| 63 |
|
| 64 |
// Layout |
| 65 |
set_titlebar(m_header_bar); |
| 66 |
add(m_text_view); |
| 67 |
|
| 68 |
show_all_children(); |
| 69 |
} |
| 70 |
|
| 71 |
Example_HeaderBar::~Example_HeaderBar() |
| 72 |
{ |
| 73 |
} |
| 74 |
|
| 75 |
void Example_HeaderBar::configure_send_receive_button() |
| 76 |
{ |
| 77 |
/* the 'const' is required, to avoid C2668/Ambiguous call errors |
| 78 |
on some compilers, such as Visual Studio or when compiling without |
| 79 |
GTKMM_DISABLE_DEPRECATED on g++ */ |
| 80 |
Glib::RefPtr<const Gio::Icon> icon = Gio::ThemedIcon::create("mail-send-receive-symbolic", false); |
| 81 |
|
| 82 |
m_send_receive_image.set(icon, Gtk::ICON_SIZE_BUTTON); |
| 83 |
m_send_receive_button.add(m_send_receive_image); |
| 84 |
} |
| 85 |
|
| 86 |
void Example_HeaderBar::configure_arrow_buttons() |
| 87 |
{ |
| 88 |
m_arrow_buttons_box.get_style_context()->add_class("linked"); |
| 89 |
|
| 90 |
m_left_arrow_button.set_image_from_icon_name("pan-start-symbolic", Gtk::ICON_SIZE_BUTTON, true); |
| 91 |
m_right_arrow_button.set_image_from_icon_name("pan-end-symbolic", Gtk::ICON_SIZE_BUTTON, true); |
| 92 |
|
| 93 |
m_arrow_buttons_box.add(m_left_arrow_button); |
| 94 |
m_arrow_buttons_box.add(m_right_arrow_button); |
| 95 |
} |