static GtkWidget * scrolledwindow_new (GladeXML *xml, GladeWidgetInfo *info) { GtkWidget *win = gtk_scrolled_window_new(NULL, NULL); GList *tmp; GtkPolicyType hpol = GTK_POLICY_ALWAYS, vpol = GTK_POLICY_ALWAYS; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; if (!strcmp(attr->name, "hscrollbar_policy")) hpol = glade_enum_from_string(GTK_TYPE_POLICY_TYPE, attr->value); else if (!strcmp(attr->name, "hupdate_policy")) gtk_range_set_update_policy( GTK_RANGE(GTK_SCROLLED_WINDOW(win)->hscrollbar), glade_enum_from_string(GTK_TYPE_UPDATE_TYPE, attr->value)); else if (!strcmp(attr->name, "shadow_type")) gtk_viewport_set_shadow_type(GTK_VIEWPORT(win), glade_enum_from_string(GTK_TYPE_SHADOW_TYPE, attr->value)); else if (!strcmp(attr->name, "vscrollbar_policy")) vpol = glade_enum_from_string(GTK_TYPE_POLICY_TYPE, attr->value); else if (!strcmp(attr->name, "vupdate_policy")) gtk_range_set_update_policy( GTK_RANGE(GTK_SCROLLED_WINDOW(win)->vscrollbar), glade_enum_from_string(GTK_TYPE_UPDATE_TYPE, attr->value)); } gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(win), hpol, vpol); return win; }
static GtkWidget * panda_clist_new(GladeXML *xml, GladeWidgetInfo *info) { GtkWidget *clist; GList *tmp; int cols = 1; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; if (!strcmp(attr->name, "columns")) { cols = strtol(attr->value, NULL, 0); break; } } clist = gtk_panda_clist_new(cols); cols = 0; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; switch (attr->name[0]) { case 'c': if (!strcmp(attr->name, "column_widths")) { gtk_panda_clist_set_column_widths(GTK_PANDA_CLIST(clist), attr->value); } else if (!strcmp(attr->name, "columns")) { gtk_panda_clist_set_columns( GTK_PANDA_CLIST(clist), atoi(attr->value)); } break; case 's': if (!strcmp(attr->name, "selection_mode")) gtk_panda_clist_set_selection_mode( GTK_PANDA_CLIST(clist), glade_enum_from_string( GTK_TYPE_SELECTION_MODE, attr->value)); else if (!strcmp(attr->name, "show_titles")) { gtk_panda_clist_set_show_titles(GTK_PANDA_CLIST(clist), attr->value[0] == 'T'); } #if 0 else if (!strcmp(attr->name, "shadow_type")) gtk_panda_clist_set_shadow_type(GTK_PANDA_CLIST(clist), glade_enum_from_string( GTK_TYPE_SHADOW_TYPE, attr->value)); #endif break; } } return clist; }
int main(int argc, char **argv) { if (!gtk_init_check(&argc, &argv)) { g_message("Could not init gtk. Skipping test"); return 77; /* magic value to ignore test */ } g_print ("Testing string to enum... "); if (glade_enum_from_string(GTK_TYPE_ANCHOR_TYPE, "GTK_ANCHOR_NORTH_WEST") != GTK_ANCHOR_NORTH_WEST) { g_print("failed\n"); return 1; } g_print("passed\n"); g_print ("Testing nickname string to enum... "); if (glade_enum_from_string(GTK_TYPE_ANCHOR_TYPE, "north-west") != GTK_ANCHOR_NORTH_WEST) { g_print("failed\n"); return 1; } g_print("passed\n"); g_print ("Testing string to enum (single component)... "); if (glade_flags_from_string(GTK_TYPE_ATTACH_OPTIONS, "GTK_EXPAND") != GTK_EXPAND) { g_print("failed\n"); return 1; } g_print("passed\n"); g_print ("Testing nicknamestring to enum (single component)... "); if (glade_flags_from_string(GTK_TYPE_ATTACH_OPTIONS, "expand") != GTK_EXPAND) { g_print("failed\n"); return 1; } g_print("passed\n"); g_print ("Testing string to flag component ordering... "); if ((glade_flags_from_string(GTK_TYPE_ATTACH_OPTIONS, "expand|fill") != (GTK_EXPAND | GTK_FILL)) || (glade_flags_from_string(GTK_TYPE_ATTACH_OPTIONS, "fill|expand") != (GTK_EXPAND | GTK_FILL))) { g_print("failed\n"); return 1; } g_print("passed\n"); g_print ("All tests passed\n"); return 0; }
static GtkWidget * accellabel_new (GladeXML *xml, GladeWidgetInfo *info) { GList *tmp; GtkWidget *label; gchar *string = NULL; GtkJustification just = GTK_JUSTIFY_CENTER; gboolean wrap = FALSE; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; if (!strcmp(attr->name, "label")) { string = attr->value; } else if (!strcmp(attr->name, "justify")) just = glade_enum_from_string(GTK_TYPE_JUSTIFICATION, attr->value); else if (!strcmp(attr->name, "wrap")) wrap = attr->value[0] == 'T'; } label = gtk_accel_label_new(_(string)); if (just != GTK_JUSTIFY_CENTER) gtk_label_set_justify(GTK_LABEL(label), just); if (wrap) gtk_label_set_line_wrap(GTK_LABEL(label), wrap); if (GTK_IS_MISC(label)) misc_set(GTK_MISC(label), info); return label; }
static GtkWidget * notebook_new(GladeXML *xml, GladeWidgetInfo *info) { GtkWidget *notebook = gtk_notebook_new(); GList *tmp; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; if (!strcmp(attr->name, "popup_enable")) { if (attr->value[0] == 'T') gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook)); else gtk_notebook_popup_disable(GTK_NOTEBOOK(notebook)); } else if (!strcmp(attr->name, "scrollable")) gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), attr->value[0] == 'T'); else if (!strcmp(attr->name, "show_border")) gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), attr->value[0] == 'T'); else if (!strcmp(attr->name, "show_tabs")) gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), attr->value[0] == 'T'); else if (!strcmp(attr->name, "tab_pos")) gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), glade_enum_from_string(GTK_TYPE_POSITION_TYPE, attr->value)); } return notebook; }
static GtkWidget * frame_new(GladeXML *xml, GladeWidgetInfo *info) { GtkWidget *frame; GList *tmp; char *label = NULL; gdouble label_xalign = 0; GtkShadowType shadow_type = GTK_SHADOW_ETCHED_IN; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; switch (attr->name[0]) { case 'l': if (!strcmp(attr->name, "label")) label = attr->value; else if (!strcmp(attr->name, "label_xalign")) label_xalign = g_strtod(attr->value, NULL); break; case 's': if (!strcmp(attr->name, "shadow_type")) shadow_type = glade_enum_from_string( GTK_TYPE_SHADOW_TYPE, attr->value); break; } } if (label) frame = gtk_frame_new(_(label)); else frame = gtk_frame_new(NULL); gtk_frame_set_label_align(GTK_FRAME(frame), label_xalign, 0.5); gtk_frame_set_shadow_type(GTK_FRAME(frame), shadow_type); return frame; }
static void mate_add_dock_item (GladeXML *xml, GtkWidget *parent, GladeWidgetInfo *info, GladeChildInfo *childinfo) { MateComponentDockPlacement placement; guint band, offset; int position; MateComponentDockItemBehavior behavior; int i; GtkWidget *child; GtkWidget *toplevel; band = offset = position = 0; placement = MATECOMPONENT_DOCK_TOP; behavior = MATECOMPONENT_DOCK_ITEM_BEH_NORMAL; for (i = 0; i < childinfo->n_properties; i++) { const char *name = childinfo->properties[i].name; const char *value = childinfo->properties[i].value; if (!strcmp (name, "placement")) placement = glade_enum_from_string ( MATECOMPONENT_TYPE_DOCK_PLACEMENT, value); else if (!strcmp (name, "band")) band = strtoul (value, NULL, 10); else if (!strcmp (name, "position")) position = strtol (value, NULL, 10); else if (!strcmp (name, "offset")) offset = strtoul (value, NULL, 10); else if (!strcmp (name, "behavior")) behavior = glade_flags_from_string ( MATECOMPONENT_TYPE_DOCK_ITEM_BEHAVIOR, value); } child = glade_xml_build_widget (xml, childinfo->child); toplevel = gtk_widget_get_ancestor (parent, MATE_TYPE_APP); matecomponent_dock_item_set_behavior (MATECOMPONENT_DOCK_ITEM (child), behavior); if (toplevel != NULL) { mate_app_add_dock_item ( MATE_APP (toplevel), MATECOMPONENT_DOCK_ITEM (child), placement, band, position, offset); } else { matecomponent_dock_add_item (MATECOMPONENT_DOCK (parent), MATECOMPONENT_DOCK_ITEM (child), placement, band, position, offset, FALSE); } }
static void dock_item_set_shadow_type (GladeXML *xml, GtkWidget *widget, const char *name, const char *value) { bonobo_dock_item_set_shadow_type ( BONOBO_DOCK_ITEM (widget), glade_enum_from_string (GTK_TYPE_SHADOW_TYPE, value)); }
static void icon_list_set_selection_mode (GladeXML *xml, GtkWidget *w, const char *name, const char *value) { mate_icon_list_set_selection_mode ( MATE_ICON_LIST (w), glade_enum_from_string (GTK_TYPE_SELECTION_MODE, value)); }
static GtkWidget * progressbar_new(GladeXML *xml, GladeWidgetInfo *info) { GtkWidget *ret = gtk_progress_bar_new(); GList *tmp; gfloat value = 0, lower = 0, upper = 100; gfloat xalign = 0.5, yalign = 0.5; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; if (!strcmp(attr->name, "value")) value = g_strtod(attr->value, NULL); else if (!strcmp(attr->name, "lower")) lower = g_strtod(attr->value, NULL); else if (!strcmp(attr->name, "upper")) upper = g_strtod(attr->value, NULL); else if (!strcmp(attr->name, "activity_mode")) gtk_progress_set_activity_mode(GTK_PROGRESS(ret), attr->value[0]=='T'); else if (!strcmp(attr->name, "bar_style")) gtk_progress_bar_set_bar_style(GTK_PROGRESS_BAR(ret), glade_enum_from_string(GTK_TYPE_PROGRESS_BAR_STYLE, attr->value)); else if (!strcmp(attr->name, "orientation")) gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(ret), glade_enum_from_string( GTK_TYPE_PROGRESS_BAR_ORIENTATION, attr->value)); else if (!strcmp(attr->name, "show_text")) gtk_progress_set_show_text(GTK_PROGRESS(ret), attr->value[0] == 'T'); else if (!strcmp(attr->name, "text_xalign")) xalign = g_strtod(attr->value, NULL); else if (!strcmp(attr->name, "text_yalign")) yalign = g_strtod(attr->value, NULL); else if (!strcmp(attr->name, "format")) gtk_progress_set_format_string(GTK_PROGRESS(ret), attr->value); } gtk_progress_configure(GTK_PROGRESS(ret), value, lower, upper); gtk_progress_set_text_alignment(GTK_PROGRESS(ret), xalign, yalign); return ret; }
static GtkWidget * label_new (GladeXML *xml, GladeWidgetInfo *info) { GList *tmp; GtkWidget *label; guint key; gchar *string = NULL, *focus_target = NULL; GtkJustification just = GTK_JUSTIFY_CENTER; gboolean wrap = FALSE; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; if (!strcmp(attr->name, "label")) { string = attr->value; } else if (!strcmp(attr->name, "justify")) { just = glade_enum_from_string(GTK_TYPE_JUSTIFICATION, attr->value); } else if (!strcmp(attr->name, "default_focus_target")) { if (!focus_target) focus_target = attr->value; } else if (!strcmp(attr->name, "focus_target")) focus_target = attr->value; else if (!strcmp(attr->name, "wrap")) wrap = attr->value[0] == 'T'; } label = gtk_label_new(""); if (string){ char *s = string [0] ? _(string) : ""; key = gtk_label_parse_uline(GTK_LABEL(label), s); } else key = 0; if (key) glade_xml_handle_label_accel(xml, focus_target, key); // for Gtk+1.2 compatibility // in Gtk+2.x Justify > Align #if 0 if (just != GTK_JUSTIFY_CENTER) gtk_label_set_justify(GTK_LABEL(label), just); #endif if (wrap) gtk_label_set_line_wrap(GTK_LABEL(label), wrap); if (GTK_IS_MISC(label)) misc_set (GTK_MISC(label), info); g_object_set(label,"use-markup",TRUE,NULL); return label; }
static GtkWidget * viewport_new(GladeXML *xml, GladeWidgetInfo *info) { GtkWidget *port = gtk_viewport_new(NULL, NULL); GList *tmp; for (tmp = info->attributes; tmp; tmp = tmp->next) { GladeAttribute *attr = tmp->data; if (!strcmp(attr->name, "shadow_type")) gtk_viewport_set_shadow_type(GTK_VIEWPORT(port), glade_enum_from_string(GTK_TYPE_SHADOW_TYPE, attr->value)); } return port; }
static void add_dock_item (GladeXML *xml, GtkWidget *parent, GladeWidgetInfo *info, GladeChildInfo *childinfo) { BonoboDockPlacement placement; guint band, offset; int position; int i; GtkWidget *child; band = offset = position = 0; placement = BONOBO_DOCK_TOP; for (i = 0; i < childinfo->n_properties; i++) { const char *name = childinfo->properties[i].name; const char *value = childinfo->properties[i].value; if (!strcmp (name, "placement")) placement = glade_enum_from_string ( BONOBO_TYPE_DOCK_PLACEMENT, value); else if (!strcmp (name, "band")) band = UINT (value); else if (!strcmp (name, "position")) position = INT (value); else if (!strcmp (name, "offset")) offset = UINT (value); } child = glade_xml_build_widget (xml, childinfo->child); bonobo_dock_add_item (BONOBO_DOCK (parent), BONOBO_DOCK_ITEM (child), placement, band, position, offset, FALSE); }
static GtkWidget * druid_page_edge_new (GladeXML *xml, GType widget_type, GladeWidgetInfo *info) { GtkWidget *druid; MateEdgePosition position = MATE_EDGE_OTHER; int i; const char *title, *text; char *filename; GdkPixbuf *logo, *watermark, *top_watermark; title = text = NULL; logo = watermark = top_watermark = NULL; for (i = 0; i < info->n_properties; i++) { const char *name = info->properties[i].name; const char *value = info->properties[i].value; if (!strcmp (name, "position")) position = glade_enum_from_string ( MATE_TYPE_EDGE_POSITION, value); else if (!strcmp (name, "text")) text = value; else if (!strcmp (name, "title")) title = value; else if (!strcmp (name, "logo")) { if (logo) g_object_unref (G_OBJECT (logo)); filename = glade_xml_relative_file (xml, value); logo = gdk_pixbuf_new_from_file (filename, NULL); g_free (filename); } else if (!strcmp (name, "watermark")) { if (watermark) g_object_unref (G_OBJECT (watermark)); filename = glade_xml_relative_file (xml, value); watermark = gdk_pixbuf_new_from_file (filename, NULL); g_free (filename); } else if (!strcmp (name, "top_watermark")) { if (top_watermark) g_object_unref (G_OBJECT (top_watermark)); filename = glade_xml_relative_file (xml, value); top_watermark = gdk_pixbuf_new_from_file (filename, NULL); g_free (filename); } } druid = glade_standard_build_widget (xml, widget_type, info); mate_druid_page_edge_construct ( MATE_DRUID_PAGE_EDGE (druid), position, TRUE, title, text, logo, watermark, top_watermark); if (logo) g_object_unref (G_OBJECT (logo)); if (watermark) g_object_unref (G_OBJECT (watermark)); if (top_watermark) g_object_unref (G_OBJECT (top_watermark)); return druid; }