Derive GimpCanvas from GimpOverlayBox

- adapt callbacks to ignore / not block events on offscreen children
- use GimpOverlayBox' scroll API which makes sure overlay children
  don't scroll along
This commit is contained in:
Michael Natterer 2009-10-18 22:19:29 +02:00
parent 3d354c9434
commit 8124792130
4 changed files with 35 additions and 98 deletions

View File

@ -46,27 +46,25 @@ enum
/* local function prototypes */
static void gimp_canvas_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_canvas_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_canvas_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_canvas_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_canvas_realize (GtkWidget *widget);
static void gimp_canvas_unrealize (GtkWidget *widget);
static void gimp_canvas_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gimp_canvas_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gimp_canvas_realize (GtkWidget *widget);
static void gimp_canvas_unrealize (GtkWidget *widget);
static void gimp_canvas_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static GdkGC * gimp_canvas_gc_new (GimpCanvas *canvas,
GimpCanvasStyle style);
G_DEFINE_TYPE (GimpCanvas, gimp_canvas, GTK_TYPE_CONTAINER)
G_DEFINE_TYPE (GimpCanvas, gimp_canvas, GIMP_TYPE_OVERLAY_BOX)
#define parent_class gimp_canvas_parent_class
@ -167,7 +165,6 @@ gimp_canvas_class_init (GimpCanvasClass *klass)
widget_class->realize = gimp_canvas_realize;
widget_class->unrealize = gimp_canvas_unrealize;
widget_class->size_allocate = gimp_canvas_size_allocate;
widget_class->style_set = gimp_canvas_style_set;
g_object_class_install_property (object_class, PROP_CONFIG,
@ -184,6 +181,7 @@ gimp_canvas_init (GimpCanvas *canvas)
gint i;
gtk_widget_set_can_focus (widget, TRUE);
gtk_widget_add_events (widget, GIMP_CANVAS_EVENT_MASK);
gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
for (i = 0; i < GIMP_CANVAS_NUM_STYLES; i++)
@ -195,9 +193,9 @@ gimp_canvas_init (GimpCanvas *canvas)
static void
gimp_canvas_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpCanvas *canvas = GIMP_CANVAS (object);
@ -234,38 +232,9 @@ gimp_canvas_get_property (GObject *object,
static void
gimp_canvas_realize (GtkWidget *widget)
{
GimpCanvas *canvas = GIMP_CANVAS (widget);
GtkAllocation allocation;
GdkWindowAttr attributes;
gint attributes_mask;
GimpCanvas *canvas = GIMP_CANVAS (widget);
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
gtk_widget_get_allocation (widget, &allocation);
attributes.x = allocation.x;
attributes.y = allocation.y;
attributes.width = allocation.width;
attributes.height = allocation.height;
attributes.window_type = GDK_WINDOW_CHILD;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = (gtk_widget_get_events (widget) |
GIMP_CANVAS_EVENT_MASK);
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
gtk_widget_set_window (widget,
gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask));
gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
widget->style = gtk_style_attach (gtk_widget_get_style (widget),
gtk_widget_get_window (widget));
gtk_style_set_background (gtk_widget_get_style (widget),
gtk_widget_get_window (widget),
GTK_STATE_NORMAL);
GTK_WIDGET_CLASS (parent_class)->realize (widget);
canvas->stipple[0] =
gdk_bitmap_create_from_data (gtk_widget_get_window (widget),
@ -305,18 +274,6 @@ gimp_canvas_unrealize (GtkWidget *widget)
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
static void
gimp_canvas_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
gtk_widget_set_allocation (widget, allocation);
if (GTK_WIDGET_REALIZED (widget))
gdk_window_move_resize (gtk_widget_get_window (widget),
allocation->x, allocation->y,
allocation->width, allocation->height);
}
static void
gimp_canvas_style_set (GtkWidget *widget,
GtkStyle *prev_style)
@ -563,34 +520,6 @@ gimp_canvas_new (GimpDisplayConfig *config)
NULL);
}
/**
* gimp_canvas_scroll:
* @canvas: the #GimpCanvas widget to scroll.
* @offset_x: the x scroll amount.
* @offset_y: the y scroll amount.
*
* Scrolls the canvas using gdk_window_scroll() and makes sure the result
* is displayed immediately by calling gdk_window_process_updates().
**/
void
gimp_canvas_scroll (GimpCanvas *canvas,
gint offset_x,
gint offset_y)
{
GtkWidget *widget;
GdkWindow *window;
g_return_if_fail (GIMP_IS_CANVAS (canvas));
widget = GTK_WIDGET (canvas);
window = gtk_widget_get_window (widget);
gdk_window_scroll (window, offset_x, offset_y);
/* Make sure expose events are processed before scrolling again */
gdk_window_process_updates (window, FALSE);
}
/**
* gimp_canvas_draw_cursor:
* @canvas: the #GimpCanvas widget to draw on.

View File

@ -19,6 +19,9 @@
#define __GIMP_CANVAS_H__
#include "widgets/gimpoverlaybox.h"
typedef enum
{
GIMP_CANVAS_STYLE_BLACK,
@ -68,7 +71,7 @@ typedef struct _GimpCanvasClass GimpCanvasClass;
struct _GimpCanvas
{
GtkContainer parent_instance;
GimpOverlayBox parent_instance;
GimpDisplayConfig *config;
@ -79,7 +82,7 @@ struct _GimpCanvas
struct _GimpCanvasClass
{
GtkContainerClass parent_class;
GimpOverlayBoxClass parent_class;
};
@ -87,10 +90,6 @@ GType gimp_canvas_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_canvas_new (GimpDisplayConfig *config);
void gimp_canvas_scroll (GimpCanvas *canvas,
gint offset_x,
gint offset_y);
void gimp_canvas_draw_cursor (GimpCanvas *canvas,
gint x,
gint y);

View File

@ -375,6 +375,10 @@ gimp_display_shell_canvas_expose (GtkWidget *widget,
if (! shell->display || ! gimp_display_get_shell (shell->display))
return TRUE;
/* ignore events on overlays */
if (eevent->window != gtk_widget_get_window (widget))
return FALSE;
if (gimp_display_get_image (shell->display))
{
gimp_display_shell_canvas_expose_image (shell, eevent);
@ -382,7 +386,7 @@ gimp_display_shell_canvas_expose (GtkWidget *widget,
/* Return TRUE here to avoid redrawing the image when it gets the
* keyboard focus.
*/
return TRUE;
return FALSE; /* TRUE; */
}
else
{
@ -615,6 +619,10 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
if (gimp_display_shell_events (canvas, event, shell))
return TRUE;
/* ignore events on overlays */
if (((GdkEventAny *) event)->window != canvas->window)
return FALSE;
display = shell->display;
gimp = gimp_display_get_gimp (display);
image = gimp_display_get_image (display);

View File

@ -122,7 +122,8 @@ gimp_display_shell_scroll (GimpDisplayShell *shell,
shell->offset_x += x_offset;
shell->offset_y += y_offset;
gimp_canvas_scroll (GIMP_CANVAS (shell->canvas), -x_offset, -y_offset);
gimp_overlay_box_scroll (GIMP_OVERLAY_BOX (shell->canvas),
-x_offset, -y_offset);
/* Update scrollbars and rulers */
gimp_display_shell_update_scrollbars_and_rulers (shell);