[cairo-commit] gtkcairo/gtkcairo Makefile.am,NONE,1.1 gtkcairo.c,NONE,1.1 gtkcairo.h,NONE,1.1

Carl Worth commit at pdx.freedesktop.org
Tue Nov 18 07:17:09 PST 2003


Committed by: cworth

Update of /cvs/cairo/gtkcairo/gtkcairo
In directory pdx:/tmp/cvs-serv6348/gtkcairo

Added Files:
	Makefile.am gtkcairo.c gtkcairo.h 
Log Message:
Initial import of gtkcairo (courtesy of Evan Martin <martine at danga.com>)

--- NEW FILE: Makefile.am ---
lib_LTLIBRARIES = libgtkcairo.la
include_HEADERS = gtkcairo.h
 
libgtkcairo_la_SOURCES = \
	gtkcairo.c \
	gtkcairo.h

libgtkcairo_la_LDFLAGS = -version-info @VERSION_INFO@

INCLUDES = $(GTKCAIRO_CFLAGS)

libgtkcairo_la_LIBADD = $(GTKCAIRO_LIBS)


--- NEW FILE: gtkcairo.c ---
/* gtkcairo - GTK+ widget for displaying a cairo surface.
 *
 * Hacked up by Evan Martin <martine at danga.com>.
 *
 * Originally from grrobot:
 *
 * Copyright © 2003 Carl Worth
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice appear in all copies
 * and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the name of Carl Worth
 * not be used in advertising or publicity pertaining to distribution
 * of the software without specific, written prior permission.
 * Carl Worth makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without express
 * or implied warranty.
 * 
 * CARL WORTH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 * NO EVENT SHALL CARL WORTH BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author: Carl Worth <carl at theworths.org>
 */

#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include <gdk/gdkx.h>

#include <cairo.h>

/* XXX  X11-specific: */
#include <cairo-xlib.h>
/* XXX  :X11-specific */

#include "gtkcairo.h"

struct _GtkCairo
{
    GtkWidget widget;

    cairo_t *cairo;
};

struct _GtkCairoClass
{
    GtkWidgetClass parent_class;
};

static void gtk_cairo_class_init               (GtkCairoClass    *klass);
static void gtk_cairo_init                     (GtkCairo         *gtkcairo);
static void gtk_cairo_destroy                  (GtkObject        *object);
static void gtk_cairo_realize                  (GtkWidget        *widget);
static void gtk_cairo_size_allocate            (GtkWidget     *widget,
                                                GtkAllocation *allocation);
static gint gtk_cairo_expose                   (GtkWidget        *widget,
                                                GdkEventExpose   *event);

static GtkWidgetClass *parent_class = NULL;

GType
gtk_cairo_get_type ()
{
	static GType gtk_cairo_type = 0;

	if (!gtk_cairo_type) {
		static const GTypeInfo gtk_cairo_info = {
			sizeof (GtkCairoClass),
			NULL,
			NULL,
			(GClassInitFunc) gtk_cairo_class_init,
			NULL,
			NULL,
			sizeof (GtkCairo),
			0,
			(GInstanceInitFunc) gtk_cairo_init,
		};

		gtk_cairo_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkCairo", &gtk_cairo_info, 0);
	}

	return gtk_cairo_type;
}

static void
gtk_cairo_class_init (GtkCairoClass *class)
{
	GtkObjectClass *object_class;
	GtkWidgetClass *widget_class;

	object_class = (GtkObjectClass*) class;
	widget_class = (GtkWidgetClass*) class;

	parent_class = gtk_type_class (gtk_widget_get_type ());

	object_class->destroy = gtk_cairo_destroy;

	widget_class->realize = gtk_cairo_realize;
	widget_class->expose_event = gtk_cairo_expose;
	widget_class->size_allocate = gtk_cairo_size_allocate;
}

static void
gtk_cairo_init (GtkCairo *gtkcairo)
{
	gtkcairo->cairo = cairo_create();
}

GtkWidget *
gtk_cairo_new (void)
{
	GtkWidget *gtkcairo;
	
	gtkcairo = GTK_WIDGET(g_object_new (gtk_cairo_get_type (), NULL));

	gtk_widget_queue_draw (GTK_WIDGET (gtkcairo));

	return gtkcairo;
}

