Files
gimp/app/widgets/gimpviewabledialog.c
Michael Natterer b53aa45a76 Changed GimpViewable preview rendering to have a context to get
2006-08-29  Michael Natterer  <mitch@gimp.org>

	Changed GimpViewable preview rendering to have a context to get
	FG/BG/whatever from. Use the context to enable dynamic FG/BG
	colors in gradients. Fixes bug #127676 and bug #352214. Addresses
	bug #128367 (doesn't fix it because there's no loading/saving and
	no GUI yet).

	* app/core/core-enums.[ch]: added enum GimpGradientColor to enable
	specifying gradient colors in terms of foreground and background.

	* app/core/gimpgradient.[ch]: added color_type members to the
	GimpGradientSegment struct and honor them in
	gimp_gradient_get_color_at(). Added GimpContext parameters to all
	functions which finally call get_color_at().

	* app/core/gimp-gradients.c: use the new method to implement the
	builtin gradients.

	* app/core/gimpviewable.[ch]: added GimpContext parameters to all
	get_preview() and get_pixbuf() functions.

	* app/core/gimpbrush.c
	* app/core/gimpbuffer.c
	* app/core/gimpdrawable-preview.[ch]
	* app/core/gimpgradient.c
	* app/core/gimpimage-preview.[ch]
	* app/core/gimpimagefile.c
	* app/core/gimppalette.c
	* app/core/gimppattern.c
	* app/core/gimpundo.[ch]
	* app/text/gimpfont.c
	* app/vectors/gimpvectors-preview.[ch]: changed ::get_preview()
	and ::get_pixbuf() implementations accordingly.

	* app/core/gimpdrawable-blend.c
	* app/core/gimppalette-import.[ch]
	* app/dialogs/dialogs-constructors.c
	* app/dialogs/palette-import-dialog.c
	* app/dialogs/resize-dialog.c
	* app/display/gimpdisplayshell-layer-select.c
	* app/display/gimpdisplayshell.c
	* app/display/gimpnavigationeditor.c
	* app/paint/gimppaintoptions.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimptexttool.c
	* app/actions/gradient-editor-commands.c
	* app/widgets/gimpaction.c
	* app/widgets/gimpbrusheditor.[ch]
	* app/widgets/gimpbufferview.c
	* app/widgets/gimpcellrendererviewable.c
	* app/widgets/gimpchanneltreeview.c
	* app/widgets/gimpclipboard.c
	* app/widgets/gimpcoloreditor.c
	* app/widgets/gimpcomponenteditor.c
	* app/widgets/gimpcontainerbox.c
	* app/widgets/gimpcontainercombobox.c
	* app/widgets/gimpcontainereditor.c
	* app/widgets/gimpcontainerentry.c
	* app/widgets/gimpcontainergridview.c
	* app/widgets/gimpcontainertreeview.[ch]
	* app/widgets/gimpdataeditor.[ch]
	* app/widgets/gimpdevicestatus.c
	* app/widgets/gimpdnd.[ch]
	* app/widgets/gimpdrawabletreeview.c
	* app/widgets/gimpfiledialog.c
	* app/widgets/gimpgradienteditor.[ch]
	* app/widgets/gimpgradientselect.c
	* app/widgets/gimpitemtreeview.c
	* app/widgets/gimplayertreeview.c
	* app/widgets/gimppaletteeditor.[ch]
	* app/widgets/gimppropwidgets.[ch]
	* app/widgets/gimpselectioneditor.c
	* app/widgets/gimpthumbbox.[ch]
	* app/widgets/gimptoolbox-image-area.c
	* app/widgets/gimptoolbox-indicator-area.c
	* app/widgets/gimptooloptionseditor.c
	* app/widgets/gimpundoeditor.c
	* app/widgets/gimpvectorstreeview.c
	* app/widgets/gimpview-popup.[ch]
	* app/widgets/gimpview.[ch]
	* app/widgets/gimpviewablebutton.c
	* app/widgets/gimpviewabledialog.c
	* app/widgets/gimpviewrenderer.[ch]
	* app/widgets/gimpviewrenderer-frame.c
	* app/widgets/gimpviewrendererbrush.c
	* app/widgets/gimpviewrendererbuffer.c
	* app/widgets/gimpviewrendererdrawable.c
	* app/widgets/gimpviewrenderergradient.c
	* app/widgets/gimpviewrendererimage.c
	* tools/pdbgen/pdb/drawable.pdb
	* tools/pdbgen/pdb/gradient.pdb
	* tools/pdbgen/pdb/gradients.pdb
	* tools/pdbgen/pdb/image.pdb: added tons of GimpContext members
	and parameters, implement GimpDocked::set_context() in many
	widgets. Pass these locally remembered contexts to GimpViewable
	functions. Did some minor cleanups on the way. There are still
	some minor FIXMEs around where the code uses a NULL context (which
	is allowed by the APIs)

	* app/pdb/drawable_cmds.c
	* app/pdb/gradient_cmds.c
	* app/pdb/gradients_cmds.c
	* app/pdb/image_cmds.c: regenerated.
