File: netk-window-menu.c

package info (click to toggle)
libxfcegui4 4.0.6-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,372 kB
  • ctags: 1,672
  • sloc: ansic: 16,344; sh: 8,496; makefile: 207
file content (117 lines) | stat: -rw-r--r-- 2,961 bytes parent folder | download | duplicates (4)
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
/* window menu */

/*
 * Copyright (C) 2001 Havoc Pennington
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "netk-window-menu.h"

static void object_weak_notify (gpointer data, GObject * obj);
static void window_weak_notify (gpointer data, GObject * window);

static void
window_weak_notify (gpointer data, GObject * window)
{
    g_object_set_data (G_OBJECT (data), "netk-window-data", NULL);
    g_object_weak_unref (G_OBJECT (data), object_weak_notify, window);
}

static void
set_window (GObject * obj, NetkWindow * win)
{
    g_object_set_data (obj, "netk-window-data", win);
    if (win)
    {
        g_object_weak_ref (G_OBJECT (win), window_weak_notify, obj);
        g_object_weak_ref (obj, object_weak_notify, win);
    }
}

static void
object_weak_notify (gpointer data, GObject * obj)
{
    g_object_weak_unref (G_OBJECT (data), window_weak_notify, obj);
}

static NetkWindow *
get_window (GObject * obj)
{
    return g_object_get_data (obj, "netk-window-data");
}

static void
item_activated_callback (GtkWidget * menu_item, gpointer data)
{
    NetkWindow *win;

    win = get_window (G_OBJECT (menu_item));

    if (win == NULL)
        return;

    netk_window_activate (win);
}

GtkWidget *
netk_create_window_menu (GList * windows)
{
    GList *tmp;
    GtkWidget *menu;

    menu = gtk_menu_new ();

    tmp = windows;

    while (tmp != NULL)
    {
        NetkWindow *win = NETK_WINDOW (tmp->data);
        GdkPixbuf *icon;
        const char *title;
        GtkWidget *mi;

        icon = netk_window_get_icon (win);
        title = netk_window_get_icon_name (win);

        if (icon)
        {
            GtkWidget *image;

            image = gtk_image_new_from_pixbuf (icon);

            mi = gtk_image_menu_item_new_with_label (title);
            gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image);
        }
        else
        {
            mi = gtk_menu_item_new_with_label (title);
        }

        g_signal_connect (G_OBJECT (mi), "activate",
                          G_CALLBACK (item_activated_callback), NULL);

        set_window (G_OBJECT (mi), win);

        gtk_widget_show (mi);

        gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);

        tmp = tmp->next;
    }

    return menu;
}