[dia] [gtk-osx] use gtk-mac-integration for mac global menu



commit edfbefdcd71c38ffdc198670f422d2c5906a8566
Author: Hans Breuer <hans breuer org>
Date:   Sun Jan 26 15:44:32 2014 +0100

    [gtk-osx] use gtk-mac-integration for mac global menu
    
    Top menu integration mostly working based on
    http://gtk-osx.sourceforge.net/gtk-mac-integration/index.html

 app/Makefile.am |    4 +++-
 app/interface.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.in    |   14 +++++++++++++-
 3 files changed, 68 insertions(+), 2 deletions(-)
---
diff --git a/app/Makefile.am b/app/Makefile.am
index 782611b..252bdd2 100644
--- a/app/Makefile.am
+++ b/app/Makefile.am
@@ -8,6 +8,7 @@ INCLUDES = \
        -I$(top_srcdir)/lib \
        $(DEBUG_FLAGS) \
        $(GTK_CFLAGS) \
+       $(GTK_MAC_CFLAGS) \ 
        $(LIBART_CFLAGS) \
        -DPREFIX=\""$(prefix)"\" \
        -DSYSCONFDIR=\""$(sysconfdir)"\" \
@@ -220,7 +221,8 @@ EFENCE =
 
 dia_LDADD = ../lib/libdia.la \
        $(EFENCE) \
-       $(APP_LIBS) $(Z_LIBS) $(FREETYPE_LIBS) $(GTK_LIBS) $(PNG_LIBS) $(INTLLIBS) $(INTLOBJS) $(XML_LIBS) 
$(LIBART_LIBS) $(GLIB_LIBS)
+       $(APP_LIBS) $(Z_LIBS) $(FREETYPE_LIBS) $(GTK_LIBS) $(PNG_LIBS) $(INTLLIBS) $(INTLOBJS) \
+       $(XML_LIBS) $(LIBART_LIBS) $(GLIB_LIBS) $(GTK_MAC_LIBS)
 
 ## Bonobo embeddable dia. Commented out, because it's a bit raw.
 ## Especially the configure/make parts.
diff --git a/app/interface.c b/app/interface.c
index 1d11680..bf04e3b 100644
--- a/app/interface.c
+++ b/app/interface.c
@@ -24,6 +24,10 @@
 #else
 #include <gtk/gtk.h>
 #endif
+/* this file should be the only place to include it */
+#ifdef HAVE_MAC_INTEGRATION
+#include <gtkosxapplication.h>
+#endif
 
 #include <stdio.h>
 #include <string.h>
@@ -904,6 +908,46 @@ app_set_icon (GtkWindow *window)
   }
 }
 
+#ifdef HAVE_MAC_INTEGRATION
+static void
+_create_mac_integration (void)
+{
+  GtkosxApplication *theOsxApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
+  GtkWidget *menubar = NULL;
+
+  /* from control-x to command-x in one call? Does _not_ work as advertized */
+  gtkosx_application_set_use_quartz_accelerators (theOsxApp, TRUE);
+  /* might be too early ... */
+  menus_get_integrated_ui_menubar (&menubar, NULL, NULL);
+  if (menubar) {
+    gtk_widget_hide (menubar); /* not working, it's shown elsewhere */
+    /* move some items to the dia menu */
+    {
+      GSList *proxies, *proxy;
+      GtkAction *action;
+
+      action = menus_get_action ("HelpAbout");
+      proxies = gtk_action_get_proxies (action);
+
+      for (proxy = proxies; proxy != NULL; proxy = g_slist_next (proxy)) {
+        g_print ("XXX ");
+        if (1 || GTK_IS_MENU_ITEM (proxy->data)) {
+          gtkosx_application_insert_app_menu_item (theOsxApp, GTK_WIDGET (proxy->data), 0);
+          break;
+        }
+      }     
+    }
+    /* hijack the menubar */
+    gtkosx_application_set_menu_bar(theOsxApp, GTK_MENU_SHELL(menubar));
+    /* setup the dock icon */
+    gtkosx_application_set_dock_icon_pixbuf (theOsxApp,
+       gdk_pixbuf_new_from_inline (-1, dia_app_icon, FALSE, NULL));
+  }
+  /* without this all the above wont have any effect */
+  gtkosx_application_ready(theOsxApp);
+}
+#endif
+
 /**
  * Create integrated user interface
  */
@@ -993,8 +1037,12 @@ create_integrated_ui (void)
 #ifdef HAVE_GNOME
   gnome_app_set_menus (GNOME_APP (window), GTK_MENU_BAR (menubar));
 #else
+#  ifdef HAVE_MAC_INTEGRATION
+  _create_mac_integration ();
+#  else
   gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0);
   gtk_widget_show (menubar);
+#  endif
 #endif
 
   /* Toolbar */
@@ -1074,8 +1122,12 @@ create_toolbox ()
 #ifdef HAVE_GNOME
   gnome_app_set_menus(GNOME_APP(window), GTK_MENU_BAR(menubar));
 #else
+#  ifdef HAVE_MAC_INTEGRATION
+  _create_mac_integration ();
+#  else
   gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0);
   gtk_widget_show (menubar);
+#  endif
 #endif
   persistence_register_window(GTK_WINDOW(window));
 
diff --git a/configure.in b/configure.in
index bfca467..d81a8b7 100644
--- a/configure.in
+++ b/configure.in
@@ -73,7 +73,7 @@ AC_SUBST(GMODULE_LIBS)
 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
 
 GTK_MODULES="gtk+-2.0 >= 2.16.0 glib-2.0 >= 2.20.0 libxml-2.0 gdk-pixbuf-2.0 gthread-2.0 gmodule-2.0"
-PKG_CHECK_MODULES(PANGOVERSION, pango >= 1.20.0, , 
+PKG_CHECK_MODULES(PANGOVERSION, pango >= 1.20.0 pangocairo, , 
                   AC_MSG_ERROR([Need Pango version 1.20.0 or higher]))
 
 AC_ARG_WITH(freetype,
@@ -154,6 +154,18 @@ PKG_CHECK_MODULES(GTK,$GTK_MODULES)
 AC_SUBST(GTK_CFLAGS)
 AC_SUBST(GTK_LIBS)
 
+### --------------------------------------------------------------------------
+### Check to see if GDK uses the quartz backend and if we can use 
+### MacOSX integration
+_gdk_tgt=`$PKG_CONFIG --variable=target gdk-2.0`
+AM_CONDITIONAL([GDK_TARGET_QUARTZ], [test x$_gdk_tgt = xquartz])
+if test "x$_gdk_tgt" = xquartz; then 
+    PKG_CHECK_MODULES(GTK_MAC, gtk-mac-integration)
+    AC_SUBST(GTK_MAC_LIBS)
+    AC_SUBST(GTK_MAC_CFLAGS)
+    AC_DEFINE(HAVE_MAC_INTEGRATION,1,[Define if building with gtk-mac-integration])
+fi
+
 AM_CONDITIONAL(HAVE_BONOBO,[test "true" = "false"])
 
 dnl Look for Cairo


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