app/widgets/Makefile.am app/widgets/widgets-types.h removed GimpEnumMenu.

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

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpenummenu.[ch]: removed GimpEnumMenu.

	* app/widgets/gimpenumwidgets.[ch]: moved widget constructors that
	don't use GimpEnumMenu from gimpenummenu.[ch] to these new files.

	* app/widgets/gimpenumcombobox.[ch]: added a GtkComboBox widget
	using GimpEnumStore; replaces GimpEnumMenu.

	* app/widgets/gimpenumstore.[ch]: added new function
	gimp_enum_store_lookup_by_value().

	* app/widgets/gimppropwidgets.[ch]: replaced
	gimp_prop_enum_option_menu_new() with gimp_prop_enum_combo_box_new().

	* app/gui/brush-select.[ch]
	* app/gui/convert-dialog.c
	* app/gui/layers-commands.c
	* app/gui/preferences-dialog.c
	* app/gui/resize-dialog.c
	* app/tools/gimpblendoptions.c
	* app/tools/gimpcolorbalancetool.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpcurvestool.c
	* app/tools/gimplevelstool.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimppaintoptions-gui.c
	* app/tools/gimpselectionoptions.c
	* app/tools/gimptransformoptions.c
	* app/widgets/gimpcolorframe.c
	* app/widgets/gimpeditor.c
	* app/widgets/gimpgrideditor.c
	* app/widgets/gimphistogrameditor.c
	* app/widgets/gimpstrokeeditor.c
	* app/widgets/gimptemplateeditor.c
	* app/widgets/gimptexteditor.c: ported to GimpEnumComboBox.
This commit is contained in:
Sven Neumann
2004-04-18 15:12:42 +00:00
committed by Sven Neumann
parent f9135400ce
commit 89cf45541a
46 changed files with 1606 additions and 916 deletions

View File

@ -0,0 +1,171 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpenumcombobox.c
* Copyright (C) 2002 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "gimpenumcombobox.h"
#include "gimpenumstore.h"
#include "gimp-intl.h"
GType
gimp_enum_combo_box_get_type (void)
{
static GType enum_combo_box_type = 0;
if (!enum_combo_box_type)
{
static const GTypeInfo enum_combo_box_info =
{
sizeof (GimpEnumComboBoxClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpEnumComboBox),
0, /* n_preallocs */
NULL /* instance_init */
};
enum_combo_box_type = g_type_register_static (GTK_TYPE_COMBO_BOX,
"GimpEnumComboBox",
&enum_combo_box_info, 0);
}
return enum_combo_box_type;
}
/**
* gimp_enum_combo_box_new:
* @enum_type: the #GType of an enum.
*
* Creates a new #GtkComboBox using the #GimpEnumStore. The enum needs
* to be registered to the type system and should have translatable
* value names.
*
* Return value: a new #GimpEnumComboBox.
**/
GtkWidget *
gimp_enum_combo_box_new (GType enum_type)
{
GtkListStore *store;
GtkWidget *combo_box;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
store = gimp_enum_store_new (enum_type);
combo_box = gimp_enum_combo_box_new_with_model (GIMP_ENUM_STORE (store));
g_object_unref (store);
return combo_box;
}
GtkWidget *
gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store)
{
GtkWidget *combo_box;
GtkCellRenderer *cell;
g_return_val_if_fail (GIMP_IS_ENUM_STORE (enum_store), NULL);
combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
"model", enum_store,
NULL);
cell = gtk_cell_renderer_pixbuf_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
"pixbuf", GIMP_ENUM_STORE_ICON,
NULL);
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
"text", GIMP_ENUM_STORE_LABEL,
NULL);
return combo_box;
}
gboolean
gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box,
gint value)
{
GtkTreeModel *model;
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box), FALSE);
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
if (gimp_enum_store_lookup_by_value (GIMP_ENUM_STORE (model), value, &iter))
{
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
return TRUE;
}
return FALSE;
}
gboolean
gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box,
gint *value)
{
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box), FALSE);
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
{
gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)),
&iter,
GIMP_ENUM_STORE_VALUE, value,
-1);
return TRUE;
}
return FALSE;
}
void
gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
const gchar *stock_prefix)
{
GtkTreeModel *model;
g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
gimp_enum_store_set_icons (GIMP_ENUM_STORE (model),
GTK_WIDGET (combo_box),
stock_prefix, GTK_ICON_SIZE_MENU);
}

