Index: app/interface.c =================================================================== --- app/interface.c (revision 3608) +++ app/interface.c (working copy) @@ -913,8 +913,9 @@ } static void -sheet_menu_callback(DiaDynamicMenu *menu, const gchar *string, void *user_data) +sheet_option_menu_changed(DiaDynamicMenu *menu, gpointer user_data) { + char *string = dia_dynamic_menu_get_entry(menu); Sheet *sheet = get_sheet_by_name(string); if (sheet == NULL) { message_warning(_("No sheet named %s"), string); @@ -955,8 +956,9 @@ sheet_option_menu = dia_dynamic_menu_new_stringlistbased(_("Other sheets"), sheet_names, - sheet_menu_callback, NULL, "sheets"); + g_signal_connect(sheet_option_menu, "changed", + G_CALLBACK(sheet_option_menu_changed), sheet_option_menu); dia_dynamic_menu_add_default_entry(DIA_DYNAMIC_MENU(sheet_option_menu), "Assorted"); dia_dynamic_menu_add_default_entry(DIA_DYNAMIC_MENU(sheet_option_menu), Index: lib/widgets.c =================================================================== --- lib/widgets.c (revision 3608) +++ lib/widgets.c (working copy) @@ -271,9 +271,17 @@ struct _DiaFontSelectorClass { GtkHBoxClass parent_class; + void (*default_handler) (DiaFontSelector *dfs); }; +enum { + DFONTSEL_VALUE_CHANGED, + DFONTSEL_LAST_SIGNAL +}; +static guint dfontsel_signals[DFONTSEL_LAST_SIGNAL] = { 0 }; + + /* New and improved font selector: Contains the three standard fonts * and an 'Other fonts...' entry that opens the font dialog. The fonts * selected in the font dialog are persistently added to the menu. @@ -291,9 +299,10 @@ * +----------------+ */ -static void dia_font_selector_fontmenu_callback(DiaDynamicMenu *button, - const gchar *fontname, +static void dia_font_selector_fontmenu_callback(DiaDynamicMenu *ddm, gpointer data); +static void dia_font_selector_stylemenu_callback(GtkMenu *menu, + gpointer data); static void dia_font_selector_set_styles(DiaFontSelector *fs, const gchar *name, DiaFontStyle dia_style); @@ -307,6 +316,16 @@ GtkObjectClass *object_class; object_class = (GtkObjectClass*) class; + + dfontsel_signals[DFONTSEL_VALUE_CHANGED] + = g_signal_new("value_changed" + , G_TYPE_FROM_CLASS(class) + , G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION + , G_STRUCT_OFFSET(DiaFontSelectorClass, default_handler) + , NULL, NULL + , g_cclosure_marshal_VOID__VOID + , G_TYPE_NONE + , 0); } static int @@ -366,15 +385,13 @@ g_strdup(pango_font_family_get_name(families[i]))); } g_free (families); - - fs->font_omenu = - GTK_OPTION_MENU - (dia_dynamic_menu_new_listbased(dia_font_selector_create_string_item, - dia_font_selector_fontmenu_callback, - fs, - _("Other fonts"), - fontnames, - "font-menu")); + + fs->font_omenu = + GTK_OPTION_MENU(dia_dynamic_menu_new_listbased(dia_font_selector_create_string_item, + fs, _("Other fonts"), + fontnames, "font-menu")); + g_signal_connect(fs->font_omenu, "changed", + G_CALLBACK(dia_font_selector_fontmenu_callback), fs); dia_dynamic_menu_add_default_entry(DIA_DYNAMIC_MENU(fs->font_omenu), "sans"); dia_dynamic_menu_add_default_entry(DIA_DYNAMIC_MENU(fs->font_omenu), @@ -387,6 +404,7 @@ omenu = gtk_option_menu_new(); fs->style_omenu = GTK_OPTION_MENU(omenu); menu = gtk_menu_new (); + /* No callback needed since fs->style_menu keeps getting replaced. */ fs->style_menu = GTK_MENU(menu); gtk_option_menu_set_menu (GTK_OPTION_MENU (fs->style_omenu), menu); @@ -448,12 +466,23 @@ } static void -dia_font_selector_fontmenu_callback(DiaDynamicMenu *ddm, const gchar *fontname, gpointer data) +dia_font_selector_fontmenu_callback(DiaDynamicMenu *ddm, gpointer data) { DiaFontSelector *fs = DIAFONTSELECTOR(data); + char *fontname = dia_dynamic_menu_get_entry(ddm); dia_font_selector_set_styles(fs, fontname, -1); + g_signal_emit(GTK_OBJECT(fs), + dfontsel_signals[DFONTSEL_VALUE_CHANGED], 0); } +static void +dia_font_selector_stylemenu_callback(GtkMenu *menu, gpointer data) +{ + DiaFontSelector *fs = DIAFONTSELECTOR(data); + g_signal_emit(GTK_OBJECT(fs), + dfontsel_signals[DFONTSEL_VALUE_CHANGED], 0); +} + static char *style_labels[] = { "Normal", "Oblique", @@ -495,6 +524,9 @@ GSList *group = NULL; menu = gtk_menu_new (); + g_signal_connect(menu, "selection-done", + G_CALLBACK(dia_font_selector_stylemenu_callback), fs); + pango_font_family_list_faces(pff, &faces, &nfaces); for (i = 0; i < nfaces; i++) { @@ -579,6 +611,8 @@ const gchar *fontname = dia_font_get_family(font); /* side effect: adds fontname to presistence list */ dia_dynamic_menu_select_entry(DIA_DYNAMIC_MENU(fs->font_omenu), fontname); + g_signal_emit(GTK_OBJECT(fs), + dfontsel_signals[DFONTSEL_VALUE_CHANGED], 0); dia_font_selector_set_styles(fs, fontname, dia_font_get_style (font)); } @@ -949,11 +983,6 @@ } static void -dia_color_selector_activate(DiaDynamicMenu *ddm, const gchar *entry, gpointer data) -{ -} - -static void dia_color_selector_more_callback(GtkWidget *widget, gpointer userdata) { GtkColorSelectionDialog *dialog = GTK_COLOR_SELECTION_DIALOG (gtk_color_selection_dialog_new(_("Select color"))); @@ -1024,7 +1053,6 @@ { GtkWidget *otheritem = gtk_menu_item_new_with_label(_("More colors...")); GtkWidget *ddm = dia_dynamic_menu_new(dia_color_selector_create_string_item, - dia_color_selector_activate, NULL, GTK_MENU_ITEM(otheritem), "color-menu"); @@ -1095,11 +1123,28 @@ struct _DiaArrowSelectorClass { GtkVBoxClass parent_class; + void (*default_handler) (DiaArrowSelector *dss); }; +enum { + DAS_VALUE_CHANGED, + DAS_LAST_SIGNAL +}; + +static guint das_signals[DAS_LAST_SIGNAL] = {0}; + static void dia_arrow_selector_class_init (DiaArrowSelectorClass *class) { + das_signals[DAS_VALUE_CHANGED] + = g_signal_new("value_changed" + , G_TYPE_FROM_CLASS(class) + , G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION + , G_STRUCT_OFFSET(DiaArrowSelectorClass, default_handler) + , NULL, NULL + , g_cclosure_marshal_VOID__VOID + , G_TYPE_NONE + , 0); } static void @@ -1116,9 +1161,10 @@ } static void -arrow_type_change_callback(DiaDynamicMenu *ddm, const gchar *name, gpointer userdata) +arrow_type_change_callback(DiaDynamicMenu *ddm, gpointer userdata) { set_size_sensitivity(DIA_ARROW_SELECTOR(userdata)); + g_signal_emit(userdata, das_signals[DAS_VALUE_CHANGED], 0); } static GtkWidget * @@ -1145,7 +1191,7 @@ GList *arrow_names = get_arrow_names(); omenu = dia_dynamic_menu_new_listbased(create_arrow_menu_item, - arrow_type_change_callback, as, + as, _("More arrows"), arrow_names, "arrow-menu"); @@ -1156,6 +1202,8 @@ gtk_box_pack_start(GTK_BOX(as), omenu, FALSE, TRUE, 0); gtk_widget_show(omenu); + g_signal_connect(omenu, "changed", G_CALLBACK(arrow_type_change_callback), as); + box = gtk_hbox_new(FALSE,0); as->sizebox = GTK_HBOX(box); @@ -1173,7 +1221,6 @@ gtk_box_pack_start_defaults(GTK_BOX(as), box); gtk_widget_show(box); - } GType @@ -1236,6 +1283,8 @@ arrow_types[arrow_index_from_type(arrow.type)].name); set_size_sensitivity(as); dia_size_selector_set_size(DIA_SIZE_SELECTOR(as->size), arrow.width, arrow.length); + + g_signal_emit(GTK_OBJECT(as), das_signals[DAS_VALUE_CHANGED], 0); } /************* DiaFileSelector: ***************/ @@ -1643,6 +1692,13 @@ static void dia_dynamic_menu_create_menu(DiaDynamicMenu *ddm); static void dia_dynamic_menu_destroy(GtkObject *object); +enum { + DDM_VALUE_CHANGED, + DDM_LAST_SIGNAL +}; + +static guint ddm_signals[DDM_LAST_SIGNAL] = { 0 }; + GtkType dia_dynamic_menu_get_type(void) { @@ -1670,6 +1726,16 @@ GtkObjectClass *object_class = (GtkObjectClass*)class; object_class->destroy = dia_dynamic_menu_destroy; + + ddm_signals[DDM_VALUE_CHANGED] + = g_signal_new("changed" + , G_TYPE_FROM_CLASS(class) + , G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION + , G_STRUCT_OFFSET(DiaDynamicMenuClass, default_handler) + , NULL, NULL + , g_cclosure_marshal_VOID__VOID + , G_TYPE_NONE + , 0); } static void @@ -1702,7 +1768,7 @@ */ GtkWidget * dia_dynamic_menu_new(DDMCreateItemFunc create, - DDMCallbackFunc activate, gpointer userdata, + gpointer userdata, GtkMenuItem *otheritem, gchar *persist) { DiaDynamicMenu *ddm; @@ -1712,7 +1778,6 @@ ddm = DIA_DYNAMIC_MENU ( gtk_type_new (dia_dynamic_menu_get_type ())); ddm->create_func = create; - ddm->activate_func = activate; ddm->userdata = userdata; ddm->other_item = otheritem; ddm->persistent_name = persist; @@ -1746,9 +1811,10 @@ else gtk_option_menu_set_history(GTK_OPTION_MENU(ddm), 0); } - if (ddm->activate_func != NULL) { - (ddm->activate_func)(ddm, name, ddm->userdata); - } + + g_free(ddm->active); + ddm->active = g_strdup(name); + g_signal_emit(GTK_OBJECT(ddm), ddm_signals[DDM_VALUE_CHANGED], 0); } static void @@ -1771,12 +1837,11 @@ */ GtkWidget * dia_dynamic_menu_new_stringbased(GtkMenuItem *otheritem, - DDMCallbackFunc activate, gpointer userdata, gchar *persist) { GtkWidget *ddm = dia_dynamic_menu_new(dia_dynamic_menu_create_string_item, - activate, userdata, + userdata, otheritem, persist); return ddm; } @@ -1787,13 +1852,12 @@ */ GtkWidget * dia_dynamic_menu_new_listbased(DDMCreateItemFunc create, - DDMCallbackFunc activate, gpointer userdata, gchar *other_label, GList *items, gchar *persist) { GtkWidget *item = gtk_menu_item_new_with_label(other_label); - GtkWidget *ddm = dia_dynamic_menu_new(create, activate, userdata, + GtkWidget *ddm = dia_dynamic_menu_new(create, userdata, GTK_MENU_ITEM(item), persist); dia_dynamic_menu_create_sublist(DIA_DYNAMIC_MENU(ddm), items, create); @@ -1807,12 +1871,11 @@ GtkWidget * dia_dynamic_menu_new_stringlistbased(gchar *other_label, GList *items, - DDMCallbackFunc activate, gpointer userdata, gchar *persist) { return dia_dynamic_menu_new_listbased(dia_dynamic_menu_create_string_item, - activate, userdata, + userdata, other_label, items, persist); } @@ -1882,9 +1945,6 @@ GList *tmp; gboolean existed; - g_free(ddm->active); - ddm->active = g_strdup(entry); - for (tmp = ddm->default_entries; tmp != NULL; tmp = g_list_next(tmp)) { if (!g_strcasecmp(tmp->data, entry)) return 0; Index: lib/widgets.h =================================================================== --- lib/widgets.h (revision 3608) +++ lib/widgets.h (working copy) @@ -235,25 +235,23 @@ struct _DiaDynamicMenuClass { GtkOptionMenuClass parent_class; + void (*default_handler) (DiaDynamicMenu *dss); }; GtkType dia_dynamic_menu_get_type (void); GtkWidget *dia_dynamic_menu_new(DDMCreateItemFunc create, - DDMCallbackFunc activate, gpointer userdata, + gpointer userdata, GtkMenuItem *otheritem, gchar *persist); GtkWidget *dia_dynamic_menu_new_stringbased(GtkMenuItem *otheritem, - DDMCallbackFunc activate, gpointer userdata, gchar *persist); GtkWidget *dia_dynamic_menu_new_listbased(DDMCreateItemFunc create, - DDMCallbackFunc activate, gpointer userdata, gchar *other_label, GList *items, gchar *persist); GtkWidget *dia_dynamic_menu_new_stringlistbased(gchar *other_label, GList *items, - DDMCallbackFunc activate, gpointer userdata, gchar *persist); void dia_dynamic_menu_add_default_entry(DiaDynamicMenu *ddm, const gchar *entry);