~ubuntu-branches/debian/sid/xfce4-indicator-plugin/sid

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Yves-Alexis Perez
  • Date: 2013-06-10 22:22:42 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20130610222242-ihlvt1rlgio67atr
Tags: 1.0.0-1
* New upstream release.
* debian/control:
  - add build-dep on libxfce4ui-1-dev.
* debian/rules:
  - don't ship .la files.
  - ignore plugin for dh_makeshlibs, since it's a plugin.
  - use autotools-dev addon to update config.{guess,sub}.
* debian/control:
  - add build-dep on dpkg-dev for including pkg-info.mk.
  - add build-dep on autotools-dev 

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>
22
32
 
23
33
#include "indicator-button.h"
24
34
 
25
 
static void                 xfce_indicator_button_finalize     (GObject *object);
 
35
 
 
36
#include <libindicator/indicator-object.h>
 
37
//#ifndef INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED
 
38
//#define INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED "scroll-entry"
 
39
//#endif
 
40
 
 
41
 
 
42
static void                 xfce_indicator_button_finalize        (GObject                *object);
 
43
static gint                 xfce_indicator_button_get_icon_size   (XfceIndicatorButton    *button);
 
44
static gboolean             xfce_indicator_button_button_press    (GtkWidget              *widget,
 
45
                                                                   GdkEventButton         *event);
 
46
static gboolean             xfce_indicator_button_scroll          (GtkWidget              *widget,
 
47
                                                                   GdkEventScroll         *event);
 
48
static void                 xfce_indicator_button_menu_deactivate (XfceIndicatorButton    *button,
 
49
                                                                   GtkMenu                *menu);
 
50
static gint                 xfce_indicator_button_get_size        (XfceIndicatorButton    *button);
 
51
 
 
52
 
 
53
 
 
54
struct _XfceIndicatorButton
 
55
{
 
56
  GtkToggleButton       __parent__;
 
57
 
 
58
  IndicatorObject      *io;
 
59
  const gchar          *io_name;
 
60
  IndicatorObjectEntry *entry;
 
61
  GtkMenu              *menu;
 
62
  XfcePanelPlugin      *plugin;
 
63
  IndicatorConfig      *config;
 
64
 
 
65
  GtkWidget            *align_box;
 
66
  GtkWidget            *box;
 
67
  GtkWidget            *label;
 
68
  GtkWidget            *icon;
 
69
  GtkWidget            *orig_icon;
 
70
  gboolean              rectangular_icon;
 
71
 
 
72
  gulong                orig_icon_changed_id;
 
73
  gulong                configuration_changed_id;
 
74
};
 
75
 
 
76
struct _XfceIndicatorButtonClass
 
77
{
 
78
  GtkToggleButtonClass __parent__;
 
79
};
 
80
 
 
81
 
26
82
 
27
83
 
28
84
G_DEFINE_TYPE (XfceIndicatorButton, xfce_indicator_button, GTK_TYPE_TOGGLE_BUTTON)
30
86
static void
31
87
xfce_indicator_button_class_init (XfceIndicatorButtonClass *klass)
32
88
{
33
 
  GObjectClass   *gobject_class;
 
89
  GObjectClass      *gobject_class;
 
90
  GtkWidgetClass    *widget_class;
34
91
 
35
92
  gobject_class = G_OBJECT_CLASS (klass);
36
93
  gobject_class->finalize = xfce_indicator_button_finalize;
 
94
 
 
95
  widget_class = GTK_WIDGET_CLASS (klass);
 
96
  widget_class->button_press_event = xfce_indicator_button_button_press;
 
97
  widget_class->scroll_event = xfce_indicator_button_scroll;
 
98
 
37
99
}
38
100
 
39
101
 
41
103
static void
42
104
xfce_indicator_button_init (XfceIndicatorButton *button)
43
105
{
44
 
  GtkWidget   *outer_container;
45
 
 
46
106
  GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (button), GTK_CAN_DEFAULT | GTK_CAN_FOCUS);
47
107
  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
48
108
  gtk_button_set_use_underline (GTK_BUTTON (button),TRUE);
51
111
 
52
112
  button->io = NULL;
53
113
  button->entry = NULL;
 
114
  button->plugin = NULL;
 
