[goocanvas/new-api] Merged the changes on the master 2.x branch from 1.90.0 to 2.0.0.
- From: Damon Chaplin <damon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goocanvas/new-api] Merged the changes on the master 2.x branch from 1.90.0 to 2.0.0.
- Date: Fri, 7 Oct 2011 21:23:23 +0000 (UTC)
commit c1267d09847bb463b7322e308b6de6f554108338
Author: Damon Chaplin <damon gnome org>
Date: Fri Oct 7 22:23:47 2011 +0100
Merged the changes on the master 2.x branch from 1.90.0 to 2.0.0.
ChangeLog | 4 +
NEWS | 20 ++
README | 19 +-
configure.in | 6 +-
demo/Makefile.am | 2 +-
demo/demo-arrowhead.c | 12 +-
demo/demo-clipping.c | 6 +-
demo/demo-events.c | 2 +-
demo/demo-fifteen.c | 6 +-
demo/demo-focus.c | 2 +-
demo/demo-grabs.c | 28 +-
demo/demo-large-items.c | 2 +-
demo/demo-table.c | 4 +-
demo/demo.c | 64 ++--
demo/generic-position-demo.c | 3 +-
demo/scalability-demo.c | 3 +-
demo/simple-demo.c | 3 +-
demo/table-demo.c | 1 -
demo/units-demo.c | 11 +-
demo/widgets-demo.c | 9 +-
src/goocanvas.c | 638 ++++++++++++++++++++++-------------------
src/goocanvas.h | 15 +-
src/goocanvasatk.c | 32 ++-
src/goocanvasimage.c | 27 ++-
src/goocanvasimage.h | 1 +
src/goocanvasitemsimple.c | 5 +
src/goocanvastext.c | 58 ++--
src/goocanvastext.h | 4 +-
src/goocanvasutils.h | 45 +++
src/goocanvaswidget.c | 36 ++--
src/goocanvaswidget.h | 2 +-
31 files changed, 607 insertions(+), 463 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 369960f..945e5ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-10-07 Damon Chaplin <damon gnome org>
+
+ * Merged the changes on the master 2.x branch from 1.90.0 to 2.0.0.
+
2010-07-10 Damon Chaplin <damon gnome org>
* src/goocanvasitemsimple.c:
diff --git a/NEWS b/NEWS
index 8109158..c3ab61c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,24 @@
+GooCanvas 2.0.0 (Feb 27 2011)
+===============
+
+ o Ported to GTK+ 3.0.
+ o Can be installed with GooCanvas 1.0.x without conflicting.
+
+
+GooCanvas 1.0.0 (Jan 10 2011)
+===============
+
+ o Added "alpha" property to GooCanvasImage to set opacity.
+ o Allow setting clip path to NULL to reset it.
+ o Allow setting line dash to NULL to reset it.
+ o Handle RTL direction better in GooCanvasTable.
+ o Fixed GooCanvasGroup bug - use the correct scale argument in paint.
+ o Fixed GooCanvasPolyline bug - update arrows when line width changes.
+ o Fixed static items bug - don't clip incorrectly.
+ o Improved performance a bit when creating lots of items.
+
+
GooCanvas 0.15 (Jun 29 2009)
==============
diff --git a/README b/README
index 3205ba7..3dfa796 100644
--- a/README
+++ b/README
@@ -1,7 +1,4 @@
- NOTE: The 1.0.9x versions are unstable development releases and should only
- be used for development and testing. The API may change before 2.0.
-
Welcome to GooCanvas
====================
@@ -11,10 +8,8 @@
GooCanvas Home Page : http://live.gnome.org/GooCanvas
-GooCanvas is similar in many ways to GnomeCanvas and FooCanvas.
-But it uses cairo for rendering, has an optional model/view split,
-and uses interfaces for items & models (so you can easily turn any
-application object into a canvas item or model).
+GooCanvas is similar in many ways to GnomeCanvas and FooCanvas, but it uses
+cairo for rendering.
NOTE: I am no longer actively developing GooCanvas, so no major new
features will be added (unless a new maintainer takes over). I'll still
@@ -26,8 +21,6 @@ for the model-view demo.)
Features:
- o Optional model/view split.
- o Uses interfaces for items & views.
o Basic items - rect/ellipse/polyline/text/image/grid/group.
o Path item, using SVG path specification strings.
o Table item for layout of other items (similar to the GtkTable widget).
@@ -35,7 +28,6 @@ Features:
their allocated width, such as text items.)
o Embedded GTK+ widgets.
o Layers/stacking order with raise/lower functions.
- o Cascading styles - line width/style/dashes, colors, fill patterns.
o Affine transformations for all items - rotations/scales/skews.
o Clip paths to support clipping items.
o Event handling - button/motion events, "pointer-events" property like SVG.
@@ -53,6 +45,13 @@ Features:
o Support for different units - pixels/points/inches/millimeters.
o API docs.
+Features that may be removed in future to simplify the code:
+
+ o Optional model/view split.
+ o Uses interfaces for items & views.
+ o Cascading styles - line width/style/dashes, colors, fill patterns.
+ (The style properties will remain, but will not cascade.)
+
Damon Chaplin (damon gnome org)
diff --git a/configure.in b/configure.in
index bbc7a63..83bb875 100644
--- a/configure.in
+++ b/configure.in
@@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
-AC_INIT(goocanvas, 1.90.0)
+AC_INIT(goocanvas, 2.90.0)
AC_PREREQ(2.50)
AC_CONFIG_SRCDIR(src/goocanvas.c)
AC_CONFIG_HEADERS(config.h)
@@ -26,12 +26,12 @@ AC_PROG_CC
AC_HEADER_STDC
AM_PROG_LIBTOOL
-pkg_modules="gtk+-3.0 >= 2.90.0 glib-2.0 >= 2.10.0 cairo >= 1.4.0"
+pkg_modules="gtk+-3.0 >= 3.0.0 glib-2.0 >= 2.28.0 cairo >= 1.10.0"
PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)
-GETTEXT_PACKAGE=goocanvas
+GETTEXT_PACKAGE=goocanvas3
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.])
diff --git a/demo/Makefile.am b/demo/Makefile.am
index b9db404..aae2a0e 100644
--- a/demo/Makefile.am
+++ b/demo/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES = \
-I$(top_builddir)/src \
@PACKAGE_CFLAGS@
-DEMO_LIBS = $(top_builddir)/src/libgoocanvas-2.0.la @PACKAGE_LIBS@ $(INTLLIBS)
+DEMO_LIBS = $(top_builddir)/src/libgoocanvas-2.0.la @PACKAGE_LIBS@ $(INTLLIBS) -lm
# -DG_DISABLE_DEPRECATED -DPANGO_DISABLE_DEPRECATED \
# -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED \
diff --git a/demo/demo-arrowhead.c b/demo/demo-arrowhead.c
index 4631eed..f33291c 100644
--- a/demo/demo-arrowhead.c
+++ b/demo/demo-arrowhead.c
@@ -192,7 +192,7 @@ create_dimension (GtkWidget *canvas,
GooCanvasItem *root,
char *arrow_name,
char *text_name,
- GtkAnchorType anchor)
+ GooCanvasAnchorType anchor)
{
GooCanvasItem *item;
@@ -219,7 +219,7 @@ create_info (GtkWidget *canvas,
{
GooCanvasItem *item;
- item = goo_canvas_text_new (root, NULL, x, y, -1, GTK_ANCHOR_NW,
+ item = goo_canvas_text_new (root, NULL, x, y, -1, GOO_CANVAS_ANCHOR_NW,
"fill_color", "black",
"font", "Sans 14",
NULL);
@@ -475,10 +475,10 @@ create_canvas_arrowhead (void)
/* Dimensions */
- create_dimension (canvas, root, "width_arrow", "width_text", GTK_ANCHOR_E);
- create_dimension (canvas, root, "shape_a_arrow", "shape_a_text", GTK_ANCHOR_N);
- create_dimension (canvas, root, "shape_b_arrow", "shape_b_text", GTK_ANCHOR_N);
- create_dimension (canvas, root, "shape_c_arrow", "shape_c_text", GTK_ANCHOR_W);
+ create_dimension (canvas, root, "width_arrow", "width_text", GOO_CANVAS_ANCHOR_E);
+ create_dimension (canvas, root, "shape_a_arrow", "shape_a_text", GOO_CANVAS_ANCHOR_N);
+ create_dimension (canvas, root, "shape_b_arrow", "shape_b_text", GOO_CANVAS_ANCHOR_N);
+ create_dimension (canvas, root, "shape_c_arrow", "shape_c_text", GOO_CANVAS_ANCHOR_W);
/* Info */
diff --git a/demo/demo-clipping.c b/demo/demo-clipping.c
index b69aa1c..805b31c 100644
--- a/demo/demo-clipping.c
+++ b/demo/demo-clipping.c
@@ -46,7 +46,7 @@ setup_canvas (GtkWidget *canvas)
g_signal_connect (item, "button_press_event",
G_CALLBACK (on_button_press), "Yellow rectangle (unclipped)");
- item = goo_canvas_text_new (root, "Sample Text", 520, 100, -1, GTK_ANCHOR_NW,
+ item = goo_canvas_text_new (root, "Sample Text", 520, 100, -1, GOO_CANVAS_ANCHOR_NW,
NULL);
g_signal_connect (item, "button_press_event",
G_CALLBACK (on_button_press), "Text (unclipped)");
@@ -78,7 +78,7 @@ setup_canvas (GtkWidget *canvas)
g_signal_connect (item, "button_press_event",
G_CALLBACK (on_button_press), "Yellow rectangle");
- item = goo_canvas_text_new (root, "Sample Text", 520, 300, -1, GTK_ANCHOR_NW,
+ item = goo_canvas_text_new (root, "Sample Text", 520, 300, -1, GOO_CANVAS_ANCHOR_NW,
"clip-path", "M535,300 h75 v40 h-75 z",
NULL);
g_signal_connect (item, "button_press_event",
@@ -121,7 +121,7 @@ setup_canvas (GtkWidget *canvas)
G_CALLBACK (on_button_press), "Yellow rectangle");
item = goo_canvas_text_new (table, "Sample Text", 520, 300, -1,
- GTK_ANCHOR_NW,
+ GOO_CANVAS_ANCHOR_NW,
"clip-path", "M535,300 h75 v40 h-75 z",
NULL);
goo_canvas_item_set_child_properties (table, item,
diff --git a/demo/demo-events.c b/demo/demo-events.c
index 9bf3336..6fd3860 100644
--- a/demo/demo-events.c
+++ b/demo/demo-events.c
@@ -130,7 +130,7 @@ create_events_area (GtkWidget *canvas,
g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);
setup_item_signals (rect);
- goo_canvas_text_new (root, label, x + 100, y + 130, -1, GTK_ANCHOR_CENTER,
+ goo_canvas_text_new (root, label, x + 100, y + 130, -1, GOO_CANVAS_ANCHOR_CENTER,
"tooltip", tooltip,
"font", "Sans 12",
"fill-color", "blue",
diff --git a/demo/demo-fifteen.c b/demo/demo-fifteen.c
index bd9f7a2..8ab0f03 100644
--- a/demo/demo-fifteen.c
+++ b/demo/demo-fifteen.c
@@ -12,7 +12,7 @@
static void
-free_stuff (GtkObject *obj, gpointer data)
+free_stuff (GObject *obj, gpointer data)
{
g_free (data);
}
@@ -179,7 +179,7 @@ setup_item_signals (GooCanvasItem *item)
#define SCRAMBLE_MOVES 256
static void
-scramble (GtkObject *object, gpointer data)
+scramble (GObject *object, gpointer data)
{
GooCanvas *canvas;
GooCanvasItem **board;
@@ -300,7 +300,7 @@ create_canvas_fifteen (void)
text = goo_canvas_text_new (board[i], buf,
PIECE_SIZE / 2.0, PIECE_SIZE / 2.0,
- -1, GTK_ANCHOR_CENTER,
+ -1, GOO_CANVAS_ANCHOR_CENTER,
"font", "Sans bold 24",
"fill_color", "black",
NULL);
diff --git a/demo/demo-focus.c b/demo/demo-focus.c
index f543aaf..2fc6576 100644
--- a/demo/demo-focus.c
+++ b/demo/demo-focus.c
@@ -153,7 +153,7 @@ create_focus_page (void)
gtk_container_add (GTK_CONTAINER (vbox), scrolled_win);
canvas = goo_canvas_new ();
- GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus (canvas, TRUE);
gtk_widget_set_size_request (canvas, 600, 450);
goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
gtk_widget_show (canvas);
diff --git a/demo/demo-grabs.c b/demo/demo-grabs.c
index 9262de3..773e318 100644
--- a/demo/demo-grabs.c
+++ b/demo/demo-grabs.c
@@ -5,15 +5,17 @@
static gboolean
-on_widget_expose (GtkWidget *widget,
- GdkEventExpose *event,
+on_widget_draw (GtkWidget *widget,
+ cairo_t *cr,
char *item_id)
{
- g_print ("%s received 'expose' signal\n", item_id);
+ GtkAllocation allocation;
+ g_print ("%s received 'draw' signal\n", item_id);
- gtk_paint_box (widget->style, widget->window, GTK_STATE_NORMAL,
- GTK_SHADOW_IN, &event->area, widget, NULL, 0, 0,
- widget->allocation.width, widget->allocation.height);
+ gtk_widget_get_allocation (widget, &allocation);
+ gtk_paint_box (gtk_widget_get_style (widget), cr, GTK_STATE_NORMAL,
+ GTK_SHADOW_IN, widget, NULL, 0, 0,
+ allocation.width, allocation.height);
return FALSE;
}
@@ -71,7 +73,7 @@ on_widget_button_press (GtkWidget *widget,
| GDK_ENTER_NOTIFY_MASK
| GDK_LEAVE_NOTIFY_MASK;
- status = gdk_pointer_grab (widget->window, FALSE, mask, FALSE, NULL,
+ status = gdk_pointer_grab (gtk_widget_get_window (widget), FALSE, mask, FALSE, NULL,
event->time);
if (status == GDK_GRAB_SUCCESS)
g_print ("grabbed pointer\n");
@@ -230,8 +232,8 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
gtk_widget_show (fixed);
view_id = g_strdup_printf ("%s-background", id);
- g_signal_connect (fixed, "expose_event",
- G_CALLBACK (on_widget_expose), view_id);
+ g_signal_connect (fixed, "draw",
+ G_CALLBACK (on_widget_draw), view_id);
g_signal_connect (fixed, "enter_notify_event",
G_CALLBACK (on_widget_enter_notify), view_id);
@@ -263,8 +265,8 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
gtk_widget_show (drawing_area);
view_id = g_strdup_printf ("%s-left", id);
- g_signal_connect (drawing_area, "expose_event",
- G_CALLBACK (on_widget_expose), view_id);
+ g_signal_connect (drawing_area, "draw",
+ G_CALLBACK (on_widget_draw), view_id);
g_signal_connect (drawing_area, "enter_notify_event",
G_CALLBACK (on_widget_enter_notify), view_id);
@@ -296,8 +298,8 @@ create_fixed (GtkTable *table, gint row, gchar *text, gchar *id)
gtk_widget_show (drawing_area);
view_id = g_strdup_printf ("%s-right", id);
- g_signal_connect (drawing_area, "expose_event",
- G_CALLBACK (on_widget_expose), view_id);
+ g_signal_connect (drawing_area, "draw",
+ G_CALLBACK (on_widget_draw), view_id);
g_signal_connect (drawing_area, "enter_notify_event",
G_CALLBACK (on_widget_enter_notify), view_id);
diff --git a/demo/demo-large-items.c b/demo/demo-large-items.c
index 7e5c67d..f459ebe 100644
--- a/demo/demo-large-items.c
+++ b/demo/demo-large-items.c
@@ -54,7 +54,7 @@ on_motion_notify (GooCanvasItem *item,
static void
zoom_changed (GtkAdjustment *adj, GooCanvas *canvas)
{
- goo_canvas_set_scale (canvas, adj->value);
+ goo_canvas_set_scale (canvas, gtk_adjustment_get_value (adj));
}
diff --git a/demo/demo-table.c b/demo/demo-table.c
index b1f5856..35ede48 100644
--- a/demo/demo-table.c
+++ b/demo/demo-table.c
@@ -46,7 +46,7 @@ create_demo_item (GooCanvasItem *table,
NULL);
break;
case DEMO_TEXT_ITEM:
- item = goo_canvas_text_new (table, text, 0, 0, -1, GTK_ANCHOR_NW, NULL);
+ item = goo_canvas_text_new (table, text, 0, 0, -1, GOO_CANVAS_ANCHOR_NW, NULL);
break;
case DEMO_WIDGET_ITEM:
widget = gtk_button_new_with_label (text);
@@ -241,7 +241,7 @@ create_width_for_height_table (GooCanvasItem *root,
NULL);
#if 1
- item = goo_canvas_text_new (table, text, 0, 0, -1, GTK_ANCHOR_NW, NULL);
+ item = goo_canvas_text_new (table, text, 0, 0, -1, GOO_CANVAS_ANCHOR_NW, NULL);
goo_canvas_item_set_child_properties (table, item,
"row", 1,
"column", 0,
diff --git a/demo/demo.c b/demo/demo.c
index 598a4e0..3acff11 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -77,7 +77,7 @@ write_pdf_clicked (GtkWidget *button, GooCanvas *canvas)
static void
zoom_changed (GtkAdjustment *adj, GooCanvas *canvas)
{
- goo_canvas_set_scale (canvas, adj->value);
+ goo_canvas_set_scale (canvas, gtk_adjustment_get_value (adj));
}
@@ -85,7 +85,7 @@ static void
zoom_x_changed (GtkAdjustment *adj, GooCanvas *canvas)
{
g_object_set (G_OBJECT (canvas),
- "scale-x", adj->value,
+ "scale-x", gtk_adjustment_get_value (adj),
NULL);
}
@@ -94,7 +94,7 @@ static void
zoom_y_changed (GtkAdjustment *adj, GooCanvas *canvas)
{
g_object_set (G_OBJECT (canvas),
- "scale-y", adj->value,
+ "scale-y", gtk_adjustment_get_value (adj),
NULL);
}
@@ -110,11 +110,11 @@ center_toggled (GtkToggleButton *button, gpointer data)
static void
anchor_toggled (GtkWidget *button, GooCanvas *canvas)
{
- GtkAnchorType anchor;
+ GooCanvasAnchorType anchor;
anchor = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "anchor"));
- if (GTK_TOGGLE_BUTTON (button)->active)
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
g_object_set (canvas, "anchor", anchor, NULL);
}
@@ -720,7 +720,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_NW));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_NW));
w = gtk_radio_button_new_with_label (group, "N");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
@@ -730,7 +730,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_N));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_N));
w = gtk_radio_button_new_with_label (group, "NE");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
@@ -740,7 +740,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_NE));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_NE));
w = gtk_radio_button_new_with_label (group, "W");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
@@ -750,7 +750,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_W));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_W));
w = gtk_radio_button_new_with_label (group, "C");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
@@ -760,7 +760,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_CENTER));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_CENTER));
w = gtk_radio_button_new_with_label (group, "E");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
@@ -770,7 +770,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_E));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_E));
w = gtk_radio_button_new_with_label (group, "SW");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
@@ -780,7 +780,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_SW));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_SW));
w = gtk_radio_button_new_with_label (group, "S");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
@@ -790,7 +790,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_S));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_S));
w = gtk_radio_button_new_with_label (group, "SE");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
@@ -800,7 +800,7 @@ create_canvas_primitives ()
G_CALLBACK (anchor_toggled),
canvas);
g_object_set_data (G_OBJECT (w), "anchor",
- GINT_TO_POINTER (GTK_ANCHOR_SE));
+ GINT_TO_POINTER (GOO_CANVAS_ANCHOR_SE));
/* Layout the stuff */
@@ -836,7 +836,7 @@ setup_heading (GooCanvasItem *root, char *text, int pos)
GooCanvasItem *item;
PangoRectangle ink_rect, logical_rect;
- item = goo_canvas_text_new (root, text, x, y, -1, GTK_ANCHOR_N,
+ item = goo_canvas_text_new (root, text, x, y, -1, GOO_CANVAS_ANCHOR_N,
"font", "Sans 12",
NULL);
goo_canvas_item_skew_y (item, 30, x, y);
@@ -1316,7 +1316,7 @@ setup_texts (GooCanvasItem *root)
#if 1
pattern = create_stipple ("blue", stipple_data);
item = goo_canvas_text_new (make_anchor (root, 420, 20),
- "Anchor NW", 0, 0, -1, GTK_ANCHOR_NW,
+ "Anchor NW", 0, 0, -1, GOO_CANVAS_ANCHOR_NW,
"font", "Sans Bold 24",
"fill_pattern", pattern,
NULL);
@@ -1325,7 +1325,7 @@ setup_texts (GooCanvasItem *root)
item = goo_canvas_text_new (make_anchor (root, 470, 75),
"Anchor center\nJustify center\nMultiline text\nb8bit text ÃÃÃÃÃÃ",
- 0, 0, -1, GTK_ANCHOR_CENTER,
+ 0, 0, -1, GOO_CANVAS_ANCHOR_CENTER,
"font", "monospace bold 14",
"alignment", PANGO_ALIGN_CENTER,
"fill_color", "firebrick",
@@ -1336,7 +1336,7 @@ setup_texts (GooCanvasItem *root)
#if 0
item = goo_canvas_text_new (make_anchor (root, 590, 140),
"Clipped text\nClipped text\nClipped text\nClipped text\nClipped text\nClipped text",
- 0, 0, -1, GTK_ANCHOR_SE,
+ 0, 0, -1, GOO_CANVAS_ANCHOR_SE,
"font", "Sans 12",
/*"clip", TRUE,*/
/*"clip_width", 50.0,*/
@@ -1350,7 +1350,7 @@ setup_texts (GooCanvasItem *root)
#if 1
textitem = goo_canvas_text_new (make_anchor (root, 420, 240),
"This is a very long paragraph that will need to be wrapped over several lines so we can see what happens to line-breaking as the view is zoomed in and out.",
- 0, 0, 180, GTK_ANCHOR_W,
+ 0, 0, 180, GOO_CANVAS_ANCHOR_W,
"font", "Sans 12",
"fill_color", "goldenrod",
NULL);
@@ -1360,7 +1360,7 @@ setup_texts (GooCanvasItem *root)
#if 1
textitem = goo_canvas_text_new (root,
"Ellipsized text.",
- 20, 420, 115, GTK_ANCHOR_W,
+ 20, 420, 115, GOO_CANVAS_ANCHOR_W,
"font", "Sans 12",
"fill_color", "blue",
"ellipsize", PANGO_ELLIPSIZE_END,
@@ -1374,7 +1374,7 @@ static void
setup_invisible_texts (GooCanvasItem *root)
{
goo_canvas_text_new (root, "Visible above 0.8x", 500, 330, -1,
- GTK_ANCHOR_CENTER,
+ GOO_CANVAS_ANCHOR_CENTER,
"visibility", GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD,
"visibility-threshold", 0.8,
NULL);
@@ -1385,7 +1385,7 @@ setup_invisible_texts (GooCanvasItem *root)
NULL);
goo_canvas_text_new (root, "Visible above 1.5x", 500, 350, -1,
- GTK_ANCHOR_CENTER,
+ GOO_CANVAS_ANCHOR_CENTER,
"visibility", GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD,
"visibility-threshold", 1.5,
NULL);
@@ -1396,7 +1396,7 @@ setup_invisible_texts (GooCanvasItem *root)
NULL);
goo_canvas_text_new (root, "Visible above 3.0x", 500, 370, -1,
- GTK_ANCHOR_CENTER,
+ GOO_CANVAS_ANCHOR_CENTER,
"visibility", GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD,
"visibility-threshold", 3.0,
NULL);
@@ -1408,7 +1408,7 @@ setup_invisible_texts (GooCanvasItem *root)
/* This should never be seen. */
goo_canvas_text_new (root, "Always Invisible", 500, 390, -1,
- GTK_ANCHOR_CENTER,
+ GOO_CANVAS_ANCHOR_CENTER,
"visibility", GOO_CANVAS_ITEM_INVISIBLE,
NULL);
goo_canvas_rect_new (root, 410.5, 350.5, 180, 15,
@@ -1419,7 +1419,7 @@ setup_invisible_texts (GooCanvasItem *root)
static void
-plant_flower (GooCanvasItem *root, double x, double y, GtkAnchorType anchor)
+plant_flower (GooCanvasItem *root, double x, double y, GooCanvasAnchorType anchor, gdouble opacity)
{
cairo_pattern_t *pattern;
cairo_surface_t *surface;
@@ -1438,6 +1438,7 @@ plant_flower (GooCanvasItem *root, double x, double y, GtkAnchorType anchor)
"width", w * 1.5,
"height", h * 2,
"scale-to-fit", TRUE,
+ "alpha", opacity,
NULL);
cairo_pattern_destroy (pattern);
setup_item_signals (image);
@@ -1458,7 +1459,7 @@ setup_images (GooCanvasItem *root)
image = goo_canvas_image_new (root, im, 100.0 - w / 2, 225.0 - h / 2,
"width", w,
"height", h,
- /* "anchor", GTK_ANCHOR_CENTER, */
+ /* "anchor", GOO_CANVAS_ANCHOR_CENTER, */
NULL);
g_object_unref(im);
setup_item_signals (image);
@@ -1466,10 +1467,10 @@ setup_images (GooCanvasItem *root)
else
g_warning ("Could not find the toroid.png sample file");
- plant_flower (root, 20.0, 170.0, GTK_ANCHOR_NW);
- plant_flower (root, 180.0, 170.0, GTK_ANCHOR_NE);
- plant_flower (root, 20.0, 280.0, GTK_ANCHOR_SW);
- plant_flower (root, 180.0, 280.0, GTK_ANCHOR_SE);
+ plant_flower (root, 20.0, 170.0, GOO_CANVAS_ANCHOR_NW, 0.3);
+ plant_flower (root, 180.0, 170.0, GOO_CANVAS_ANCHOR_NE, 0.5);
+ plant_flower (root, 20.0, 280.0, GOO_CANVAS_ANCHOR_SW, 0.7);
+ plant_flower (root, 180.0, 280.0, GOO_CANVAS_ANCHOR_SE, 1.0);
}
@@ -1504,7 +1505,7 @@ setup_static_items (GooCanvas *canvas)
NULL);
setup_item_signals (item);
- item = goo_canvas_text_new (group, "N", 40, 320, -1, GTK_ANCHOR_S,
+ item = goo_canvas_text_new (group, "N", 40, 320, -1, GOO_CANVAS_ANCHOR_S,
"font", "Sans 12",
NULL);
setup_item_signals (item);
@@ -1737,7 +1738,6 @@ main (int argc, char *argv[])
{
GtkWidget *window;
- gtk_set_locale ();
gtk_init (&argc, &argv);
window = create_window ();
diff --git a/demo/generic-position-demo.c b/demo/generic-position-demo.c
index 7691a72..2fab9bc 100644
--- a/demo/generic-position-demo.c
+++ b/demo/generic-position-demo.c
@@ -140,7 +140,7 @@ setup_canvas (GtkWidget *canvas)
g_object_unref (pixbuf);
setup_dnd_handlers (GOO_CANVAS (canvas), item);
- item = goo_canvas_text_new (root, "Hello, World!", 250, 450, -1, GTK_ANCHOR_NW, "fill-color", "magenta", "wrap", PANGO_WRAP_WORD_CHAR, NULL);
+ item = goo_canvas_text_new (root, "Hello, World!", 250, 450, -1, GOO_CANVAS_ANCHOR_NW, "fill-color", "magenta", "wrap", PANGO_WRAP_WORD_CHAR, NULL);
setup_dnd_handlers (GOO_CANVAS (canvas), item);
button = gtk_label_new ("GtkLabel");
@@ -176,7 +176,6 @@ main (int argc, char *argv[])
GtkWidget *window, *vbox, *label, *scrolled_win, *canvas;
/* Initialize GTK+. */
- gtk_set_locale ();
gtk_init (&argc, &argv);
/* Create the window and widgets. */
diff --git a/demo/scalability-demo.c b/demo/scalability-demo.c
index d4058ef..e938e84 100644
--- a/demo/scalability-demo.c
+++ b/demo/scalability-demo.c
@@ -208,7 +208,7 @@ setup_canvas (GtkWidget *canvas)
item = goo_canvas_text_new (group, ids[id_item_num],
item_x + item_width / 2,
item_y + item_height / 2,
- item_width, GTK_ANCHOR_CENTER,
+ item_width, GOO_CANVAS_ANCHOR_CENTER,
/*"height", item_height,*/
/*"alignment", PANGO_ALIGN_CENTER,*/
NULL);
@@ -343,7 +343,6 @@ main (int argc, char *argv[])
{
GtkWidget *window, *scrolled_win, *canvas;
- gtk_set_locale ();
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/demo/simple-demo.c b/demo/simple-demo.c
index 4f58430..0cb64d5 100644
--- a/demo/simple-demo.c
+++ b/demo/simple-demo.c
@@ -19,7 +19,6 @@ main (int argc, char *argv[])
GooCanvasItem *root, *rect_item, *text_item;
/* Initialize GTK+. */
- gtk_set_locale ();
gtk_init (&argc, &argv);
/* Create the window and widgets. */
@@ -53,7 +52,7 @@ main (int argc, char *argv[])
NULL);
text_item = goo_canvas_text_new (root, "Hello World", 300, 300, -1,
- GTK_ANCHOR_CENTER,
+ GOO_CANVAS_ANCHOR_CENTER,
"font", "Sans 24",
NULL);
goo_canvas_item_rotate (text_item, 45, 300, 300);
diff --git a/demo/table-demo.c b/demo/table-demo.c
index 4486d47..431cba6 100644
--- a/demo/table-demo.c
+++ b/demo/table-demo.c
@@ -215,7 +215,6 @@ main (int argc, char *argv[])
GtkWidget *window, *vbox, *label, *scrolled_win, *canvas;
/* Initialize GTK+. */
- gtk_set_locale ();
gtk_init (&argc, &argv);
/* Create the window and widgets. */
diff --git a/demo/units-demo.c b/demo/units-demo.c
index 6c96991..d08d245 100644
--- a/demo/units-demo.c
+++ b/demo/units-demo.c
@@ -65,7 +65,7 @@ setup_canvas (GtkWidget *canvas,
sprintf (buffer, "This box is %gx%g %s", d[2], d[3], units_name);
sprintf (font_desc, "Sans %gpx", d[4]);
item = goo_canvas_text_new (root, buffer, d[0] + d[2] / 2, d[1] + d[3] / 2,
- -1, GTK_ANCHOR_CENTER,
+ -1, GOO_CANVAS_ANCHOR_CENTER,
"font", font_desc,
NULL);
@@ -73,13 +73,13 @@ setup_canvas (GtkWidget *canvas,
sprintf (buffer, "This font is %g %s high", d[7], units_name);
sprintf (font_desc, "Sans %gpx", d[7]);
item = goo_canvas_text_new (root, buffer, d[5], d[6], -1,
- GTK_ANCHOR_CENTER,
+ GOO_CANVAS_ANCHOR_CENTER,
"font", font_desc,
NULL);
sprintf (buffer, "This font is 12 points high");
item = goo_canvas_text_new (root, buffer, d[5], d[6] * 1.5, -1,
- GTK_ANCHOR_CENTER,
+ GOO_CANVAS_ANCHOR_CENTER,
"font", "Sans 12",
NULL);
@@ -95,7 +95,7 @@ setup_canvas (GtkWidget *canvas,
static void
zoom_changed (GtkAdjustment *adj, GooCanvas *canvas)
{
- goo_canvas_set_scale (canvas, adj->value);
+ goo_canvas_set_scale (canvas, gtk_adjustment_get_value (adj));
}
@@ -140,7 +140,7 @@ create_canvas (GtkUnit units,
goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
g_object_set (canvas,
"units", units,
- "anchor", GTK_ANCHOR_CENTER,
+ "anchor", GOO_CANVAS_ANCHOR_CENTER,
NULL);
gtk_widget_show (canvas);
@@ -166,7 +166,6 @@ main (int argc, char *argv[])
GtkWidget *window, *notebook;
cairo_surface_t *surface;
- gtk_set_locale ();
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/demo/widgets-demo.c b/demo/widgets-demo.c
index 687b535..91e45d0 100644
--- a/demo/widgets-demo.c
+++ b/demo/widgets-demo.c
@@ -72,15 +72,15 @@ move_widget_clicked (GtkWidget *button, gpointer data)
static void
change_anchor_clicked (GtkWidget *button, gpointer data)
{
- static GtkAnchorType anchor = GTK_ANCHOR_CENTER;
+ static GooCanvasAnchorType anchor = GOO_CANVAS_ANCHOR_CENTER;
g_print ("Setting anchor to: %i\n", anchor);
g_object_set (move_item,
"anchor", anchor,
NULL);
anchor++;
- if (anchor > GTK_ANCHOR_EAST)
- anchor = GTK_ANCHOR_CENTER;
+ if (anchor > GOO_CANVAS_ANCHOR_EAST)
+ anchor = GOO_CANVAS_ANCHOR_CENTER;
}
@@ -272,7 +272,6 @@ main (int argc, char *argv[])
GooCanvasItem *root, *witem;
/* Initialize GTK+. */
- gtk_set_locale ();
gtk_init (&argc, &argv);
/* Create the window and widgets. */
@@ -352,7 +351,7 @@ main (int argc, char *argv[])
gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
canvas = goo_canvas_new ();
- GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus (canvas, TRUE);
gtk_widget_set_size_request (canvas, 600, 450);
goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);
diff --git a/src/goocanvas.c b/src/goocanvas.c
index 289a281..cc70963 100644
--- a/src/goocanvas.c
+++ b/src/goocanvas.c
@@ -29,7 +29,6 @@
* GooCanvasItem *root, *rect_item, *text_item;
*
* /* Initialize GTK+. */
- * gtk_set_locale ();
* gtk_init (&argc, &argv);
*
* /* Create the window and widgets. */
@@ -63,7 +62,7 @@
* NULL);
*
* text_item = goo_canvas_text_new (root, "Hello World", 300, 300, -1,
- * GTK_ANCHOR_CENTER,
+ * GOO_CANVAS_ANCHOR_CENTER,
* "font", "Sans 24",
* NULL);
* goo_canvas_item_rotate (text_item, 45, 300, 300);
@@ -125,7 +124,11 @@ enum {
PROP_BACKGROUND_COLOR_RGB,
PROP_INTEGER_LAYOUT,
PROP_CLEAR_BACKGROUND,
- PROP_REDRAW_WHEN_SCROLLED
+ PROP_REDRAW_WHEN_SCROLLED,
+ PROP_HADJUSTMENT,
+ PROP_VADJUSTMENT,
+ PROP_HSCROLL_POLICY,
+ PROP_VSCROLL_POLICY
};
@@ -136,15 +139,20 @@ static void goo_canvas_unrealize (GtkWidget *widget);
static void goo_canvas_map (GtkWidget *widget);
static void goo_canvas_style_set (GtkWidget *widget,
GtkStyle *old_style);
-static void goo_canvas_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
+static void goo_canvas_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+static void goo_canvas_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
static void goo_canvas_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static void goo_canvas_set_adjustments (GooCanvas *canvas,
- GtkAdjustment *hadj,
- GtkAdjustment *vadj);
-static gboolean goo_canvas_expose_event (GtkWidget *widget,
- GdkEventExpose *event);
+static void goo_canvas_set_hadjustment (GooCanvas *canvas,
+ GtkAdjustment *adjustment);
+static void goo_canvas_set_vadjustment (GooCanvas *canvas,
+ GtkAdjustment *adjustment);
+static gboolean goo_canvas_draw (GtkWidget *widget,
+ cairo_t *cr);
static gboolean goo_canvas_button_press (GtkWidget *widget,
GdkEventButton *event);
static gboolean goo_canvas_button_release (GtkWidget *widget,
@@ -199,11 +207,15 @@ static void reconfigure_canvas (GooCanvas *canvas,
gboolean redraw_if_needed);
static void goo_canvas_update_automatic_bounds (GooCanvas *canvas);
+static void goo_canvas_convert_from_window_pixels (GooCanvas *canvas,
+ gdouble *x,
+ gdouble *y);
static void goo_canvas_convert_to_static_item_space (GooCanvas *canvas,
gdouble *x,
gdouble *y);
-G_DEFINE_TYPE (GooCanvas, goo_canvas, GTK_TYPE_CONTAINER)
+G_DEFINE_TYPE_WITH_CODE (GooCanvas, goo_canvas, GTK_TYPE_CONTAINER,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
/* This evaluates to TRUE if an item is still in the canvas. */
#define ITEM_IS_VALID(item) (goo_canvas_item_get_canvas (item))
@@ -226,10 +238,11 @@ goo_canvas_class_init (GooCanvasClass *klass)
widget_class->realize = goo_canvas_realize;
widget_class->unrealize = goo_canvas_unrealize;
widget_class->map = goo_canvas_map;
- widget_class->size_request = goo_canvas_size_request;
+ widget_class->get_preferred_width = goo_canvas_get_preferred_width;
+ widget_class->get_preferred_height = goo_canvas_get_preferred_height;
widget_class->size_allocate = goo_canvas_size_allocate;
widget_class->style_set = goo_canvas_style_set;
- widget_class->expose_event = goo_canvas_expose_event;
+ widget_class->draw = goo_canvas_draw;
widget_class->button_press_event = goo_canvas_button_press;
widget_class->button_release_event = goo_canvas_button_release;
widget_class->motion_notify_event = goo_canvas_motion;
@@ -247,8 +260,6 @@ goo_canvas_class_init (GooCanvasClass *klass)
container_class->remove = goo_canvas_remove;
container_class->forall = goo_canvas_forall;
- klass->set_scroll_adjustments = goo_canvas_set_adjustments;
-
/* Register our accessible factory, but only if accessibility is enabled. */
if (!ATK_IS_NO_OP_OBJECT_FACTORY (atk_registry_get_factory (atk_get_default_registry (), GTK_TYPE_WIDGET)))
{
@@ -282,8 +293,8 @@ goo_canvas_class_init (GooCanvasClass *klass)
g_param_spec_enum ("anchor",
_("Anchor"),
_("Where to place the canvas when it is smaller than the widget's allocated area"),
- GTK_TYPE_ANCHOR_TYPE,
- GTK_ANCHOR_NW,
+ GOO_TYPE_CANVAS_ANCHOR_TYPE,
+ GOO_CANVAS_ANCHOR_NW,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_X1,
@@ -402,27 +413,11 @@ goo_canvas_class_init (GooCanvasClass *klass)
FALSE,
G_PARAM_READWRITE));
- /**
- * GooCanvas::set-scroll-adjustments
- * @canvas: the canvas.
- * @hadjustment: the horizontal adjustment.
- * @vadjustment: the vertical adjustment.
- *
- * This is used when the #GooCanvas is placed inside a #GtkScrolledWindow,
- * to connect up the adjustments so scrolling works properly.
- *
- * It isn't useful for applications.
- */
- widget_class->set_scroll_adjustments_signal =
- g_signal_new ("set_scroll_adjustments",
- G_OBJECT_CLASS_TYPE (gobject_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GooCanvasClass, set_scroll_adjustments),
- NULL, NULL,
- goo_canvas_marshal_VOID__OBJECT_OBJECT,
- G_TYPE_NONE, 2,
- GTK_TYPE_ADJUSTMENT,
- GTK_TYPE_ADJUSTMENT);
+ /* GtkScrollable interface */
+ g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
+ g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
+ g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
+ g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
}
@@ -431,7 +426,7 @@ goo_canvas_init (GooCanvas *canvas)
{
/* We set GTK_CAN_FOCUS by default, so it works as people expect.
Though developers can turn this off if not needed for efficiency. */
- GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus (GTK_WIDGET (canvas), TRUE);
canvas->scale_x = 1.0;
canvas->scale_y = 1.0;
@@ -439,10 +434,10 @@ goo_canvas_init (GooCanvas *canvas)
canvas->need_update = TRUE;
canvas->need_entire_subtree_update = TRUE;
canvas->crossing_event.type = GDK_LEAVE_NOTIFY;
- canvas->anchor = GTK_ANCHOR_NORTH_WEST;
+ canvas->anchor = GOO_CANVAS_ANCHOR_NORTH_WEST;
canvas->clear_background = TRUE;
canvas->redraw_when_scrolled = FALSE;
- canvas->before_initial_expose = TRUE;
+ canvas->before_initial_draw = TRUE;
/* Set the default bounds to a reasonable size. */
canvas->bounds.x1 = 0.0;
@@ -476,8 +471,8 @@ goo_canvas_init (GooCanvas *canvas)
goo_canvas_item_set_canvas (canvas->static_root_item, canvas);
goo_canvas_item_set_is_static (canvas->static_root_item, TRUE);
- canvas->window_x = 0;
- canvas->window_y = 0;
+ canvas->window_x = canvas->static_window_x = 0;
+ canvas->window_y = canvas->static_window_y = 0;
}
@@ -617,8 +612,12 @@ goo_canvas_apply_style (GooCanvas *canvas,
if (style->mask & GOO_CANVAS_STYLE_OPERATOR)
cairo_set_operator (cr, style->op);
+ /* We use CAIRO_ANTIALIAS_GRAY as the default antialiasing mode, as that is
+ what is recommended when using unhinted text. */
if (style->mask & GOO_CANVAS_STYLE_ANTIALIAS)
cairo_set_antialias (cr, style->antialias);
+ else
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_GRAY);
if (style->mask & GOO_CANVAS_STYLE_LINE_CAP)
cairo_set_line_cap (cr, style->line_cap);
@@ -670,10 +669,6 @@ goo_canvas_create_cairo_context (GooCanvas *canvas)
cairo_surface_destroy (surface);
}
- /* We use CAIRO_ANTIALIAS_GRAY as the default antialiasing mode, as that is
- what is recommended when using unhinted text. */
- cairo_set_antialias (cr, CAIRO_ANTIALIAS_GRAY);
-
goo_canvas_apply_style (canvas, cr);
return cr;
@@ -741,6 +736,18 @@ goo_canvas_get_property (GObject *object,
case PROP_REDRAW_WHEN_SCROLLED:
g_value_set_boolean (value, canvas->redraw_when_scrolled);
break;
+ case PROP_HADJUSTMENT:
+ g_value_set_object (value, canvas->hadjustment);
+ break;
+ case PROP_VADJUSTMENT:
+ g_value_set_object (value, canvas->vadjustment);
+ break;
+ case PROP_HSCROLL_POLICY:
+ g_value_set_enum (value, canvas->hscroll_policy);
+ break;
+ case PROP_VSCROLL_POLICY:
+ g_value_set_enum (value, canvas->vscroll_policy);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -823,9 +830,9 @@ goo_canvas_set_property (GObject *object,
break;
case PROP_BACKGROUND_COLOR:
if (!g_value_get_string (value))
- gtk_widget_modify_base ((GtkWidget*) canvas, GTK_STATE_NORMAL, NULL);
+ gtk_widget_modify_bg ((GtkWidget*) canvas, GTK_STATE_NORMAL, NULL);
else if (gdk_color_parse (g_value_get_string (value), &color))
- gtk_widget_modify_base ((GtkWidget*) canvas, GTK_STATE_NORMAL, &color);
+ gtk_widget_modify_bg ((GtkWidget*) canvas, GTK_STATE_NORMAL, &color);
else
g_warning ("Unknown color: %s", g_value_get_string (value));
break;
@@ -834,7 +841,7 @@ goo_canvas_set_property (GObject *object,
color.red = ((rgb >> 16) & 0xFF) * 257;
color.green = ((rgb >> 8) & 0xFF) * 257;
color.blue = ((rgb) & 0xFF) * 257;
- gtk_widget_modify_base ((GtkWidget*) canvas, GTK_STATE_NORMAL, &color);
+ gtk_widget_modify_bg ((GtkWidget*) canvas, GTK_STATE_NORMAL, &color);
break;
case PROP_INTEGER_LAYOUT:
canvas->integer_layout = g_value_get_boolean (value);
@@ -847,6 +854,20 @@ goo_canvas_set_property (GObject *object,
case PROP_REDRAW_WHEN_SCROLLED:
canvas->redraw_when_scrolled = g_value_get_boolean (value);
break;
+ case PROP_HADJUSTMENT:
+ goo_canvas_set_hadjustment (canvas, g_value_get_object (value));
+ break;
+ case PROP_VADJUSTMENT:
+ goo_canvas_set_vadjustment (canvas, g_value_get_object (value));
+ break;
+ case PROP_HSCROLL_POLICY:
+ canvas->hscroll_policy = g_value_get_enum (value);
+ gtk_widget_queue_resize (GTK_WIDGET (canvas));
+ break;
+ case PROP_VSCROLL_POLICY:
+ canvas->vscroll_policy = g_value_get_enum (value);
+ gtk_widget_queue_resize (GTK_WIDGET (canvas));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1186,36 +1207,39 @@ goo_canvas_realize (GtkWidget *widget)
gint attributes_mask;
gint width_pixels, height_pixels;
GList *tmp_list;
+ GtkAllocation allocation;
+ GdkWindow* window;
g_return_if_fail (GOO_IS_CANVAS (widget));
canvas = GOO_CANVAS (widget);
- GTK_WIDGET_SET_FLAGS (canvas, GTK_REALIZED);
+ gtk_widget_set_realized (GTK_WIDGET (canvas), TRUE);
+ gtk_widget_get_allocation (widget, &allocation);
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
- widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
- gdk_window_set_user_data (widget->window, widget);
+ gtk_widget_set_window (widget, window);
+ gdk_window_set_user_data (window, widget);
/* We want to round the sizes up to the next pixel. */
width_pixels = ((canvas->bounds.x2 - canvas->bounds.x1) * canvas->device_to_pixels_x) + 1;
height_pixels = ((canvas->bounds.y2 - canvas->bounds.y1) * canvas->device_to_pixels_y) + 1;
- attributes.x = canvas->hadjustment ? - canvas->hadjustment->value : 0,
- attributes.y = canvas->vadjustment ? - canvas->vadjustment->value : 0;
- attributes.width = MAX (width_pixels, widget->allocation.width);
- attributes.height = MAX (height_pixels, widget->allocation.height);
+ attributes.x = canvas->hadjustment ? - gtk_adjustment_get_value (canvas->hadjustment) : 0,
+ attributes.y = canvas->vadjustment ? - gtk_adjustment_get_value (canvas->vadjustment) : 0;
+ attributes.width = MAX (width_pixels, allocation.width);
+ attributes.height = MAX (height_pixels, allocation.height);
attributes.event_mask = GDK_EXPOSURE_MASK
| GDK_SCROLL_MASK
| GDK_BUTTON_PRESS_MASK
@@ -1229,31 +1253,34 @@ goo_canvas_realize (GtkWidget *widget)
| GDK_FOCUS_CHANGE_MASK
| gtk_widget_get_events (widget);
- canvas->window_x = attributes.x;
- canvas->window_y = attributes.y;
+ canvas->window_x = canvas->static_window_x = attributes.x;
+ canvas->window_y = canvas->static_window_y = attributes.y;
- canvas->canvas_window = gdk_window_new (widget->window,
+ canvas->canvas_window = gdk_window_new (window,
&attributes, attributes_mask);
gdk_window_set_user_data (canvas->canvas_window, widget);
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
attributes.event_mask = 0;
canvas->tmp_window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
gdk_window_set_user_data (canvas->tmp_window, widget);
- widget->style = gtk_style_attach (widget->style, widget->window);
+ gtk_widget_set_style(widget, gtk_style_attach (gtk_widget_get_style (widget), window));
/* Make sure the window backgrounds aren't set, to avoid flicker when
scrolling (due to the delay between X clearing the background and
GooCanvas painting it). */
- gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
- gdk_window_set_back_pixmap (canvas->canvas_window, NULL, FALSE);
- gdk_window_set_back_pixmap (canvas->tmp_window, NULL, FALSE);
+ /* TODO: Do this with GTK+ 3 too? */
+#if 0
+ gdk_window_set_background_pattern (window, NULL);
+ gdk_window_set_background_pattern (canvas->canvas_window, NULL);
+ gdk_window_set_background_pattern (canvas->tmp_window, NULL);
+#endif
/* Set the parent window of all the child widget items. */
tmp_list = canvas->widget_items;
@@ -1302,7 +1329,7 @@ goo_canvas_map (GtkWidget *widget)
canvas = GOO_CANVAS (widget);
- GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
+ gtk_widget_set_mapped (widget, TRUE);
tmp_list = canvas->widget_items;
while (tmp_list)
@@ -1318,7 +1345,7 @@ goo_canvas_map (GtkWidget *widget)
}
gdk_window_show (canvas->canvas_window);
- gdk_window_show (widget->window);
+ gdk_window_show (gtk_widget_get_window (widget));
}
@@ -1334,8 +1361,11 @@ goo_canvas_style_set (GtkWidget *widget,
/* Make sure the window backgrounds aren't set, to avoid flicker when
scrolling (due to the delay between X clearing the background and
GooCanvas painting it). */
- gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
- gdk_window_set_back_pixmap (GOO_CANVAS (widget)->canvas_window, NULL, FALSE);
+ /* TODO: Do this with GTK+ 3 too? */
+#if 0
+ gdk_window_set_background_pattern (gtk_widget_get_window (widget), NULL);
+ gdk_window_set_background_pattern (GOO_CANVAS (widget)->canvas_window, NULL);
+#endif
}
}
@@ -1349,27 +1379,36 @@ goo_canvas_configure_hadjustment (GooCanvas *canvas,
gboolean changed = FALSE;
gboolean value_changed = FALSE;
gdouble max_value;
+ gdouble page_size;
+ GtkAllocation allocation;
- if (adj->upper != window_width)
+ canvas->freeze_count++;
+
+ if (gtk_adjustment_get_upper (adj) != window_width)
{
- adj->upper = window_width;
+ gtk_adjustment_set_upper (adj, window_width);
changed = TRUE;
}
- if (adj->page_size != widget->allocation.width)
+ gtk_widget_get_allocation (widget, &allocation);
+ page_size = gtk_adjustment_get_page_size (adj);
+ if (page_size != allocation.width)
{
- adj->page_size = widget->allocation.width;
- adj->page_increment = adj->page_size * 0.9;
- adj->step_increment = adj->page_size * 0.1;
+ page_size = allocation.width;
+ gtk_adjustment_set_page_size (adj, page_size);
+ gtk_adjustment_set_page_increment (adj, page_size * 0.9);
+ gtk_adjustment_set_step_increment (adj, page_size * 0.1);
changed = TRUE;
}
-
- max_value = MAX (0.0, adj->upper - adj->page_size);
- if (adj->value > max_value)
+
+ max_value = MAX (0.0, gtk_adjustment_get_upper (adj) - page_size);
+ if (gtk_adjustment_get_value (adj) > max_value)
{
- adj->value = max_value;
+ gtk_adjustment_set_value (adj, max_value);
value_changed = TRUE;
}
+
+ canvas->freeze_count--;
if (changed)
gtk_adjustment_changed (adj);
@@ -1388,28 +1427,37 @@ goo_canvas_configure_vadjustment (GooCanvas *canvas,
gboolean changed = FALSE;
gboolean value_changed = FALSE;
gdouble max_value;
+ GtkAllocation allocation;
+ gdouble page_size;
- if (adj->upper != window_height)
+ canvas->freeze_count++;
+
+ if (gtk_adjustment_get_upper (adj) != window_height)
{
- adj->upper = window_height;
+ gtk_adjustment_set_upper (adj, window_height);
changed = TRUE;
}
- if (adj->page_size != widget->allocation.height)
+ gtk_widget_get_allocation (widget, &allocation);
+ page_size = gtk_adjustment_get_page_size (adj);
+ if (page_size != allocation.height)
{
- adj->page_size = widget->allocation.height;
- adj->page_increment = adj->page_size * 0.9;
- adj->step_increment = adj->page_size * 0.1;
+ page_size = allocation.height;
+ gtk_adjustment_set_page_size (adj, page_size);
+ gtk_adjustment_set_page_increment (adj, page_size * 0.9);
+ gtk_adjustment_set_step_increment (adj, page_size * 0.1);
changed = TRUE;
}
-
- max_value = MAX (0.0, adj->upper - adj->page_size);
- if (adj->value > max_value)
+
+ max_value = MAX (0.0, gtk_adjustment_get_upper (adj) - page_size);
+ if (gtk_adjustment_get_value (adj) > max_value)
{
- adj->value = max_value;
+ gtk_adjustment_set_value (adj, max_value);
value_changed = TRUE;
}
-
+
+ canvas->freeze_count--;
+
if (changed)
gtk_adjustment_changed (adj);
@@ -1463,6 +1511,10 @@ request_static_redraw (GooCanvas *canvas,
rect.width = (double) bounds->x2 - canvas->window_x - rect.x + 2 + 1;
rect.height = (double) bounds->y2 - canvas->window_y - rect.y + 2 + 1;
+#if 0
+ g_print ("Invalidating rect: %i,%i %ix%i\n",
+ rect.x, rect.y, rect.width, rect.height);
+#endif
gdk_window_invalidate_rect (canvas->canvas_window, &rect, FALSE);
}
@@ -1483,8 +1535,8 @@ redraw_static_items_at_position (GooCanvas *canvas,
if (!canvas->static_root_item)
return;
- window_x_copy = canvas->window_x;
- window_y_copy = canvas->window_y;
+ window_x_copy = canvas->static_window_x;
+ window_y_copy = canvas->static_window_y;
n_children = goo_canvas_item_get_n_children (canvas->static_root_item);
for (i = 0; i < n_children; i++)
@@ -1498,14 +1550,15 @@ redraw_static_items_at_position (GooCanvas *canvas,
request_static_redraw (canvas, &bounds);
/* Redraw the item in its new position. */
- canvas->window_x = x;
- canvas->window_y = y;
+ canvas->static_window_x = x;
+ canvas->static_window_y = y;
- gdk_window_process_updates (canvas->canvas_window, TRUE);
+ /* FIXME: This causes flicker. Do we need it? */
+ /*gdk_window_process_updates (canvas->canvas_window, TRUE);*/
/* Now reset the window position. */
- canvas->window_x = window_x_copy;
- canvas->window_y = window_y_copy;
+ canvas->static_window_x = window_x_copy;
+ canvas->static_window_y = window_y_copy;
}
}
@@ -1521,6 +1574,7 @@ reconfigure_canvas (GooCanvas *canvas,
gint window_x = 0, window_y = 0, window_width, window_height;
gint new_x_offset = 0, new_y_offset = 0;
GtkWidget *widget;
+ GtkAllocation allocation;
widget = GTK_WIDGET (canvas);
@@ -1539,51 +1593,52 @@ reconfigure_canvas (GooCanvas *canvas,
height_pixels = ((canvas->bounds.y2 - canvas->bounds.y1) * canvas->device_to_pixels_y) + 1;
/* The actual window size is always at least as big as the widget's window.*/
- window_width = MAX (width_pixels, widget->allocation.width);
- window_height = MAX (height_pixels, widget->allocation.height);
+ gtk_widget_get_allocation (widget, &allocation);
+ window_width = MAX (width_pixels, allocation.width);
+ window_height = MAX (height_pixels, allocation.height);
/* If the width or height is smaller than the window, we need to calculate
the canvas x & y offsets according to the anchor. */
- if (width_pixels < widget->allocation.width)
+ if (width_pixels < allocation.width)
{
switch (canvas->anchor)
{
- case GTK_ANCHOR_NORTH_WEST:
- case GTK_ANCHOR_WEST:
- case GTK_ANCHOR_SOUTH_WEST:
+ case GOO_CANVAS_ANCHOR_NORTH_WEST:
+ case GOO_CANVAS_ANCHOR_WEST:
+ case GOO_CANVAS_ANCHOR_SOUTH_WEST:
new_x_offset = 0;
break;
- case GTK_ANCHOR_NORTH:
- case GTK_ANCHOR_CENTER:
- case GTK_ANCHOR_SOUTH:
- new_x_offset = (widget->allocation.width - width_pixels) / 2;
+ case GOO_CANVAS_ANCHOR_NORTH:
+ case GOO_CANVAS_ANCHOR_CENTER:
+ case GOO_CANVAS_ANCHOR_SOUTH:
+ new_x_offset = (allocation.width - width_pixels) / 2;
break;
- case GTK_ANCHOR_NORTH_EAST:
- case GTK_ANCHOR_EAST:
- case GTK_ANCHOR_SOUTH_EAST:
- new_x_offset = widget->allocation.width - width_pixels;
+ case GOO_CANVAS_ANCHOR_NORTH_EAST:
+ case GOO_CANVAS_ANCHOR_EAST:
+ case GOO_CANVAS_ANCHOR_SOUTH_EAST:
+ new_x_offset = allocation.width - width_pixels;
break;
}
}
- if (height_pixels < widget->allocation.height)
+ if (height_pixels < allocation.height)
{
switch (canvas->anchor)
{
- case GTK_ANCHOR_NORTH_WEST:
- case GTK_ANCHOR_NORTH:
- case GTK_ANCHOR_NORTH_EAST:
+ case GOO_CANVAS_ANCHOR_NORTH_WEST:
+ case GOO_CANVAS_ANCHOR_NORTH:
+ case GOO_CANVAS_ANCHOR_NORTH_EAST:
new_y_offset = 0;
break;
- case GTK_ANCHOR_WEST:
- case GTK_ANCHOR_CENTER:
- case GTK_ANCHOR_EAST:
- new_y_offset = (widget->allocation.height - height_pixels) / 2;
+ case GOO_CANVAS_ANCHOR_WEST:
+ case GOO_CANVAS_ANCHOR_CENTER:
+ case GOO_CANVAS_ANCHOR_EAST:
+ new_y_offset = (allocation.height - height_pixels) / 2;
break;
- case GTK_ANCHOR_SOUTH_WEST:
- case GTK_ANCHOR_SOUTH:
- case GTK_ANCHOR_SOUTH_EAST:
- new_y_offset = widget->allocation.height - height_pixels;
+ case GOO_CANVAS_ANCHOR_SOUTH_WEST:
+ case GOO_CANVAS_ANCHOR_SOUTH:
+ case GOO_CANVAS_ANCHOR_SOUTH_EAST:
+ new_y_offset = allocation.height - height_pixels;
break;
}
}
@@ -1593,13 +1648,13 @@ reconfigure_canvas (GooCanvas *canvas,
if (canvas->hadjustment)
{
goo_canvas_configure_hadjustment (canvas, window_width);
- window_x = - canvas->hadjustment->value;
+ window_x = - gtk_adjustment_get_value (canvas->hadjustment);
}
if (canvas->vadjustment)
{
goo_canvas_configure_vadjustment (canvas, window_height);
- window_y = - canvas->vadjustment->value;
+ window_y = - gtk_adjustment_get_value (canvas->vadjustment);
}
canvas->freeze_count--;
@@ -1627,32 +1682,21 @@ reconfigure_canvas (GooCanvas *canvas,
}
-static void
-goo_canvas_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+static void
+goo_canvas_get_preferred_width (GtkWidget *widget,
+ gint *minimal_width,
+ gint *natural_width)
{
- GList *tmp_list;
- GooCanvas *canvas;
-
- g_return_if_fail (GOO_IS_CANVAS (widget));
-
- canvas = GOO_CANVAS (widget);
-
- requisition->width = 0;
- requisition->height = 0;
-
- tmp_list = canvas->widget_items;
+ *minimal_width = *natural_width = 0;
+}
- while (tmp_list)
- {
- GooCanvasWidget *witem = tmp_list->data;
- GtkRequisition child_requisition;
-
- tmp_list = tmp_list->next;
- if (witem->widget)
- gtk_widget_size_request (witem->widget, &child_requisition);
- }
+static void
+goo_canvas_get_preferred_height (GtkWidget *widget,
+ gint *minimal_height,
+ gint *natural_height)
+{
+ *minimal_height = *natural_height = 0;
}
@@ -1690,7 +1734,7 @@ goo_canvas_size_allocate (GtkWidget *widget,
canvas = GOO_CANVAS (widget);
- widget->allocation = *allocation;
+ gtk_widget_set_allocation (widget, allocation);
if (gtk_widget_get_realized (widget))
{
@@ -1706,7 +1750,7 @@ goo_canvas_size_allocate (GtkWidget *widget,
goo_canvas_allocate_child_widget (canvas, witem);
}
- gdk_window_move_resize (widget->window,
+ gdk_window_move_resize (gtk_widget_get_window (widget),
allocation->x, allocation->y,
allocation->width, allocation->height);
gdk_window_move_resize (canvas->tmp_window,
@@ -1723,9 +1767,14 @@ goo_canvas_adjustment_value_changed (GtkAdjustment *adjustment,
GooCanvas *canvas)
{
AtkObject *accessible;
+ int new_window_x, new_window_y;
if (!canvas->freeze_count && gtk_widget_get_realized (GTK_WIDGET(canvas)))
{
+ /* These get truncated to ints. */
+ new_window_x = -gtk_adjustment_get_value (canvas->hadjustment);
+ new_window_y = -gtk_adjustment_get_value (canvas->vadjustment);
+
if (canvas->redraw_when_scrolled)
{
/* Map the temporary window to stop the canvas window being scrolled.
@@ -1738,18 +1787,14 @@ goo_canvas_adjustment_value_changed (GtkAdjustment *adjustment,
/* Redraw the area currently occupied by the static items. But
draw the static items in their new position. This stops them
from being "dragged" when the window is scrolled. */
- redraw_static_items_at_position (canvas,
- -canvas->hadjustment->value,
- -canvas->hadjustment->value);
-
- /* Move the static items to the new position. */
- canvas->window_x = -canvas->hadjustment->value;
- canvas->window_y = -canvas->vadjustment->value;
+ redraw_static_items_at_position (canvas, new_window_x, new_window_y);
}
- gdk_window_move (canvas->canvas_window,
- - canvas->hadjustment->value,
- - canvas->vadjustment->value);
+ /* Move the window to the new position. */
+ canvas->window_x = canvas->static_window_x = new_window_x;
+ canvas->window_y = canvas->static_window_y = new_window_y;
+
+ gdk_window_move (canvas->canvas_window, new_window_x, new_window_y);
if (canvas->redraw_when_scrolled)
{
@@ -1761,7 +1806,8 @@ goo_canvas_adjustment_value_changed (GtkAdjustment *adjustment,
else
{
/* Process updates here for smoother scrolling. */
- gdk_window_process_updates (canvas->canvas_window, TRUE);
+ /* FIXME: This causes flicker. Do we need it? */
+ /*gdk_window_process_updates (canvas->canvas_window, TRUE);*/
/* Now ensure the static items are redrawn in their new position. */
redraw_static_items_at_position (canvas, canvas->window_x,
@@ -1775,70 +1821,62 @@ goo_canvas_adjustment_value_changed (GtkAdjustment *adjustment,
}
-/* Sets either or both adjustments, If hadj or vadj is NULL a new adjustment
- is created. */
-static void
-goo_canvas_set_adjustments (GooCanvas *canvas,
- GtkAdjustment *hadj,
- GtkAdjustment *vadj)
+static void
+goo_canvas_set_hadjustment (GooCanvas *canvas,
+ GtkAdjustment *adjustment)
{
- gboolean need_reconfigure = FALSE;
-
g_return_if_fail (GOO_IS_CANVAS (canvas));
- if (hadj)
- g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
- else if (canvas->hadjustment)
- hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
+ if (adjustment && canvas->hadjustment == adjustment)
+ return;
- if (vadj)
- g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
- else if (canvas->vadjustment)
- vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
-
- if (canvas->hadjustment && (canvas->hadjustment != hadj))
+ if (canvas->hadjustment)
{
g_signal_handlers_disconnect_by_func (canvas->hadjustment,
- goo_canvas_adjustment_value_changed,
- canvas);
+ goo_canvas_adjustment_value_changed,
+ canvas);
g_object_unref (canvas->hadjustment);
}
-
- if (canvas->vadjustment && (canvas->vadjustment != vadj))
+
+ if (adjustment == NULL)
+ adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
+
+ g_signal_connect (adjustment, "value-changed",
+ G_CALLBACK (goo_canvas_adjustment_value_changed), canvas);
+ canvas->hadjustment = g_object_ref_sink (adjustment);
+ reconfigure_canvas (canvas, TRUE);
+
+ g_object_notify (G_OBJECT (canvas), "hadjustment");
+}
+
+static void
+goo_canvas_set_vadjustment (GooCanvas *canvas,
+ GtkAdjustment *adjustment)
+{
+ g_return_if_fail (GOO_IS_CANVAS (canvas));
+
+ if (adjustment && canvas->vadjustment == adjustment)
+ return;
+
+ if (canvas->vadjustment)
{
g_signal_handlers_disconnect_by_func (canvas->vadjustment,
- goo_canvas_adjustment_value_changed,
- canvas);
+ goo_canvas_adjustment_value_changed,
+ canvas);
g_object_unref (canvas->vadjustment);
}
-
- if (canvas->hadjustment != hadj)
- {
- canvas->hadjustment = hadj;
- g_object_ref_sink (canvas->hadjustment);
- g_signal_connect (canvas->hadjustment, "value_changed",
- G_CALLBACK (goo_canvas_adjustment_value_changed),
- canvas);
- need_reconfigure = TRUE;
- }
-
- if (canvas->vadjustment != vadj)
- {
- canvas->vadjustment = vadj;
- g_object_ref_sink (canvas->vadjustment);
+ if (adjustment == NULL)
+ adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
- g_signal_connect (canvas->vadjustment, "value_changed",
- G_CALLBACK (goo_canvas_adjustment_value_changed),
- canvas);
- need_reconfigure = TRUE;
- }
+ g_signal_connect (adjustment, "value-changed",
+ G_CALLBACK (goo_canvas_adjustment_value_changed), canvas);
+ canvas->vadjustment = g_object_ref_sink (adjustment);
+ reconfigure_canvas (canvas, TRUE);
- if (need_reconfigure)
- reconfigure_canvas (canvas, TRUE);
+ g_object_notify (G_OBJECT (canvas), "vadjustment");
}
-
/* Sets one of our pointers to an item, adding a reference to it and
releasing any reference to the current item. */
static void
@@ -1949,10 +1987,10 @@ goo_canvas_scroll_to (GooCanvas *canvas,
goo_canvas_convert_to_pixels (canvas, &x, &y);
/* Make sure we stay within the bounds. */
- x = CLAMP (x, canvas->hadjustment->lower,
- canvas->hadjustment->upper - canvas->hadjustment->page_size);
- y = CLAMP (y, canvas->vadjustment->lower,
- canvas->vadjustment->upper - canvas->vadjustment->page_size);
+ x = CLAMP (x, gtk_adjustment_get_lower (canvas->hadjustment),
+ gtk_adjustment_get_upper (canvas->hadjustment) - gtk_adjustment_get_page_size (canvas->hadjustment));
+ y = CLAMP (y, gtk_adjustment_get_lower (canvas->vadjustment),
+ gtk_adjustment_get_upper (canvas->vadjustment) - gtk_adjustment_get_page_size (canvas->vadjustment));
canvas->freeze_count++;
@@ -1984,8 +2022,8 @@ goo_canvas_scroll_to_item (GooCanvas *canvas,
canvas->freeze_count++;
/* Remember the current adjustment values. */
- hvalue = canvas->hadjustment->value;
- vvalue = canvas->vadjustment->value;
+ hvalue = gtk_adjustment_get_value (canvas->hadjustment);
+ vvalue = gtk_adjustment_get_value (canvas->vadjustment);
/* Update the adjustments so the item is displayed. */
gtk_adjustment_clamp_page (canvas->hadjustment, bounds.x1, bounds.x2);
@@ -1994,8 +2032,8 @@ goo_canvas_scroll_to_item (GooCanvas *canvas,
canvas->freeze_count--;
/* If the adjustments have changed we need to scroll. */
- if (hvalue != canvas->hadjustment->value
- || vvalue != canvas->vadjustment->value)
+ if (hvalue != gtk_adjustment_get_value (canvas->hadjustment)
+ || vvalue != gtk_adjustment_get_value (canvas->vadjustment))
goo_canvas_adjustment_value_changed (NULL, canvas);
}
@@ -2031,8 +2069,8 @@ goo_canvas_set_scale_internal (GooCanvas *canvas,
g_return_if_fail (GOO_IS_CANVAS (canvas));
/* Calculate the coords of the current center point in pixels. */
- x = canvas->hadjustment->value + canvas->hadjustment->page_size / 2;
- y = canvas->vadjustment->value + canvas->vadjustment->page_size / 2;
+ x = gtk_adjustment_get_value (canvas->hadjustment) + gtk_adjustment_get_page_size (canvas->hadjustment)/ 2;
+ y = gtk_adjustment_get_value (canvas->vadjustment) + gtk_adjustment_get_page_size (canvas->vadjustment)/ 2;
/* Convert from pixel units to device units. */
goo_canvas_convert_from_pixels (canvas, &x, &y);
@@ -2043,8 +2081,10 @@ goo_canvas_set_scale_internal (GooCanvas *canvas,
scrolling is unnecessary and really ugly.
FIXME: There is a possible issue with keyboard focus/input methods here,
since hidden windows can't have the keyboard focus. */
+#if 0
if (gtk_widget_get_mapped (GTK_WIDGET (canvas)))
gdk_window_show (canvas->tmp_window);
+#endif
canvas->freeze_count++;
@@ -2054,8 +2094,8 @@ goo_canvas_set_scale_internal (GooCanvas *canvas,
reconfigure_canvas (canvas, FALSE);
/* Convert from the center point to the new desired top-left posision. */
- x -= canvas->hadjustment->page_size / canvas->device_to_pixels_x / 2;
- y -= canvas->vadjustment->page_size / canvas->device_to_pixels_y / 2;
+ x -= gtk_adjustment_get_page_size (canvas->hadjustment)/ canvas->device_to_pixels_x / 2;
+ y -= gtk_adjustment_get_page_size (canvas->vadjustment)/ canvas->device_to_pixels_y / 2;
/* Now try to scroll to it. */
goo_canvas_scroll_to (canvas, x, y);
@@ -2063,10 +2103,13 @@ goo_canvas_set_scale_internal (GooCanvas *canvas,
canvas->freeze_count--;
goo_canvas_adjustment_value_changed (NULL, canvas);
- /* Now hide the temporary window, so the canvas window will get an expose
- event. */
+ /* Now hide the temporary window, so the canvas window will get an draw
+ signal. */
+#if 0
if (gtk_widget_get_mapped (GTK_WIDGET (canvas)))
gdk_window_hide (canvas->tmp_window);
+#endif
+ gtk_widget_queue_draw (GTK_WIDGET (canvas));
}
@@ -2298,7 +2341,7 @@ goo_canvas_request_item_redraw (GooCanvas *canvas,
{
/* If the canvas hasn't been painted yet, we can just return as it all needs
a redraw. This can save a lot of time if there are lots of items. */
- if (canvas->before_initial_expose)
+ if (canvas->before_initial_draw)
return;
if (is_static)
@@ -2310,67 +2353,69 @@ goo_canvas_request_item_redraw (GooCanvas *canvas,
static void
paint_static_items (GooCanvas *canvas,
- GdkEventExpose *event,
- cairo_t *cr)
+ cairo_t *cr,
+ GooCanvasBounds *clip_bounds)
{
- GooCanvasBounds static_bounds;
- double static_x_offset, static_y_offset;
-
cairo_save (cr);
cairo_identity_matrix (cr);
- static_x_offset = floor (canvas->hadjustment->value);
- static_y_offset = floor (canvas->vadjustment->value);
- cairo_translate (cr, static_x_offset, static_y_offset);
+ cairo_translate (cr, -canvas->static_window_x, -canvas->static_window_y);
/* FIXME: Uses pixels at present - use canvas units instead? */
- static_bounds.x1 = event->area.x - static_x_offset;
- static_bounds.y1 = event->area.y - static_y_offset;
- static_bounds.x2 = event->area.width + static_bounds.x1;
- static_bounds.y2 = event->area.height + static_bounds.y1;
- goo_canvas_item_paint (canvas->static_root_item, cr, &static_bounds, 1.0);
+ goo_canvas_item_paint (canvas->static_root_item, cr, clip_bounds, 1.0);
cairo_restore (cr);
}
static gboolean
-goo_canvas_expose_event (GtkWidget *widget,
- GdkEventExpose *event)
+goo_canvas_draw (GtkWidget *widget,
+ cairo_t *cr)
{
GooCanvas *canvas = GOO_CANVAS (widget);
- GooCanvasBounds bounds, root_item_bounds;
- cairo_t *cr;
+ GooCanvasBounds clip_bounds, bounds, root_item_bounds;
double x1, y1, x2, y2;
+ if (!gtk_cairo_should_draw_window (cr, canvas->canvas_window))
+ return FALSE;
+
if (!canvas->root_item)
{
- canvas->before_initial_expose = FALSE;
+ canvas->before_initial_draw = FALSE;
return FALSE;
}
- if (event->window != canvas->canvas_window)
- return FALSE;
+ /* TODO: Need to worry about child widgets? */
+
+ /* The clip extents tell us which parts of the window need to be drawn,
+ in pixels, where (0,0) is the top-left of the widget window (not the
+ entire canvas window as was the case with the expose_event signal). */
+ cairo_clip_extents (cr, &clip_bounds.x1, &clip_bounds.y1,
+ &clip_bounds.x2, &clip_bounds.y2);
+
+ goo_canvas_apply_style (canvas, cr);
+ cairo_save (cr);
+
+ /* Get rid of the translation passed in by GTK+. We use our own. */
+ cairo_identity_matrix (cr);
/* Clear the background. */
if (canvas->clear_background)
{
- gdk_draw_rectangle (canvas->canvas_window,
- widget->style->base_gc[widget->state], TRUE,
- event->area.x, event->area.y,
- event->area.width, event->area.height);
- }
-
- cr = goo_canvas_create_cairo_context (canvas);
-
- cairo_save (cr);
+ const GtkStyle* style = gtk_widget_get_style (widget);
+ const GtkStateType state = gtk_widget_get_state (widget);
+ gdk_cairo_set_source_color (cr, &(style->base[state]));
+ cairo_paint (cr);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ }
if (canvas->need_update)
goo_canvas_update_internal (canvas, cr);
- bounds.x1 = ((event->area.x - canvas->canvas_x_offset) / canvas->device_to_pixels_x)
- + canvas->bounds.x1;
- bounds.y1 = ((event->area.y - canvas->canvas_y_offset) / canvas->device_to_pixels_y)
- + canvas->bounds.y1;
- bounds.x2 = (event->area.width / canvas->device_to_pixels_x) + bounds.x1;
- bounds.y2 = (event->area.height / canvas->device_to_pixels_y) + bounds.y1;
+ bounds = clip_bounds;
+ goo_canvas_convert_from_window_pixels (canvas, &bounds.x1, &bounds.y1);
+ goo_canvas_convert_from_window_pixels (canvas, &bounds.x2, &bounds.y2);
+
+ /* Get rid of the current clip, as it uses the wrong coordinate space.
+ FIXME: Maybe we should always set a clip with the new GTK+ drawing code. */
+ cairo_reset_clip (cr);
/* Translate it to use the canvas pixel offsets (used when the canvas is
smaller than the window and the anchor isn't set to NORTH_WEST). */
@@ -2382,6 +2427,7 @@ goo_canvas_expose_event (GtkWidget *widget,
/* Translate it so the top-left of the canvas becomes (0,0). */
cairo_translate (cr, -canvas->bounds.x1, -canvas->bounds.y1);
+ /* TODO: check this works OK with the clipping from GTK+ 3. */
/* Clip to the canvas bounds, if necessary. We only need to clip if the
items in the canvas extend outside the canvas bounds and the canvas
bounds is less than the area being painted. */
@@ -2396,7 +2442,7 @@ goo_canvas_expose_event (GtkWidget *widget,
&& canvas->bounds.y2 < bounds.y2))
{
/* Clip to the intersection of the canvas bounds and the expose
- bounds, to avoid cairo's coordinate limits. */
+ bounds, to avoid cairo's 16-bit limits. */
x1 = MAX (canvas->bounds.x1, bounds.x1);
y1 = MAX (canvas->bounds.y1, bounds.y1);
x2 = MIN (canvas->bounds.x2, bounds.x2);
@@ -2411,17 +2457,19 @@ goo_canvas_expose_event (GtkWidget *widget,
cairo_clip (cr);
}
+#if 0
+ g_print ("Painting bounds: %g, %g - %g, %g\n", bounds.x1, bounds.y1,
+ bounds.x2, bounds.y2);
+#endif
goo_canvas_item_paint (canvas->root_item, cr, &bounds, canvas->scale);
cairo_restore (cr);
- paint_static_items (canvas, event, cr);
-
- cairo_destroy (cr);
+ paint_static_items (canvas, cr, &clip_bounds);
- GTK_WIDGET_CLASS (goo_canvas_parent_class)->expose_event (widget, event);
+ GTK_WIDGET_CLASS (goo_canvas_parent_class)->draw (widget, cr);
- canvas->before_initial_expose = FALSE;
+ canvas->before_initial_draw = FALSE;
return FALSE;
}
@@ -2865,13 +2913,13 @@ goo_canvas_scroll (GtkWidget *widget,
else
adj = canvas->hadjustment;
- delta = pow (adj->page_size, 2.0 / 3.0);
+ delta = pow (gtk_adjustment_get_page_size (adj), 2.0 / 3.0);
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_LEFT)
delta = - delta;
- new_value = CLAMP (adj->value + delta, adj->lower,
- adj->upper - adj->page_size);
+ new_value = CLAMP (gtk_adjustment_get_value (adj) + delta, gtk_adjustment_get_lower (adj),
+ gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj));
gtk_adjustment_set_value (adj, new_value);
@@ -2885,8 +2933,6 @@ goo_canvas_focus_in (GtkWidget *widget,
{
GooCanvas *canvas = GOO_CANVAS (widget);
- GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
-
if (canvas->focused_item)
return propagate_event (canvas, canvas->focused_item,
"focus_in_event", (GdkEvent*) event);
@@ -2901,8 +2947,6 @@ goo_canvas_focus_out (GtkWidget *widget,
{
GooCanvas *canvas = GOO_CANVAS (widget);
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
-
if (canvas->focused_item)
return propagate_event (canvas, canvas->focused_item,
"focus_out_event", (GdkEvent*) event);
@@ -3277,8 +3321,8 @@ goo_canvas_convert_from_window_pixels (GooCanvas *canvas,
gdouble *x,
gdouble *y)
{
- *x += canvas->hadjustment->value;
- *y += canvas->vadjustment->value;
+ *x -= canvas->window_x;
+ *y -= canvas->window_y;
goo_canvas_convert_from_pixels (canvas, x, y);
}
@@ -3291,9 +3335,9 @@ goo_canvas_convert_to_static_item_space (GooCanvas *canvas,
gdouble *y)
{
*x = ((*x - canvas->bounds.x1) * canvas->device_to_pixels_x)
- + canvas->canvas_x_offset - canvas->hadjustment->value;
+ + canvas->canvas_x_offset - canvas->window_x;
*y = ((*y - canvas->bounds.y1) * canvas->device_to_pixels_y)
- + canvas->canvas_y_offset - canvas->vadjustment->value;
+ + canvas->canvas_y_offset - canvas->window_y;
}
@@ -3492,7 +3536,8 @@ goo_canvas_get_start_bounds (GooCanvas *canvas,
{
GooCanvasBounds *bounds;
GtkWidget *toplevel, *focus_widget;
- GtkAllocation *allocation;
+ GtkAllocation allocation;
+ GtkAllocation focus_widget_allocation;
gint focus_widget_x, focus_widget_y;
/* If an item is currently focused, we just need its bounds. */
@@ -3506,9 +3551,9 @@ goo_canvas_get_start_bounds (GooCanvas *canvas,
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (canvas));
bounds = &data->start_bounds;
if (toplevel && GTK_IS_WINDOW (toplevel)
- && GTK_WINDOW (toplevel)->focus_widget)
+ && gtk_window_get_focus (GTK_WINDOW (toplevel)))
{
- focus_widget = GTK_WINDOW (toplevel)->focus_widget;
+ focus_widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
/* Translate the allocation to be relative to the GooCanvas.
Skip ancestor widgets as the coords won't help. */
@@ -3520,10 +3565,11 @@ goo_canvas_get_start_bounds (GooCanvas *canvas,
&focus_widget_y))
{
/* Translate into device units. */
+ gtk_widget_get_allocation (focus_widget, &focus_widget_allocation);
bounds->x1 = focus_widget_x;
bounds->y1 = focus_widget_y;
- bounds->x2 = focus_widget_x + focus_widget->allocation.width;
- bounds->y2 = focus_widget_y + focus_widget->allocation.height;
+ bounds->x2 = focus_widget_x + focus_widget_allocation.width;
+ bounds->y2 = focus_widget_y + focus_widget_allocation.height;
goo_canvas_convert_from_window_pixels (canvas, &bounds->x1,
&bounds->y1);
@@ -3534,7 +3580,7 @@ goo_canvas_get_start_bounds (GooCanvas *canvas,
}
/* As a last resort, we guess a starting position based on the direction. */
- allocation = >K_WIDGET (canvas)->allocation;
+ gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
switch (data->direction)
{
case GTK_DIR_DOWN:
@@ -3547,12 +3593,12 @@ goo_canvas_get_start_bounds (GooCanvas *canvas,
case GTK_DIR_UP:
/* Start from bottom-left. */
bounds->x1 = 0.0;
- bounds->y1 = allocation->height;
+ bounds->y1 = allocation.height;
break;
case GTK_DIR_LEFT:
/* Start from top-right. */
- bounds->x1 = allocation->width;
+ bounds->x1 = allocation.width;
bounds->y1 = 0.0;
break;
@@ -3560,20 +3606,20 @@ goo_canvas_get_start_bounds (GooCanvas *canvas,
bounds->y1 = 0.0;
if (data->text_direction == GTK_TEXT_DIR_RTL)
/* Start from top-right. */
- bounds->x1 = allocation->width;
+ bounds->x1 = allocation.width;
else
/* Start from top-left. */
bounds->x1 = 0.0;
break;
case GTK_DIR_TAB_BACKWARD:
- bounds->y1 = allocation->height;
+ bounds->y1 = allocation.height;
if (data->text_direction == GTK_TEXT_DIR_RTL)
/* Start from bottom-left. */
bounds->x1 = 0.0;
else
/* Start from bottom-right. */
- bounds->x1 = allocation->width;
+ bounds->x1 = allocation.width;
break;
}
@@ -3849,7 +3895,7 @@ goo_canvas_focus (GtkWidget *widget,
return FALSE;
/* If a child widget has the focus, try moving the focus within that. */
- old_focus_child = GTK_CONTAINER (canvas)->focus_child;
+ old_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (canvas));
if (old_focus_child && gtk_widget_child_focus (old_focus_child, direction))
return TRUE;
diff --git a/src/goocanvas.h b/src/goocanvas.h
index afe4669..18a2b11 100644
--- a/src/goocanvas.h
+++ b/src/goocanvas.h
@@ -60,7 +60,7 @@ struct _GooCanvas
/* Where the canvas is anchored (where it is displayed when it is smaller
than the entire window). */
- GtkAnchorType anchor;
+ GooCanvasAnchorType anchor;
/* Idle handler ID, for processing updates. */
guint idle_id;
@@ -88,8 +88,12 @@ struct _GooCanvas
useful when there are sticky items to reduce flicker, but is slower. */
guint redraw_when_scrolled : 1;
- /* If the canvas hasn't received the initial expose event yet. */
- guint before_initial_expose : 1;
+ /* If the canvas hasn't received the initial draw signal yet. */
+ guint before_initial_draw : 1;
+
+ /* GtkScrollablePolicy for each adjustment. */
+ guint hscroll_policy : 1;
+ guint vscroll_policy : 1;
/* This is the padding around the automatic bounds. */
gdouble bounds_padding;
@@ -155,6 +159,7 @@ struct _GooCanvas
/* The last window position, used for static items. */
gint window_x, window_y;
+ gint static_window_x, static_window_y;
/* The default style for all canvas items. */
GooCanvasStyle *style;
@@ -170,10 +175,6 @@ struct _GooCanvasClass
/*< private >*/
GtkContainerClass parent_class;
- void (* set_scroll_adjustments) (GooCanvas *canvas,
- GtkAdjustment *hadjustment,
- GtkAdjustment *vadjustment);
-
/*< private >*/
/* Padding for future expansion */
void (*_goo_canvas_reserved1) (void);
diff --git a/src/goocanvasatk.c b/src/goocanvasatk.c
index 2abf2d0..565f1bc 100644
--- a/src/goocanvasatk.c
+++ b/src/goocanvasatk.c
@@ -59,10 +59,10 @@ goo_canvas_item_accessible_get_item_extents (GooCanvasItem *item,
goo_canvas_convert_to_pixels (canvas, &bounds.x2, &bounds.y2);
/* Convert to pixels within the visible window. */
- bounds.x1 -= canvas->hadjustment->value;
- bounds.y1 -= canvas->vadjustment->value;
- bounds.x2 -= canvas->hadjustment->value;
- bounds.y2 -= canvas->vadjustment->value;
+ bounds.x1 -= gtk_adjustment_get_value (canvas->hadjustment);
+ bounds.y1 -= gtk_adjustment_get_value (canvas->vadjustment);
+ bounds.x2 -= gtk_adjustment_get_value (canvas->hadjustment);
+ bounds.y2 -= gtk_adjustment_get_value (canvas->vadjustment);
}
/* Round up or down to integers. */
@@ -80,13 +80,16 @@ goo_canvas_item_accessible_is_item_in_window (GooCanvasItem *item,
GdkRectangle *rect)
{
GtkWidget *widget;
+ GtkAllocation allocation;
widget = (GtkWidget*) goo_canvas_item_get_canvas (item);
if (!widget)
return FALSE;
- if (rect->x + rect->width < 0 || rect->x > widget->allocation.width
- || rect->y + rect->height < 0 || rect->y > widget->allocation.height)
+ gtk_widget_get_allocation (widget, &allocation);
+
+ if (rect->x + rect->width < 0 || rect->x > allocation.width
+ || rect->y + rect->height < 0 || rect->y > allocation.height)
return FALSE;
return TRUE;
@@ -118,7 +121,7 @@ goo_canvas_item_accessible_get_extents (AtkComponent *component,
gint window_x, window_y;
gint toplevel_x, toplevel_y;
GdkRectangle rect;
- GdkWindow *window;
+ GdkWindow *canvas_window, *window;
g_return_if_fail (GOO_IS_CANVAS_ITEM_ACCESSIBLE (component));
@@ -131,7 +134,11 @@ goo_canvas_item_accessible_get_extents (AtkComponent *component,
item = GOO_CANVAS_ITEM (object);
canvas = goo_canvas_item_get_canvas (item);
- if (!canvas || !GTK_WIDGET (canvas)->window)
+ if (!canvas)
+ return;
+
+ canvas_window = gtk_widget_get_window (GTK_WIDGET (canvas));
+ if (!canvas_window)
return;
goo_canvas_item_accessible_get_item_extents (item, &rect);
@@ -141,14 +148,13 @@ goo_canvas_item_accessible_get_extents (AtkComponent *component,
if (!goo_canvas_item_accessible_is_item_in_window (item, &rect))
return;
- gdk_window_get_origin (GTK_WIDGET (canvas)->window,
- &window_x, &window_y);
+ gdk_window_get_origin (canvas_window, &window_x, &window_y);
*x = rect.x + window_x;
*y = rect.y + window_y;
if (coord_type == ATK_XY_WINDOW)
{
- window = gdk_window_get_toplevel (GTK_WIDGET (canvas)->window);
+ window = gdk_window_get_toplevel (canvas_window);
gdk_window_get_origin (window, &toplevel_x, &toplevel_y);
*x -= toplevel_x;
*y -= toplevel_y;
@@ -639,7 +645,7 @@ goo_canvas_accessible_get_n_children (AtkObject *object)
GtkWidget *widget;
accessible = GTK_ACCESSIBLE (object);
- widget = accessible->widget;
+ widget = gtk_accessible_get_widget (accessible);
/* Check if widget still exists. */
if (widget == NULL)
@@ -667,7 +673,7 @@ goo_canvas_accessible_ref_child (AtkObject *object,
return NULL;
accessible = GTK_ACCESSIBLE (object);
- widget = accessible->widget;
+ widget = gtk_accessible_get_widget (accessible);
/* Check if widget still exists. */
if (widget == NULL)
diff --git a/src/goocanvasimage.c b/src/goocanvasimage.c
index 1b679a1..fcc2a2c 100644
--- a/src/goocanvasimage.c
+++ b/src/goocanvasimage.c
@@ -42,6 +42,7 @@ enum {
PROP_WIDTH,
PROP_HEIGHT,
PROP_SCALE_TO_FIT,
+ PROP_ALPHA,
/* Convenience properties. */
PROP_PIXBUF
@@ -54,7 +55,7 @@ G_DEFINE_TYPE (GooCanvasImage, goo_canvas_image, GOO_TYPE_CANVAS_ITEM_SIMPLE)
static void
goo_canvas_image_init (GooCanvasImage *image)
{
-
+ image->alpha = 1.0;
}
@@ -163,6 +164,9 @@ goo_canvas_image_get_property (GObject *object,
case PROP_SCALE_TO_FIT:
g_value_set_boolean (value, image->scale_to_fit);
break;
+ case PROP_ALPHA:
+ g_value_set_double (value, image->alpha);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -179,6 +183,7 @@ goo_canvas_image_set_property (GObject *object,
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasImage *image = (GooCanvasImage*) object;
GdkPixbuf *pixbuf;
+ gboolean recompute_bounds = TRUE;
switch (prop_id)
{
@@ -209,12 +214,16 @@ goo_canvas_image_set_property (GObject *object,
image->width = pixbuf ? gdk_pixbuf_get_width (pixbuf) : 0;
image->height = pixbuf ? gdk_pixbuf_get_height (pixbuf) : 0;
break;
+ case PROP_ALPHA:
+ image->alpha = g_value_get_double (value);
+ recompute_bounds = FALSE;
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
- goo_canvas_item_simple_changed (simple, TRUE);
+ goo_canvas_item_simple_changed (simple, recompute_bounds);
}
@@ -284,7 +293,12 @@ goo_canvas_image_paint (GooCanvasItemSimple *simple,
cairo_set_source (cr, image->pattern);
cairo_rectangle (cr, image->x, image->y,
image->width, image->height);
- cairo_fill (cr);
+ /* To have better performance, we don't use cairo_paint_with_alpha if
+ * the image is not transparent at all. */
+ if (image->alpha != 1.0)
+ cairo_paint_with_alpha (cr, image->alpha);
+ else
+ cairo_fill (cr);
#else
/* Using cairo_paint() used to be much slower than cairo_fill(), though
they seem similar now. I'm not sure if it matters which we use. */
@@ -356,6 +370,13 @@ goo_canvas_image_class_init (GooCanvasImageClass *klass)
FALSE,
G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_ALPHA,
+ g_param_spec_double ("alpha",
+ _("Alpha"),
+ _("The opacity of the image, 0.0 is fully transparent, and 1.0 is opaque."),
+ 0.0, 1.0, 1.0,
+ G_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class, PROP_PIXBUF,
g_param_spec_object ("pixbuf",
_("Pixbuf"),
diff --git a/src/goocanvasimage.h b/src/goocanvasimage.h
index 27d8a5e..c95ae37 100644
--- a/src/goocanvasimage.h
+++ b/src/goocanvasimage.h
@@ -36,6 +36,7 @@ struct _GooCanvasImage
cairo_pattern_t *pattern;
gdouble x, y, width, height;
+ gdouble alpha;
gboolean scale_to_fit;
};
diff --git a/src/goocanvasitemsimple.c b/src/goocanvasitemsimple.c
index e65c423..a17193c 100644
--- a/src/goocanvasitemsimple.c
+++ b/src/goocanvasitemsimple.c
@@ -858,6 +858,11 @@ goo_canvas_item_simple_update_internal (GooCanvasItemSimple *simple,
}
cairo_set_matrix (cr, &transform);
+
+#if 0
+ g_print ("Item bounds: %g,%g -%g,%g\n", simple->bounds.x1, simple->bounds.y1,
+ simple->bounds.x2, simple->bounds.y2);
+#endif
}
diff --git a/src/goocanvastext.c b/src/goocanvastext.c
index e13b556..5c67a32 100644
--- a/src/goocanvastext.c
+++ b/src/goocanvastext.c
@@ -69,7 +69,7 @@ goo_canvas_text_init (GooCanvasText *text)
text->width = -1.0;
text->height = -1.0;
text->layout_width = -1.0;
- text->anchor = GTK_ANCHOR_NW;
+ text->anchor = GOO_CANVAS_ANCHOR_NW;
text->ellipsize = PANGO_ELLIPSIZE_NONE;
text->wrap = PANGO_WRAP_WORD;
}
@@ -99,7 +99,7 @@ goo_canvas_text_init (GooCanvasText *text)
* of the text box placed at (500,500):
*
* <informalexample><programlisting>
- * GooCanvasItem *text = goo_canvas_text_new (mygroup, "Hello World", 500.0, 500.0, 200.0, GTK_ANCHOR_SE,
+ * GooCanvasItem *text = goo_canvas_text_new (mygroup, "Hello World", 500.0, 500.0, 200.0, GOO_CANVAS_ANCHOR_SE,
* "fill-color", "blue",
* NULL);
* </programlisting></informalexample>
@@ -112,7 +112,7 @@ goo_canvas_text_new (GooCanvasItem *parent,
gdouble x,
gdouble y,
gdouble width,
- GtkAnchorType anchor,
+ GooCanvasAnchorType anchor,
...)
{
GooCanvasItem *item;
@@ -329,14 +329,14 @@ goo_canvas_text_create_layout (GooCanvasText *text,
switch (text->anchor)
{
- case GTK_ANCHOR_N:
- case GTK_ANCHOR_CENTER:
- case GTK_ANCHOR_S:
+ case GOO_CANVAS_ANCHOR_N:
+ case GOO_CANVAS_ANCHOR_CENTER:
+ case GOO_CANVAS_ANCHOR_S:
origin_x -= align_width / 2.0;
break;
- case GTK_ANCHOR_NE:
- case GTK_ANCHOR_E:
- case GTK_ANCHOR_SE:
+ case GOO_CANVAS_ANCHOR_NE:
+ case GOO_CANVAS_ANCHOR_E:
+ case GOO_CANVAS_ANCHOR_SE:
origin_x -= align_width;
break;
default:
@@ -345,14 +345,14 @@ goo_canvas_text_create_layout (GooCanvasText *text,
switch (text->anchor)
{
- case GTK_ANCHOR_W:
- case GTK_ANCHOR_CENTER:
- case GTK_ANCHOR_E:
+ case GOO_CANVAS_ANCHOR_W:
+ case GOO_CANVAS_ANCHOR_CENTER:
+ case GOO_CANVAS_ANCHOR_E:
origin_y -= logical_height / 2.0;
break;
- case GTK_ANCHOR_SW:
- case GTK_ANCHOR_S:
- case GTK_ANCHOR_SE:
+ case GOO_CANVAS_ANCHOR_SW:
+ case GOO_CANVAS_ANCHOR_S:
+ case GOO_CANVAS_ANCHOR_SE:
origin_y -= logical_height;
break;
default:
@@ -438,14 +438,14 @@ goo_canvas_text_update (GooCanvasItemSimple *simple,
switch (text->anchor)
{
- case GTK_ANCHOR_N:
- case GTK_ANCHOR_CENTER:
- case GTK_ANCHOR_S:
+ case GOO_CANVAS_ANCHOR_N:
+ case GOO_CANVAS_ANCHOR_CENTER:
+ case GOO_CANVAS_ANCHOR_S:
simple->bounds.x1 -= text->width / 2.0;
break;
- case GTK_ANCHOR_NE:
- case GTK_ANCHOR_E:
- case GTK_ANCHOR_SE:
+ case GOO_CANVAS_ANCHOR_NE:
+ case GOO_CANVAS_ANCHOR_E:
+ case GOO_CANVAS_ANCHOR_SE:
simple->bounds.x1 -= text->width;
break;
default:
@@ -454,14 +454,14 @@ goo_canvas_text_update (GooCanvasItemSimple *simple,
switch (text->anchor)
{
- case GTK_ANCHOR_W:
- case GTK_ANCHOR_CENTER:
- case GTK_ANCHOR_E:
+ case GOO_CANVAS_ANCHOR_W:
+ case GOO_CANVAS_ANCHOR_CENTER:
+ case GOO_CANVAS_ANCHOR_E:
simple->bounds.y1 -= text->height / 2.0;
break;
- case GTK_ANCHOR_SW:
- case GTK_ANCHOR_S:
- case GTK_ANCHOR_SE:
+ case GOO_CANVAS_ANCHOR_SW:
+ case GOO_CANVAS_ANCHOR_S:
+ case GOO_CANVAS_ANCHOR_SE:
simple->bounds.y1 -= text->height;
break;
default:
@@ -787,8 +787,8 @@ goo_canvas_text_class_init (GooCanvasTextClass *klass)
g_param_spec_enum ("anchor",
_("Anchor"),
_("How to position the text relative to the given x and y coordinates"),
- GTK_TYPE_ANCHOR_TYPE,
- GTK_ANCHOR_NW,
+ GOO_TYPE_CANVAS_ANCHOR_TYPE,
+ GOO_CANVAS_ANCHOR_NW,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_ALIGN,
diff --git a/src/goocanvastext.h b/src/goocanvastext.h
index 5e0824b..24ed46d 100644
--- a/src/goocanvastext.h
+++ b/src/goocanvastext.h
@@ -38,7 +38,7 @@ struct _GooCanvasText
gdouble layout_width;
guint use_markup : 1;
- guint anchor : 5; /* GtkAnchorType */
+ guint anchor : 5; /* GooCanvasAnchorType */
guint alignment : 3; /* PangoAlignment */
guint ellipsize : 3; /* PangoEllipsizeMode */
guint wrap : 3; /* PangoWrapMode */
@@ -65,7 +65,7 @@ GooCanvasItem* goo_canvas_text_new (GooCanvasItem *parent,
gdouble x,
gdouble y,
gdouble width,
- GtkAnchorType anchor,
+ GooCanvasAnchorType anchor,
...);
void goo_canvas_text_get_natural_extents (GooCanvasText *text,
diff --git a/src/goocanvasutils.h b/src/goocanvasutils.h
index 64b5bb9..5da1e7e 100644
--- a/src/goocanvasutils.h
+++ b/src/goocanvasutils.h
@@ -186,6 +186,50 @@ typedef enum
} GooCanvasPathCommandType;
+/**
+ * GooCanvasAnchorType
+ * @GOO_CANVAS_ANCHOR_CENTER: the anchor is in the center of the object.
+ * @GOO_CANVAS_ANCHOR_NORTH: the anchor is at the top of the object, centered horizontally.
+ * @GOO_CANVAS_ANCHOR_NORTH_WEST: the anchor is at the top-left of the object.
+ * @GOO_CANVAS_ANCHOR_NORTH_EAST: the anchor is at the top-right of the object.
+ * @GOO_CANVAS_ANCHOR_SOUTH: the anchor is at the bottom of the object, centered horizontally.
+ * @GOO_CANVAS_ANCHOR_SOUTH_WEST: the anchor is at the bottom-left of the object.
+ * @GOO_CANVAS_ANCHOR_SOUTH_EAST: the anchor is at the bottom-right of the object.
+ * @GOO_CANVAS_ANCHOR_WEST: the anchor is on the left of the object, centered vertically.
+ * @GOO_CANVAS_ANCHOR_EAST: the anchor is on the right of the object, centered vertically.
+ * @GOO_CANVAS_ANCHOR_N: see GOO_CANVAS_ANCHOR_NORTH.
+ * @GOO_CANVAS_ANCHOR_NW: see GOO_CANVAS_ANCHOR_NORTH_WEST.
+ * @GOO_CANVAS_ANCHOR_NE: see GOO_CANVAS_ANCHOR_NORTH_EAST.
+ * @GOO_CANVAS_ANCHOR_S: see GOO_CANVAS_ANCHOR_SOUTH.
+ * @GOO_CANVAS_ANCHOR_SW: see GOO_CANVAS_ANCHOR_SOUTH_WEST.
+ * @GOO_CANVAS_ANCHOR_SE: see GOO_CANVAS_ANCHOR_SOUTH_EAST.
+ * @GOO_CANVAS_ANCHOR_W: see GOO_CANVAS_ANCHOR_WEST.
+ * @GOO_CANVAS_ANCHOR_E: see GOO_CANVAS_ANCHOR_EAST.
+ *
+ * GooCanvasAnchorType is used to specify the positions of objects relative to
+ * a particular anchor point.
+ */
+typedef enum
+{
+ GOO_CANVAS_ANCHOR_CENTER,
+ GOO_CANVAS_ANCHOR_NORTH,
+ GOO_CANVAS_ANCHOR_NORTH_WEST,
+ GOO_CANVAS_ANCHOR_NORTH_EAST,
+ GOO_CANVAS_ANCHOR_SOUTH,
+ GOO_CANVAS_ANCHOR_SOUTH_WEST,
+ GOO_CANVAS_ANCHOR_SOUTH_EAST,
+ GOO_CANVAS_ANCHOR_WEST,
+ GOO_CANVAS_ANCHOR_EAST,
+ GOO_CANVAS_ANCHOR_N = GOO_CANVAS_ANCHOR_NORTH,
+ GOO_CANVAS_ANCHOR_NW = GOO_CANVAS_ANCHOR_NORTH_WEST,
+ GOO_CANVAS_ANCHOR_NE = GOO_CANVAS_ANCHOR_NORTH_EAST,
+ GOO_CANVAS_ANCHOR_S = GOO_CANVAS_ANCHOR_SOUTH,
+ GOO_CANVAS_ANCHOR_SW = GOO_CANVAS_ANCHOR_SOUTH_WEST,
+ GOO_CANVAS_ANCHOR_SE = GOO_CANVAS_ANCHOR_SOUTH_EAST,
+ GOO_CANVAS_ANCHOR_W = GOO_CANVAS_ANCHOR_WEST,
+ GOO_CANVAS_ANCHOR_E = GOO_CANVAS_ANCHOR_EAST
+} GooCanvasAnchorType;
+
typedef union _GooCanvasPathCommand GooCanvasPathCommand;
/* Note that the command type is always the first element in each struct, so
@@ -248,6 +292,7 @@ typedef struct _GooCanvasLineDash GooCanvasLineDash;
*/
struct _GooCanvasLineDash
{
+ /*< public >*/
int ref_count;
int num_dashes;
double *dashes;
diff --git a/src/goocanvaswidget.c b/src/goocanvaswidget.c
index 88089de..6d1ceac 100644
--- a/src/goocanvaswidget.c
+++ b/src/goocanvaswidget.c
@@ -62,7 +62,7 @@ goo_canvas_widget_init (GooCanvasWidget *witem)
witem->y = 0.0;
witem->width = -1.0;
witem->height = -1.0;
- witem->anchor = GTK_ANCHOR_NW;
+ witem->anchor = GOO_CANVAS_ANCHOR_NW;
}
@@ -89,7 +89,7 @@ goo_canvas_widget_init (GooCanvasWidget *witem)
* GtkWidget *entry = gtk_entry_new ();
* GooCanvasItem *witem = goo_canvas_widget_new (mygroup, entry,
* 100, 100, -1, -1,
- * "anchor", GTK_ANCHOR_CENTER,
+ * "anchor", GOO_CANVAS_ANCHOR_CENTER,
* NULL);
* </programlisting></informalexample>
*
@@ -144,18 +144,18 @@ goo_canvas_widget_new (GooCanvasItem *parent,
/* Returns the anchor position, within the given width. */
static gdouble
-goo_canvas_widget_anchor_horizontal_pos (GtkAnchorType anchor,
+goo_canvas_widget_anchor_horizontal_pos (GooCanvasAnchorType anchor,
gdouble width)
{
switch(anchor)
{
- case GTK_ANCHOR_N:
- case GTK_ANCHOR_CENTER:
- case GTK_ANCHOR_S:
+ case GOO_CANVAS_ANCHOR_N:
+ case GOO_CANVAS_ANCHOR_CENTER:
+ case GOO_CANVAS_ANCHOR_S:
return width / 2.0;
- case GTK_ANCHOR_NE:
- case GTK_ANCHOR_E:
- case GTK_ANCHOR_SE:
+ case GOO_CANVAS_ANCHOR_NE:
+ case GOO_CANVAS_ANCHOR_E:
+ case GOO_CANVAS_ANCHOR_SE:
return width;
default:
return 0.0;
@@ -165,18 +165,18 @@ goo_canvas_widget_anchor_horizontal_pos (GtkAnchorType anchor,
/* Returns the anchor position, within the given height. */
static gdouble
-goo_canvas_widget_anchor_vertical_pos (GtkAnchorType anchor,
+goo_canvas_widget_anchor_vertical_pos (GooCanvasAnchorType anchor,
gdouble height)
{
switch (anchor)
{
- case GTK_ANCHOR_W:
- case GTK_ANCHOR_CENTER:
- case GTK_ANCHOR_E:
+ case GOO_CANVAS_ANCHOR_W:
+ case GOO_CANVAS_ANCHOR_CENTER:
+ case GOO_CANVAS_ANCHOR_E:
return height / 2.0;
- case GTK_ANCHOR_SW:
- case GTK_ANCHOR_S:
- case GTK_ANCHOR_SE:
+ case GOO_CANVAS_ANCHOR_SW:
+ case GOO_CANVAS_ANCHOR_S:
+ case GOO_CANVAS_ANCHOR_SE:
return height;
default:
return 0.0;
@@ -568,8 +568,8 @@ goo_canvas_widget_class_init (GooCanvasWidgetClass *klass)
g_param_spec_enum ("anchor",
_("Anchor"),
_("How to position the widget relative to the item's x and y coordinate settings"),
- GTK_TYPE_ANCHOR_TYPE,
- GTK_ANCHOR_NW,
+ GOO_TYPE_CANVAS_ANCHOR_TYPE,
+ GOO_CANVAS_ANCHOR_NW,
G_PARAM_READWRITE));
g_object_class_override_property (gobject_class, PROP_VISIBILITY,
diff --git a/src/goocanvaswidget.h b/src/goocanvaswidget.h
index 7d10fe2..48b7998 100644
--- a/src/goocanvaswidget.h
+++ b/src/goocanvaswidget.h
@@ -35,7 +35,7 @@ struct _GooCanvasWidget
GtkWidget *widget;
gdouble x, y, width, height;
- GtkAnchorType anchor;
+ GooCanvasAnchorType anchor;
};
struct _GooCanvasWidgetClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]