Skip to content

Commit dd02a6d

Browse files
committed
[Gtk4] Use gtk_widget_set_visible to replace gtk_widget_hide/show #228
Add helper methods that redirect to GTK/GTK3 in Widget for convenience. Contributes to #228
1 parent 4df99ba commit dd02a6d

34 files changed

+161
-150
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c

+20-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
11-
* Contributors:
12-
* IBM Corporation - initial API and implementation
1310
*******************************************************************************/
1411

1512
/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */
@@ -2275,6 +2272,16 @@ JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1widget_1get_1window)
22752272
}
22762273
#endif
22772274

2275+
#ifndef NO_gtk_1widget_1hide
2276+
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1hide)
2277+
(JNIEnv *env, jclass that, jlong arg0)
2278+
{
2279+
GTK3_NATIVE_ENTER(env, that, gtk_1widget_1hide_FUNC);
2280+
gtk_widget_hide((GtkWidget *)arg0);
2281+
GTK3_NATIVE_EXIT(env, that, gtk_1widget_1hide_FUNC);
2282+
}
2283+
#endif
2284+
22782285
#ifndef NO_gtk_1widget_1input_1shape_1combine_1region
22792286
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1input_1shape_1combine_1region)
22802287
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)
@@ -2408,6 +2415,16 @@ JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1shape_1combine_1region)
24082415
}
24092416
#endif
24102417

2418+
#ifndef NO_gtk_1widget_1show
2419+
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1show)
2420+
(JNIEnv *env, jclass that, jlong arg0)
2421+
{
2422+
GTK3_NATIVE_ENTER(env, that, gtk_1widget_1show_FUNC);
2423+
gtk_widget_show((GtkWidget *)arg0);
2424+
GTK3_NATIVE_EXIT(env, that, gtk_1widget_1show_FUNC);
2425+
}
2426+
#endif
2427+
24112428
#ifndef NO_gtk_1widget_1size_1allocate
24122429
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1size_1allocate)
24132430
(JNIEnv *env, jclass that, jlong arg0, jobject arg1)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
11-
* Contributors:
12-
* IBM Corporation - initial API and implementation
1310
*******************************************************************************/
1411

1512
/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */
@@ -209,6 +206,7 @@ typedef enum {
209206
gtk_1widget_1get_1screen_FUNC,
210207
gtk_1widget_1get_1toplevel_FUNC,
211208
gtk_1widget_1get_1window_FUNC,
209+
gtk_1widget_1hide_FUNC,
212210
gtk_1widget_1input_1shape_1combine_1region_FUNC,
213211
gtk_1widget_1override_1font_FUNC,
214212
gtk_1widget_1remove_1accelerator_FUNC,
@@ -221,6 +219,7 @@ typedef enum {
221219
gtk_1widget_1set_1parent_1window_FUNC,
222220
gtk_1widget_1set_1redraw_1on_1allocate_FUNC,
223221
gtk_1widget_1shape_1combine_1region_FUNC,
222+
gtk_1widget_1show_FUNC,
224223
gtk_1widget_1size_1allocate_FUNC,
225224
gtk_1widget_1style_1get__J_3B_3IJ_FUNC,
226225
gtk_1widget_1style_1get__J_3B_3JJ_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
11-
* Contributors:
12-
* IBM Corporation - initial API and implementation
1310
*******************************************************************************/
1411

1512
/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
11-
* Contributors:
12-
* IBM Corporation - initial API and implementation
1310
*******************************************************************************/
1411

1512
/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c

-20
Original file line numberDiff line numberDiff line change
@@ -9352,16 +9352,6 @@ JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1widget_1has_1focus)
93529352
}
93539353
#endif
93549354

9355-
#ifndef NO_gtk_1widget_1hide
9356-
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1hide)
9357-
(JNIEnv *env, jclass that, jlong arg0)
9358-
{
9359-
GTK_NATIVE_ENTER(env, that, gtk_1widget_1hide_FUNC);
9360-
gtk_widget_hide((GtkWidget *)arg0);
9361-
GTK_NATIVE_EXIT(env, that, gtk_1widget_1hide_FUNC);
9362-
}
9363-
#endif
9364-
93659355
#ifndef NO_gtk_1widget_1insert_1action_1group
93669356
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1insert_1action_1group)
93679357
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1, jlong arg2)
@@ -9680,16 +9670,6 @@ JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1set_1visible)
96809670
}
96819671
#endif
96829672

