Skip to content

Commit 06b77ef

Browse files
committed
patch 8.0.1466: older GTK versions don't have gtk_entry_get_text_length()
Problem: Older GTK versions don't have gtk_entry_get_text_length(). Solution: Add a function with #ifdefs to take care of GTK version differences. (Kazunobu Kuriyama, closes #2605)
1 parent 4bc0bed commit 06b77ef

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/gui_gtk.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,37 @@ convert_localized_message(char_u **buffer, const char *message)
21442144
return (const char *)*buffer;
21452145
}
21462146

2147+
/*
2148+
* Returns the number of characters in GtkEntry.
2149+
*/
2150+
static unsigned long
2151+
entry_get_text_length(GtkEntry *entry)
2152+
{
2153+
g_return_val_if_fail(entry != NULL, 0);
2154+
g_return_val_if_fail(GTK_IS_ENTRY(entry) == TRUE, 0);
2155+
2156+
#if GTK_CHECK_VERSION(2,18,0)
2157+
/* 2.18 introduced a new object GtkEntryBuffer to handle text data for
2158+
* GtkEntry instead of letting each instance of the latter have its own
2159+
* storage for that. The code below is almost identical to the
2160+
* implementation of gtk_entry_get_text_length() for the versions >= 2.18.
2161+
*/
2162+
return gtk_entry_buffer_get_length(gtk_entry_get_buffer(entry));
2163+
#elif GTK_CHECK_VERSION(2,14,0)
2164+
/* 2.14 introduced a new function to avoid memory management bugs which can
2165+
* happen when gtk_entry_get_text() is used without due care and attention.
2166+
*/
2167+
return gtk_entry_get_text_length(entry);
2168+
#else
2169+
/* gtk_entry_get_text() returns the pointer to the storage allocated
2170+
* internally by the widget. Accordingly, use the one with great care:
2171+
* Don't free it nor modify the contents it points to; call the function
2172+
* every time you need the pointer since its value may have been changed
2173+
* by the widget. */
2174+
return g_utf8_strlen(gtk_entry_get_text(entry), -1);
2175+
#endif
2176+
}
2177+
21472178
static void
21482179
find_replace_dialog_create(char_u *arg, int do_replace)
21492180
{
@@ -2198,10 +2229,9 @@ find_replace_dialog_create(char_u *arg, int do_replace)
21982229
* For :promptrepl dialog, give it to 'with' entry if 'what' has an
21992230
* non-empty entry; otherwise, to 'what' entry. */
22002231
gtk_widget_grab_focus(frdp->what);
2201-
if (do_replace && gtk_entry_get_text_length(GTK_ENTRY(frdp->what)))
2232+
if (do_replace && entry_get_text_length(GTK_ENTRY(frdp->what)) > 0)
22022233
gtk_widget_grab_focus(frdp->with);
22032234

2204-
22052235
vim_free(entry_text);
22062236
return;
22072237
}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1466,
774776
/**/
775777
1465,
776778
/**/

0 commit comments

Comments
 (0)