115
  button->config = NULL;
54
116
  button->menu = NULL;
55
117
 
56
118
  button->label = NULL;
57
119
  button->orig_icon = NULL;
58
120
  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);
 
121
  button->orig_icon_changed_id = 0;
 
122
  button->configuration_changed_id = 0;
 
123
  button->rectangular_icon = FALSE;
 
124
 
 
125
  button->align_box = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
 
126
  gtk_container_add (GTK_CONTAINER (button), button->align_box);
 
127
  gtk_widget_show (button->align_box);
 
128
 
 
129
  button->box = xfce_hvbox_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 1);
 
130
  gtk_container_add (GTK_CONTAINER (button->align_box), button->box);
75
131
  gtk_widget_show (button->box);
76
132
}
77
133
 
82
138
{
83
139
  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (object);
84
140
 
 
141
  xfce_indicator_button_disconnect_signals (button);
 
142
 
85
143
  if (button->label != NULL)
86
144
    g_object_unref (G_OBJECT (button->label));
87
145
  if (button->orig_icon != NULL)
105
163
xfce_indicator_button_update_layout (XfceIndicatorButton *button)
106
164
{
107
165
  GtkRequisition          label_size;
 
166
  gfloat                  align_x;
108
167
 
109
168
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
110
169
 
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
 
    }
 
170
  if (button->label != NULL)
 
171
    gtk_label_set_ellipsize (GTK_LABEL (button->label), PANGO_ELLIPSIZE_NONE);
 
172
 
 
173
  /* deskbar mode? */
 
174
  if (button->label != NULL &&
 
175
      indicator_config_get_panel_orientation (button->config) == GTK_ORIENTATION_VERTICAL &&
 
176
      indicator_config_get_orientation (button->config) == GTK_ORIENTATION_HORIZONTAL)
 
177
    {
 
178
      gtk_widget_size_request (button->label, &label_size);
 
179
 
 
180
      /* check if icon and label fit side by side */
 
181
      if (!indicator_config_get_align_left (button->config)
 
182
          || (button->icon != NULL
 
183
              && label_size.width >
 
184
              indicator_config_get_panel_size (button->config)
 
185
              - xfce_indicator_button_get_size (button)))
 
186
        {
 
187
          align_x = 0.5;
 
188
          gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_VERTICAL);
 
189
        }
 
190
      else
 
191
        {
 
192
          align_x = 0.0;
 
193
          gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_HORIZONTAL);
 
194
        }
 
195
 
 
196
      /* check if label alone fits in the panel */
 
197
      if (label_size.width > indicator_config_get_panel_size (button->config) - 6)
 
198
        {
 
199
          gtk_alignment_set (GTK_ALIGNMENT (button->align_box), align_x, 0.5, 1.0, 0.0);
 
200
          gtk_label_set_ellipsize (GTK_LABEL (button->label), PANGO_ELLIPSIZE_END);
 
201
        }
 
202
      else
 
203
        {
 
204
          gtk_alignment_set (GTK_ALIGNMENT (button->align_box), align_x, 0.5, 0.0, 0.0);
 
205
        }
 
206
    }
 
207
  else
 
208
    {
 
209
      gtk_alignment_set (GTK_ALIGNMENT (button->align_box), 0.5, 0.5, 0.0, 0.0);
 
210
      gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box),
 
211
                                      indicator_config_get_orientation (button->config));
 
212
    }
 
213
 
 
214
 
 
215
  if (button->label != NULL)
 
216
    gtk_label_set_angle (GTK_LABEL (button->label),
 
217
                         (indicator_config_get_orientation (button->config) == GTK_ORIENTATION_VERTICAL)
 
218
                         ? -90 : 0);
130
219
}
131
220
 
132
221
 
133
222
 
 
223
 
