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
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
/* -*- C -*- */ 
require libglade; 
 
class GTK2.GladeXML; 
inherit G.Object; 
 
%{ 
#include <glade/glade.h> 
 
/* This function is used by signal_autoconnect to handle signal connection. 
 * Basically it uses a mapping and data from the stack to do signal callbacks 
 * exactly in the same way as normal signals in PiGTK. 
 */ 
static void pgtk2__signal_connect(const gchar *handler_name, 
                                 GObject *object, 
                                 const gchar *signal_name, 
                                 const gchar *signal_data, 
                                 GObject *connect_object, 
                                 gboolean after, 
                                 gpointer args) 
{ 
  struct mapping *callbacks; 
  struct svalue *data; 
  int id; 
  struct signal_data *b; 
  struct svalue *cb; 
  struct pike_string *funname; 
  guint signal_id; 
  GClosure *gc; 
#ifdef GLADE_CONNECT_DEBUG 
  fprintf(stderr,"Connecting handler %s, signal %s,\n data %s, " 
                 "after: %d\n", 
                 handler_name,signal_name,signal_data,after); 
#endif 
  get_all_args(NULL,*(INT32 *)args,"%m%*",&callbacks,&data); 
/* 
  funname=make_shared_string(handler_name); 
  cb=low_mapping_string_lookup(callbacks,funname); 
  free_string(funname); 
*/ 
  cb=simple_mapping_string_lookup(callbacks,handler_name); 
  if (cb==NULL) { 
    fprintf(stderr,"** WARNING **: Unknown function %s for signal %s\n", 
            handler_name,signal_name); 
    return; 
  } else if (TYPEOF(*cb) != PIKE_T_FUNCTION) { 
    fprintf(stderr,"** WARNING **: Value for handler %s for signal %s not a function.\n", 
            handler_name,signal_name); 
    return; 
  } 
  b=(struct signal_data *)g_malloc(sizeof(struct signal_data)); 
  if (b==NULL) 
    Pike_error(msg_out_of_mem); 
  assign_svalue_no_free(&b->cb,cb); 
  assign_svalue_no_free(&b->args,data); 
  b->signal_id=g_signal_lookup(signal_name,G_TYPE_FROM_INSTANCE(object)); 
  if (!b->signal_id) { 
    g_free(b); 
    fprintf(stderr, 
            "** WARNING **; Signal \"%s\" not defined in the '%s' " 
            "class ancestry.\n", 
            signal_name,g_type_name(G_TYPE_FROM_INSTANCE(object))); 
  } 
/* 
  id=g_signal_connect_data(G_OBJECT(object),signal_name, 
                           G_CALLBACK(pgtk2_signal_func_wrapper),b, 
                           (GClosureNotify)pgtk2_free_signal_data, 
                           G_CONNECT_SWAPPED); 
*/ 
  gc=g_cclosure_new_swap(G_CALLBACK(pgtk2_signal_func_wrapper),b, 
                         (GClosureNotify)pgtk2_free_signal_data); 
  g_closure_set_marshal(gc,pgtk2_marshaller); 
  id=g_signal_connect_closure(G_OBJECT(object),signal_name,gc,1); 
  g_object_set_data(G_OBJECT(object),"signal-data",b); 
} 
%} 
 
//! Glade is a free GUI builder for GTK2+ and Gnome.  It's normally used to 
//! create C-code, but can also produce code for other languages.  Libglade 
//! is a utility library that builds the GI from the Glade XML save files. 
//! This module uses libglade and allows you to easily make GUI designs to be 
//! used with your Pike applications. 
 
