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
127
128
129
130
|
/*
* Copyright (C) 2000 Marco Pesenti Gritti
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "ephy-glade.h"
#include "ephy-file-helpers.h"
#include <glade/glade-xml.h>
#include <gtk/gtkmenu.h>
#include <gmodule.h>
static void
glade_signal_connect_func (const gchar *cb_name, GObject *obj,
const gchar *signal_name, const gchar *signal_data,
GObject *conn_obj, gboolean conn_after,
gpointer user_data);
/**
* ephy_widget_new: build a new widget of the provided name, with all
* signals attached and data set to the provided parameter.
*/
GladeXML *
ephy_glade_widget_new (const char *file, const char *widget_name,
GtkWidget **root, gpointer data)
{
GladeXML *gxml;
/* build the widget */
/* note that libglade automatically caches the parsed file,
* so we don't need to worry about the efficiency of this */
gxml = glade_xml_new (file, widget_name, NULL);
g_return_val_if_fail (gxml != NULL, NULL);
/* lookup the root widget if requested */
if (root != NULL)
{
*root = glade_xml_get_widget (gxml, widget_name);
}
/* connect signals and data */
glade_xml_signal_autoconnect_full
(gxml, (GladeXMLConnectFunc)glade_signal_connect_func, data);
/* return xml document for subsequent widget lookups */
return gxml;
}
/*
* glade_signal_connect_func: used by glade_xml_signal_autoconnect_full
*/
static void
glade_signal_connect_func (const gchar *cb_name, GObject *obj,
const gchar *signal_name, const gchar *signal_data,
GObject *conn_obj, gboolean conn_after,
gpointer user_data)
{
/** Module with all the symbols of the program */
static GModule *mod_self = NULL;
gpointer handler_func;
/* initialize gmodule */
if (mod_self == NULL)
{
mod_self = g_module_open (NULL, 0);
g_assert (mod_self != NULL);
}
/*g_print( "glade_signal_connect_func: cb_name = '%s', signal_name = '%s', signal_data = '%s'\n",
cb_name, signal_name, signal_data ); */
if (g_module_symbol (mod_self, cb_name, &handler_func))
{
/* found callback */
if (conn_obj)
{
if (conn_after)
{
g_signal_connect_object
(obj, signal_name,
handler_func, conn_obj,
G_CONNECT_AFTER);
}
else
{
g_signal_connect_object
(obj, signal_name,
handler_func, conn_obj,
G_CONNECT_SWAPPED);
}
}
else
{
/* no conn_obj; use standard connect */
gpointer data = NULL;
data = user_data;
if (conn_after)
{
g_signal_connect_after
(obj, signal_name,
handler_func, data);
}
else
{
g_signal_connect
(obj, signal_name,
handler_func, data);
}
}
}
else
{
g_warning("callback function not found: %s", cb_name);
}
}
|