[gtkmm-documentation] Added Gtk::Popover book example



commit be55aca66123b38c19890aadf893b821f180343a
Author: Juan R. GarcĂ­a Blanco <juanrgar gmail com>
Date:   Sat Feb 8 13:52:39 2014 +0100

    Added Gtk::Popover book example

 examples/Makefile.am                   |    6 +
 examples/book/popover/examplewindow.cc |  171 ++++++++++++++++++++++++++++++++
 examples/book/popover/examplewindow.h  |   63 ++++++++++++
 examples/book/popover/main.cc          |   29 ++++++
 4 files changed, 269 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index a067e90..399b1b0 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -80,6 +80,7 @@ check_PROGRAMS =                                      \
        book/notebook/example                           \
        book/paned/example                              \
        book/placessidebar/example                      \
+       book/popover/example                    \
        book/printing/advanced/example                  \
        book/printing/simple/example                    \
        book/progressbar/example                        \
@@ -519,6 +520,11 @@ book_placessidebar_example_SOURCES =               \
        book/placessidebar/examplewindow.h              \
        book/placessidebar/main.cc
 
+book_popover_example_SOURCES =         \
+       book/popover/examplewindow.cc           \
+       book/popover/examplewindow.h            \
+       book/popover/main.cc
+
 book_printing_advanced_example_SOURCES =               \
        book/printing/advanced/examplewindow.cc         \
        book/printing/advanced/examplewindow.h          \
