changeset 1667:0806ccdfe06b

simplified menu_item_add_radio usage
author nadvornik
date Sat, 27 Jun 2009 20:12:56 +0000
parents fa942b3f0ef5
children 8ebc26a4383f
files src/bar_gps.c src/bar_histogram.c src/layout_util.c src/menu.c src/ui_menu.c src/ui_menu.h
diffstat 6 files changed, 50 insertions(+), 149 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_gps.c	Sat Jun 27 17:54:31 2009 +0000
+++ b/src/bar_gps.c	Sat Jun 27 20:12:56 2009 +0000
@@ -384,17 +384,15 @@
 
 static void bar_pane_gps_change_map_cb(GtkWidget *widget, gpointer data)
 {
-	PaneGPSData *pgd;
+	PaneGPSData *pgd = data;
 	gchar *mapsource;
 
 	if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
 		return;
 
-	pgd = (PaneGPSData *) submenu_item_get_data(widget);
-
 	if (!pgd) return;
 
-	mapsource = data;
+	mapsource = g_object_get_data(G_OBJECT(widget), "menu_item_radio_data");
 	bar_pane_gps_set_map_source(pgd, mapsource);
 }
 
@@ -554,51 +552,28 @@
 	return map_id;
 }
 
-static GtkWidget *bar_pane_gps_add_radio(GtkWidget *menu, GtkWidget *parent,
-             								const gchar *label, GCallback func, gchar *value,
-               								gboolean show_current, const gchar *current_value)
-{
-	GtkWidget *item;
-
-	if (show_current)
-		{
-		item = menu_item_add_radio(menu, parent,
-		                        	label, (g_strcmp0(value, current_value) == 0), func, value);
-		}
-		else
-		{
-		item = menu_item_add(menu, label, func, value);
-		}
-
-	return item;
-}
-
 static GtkWidget *bar_pane_gps_menu(PaneGPSData *pgd)
 {
 	GtkWidget *menu;
 	GtkWidget *map_centre;
-	static gboolean show_current = TRUE;
 	GtkWidget *parent;
 	ChamplainMapSourceFactory *map_factory;
 	GSList *map_list;
 	ChamplainMapSourceDesc *map_desc;
+	const gchar *current;
 
 	menu = popup_menu_short_lived();
 
 	map_factory = champlain_map_source_factory_get_default();
 	map_list = champlain_map_source_factory_get_list(map_factory);
-	map_desc = (ChamplainMapSourceDesc *)(map_list->data);
-	map_list = g_slist_next(map_list);
-
-	g_object_set_data(G_OBJECT(menu), "submenu_data", pgd);
-
-	parent = bar_pane_gps_add_radio(menu, NULL, (map_desc->name),  G_CALLBACK(bar_pane_gps_change_map_cb), map_desc->id, show_current, bar_pane_gps_get_map_id(pgd));
+	current = bar_pane_gps_get_map_id(pgd);
 
 	while (map_list)
 		{
-	    map_desc = (ChamplainMapSourceDesc *)(map_list->data);
-		bar_pane_gps_add_radio(menu, parent, (map_desc->name), G_CALLBACK(bar_pane_gps_change_map_cb), map_desc->id,
-											show_current, bar_pane_gps_get_map_id(pgd));
+		map_desc = (ChamplainMapSourceDesc *)(map_list->data);
+		
+		menu_item_add_radio(menu, map_desc->name, map_desc->id, strcmp(map_desc->id, current) == 0, G_CALLBACK(bar_pane_gps_change_map_cb), pgd); 
+		
 		map_list = g_slist_next(map_list);
 		}
 		
@@ -717,8 +692,10 @@
 
 	scrolled = gtk_scrolled_window_new(NULL, NULL);
 	vbox = gtk_vbox_new(FALSE, 0);
-	view = champlain_view_new();
-	gpswidget = champlain_view_embed_new(CHAMPLAIN_VIEW(view));
+
+	gpswidget = gtk_champlain_embed_new ();
+	view = gtk_champlain_embed_get_view (GTK_CHAMPLAIN_EMBED (gpswidget));
+
 	viewport = gtk_viewport_new(NULL, NULL);
 	
 	gtk_container_add(GTK_CONTAINER(viewport), gpswidget);
--- a/src/bar_histogram.c	Sat Jun 27 17:54:31 2009 +0000
+++ b/src/bar_histogram.c	Sat Jun 27 20:12:56 2009 +0000
@@ -198,123 +198,55 @@
 
 static void bar_pane_histogram_popup_channels_cb(GtkWidget *widget, gpointer data)
 {
-	PaneHistogramData *phd;
+	PaneHistogramData *phd = data;
 	gint channel;
 
 	if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
 
-	phd = submenu_item_get_data(widget);
-
 	if (!phd) return;
 
-	channel = GPOINTER_TO_INT(data);
+	channel = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "menu_item_radio_data"));
 	if (channel == histogram_get_channel(phd->histogram)) return;
 
 	histogram_set_channel(phd->histogram, channel);
 	bar_pane_histogram_update(phd);
 }
 
