Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul D'Pong2021-05-12 19:34:18 +0000
committerAlexander Kurtakov2021-05-13 07:54:10 +0000
commit19b470e4361ea3aa71538354ad8bca160c749675 (patch)
tree0762a280a6b793730373699f9c4608628d20bdde
parentfca781fb3e82a8c3f91313a2cb819aff9b8aa0e7 (diff)
downloadeclipse.platform.swt-19b470e4361ea3aa71538354ad8bca160c749675.tar.gz
eclipse.platform.swt-19b470e4361ea3aa71538354ad8bca160c749675.tar.xz
eclipse.platform.swt-19b470e4361ea3aa71538354ad8bca160c749675.zip
Bug 573387 - [GTK4] ControlExample fix errors due to GTK3 only functions
- Moved gtk_widget_add_events & their corresponding mask into GTK3 only guard - In Text, moved gtk_entry_set_width_chars into previous style check for SWT.SINGLE and into GTK3 guard - Replaced gtk_entry_get_layout with GTK4 equivalent - Proper GTK4 font description retrieval in getFontDescription - Place gtk_widget_set_redraw_on_allocate & gtk_widget_set_double_buffered behind GTK3 only guard Change-Id: I589dc8cf24add948d79b7e527b0868fd9021b41c Signed-off-by: Paul D'Pong <sdamrong@redhat.com> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/180552 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java31
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java30
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java7
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java20
5 files changed, 56 insertions, 34 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
index 8809d0b82a..806e8d6a4b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java
@@ -397,20 +397,23 @@ void createHandle (int index, boolean fixed, boolean scrolled) {
GTK3.gtk_container_add (handle, socketHandle);
}
}
- if ((style & SWT.NO_REDRAW_RESIZE) != 0 && (style & SWT.RIGHT_TO_LEFT) == 0) {
- GTK3.gtk_widget_set_redraw_on_allocate (handle, false);
- }
- /*
- * Bug in GTK. When a widget is double buffered and the back
- * pixmap is null, the double buffer pixmap is filled with the
- * background of the widget rather than the current contents of
- * the screen. If nothing is drawn during an expose event,
- * the pixels are altered. The fix is to clear double buffering
- * when NO_BACKGROUND is set and DOUBLE_BUFFERED
- * is not explicitly set.
- */
- if ((style & SWT.DOUBLE_BUFFERED) == 0 && (style & SWT.NO_BACKGROUND) != 0) {
- GTK3.gtk_widget_set_double_buffered (handle, false);
+
+ if (!GTK.GTK4) {
+ if ((style & SWT.NO_REDRAW_RESIZE) != 0 && (style & SWT.RIGHT_TO_LEFT) == 0) {
+ GTK3.gtk_widget_set_redraw_on_allocate (handle, false);
+ }
+ /*
+ * Bug in GTK. When a widget is double buffered and the back
+ * pixmap is null, the double buffer pixmap is filled with the
+ * background of the widget rather than the current contents of
+ * the screen. If nothing is drawn during an expose event,
+ * the pixels are altered. The fix is to clear double buffering
+ * when NO_BACKGROUND is set and DOUBLE_BUFFERED
+ * is not explicitly set.
+ */
+ if ((style & SWT.DOUBLE_BUFFERED) == 0 && (style & SWT.NO_BACKGROUND) != 0) {
+ GTK3.gtk_widget_set_double_buffered (handle, false);
+ }
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
index 5c3a376c02..8b3be27724 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
@@ -3139,15 +3139,29 @@ long getFontDescription () {
// returns pointer owned by GTK. The workaround is to make a copy of the data.
long gtkOwnedPointer = GTK.gtk_style_context_get_font(context, GTK.GTK_STATE_FLAG_NORMAL);
return OS.pango_font_description_copy(gtkOwnedPointer);
- } else if (GTK.GTK4) {
- GTK.gtk_style_context_get(context, GTK.gtk_style_property_font, fontDesc, 0);
- return fontDesc [0];
} else {
- GTK.gtk_style_context_save(context);
- GTK.gtk_style_context_set_state(context, GTK.GTK_STATE_FLAG_NORMAL);
- GTK.gtk_style_context_get(context, GTK.GTK_STATE_FLAG_NORMAL, GTK.gtk_style_property_font, fontDesc, 0);
- GTK.gtk_style_context_restore(context);
- return fontDesc [0];
+ if (GTK.GTK4) {
+ long[] fontPtr = new long[1];
+ long settings = GTK.gtk_settings_get_default();
+ OS.g_object_get(settings, GTK.gtk_style_property_font, fontPtr, 0);
+ if (fontPtr[0] != 0) {
+ int length = C.strlen(fontPtr[0]);
+ if (length != 0) {
+ byte[] fontString = new byte[length + 1];
+ C.memmove(fontString, fontPtr[0], length);
+ OS.g_free(fontPtr[0]);
+ return OS.pango_font_description_from_string(fontString);
+ }
+ }
+
+ return 0;
+ } else {
+ GTK.gtk_style_context_save(context);
+ GTK.gtk_style_context_set_state(context, GTK.GTK_STATE_FLAG_NORMAL);
+ GTK.gtk_style_context_get(context, GTK.GTK_STATE_FLAG_NORMAL, GTK.gtk_style_property_font, fontDesc, 0);
+ GTK.gtk_style_context_restore(context);
+ return fontDesc [0];
+ }
}
}
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 fd89010ab5..326070eb24 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
@@ -955,15 +955,14 @@ void hookEvents () {
if (isCalendar ()) {
hookEventsForCalendar ();
} else {
- int eventMask = GDK.GDK_POINTER_MOTION_MASK | GDK.GDK_BUTTON_PRESS_MASK | GDK.GDK_BUTTON_RELEASE_MASK;
- GTK3.gtk_widget_add_events (textEntryHandle, eventMask);
-
-
if ((style & SWT.DROP_DOWN) == 0 ) {
hookEventsForDateTimeSpinner ();
}
if (!GTK.GTK4) {
+ int eventMask = GDK.GDK_POINTER_MOTION_MASK | GDK.GDK_BUTTON_PRESS_MASK | GDK.GDK_BUTTON_RELEASE_MASK;
+ GTK3.gtk_widget_add_events(textEntryHandle, eventMask);
+
if (OS.G_OBJECT_TYPE (textEntryHandle) == GTK3.GTK_TYPE_MENU ()) {
hookEventsForMenu ();
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java
index 576cda7b12..f9b5a23e4f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java
@@ -484,7 +484,7 @@ long gtk_realize (long widget) {
@Override
void hookEvents () {
super.hookEvents ();
- GTK3.gtk_widget_add_events (handle, GDK.GDK_POINTER_MOTION_HINT_MASK);
+ if (!GTK.GTK4) GTK3.gtk_widget_add_events(handle, GDK.GDK_POINTER_MOTION_HINT_MASK);
}
@Override
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
index 851bfa5606..45942fc512 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
@@ -234,6 +234,8 @@ void createHandle (int index) {
} else {
GTK3.gtk_widget_set_has_window(fixedHandle, true);
GTK3.gtk_container_add(fixedHandle, handle);
+
+ GTK3.gtk_entry_set_width_chars(handle, 1);
}
GTK.gtk_editable_set_editable(handle, (style & SWT.READ_ONLY) == 0);
@@ -298,9 +300,7 @@ void createHandle (int index) {
GTK.gtk_text_view_set_justification (handle, just);
}
imContext = OS.imContextLast();
- if ((style & SWT.SINGLE) != 0) {
- GTK3.gtk_entry_set_width_chars(handle, 1);
- }
+
// In GTK 3 font description is inherited from parent widget which is not how SWT has always worked,
// reset to default font to get the usual behavior
setFontDescription(defaultFont().handle);
@@ -613,11 +613,17 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
checkWidget ();
if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
- int[] w = new int [1], h = new int [1];
+ int[] w = new int[1], h = new int[1];
if ((style & SWT.SINGLE) != 0) {
- GTK.gtk_widget_realize (handle);
- long layout = GTK3.gtk_entry_get_layout (handle);
- OS.pango_layout_get_pixel_size (layout, w, h);
+ long layout;
+ if (GTK.GTK4) {
+ long context = GTK.gtk_widget_get_pango_context(handle);
+ layout = OS.pango_layout_new(context);
+ } else {
+ GTK.gtk_widget_realize(handle);
+ layout = GTK3.gtk_entry_get_layout(handle);
+ }
+ OS.pango_layout_get_pixel_size(layout, w, h);
} else {
byte [] start = new byte [ITER_SIZEOF], end = new byte [ITER_SIZEOF];
GTK.gtk_text_buffer_get_bounds (bufferHandle, start, end);

Back to the top