diff --git a/examples/book/popover/examplewindow.cc b/examples/book/popover/examplewindow.cc
new file mode 100644
index 0000000..5ced7fb
--- /dev/null
+++ b/examples/book/popover/examplewindow.cc
@@ -0,0 +1,171 @@
+/* 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_format_buttons_box(Gtk::ORIENTATION_HORIZONTAL),
+   m_toggle_button("Button"),
+   m_toggle_form_popover(m_toggle_button),
+   m_toggle_form_label("Non-modal Popover"),
+   m_toggle_form_combo_label("Popover position:"),
+   m_calendar_popover_label("Label:"),
+   m_calendar_popover(m_calendar)
+{
+  // Window properties
+  set_title("Popover Example");
+  set_border_width(12);
+  set_default_size(500, -1);
+
+  // Button
+  m_toggle_button.signal_toggled().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_toggled));
+
+  // Form popover
+  configure_form_popover();
+
+  // Calendar
+  m_calendar.set_hexpand();
+  m_calendar.set_vexpand();
+
+  // Calendar popover
+  configure_cal_popover();
+
+  // Layout
+  m_grid.set_row_spacing(6);
+  m_grid.attach(m_toggle_button, 0, 0, 1, 1);
+  m_grid.attach(m_calendar, 0, 1, 6, 1);
+  add(m_grid);
+
+  show_all_children();
+}
+
+ExampleWindow::~ExampleWindow()
+{
+}
+
+void ExampleWindow::on_button_toggled()
+{
+    bool active = m_toggle_button.get_active(); 
+    m_toggle_form_popover.set_visible(active);
+}
+
+void ExampleWindow::configure_form_popover()
+{
+  configure_form_buttons();
+  configure_form_combo();
+
+  m_toggle_form_grid.set_row_spacing(6);
+  m_toggle_form_grid.set_column_spacing(6);
+  m_toggle_form_grid.attach(m_toggle_form_label, 0, 0, 2, 1);
+  m_toggle_form_grid.attach(m_format_buttons_box, 0, 1, 2, 1);
+  m_toggle_form_grid.attach(m_toggle_form_combo_label, 0, 2, 1, 1);
+  m_toggle_form_grid.attach(m_toggle_form_combo, 1, 2, 1, 1);
+  m_toggle_form_grid.show_all();
+
+  m_toggle_form_popover.add(m_toggle_form_grid);
+  m_toggle_form_popover.set_position(Gtk::POS_BOTTOM);
+  m_toggle_form_popover.set_border_width(6);
+  m_toggle_form_popover.set_modal(false);
+}
+
+void ExampleWindow::configure_form_buttons()
+{
+  m_toggle_form_buttons[0].set_image_from_icon_name("format-justify-left-symbolic");
+  m_toggle_form_buttons[1].set_image_from_icon_name("format-justify-center-symbolic");
+  m_toggle_form_buttons[2].set_image_from_icon_name("format-justify-right-symbolic");
+
+  m_toggle_form_buttons[0].set_mode(false);
+  m_toggle_form_buttons[1].set_mode(false);
+  m_toggle_form_buttons[2].set_mode(false);
+
+  m_toggle_form_buttons[1].join_group(m_toggle_form_buttons[0]);
+  m_toggle_form_buttons[2].join_group(m_toggle_form_buttons[0]);
+
+  m_format_buttons_box.pack_start(m_toggle_form_buttons[0], Gtk::PACK_EXPAND_WIDGET, 0);
+  m_format_buttons_box.pack_start(m_toggle_form_buttons[1], Gtk::PACK_EXPAND_WIDGET, 0);
+  m_format_buttons_box.pack_start(m_toggle_form_buttons[2], Gtk::PACK_EXPAND_WIDGET, 0);
+
+  m_format_buttons_box.set_hexpand();
+
+  Glib::RefPtr<Gtk::StyleContext> style_context = m_format_buttons_box.get_style_context();
+  style_context->add_class("raised");
+  style_context->add_class("linked");
+}
+
+void ExampleWindow::configure_form_combo()
+{
+  m_toggle_form_combo.append("BOTTOM");
+  m_toggle_form_combo.append("RIGHT");
+
+  m_toggle_form_combo.set_active(0);
+
+  m_toggle_form_combo.signal_changed().connect(sigc::mem_fun(*this, &ExampleWindow::on_combo_changed));
+}
+
+void ExampleWindow::on_combo_changed()
+{
+  int active_entry = m_toggle_form_combo.get_active_row_number();
+
+  if (active_entry == 0)
+  {
+    m_toggle_form_popover.set_position(Gtk::POS_BOTTOM);
+  }
+  else if (active_entry == 1)
+  {
+    m_toggle_form_popover.set_position(Gtk::POS_RIGHT);
+  }
+}
+
+void ExampleWindow::configure_cal_popover()
+{
+  m_calendar.signal_day_selected().connect(sigc::mem_fun(*this, &ExampleWindow::on_day_selected));
+
+  m_calendar_form_grid.set_column_spacing(6);
+  m_calendar_form_grid.attach(m_calendar_popover_label, 0, 0, 1, 1);
+  m_calendar_form_grid.attach(m_calendar_popover_entry, 1, 0, 1, 1);
+  m_calendar_form_grid.show_all();
+
+  m_calendar_popover.add(m_calendar_form_grid);
+  m_calendar_popover.set_border_width(6);
+}
+
+void ExampleWindow::on_day_selected()
+{
+  cairo_rectangle_int_t rect;
+
+  GdkEvent* event = gtk_get_current_event();
+
+  if (event->type != GDK_BUTTON_PRESS)
+  {
+    return;
+  }
+
+  gdk_window_coords_to_parent (event->button.window,
+                               event->button.x, event->button.y,
+                               &event->button.x, &event->button.y);
+  Gtk::Allocation allocation = m_calendar.get_allocation();
+  rect.x = event->button.x - allocation.get_x();
+  rect.y = event->button.y - allocation.get_y();
+  rect.width = rect.height = 1;
+
+  m_calendar_popover.set_pointing_to(rect);
+  m_calendar_popover.set_visible(true);
+
+  m_calendar_popover_entry.set_text("");
+
+  gdk_event_free (event);
+}
+
diff --git a/examples/book/popover/examplewindow.h b/examples/book/popover/examplewindow.h
new file mode 100644
index 0000000..e9b72d8
--- /dev/null
+++ b/examples/book/popover/examplewindow.h
@@ -0,0 +1,63 @@
+/* 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_button_toggled();
+  void on_combo_changed();
+  void on_day_selected();
+
+  // Containers 
+  Gtk::Grid m_grid;
+  Gtk::Grid m_toggle_form_grid;
+  Gtk::Box m_format_buttons_box;
+  Gtk::Grid m_calendar_form_grid;
+
+  // Widgets
+  Gtk::ToggleButton m_toggle_button;
+
+  Gtk::Popover m_toggle_form_popover;
+  Gtk::Label m_toggle_form_label;
+  Gtk::RadioButton m_toggle_form_buttons[3];
+  Gtk::Label m_toggle_form_combo_label;
+  Gtk::ComboBoxText m_toggle_form_combo;
+
+  Gtk::Calendar m_calendar;
+  Gtk::Popover m_calendar_popover;
+  Gtk::Label m_calendar_popover_label;
+  Gtk::Entry m_calendar_popover_entry;
+
+private:
+  void configure_form_popover();
+  void configure_form_buttons();
+  void configure_form_combo();
+
+  void configure_cal_popover();
+};
+
+#endif // GTKMM_EXAMPLEWINDOW_H
+
diff --git a/examples/book/popover/main.cc b/examples/book/popover/main.cc
new file mode 100644
index 0000000..41389fe
--- /dev/null
+++ b/examples/book/popover/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.popovers");
+
+  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]