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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "GtkDefs.h"
typedef GtkItemFactoryEntry* Gtk__ItemFactory__Entry;
static void default_ifactory_callback (gpointer callback_data, guint callback_action, GtkWidget *widget);
GtkItemFactoryEntry*
SvGtkItemFactoryEntry(SV *data) {
HV * h;
AV * a;
SV ** s;
GtkItemFactoryEntry* e;
STRLEN len;
if ((!data) || (!SvOK(data)) || (!SvRV(data)) ||
(SvTYPE(SvRV(data)) != SVt_PVHV && SvTYPE(SvRV(data)) != SVt_PVAV))
return NULL;
e = pgtk_alloc_temp(sizeof(GtkItemFactoryEntry));
memset(e,0,sizeof(GtkItemFactoryEntry));
/* path, accelerator, callback_action, item_type */
if (SvTYPE(SvRV(data)) == SVt_PVHV) {
h = (HV*)SvRV(data);
if ((s=hv_fetch(h, "path", 4, 0)) && SvOK(*s))
e->path = SvPV(*s, len);
if ((s=hv_fetch(h, "accelerator", 11, 0)) && SvOK(*s))
e->accelerator = SvPV(*s, len);
if ((s=hv_fetch(h, "action", 6, 0)) && SvOK(*s))
e->callback_action = SvIV(*s);
if ((s=hv_fetch(h, "type", 4, 0)) && SvOK(*s))
e->item_type = SvPV(*s, len);
} else { /* array */
a = (AV*)SvRV(data);
if ((s=av_fetch(a, 0, 0)) && SvOK(*s))
e->path = SvPV(*s, len);
if ((s=av_fetch(a, 1, 0)) && SvOK(*s))
e->accelerator = SvPV(*s, len);
if ((s=av_fetch(a, 2, 0)) && SvOK(*s))
e->callback_action = SvIV(*s);
if ((s=av_fetch(a, 3, 0)) && SvOK(*s))
e->item_type = SvPV(*s, len);
}
if (e->item_type && (!strcmp(e->item_type, "<Branch>") ||
!strcmp(e->item_type, "<LastBranch>")) )
e->callback = NULL;
else
e->callback = default_ifactory_callback;
return e;
}
/* The GtkItemFactoryEntry struct does not have a separate
callback_data member for each item. Instead, the callback_data is
passed into gtk_item_factory_create_item(s), and, to make matters
even worse, gtk_item_factory_create_items() only has a single
callback_data argument. Therefore, we have to get the actual
callback data in a separate function from the one above. */
static SV*
ifactory_sv_get_handler(SV* data)
{
SV* handler = NULL;
if (SvTYPE(SvRV(data)) == SVt_PVHV) {
HV *h = (HV*)SvRV(data);
SV **s;
if ((s = hv_fetch(h, "callback", 8, 0)) && SvOK(*s))
handler = *s;
} else if (SvTYPE(SvRV(data)) == SVt_PVAV) {
AV *a = (AV*)SvRV(data);
SV **s;
if ((s = av_fetch(a, 4, 0)) && SvOK(*s))
handler = *s;
}
return handler;
}
static void
default_ifactory_callback (gpointer callback_data, guint callback_action, GtkWidget *widget)
{
AV * args;
SV * handler;
SV * sv_widget;
int i;
dSP;
if (callback_data == NULL)
return;
PUSHMARK(SP);
args = (AV*)callback_data;
handler = *av_fetch(args, 0, 0);
sv_widget = newSVGtkObjectRef(GTK_OBJECT(widget), 0);
XPUSHs(sv_2mortal(sv_widget));
XPUSHs(sv_2mortal(newSViv(callback_action)));
for (i=1;i<=av_len(args);i++)
XPUSHs(sv_2mortal(newSVsv(*av_fetch(args, i, 0))));
PUTBACK;
perl_call_sv(handler, G_DISCARD);
}
MODULE = Gtk::ItemFactory PACKAGE = Gtk::ItemFactory PREFIX = gtk_item_factory_
#ifdef GTK_ITEM_FACTORY
Gtk::ItemFactory_Sink
gtk_item_factory_new(Class, container_type, path, accel_group)
SV * Class
char* container_type
char* path
Gtk::AccelGroup accel_group
CODE:
{
GtkType wtype;
wtype = gtnumber_for_gtname(container_type);
if (!wtype)
wtype = gtnumber_for_ptname(container_type);
RETVAL = (GtkItemFactory*)(gtk_item_factory_new(wtype, path, accel_group));
}
OUTPUT:
RETVAL
void
gtk_item_factory_construct(item_factory, container_type, path, accel_group)
Gtk::ItemFactory item_factory
char* container_type
char* path
Gtk::AccelGroup accel_group
CODE:
{
GtkType wtype;
wtype = gtnumber_for_gtname(container_type);
if (!wtype)
wtype = gtnumber_for_ptname(container_type);
gtk_item_factory_construct(item_factory, wtype, path, accel_group);
}
void
gtk_item_factory_parse_rc(Class, file_name)
SV* Class
char* file_name
CODE:
gtk_item_factory_parse_rc(file_name);
void
gtk_item_factory_parse_rc_string(Class, rc_string)
SV* Class
char* rc_string
CODE:
gtk_item_factory_parse_rc_string(rc_string);
# gtk_item_factory_parse_rc_scanner()
# gtk_item_factory_from_widget()
void
gtk_item_factory_add_foreign(Class, accel_widget, full_path, accel_group, keyval, modifiers)
SV * Class
Gtk::Widget accel_widget
char * full_path
Gtk::AccelGroup accel_group
unsigned int keyval
Gtk::Gdk::ModifierType modifiers
CODE:
gtk_item_factory_add_foreign(accel_widget, full_path, accel_group, keyval, modifiers);
Gtk::Widget_Up
gtk_item_factory_get_widget(item_factory, path)
Gtk::ItemFactory item_factory
char* path
Gtk::Widget_Up
gtk_item_factory_get_item(item_factory, path)
Gtk::ItemFactory item_factory
char* path
Gtk::Widget_Up
gtk_item_factory_get_widget_by_action(item_factory, action)
Gtk::ItemFactory item_factory
unsigned int action
Gtk::Widget_Up
gtk_item_factory_get_item_by_action(item_factory, action)
Gtk::ItemFactory item_factory
unsigned int action
void
gtk_item_factory_create_item(item_factory, entry, ...)
Gtk::ItemFactory item_factory
Gtk::ItemFactory::Entry entry
CODE:
{
AV *args = NULL;
/* Need to unref args when the item is destroyed.
Should be fixed at the Gtk+ level with a _full
version of the function. */
if (items > 2) {
/* If we have a handler and arg-list, use it */
args = newAV();
PackCallbackST(args, 2);
} else {
SV *handler = ifactory_sv_get_handler(ST(1)); /* entry */
if (handler) {
args = newAV();
PackCallback(args, handler);
} else
entry->callback = NULL;
}
gtk_item_factory_create_item(item_factory, entry, args, 1);
}
void
gtk_item_factory_create_items(item_factory, ...)
Gtk::ItemFactory item_factory
CODE:
{
int i;
for (i = 1; i < items; i++) {
GtkItemFactoryEntry *entry = SvGtkItemFactoryEntry(ST(i));
SV *handler = ifactory_sv_get_handler(ST(i));
AV *args = NULL;
/* As above, args will leak memory :( */
if (handler) {
args = newAV();
PackCallback(args, handler);
} else
entry->callback = NULL;
gtk_item_factory_create_item(item_factory, entry, args, 1);
}
}
void
gtk_item_factory_delete_item(item_factory, path)
Gtk::ItemFactory item_factory
char * path
void
gtk_item_factory_delete_entry(item_factory, entry)
Gtk::ItemFactory item_factory
Gtk::ItemFactory::Entry entry
void
gtk_item_factory_popup(item_factory, x, y, mouse_button, time)
Gtk::ItemFactory item_factory
unsigned int x
unsigned int y
unsigned int mouse_button
unsigned int time
# gtk_item_factory_set_translate_func
#endif
MODULE = Gtk::ItemFactory PACKAGE = Gtk::Widget
#ifdef GTK_ITEM_FACTORY
Gtk::ItemFactory
item_factory(widget)
Gtk::Widget widget
CODE:
RETVAL = gtk_item_factory_from_widget (widget);
OUTPUT:
RETVAL
char*
item_factory_path(widget)
Gtk::Widget widget
CODE:
RETVAL = gtk_item_factory_path_from_widget (widget);
OUTPUT:
RETVAL
#endif
|