~ubuntu-branches/ubuntu/trusty/xfce4-indicator-plugin/trusty

« back to all changes in this revision

Viewing changes to panel-plugin/indicator-button.c

  • Committer: Package Import Robot
  • Author(s): Unit 193
  • Date: 2014-02-13 16:07:50 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20140213160750-d34ou82fz6gn1z2n
Tags: upstream-2.2.0
ImportĀ upstreamĀ versionĀ 2.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  Copyright (c) 2012 Andrzej <ndrwrdck@gmail.com>
 
1
/*  Copyright (c) 2012-2013 Andrzej <ndrwrdck@gmail.com>
2
2
 *
3
3
 *  This program is free software; you can redistribute it and/or modify
4
4
 *  it under the terms of the GNU General Public License as published by
15
15
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
16
 */
17
17
 
 
18
 
 
19
 
 
20
/*
 
21
 *  This file implements an indicator button class corresponding to
 
22
 *  a single indicator object entry.
 
23
 *
 
24
 */
 
25
 
 
26
 
 
27
 
18
28
#include <glib.h>
19
29
#include <gtk/gtk.h>
20
30
#include <libxfce4panel/libxfce4panel.h>
21
31
#include <libindicator/indicator-object.h>
22
32
 
23
33
#include "indicator-button.h"
24
 
 
25
 
static void                 xfce_indicator_button_finalize     (GObject *object);
 
34
#include "indicator-button-box.h"
 
35
 
 
36
 
 
37
#include <libindicator/indicator-object.h>
 
38
 
 
39
#define ICON_SIZE 22
 
40
#define SPACING 2
 
41
 
 
42
//#ifndef INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED
 
43
//#define INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED "scroll-entry"
 
44
//#endif
 
45
 
 
46
static void                 xfce_indicator_button_finalize        (GObject                *object);
 
47
static gboolean             xfce_indicator_button_button_press    (GtkWidget              *widget,
 
48
                                                                   GdkEventButton         *event);
 
49
static gboolean             xfce_indicator_button_button_release  (GtkWidget              *widget,
 
50
                                                                   GdkEventButton         *event);
 
51
static gboolean             xfce_indicator_button_scroll_event    (GtkWidget              *widget,
 
52
                                                                   GdkEventScroll         *event);
 
53
static void                 xfce_indicator_button_menu_deactivate (XfceIndicatorButton    *button,
 
54
                                                                   GtkMenu                *menu);
 
55
static void            xfce_indicator_button_get_preferred_width  (GtkWidget              *widget,
 
56
                                                                   gint                   *minimum_width,
 
57
                                                                   gint                   *natural_width);
 
58
static void            xfce_indicator_button_get_preferred_height (GtkWidget              *widget,
 
59
                                                                   gint                   *minimum_height,
 
60
                                                                   gint                   *natural_height);
 
61
 
 
62
 
 
63
struct _XfceIndicatorButton
 
64
{
 
65
  GtkToggleButton       __parent__;
 
66
 
 
67
  IndicatorObject      *io;
 
68
  const gchar          *io_name;
 
69
  IndicatorObjectEntry *entry;
 
70
  GtkMenu              *menu;
 
71
  XfcePanelPlugin      *plugin;
 
72
  IndicatorConfig      *config;
 
73
 
 
74
  GtkWidget            *align_box;
 
75
  GtkWidget            *box;
 
76
};
 
77
 
 
78
struct _XfceIndicatorButtonClass
 
79
{
 
80
  GtkToggleButtonClass __parent__;
 
81
};
 
82
 
 
83
 
26
84
 
27
85
 
