blob: bde5ec1bc19e732c8288b9c9e9d8e79a9c718a25 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005-2006 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25#ifndef _GTK2_INTERFACE_H
26#define _GTK2_INTERFACE_H
27
28#include <stdlib.h>
29#include <jni.h>
30
31typedef enum _WidgetType
32{
33 BUTTON, /* GtkButton */
34 CHECK_BOX, /* GtkCheckButton */
35 CHECK_BOX_MENU_ITEM, /* GtkCheckMenuItem */
36 COLOR_CHOOSER, /* GtkColorSelectionDialog */
37 COMBO_BOX, /* GtkComboBox */
38 COMBO_BOX_ARROW_BUTTON, /* GtkComboBoxEntry */
39 COMBO_BOX_TEXT_FIELD, /* GtkComboBoxEntry */
40 DESKTOP_ICON, /* GtkLabel */
41 DESKTOP_PANE, /* GtkContainer */
42 EDITOR_PANE, /* GtkTextView */
43 FORMATTED_TEXT_FIELD, /* GtkEntry */
44 HANDLE_BOX, /* GtkHandleBox */
45 HPROGRESS_BAR, /* GtkProgressBar */
46 HSCROLL_BAR, /* GtkHScrollbar */
47 HSCROLL_BAR_BUTTON_LEFT, /* GtkHScrollbar */
48 HSCROLL_BAR_BUTTON_RIGHT, /* GtkHScrollbar */
49 HSCROLL_BAR_TRACK, /* GtkHScrollbar */
50 HSCROLL_BAR_THUMB, /* GtkHScrollbar */
51 HSEPARATOR, /* GtkHSeparator */
52 HSLIDER, /* GtkHScale */
53 HSLIDER_TRACK, /* GtkHScale */
54 HSLIDER_THUMB, /* GtkHScale */
55 HSPLIT_PANE_DIVIDER, /* GtkHPaned */
56 INTERNAL_FRAME, /* GtkWindow */
57 INTERNAL_FRAME_TITLE_PANE, /* GtkLabel */
58 IMAGE, /* GtkImage */
59 LABEL, /* GtkLabel */
60 LIST, /* GtkTreeView */
61 MENU, /* GtkMenu */
62 MENU_BAR, /* GtkMenuBar */
63 MENU_ITEM, /* GtkMenuItem */
64 MENU_ITEM_ACCELERATOR, /* GtkLabel */
65 OPTION_PANE, /* GtkMessageDialog */
66 PANEL, /* GtkContainer */
67 PASSWORD_FIELD, /* GtkEntry */
68 POPUP_MENU, /* GtkMenu */
69 POPUP_MENU_SEPARATOR, /* GtkSeparatorMenuItem */
70 RADIO_BUTTON, /* GtkRadioButton */
71 RADIO_BUTTON_MENU_ITEM, /* GtkRadioMenuItem */
72 ROOT_PANE, /* GtkContainer */
73 SCROLL_PANE, /* GtkScrolledWindow */
74 SPINNER, /* GtkSpinButton */
75 SPINNER_ARROW_BUTTON, /* GtkSpinButton */
76 SPINNER_TEXT_FIELD, /* GtkSpinButton */
77 SPLIT_PANE, /* GtkPaned */
78 TABBED_PANE, /* GtkNotebook */
79 TABBED_PANE_TAB_AREA, /* GtkNotebook */
80 TABBED_PANE_CONTENT, /* GtkNotebook */
81 TABBED_PANE_TAB, /* GtkNotebook */
82 TABLE, /* GtkTreeView */
83 TABLE_HEADER, /* GtkButton */
84 TEXT_AREA, /* GtkTextView */
85 TEXT_FIELD, /* GtkEntry */
86 TEXT_PANE, /* GtkTextView */
87 TITLED_BORDER, /* GtkFrame */
88 TOGGLE_BUTTON, /* GtkToggleButton */
89 TOOL_BAR, /* GtkToolbar */
90 TOOL_BAR_DRAG_WINDOW, /* GtkToolbar */
91 TOOL_BAR_SEPARATOR, /* GtkSeparatorToolItem */
92 TOOL_TIP, /* GtkWindow */
93 TREE, /* GtkTreeView */
94 TREE_CELL, /* GtkTreeView */
95 VIEWPORT, /* GtkViewport */
96 VPROGRESS_BAR, /* GtkProgressBar */
97 VSCROLL_BAR, /* GtkVScrollbar */
98 VSCROLL_BAR_BUTTON_UP, /* GtkVScrollbar */
99 VSCROLL_BAR_BUTTON_DOWN, /* GtkVScrollbar */
100 VSCROLL_BAR_TRACK, /* GtkVScrollbar */
101 VSCROLL_BAR_THUMB, /* GtkVScrollbar */
102 VSEPARATOR, /* GtkVSeparator */
103 VSLIDER, /* GtkVScale */
104 VSLIDER_TRACK, /* GtkVScale */
105 VSLIDER_THUMB, /* GtkVScale */
106 VSPLIT_PANE_DIVIDER, /* GtkVPaned */
107 WIDGET_TYPE_SIZE
108} WidgetType;
109
110typedef enum _ColorType
111{
112 FOREGROUND,
113 BACKGROUND,
114 TEXT_FOREGROUND,
115 TEXT_BACKGROUND,
116 FOCUS,
117 LIGHT,
118 DARK,
119 MID,
120 BLACK,
121 WHITE
122} ColorType;
123
124typedef enum _Setting
125{
126 GTK_FONT_NAME,
127 GTK_ICON_SIZES
128} Setting;
129
130/* GTK types, here to eliminate need for GTK headers at compile time */
131
132#ifndef FALSE
133#define FALSE (0)
134#define TRUE (!FALSE)
135#endif
136
137#define GTK_HAS_FOCUS (1 << 12)
138#define GTK_HAS_DEFAULT (1 << 14)
139
140
141/* basic types */
142typedef char gchar;
143typedef short gshort;
144typedef int gint;
145typedef long glong;
146typedef float gfloat;
147typedef double gdouble;
148typedef void* gpointer;
149typedef gint gboolean;
150
151typedef signed char gint8;
152typedef signed short gint16;
153typedef signed int gint32;
154
155typedef unsigned char guchar;
156typedef unsigned char guint8;
157typedef unsigned short gushort;
158typedef unsigned short guint16;
159typedef unsigned int guint;
160typedef unsigned int guint32;
161typedef unsigned int gsize;
162typedef unsigned long gulong;
163
164typedef signed long long gint64;
165typedef unsigned long long guint64;
166
167/* enumerated constants */
168typedef enum
169{
170 GTK_ARROW_UP,
171 GTK_ARROW_DOWN,
172 GTK_ARROW_LEFT,
173 GTK_ARROW_RIGHT
174} GtkArrowType;
175
176typedef enum {
177 GDK_COLORSPACE_RGB
178} GdkColorspace;
179
180typedef enum
181{
182 GTK_EXPANDER_COLLAPSED,
183 GTK_EXPANDER_SEMI_COLLAPSED,
184 GTK_EXPANDER_SEMI_EXPANDED,
185 GTK_EXPANDER_EXPANDED
186} GtkExpanderStyle;
187
188typedef enum
189{
190 GTK_ICON_SIZE_INVALID,
191 GTK_ICON_SIZE_MENU,
192 GTK_ICON_SIZE_SMALL_TOOLBAR,
193 GTK_ICON_SIZE_LARGE_TOOLBAR,
194 GTK_ICON_SIZE_BUTTON,
195 GTK_ICON_SIZE_DND,
196 GTK_ICON_SIZE_DIALOG
197} GtkIconSize;
198
199typedef enum
200{
201 GTK_ORIENTATION_HORIZONTAL,
202 GTK_ORIENTATION_VERTICAL
203} GtkOrientation;
204
205typedef enum
206{
207 GTK_POS_LEFT,
208 GTK_POS_RIGHT,
209 GTK_POS_TOP,
210 GTK_POS_BOTTOM
211} GtkPositionType;
212
213typedef enum
214{
215 GTK_SHADOW_NONE,
216 GTK_SHADOW_IN,
217 GTK_SHADOW_OUT,
218 GTK_SHADOW_ETCHED_IN,
219 GTK_SHADOW_ETCHED_OUT
220} GtkShadowType;
221
222typedef enum
223{
224 GTK_STATE_NORMAL,
225 GTK_STATE_ACTIVE,
226 GTK_STATE_PRELIGHT,
227 GTK_STATE_SELECTED,
228 GTK_STATE_INSENSITIVE
229} GtkStateType;
230
231typedef enum
232{
233 GTK_TEXT_DIR_NONE,
234 GTK_TEXT_DIR_LTR,
235 GTK_TEXT_DIR_RTL
236} GtkTextDirection;
237
238typedef enum
239{
240 GTK_WINDOW_TOPLEVEL,
241 GTK_WINDOW_POPUP
242} GtkWindowType;
243
244typedef enum
245{
246 G_PARAM_READABLE = 1 << 0,
247 G_PARAM_WRITABLE = 1 << 1,
248 G_PARAM_CONSTRUCT = 1 << 2,
249 G_PARAM_CONSTRUCT_ONLY = 1 << 3,
250 G_PARAM_LAX_VALIDATION = 1 << 4,
251 G_PARAM_PRIVATE = 1 << 5
252} GParamFlags;
253
254/* We define all structure pointers to be void* */
255typedef void GError;
256typedef void GMainContext;
257typedef void GSList;
258
259typedef void GdkColormap;
260typedef void GdkDrawable;
261typedef void GdkGC;
262typedef void GdkPixbuf;
263typedef void GdkPixmap;
264typedef void GdkWindow;
265
266typedef void GtkFixed;
267typedef void GtkMenuItem;
268typedef void GtkMenuShell;
269typedef void GtkWidgetClass;
270typedef void PangoFontDescription;
271typedef void GtkSettings;
272
273/* Some real structures */
274typedef struct
275{
276 guint32 pixel;
277 guint16 red;
278 guint16 green;
279 guint16 blue;
280} GdkColor;
281
282typedef struct {
283 gint fd;
284 gushort events;
285 gushort revents;
286} GPollFD;
287
288typedef struct {
289 gint x;
290 gint y;
291 gint width;
292 gint height;
293} GdkRectangle;
294
295typedef struct {
296 gint x;
297 gint y;
298 gint width;
299 gint height;
300} GtkAllocation;
301
302typedef struct {
303 gint width;
304 gint height;
305} GtkRequisition;
306
307typedef struct {
308 GtkWidgetClass *g_class;
309} GTypeInstance;
310
311typedef struct {
312 gint left;
313 gint right;
314 gint top;
315 gint bottom;
316} GtkBorder;
317
318/******************************************************
319 * FIXME: it is more safe to include gtk headers for
320 * the precise type definition of GType and other
321 * structures. This is a place where getting rid of gtk
322 * headers may be dangerous.
323 ******************************************************/
324typedef gulong GType;
325
326typedef struct
327{
328 GType g_type;
329
330 union {
331 gint v_int;
332 guint v_uint;
333 glong v_long;
334 gulong v_ulong;
335 gint64 v_int64;
336 guint64 v_uint64;
337 gfloat v_float;
338 gdouble v_double;
339 gpointer v_pointer;
340 } data[2];
341} GValue;
342
343typedef struct
344{
345 GTypeInstance g_type_instance;
346
347 gchar *name;
348 GParamFlags flags;
349 GType value_type;
350 GType owner_type;
351} GParamSpec;
352
353typedef struct {
354 GTypeInstance g_type_instance;
355 guint ref_count;
356 void *qdata;
357} GObject;
358
359typedef struct {
360 GObject parent_instance;
361 guint32 flags;
362} GtkObject;
363
364typedef struct
365{
366 GObject parent_instance;
367
368 GdkColor fg[5];
369 GdkColor bg[5];
370 GdkColor light[5];
371 GdkColor dark[5];
372 GdkColor mid[5];
373 GdkColor text[5];
374 GdkColor base[5];
375 GdkColor text_aa[5]; /* Halfway between text/base */
376
377 GdkColor black;
378 GdkColor white;
379 PangoFontDescription *font_desc;
380
381 gint xthickness;
382 gint ythickness;
383
384 GdkGC *fg_gc[5];
385 GdkGC *bg_gc[5];
386 GdkGC *light_gc[5];
387 GdkGC *dark_gc[5];
388 GdkGC *mid_gc[5];
389 GdkGC *text_gc[5];
390 GdkGC *base_gc[5];
391 GdkGC *text_aa_gc[5];
392 GdkGC *black_gc;
393 GdkGC *white_gc;
394
395 GdkPixmap *bg_pixmap[5];
396} GtkStyle;
397
398typedef struct _GtkWidget GtkWidget;
399struct _GtkWidget
400{
401 GtkObject object;
402 guint16 private_flags;
403 guint8 state;
404 guint8 saved_state;
405 gchar *name;
406 GtkStyle *style;
407 GtkRequisition requisition;
408 GtkAllocation allocation;
409 GdkWindow *window;
410 GtkWidget *parent;
411};
412
413typedef struct
414{
415 GtkWidget widget;
416
417 gfloat xalign;
418 gfloat yalign;
419
420 guint16 xpad;
421 guint16 ypad;
422} GtkMisc;
423
424typedef struct {
425 GtkWidget widget;
426 GtkWidget *focus_child;
427 guint border_width : 16;
428 guint need_resize : 1;
429 guint resize_mode : 2;
430 guint reallocate_redraws : 1;
431 guint has_focus_chain : 1;
432} GtkContainer;
433
434typedef struct {
435 GtkContainer container;
436 GtkWidget *child;
437} GtkBin;
438
439typedef struct {
440 GtkBin bin;
441 GdkWindow *event_window;
442 gchar *label_text;
443 guint activate_timeout;
444 guint constructed : 1;
445 guint in_button : 1;
446 guint button_down : 1;
447 guint relief : 2;
448 guint use_underline : 1;
449 guint use_stock : 1;
450 guint depressed : 1;
451 guint depress_on_activate : 1;
452 guint focus_on_click : 1;
453} GtkButton;
454
455typedef struct {
456 GtkButton button;
457 guint active : 1;
458 guint draw_indicator : 1;
459 guint inconsistent : 1;
460} GtkToggleButton;
461
462typedef struct _GtkAdjustment GtkAdjustment;
463struct _GtkAdjustment
464{
465 GtkObject parent_instance;
466
467 gdouble lower;
468 gdouble upper;
469 gdouble value;
470 gdouble step_increment;
471 gdouble page_increment;
472 gdouble page_size;
473};
474
475typedef enum
476{
477 GTK_UPDATE_CONTINUOUS,
478 GTK_UPDATE_DISCONTINUOUS,
479 GTK_UPDATE_DELAYED
480} GtkUpdateType;
481
482typedef struct _GtkRange GtkRange;
483struct _GtkRange
484{
485 GtkWidget widget;
486 GtkAdjustment *adjustment;
487 GtkUpdateType update_policy;
488 guint inverted : 1;
489 /*< protected >*/
490 guint flippable : 1;
491 guint has_stepper_a : 1;
492 guint has_stepper_b : 1;
493 guint has_stepper_c : 1;
494 guint has_stepper_d : 1;
495 guint need_recalc : 1;
496 guint slider_size_fixed : 1;
497 gint min_slider_size;
498 GtkOrientation orientation;
499 GdkRectangle range_rect;
500 gint slider_start, slider_end;
501 gint round_digits;
502 /*< private >*/
503 guint trough_click_forward : 1;
504 guint update_pending : 1;
505 /*GtkRangeLayout * */ void *layout;
506 /*GtkRangeStepTimer * */ void* timer;
507 gint slide_initial_slider_position;
508 gint slide_initial_coordinate;
509 guint update_timeout_id;
510 GdkWindow *event_window;
511};
512
513typedef struct _GtkProgressBar GtkProgressBar;
514
515typedef enum
516{
517 GTK_PROGRESS_CONTINUOUS,
518 GTK_PROGRESS_DISCRETE
519} GtkProgressBarStyle;
520
521typedef enum
522{
523 GTK_PROGRESS_LEFT_TO_RIGHT,
524 GTK_PROGRESS_RIGHT_TO_LEFT,
525 GTK_PROGRESS_BOTTOM_TO_TOP,
526 GTK_PROGRESS_TOP_TO_BOTTOM
527} GtkProgressBarOrientation;
528
529typedef struct _GtkProgress GtkProgress;
530
531struct _GtkProgress
532{
533 GtkWidget widget;
534 GtkAdjustment *adjustment;
535 GdkPixmap *offscreen_pixmap;
536 gchar *format;
537 gfloat x_align;
538 gfloat y_align;
539 guint show_text : 1;
540 guint activity_mode : 1;
541 guint use_text_format : 1;
542};
543
544struct _GtkProgressBar
545{
546 GtkProgress progress;
547 GtkProgressBarStyle bar_style;
548 GtkProgressBarOrientation orientation;
549 guint blocks;
550 gint in_block;
551 gint activity_pos;
552 guint activity_step;
553 guint activity_blocks;
554 gdouble pulse_fraction;
555 guint activity_dir : 1;
556 guint ellipsize : 3;
557};
558
559/*
560 * Converts java.lang.String object to UTF-8 character string.
561 */
562const char *getStrFor(JNIEnv *env, jstring value);
563
564/*
565 * Check whether the gtk2 library is available and meets the minimum
566 * version requirement. If the library is already loaded this method has no
567 * effect and returns success.
568 * Returns FALSE on failure and TRUE on success.
569 */
570gboolean gtk2_check_version();
571
572/*
573 * Load the gtk2 library. If the library is already loaded this method has no
574 * effect and returns success.
575 * Returns FALSE on failure and TRUE on success.
576 */
577gboolean gtk2_load();
578
579/*
580 * Unload the gtk2 library. If the library is already unloaded this method has
581 * no effect and returns success.
582 * Returns FALSE on failure and TRUE on success.
583 */
584gboolean gtk2_unload();
585
586void gtk2_paint_arrow(WidgetType widget_type, GtkStateType state_type,
587 GtkShadowType shadow_type, const gchar *detail,
588 gint x, gint y, gint width, gint height,
589 GtkArrowType arrow_type, gboolean fill);
590void gtk2_paint_box(WidgetType widget_type, GtkStateType state_type,
591 GtkShadowType shadow_type, const gchar *detail,
592 gint x, gint y, gint width, gint height,
593 gint synth_state, GtkTextDirection dir);
594void gtk2_paint_box_gap(WidgetType widget_type, GtkStateType state_type,
595 GtkShadowType shadow_type, const gchar *detail,
596 gint x, gint y, gint width, gint height,
597 GtkPositionType gap_side, gint gap_x, gint gap_width);
598void gtk2_paint_check(WidgetType widget_type, gint synth_state,
599 const gchar *detail, gint x, gint y, gint width, gint height);
600void gtk2_paint_diamond(WidgetType widget_type, GtkStateType state_type,
601 GtkShadowType shadow_type, const gchar *detail,
602 gint x, gint y, gint width, gint height);
603void gtk2_paint_expander(WidgetType widget_type, GtkStateType state_type,
604 const gchar *detail, gint x, gint y, gint width, gint height,
605 GtkExpanderStyle expander_style);
606void gtk2_paint_extension(WidgetType widget_type, GtkStateType state_type,
607 GtkShadowType shadow_type, const gchar *detail,
608 gint x, gint y, gint width, gint height, GtkPositionType gap_side);
609void gtk2_paint_flat_box(WidgetType widget_type, GtkStateType state_type,
610 GtkShadowType shadow_type, const gchar *detail,
611 gint x, gint y, gint width, gint height, gboolean has_focus);
612void gtk2_paint_focus(WidgetType widget_type, GtkStateType state_type,
613 const char *detail, gint x, gint y, gint width, gint height);
614void gtk2_paint_handle(WidgetType widget_type, GtkStateType state_type,
615 GtkShadowType shadow_type, const gchar *detail,
616 gint x, gint y, gint width, gint height, GtkOrientation orientation);
617void gtk2_paint_hline(WidgetType widget_type, GtkStateType state_type,
618 const gchar *detail, gint x, gint y, gint width, gint height);
619void gtk2_paint_option(WidgetType widget_type, gint synth_state,
620 const gchar *detail, gint x, gint y, gint width, gint height);
621void gtk2_paint_shadow(WidgetType widget_type, GtkStateType state_type,
622 GtkShadowType shadow_type, const gchar *detail,
623 gint x, gint y, gint width, gint height,
624 gint synth_state, GtkTextDirection dir);
625void gtk2_paint_slider(WidgetType widget_type, GtkStateType state_type,
626 GtkShadowType shadow_type, const gchar *detail,
627 gint x, gint y, gint width, gint height, GtkOrientation orientation);
628void gtk2_paint_vline(WidgetType widget_type, GtkStateType state_type,
629 const gchar *detail, gint x, gint y, gint width, gint height);
630void gtk_paint_background(WidgetType widget_type, GtkStateType state_type,
631 gint x, gint y, gint width, gint height);
632
633void gtk2_init_painting(gint w, gint h);
634gint gtk2_copy_image(gint *dest, gint width, gint height);
635
636gint gtk2_get_xthickness(JNIEnv *env, WidgetType widget_type);
637gint gtk2_get_ythickness(JNIEnv *env, WidgetType widget_type);
638gint gtk2_get_color_for_state(JNIEnv *env, WidgetType widget_type,
639 GtkStateType state_type, ColorType color_type);
640jobject gtk2_get_class_value(JNIEnv *env, WidgetType widget_type, jstring key);
641
642GdkPixbuf *gtk2_get_stock_icon(gint widget_type, const gchar *stock_id,
643 GtkIconSize size, GtkTextDirection direction, const char *detail);
644GdkPixbuf *gtk2_get_icon(const gchar *filename, gint size);
645jstring gtk2_get_pango_font_name(JNIEnv *env, WidgetType widget_type);
646
647void flush_gtk_event_loop();
648
649jobject gtk2_get_setting(JNIEnv *env, Setting property);
650
651void gtk2_set_range_value(WidgetType widget_type, jdouble value,
652 jdouble min, jdouble max, jdouble visible);
653
654void (*fp_g_object_unref)(gpointer object);
655int (*fp_gdk_pixbuf_get_bits_per_sample)(const GdkPixbuf *pixbuf);
656guchar *(*fp_gdk_pixbuf_get_pixels)(const GdkPixbuf *pixbuf);
657gboolean (*fp_gdk_pixbuf_get_has_alpha)(const GdkPixbuf *pixbuf);
658int (*fp_gdk_pixbuf_get_height)(const GdkPixbuf *pixbuf);
659int (*fp_gdk_pixbuf_get_n_channels)(const GdkPixbuf *pixbuf);
660int (*fp_gdk_pixbuf_get_rowstride)(const GdkPixbuf *pixbuf);
661int (*fp_gdk_pixbuf_get_width)(const GdkPixbuf *pixbuf);
662GdkPixbuf *(*fp_gdk_pixbuf_new_from_file)(const char *filename, GError **error);
663
664#endif /* !_GTK2_INTERFACE_H */