summaryrefslogtreecommitdiffstats
path: root/qtjava/javalib/qtjava/qtjava.cpp
blob: bb83739ec654cf639db988df01303d4b76ce9df9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/***************************************************************************
                          qtjava.cpp  -  description
                             -------------------
    begin                : Tue Oct 31 2000
    copyright            : (C) 2000 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    written by           : Richard Dale.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

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

#include <tqobject.h>

JNIEXPORT jobject JNICALL
Java_org_kde_qt_qtjava_allocateInstance(JNIEnv * env, jclass cls, jclass targetClass)
{
	(void) cls;
	return (jobject) env->AllocObject(targetClass);
}


JNIEXPORT jclass JNICALL
Java_org_kde_qt_qtjava_classFromQtMetaData(JNIEnv * env, jclass cls, jclass approximateClass, jstring approximateClassName, jlong qt)
{
	jclass			exactClass;
	const char *	className;
static char fullyQualifiedClassName[200];

	(void) cls;
	(void) approximateClassName;
	className = (const char *)((TQObject*) qt)->className();
	
	if (className[0] == 'Q') {
		(void) sprintf(fullyQualifiedClassName, "org/kde/qt/%s", className);
	} else if (className[0] == 'K') {
		(void) sprintf(fullyQualifiedClassName, "org/kde/koala/%s", className);
	} else {
		(void) strcpy(fullyQualifiedClassName, className);
		exactClass = env->FindClass(fullyQualifiedClassName);
	
		if (exactClass != 0) {
			// An unqualified classname, with no package, has been found
			return exactClass;
		}
		
		// Assume that any classes are part of org.kde.koala if they don't start with 'K' or 'Q',
		// but haven't just been found without a package qualifier.
		env->ExceptionClear();
		(void) sprintf(fullyQualifiedClassName, "org/kde/koala/%s", className);
	}
	
	exactClass = env->FindClass(fullyQualifiedClassName);
	
	if (exactClass == 0) {
		env->ExceptionClear();
		return approximateClass;
	}
	
	return exactClass;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_qtjava_registerJVM(JNIEnv * env, jclass cls)
{
	(void) cls;
	QtSupport::registerJVM(env);	
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_qtjava_setAllocatedInJavaWorld(JNIEnv * env, jclass cls, jobject obj, jboolean yn)
{
	(void) cls;
	QtSupport::setAllocatedInJavaWorld(env, obj, (bool) yn);
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_qtjava_allocatedInJavaWorld(JNIEnv * env, jclass cls, jobject obj)
{
	(void) cls;
	return QtSupport::allocatedInJavaWorld(env, obj);
}

JNIEXPORT void JNICALL
Java_org_kde_qt_qtjava_setQt(JNIEnv * env, jclass cls, jobject obj, jlong qt)
{
	(void) cls;
	QtSupport::setQt(env, obj, (void *) qt);
	return;
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_qtjava_getQt(JNIEnv * env, jclass cls, jobject obj)
{
	(void) cls;
	return (jlong) QtSupport::getQt(env, obj);
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_qtjava_newJavaSignal(JNIEnv * env, jclass cls)
{
	(void) env;
	(void) cls;
	return (jlong) new JavaSignal();
}

JNIEXPORT void JNICALL
Java_org_kde_qt_qtjava_setJavaSlotFactory(JNIEnv * env, jclass cls)
{
	(void) env;
	(void) cls;
	JavaSlot::setJavaSlotFactory(new JavaSlotFactory());
	return;
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_qtjava_newJavaSlot(JNIEnv * env, jclass cls, jobject receiver, jstring member)
{
	(void) cls;
	return (jlong) JavaSlot::createJavaSlot(env, receiver, member);
}