28
86
G_DEFINE_TYPE (XfceIndicatorButton, xfce_indicator_button, GTK_TYPE_TOGGLE_BUTTON)
30
88
static void
31
89
xfce_indicator_button_class_init (XfceIndicatorButtonClass *klass)
32
90
{
33
 
  GObjectClass   *gobject_class;
 
91
  GObjectClass      *gobject_class;
 
92
  GtkWidgetClass    *widget_class;
34
93
 
35
94
  gobject_class = G_OBJECT_CLASS (klass);
36
95
  gobject_class->finalize = xfce_indicator_button_finalize;
 
96
 
 
97
  widget_class = GTK_WIDGET_CLASS (klass);
 
98
  widget_class->button_press_event = xfce_indicator_button_button_press;
 
99
  widget_class->button_release_event = xfce_indicator_button_button_release;
 
100
  widget_class->scroll_event = xfce_indicator_button_scroll_event;
 
101
  widget_class->get_preferred_width = xfce_indicator_button_get_preferred_width;
 
102
  widget_class->get_preferred_height = xfce_indicator_button_get_preferred_height;
37
103
}
38
104
 
39
105
 
41
107
static void
42
108
xfce_indicator_button_init (XfceIndicatorButton *button)
43
109
{
44
 
  GtkWidget   *outer_container;
45
 
 
46
 
  GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (button), GTK_CAN_DEFAULT | GTK_CAN_FOCUS);
 
110
  //GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (button), GTK_CAN_DEFAULT | GTK_CAN_FOCUS);
 
111
  gtk_widget_set_can_focus(GTK_WIDGET(button), FALSE);
 
112
  gtk_widget_set_can_default (GTK_WIDGET (button), FALSE);
47
113
  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
48
114
  gtk_button_set_use_underline (GTK_BUTTON (button),TRUE);
49
115
  gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
50
116
  gtk_widget_set_name (GTK_WIDGET (button), "indicator-button");
51
117
 
 
118
  gtk_widget_add_events (GTK_WIDGET (button), GDK_SCROLL_MASK);
 
119
 
52
120
  button->io = NULL;
53
121
  button->entry = NULL;
 
122
  button->plugin = NULL;
 
123
  button->config = NULL;
54
124
  button->menu = NULL;
55
125
 
56
 
  button->label = NULL;
57
 
  button->orig_icon = NULL;
58
 
  button->icon = NULL;
59
 
  button->orig_icon_handler = 0;
60
 
 
61
 
  button->size = 0;
62
 
  button->panel_size = 0;
63
 
  button->icon_size = 24;
64
 
  button->panel_orientation = GTK_ORIENTATION_HORIZONTAL;
65
 
  button->orientation = GTK_ORIENTATION_HORIZONTAL;
66
 
 
67
 
  outer_container = gtk_table_new (1, 1, FALSE);
68
 
  gtk_container_add (GTK_CONTAINER (button), outer_container);
69
 
  gtk_widget_show (outer_container);
70
 
 
71
 
  button->box = xfce_hvbox_new (button->orientation, FALSE, 1);
72
 
  gtk_table_attach (GTK_TABLE (outer_container), button->box,
73
 
                    0, 1, 0, 1,
74
 
                    GTK_EXPAND | GTK_SHRINK, GTK_EXPAND | GTK_SHRINK, 0, 0);
75
 
  gtk_widget_show (button->box);
 
126
  button->align_box = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
 
127
  gtk_container_add (GTK_CONTAINER (button), button->align_box);
 
128
  gtk_widget_show (button->align_box);
76
129
}
77
130
 
78
131
 
