[gtkmm] Demos, tests: Update for the latest gtk4 (remove menus demo, etc.)



commit b5dc66011f91552e1315120644ab41491614bd82
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Thu Jan 9 15:11:20 2020 +0100

    Demos, tests: Update for the latest gtk4 (remove menus demo, etc.)
    
    Remove Change Display demo and Menus demo. The corresponding gtk demos
    have been removed.
    
    Convert the Builder demo to a menu model, as in gtk.
    
    Make the RGBA test work when Gdk::RGBA uses float instead of double.

 demos/Makefile.am                        |   2 -
 demos/gtk-demo/demo.gresource.xml        |   2 -
 demos/gtk-demo/demos.h                   |   4 -
 demos/gtk-demo/example_appwindow.cc      |   2 +-
 demos/gtk-demo/example_builder.cc        |  61 ++----
 demos/gtk-demo/example_builder.ui        | 173 ++++++---------
 demos/gtk-demo/example_change_display.cc | 366 -------------------------------
 demos/gtk-demo/example_menus.cc          | 177 ---------------
 tests/Makefile.am                        |   2 -
 tests/gdk_rgba/main.cc                   |  36 ++-
 10 files changed, 116 insertions(+), 709 deletions(-)
---
diff --git a/demos/Makefile.am b/demos/Makefile.am
index 0fa482de..483bd777 100644
--- a/demos/Makefile.am
+++ b/demos/Makefile.am
@@ -38,7 +38,6 @@ dist_noinst_DATA = \
 GTK_DEMOS = \
   gtk-demo/example_appwindow.cc \
   gtk-demo/example_builder.cc \
-  gtk-demo/example_change_display.cc \
   gtk-demo/example_colorsel.cc \
   gtk-demo/example_dialog.cc \
   gtk-demo/example_drawingarea.cc \
@@ -49,7 +48,6 @@ GTK_DEMOS = \
   gtk-demo/example_iconbrowser.cc \
   gtk-demo/example_iconview.cc \
   gtk-demo/example_images.cc \
-  gtk-demo/example_menus.cc \
   gtk-demo/example_overlay.cc \
   gtk-demo/example_panes.cc \
   gtk-demo/example_pixbufs.cc \
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index b800b455..a55e0be4 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -39,7 +39,6 @@
   <gresource prefix="/sources">
     <file>example_appwindow.cc</file>
     <file>example_builder.cc</file>
-    <file>example_change_display.cc</file>
     <file>example_colorsel.cc</file>
     <file>example_dialog.cc</file>
     <file>example_drawingarea.cc</file>
@@ -50,7 +49,6 @@
     <file>example_iconbrowser.cc</file>
     <file>example_iconview.cc</file>
     <file>example_images.cc</file>
-    <file>example_menus.cc</file>
     <file>example_overlay.cc</file>
     <file>example_panes.cc</file>
     <file>example_pixbufs.cc</file>
diff --git a/demos/gtk-demo/demos.h b/demos/gtk-demo/demos.h
index 794460f1..12bab82a 100644
--- a/demos/gtk-demo/demos.h
+++ b/demos/gtk-demo/demos.h
@@ -15,7 +15,6 @@ struct Demo
 
 Gtk::Window* do_appwindow();
 Gtk::Window* do_builder();
-Gtk::Window* do_change_display();
 Gtk::Window* do_colorsel();
 Gtk::Window* do_dialog();
 Gtk::Window* do_drawingarea();
@@ -26,7 +25,6 @@ Gtk::Window* do_headerbar();
 Gtk::Window* do_iconbrowser();
 Gtk::Window* do_iconview();
 Gtk::Window* do_images();
-Gtk::Window* do_menus();
 Gtk::Window* do_overlay();
 Gtk::Window* do_panes();
 Gtk::Window* do_pixbufs();
