Skip to content

Commit 2f29886

Browse files
committed
[GTK] Fix Spinner [get|set]TextLimit on GTK 4
1 parent 84f02de commit 2f29886

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,18 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1editable_1get_1delegate)
707707
}
708708
#endif
709709

710+
#ifndef NO_gtk_1editable_1get_1max_1width_1chars
711+
JNIEXPORT jint JNICALL GTK4_NATIVE(gtk_1editable_1get_1max_1width_1chars)
712+
(JNIEnv *env, jclass that, jlong arg0)
713+
{
714+
jint rc = 0;
715+
GTK4_NATIVE_ENTER(env, that, gtk_1editable_1get_1max_1width_1chars_FUNC);
716+
rc = (jint)gtk_editable_get_max_width_chars((GtkEditable *)arg0);
717+
GTK4_NATIVE_EXIT(env, that, gtk_1editable_1get_1max_1width_1chars_FUNC);
718+
return rc;
719+
}
720+
#endif
721+
710722
#ifndef NO_gtk_1editable_1get_1text
711723
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1editable_1get_1text)
712724
(JNIEnv *env, jclass that, jlong arg0)
@@ -719,6 +731,16 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1editable_1get_1text)
719731
}
720732
#endif
721733

734+
#ifndef NO_gtk_1editable_1set_1max_1width_1chars
735+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1editable_1set_1max_1width_1chars)
736+
(JNIEnv *env, jclass that, jlong arg0, jint arg1)
737+
{
738+
GTK4_NATIVE_ENTER(env, that, gtk_1editable_1set_1max_1width_1chars_FUNC);
739+
gtk_editable_set_max_width_chars((GtkEditable *)arg0, (int)arg1);
740+
GTK4_NATIVE_EXIT(env, that, gtk_1editable_1set_1max_1width_1chars_FUNC);
741+
}
742+
#endif
743+
722744
#ifndef NO_gtk_1entry_1buffer_1get_1text
723745
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1entry_1buffer_1get_1text)
724746
(JNIEnv *env, jclass that, jlong arg0)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ typedef enum {
7272
gtk_1drop_1target_1async_1new_FUNC,
7373
gtk_1drop_1target_1async_1set_1formats_FUNC,
7474
gtk_1editable_1get_1delegate_FUNC,
75+
gtk_1editable_1get_1max_1width_1chars_FUNC,
7576
gtk_1editable_1get_1text_FUNC,
77+
gtk_1editable_1set_1max_1width_1chars_FUNC,
7678
gtk_1entry_1buffer_1get_1text_FUNC,
7779
gtk_1entry_1get_1buffer_FUNC,
7880
gtk_1entry_1get_1text_1length_FUNC,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ public class GTK4 {
120120
public static final native long gtk_editable_get_text(long editable);
121121
/** @param editable cast=(GtkEditable *) */
122122
public static final native long gtk_editable_get_delegate(long editable);
123+
/**
124+
* @param editable cast=(GtkEditable *)
125+
*/
126+
public static final native int gtk_editable_get_max_width_chars(long editable);
127+
/**
128+
* @param editable cast=(GtkEditable *)
129+
* @param chars cast=(int)
130+
*/
131+
public static final native void gtk_editable_set_max_width_chars(long editable, int chars);
123132

124133
/* GtkPicture */
125134
public static final native long gtk_picture_new();

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void createHandle (int index) {
330330
GTK3.gtk_widget_set_has_window(fixedHandle, true);
331331
GTK3.gtk_container_add (fixedHandle, handle);
332332
}
333-
GTK.gtk_editable_set_editable (GTK.GTK4 ? entryHandle : handle, (style & SWT.READ_ONLY) == 0);
333+
GTK.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0);
334334
GTK.gtk_spin_button_set_wrap (handle, (style & SWT.WRAP) != 0);
335335
imContext = OS.imContextLast();
336336
// In GTK 3 font description is inherited from parent widget which is not how SWT has always worked,
@@ -586,7 +586,12 @@ public String getText() {
586586
*/
587587
public int getTextLimit () {
588588
checkWidget ();
589-
int limit = GTK.gtk_entry_get_max_length (GTK.GTK4 ? entryHandle : handle);
589+
int limit;
590+
if (GTK.GTK4) {
591+
limit = GTK4.gtk_editable_get_max_width_chars(handle);
592+
} else {
593+
limit = GTK.gtk_entry_get_max_length (handle);
594+
}
590595
return limit == 0 ? LIMIT : limit;
591596
}
592597

@@ -1160,7 +1165,11 @@ public void setSelection (int value) {
11601165
public void setTextLimit (int limit) {
11611166
checkWidget ();
11621167
if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);
1163-
GTK.gtk_entry_set_max_length (GTK.GTK4 ? entryHandle : handle, limit);
1168+
if(GTK.GTK4) {
1169+
GTK4.gtk_editable_set_max_width_chars (handle, limit);
1170+
} else {
1171+
GTK.gtk_entry_set_max_length (handle, limit);
1172+
}
11641173
}
11651174

11661175
/**

0 commit comments

Comments
 (0)