134
224
static void
135
225
xfce_indicator_button_update_icon (XfceIndicatorButton *button)
136
226
{
137
227
  GdkPixbuf    *pixbuf_s, *pixbuf_d;
138
228
  gdouble       aspect;
139
 
  gint          size;
 
229
  gint          w, h, size;
 
230
  gint          border_thickness;
 
231
  GtkStyle     *style;
140
232
 
141
233
  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 */
 
234
  g_return_if_fail (GTK_IS_IMAGE (button->icon));
 
235
 
 
236
  size = xfce_indicator_button_get_icon_size (button);
 
237
 
147
238
#if 0
148
239
  if (size > 16 && size < 22)
149
240
    size = 16;
157
248
 
158
249
  if (pixbuf_s != NULL)
159
250
    {
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);
 
251
      w = gdk_pixbuf_get_width (pixbuf_s);
 
252
      h = gdk_pixbuf_get_height (pixbuf_s);
 
253
      aspect = (gdouble) w / (gdouble) h;
 
254
 
 
255
      button->rectangular_icon = (w != h);
 
256
 
 
257
      if (indicator_config_get_panel_orientation (button->config) == GTK_ORIENTATION_VERTICAL &&
 
258
          size * aspect > indicator_config_get_panel_size (button->config))
 
259
        {
 
260
          style = gtk_widget_get_style (GTK_WIDGET (button->plugin));
 
261
          border_thickness = 2 * MAX (style->xthickness, style->ythickness);
 
262
          w = indicator_config_get_panel_size (button->config) - border_thickness;
 
263
          h = (gint) (w / aspect);
 
264
        }
166
265
      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);
 
266
        {
 
267
          h = size;
 
268
          w = (gint) (h * aspect);
 
269
        }
 
270
      pixbuf_d = gdk_pixbuf_scale_simple (pixbuf_s, w, h, GDK_INTERP_BILINEAR);
 
271
      gtk_image_set_from_pixbuf (GTK_IMAGE (button->icon), pixbuf_d);
 
272
      g_object_unref (G_OBJECT (pixbuf_d));
171
273
    }
172
274
  else
173
275
    {
174
 
      xfce_panel_image_set_from_source (XFCE_PANEL_IMAGE (button->icon), "image-missing");
 
276
      gtk_image_set_from_icon_name (GTK_IMAGE (button->icon),
 
277
                                    "image-missing", GTK_ICON_SIZE_MENU);
175
278
    }
176
 
 
177
 
  xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), button->icon_size);
 
279
}
 
280
 
 
281
 
 
282
 
 
283
static void
 
284
xfce_indicator_button_label_changed (GtkLabel            *label,
 
285
                                     GParamSpec          *pspec,
 
286
                                     XfceIndicatorButton *button)
 
287
{
 
288
  xfce_indicator_button_update_layout (button);
178
289
}
179
290
 
180
291
 
196
307
 
197
308
      button->label = GTK_WIDGET (label);
198
309
      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
310
      gtk_box_pack_end (GTK_BOX (button->box), button->label, TRUE, FALSE, 1);
 
311
      g_signal_connect(G_OBJECT(button->label), "notify::label", G_CALLBACK(xfce_indicator_button_label_changed), button);
202
312
    }
203
313
  xfce_indicator_button_update_layout (button);
204
314
}
209
319
static void
210
320
on_pixbuf_changed (GtkImage *image, GParamSpec *pspec, XfceIndicatorButton *button)
211
321
{
212
 
  GdkPixbuf     *pixbuf;
213
 
 
214
322
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
215
323
  g_return_if_fail (GTK_IS_IMAGE (image));
216
 
  g_return_if_fail (XFCE_IS_PANEL_IMAGE (button->icon));
 
324
  g_return_if_fail (GTK_IS_IMAGE (button->icon));
217
325
 
218
326
  xfce_indicator_button_update_icon (button);
219
327
}
224
332
xfce_indicator_button_set_image (XfceIndicatorButton *button,
225
333
                                 GtkImage            *image)
