/* -*- Mode: C; c-basic-offset: 4 -*- */
%%
headers
#include <Python.h>
#define NO_IMPORT_PYGOBJECT
#include <pygobject.h>
#include <pymatecorba.h>
#include <matecomponent.h>
#include <matecomponent/matecomponent-ui-config-widget.h>
#include "config.h"

%%
modulename matecomponent.ui
%%
init
    init_pymatecorba();
%%
import gobject.GObject as PyGObject_Type
import gtk.AccelGroup as PyGtkAccelGroup_Type
import gtk.Bin as PyGtkBin_Type
import gtk.Box as PyGtkBox_Type
import gtk.Container as PyGtkContainer_Type
import gtk.Dialog as PyGtkDialog_Type
import gtk.Image as PyGtkImage_Type
import gtk.Menu as PyGtkMenu_Type
import gtk.MenuBar as PyGtkMenuBar_Type
import gtk.Plug as PyGtkPlug_Type
import gtk.Socket as PyGtkSocket_Type
import gtk.Tooltips as PyGtkTooltips_Type
import gtk.VBox as PyGtkVBox_Type
import gtk.Widget as PyGtkWidget_Type
import gtk.Window as PyGtkWindow_Type
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
import matecanvas.CanvasItem as PyMateCanvasItem_Type
import matecomponent._matecomponent.Object as PyMateComponentObject_Type
import matecomponent._matecomponent.PropertyBag as PyMateComponentPropertyBag_Type
%%
ignore-glob
  *_get_type
  *_construct
%%
ignore
  matecomponent_ui_component_new_default
  matecomponent_ui_node_*