@@ -52,7 +50,6 @@ Demo testgtk_demos[] =
 {
   { "Application main window", "example_appwindow.cc", sigc::ptr_fun(&do_appwindow), nullptr },
   { "Builder", "example_builder.cc", sigc::ptr_fun(&do_builder), nullptr },
-  { "Change Display", "example_change_display.cc", sigc::ptr_fun(&do_change_display), nullptr },
   { "Color Chooser", "example_colorsel.cc", sigc::ptr_fun(&do_colorsel), nullptr },
   { "Dialog and Message Boxes", "example_dialog.cc", sigc::ptr_fun(&do_dialog), nullptr },
   { "Drawing Area", "example_drawingarea.cc", sigc::ptr_fun(&do_drawingarea), nullptr },
@@ -62,7 +59,6 @@ Demo testgtk_demos[] =
   { "Icon Browser", "example_iconbrowser.cc", sigc::ptr_fun(&do_iconbrowser), nullptr },
   { "Icon View", "example_iconview.cc", sigc::ptr_fun(&do_iconview), nullptr },
   { "Images", "example_images.cc", sigc::ptr_fun(&do_images), nullptr },
-  { "Menus", "example_menus.cc", sigc::ptr_fun(&do_menus), nullptr },
   { "OpenGL Area", "example_glarea.cc", sigc::ptr_fun(&do_glarea), nullptr },
   { "Overlay", "example_overlay.cc", sigc::ptr_fun(&do_overlay), nullptr },
   { "Paned Widgets", "example_panes.cc", sigc::ptr_fun(&do_panes), nullptr },
diff --git a/demos/gtk-demo/example_appwindow.cc b/demos/gtk-demo/example_appwindow.cc
index d998eeec..4ff63396 100644
--- a/demos/gtk-demo/example_appwindow.cc
+++ b/demos/gtk-demo/example_appwindow.cc
@@ -19,7 +19,7 @@ protected:
 
   //Member widgets:
   Gtk::Grid m_Grid;
-  Gtk::Menu m_Menubar;
+  //Gtk::Menu m_Menubar;
   Gtk::Toolbar m_Toolbar;
   Gtk::ScrolledWindow m_ScrolledWindow;
   Gtk::Statusbar m_Statusbar;
diff --git a/demos/gtk-demo/example_builder.cc b/demos/gtk-demo/example_builder.cc
index 66ea527b..96b9811e 100644
--- a/demos/gtk-demo/example_builder.cc
+++ b/demos/gtk-demo/example_builder.cc
@@ -18,6 +18,7 @@ protected:
   void on_file_quit();
   void on_help_about();
   void on_help_help();
+  void on_not_implemented();
 
   Glib::RefPtr<Gtk::Builder> m_builder;
 };
