Commit 875342af authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

support setting a context even if the viewed container's children_type is

2006-08-31  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpcontainerview.c
	(gimp_container_view_real_set_container)
	(gimp_container_view_real_set_context)
	(gimp_container_view_item_selected)
	(gimp_container_view_thaw): support setting a context even if
	the viewed container's children_type is *not* a property of
	GimpContext. This removes a major restriction of container
	views and allows to get rid of some hacks:

	* app/widgets/gimpitemtreeview.[ch]: removed GimpContext member
	and implement GimpContainerView::set_context() instead of
	GimpDocked::set_context().

	* app/widgets/gimpchanneltreeview.c
	* app/widgets/gimpcontainergridview.c
	* app/widgets/gimpcontainertreeview.c
	* app/widgets/gimpdrawabletreeview.c
	* app/widgets/gimplayertreeview.c: use GimpContainerView's context
	instead of GimpItemTreeView's and implement GimpContainerView's
	set_context() instead of GimpDocked's.

	* app/actions/actions.c (action_data_get_gimp)
	(action_data_get_context): don't special-case GimpItemTreeView any
	more, it's just like a normal GimpContainerView now.

	* app/widgets/gimpcontrollerlist.c
	(gimp_controller_list_constructor): set a context on the
	GimpContainerView so its renderers have a context to use.
