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

added a read-only property for the display's image, so it can be retreived

2002-05-10  Michael Natterer  <mitch@gimp.org>

	* app/display/gimpdisplay.c: added a read-only property for the
	display's image, so it can be retreived by the core, which
	treats displays as simple GimpObjects.

	* app/core/gimpcontext.c: made context->display an object
	property, not just gpointer. Connect to the "remove" signal of
	gimp->displays to get notified of disappearing displays. Removed
	the EEKWrapper and get the display's gimage with g_object_get().

	* app/widgets/gimpimagedock.[ch]: added image_dock->display_container
	and require it being passed in the constructor. Do voodoo things
	in the "image_changed" and "display_changed" callbacks to ensure
	that the dock doesn't end up with no display even if the active
	image has one. Added a style property for the image menu's preview
	size.

	* app/gui/dialogs-commands.c (dialogs_menu_update): set the
	"View as List" and "View as Grid" items insensitive if the
	other view type doesn't exist. Hide them if the view cannot
	be classified as "list" or "grid" at all. Also hide the
	"Preview Size" submenu if it's pointless for the view.

	* app/gui/dialogs-constructors.c: added a special tab for the
	navigation dialog. Will propbaby add dockable->stock_id to
	generalize this kind of tab. Pass gimp->displays to
	gimp_image_dock_new().

	* app/gui/menus.c: reordered the "<Dialogs>" factory entries,
	added more stock icons, cleanup.

	* etc/gtkrc_user
	* themes/Default/gtkrc: document usage of GimpImageDock's
	"menu_preview_height" property.
parent f4ce6a9e
2002-05-10 Michael Natterer <mitch@gimp.org>
* app/display/gimpdisplay.c: added a read-only property for the
display's image, so it can be retreived by the core, which
treats displays as simple GimpObjects.
* app/core/gimpcontext.c: made context->display an object
property, not just gpointer. Connect to the "remove" signal of
gimp->displays to get notified of disappearing displays. Removed
the EEKWrapper and get the display's gimage with g_object_get().
* app/widgets/gimpimagedock.[ch]: added image_dock->display_container
and require it being passed in the constructor. Do voodoo things
in the "image_changed" and "display_changed" callbacks to ensure
that the dock doesn't end up with no display even if the active
image has one. Added a style property for the image menu's preview
size.
* app/gui/dialogs-commands.c (dialogs_menu_update): set the
"View as List" and "View as Grid" items insensitive if the
other view type doesn't exist. Hide them if the view cannot
be classified as "list" or "grid" at all. Also hide the
"Preview Size" submenu if it's pointless for the view.
* app/gui/dialogs-constructors.c: added a special tab for the
navigation dialog. Will propbaby add dockable->stock_id to
generalize this kind of tab. Pass gimp->displays to
gimp_image_dock_new().
* app/gui/menus.c: reordered the "<Dialogs>" factory entries,
added more stock icons, cleanup.
* etc/gtkrc_user
* themes/Default/gtkrc: document usage of GimpImageDock's
"menu_preview_height" property.
2002-05-10 Michael Natterer <mitch@gimp.org>
 