void create(string filename_or_buffer, ?int size, ?string root, ?string domain) 
//! Creates a new GladeXML object (and the corresponding widgets) from the 
//! XML file.  Optionally it will only build the interface from the widget 
//! node root.  This feature is useful if you only want to build say a 
//! toolbar or menu from the XML file, but not the window it is embedded in. 
//! Note also that the XML parse tree is cached to speed up creating another 
//! GladeXML object from the same file.  The third optional argument is used to 
//! specify a different translation domain from the default to be used. 
//! If xml description is in a string buffer instead, specify the size (or -1 
//! to auto-calculate).  If size is 0, then it will assume a file with root 
//! and/or domain specified. 
{ 
  pgtk2_verify_not_inited(); 
  pgtk2_verify_setup(); 
  { 
    GladeXML *gl; 
    struct pike_string *fname; 
    char *root=NULL,*dom=NULL; 
    INT_TYPE size=0; 
    get_all_args(NULL,args,"%n.%i%s%s",&fname,&size,&root,&dom); 
    if (size==0) 
      gl=glade_xml_new(fname->str,root,dom); 
    else if ((size < 0) || (size > fname->len)) 
      gl=glade_xml_new_from_buffer(fname->str,fname->len,root,dom); 
    else 
      gl=glade_xml_new_from_buffer(fname->str,size,root,dom); 
    THIS->obj=G_OBJECT(gl); 
  } 
  pgtk2_pop_n_elems(args); 
  pgtk2__init_this_object(); 
} 
 
+GTK2.Widget get_widget(string name) 
//! This function is used to get the widget corresponding to name in the 
//! interface description.  You would use this if you have to do anything to 
//! the widget after loading. 
{ 
  pgtk2_verify_inited(); 
  { 
    char *name; 
    GtkWidget *widget; 
    get_all_args(NULL,args,"%s",&name); 
    widget=glade_xml_get_widget(GLADE_XML(THIS->obj),name); 
    pgtk2_pop_n_elems(args); 
    push_gobject(widget); 
  } 
} 
 
array(GTK2.Widget) get_widget_prefix(string name) 
//! This function is used to get a list GTK2.Widgets with names that start with 
//! the string name in the interface description. 
{ 
  pgtk2_verify_inited(); 
  { 
    char *name; 
    GList *gl,*g2; 
    int i=0; 
    get_all_args(NULL,args,"%s",&name); 
    gl=g2=glade_xml_get_widget_prefix(GLADE_XML(THIS->obj),name); 
    pgtk2_pop_n_elems(args); 
    while (g2) { 
      push_gobject(g2->data); 
      g_object_ref(g2->data); 
      i++; 
      g2=g_list_next(g2); 
    } 
    f_aggregate(i); 
    g_list_free(gl); 
  } 
} 
 
string get_widget_name(GTK2.Widget widget) 
//! Used to get the name of a widget that was generated by a GladeXML object. 
{ 
  pgtk2_verify_inited(); 
  { 
    const char *s; 
    struct object *o1; 
    GtkWidget *widget; 
    get_all_args(NULL,args,"%o",&o1); 
    widget=GTK_WIDGET(get_gobject(o1)); 
    if (!widget) 
      Pike_error("GladeXML->get_widget_name:  Invalid argument 1, wanted GTK2 object of type WIDGET.\n"); 
    s=glade_get_widget_name(widget); 
    pgtk2_pop_n_elems(args); 
    push_text(s); 
/* Per documentation, don't free this */ 
/*    g_free((void *)s); */ 
  } 
} 
 
int get_signal_id(GTK2.Widget widget) 
//! Used to get the signal id attached to a GladeXML object. 
{ 
  pgtk2_verify_inited(); 
  { 
    int id; 
    struct object *o1; 
    GtkWidget *w; 
    struct signal_data *sd; 
 
    get_all_args(NULL,args,"%o",&o1); 
    w=GTK_WIDGET(get_gobject(o1)); 
    if (!w) 
      Pike_error("GladeXML->get_signal_id:  Invalid argument 1, wanted GTK2 object of type WIDGET.\n"); 
    sd=g_object_get_data(G_OBJECT(w),"signal-data"); 
    pgtk2_pop_n_elems(args); 
    if (sd) 
      push_int(sd->signal_id); 
    else 
      push_int(-1); 
  } 
} 
 
void signal_autoconnect(mapping(string:function) callbacks, mixed data) 
//! Try to connect functions to all signals in the interface.  The mapping 
//! should consist of handler name : function pairs.  The data argument will 
//! be saved and sent as the first argument to all callback functions. 
{ 
  pgtk2_verify_inited(); 
  if (args!=2 || TYPEOF(Pike_sp[-args]) != PIKE_T_MAPPING) 
    Pike_error("GTK2.GladeXML->signal_autoconnect: Invalid arguments, expected (mapping,mixed)\n"); 
  glade_xml_signal_autoconnect_full(GLADE_XML(THIS->obj),pgtk2__signal_connect,&args); 
  RETURN_THIS(); 
} 
 
endrequire;