Commit ea1b88f5 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/widgets/Makefile.am app/widgets/widgets-types.h new widget built from

2004-10-26  Michael Natterer  <mitch@gimp.org>

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpcontrollereditor.[ch]: new widget built from
	preliminary code from the prefs dialog. Prerequisite for finally
	fixing bug #106920.

	* app/dialogs/preferences-dialog.c: use the new widget.
parent 3df8d90b
2004-10-26 Michael Natterer <mitch@gimp.org>
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpcontrollereditor.[ch]: new widget built from
preliminary code from the prefs dialog. Prerequisite for finally
fixing bug #106920.
* app/dialogs/preferences-dialog.c: use the new widget.
2004-10-26 Michael Natterer <mitch@gimp.org>
 
* plug-ins/common/retinex.c: cleaned up the GUI and GIMP-specific
......
......@@ -25,7 +25,6 @@
#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimpwidgets/gimpcontroller.h"
#include "dialogs-types.h"
......@@ -43,7 +42,7 @@
#include "widgets/gimpcontainercombobox.h"
#include "widgets/gimpcontainerview.h"
#include "widgets/gimpcontrollers.h"
#include "widgets/gimpcontrollerinfo.h"
#include "widgets/gimpcontrollereditor.h"
#include "widgets/gimpdeviceinfo.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpdialogfactory.h"
......@@ -2032,13 +2031,6 @@ prefs_dialog_new (Gimp *gimp,
GimpContainer *controllers;
GtkWidget *notebook;
GList *list;
enum
{
COLUMN_EVENT,
COLUMN_ACTION,
NUM_COLUMNS
};
controllers = gimp_controllers_get_list (gimp);
......@@ -2052,147 +2044,15 @@ prefs_dialog_new (Gimp *gimp,
list;
list = g_list_next (list))
{
GimpControllerInfo *info = list->data;
GimpController *controller = info->controller;
GimpControllerClass *controller_class;
GtkListStore *store;
GtkWidget *vbox3;
GtkWidget *vbox4;
GtkWidget *tv;
GtkWidget *sw;
GtkWidget *entry;
GParamSpec **property_specs;
guint n_property_specs;
gint n_events;
gint row;
gint i;
controller_class = GIMP_CONTROLLER_GET_CLASS (controller);
vbox3 = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (vbox3), 4);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox3,
GimpControllerInfo *info = list->data;
GtkWidget *editor;
editor = gimp_controller_editor_new (info);
gtk_container_set_border_width (GTK_CONTAINER (editor), 4);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), editor,
gimp_prop_label_new (G_OBJECT (info),
"name"));
gtk_widget_show (vbox3);
vbox4 = prefs_frame_new (_("General"),
GTK_CONTAINER (vbox3), FALSE);
entry = gimp_prop_entry_new (G_OBJECT (info), "name", -1);
gtk_box_pack_start (GTK_BOX (vbox4), entry, FALSE, FALSE, 0);
gtk_widget_show (entry);
prefs_check_button_add (G_OBJECT (info), "debug-events",
_("Dump events from this controller"),
GTK_BOX (vbox4));
prefs_check_button_add (G_OBJECT (info), "enabled",
_("Enable this controller"),
GTK_BOX (vbox4));
vbox4 = prefs_frame_new (controller_class->name,
GTK_CONTAINER (vbox3), TRUE);
property_specs =
g_object_class_list_properties (G_OBJECT_CLASS (controller_class),
&n_property_specs);
table = prefs_table_new (1, GTK_CONTAINER (vbox4));
row = 0;
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
_("Name:"), 0.0, 0.5,
gimp_prop_label_new (G_OBJECT (controller),
"name"),
1, TRUE);
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec = property_specs[i];
GtkWidget *widget = NULL;
if (prop_spec->owner_type == GIMP_TYPE_CONTROLLER)
continue;
if (G_IS_PARAM_SPEC_STRING (prop_spec))
{
if (prop_spec->flags & G_PARAM_WRITABLE)
widget = gimp_prop_entry_new (G_OBJECT (controller),
prop_spec->name, -1);
else
widget = gimp_prop_label_new (G_OBJECT (controller),
prop_spec->name);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
g_param_spec_get_nick (prop_spec),
0.0, 0.5,
widget,
1, FALSE);
}
else if (G_IS_PARAM_SPEC_INT (prop_spec))
{
if (prop_spec->flags & G_PARAM_WRITABLE)
{
widget = gimp_prop_spin_button_new (G_OBJECT (controller),
prop_spec->name,
1, 8, 0);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
g_param_spec_get_nick (prop_spec),
0.0, 0.5,
widget,
1, TRUE);
}
}
}
g_free (property_specs);
store = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_STRING, G_TYPE_STRING);
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
g_object_unref (store);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (sw), tv);
gtk_widget_show (tv);
gtk_container_add (GTK_CONTAINER (vbox4), sw);
gtk_widget_show (sw);
n_events = gimp_controller_get_n_events (controller);
for (i = 0; i < n_events; i++)
{
GtkTreeIter iter;
const gchar *event_name;
const gchar *event_blurb;
const gchar *event_action;
event_name = gimp_controller_get_event_name (controller, i);
event_blurb = gimp_controller_get_event_blurb (controller, i);
event_action = g_hash_table_lookup (info->mapping, event_name);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COLUMN_EVENT, event_blurb,
COLUMN_ACTION, event_action,
-1);
}
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tv), 0,
_("Event"),
gtk_cell_renderer_text_new (),
"text", COLUMN_EVENT,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tv), 2,
_("Action"),
gtk_cell_renderer_text_new (),
"text", COLUMN_ACTION,
NULL);
gtk_widget_show (editor);
}
}
......
......@@ -81,6 +81,8 @@ libappwidgets_a_sources = \
gimpcontainerview.h \
gimpcontainerview-utils.c \
gimpcontainerview-utils.h \
gimpcontrollereditor.c \
gimpcontrollereditor.h \
gimpcontrollerinfo.c \
gimpcontrollerinfo.h \
gimpcontrollers.c \
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* gimpcontrollereditor.c
* Copyright (C) 2004 Michael Natterer <mitch@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 "libgimpwidgets/gimpcontroller.h"
#include "widgets-types.h"
#include "gimpcontrollereditor.h"
#include "gimpcontrollerinfo.h"
#include "gimppropwidgets.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_CONTROLLER_INFO
};
enum
{
COLUMN_EVENT,
COLUMN_ACTION,
NUM_COLUMNS
};
static void gimp_controller_editor_class_init (GimpControllerEditorClass *klass);
static void gimp_controller_editor_init (GimpControllerEditor *editor);
static GObject * gimp_controller_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_controller_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_controller_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_controller_editor_finalize (GObject *object);
static GtkVBoxClass *parent_class = NULL;
GType
gimp_controller_editor_get_type (void)
{
static GType view_type = 0;
if (! view_type)
{
static const GTypeInfo view_info =
{
sizeof (GimpControllerEditorClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_controller_editor_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpControllerEditor),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_controller_editor_init
};
view_type = g_type_register_static (GTK_TYPE_VBOX,
"GimpControllerEditor",
&view_info, 0);
}
return view_type;
}
static void
gimp_controller_editor_class_init (GimpControllerEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_controller_editor_constructor;
object_class->set_property = gimp_controller_editor_set_property;
object_class->get_property = gimp_controller_editor_get_property;
object_class->finalize = gimp_controller_editor_finalize;
g_object_class_install_property (object_class, PROP_CONTROLLER_INFO,
g_param_spec_object ("controller-info",
NULL, NULL,
GIMP_TYPE_CONTROLLER_INFO,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_controller_editor_init (GimpControllerEditor *editor)
{
editor->info = NULL;
}
static GObject *
gimp_controller_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpControllerEditor *editor;
GimpControllerInfo *info;
GimpController *controller;
GimpControllerClass *controller_class;
GtkListStore *store;
GtkWidget *frame;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *button;
GtkWidget *tv;
GtkWidget *sw;
GtkWidget *entry;
GParamSpec **property_specs;
guint n_property_specs;
gint n_events;
gint row;
gint i;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
editor = GIMP_CONTROLLER_EDITOR (object);
g_assert (GIMP_IS_CONTROLLER_INFO (editor->info));
info = editor->info;
controller = info->controller;
controller_class = GIMP_CONTROLLER_GET_CLASS (controller);
frame = gimp_frame_new (_("General"));
gtk_box_pack_start (GTK_BOX (editor), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
entry = gimp_prop_entry_new (G_OBJECT (info), "name", -1);
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
gtk_widget_show (entry);
button = gimp_prop_check_button_new (G_OBJECT (info), "debug-events",
_("Dump events from this controller"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
button = gimp_prop_check_button_new (G_OBJECT (info), "enabled",
_("Enable this controller"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
frame = gimp_frame_new (controller_class->name);
gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
table = gtk_table_new (1, 2, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
row = 0;
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
_("Name:"), 0.0, 0.5,
gimp_prop_label_new (G_OBJECT (controller),
"name"),
1, TRUE);
property_specs =
g_object_class_list_properties (G_OBJECT_CLASS (controller_class),
&n_property_specs);
for (i = 0; i < n_property_specs; i++)
{
GParamSpec *prop_spec = property_specs[i];
GtkWidget *widget = NULL;
if (prop_spec->owner_type == GIMP_TYPE_CONTROLLER)
continue;
if (G_IS_PARAM_SPEC_STRING (prop_spec))
{
if (prop_spec->flags & G_PARAM_WRITABLE)
widget = gimp_prop_entry_new (G_OBJECT (controller),
prop_spec->name, -1);
else
widget = gimp_prop_label_new (G_OBJECT (controller),
prop_spec->name);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
g_param_spec_get_nick (prop_spec),
0.0, 0.5,
widget,
1, FALSE);
}
else if (G_IS_PARAM_SPEC_INT (prop_spec))
{
if (prop_spec->flags & G_PARAM_WRITABLE)
{
widget = gimp_prop_spin_button_new (G_OBJECT (controller),
prop_spec->name,
1, 8, 0);
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
g_param_spec_get_nick (prop_spec),
0.0, 0.5,
widget,
1, TRUE);
}
}
}
g_free (property_specs);
store = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_STRING,
G_TYPE_STRING);
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
g_object_unref (store);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (sw), tv);
gtk_widget_show (tv);
gtk_container_add (GTK_CONTAINER (vbox), sw);
gtk_widget_show (sw);
n_events = gimp_controller_get_n_events (controller);
for (i = 0; i < n_events; i++)
{
GtkTreeIter iter;
const gchar *event_name;
const gchar *event_blurb;
const gchar *event_action;
event_name = gimp_controller_get_event_name (controller, i);
event_blurb = gimp_controller_get_event_blurb (controller, i);
event_action = g_hash_table_lookup (info->mapping, event_name);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COLUMN_EVENT, event_blurb,
COLUMN_ACTION, event_action,
-1);
}
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tv), 0,
_("Event"),
gtk_cell_renderer_text_new (),
"text", COLUMN_EVENT,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tv), 2,
_("Action"),
gtk_cell_renderer_text_new (),
"text", COLUMN_ACTION,
NULL);
return object;
}
static void
gimp_controller_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpControllerEditor *editor = GIMP_CONTROLLER_EDITOR (object);
switch (property_id)
{
case PROP_CONTROLLER_INFO:
editor->info = GIMP_CONTROLLER_INFO (g_value_dup_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_controller_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpControllerEditor *editor = GIMP_CONTROLLER_EDITOR (object);
switch (property_id)
{
case PROP_CONTROLLER_INFO:
g_value_set_object (value, editor->info);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_controller_editor_finalize (GObject *object)
{
GimpControllerEditor *editor = GIMP_CONTROLLER_EDITOR (object);
if (editor->info)
{
g_object_unref (editor->info);
editor->info = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
GtkWidget *
gimp_controller_editor_new (GimpControllerInfo *info)
{
g_return_val_if_fail (GIMP_IS_CONTROLLER_INFO (info), NULL);
return g_object_new (GIMP_TYPE_CONTROLLER_EDITOR,
"controller-info", info,
NULL);
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcontrollereditor.h
* Copyright (C) 2004 Michael Natterer <mitch@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_CONTROLLER_EDITOR_H__
#define __GIMP_CONTROLLER_EDITOR_H__
#include <gtk/gtkvbox.h>
#define GIMP_TYPE_CONTROLLER_EDITOR (gimp_controller_editor_get_type ())
#define GIMP_CONTROLLER_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTROLLER_EDITOR, GimpControllerEditor))
#define GIMP_CONTROLLER_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTROLLER_EDITOR, GimpControllerEditorClass))
#define GIMP_IS_CONTROLLER_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CONTROLLER_EDITOR))
#define GIMP_IS_CONTROLLER_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTROLLER_EDITOR))
#define GIMP_CONTROLLER_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CONTROLLER_EDITOR, GimpControllerEditorClass))
typedef struct _GimpControllerEditorClass GimpControllerEditorClass;
struct _GimpControllerEditor
{
GtkVBox parent_instance;
GimpControllerInfo *info;
};