2006-08-29 21:44:51 +00:00

368 lines
13 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpviewabledialog.c
* Copyright (C) 2000 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 "widgets-types.h"
#include "core/gimpimage.h"
#include "core/gimpitem.h"
#include "file/file-utils.h"
#include "gimpview.h"
#include "gimpviewabledialog.h"
enum
{
PROP_0,
PROP_VIEWABLE,
PROP_STOCK_ID,
PROP_DESC,
PROP_PARENT
};
static void gimp_viewable_dialog_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_viewable_dialog_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_viewable_dialog_destroy (GtkObject *object);
static void gimp_viewable_dialog_name_changed (GimpObject *object,
GimpViewableDialog *dialog);
static void gimp_viewable_dialog_close (GimpViewableDialog *dialog);
G_DEFINE_TYPE (GimpViewableDialog, gimp_viewable_dialog, GIMP_TYPE_DIALOG)
#define parent_class gimp_viewable_dialog_parent_class
static void
gimp_viewable_dialog_class_init (GimpViewableDialogClass *klass)
{
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
gtk_object_class->destroy = gimp_viewable_dialog_destroy;
object_class->get_property = gimp_viewable_dialog_get_property;
object_class->set_property = gimp_viewable_dialog_set_property;
g_object_class_install_property (object_class, PROP_VIEWABLE,
g_param_spec_object ("viewable", NULL, NULL,
GIMP_TYPE_VIEWABLE,
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_STOCK_ID,
g_param_spec_string ("stock-id", NULL, NULL,
NULL,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_DESC,
g_param_spec_string ("description", NULL, NULL,
NULL,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_PARENT,
g_param_spec_object ("parent", NULL, NULL,
GTK_TYPE_WIDGET,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_viewable_dialog_init (GimpViewableDialog *dialog)
{
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *vbox;
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
FALSE, FALSE, 0);
gtk_widget_show (frame);
hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
gtk_container_add (GTK_CONTAINER (frame), hbox);
gtk_widget_show (hbox);
dialog->icon = gtk_image_new ();
gtk_misc_set_alignment (GTK_MISC (dialog->icon), 0.5, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), dialog->icon, FALSE, FALSE, 0);
gtk_widget_show (dialog->icon);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (hbox), vbox);
gtk_widget_show (vbox);
dialog->desc_label = gtk_label_new (NULL);
gtk_misc_set_alignment (GTK_MISC (dialog->desc_label), 0.0, 0.5);
gimp_label_set_attributes (GTK_LABEL (dialog->desc_label),
PANGO_ATTR_SCALE, PANGO_SCALE_LARGE,
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
-1);
gtk_box_pack_start (GTK_BOX (vbox), dialog->desc_label, FALSE, FALSE, 0);
gtk_widget_show (dialog->desc_label);
dialog->viewable_label = g_object_new (GTK_TYPE_LABEL,
"xalign", 0.0,
"yalign", 0.5,
"ellipsize", PANGO_ELLIPSIZE_END,
NULL);
gimp_label_set_attributes (GTK_LABEL (dialog->viewable_label),
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
-1);
gtk_box_pack_start (GTK_BOX (vbox), dialog->viewable_label, FALSE, FALSE, 0);
gtk_widget_show (dialog->viewable_label);
}
static void
gimp_viewable_dialog_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpViewableDialog *dialog = GIMP_VIEWABLE_DIALOG (object);
switch (property_id)
{
case PROP_VIEWABLE:
gimp_viewable_dialog_set_viewable (dialog, g_value_get_object (value));
break;
case PROP_STOCK_ID:
gtk_image_set_from_stock (GTK_IMAGE (dialog->icon),
g_value_get_string (value),
GTK_ICON_SIZE_LARGE_TOOLBAR);
break;
case PROP_DESC:
gtk_label_set_text (GTK_LABEL (dialog->desc_label),
g_value_get_string (value));
break;
case PROP_PARENT:
{
GtkWidget *parent = g_value_get_object (value);
if (parent)
{
if (GTK_IS_WINDOW (parent))
gtk_window_set_transient_for (GTK_WINDOW (dialog),
GTK_WINDOW (parent));
else
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_widget_get_screen (parent));
}
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_viewable_dialog_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpViewableDialog *dialog = GIMP_VIEWABLE_DIALOG (object);
switch (property_id)
{
case PROP_VIEWABLE:
g_value_set_object (value,
dialog->view ?
GIMP_VIEW (dialog->view)->viewable : NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_viewable_dialog_destroy (GtkObject *object)
{
GimpViewableDialog *dialog = GIMP_VIEWABLE_DIALOG (object);
if (dialog->view)
gimp_viewable_dialog_set_viewable (dialog, NULL);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
GtkWidget *
gimp_viewable_dialog_new (GimpViewable *viewable,
const gchar *title,
const gchar *role,
const gchar *stock_id,
const gchar *desc,
GtkWidget *parent,
GimpHelpFunc help_func,
const gchar *help_id,
...)
{
GimpViewableDialog *dialog;
va_list args;
g_return_val_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (title != NULL, NULL);
g_return_val_if_fail (role != NULL, NULL);
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
if (! viewable)
g_warning ("Use of GimpViewableDialog with a NULL viewable is depecrated!");
dialog = g_object_new (GIMP_TYPE_VIEWABLE_DIALOG,
"viewable", viewable,
"title", title,
"role", role,
"help-func", help_func,
"help-id", help_id,
"stock-id", stock_id,
"description", desc,
"parent", parent,
NULL);
va_start (args, help_id);
gimp_dialog_add_buttons_valist (GIMP_DIALOG (dialog), args);
va_end (args);
return GTK_WIDGET (dialog);
}
void
gimp_viewable_dialog_set_viewable (GimpViewableDialog *dialog,
GimpViewable *viewable)
{
g_return_if_fail (GIMP_IS_VIEWABLE_DIALOG (dialog));
g_return_if_fail (viewable == NULL || GIMP_IS_VIEWABLE (viewable));
if (dialog->view)
{
GimpViewable *old_viewable = GIMP_VIEW (dialog->view)->viewable;
if (viewable == old_viewable)
return;
gtk_widget_destroy (dialog->view);
if (old_viewable)
{
g_signal_handlers_disconnect_by_func (old_viewable,
gimp_viewable_dialog_name_changed,
dialog);
g_signal_handlers_disconnect_by_func (old_viewable,
gimp_viewable_dialog_close,
dialog);
}
}
if (viewable)
{
g_signal_connect_object (viewable,
GIMP_VIEWABLE_GET_CLASS (viewable)->name_changed_signal,
G_CALLBACK (gimp_viewable_dialog_name_changed),
dialog,
0);
dialog->view = gimp_view_new (NULL, /* FIXME */
viewable, 32, 1, TRUE);
gtk_box_pack_end (GTK_BOX (dialog->icon->parent), dialog->view,
FALSE, FALSE, 2);
gtk_widget_show (dialog->view);
g_object_add_weak_pointer (G_OBJECT (dialog->view),
(gpointer) &dialog->view);
gimp_viewable_dialog_name_changed (GIMP_OBJECT (viewable), dialog);
if (GIMP_IS_ITEM (viewable))
{
g_signal_connect_object (viewable, "removed",
G_CALLBACK (gimp_viewable_dialog_close),
dialog,
G_CONNECT_SWAPPED);
}
else
{
g_signal_connect_object (viewable, "disconnect",
G_CALLBACK (gimp_viewable_dialog_close),
dialog,
G_CONNECT_SWAPPED);
}
}
}
/* private functions */
static void
gimp_viewable_dialog_name_changed (GimpObject *object,
GimpViewableDialog *dialog)
{
gchar *name;
name = gimp_viewable_get_description (GIMP_VIEWABLE (object), NULL);
if (GIMP_IS_ITEM (object))
{
const gchar *uri;
gchar *basename;
gchar *tmp;
uri = gimp_image_get_uri (gimp_item_get_image (GIMP_ITEM (object)));
tmp = name;
basename = file_utils_uri_display_basename (uri);
name = g_strdup_printf ("%s-%d (%s)",
tmp,
gimp_item_get_ID (GIMP_ITEM (object)),
basename);
g_free (basename);
g_free (tmp);
}
gtk_label_set_text (GTK_LABEL (dialog->viewable_label), name);
g_free (name);
}
static void
gimp_viewable_dialog_close (GimpViewableDialog *dialog)
{
g_signal_emit_by_name (dialog, "close");
}