View File

@ -0,0 +1,62 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpenumcombobox.h
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_ENUM_COMBO_BOX_H__
#define __GIMP_ENUM_COMBO_BOX_H__
#include <gtk/gtkcombobox.h>
#define GIMP_TYPE_ENUM_COMBO_BOX (gimp_enum_combo_box_get_type ())
#define GIMP_ENUM_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ENUM_COMBO_BOX, GimpEnumComboBox))
#define GIMP_ENUM_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ENUM_COMBO_BOX, GimpEnumComboBoxClass))
#define GIMP_IS_ENUM_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ENUM_COMBO_BOX))
#define GIMP_IS_ENUM_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_ENUM_COMBO_BOX))
#define GIMP_ENUM_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ENUM_COMBO_BOX, GimpEnumComboBoxClass))
typedef struct _GimpEnumComboBoxClass GimpEnumComboBoxClass;
struct _GimpEnumComboBoxClass
{
GtkComboBoxClass parent_instance;
};
struct _GimpEnumComboBox
{
GtkComboBox parent_instance;
};
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);
#endif /* __GIMP_ENUM_COMBO_BOX_H__ */

View File

@ -213,6 +213,35 @@ gimp_enum_store_new_with_values_valist (GType enum_type,
return store;
}
gboolean
gimp_enum_store_lookup_by_value (GimpEnumStore *store,
gint value,
GtkTreeIter *iter)
{
GtkTreeModel *model;
gboolean iter_valid;
g_return_val_if_fail (GIMP_IS_ENUM_STORE (store), 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))
{
gint this;
gtk_tree_model_get (model, iter,
GIMP_ENUM_STORE_VALUE, &this,
-1);
if (this == value)
break;
}
return iter_valid;
}
void
gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget,
@ -259,6 +288,9 @@ gimp_enum_store_set_icons (GimpEnumStore *store,
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
GIMP_ENUM_STORE_ICON, pixbuf,
-1);
if (pixbuf)
g_object_unref (pixbuf);
}
}

View File

@ -58,7 +58,7 @@ struct _GimpEnumStore
};
GType gimp_enum_store_get_type (void) G_GNUC_CONST;
GType gimp_enum_store_get_type (void) G_GNUC_CONST;
GtkListStore * gimp_enum_store_new (GType enum_type);;
GtkListStore * gimp_enum_store_new_with_range (GType enum_type,
@ -71,9 +71,14 @@ 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);
void gimp_enum_store_set_icons (GimpEnumStore *store,
GtkWidget *widget,
const gchar *stock_prefix,
GtkIconSize size);
#endif /* __GIMP_ENUM_STORE_H__ */

View File

