Reworked the code handling "manual backspace" in the dialer and PIN entry dialogs

This commit is contained in:
Pierre Pronchery 2014-12-02 22:20:20 +01:00
parent 9235114f7c
commit f0cc6dcf43

View File

@ -737,24 +737,31 @@ void phone_code_enter(Phone * phone)
/* phone_code_backspace */ /* phone_code_backspace */
void phone_code_backspace(Phone * phone) void phone_code_backspace(Phone * phone)
{ {
int pos; int start;
int end;
#if !GTK_CHECK_VERSION(2, 14, 0) #if !GTK_CHECK_VERSION(2, 14, 0)
char const * s; char const * s;
#endif #endif
if((pos = gtk_editable_get_position(GTK_EDITABLE(phone->en_entry))) if(gtk_editable_get_selection_bounds(GTK_EDITABLE(phone->en_entry),
< 1) &start, &end) == FALSE)
{ {
if((end = gtk_editable_get_position(GTK_EDITABLE(
phone->en_entry))) < 1)
{
#if GTK_CHECK_VERSION(2, 14, 0) #if GTK_CHECK_VERSION(2, 14, 0)
pos = gtk_entry_get_text_length(GTK_ENTRY(phone->en_entry)); end = gtk_entry_get_text_length(GTK_ENTRY(
phone->en_entry));
#else #else
s = gtk_entry_get_text(GTK_ENTRY(phone->en_entry)); s = gtk_entry_get_text(GTK_ENTRY(phone->en_entry));
pos = strlen(s); end = strlen(s);
#endif #endif
}
start = end - 1;
} }
if(pos < 1) if(end < 1)
return; return;
gtk_editable_delete_text(GTK_EDITABLE(phone->en_entry), pos - 1, pos); gtk_editable_delete_text(GTK_EDITABLE(phone->en_entry), start, end);
} }
@ -945,24 +952,31 @@ int phone_dialer_append(Phone * phone, char character)
/* phone_dialer_backspace */ /* phone_dialer_backspace */
void phone_dialer_backspace(Phone * phone) void phone_dialer_backspace(Phone * phone)
{ {
int pos; int start;
int end;
#if !GTK_CHECK_VERSION(2, 14, 0) #if !GTK_CHECK_VERSION(2, 14, 0)
char const * s; char const * s;
#endif #endif
if((pos = gtk_editable_get_position(GTK_EDITABLE(phone->di_entry))) if(gtk_editable_get_selection_bounds(GTK_EDITABLE(phone->di_entry),
< 1) &start, &end) == FALSE)
{ {
if((end = gtk_editable_get_position(GTK_EDITABLE(
phone->di_entry))) < 1)
{
#if GTK_CHECK_VERSION(2, 14, 0) #if GTK_CHECK_VERSION(2, 14, 0)
pos = gtk_entry_get_text_length(GTK_ENTRY(phone->di_entry)); end = gtk_entry_get_text_length(GTK_ENTRY(
phone->di_entry));
#else #else
s = gtk_entry_get_text(GTK_ENTRY(phone->di_entry)); s = gtk_entry_get_text(GTK_ENTRY(phone->di_entry));
pos = strlen(s); end = strlen(s);
#endif #endif
}
start = end - 1;
} }
if(pos < 1) if(end < 1)
return; return;
gtk_editable_delete_text(GTK_EDITABLE(phone->di_entry), pos - 1, pos); gtk_editable_delete_text(GTK_EDITABLE(phone->di_entry), start, end);
} }