avoid unnecessary casts.

2004-04-19  Sven Neumann  <sven@gimp.org>

	* app/widgets/gimpenumstore.[ch]: avoid unnecessary casts.

	* app/widgets/gimpenumcombobox.[ch]: added an API that inserts a
	GtkTreeModelFilter to make items invisible. This is a kludge to
	workaround bug #135875.

	* app/tools/gimpcurvestool.c
	* app/tools/gimplevelstool.c
	* app/widgets/gimphistogrameditor.c: use the new function to hide
	histogram channels that are not available with the current
	drawable.
This commit is contained in:
Sven Neumann 2004-04-18 22:38:45 +00:00 committed by Sven Neumann
parent da2115bad5
commit e2709b97ba
12 changed files with 157 additions and 74 deletions

View File

@ -1,3 +1,15 @@
2004-04-19 Sven Neumann <sven@gimp.org>
* app/widgets/gimpenumstore.[ch]: avoid unnecessary casts.
* app/widgets/gimpenumcombobox.[ch]: added an API that inserts a
GtkTreeModelFilter to make items invisible. This is a kludge to
workaround bug #.
* app/tools/gimpcurvestool.c
* app/tools/gimplevelstool.c
* app/widgets/gimphistogrameditor.c
2004-04-18 Henrik Brix Andersen <brix@gimp.org> 2004-04-18 Henrik Brix Andersen <brix@gimp.org>
* app/widgets/gimptemplateeditor.c * app/widgets/gimptemplateeditor.c

View File