-static void bar_pane_histogram_popup_logmode_cb(GtkWidget *widget, gpointer data)
+static void bar_pane_histogram_popup_mode_cb(GtkWidget *widget, gpointer data)
 {
-	PaneHistogramData *phd;
+	PaneHistogramData *phd = data;
 	gint logmode;
 	
 	if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
 
-	phd = submenu_item_get_data(widget);
-
 	if (!phd) return;
 
-	logmode = GPOINTER_TO_INT(data);
+	logmode = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "menu_item_radio_data"));
 	if (logmode == histogram_get_mode(phd->histogram)) return;
 
 	histogram_set_mode(phd->histogram, logmode);
 	bar_pane_histogram_update(phd);
 }
 
-static GtkWidget *bar_pane_histogram_add_radio(GtkWidget *menu, GtkWidget *parent,
-					const gchar *label,
-					GCallback func, gint value,
-					gboolean show_current, gint current_value)
-{
-	GtkWidget *item;
-
-	if (show_current)
-		{
-		item = menu_item_add_radio(menu, parent,
-					   label, (value == current_value),
-					   func, GINT_TO_POINTER((gint)value));
-		}
-	else
-		{
-		item = menu_item_add(menu, label,
-				     func, GINT_TO_POINTER((gint)value));
-		}
-
-	return item;
-}
-
-GtkWidget *bar_pane_histogram_add_channels(GtkWidget *menu, GCallback func, gpointer data,
-			    		   gboolean show_current, gint current_value)
-{
-	GtkWidget *submenu;
-	GtkWidget *parent;
-
-	submenu = gtk_menu_new();
-	g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
-
-	parent = bar_pane_histogram_add_radio(submenu, NULL, _("_Red"), func, HCHAN_R, show_current, current_value);
-	bar_pane_histogram_add_radio(submenu, parent, _("_Green"), func, HCHAN_G, show_current, current_value);
-	bar_pane_histogram_add_radio(submenu, parent, _("_Blue"),func, HCHAN_B, show_current, current_value);
-	bar_pane_histogram_add_radio(submenu, parent, _("_RGB"),func, HCHAN_RGB, show_current, current_value);
-	bar_pane_histogram_add_radio(submenu, parent, _("_Value"),func, HCHAN_MAX, show_current, current_value);
-
-	if (menu)
-		{
-		GtkWidget *item;
-
-		item = menu_item_add(menu, _("Channels"), NULL, NULL);
-		gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
-		return item;
-		}
-
-	return submenu;
-}
-GtkWidget *bar_pane_histogram_add_logmode(GtkWidget *menu, GCallback func, gpointer data,
-			    		   gboolean show_current, gint current_value)
-{
-	GtkWidget *submenu;
-	GtkWidget *parent;
-
-	submenu = gtk_menu_new();
-	g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
-
-	parent = bar_pane_histogram_add_radio(submenu, NULL, _("_Linear"), func, 0, show_current, current_value);
-	bar_pane_histogram_add_radio(submenu, parent, _("Lo_garithmical"), func, 1, show_current, current_value);
-
-	if (menu)
-		{
-		GtkWidget *item;
-
-		item = menu_item_add(menu, _("Mode"), NULL, NULL);
-		gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
-		return item;
-		}
-
-	return submenu;
-}
-
-
 static GtkWidget *bar_pane_histogram_menu(PaneHistogramData *phd)
 {
 	GtkWidget *menu;
-	static gboolean show_current = TRUE;
+	gint channel = histogram_get_channel(phd->histogram);
+	gint mode = histogram_get_mode(phd->histogram);
 
 	menu = popup_menu_short_lived();
-	bar_pane_histogram_add_channels(menu, G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd,
-					show_current, histogram_get_channel(phd->histogram));
-	bar_pane_histogram_add_logmode(menu, G_CALLBACK(bar_pane_histogram_popup_logmode_cb), phd,
-				       show_current, histogram_get_mode(phd->histogram));
+
+	/* use the same strings as in layout_util.c */
+	menu_item_add_radio(menu, _("Histogram on _Red"),   GINT_TO_POINTER(HCHAN_R), (channel == HCHAN_R), G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd);
+	menu_item_add_radio(menu, _("Histogram on _Green"), GINT_TO_POINTER(HCHAN_G), (channel == HCHAN_G), G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd);
+	menu_item_add_radio(menu, _("Histogram on _Blue"),  GINT_TO_POINTER(HCHAN_B), (channel == HCHAN_B), G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd);
+	menu_item_add_radio(menu, _("_Histogram on RGB"),   GINT_TO_POINTER(HCHAN_RGB), (channel == HCHAN_RGB), G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd);
+	menu_item_add_radio(menu, _("Histogram on _Value"), GINT_TO_POINTER(HCHAN_MAX), (channel == HCHAN_MAX), G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd);
+	
+	menu_item_add_divider(menu);
+	
+	menu_item_add_radio(menu, _("Li_near Histogram"), GINT_TO_POINTER(0), (mode == 0), G_CALLBACK(bar_pane_histogram_popup_mode_cb), phd);
+	menu_item_add_radio(menu, _("L_og Histogram"),    GINT_TO_POINTER(1), (mode == 1), G_CALLBACK(bar_pane_histogram_popup_mode_cb), phd);
 
 	return menu;
 }