82
135
{
83
136
  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (object);
84
137
 
85
 
  if (button->label != NULL)
86
 
    g_object_unref (G_OBJECT (button->label));
87
 
  if (button->orig_icon != NULL)
88
 
    g_object_unref (G_OBJECT (button->orig_icon));
89
 
  if (button->icon != NULL)
90
 
    g_object_unref (G_OBJECT (button->icon));
 
138
  xfce_indicator_button_disconnect_signals (button);
 
139
 
91
140
  if (button->menu != NULL)
92
141
    g_object_unref (G_OBJECT (button->menu));
93
142
  /* IndicatorObjectEntry is not GObject */
101
150
 
102
151
 
103
152
 
104
 
static void
105
 
xfce_indicator_button_update_layout (XfceIndicatorButton *button)
106
 
{
107
 
  GtkRequisition          label_size;
108
 
 
109
 
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
110
 
 
111
 
  if (button->icon != NULL && button->size != 0)
112
 
    {
113
 
      if (button->label != NULL &&
114
 
          button->panel_orientation == GTK_ORIENTATION_VERTICAL &&
115
 
          button->orientation == GTK_ORIENTATION_HORIZONTAL)
116
 
        {
117
 
          gtk_widget_size_request (button->label, &label_size);
118
 
 
119
 
          /* put icon above the label if number of rows > 1 (they look better)
120
 
             or if they don't fit when arranged horizontally */
121
 
          if (button->panel_size != button->size ||
122
 
              label_size.width > button->panel_size - button->size)
123
 
            gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_VERTICAL);
124
 
          else
125
 
            gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_HORIZONTAL);
126
 
        }
127
 
 
128
 
      xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), button->icon_size);
129
 
    }
130
 
}
131
 
 
132
 
 
133
 
 
134
 
static void
135
 
xfce_indicator_button_update_icon (XfceIndicatorButton *button)
136
 
{
137
 
  GdkPixbuf    *pixbuf_s, *pixbuf_d;
138
 
  gdouble       aspect;
139
 
  gint          size;
140
 
 
141
 
  g_return_if_fail (GTK_IS_IMAGE (button->orig_icon));
142
 
  g_return_if_fail (XFCE_IS_PANEL_IMAGE (button->icon));
143
 
 
144
 
  size = button->icon_size;
145
 
 
146
 
  /* Copied from xfce_panel_image.c, try to snap to icon sizes, which minimize smoothing */
147
 
#if 0
148
 
  if (size > 16 && size < 22)
149
 
    size = 16;
150
 
  else if (size > 22 && size < 24)
151
 
    size = 22;
152
 
  else if (size > 24 && size < 32)
153
 
    size = 24;
154
 
#endif
155
 
 
156
 
  pixbuf_s = gtk_image_get_pixbuf (GTK_IMAGE (button->orig_icon));
157
 
 
158
 
  if (pixbuf_s != NULL)
159
 
    {
160
 
      aspect = (gdouble) gdk_pixbuf_get_width (pixbuf_s) /
161
 
        (gdouble) gdk_pixbuf_get_height (pixbuf_s);
162
 
      if (aspect > 1.0)
163
 
        pixbuf_d = gdk_pixbuf_scale_simple
164
 
          (pixbuf_s, size, (gint) (size / aspect),
165
 
           GDK_INTERP_BILINEAR);
166
 
      else
167
 
        pixbuf_d = gdk_pixbuf_scale_simple
168
 
          (pixbuf_s, (gint) (size * aspect), size,
169
 
           GDK_INTERP_BILINEAR);
170
 
      xfce_panel_image_set_from_pixbuf (XFCE_PANEL_IMAGE (button->icon), pixbuf_d);
171
 
    }
172
 
  else
173
 
    {
174
 
      xfce_panel_image_set_from_source (XFCE_PANEL_IMAGE (button->icon), "image-missing");
175
 
    }
176
 
 
177
 
  xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), button->icon_size);
178
 
}
179
 
 
180
 
 
181
 
 
182
153
void
183
154
xfce_indicator_button_set_label (XfceIndicatorButton *button,
184
155
                                 GtkLabel            *label)
186
157
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
187
158
  g_return_if_fail (GTK_IS_LABEL (label));
188
159
 
189
 
  if (button->label != GTK_WIDGET (label))