@ -45,6 +45,7 @@
#include "widgets/gimpcolorbar.h" #include "widgets/gimpcolorbar.h"
#include "widgets/gimpcursor.h" #include "widgets/gimpcursor.h"
#include "widgets/gimpenumcombobox.h" #include "widgets/gimpenumcombobox.h"
#include "widgets/gimpenumstore.h"
#include "widgets/gimpenumwidgets.h" #include "widgets/gimpenumwidgets.h"
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "widgets/gimphistogramview.h" #include "widgets/gimphistogramview.h"
@ -110,8 +111,9 @@ static void curves_channel_callback (GtkWidget *widget,
static void curves_channel_reset_callback (GtkWidget *widget, static void curves_channel_reset_callback (GtkWidget *widget,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static gboolean curves_set_sensitive_callback (GimpHistogramChannel channel, static gboolean curves_menu_visible_func (GtkTreeModel *model,
GimpCurvesTool *tool); GtkTreeIter *iter,
gpointer data);
static void curves_curve_type_callback (GtkWidget *widget, static void curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool); GimpCurvesTool *tool);
static gboolean curves_graph_events (GtkWidget *widget, static gboolean curves_graph_events (GtkWidget *widget,
@ -302,15 +304,9 @@ gimp_curves_tool_initialize (GimpTool *tool,
gimp_color_tool_enable (GIMP_COLOR_TOOL (tool), gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
GIMP_COLOR_OPTIONS (tool->tool_info->tool_options)); GIMP_COLOR_OPTIONS (tool->tool_info->tool_options));
/* FIXME: regression! */ gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (c_tool->channel_menu),
#if 0 curves_menu_visible_func, c_tool);
/* set the sensitivity of the channel menu based on the drawable type */
gimp_int_option_menu_set_sensitive (GTK_OPTION_MENU (c_tool->channel_menu),
(GimpIntOptionMenuSensitivityCallback) curves_set_sensitive_callback,
c_tool);
#endif
/* set the current selection */
gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (c_tool->channel_menu), gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (c_tool->channel_menu),
c_tool->channel); c_tool->channel);
@ -832,9 +828,17 @@ curves_channel_reset_callback (GtkWidget *widget,
} }
static gboolean static gboolean
curves_set_sensitive_callback (GimpHistogramChannel channel, curves_menu_visible_func (GtkTreeModel *model,
GimpCurvesTool *tool) GtkTreeIter *iter,
gpointer data)
{ {
GimpCurvesTool *tool = GIMP_CURVES_TOOL (data);
GimpHistogramChannel channel;
gtk_tree_model_get (model, iter,
GIMP_ENUM_STORE_VALUE, &channel,
-1);
switch (channel) switch (channel)
{ {
case GIMP_HISTOGRAM_VALUE: case GIMP_HISTOGRAM_VALUE:
@ -846,7 +850,7 @@ curves_set_sensitive_callback (GimpHistogramChannel channel,
return tool->color; return tool->color;
case GIMP_HISTOGRAM_ALPHA: case GIMP_HISTOGRAM_ALPHA:
return gimp_drawable_has_alpha (GIMP_IMAGE_MAP_TOOL (tool)->drawable); return tool->alpha;
} }
return FALSE; return FALSE;

View File

@ -45,6 +45,7 @@
#include "widgets/gimpcolorbar.h" #include "widgets/gimpcolorbar.h"
#include "widgets/gimpenumcombobox.h" #include "widgets/gimpenumcombobox.h"
#include "widgets/gimpenumstore.h"
#include "widgets/gimpenumwidgets.h" #include "widgets/gimpenumwidgets.h"
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "widgets/gimphistogramview.h" #include "widgets/gimphistogramview.h"
@ -108,8 +109,9 @@ static void levels_channel_callback (GtkWidget *widget,
GimpLevelsTool *tool); GimpLevelsTool *tool);
static void levels_channel_reset_callback (GtkWidget *widget, static void levels_channel_reset_callback (GtkWidget *widget,
GimpLevelsTool *tool); GimpLevelsTool *tool);
static gboolean levels_set_sensitive_callback (GimpHistogramChannel channel, static gboolean levels_menu_visible_func (GtkTreeModel *model,
GimpLevelsTool *tool); GtkTreeIter *iter,
gpointer data);
static void levels_auto_callback (GtkWidget *widget, static void levels_auto_callback (GtkWidget *widget,
GimpLevelsTool *tool); GimpLevelsTool *tool);
static void levels_low_input_adjustment_update (GtkAdjustment *adjustment, static void levels_low_input_adjustment_update (GtkAdjustment *adjustment,
@ -300,15 +302,9 @@ gimp_levels_tool_initialize (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp); GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
/* FIXME: regression! */ gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (l_tool->channel_menu),
#if 0 levels_menu_visible_func, l_tool);
/* set the sensitivity of the channel menu based on the drawable type */
gimp_int_option_menu_set_sensitive (GTK_OPTION_MENU (l_tool->channel_menu),
(GimpIntOptionMenuSensitivityCallback) levels_set_sensitive_callback,
l_tool);
#endif
/* set the current selection */
gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (l_tool->channel_menu), gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (l_tool->channel_menu),
l_tool->channel); l_tool->channel);
@ -934,9 +930,17 @@ levels_channel_reset_callback (GtkWidget *widget,
} }
static gboolean static gboolean
levels_set_sensitive_callback (GimpHistogramChannel channel, levels_menu_visible_func (GtkTreeModel *model,
GimpLevelsTool *tool) GtkTreeIter *iter,
gpointer data)
{ {
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (data);
GimpHistogramChannel channel;
gtk_tree_model_get (model, iter,
GIMP_ENUM_STORE_VALUE, &channel,
-1);
switch (channel) switch (channel)
{ {
case GIMP_HISTOGRAM_VALUE: case GIMP_HISTOGRAM_VALUE:
@ -948,7 +952,7 @@ levels_set_sensitive_callback (GimpHistogramChannel channel,
return tool->color; return tool->color;
case GIMP_HISTOGRAM_ALPHA: case GIMP_HISTOGRAM_ALPHA:
return gimp_drawable_has_alpha (GIMP_IMAGE_MAP_TOOL (tool)->drawable); return tool->alpha;
} }
return FALSE; return FALSE;

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis * Copyright (C) 1995 Spencer Kimball and Peter Mattis
* *
* gimpenumcombobox.c * gimpenumcombobox.c
* Copyright (C) 2002 Sven Neumann <sven@gimp.org> * Copyright (C) 2004 Sven Neumann <sven@gimp.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -126,7 +126,7 @@ gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box,
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)); model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
if (gimp_enum_store_lookup_by_value (GIMP_ENUM_STORE (model), value, &iter)) if (gimp_enum_store_lookup_by_value (model, value, &iter))
{ {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return TRUE; return TRUE;
@ -169,3 +169,34 @@ gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
GTK_WIDGET (combo_box), GTK_WIDGET (combo_box),
stock_prefix, GTK_ICON_SIZE_MENU); stock_prefix, GTK_ICON_SIZE_MENU);
} }
/* This is a kludge to allow to work around bug #135875 */
void
gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
GtkTreeModelFilterVisibleFunc func,
gpointer data)
{
GtkTreeModel *model;
GtkTreeModelFilter *filter;
g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
if (GTK_IS_TREE_MODEL_FILTER (model))
{
filter = GTK_TREE_MODEL_FILTER (model);
}
else
{
filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
GTK_TREE_MODEL (filter));
g_object_unref (filter);
}
gtk_tree_model_filter_set_visible_func (filter, func, data, NULL);
gtk_tree_model_filter_refilter (filter);
}