--- a/src/layout_util.c	Sat Jun 27 17:54:31 2009 +0000
+++ b/src/layout_util.c	Sat Jun 27 20:12:56 2009 +0000
@@ -1384,8 +1384,8 @@
   { "Escape",		GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),		"Escape",		N_("Leave full screen"),		CB(layout_menu_escape_cb) },
   { "EscapeAlt1",	GTK_STOCK_LEAVE_FULLSCREEN,N_("_Leave full screen"),		"Q",			N_("Leave full screen"),		CB(layout_menu_escape_cb) },
   { "ImageOverlayCycle",NULL,			N_("_Cycle through overlay modes"),	"I",			N_("Cycle through Overlay modes"),	CB(layout_menu_overlay_toggle_cb) },
-  { "HistogramChanCycle",NULL,			N_("Cycle through histogram _channels"),"K",			N_("Cycle through histogram channels"),	CB(layout_menu_histogram_toggle_channel_cb) },
-  { "HistogramModeCycle",NULL,			N_("Cycle through histogram _modes"),	"J",			N_("Cycle through histogram modes"),	CB(layout_menu_histogram_toggle_mode_cb) },
+  { "HistogramChanCycle",NULL,			N_("Cycle through histogram ch_annels"),"K",			N_("Cycle through histogram channels"),	CB(layout_menu_histogram_toggle_channel_cb) },
+  { "HistogramModeCycle",NULL,			N_("Cycle through histogram mo_des"),	"J",			N_("Cycle through histogram modes"),	CB(layout_menu_histogram_toggle_mode_cb) },
   { "HideTools",	NULL,			N_("_Hide file list"),			"<control>H",		N_("Hide file list"),			CB(layout_menu_hide_cb) },
   { "SlideShowPause",	GTK_STOCK_MEDIA_PAUSE,	N_("_Pause slideshow"), 		"P",			N_("Pause slideshow"), 			CB(layout_menu_slideshow_pause_cb) },
   { "Refresh",		GTK_STOCK_REFRESH,	N_("_Refresh"),				"R",			N_("Refresh"),				CB(layout_menu_refresh_cb) },
@@ -1444,13 +1444,13 @@
   { "HistogramChanR",	NULL,			N_("Histogram on _Red"),		NULL,			N_("Histogram on Red"),		HCHAN_R },
   { "HistogramChanG",	NULL,			N_("Histogram on _Green"),		NULL,			N_("Histogram on Green"),	HCHAN_G },
   { "HistogramChanB",	NULL,			N_("Histogram on _Blue"),		NULL,			N_("Histogram on Blue"),	HCHAN_B },
-  { "HistogramChanRGB",	NULL,			N_("Histogram on RGB"),			NULL,			N_("Histogram on RGB"),		HCHAN_RGB },
-  { "HistogramChanV",	NULL,			N_("Histogram on Value"),		NULL,			N_("Histogram on Value"),	HCHAN_MAX }
+  { "HistogramChanRGB",	NULL,			N_("_Histogram on RGB"),			NULL,			N_("Histogram on RGB"),		HCHAN_RGB },
+  { "HistogramChanV",	NULL,			N_("Histogram on _Value"),		NULL,			N_("Histogram on Value"),	HCHAN_MAX }
 };
 
 static GtkRadioActionEntry menu_histogram_mode[] = {
   { "HistogramModeLin",	NULL,			N_("Li_near Histogram"),		NULL,			N_("Linear Histogram"),		0 },
-  { "HistogramModeLog",	NULL,			N_("Lo_g Histogram"),			NULL,			N_("Log Histogram"),		1 },
+  { "HistogramModeLog",	NULL,			N_("L_og Histogram"),			NULL,			N_("Log Histogram"),		1 },
 };
 
 
