~khurshid-alam/gtk/packaging-xenial

« back to all changes in this revision

Viewing changes to debian/patches/ubuntu_gtk_custom_menu_items.patch

  • Committer: Khurshid Alam (Technologist)
  • Date: 2016-08-17 17:46:23 UTC
  • Revision ID: khurshid.alam@linuxmail.org-20160817174623-8nheg5eemu2jrzbf
gtk+3.0 packaging with icon-size patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From 59168f3c1a72f610b693cd1ed4cfa5fac281079a Mon Sep 17 00:00:00 2001
 
2
From: Lars Uebernickel <lars.uebernickel@canonical.com>
 
3
Date: Wed, 6 Nov 2013 14:48:19 +0100
 
4
Subject: [PATCH] Add UbuntuMenuItemFactory
 
5
 
 
6
UbuntuMenuItemFactory is an interface for creating widgets for menu
 
7
items in a GMenuModel that have an 'x-canonical-type' attribute.
 
8
 
 
9
It is needed by unity and should not be considered public API.
 
10
---
 
11
 gtk/Makefile.am             |  3 ++
 
12
 gtk/gtkmenushell.c          | 69 ++++++++++++++++++++++++++++++++++++++++++++
 
13
 gtk/gtkmenutrackeritem.c    | 16 +++++++++++
 
14
 gtk/gtkmenutrackeritem.h    |  4 +++
 
15
 gtk/ubuntu-private.h        | 32 +++++++++++++++++++++
 
16
 gtk/ubuntumenuitemfactory.c | 70 +++++++++++++++++++++++++++++++++++++++++++++
 
17
 gtk/ubuntumenuitemfactory.h | 61 +++++++++++++++++++++++++++++++++++++++
 
18
 7 files changed, 255 insertions(+)
 
19
 create mode 100644 gtk/ubuntu-private.h
 
20
 create mode 100644 gtk/ubuntumenuitemfactory.c
 
21
 create mode 100644 gtk/ubuntumenuitemfactory.h
 
22
 
 
23
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
 
24
index 51153e6..3c01638 100644
 
25
--- a/gtk/Makefile.am
 
26
+++ b/gtk/Makefile.am
 
27
@@ -108,6 +108,8 @@ include $(srcdir)/inspector/Makefile.inc
 
28
 gtk_public_h_sources =                 \
 
29
        gtk.h                   \
 
30
        gtk-autocleanups.h      \
 
31
+       ubuntu-private.h        \
 
32
+       ubuntumenuitemfactory.h \
 
33
        gtkx.h                  \
 
34
        gtkx-autocleanups.h     \
 
35
        gtk-a11y.h              \
 
36
@@ -528,6 +530,7 @@ gtk_base_c_sources =                \
 
37
        $(a11y_c_sources)       \
 
38
        $(deprecated_c_sources) \
 
39
        $(inspector_c_sources)  \
 
40
+       ubuntumenuitemfactory.c \
 
41
        gtkactionmuxer.c        \
 
42
        gtkactionobserver.c     \
 
43
        gtkactionobservable.c   \
 
44
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
 
45
index e1ba138..6d7a2f6 100644
 
46
--- a/gtk/gtkmenushell.c
 
47
+++ b/gtk/gtkmenushell.c
 
48
@@ -80,6 +80,8 @@
 
49
 
 
50
 #include "a11y/gtkmenushellaccessible.h"
 
51
 
 
52
+#include "ubuntu-private.h"
 
53
+
 
54
 
 
55
 #define MENU_SHELL_TIMEOUT   500
 
56
 #define MENU_POPUP_DELAY     225
 
57
@@ -2044,6 +2046,58 @@ gtk_menu_shell_tracker_remove_func (gint     position,
 
58
   gtk_widget_destroy (child);
 
59
 }
 
60
 
 
61
+static GtkWidget *
 
62
+create_custom_menu_item (GMenuItem   *item,
 
63
+                         GtkWidget   *parent,
 
64
+                         const gchar *action_namespace)
 
