~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to src/geanymenubuttonaction.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-08-07 03:23:12 UTC
  • mfrom: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20100807032312-ot70ac9d50cn79we
Tags: upstream-0.19
ImportĀ upstreamĀ versionĀ 0.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
typedef struct _GeanyMenubuttonActionPrivate            GeanyMenubuttonActionPrivate;
34
34
 
35
 
#define GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(obj)       (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
36
 
                        GEANY_MENU_BUTTON_ACTION_TYPE, GeanyMenubuttonActionPrivate))
 
35
#define GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(obj)       (GEANY_MENU_BUTTON_ACTION(obj)->priv)
37
36
 
38
37
 
39
38
struct _GeanyMenubuttonActionPrivate
40
39
{
41
40
        GtkWidget       *menu;
 
41
 
 
42
        gchar *tooltip_arrow;
 
43
};
 
44
 
 
45
enum
 
46
{
 
47
        PROP_0,
 
48
        PROP_TOOLTIP_ARROW
42
49
};
43
50
 
44
51
enum
49
56
static guint signals[LAST_SIGNAL];
50
57
 
51
58
 
52
 
G_DEFINE_TYPE(GeanyMenubuttonAction, geany_menu_button_action, GTK_TYPE_ACTION);
 
59
G_DEFINE_TYPE(GeanyMenubuttonAction, geany_menu_button_action, GTK_TYPE_ACTION)
53
60
 
54
61
 
55
62
static void geany_menu_button_action_finalize(GObject *object)
57
64
        GeanyMenubuttonActionPrivate *priv = GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(object);
58
65
 
59
66
        g_object_unref(priv->menu);
 
67
        g_free(priv->tooltip_arrow);
60
68
 
61
69
        (* G_OBJECT_CLASS(geany_menu_button_action_parent_class)->finalize)(object);
62
70
}
68
76
}
69
77
 
70
78
 
 
79
static void set_arrow_tooltip(GtkMenuToolButton *button, const gchar *tooltip)
 
80
{
 
81
#if GTK_CHECK_VERSION(2, 12, 0)
 
82
        gtk_menu_tool_button_set_arrow_tooltip_text(button, tooltip);
 
83
#else
 
84
        static GtkTooltips *tooltips = NULL;
 
85
 
 
86
        if (G_UNLIKELY(tooltips == NULL))
 
87
                tooltips = gtk_tooltips_new();
 
88
 
 
89
        gtk_menu_tool_button_set_arrow_tooltip(button, tooltips, tooltip, NULL);
 
90
#endif
 
91
}
 
92
 
 
93
 
 
94
static void geany_menu_button_action_set_property(GObject *object, guint prop_id,
 
95
                                                                                                  const GValue *value, GParamSpec *pspec)
 
96
{
 
97
        switch (prop_id)
 
98
        {
 
99
        case PROP_TOOLTIP_ARROW:
 
100
        {
 
101
                GeanyMenubuttonActionPrivate *priv = GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(object);
 
102
                g_free(priv->tooltip_arrow);
 
103
                priv->tooltip_arrow = g_value_dup_string(value);
 
104
                break;
 
105
        }
 
106
        default:
 
107
                G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
108
                break;
 
109
        }
 
110
}
 
111
 
 
112
 
 
113
static GtkWidget *geany_menu_button_action_create_tool_item(GtkAction *action)
 
114
{
 
115
        GtkWidget *toolitem;
 
116
        GeanyMenubuttonActionPrivate *priv = GEANY_MENU_BUTTON_ACTION_GET_PRIVATE(action);
 
117
 
 
118
        toolitem = g_object_new(GTK_TYPE_MENU_TOOL_BUTTON, NULL);
 
119
        set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(toolitem), priv->tooltip_arrow);
 
120
 
 
121
        return toolitem;
 
122
}
 
123
 
 
124
 
71
125
static void geany_menu_button_action_class_init(GeanyMenubuttonActionClass *klass)
72
126
{
73
127
        GtkActionClass *action_class = GTK_ACTION_CLASS(klass);
74
128
        GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
75
129
 
76
130
        g_object_class->finalize = geany_menu_button_action_finalize;
 
131
        g_object_class->set_property = geany_menu_button_action_set_property;
77
132
 
78
133
        action_class->activate = delegate_button_activated;
 
134
        action_class->create_tool_item = geany_menu_button_action_create_tool_item;
79
135
        action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
80
136
 
81
137
        g_type_class_add_private(klass, sizeof(GeanyMenubuttonActionPrivate));
82
138
 
 
139
        g_object_class_install_property(g_object_class,
 
140
                                                                        PROP_TOOLTIP_ARROW,
 
141
                                                                        g_param_spec_string(
 
142
                                                                        "tooltip-arrow",
 
143
                                                                        "Arrow tooltip",
 
144
                                                                        "A special tooltip for the arrow button",
 
145
                                                                        "",
 
146
                                                                        G_PARAM_WRITABLE));
 
147
 
83
148
        signals[BUTTON_CLICKED] = g_signal_new("button-clicked",
84
149
                                                                                G_TYPE_FROM_CLASS(klass),
85
150
                                                                                (GSignalFlags) 0,
93
158
 
94
159
static void geany_menu_button_action_init(GeanyMenubuttonAction *action)
95
160
{
96
 
        /* nothing to do */
 
161
        GeanyMenubuttonActionPrivate *priv;
 
162
 
 
163
        action->priv = G_TYPE_INSTANCE_GET_PRIVATE(action,
 
164
                GEANY_MENU_BUTTON_ACTION_TYPE, GeanyMenubuttonActionPrivate);
 
165
 
 
166
        priv = action->priv;
 
167
        priv->tooltip_arrow = NULL;
 
168
        priv->menu = NULL;
97
169
}
98
170
 
99
171
 
100
172
GtkAction *geany_menu_button_action_new(const gchar *name,
101
173
                                                                                const gchar *label,
102
174
                                                                            const gchar *tooltip,
 
175
                                                                            const gchar *tooltip_arrow,
103
176
                                                                                const gchar *stock_id)
104
177
{
105
178
        GtkAction *action = g_object_new(GEANY_MENU_BUTTON_ACTION_TYPE,
106
179
                "name", name,
107
180
                "label", label,
108
181
                "tooltip", tooltip,
 
182
                "tooltip-arrow", tooltip_arrow,
109
183
                "stock-id", stock_id,
110
184
                NULL);
111
185
 
139
213
        else
140
214
                enable = FALSE;
141
215
 
142
 
        if (enable)
 
216
        foreach_slist(l, gtk_action_get_proxies(GTK_ACTION(action)))
143
217
        {
144
 
                foreach_slist(l, gtk_action_get_proxies(GTK_ACTION(action)))
 
218
                /* On Windows a GtkImageMenuItem proxy is created for whatever reason. So we filter
 
219
                 * by type and act only on GtkMenuToolButton proxies. */
 
220
                /* TODO find why the GtkImageMenuItem proxy is created */
 
221
                if (! GTK_IS_MENU_TOOL_BUTTON(l->data))
 
222
                        continue;
 
223
 
 
224
                if (enable)
145
225
                {
146
226
                        if (gtk_menu_tool_button_get_menu(GTK_MENU_TOOL_BUTTON(l->data)) == NULL)
147
227
                                gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(l->data), priv->menu);
148
228
                }
149
 
        }
150
 
        else
151
 
        {
152
 
                foreach_slist(l, gtk_action_get_proxies(GTK_ACTION(action)))
153
 
                {
 
229
                else
154
230
                        gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(l->data), NULL);
155
 
                }
156
231
        }
157
232
}
158
233