~ubuntu-branches/ubuntu/oneiric/gnome-panel/oneiric

« back to all changes in this revision

Viewing changes to applets/wncklet/showdesktop.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-30 11:04:49 UTC
  • mfrom: (1.3.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: james.westby@ubuntu.com-20110530110449-ut1tc5t61rpvf9e3
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * 02111-1307, USA.
22
22
 */
23
23
 
24
 
#define WNCK_I_KNOW_THIS_IS_UNSTABLE 1
25
 
 
26
24
#ifdef HAVE_CONFIG_H
27
25
#include <config.h>
28
26
#endif
32
30
#include <gtk/gtk.h>
33
31
#include <gdk/gdkx.h>
34
32
 
35
 
#include <libwnck/screen.h>
 
33
#include <libwnck/libwnck.h>
36
34
 
37
35
#include "wncklet.h"
38
36
#include "showdesktop.h"
48
46
        GtkWidget *applet;
49
47
        GtkWidget *button;
50
48
        GtkWidget *image;
51
 
        GtkWidget *about_dialog;
52
49
 
53
50
        GtkOrientation orient;
54
51
        int size;
61
58
        GtkIconTheme *icon_theme;
62
59
} ShowDesktopData;
63
60
 
64
 
static void display_help_dialog  (GtkAction       *action,
65
 
                                  ShowDesktopData *sdd);
66
 
static void display_about_dialog (GtkAction       *action,
67
 
                                  ShowDesktopData *sdd);
68
 
 
69
61
static void update_icon           (ShowDesktopData *sdd);
70
62
static void update_button_state   (ShowDesktopData *sdd);
71
63
static void update_button_display (ShowDesktopData *sdd);
135
127
static void
136
128
update_icon (ShowDesktopData *sdd)
137
129
{
138
 
        GtkStyle  *style;
139
130
        int width, height;
140
131
        GdkPixbuf *icon;
141
132
        GdkPixbuf *scaled;
144
135
        int        focus_width = 0;
145
136
        int        focus_pad = 0;
146
137
        int        thickness = 0;
 
138
        GtkStyleContext *context;
 
139
        GtkStateFlags    state;
 
140
        GtkBorder        padding;
147
141
 
148
142
        if (!sdd->icon_theme)
149
143
                return;
150
144
 
151
 
        gtk_widget_style_get (sdd->button,
152
 
                              "focus-line-width", &focus_width,
153
 
                              "focus-padding", &focus_pad,
154
 
                              NULL);
155
 
 
156
 
        style = gtk_widget_get_style (sdd->button);
 
145
        state = gtk_widget_get_state_flags (sdd->button);
 
146
        context = gtk_widget_get_style_context (sdd->button);
 
147
        gtk_style_context_get_padding (context, state, &padding);
 
148
        gtk_style_context_get_style (context,
 
149
                                     "focus-line-width", &focus_width,
 
150
                                     "focus-padding", &focus_pad,
 
151
                                     NULL);
157
152
 
158
153
        switch (sdd->orient) {
159
154
        case GTK_ORIENTATION_HORIZONTAL:
160
 
                thickness = style->ythickness;
 
155
                thickness = padding.top + padding.bottom;
161
156
                break;
162
157
        case GTK_ORIENTATION_VERTICAL:
163
 
                thickness = style->xthickness;
 
158
                thickness = padding.left + padding.right;
164
159
                break;
165
160
        }
166
161
 
167
 
        icon_size = sdd->size - 2 * (focus_width + focus_pad + thickness);
 
162
        icon_size = sdd->size - 2 * (focus_width + focus_pad) - thickness;
168
163
 
169
164
        if (icon_size < 22)
170
165
                icon_size = 16;
224
219
        g_object_unref (icon);
225
220
}
226
221
 
227
 
static const GtkActionEntry show_desktop_menu_actions [] = {
228
 
        { "ShowDesktopHelp", GTK_STOCK_HELP, N_("_Help"),
229
 
          NULL, NULL,
230
 
          G_CALLBACK (display_help_dialog) },
231
 
        { "ShowDesktopAbout", GTK_STOCK_ABOUT, N_("_About"),
232
 
          NULL, NULL,
233
 
          G_CALLBACK (display_about_dialog) }
234
 
};
235
 
 
236
222
/* This updates things that should be consistent with the button's appearance,
237
223
 * and update_button_state updates the button appearance itself
238
224
 */
280
266
applet_destroyed (GtkWidget       *applet,
281
267
                  ShowDesktopData *sdd)
