[gtkmm] Menu, MenuBar: Add constructors that take Gio::MenuModels.



commit b68dbe051cd36a0f83081d41eee908aef21174c6
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Jul 22 14:02:38 2013 +0200

    Menu, MenuBar: Add constructors that take Gio::MenuModels.
    
    This "wraps" gtk_menu_new_from_model() and
    gtk_menu_bar_new_from_model().

 gtk/src/menu.ccg    |    9 +++++++++
 gtk/src/menu.hg     |   18 ++++++++++++++++++
 gtk/src/menubar.ccg |   16 ++++++++++++++++
 gtk/src/menubar.hg  |   17 +++++++++++++++++
 4 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/gtk/src/menu.ccg b/gtk/src/menu.ccg
index 77c1f47..f9f7f34 100644
--- a/gtk/src/menu.ccg
+++ b/gtk/src/menu.ccg
@@ -52,6 +52,15 @@ static void SignalProxy_PopupPosition_gtk_callback_destroy(void* data)
 namespace Gtk
 {
 
+Menu::Menu(const Glib::RefPtr<Gio::MenuModel>& model)
+:
+  _CONSTRUCT()
+{
+  //g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL);
+
+  bind_model(model, true);
+}
+
 void Menu::popup(const SlotPositionCalc& position_calc_slot, guint button, guint32 activate_time, const 
Glib::RefPtr<Gdk::Device>& device)
 {
   // Tell GTK+ to call the static function with the slot's address as the extra
diff --git a/gtk/src/menu.hg b/gtk/src/menu.hg
index 7519a67..5de9439 100644
--- a/gtk/src/menu.hg
+++ b/gtk/src/menu.hg
@@ -45,6 +45,24 @@ class Menu : public MenuShell
 public:
   _CTOR_DEFAULT
 
+  //This is custom-implemented because the gtk_menu_new_from_model() does more
+  //than just call g_object_new. See https://bugzilla.gnome.org/show_bug.cgi?id=704671
+  /** Creates a new Menu and populates it with menu items
+   * and submenus according to the @a model.
+   *
+   * The created menu items are connected to actions found in the
+   * ApplicationWindow to which the menu belongs - typically
+   * by means of being attached to a widget (see attach_to_widget())
+   * that is contained within the ApplicationWindow's widget hierarchy.
+   *
+   * @param model
+   *
+   * @newin{3,10}
+   */
+  explicit Menu(const Glib::RefPtr<Gio::MenuModel>& model);
+  _IGNORE(gtk_menu_new_from_model)
+
+
 /* append, prepend, and insert are defined in MenuShell */
 
   /** For instance,
diff --git a/gtk/src/menubar.ccg b/gtk/src/menubar.ccg
index 34d6eae..3259ef1 100644
--- a/gtk/src/menubar.ccg
+++ b/gtk/src/menubar.ccg
@@ -31,6 +31,22 @@ MenuBar::MenuBar()
   signal_realize().connect(sigc::mem_fun(*this, &MenuBar::init_accels_handler_));
 }
 
+MenuBar::MenuBar(const Glib::RefPtr<Gio::MenuModel>& model)
+:
+  _CONSTRUCT()
+{
+  //g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL);
+
+  bind_model(model, false);
+
+
+  // Connect to the signal instead of overriding the on_hierarchy_changed()
+  // method because invocation of C++ default signal handlers is skipped
+  // for gtkmmproc-generated classes (a gtkmm-wide optimization).
+
+  signal_realize().connect(sigc::mem_fun(*this, &MenuBar::init_accels_handler_));
+}
+
 void MenuBar::init_accels_handler_()
 {
   if(gobj())
diff --git a/gtk/src/menubar.hg b/gtk/src/menubar.hg
index 78424fe..5b848fe 100644
--- a/gtk/src/menubar.hg
+++ b/gtk/src/menubar.hg
@@ -43,6 +43,23 @@ class MenuBar : public MenuShell
 public:
   MenuBar();
 
+  //This is custom-implemented because the gtk_menu_new_from_model() does more
+  //than just call g_object_new. See https://bugzilla.gnome.org/show_bug.cgi?id=704671
+  /** Creates a new MenuBar and populates it with menu items
+   * and submenus according to the @a model.
+   *
+   * The created menu items are connected to actions found in the
+   * ApplicationWindow to which the menu bar belongs - typically
+   * by means of being contained within the ApplicationWindow's
+   * widget hierarchy.
+   *
+   * @param model
+   *
+   * @newin{3,10}
+   */
+  explicit MenuBar(const Glib::RefPtr<Gio::MenuModel>& model);
+  _IGNORE(gtk_menu_bar_new_from_model)
+
   _WRAP_METHOD(PackDirection get_pack_direction () const, gtk_menu_bar_get_pack_direction)
   _WRAP_METHOD(void set_pack_direction(PackDirection pack_dir), gtk_menu_bar_set_pack_direction)
   _WRAP_METHOD(PackDirection get_child_pack_direction() const, gtk_menu_bar_get_child_pack_direction)


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