Merged with mainline at revision 128810.
[official-gcc.git] / libjava / classpath / native / jni / gtk-peer / gtkpeer.h
blob8b677aff7fdcc7fe373befcc53d513aaa07ff6c8
1 /* gtkpeer.h -- Some global variables and #defines
2 Copyright (C) 1998, 1999, 2004, 2005, 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 #include <cairo.h>
40 #include <gtk/gtk.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <config.h>
45 #include <gdk-pixbuf/gdk-pixbuf.h>
47 #include <jni.h>
49 #ifndef __GTKPEER_H__
50 #define __GTKPEER_H__
52 #ifndef __GNUC__
53 #define __attribute__(x) /* nothing */
54 #endif
56 /**
57 * Initializes the IDs of the Pointer* classes.
59 * @param env the JNI environment
61 void gtkpeer_init_pointer_IDs(JNIEnv* env);
63 /**
64 * Initializes the field IDs for the widget reference.
66 * @param env the JNI environment
68 void gtkpeer_init_widget_IDs(JNIEnv *env);
70 /**
71 * Stores the GTK widget reference in the GtkComponentPeer object.
73 * @param env the JNI environment
74 * @param peer the actual peer object
75 * @param widget the widget reference to store
77 void gtkpeer_set_widget(JNIEnv *env, jobject peer, void *widget);
79 /**
80 * Retrieves the GTK widget reference from a GtkComponentPeer object.
82 * @param env the JNI environment
83 * @param peer the actual peer object
85 * @return the widget reference
87 void* gtkpeer_get_widget(JNIEnv *env, jobject peer);
89 /**
90 * Stores the global JNI reference of a peer inside the peer.
92 * @param env the JNI environment
93 * @param peer the peer object
95 void gtkpeer_set_global_ref(JNIEnv *env, jobject peer);
97 /**
98 * Retrieves the global reference from a peer.
100 * @param env the JNI environment
101 * @param peer the peer object
103 * @return the global reference
105 void* gtkpeer_get_global_ref(JNIEnv *env, jobject peer);
108 * Deletes the global reference of a peer. This is necessary in order to
109 * allow the peer to be garbage collected.
111 * @param env the JNI environment
112 * @param peer the peer object.
114 void gtkpeer_del_global_ref(JNIEnv* env, jobject peer);
118 * Initializes the fieldIDs for the display and screen fields.
120 * @param env the JNI environment
122 void gtkpeer_init_display_IDs(JNIEnv* env);
125 * Sets the native display pointer in the GdkGraphicsEnvironment object.
127 * @param env the JNI environment
128 * @param graphicsenv the GdkGraphicsEnvironment object
129 * @param display the native display pointer
131 void gtkpeer_set_display(JNIEnv* env, jobject graphicsenv, void* display);
134 * Fetches the native display pointer from the GdkGraphicsEnvironment object.
136 * @param env the JNI environment
137 * @param graphicsenv the GdkGraphicsEnvironment object
139 * @return the native display pointer
141 void* gtkpeer_get_display(JNIEnv* env, jobject graphicsenv);
144 * Initializes the fieldIDs for the screen field.
146 * @param env the JNI environment
148 void gtkpeer_init_screen_IDs(JNIEnv* env);
151 * Sets the native screen in the GdkScreenGraphicsDevice object.
153 * @param env the JNI environment
154 * @param screen_graphics_device the GdkScreenGraphicsDevice object
155 * @param ptr the native screen pointer
157 void gtkpeer_set_screen(JNIEnv* env, jobject screen_graphics_device,
158 void* ptr);
161 * Fetches the native screen pointer from the GdkScreenGraphicsDevice object.
163 * @param env the JNI environment
164 * @param screen_graphics_device the GdkScreenGraphicsDevice object
166 * @return the native screen pointer
168 void* gtkpeer_get_screen(JNIEnv* env, jobject screen_graphics_device);
171 * Initializes the field IDs for fonts.
173 * @param env the JNI environment
175 void gtkpeer_init_font_IDs(JNIEnv* env);
178 * Sets the native font in the nativeFont field in GdkFontPeer.
180 * @param env the JNI environment
181 * @param font_peer the font peer object
182 * @param font the actual native font reference
184 void gtkpeer_set_font(JNIEnv* env, jobject font_peer, void* font);
187 * Fetches the native font reference from the GdkFontPeer object.
189 * @param env the JNI environment
190 * @param font_peer the font peer object
192 * @return the native font structure
194 void* gtkpeer_get_font(JNIEnv* env, jobject font_peer);
197 * Initializes the field IDs for pixbuf decoder.
199 * @param env the JNI environment
201 void gtkpeer_init_pixbuf_IDs(JNIEnv* env);
204 * Sets the native font in the nativeFont field in GdkFontPeer.
206 * @param env the JNI environment
207 * @param pixbuf_dec the pixbuf decoder object
208 * @param pixbuf_loader the native pixbuf loader
210 void gtkpeer_set_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec,
211 void* pixbuf_loader);
214 * Fetches the native pixbuf loader reference from the GdkPixbufDecoder object.
216 * @param env the JNI environment
217 * @param pixbuf_dec the pixbuf decoder object
219 * @return the native pixbuf loader
221 void* gtkpeer_get_pixbuf_loader(JNIEnv* env, jobject pixbuf_dec);
224 #define SWAPU32(w) \
225 (((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24))
227 /* New-style event masks. */
228 #define AWT_BUTTON1_DOWN_MASK (1 << 10)
229 #define AWT_BUTTON2_DOWN_MASK (1 << 11)
230 #define AWT_BUTTON3_DOWN_MASK (1 << 12)
232 #define AWT_SHIFT_DOWN_MASK (1 << 6)
233 #define AWT_CTRL_DOWN_MASK (1 << 7)
234 #define AWT_META_DOWN_MASK (1 << 8)
235 #define AWT_ALT_DOWN_MASK (1 << 9)
237 /* Old-style event masks. */
238 #define AWT_BUTTON1_MASK (1 << 4)
239 #define AWT_BUTTON2_MASK (1 << 3)
240 #define AWT_BUTTON3_MASK (1 << 2)
242 #define AWT_SHIFT_MASK (1 << 0)
243 #define AWT_CTRL_MASK (1 << 1)
244 #define AWT_META_MASK (1 << 2)
245 #define AWT_ALT_MASK (1 << 3)
247 #define AWT_ITEM_SELECTED 1
248 #define AWT_ITEM_DESELECTED 2
250 #define AWT_KEY_TYPED 400
251 #define AWT_KEY_PRESSED 401
252 #define AWT_KEY_RELEASED 402
254 #define AWT_KEY_LOCATION_UNKNOWN 0
255 #define AWT_KEY_LOCATION_STANDARD 1
256 #define AWT_KEY_LOCATION_LEFT 2
257 #define AWT_KEY_LOCATION_RIGHT 3
258 #define AWT_KEY_LOCATION_NUMPAD 4
260 #define AWT_STYLE_PLAIN 0
261 #define AWT_STYLE_BOLD 1
262 #define AWT_STYLE_ITALIC 2
264 /* Used in GtkComponentPeer and GtkWindowPeer */
265 #define VK_NUMPAD0 96
266 #define VK_NUMPAD1 97
267 #define VK_NUMPAD2 98
268 #define VK_NUMPAD3 99
269 #define VK_NUMPAD4 100
270 #define VK_NUMPAD5 101
271 #define VK_NUMPAD6 102
272 #define VK_NUMPAD7 103
273 #define VK_NUMPAD8 104
274 #define VK_NUMPAD9 105
275 #define VK_DECIMAL 110
277 JNIEnv *cp_gtk_gdk_env(void);
279 /* Global variables */
280 extern double cp_gtk_dpi_conversion_factor;
281 extern GtkWindowGroup *cp_gtk_global_window_group;
283 /* Shared global clipboard and selection for GtkClipboard and GtkSelection. */
284 extern GtkClipboard *cp_gtk_clipboard;
285 extern GtkClipboard *cp_gtk_selection;
287 extern jobject cp_gtk_clipboard_instance;
288 extern jobject cp_gtk_selection_instance;
290 /* Standard target (strings) for GtkClipboard and GtkSelection. */
291 extern jstring cp_gtk_stringTarget;
292 extern jstring cp_gtk_imageTarget;
293 extern jstring cp_gtk_filesTarget;
295 /* Union used for type punning. */
296 union widget_union
298 void **void_widget;
299 GtkWidget **widget;
302 /* Constant conversion helpers */
303 guint cp_gtk_awt_keycode_to_keysym (jint keyCode, jint keyLocation);
304 jint cp_gtk_state_to_awt_mods (guint state);
306 /* Image helpers */
307 GdkPixbuf *cp_gtk_image_get_pixbuf (JNIEnv *env, jobject obj);
309 /* Component Graphics helpers */
310 void cp_gtk_grab_current_drawable(GtkWidget *widget, GdkDrawable **draw,
311 GdkWindow **win);
313 /* JNI initialization functions */
314 void cp_gtk_button_init_jni (JNIEnv*);
315 void cp_gtk_checkbox_init_jni (void);
316 void cp_gtk_choice_init_jni (void);
317 void cp_gtk_component_init_jni (void);
318 void cp_gtk_filedialog_init_jni (void);
319 void cp_gtk_list_init_jni (void);
320 void cp_gtk_menuitem_init_jni (void);
321 void cp_gtk_scrollbar_init_jni (void);
322 void cp_gtk_textcomponent_init_jni (void);
323 void cp_gtk_window_init_jni (void);
325 /* Signal connection convience functions */
326 void cp_gtk_component_connect_expose_signals (GObject *ptr, jobject gref);
327 void cp_gtk_component_connect_focus_signals (GObject *ptr, jobject gref);
328 void cp_gtk_component_connect_mouse_signals (GObject *ptr, jobject gref);
329 void cp_gtk_component_connect_signals (GObject *ptr, jobject gref);
330 void cp_gtk_textcomponent_connect_signals (GObject *ptr, jobject gref);
332 /* Debugging */
333 void cp_gtk_print_current_thread (void);
335 GdkPixmap *cp_gtk_get_pixmap( JNIEnv *env, jobject obj);
337 #define SYNCHRONIZE_GDK 0
339 #define DEBUG_LOCKING 0
341 #if DEBUG_LOCKING
342 #define gdk_threads_enter() \
344 g_print ("locking: %s, %d\n", __FILE__, __LINE__); \
345 cp_gtk_print_current_thread (); \
346 gdk_threads_enter (); \
347 g_print ("locked: %s, %d\n", __FILE__, __LINE__); \
348 cp_gtk_print_current_thread (); \
350 #define gdk_threads_leave() \
352 g_print ("unlocking: %s, %d\n", __FILE__, __LINE__); \
353 cp_gtk_print_current_thread (); \
354 gdk_threads_leave (); \
355 g_print ("unlocked: %s, %d\n", __FILE__, __LINE__); \
356 cp_gtk_print_current_thread (); \
358 #endif
360 #endif /* __GTKPEER_H */