View File

@ -50,13 +50,16 @@ GType gimp_enum_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_enum_combo_box_new (GType enum_type); GtkWidget * gimp_enum_combo_box_new (GType enum_type);
GtkWidget * gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store); GtkWidget * gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store);
gboolean gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box, gboolean gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box,
gint value); gint value);
gboolean gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box, gboolean gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box,
gint *value); gint *value);
void gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box, void gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
const gchar *stock_prefix); const gchar *stock_prefix);
void gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
GtkTreeModelFilterVisibleFunc func,
gpointer data);
#endif /* __GIMP_ENUM_COMBO_BOX_H__ */ #endif /* __GIMP_ENUM_COMBO_BOX_H__ */

View File

@ -214,18 +214,15 @@ gimp_enum_store_new_with_values_valist (GType enum_type,
} }
gboolean gboolean
gimp_enum_store_lookup_by_value (GimpEnumStore *store, gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value, gint value,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
GtkTreeModel *model; gboolean iter_valid;
gboolean iter_valid;
g_return_val_if_fail (GIMP_IS_ENUM_STORE (store), FALSE); g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (iter != NULL, FALSE);
model = GTK_TREE_MODEL (store);
for (iter_valid = gtk_tree_model_get_iter_first (model, iter); for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid; iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter)) iter_valid = gtk_tree_model_iter_next (model, iter))

View File

@ -71,9 +71,9 @@ GtkListStore * gimp_enum_store_new_with_values_valist (GType enum_type,
gint n_values, gint n_values,
va_list args); va_list args);
gboolean gimp_enum_store_lookup_by_value (GimpEnumStore *store, gboolean gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value, gint value,
GtkTreeIter *iter); GtkTreeIter *iter);
void gimp_enum_store_set_icons (GimpEnumStore *store, void gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget, GtkWidget *widget,

View File

@ -34,6 +34,7 @@
#include "core/gimpimage.h" #include "core/gimpimage.h"
#include "gimpenumcombobox.h" #include "gimpenumcombobox.h"
#include "gimpenumstore.h"
#include "gimphelp-ids.h" #include "gimphelp-ids.h"
#include "gimphistogrambox.h" #include "gimphistogrambox.h"
#include "gimphistogrameditor.h" #include "gimphistogrameditor.h"
@ -62,6 +63,9 @@ static void gimp_histogram_editor_layer_changed (GimpImage *gimage,
static void gimp_histogram_editor_update (GimpHistogramEditor *editor); static void gimp_histogram_editor_update (GimpHistogramEditor *editor);
static gboolean gimp_histogram_editor_idle_update (GimpHistogramEditor *editor); static gboolean gimp_histogram_editor_idle_update (GimpHistogramEditor *editor);
static gboolean gimp_histogram_editor_item_visible (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
static void gimp_histogram_editor_menu_update (GimpHistogramEditor *editor); static void gimp_histogram_editor_menu_update (GimpHistogramEditor *editor);
static void gimp_histogram_editor_info_update (GimpHistogramEditor *editor); static void gimp_histogram_editor_info_update (GimpHistogramEditor *editor);
@ -154,6 +158,9 @@ gimp_histogram_editor_init (GimpHistogramEditor *editor)
0, 0); 0, 0);
gimp_enum_combo_box_set_stock_prefix (GIMP_ENUM_COMBO_BOX (menu), gimp_enum_combo_box_set_stock_prefix (GIMP_ENUM_COMBO_BOX (menu),
"gimp-channel"); "gimp-channel");
gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (editor->menu),
gimp_histogram_editor_item_visible,
editor);
gtk_box_pack_start (GTK_BOX (hbox), menu, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), menu, FALSE, FALSE, 0);
gtk_widget_show (menu); gtk_widget_show (menu);
@ -372,11 +379,16 @@ gimp_histogram_editor_idle_update (GimpHistogramEditor *editor)
} }
static gboolean static gboolean
gimp_histogram_editor_item_sensitive (GimpHistogramChannel channel, gimp_histogram_editor_item_visible (GtkTreeModel *model,
GimpDrawable *drawable) GtkTreeIter *iter,
gpointer data)
{ {
if (! drawable) GimpHistogramEditor *editor = GIMP_HISTOGRAM_EDITOR (data);
return FALSE; GimpHistogramChannel channel;
gtk_tree_model_get (model, iter,
GIMP_ENUM_STORE_VALUE, &channel,
-1);
switch (channel) switch (channel)
{ {
@ -386,32 +398,21 @@ gimp_histogram_editor_item_sensitive (GimpHistogramChannel channel,
case GIMP_HISTOGRAM_RED: case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN: case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE: case GIMP_HISTOGRAM_BLUE:
return gimp_drawable_is_rgb (drawable); return editor->drawable && gimp_drawable_is_rgb (editor->drawable);
case GIMP_HISTOGRAM_ALPHA: case GIMP_HISTOGRAM_ALPHA:
return gimp_drawable_has_alpha (drawable); return editor->drawable && gimp_drawable_has_alpha (editor->drawable);
} }
return FALSE; return FALSE;
} }
static void static void
gimp_histogram_editor_menu_update (GimpHistogramEditor *editor) gimp_histogram_editor_menu_update (GimpHistogramEditor *editor)
{ {
GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view; GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (editor->menu));
GimpHistogramChannel channel = gimp_histogram_view_get_channel (view);
if (! gimp_histogram_editor_item_sensitive (channel, editor->drawable)) gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
{
gimp_histogram_view_set_channel (view, GIMP_HISTOGRAM_VALUE);
}
/* FIXME: regression! */
#if 0
gimp_int_option_menu_set_sensitive (GTK_OPTION_MENU (editor->menu),
(GimpIntOptionMenuSensitivityCallback) gimp_histogram_editor_item_sensitive,
editor->drawable);
#endif
} }
static void static void

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis * Copyright (C) 1995 Spencer Kimball and Peter Mattis
* *
* gimpenumcombobox.c * gimpenumcombobox.c
* Copyright (C) 2002 Sven Neumann <sven@gimp.org> * Copyright (C) 2004 Sven Neumann <sven@gimp.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -126,7 +126,7 @@ gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box,
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)); model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
if (gimp_enum_store_lookup_by_value (GIMP_ENUM_STORE (model), value, &iter)) if (gimp_enum_store_lookup_by_value (model, value, &iter))
{ {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return TRUE; return TRUE;
@ -169,3 +169,34 @@ gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
GTK_WIDGET (combo_box), GTK_WIDGET (combo_box),
stock_prefix, GTK_ICON_SIZE_MENU); stock_prefix, GTK_ICON_SIZE_MENU);
} }
/* This is a kludge to allow to work around bug #135875 */
void
gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
GtkTreeModelFilterVisibleFunc func,
gpointer data)
{
GtkTreeModel *model;
GtkTreeModelFilter *filter;
g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
if (GTK_IS_TREE_MODEL_FILTER (model))
{
filter = GTK_TREE_MODEL_FILTER (model);
}
else
{
filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box),
GTK_TREE_MODEL (filter));
g_object_unref (filter);
}
gtk_tree_model_filter_set_visible_func (filter, func, data, NULL);
gtk_tree_model_filter_refilter (filter);
}

