Skip to content

Commit

Permalink
Fix up bar pane histogram contextual menu: show current state for cha…
Browse files Browse the repository at this point in the history
…nnel and log mode.
  • Loading branch information
Laurent Monin committed Feb 25, 2009
1 parent 4d85c50 commit fddb6eb
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/bar_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,15 @@ static void bar_pane_histogram_popup_channels_cb(GtkWidget *widget, gpointer dat
PaneHistogramData *phd;
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);
if (channel == histogram_get_channel(phd->histogram)) return;

histogram_set_channel(phd->histogram, channel);
bar_pane_histogram_update(phd);
}
Expand All @@ -166,27 +170,31 @@ static void bar_pane_histogram_popup_logmode_cb(GtkWidget *widget, gpointer data
{
PaneHistogramData *phd;
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);
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 show_value)
gboolean show_current, gint current_value)
{
GtkWidget *item;

if (show_current)
{
item = menu_item_add_radio(menu, parent,
label, (value == show_value),
label, (value == current_value),
func, GINT_TO_POINTER((gint)value));
}
else
Expand All @@ -199,19 +207,19 @@ static GtkWidget *bar_pane_histogram_add_radio(GtkWidget *menu, GtkWidget *paren
}

GtkWidget *bar_pane_histogram_add_channels(GtkWidget *menu, GCallback func, gpointer data,
gboolean show_current, gint value)
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, value);
bar_pane_histogram_add_radio(submenu, parent, _("_Green"), func, HCHAN_G, show_current, value);
bar_pane_histogram_add_radio(submenu, parent, _("_Blue"),func, HCHAN_B, show_current, value);
bar_pane_histogram_add_radio(submenu, parent, _("_RGB"),func, HCHAN_RGB, show_current, value);
bar_pane_histogram_add_radio(submenu, parent, _("_Value"),func, HCHAN_MAX, show_current, value);
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)
{
Expand All @@ -225,16 +233,16 @@ GtkWidget *bar_pane_histogram_add_channels(GtkWidget *menu, GCallback func, gpoi
return submenu;
}
GtkWidget *bar_pane_histogram_add_logmode(GtkWidget *menu, GCallback func, gpointer data,
gboolean show_current, gint value)
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, value);
bar_pane_histogram_add_radio(submenu, parent, _("Lo_garithmical"), func, 1, show_current, value);
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)
{
Expand All @@ -252,7 +260,7 @@ GtkWidget *bar_pane_histogram_add_logmode(GtkWidget *menu, GCallback func, gpoin
static GtkWidget *bar_pane_histogram_menu(PaneHistogramData *phd)
{
GtkWidget *menu;
static gboolean show_current = FALSE; /* FIXME: TRUE -> buggy behavior */
static gboolean show_current = TRUE;

menu = popup_menu_short_lived();
bar_pane_histogram_add_channels(menu, G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd,
Expand Down

0 comments on commit fddb6eb

Please sign in to comment.