@ -0,0 +1,349 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpenumwidgets.c
* Copyright (C) 2002-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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "gimpenumwidgets.h"
#include "gimp-intl.h"
/**
* gimp_enum_radio_box_new:
* @enum_type: the #GType of an enum.
* @callback: a callback to connect to the "toggled" signal of each
* #GtkRadioButton that is created.
* @callback_data: data to pass to the @callback.
* @first_button: returns the first button in the created group.
*
* Creates a new group of #GtkRadioButtons representing the enum values.
* This is very similar to gimp_enum_menu_new().
*
* Return value: a new #GtkVBox holding a group of #GtkRadioButtons.
**/
GtkWidget *
gimp_enum_radio_box_new (GType enum_type,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button)
{
GEnumClass *enum_class;
GtkWidget *vbox;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
enum_class = g_type_class_ref (enum_type);
vbox = gimp_enum_radio_box_new_with_range (enum_type,
enum_class->minimum,
enum_class->maximum,
callback, callback_data,
first_button);
g_type_class_unref (enum_class);
return vbox;
}
GtkWidget *
gimp_enum_radio_box_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button)
{
GtkWidget *vbox;
GtkWidget *button;
GEnumClass *enum_class;
GEnumValue *value;
GSList *group = NULL;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
enum_class = g_type_class_ref (enum_type);
vbox = gtk_vbox_new (FALSE, 1);
g_object_weak_ref (G_OBJECT (vbox),
(GWeakNotify) g_type_class_unref, enum_class);
if (first_button)
*first_button = NULL;
for (value = enum_class->values; value->value_name; value++)
{
if (value->value < minimum || value->value > maximum)
continue;
button = gtk_radio_button_new_with_mnemonic (group,
gettext (value->value_name));
if (first_button && *first_button == NULL)
*first_button = button;
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
g_object_set_data (G_OBJECT (button), "gimp-item-data",
GINT_TO_POINTER (value->value));
if (callback)
g_signal_connect (button, "toggled",
callback,
callback_data);
}
return vbox;
}
/**
* gimp_enum_radio_frame_new:
* @enum_type: the #GType of an enum.
* @label_widget: a widget to put into the frame that will hold the radio box.
* @border_width: the border_width of the vbox inside the frame.
* @callback: a callback to connect to the "toggled" signal of each
* #GtkRadioButton that is created.
* @callback_data: data to pass to the @callback.
* @first_button: returns the first button in the created group.
*
* Calls gimp_enum_radio_box_new() and puts the resulting vbox into a
* #GtkFrame.
*
* Return value: a new #GtkFrame holding a group of #GtkRadioButtons.
**/
GtkWidget *
gimp_enum_radio_frame_new (GType enum_type,
GtkWidget *label_widget,
gint border_width,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button)
{
GtkWidget *frame;
GtkWidget *radio_box;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
g_return_val_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget),
NULL);
frame = gtk_frame_new (NULL);
if (label_widget)
{
gtk_frame_set_label_widget (GTK_FRAME (frame), label_widget);
gtk_widget_show (label_widget);
}
radio_box = gimp_enum_radio_box_new (enum_type,
callback, callback_data,
first_button);
gtk_container_set_border_width (GTK_CONTAINER (radio_box), border_width);
gtk_container_add (GTK_CONTAINER (frame), radio_box);
gtk_widget_show (radio_box);
return frame;
}
GtkWidget *
gimp_enum_radio_frame_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GtkWidget *label_widget,
gint border_width,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button)
{
GtkWidget *frame;
GtkWidget *radio_box;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
g_return_val_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget),
NULL);
frame = gtk_frame_new (NULL);
if (label_widget)
{
gtk_frame_set_label_widget (GTK_FRAME (frame), label_widget);
gtk_widget_show (label_widget);
}
radio_box = gimp_enum_radio_box_new_with_range (enum_type,
minimum,
maximum,
callback, callback_data,
first_button);
gtk_container_set_border_width (GTK_CONTAINER (radio_box), border_width);
gtk_container_add (GTK_CONTAINER (frame), radio_box);
gtk_widget_show (radio_box);
return frame;
}
/**
* gimp_enum_stock_box_new:
* @enum_type: the #GType of an enum.
* @stock_prefix: the prefix of the group of stock ids to use.
* @icon_size:
* @callback: a callback to connect to the "toggled" signal of each
* #GtkRadioButton that is created.
* @callback_data: data to pass to the @callback.
* @first_button: returns the first button in the created group.
*
* Creates a horizontal box of radio buttons with stock icons. The
* stock_id for each icon is created by appending the enum_value's
* nick to the given @stock_prefix.
*
* Return value: a new #GtkHbox holding a group of #GtkRadioButtons.
**/
GtkWidget *
gimp_enum_stock_box_new (GType enum_type,
const gchar *stock_prefix,
GtkIconSize icon_size,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button)
{
GEnumClass *enum_class;
GtkWidget *box;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
enum_class = g_type_class_ref (enum_type);
box = gimp_enum_stock_box_new_with_range (enum_type,
enum_class->minimum,
enum_class->maximum,
stock_prefix, icon_size,
callback, callback_data,
first_button);
g_type_class_unref (enum_class);
return box;
}
GtkWidget *
gimp_enum_stock_box_new_with_range (GType enum_type,
gint minimum,
gint maximum,
const gchar *stock_prefix,
GtkIconSize icon_size,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button)
{
GtkWidget *hbox;
GtkWidget *button;
GtkWidget *image;
GEnumClass *enum_class;
GEnumValue *value;
gchar *stock_id;
GSList *group = NULL;
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
g_return_val_if_fail (stock_prefix != NULL, NULL);
enum_class = g_type_class_ref (enum_type);
hbox = gtk_hbox_new (FALSE, 2);
g_object_weak_ref (G_OBJECT (hbox),
(GWeakNotify) g_type_class_unref, enum_class);
if (first_button)
*first_button = NULL;
for (value = enum_class->values; value->value_name; value++)
{
if (value->value < minimum || value->value > maximum)
continue;
button = gtk_radio_button_new (group);
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
if (first_button && *first_button == NULL)
*first_button = button;
stock_id = g_strconcat (stock_prefix, "-", value->value_nick, NULL);
image = gtk_image_new_from_stock (stock_id, icon_size);
g_free (stock_id);
if (image)
{
gtk_container_add (GTK_CONTAINER (button), image);
gtk_widget_show (image);
}
if (value->value_name)
gimp_help_set_help_data (button, gettext (value->value_name), NULL);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
g_object_set_data (G_OBJECT (button), "gimp-item-data",
GINT_TO_POINTER (value->value));
if (callback)
g_signal_connect (button, "toggled",
callback,
callback_data);
}
return hbox;
}
void
gimp_enum_stock_box_set_child_padding (GtkWidget *stock_box,
gint xpad,
gint ypad)
{
GList *list;
g_return_if_fail (GTK_IS_CONTAINER (stock_box));
for (list = gtk_container_get_children (GTK_CONTAINER (stock_box));
list;
list = g_list_next (list))
{
GtkBin *bin = list->data;
GtkMisc *misc = GTK_MISC (bin->child);
gtk_misc_set_padding (misc,
xpad < 0 ? misc->xpad : xpad,
ypad < 0 ? misc->ypad : ypad);
}
}

