Files
gimp/app/widgets/gimpview-popup.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

233 lines
6.9 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpview-popup.c
* Copyright (C) 2003-2006 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/gimpcontext.h"
#include "core/gimpviewable.h"
#include "gimpview.h"
#include "gimpviewrenderer.h"
#include "gimpview-popup.h"
#define VIEW_POPUP_DELAY 150
typedef struct _GimpViewPopup GimpViewPopup;
struct _GimpViewPopup
{
GtkWidget *widget;
GimpContext *context;
GimpViewable *viewable;
gint popup_width;
gint popup_height;
gboolean dot_for_dot;
gint button;
gint button_x;
gint button_y;
guint timeout_id;
GtkWidget *popup;
};
/* local function prototypes */
static void gimp_view_popup_hide (GimpViewPopup *popup);
static gboolean gimp_view_popup_button_release (GtkWidget *widget,
GdkEventButton *bevent,
GimpViewPopup *popup);
static void gimp_view_popup_unmap (GtkWidget *widget,
GimpViewPopup *popup);
static gboolean gimp_view_popup_timeout (GimpViewPopup *popup);
/* public functions */
gboolean
gimp_view_popup_show (GtkWidget *widget,
GdkEventButton *bevent,
GimpContext *context,
GimpViewable *viewable,
gint view_width,
gint view_height,
gboolean dot_for_dot)
{
GimpViewPopup *popup;
gint popup_width;
gint popup_height;
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
g_return_val_if_fail (bevent != NULL, FALSE);
g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), FALSE);
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), FALSE);
if (! gimp_viewable_get_popup_size (viewable,
view_width,
view_height,
dot_for_dot,
&popup_width,
&popup_height))
return FALSE;
popup = g_new0 (GimpViewPopup, 1);
popup->widget = widget;
popup->context = context;
popup->viewable = viewable;
popup->popup_width = popup_width;
popup->popup_height = popup_height;
popup->dot_for_dot = dot_for_dot;
popup->button = bevent->button;
popup->button_x = bevent->x;
popup->button_y = bevent->y;
if (GTK_WIDGET_NO_WINDOW (widget))
{
popup->button_x += widget->allocation.x;
popup->button_y += widget->allocation.y;
}
g_signal_connect (widget, "button-release-event",
G_CALLBACK (gimp_view_popup_button_release),
popup);
g_signal_connect (widget, "unmap",
G_CALLBACK (gimp_view_popup_unmap),
popup);
popup->timeout_id = g_timeout_add (VIEW_POPUP_DELAY,
(GSourceFunc) gimp_view_popup_timeout,
popup);
g_object_set_data_full (G_OBJECT (widget), "gimp-view-popup", popup,
(GDestroyNotify) gimp_view_popup_hide);
gtk_grab_add (widget);
return TRUE;
}
/* private functions */
static void
gimp_view_popup_hide (GimpViewPopup *popup)
{
if (popup->timeout_id)
g_source_remove (popup->timeout_id);
if (popup->popup)
gtk_widget_destroy (popup->popup);
g_signal_handlers_disconnect_by_func (popup->widget,
gimp_view_popup_button_release,
popup);
g_signal_handlers_disconnect_by_func (popup->widget,
gimp_view_popup_unmap,
popup);
gtk_grab_remove (popup->widget);
g_free (popup);
}
static gboolean
gimp_view_popup_button_release (GtkWidget *widget,
GdkEventButton *bevent,
GimpViewPopup *popup)
{
if (bevent->button == popup->button)
g_object_set_data (G_OBJECT (popup->widget), "gimp-view-popup", NULL);
return FALSE;
}
static void
gimp_view_popup_unmap (GtkWidget *widget,
GimpViewPopup *popup)
{
g_object_set_data (G_OBJECT (popup->widget), "gimp-view-popup", NULL);
}
static gboolean
gimp_view_popup_timeout (GimpViewPopup *popup)
{
GtkWidget *window;
GtkWidget *frame;
GtkWidget *view;
GdkScreen *screen;
GdkRectangle rect;
gint monitor;
gint x;
gint y;
popup->timeout_id = 0;
screen = gtk_widget_get_screen (popup->widget);
window = gtk_window_new (GTK_WINDOW_POPUP);
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
gtk_window_set_screen (GTK_WINDOW (window), screen);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
gtk_container_add (GTK_CONTAINER (window), frame);
gtk_widget_show (frame);
view = gimp_view_new_full (popup->context,
popup->viewable,
popup->popup_width,
popup->popup_height,
0, TRUE, FALSE, FALSE);
gimp_view_renderer_set_dot_for_dot (GIMP_VIEW (view)->renderer,
popup->dot_for_dot);
gtk_container_add (GTK_CONTAINER (frame), view);
gtk_widget_show (view);
gdk_window_get_origin (popup->widget->window, &x, &y);
x += popup->button_x - (popup->popup_width >> 1);
y += popup->button_y - (popup->popup_height >> 1);
monitor = gdk_screen_get_monitor_at_point (screen, x, y);
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
x = CLAMP (x, rect.x, rect.x + rect.width - popup->popup_width);
y = CLAMP (y, rect.y, rect.y + rect.height - popup->popup_height);
gtk_window_move (GTK_WINDOW (window), x, y);
gtk_widget_show (window);
popup->popup = window;
return FALSE;
}