comparison src/bar_histogram.c @ 1323:50ab4016ae0b

Fix up bar pane histogram contextual menu: show current state for channel and log mode.
author zas_
date Wed, 25 Feb 2009 20:42:35 +0000
parents 358685fb9dc9
children e4f9e3567f0a
comparison
equal deleted inserted replaced
1322:4370b90fa774 1323:50ab4016ae0b
151 static void bar_pane_histogram_popup_channels_cb(GtkWidget *widget, gpointer data) 151 static void bar_pane_histogram_popup_channels_cb(GtkWidget *widget, gpointer data)
152 { 152 {
153 PaneHistogramData *phd; 153 PaneHistogramData *phd;
154 gint channel; 154 gint channel;
155 155
156 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
157
156 phd = submenu_item_get_data(widget); 158 phd = submenu_item_get_data(widget);
157 159
158 if (!phd) return; 160 if (!phd) return;
159 161
160 channel = GPOINTER_TO_INT(data); 162 channel = GPOINTER_TO_INT(data);
163 if (channel == histogram_get_channel(phd->histogram)) return;
164
161 histogram_set_channel(phd->histogram, channel); 165 histogram_set_channel(phd->histogram, channel);
162 bar_pane_histogram_update(phd); 166 bar_pane_histogram_update(phd);
163 } 167 }
164 168
165 static void bar_pane_histogram_popup_logmode_cb(GtkWidget *widget, gpointer data) 169 static void bar_pane_histogram_popup_logmode_cb(GtkWidget *widget, gpointer data)
166 { 170 {
167 PaneHistogramData *phd; 171 PaneHistogramData *phd;
168 gint logmode; 172 gint logmode;
173
174 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return;
169 175
170 phd = submenu_item_get_data(widget); 176 phd = submenu_item_get_data(widget);
171 177
172 if (!phd) return; 178 if (!phd) return;
173 179
174 logmode = GPOINTER_TO_INT(data); 180 logmode = GPOINTER_TO_INT(data);
181 if (logmode == histogram_get_mode(phd->histogram)) return;
182
175 histogram_set_mode(phd->histogram, logmode); 183 histogram_set_mode(phd->histogram, logmode);
176 bar_pane_histogram_update(phd); 184 bar_pane_histogram_update(phd);
177 } 185 }
178 186
179 static GtkWidget *bar_pane_histogram_add_radio(GtkWidget *menu, GtkWidget *parent, 187 static GtkWidget *bar_pane_histogram_add_radio(GtkWidget *menu, GtkWidget *parent,
180 const gchar *label, 188 const gchar *label,
181 GCallback func, gint value, 189 GCallback func, gint value,
182 gboolean show_current, gint show_value) 190 gboolean show_current, gint current_value)
183 { 191 {
184 GtkWidget *item; 192 GtkWidget *item;
185 193
186 if (show_current) 194 if (show_current)
187 { 195 {
188 item = menu_item_add_radio(menu, parent, 196 item = menu_item_add_radio(menu, parent,
189 label, (value == show_value), 197 label, (value == current_value),
190 func, GINT_TO_POINTER((gint)value)); 198 func, GINT_TO_POINTER((gint)value));
191 } 199 }
192 else 200 else
193 { 201 {
194 item = menu_item_add(menu, label, 202 item = menu_item_add(menu, label,
197 205
198 return item; 206 return item;
199 } 207 }
200 208
201 GtkWidget *bar_pane_histogram_add_channels(GtkWidget *menu, GCallback func, gpointer data, 209 GtkWidget *bar_pane_histogram_add_channels(GtkWidget *menu, GCallback func, gpointer data,
202 gboolean show_current, gint value) 210 gboolean show_current, gint current_value)
203 { 211 {
204 GtkWidget *submenu; 212 GtkWidget *submenu;
205 GtkWidget *parent; 213 GtkWidget *parent;
206 214
207 submenu = gtk_menu_new(); 215 submenu = gtk_menu_new();
208 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); 216 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
209 217
210 parent = bar_pane_histogram_add_radio(submenu, NULL, _("_Red"), func, HCHAN_R, show_current, value); 218 parent = bar_pane_histogram_add_radio(submenu, NULL, _("_Red"), func, HCHAN_R, show_current, current_value);
211 bar_pane_histogram_add_radio(submenu, parent, _("_Green"), func, HCHAN_G, show_current, value); 219 bar_pane_histogram_add_radio(submenu, parent, _("_Green"), func, HCHAN_G, show_current, current_value);
212 bar_pane_histogram_add_radio(submenu, parent, _("_Blue"),func, HCHAN_B, show_current, value); 220 bar_pane_histogram_add_radio(submenu, parent, _("_Blue"),func, HCHAN_B, show_current, current_value);
213 bar_pane_histogram_add_radio(submenu, parent, _("_RGB"),func, HCHAN_RGB, show_current, value); 221 bar_pane_histogram_add_radio(submenu, parent, _("_RGB"),func, HCHAN_RGB, show_current, current_value);
214 bar_pane_histogram_add_radio(submenu, parent, _("_Value"),func, HCHAN_MAX, show_current, value); 222 bar_pane_histogram_add_radio(submenu, parent, _("_Value"),func, HCHAN_MAX, show_current, current_value);
215 223
216 if (menu) 224 if (menu)
217 { 225 {
218 GtkWidget *item; 226 GtkWidget *item;
219 227
223 } 231 }
224 232
225 return submenu; 233 return submenu;
226 } 234 }
227 GtkWidget *bar_pane_histogram_add_logmode(GtkWidget *menu, GCallback func, gpointer data, 235 GtkWidget *bar_pane_histogram_add_logmode(GtkWidget *menu, GCallback func, gpointer data,
228 gboolean show_current, gint value) 236 gboolean show_current, gint current_value)
229 { 237 {
230 GtkWidget *submenu; 238 GtkWidget *submenu;
231 GtkWidget *parent; 239 GtkWidget *parent;
232 240
233 submenu = gtk_menu_new(); 241 submenu = gtk_menu_new();
234 g_object_set_data(G_OBJECT(submenu), "submenu_data", data); 242 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
235 243
236 parent = bar_pane_histogram_add_radio(submenu, NULL, _("_Linear"), func, 0, show_current, value); 244 parent = bar_pane_histogram_add_radio(submenu, NULL, _("_Linear"), func, 0, show_current, current_value);
237 bar_pane_histogram_add_radio(submenu, parent, _("Lo_garithmical"), func, 1, show_current, value); 245 bar_pane_histogram_add_radio(submenu, parent, _("Lo_garithmical"), func, 1, show_current, current_value);
238 246
239 if (menu) 247 if (menu)
240 { 248 {
241 GtkWidget *item; 249 GtkWidget *item;
242 250
250 258
251 259
252 static GtkWidget *bar_pane_histogram_menu(PaneHistogramData *phd) 260 static GtkWidget *bar_pane_histogram_menu(PaneHistogramData *phd)
253 { 261 {
254 GtkWidget *menu; 262 GtkWidget *menu;
255 static gboolean show_current = FALSE; /* FIXME: TRUE -> buggy behavior */ 263 static gboolean show_current = TRUE;
256 264
257 menu = popup_menu_short_lived(); 265 menu = popup_menu_short_lived();
258 bar_pane_histogram_add_channels(menu, G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd, 266 bar_pane_histogram_add_channels(menu, G_CALLBACK(bar_pane_histogram_popup_channels_cb), phd,
259 show_current, histogram_get_channel(phd->histogram)); 267 show_current, histogram_get_channel(phd->histogram));
260 bar_pane_histogram_add_logmode(menu, G_CALLBACK(bar_pane_histogram_popup_logmode_cb), phd, 268 bar_pane_histogram_add_logmode(menu, G_CALLBACK(bar_pane_histogram_popup_logmode_cb), phd,