aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-label-action.c
blob: 766fb7e0d23244492f4a9acd9245424b048dd886 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * e-mail-label-action.c
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "e-mail-label-action.h"

#define E_MAIL_LABEL_ACTION_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_MAIL_LABEL_ACTION, EMailLabelActionPrivate))

struct _EMailLabelActionPrivate {
    gint placeholder;
};

G_DEFINE_TYPE (EMailLabelAction, e_mail_label_action, GTK_TYPE_TOGGLE_ACTION)

static void
mail_label_action_menu_item_realize_cb (GtkWidget *menu_item)
{
    GtkAction *action;
    GtkActivatable *activatable;
    GtkWidget *container;
    GtkWidget *widget;

    activatable = GTK_ACTIVATABLE (menu_item);
    action = gtk_activatable_get_related_action (activatable);
    g_return_if_fail (E_IS_MAIL_LABEL_ACTION (action));

    /* Prevent GtkMenuItem's sync_action_properties() method from
     * destroying our hack.  Instead we use EBindings to keep the
     * label and image in sync with the action. */
    gtk_activatable_set_use_action_appearance (activatable, FALSE);

    /* Remove the menu item's child widget. */
    widget = gtk_bin_get_child (GTK_BIN (menu_item));
    gtk_widget_destroy (widget);

    /* Now add our own child widget. */

    widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
    gtk_container_add (GTK_CONTAINER (menu_item), widget);
    gtk_widget_show (widget);

    container = widget;

    widget = gtk_action_create_icon (action, GTK_ICON_SIZE_MENU);
    gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
    gtk_widget_show (widget);

    widget = gtk_label_new (NULL);
    gtk_label_set_use_underline (GTK_LABEL (widget), TRUE);
    gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
    gtk_widget_show (widget);

    g_object_bind_property (
        action, "label",
        widget, "label",
        G_BINDING_BIDIRECTIONAL |
        G_BINDING_SYNC_CREATE);
}

static GtkWidget *
mail_label_action_create_menu_item (GtkAction *action)
{
    GtkWidget *menu_item;

    menu_item = gtk_check_menu_item_new ();

    g_signal_connect (
        menu_item, "realize",
        G_CALLBACK (mail_label_action_menu_item_realize_cb), NULL);

    return menu_item;
}

static void
e_mail_label_action_class_init (EMailLabelActionClass *class)
{
    GtkActionClass *action_class;

    g_type_class_add_private (class, sizeof (EMailLabelActionPrivate));

    action_class = GTK_ACTION_CLASS (class);
    action_class->create_menu_item = mail_label_action_create_menu_item;
}

static void
e_mail_label_action_init (EMailLabelAction *action)
{
    action->priv = E_MAIL_LABEL_ACTION_GET_PRIVATE (action);
}

EMailLabelAction *
e_mail_label_action_new (const gchar *name,
                         const gchar *label,
                         const gchar *tooltip,
                         const gchar *stock_id)
{
    g_return_val_if_fail (name != NULL, NULL);

    return g_object_new (
        E_TYPE_MAIL_LABEL_ACTION,
        "name", name, "label", label,
        "tooltip", tooltip, "stock-id", stock_id, NULL);
}