summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gnome.c
blob: 30d40ece0a4c1c5bbb22c73ddedfe038b630d41f (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/


/**
 * SWT GNOME natives implementation.
 */ 

/* #define PRINT_FAILED_RCODES */
#define NDEBUG 

#include "swt.h"

#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <libgnome/libgnome.h>
#include <libgnome/gnome-program.h>
#include <libgnomeui/libgnomeui.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomevfs/gnome-vfs-mime-info.h>

#ifndef NO_GnomeVFSMimeApplication
typedef struct GnomeVFSMimeApplication_FID_CACHE {
	int cached;
	jclass clazz;
	jfieldID requires_terminal, supported_uri_schemes, expects_uris, can_open_multiple_files, command, name, id;
} GnomeVFSMimeApplication_FID_CACHE;

GnomeVFSMimeApplication_FID_CACHE GnomeVFSMimeApplicationFc;

void cacheGnomeVFSMimeApplicationFids(JNIEnv *env, jobject lpObject)
{
	if (GnomeVFSMimeApplicationFc.cached) return;
	GnomeVFSMimeApplicationFc.clazz = (*env)->GetObjectClass(env, lpObject);
	GnomeVFSMimeApplicationFc.requires_terminal = (*env)->GetFieldID(env, GnomeVFSMimeApplicationFc.clazz, "requires_terminal", "Z");
	GnomeVFSMimeApplicationFc.supported_uri_schemes = (*env)->GetFieldID(env, GnomeVFSMimeApplicationFc.clazz, "supported_uri_schemes", "I");
	GnomeVFSMimeApplicationFc.expects_uris = (*env)->GetFieldID(env, GnomeVFSMimeApplicationFc.clazz, "expects_uris", "I");
	GnomeVFSMimeApplicationFc.can_open_multiple_files = (*env)->GetFieldID(env, GnomeVFSMimeApplicationFc.clazz, "can_open_multiple_files", "Z");
	GnomeVFSMimeApplicationFc.command = (*env)->GetFieldID(env, GnomeVFSMimeApplicationFc.clazz, "command", "I");
	GnomeVFSMimeApplicationFc.name = (*env)->GetFieldID(env, GnomeVFSMimeApplicationFc.clazz, "name", "I");
	GnomeVFSMimeApplicationFc.id = (*env)->GetFieldID(env, GnomeVFSMimeApplicationFc.clazz, "id", "I");
	GnomeVFSMimeApplicationFc.cached = 1;
}

GnomeVFSMimeApplication *getGnomeVFSMimeApplicationFields(JNIEnv *env, jobject lpObject, GnomeVFSMimeApplication *lpStruct)
{
	if (!GnomeVFSMimeApplicationFc.cached) cacheGnomeVFSMimeApplicationFids(env, lpObject);
	lpStruct->requires_terminal = (gboolean)(*env)->GetBooleanField(env, lpObject, GnomeVFSMimeApplicationFc.requires_terminal);
	lpStruct->supported_uri_schemes = (GList *)(*env)->GetIntField(env, lpObject, GnomeVFSMimeApplicationFc.supported_uri_schemes);
	lpStruct->expects_uris = (GnomeVFSMimeApplicationArgumentType)(*env)->GetIntField(env, lpObject, GnomeVFSMimeApplicationFc.expects_uris);
	lpStruct->can_open_multiple_files = (gboolean)(*env)->GetBooleanField(env, lpObject, GnomeVFSMimeApplicationFc.can_open_multiple_files);
	lpStruct->command = (char *)(*env)->GetIntField(env, lpObject, GnomeVFSMimeApplicationFc.command);
	lpStruct->name = (char *)(*env)->GetIntField(env, lpObject, GnomeVFSMimeApplicationFc.name);
	lpStruct->id = (char *)(*env)->GetIntField(env, lpObject, GnomeVFSMimeApplicationFc.id);
	return lpStruct;
}

void setGnomeVFSMimeApplicationFields(JNIEnv *env, jobject lpObject, GnomeVFSMimeApplication *lpStruct)
{
	if (!GnomeVFSMimeApplicationFc.cached) cacheGnomeVFSMimeApplicationFids(env, lpObject);
	(*env)->SetBooleanField(env, lpObject, GnomeVFSMimeApplicationFc.requires_terminal, (jboolean)lpStruct->requires_terminal);
	(*env)->SetIntField(env, lpObject, GnomeVFSMimeApplicationFc.supported_uri_schemes, (jint)lpStruct->supported_uri_schemes);
	(*env)->SetIntField(env, lpObject, GnomeVFSMimeApplicationFc.expects_uris, (jint)lpStruct->expects_uris);
	(*env)->SetBooleanField(env, lpObject, GnomeVFSMimeApplicationFc.can_open_multiple_files, (jboolean)lpStruct->can_open_multiple_files);
	(*env)->SetIntField(env, lpObject, GnomeVFSMimeApplicationFc.command, (jint)lpStruct->command);
	(*env)->SetIntField(env, lpObject, GnomeVFSMimeApplicationFc.name, (jint)lpStruct->name);
	(*env)->SetIntField(env, lpObject, GnomeVFSMimeApplicationFc.id, (jint)lpStruct->id);
}
#endif /* NO_GnomeVFSMimeApplication */

#ifndef NO_LIBGNOME_1MODULE
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_LIBGNOME_1MODULE
	(JNIEnv *env, jclass that)
{
	jint rc;
	/* custom */
	rc = (jint)LIBGNOME_MODULE;
	return rc;
}
#endif

#ifndef NO_GnomeVFSMimeApplication_1sizeof
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_GnomeVFSMimeApplication_1sizeof
	(JNIEnv *env, jclass that)
{
	DEBUG_CALL("GnomeVFSMimeApplication_1sizeof\n")
	return (jint)sizeof(GnomeVFSMimeApplication);
}
#endif

#ifndef NO_gnome_1icon_1lookup
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1icon_1lookup
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jbyteArray arg2, jbyteArray arg3, jint arg4, jbyteArray arg5, jint arg6, jintArray arg7)
{
	jbyte *lparg2=NULL;
	jbyte *lparg3=NULL;
	jbyte *lparg5=NULL;
	jint *lparg7=NULL;
	jint rc;
	DEBUG_CALL("gnome_1icon_1lookup\n")
	if (arg2) lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL);
	if (arg3) lparg3 = (*env)->GetByteArrayElements(env, arg3, NULL);
	if (arg5) lparg5 = (*env)->GetByteArrayElements(env, arg5, NULL);
	if (arg7) lparg7 = (*env)->GetIntArrayElements(env, arg7, NULL);
	rc = (jint)gnome_icon_lookup((GnomeIconTheme *)arg0, (GnomeThumbnailFactory *)arg1, (const char *)lparg2, (const char *)lparg3, (GnomeVFSFileInfo *)arg4, (const char *)lparg5, arg6, (GnomeIconLookupResultFlags *)lparg7);
	if (arg7) (*env)->ReleaseIntArrayElements(env, arg7, lparg7, 0);
	if (arg5) (*env)->ReleaseByteArrayElements(env, arg5, lparg5, 0);
	if (arg3) (*env)->ReleaseByteArrayElements(env, arg3, lparg3, 0);
	if (arg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, 0);
	return rc;
}
#endif