282
268
{
283
 
        if (sdd->about_dialog) {
284
 
                gtk_widget_destroy (sdd->about_dialog);
285
 
                sdd->about_dialog =  NULL;
286
 
        }
287
 
 
288
269
        if (sdd->button_activate != 0) {
289
270
                g_source_remove (sdd->button_activate);
290
271
                sdd->button_activate = 0;
413
394
show_desktop_applet_fill (PanelApplet *applet)
414
395
{
415
396
        ShowDesktopData *sdd;
416
 
        GtkActionGroup  *action_group;
417
 
        gchar           *ui_path;
418
397
        AtkObject       *atk_obj;
 
398
        GtkCssProvider  *provider;
419
399
 
420
400
        panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
421
401
 
445
425
        sdd->button = gtk_toggle_button_new ();
446
426
 
447
427
        gtk_widget_set_name (sdd->button, "showdesktop-button");
448
 
        gtk_rc_parse_string ("\n"
449
 
                             "   style \"showdesktop-button-style\"\n"
450
 
                             "   {\n"
451
 
                             "      GtkWidget::focus-line-width=0\n"
452
 
                             "      GtkWidget::focus-padding=0\n"
453
 
                             "   }\n"
454
 
                             "\n"
455
 
                             "    widget \"*.showdesktop-button\" style \"showdesktop-button-style\"\n"
456
 
                             "\n");
 
428
        provider = gtk_css_provider_new ();
 
429
        gtk_css_provider_load_from_data (provider,
 
430
                                         "#showdesktop-button {\n"
 
431
                                         " -GtkWidget-focus-line-width: 0px;\n"
 
432
                                         " -GtkWidget-focus-padding: 0px;\n"
 
433
                                         "}",
 
434
                                         -1, NULL);
 
435
        gtk_style_context_add_provider (gtk_widget_get_style_context (sdd->button),
 
436
                                        GTK_STYLE_PROVIDER (provider),
 
437
                                        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 
438
        g_object_unref (provider);
457
439
 
458
440
        atk_obj = gtk_widget_get_accessible (sdd->button);
459
441
        atk_object_set_name (atk_obj, _("Show Desktop Button"));
484
466
        panel_applet_set_background_widget (PANEL_APPLET (sdd->applet),
485
467
                                            GTK_WIDGET (sdd->applet));
486
468
 
487
 
        action_group = gtk_action_group_new ("ShowDesktop Applet Actions");
488
 
        gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
489
 
        gtk_action_group_add_actions (action_group,
490
 
                                      show_desktop_menu_actions,
491
 
                                      G_N_ELEMENTS (show_desktop_menu_actions),
492
 
                                      sdd);
493
 
        ui_path = g_build_filename (WNCK_MENU_UI_DIR, "showdesktop-menu.xml", NULL);
494
 
        panel_applet_setup_menu_from_file (PANEL_APPLET (sdd->applet),
495
 
                                           ui_path, action_group);
496
 
        g_free (ui_path);
497
 
        g_object_unref (action_group);
498
 
 
499
469
        g_signal_connect (G_OBJECT (sdd->applet),
500
470
                          "destroy",
501
471
                          G_CALLBACK (applet_destroyed),
516
486
}
517
487
 
518
488
static void
519
 
display_help_dialog (GtkAction       *action,
520
 
                     ShowDesktopData *sdd)
521
 
{
522
 
        wncklet_display_help (sdd->applet, "user-guide",
523
 
                              "gospanel-564", SHOW_DESKTOP_ICON);
524
 
}
525
 
 
526
 
static void
527
 
display_about_dialog (GtkAction       *action,
528
 
                      ShowDesktopData *sdd)
529
 
{
530
 
        static const gchar *authors[] = {
531
 
                "Havoc Pennington <hp@redhat.com>",
532
 
                NULL
533
 
        };
534
 
        static const char *documenters[] = {
535
 
                "Sun GNOME Documentation Team <gdocteam@sun.com>",
536
 
                NULL
537
 
        };
538
 
 
539
 
        /* Translator credits */
540
 
        const char *translator_credits = _("translator-credits");
541
 
 
542
 
        wncklet_display_about (sdd->applet, &sdd->about_dialog,
543
 
                               _("Show Desktop Button"),
544
 
                               "Copyright \xc2\xa9 2002 Red Hat, Inc.",
545
 
                               _("This button lets you hide all windows and show the desktop."),
546
 
                               authors,
547
 
                               documenters,
548
 
                               translator_credits,
549
 
                               SHOW_DESKTOP_ICON,
550
 
                               "show-desktop",
551
 
                               "show-desktop");
552
 
}
553
 
 
554
 
static void
555
489
button_toggled_callback (GtkWidget       *button,
556
490
                         ShowDesktopData *sdd)
557
491
{