/***************************************************************************
                            QAccessibleObject.cpp -  description
                             -------------------
    begin                : Wed Nov 21 17:05:56 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 17:05:56 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
***************************************************************************/

#define _BOOL_H_
#include <qaccessible.h>
#include <qstring.h>
#include <qcstring.h>

#include <qtjava/QtSupport.h>
#include <qtjava/QAccessibleObject.h>

#if defined(QT_ACCESSIBILITY_SUPPORT)

class QAccessibleObjectJBridge : public QAccessibleObject
{
public:
	QAccessibleObjectJBridge(QObject* object) : QAccessibleObject(object) {}
	~QAccessibleObjectJBridge() {QtSupport::qtKeyDeleted(this);}
	QObject * protected_object() {
		return (QObject *) QAccessibleObject::object();
	}
	void childEvent(QChildEvent* arg1) {
		if (! QtSupport::eventDelegate(this, "childEvent", arg1, "org.kde.qt.QChildEvent")) {
			QObject::childEvent(arg1);
		}
		return;
	}
	void customEvent(QCustomEvent* arg1) {
		if (! QtSupport::eventDelegate(this, "customEvent", arg1, "org.kde.qt.QCustomEvent")) {
			QObject::customEvent(arg1);
		}
		return;
	}
	void timerEvent(QTimerEvent* arg1) {
		if (! QtSupport::eventDelegate(this, "timerEvent", arg1, "org.kde.qt.QTimerEvent")) {
			QObject::timerEvent(arg1);
		}
		return;
	}
};


JNIEXPORT void JNICALL
Java_org_kde_qt_QAccessibleObject_newQAccessibleObject(JNIEnv *env, jobject obj, jobject object)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new QAccessibleObjectJBridge((QObject*) QtSupport::getQt(env, object)));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QAccessibleObject_finalize(JNIEnv *env, jobject obj)
{
	if (QtSupport::allocatedInJavaWorld(env, obj) && ((QAccessibleObject*)QtSupport::getQt(env, obj))->parent() == (QObject *) 0) {
		delete (QAccessibleObject*)QtSupport::getQt(env, obj);
		QtSupport::setQt(env, obj, 0);
	}
	return;
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QAccessibleObject_queryInterface(JNIEnv *env, jobject obj, jobject arg1, jobject arg2)
{
	return (jlong) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->queryInterface((QUuid&) *(QUuid *) QtSupport::getQt(env, arg1), (QUnknownInterface**) QtSupport::getQt(env, arg2));
}

JNIEXPORT  JNICALL
Java_org_kde_qt_QAccessibleObject_isValid(JNIEnv *env, jobject obj)
{
	return () ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->isValid();
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QAccessibleObject_object(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->protected_object(), "org.kde.qt.QObject");
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QAccessibleObject_isValid(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->isValid();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QAccessibleObject_childCount(JNIEnv *env, jobject obj)
{
	return (jint) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->childCount();
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QAccessibleObject_queryChild(JNIEnv *env, jobject obj, jint control, jobject arg1)
{
	return (jlong) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->queryChild((int) control, (QAccessibleInterface**) QtSupport::getQt(env, arg1));
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QAccessibleObject_queryParent(JNIEnv *env, jobject obj, jobject arg1)
{
	return (jlong) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->queryParent((QAccessibleInterface**) QtSupport::getQt(env, arg1));
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QAccessibleObject_controlAt(JNIEnv *env, jobject obj, jint x, jint y)
{
	return (jint) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->controlAt((int) x, (int) y);
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QAccessibleObject_rect(JNIEnv *env, jobject obj, jint control)
{
	QRect _r= ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->rect((int) control);
	return (jobject) QtSupport::objectForQtKey(env, (void *)new QRect(_r.left(),_r.top(),_r.width(),_r.height()), "org.kde.qt.QRect", TRUE);
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QAccessibleObject_navigate(JNIEnv *env, jobject obj, jint direction, jint startControl)
{
	return (jint) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->navigate((NavDirection) direction, (int) startControl);
}

JNIEXPORT jstring JNICALL
Java_org_kde_qt_QAccessibleObject_text(JNIEnv *env, jobject obj, jint t, jint control)
{
	QString  _qstring;
	_qstring = ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->text((Text) t, (int) control);
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QAccessibleObject_role(JNIEnv *env, jobject obj, jint control)
{
	return (jint) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->role((int) control);
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QAccessibleObject_state(JNIEnv *env, jobject obj, jint control)
{
	return (jint) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->state((int) control);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QAccessibleObject_doDefaultAction(JNIEnv *env, jobject obj, jint control)
{
	return (jboolean) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->doDefaultAction((int) control);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QAccessibleObject_setFocus(JNIEnv *env, jobject obj, jint control)
{
	return (jboolean) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->setFocus((int) control);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QAccessibleObject_setSelected(JNIEnv *env, jobject obj, jint control, jboolean on, jboolean extend)
{
	return (jboolean) ((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->setSelected((int) control, (bool) on, (bool) extend);
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QAccessibleObject_clearSelection(JNIEnv *env, jobject obj)
{
	((QAccessibleObjectJBridge*) QtSupport::getQt(env, obj))->clearSelection();
	return;
}

#endif
