summaryrefslogtreecommitdiff
path: root/libjava/classpath/native/jni/gtk-peer/gtkpeer.h
blob: 8b677aff7fdcc7fe373befcc53d513aaa07ff6c8 (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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/* gtkpeer.h -- Some global variables and #defines
   Copyright (C) 1998, 1999, 2004, 2005, 2006 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath 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, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


#include <cairo.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <config.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

#include <jni.h>

#ifndef __GTKPEER_H__
#define __GTKPEER_H__

#ifndef __GNUC__
#define __attribute__(x) /* nothing */
#endif

/**
 * Initializes the IDs of the Pointer* classes.
 *
 * @param env the JNI environment
 */
void gtkpeer_init_pointer_IDs(JNIEnv* env);

/**
 * Initializes the field IDs for the widget reference.
 *
 * @param env the JNI environment
 */
void gtkpeer_init_widget_IDs(JNIEnv *env);

/**
 * Stores the GTK widget reference in the GtkComponentPeer object.
 *
 * @param env the JNI environment
 * @param peer the actual peer object
 * @param widget the widget reference to store
 */
void gtkpeer_set_widget(JNIEnv *env, jobject peer, void *widget);

/**
 * Retrieves the GTK widget reference from a GtkComponentPeer object.
 *
 * @param env the JNI environment
 * @param peer the actual peer object
 *
 * @return the widget reference
 */
void* gtkpeer_get_widget(JNIEnv *env, jobject peer);

/**
 * Stores the global JNI reference of a peer inside the peer.
 *
 * @param env the JNI environment
 * @param peer the peer object
 */
void gtkpeer_set_global_ref(JNIEnv *env, jobject peer);

/**
 * Retrieves the global reference from a peer.
 *
 * @param env the JNI environment
 * @param peer the peer object
 *
 * @return the global reference
 */
void* gtkpeer_get_global_ref(JNIEnv *env, jobject peer);

/**
 * Deletes the global reference of a peer. This is necessary in order to
 * allow the peer to be garbage collected.
 *
 * @param env the JNI environment
 * @param peer the peer object.
 */
void gtkpeer_del_global_ref(JNIEnv* env, jobject peer);


/**
 * Initializes the fieldIDs for the display and screen fields.
 *
 * @param env the JNI environment
 */
void gtkpeer_init_display_IDs(JNIEnv* env);

/**
 * Sets the native display pointer in the GdkGraphicsEnvironment object.
 *
 * @param env the JNI environment
 * @param graphicsenv the GdkGraphicsEnvironment object
 * @param display the native display pointer
 */
void gtkpeer_set_display(JNIEnv* env, jobject graphicsenv, void* display);

/**
 * Fetches the native display pointer from the GdkGraphicsEnvironment object.
 *
 * @param env the JNI environment
 * @param graphicsenv the GdkGraphicsEnvironment object
 *
 * @return the native display pointer
 */
void* gtkpeer_get_display(JNIEnv* env, jobject graphicsenv);

/**
 * Initializes the fieldIDs for the screen field.
 *
 * @param env the JNI environment
 */
void gtkpeer_init_screen_IDs(JNIEnv* env);

/**
 * Sets the native screen in the GdkScreenGraphicsDevice object.
 *
 * @param env the JNI environment
 * @param screen_graphics_device the GdkScreenGraphicsDevice object
 * @param ptr the native screen pointer
 */
void gtkpeer_set_screen(JNIEnv* env, jobject screen_graphics_device,
                        void* ptr);

/**
 * Fetches the native screen pointer from the GdkScreenGraphicsDevice object.
 *
 * @param env the JNI environment
 * @param screen_graphics_device the GdkScreenGraphicsDevice object
 *
 * @return the native screen pointer
 */
void* gtkpeer_get_screen(JNIEnv* env, jobject screen_graphics_device);

/**
 * Initializes the field IDs for fonts.
 *
 * @param env the JNI environment
 */
void gtkpeer_init_font_IDs(JNIEnv* env);

/**
 * Sets the native font in the nativeFont field in GdkFontPeer.
 *
 * @param env the JNI environment
 * @param font_peer the font peer object
 * @param font the actual native font reference
 */
void gtkpeer_set_font(JNIEnv* env, jobject font_peer, void* font);

/**
 * Fetches the native font reference from the GdkFontPeer object.
 *
 * @param env the JNI environment
 * @param font_peer the font peer object
 *
 * @return the native font structure
 */
void* gtkpeer_get_font(JNIEnv* env, jobject font_peer);

/**
 * Initializes the field IDs for pixbuf decoder.
 *
 * @param env the JNI environment
 */
void gtkpeer_init_pixbuf_IDs(JNIEnv* env);

/**
 * Sets the native font in the nativeFont field in GdkFontPeer.
 *
 * @param env the JNI environment
 * @param pixbuf_dec the pixbuf decoder object
 * @param pixbuf_loader the native pixbuf loader
 */
void gtkpeer_set_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec,
                               void* pixbuf_loader);

/**
 * Fetches the native pixbuf loader reference from the GdkPixbufDecoder object.
 *
 * @param env the JNI environment
 * @param pixbuf_dec the pixbuf decoder object
 *
 * @return the native pixbuf loader
 */
void* gtkpeer_get_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec);


