%%
headers
/* vim: syntax=c
 */
#include <Python.h>
#define NO_IMPORT_PYGOBJECT 1
#define NO_IMPORT_PYGTK 1
#include <pygobject.h>
#include <pygtk/pygtk.h>

#include <diacanvas/dia-canvas-view.h>
#include <diacanvas/dia-handle-layer.h>
#include <diacanvas/dia-selector.h>
#include <diacanvas/dia-tool.h>
#include <diacanvas/dia-placement-tool.h>
#include <diacanvas/dia-stack-tool.h>
#include <diacanvas/dia-handle-tool.h>
#include <diacanvas/dia-selection-tool.h>
#include <diacanvas/dia-item-tool.h>
#include <diacanvas/dia-default-tool.h>

/* And some defines to do some casting from one type to another... */
#define dia_canvas_view_item_add_items(a,b) dia_canvas_view_item_add_items((GnomeCanvasGroup*)a,b)
#define dia_tool_button_press(t,o,e) dia_tool_button_press(t,o,(GdkEventButton*)e)
#define dia_tool_button_release(t,o,e) dia_tool_button_release(t,o,(GdkEventButton*)e)
#define dia_tool_motion_notify(t,o,e) dia_tool_motion_notify(t,o,(GdkEventMotion*)e)
#define dia_tool_key_press(t,o,e) dia_tool_key_press(t,o,(GdkEventKey*)e)
#define dia_tool_key_release(t,o,e) dia_tool_key_release(t,o,(GdkEventKey*)e)

%%
import gobject.GObject as PyGObject_Type
import gtk.gdk.Drawable as PyGdkDrawable_Type
import gnome.canvas.Canvas as PyGnomeCanvas_Type
import gnome.canvas.CanvasItem as PyGnomeCanvasItem_Type
import gnome.canvas.CanvasGroup as PyGnomeCanvasGroup_Type
import diacanvas.Canvas as PyDiaCanvas_Type
import diacanvas.CanvasItem as PyDiaCanvasItem_Type
import diacanvas.Handle as PyDiaHandle_Type
%%
ignore-glob
  *_get_type
  _*
%%
override dia_canvas_view_select_rectangle kwargs
static PyObject *
_wrap_dia_canvas_view_select_rectangle(PyGObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "rect", NULL };
	PyObject *py_rect;
	GValue v_rect = { 0, };
	DiaRectangle *rect = NULL;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:DiaCanvasView.select_rectangle", kwlist, &py_rect))
		return NULL;

	g_value_init (&v_rect, DIA_TYPE_RECTANGLE);

	if (pyg_value_from_pyobject (&v_rect, py_rect))
		return NULL;

	rect = g_value_get_boxed (&v_rect);

	dia_canvas_view_select_rectangle(DIA_CANVAS_VIEW(self->obj), rect);

	g_value_unset (&v_rect);

	Py_INCREF(Py_None);
	return Py_None;
}
%%
override-attr DiaCanvasView.selected_items
static PyObject *
_wrap_dia_canvas_view__get_selected_items (PyGObject *self, void *closure)
{
	GList *l;
	PyObject *list;
	int i;

	l = DIA_CANVAS_VIEW (self->obj)->selected_items;
	list = PyList_New (g_list_length (l));

	for (i = 0 ; l != NULL; l = l->next) {
		// PyList_SetItem() steals the reference
		if (PyList_SetItem (list, i++, pygobject_new (l->data)) != 0) {
			PyErr_Print();
			PyErr_Clear();
			break;
		}
	}

	return list;
}
