Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / native / jni / gtk-peer / gtkpeer.h
blobf332b62a156ecdb660765189ed81cef231efd0c2
1 /* gtkpeer.h -- Some global variables and #defines
2 Copyright (C) 1998, 1999, 2004, 2005 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 <gtk/gtk.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <config.h>
44 #include "native_state.h"
46 #include <jni.h>
48 #ifndef __GTKPEER_H__
49 #define __GTKPEER_H__
51 #ifndef __GNUC__
52 #define __attribute__(x) /* nothing */
53 #endif
55 extern struct state_table *cp_gtk_native_state_table;
56 extern struct state_table *cp_gtk_native_global_ref_table;
58 #define NSA_INIT(env, clazz) \
59 do {cp_gtk_native_state_table = cp_gtk_init_state_table (env, clazz); \
60 cp_gtk_native_global_ref_table = cp_gtk_init_state_table (env, clazz);} while (0)
62 #define NSA_GET_PTR(env, obj) \
63 cp_gtk_get_state (env, obj, cp_gtk_native_state_table)
65 #define NSA_SET_PTR(env, obj, ptr) \
66 cp_gtk_set_state (env, obj, cp_gtk_native_state_table, (void *)ptr)
68 #define NSA_DEL_PTR(env, obj) \
69 cp_gtk_remove_state_slot (env, obj, cp_gtk_native_state_table)
71 #define NSA_GET_GLOBAL_REF(env, obj) \
72 cp_gtk_get_state (env, obj, cp_gtk_native_global_ref_table)
74 #define NSA_SET_GLOBAL_REF(env, obj) \
75 do {jobject *globRefPtr; \
76 globRefPtr = (jobject *) malloc (sizeof (jobject)); \
77 *globRefPtr = (*env)->NewGlobalRef (env, obj); \
78 cp_gtk_set_state (env, obj, cp_gtk_native_global_ref_table, (void *)globRefPtr);} while (0)
80 #define NSA_DEL_GLOBAL_REF(env, obj) \
81 do {jobject *globRefPtr = cp_gtk_get_state (env, obj, cp_gtk_native_global_ref_table); \
82 cp_gtk_remove_state_slot (env, obj, cp_gtk_native_global_ref_table); \
83 (*env)->DeleteGlobalRef (env, *globRefPtr); \
84 free (globRefPtr);} while (0)
86 extern struct state_table *cp_gtk_native_graphics_state_table;
88 #define NSA_G_INIT(env, clazz) \
89 cp_gtk_native_graphics_state_table = cp_gtk_init_state_table (env, clazz)
91 #define NSA_GET_G_PTR(env, obj) \
92 cp_gtk_get_state (env, obj, cp_gtk_native_graphics_state_table)
94 #define NSA_SET_G_PTR(env, obj, ptr) \
95 cp_gtk_set_state (env, obj, cp_gtk_native_graphics_state_table, (void *)ptr)
97 #define NSA_DEL_G_PTR(env, obj) \
98 cp_gtk_remove_state_slot (env, obj, cp_gtk_native_graphics_state_table)
100 #define SWAPU32(w) \
101 (((w) << 24) | (((w) & 0xff00) << 8) | (((w) >> 8) & 0xff00) | ((w) >> 24))
103 struct graphics
105 GdkDrawable *drawable;
106 GdkGC *gc;
107 GdkColormap *cm;
108 PangoFontDescription *pango_font;
109 PangoContext *pango_context;
110 PangoLayout *pango_layout;
111 jint x_offset, y_offset;
114 /* New-style event masks. */
115 #define AWT_BUTTON1_DOWN_MASK (1 << 10)
116 #define AWT_BUTTON2_DOWN_MASK (1 << 11)
117 #define AWT_BUTTON3_DOWN_MASK (1 << 12)
119 #define AWT_SHIFT_DOWN_MASK (1 << 6)
120 #define AWT_CTRL_DOWN_MASK (1 << 7)
121 #define AWT_META_DOWN_MASK (1 << 8)
122 #define AWT_ALT_DOWN_MASK (1 << 9)
124 /* Old-style event masks. */
125 #define AWT_BUTTON1_MASK (1 << 4)
126 #define AWT_BUTTON2_MASK (1 << 3)
127 #define AWT_BUTTON3_MASK (1 << 2)
129 #define AWT_SHIFT_MASK (1 << 0)
130 #define AWT_CTRL_MASK (1 << 1)
131 #define AWT_META_MASK (1 << 2)
132 #define AWT_ALT_MASK (1 << 3)
134 #define AWT_ITEM_SELECTED 1
135 #define AWT_ITEM_DESELECTED 2
137 #define AWT_KEY_TYPED 400
138 #define AWT_KEY_PRESSED 401
139 #define AWT_KEY_RELEASED 402
141 #define AWT_KEY_LOCATION_UNKNOWN 0
142 #define AWT_KEY_LOCATION_STANDARD 1
143 #define AWT_KEY_LOCATION_LEFT 2
144 #define AWT_KEY_LOCATION_RIGHT 3
145 #define AWT_KEY_LOCATION_NUMPAD 4
147 #define AWT_STYLE_PLAIN 0
148 #define AWT_STYLE_BOLD 1
149 #define AWT_STYLE_ITALIC 2
151 /* Used in GtkComponentPeer and GtkWindowPeer */
152 #define VK_NUMPAD0 96
153 #define VK_NUMPAD1 97
154 #define VK_NUMPAD2 98
155 #define VK_NUMPAD3 99
156 #define VK_NUMPAD4 100
157 #define VK_NUMPAD5 101
158 #define VK_NUMPAD6 102
159 #define VK_NUMPAD7 103
160 #define VK_NUMPAD8 104
161 #define VK_NUMPAD9 105
162 #define VK_DECIMAL 110
164 JNIEnv *cp_gtk_gdk_env(void);
166 /* Global variables */
167 extern double cp_gtk_dpi_conversion_factor;
168 extern GtkWindowGroup *cp_gtk_global_window_group;
170 /* Shared global clipboard for GtkClipboard and GtkSelection. */
171 extern GtkClipboard *cp_gtk_clipboard;
173 /* Standard target (strings) for GtkClipboard and GtkSelection. */
174 extern jstring cp_gtk_stringTarget;
175 extern jstring cp_gtk_imageTarget;
176 extern jstring cp_gtk_filesTarget;
178 /* Union used for type punning. */
179 union widget_union
181 void **void_widget;
182 GtkWidget **widget;
185 /* Constant conversion helpers */
186 guint cp_gtk_awt_keycode_to_keysym (jint keyCode, jint keyLocation);
187 jint cp_gtk_state_to_awt_mods (guint state);
189 /* Image helpers */
190 GdkPixbuf *cp_gtk_image_get_pixbuf (JNIEnv *env, jobject obj);
191 GdkPixmap *cp_gtk_image_get_pixmap (JNIEnv *env, jobject obj);
192 jboolean cp_gtk_image_is_offscreen (JNIEnv *env, jobject obj);
194 /* JNI initialization functions */
195 #if GTK_CAIRO
196 void cp_gtk_graphics2d_init_jni (void);
197 #endif
198 void cp_gtk_graphics_init_jni (void);
199 void cp_gtk_button_init_jni (void);
200 void cp_gtk_checkbox_init_jni (void);
201 void cp_gtk_choice_init_jni (void);
202 void cp_gtk_component_init_jni (void);
203 void cp_gtk_filedialog_init_jni (void);
204 void cp_gtk_list_init_jni (void);
205 void cp_gtk_menuitem_init_jni (void);
206 void cp_gtk_scrollbar_init_jni (void);
207 void cp_gtk_textcomponent_init_jni (void);
208 void cp_gtk_window_init_jni (void);
210 /* Signal connection convience functions */
211 void cp_gtk_component_connect_expose_signals (GObject *ptr, jobject *gref);
212 void cp_gtk_component_connect_focus_signals (GObject *ptr, jobject *gref);
213 void cp_gtk_component_connect_mouse_signals (GObject *ptr, jobject *gref);
214 void cp_gtk_component_connect_signals (GObject *ptr, jobject *gref);
215 void cp_gtk_textcomponent_connect_signals (GObject *ptr, jobject *gref);
217 /* Debugging */
218 void cp_gtk_print_current_thread (void);
220 #define SYNCHRONIZE_GDK 0
222 #define DEBUG_LOCKING 0
224 #if DEBUG_LOCKING
225 #define gdk_threads_enter() \
227 g_print ("locking: %s, %d\n", __FILE__, __LINE__); \
228 cp_gtk_print_current_thread (); \
229 gdk_threads_enter (); \
230 g_print ("locked: %s, %d\n", __FILE__, __LINE__); \
231 cp_gtk_print_current_thread (); \
233 #define gdk_threads_leave() \
235 g_print ("unlocking: %s, %d\n", __FILE__, __LINE__); \
236 cp_gtk_print_current_thread (); \
237 gdk_threads_leave (); \
238 g_print ("unlocked: %s, %d\n", __FILE__, __LINE__); \
239 cp_gtk_print_current_thread (); \
241 #endif
243 #endif /* __GTKPEER_H */