diff options
author | Anatoly Spektor <aspektor@redhat.com> | 2013-02-18 14:53:25 -0500 |
---|---|---|
committer | Anatoly Spektor <aspektor@localhost> | 2013-02-25 12:11:25 -0500 |
commit | 9b03b61008b6b777807239332fb6c32cf968171b (patch) | |
tree | 4b9f4cf6f00341ff1a34fa14a6dbc8ba738b4c6f | |
parent | 343f779786dccf93f19a54ab36ff42d836e0a1b7 (diff) | |
download | eclipse.platform.swt-button_init_style.tar.gz eclipse.platform.swt-button_init_style.tar.xz eclipse.platform.swt-button_init_style.zip |
Initialize CSS button styling to solve button's height clipping issuebutton_init_style
6 files changed, 145 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index de01c3ec7c..cc58a0369d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -9522,6 +9522,53 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1container_1set_1border_1width) } #endif +#ifndef NO__1gtk_1css_1provider_1load_1from_1data +JNIEXPORT jboolean JNICALL OS_NATIVE(_1gtk_1css_1provider_1load_1from_1data) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jintLong arg2, jintLongArray arg3) +{ + jbyte *lparg1=NULL; + jintLong *lparg3=NULL; + jboolean rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1css_1provider_1load_1from_1data_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg3) if ((lparg3 = (*env)->GetIntLongArrayElements(env, arg3, NULL)) == NULL) goto fail; +/* + rc = (jboolean)gtk_css_provider_load_from_data(arg0, (const gchar *)lparg1, (gssize)arg2, (GError **)lparg3); +*/ + { + OS_LOAD_FUNCTION(fp, gtk_css_provider_load_from_data) + if (fp) { + rc = (jboolean)((jboolean (CALLING_CONVENTION*)(jintLong, const gchar *, gssize, GError **))fp)(arg0, (const gchar *)lparg1, (gssize)arg2, (GError **)lparg3); + } + } +fail: + if (arg3 && lparg3) (*env)->ReleaseIntLongArrayElements(env, arg3, lparg3, 0); + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1gtk_1css_1provider_1load_1from_1data_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1css_1provider_1new +JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1css_1provider_1new) + (JNIEnv *env, jclass that) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1css_1provider_1new_FUNC); +/* + rc = (jintLong)gtk_css_provider_new(); +*/ + { + OS_LOAD_FUNCTION(fp, gtk_css_provider_new) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)())fp)(); + } + } + OS_NATIVE_EXIT(env, that, _1gtk_1css_1provider_1new_FUNC); + return rc; +} +#endif + #ifndef NO__1gtk_1dialog_1add_1button JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1dialog_1add_1button) (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jint arg2) @@ -14904,6 +14951,24 @@ fail: } #endif +#ifndef NO__1gtk_1style_1context_1add_1provider +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1style_1context_1add_1provider) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1style_1context_1add_1provider_FUNC); +/* + gtk_style_context_add_provider(arg0, arg1, (guint)arg2); +*/ + { + OS_LOAD_FUNCTION(fp, gtk_style_context_add_provider) + if (fp) { + ((void (CALLING_CONVENTION*)(jintLong, jintLong, guint))fp)(arg0, arg1, (guint)arg2); + } + } + OS_NATIVE_EXIT(env, that, _1gtk_1style_1context_1add_1provider_FUNC); +} +#endif + #ifndef NO__1gtk_1style_1context_1get_1background_1color JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1style_1context_1get_1background_1color) (JNIEnv *env, jclass that, jintLong arg0, jint arg1, jobject arg2) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h index 68b919ba5e..2c4a43ba36 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h @@ -275,6 +275,7 @@ #define gtk_scrolled_window_get_hscrollbar_LIB LIB_GTK #define gtk_scrolled_window_get_vscrollbar_LIB LIB_GTK #define gtk_scale_new_LIB LIB_GTK +#define gtk_style_context_add_provider_LIB LIB_GTK #define gtk_style_context_restore_LIB LIB_GTK #define gtk_style_context_save_LIB LIB_GTK #define gtk_style_context_set_state_LIB LIB_GTK @@ -536,6 +537,8 @@ #define gdk_event_get_scroll_deltas_LIB LIB_GTK #define gtk_cell_renderer_set_fixed_size_LIB LIB_GTK #define gtk_cell_renderer_get_preferred_height_for_width_LIB LIB_GTK +#define gtk_css_provider_load_from_data_LIB LIB_GTK +#define gtk_css_provider_new_LIB LIB_GTK #define gtk_icon_set_render_icon_pixbuf_LIB LIB_GTK /* Field accessors */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c index 6633acb96b..aaf94eeac2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. All rights reserved. + * Copyright (c) 2000, 2013 IBM Corporation and others. All rights reserved. * The contents of this file are made available under the terms * of the GNU Lesser General Public License (LGPL) Version 2.1 that * accompanies this distribution (lgpl-v21.txt). The LGPL is also @@ -705,6 +705,8 @@ char * OS_nativeFunctionNames[] = { "_1gtk_1container_1remove", "_1gtk_1container_1resize_1children", "_1gtk_1container_1set_1border_1width", + "_1gtk_1css_1provider_1load_1from_1data", + "_1gtk_1css_1provider_1new", "_1gtk_1dialog_1add_1button", "_1gtk_1dialog_1run", "_1gtk_1drag_1begin", @@ -1063,6 +1065,7 @@ char * OS_nativeFunctionNames[] = { "_1gtk_1status_1icon_1set_1tooltip", "_1gtk_1status_1icon_1set_1visible", "_1gtk_1style_1context_1add_1class", + "_1gtk_1style_1context_1add_1provider", "_1gtk_1style_1context_1get_1background_1color", "_1gtk_1style_1context_1get_1border", "_1gtk_1style_1context_1get_1border_1color", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index d58537b454..23da50bfb3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. All rights reserved. + * Copyright (c) 2000, 2013 IBM Corporation and others. All rights reserved. * The contents of this file are made available under the terms * of the GNU Lesser General Public License (LGPL) Version 2.1 that * accompanies this distribution (lgpl-v21.txt). The LGPL is also @@ -715,6 +715,8 @@ typedef enum { _1gtk_1container_1remove_FUNC, _1gtk_1container_1resize_1children_FUNC, _1gtk_1container_1set_1border_1width_FUNC, + _1gtk_1css_1provider_1load_1from_1data_FUNC, + _1gtk_1css_1provider_1new_FUNC, _1gtk_1dialog_1add_1button_FUNC, _1gtk_1dialog_1run_FUNC, _1gtk_1drag_1begin_FUNC, @@ -1073,6 +1075,7 @@ typedef enum { _1gtk_1status_1icon_1set_1tooltip_FUNC, _1gtk_1status_1icon_1set_1visible_FUNC, _1gtk_1style_1context_1add_1class_FUNC, + _1gtk_1style_1context_1add_1provider_FUNC, _1gtk_1style_1context_1get_1background_1color_FUNC, _1gtk_1style_1context_1get_1border_FUNC, _1gtk_1style_1context_1get_1border_1color_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java index 135d5fe2cd..498108f012 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java @@ -410,6 +410,7 @@ public class OS extends C { public static final int GTK_TREE_VIEW_GRID_LINES_HORIZONTAL = 1; public static final int GTK_TREE_VIEW_GRID_LINES_VERTICAL = 2; public static final int GTK_TREE_VIEW_GRID_LINES_BOTH = 3; + public static final int GTK_STYLE_PROVIDER_PRIORITY_APPLICATION = 600; public static final int GDK_UNMAP = 15; public static final int GTK_UNIT_PIXEL = 0; public static final int GTK_UNIT_POINTS = 1; @@ -8451,6 +8452,44 @@ public static final long /*int*/ gtk_list_store_newv(int numColumns, long /*int* } } /** + * @method flags=dynamic + * @param data cast=(const gchar *) + * @param length cast=(gssize) + * @param error cast=(GError **) + */ +public static final native boolean _gtk_css_provider_load_from_data(long /*int*/ css_provider, byte[] data, long /*int*/ length, long /*int*/ error[]); +public static final boolean gtk_css_provider_load_from_data(long /*int*/ css_provider, byte[] data, long /*int*/ length, long /*int*/ error[] ) { + lock.lock(); + try { + return _gtk_css_provider_load_from_data(css_provider, data, length, error); + } finally { + lock.unlock(); + } +} +/** @method flags=dynamic */ +public static final native long /*int*/ _gtk_css_provider_new(); +public static final long /*int*/gtk_css_provider_new() { + lock.lock(); + try { + return _gtk_css_provider_new(); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param priority cast=(guint) + */ +public static final native void _gtk_style_context_add_provider (long /*int*/ context, long /*int*/ provider, int priority); +public static final void gtk_style_context_add_provider(long /*int*/ context, long /*int*/ provider, int priority) { + lock.lock(); + try { + _gtk_style_context_add_provider(context, provider, priority); + } finally { + lock.unlock(); + } +} +/** * @param list_store cast=(GtkListStore *) * @param iter cast=(GtkTreeIter *) */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java index 8282c908b3..44bc1ef632 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java @@ -273,6 +273,7 @@ void createHandle (int index) { break; case SWT.TOGGLE: handle = OS.gtk_toggle_button_new (); + initButtonStyle(handle); if (handle == 0) error (SWT.ERROR_NO_HANDLES); break; case SWT.CHECK: @@ -301,6 +302,7 @@ void createHandle (int index) { case SWT.PUSH: default: handle = OS.gtk_button_new (); + initButtonStyle(handle); if (handle == 0) error (SWT.ERROR_NO_HANDLES); gtk_widget_set_can_default (handle, true); break; @@ -995,5 +997,33 @@ int traversalCode (int key, GdkEventKey event) { if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS; return code; } +/** + * <p> + * This function receives widget and initializes it's style using CSS. + * Initialization of style is needed to avoid height-clipping issue. + * </p><p> + * As clipping occurs only in GTK3, implementation of the function + * is version guarded. + * </p> + * @param handle - button widget + */ +void initButtonStyle(long /*int*/ handle) { + if (OS.GTK3) { + String button_css = + ".button {\n" + + "-GtkButton-default-border : 0;\n" + + "-GtkButton-default-outside-border : 0;\n" + + "-GtkButton-inner-border: 0;\n" + + "-GtkWidget-focus-line-width : 0;\n" + + "-GtkWidget-focus-padding : 0;\n" + + "}"; + byte[] data = Converter.wcsToMbcs (null, button_css, true); + long /*int*/ provider = OS.gtk_css_provider_new(); + long/*int*/ context = OS.gtk_widget_get_style_context(handle); + OS.gtk_css_provider_load_from_data(provider, data, -1, null); + OS.gtk_style_context_add_provider (context, provider, OS.GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + OS.g_object_unref (provider); + } +} } |