190
 
    {
191
 
      if (button->label != NULL)
192
 
        {
193
 
          gtk_container_remove (GTK_CONTAINER (button->box), button->label);
194
 
          g_object_unref (G_OBJECT (button->label));
195
 
        }
196
 
 
197
 
      button->label = GTK_WIDGET (label);
198
 
      g_object_ref (G_OBJECT (button->label));
199
 
      gtk_label_set_angle (GTK_LABEL (button->label),
200
 
                           (button->orientation == GTK_ORIENTATION_VERTICAL) ? -90 : 0);
201
 
      gtk_box_pack_end (GTK_BOX (button->box), button->label, TRUE, FALSE, 1);
202
 
    }
203
 
  xfce_indicator_button_update_layout (button);
204
 
}
205
 
 
206
 
 
207
 
 
208
 
 
209
 
static void
210
 
on_pixbuf_changed (GtkImage *image, GParamSpec *pspec, XfceIndicatorButton *button)
211
 
{
212
 
  GdkPixbuf     *pixbuf;
213
 
 
214
 
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
215
 
  g_return_if_fail (GTK_IS_IMAGE (image));
216
 
  g_return_if_fail (XFCE_IS_PANEL_IMAGE (button->icon));
217
 
 
218
 
  xfce_indicator_button_update_icon (button);
219
 
}
 
160
  indicator_button_box_set_label (XFCE_INDICATOR_BUTTON_BOX (button->box), label);
 
161
}
 
162
 
220
163
 
221
164
 
222
165
 
224
167
xfce_indicator_button_set_image (XfceIndicatorButton *button,
225
168
                                 GtkImage            *image)
226
169
{
227
 
  GdkPixbuf     *pixbuf;
228
 
 
229
170
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
230
171
  g_return_if_fail (GTK_IS_IMAGE (image));
231
172
 
232
 
  g_debug ("indicator-button set image, image=%x\n", (uint) image);
233
 
 
234
 
  if (button->orig_icon != GTK_WIDGET (image))
235
 
    {
236
 
      if (button->orig_icon != NULL)
237
 
        {
238
 
          g_signal_handler_disconnect
239
 
            (G_OBJECT (button->orig_icon), button->orig_icon_handler);
240
 
          g_object_unref (G_OBJECT (button->orig_icon));
241
 
        }
242
 
 
243
 
      if (button->icon != NULL)
244
 
        {
245
 
          gtk_container_remove (GTK_CONTAINER (button->box), button->icon);
246
 
          g_object_unref (G_OBJECT (button->icon));
247
 
        }
248
 
 
249
 
      button->orig_icon = GTK_WIDGET (image);
250
 
      g_object_ref (G_OBJECT (button->orig_icon));
251
 
 
252
 
      button->orig_icon_handler = g_signal_connect
253
 
        (G_OBJECT (image), "notify::pixbuf", G_CALLBACK (on_pixbuf_changed), button);
254
 
 
255
 
 
256
 
      button->icon = xfce_panel_image_new ();
257
 
      xfce_indicator_button_update_icon (button);
258
 
 
259
 
      gtk_box_pack_start (GTK_BOX (button->box), button->icon, TRUE, FALSE, 1);
260
 
      gtk_widget_show (button->icon);
261
 
 
262
 
      xfce_indicator_button_update_layout (button);
263
 
    }
 
173
  indicator_button_box_set_image (XFCE_INDICATOR_BUTTON_BOX (button->box), image);
264
174
}
265
175
 
266
176
 
278
188
        g_object_unref (G_OBJECT (button->menu));
279
189
      button->menu = menu;
280
190
      g_object_ref (G_OBJECT (button->menu));
 
191
      g_signal_connect_swapped (G_OBJECT (button->menu), "deactivate",
 
192
                                G_CALLBACK (xfce_indicator_button_menu_deactivate), button);
281
193
      gtk_menu_attach_to_widget(menu, GTK_WIDGET (button), NULL);
282
194
    }
283
195
}
284
196
 
285
197
 
286
198
 
287
 
GtkWidget *
288
 
xfce_indicator_button_get_label (XfceIndicatorButton *button)
289
 
{
290
 
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), NULL);
291
 
 
292
 
  return button->label;