--- a/src/menu.c	Sat Jun 27 17:54:31 2009 +0000
+++ b/src/menu.c	Sat Jun 27 20:12:56 2009 +0000
@@ -153,7 +153,7 @@
 	return "";
 }
 
-static GtkWidget *submenu_add_sort_item(GtkWidget *menu, GtkWidget *parent,
+static GtkWidget *submenu_add_sort_item(GtkWidget *menu,
 					GCallback func, SortType type,
 					gboolean show_current, SortType show_type)
 {
@@ -161,8 +161,8 @@
 
 	if (show_current)
 		{
-		item = menu_item_add_radio(menu, parent,
-					   sort_type_get_text(type), (type == show_type),
+		item = menu_item_add_radio(menu,
+					   sort_type_get_text(type), GINT_TO_POINTER((gint)type), (type == show_type),
 					   func, GINT_TO_POINTER((gint)type));
 		}
 	else
@@ -179,19 +179,18 @@
 			    gboolean show_current, SortType type)
 {
 	GtkWidget *submenu;
-	GtkWidget *parent;
 
 	submenu = gtk_menu_new();
 	g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
 
-	parent = submenu_add_sort_item(submenu, NULL, func, SORT_NAME, show_current, type);
+	submenu_add_sort_item(submenu, func, SORT_NAME, show_current, type);
 #ifdef HAVE_STRVERSCMP
-	submenu_add_sort_item(submenu, parent, func, SORT_NUMBER, show_current, type);
+	submenu_add_sort_item(submenu, func, SORT_NUMBER, show_current, type);
 #endif
-	submenu_add_sort_item(submenu, parent, func, SORT_TIME, show_current, type);
-	submenu_add_sort_item(submenu, parent, func, SORT_SIZE, show_current, type);
-	if (include_path) submenu_add_sort_item(submenu, parent, func, SORT_PATH, show_current, type);
-	if (include_none) submenu_add_sort_item(submenu, parent, func, SORT_NONE, show_current, type);
+	submenu_add_sort_item(submenu, func, SORT_TIME, show_current, type);
+	submenu_add_sort_item(submenu, func, SORT_SIZE, show_current, type);
+	if (include_path) submenu_add_sort_item(submenu, func, SORT_PATH, show_current, type);
+	if (include_none) submenu_add_sort_item(submenu, func, SORT_NONE, show_current, type);
 
 	if (menu)
 		{
--- a/src/ui_menu.c	Sat Jun 27 17:54:31 2009 +0000
+++ b/src/ui_menu.c	Sat Jun 27 20:12:56 2009 +0000
@@ -97,18 +97,12 @@
 	return item;
 }
 
-GtkWidget *menu_item_add_radio(GtkWidget *menu, GtkWidget *parent,
-			       const gchar *label, gboolean active,
+GtkWidget *menu_item_add_radio(GtkWidget *menu, const gchar *label, gpointer item_data, gboolean active,
 			       GCallback func, gpointer data)
 {
-	GtkWidget *item;
-	GSList *group = NULL;
-
-	if (parent) group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(parent));
-
-	item = gtk_radio_menu_item_new_with_mnemonic(group, label);
-	if (active) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), active);
-	menu_item_finish(menu, item, func, data);
+	GtkWidget *item = menu_item_add_check(menu, label, active, func, data);
+	g_object_set_data(G_OBJECT(item), "menu_item_radio_data", item_data);
+	g_object_set(G_OBJECT(item), "draw-as-radio", TRUE, NULL);
 
 	return item;
 }
--- a/src/ui_menu.h	Sat Jun 27 17:54:31 2009 +0000
+++ b/src/ui_menu.h	Sat Jun 27 20:12:56 2009 +0000
@@ -25,8 +25,7 @@
 					 GCallback func, gpointer data);
 GtkWidget *menu_item_add_check(GtkWidget *menu, const gchar *label, gboolean active,
 			       GCallback func, gpointer data);
-GtkWidget *menu_item_add_radio(GtkWidget *menu, GtkWidget *parent,
-			       const gchar *label, gboolean active,
+GtkWidget *menu_item_add_radio(GtkWidget *menu, const gchar *label, gpointer item_data, gboolean active,
 			       GCallback func, gpointer data);
 void menu_item_add_divider(GtkWidget *menu);