comparison src/gui_gtk.c @ 13184:2ede8acf65dc v8.0.1466

patch 8.0.1466: older GTK versions don't have gtk_entry_get_text_length() commit https://github.com/vim/vim/commit/06b77ef69f252e1ba8a2136dcbed6622bc2371bb Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 4 14:32:57 2018 +0100 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)
author Christian Brabandt <cb@256bit.org>
date Sun, 04 Feb 2018 14:45:06 +0100
parents 729f279fda8d
children 8412df1479a3
comparison
equal deleted inserted replaced
13183:583679d18392 13184:2ede8acf65dc
2142 *buffer = string_convert(&output_conv, (char_u *)message, NULL); 2142 *buffer = string_convert(&output_conv, (char_u *)message, NULL);
2143 2143
2144 return (const char *)*buffer; 2144 return (const char *)*buffer;
2145 } 2145 }
2146 2146
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
2147 static void 2178 static void
2148 find_replace_dialog_create(char_u *arg, int do_replace) 2179 find_replace_dialog_create(char_u *arg, int do_replace)
2149 { 2180 {
2150 GtkWidget *hbox; /* main top down box */ 2181 GtkWidget *hbox; /* main top down box */
2151 GtkWidget *actionarea; 2182 GtkWidget *actionarea;
2196 2227
2197 /* For :promptfind dialog, always give keyboard focus to 'what' entry. 2228 /* For :promptfind dialog, always give keyboard focus to 'what' entry.
2198 * For :promptrepl dialog, give it to 'with' entry if 'what' has an 2229 * For :promptrepl dialog, give it to 'with' entry if 'what' has an
2199 * non-empty entry; otherwise, to 'what' entry. */ 2230 * non-empty entry; otherwise, to 'what' entry. */
2200 gtk_widget_grab_focus(frdp->what); 2231 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)
2202 gtk_widget_grab_focus(frdp->with); 2233 gtk_widget_grab_focus(frdp->with);
2203
2204 2234
2205 vim_free(entry_text); 2235 vim_free(entry_text);
2206 return; 2236 return;
2207 } 2237 }
2208 2238