293
 
}
294
 
 
295
 
 
296
 
 
297
 
GtkWidget *
298
 
xfce_indicator_button_get_image (XfceIndicatorButton *button)
299
 
{
300
 
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), NULL);
301
 
 
302
 
  return button->orig_icon;
303
 
}
304
 
 
305
 
 
306
 
 
307
199
IndicatorObjectEntry *
308
200
xfce_indicator_button_get_entry (XfceIndicatorButton *button)
309
201
{
324
216
 
325
217
 
326
218
 
 
219
const gchar *
 
220
xfce_indicator_button_get_io_name (XfceIndicatorButton *button)
 
221
{
 
222
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), NULL);
 
223
 
 
224
  return button->io_name;
 
225
}
 
226
 
 
227
 
 
228
 
 
229
guint
 
230
xfce_indicator_button_get_pos (XfceIndicatorButton *button)
 
231
{
 
232
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), 0);
 
233
 
 
234
  return indicator_object_get_location (button->io, button->entry);
 
235
}
 
236
 
 
237
 
 
238
 
 
239
 
 
240
 
 
241
 
 
242
 
327
243
GtkMenu *
328
244
xfce_indicator_button_get_menu (XfceIndicatorButton *button)
329
245
{
334
250
 
335
251
 
336
252
 
337
 
void
338
 
xfce_indicator_button_set_orientation (XfceIndicatorButton *button,
339
 
                                       GtkOrientation       panel_orientation,
340
 
                                       GtkOrientation       orientation)
341
 
{
342
 
  gboolean    needs_update = FALSE;
343
 
 
344
 
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
345
 
 
346
 
  if (button->orientation != orientation)
347
 
    {
348
 
      button->orientation = orientation;
349
 
 
350
 
      if (button->label != NULL)
351
 
        gtk_label_set_angle (GTK_LABEL (button->label),
352
 
                             (orientation == GTK_ORIENTATION_VERTICAL) ? -90 : 0);
353
 
      needs_update = TRUE;
354
 
    }
355
 
 
356
 
  if (button->panel_orientation != panel_orientation)
357
 
    {
358
 
      button->panel_orientation = panel_orientation;
359
 
      needs_update = TRUE;
360
 
    }
361
 
 
362
 
  if (needs_update)
363
 
    {
364
 
      gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), orientation);
365
 
      xfce_indicator_button_update_layout (button);
366
 
    }
367
 
}
368
 
 
369
 
 
370
 
 
371
 
void
372
 
xfce_indicator_button_set_size (XfceIndicatorButton *button,
373
 
                                gint                 panel_size,
374
 
                                gint                 size)
375
 
{
376
 
  gboolean    needs_update = FALSE;
377
 
  gint        border_thickness;
378
 
  GtkStyle   *style;
379
 
  gdouble     aspect;
380
 
 
381
 
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
382
 
 
383
 
  if (button->size != size)
384
 
    {
385
 
      button->size = size;
386
 
      needs_update = TRUE;
387
 
    }
388
 
 
389
 
  if (button->panel_size != panel_size)
390
 
    {
391
 
      button->panel_size = panel_size;
392
 
      needs_update = TRUE;
393
 
    }
394
 
 
395
 
  if (needs_update)
396
 
    {
397
 
      style = gtk_widget_get_style (GTK_WIDGET (button));
398
 
      border_thickness = 2 * MAX (style->xthickness, style->ythickness) + 2;
399
 
      button->icon_size = button->size - border_thickness;
400
 
 
401
 
      if (button->orig_icon != NULL)
402
 
        {
403
 
          xfce_indicator_button_update_icon (button);
404
 
          xfce_indicator_button_update_layout (button);
405
 
        }
406
 
    }
407
 
}
408
 
 
 
253
 
 
254
 
 
255
gboolean
 
256
xfce_indicator_button_is_small (XfceIndicatorButton *button)
 