226
334
{
227
 
  GdkPixbuf     *pixbuf;
228
 
 
229
335
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
230
336
  g_return_if_fail (GTK_IS_IMAGE (image));
231
337
 
235
341
    {
236
342
      if (button->orig_icon != NULL)
237
343
        {
238
 
          g_signal_handler_disconnect
239
 
            (G_OBJECT (button->orig_icon), button->orig_icon_handler);
 
344
          if (button->orig_icon_changed_id != 0)
 
345
            {
 
346
              g_signal_handler_disconnect (G_OBJECT (button->orig_icon), button->orig_icon_changed_id);
 
347
              button->orig_icon_changed_id = 0;
 
348
            }
240
349
          g_object_unref (G_OBJECT (button->orig_icon));
241
350
        }
242
351
 
249
358
      button->orig_icon = GTK_WIDGET (image);
250
359
      g_object_ref (G_OBJECT (button->orig_icon));
251
360
 
252
 
      button->orig_icon_handler = g_signal_connect
 
361
      button->orig_icon_changed_id = g_signal_connect
253
362
        (G_OBJECT (image), "notify::pixbuf", G_CALLBACK (on_pixbuf_changed), button);
254
363
 
255
 
 
256
 
      button->icon = xfce_panel_image_new ();
 
364
      button->icon = gtk_image_new ();
257
365
      xfce_indicator_button_update_icon (button);
258
366
 
259
367
      gtk_box_pack_start (GTK_BOX (button->box), button->icon, TRUE, FALSE, 1);
278
386
        g_object_unref (G_OBJECT (button->menu));
279
387
      button->menu = menu;
280
388
      g_object_ref (G_OBJECT (button->menu));
 
389
      g_signal_connect_swapped (G_OBJECT (button->menu), "deactivate",
 
390
                                G_CALLBACK (xfce_indicator_button_menu_deactivate), button);
281
391
      gtk_menu_attach_to_widget(menu, GTK_WIDGET (button), NULL);
282
392
    }
283
393
}
324
434
 
325
435
 
326
436
 
 
437
const gchar *
 
438
xfce_indicator_button_get_io_name (XfceIndicatorButton *button)
 
439
{
 
440
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), NULL);
 
441
 
 
442
  return button->io_name;
 
443
}
 
444
 
 
445
 
 
446
 
 
447
guint
 
448
xfce_indicator_button_get_pos (XfceIndicatorButton *button)
 
449
{
 
450
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), 0);
 
451
 
 
452
  return indicator_object_get_location (button->io, button->entry);
 
453
}
 
454
 
 
455
 
 
456
 
 
457
 
 
458
 
 
459
 
 
460
 
327
461
GtkMenu *
328
462
xfce_indicator_button_get_menu (XfceIndicatorButton *button)
329
463
{
334
468
 
335
469
 
336
470
 
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
 
    }
 
471
 
 
472
 
 
473
gboolean
 
474
xfce_indicator_button_is_icon_rectangular (XfceIndicatorButton *button)
 
475
{
 
476
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), FALSE);
 
477
 
 
478
  return button->rectangular_icon;
 
479
}
 
480
 
 
481
 
 
482
 
 
483
 
 
484
static gint
 
485
xfce_indicator_button_get_icon_size (XfceIndicatorButton *button)
 
486
{
 
487
  gint                 indicator_size;
 
488
  gint                 border_thickness;
 
489
  GtkStyle            *style;
 
490
 
 
491
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), 22);
 
492
 
 
493
  indicator_size = xfce_indicator_button_get_size (button);
 
494
 
 
495
  style = gtk_widget_get_style (GTK_WIDGET (button->plugin));
 
496
  border_thickness = 2 * MAX (style->xthickness, style->ythickness);
 
497
 
 
498
  return MIN (indicator_size - border_thickness,
 
499
              indicator_config_get_icon_size_max (button->config));
 
500
}
 
501
 
 
502
 
 
503
 
 
504
static gint
 
505
xfce_indicator_button_get_size (XfceIndicatorButton *button)
 
506
{
 
507
  gint                 border_thickness;
 
508
  GtkStyle            *style;
 
509
 
 
510
  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), 24);
 
511
 
 
512
  style = gtk_widget_get_style (GTK_WIDGET (button->plugin));
 
513
  border_thickness = 2 * MAX (style->xthickness, style->ythickness) ;
 
514
 
 
515
  return MIN (indicator_config_get_panel_size (button->config) /
 
516
              indicator_config_get_nrows (button->config),
 
517
              indicator_config_get_icon_size_max (button->config) + border_thickness);
 
518
}
 
519
 
 
520
 
 
521
 
 
522
 
 
523
static void
 
524
xfce_indicator_configuration_changed (XfceIndicatorButton *button,
 
525
                                      IndicatorConfig     *config)
 
