Skip to content

[GTK] Use gtk_widget_set_visible instead of gtk_widget_hide/show #2125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

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

#ifndef NO_gtk_1widget_1hide
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1hide)
(JNIEnv *env, jclass that, jlong arg0)
{
GTK3_NATIVE_ENTER(env, that, gtk_1widget_1hide_FUNC);
gtk_widget_hide((GtkWidget *)arg0);
GTK3_NATIVE_EXIT(env, that, gtk_1widget_1hide_FUNC);
}
#endif

#ifndef NO_gtk_1widget_1input_1shape_1combine_1region
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1input_1shape_1combine_1region)
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)
Expand Down Expand Up @@ -2408,6 +2415,16 @@ JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1shape_1combine_1region)
}
#endif

#ifndef NO_gtk_1widget_1show
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1show)
(JNIEnv *env, jclass that, jlong arg0)
{
GTK3_NATIVE_ENTER(env, that, gtk_1widget_1show_FUNC);
gtk_widget_show((GtkWidget *)arg0);
GTK3_NATIVE_EXIT(env, that, gtk_1widget_1show_FUNC);
}
#endif

#ifndef NO_gtk_1widget_1size_1allocate
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1widget_1size_1allocate)
(JNIEnv *env, jclass that, jlong arg0, jobject arg1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */
Expand Down Expand Up @@ -209,6 +206,7 @@ typedef enum {
gtk_1widget_1get_1screen_FUNC,
gtk_1widget_1get_1toplevel_FUNC,
gtk_1widget_1get_1window_FUNC,
gtk_1widget_1hide_FUNC,
gtk_1widget_1input_1shape_1combine_1region_FUNC,
gtk_1widget_1override_1font_FUNC,
gtk_1widget_1remove_1accelerator_FUNC,
Expand All @@ -221,6 +219,7 @@ typedef enum {
gtk_1widget_1set_1parent_1window_FUNC,
gtk_1widget_1set_1redraw_1on_1allocate_FUNC,
gtk_1widget_1shape_1combine_1region_FUNC,
gtk_1widget_1show_FUNC,
gtk_1widget_1size_1allocate_FUNC,
gtk_1widget_1style_1get__J_3B_3IJ_FUNC,
gtk_1widget_1style_1get__J_3B_3JJ_FUNC,
Expand Down
3 changes: 0 additions & 3 deletions bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

/* Note: This file was auto-generated by org.eclipse.swt.tools.internal.JNIGenerator */
Expand Down
20 changes: 0 additions & 20 deletions bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -9352,16 +9352,6 @@ JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1widget_1has_1focus)
}
#endif

#ifndef NO_gtk_1widget_1hide
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1hide)
(JNIEnv *env, jclass that, jlong arg0)
{
GTK_NATIVE_ENTER(env, that, gtk_1widget_1hide_FUNC);
gtk_widget_hide((GtkWidget *)arg0);
GTK_NATIVE_EXIT(env, that, gtk_1widget_1hide_FUNC);
}
#endif

#ifndef NO_gtk_1widget_1insert_1action_1group
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1insert_1action_1group)
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1, jlong arg2)
Expand Down Expand Up @@ -9680,16 +9670,6 @@ JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1set_1visible)
}
#endif

#ifndef NO_gtk_1widget_1show
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1show)
(JNIEnv *env, jclass that, jlong arg0)
{
GTK_NATIVE_ENTER(env, that, gtk_1widget_1show_FUNC);
gtk_widget_show((GtkWidget *)arg0);
GTK_NATIVE_EXIT(env, that, gtk_1widget_1show_FUNC);
}
#endif

