[gtkmm-documentation/gmenu] gmenu: Port the simple printing example



commit 39a5faea4f8f701ffbcfc20204dc25b8d18530aa
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Aug 7 15:26:41 2013 +0200

    gmenu: Port the simple printing example

 examples/book/printing/simple/examplewindow.cc |   92 ++++++++++++++----------
 examples/book/printing/simple/examplewindow.h  |    3 +-
 2 files changed, 54 insertions(+), 41 deletions(-)
---
diff --git a/examples/book/printing/simple/examplewindow.cc b/examples/book/printing/simple/examplewindow.cc
index f784d3f..5504b8b 100644
--- a/examples/book/printing/simple/examplewindow.cc
+++ b/examples/book/printing/simple/examplewindow.cc
@@ -78,76 +78,90 @@ ExampleWindow::~ExampleWindow()
 void ExampleWindow::build_main_menu()
 {
   //Create actions for menus and toolbars:
-  m_refActionGroup = Gtk::ActionGroup::create();
+  Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup =
+   Gio::SimpleActionGroup::create();
 
   //File menu:
-  m_refActionGroup->add(
-    Gtk::Action::create("FileMenu", "_File"));
-
-  m_refActionGroup->add(
-    Gtk::Action::create("New", Gtk::Stock::NEW),
+  refActionGroup->add_action("new",
     sigc::mem_fun(*this, &ExampleWindow::on_menu_file_new));
 
-  m_refActionGroup->add(
-    Gtk::Action::create("PageSetup", "Page _Setup"),
+  refActionGroup->add_action("pagesetup",
     sigc::mem_fun(*this, &ExampleWindow::on_menu_file_page_setup));
 
-  m_refActionGroup->add(
-    Gtk::Action::create("PrintPreview", "Print Preview"),
+  refActionGroup->add_action("printpreview",
     sigc::mem_fun(*this, &ExampleWindow::on_menu_file_print_preview));
 
-  m_refActionGroup->add(
-    Gtk::Action::create("Print", Gtk::Stock::PRINT),
+  refActionGroup->add_action("print",
     sigc::mem_fun(*this, &ExampleWindow::on_menu_file_print));
 
-  m_refActionGroup->add(
-    Gtk::Action::create("Quit", Gtk::Stock::QUIT),
+  refActionGroup->add_action("quit",
     sigc::mem_fun(*this, &ExampleWindow::on_menu_file_quit));
 
-  m_refUIManager = Gtk::UIManager::create();
-  m_refUIManager->insert_action_group(m_refActionGroup);
+  insert_action_group("example", refActionGroup);
 
-  add_accel_group(m_refUIManager->get_accel_group());
+  m_refBuilder = Gtk::Builder::create();
+ 
+  //TODO: add_accel_group(m_refBuilder->get_accel_group());
 
   //Layout the actions in a menubar and toolbar:
-
-  Glib::ustring ui_info =
-        "<ui>"
-        "  <menubar name='MenuBar'>"
-        "    <menu action='FileMenu'>"
-        "      <menuitem action='New'/>"
-        "      <menuitem action='PageSetup'/>"
-        "      <menuitem action='PrintPreview'/>"
-        "      <menuitem action='Print'/>"
-        "      <separator/>"
-        "      <menuitem action='Quit'/>"
-        "    </menu>"
-        "  </menubar>"
-        "  <toolbar  name='ToolBar'>"
+  
+  Glib::ustring ui_info = 
+   "<interface>"
+    "  <menu id='menu-example'>"
+    "    <submenu>"
+    "      <attribute name='label' translatable='yes'>_File</attribute>"
+    "      <section>"
+    "        <item>"
+    "          <attribute name='label' translatable='yes'>Page _Setup</attribute>"
+    "          <attribute name='action'>example.pagesetup</attribute>"
+    "        </item>"
+    "        <item>"
+    "          <attribute name='label' translatable='yes'>Print Preview</attribute>"
+    "          <attribute name='action'>example.printpreview</attribute>"
+    "        </item>"
+    "        <item>"
+    "          <attribute name='label' translatable='yes'>_Print</attribute>"
+    "          <attribute name='action'>example.print</attribute>"
+    "        </item>"
+    "      </section>"
+    "    </submenu>"
+    "  </menu>"
+/* TODO:
+      "  <toolbar  name='ToolBar'>"
         "    <toolitem action='New'/>"
         "    <toolitem action='Print'/>"
         "      <separator/>"
         "    <toolitem action='Quit'/>"
         "  </toolbar>"
-        "</ui>";
+*/
+    "</interface>";
 
   try
-  {
-    m_refUIManager->add_ui_from_string(ui_info);
+  {      
+    m_refBuilder->add_from_string(ui_info);
   }
   catch(const Glib::Error& ex)
   {
     std::cerr << "building menus failed: " << ex.what();
   }
 
-  //Get the menubar and toolbar widgets, and add them to a container widget:
-  Gtk::Widget* pMenubar = m_refUIManager->get_widget("/MenuBar");
-  if(pMenubar)
-    m_VBox.pack_start(*pMenubar, Gtk::PACK_SHRINK);
 
-  Gtk::Widget* pToolbar = m_refUIManager->get_widget("/ToolBar") ;
+  //Get the menubar and toolbar widgets, and add them to a container widget:
+  Glib::RefPtr<Glib::Object> object =
+    m_refBuilder->get_object("menu-example");
+  Glib::RefPtr<Gio::Menu> gmenu =
+    Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
+  if(!gmenu)
+    g_warning("GMenu not found");
+
+  Gtk::MenuBar* pMenubar = new Gtk::MenuBar(gmenu);
+  m_VBox.pack_start(*pMenubar, Gtk::PACK_SHRINK);
+
+/* TODO:
+  Gtk::Widget* pToolbar = m_refBuilder->get_widget("/ToolBar") ;
   if(pToolbar)
     m_VBox.pack_start(*pToolbar, Gtk::PACK_SHRINK);
+*/
 }
 
 void ExampleWindow::on_printoperation_status_changed(
diff --git a/examples/book/printing/simple/examplewindow.h b/examples/book/printing/simple/examplewindow.h
index ce80a18..1297fbf 100644
--- a/examples/book/printing/simple/examplewindow.h
+++ b/examples/book/printing/simple/examplewindow.h
@@ -71,8 +71,7 @@ protected:
   unsigned m_ContextId;
   Gtk::Statusbar m_Statusbar;
 
-  Glib::RefPtr<Gtk::UIManager> m_refUIManager;
-  Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
+  Glib::RefPtr<Gtk::Builder> m_refBuilder;
 };
 
 #endif //GTKMM_EXAMPLEWINDOW_H


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