#ifndef NO_gnome_1icon_1theme_1lookup_1icon
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1icon_1theme_1lookup_1icon
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jintArray arg3, jintArray arg4)
{
	jint *lparg3=NULL;
	jint *lparg4=NULL;
	jint rc;
	DEBUG_CALL("gnome_1icon_1theme_1lookup_1icon\n")
	if (arg3) lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL);
	if (arg4) lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL);
	rc = (jint)gnome_icon_theme_lookup_icon((GnomeIconTheme *)arg0, (const char *)arg1, arg2, (const GnomeIconData **)lparg3, lparg4);
	if (arg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0);
	if (arg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0);
	return rc;
}
#endif

#ifndef NO_gnome_1icon_1theme_1new
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1icon_1theme_1new
	(JNIEnv *env, jclass that)
{
	DEBUG_CALL("gnome_1icon_1theme_1new\n")

	return (jint)gnome_icon_theme_new();
}
#endif

#ifndef NO_gnome_1vfs_1get_1registered_1mime_1types
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1vfs_1get_1registered_1mime_1types
	(JNIEnv *env, jclass that)
{
	DEBUG_CALL("gnome_1vfs_1get_1registered_1mime_1types\n")

	return (jint)gnome_vfs_get_registered_mime_types();
}
#endif