257
{
 
258
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), FALSE);
 
259
 
 
260
  return indicator_button_box_is_small (XFCE_INDICATOR_BUTTON_BOX (button->box));
 
261
}
 
262
 
 
263
 
 
264
 
 
265
 
 
266
gint
 
267
xfce_indicator_button_get_button_border (XfceIndicatorButton  *button)
 
268
{
 
269
  GtkStyleContext     *ctx;
 
270
  GtkBorder            padding, border;
 
271
 
 
272
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), 0);
 
273
 
 
274
  ctx = gtk_widget_get_style_context (GTK_WIDGET (button));
 
275
  gtk_style_context_get_padding (ctx, gtk_widget_get_state_flags (GTK_WIDGET (button)), &padding);
 
276
  gtk_style_context_get_border (ctx, gtk_widget_get_state_flags (GTK_WIDGET (button)), &border);
 
277
 
 
278
  return MAX (padding.left+padding.right+border.left+border.right,
 
279
              padding.top+padding.bottom+border.top+border.bottom);
 
280
}
409
281
 
410
282
 
411
283
GtkWidget *
412
 
xfce_indicator_button_new (IndicatorObject *io,
413
 
                           IndicatorObjectEntry *entry)
 
284
xfce_indicator_button_new (IndicatorObject      *io,
 
285
                           const gchar          *io_name,
 
286
                           IndicatorObjectEntry *entry,
 
287
                           XfcePanelPlugin      *plugin,
 
288
                           IndicatorConfig      *config)
414
289
{
415
290
  XfceIndicatorButton *button = g_object_new (XFCE_TYPE_INDICATOR_BUTTON, NULL);
 
291
  g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), NULL);
 
292
  g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), NULL);
 
293
 
416
294
  button->io = io;
 
295
  button->io_name = io_name;
417
296
  button->entry = entry;
 
297
  button->plugin = plugin;
 
298
  button->config = config;
 
299
 
 
300
  button->box = indicator_button_box_new (button->config);
 
301
  //gtk_container_add (GTK_CONTAINER (button), button->box);
 
302
  gtk_container_add (GTK_CONTAINER (button->align_box), button->box);
 
303
  gtk_widget_show (button->box);
 
304
 
418
305
  if (button->io != NULL)
419
306
    g_object_ref (G_OBJECT (button->io));
420
307
  /* IndicatorObjectEntry is not GObject */
421
308
  /* g_object_ref (G_OBJECT (button->entry)); */
 
309
 
422
310
  return GTK_WIDGET (button);
423
311
}
424
312
 
425
313
 
 
314
 
 
315
void
 
316
xfce_indicator_button_disconnect_signals (XfceIndicatorButton *button)
 
317
{
 
318
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
 
319
 
 
320
  if (button->menu != 0)
 
321
    {
 
322
      gtk_menu_popdown (button->menu);
 
323
    }
 
324
}
 
325
 
 
326
 
 
327
static gboolean
 
328
xfce_indicator_button_button_press (GtkWidget      *widget,
 
329
                                    GdkEventButton *event)
 
330
{
 
331
  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (widget);
 
332
 
 
333
  if(event->button == 1 && button->menu != NULL) /* left click only */
 
334
    {
 
335
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),TRUE);
 
336
      gtk_menu_reposition (GTK_MENU (button->menu));
 
337
      gtk_menu_popup (button->menu, NULL, NULL,
 
338
                      xfce_panel_plugin_position_menu, button->plugin,
 
339
                      event->button, event->time);
 
340
      return TRUE;
 
341
    }
 
342
 
 
343
  return FALSE;
 
344
}
 
345
 
 
346
 
 
347
static gboolean
 
348
xfce_indicator_button_button_release (GtkWidget      *widget,
 
349
                                      GdkEventButton *event)
 