9683-
#ifndef NO_gtk_1widget_1show
9684-
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1show)
9685-
(JNIEnv *env, jclass that, jlong arg0)
9686-
{
9687-
GTK_NATIVE_ENTER(env, that, gtk_1widget_1show_FUNC);
9688-
gtk_widget_show((GtkWidget *)arg0);
9689-
GTK_NATIVE_EXIT(env, that, gtk_1widget_1show_FUNC);
9690-
}
9691-
#endif
9692-
96939673
#ifndef NO_gtk_1widget_1unparent
96949674
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1unparent)
96959675
(JNIEnv *env, jclass that, jlong arg0)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h

-2
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ typedef enum {
748748
gtk_1widget_1grab_1focus_FUNC,
749749
gtk_1widget_1has_1default_FUNC,
750750
gtk_1widget_1has_1focus_FUNC,
751-
gtk_1widget_1hide_FUNC,
752751
gtk_1widget_1insert_1action_1group_FUNC,
753752
gtk_1widget_1is_1focus_FUNC,
754753
gtk_1widget_1mnemonic_1activate_FUNC,
@@ -774,7 +773,6 @@ typedef enum {
774773
gtk_1widget_1set_1valign_FUNC,
775774
gtk_1widget_1set_1vexpand_FUNC,
776775
gtk_1widget_1set_1visible_FUNC,
777-
gtk_1widget_1show_FUNC,
778776
gtk_1widget_1unparent_FUNC,
779777
gtk_1window_1fullscreen_FUNC,
780778
gtk_1window_1get_1default_1size_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -2340,8 +2340,7 @@ public class GTK extends OS {
23402340
public static final native void gtk_widget_grab_focus(long widget);
23412341
/** @param widget cast=(GtkWidget *) */
23422342
public static final native boolean gtk_widget_has_focus(long widget);
2343-
/** @param widget cast=(GtkWidget *) */
2344-
public static final native void gtk_widget_hide(long widget);
2343+
23452344
/** @param widget cast=(GtkWidget *) */
23462345
public static final native boolean gtk_widget_is_focus(long widget);
23472346
/** @param widget cast=(GtkWidget *) */
@@ -2399,8 +2398,7 @@ public class GTK extends OS {
23992398
* @param height cast=(gint)
24002399
*/
24012400
public static final native void gtk_widget_set_size_request(long widget, int width, int height);
2402-
/** @param widget cast=(GtkWidget *) */
2403-
public static final native void gtk_widget_show(long widget);
2401+
24042402
/** @param widget cast=(GtkWidget *) */
24052403
public static final native boolean gtk_widget_activate(long widget);
24062404
/** @param widget cast=(GtkWidget *) */

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java

+4
Original file line numberDiff line numberDiff line change
@@ -1089,5 +1089,9 @@ public class GTK3 {
10891089
public static final native int GdkEventWindowState_sizeof();
10901090
public static final native int GdkGeometry_sizeof();
10911091
public static final native int GdkWindowAttr_sizeof();
1092+
/** @param widget cast=(GtkWidget *) */
1093+
public static final native void gtk_widget_show(long widget);
1094+
/** @param widget cast=(GtkWidget *) */
1095+
public static final native void gtk_widget_hide(long widget);
10921096

10931097
}

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java

+1
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ public class GTK4 {
658658
public static final native void gtk_widget_set_focusable(long widget, boolean focusable);
659659
/** @param widget cast=(GtkWidget *) */
660660
public static final native long gtk_widget_get_clipboard(long widget);
661+
661662
/**
662663
* @param widget cast=(GtkWidget *)
663664
* @param allocation cast=(GtkAllocation *),flags=no_out

bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,13 @@ public void create (Composite parent, int style) {
709709
OS.g_signal_connect (WebKitGTK.webkit_web_context_get_default(), WebKitGTK.download_started, Proc3.getAddress (), DOWNLOAD_STARTED);
710710
}
711711

712-
GTK.gtk_widget_show (webView);
713-
GTK.gtk_widget_show (browser.handle);
712+
if (GTK.GTK4) {
713+
GTK.gtk_widget_set_visible(webView, true);
714+
GTK.gtk_widget_set_visible(browser.handle, true);
715+
} else {
716+
GTK3.gtk_widget_show(webView);
717+
GTK3.gtk_widget_show(browser.handle);
718+
}
714719

715720
// Webview 'title' property
716721
OS.g_signal_connect (webView, WebKitGTK.notify_title, Proc3.getAddress (), NOTIFY_TITLE);

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/SyncDialogUtil.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.function.*;
1818

1919
import org.eclipse.swt.internal.gtk.*;
20+
import org.eclipse.swt.internal.gtk3.*;
2021
import org.eclipse.swt.widgets.*;
2122

2223
/**
@@ -76,7 +77,11 @@ static public int run(Display display, long handle, boolean isNativeDialog) {
7677
if (isNativeDialog) {
7778
GTK.gtk_native_dialog_show(handle);
7879
} else {
79-
GTK.gtk_widget_show(handle);
80+
if (GTK.GTK4) {
81+
GTK.gtk_widget_set_visible(handle, true);
82+
} else {
83+
GTK3.gtk_widget_show(handle);
84+
}
8085
}
8186

8287
while (!display.isDisposed()) {

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1295,28 +1295,28 @@ public void setText (String string) {
12951295

12961296
private void updateWidgetsVisibility() {
12971297
if (text.length() == 0 && image == null) {
1298-
GTK.gtk_widget_hide (boxHandle);
1299-
GTK.gtk_widget_hide (labelHandle);
1300-
GTK.gtk_widget_hide (imageHandle);
1298+
gtk_widget_hide (boxHandle);
1299+
gtk_widget_hide (labelHandle);
1300+
gtk_widget_hide (imageHandle);
13011301
} else {
1302-
GTK.gtk_widget_show (boxHandle);
1302+
gtk_widget_show (boxHandle);
13031303
if (text.length() == 0)
1304-
GTK.gtk_widget_hide (labelHandle);
1304+
gtk_widget_hide (labelHandle);
13051305
else
1306-
GTK.gtk_widget_show (labelHandle);
1306+
gtk_widget_show (labelHandle);
13071307
if (image == null)
1308-
GTK.gtk_widget_hide (imageHandle);
1308+
gtk_widget_hide (imageHandle);
13091309
else
1310-
GTK.gtk_widget_show (imageHandle);
1310+
gtk_widget_show (imageHandle);
13111311
}
13121312
}
13131313

13141314
@Override
13151315
void showWidget () {
13161316
super.showWidget ();
1317-
if (boxHandle != 0 && ((text != null && text.length() != 0) || image != null)) GTK.gtk_widget_show (boxHandle);
1318-
if (labelHandle != 0 && text != null && text.length() != 0) GTK.gtk_widget_show (labelHandle);
1319-
if (arrowHandle != 0) GTK.gtk_widget_show (arrowHandle);
1317+
if (boxHandle != 0 && ((text != null && text.length() != 0) || image != null)) gtk_widget_show (boxHandle);
1318+
if (labelHandle != 0 && text != null && text.length() != 0) gtk_widget_show (labelHandle);
1319+
if (arrowHandle != 0) gtk_widget_show (arrowHandle);
13201320
}
13211321

13221322
@Override

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
16601660
if (fixedHandle != 0 && handle != 0
16611661
&& getVisible() && !GTK.gtk_widget_get_visible(topHandle) //if SWT State is not HIDDEN, but widget is hidden on GTK side.
16621662
&& topHandle == fixedHandle && width > 0 && height > 0 && resize) {
1663-
GTK.gtk_widget_show(topHandle);
1663+
gtk_widget_show(topHandle);
16641664
}
16651665

16661666
int result = super.setBounds (x, y, width, height, move, resize);
@@ -1823,7 +1823,7 @@ public void setTabList (Control [] tabList) {
18231823
void showWidget () {
18241824
super.showWidget ();
18251825
if (socketHandle != 0) {
1826-
GTK.gtk_widget_show (socketHandle);
1826+
gtk_widget_show (socketHandle);
18271827
embeddedHandle = GTK.gtk_socket_get_id (socketHandle);
18281828
}
18291829
if (scrolledHandle == 0) fixStyle (handle);

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,10 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
11451145
*/
11461146
if (!GTK.gtk_widget_get_visible(topHandle)) {
11471147
Control focusControl = display.getFocusControl();
1148-
GTK.gtk_widget_show(topHandle);
1148+
gtk_widget_show(topHandle);
11491149
gtk_widget_get_preferred_size (topHandle, requisition);
11501150
gtk_widget_size_allocate(topHandle, allocation, -1);
1151-
GTK.gtk_widget_hide(topHandle);
1151+
gtk_widget_hide(topHandle);
11521152
/* Bug 540002: Showing and hiding widget causes original focused control to loose focus,
11531153
* Reset focus to original focused control after dealing with allocation.
11541154
*/
@@ -1180,7 +1180,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
11801180
}
11811181
}
11821182

1183-
GTK.gtk_widget_hide(topHandle);
1183+
gtk_widget_hide(topHandle);
11841184
} else {
11851185
if ((state & HIDDEN) == 0) {
11861186
if (!GTK.GTK4) {
@@ -1189,7 +1189,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
11891189
}
11901190
}
11911191

1192-
GTK.gtk_widget_show(topHandle);
1192+
gtk_widget_show(topHandle);
11931193
}
11941194
}
11951195

@@ -6126,7 +6126,7 @@ public void setVisible (boolean visible) {
61266126
if (!GTK.GTK4) {
61276127
if (enableWindow != 0) GDK.gdk_window_show_unraised(enableWindow);
61286128
}
6129-
GTK.gtk_widget_show (topHandle);
6129+
gtk_widget_show (topHandle);
61306130
}
61316131
} else {
61326132
/*
@@ -6151,7 +6151,7 @@ public void setVisible (boolean visible) {
61516151
if (isDisposed ()) return;
61526152
GTK.gtk_widget_set_can_focus (topHandle, true);
61536153
}
6154-
GTK.gtk_widget_hide (topHandle);
6154+
gtk_widget_hide (topHandle);
61556155
if (isDisposed ()) return;
61566156
if (!GTK.GTK4) {
61576157
if (enableWindow != 0) GDK.gdk_window_hide(enableWindow);
@@ -6338,9 +6338,9 @@ void showWidget () {
63386338
} else {
63396339
GTK3.gtk_container_add(parentHandle, topHandle);
63406340
}
6341-
if (handle != 0 && handle != topHandle) GTK.gtk_widget_show (handle);
6341+
if (handle != 0 && handle != topHandle) gtk_widget_show (handle);
63426342
if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) {
6343-
if (fixedHandle != 0) GTK.gtk_widget_show (fixedHandle);
6343+
if (fixedHandle != 0) gtk_widget_show (fixedHandle);
63446344
}
63456345
if (fixedHandle != 0) fixStyle (fixedHandle);
63466346
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ private void createHandleForCalendar() {
434434
flags |= GTK.GTK_CALENDAR_SHOW_WEEK_NUMBERS;
435435
}
436436
GTK3.gtk_calendar_set_display_options(handle, flags);
437-
GTK.gtk_widget_show(handle);
437+
gtk_widget_show(handle);
438438
}
439439
}
440440

@@ -457,8 +457,8 @@ private void createHandleForDateWithDropDown () {
457457

458458
GTK3.gtk_container_add(fixedHandle, handle);
459459
GTK3.gtk_container_add(handle, textEntryHandle);
460-
GTK.gtk_widget_show(containerHandle);
461-
GTK.gtk_widget_show(textEntryHandle);
460+
gtk_widget_show(containerHandle);
461+
gtk_widget_show(textEntryHandle);
462462

463463

464464
// In GTK 3 font description is inherited from parent widget which is not how SWT has always worked,
@@ -2326,7 +2326,7 @@ void selectAll () {
23262326

23272327
void hideDateTime () {
23282328
if (isDate () || isTime ()){
2329-
GTK.gtk_widget_hide (fixedHandle);
2329+
gtk_widget_hide (fixedHandle);
23302330
}
23312331
}
23322332

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public long await(long result) {
275275
}
276276
}
277277
}
278-
278+
279279
Optional<String> result = Optional.empty();
280280
if (response == GTK.GTK_RESPONSE_ACCEPT) {
281281
result = Optional.ofNullable(selectedPath);
@@ -306,7 +306,7 @@ void GTK3setNativeDialogMessage(long handle, String message) {
306306
if (label == 0) error(SWT.ERROR_NO_HANDLES);
307307

308308
GTK3.gtk_container_add(box, label);
309-
GTK.gtk_widget_show(label);
309+
GTK3.gtk_widget_show(label);
310310
GTK3.gtk_label_set_line_wrap(label, true);
311311

312312
GTK.gtk_box_set_homogeneous(box, false);

0 commit comments

Comments
 (0)