#ifndef NO_gnome_1vfs_1init
JNIEXPORT jboolean JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1vfs_1init
	(JNIEnv *env, jclass that)
{
	DEBUG_CALL("gnome_1vfs_1init\n")

	return (jboolean)gnome_vfs_init();
}
#endif

#ifndef NO_gnome_1vfs_1mime_1application_1free
JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1vfs_1mime_1application_1free
	(JNIEnv *env, jclass that, jint arg0)
{
	DEBUG_CALL("gnome_1vfs_1mime_1application_1free\n")

	gnome_vfs_mime_application_free((GnomeVFSMimeApplication *)arg0);
}
#endif

#ifndef NO_gnome_1vfs_1mime_1extensions_1list_1free
JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1vfs_1mime_1extensions_1list_1free
	(JNIEnv *env, jclass that, jint arg0)
{
	DEBUG_CALL("gnome_1vfs_1mime_1extensions_1list_1free\n")

	gnome_vfs_mime_extensions_list_free((GList*)arg0);
}
#endif

#ifndef NO_gnome_1vfs_1mime_1registered_1mime_1type_1list_1free
JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1vfs_1mime_1registered_1mime_1type_1list_1free
	(JNIEnv *env, jclass that, jint arg0)
{
	DEBUG_CALL("gnome_1vfs_1mime_1registered_1mime_1type_1list_1free\n")

	gnome_vfs_mime_registered_mime_type_list_free((GList *)arg0);
}
#endif

#ifndef NO_gnome_1vfs_1mime_1get_1default_1application
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1vfs_1mime_1get_1default_1application
	(JNIEnv *env, jclass that, jbyteArray arg0)
{
	jbyte *lparg0=NULL;
	jint rc;

	DEBUG_CALL("gnome_1vfs_1mime_1get_1default_1application\n")

	if (arg0) lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL);
	rc = (jint)gnome_vfs_mime_get_default_application(lparg0);
	if (arg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0);
	return rc;
}
#endif

#ifndef NO_gnome_1vfs_1mime_1get_1extensions_1list
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1vfs_1mime_1get_1extensions_1list
	(JNIEnv *env, jclass that, jint arg0)
{
	DEBUG_CALL("gnome_1vfs_1mime_1get_1extensions_1list\n")

	return (jint)gnome_vfs_mime_get_extensions_list((const char *)arg0);
}
#endif

#ifndef NO_memmove
JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_memmove
	(JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2)
{
	GnomeVFSMimeApplication _arg0, *lparg0=NULL;

	DEBUG_CALL("memmove\n")

	if (arg0) lparg0 = getGnomeVFSMimeApplicationFields(env, arg0, &_arg0);
	memmove((void *)lparg0, (void *)arg1, arg2);
	if (arg0) setGnomeVFSMimeApplicationFields(env, arg0, lparg0);
}
#endif

#ifndef NO_gnome_1vfs_1mime_1get_1icon
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1vfs_1mime_1get_1icon
	(JNIEnv *env, jclass that, jbyteArray arg0)
{
	jbyte *lparg0=NULL;
	jint rc;

	DEBUG_CALL("gnome_1vfs_1mime_1get_1icon\n")
	if (arg0) lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL);
	rc = (jint)gnome_vfs_mime_get_icon(lparg0);
	if (arg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0);
	return rc;
}
#endif

#ifndef NO_gnome_1program_1init
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1program_1init
	(JNIEnv *env, jclass that, jbyteArray arg0, jbyteArray arg1, jint arg2, jint arg3, jintArray arg4, jint arg5)
{
	jbyte *lparg0=NULL;
	jbyte *lparg1=NULL;
	jint *lparg4=NULL;
	jint rc;
	if (arg0) lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL);
	if (arg1) lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL);
	if (arg4) lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL);
	rc = (jint)gnome_program_init((const char *)lparg0, (const char *)lparg1, (const GnomeModuleInfo *)arg2, arg3, (char **)lparg4, (void *)arg5);
	if (arg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0);
	if (arg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0);
	if (arg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0);
	return rc;
}
#endif

#ifndef NO_gnome_1program_1locate_1file
JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_gtk_GNOME_gnome_1program_1locate_1file
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jboolean arg3, jint arg4)
{
	jint rc;
	rc = (jint)gnome_program_locate_file((GnomeProgram *)arg0, arg1, (const gchar *)arg2, (gboolean)arg3,  (GSList **)arg4);
	return rc;
}
#endif