%%
override matecomponent_ui_component_add_verb kwargs
static PyObject *
_wrap_matecomponent_ui_component_add_verb (PyGObject * self,
				    PyObject *  args,
				    PyObject *  kwargs)
{
    static char *kwlist[] = { "cname", "callback", "extra_data", NULL };
    PyObject *callback, *param=NULL;
    char *cname;

    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
				      "sO|O:MateComponentUIComponent.add_verb", kwlist,
				      &cname, &callback, &param)) {
	return NULL;
    }

    if (!PyCallable_Check (callback)) {
        PyErr_SetString (PyExc_TypeError, "second arg not callable");
	return NULL;
    }

    matecomponent_ui_component_add_verb_full (MATECOMPONENT_UI_COMPONENT (self->obj),
				       cname,
				       pyg_closure_new (callback, param, NULL));
    Py_INCREF (Py_None);
    return Py_None;
}
%%
override matecomponent_ui_component_add_verb_list kwargs
static PyObject *
_wrap_matecomponent_ui_component_add_verb_list (PyGObject * self,
					 PyObject *  args,
					 PyObject *  kwargs)
{
    static char *kwlist[] = { "list", "extra_data", NULL };    
    PyObject *          list;
    PyObject *          params = NULL;
    MateComponentUIComponent * uic;
    int                 len, i;
    PyObject *          item;
    char *              cname;
    PyObject *          callback;
    
    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
				      "O|O:MateComponentUIComponent.add_verb_list", 
				      kwlist, &list, &params)) {
	return NULL;
    }

    if (!PySequence_Check (list)) {
	PyErr_SetString (PyExc_TypeError, "entries must be a sequence");
	return NULL;
    }

    uic = MATECOMPONENT_UI_COMPONENT (self->obj);
    len = PySequence_Size (list);
    for (i = 0; i < len; i++) {
	item = PySequence_GetItem (list, i);
	Py_DECREF (item);
	
	if (!PyArg_ParseTuple (item, "sO", &cname, &callback)) {
	    return NULL;
	}

	matecomponent_ui_component_add_verb_full (uic, cname,
					   pyg_closure_new (callback, params, NULL));
    }

    Py_INCREF(Py_None);
    return Py_None;
}
%%
override matecomponent_ui_component_add_listener kwargs
static PyObject *
_wrap_matecomponent_ui_component_add_listener (PyGObject * self,
				        PyObject *  args,
				        PyObject *  kwargs)
{
    static char *kwlist[] = { "id", "callback", "extra_data", NULL };
    PyObject *callback, *param=NULL;
    char *id;

    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
				      "sO|O:MateComponentUIComponent.add_listener",
				      kwlist, &id, &callback, &param))
	return NULL;

    if (!PyCallable_Check (callback)) {
        PyErr_SetString (PyExc_TypeError, "second arg not callable");
	return NULL;
    }

    matecomponent_ui_component_add_listener_full (MATECOMPONENT_UI_COMPONENT (self->obj),
				           id,
				           pyg_closure_new (callback, param, NULL));
    Py_INCREF (Py_None);
    return Py_None;
}
%%
override matecomponent_widget_new_control kwargs
static int
_wrap_matecomponent_widget_new_control(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "object", "uic", NULL };
    PyObject *object;
    PyObject *pyuic = Py_None;
    CORBA_Environment ev;
    MateComponent_UIContainer uic = CORBA_OBJECT_NIL;
    
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				     "O|O:MateComponentWidget.__init__",
				     kwlist, &object, &pyuic)) {
        return -1;
    }

    CORBA_exception_init (&ev);

    if (PyObject_TypeCheck(pyuic, &PyCORBA_Object_Type)) {
	gboolean is_uic = CORBA_Object_is_a(((PyCORBA_Object *)pyuic)->objref,
					    "IDL:MateComponent/UIContainer:1.0", &ev);
	if (pymatecorba_check_ex(&ev))
	    return -1;
	if (!is_uic) {
	    PyErr_SetString (PyExc_TypeError, "uic must be a MateComponent.UIContainer");
	    return -1;
	}
	uic = (MateComponent_UIContainer)((PyCORBA_Object *)pyuic)->objref;
    } else if (pyuic != Py_None) {
	PyErr_SetString (PyExc_TypeError, "uic must be a MateComponent.UIContainer");
	return -1;
    }
    
	
    if (PyString_Check (object)) {
	self->obj = (GObject *)matecomponent_widget_new_control(PyString_AsString (object), uic);
    } else if (PyObject_TypeCheck(object, &PyCORBA_Object_Type)) {
	self->obj = (GObject *)matecomponent_widget_new_control_from_objref(((PyCORBA_Object *)object)->objref, uic);
    } else {
	PyErr_SetString(PyExc_TypeError, "object should be a string or a MateComponent.Control");	
	return -1;
    }
    
    if (!self->obj) {
        PyErr_SetString(PyExc_RuntimeError, "could not create MateComponentControl object");
        return -1;
    }
    
    pygobject_register_wrapper((PyObject *)self);
    return 0;
}

%%
override matecomponent_ui_component_new
static int
_wrap_matecomponent_ui_component_new(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "name", NULL };
    char *name = NULL;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s:MateComponentUIComponent.__init__", kwlist, &name))
        return -1;
    if (name)
	self->obj = (GObject *)matecomponent_ui_component_new(name);
    else
	self->obj = (GObject *)matecomponent_ui_component_new_default();

    if (!self->obj) {
        PyErr_SetString(PyExc_RuntimeError, "could not create MateComponentUIComponent object");
        return -1;
    }
    g_object_ref (self->obj);
    pygobject_register_wrapper((PyObject *)self);
    return 0;
}
%%
override libmatecomponent_ui_module_info_get noargs
static PyObject *
_wrap_libmatecomponent_ui_module_info_get(PyObject *self)
{
    MateModuleInfo *ret;

    ret = (MateModuleInfo *) libmatecomponent_ui_module_info_get();
    /* pyg_boxed_new handles NULL checking */
    return pyg_boxed_new(MATE_TYPE_MODULE_INFO, ret, TRUE, TRUE);
}
%%
override matecomponent_ui_gtk_module_info_get noargs
static PyObject *
_wrap_matecomponent_ui_gtk_module_info_get(PyObject *self)
{
    MateModuleInfo *ret;

    ret = (MateModuleInfo *) matecomponent_ui_gtk_module_info_get();
    /* pyg_boxed_new handles NULL checking */
    return pyg_boxed_new(MATE_TYPE_MODULE_INFO, ret, TRUE, TRUE);
}
