| 1 | /* |
| 2 | * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Oracle designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Oracle in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | * or visit www.oracle.com if you need additional information or have any |
| 23 | * questions. |
| 24 | */ |
| 25 | #ifndef _GTK2_INTERFACE_H |
| 26 | #define _GTK2_INTERFACE_H |
| 27 | |
| 28 | #include <stdlib.h> |
| 29 | #include <jni.h> |
| 30 | #include <X11/X.h> |
| 31 | #include "gtk_interface.h" |
| 32 | |
| 33 | #define GTK_HAS_FOCUS (1 << 12) |
| 34 | #define GTK_HAS_DEFAULT (1 << 14) |
| 35 | |
| 36 | typedef enum |
| 37 | { |
| 38 | GTK_WINDOW_TOPLEVEL, |
| 39 | |
| 40 | } GtkWindowType; |
| 41 | |
| 42 | typedef enum |
| 43 | { |
| 44 | G_PARAM_READABLE = 1 << 0, |
| 45 | G_PARAM_WRITABLE = 1 << 1, |
| 46 | G_PARAM_CONSTRUCT = 1 << 2, |
| 47 | G_PARAM_CONSTRUCT_ONLY = 1 << 3, |
| 48 | G_PARAM_LAX_VALIDATION = 1 << 4, |
| 49 | G_PARAM_PRIVATE = 1 << 5 |
| 50 | } GParamFlags; |
| 51 | |
| 52 | /* We define all structure pointers to be void* */ |
| 53 | typedef void GMainContext; |
| 54 | typedef void GVfs; |
| 55 | |
| 56 | typedef void GdkColormap; |
| 57 | typedef void GdkDrawable; |
| 58 | typedef void GdkGC; |
| 59 | typedef void GdkPixbuf; |
| 60 | typedef void GdkPixmap; |
| 61 | |
| 62 | typedef void GtkFixed; |
| 63 | typedef void ; |
| 64 | typedef void ; |
| 65 | typedef void GtkWidgetClass; |
| 66 | typedef void PangoFontDescription; |
| 67 | typedef void GtkSettings; |
| 68 | |
| 69 | /* Some real structures */ |
| 70 | typedef struct |
| 71 | { |
| 72 | guint32 pixel; |
| 73 | guint16 red; |
| 74 | guint16 green; |
| 75 | guint16 blue; |
| 76 | } GdkColor; |
| 77 | |
| 78 | typedef struct { |
| 79 | gint fd; |
| 80 | gushort events; |
| 81 | gushort revents; |
| 82 | } GPollFD; |
| 83 | |
| 84 | typedef struct { |
| 85 | gint x; |
| 86 | gint y; |
| 87 | gint width; |
| 88 | gint height; |
| 89 | } GdkRectangle; |
| 90 | |
| 91 | typedef struct { |
| 92 | gint x; |
| 93 | gint y; |
| 94 | gint width; |
| 95 | gint height; |
| 96 | } GtkAllocation; |
| 97 | |
| 98 | typedef struct { |
| 99 | gint width; |
| 100 | gint height; |
| 101 | } GtkRequisition; |
| 102 | |
| 103 | typedef struct { |
| 104 | GtkWidgetClass *g_class; |
| 105 | } GTypeInstance; |
| 106 | |
| 107 | typedef struct { |
| 108 | gint left; |
| 109 | gint right; |
| 110 | gint top; |
| 111 | gint bottom; |
| 112 | } GtkBorder; |
| 113 | |
| 114 | /****************************************************** |
| 115 | * FIXME: it is more safe to include gtk headers for |
| 116 | * the precise type definition of GType and other |
| 117 | * structures. This is a place where getting rid of gtk |
| 118 | * headers may be dangerous. |
| 119 | ******************************************************/ |
| 120 | |
| 121 | typedef struct |
| 122 | { |
| 123 | GType g_type; |
| 124 | |
| 125 | union { |
| 126 | gint v_int; |
| 127 | guint v_uint; |
| 128 | glong v_long; |
| 129 | gulong v_ulong; |
| 130 | gint64 v_int64; |
| 131 | guint64 v_uint64; |
| 132 | gfloat v_float; |
| 133 | gdouble v_double; |
| 134 | gpointer v_pointer; |
| 135 | } data[2]; |
| 136 | } GValue; |
| 137 | |
| 138 | typedef struct |
| 139 | { |
| 140 | GTypeInstance g_type_instance; |
| 141 | |
| 142 | gchar *name; |
| 143 | GParamFlags flags; |
| 144 | GType value_type; |
| 145 | GType owner_type; |
| 146 | } GParamSpec; |
| 147 | |
| 148 | typedef struct { |
| 149 | GTypeInstance g_type_instance; |
| 150 | guint ref_count; |
| 151 | void *qdata; |
| 152 | } GObject; |
| 153 | |
| 154 | typedef struct { |
| 155 | GObject parent_instance; |
| 156 | guint32 flags; |
| 157 | } GtkObject; |
| 158 | |
| 159 | typedef struct |
| 160 | { |
| 161 | GObject parent_instance; |
| 162 | |
| 163 | GdkColor fg[5]; |
| 164 | GdkColor bg[5]; |
| 165 | GdkColor light[5]; |
| 166 | GdkColor dark[5]; |
| 167 | GdkColor mid[5]; |
| 168 | GdkColor text[5]; |
| 169 | GdkColor base[5]; |
| 170 | GdkColor text_aa[5]; /* Halfway between text/base */ |
| 171 | |
| 172 | GdkColor black; |
| 173 | GdkColor white; |
| 174 | PangoFontDescription *font_desc; |
| 175 | |
| 176 | gint xthickness; |
| 177 | gint ythickness; |
| 178 | |
| 179 | GdkGC *fg_gc[5]; |
| 180 | GdkGC *bg_gc[5]; |
| 181 | GdkGC *light_gc[5]; |
| 182 | GdkGC *dark_gc[5]; |
| 183 | GdkGC *mid_gc[5]; |
| 184 | GdkGC *text_gc[5]; |
| 185 | GdkGC *base_gc[5]; |
| 186 | GdkGC *text_aa_gc[5]; |
| 187 | GdkGC *black_gc; |
| 188 | GdkGC *white_gc; |
| 189 | |
| 190 | GdkPixmap *bg_pixmap[5]; |
| 191 | } GtkStyle; |
| 192 | |
| 193 | typedef struct _GtkWidget GtkWidget; |
| 194 | struct _GtkWidget |
| 195 | { |
| 196 | GtkObject object; |
| 197 | guint16 private_flags; |
| 198 | guint8 state; |
| 199 | guint8 saved_state; |
| 200 | gchar *name; |
| 201 | GtkStyle *style; |
| 202 | GtkRequisition requisition; |
| 203 | GtkAllocation allocation; |
| 204 | GdkWindow *window; |
| 205 | GtkWidget *parent; |
| 206 | }; |
| 207 | |
| 208 | typedef struct |
| 209 | { |
| 210 | GtkWidget widget; |
| 211 | |
| 212 | gfloat xalign; |
| 213 | gfloat yalign; |
| 214 | |
| 215 | guint16 xpad; |
| 216 | guint16 ypad; |
| 217 | } GtkMisc; |
| 218 | |
| 219 | typedef struct { |
| 220 | GtkWidget widget; |
| 221 | GtkWidget *focus_child; |
| 222 | guint border_width : 16; |
| 223 | guint need_resize : 1; |
| 224 | guint resize_mode : 2; |
| 225 | guint reallocate_redraws : 1; |
| 226 | guint has_focus_chain : 1; |
| 227 | } GtkContainer; |
| 228 | |
| 229 | typedef struct { |
| 230 | GtkContainer container; |
| 231 | GtkWidget *child; |
| 232 | } GtkBin; |
| 233 | |
| 234 | typedef struct { |
| 235 | GtkBin bin; |
| 236 | GdkWindow *event_window; |
| 237 | gchar *label_text; |
| 238 | guint activate_timeout; |
| 239 | guint constructed : 1; |
| 240 | guint in_button : 1; |
| 241 | guint button_down : 1; |
| 242 | guint relief : 2; |
| 243 | guint use_underline : 1; |
| 244 | guint use_stock : 1; |
| 245 | guint depressed : 1; |
| 246 | guint depress_on_activate : 1; |
| 247 | guint focus_on_click : 1; |
| 248 | } GtkButton; |
| 249 | |
| 250 | typedef struct { |
| 251 | GtkButton button; |
| 252 | guint active : 1; |
| 253 | guint draw_indicator : 1; |
| 254 | guint inconsistent : 1; |
| 255 | } GtkToggleButton; |
| 256 | |
| 257 | typedef struct _GtkAdjustment GtkAdjustment; |
| 258 | struct _GtkAdjustment |
| 259 | { |
| 260 | GtkObject parent_instance; |
| 261 | |
| 262 | gdouble lower; |
| 263 | gdouble upper; |
| 264 | gdouble value; |
| 265 | gdouble step_increment; |
| 266 | gdouble page_increment; |
| 267 | gdouble page_size; |
| 268 | }; |
| 269 | |
| 270 | typedef enum |
| 271 | { |
| 272 | GTK_UPDATE_CONTINUOUS, |
| 273 | GTK_UPDATE_DISCONTINUOUS, |
| 274 | GTK_UPDATE_DELAYED |
| 275 | } GtkUpdateType; |
| 276 | |
| 277 | typedef struct _GtkRange GtkRange; |
| 278 | struct _GtkRange |
| 279 | { |
| 280 | GtkWidget widget; |
| 281 | GtkAdjustment *adjustment; |
| 282 | GtkUpdateType update_policy; |
| 283 | guint inverted : 1; |
| 284 | /*< protected >*/ |
| 285 | guint flippable : 1; |
| 286 | guint has_stepper_a : 1; |
| 287 | guint has_stepper_b : 1; |
| 288 | guint has_stepper_c : 1; |
| 289 | guint has_stepper_d : 1; |
| 290 | guint need_recalc : 1; |
| 291 | guint slider_size_fixed : 1; |
| 292 | gint min_slider_size; |
| 293 | GtkOrientation orientation; |
| 294 | GdkRectangle range_rect; |
| 295 | gint slider_start, slider_end; |
| 296 | gint round_digits; |
| 297 | /*< private >*/ |
| 298 | guint trough_click_forward : 1; |
| 299 | guint update_pending : 1; |
| 300 | /*GtkRangeLayout * */ void *layout; |
| 301 | /*GtkRangeStepTimer * */ void* timer; |
| 302 | gint slide_initial_slider_position; |
| 303 | gint slide_initial_coordinate; |
| 304 | guint update_timeout_id; |
| 305 | GdkWindow *event_window; |
| 306 | }; |
| 307 | |
| 308 | typedef struct _GtkProgressBar GtkProgressBar; |
| 309 | |
| 310 | typedef enum |
| 311 | { |
| 312 | GTK_PROGRESS_CONTINUOUS, |
| 313 | GTK_PROGRESS_DISCRETE |
| 314 | } GtkProgressBarStyle; |
| 315 | |
| 316 | typedef enum |
| 317 | { |
| 318 | GTK_PROGRESS_LEFT_TO_RIGHT, |
| 319 | GTK_PROGRESS_RIGHT_TO_LEFT, |
| 320 | GTK_PROGRESS_BOTTOM_TO_TOP, |
| 321 | GTK_PROGRESS_TOP_TO_BOTTOM |
| 322 | } GtkProgressBarOrientation; |
| 323 | |
| 324 | typedef struct _GtkProgress GtkProgress; |
| 325 | |
| 326 | struct _GtkProgress |
| 327 | { |
| 328 | GtkWidget widget; |
| 329 | GtkAdjustment *adjustment; |
| 330 | GdkPixmap *offscreen_pixmap; |
| 331 | gchar *format; |
| 332 | gfloat x_align; |
| 333 | gfloat y_align; |
| 334 | guint show_text : 1; |
| 335 | guint activity_mode : 1; |
| 336 | guint use_text_format : 1; |
| 337 | }; |
| 338 | |
| 339 | struct _GtkProgressBar |
| 340 | { |
| 341 | GtkProgress progress; |
| 342 | GtkProgressBarStyle bar_style; |
| 343 | GtkProgressBarOrientation orientation; |
| 344 | guint blocks; |
| 345 | gint in_block; |
| 346 | gint activity_pos; |
| 347 | guint activity_step; |
| 348 | guint activity_blocks; |
| 349 | gdouble pulse_fraction; |
| 350 | guint activity_dir : 1; |
| 351 | guint ellipsize : 3; |
| 352 | }; |
| 353 | |
| 354 | /** |
| 355 | * Returns : |
| 356 | * NULL if the GLib library is compatible with the given version, or a string |
| 357 | * describing the version mismatch. |
| 358 | * Please note that the glib_check_version() is available since 2.6, |
| 359 | * so you should use GLIB_CHECK_VERSION macro instead. |
| 360 | */ |
| 361 | static gchar* (*fp_glib_check_version)(guint required_major, guint required_minor, |
| 362 | guint required_micro); |
| 363 | |
| 364 | /** |
| 365 | * Returns : |
| 366 | * TRUE if the GLib library is compatible with the given version |
| 367 | */ |
| 368 | #define GLIB_CHECK_VERSION(major, minor, micro) \ |
| 369 | (fp_glib_check_version && fp_glib_check_version(major, minor, micro) == NULL) |
| 370 | |
| 371 | /** |
| 372 | * Returns : |
| 373 | * NULL if the GTK+ library is compatible with the given version, or a string |
| 374 | * describing the version mismatch. |
| 375 | */ |
| 376 | static gchar* (*fp_gtk_check_version)(guint required_major, guint required_minor, |
| 377 | guint required_micro); |
| 378 | |
| 379 | static void gtk2_init(GtkApi* gtk); |
| 380 | |
| 381 | static void (*fp_g_free)(gpointer mem); |
| 382 | static void (*fp_g_object_unref)(gpointer object); |
| 383 | static GdkWindow *(*fp_gdk_get_default_root_window) (void); |
| 384 | |
| 385 | static int (*fp_gdk_pixbuf_get_bits_per_sample)(const GdkPixbuf *pixbuf); |
| 386 | static guchar *(*fp_gdk_pixbuf_get_pixels)(const GdkPixbuf *pixbuf); |
| 387 | static gboolean (*fp_gdk_pixbuf_get_has_alpha)(const GdkPixbuf *pixbuf); |
| 388 | static int (*fp_gdk_pixbuf_get_height)(const GdkPixbuf *pixbuf); |
| 389 | static int (*fp_gdk_pixbuf_get_n_channels)(const GdkPixbuf *pixbuf); |
| 390 | static int (*fp_gdk_pixbuf_get_rowstride)(const GdkPixbuf *pixbuf); |
| 391 | static int (*fp_gdk_pixbuf_get_width)(const GdkPixbuf *pixbuf); |
| 392 | static GdkPixbuf *(*fp_gdk_pixbuf_new_from_file)(const char *filename, GError **error); |
| 393 | static GdkColorspace (*fp_gdk_pixbuf_get_colorspace)(const GdkPixbuf *pixbuf); |
| 394 | |
| 395 | static GdkPixbuf *(*fp_gdk_pixbuf_get_from_drawable)(GdkPixbuf *dest, |
| 396 | GdkDrawable *src, GdkColormap *cmap, int src_x, int src_y, |
| 397 | int dest_x, int dest_y, int width, int height); |
| 398 | static GdkPixbuf *(*fp_gdk_pixbuf_scale_simple)(GdkPixbuf *src, |
| 399 | int dest_width, int dest_heigh, GdkInterpType interp_type); |
| 400 | |
| 401 | |
| 402 | static void (*fp_gtk_widget_destroy)(void *widget); |
| 403 | static void (*fp_gtk_window_present)(GtkWindow *window); |
| 404 | static void (*fp_gtk_window_move)(GtkWindow *window, gint x, gint y); |
| 405 | static void (*fp_gtk_window_resize)(GtkWindow *window, gint width, gint height); |
| 406 | |
| 407 | /** |
| 408 | * Function Pointers for GtkFileChooser |
| 409 | */ |
| 410 | static gchar* (*fp_gtk_file_chooser_get_filename)(GtkFileChooser *chooser); |
| 411 | static void (*fp_gtk_widget_hide)(void *widget); |
| 412 | static void (*fp_gtk_main_quit)(void); |
| 413 | static void* (*fp_gtk_file_chooser_dialog_new)(const gchar *title, |
| 414 | GtkWindow *parent, GtkFileChooserAction action, |
| 415 | const gchar *first_button_text, ...); |
| 416 | static gboolean (*fp_gtk_file_chooser_set_current_folder)(GtkFileChooser *chooser, |
| 417 | const gchar *filename); |
| 418 | static gboolean (*fp_gtk_file_chooser_set_filename)(GtkFileChooser *chooser, |
| 419 | const char *filename); |
| 420 | static void (*fp_gtk_file_chooser_set_current_name)(GtkFileChooser *chooser, |
| 421 | const gchar *name); |
| 422 | static void (*fp_gtk_file_filter_add_custom)(GtkFileFilter *filter, |
| 423 | GtkFileFilterFlags needed, GtkFileFilterFunc func, gpointer data, |
| 424 | GDestroyNotify notify); |
| 425 | static void (*fp_gtk_file_chooser_set_filter)(GtkFileChooser *chooser, |
| 426 | GtkFileFilter *filter); |
| 427 | static GType (*fp_gtk_file_chooser_get_type)(void); |
| 428 | static GtkFileFilter* (*fp_gtk_file_filter_new)(void); |
| 429 | static void (*fp_gtk_file_chooser_set_do_overwrite_confirmation)( |
| 430 | GtkFileChooser *chooser, gboolean do_overwrite_confirmation); |
| 431 | static void (*fp_gtk_file_chooser_set_select_multiple)( |
| 432 | GtkFileChooser *chooser, gboolean select_multiple); |
| 433 | static gchar* (*fp_gtk_file_chooser_get_current_folder)(GtkFileChooser *chooser); |
| 434 | static GSList* (*fp_gtk_file_chooser_get_filenames)(GtkFileChooser *chooser); |
| 435 | static guint (*fp_gtk_g_slist_length)(GSList *list); |
| 436 | static gulong (*fp_g_signal_connect_data)(gpointer instance, |
| 437 | const gchar *detailed_signal, GCallback c_handler, gpointer data, |
| 438 | GClosureNotify destroy_data, GConnectFlags connect_flags); |
| 439 | static void (*fp_gtk_widget_show)(void *widget); |
| 440 | static void (*fp_gtk_main)(void); |
| 441 | static guint (*fp_gtk_main_level)(void); |
| 442 | static gchar* (*fp_g_path_get_dirname) (const gchar *file_name); |
| 443 | static XID (*fp_gdk_x11_drawable_get_xid) (GdkWindow *drawable); |
| 444 | |
| 445 | static GList* (*fp_g_list_append) (GList *list, gpointer data); |
| 446 | static void (*fp_g_list_free) (GList *list); |
| 447 | static void (*fp_g_list_free_full) (GList *list, GDestroyNotify free_func); |
| 448 | |
| 449 | static gboolean (*fp_gtk_show_uri)(GdkScreen *screen, const gchar *uri, |
| 450 | guint32 timestamp, GError **error); |
| 451 | |
| 452 | #endif /* !_GTK2_INTERFACE_H */ |
| 453 | |