/* -*- Mode: C; c-basic-offset: 4 -*- */
%%
headers
#include <Python.h>

#define NO_IMPORT_PYGOBJECT
#define NO_IMPORT_PYGTK

#include <pygobject.h>
#include <pygtk/pygtk.h>
#include <pycairo/pycairo.h>

#include <evince-document.h>
#include <evince-view.h>

extern Pycairo_CAPI_t *Pycairo_CAPI;

/* A boxed type for GdkRegion until one gets into gtk+ itself. */
#ifdef GDK_TYPE_REGION
# define PYGDK_TYPE_REGION  GDK_TYPE_REGION 
#else
GType pygdk_region_get_type (void) G_GNUC_CONST;
GType pygdk_region_get_type (void)
{
  static GType our_type = 0;
  
  if (our_type == 0)
    our_type = g_boxed_type_register_static ("GdkRegion",
					     (GBoxedCopyFunc)gdk_region_copy,
					     (GBoxedFreeFunc)gdk_region_destroy);
  return our_type;
}
# define PYGDK_TYPE_REGION (pygdk_region_get_type ())
#endif /* GDK_TYPE_REGION */



%%
modulename ev

%%
import gobject.GObject as PyGObject_Type
import gtk.Widget as PyGtkWidget_Type
import gtk.ScrolledWindow as PyGtkScrolledWindow_Type
import gtk.TreeModel as PyGtkTreeModel_Type
import gtk.Layout as PyGtkLayout_Type
import gtk.PrintSettings as PyGtkPrintSettings_Type
import gtk.PageSetup as PyGtkPageSetup_Type
import gtk.Window as PyGtkWindow_Type
import gtk.gdk.Screen as PyGdkScreen_Type
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
import gtk.gdk.Drawable as PyGdkDrawable_Type

%%
override ev_view_find_changed kwargs
/* This function usually takes a GList of search results and hence must be
 * wrapped manually. In our override, we modify it to take the corresponding 
 * job to avoid having to unpack/repack lists.
 */
static PyObject *
_wrap_ev_view_find_changed(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "job", "page", NULL };
    PyGObject *job;
    int page;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!i:EvView.find_changed",
            kwlist, &PyEvJobFind_Type, &job, &page))
        return NULL;

    ev_view_find_changed(EV_VIEW(self->obj),
        ev_job_find_get_results(EV_JOB_FIND(job->obj)),
        page);

    Py_RETURN_NONE;
}
%%
override ev_job_find_new kwargs
/*
 * We wrap this here because the object takes an EvDocument gpointer as a
 * construction property, and you can't do gpointers from python.
 * We can't make the property be a GObject parameter because EV_DOCUMENT_TYPE
 * is an interface and not a G_OBJECT type.
 */
static int
_wrap_ev_job_find_new(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "document", "start_page", "n_pages", "text",
        "case_sensitive",  NULL };
    PyGObject *document;
    gint start_page, n_pages;
    const gchar *text;
    gboolean case_sensitive;
    EvJob *job;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!iizi:EvJobFind.__init__",
            kwlist, &PyEvDocument_Type, &document, &start_page, &n_pages,
            &text, &case_sensitive))
        return -1;

    job = ev_job_find_new(EV_DOCUMENT(document->obj), start_page, n_pages, text,
                          case_sensitive);
    if (!job) {
        PyErr_SetString(PyExc_RuntimeError, "could not create JobFind object");
        return -1;
    } else {
        self->obj = (GObject*) job;
        pygobject_register_wrapper((PyObject *)self);
        return 0;
    }
}
%%
