[gtk+] Introduce gtkaccelmapprivate.h



commit 2398d7e900708bca24cf38bba9d87c920d7bb69f
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 5 17:37:04 2011 -0500

    Introduce gtkaccelmapprivate.h
    
    Move internal accel map API there and update all users.
    Also, add an internal function to create an accel path for
    an action and parameter, and use it in gtkapplication.c and
    gtkmodelmenuitem.c instead of duplicating that code.

 gtk/Makefile.am          |    1 +
 gtk/gtkaccelmap.c        |   19 ++++++++++++++++++-
 gtk/gtkaccelmap.h        |   10 ----------
 gtk/gtkaccelmapprivate.h |   45 +++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkapplication.c     |   23 +++--------------------
 gtk/gtkmain.c            |    2 +-
 gtk/gtkmodelmenuitem.c   |   20 ++------------------
 gtk/gtkwidget.c          |    2 +-
 8 files changed, 71 insertions(+), 51 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index d1cafc5..c5cd39a 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -395,6 +395,7 @@ gtk_private_h_sources =		\
 	gactionobserver.h	\
 	gactionobservable.h	\
 	gtkaccelgroupprivate.h	\
+	gtkaccelmapprivate.h	\
 	gtkanimationdescription.h \
 	gtkappchooserprivate.h	\
 	gtkappchoosermodule.h	\
diff --git a/gtk/gtkaccelmap.c b/gtk/gtkaccelmap.c
index efc06ba..2f33b92 100644
--- a/gtk/gtkaccelmap.c
+++ b/gtk/gtkaccelmap.c
@@ -19,7 +19,7 @@
 
 #include "config.h"
 
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 
 #include "gtkmarshalers.h"
 #include "gtkwindowprivate.h"
@@ -1066,3 +1066,20 @@ do_accel_map_changed (AccelEntry *entry)
 		   entry->accel_key,
 		   entry->accel_mods);
 }
+
+gchar *
+_gtk_accel_path_for_action (const gchar *action_name,
+                            GVariant    *parameter)
+{
+  GString *s;
+
+  s = g_string_new ("<Actions>/");
+  g_string_append (s, action_name);
+  if (parameter)
+    {
+      g_string_append_c (s, '/');
+      g_variant_print_string (parameter, s, FALSE);
+    }
+  return g_string_free (s, FALSE);
+}
+
diff --git a/gtk/gtkaccelmap.h b/gtk/gtkaccelmap.h
index dfce2b8..d55318e 100644
--- a/gtk/gtkaccelmap.h
+++ b/gtk/gtkaccelmap.h
@@ -90,16 +90,6 @@ GType        gtk_accel_map_get_type (void) G_GNUC_CONST;
 GtkAccelMap *gtk_accel_map_get      (void);
 
 
-/* --- internal API --- */
-void		_gtk_accel_map_init		(void);
-
-void            _gtk_accel_map_add_group	 (const gchar   *accel_path,
-						  GtkAccelGroup *accel_group);
-void            _gtk_accel_map_remove_group 	 (const gchar   *accel_path,
-						  GtkAccelGroup *accel_group);
-gboolean	_gtk_accel_path_is_valid	 (const gchar	*accel_path);
-
-
 G_END_DECLS
 
 #endif /* __GTK_ACCEL_MAP_H__ */
diff --git a/gtk/gtkaccelmapprivate.h b/gtk/gtkaccelmapprivate.h
new file mode 100644
index 0000000..52843af
--- /dev/null
+++ b/gtk/gtkaccelmapprivate.h
@@ -0,0 +1,45 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1998, 2001 Tim Janik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_ACCEL_MAP_PRIVATE_H__
+#define __GTK_ACCEL_MAP_PRIVATE_H__
+
+
+#include <gtk/gtkaccelmap.h>
+
+G_BEGIN_DECLS
+
+void            _gtk_accel_map_init         (void);
+
+void            _gtk_accel_map_add_group    (const gchar   *accel_path,
+                                             GtkAccelGroup *accel_group);
+void            _gtk_accel_map_remove_group (const gchar   *accel_path,
+                                             GtkAccelGroup *accel_group);
+gboolean        _gtk_accel_path_is_valid    (const gchar   *accel_path);
+
+gchar         * _gtk_accel_path_for_action  (const gchar   *action_name,
+                                             GVariant      *parameter);
+
+G_END_DECLS
+
+#endif /* __GTK_ACCEL_MAP_PRIVATE_H__ */
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 66cb488..3ba6bf1 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -31,7 +31,7 @@
 #include "gtkmarshalers.h"
 #include "gtkmain.h"
 #include "gtkapplicationwindow.h"
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 
 #include <gdk/gdk.h>
 #ifdef GDK_WINDOWING_X11