@@ -60,55 +61,14 @@ Example_Builder::Example_Builder(
   refActions->add_action("quit", sigc::mem_fun(*this, &Example_Builder::on_file_quit));
   refActions->add_action("about", sigc::mem_fun(*this, &Example_Builder::on_help_about));
   refActions->add_action("help", sigc::mem_fun(*this, &Example_Builder::on_help_help));
+  refActions->add_action("new", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
+  refActions->add_action("open", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
+  refActions->add_action("save", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
+  refActions->add_action("save-as", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
+  refActions->add_action("copy", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
+  refActions->add_action("cut", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
+  refActions->add_action("paste", sigc::mem_fun(*this, &Example_Builder::on_not_implemented));
   insert_action_group("win", refActions);
-
-  auto refAccelGroup = Gtk::AccelGroup::create();
-  add_accel_group(refAccelGroup);
-
-  auto pMenuItem = builder->get_widget<Gtk::MenuItem>("new_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_n, Gdk::ModifierType::CONTROL_MASK, Gtk::AccelFlags::VISIBLE);
-
-  pMenuItem = builder->get_widget<Gtk::MenuItem>("open_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_o, Gdk::ModifierType::CONTROL_MASK, Gtk::AccelFlags::VISIBLE);
-
-  pMenuItem = builder->get_widget<Gtk::MenuItem>("save_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_s, Gdk::ModifierType::CONTROL_MASK, Gtk::AccelFlags::VISIBLE);
-
-  pMenuItem = builder->get_widget<Gtk::MenuItem>("quit_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_q, Gdk::ModifierType::CONTROL_MASK, Gtk::AccelFlags::VISIBLE);
-
-  pMenuItem = builder->get_widget<Gtk::MenuItem>("copy_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_c, Gdk::ModifierType::CONTROL_MASK, Gtk::AccelFlags::VISIBLE);
-
-  pMenuItem = builder->get_widget<Gtk::MenuItem>("cut_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_x, Gdk::ModifierType::CONTROL_MASK, Gtk::AccelFlags::VISIBLE);
-
-  pMenuItem = builder->get_widget<Gtk::MenuItem>("paste_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_v, Gdk::ModifierType::CONTROL_MASK, Gtk::AccelFlags::VISIBLE);
-
-  pMenuItem = builder->get_widget<Gtk::MenuItem>("help_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_F1, (Gdk::ModifierType)0, Gtk::AccelFlags::VISIBLE);
-
-  pMenuItem = builder->get_widget<Gtk::MenuItem>("about_item");
-  if (pMenuItem)
-    pMenuItem->add_accelerator("activate", refAccelGroup,
-      GDK_KEY_F7, (Gdk::ModifierType)0, Gtk::AccelFlags::VISIBLE);
 }
 
 Example_Builder::~Example_Builder()
@@ -135,3 +95,8 @@ void Example_Builder::on_help_help()
 {
   std::cout << "Help not available." << std::endl;
 }
+
+void Example_Builder::on_not_implemented()
+{
+  std::cout << "The selected menu item is not implemented." << std::endl;
+}
diff --git a/demos/gtk-demo/example_builder.ui b/demos/gtk-demo/example_builder.ui
index 70e180a9..40df0b64 100644
--- a/demos/gtk-demo/example_builder.ui
+++ b/demos/gtk-demo/example_builder.ui
@@ -22,6 +22,75 @@
       </row>
     </data>
   </object>
+  <menu id="menubar">
+    <submenu>
+      <attribute name="label" translatable="yes">_File</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_New</attribute>
+          <attribute name="action">win.new</attribute>
+          <attribute name="accel">&lt;Primary&gt;n</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Open</attribute>
+          <attribute name="action">win.open</attribute>
+          <attribute name="accel">&lt;Primary&gt;o</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Save</attribute>
+          <attribute name="action">win.save</attribute>
+          <attribute name="accel">&lt;Primary&gt;s</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Save _As</attribute>
+          <attribute name="action">win.save-as</attribute>
+          <attribute name="accel">&lt;Primary&gt;q</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Quit</attribute>
+          <attribute name="action">win.quit</attribute>
+          <attribute name="accel">&lt;Primary&gt;&lt;Shift&gt;s</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name="label" translatable="yes">_Edit</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Copy</attribute>
+          <attribute name="action">win.copy</attribute>
+          <attribute name="accel">&lt;Primary&gt;c</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Cut</attribute>
+          <attribute name="action">win.cut</attribute>
+          <attribute name="accel">&lt;Primary&gt;x</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Paste</attribute>
+          <attribute name="action">win.paste</attribute>
+          <attribute name="accel">&lt;Primary&gt;v</attribute>
+        </item>
+      </section>
+    </submenu>
+    <submenu>
+      <attribute name="label" translatable="yes">_Help</attribute>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Help</attribute>
+          <attribute name="action">win.help</attribute>
+          <attribute name="accel">F1</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_About</attribute>
+          <attribute name="action">win.about</attribute>
+          <attribute name="accel">F7</attribute>
+        </item>
+      </section>
+    </submenu>
+  </menu>
   <object class="GtkAboutDialog" id="aboutdialog1">
     <property name="program-name" translatable="yes">Gtk::Builder demo</property>
     <property name="logo-icon-name" translatable="yes">gtk3-demo</property>
@@ -37,108 +106,8 @@
       <object class="GtkBox" id="vbox1">
         <property name="orientation">vertical</property>
         <child>
-          <object class="GtkMenuBar" id="menubar1">
-            <child internal-child="accessible">
-              <object class="AtkObject" id="a11y-menubar">
-                <property name="AtkObject::accessible-name">The menubar</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkMenuItem">
-                <property name="label" translatable="yes">_File</property>
-                <property name="use-underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu">
-                    <child>
-                      <object class="GtkMenuItem" id="new_item">
-                        <property name="label" translatable="yes">_New</property>
-                        <property name="use-underline">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="open_item">
-                        <property name="label" translatable="yes">_Open</property>
-                        <property name="use-underline">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="save_item">
-                        <property name="label" translatable="yes">_Save</property>
-                        <property name="use-underline">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="save_as_item">
-                        <property name="label" translatable="yes">Save _As</property>
-                        <property name="use-underline">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem"/>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="quit_item">
-                        <property name="label" translatable="yes">_Quit</property>
-                        <property name="use-underline">True</property>
-                        <property name="action-name">win.quit</property>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="GtkMenuItem">
-                <property name="label" translatable="yes">_Edit</property>
-                <property name="use-underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu">
-                    <child>
-                      <object class="GtkMenuItem" id="copy_item">
-                        <property name="label" translatable="yes">_Copy</property>
-                        <property name="use-underline">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="cut_item">
-                        <property name="label" translatable="yes">_Cut</property>
-                        <property name="use-underline">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="paste_item">
-                        <property name="label" translatable="yes">_Paste</property>
-                        <property name="use-underline">True</property>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="GtkMenuItem">
-                <property name="label" translatable="yes">_Help</property>
-                <property name="use-underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu">
-                    <child>
-                      <object class="GtkMenuItem" id="help_item">
-                        <property name="label" translatable="yes">_Help</property>
-                        <property name="use-underline">True</property>
-                        <property name="action-name">win.help</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="about_item">
-                        <property name="label" translatable="yes">_About</property>
-                        <property name="use-underline">True</property>
-                        <property name="action-name">win.about</property>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
+          <object class="GtkPopoverMenuBar" id="menubar1">
+            <property name="menu-model">menubar</property>
           </object>
         </child>
         <child>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f4139278..e15d3111 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -26,7 +26,6 @@ check_PROGRAMS =                      \
        dialog_deletethis/test          \
        gdk_rgba/test \
        main_with_options/test          \
-       menu_destruction/test           \
        object_move/test                \
        property_notification/test      \
        refcount_dialog/test            \
@@ -48,7 +47,6 @@ delete_cpp_child_test_SOURCES      = delete_cpp_child/main.cc
 dialog_deletethis_test_SOURCES     = dialog_deletethis/main.cc
 gdk_rgba_test_SOURCES              = gdk_rgba/main.cc
 main_with_options_test_SOURCES     = main_with_options/main.cc
-menu_destruction_test_SOURCES      = menu_destruction/main.cc
 object_move_test_SOURCES           = object_move/main.cc
 property_notification_test_SOURCES = property_notification/main.cc
 refcount_dialog_test_SOURCES       = refcount_dialog/main.cc
diff --git a/tests/gdk_rgba/main.cc b/tests/gdk_rgba/main.cc
index d692cffd..4cee2a78 100644
--- a/tests/gdk_rgba/main.cc
+++ b/tests/gdk_rgba/main.cc
@@ -1,8 +1,34 @@
+// Test Gdk::RGBA
+// https://gitlab.gnome.org/GNOME/gtkmm/issues/40
+// https://gitlab.gnome.org/GNOME/gtkmm/issues/42
+// https://gitlab.gnome.org/GNOME/gtkmm/merge_requests/7
+// https://gitlab.gnome.org/GNOME/gtkmm/merge_requests/8
+
 #include <gdkmm/rgba.h>
 #include <glib.h>
+#include <limits>
+#include <cmath>
+
+// It's usually not safe to compare floating-point numbers for exact equality.
+// In this test program, most (but not all) such comparisons are safe.
+// Where compared colors can't be expected to be exactly equal, but should
+// have been exactly equal, had all calculations been made with infinit precision,
+// then they are compared with is_almost_equal().
 
-int
-main()
+namespace
+{
+bool is_almost_equal(const Gdk::RGBA& lhs, const Gdk::RGBA& rhs)
+{
+  constexpr float tolerance = 10 * std::numeric_limits<float>::epsilon();
+
+  return std::abs(lhs.get_red() - rhs.get_red()) <= tolerance
+      && std::abs(lhs.get_green() - rhs.get_green()) <= tolerance
+      && std::abs(lhs.get_blue() - rhs.get_blue()) <= tolerance
+      && std::abs(lhs.get_alpha() - rhs.get_alpha()) <= tolerance;
+}
+} // anonymous namespace
+
+int main()
 {
   // A default-constructed RGBA is black and fully transparent
   auto rgba = Gdk::RGBA{};
@@ -45,11 +71,11 @@ main()
   rgba2.set_hsv(360.0, 1.0, 1.0);
   g_assert_true(rgba == rgba2);
 
-  // Test HSL the same way
+  // Test HSL almost the same way
   rgba2.set_hsl(0.0, 1.0, 0.5);
-  g_assert_true(rgba == rgba2);
+  g_assert_true(is_almost_equal(rgba, rgba2));
   rgba2.set_hsl(360.0, 1.0, 0.5);
-  g_assert_true(rgba == rgba2);
+  g_assert_true(is_almost_equal(rgba, rgba2));
 
   return 0;
 }


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