parent c1456a33
2006-08-31 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcontainerview.c
(gimp_container_view_real_set_container)
(gimp_container_view_real_set_context)
(gimp_container_view_item_selected)
(gimp_container_view_thaw): support setting a context even if
the viewed container's children_type is *not* a property of
GimpContext. This removes a major restriction of container
views and allows to get rid of some hacks:
* app/widgets/gimpitemtreeview.[ch]: removed GimpContext member
and implement GimpContainerView::set_context() instead of
GimpDocked::set_context().
* app/widgets/gimpchanneltreeview.c
* app/widgets/gimpcontainergridview.c
* app/widgets/gimpcontainertreeview.c
* app/widgets/gimpdrawabletreeview.c
* app/widgets/gimplayertreeview.c: use GimpContainerView's context
instead of GimpItemTreeView's and implement GimpContainerView's
set_context() instead of GimpDocked's.
* app/actions/actions.c (action_data_get_gimp)
(action_data_get_context): don't special-case GimpItemTreeView any
more, it's just like a normal GimpContainerView now.
* app/widgets/gimpcontrollerlist.c
(gimp_controller_list_constructor): set a context on the
GimpContainerView so its renderers have a context to use.
2006-08-31 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpthumbbox.[ch]: remember the context passed to
......
......@@ -256,8 +256,6 @@ action_data_get_gimp (gpointer data)
return data;
else if (GIMP_IS_DOCK (data))
context = ((GimpDock *) data)->context;
else if (GIMP_IS_ITEM_TREE_VIEW (data))
context = ((GimpItemTreeView *) data)->context;
else if (GIMP_IS_CONTAINER_VIEW (data))
context = gimp_container_view_get_context ((GimpContainerView *) data);
else if (GIMP_IS_CONTAINER_EDITOR (data))
......@@ -285,8 +283,6 @@ action_data_get_context (gpointer data)
return gimp_get_user_context (data);
else if (GIMP_IS_DOCK (data))
return ((GimpDock *) data)->context;
else if (GIMP_IS_ITEM_TREE_VIEW (data))
return ((GimpItemTreeView *) data)->context;
else if (GIMP_IS_CONTAINER_VIEW (data))
return gimp_container_view_get_context ((GimpContainerView *) data);
else if (GIMP_IS_CONTAINER_EDITOR (data))
......
......@@ -48,7 +48,6 @@
static void gimp_channel_tree_view_view_iface_init (GimpContainerViewInterface *iface);
static void gimp_channel_tree_view_docked_iface_init (GimpDockedInterface *iface);
static GObject * gimp_channel_tree_view_constructor (GType type,
guint n_params,
......@@ -66,23 +65,19 @@ static void gimp_channel_tree_view_set_image (GimpItemTreeView *item_v
GimpImage *image);
static GimpItem * gimp_channel_tree_view_item_new (GimpImage *image);
static void gimp_channel_tree_view_set_view_size (GimpContainerView *view);
static void gimp_channel_tree_view_set_context (GimpDocked *docked,
static void gimp_channel_tree_view_set_context (GimpContainerView *view,
GimpContext *context);
static void gimp_channel_tree_view_set_view_size (GimpContainerView *view);
G_DEFINE_TYPE_WITH_CODE (GimpChannelTreeView, gimp_channel_tree_view,
GIMP_TYPE_DRAWABLE_TREE_VIEW,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONTAINER_VIEW,
gimp_channel_tree_view_view_iface_init)
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
gimp_channel_tree_view_docked_iface_init))
gimp_channel_tree_view_view_iface_init))
#define parent_class gimp_channel_tree_view_parent_class
static GimpContainerViewInterface *parent_view_iface = NULL;
static GimpDockedInterface *parent_docked_iface = NULL;
static void
......@@ -129,17 +124,10 @@ gimp_channel_tree_view_view_iface_init (GimpContainerViewInterface *view_iface)
{
parent_view_iface = g_type_interface_peek_parent (view_iface);
view_iface->set_context = gimp_channel_tree_view_set_context;
view_iface->set_view_size = gimp_channel_tree_view_set_view_size;
}
static void
gimp_channel_tree_view_docked_iface_init (GimpDockedInterface *docked_iface)
{
parent_docked_iface = g_type_interface_peek_parent (docked_iface);
docked_iface->set_context = gimp_channel_tree_view_set_context;
}
static void
gimp_channel_tree_view_init (GimpChannelTreeView *view)
{
......@@ -295,7 +283,7 @@ gimp_channel_tree_view_set_image (GimpItemTreeView *item_view,
gimp_component_editor_new (view_size,
GIMP_EDITOR (item_view)->menu_factory);
gimp_docked_set_context (GIMP_DOCKED (channel_view->component_editor),
item_view->context);
gimp_container_view_get_context (view));
gtk_box_pack_start (GTK_BOX (item_view), channel_view->component_editor,
FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (item_view),
......@@ -341,32 +329,29 @@ gimp_channel_tree_view_item_new (GimpImage *image)
/* GimpContainerView methods */
static void
gimp_channel_tree_view_set_view_size (GimpContainerView *view)
gimp_channel_tree_view_set_context (GimpContainerView *view,
GimpContext *context)
{
GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (view);
gint view_size;
parent_view_iface->set_view_size (view);
view_size = gimp_container_view_get_view_size (view, NULL);
parent_view_iface->set_context (view, context);
if (channel_view->component_editor)
gimp_component_editor_set_view_size (GIMP_COMPONENT_EDITOR (channel_view->component_editor),
view_size);
gimp_docked_set_context (GIMP_DOCKED (channel_view->component_editor),
context);
}
/* GimpDocked methods */
static void
gimp_channel_tree_view_set_context (GimpDocked *docked,
GimpContext *context)
gimp_channel_tree_view_set_view_size (GimpContainerView *view)
{
GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (docked);
GimpChannelTreeView *channel_view = GIMP_CHANNEL_TREE_VIEW (view);
gint view_size;
parent_docked_iface->set_context (docked, context);
parent_view_iface->set_view_size (view);
view_size = gimp_container_view_get_view_size (view, NULL);
if (channel_view->component_editor)
gimp_docked_set_context (GIMP_DOCKED (channel_view->component_editor),
context);
gimp_component_editor_set_view_size (GIMP_COMPONENT_EDITOR (channel_view->component_editor),
view_size);
}
......@@ -36,7 +36,6 @@
#include "gimpcontainergridview.h"
#include "gimpcontainerview.h"
#include "gimpdocked.h"
#include "gimpview.h"
#include "gimpviewrenderer.h"
#include "gimpwidgets-utils.h"
......@@ -53,7 +52,6 @@ enum
static void gimp_container_grid_view_view_iface_init (GimpContainerViewInterface *iface);
static void gimp_container_grid_view_docked_iface_init (GimpDockedInterface *iface);
static gboolean gimp_container_grid_view_move_cursor (GimpContainerGridView *view,
GtkMovementStep step,
......@@ -62,6 +60,8 @@ static gboolean gimp_container_grid_view_focus (GtkWidget *w
GtkDirectionType direction);
static gboolean gimp_container_grid_view_popup_menu (GtkWidget *widget);
static void gimp_container_grid_view_set_context (GimpContainerView *view,
GimpContext *context);
static gpointer gimp_container_grid_view_insert_item (GimpContainerView *view,
GimpViewable *viewable,
gint index);
......@@ -80,8 +80,6 @@ static gboolean gimp_container_grid_view_select_item (GimpContainerView *v
gpointer insert_data);
static void gimp_container_grid_view_clear_items (GimpContainerView *view);
static void gimp_container_grid_view_set_view_size (GimpContainerView *view);
static void gimp_container_grid_view_set_context (GimpDocked *docked,
GimpContext *context);
static gboolean gimp_container_grid_view_item_selected(GtkWidget *widget,
GdkEventButton *bevent,
......@@ -105,14 +103,11 @@ static gboolean gimp_container_grid_view_button_press (GtkWidget *w
G_DEFINE_TYPE_WITH_CODE (GimpContainerGridView, gimp_container_grid_view,
GIMP_TYPE_CONTAINER_BOX,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONTAINER_VIEW,
gimp_container_grid_view_view_iface_init)
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
gimp_container_grid_view_docked_iface_init))
gimp_container_grid_view_view_iface_init))
#define parent_class gimp_container_grid_view_parent_class
static GimpContainerViewInterface *parent_view_iface = NULL;
static GimpDockedInterface *parent_docked_iface = NULL;
static guint grid_view_signals[LAST_SIGNAL] = { 0 };
......@@ -170,6 +165,7 @@ gimp_container_grid_view_view_iface_init (GimpContainerViewInterface *iface)
{
parent_view_iface = g_type_interface_peek_parent (iface);
iface->set_context = gimp_container_grid_view_set_context;
iface->insert_item = gimp_container_grid_view_insert_item;
iface->remove_item = gimp_container_grid_view_remove_item;
iface->reorder_item = gimp_container_grid_view_reorder_item;
......@@ -179,17 +175,6 @@ gimp_container_grid_view_view_iface_init (GimpContainerViewInterface *iface)
iface->set_view_size = gimp_container_grid_view_set_view_size;
}
static void
gimp_container_grid_view_docked_iface_init (GimpDockedInterface *iface)
{
parent_docked_iface = g_type_interface_peek_parent (iface);
if (! parent_docked_iface)
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
iface->set_context = gimp_container_grid_view_set_context;
}
static void
gimp_container_grid_view_init (GimpContainerGridView *grid_view)
{
......@@ -406,6 +391,25 @@ gimp_container_grid_view_popup_menu (GtkWidget *widget)
grid_view);
}
static void
gimp_container_grid_view_set_context (GimpContainerView *view,
GimpContext *context)
{
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GtkWrapBoxChild *child;
parent_view_iface->set_context (view, context);
for (child = GTK_WRAP_BOX (grid_view->wrap_box)->children;
child;
child = child->next)
{
GimpView *view = GIMP_VIEW (child->widget);
gimp_view_renderer_set_context (view->renderer, context);
}
}
static gpointer
gimp_container_grid_view_insert_item (GimpContainerView *container_view,
GimpViewable *viewable,
......@@ -538,25 +542,6 @@ gimp_container_grid_view_set_view_size (GimpContainerView *view)
gtk_widget_queue_resize (grid_view->wrap_box);
}
static void
gimp_container_grid_view_set_context (GimpDocked *docked,
GimpContext *context)
{
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (docked);
GtkWrapBoxChild *child;
parent_docked_iface->set_context (docked, context);
for (child = GTK_WRAP_BOX (grid_view->wrap_box)->children;
child;
child = child->next)
{
GimpView *view = GIMP_VIEW (child->widget);
gimp_view_renderer_set_context (view->renderer, context);
}
}
static gboolean
gimp_container_grid_view_item_selected (GtkWidget *widget,
GdkEventButton *bevent,
......
......@@ -38,7 +38,6 @@
#include "gimpcontainertreeview-dnd.h"
#include "gimpcontainerview.h"
#include "gimpdnd.h"
#include "gimpdocked.h"
#include "gimpviewrenderer.h"
#include "gimpwidgets-utils.h"
......@@ -53,7 +52,6 @@ enum
static void gimp_container_tree_view_view_iface_init (GimpContainerViewInterface *iface);
static void gimp_container_tree_view_docked_iface_init (GimpDockedInterface *iface);
static GObject *gimp_container_tree_view_constructor (GType type,
guint n_params,
......@@ -65,6 +63,8 @@ static gboolean gimp_container_tree_view_popup_menu (GtkWidget *w
static void gimp_container_tree_view_set_container (GimpContainerView *view,
GimpContainer *container);
static void gimp_container_tree_view_set_context (GimpContainerView *view,
GimpContext *context);
static gpointer gimp_container_tree_view_insert_item (GimpContainerView *view,
GimpViewable *viewable,
gint index);
......@@ -87,9 +87,6 @@ static void gimp_container_tree_view_set_view_size (GimpContainerView *v
static void gimp_container_tree_view_name_canceled (GtkCellRendererText *cell,
GimpContainerTreeView *tree_view);
static void gimp_container_tree_view_set_context (GimpDocked *view,
GimpContext *context);
static void gimp_container_tree_view_selection_changed (GtkTreeSelection *sel,
GimpContainerTreeView *tree_view);
static gboolean gimp_container_tree_view_button_press (GtkWidget *widget,
......@@ -108,14 +105,11 @@ static GdkPixbuf * gimp_container_tree_view_drag_pixbuf (GtkWidget *w
G_DEFINE_TYPE_WITH_CODE (GimpContainerTreeView, gimp_container_tree_view,
GIMP_TYPE_CONTAINER_BOX,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONTAINER_VIEW,
gimp_container_tree_view_view_iface_init)
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
gimp_container_tree_view_docked_iface_init))
gimp_container_tree_view_view_iface_init))
#define parent_class gimp_container_tree_view_parent_class
static GimpContainerViewInterface *parent_view_iface = NULL;
static GimpDockedInterface *parent_docked_iface = NULL;
static void
......@@ -145,6 +139,7 @@ gimp_container_tree_view_view_iface_init (GimpContainerViewInterface *iface)
parent_view_iface = g_type_interface_peek_parent (iface);
iface->set_container = gimp_container_tree_view_set_container;
iface->set_context = gimp_container_tree_view_set_context;
iface->insert_item = gimp_container_tree_view_insert_item;
iface->remove_item = gimp_container_tree_view_remove_item;
iface->reorder_item = gimp_container_tree_view_reorder_item;
......@@ -156,17 +151,6 @@ gimp_container_tree_view_view_iface_init (GimpContainerViewInterface *iface)
iface->insert_data_free = (GDestroyNotify) g_free;
}
static void
gimp_container_tree_view_docked_iface_init (GimpDockedInterface *iface)
{
parent_docked_iface = g_type_interface_peek_parent (iface);
if (! parent_docked_iface)
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
iface->set_context = gimp_container_tree_view_set_context;
}
static void
gimp_container_tree_view_init (GimpContainerTreeView *tree_view)
{
......@@ -494,6 +478,35 @@ gimp_container_tree_view_set_container (GimpContainerView *view,
parent_view_iface->set_container (view, container);
}
static void
gimp_container_tree_view_set_context (GimpContainerView *view,
GimpContext *context)
{
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
parent_view_iface->set_context (view, context);
if (tree_view->model)
{
GtkTreeIter iter;
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (tree_view->model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (tree_view->model, &iter))
{
GimpViewRenderer *renderer;
gtk_tree_model_get (tree_view->model, &iter,
COLUMN_RENDERER, &renderer,
-1);
gimp_view_renderer_set_context (renderer, context);
g_object_unref (renderer);
}
}
}
static gpointer
gimp_container_tree_view_insert_item (GimpContainerView *view,
GimpViewable *viewable,
......@@ -760,38 +773,6 @@ gimp_container_tree_view_set_view_size (GimpContainerView *view)
}
/* GimpDocked methods */
static void
gimp_container_tree_view_set_context (GimpDocked *docked,
GimpContext *context)
{
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (docked);
parent_docked_iface->set_context (docked, context);
if (tree_view->model)
{
GtkTreeIter iter;
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (tree_view->model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (tree_view->model, &iter))
{
GimpViewRenderer *renderer;
gtk_tree_model_get (tree_view->model, &iter,
COLUMN_RENDERER, &renderer,
-1);
gimp_view_renderer_set_context (renderer, context);
g_object_unref (renderer);
}
}
}
/* callbacks */
static void
......
......@@ -388,6 +388,13 @@ gimp_container_view_real_set_container (GimpContainerView *view,
view);
if (private->context)
{
GType children_type = private->container->children_type;
const gchar *signal_name;
signal_name = gimp_context_type_to_signal_name (children_type);
if (signal_name)
{
g_signal_handlers_disconnect_by_func (private->context,
gimp_container_view_context_changed,
......@@ -397,7 +404,8 @@ gimp_container_view_real_set_container (GimpContainerView *view,
{
gtk_drag_dest_unset (private->dnd_widget);
gimp_dnd_viewable_dest_remove (private->dnd_widget,
private->container->children_type);
children_type);
}
}
}
}
......@@ -406,9 +414,10 @@ gimp_container_view_real_set_container (GimpContainerView *view,
if (private->container)
{
GType children_type = private->container->children_type;
GimpViewableClass *viewable_class;
viewable_class = g_type_class_ref (container->children_type);
viewable_class = g_type_class_ref (children_type);
gimp_container_foreach (private->container,
(GFunc) gimp_container_view_add_foreach,
......@@ -445,11 +454,13 @@ gimp_container_view_real_set_container (GimpContainerView *view,
if (private->context)
{
GimpObject *object;
const gchar *signal_name;
signal_name =
gimp_context_type_to_signal_name (private->container->children_type);
signal_name = gimp_context_type_to_signal_name (children_type);
if (signal_name)
{
GimpObject *object;
g_signal_connect_object (private->context, signal_name,
G_CALLBACK (gimp_container_view_context_changed),
......@@ -457,17 +468,18 @@ gimp_container_view_real_set_container (GimpContainerView *view,
0);
object = gimp_context_get_by_type (private->context,
private->container->children_type);
children_type);
gimp_container_view_select_item (view, GIMP_VIEWABLE (object));
if (private->dnd_widget)
gimp_dnd_viewable_dest_add (private->dnd_widget,
private->container->children_type,
children_type,
gimp_container_view_viewable_dropped,
view);
}
}
}
}
GimpContext *
......@@ -510,6 +522,13 @@ gimp_container_view_real_set_context (GimpContainerView *view,
if (private->context)
{
if (private->container)
{
GType children_type = private->container->children_type;
const gchar *signal_name;
signal_name = gimp_context_type_to_signal_name (children_type);
if (signal_name)
{
g_signal_handlers_disconnect_by_func (private->context,
gimp_container_view_context_changed,
......@@ -519,7 +538,8 @@ gimp_container_view_real_set_context (GimpContainerView *view,
{
gtk_drag_dest_unset (private->dnd_widget);
gimp_dnd_viewable_dest_remove (private->dnd_widget,
private->container->children_type);
children_type);
}
}
}
......@@ -534,11 +554,14 @@ gimp_container_view_real_set_context (GimpContainerView *view,
if (private->container)
{
GimpObject *object;
GType children_type = private->container->children_type;
const gchar *signal_name;
signal_name =
gimp_context_type_to_signal_name (private->container->children_type);
signal_name = gimp_context_type_to_signal_name (children_type);
if (signal_name)
{
GimpObject *object;
g_signal_connect_object (private->context, signal_name,
G_CALLBACK (gimp_container_view_context_changed),
......@@ -546,17 +569,18 @@ gimp_container_view_real_set_context (GimpContainerView *view,
0);
object = gimp_context_get_by_type (private->context,
private->container->children_type);
children_type);
gimp_container_view_select_item (view, GIMP_VIEWABLE (object));
if (private->dnd_widget)
gimp_dnd_viewable_dest_add (private->dnd_widget,
private->container->children_type,
children_type,
gimp_container_view_viewable_dropped,
view);
}
}
}
}
gint
......@@ -773,12 +797,18 @@ gimp_container_view_item_selected (GimpContainerView *view,
/* HACK */
if (private->container && private->context)
{
gimp_context_set_by_type (private->context,
private->container->children_type,
GIMP_OBJECT (viewable));
GType children_type = private->container->children_type;
const gchar *signal_name;
signal_name = gimp_context_type_to_signal_name (children_type);
if (signal_name)
{
gimp_context_set_by_type (private->context, children_type,
GIMP_OBJECT (viewable));
return TRUE;
}
}
success = gimp_container_view_select_item (view, viewable);
......@@ -1047,14 +1077,21 @@ gimp_container_view_thaw (GimpContainerView *view,
view);
if (private->context)
{
GType children_type = private->container->children_type;
const gchar *signal_name;
signal_name = gimp_context_type_to_signal_name (children_type);
if (signal_name)
{
GimpObject *object;
object = gimp_context_get_by_type (private->context,
private->container->children_type);
object = gimp_context_get_by_type (private->context, children_type);
gimp_container_view_select_item (view, GIMP_VIEWABLE (object));
}
}
}
static void
......
......@@ -332,6 +332,9 @@ gimp_controller_list_constructor (GType type,
gimp_container_view_set_container (GIMP_CONTAINER_VIEW (list->dest),
gimp_controllers_get_list (list->gimp));
gimp_container_view_set_context (GIMP_CONTAINER_VIEW (list->dest),
gimp_get_user_context (list->gimp));
return object;
}
......
......@@ -342,7 +342,7 @@ gimp_drawable_tree_view_new_dropped (GimpItemTreeView *view,