@@ -510,23 +510,6 @@ gtk_application_get_windows (GtkApplication *application)
   return application->priv->windows;
 }
 
-/* keep this in sync with gtkmodelmenuitem.c */
-static gchar *
-get_accel_path (const gchar *action_name,
-                GVariant    *parameter)
-{
-  GString *s;
-
-  s = g_string_new ("<Actions>/");
-  g_string_append (s, action_name);
-  if (parameter)
-    {
-      g_string_append_c (s, '/');
-      g_variant_print_string (parameter, s, FALSE);
-    }
-  return g_string_free (s, FALSE);
-}
-
 /**
  * gtk_application_add_accelerator:
  * @application: a #GtkApplication
@@ -572,7 +555,7 @@ gtk_application_add_accelerator (GtkApplication *application,
       return;
     }
 
-  accel_path = get_accel_path (action_name, parameter);
+  accel_path = _gtk_accel_path_for_action (action_name, parameter);
 
   if (gtk_accel_map_lookup_entry (accel_path, NULL))
     gtk_accel_map_change_entry (accel_path, accel_key, accel_mods, TRUE);
@@ -603,7 +586,7 @@ gtk_application_remove_accelerator (GtkApplication *application,
 
   g_return_if_fail (GTK_IS_APPLICATION (application));
 
-  accel_path = get_accel_path (action_name, parameter);
+  accel_path = _gtk_accel_path_for_action (action_name, parameter);
 
   if (!gtk_accel_map_lookup_entry (accel_path, NULL))
     {
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 25e61eb..67d843e 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -111,7 +111,7 @@
 
 #include "gtkintl.h"
 
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 #include "gtkbox.h"
 #include "gtkclipboard.h"
 #include "gtkdebug.h"
diff --git a/gtk/gtkmodelmenuitem.c b/gtk/gtkmodelmenuitem.c
index 4e2fd09..ed49daf 100644
--- a/gtk/gtkmodelmenuitem.c
+++ b/gtk/gtkmodelmenuitem.c
@@ -23,7 +23,7 @@
 
 #include "gtkmodelmenuitem.h"
 
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 #include "gtkmodelmenu.h"
 
 struct _GtkModelMenuItem
@@ -189,22 +189,6 @@ gtk_model_menu_item_action_removed (GActionObserver   *observer,
   gtk_widget_queue_resize (GTK_WIDGET (item));
 }
 
-static gchar *
-get_accel_path (const gchar *action_name,
-                GVariant    *parameter)
-{
-  GString *s;
-
-  s = g_string_new ("<Actions>/");
-  g_string_append (s, action_name);
-  if (parameter)
-    {
-      g_string_append_c (s, '/');
-      g_variant_print_string (parameter, s, FALSE);
-    }
-  return g_string_free (s, FALSE);
-}
-
 static void
 gtk_model_menu_item_setup (GtkModelMenuItem  *item,
                            GMenuModel        *model,
@@ -262,7 +246,7 @@ gtk_model_menu_item_setup (GtkModelMenuItem  *item,
       if (state != NULL)
         g_variant_unref (state);
 
-      path = get_accel_path (item->action_name, item->target);
+      path = _gtk_accel_path_for_action (item->action_name, item->target);
       gtk_menu_item_set_accel_path (GTK_MENU_ITEM (item), path);
       g_free (path);
     }
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 9626333..28a18fb 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -35,7 +35,7 @@
 #include <cairo-gobject.h>
 
 #include "gtkcontainer.h"
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 #include "gtkclipboard.h"
 #include "gtkiconfactory.h"
 #include "gtkintl.h"



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