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