[gtkmm] Update the Menus demo
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Update the Menus demo
- Date: Mon, 12 Feb 2018 12:23:28 +0000 (UTC)
commit e90c22c611704864904faea9a1d651755c50293e
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Mon Feb 12 13:20:39 2018 +0100
Update the Menus demo
Don't mention the removed ImageMenuItem in the description.
Show the menu with accelerator keys.
demos/gtk-demo/example_menus.cc | 43 +++++++++++++++++++++++++++-----------
1 files changed, 30 insertions(+), 13 deletions(-)
---
diff --git a/demos/gtk-demo/example_menus.cc b/demos/gtk-demo/example_menus.cc
index 47bad09..51c9d90 100644
--- a/demos/gtk-demo/example_menus.cc
+++ b/demos/gtk-demo/example_menus.cc
@@ -11,8 +11,7 @@
* There are several kinds of menu item, including plain Gtk::MenuItem,
* Gtk::CheckMenuItem which can be checked/unchecked, Gtk::RadioMenuItem
* which is a check menu item that's in a mutually exclusive group,
- * Gtk::SeparatorMenuItem which is a separator bar, and Gtk::ImageMenuItem which
- * can place a Gtk::Image or other widget next to the menu text.
+ * and Gtk::SeparatorMenuItem which is a separator bar.
*
* A Gtk::MenuItem can have a submenu, which is simply a Gtk::Menu to pop
* up when the menu item is selected. Typically, all menu items in a menu bar
@@ -24,7 +23,7 @@
*/
#include <gtkmm.h>
-#include <stdio.h>
+#include <iostream>
class Example_Menus : public Gtk::Window
{
@@ -34,12 +33,12 @@ public:
protected:
//signal handlers:
- virtual void on_button_clicked();
+ void on_button_clicked();
+ void on_item_activated(const Glib::ustring& item);
- virtual Gtk::Menu* create_menu(gint depth);
+ Gtk::Menu* create_menu(gint depth);
//Member widgets:
- Gtk::Frame m_Frame_Horizontal, m_Frame_Vertical;
Gtk::Box m_VBox1, m_VBox_Sub1, m_VBox_Sub2;
Gtk::MenuBar m_MenuBar;
Gtk::Separator m_Separator;
@@ -84,7 +83,7 @@ Example_Menus::Example_Menus()
}
- m_VBox_Sub1.property_margin() = 10;
+ m_VBox_Sub1.set_margin(10);
m_VBox1.pack_start(m_VBox_Sub1, Gtk::PackOptions::EXPAND_WIDGET);
{
@@ -95,26 +94,39 @@ Example_Menus::Example_Menus()
pMenu->append(*pMenuItem);
pMenuItem->show();
+ pMenuItem = Gtk::manage(new Gtk::MenuItem("accel"));
+ pMenuItem->set_submenu(*pMenu);
+ m_MenuBar.append(*pMenuItem);
+ pMenuItem->show();
+
pMenuItem = Gtk::manage(new Gtk::CheckMenuItem("Accelerate Me"));
- pMenuItem->add_accelerator("activate", get_accel_group(), GDK_KEY_F1, Gdk::ModifierType(0),
Gtk::AccelFlags::VISIBLE);
+ pMenuItem->add_accelerator("activate", get_accel_group(), GDK_KEY_F1,
+ Gdk::ModifierType(0), Gtk::AccelFlags::VISIBLE);
pMenu->append(*pMenuItem);
pMenuItem->show();
+ pMenuItem->signal_activate().connect(
+ sigc::bind(sigc::mem_fun(*this, &Example_Menus::on_item_activated), "F1"));
pMenuItem = Gtk::manage(new Gtk::CheckMenuItem("Accelerator Locked"));
pMenu->append(*pMenuItem);
- pMenuItem->add_accelerator("activate", get_accel_group(), GDK_KEY_F2, Gdk::ModifierType(0),
Gtk::AccelFlags::VISIBLE | Gtk::AccelFlags::LOCKED);
+ pMenuItem->add_accelerator("activate", get_accel_group(), GDK_KEY_F2,
+ Gdk::ModifierType(0), Gtk::AccelFlags::VISIBLE | Gtk::AccelFlags::LOCKED);
pMenuItem->show();
+ pMenuItem->signal_activate().connect(
+ sigc::bind(sigc::mem_fun(*this, &Example_Menus::on_item_activated), "F2"));
pMenuItem = Gtk::manage(new Gtk::CheckMenuItem("Accelerator Frozen"));
pMenu->append(*pMenuItem);
- pMenuItem->add_accelerator("activate", get_accel_group(), GDK_KEY_F2, Gdk::ModifierType(0),
Gtk::AccelFlags::VISIBLE);
+ pMenuItem->add_accelerator("activate", get_accel_group(), GDK_KEY_F3,
+ Gdk::ModifierType(0), Gtk::AccelFlags::VISIBLE);
pMenuItem->show();
+ pMenuItem->signal_activate().connect(
+ sigc::bind(sigc::mem_fun(*this, &Example_Menus::on_item_activated), "F3"));
}
m_VBox1.pack_start(m_Separator, Gtk::PackOptions::SHRINK);
-
- m_VBox_Sub2.property_margin() = 10;
+ m_VBox_Sub2.set_margin(10);
m_VBox1.pack_start(m_VBox_Sub2, Gtk::PackOptions::SHRINK);
m_Button.signal_clicked().connect(sigc::mem_fun(*this, &Example_Menus::on_button_clicked));
@@ -122,7 +134,7 @@ Example_Menus::Example_Menus()
m_VBox_Sub2.pack_start(m_Button, Gtk::PackOptions::EXPAND_WIDGET);
m_VBox_Sub2.set_vexpand(false);
- m_Button.property_can_default() = true;
+ m_Button.set_can_default(true);
m_Button.grab_default();
}
@@ -161,6 +173,11 @@ Gtk::Menu* Example_Menus::create_menu(gint depth)
return pMenu;
}
+void Example_Menus::on_item_activated(const Glib::ustring& item)
+{
+ std::cout << "Item " << item << " was activated" << std::endl;
+}
+
void Example_Menus::on_button_clicked()
{
hide();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]