350
{
 
351
  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (widget);
 
352
 
 
353
  if(event->button == 2) /* middle button */
 
354
    {
 
355
      g_signal_emit_by_name(button->io, INDICATOR_OBJECT_SIGNAL_SECONDARY_ACTIVATE, 
 
356
                            button->entry, event->time);
 
357
      return TRUE;
 
358
    }
 
359
 
 
360
  return FALSE;
 
361
}
 
362
 
 
363
 
 
364
static gboolean
 
365
xfce_indicator_button_scroll_event (GtkWidget *widget, GdkEventScroll *event)
 
366
{
 
367
  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (widget);
 
368
 
 
369
  g_signal_emit_by_name (button->io, INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED,
 
370
                         button->entry, 1, event->direction);
 
371
 
 
372
  return TRUE;
 
373
}
 
374
 
 
375
 
 
376
static void
 
377
xfce_indicator_button_menu_deactivate (XfceIndicatorButton *button,
 
378
                                       GtkMenu             *menu)
 
379
{
 
380
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
 
381
  g_return_if_fail (GTK_IS_MENU (menu));
 
382
 
 
383
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
 
384
}
 
385
 
 
386
 
 
387
 
 
388
 
 
389
/* When can_focus is true, GtkButton allocates larger size than requested *
 
390
 * and causes the panel image to grow indefinitely.                       *
 
391
 * This workaround compensates for this difference.                       *
 
392
 * Details in https://bugzilla.gnome.org/show_bug.cgi?id=698030           *
 
393
 */
 
394
static gint
 
395
xfce_indicator_button_padding_correction (GtkWidget *widget)
 
396
{
 
397
  GtkStyleContext       *context;
 
398
  gint                   focus_width;
 
399
  gint                   focus_pad;
 
400
  gint                   correction;
 
401
 
 
402
  if (!gtk_widget_get_can_focus (widget))
 
403
    {
 
404
      context = gtk_widget_get_style_context (widget);
 
405
      gtk_style_context_get_style (context,
 
406
                                   "focus-line-width", &focus_width,
 
407
                                   "focus-padding", &focus_pad,
 
408
                                   NULL);
 
409
      correction = (focus_width + focus_pad) * 2;
 
410
    }
 
411
  else
 
412
    {
 
413
      correction = 0;
 
414
    }
 
415
 
 
416
  return correction;
 
417
}
 
418
 
 
419
 
 
420
static void
 
421
xfce_indicator_button_get_preferred_width (GtkWidget *widget,
 
422
                                           gint      *minimum_width,
 
423
                                           gint      *natural_width)
 
424
{
 
425
  gint                 correction;
 
426
 
 
427
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (widget));
 
428
 
 
429
  (*GTK_WIDGET_CLASS (xfce_indicator_button_parent_class)->get_preferred_width) (widget, minimum_width, natural_width);
 
430
 
 
431
  correction = xfce_indicator_button_padding_correction (widget);
 
432
 
 
433
  if (minimum_width != NULL)
 
434
    *minimum_width = MAX (1, *minimum_width - correction);
 
435
 
 
436
  if (natural_width != NULL)
 
437
    *natural_width = MAX (1, *natural_width - correction);
 
438
}
 
439
 
 
440
 
 
441
 
 
442
static void
 
443
xfce_indicator_button_get_preferred_height (GtkWidget *widget,
 
444
                                            gint      *minimum_height,
 
445
                                            gint      *natural_height)
 
446
{
 
447
  gint                 correction;
 
448
 
 
449
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (widget));
 
450
 
 
451
  (*GTK_WIDGET_CLASS (xfce_indicator_button_parent_class)->get_preferred_height) (widget, minimum_height, natural_height);
 
452
 
 
453
  correction = xfce_indicator_button_padding_correction (widget);
 
454
 
 
455
  if (minimum_height != NULL)
 
456
    *minimum_height = MAX (1, *minimum_height - correction);
 
457
 
 
458
  if (natural_height != NULL)
 
459
    *natural_height = MAX (1, *natural_height - correction);
 
460
}