Commit 92ad7c1d authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/widgets/Makefile.am app/widgets/widgets-types.h new widget which

2005-05-09  Michael Natterer  <mitch@gimp.org>

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpcontrollerlist.[ch]: new widget which allows
	adding/removing controllers using two lists of available/active
	controllers. Work in progress...

	* app/widgets/gimpcontrollerinfo.[ch]: derive it from GimpVieable
	so it can have an icon (unfinished). Added convenience constructor
	gimp_controller_info_new().

	* app/dialogs/preferences-dialog.c: use a GimpControllerList
	instead of a notebook of GimpControllerEditors.
parent 06e83246
2005-05-09 Michael Natterer <mitch@gimp.org>
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpcontrollerlist.[ch]: new widget which allows
adding/removing controllers using two lists of available/active
controllers. Work in progress...
* app/widgets/gimpcontrollerinfo.[ch]: derive it from GimpVieable
so it can have an icon (unfinished). Added convenience constructor
gimp_controller_info_new().
* app/dialogs/preferences-dialog.c: use a GimpControllerList
instead of a notebook of GimpControllerEditors.
2005-05-09 Sven Neumann <sven@gimp.org>
* plug-ins/jpeg/Makefile.am: removed traces of plug-ins/common,
......
......@@ -39,8 +39,7 @@
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimpcontainercombobox.h"
#include "widgets/gimpcontainerview.h"
#include "widgets/gimpcontrollers.h"
#include "widgets/gimpcontrollereditor.h"
#include "widgets/gimpcontrollerlist.h"
#include "widgets/gimpdeviceinfo.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpdialogfactory.h"
......@@ -2258,32 +2257,9 @@ prefs_dialog_new (Gimp *gimp,
&child_iter,
page_index++);
{
GimpContainer *controllers = gimp_controllers_get_list (gimp);
GtkWidget *notebook;
GList *list;
notebook = gtk_notebook_new ();
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook));
gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
gtk_widget_show (notebook);
for (list = GIMP_LIST (controllers)->list;
list;
list = g_list_next (list))
{
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 (editor);
}
}
vbox2 = gimp_controller_list_new (gimp);
gtk_box_pack_start (GTK_BOX (vbox), vbox2, TRUE, TRUE, 0);
gtk_widget_show (vbox2);
/***********************/
......
......@@ -84,6 +84,8 @@ libappwidgets_a_sources = \
gimpcontrollereditor.h \
gimpcontrollerinfo.c \
gimpcontrollerinfo.h \
gimpcontrollerlist.c \
gimpcontrollerlist.h \
gimpcontrollers.c \
gimpcontrollers.h \
gimpcontrollerkeyboard.c \
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcontrollerinfo.c
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
* Copyright (C) 2004-2005 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -90,7 +90,7 @@ static gboolean gimp_controller_info_event (GimpController *controlle
GimpControllerInfo *info);
static GimpObjectClass *parent_class = NULL;
static GimpViewableClass *parent_class = NULL;
static guint info_signals[LAST_SIGNAL] = { 0 };
......@@ -121,7 +121,7 @@ gimp_controller_info_get_type (void)
NULL /* iface_data */
};
controller_type = g_type_register_static (GIMP_TYPE_OBJECT,
controller_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
"GimpControllerInfo",
&controller_info, 0);
......@@ -405,6 +405,32 @@ gimp_controller_info_deserialize_property (GimpConfig *config,
return TRUE;
}
/* public functions */
GimpControllerInfo *
gimp_controller_info_new (GType type)
{
GimpControllerClass *controller_class;
GimpController *controller;
GimpControllerInfo *info;
g_return_val_if_fail (g_type_is_a (type, GIMP_TYPE_CONTROLLER), NULL);
controller_class = g_type_class_ref (type);
controller = gimp_controller_new (type);
info = g_object_new (GIMP_TYPE_CONTROLLER_INFO,
"name", controller_class->name,
"controller", controller,
NULL);
g_object_unref (controller);
g_type_class_unref (controller_class);
return info;
}
void
gimp_controller_info_set_enabled (GimpControllerInfo *info,
gboolean enabled)
......@@ -423,6 +449,9 @@ gimp_controller_info_get_enabled (GimpControllerInfo *info)
return info->enabled;
}
/* private functions */
static gboolean
gimp_controller_info_event (GimpController *controller,
const GimpControllerEvent *event,
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcontrollerinfo.h
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
* Copyright (C) 2004-2005 Michael Natterer <mitch@gimp.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -24,7 +24,7 @@
#define __GIMP_CONTROLLER_INFO_H__
#include "core/gimpobject.h"
#include "core/gimpviewable.h"
#define GIMP_TYPE_CONTROLLER_INFO (gimp_controller_info_get_type ())
......@@ -39,7 +39,7 @@ typedef struct _GimpControllerInfoClass GimpControllerInfoClass;
struct _GimpControllerInfo
{
GimpObject parent_instance;
GimpViewable parent_instance;
gboolean enabled;
gboolean debug_events;
......@@ -50,7 +50,7 @@ struct _GimpControllerInfo
struct _GimpControllerInfoClass
{
GimpObjectClass parent_class;
GimpViewableClass parent_class;
gboolean (* event_mapped) (GimpControllerInfo *info,
GimpController *controller,
......@@ -59,11 +59,13 @@ struct _GimpControllerInfoClass
};
GType gimp_controller_info_get_type (void) G_GNUC_CONST;
GType gimp_controller_info_get_type (void) G_GNUC_CONST;
void gimp_controller_info_set_enabled (GimpControllerInfo *info,
gboolean enabled);
gboolean gimp_controller_info_get_enabled (GimpControllerInfo *info);
GimpControllerInfo * gimp_controller_info_new (GType type);
void gimp_controller_info_set_enabled (GimpControllerInfo *info,
gboolean enabled);
gboolean gimp_controller_info_get_enabled (GimpControllerInfo *info);
#endif /* __GIMP_CONTROLLER_INFO_H__ */
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* gimpcontrollerlist.c
* Copyright (C) 2005 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 <string.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#define GIMP_ENABLE_CONTROLLER_UNDER_CONSTRUCTION
#include "libgimpwidgets/gimpcontroller.h"
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "gimpcontainertreeview.h"
#include "gimpcontrollereditor.h"
#include "gimpcontrollerlist.h"
#include "gimpcontrollerinfo.h"
#include "gimpcontrollerkeyboard.h"
#include "gimpcontrollerwheel.h"
#include "gimpcontrollers.h"
#include "gimpdialogfactory.h"
#include "gimphelp-ids.h"
#include "gimppropwidgets.h"
#include "gimpuimanager.h"
#include "gimpviewabledialog.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_GIMP
};
enum
{
COLUMN_ICON,
COLUMN_NAME,
COLUMN_TYPE,
NUM_COLUMNS
};
static void gimp_controller_list_class_init (GimpControllerListClass *klass);
static void gimp_controller_list_init (GimpControllerList *list);
static GObject * gimp_controller_list_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_controller_list_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_controller_list_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_controller_list_finalize (GObject *object);
static void gimp_controller_list_src_sel_changed (GtkTreeSelection *sel,
GimpControllerList *list);
static void gimp_controller_list_row_activated (GtkTreeView *tv,
GtkTreePath *path,
GtkTreeViewColumn *column,
GimpControllerList *list);
static void gimp_controller_list_select_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data,
GimpControllerList *list);
static void gimp_controller_list_activate_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data,
GimpControllerList *list);
static void gimp_controller_list_add_clicked (GtkWidget *button,
GimpControllerList *list);
static void gimp_controller_list_remove_clicked (GtkWidget *button,
GimpControllerList *list);
static void gimp_controller_list_edit_clicked (GtkWidget *button,
GimpControllerList *list);
static void gimp_controller_list_edit_destroy (GtkWidget *widget,
GimpControllerInfo *info);
static GtkVBoxClass *parent_class = NULL;
GType
gimp_controller_list_get_type (void)
{
static GType view_type = 0;
if (! view_type)
{
static const GTypeInfo view_info =
{
sizeof (GimpControllerListClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gimp_controller_list_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpControllerList),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_controller_list_init
};
view_type = g_type_register_static (GTK_TYPE_VBOX,
"GimpControllerList",
&view_info, 0);
}
return view_type;
}
static void
gimp_controller_list_class_init (GimpControllerListClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_controller_list_constructor;
object_class->set_property = gimp_controller_list_set_property;
object_class->get_property = gimp_controller_list_get_property;
object_class->finalize = gimp_controller_list_finalize;
g_object_class_install_property (object_class, PROP_GIMP,
g_param_spec_object ("gimp",
NULL, NULL,
GIMP_TYPE_GIMP,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_controller_list_init (GimpControllerList *list)
{
GtkWidget *hbox;
GtkWidget *sw;
GtkWidget *tv;
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
GtkWidget *vbox;
GtkWidget *image;
GType *controller_types;
gint n_controller_types;
gint i;
list->gimp = NULL;
list->hbox = hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (list), hbox, TRUE, TRUE, 0);
gtk_widget_show (hbox);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
GTK_SHADOW_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0);
gtk_widget_show (sw);
list->src = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_POINTER);
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list->src));
g_object_unref (list->src);
gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (tv), FALSE);
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, _("Available Controllers"));
gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);
cell = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, cell, FALSE);
gtk_tree_view_column_set_attributes (column, cell,
"stock-id", COLUMN_ICON,
NULL);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_set_attributes (column, cell,
"text", COLUMN_NAME,
NULL);
gtk_container_add (GTK_CONTAINER (sw), tv);
gtk_widget_show (tv);
g_signal_connect_object (tv, "row-activated",
G_CALLBACK (gimp_controller_list_row_activated),
G_OBJECT (list), 0);
list->src_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
gtk_tree_selection_set_mode (list->src_sel, GTK_SELECTION_BROWSE);
g_signal_connect_object (list->src_sel, "changed",
G_CALLBACK (gimp_controller_list_src_sel_changed),
G_OBJECT (list), 0);
controller_types = g_type_children (GIMP_TYPE_CONTROLLER,
&n_controller_types);
for (i = 0; i < n_controller_types; i++)
{
GimpControllerClass *controller_class;
GtkTreeIter iter;
controller_class = g_type_class_ref (controller_types[i]);
gtk_list_store_append (list->src, &iter);
gtk_list_store_set (list->src, &iter,
COLUMN_ICON, "foobar",
COLUMN_NAME, controller_class->name,
COLUMN_TYPE, controller_types[i],
-1);
g_type_class_unref (controller_class);
}
vbox = gtk_vbox_new (TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
gtk_widget_show (vbox);
list->add_button = gtk_button_new ();
gtk_box_pack_start (GTK_BOX (vbox), list->add_button, TRUE, FALSE, 0);
gtk_widget_set_sensitive (list->add_button, FALSE);
gtk_widget_show (list->add_button);
image = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (list->add_button), image);
gtk_widget_show (image);
gimp_help_set_help_data (list->add_button,
_("Create a controller of the selected type."),
NULL);
g_signal_connect (list->add_button, "clicked",
G_CALLBACK (gimp_controller_list_add_clicked),
list);
g_object_add_weak_pointer (G_OBJECT (list->add_button),
(gpointer) &list->add_button);
list->remove_button = gtk_button_new ();
gtk_box_pack_start (GTK_BOX (vbox), list->remove_button, TRUE, FALSE, 0);
gtk_widget_set_sensitive (list->remove_button, FALSE);
gtk_widget_show (list->remove_button);
image = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (list->remove_button), image);
gtk_widget_show (image);
gimp_help_set_help_data (list->remove_button,
_("Remove the selected filter from the list of "
"active filters."), NULL);
g_signal_connect (list->remove_button, "clicked",
G_CALLBACK (gimp_controller_list_remove_clicked),
list);
g_object_add_weak_pointer (G_OBJECT (list->remove_button),
(gpointer) &list->remove_button);
}
static GObject *
gimp_controller_list_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpControllerList *list;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
list = GIMP_CONTROLLER_LIST (object);
g_assert (GIMP_IS_GIMP (list->gimp));
list->dest =
gimp_container_tree_view_new (gimp_controllers_get_list (list->gimp),
NULL,
GIMP_VIEW_SIZE_SMALL, 0);
gtk_tree_view_column_set_title (GIMP_CONTAINER_TREE_VIEW (list->dest)->main_column,
_("Active Controllers"));
gtk_tree_view_set_headers_visible (GIMP_CONTAINER_TREE_VIEW (list->dest)->view,
TRUE);
gtk_box_pack_start (GTK_BOX (list->hbox), list->dest, TRUE, TRUE, 0);
gtk_widget_show (list->dest);
g_signal_connect_object (list->dest, "select-item",
G_CALLBACK (gimp_controller_list_select_item),
G_OBJECT (list), 0);
g_signal_connect_object (list->dest, "activate-item",
G_CALLBACK (gimp_controller_list_activate_item),
G_OBJECT (list), 0);
list->edit_button =
gimp_editor_add_button (GIMP_EDITOR (list->dest),
GIMP_STOCK_EDIT,
_("Configure the selected controller"),
NULL,
G_CALLBACK (gimp_controller_list_edit_clicked),
NULL,
list);
gtk_widget_set_sensitive (list->edit_button, FALSE);
return object;
}
static void
gimp_controller_list_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
switch (property_id)
{
case PROP_GIMP:
list->gimp = GIMP (g_value_dup_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_controller_list_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
switch (property_id)
{
case PROP_GIMP:
g_value_set_object (value, list->gimp);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_controller_list_finalize (GObject *object)
{
GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
if (list->gimp)
{
g_object_unref (list->gimp);
list->gimp = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/* public functions */
GtkWidget *
gimp_controller_list_new (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
return g_object_new (GIMP_TYPE_CONTROLLER_LIST,
"gimp", gimp,
NULL);
}
/* private functions */
static void
gimp_controller_list_src_sel_changed (GtkTreeSelection *sel,
GimpControllerList *list)
{
GtkTreeModel *model;
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (sel, &model, &iter))
{
gtk_tree_model_get (model, &iter,
COLUMN_TYPE, &list->src_gtype,
-1);
if (list->add_button)
gtk_widget_set_sensitive (list->add_button, TRUE);
}
else
{
if (list->add_button)