#ifndef NO_gtk_1widget_1unparent
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1widget_1unparent)
(JNIEnv *env, jclass that, jlong arg0)
Expand Down
2 changes: 0 additions & 2 deletions bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,6 @@ typedef enum {
gtk_1widget_1grab_1focus_FUNC,
gtk_1widget_1has_1default_FUNC,
gtk_1widget_1has_1focus_FUNC,
gtk_1widget_1hide_FUNC,
gtk_1widget_1insert_1action_1group_FUNC,
gtk_1widget_1is_1focus_FUNC,
gtk_1widget_1mnemonic_1activate_FUNC,
Expand All @@ -774,7 +773,6 @@ typedef enum {
gtk_1widget_1set_1valign_FUNC,
gtk_1widget_1set_1vexpand_FUNC,
gtk_1widget_1set_1visible_FUNC,
gtk_1widget_1show_FUNC,
gtk_1widget_1unparent_FUNC,
gtk_1window_1fullscreen_FUNC,
gtk_1window_1get_1default_1size_FUNC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2340,8 +2340,7 @@ public class GTK extends OS {
public static final native void gtk_widget_grab_focus(long widget);
/** @param widget cast=(GtkWidget *) */
public static final native boolean gtk_widget_has_focus(long widget);
/** @param widget cast=(GtkWidget *) */
public static final native void gtk_widget_hide(long widget);

/** @param widget cast=(GtkWidget *) */
public static final native boolean gtk_widget_is_focus(long widget);
/** @param widget cast=(GtkWidget *) */
Expand Down Expand Up @@ -2399,8 +2398,7 @@ public class GTK extends OS {
* @param height cast=(gint)
*/
public static final native void gtk_widget_set_size_request(long widget, int width, int height);
/** @param widget cast=(GtkWidget *) */
public static final native void gtk_widget_show(long widget);

/** @param widget cast=(GtkWidget *) */
public static final native boolean gtk_widget_activate(long widget);
/** @param widget cast=(GtkWidget *) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,5 +1089,9 @@ public class GTK3 {
public static final native int GdkEventWindowState_sizeof();
public static final native int GdkGeometry_sizeof();
public static final native int GdkWindowAttr_sizeof();
/** @param widget cast=(GtkWidget *) */
public static final native void gtk_widget_show(long widget);
/** @param widget cast=(GtkWidget *) */
public static final native void gtk_widget_hide(long widget);

}
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,13 @@ public void create (Composite parent, int style) {
OS.g_signal_connect (WebKitGTK.webkit_web_context_get_default(), WebKitGTK.download_started, Proc3.getAddress (), DOWNLOAD_STARTED);
}

GTK.gtk_widget_show (webView);
GTK.gtk_widget_show (browser.handle);
if (GTK.GTK4) {
GTK.gtk_widget_set_visible(webView, true);
GTK.gtk_widget_set_visible(browser.handle, true);
} else {
GTK3.gtk_widget_show(webView);
GTK3.gtk_widget_show(browser.handle);
}

// Webview 'title' property
OS.g_signal_connect (webView, WebKitGTK.notify_title, Proc3.getAddress (), NOTIFY_TITLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.function.*;

import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.internal.gtk3.*;
import org.eclipse.swt.widgets.*;

/**
Expand Down Expand Up @@ -76,7 +77,11 @@ static public int run(Display display, long handle, boolean isNativeDialog) {
if (isNativeDialog) {
GTK.gtk_native_dialog_show(handle);
} else {
GTK.gtk_widget_show(handle);
if (GTK.GTK4) {
GTK.gtk_widget_set_visible(handle, true);
} else {
GTK3.gtk_widget_show(handle);
}
}

while (!display.isDisposed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1295,28 +1295,28 @@ public void setText (String string) {

private void updateWidgetsVisibility() {
if (text.length() == 0 && image == null) {
GTK.gtk_widget_hide (boxHandle);
GTK.gtk_widget_hide (labelHandle);
GTK.gtk_widget_hide (imageHandle);
gtk_widget_hide (boxHandle);
gtk_widget_hide (labelHandle);
gtk_widget_hide (imageHandle);
} else {
GTK.gtk_widget_show (boxHandle);
gtk_widget_show (boxHandle);
if (text.length() == 0)
GTK.gtk_widget_hide (labelHandle);
gtk_widget_hide (labelHandle);
else
GTK.gtk_widget_show (labelHandle);
gtk_widget_show (labelHandle);
if (image == null)
GTK.gtk_widget_hide (imageHandle);
gtk_widget_hide (imageHandle);
else
GTK.gtk_widget_show (imageHandle);
gtk_widget_show (imageHandle);
}
}

@Override
void showWidget () {
super.showWidget ();
if (boxHandle != 0 && ((text != null && text.length() != 0) || image != null)) GTK.gtk_widget_show (boxHandle);
if (labelHandle != 0 && text != null && text.length() != 0) GTK.gtk_widget_show (labelHandle);
if (arrowHandle != 0) GTK.gtk_widget_show (arrowHandle);
if (boxHandle != 0 && ((text != null && text.length() != 0) || image != null)) gtk_widget_show (boxHandle);
if (labelHandle != 0 && text != null && text.length() != 0) gtk_widget_show (labelHandle);
if (arrowHandle != 0) gtk_widget_show (arrowHandle);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
if (fixedHandle != 0 && handle != 0
&& getVisible() && !GTK.gtk_widget_get_visible(topHandle) //if SWT State is not HIDDEN, but widget is hidden on GTK side.
&& topHandle == fixedHandle && width > 0 && height > 0 && resize) {
GTK.gtk_widget_show(topHandle);
gtk_widget_show(topHandle);
}

int result = super.setBounds (x, y, width, height, move, resize);
Expand Down Expand Up @@ -1823,7 +1823,7 @@ public void setTabList (Control [] tabList) {
void showWidget () {
super.showWidget ();
if (socketHandle != 0) {
GTK.gtk_widget_show (socketHandle);
gtk_widget_show (socketHandle);
embeddedHandle = GTK.gtk_socket_get_id (socketHandle);
}
if (scrolledHandle == 0) fixStyle (handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,10 +1145,10 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
*/
if (!GTK.gtk_widget_get_visible(topHandle)) {
Control focusControl = display.getFocusControl();
GTK.gtk_widget_show(topHandle);
gtk_widget_show(topHandle);
gtk_widget_get_preferred_size (topHandle, requisition);
gtk_widget_size_allocate(topHandle, allocation, -1);
GTK.gtk_widget_hide(topHandle);
gtk_widget_hide(topHandle);
/* Bug 540002: Showing and hiding widget causes original focused control to loose focus,
* Reset focus to original focused control after dealing with allocation.
*/
Expand Down Expand Up @@ -1180,7 +1180,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
}
}

GTK.gtk_widget_hide(topHandle);
gtk_widget_hide(topHandle);
} else {
if ((state & HIDDEN) == 0) {
if (!GTK.GTK4) {
Expand All @@ -1189,7 +1189,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
}
}

GTK.gtk_widget_show(topHandle);
gtk_widget_show(topHandle);
}
}

Expand Down Expand Up @@ -6126,7 +6126,7 @@ public void setVisible (boolean visible) {
if (!GTK.GTK4) {
if (enableWindow != 0) GDK.gdk_window_show_unraised(enableWindow);
}
GTK.gtk_widget_show (topHandle);
gtk_widget_show (topHandle);
}
} else {
/*
Expand All @@ -6151,7 +6151,7 @@ public void setVisible (boolean visible) {
if (isDisposed ()) return;
GTK.gtk_widget_set_can_focus (topHandle, true);
}
GTK.gtk_widget_hide (topHandle);
gtk_widget_hide (topHandle);
if (isDisposed ()) return;
if (!GTK.GTK4) {
if (enableWindow != 0) GDK.gdk_window_hide(enableWindow);
Expand Down Expand Up @@ -6338,9 +6338,9 @@ void showWidget () {
} else {
GTK3.gtk_container_add(parentHandle, topHandle);
}
if (handle != 0 && handle != topHandle) GTK.gtk_widget_show (handle);
if (handle != 0 && handle != topHandle) gtk_widget_show (handle);
if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) {
if (fixedHandle != 0) GTK.gtk_widget_show (fixedHandle);
if (fixedHandle != 0) gtk_widget_show (fixedHandle);
}
if (fixedHandle != 0) fixStyle (fixedHandle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ private void createHandleForCalendar() {
flags |= GTK.GTK_CALENDAR_SHOW_WEEK_NUMBERS;
}
GTK3.gtk_calendar_set_display_options(handle, flags);
GTK.gtk_widget_show(handle);
gtk_widget_show(handle);
}
}

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

GTK3.gtk_container_add(fixedHandle, handle);
GTK3.gtk_container_add(handle, textEntryHandle);
GTK.gtk_widget_show(containerHandle);
GTK.gtk_widget_show(textEntryHandle);
gtk_widget_show(containerHandle);
gtk_widget_show(textEntryHandle);


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

void hideDateTime () {
if (isDate () || isTime ()){
GTK.gtk_widget_hide (fixedHandle);
gtk_widget_hide (fixedHandle);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public long await(long result) {
}
}
}

Optional<String> result = Optional.empty();
if (response == GTK.GTK_RESPONSE_ACCEPT) {
result = Optional.ofNullable(selectedPath);
Expand Down Expand Up @@ -306,7 +306,7 @@ void GTK3setNativeDialogMessage(long handle, String message) {
if (label == 0) error(SWT.ERROR_NO_HANDLES);

GTK3.gtk_container_add(box, label);
GTK.gtk_widget_show(label);
GTK3.gtk_widget_show(label);
GTK3.gtk_label_set_line_wrap(label, true);

GTK.gtk_box_set_homogeneous(box, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5556,7 +5556,7 @@ void showIMWindow (Control control) {
GTK4.gtk_window_set_child(preeditWindow, preeditLabel);
} else {
GTK3.gtk_container_add (preeditWindow, preeditLabel);
GTK.gtk_widget_show (preeditLabel);
GTK3.gtk_widget_show (preeditLabel);
}
}
long [] preeditString = new long [1];
Expand All @@ -5578,9 +5578,9 @@ void showIMWindow (Control control) {
GtkRequisition requisition = new GtkRequisition ();
GTK.gtk_widget_get_preferred_size (preeditLabel, requisition, null);
GTK3.gtk_window_resize (preeditWindow, requisition.width, requisition.height);
GTK.gtk_widget_show (preeditWindow);
GTK3.gtk_widget_show (preeditWindow);
} else {
GTK.gtk_widget_hide (preeditWindow);
GTK3.gtk_widget_hide (preeditWindow);
}
if (preeditString [0] != 0) OS.g_free (preeditString [0]);
if (pangoAttrs [0] != 0) OS.pango_attr_list_unref (pangoAttrs [0]);
Expand Down
Loading
Loading