View File

@ -0,0 +1,72 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpenumwidgets.h
* Copyright (C) 2002-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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_ENUM_WIDGETS_H__
#define __GIMP_ENUM_WIDGETS_H__
GtkWidget * gimp_enum_radio_box_new (GType enum_type,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_box_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_frame_new (GType enum_type,
GtkWidget *label_widget,
gint border_width,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_radio_frame_new_with_range (GType enum_type,
gint minimum,
gint maximum,
GtkWidget *label_widget,
gint border_width,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_stock_box_new (GType enum_type,
const gchar *stock_prefix,
GtkIconSize icon_size,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
GtkWidget * gimp_enum_stock_box_new_with_range (GType enum_type,
gint minimum,
gint maximum,
const gchar *stock_prefix,
GtkIconSize icon_size,
GCallback callback,
gpointer callback_data,
GtkWidget **first_button);
void gimp_enum_stock_box_set_child_padding (GtkWidget *stock_box,
gint xpad,
gint ypad);
#endif /* __GIMP_ENUM_WIDGETS_H__ */

View File

@ -2,7 +2,8 @@
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimppropwidgets.c
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
* Copyright (C) 2002-2004 Michael Natterer <mitch@gimp.org>
* 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
@ -38,7 +39,9 @@
#include "gimpcolorpanel.h"
#include "gimpdnd.h"
#include "gimpenummenu.h"
#include "gimpenumcombobox.h"
#include "gimpenumstore.h"
#include "gimpenumwidgets.h"
#include "gimppreview.h"
#include "gimppropwidgets.h"
#include "gimpwidgets-constructors.h"
@ -283,6 +286,100 @@ gimp_prop_enum_check_button_notify (GObject *config,
}
/*********************/
/* enum combo box */
/*********************/
static void gimp_prop_enum_combo_box_callback (GtkWidget *widget,
GObject *config);
static void gimp_prop_enum_combo_box_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *widget);
GtkWidget *
gimp_prop_enum_combo_box_new (GObject *config,
const gchar *property_name,
gint minimum,
gint maximum)
{
GParamSpec *param_spec;
GtkWidget *combo_box;
gint value;
param_spec = check_param_spec (config, property_name,
G_TYPE_PARAM_ENUM, G_STRLOC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
if (minimum != maximum)
{
GtkListStore *store;
store = gimp_enum_store_new_with_range (param_spec->value_type,
minimum, maximum);
combo_box = gimp_enum_combo_box_new_with_model (GIMP_ENUM_STORE (store));
g_object_unref (store);
}
else
{
combo_box = gimp_enum_combo_box_new (param_spec->value_type);
}
gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo_box), value);
g_signal_connect (combo_box, "changed",
G_CALLBACK (gimp_prop_enum_combo_box_callback),
config);
set_param_spec (G_OBJECT (combo_box), combo_box, param_spec);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_enum_combo_box_notify),
combo_box);
return combo_box;
}
static void
gimp_prop_enum_combo_box_callback (GtkWidget *widget,
GObject *config)
{
GParamSpec *param_spec;
gint value;
param_spec = get_param_spec (G_OBJECT (widget));
if (! param_spec)
return;
if (gimp_enum_combo_box_get_active (GIMP_ENUM_COMBO_BOX (widget), &value))
{
g_object_set (config,
param_spec->name, value,
NULL);
}
}
static void
gimp_prop_enum_combo_box_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *combo_box)
{
gint value;
g_object_get (config,
param_spec->name, &value,
NULL);
gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo_box), value);
}
/******************/
/* option menus */
/******************/
@ -293,6 +390,39 @@ static void gimp_prop_option_menu_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *menu);
GtkWidget *
gimp_prop_paint_mode_menu_new (GObject *config,
const gchar *property_name,
gboolean with_behind_mode)
{
GParamSpec *param_spec;
GtkWidget *menu;
gint value;
param_spec = check_param_spec (config, property_name,
G_TYPE_PARAM_ENUM, G_STRLOC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
menu = gimp_paint_mode_menu_new (G_CALLBACK (gimp_prop_option_menu_callback),
config,
with_behind_mode,
value);
set_param_spec (G_OBJECT (menu), menu, param_spec);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_option_menu_notify),
menu);
return menu;
}
GtkWidget *
gimp_prop_boolean_option_menu_new (GObject *config,
const gchar *property_name,
@ -331,82 +461,6 @@ gimp_prop_boolean_option_menu_new (GObject *config,
return menu;
}
GtkWidget *
gimp_prop_enum_option_menu_new (GObject *config,
const gchar *property_name,
gint minimum,
gint maximum)
{
GParamSpec *param_spec;
GtkWidget *menu;
gint value;
param_spec = check_param_spec (config, property_name,
G_TYPE_PARAM_ENUM, G_STRLOC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
if (minimum != maximum)
{
menu = gimp_enum_option_menu_new_with_range (param_spec->value_type,
minimum, maximum,
G_CALLBACK (gimp_prop_option_menu_callback),
config);
}
else
{
menu = gimp_enum_option_menu_new (param_spec->value_type,
G_CALLBACK (gimp_prop_option_menu_callback),
config);
}
gimp_int_option_menu_set_history (GTK_OPTION_MENU (menu), value);
set_param_spec (G_OBJECT (menu), menu, param_spec);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_option_menu_notify),
menu);
return menu;
}
GtkWidget *
gimp_prop_paint_mode_menu_new (GObject *config,
const gchar *property_name,
gboolean with_behind_mode)
{
GParamSpec *param_spec;
GtkWidget *menu;
gint value;
param_spec = check_param_spec (config, property_name,
G_TYPE_PARAM_ENUM, G_STRLOC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
menu = gimp_paint_mode_menu_new (G_CALLBACK (gimp_prop_option_menu_callback),
config,
with_behind_mode,
value);
set_param_spec (G_OBJECT (menu), menu, param_spec);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_option_menu_notify),
menu);
return menu;
}
static void
gimp_prop_option_menu_callback (GtkWidget *widget,
GObject *config)

View File

@ -41,10 +41,11 @@ GtkWidget * gimp_prop_boolean_radio_frame_new (GObject *config,
/* GParamEnum */
GtkWidget * gimp_prop_enum_option_menu_new (GObject *config,
GtkWidget * gimp_prop_enum_combo_box_new (GObject *config,
const gchar *property_name,
gint minimum,
gint maximum);
GtkWidget * gimp_prop_paint_mode_menu_new (GObject *config,
const gchar *property_name,
gboolean with_behind_mode);