65
+{
 
66
+  gchar *type;
 
67
+  GActionGroup *actions;
 
68
+  GtkMenuItem *widget = NULL;
 
69
+  GList *it;
 
70
+
 
71
+  g_menu_item_get_attribute (item, "x-canonical-type", "s", &type);
 
72
+
 
73
+  if (action_namespace)
 
74
+    {
 
75
+      gchar *action;
 
76
+
 
77
+      /* Rewrite the menu item to include the fully qualified action
 
78
+       * name to make writing widgets easier. This won't break, as
 
79
+       * we don't use the tracker item for custom items.
 
80
+       */
 
81
+      if (g_menu_item_get_attribute (item, "action", "s", &action))
 
82
+        {
 
83
+          gchar *fullname;
 
84
+
 
85
+          fullname = g_strconcat (action_namespace, ".", action, NULL);
 
86
+          g_menu_item_set_attribute (item, "action", "s", fullname);
 
87
+
 
88
+          g_free (fullname);
 
89
+          g_free (action);
 
90
+        }
 
91
+    }
 
92
+
 
93
+  /* Passing the parent muxer is wrong, but we'll only have access
 
94
+   * to the menuitem's muxer after the widget has been created.
 
95
+   * Thus we'd need some other form of passing the action group to
 
96
+   * the widget, which would complicate things for no practical
 
97
+   * reason: the panel service is the only consumer of this API and
 
98
+   * it will never call gtk_widget_insert_action_group() on the
 
99
+   * returned menu item.
 
100
+   */
 
101
+  actions = G_ACTION_GROUP (_gtk_widget_get_action_muxer (parent, TRUE));
 
102
+
 
103
+  for (it = ubuntu_menu_item_factory_get_all (); it != NULL && widget == NULL; it = it->next)
 
104
+    widget = ubuntu_menu_item_factory_create_menu_item (it->data, type, item, actions);
 
105
+
 
106
+  if (widget == NULL)
 
107
+    g_warning ("Cannot create custom menu item of type '%s'", type);
 
108
+
 
109
+  g_free (type);
 
110
+  return GTK_WIDGET (widget);
 
111
+}
 
112
+
 
113
 static void
 
114
 gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
 
115
                                     gint                position,
 
116
@@ -2051,6 +2105,9 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
 