View File

@ -50,13 +50,16 @@ GType gimp_enum_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_enum_combo_box_new (GType enum_type); GtkWidget * gimp_enum_combo_box_new (GType enum_type);
GtkWidget * gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store); GtkWidget * gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store);
gboolean gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box, gboolean gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box,
gint value); gint value);
gboolean gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box, gboolean gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box,
gint *value); gint *value);
void gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box, void gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
const gchar *stock_prefix); const gchar *stock_prefix);
void gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
GtkTreeModelFilterVisibleFunc func,
gpointer data);
#endif /* __GIMP_ENUM_COMBO_BOX_H__ */ #endif /* __GIMP_ENUM_COMBO_BOX_H__ */

View File

@ -214,18 +214,15 @@ gimp_enum_store_new_with_values_valist (GType enum_type,
} }
gboolean gboolean
gimp_enum_store_lookup_by_value (GimpEnumStore *store, gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value, gint value,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
GtkTreeModel *model; gboolean iter_valid;
gboolean iter_valid;
g_return_val_if_fail (GIMP_IS_ENUM_STORE (store), FALSE); g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (iter != NULL, FALSE);
model = GTK_TREE_MODEL (store);
for (iter_valid = gtk_tree_model_get_iter_first (model, iter); for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid; iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter)) iter_valid = gtk_tree_model_iter_next (model, iter))

View File

@ -71,9 +71,9 @@ GtkListStore * gimp_enum_store_new_with_values_valist (GType enum_type,
gint n_values, gint n_values,
va_list args); va_list args);
gboolean gimp_enum_store_lookup_by_value (GimpEnumStore *store, gboolean gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value, gint value,
GtkTreeIter *iter); GtkTreeIter *iter);
void gimp_enum_store_set_icons (GimpEnumStore *store, void gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget, GtkWidget *widget,