[gtkmm] gtkmm-demo: use HeaderBar in main window



commit 7921db4f3553c169238946008ddd085e30eefc82
Author: Juan R. GarcĂ­a Blanco <juanrgar gmail com>
Date:   Sun May 25 11:52:58 2014 +0200

    gtkmm-demo: use HeaderBar in main window
    
    As it is currently done in gtk3-demo, pleace a HeaderBar at the top of
    the demo main window.

 demos/gtk-demo/demowindow.cc |   55 ++++++++++++++++++++++++++++++++---------
 demos/gtk-demo/demowindow.h  |    8 ++++++
 2 files changed, 51 insertions(+), 12 deletions(-)
---
diff --git a/demos/gtk-demo/demowindow.cc b/demos/gtk-demo/demowindow.cc
index 061746e..1e59480 100644
--- a/demos/gtk-demo/demowindow.cc
+++ b/demos/gtk-demo/demowindow.cc
@@ -76,13 +76,14 @@ const DemoColumns& demo_columns()
 
 
 DemoWindow::DemoWindow()
-: m_HBox(Gtk::ORIENTATION_HORIZONTAL),
+: m_RunButton("Run"),
+  m_HBox(Gtk::ORIENTATION_HORIZONTAL),
   m_TextWidget_Info(false),
   m_TextWidget_Source(true)
 {
   m_pWindow_Example = 0;
 
-  set_title("gtkmm Code Demos");
+  configure_header_bar();
 
   add(m_HBox);
 
@@ -111,6 +112,17 @@ DemoWindow::DemoWindow()
   show_all();
 }
 
+void DemoWindow::configure_header_bar()
+{
+  m_HeaderBar.set_show_close_button();
+  m_HeaderBar.pack_start(m_RunButton);
+
+  m_RunButton.get_style_context()->add_class("suggested-action");
+  m_RunButton.signal_clicked().connect(sigc::mem_fun(*this, &DemoWindow::on_run_button_clicked));
+
+  set_titlebar(m_HeaderBar);
+}
+
 void DemoWindow::fill_tree()
 {
   const DemoColumns& columns = demo_columns();
@@ -158,6 +170,19 @@ DemoWindow::~DemoWindow()
   on_example_window_hide(); //delete the example window if there is one.
 }
 
+void DemoWindow::on_run_button_clicked()
+{
+  if(m_pWindow_Example == 0) //Don't open a second window.
+  {
+    if(const Gtk::TreeModel::iterator iter = m_refTreeSelection->get_selected())
+    {
+      m_TreePath = m_refTreeStore->get_path(iter);
+
+      run_example(*iter);
+    }
+  }
+}
+
 void DemoWindow::on_treeview_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* model 
*/)
 {
   m_TreePath = path;
@@ -166,19 +191,23 @@ void DemoWindow::on_treeview_row_activated(const Gtk::TreeModel::Path& path, Gtk
   {
     if(const Gtk::TreeModel::iterator iter = m_TreeView.get_model()->get_iter(m_TreePath))
     {
-      Gtk::TreeModel::Row row = *iter;
-      const DemoColumns& columns = demo_columns();
+      run_example(*iter);
+    }
+  }
+}
+
+void DemoWindow::run_example(const Gtk::TreeModel::Row& row)
+{
+  const DemoColumns& columns = demo_columns();
 
-      const type_slotDo& slot = row[columns.slot];
+  const type_slotDo& slot = row[columns.slot];
 
-      if(slot && (m_pWindow_Example = slot()))
-      {
-        row[columns.italic] = true;
+  if(slot && (m_pWindow_Example = slot()))
+  {
+    row[columns.italic] = true;
 
-        m_pWindow_Example->signal_hide().connect(sigc::mem_fun(*this, &DemoWindow::on_example_window_hide));
-        m_pWindow_Example->show();
-      }
-    }
+    m_pWindow_Example->signal_hide().connect(sigc::mem_fun(*this, &DemoWindow::on_example_window_hide));
+    m_pWindow_Example->show();
   }
 }
 
@@ -194,8 +223,10 @@ void DemoWindow::on_treeselection_changed()
   if(const Gtk::TreeModel::iterator iter = m_refTreeSelection->get_selected())
   {
     const Glib::ustring filename = (*iter)[demo_columns().filename];
+    const Glib::ustring title = (*iter)[demo_columns().title];
 
     load_file(Glib::filename_from_utf8(filename));
+    m_HeaderBar.set_title(title);
   }
 }
 
diff --git a/demos/gtk-demo/demowindow.h b/demos/gtk-demo/demowindow.h
index 08142b6..44c3bc2 100644
--- a/demos/gtk-demo/demowindow.h
+++ b/demos/gtk-demo/demowindow.h
@@ -21,6 +21,8 @@
 #define _DEMOWINDOW_H
 
 #include "gtkmm/window.h"
+#include "gtkmm/headerbar.h"
+#include "gtkmm/button.h"
 #include "gtkmm/notebook.h"
 #include "gtkmm/box.h"
 
@@ -36,6 +38,9 @@ public:
   virtual ~DemoWindow();
 
 protected:
+  void run_example(const Gtk::TreeModel::Row& row);
+  void configure_header_bar();
+
   void fill_tree();
 
   void load_file(const std::string& filename);
@@ -46,8 +51,11 @@ protected:
   virtual void on_treeselection_changed();
   virtual void on_treeview_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
   virtual void on_example_window_hide();
+  virtual void on_run_button_clicked();
 
   //Member widgets:
+  Gtk::HeaderBar m_HeaderBar;
+  Gtk::Button m_RunButton;
   Gtk::Notebook m_Notebook;
   Gtk::Box m_HBox;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]