526
{
 
527
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
 
528
  g_return_if_fail (XFCE_IS_INDICATOR_CONFIG (config));
 
529
  g_return_if_fail (GTK_WIDGET (button)->parent != NULL);
 
530
 
 
531
  if (button->orig_icon != NULL)
 
532
    xfce_indicator_button_update_icon (button);
 
533
  xfce_indicator_button_update_layout (button);
407
534
}
408
535
 
409
536
 
410
537
 
411
538
GtkWidget *
412
 
xfce_indicator_button_new (IndicatorObject *io,
413
 
                           IndicatorObjectEntry *entry)
 
539
xfce_indicator_button_new (IndicatorObject      *io,
 
540
                           const gchar          *io_name,
 
541
                           IndicatorObjectEntry *entry,
 
542
                           XfcePanelPlugin      *plugin,
 
543
                           IndicatorConfig      *config)
414
544
{
415
545
  XfceIndicatorButton *button = g_object_new (XFCE_TYPE_INDICATOR_BUTTON, NULL);
 
546
  g_return_val_if_fail (XFCE_IS_INDICATOR_CONFIG (config), NULL);
 
547
  g_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (plugin), NULL);
 
548
 
416
549
  button->io = io;
 
550
  button->io_name = io_name;
417
551
  button->entry = entry;
 
552
  button->plugin = plugin;
 
553
  button->config = config;
 
554
 
418
555
  if (button->io != NULL)
419
556
    g_object_ref (G_OBJECT (button->io));
420
557
  /* IndicatorObjectEntry is not GObject */
421
558
  /* g_object_ref (G_OBJECT (button->entry)); */
 
559
 
 
560
  button->configuration_changed_id =
 
561
    g_signal_connect_swapped (G_OBJECT (button->config), "configuration-changed",
 
562
                              G_CALLBACK (xfce_indicator_configuration_changed), button);
 
563
 
422
564
  return GTK_WIDGET (button);
423
565
}
424
566
 
425
567
 
 
568
 
 
569
void
 
570
xfce_indicator_button_disconnect_signals (XfceIndicatorButton *button)
 
571
{
 
572
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
 
573
 
 
574
  if (button->menu != 0)
 
575
    {
 
576
      gtk_menu_popdown (button->menu);
 
577
    }
 
578
 
 
579
  if (button->configuration_changed_id != 0)
 
580
    {
 
581
      g_signal_handler_disconnect (button->config, button->configuration_changed_id);
 
582
      button->configuration_changed_id = 0;
 
583
    }
 
584
 
 
585
  if (button->orig_icon_changed_id != 0)
 
586
    {
 
587
      g_signal_handler_disconnect (G_OBJECT (button->orig_icon), button->orig_icon_changed_id);
 
588
      button->orig_icon_changed_id = 0;
 
589
    }
 
590
 
 
591
}
 
592
 
 
593
 
 
594
static gboolean
 
595
xfce_indicator_button_button_press (GtkWidget      *widget,
 
596
                                    GdkEventButton *event)
 
597
{
 
598
  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (widget);
 
599
 
 
600
  if(event->button == 1 && button->menu != NULL) /* left click only */
 
601
    {
 
602
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),TRUE);
 
603
      gtk_menu_reposition (GTK_MENU (button->menu));
 
604
      gtk_menu_popup (button->menu, NULL, NULL,
 
605
                      xfce_panel_plugin_position_menu, button->plugin,
 
606
                      event->button, event->time);
 
607
      return TRUE;
 
608
    }
 
609
 
 
610
  return FALSE;
 
611
}
 
612
 
 
613
 
 
614
static gboolean
 
615
xfce_indicator_button_scroll (GtkWidget *widget, GdkEventScroll *event)
 
616
{
 
617
  XfceIndicatorButton *button = XFCE_INDICATOR_BUTTON (widget);
 
618
 
 
619
  g_signal_emit_by_name (button->io, INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED,
 
620
                         button->entry, 1, event->direction);
 
621
 
 
622
  return TRUE;
 
623
}
 
624
 
 
625
 
 
626
static void
 
627
xfce_indicator_button_menu_deactivate (XfceIndicatorButton *button,
 
628
                                       GtkMenu             *menu)
 
629
{
 
630
  g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
 
631
  g_return_if_fail (GTK_IS_MENU (menu));
 
632
 
 
633
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
 
634
}