[gtkmm-documentation] Gtk::SearchBar example added



commit 057e7b0b11f47b09155ad57b36645edda9c68bf1
Author: Juan Rafael Garcia Blanco <juanrgar gmail com>
Date:   Sat Oct 5 19:03:13 2013 +0200

    Gtk::SearchBar example added

 examples/Makefile.am                     |    6 ++
 examples/book/searchbar/examplewindow.cc |  112 ++++++++++++++++++++++++++++++
 examples/book/searchbar/examplewindow.h  |   59 ++++++++++++++++
 examples/book/searchbar/main.cc          |   29 ++++++++
 4 files changed, 206 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 35717ec..a067e90 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -87,6 +87,7 @@ check_PROGRAMS =                                      \
        book/recent_files/example                       \
        book/revealer/example                           \
        book/scrolledwindow/example                     \
+       book/searchbar/example                          \
        book/signals/custom/example                     \
        book/socket/plug                                \
        book/socket/socket                              \
@@ -559,6 +560,11 @@ book_scrolledwindow_example_SOURCES =              \
        book/scrolledwindow/examplewindow.h     \
        book/scrolledwindow/main.cc
 
+book_searchbar_example_SOURCES =       \
+       book/searchbar/examplewindow.cc \
+       book/searchbar/examplewindow.h  \
+       book/searchbar/main.cc
+
 book_signals_custom_example_SOURCES =  \
        book/signals/custom/client.cc   \
        book/signals/custom/client.h    \
diff --git a/examples/book/searchbar/examplewindow.cc b/examples/book/searchbar/examplewindow.cc
new file mode 100644
index 0000000..6c0a505
--- /dev/null
+++ b/examples/book/searchbar/examplewindow.cc
@@ -0,0 +1,112 @@
+/* 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_vbox(Gtk::ORIENTATION_VERTICAL),
+  m_search_box(Gtk::ORIENTATION_HORIZONTAL),
+  m_up_down_box(Gtk::ORIENTATION_HORIZONTAL),
+  m_label("Press any key to start searching"),
+  m_search_mode_label("Show search bar:", 1.0, 0.5),
+  m_close_button_label("Show close button:", 1.0, 0.5)
+{
+  // Window properties
+  set_title("SearchBar Example");
+  set_border_width(12);
+  set_size_request(800, -1);
+
+  // Search bar properties
+  m_search_bar.set_show_close_button(true);
+
+  // Connect search entry
+  m_search_bar.connect_entry(m_entry);
+
+  // Events
+  add_events(Gdk::KEY_PRESS_MASK);
+
+  // Connect signals
+  signal_key_press_event().connect(sigc::mem_fun(*this, &ExampleWindow::on_window_key_press));
+  m_search_bar.property_search_mode_enabled().signal_changed().connect(sigc::mem_fun(*this, 
&ExampleWindow::on_search_bar_reveal_changed));
+
+  // Buttons
+  m_go_up_button.set_image_from_icon_name("go-up-symbolic");
+  m_go_down_button.set_image_from_icon_name("go-down-symbolic");
+
+  // Switches
+  m_search_mode_switch.set_active(false);
+  m_close_button_switch.set_active(true);
+  m_search_mode_switch.property_active().signal_changed().connect(sigc::mem_fun(*this, 
&ExampleWindow::on_search_mode_changed));
+  m_close_button_switch.property_active().signal_changed().connect(sigc::mem_fun(*this, 
&ExampleWindow::on_show_close_button_changed));
+
+  // Match style of epiphany's search bar
+  m_up_down_box.get_style_context()->add_class("raised");
+  m_up_down_box.get_style_context()->add_class("linked");
+
+  // Options panel layout
+  m_options_grid.set_halign(Gtk::ALIGN_CENTER);
+  m_options_grid.set_column_spacing(6);
+  m_options_grid.attach(m_search_mode_label, 0, 0, 1, 1);
+  m_options_grid.attach(m_search_mode_switch, 1, 0, 1, 1);
+  m_options_grid.attach(m_close_button_label, 0, 1, 1, 1);
+  m_options_grid.attach(m_close_button_switch, 1, 1, 1, 1);
+
+  // Layout
+  m_up_down_box.pack_start(m_go_down_button, Gtk::PACK_SHRINK, 0);
+  m_up_down_box.pack_start(m_go_up_button, Gtk::PACK_SHRINK, 0);
+  m_search_box.pack_end(m_up_down_box, Gtk::PACK_SHRINK, 0);
+  m_search_box.pack_start(m_entry, Gtk::PACK_EXPAND_WIDGET, 6);
+  m_search_bar.add(m_search_box);
+
+  m_vbox.pack_start(m_search_bar, Gtk::PACK_EXPAND_WIDGET, 6);
+  m_vbox.pack_start(m_label, Gtk::PACK_EXPAND_WIDGET, 6);
+  m_vbox.pack_start(m_separator, Gtk::PACK_EXPAND_WIDGET, 12);
+  m_vbox.pack_start(m_options_grid, Gtk::PACK_SHRINK, 12);
+  add(m_vbox);
+
+  show_all_children();
+}
+
+ExampleWindow::~ExampleWindow()
+{
+}
+
+bool ExampleWindow::on_window_key_press(GdkEventKey* key_event)
+{
+  GdkEvent event;
+
+  event.key = *key_event;
+  return m_search_bar.handle_event(&event);
+}
+
+void ExampleWindow::on_search_bar_reveal_changed()
+{
+  bool revealed = m_search_bar.get_search_mode();
+  m_search_mode_switch.set_active(revealed);
+}
+
+void ExampleWindow::on_search_mode_changed()
+{
+  bool search_mode = m_search_mode_switch.get_active();
+  m_search_bar.set_search_mode(search_mode);
+}
+
+void ExampleWindow::on_show_close_button_changed()
+{
+  bool show_close_button = m_close_button_switch.get_active();
+  m_search_bar.set_show_close_button(show_close_button);
+}
+
diff --git a/examples/book/searchbar/examplewindow.h b/examples/book/searchbar/examplewindow.h
new file mode 100644
index 0000000..dbfa6e4
--- /dev/null
+++ b/examples/book/searchbar/examplewindow.h
@@ -0,0 +1,59 @@
+/* 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>
+
+#include <iostream>
+
+class ExampleWindow : public Gtk::Window
+{
+public:
+  ExampleWindow();
+  virtual ~ExampleWindow();
+
+protected:
+  // Slots
+  bool on_window_key_press(GdkEventKey* key_event);
+  void on_search_mode_changed();
+  void on_show_close_button_changed();
+  void on_search_bar_reveal_changed();
+
+  // Containers 
+  Gtk::Box m_vbox;
+  Gtk::Box m_search_box;
+  Gtk::Box m_up_down_box;
+  Gtk::Grid m_options_grid;
+
+  // Widgets
+  Gtk::SearchBar m_search_bar;
+  Gtk::SearchEntry m_entry;
+  Gtk::Button m_go_up_button;
+  Gtk::Button m_go_down_button;
+  Gtk::Label m_label;
+  Gtk::Switch m_search_mode_switch;
+  Gtk::Label m_search_mode_label;
+  Gtk::Switch m_close_button_switch;
+  Gtk::Label m_close_button_label;
+  Gtk::Separator m_separator;
+
+private:
+};
+
+#endif // GTKMM_EXAMPLEWINDOW_H
+
diff --git a/examples/book/searchbar/main.cc b/examples/book/searchbar/main.cc
new file mode 100644
index 0000000..a5e307a
--- /dev/null
+++ b/examples/book/searchbar/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.searchbar");
+
+  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]