static void
gtk_cairo_destroy (GtkObject *object)
{
	GtkCairo *gtkcairo;

	g_return_if_fail (object != NULL);
	g_return_if_fail (GTK_IS_CAIRO (object));

	gtkcairo = GTK_CAIRO (object);

	cairo_destroy (gtkcairo->cairo);

	if (GTK_OBJECT_CLASS (parent_class)->destroy)
		(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}

static void
gtk_cairo_realize (GtkWidget *widget)
{
	GtkCairo *gtkcairo;
	GdkWindowAttr attributes;
	gint attributes_mask;

	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_IS_CAIRO (widget));

	GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
	gtkcairo = GTK_CAIRO (widget);

	attributes.x = widget->allocation.x;
	attributes.y = widget->allocation.y;
	attributes.width = widget->allocation.width;
	attributes.height = widget->allocation.height;
	attributes.wclass = GDK_INPUT_OUTPUT;
	attributes.window_type = GDK_WINDOW_CHILD;
	attributes.event_mask = gtk_widget_get_events (widget) | 
		GDK_EXPOSURE_MASK/* | GDK_BUTTON_PRESS_MASK | 
		GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
		GDK_POINTER_MOTION_HINT_MASK*/;
	attributes.visual = gtk_widget_get_visual (widget);
	attributes.colormap = gtk_widget_get_colormap (widget);
	
	attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
	widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
	
	widget->style = gtk_style_attach (widget->style, widget->window);
	
	gdk_window_set_user_data (widget->window, widget);

	//gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
}

static void
gtk_cairo_size_allocate (GtkWidget     *widget,
                         GtkAllocation *allocation)
{
	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_IS_CAIRO (widget));
	g_return_if_fail (allocation != NULL);

	widget->allocation = *allocation;

	if (GTK_WIDGET_REALIZED (widget)) {
		gdk_window_move_resize (widget->window,
					allocation->x, allocation->y,
					allocation->width, allocation->height);
	}
}

static gint
gtk_cairo_expose (GtkWidget      *widget,
                  GdkEventExpose *event)
{
	GtkCairo *gtkcairo;
	GdkDrawable *gdkdrawable;
	gint x_off, y_off;

	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (GTK_IS_CAIRO (widget), FALSE);
	g_return_val_if_fail (event != NULL, FALSE);

	gtkcairo = GTK_CAIRO (widget);

	/* Ignore GTK+ and use Cairo for drawing. */
	gdk_window_get_internal_paint_info (widget->window,
			&gdkdrawable, &x_off, &y_off);

	/* XXX  X11-specific: */
	cairo_set_target_drawable (gtkcairo->cairo,
			gdk_x11_drawable_get_xdisplay (gdkdrawable),
			gdk_x11_drawable_get_xid (gdkdrawable));
	/* XXX  :X11-specific */

	return FALSE;
}

cairo_t*
gtk_cairo_get_cairo(GtkCairo *gtkcairo) {
	g_return_val_if_fail (gtkcairo != NULL, NULL);
	g_return_val_if_fail (GTK_IS_CAIRO (gtkcairo), NULL);
	return gtkcairo->cairo;
}

/* vim: set ts=4 sw=4 noet : */

--- NEW FILE: gtkcairo.h ---
/* gtkcairo - GTK+ widget for displaying a cairo surface.
 *
 * Hacked up by Evan Martin <martine at danga.com>.
 *
 * Originally from Ricochet Robots:
 *
 * Copyright © 2003 Carl Worth
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice appear in all copies
 * and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the name of Carl Worth
 * not be used in advertising or publicity pertaining to distribution
 * of the software without specific, written prior permission.
 * Carl Worth makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without express
 * or implied warranty.
 * 
 * CARL WORTH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 * NO EVENT SHALL CARL WORTH BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author: Carl Worth <carl at theworths.org>
 */

#ifndef GTK_CAIRO_H
#define GTK_CAIRO_H

#include <gdk/gdk.h>
#include <gtk/gtkadjustment.h>
#include <gtk/gtkwidget.h>

#include <cairo.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#define GTK_CAIRO(obj)	GTK_CHECK_CAST (obj, gtk_cairo_get_type (), GtkCairo)
#define GTK_CAIRO_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_cairo_get_type (), GtkCairoClass)
#define GTK_IS_CAIRO(obj)	GTK_CHECK_TYPE (obj, gtk_cairo_get_type ())

typedef struct _GtkCairo		GtkCairo;
typedef struct _GtkCairoClass	GtkCairoClass;

GType      gtk_cairo_get_type   (void);
GtkWidget* gtk_cairo_new        (void);

cairo_t*   gtk_cairo_get_cairo  (GtkCairo *gtkcairo);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* GTK_CAIRO_H */





More information about the cairo-commit mailing list