Mercurial > pidgin
comparison finch/libgnt/gntutils.c @ 19171:9f7587b86b0d
propagate from branch 'tmpbranch' (head e6743aa2d424749cd40350df703d079ef61fd5ce)
to branch 'im.pidgin.soc.2007.finchfeat' (head a87f346863ddc48e5705c2c555c7ed842325a9a3)
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Sun, 22 Jul 2007 01:28:19 +0000 |
parents | cf7297803a73 |
children | 85b155a574a3 |
comparison
equal
deleted
inserted
replaced
19170:315fd66bb08f | 19171:9f7587b86b0d |
---|---|
232 return tree; | 232 return tree; |
233 } | 233 } |
234 | 234 |
235 #ifndef NO_LIBXML | 235 #ifndef NO_LIBXML |
236 static GntWidget * | 236 static GntWidget * |
237 gnt_widget_from_xmlnode(xmlNode *node, GntWidget **data[]) | 237 gnt_widget_from_xmlnode(xmlNode *node, GntWidget **data[], int max) |
238 { | 238 { |
239 GntWidget *widget = NULL; | 239 GntWidget *widget = NULL; |
240 char *name; | 240 char *name; |
241 char *id, *prop, *content; | 241 char *id, *prop, *content; |
242 int val; | 242 int val; |
282 gnt_box_set_pad(GNT_BOX(widget), val); | 282 gnt_box_set_pad(GNT_BOX(widget), val); |
283 xmlFree(prop); | 283 xmlFree(prop); |
284 } | 284 } |
285 | 285 |
286 for (ch = node->children; ch; ch=ch->next) | 286 for (ch = node->children; ch; ch=ch->next) |
287 gnt_box_add_widget(GNT_BOX(widget), gnt_widget_from_xmlnode(ch, data)); | 287 gnt_box_add_widget(GNT_BOX(widget), gnt_widget_from_xmlnode(ch, data, max)); |
288 } else if (strcmp(name, "button") == 0) { | 288 } else if (strcmp(name, "button") == 0) { |
289 widget = gnt_button_new(content); | 289 widget = gnt_button_new(content); |
290 } else if (strcmp(name, "label") == 0) { | 290 } else if (strcmp(name, "label") == 0) { |
291 widget = gnt_label_new(content); | 291 widget = gnt_label_new(content); |
292 } else if (strcmp(name, "entry") == 0) { | 292 } else if (strcmp(name, "entry") == 0) { |
311 } | 311 } |
312 | 312 |
313 id = (char*)xmlGetProp(node, (xmlChar*)"id"); | 313 id = (char*)xmlGetProp(node, (xmlChar*)"id"); |
314 if (id) { | 314 if (id) { |
315 int i; | 315 int i; |
316 sscanf(id, "%d", &i); | 316 if (sscanf(id, "%d", &i) == 1 && i >= 0 && i < max) { |
317 *data[i] = widget; | 317 *data[i] = widget; |
318 xmlFree(id); | 318 xmlFree(id); |
319 } | |
319 } | 320 } |
320 | 321 |
321 prop = (char*)xmlGetProp(node, (xmlChar*)"border"); | 322 prop = (char*)xmlGetProp(node, (xmlChar*)"border"); |
322 if (prop) { | 323 if (prop) { |
323 int val; | 324 int val; |
364 va_start(list, num); | 365 va_start(list, num); |
365 for (id = 0; id < num; id++) | 366 for (id = 0; id < num; id++) |
366 data[id] = va_arg(list, gpointer); | 367 data[id] = va_arg(list, gpointer); |
367 | 368 |
368 node = xmlDocGetRootElement(doc); | 369 node = xmlDocGetRootElement(doc); |
369 gnt_widget_from_xmlnode(node, data); | 370 gnt_widget_from_xmlnode(node, data, num); |
370 | 371 |
371 xmlFreeDoc(doc); | 372 xmlFreeDoc(doc); |
372 xmlCleanupParser(); | 373 xmlCleanupParser(); |
373 va_end(list); | 374 va_end(list); |
374 g_free(data); | 375 g_free(data); |
375 #endif | 376 #endif |
376 } | 377 } |
377 | 378 |
379 /* Setup trigger widget */ | |
380 typedef struct { | |
381 char *text; | |
382 GntWidget *button; | |
383 } TriggerButton; | |
384 | |
385 static void | |
386 free_trigger_button(TriggerButton *b) | |
387 { | |
388 g_free(b->text); | |
389 g_free(b); | |
390 } | |
391 | |
392 static gboolean | |
393 key_pressed(GntWidget *widget, const char *text, TriggerButton *trig) | |
394 { | |
395 if (text && trig->text && | |
396 strcmp(text, trig->text) == 0) { | |
397 gnt_widget_activate(trig->button); | |
398 return TRUE; | |
399 } | |
400 return FALSE; | |
401 } | |
402 | |
403 void gnt_util_set_trigger_widget(GntWidget *wid, const char *text, GntWidget *button) | |
404 { | |
405 TriggerButton *tb = g_new0(TriggerButton, 1); | |
406 tb->text = g_strdup(text); | |
407 tb->button = button; | |
408 g_signal_connect(G_OBJECT(wid), "key_pressed", G_CALLBACK(key_pressed), tb); | |
409 g_signal_connect_swapped(G_OBJECT(button), "destroy", G_CALLBACK(free_trigger_button), tb); | |
410 } | |
411 |