#define SWAPU32(w)							\
  (((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24))

/* New-style event masks. */
#define AWT_BUTTON1_DOWN_MASK (1 << 10)
#define AWT_BUTTON2_DOWN_MASK (1 << 11)
#define AWT_BUTTON3_DOWN_MASK (1 << 12)

#define AWT_SHIFT_DOWN_MASK   (1 << 6)
#define AWT_CTRL_DOWN_MASK    (1 << 7)
#define AWT_META_DOWN_MASK    (1 << 8)
#define AWT_ALT_DOWN_MASK     (1 << 9)

/* Old-style event masks. */
#define AWT_BUTTON1_MASK (1 << 4)
#define AWT_BUTTON2_MASK (1 << 3)
#define AWT_BUTTON3_MASK (1 << 2)

#define AWT_SHIFT_MASK   (1 << 0)
#define AWT_CTRL_MASK    (1 << 1)
#define AWT_META_MASK    (1 << 2)
#define AWT_ALT_MASK     (1 << 3)

#define AWT_ITEM_SELECTED 1
#define AWT_ITEM_DESELECTED 2
     
#define AWT_KEY_TYPED    400
#define AWT_KEY_PRESSED  401
#define AWT_KEY_RELEASED 402

#define AWT_KEY_LOCATION_UNKNOWN 0
#define AWT_KEY_LOCATION_STANDARD 1
#define AWT_KEY_LOCATION_LEFT 2
#define AWT_KEY_LOCATION_RIGHT 3
#define AWT_KEY_LOCATION_NUMPAD 4

#define AWT_STYLE_PLAIN  0
#define AWT_STYLE_BOLD   1
#define AWT_STYLE_ITALIC 2

/* Used in GtkComponentPeer and GtkWindowPeer */
#define VK_NUMPAD0 96
#define VK_NUMPAD1 97
#define VK_NUMPAD2 98
#define VK_NUMPAD3 99
#define VK_NUMPAD4 100
#define VK_NUMPAD5 101
#define VK_NUMPAD6 102
#define VK_NUMPAD7 103
#define VK_NUMPAD8 104
#define VK_NUMPAD9 105
#define VK_DECIMAL 110

JNIEnv *cp_gtk_gdk_env(void);

/* Global variables */
extern double cp_gtk_dpi_conversion_factor;
extern GtkWindowGroup *cp_gtk_global_window_group;

/* Shared global clipboard and selection for GtkClipboard and GtkSelection. */
extern GtkClipboard *cp_gtk_clipboard;
extern GtkClipboard *cp_gtk_selection;

extern jobject cp_gtk_clipboard_instance;
extern jobject cp_gtk_selection_instance;

/* Standard target (strings) for GtkClipboard and GtkSelection. */
extern jstring cp_gtk_stringTarget;
extern jstring cp_gtk_imageTarget;
extern jstring cp_gtk_filesTarget;

/* Union used for type punning. */
union widget_union
{
  void **void_widget;
  GtkWidget **widget;
};

/* Constant conversion helpers */
guint cp_gtk_awt_keycode_to_keysym (jint keyCode, jint keyLocation);
jint cp_gtk_state_to_awt_mods (guint state);

/* Image helpers */
GdkPixbuf *cp_gtk_image_get_pixbuf (JNIEnv *env, jobject obj);

/* Component Graphics helpers */
void cp_gtk_grab_current_drawable(GtkWidget *widget, GdkDrawable **draw,
				  GdkWindow **win);

/* JNI initialization functions */
void cp_gtk_button_init_jni (JNIEnv*);
void cp_gtk_checkbox_init_jni (void);
void cp_gtk_choice_init_jni (void);
void cp_gtk_component_init_jni (void);
void cp_gtk_filedialog_init_jni (void);
void cp_gtk_list_init_jni (void);
void cp_gtk_menuitem_init_jni (void);
void cp_gtk_scrollbar_init_jni (void);
void cp_gtk_textcomponent_init_jni (void);
void cp_gtk_window_init_jni (void);

/* Signal connection convience functions */
void cp_gtk_component_connect_expose_signals (GObject *ptr, jobject gref);
void cp_gtk_component_connect_focus_signals (GObject *ptr, jobject gref);
void cp_gtk_component_connect_mouse_signals (GObject *ptr, jobject gref);
void cp_gtk_component_connect_signals (GObject *ptr, jobject gref);
void cp_gtk_textcomponent_connect_signals (GObject *ptr, jobject gref);

/* Debugging */
void cp_gtk_print_current_thread (void);

GdkPixmap *cp_gtk_get_pixmap( JNIEnv *env, jobject obj);

#define SYNCHRONIZE_GDK 0

#define DEBUG_LOCKING 0

#if DEBUG_LOCKING
#define gdk_threads_enter()                          \
{                                                    \
  g_print ("locking: %s, %d\n", __FILE__, __LINE__); \
  cp_gtk_print_current_thread ();                    \
  gdk_threads_enter ();                              \
  g_print ("locked: %s, %d\n", __FILE__, __LINE__); \
  cp_gtk_print_current_thread ();                    \
}
#define gdk_threads_leave()                            \
{                                                      \
  g_print ("unlocking: %s, %d\n", __FILE__, __LINE__); \
  cp_gtk_print_current_thread ();                      \
  gdk_threads_leave ();                                \
  g_print ("unlocked: %s, %d\n", __FILE__, __LINE__);  \
  cp_gtk_print_current_thread ();                      \
}
#endif

#endif /* __GTKPEER_H */