/***************************************************************************
                            Range.cpp -  description
                             -------------------
    begin                : Sun Jan 27 16:22:17 2002
    copyright            : (C) 2000-2001 Lost Highway Ltd.
    email                : Richard_Dale@tipitina.demon.co.uk
    generated by         : duke@tipitina on Sun Jan 27 16:22:17 2002, 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 <dom/dom2_range.h>
#include <qstring.h>
#include <qcstring.h>

#include <qtjava/QtSupport.h>
#include <kdejava/KDESupport.h>
#include <kdejava/Range.h>

class RangeJBridge : public DOM::Range
{
public:
	RangeJBridge() : Range() {}
	RangeJBridge(const DOM::Document rootContainer) : Range(rootContainer) {}
	RangeJBridge(const Range& other) : Range(other) {}
	RangeJBridge(const DOM::Node startContainer, const long startOffset, const DOM::Node endContainer, const long endOffset) : Range(startContainer, startOffset, endContainer, endOffset) {}
	~RangeJBridge() {QtSupport::qtKeyDeleted(this);}
};


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

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_newRange__Lorg_kde_koala_DOMDocument_2(JNIEnv *env, jobject obj, jobject rootContainer)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new RangeJBridge((DOM::Document) *(DOM::Document *) QtSupport::getQt(env, rootContainer)));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_newRange__Lorg_kde_koala_Range_2(JNIEnv *env, jobject obj, jobject other)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new RangeJBridge((DOM::Range&) *(DOM::Range *) QtSupport::getQt(env, other)));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_newRange__Lorg_kde_koala_DOMNode_2JLorg_kde_koala_DOMNode_2J(JNIEnv *env, jobject obj, jobject startContainer, jlong startOffset, jobject endContainer, jlong endOffset)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new RangeJBridge((DOM::Node) *(DOM::Node *) QtSupport::getQt(env, startContainer), (long) startOffset, (DOM::Node) *(DOM::Node *) QtSupport::getQt(env, endContainer), (long) endOffset));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_finalize(JNIEnv *env, jobject obj)
{
	if (QtSupport::allocatedInJavaWorld(env, obj)) {
		delete (DOM::Range*)QtSupport::getQt(env, obj);
		QtSupport::setQt(env, obj, 0);
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_dispose(JNIEnv *env, jobject obj)
{
	Java_org_kde_koala_Range_finalize(env, obj);
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_Range_isDisposed(JNIEnv *env, jobject obj)
{
	return (QtSupport::getQt(env, obj) == 0);
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_Range_startContainer(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new DOM::Node (((DOM::Range*) QtSupport::getQt(env, obj))->startContainer()), "org.kde.koala.DOMNode", TRUE);
}

JNIEXPORT jlong JNICALL
Java_org_kde_koala_Range_startOffset(JNIEnv *env, jobject obj)
{
	return (jlong) ((DOM::Range*) QtSupport::getQt(env, obj))->startOffset();
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_Range_endContainer(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new DOM::Node (((DOM::Range*) QtSupport::getQt(env, obj))->endContainer()), "org.kde.koala.DOMNode", TRUE);
}

JNIEXPORT jlong JNICALL
Java_org_kde_koala_Range_endOffset(JNIEnv *env, jobject obj)
{
	return (jlong) ((DOM::Range*) QtSupport::getQt(env, obj))->endOffset();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_Range_collapsed(JNIEnv *env, jobject obj)
{
	return (jboolean) ((DOM::Range*) QtSupport::getQt(env, obj))->collapsed();
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_Range_commonAncestorContainer(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new DOM::Node (((DOM::Range*) QtSupport::getQt(env, obj))->commonAncestorContainer()), "org.kde.koala.DOMNode", TRUE);
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_setStart(JNIEnv *env, jobject obj, jobject refNode, jlong offset)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->setStart((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, refNode), (long) offset);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_setEnd(JNIEnv *env, jobject obj, jobject refNode, jlong offset)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->setEnd((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, refNode), (long) offset);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_setStartBefore(JNIEnv *env, jobject obj, jobject refNode)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->setStartBefore((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, refNode));
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_setStartAfter(JNIEnv *env, jobject obj, jobject refNode)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->setStartAfter((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, refNode));
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_setEndBefore(JNIEnv *env, jobject obj, jobject refNode)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->setEndBefore((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, refNode));
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_setEndAfter(JNIEnv *env, jobject obj, jobject refNode)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->setEndAfter((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, refNode));
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_collapse(JNIEnv *env, jobject obj, jboolean toStart)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->collapse((bool) toStart);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_selectNode(JNIEnv *env, jobject obj, jobject refNode)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->selectNode((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, refNode));
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_selectNodeContents(JNIEnv *env, jobject obj, jobject refNode)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->selectNodeContents((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, refNode));
	return;
}

JNIEXPORT jshort JNICALL
Java_org_kde_koala_Range_compareBoundaryPoints(JNIEnv *env, jobject obj, jint how, jobject sourceRange)
{
	return (jshort) ((DOM::Range*) QtSupport::getQt(env, obj))->compareBoundaryPoints((DOM::Range::CompareHow) how, (DOM::Range&) *(DOM::Range *) QtSupport::getQt(env, sourceRange));
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_Range_boundaryPointsValid(JNIEnv *env, jobject obj)
{
	return (jboolean) ((DOM::Range*) QtSupport::getQt(env, obj))->boundaryPointsValid();
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_deleteContents(JNIEnv *env, jobject obj)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->deleteContents();
	return;
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_Range_extractContents(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new DOM::DocumentFragment (((DOM::Range*) QtSupport::getQt(env, obj))->extractContents()), "org.kde.koala.DocumentFragment", TRUE);
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_Range_cloneContents(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new DOM::DocumentFragment (((DOM::Range*) QtSupport::getQt(env, obj))->cloneContents()), "org.kde.koala.DocumentFragment", TRUE);
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_insertNode(JNIEnv *env, jobject obj, jobject newNode)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->insertNode((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, newNode));
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_surroundContents(JNIEnv *env, jobject obj, jobject newParent)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->surroundContents((DOM::Node&) *(DOM::Node *) QtSupport::getQt(env, newParent));
	return;
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_Range_cloneRange(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new DOM::Range (((DOM::Range*) QtSupport::getQt(env, obj))->cloneRange()), "org.kde.koala.Range", TRUE);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_Range_toString(JNIEnv *env, jobject obj)
{
	DOM::DOMString _domstring;
	_domstring = ((DOM::Range*) QtSupport::getQt(env, obj))->toString();
	return KDESupport::fromDOMString(env, &_domstring);
}

JNIEXPORT jstring JNICALL
Java_org_kde_koala_Range_toHTML(JNIEnv *env, jobject obj)
{
	DOM::DOMString _domstring;
	_domstring = ((DOM::Range*) QtSupport::getQt(env, obj))->toHTML();
	return KDESupport::fromDOMString(env, &_domstring);
}

JNIEXPORT void JNICALL
Java_org_kde_koala_Range_detach(JNIEnv *env, jobject obj)
{
	((DOM::Range*) QtSupport::getQt(env, obj))->detach();
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_Range_isDetached(JNIEnv *env, jobject obj)
{
	return (jboolean) ((DOM::Range*) QtSupport::getQt(env, obj))->isDetached();
}

JNIEXPORT jobject JNICALL
Java_org_kde_koala_Range_handle(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)((DOM::Range*) QtSupport::getQt(env, obj))->handle(), "org.kde.koala.RangeImpl");
}

JNIEXPORT jboolean JNICALL
Java_org_kde_koala_Range_isNull(JNIEnv *env, jobject obj)
{
	return (jboolean) ((DOM::Range*) QtSupport::getQt(env, obj))->isNull();
}

