]> Pileus Git - ~andy/gtk/blob - gtk/gtkactionable.c
styleproperty: Remove context arg from _gtk_style_context_query()
[~andy/gtk] / gtk / gtkactionable.c
1 /*
2  * Copyright © 2012 Canonical Limited
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * licence or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
17  * USA.
18  *
19  * Authors: Ryan Lortie <desrt@desrt.ca>
20  */
21
22 #include "config.h"
23
24 #include "gtkactionable.h"
25
26 #include "gtkwidget.h"
27 #include "gtkintl.h"
28
29 G_DEFINE_INTERFACE (GtkActionable, gtk_actionable, GTK_TYPE_WIDGET)
30
31 static void
32 gtk_actionable_default_init (GtkActionableInterface *iface)
33 {
34   g_object_interface_install_property (iface,
35     g_param_spec_string ("action-name", P_("action name"),
36                          P_("The name of the associated action, like 'app.quit'"),
37                          NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
38
39   g_object_interface_install_property (iface,
40     g_param_spec_variant ("action-target", P_("action target value"),
41                           P_("The parameter for action invocations"),
42                           G_VARIANT_TYPE_ANY, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
43 }
44
45 const gchar *
46 gtk_actionable_get_action_name (GtkActionable *actionable)
47 {
48   g_return_val_if_fail (GTK_IS_ACTIONABLE (actionable), NULL);
49
50   return GTK_ACTIONABLE_GET_IFACE (actionable)
51     ->get_action_name (actionable);
52 }
53
54 void
55 gtk_actionable_set_action_name (GtkActionable *actionable,
56                                 const gchar   *action_name)
57 {
58   g_return_if_fail (GTK_IS_ACTIONABLE (actionable));
59
60   GTK_ACTIONABLE_GET_IFACE (actionable)
61     ->set_action_name (actionable, action_name);
62 }
63
64 GVariant *
65 gtk_actionable_get_action_target_value (GtkActionable *actionable)
66 {
67   g_return_val_if_fail (GTK_IS_ACTIONABLE (actionable), NULL);
68
69   return GTK_ACTIONABLE_GET_IFACE (actionable)
70     ->get_action_target_value (actionable);
71 }
72
73 void
74 gtk_actionable_set_action_target_value (GtkActionable *actionable,
75                                         GVariant      *target_value)
76 {
77   g_return_if_fail (GTK_IS_ACTIONABLE (actionable));
78
79   GTK_ACTIONABLE_GET_IFACE (actionable)
80     ->set_action_target_value (actionable, target_value);
81 }
82
83 void
84 gtk_actionable_set_action_target (GtkActionable *actionable,
85                                   const gchar   *format_string,
86                                   ...)
87 {
88   va_list ap;
89
90   va_start (ap, format_string);
91   gtk_actionable_set_action_target_value (actionable, g_variant_new_va (format_string, NULL, &ap));
92   va_end (ap);
93 }
94
95 void
96 gtk_actionable_set_detailed_action_name (GtkActionable *actionable,
97                                          const gchar   *detailed_action_name)
98 {
99   gchar **parts;
100
101   g_return_if_fail (GTK_IS_ACTIONABLE (actionable));
102
103   if (detailed_action_name == NULL)
104     {
105       gtk_actionable_set_action_name (actionable, NULL);
106       gtk_actionable_set_action_target_value (actionable, NULL);
107       return;
108     }
109
110   parts = g_strsplit (detailed_action_name, "::", 2);
111   gtk_actionable_set_action_name (actionable, parts[0]);
112   if (parts[0] && parts[1])
113     gtk_actionable_set_action_target (actionable, "s", parts[1]);
114   else
115     gtk_actionable_set_action_target_value (actionable, NULL);
116   g_strfreev (parts);
117 }