[gtkmm-documentation] Gtk::HeaderBar example added.



commit 97f7375d94507934772bf076ebd7f21e13e3debd
Author: Juan Rafael Garcia Blanco <juanrgar gmail com>
Date:   Sat Sep 28 11:48:52 2013 +0200

    Gtk::HeaderBar example added.
    
    Bug #708866

 examples/Makefile.am                     |    6 ++
 examples/book/headerbar/examplewindow.cc |   95 ++++++++++++++++++++++++++++++
 examples/book/headerbar/examplewindow.h  |   52 ++++++++++++++++
 examples/book/headerbar/main.cc          |   29 +++++++++
 4 files changed, 182 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index cc7e021..26bf4b8 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -62,6 +62,7 @@ check_PROGRAMS =                                      \
        book/giomm/volumes/example                      \
        book/giomm/write_file/example                   \
        book/grid/example                               \
+       book/headerbar/example                          \
        book/helloworld/helloworld                      \
        book/helloworld2/helloworld2                    \
        book/iconview/example                           \
@@ -415,6 +416,11 @@ book_giomm_write_file_example_LDADD = $(GIOMM_LIBS)
 book_giomm_write_file_example_SOURCES = \
        book/giomm/write_file/main.cc
 
+book_headerbar_example_SOURCES = \
+       book/headerbar/examplewindow.cc \
+       book/headerbar/examplewindow.h \
+       book/headerbar/main.cc
+
 book_grid_example_SOURCES = \
        book/grid/examplewindow.cc \
        book/grid/examplewindow.h \
diff --git a/examples/book/headerbar/examplewindow.cc b/examples/book/headerbar/examplewindow.cc
new file mode 100644
index 0000000..d7c3590
--- /dev/null
+++ b/examples/book/headerbar/examplewindow.cc
@@ -0,0 +1,95 @@
+/* gtkmm example Copyright (C) 2013 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "examplewindow.h"
+
+ExampleWindow::ExampleWindow()
+ : m_close_button_label("Show close button:", 1.0, 0.5),
+   m_title_label("Title:", 1.0, 0.5),
+   m_subtitle_label("Subtitle:", 1.0, 0.5)
+{
+  // Window properties
+  set_title("HeaderBar Example");
+  set_border_width(12);
+
+  // Button
+  m_button.set_image_from_icon_name("go-home-symbolic");
+  m_button.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
+
+  // Entries
+  m_title_entry.set_text("HeaderBar title");
+  m_subtitle_entry.set_text("HeaderBar subtitle");
+  m_title_entry.signal_activate().connect(sigc::mem_fun(*this, &ExampleWindow::on_title_entry_activate));
+  m_subtitle_entry.signal_activate().connect(sigc::mem_fun(*this, 
&ExampleWindow::on_subtitle_entry_activate));
+
+  // Header bar
+  on_title_entry_activate();
+  on_subtitle_entry_activate();
+  m_header_bar.set_show_close_button();
+  m_header_bar.pack_start(m_button);
+
+  // Set headerbar as titlebar
+  set_titlebar(m_header_bar);
+
+  // Switch
+  m_switch.set_active(true);
+  m_switch.property_active().signal_changed().connect(sigc::mem_fun(*this, 
&ExampleWindow::on_switch_active_changed));
+
+  // Layout
+  m_grid.set_column_spacing(6);
+  m_grid.set_row_spacing(6);
+  m_grid.attach(m_close_button_label, 0, 0, 1, 1);
+  m_grid.attach(m_switch, 1, 0, 1, 1);
+  m_grid.attach(m_title_label, 0, 1, 1, 1);
+  m_grid.attach(m_title_entry, 1, 1, 1, 1);
+  m_grid.attach(m_subtitle_label, 0, 2, 1, 1);
+  m_grid.attach(m_subtitle_entry, 1, 2, 1, 1);
+  add(m_grid);
+
+  show_all_children();
+}
+
+ExampleWindow::~ExampleWindow()
+{
+}
+
+void ExampleWindow::on_switch_active_changed()
+{
+  bool show_close_button = m_switch.get_active();
+  m_header_bar.set_show_close_button(show_close_button);
+}
+
+void ExampleWindow::on_title_entry_activate()
+{
+  const Glib::ustring title = m_title_entry.get_text();
+  if(!title.empty())
+  {
+    m_header_bar.set_title(title);
+  }
+}
+
+void ExampleWindow::on_subtitle_entry_activate()
+{
+  const Glib::ustring subtitle = m_subtitle_entry.get_text();
+  m_header_bar.set_subtitle(subtitle);
+}
+
+void ExampleWindow::on_button_clicked()
+{
+  Gtk::MessageDialog dialog(*this, "Button clicked", true);
+  dialog.run();
+}
+ 
diff --git a/examples/book/headerbar/examplewindow.h b/examples/book/headerbar/examplewindow.h
new file mode 100644
index 0000000..45106eb
--- /dev/null
+++ b/examples/book/headerbar/examplewindow.h
@@ -0,0 +1,52 @@
+/* gtkmm example Copyright (C) 2013 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLEWINDOW_H
+#define GTKMM_EXAMPLEWINDOW_H
+
+#include <gtkmm.h>
+
+class ExampleWindow : public Gtk::Window
+{
+public:
+  ExampleWindow();
+  virtual ~ExampleWindow();
+
+protected:
+  // Slots
+  void on_switch_active_changed();
+  void on_title_entry_activate();
+  void on_subtitle_entry_activate();
+  void on_button_clicked();
+
+  // Containers 
+  Gtk::Grid m_grid;
+
+  // Widgets
+  Gtk::HeaderBar m_header_bar;
+  Gtk::Button m_button;
+  Gtk::Label m_close_button_label;
+  Gtk::Switch m_switch;
+  Gtk::Label m_title_label;
+  Gtk::Entry m_title_entry;
+  Gtk::Label m_subtitle_label;
+  Gtk::Entry m_subtitle_entry;
+
+private:
+};
+
+#endif // GTKMM_EXAMPLEWINDOW_H
+
diff --git a/examples/book/headerbar/main.cc b/examples/book/headerbar/main.cc
new file mode 100644
index 0000000..3f6a6ab
--- /dev/null
+++ b/examples/book/headerbar/main.cc
@@ -0,0 +1,29 @@
+/* gtkmm example Copyright (C) 2013 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "examplewindow.h"
+#include <gtkmm/application.h>
+
+int main(int argc, char *argv[])
+{
+  Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example.headerbar");
+
+  ExampleWindow window;
+
+  // Shows the window and returns when it is closed.
+  return app->run(window);
+}
+


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