* app/display/gimpnavigationview.c: pack the preview's alignment
......
......@@ -169,7 +169,7 @@ dialogs_toggle_view_cmd_callback (GtkWidget *widget,
if (entry)
{
gchar *identifier;
gchar *substring;
gchar *substring = NULL;
identifier = g_strdup (entry->identifier);
......@@ -184,7 +184,7 @@ dialogs_toggle_view_cmd_callback (GtkWidget *widget,
memcpy (substring, "grid", 4);
}
if (strcmp (entry->identifier, identifier))
if (substring)
{
GimpContainerView *old_view;
GtkWidget *new_dockable;
......@@ -417,8 +417,9 @@ dialogs_menu_update (GtkItemFactory *factory,
gint page_num;
GimpDialogFactoryEntry *entry;
GimpContainerView *view;
gboolean is_grid = FALSE;
GimpPreviewSize preview_size = GIMP_PREVIEW_SIZE_NONE;
GimpViewType view_type = -1;
gboolean other_view_type = FALSE;
GimpPreviewSize preview_size = GIMP_PREVIEW_SIZE_NONE;
page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
......@@ -430,66 +431,100 @@ dialogs_menu_update (GtkItemFactory *factory,
if (entry)
{
if (strstr (entry->identifier, "grid"))
is_grid = TRUE;
gchar *identifier;
gchar *substring = NULL;
identifier = g_strdup (entry->identifier);
if ((substring = strstr (identifier, "grid")))
view_type = GIMP_VIEW_TYPE_GRID;
else if ((substring = strstr (identifier, "list")))
view_type = GIMP_VIEW_TYPE_LIST;
if (substring)
{
if (view_type == GIMP_VIEW_TYPE_GRID)
memcpy (substring, "list", 4);
else if (view_type == GIMP_VIEW_TYPE_LIST)
memcpy (substring, "grid", 4);
if (gimp_dialog_factory_find_entry (dockbook->dock->dialog_factory,
identifier))
other_view_type = TRUE;
}
g_free (identifier);
}
view = gimp_container_view_get_by_dockable (dockable);
if (view)
{
preview_size = view->preview_size;
}
preview_size = view->preview_size;
#define SET_ACTIVE(path,active) \
gimp_item_factory_set_active (factory, (path), (active))
#define SET_VISIBLE(path,active) \
gimp_item_factory_set_visible (factory, (path), (active))
#define SET_SENSITIVE(path,sensitive) \
gimp_item_factory_set_sensitive (factory, (path), (sensitive))
if (preview_size >= GIMP_PREVIEW_SIZE_GIGANTIC)
{
SET_ACTIVE ("/Preview Size/Gigantic", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_ENORMOUS)
{
SET_ACTIVE ("/Preview Size/Enormous", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_HUGE)
{
SET_ACTIVE ("/Preview Size/Huge", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_EXTRA_LARGE)
{
SET_ACTIVE ("/Preview Size/Extra Large", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_LARGE)
{
SET_ACTIVE ("/Preview Size/Large", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_MEDIUM)
{
SET_ACTIVE ("/Preview Size/Medium", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_SMALL)
{
SET_ACTIVE ("/Preview Size/Small", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_EXTRA_SMALL)
{
SET_ACTIVE ("/Preview Size/Extra Small", TRUE);
}
else
{
SET_ACTIVE ("/Preview Size/Tiny", TRUE);
}
SET_VISIBLE ("/view-type-separator",
preview_size != GIMP_PREVIEW_SIZE_NONE || view_type != -1);
if (is_grid)
SET_VISIBLE ("/Preview Size", preview_size != GIMP_PREVIEW_SIZE_NONE);
if (preview_size != GIMP_PREVIEW_SIZE_NONE)
{
SET_ACTIVE ("/View as Grid", TRUE);
if (preview_size >= GIMP_PREVIEW_SIZE_GIGANTIC)
{
SET_ACTIVE ("/Preview Size/Gigantic", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_ENORMOUS)
{
SET_ACTIVE ("/Preview Size/Enormous", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_HUGE)
{
SET_ACTIVE ("/Preview Size/Huge", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_EXTRA_LARGE)
{
SET_ACTIVE ("/Preview Size/Extra Large", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_LARGE)
{
SET_ACTIVE ("/Preview Size/Large", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_MEDIUM)
{
SET_ACTIVE ("/Preview Size/Medium", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_SMALL)
{
SET_ACTIVE ("/Preview Size/Small", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_EXTRA_SMALL)
{
SET_ACTIVE ("/Preview Size/Extra Small", TRUE);
}
else if (preview_size >= GIMP_PREVIEW_SIZE_TINY)
{
SET_ACTIVE ("/Preview Size/Tiny", TRUE);
}
}
else
SET_VISIBLE ("/View as Grid", view_type != -1);
SET_VISIBLE ("/View as List", view_type != -1);
if (view_type != -1)
{
SET_ACTIVE ("/View as List", TRUE);
if (view_type == GIMP_VIEW_TYPE_LIST)
SET_ACTIVE ("/View as List", TRUE);
else
SET_ACTIVE ("/View as Grid", TRUE);
SET_SENSITIVE ("/View as Grid", other_view_type);
SET_SENSITIVE ("/View as List", other_view_type);
}
if (GIMP_IS_IMAGE_DOCK (dockbook->dock))
......@@ -512,5 +547,6 @@ dialogs_menu_update (GtkItemFactory *factory,
#undef SET_ACTIVE
#undef SET_VISIBLE
#undef SET_SENSITIVE
}
}
......@@ -88,6 +88,9 @@ static void gimp_context_copy_image (GimpContext *src,
GimpContext *dest);
/* display */
static void gimp_context_display_removed (GimpContainer *container,
gpointer display,
GimpContext *context);
static void gimp_context_real_set_display (GimpContext *context,
gpointer display);
static void gimp_context_copy_display (GimpContext *src,
......@@ -395,9 +398,9 @@ gimp_context_class_init (GimpContextClass *klass)
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpContextClass, display_changed),
NULL, NULL,
gimp_marshal_VOID__POINTER,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
GIMP_TYPE_OBJECT);
gimp_context_signals[TOOL_CHANGED] =
g_signal_new (gimp_context_signal_names[TOOL_CHANGED],
......@@ -556,9 +559,10 @@ gimp_context_class_init (GimpContextClass *klass)
g_object_class_install_property (object_class,
PROP_DISPLAY,
g_param_spec_pointer (gimp_context_prop_names[DISPLAY_CHANGED],
NULL, NULL,
G_PARAM_READWRITE));
g_param_spec_object (gimp_context_prop_names[DISPLAY_CHANGED],
NULL, NULL,
GIMP_TYPE_OBJECT,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_TOOL,
......@@ -799,7 +803,7 @@ gimp_context_set_property (GObject *object,
gimp_context_set_image (context, g_value_get_object (value));
break;
case PROP_DISPLAY:
gimp_context_set_display (context, g_value_get_pointer (value));
gimp_context_set_display (context, g_value_get_object (value));
break;
case PROP_TOOL:
gimp_context_set_tool (context, g_value_get_object (value));
......@@ -859,7 +863,7 @@ gimp_context_get_property (GObject *object,
g_value_set_object (value, gimp_context_get_image (context));
break;
case PROP_DISPLAY:
g_value_set_pointer (value, gimp_context_get_display (context));
g_value_set_object (value, gimp_context_get_display (context));
break;
case PROP_TOOL:
g_value_set_object (value, gimp_context_get_tool (context));
......@@ -947,6 +951,10 @@ gimp_context_new (Gimp *gimp,
G_CALLBACK (gimp_context_image_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->displays), "remove",
G_CALLBACK (gimp_context_display_removed),
G_OBJECT (context),
0);
g_signal_connect_object (G_OBJECT (gimp->tool_info_list), "remove",
G_CALLBACK (gimp_context_tool_removed),
......@@ -1367,61 +1375,34 @@ gimp_context_display_changed (GimpContext *context)
context->display);
}
/* handle dissapearing displays */
/* handle disappearing displays */
static void
gimp_context_display_destroy (GObject *disp_shell,
GimpContext *context)
gimp_context_display_removed (GimpContainer *container,
gpointer display,
GimpContext *context)
{
context->display = NULL;
gimp_context_real_set_image (context, NULL);
gimp_context_display_changed (context);
if (context->display == display)
gimp_context_real_set_display (context, NULL);
}
static void
gimp_context_real_set_display (GimpContext *context,
gpointer display)
{
#ifdef __GNUC__
#warning FIXME: EEKWrapper
#endif
typedef struct
{
GimpObject foo;
gint bar;
GimpImage *gimage;
gint baz;
GObject *shell;
} EEKWrapper;
EEKWrapper *eek_wrapper;
if (context->display == display)
return;
if (context->display)
{
eek_wrapper = (EEKWrapper *) context->display;
if (G_IS_OBJECT (eek_wrapper->shell))
g_signal_handlers_disconnect_by_func (eek_wrapper->shell,
gimp_context_display_destroy,
context);
}
context->display = display;
if (context->display)
{
eek_wrapper = (EEKWrapper *) context->display;
GimpImage *gimage;
g_signal_connect_object (G_OBJECT (eek_wrapper->shell), "destroy",
G_CALLBACK (gimp_context_display_destroy),
G_OBJECT (context),
0);
g_object_get (display, "image", &gimage, NULL);
gimp_context_real_set_image (context, gimage);
gimp_context_real_set_image (context, eek_wrapper->gimage);
g_object_unref (G_OBJECT (gimage));
}
gimp_context_display_changed (context);
......
......@@ -47,12 +47,27 @@
#include "libgimp/gimpintl.h"
enum
{
PROP_0,
PROP_IMAGE
};
/* local function prototypes */
static void gimp_display_class_init (GimpDisplayClass *klass);
static void gimp_display_init (GimpDisplay *gdisp);
static void gimp_display_finalize (GObject *object);
static void gimp_display_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_display_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_display_flush_whenever (GimpDisplay *gdisp,
gboolean now);
......@@ -106,7 +121,15 @@ gimp_display_class_init (GimpDisplayClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_display_finalize;
object_class->finalize = gimp_display_finalize;
object_class->set_property = gimp_display_set_property;
object_class->get_property = gimp_display_get_property;
g_object_class_install_property (object_class, PROP_IMAGE,
g_param_spec_object ("image",
NULL, NULL,
GIMP_TYPE_IMAGE,
G_PARAM_READABLE));
}
static void
......@@ -135,13 +158,53 @@ gimp_display_finalize (GObject *object)
{
GimpDisplay *gdisp;
g_return_if_fail (GIMP_IS_DISPLAY (object));
gdisp = GIMP_DISPLAY (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_display_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpDisplay *gdisp;
gdisp = GIMP_DISPLAY (object);
switch (property_id)
{
case PROP_IMAGE:
g_assert_not_reached ();
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_display_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpDisplay *gdisp;
gdisp = GIMP_DISPLAY (object);
switch (property_id)
{
case PROP_IMAGE:
g_value_set_object (value, gdisp->gimage);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
GimpDisplay *
gimp_display_new (GimpImage *gimage,
guint scale)
......
......@@ -117,6 +117,9 @@ static GtkWidget * dialogs_tool_tab_func (GimpDockable *dockable,
static GtkWidget * dialogs_tool_options_tab_func (GimpDockable *dockable,
GimpDockbook *dockbook,
gint size);
static GtkWidget * dialogs_navigation_tab_func (GimpDockable *dockable,
GimpDockbook *dockbook,
gint size);
static void dialogs_set_view_context_func (GimpDockable *dockable,
GimpContext *context);
......@@ -266,7 +269,9 @@ dialogs_dock_new (GimpDialogFactory *factory,
GimpContext *context,
gint preview_size)
{
return gimp_image_dock_new (factory, context->gimp->images);
return gimp_image_dock_new (factory,
context->gimp->images,
context->gimp->displays);
}
......@@ -929,7 +934,7 @@ dialogs_navigation_view_new (GimpDialogFactory *factory,
return dialogs_dockable_new (view,
_("Display Navigation"), _("Navigation"),
NULL,
dialogs_navigation_tab_func,
dialogs_set_navigation_context_func);
}
......@@ -1146,6 +1151,62 @@ dialogs_tool_options_tab_func (GimpDockable *dockable,
return hbox;
}
static GtkIconSize
gimp_preview_size_to_gtk_icon_size (GimpPreviewSize preview_size)
{
GtkIconSize gtk_size;
gint width, height;
GtkIconSize best_match;
gint diff;
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
best_match = GTK_ICON_SIZE_MENU;
diff = abs (preview_size - height);
for (gtk_size = GTK_ICON_SIZE_MENU + 1;
gtk_size <= GTK_ICON_SIZE_DIALOG;
gtk_size++)
{
if (gtk_icon_size_lookup (gtk_size, &width, &height))
{
if (abs (preview_size - height) < diff)
{
best_match = gtk_size;
diff = abs (preview_size - height);
}
}
}
return best_match;
}
static GtkWidget *
dialogs_navigation_tab_func (GimpDockable *dockable,
GimpDockbook *dockbook,
gint size)
{
GimpContext *context;
GtkWidget *hbox;
GtkWidget *image;
GtkWidget *label;
context = dockbook->dock->context;
hbox = gtk_hbox_new (FALSE, 2);
image = gtk_image_new_from_stock (GIMP_STOCK_TOOL_MOVE,
gimp_preview_size_to_gtk_icon_size (size));
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
label = gtk_label_new (dockable->short_name);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
return hbox;
}
static void
dialogs_set_view_context_func (GimpDockable *dockable,
GimpContext *context)
......
......@@ -47,12 +47,27 @@
#include "libgimp/gimpintl.h"
enum
{
PROP_0,
PROP_IMAGE
};
/* local function prototypes */
static void gimp_display_class_init (GimpDisplayClass *klass);
static void gimp_display_init (GimpDisplay *gdisp);
static void gimp_display_finalize (GObject *object);
static void gimp_display_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_display_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_display_flush_whenever (GimpDisplay *gdisp,
gboolean now);
......@@ -106,7 +121,15 @@ gimp_display_class_init (GimpDisplayClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_display_finalize;
object_class->finalize = gimp_display_finalize;
object_class->set_property = gimp_display_set_property;
object_class->get_property = gimp_display_get_property;
g_object_class_install_property (object_class, PROP_IMAGE,
g_param_spec_object ("image",
NULL, NULL,
GIMP_TYPE_IMAGE,
G_PARAM_READABLE));
}
static void
......@@ -135,13 +158,53 @@ gimp_display_finalize (GObject *object)
{
GimpDisplay *gdisp;
g_return_if_fail (GIMP_IS_DISPLAY (object));
gdisp = GIMP_DISPLAY (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_display_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpDisplay *gdisp;
gdisp = GIMP_DISPLAY (object);
switch (property_id)
{
case PROP_IMAGE:
g_assert_not_reached ();
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}