117
 {
 
118
   GtkMenuShell *menu_shell = user_data;
 
119
   GtkWidget *widget;
 
120
+  GMenuItem *menuitem;
 
121
+
 
122
+  menuitem = gtk_menu_tracker_item_get_menu_item (item);
 
123
 
 
124
   if (gtk_menu_tracker_item_get_is_separator (item))
 
125
     {
 
126
@@ -2112,6 +2169,18 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
 
127
 
 
128
       gtk_widget_show (widget);
 
129
     }
 
130
+  else if (g_menu_item_get_attribute (menuitem, "x-canonical-type", "s", NULL))
 
131
+    {
 
132
+      const gchar *namespace;
 
133
+
 
134
+      namespace = gtk_menu_tracker_item_get_action_namespace (item);
 
135
+      widget = create_custom_menu_item (menuitem, GTK_WIDGET (menu_shell), namespace);
 
136
+
 
137
+      if (widget == NULL)
 
138
+        return;
 
139
+
 
140
+      gtk_widget_show (widget);
 
141
+    }
 
142
   else
 
143
     {
 
144
       widget = gtk_model_menu_item_new ();
 
145
diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c
 
146
index c304b66..cd0c796 100644
 
147
--- a/gtk/gtkmenutrackeritem.c
 
148
+++ b/gtk/gtkmenutrackeritem.c
 
149
@@ -979,3 +979,19 @@ gtk_menu_tracker_item_may_disappear (GtkMenuTrackerItem *self)
 
150
 {
 
151
   return self->hidden_when != HIDDEN_NEVER;
 
152
 }
 
153
+
 
154
+GMenuItem *
 
155
+gtk_menu_tracker_item_get_menu_item (GtkMenuTrackerItem *self)
 
156
+{
 
157
+  g_return_val_if_fail (GTK_IS_MENU_TRACKER_ITEM (self), NULL);
 
158
+
 
159
+  return self->item;
 
160
+}
 
161
+
 
162
+const gchar *
 
163
+gtk_menu_tracker_item_get_action_namespace (GtkMenuTrackerItem *self)
 
164
+{
 
165
+  g_return_val_if_fail (GTK_IS_MENU_TRACKER_ITEM (self), NULL);
 
166
+
 
167
+  return self->action_namespace;
 
168
+}
 
169
diff --git a/gtk/gtkmenutrackeritem.h b/gtk/gtkmenutrackeritem.h
 
170
index 6b4fcb5..d74fe92 100644
 
171
--- a/gtk/gtkmenutrackeritem.h
 
172
+++ b/gtk/gtkmenutrackeritem.h
 
173
@@ -92,4 +92,8 @@ void                    gtk_menu_tracker_item_request_submenu_shown     (GtkMenu
 
174
 
 
175
 gboolean                gtk_menu_tracker_item_get_submenu_shown         (GtkMenuTrackerItem *self);
 
176
 
 
177
+GMenuItem *             gtk_menu_tracker_item_get_menu_item             (GtkMenuTrackerItem *self);
 
178
+
 
179
+const gchar *           gtk_menu_tracker_item_get_action_namespace      (GtkMenuTrackerItem *self);
 
180
+
 
181
 #endif
 
182
diff --git a/gtk/ubuntu-private.h b/gtk/ubuntu-private.h
 
183
new file mode 100644
 
184
index 0000000..3ed366f
 
185
--- /dev/null
 
186
+++ b/gtk/ubuntu-private.h
 
187
@@ -0,0 +1,32 @@
 
188
+/*
 
189
+* Copyright 2013 Canonical Ltd.
 
190
+*
 
191
+* This program is free software: you can redistribute it and/or modify it
 
192
+* under the terms of the GNU General Public License version 3, as published
 
193
+* by the Free Software Foundation.
 
194
+*
 
195
+* This program is distributed in the hope that it will be useful, but
 
196
+* WITHOUT ANY WARRANTY; without even the implied warranties of
 
197
+* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
198
+* PURPOSE.  See the GNU General Public License for more details.
 
199
+*
 
200
+* You should have received a copy of the GNU General Public License along
 
201
+* with this program.  If not, see <http://www.gnu.org/licenses/>.
 
202
+*
 
203
+* Authors:
 
204
+*     Lars Uebernickel <lars.uebernickel@canonical.com>
 
205
+*/
 
206
+
 
207
+/*
 
208
+ * Warning: this file is not part of gtk+, but an Ubuntu-specific extension.
 
209
+ * The API provided here is meant to be used only from Unity.
 
210
+ *
 
211
+ * Applications should not use this.
 
212
+ */
 
213
+
 
214
+#ifndef __UBUNTU_PRIVATE_H__
 
215
+#define __UBUNTU_PRIVATE_H__
 
216
+
 
217
+#include "ubuntumenuitemfactory.h"
 
218
+
 
219
+#endif
 
220
diff --git a/gtk/ubuntumenuitemfactory.c b/gtk/ubuntumenuitemfactory.c
 
221
new file mode 100644
 
222
index 0000000..24eb214
 
223
--- /dev/null
 
224
+++ b/gtk/ubuntumenuitemfactory.c
 
225
@@ -0,0 +1,70 @@
 
226
+/*
 
227
+* Copyright 2013 Canonical Ltd.
 
228
+*
 
229
+* This program is free software: you can redistribute it and/or modify it
 
230
+* under the terms of the GNU General Public License version 3, as published
 
231
+* by the Free Software Foundation.
 
232
+*
 
233
+* This program is distributed in the hope that it will be useful, but
 
234
+* WITHOUT ANY WARRANTY; without even the implied warranties of
 
235
+* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
236
+* PURPOSE.  See the GNU General Public License for more details.
 
237
+*
 
238
+* You should have received a copy of the GNU General Public License along
 
239
+* with this program.  If not, see <http://www.gnu.org/licenses/>.
 
240
+*
 
241
+* Authors:
 
242
+*     Lars Uebernickel <lars.uebernickel@canonical.com>
 
243
+*/
 
244
+
 
245
+#include "config.h"
 
246
+#include "ubuntumenuitemfactory.h"
 
247
+
 
248
+G_DEFINE_INTERFACE_WITH_CODE (UbuntuMenuItemFactory, ubuntu_menu_item_factory, G_TYPE_OBJECT,
 
249
+  GIOExtensionPoint *ep = g_io_extension_point_register (UBUNTU_MENU_ITEM_FACTORY_EXTENSION_POINT_NAME);
 
250
+  g_io_extension_point_set_required_type (ep, g_define_type_id);)
 
251
+
 
252
+/*
 
253
+ * ubuntu_menu_item_factory_get_all:
 
254
+ *
 
255
+ * Returns a static list of all registered factories.
 
256
+ */
 
257
+GList *
 
258
+ubuntu_menu_item_factory_get_all (void)
 
259
+{
 
260
+  static GList *factories = NULL;
 
261
+
 
262
+  if (factories == NULL)
 
263
+    {
 
264
+      GIOExtensionPoint *ep;
 
265
+      GList *it;
 
266
+
 
267
+      g_type_ensure (UBUNTU_TYPE_MENU_ITEM_FACTORY);
 
268
+      ep = g_io_extension_point_lookup (UBUNTU_MENU_ITEM_FACTORY_EXTENSION_POINT_NAME);
 
269
+      for (it = g_io_extension_point_get_extensions (ep); it != NULL; it = it->next)
 
270
+        {
 
271
+          GIOExtension *ext = it->data;
 
272
+          UbuntuMenuItemFactory *factory;
 
273
+
 
274
+          factory = g_object_new (g_io_extension_get_type (ext), NULL);
 
275
+          factories = g_list_prepend (factories, factory);
 
276
+        }
 
277
+      factories = g_list_reverse (factories);
 
278
+    }
 
279
+
 
280
+  return factories;
 
281
+}
 
282
+
 
283
+static void
 
284
+ubuntu_menu_item_factory_default_init (UbuntuMenuItemFactoryInterface *iface)
 
285
+{
 
286
+}
 
287
+
 
288
+GtkMenuItem *
 
289
+ubuntu_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory,
 
290
+                                           const gchar           *type,
 
291
+                                           GMenuItem             *menuitem,
 
292
+                                           GActionGroup          *actions)
 
293
+{
 
294
+  return UBUNTU_MENU_ITEM_FACTORY_GET_IFACE (factory)->create_menu_item (factory, type, menuitem, actions);
 
295
+}
 
296
diff --git a/gtk/ubuntumenuitemfactory.h b/gtk/ubuntumenuitemfactory.h
 
297
new file mode 100644
 
298
index 0000000..e97539d
 
299
--- /dev/null
 
300
+++ b/gtk/ubuntumenuitemfactory.h
 
301
@@ -0,0 +1,61 @@
 
302
+/*
 
303
+* Copyright 2013 Canonical Ltd.
 
304
+*
 
305
+* This program is free software: you can redistribute it and/or modify it
 
306
+* under the terms of the GNU General Public License version 3, as published
 
307
+* by the Free Software Foundation.
 
308
+*
 
309
+* This program is distributed in the hope that it will be useful, but
 
310
+* WITHOUT ANY WARRANTY; without even the implied warranties of
 
311
+* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
312
+* PURPOSE.  See the GNU General Public License for more details.
 
313
+*
 
314
+* You should have received a copy of the GNU General Public License along
 
315
+* with this program.  If not, see <http://www.gnu.org/licenses/>.
 
316
+*
 
317
+* Authors:
 
318
+*     Lars Uebernickel <lars.uebernickel@canonical.com>
 
319
+*/
 
320
+
 
321
+#ifndef __UBUNTU_MENU_ITEM_FACTORY_H__
 
322
+#define __UBUNTU_MENU_ITEM_FACTORY_H__
 
323
+
 
324
+#include <gtk/gtkmenuitem.h>
 
325
+
 
326
+G_BEGIN_DECLS
 
327
+
 
328
+#define UBUNTU_TYPE_MENU_ITEM_FACTORY         (ubuntu_menu_item_factory_get_type ())
 
329
+#define UBUNTU_MENU_ITEM_FACTORY(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), UBUNTU_TYPE_MENU_ITEM_FACTORY, UbuntuMenuItemFactory))
 
330
+#define UBUNTU_IS_MENU_ITEM_FACTORY(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), UBUNTU_TYPE_MENU_ITEM_FACTORY))
 
331
+#define UBUNTU_MENU_ITEM_FACTORY_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), UBUNTU_TYPE_MENU_ITEM_FACTORY, UbuntuMenuItemFactoryInterface))
 
332
+
 
333
+#define UBUNTU_MENU_ITEM_FACTORY_EXTENSION_POINT_NAME "ubuntu-menu-item-factory"
 
334
+
 
335
+typedef struct _UbuntuMenuItemFactoryInterface UbuntuMenuItemFactoryInterface;
 
336
+typedef struct _UbuntuMenuItemFactory          UbuntuMenuItemFactory;
 
337
+
 
338
+struct _UbuntuMenuItemFactoryInterface
 
339
+{
 
340
+  GTypeInterface iface;
 
341
+
 
342
+  GtkMenuItem * (*create_menu_item)  (UbuntuMenuItemFactory *factory,
 
343
+                                      const gchar           *type,
 
344
+                                      GMenuItem             *menuitem,
 
345
+                                      GActionGroup          *actions);
 
346
+};
 
347
+
 
348
+GDK_AVAILABLE_IN_3_10
 
349
+GList *                 ubuntu_menu_item_factory_get_all                (void);
 
350
+
 
351
+GDK_AVAILABLE_IN_3_10
 
352
+GType                   ubuntu_menu_item_factory_get_type               (void);
 
353
+
 
354
+GDK_AVAILABLE_IN_3_10
 
355
+GtkMenuItem *           ubuntu_menu_item_factory_create_menu_item       (UbuntuMenuItemFactory *factory,
 
356
+                                                                         const gchar           *type,
 
357
+                                                                         GMenuItem             *menuitem,
 
358
+                                                                         GActionGroup          *actions);
 
359
+
 
360
+G_END_DECLS
 
361
+
 
362
+#endif
 
363
-- 
 
364
2.1.4
 
365