Commit e2709b97 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

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.
parent da2115ba
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>
* app/widgets/gimptemplateeditor.c
......
......@@ -45,6 +45,7 @@
#include "widgets/gimpcolorbar.h"
#include "widgets/gimpcursor.h"
#include "widgets/gimpenumcombobox.h"
#include "widgets/gimpenumstore.h"
#include "widgets/gimpenumwidgets.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimphistogramview.h"
......@@ -110,8 +111,9 @@ static void curves_channel_callback (GtkWidget *widget,
static void curves_channel_reset_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static gboolean curves_set_sensitive_callback (GimpHistogramChannel channel,
GimpCurvesTool *tool);
static gboolean curves_menu_visible_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
static void curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool);
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_OPTIONS (tool->tool_info->tool_options));
/* FIXME: regression! */
#if 0
/* 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
gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (c_tool->channel_menu),
curves_menu_visible_func, c_tool);
/* set the current selection */
gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (c_tool->channel_menu),
c_tool->channel);
......@@ -832,9 +828,17 @@ curves_channel_reset_callback (GtkWidget *widget,
}
static gboolean
curves_set_sensitive_callback (GimpHistogramChannel channel,
GimpCurvesTool *tool)
curves_menu_visible_func (GtkTreeModel *model,
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)
{
case GIMP_HISTOGRAM_VALUE:
......@@ -846,7 +850,7 @@ curves_set_sensitive_callback (GimpHistogramChannel channel,
return tool->color;
case GIMP_HISTOGRAM_ALPHA:
return gimp_drawable_has_alpha (GIMP_IMAGE_MAP_TOOL (tool)->drawable);
return tool->alpha;
}
return FALSE;
......
......@@ -45,6 +45,7 @@
#include "widgets/gimpcolorbar.h"
#include "widgets/gimpenumcombobox.h"
#include "widgets/gimpenumstore.h"
#include "widgets/gimpenumwidgets.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimphistogramview.h"
......@@ -108,8 +109,9 @@ static void levels_channel_callback (GtkWidget *widget,
GimpLevelsTool *tool);
static void levels_channel_reset_callback (GtkWidget *widget,
GimpLevelsTool *tool);
static gboolean levels_set_sensitive_callback (GimpHistogramChannel channel,
GimpLevelsTool *tool);
static gboolean levels_menu_visible_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
static void levels_auto_callback (GtkWidget *widget,
GimpLevelsTool *tool);
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);
/* FIXME: regression! */
#if 0
/* 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
gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (l_tool->channel_menu),
levels_menu_visible_func, l_tool);
/* set the current selection */
gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (l_tool->channel_menu),
l_tool->channel);
......@@ -934,9 +930,17 @@ levels_channel_reset_callback (GtkWidget *widget,
}
static gboolean
levels_set_sensitive_callback (GimpHistogramChannel channel,
GimpLevelsTool *tool)
levels_menu_visible_func (GtkTreeModel *model,
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)
{
case GIMP_HISTOGRAM_VALUE:
......@@ -948,7 +952,7 @@ levels_set_sensitive_callback (GimpHistogramChannel channel,
return tool->color;
case GIMP_HISTOGRAM_ALPHA:
return gimp_drawable_has_alpha (GIMP_IMAGE_MAP_TOOL (tool)->drawable);
return tool->alpha;
}
return FALSE;
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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
* 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));
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);
return TRUE;
......@@ -169,3 +169,34 @@ gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
GTK_WIDGET (combo_box),
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);
}
......@@ -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_with_model (GimpEnumStore *enum_store);
gboolean gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box,
gint value);
gboolean gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box,
gint *value);
void gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
const gchar *stock_prefix);
void gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
GtkTreeModelFilterVisibleFunc func,
gpointer data);
#endif /* __GIMP_ENUM_COMBO_BOX_H__ */
......@@ -214,18 +214,15 @@ gimp_enum_store_new_with_values_valist (GType enum_type,
}
gboolean
gimp_enum_store_lookup_by_value (GimpEnumStore *store,
gint value,
GtkTreeIter *iter)
gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value,
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);
model = GTK_TREE_MODEL (store);
for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter))
......
......@@ -71,9 +71,9 @@ GtkListStore * gimp_enum_store_new_with_values_valist (GType enum_type,
gint n_values,
va_list args);
gboolean gimp_enum_store_lookup_by_value (GimpEnumStore *store,
gint value,
GtkTreeIter *iter);
gboolean gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value,
GtkTreeIter *iter);
void gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget,
......
......@@ -34,6 +34,7 @@
#include "core/gimpimage.h"
#include "gimpenumcombobox.h"
#include "gimpenumstore.h"
#include "gimphelp-ids.h"
#include "gimphistogrambox.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 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_info_update (GimpHistogramEditor *editor);
......@@ -154,6 +158,9 @@ gimp_histogram_editor_init (GimpHistogramEditor *editor)
0, 0);
gimp_enum_combo_box_set_stock_prefix (GIMP_ENUM_COMBO_BOX (menu),
"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_widget_show (menu);
......@@ -372,11 +379,16 @@ gimp_histogram_editor_idle_update (GimpHistogramEditor *editor)
}
static gboolean
gimp_histogram_editor_item_sensitive (GimpHistogramChannel channel,
GimpDrawable *drawable)
gimp_histogram_editor_item_visible (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
if (! drawable)
return FALSE;
GimpHistogramEditor *editor = GIMP_HISTOGRAM_EDITOR (data);
GimpHistogramChannel channel;
gtk_tree_model_get (model, iter,
GIMP_ENUM_STORE_VALUE, &channel,
-1);
switch (channel)
{
......@@ -386,32 +398,21 @@ gimp_histogram_editor_item_sensitive (GimpHistogramChannel channel,
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
return gimp_drawable_is_rgb (drawable);
return editor->drawable && gimp_drawable_is_rgb (editor->drawable);
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
gimp_histogram_editor_menu_update (GimpHistogramEditor *editor)
{
GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view;
GimpHistogramChannel channel = gimp_histogram_view_get_channel (view);
if (! gimp_histogram_editor_item_sensitive (channel, editor->drawable))
{
gimp_histogram_view_set_channel (view, GIMP_HISTOGRAM_VALUE);
}
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (editor->menu));
/* FIXME: regression! */
#if 0
gimp_int_option_menu_set_sensitive (GTK_OPTION_MENU (editor->menu),
(GimpIntOptionMenuSensitivityCallback) gimp_histogram_editor_item_sensitive,
editor->drawable);
#endif
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
}
static void
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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
* 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));
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);
return TRUE;
......@@ -169,3 +169,34 @@ gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
GTK_WIDGET (combo_box),
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);
}
......@@ -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_with_model (GimpEnumStore *enum_store);
gboolean gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box,
gint value);
gboolean gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box,
gint *value);
void gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
const gchar *stock_prefix);
void gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
GtkTreeModelFilterVisibleFunc func,
gpointer data);
#endif /* __GIMP_ENUM_COMBO_BOX_H__ */
......@@ -214,18 +214,15 @@ gimp_enum_store_new_with_values_valist (GType enum_type,
}
gboolean
gimp_enum_store_lookup_by_value (GimpEnumStore *store,
gint value,
GtkTreeIter *iter)
gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value,
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);
model = GTK_TREE_MODEL (store);
for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter))
......
......@@ -71,9 +71,9 @@ GtkListStore * gimp_enum_store_new_with_values_valist (GType enum_type,
gint n_values,
va_list args);
gboolean gimp_enum_store_lookup_by_value (GimpEnumStore *store,
gint value,
GtkTreeIter *iter);
gboolean gimp_enum_store_lookup_by_value (GtkTreeModel *model,
gint value,
GtkTreeIter *iter);
void gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment