static void create_sheets(GtkWidget *parent) { GtkWidget *notebook; GtkWidget *separator; GSList *list; Sheet *sheet; GtkWidget *child; GtkWidget *label; GtkWidget *menu_label; separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (parent), separator, FALSE, TRUE, 3); gtk_widget_show(separator); notebook = gtk_notebook_new (); /* gtk_signal_connect (GTK_OBJECT (notebook), "switch_page", GTK_SIGNAL_FUNC (page_switch), NULL); */ gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), TRUE); gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook)); gtk_container_set_border_width (GTK_CONTAINER (notebook), 1); gtk_box_pack_start (GTK_BOX (parent), notebook, TRUE, TRUE, 0); list = get_sheets_list(); while (list != NULL) { sheet = (Sheet *) list->data; label = gtk_label_new(gettext(sheet->name)); menu_label = gtk_label_new(gettext(sheet->name)); gtk_misc_set_alignment(GTK_MISC(menu_label), 0.0, 0.5); child = create_sheet_page(notebook, sheet); gtk_widget_show(label); gtk_widget_show(menu_label); gtk_widget_show_all(child); gtk_notebook_append_page_menu (GTK_NOTEBOOK (notebook), child, label, menu_label); list = g_slist_next(list); } gtk_widget_show(notebook); }
static void load_register_sheet(const gchar *dirname, const gchar *filename) { xmlDocPtr doc; xmlNsPtr ns; xmlNodePtr node, contents,subnode,root; char *tmp; gchar *name = NULL, *description = NULL; int name_score = -1; int descr_score = -1; Sheet *sheet = NULL; GSList *sheetp; /* the XML fun begins here. */ doc = xmlParseFile(filename); if (!doc) return; root = doc->root; while (root && (root->type != XML_ELEMENT_NODE)) root=root->next; if (!root) return; if (!(ns = xmlSearchNsByHref(doc,root, "http://www.lysator.liu.se/~alla/dia/dia-sheet-ns"))) { g_warning("could not find sheet namespace"); xmlFreeDoc(doc); return; } if ((root->ns != ns) || (strcmp(root->name,"sheet"))) { g_warning("root element was %s -- expecting sheet", doc->root->name); xmlFreeDoc(doc); return; } for (node = root->childs; node != NULL; node = node->next) { if (node->type != XML_ELEMENT_NODE) continue; if (node->ns == ns && !strcmp(node->name, "name")) { gint score; /* compare the xml:lang property on this element to see if we get a * better language match. LibXML seems to throw away attribute * namespaces, so we use "lang" instead of "xml:lang" */ tmp = xmlGetProp(node, "xml:lang"); if (!tmp) tmp = xmlGetProp(node, "lang"); score = intl_score_locale(tmp); if (tmp) free(tmp); if (name_score < 0 || score < name_score) { name_score = score; if (name) free(name); name = xmlNodeGetContent(node); } } else if (node->ns == ns && !strcmp(node->name, "description")) { gint score; /* compare the xml:lang property on this element to see if we get a * better language match. LibXML seems to throw away attribute * namespaces, so we use "lang" instead of "xml:lang" */ tmp = xmlGetProp(node, "xml:lang"); if (!tmp) tmp = xmlGetProp(node, "lang"); score = intl_score_locale(tmp); g_free(tmp); if (descr_score < 0 || score < descr_score) { descr_score = score; if (description) free(description); description = xmlNodeGetContent(node); } } else if (node->ns == ns && !strcmp(node->name, "contents")) { contents = node; } } if (!contents) { g_warning("no contents in sheet %s.", filename); xmlFreeDoc(doc); if (name) free(name); if (description) free(description); return; } sheetp = get_sheets_list(); while (sheetp) { if (sheetp->data && !strcmp(((Sheet *)(sheetp->data))->name,name)) { sheet = sheetp->data; break; } sheetp = sheetp->next; } if (!sheet) sheet = new_sheet(name,description); for (node = contents->childs ; node != NULL; node = node->next) { ObjectType *obj_type; SheetObject *sheet_obj; gboolean isobject = FALSE,isshape = FALSE; gchar *iconname = NULL; int subdesc_score = -1; gchar *objdesc = NULL, *objicon = NULL; gint intdata = 0; gchar *chardata = NULL; if (node->type != XML_ELEMENT_NODE) continue; if (node->ns != ns) continue; if (!strcmp(node->name,"object")) { isobject = TRUE; } else if (!strcmp(node->name,"shape")) { isshape = TRUE; } if (isobject) { tmp = xmlGetProp(node,"intdata"); if (tmp) { char *p; intdata = (gint)strtol(tmp,&p,0); if (*p != 0) intdata = 0; free(tmp); } chardata = xmlGetProp(node,"chardata"); /* TODO.... */ if (chardata) free(chardata); } if (isobject || isshape) { for (subnode = node->childs; subnode != NULL ; subnode = subnode->next) { if (subnode->ns == ns && !strcmp(subnode->name, "description")) { gint score; /* compare the xml:lang property on this element to see if we get a * better language match. LibXML seems to throw away attribute * namespaces, so we use "lang" instead of "xml:lang" */ tmp = xmlGetProp(subnode, "xml:lang"); if (!tmp) tmp = xmlGetProp(subnode, "lang"); score = intl_score_locale(tmp); if (tmp) free(tmp); if (subdesc_score < 0 || score < subdesc_score) { subdesc_score = score; if (objdesc) free(objdesc); objdesc = xmlNodeGetContent(subnode); } } else if (subnode->ns == ns && !strcmp(subnode->name,"icon")) { tmp = xmlNodeGetContent(subnode); iconname = g_strconcat(dirname,G_DIR_SEPARATOR_S,tmp,NULL); if (tmp) free(tmp); } } tmp = xmlGetProp(node,"name"); sheet_obj = g_new(SheetObject,1); sheet_obj->object_type = g_strdup(tmp); sheet_obj->description = objdesc; sheet_obj->pixmap = NULL; sheet_obj->user_data = (void *)intdata; /* XXX modify user_data type ? */ sheet_obj->pixmap_file = iconname; if (isshape) { ShapeInfo *info = shape_info_getbyname(tmp); if (info) { if (!sheet_obj->description) sheet_obj->description = g_strdup(info->description); if (!sheet_obj->pixmap_file && !sheet_obj->pixmap) sheet_obj->pixmap_file = info->icon; sheet_obj->user_data = (void *)info; } else { /* Somehow, this shape is unknown */ g_free(sheet_obj->description); g_free(sheet_obj->pixmap_file); g_free(sheet_obj->object_type); g_free(sheet_obj); if (tmp) free(tmp); continue; } } else { if (shape_info_getbyname(tmp)) { g_warning("Object_type(%s) is really a shape, not an object..",tmp); /* maybe I should listen to what others say, after all, and dump this shape/object distinction ? */ } if (!object_get_type(tmp)) { g_free(sheet_obj->description); g_free(sheet_obj->pixmap_file); g_free(sheet_obj->object_type); g_free(sheet_obj); if (tmp) free(tmp); continue; } } if (tmp) free(tmp); /* we don't need to fix up the icon and descriptions for simple objects, since they don't have their own description, and their icon is already automatically handled. */ sheet_append_sheet_obj(sheet,sheet_obj); } } if (sheet) register_sheet(sheet); xmlFreeDoc(doc); }
gboolean sheets_dialog_create(void) { GList *plugin_list; GSList *sheets_list; GtkWidget *option_menu; GtkWidget *sw; GtkWidget *wrapbox; gchar *sheet_left; gchar *sheet_right; if (sheets_mods_list) { /* not sure if I understood the data structure * but simply leaking isn't acceptable ... --hb */ g_slist_foreach(sheets_mods_list, (GFunc)g_free, NULL); g_slist_free(sheets_mods_list); } sheets_mods_list = NULL; if (sheets_dialog == NULL) { sheets_dialog = create_sheets_main_dialog(); if (!sheets_dialog) { /* don not let a broken builder file crash Dia */ g_warning("SheetDialog creation failed"); return FALSE; } /* Make sure to null our pointer when destroyed */ g_signal_connect (G_OBJECT (sheets_dialog), "destroy", G_CALLBACK (gtk_widget_destroyed), &sheets_dialog); sheet_left = NULL; sheet_right = NULL; } else { option_menu = lookup_widget(sheets_dialog, "optionmenu_left"); sheet_left = g_object_get_data(G_OBJECT(option_menu), "active_sheet_name"); option_menu = lookup_widget(sheets_dialog, "optionmenu_right"); sheet_right = g_object_get_data(G_OBJECT(option_menu), "active_sheet_name"); wrapbox = lookup_widget(sheets_dialog, "wrapbox_left"); if (wrapbox) gtk_widget_destroy(wrapbox); wrapbox = lookup_widget(sheets_dialog, "wrapbox_right"); if (wrapbox) gtk_widget_destroy(wrapbox); } if (custom_type_symbol == NULL) { /* This little bit identifies a custom object symbol so we can tell the difference later between a SVG shape and a Programmed shape */ custom_type_symbol = NULL; for (plugin_list = dia_list_plugins(); plugin_list != NULL; plugin_list = g_list_next(plugin_list)) { PluginInfo *info = plugin_list->data; custom_type_symbol = (gpointer)dia_plugin_get_symbol (info, "custom_type"); if (custom_type_symbol) break; } } if (!custom_type_symbol) { message_warning (_("Can't get symbol 'custom_type' from any module.\n" "Editing shapes is disabled.")); return FALSE; } for (sheets_list = get_sheets_list(); sheets_list; sheets_list = g_slist_next(sheets_list)) sheets_append_sheet_mods(sheets_list->data); sw = lookup_widget(sheets_dialog, "scrolledwindow_right"); /* In case glade already add a child to scrolledwindow */ wrapbox = gtk_bin_get_child (GTK_BIN(sw)); if (wrapbox) gtk_container_remove(GTK_CONTAINER(sw), wrapbox); wrapbox = gtk_hwrap_box_new(FALSE); g_object_ref(wrapbox); g_object_set_data(G_OBJECT(sheets_dialog), "wrapbox_right", wrapbox); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), wrapbox); gtk_wrap_box_set_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_TOP); gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_LEFT); gtk_widget_show(wrapbox); g_object_set_data(G_OBJECT(wrapbox), "is_left", FALSE); option_menu = lookup_widget(sheets_dialog, "optionmenu_right"); sheets_optionmenu_create(option_menu, wrapbox, sheet_right); sw = lookup_widget(sheets_dialog, "scrolledwindow_left"); /* In case glade already add a child to scrolledwindow */ wrapbox = gtk_bin_get_child (GTK_BIN(sw)); if (wrapbox) gtk_container_remove(GTK_CONTAINER(sw), wrapbox); wrapbox = gtk_hwrap_box_new(FALSE); g_object_ref(wrapbox); g_object_set_data(G_OBJECT(sheets_dialog), "wrapbox_left", wrapbox); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), wrapbox); gtk_wrap_box_set_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_TOP); gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_LEFT); gtk_widget_show(wrapbox); g_object_set_data(G_OBJECT(wrapbox), "is_left", (gpointer)TRUE); option_menu = lookup_widget(sheets_dialog, "optionmenu_left"); sheets_optionmenu_create(option_menu, wrapbox, sheet_left); return TRUE; }