diff options
author | Eric Williams | 2019-01-30 19:30:48 +0000 |
---|---|---|
committer | Eric Williams | 2019-02-04 20:15:00 +0000 |
commit | 68151edac00a7e6861d405833a6c270526304454 (patch) | |
tree | 352109edeac4cdb8fa0d0e0a63bb511450e2e19c | |
parent | a43e2d35df296d43c4e345e18c2412744183d278 (diff) | |
download | eclipse.platform.swt-68151edac00a7e6861d405833a6c270526304454.tar.gz eclipse.platform.swt-68151edac00a7e6861d405833a6c270526304454.tar.xz eclipse.platform.swt-68151edac00a7e6861d405833a6c270526304454.zip |
Bug 543989: [GTK4] De-couple GtkEntry calls from GtkSpinButton
Separate GtkSpinButton from the actual GtkEntry handle inside of it
before calling gtk_entry_* functions.
Tested on GTK4 using Snippet184, Snippet190, and Snippet310.
Change-Id: I7d175ce836d65f7a67755ff6b3fdff5f84cc0faf
Signed-off-by: Eric Williams <ericwill@redhat.com>
7 files changed, 83 insertions, 36 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 948d0cfd74..c25e26ed32 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 @@ -12167,6 +12167,18 @@ JNIEXPORT jint JNICALL GTK_NATIVE(_1gtk_1widget_1get_1events) } #endif +#ifndef NO__1gtk_1widget_1get_1first_1child +JNIEXPORT jintLong JNICALL GTK_NATIVE(_1gtk_1widget_1get_1first_1child) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jintLong rc = 0; + GTK_NATIVE_ENTER(env, that, _1gtk_1widget_1get_1first_1child_FUNC); + rc = (jintLong)gtk_widget_get_first_child((GtkWidget *)arg0); + GTK_NATIVE_EXIT(env, that, _1gtk_1widget_1get_1first_1child_FUNC); + return rc; +} +#endif + #ifndef NO__1gtk_1widget_1get_1has_1surface JNIEXPORT jboolean JNICALL GTK_NATIVE(_1gtk_1widget_1get_1has_1surface) (JNIEnv *env, jclass that, jintLong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h index 6ddf4a2891..20cc9a2642 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h @@ -438,6 +438,7 @@ #define NO__1gdk_1display_1get_1keymap #define NO__1gtk_1widget_1measure #define NO__1gtk_1style_1context_1add_1provider_1for_1display +#define NO__1gtk_1widget_1get_1first_1child // GdkCursor API changes from GTK3 -> GTK4 #define NO__1gdk_1cursor_1new_1from_1name___3BI 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 0b5b142757..4c0fc02e47 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 @@ -1109,6 +1109,7 @@ char * GTK_nativeFunctionNames[] = { "_1gtk_1widget_1get_1child_1visible", "_1gtk_1widget_1get_1clip", "_1gtk_1widget_1get_1events", + "_1gtk_1widget_1get_1first_1child", "_1gtk_1widget_1get_1has_1surface", "_1gtk_1widget_1get_1has_1window", "_1gtk_1widget_1get_1mapped", 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 8b73563106..bc462370ca 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 @@ -1107,6 +1107,7 @@ typedef enum { _1gtk_1widget_1get_1child_1visible_FUNC, _1gtk_1widget_1get_1clip_FUNC, _1gtk_1widget_1get_1events_FUNC, + _1gtk_1widget_1get_1first_1child_FUNC, _1gtk_1widget_1get_1has_1surface_FUNC, _1gtk_1widget_1get_1has_1window_FUNC, _1gtk_1widget_1get_1mapped_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java index 2823e1c55a..4de0307541 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java @@ -463,6 +463,18 @@ public class GTK extends OS { } } + /** @param widget cast=(GtkWidget *) */ + public static final native long /*int*/ _gtk_widget_get_first_child(long /*int*/ widget); + /** [GTK4 only, if-def'd in os.h] */ + public static final long /*int*/ gtk_widget_get_first_child(long /*int*/ widget) { + lock.lock(); + try { + return _gtk_widget_get_first_child(widget); + } finally { + lock.unlock(); + } + } + /** * @param widget cast=(GtkWidget *) */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java index 6111f78cbf..e8810f6e52 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java @@ -68,7 +68,7 @@ public class DateTime extends Composite { * Major handles of this class. * Note, these can vary or all equal each other depending on Date/Time/Calendar/Drop_down * configuration used. See createHandle () */ - long /*int*/ textEntryHandle, + long /*int*/ textEntryHandle, spinButtonHandle, containerHandle, calendarHandle; @@ -295,7 +295,7 @@ Point computeMaxTextSize (int wHint, int hHint, boolean changed) { // Fixed length for DEFAULT_SHORT_DATE_FORMAT, no need to adjust text length. } - Point textSize = computeNativeSize (textEntryHandle, wHint, hHint, changed); + Point textSize = computeNativeSize (GTK.GTK4? spinButtonHandle : textEntryHandle, wHint, hHint, changed); // Change the text back to match the current calendar updateControl(); return textSize; @@ -361,7 +361,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) { Rectangle trim = super.computeTrimInPixels (x, y, width, height); int xborder = 0, yborder = 0; GtkBorder tmp = new GtkBorder (); - long /*int*/ context = GTK.gtk_widget_get_style_context (textEntryHandle); + long /*int*/ context = GTK.gtk_widget_get_style_context (GTK.GTK4 ? spinButtonHandle :textEntryHandle); int state_flag = GTK.GTK_VERSION < OS.VERSION(3, 18, 0) ? GTK.GTK_STATE_FLAG_NORMAL : GTK.gtk_widget_get_state_flags(textEntryHandle); gtk_style_context_get_padding(context, state_flag, tmp); trim.x -= tmp.left; @@ -464,13 +464,20 @@ private void createHandleForDateWithDropDown () { private void createHandleForDateTime () { long /*int*/ adjusment = GTK.gtk_adjustment_new (0, -9999, 9999, 1, 0, 0); - textEntryHandle = GTK.gtk_spin_button_new (adjusment, 1, 0); + if (GTK.GTK4) { + spinButtonHandle = GTK.gtk_spin_button_new (adjusment, 1, 0); + long /*int*/ boxHandle = GTK.gtk_widget_get_first_child(spinButtonHandle); + long /*int*/ textHandle = GTK.gtk_widget_get_first_child(boxHandle); + textEntryHandle = textHandle; + handle = spinButtonHandle; + containerHandle = spinButtonHandle; + } else { + textEntryHandle = GTK.gtk_spin_button_new (adjusment, 1, 0); + handle = textEntryHandle; + containerHandle = textEntryHandle; + } if (textEntryHandle == 0) error (SWT.ERROR_NO_HANDLES); - //in this case,the Entry becomes the container. - handle = textEntryHandle; - containerHandle = textEntryHandle; - GTK.gtk_spin_button_set_numeric (textEntryHandle, false); GTK.gtk_container_add (fixedHandle, textEntryHandle); GTK.gtk_spin_button_set_wrap (textEntryHandle, (style & SWT.WRAP) != 0); @@ -913,8 +920,13 @@ long /*int*/ fontHandle () { private long /*int*/ dateTimeHandle () { if (isCalendar () && calendarHandle != 0) { return calendarHandle; - } else if ((isDate () || isTime ()) && textEntryHandle != 0) { - return textEntryHandle; + } else if ((isDate () || isTime ())) { + if (GTK.GTK4) { + if (spinButtonHandle != 0) return spinButtonHandle; + } else { + if (textEntryHandle != 0) return textEntryHandle; + } + return super.focusHandle (); } else { return super.focusHandle (); } @@ -1677,12 +1689,13 @@ void setBoundsInPixels (int x, int y, int width, int height) { //Date with Drop down is in container. Needs extra handling. if (isDateWithDropDownButton ()) { + long /*int*/ sizingHandle = GTK.GTK4 ? spinButtonHandle : textEntryHandle; GtkRequisition requisition = new GtkRequisition (); - GTK.gtk_widget_get_preferred_size (textEntryHandle, null, requisition); + GTK.gtk_widget_get_preferred_size (sizingHandle, null, requisition); int oldHeight = requisition.height; //Entry should not expand vertically. It is single liner. int newWidth = width - (down.getSizeInPixels ().x + getGtkBorderPadding ().right); - GTK.gtk_widget_set_size_request (textEntryHandle, (newWidth >= 0) ? newWidth : 0, oldHeight); + GTK.gtk_widget_set_size_request (sizingHandle, (newWidth >= 0) ? newWidth : 0, oldHeight); } /* @@ -1719,7 +1732,7 @@ private void setDropDownButtonSize () { Point buttonSize = down.computeSizeInPixels (SWT.DEFAULT, parentHeight); //TAG_GTK3__NO_VERTICAL_FILL_ADJUSTMENT - int dateEntryHeight = computeNativeSize (textEntryHandle, SWT.DEFAULT, SWT.DEFAULT, false).y; + int dateEntryHeight = computeNativeSize (GTK.GTK4 ? spinButtonHandle : textEntryHandle, SWT.DEFAULT, SWT.DEFAULT, false).y; int newHeight = dateEntryHeight; //Move button a little closer to entry field, by amount of padding. @@ -1738,8 +1751,9 @@ private void setDropDownButtonSize () { GtkBorder getGtkBorderPadding () { //In Gtk3, acquire border. GtkBorder gtkBorderPadding = new GtkBorder (); - long /*int*/ context = GTK.gtk_widget_get_style_context (textEntryHandle); - int state_flag = GTK.GTK_VERSION < OS.VERSION(3, 18, 0) ? GTK.GTK_STATE_FLAG_NORMAL : GTK.gtk_widget_get_state_flags(textEntryHandle); + long /*int*/ contextHandle = GTK.GTK4 ? spinButtonHandle : textEntryHandle; + long /*int*/ context = GTK.gtk_widget_get_style_context (contextHandle); + int state_flag = GTK.GTK_VERSION < OS.VERSION(3, 18, 0) ? GTK.GTK_STATE_FLAG_NORMAL : GTK.gtk_widget_get_state_flags(contextHandle); gtk_style_context_get_padding(context, state_flag, gtkBorderPadding); return gtkBorderPadding; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java index 9a8ade8c89..38edffdfa6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java @@ -50,6 +50,7 @@ public class Spinner extends Composite { int lastEventTime = 0; long /*int*/ imContext; long /*int*/ gdkEventKey = 0; + long /*int*/ entryHandle; int fixStart = -1, fixEnd = -1; double climbRate = 1; @@ -212,7 +213,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) { if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; GTK.gtk_widget_realize (handle); - long /*int*/ layout = GTK.gtk_entry_get_layout (handle); + long /*int*/ layout = GTK.gtk_entry_get_layout (GTK.GTK4 ? entryHandle : handle); long /*int*/ hAdjustment = GTK.gtk_spin_button_get_adjustment (handle); double upper = GTK.gtk_adjustment_get_upper (hAdjustment); int digits = GTK.gtk_spin_button_get_digits (handle); @@ -267,7 +268,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) { int [] property = new int [1]; if (!GTK.GTK4) GTK.gtk_widget_style_get (handle, OS.interior_focus, property, 0); if (property [0] == 0) { - GTK.gtk_widget_style_get (handle, OS.focus_line_width, property, 0); + if (!GTK.GTK4) GTK.gtk_widget_style_get (handle, OS.focus_line_width, property, 0); xborder += property [0]; yborder += property [0]; } @@ -291,7 +292,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) { */ public void copy () { checkWidget (); - GTK.gtk_editable_copy_clipboard (handle); + GTK.gtk_editable_copy_clipboard (GTK.GTK4? entryHandle : handle); } @Override @@ -305,9 +306,14 @@ void createHandle (int index) { handle = GTK.gtk_spin_button_new (adjustment, climbRate, 0); if (handle == 0) error (SWT.ERROR_NO_HANDLES); GTK.gtk_container_add (fixedHandle, handle); - GTK.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0); + if (GTK.GTK4) { + long /*int*/ boxHandle = GTK.gtk_widget_get_first_child(handle); + long /*int*/ textHandle = GTK.gtk_widget_get_first_child(boxHandle); + entryHandle = textHandle; + } + GTK.gtk_editable_set_editable (GTK.GTK4 ? entryHandle : handle, (style & SWT.READ_ONLY) == 0); if (GTK.GTK_VERSION <= OS.VERSION(3, 20, 0)) { - GTK.gtk_entry_set_has_frame (handle, (style & SWT.BORDER) != 0); + GTK.gtk_entry_set_has_frame (GTK.GTK4 ? entryHandle : handle, (style & SWT.BORDER) != 0); } GTK.gtk_spin_button_set_wrap (handle, (style & SWT.WRAP) != 0); imContext = OS.imContextLast(); @@ -330,7 +336,7 @@ void createHandle (int index) { */ public void cut () { checkWidget (); - GTK.gtk_editable_cut_clipboard (handle); + GTK.gtk_editable_cut_clipboard (GTK.GTK4? entryHandle : handle); } @Override @@ -516,7 +522,7 @@ public int getSelection () { */ public String getText () { checkWidget (); - long /*int*/ str = GTK.gtk_entry_get_text (handle); + long /*int*/ str = GTK.gtk_entry_get_text (GTK.GTK4 ? entryHandle : handle); if (str == 0) return ""; int length = C.strlen (str); byte [] buffer = new byte [length]; @@ -543,7 +549,7 @@ public String getText () { */ public int getTextLimit () { checkWidget (); - int limit = GTK.gtk_entry_get_max_length (handle); + int limit = GTK.gtk_entry_get_max_length (GTK.GTK4 ? entryHandle : handle); return limit == 0 ? LIMIT : limit; } @@ -578,7 +584,7 @@ long /*int*/ gtk_activate (long /*int*/ widget) { @Override long /*int*/ gtk_changed (long /*int*/ widget) { - long /*int*/ str = GTK.gtk_entry_get_text (handle); + long /*int*/ str = GTK.gtk_entry_get_text (GTK.GTK4 ? entryHandle : handle); int length = C.strlen (str); if (length > 0) { long /*int*/ [] endptr = new long /*int*/ [1]; @@ -624,7 +630,7 @@ long /*int*/ gtk_changed (long /*int*/ widget) { @Override long /*int*/ gtk_commit (long /*int*/ imContext, long /*int*/ text) { if (text == 0) return 0; - if (!GTK.gtk_editable_get_editable (handle)) return 0; + if (!GTK.gtk_editable_get_editable (GTK.GTK4? entryHandle : handle)) return 0; int length = C.strlen (text); if (length == 0) return 0; byte [] buffer = new byte [length]; @@ -653,8 +659,8 @@ long /*int*/ gtk_commit (long /*int*/ imContext, long /*int*/ text) { OS.g_signal_handlers_unblock_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle); if (fixStart != -1 && fixEnd != -1) { - GTK.gtk_editable_set_position (handle, fixStart); - GTK.gtk_editable_select_region (handle, fixStart, fixEnd); + GTK.gtk_editable_set_position (GTK.GTK4? entryHandle : handle, fixStart); + GTK.gtk_editable_select_region (GTK.GTK4? entryHandle : handle, fixStart, fixEnd); } fixStart = fixEnd = -1; return 0; @@ -663,7 +669,7 @@ long /*int*/ gtk_commit (long /*int*/ imContext, long /*int*/ text) { @Override long /*int*/ gtk_delete_text (long /*int*/ widget, long /*int*/ start_pos, long /*int*/ end_pos) { if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - long /*int*/ ptr = GTK.gtk_entry_get_text (handle); + long /*int*/ ptr = GTK.gtk_entry_get_text (GTK.GTK4 ? entryHandle : handle); if (end_pos == -1) end_pos = OS.g_utf8_strlen (ptr, -1); int start = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, start_pos); int end = (int)/*64*/OS.g_utf8_offset_to_utf16_offset (ptr, end_pos); @@ -677,10 +683,10 @@ long /*int*/ gtk_delete_text (long /*int*/ widget, long /*int*/ start_pos, long byte [] buffer = Converter.wcsToMbcs (newText, false); OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - GTK.gtk_editable_insert_text (handle, buffer, buffer.length, pos); + GTK.gtk_editable_insert_text (GTK.GTK4? entryHandle : handle, buffer, buffer.length, pos); OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - GTK.gtk_editable_set_position (handle, pos [0]); + GTK.gtk_editable_set_position (GTK.GTK4? entryHandle : handle, pos [0]); } } return 0; @@ -707,24 +713,24 @@ long /*int*/ gtk_insert_text (long /*int*/ widget, long /*int*/ new_text, long / String oldText = new String (Converter.mbcsToWcs (buffer)); int [] pos = new int [1]; C.memmove (pos, position, 4); - long /*int*/ ptr = GTK.gtk_entry_get_text (handle); + long /*int*/ ptr = GTK.gtk_entry_get_text (GTK.GTK4 ? entryHandle : handle); if (pos [0] == -1) pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1); int start = (int)/*64*/OS.g_utf16_pointer_to_offset (ptr, pos [0]); String newText = verifyText (oldText, start, start); if (newText != oldText) { int [] newStart = new int [1], newEnd = new int [1]; - GTK.gtk_editable_get_selection_bounds (handle, newStart, newEnd); + GTK.gtk_editable_get_selection_bounds (GTK.GTK4? entryHandle : handle, newStart, newEnd); if (newText != null) { if (newStart [0] != newEnd [0]) { OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - GTK.gtk_editable_delete_selection (handle); + GTK.gtk_editable_delete_selection (GTK.GTK4? entryHandle : handle); OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); } byte [] buffer3 = Converter.wcsToMbcs (newText, false); OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - GTK.gtk_editable_insert_text (handle, buffer3, buffer3.length, pos); + GTK.gtk_editable_insert_text (GTK.GTK4? entryHandle : handle, buffer3, buffer3.length, pos); OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); newStart [0] = newEnd [0] = pos [0]; } @@ -818,7 +824,7 @@ long /*int*/ paintSurface () { */ public void paste () { checkWidget (); - GTK.gtk_editable_paste_clipboard (handle); + GTK.gtk_editable_paste_clipboard (GTK.GTK4? entryHandle : handle); } @Override @@ -1086,7 +1092,7 @@ public void setSelection (int value) { public void setTextLimit (int limit) { checkWidget (); if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - GTK.gtk_entry_set_max_length (handle, limit); + GTK.gtk_entry_set_max_length (GTK.GTK4 ? entryHandle : handle, limit); } /** |