text, entry and labels: setters during the first style of a text view no longer crash, a text view destroyed during a selection drag keeps its buffer, tags up to the end relayout, a link handler that changes the label is safe, label selections survive the same text, keypad cut/copy/paste, Select All only with text, IM cursor positions in characters, accelerator labels without XF86, spin buttons take digits of other scripts, as in GTK+ 3
This commit is contained in:
parent
16d92e39b4
commit
c787fa9d78
10 changed files with 157 additions and 45 deletions
|
|
@ -1258,12 +1258,16 @@ gtk_accelerator_parse (const gchar *accelerator,
|
|||
}
|
||||
else
|
||||
{
|
||||
gchar last_ch;
|
||||
|
||||
last_ch = *accelerator;
|
||||
while (last_ch && last_ch != '>')
|
||||
/* skip an unknown modifier, up to and including its '>';
|
||||
* without one, stop at the end of the string rather than
|
||||
* reading past it */
|
||||
while (len > 0 && *accelerator != '>')
|
||||
{
|
||||
accelerator += 1;
|
||||
len -= 1;
|
||||
}
|
||||
if (len > 0)
|
||||
{
|
||||
last_ch = *accelerator;
|
||||
accelerator += 1;
|
||||
len -= 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -572,16 +572,34 @@ gtk_accel_label_get_string (GtkAccelLabel *accel_label)
|
|||
}
|
||||
|
||||
/* Underscores in key names are better displayed as spaces
|
||||
* E.g., Page_Up should be "Page Up"
|
||||
* E.g., Page_Up should be "Page Up".
|
||||
*
|
||||
* Some keynames also have prefixes that are not suitable
|
||||
* for display, e.g XF86AudioMute, so strip those out, too.
|
||||
*
|
||||
* This function is only called on untranslated keynames,
|
||||
* so no need to be UTF-8 safe.
|
||||
*/
|
||||
static void
|
||||
substitute_underscores (char *str)
|
||||
append_without_underscores (GString *s,
|
||||
const gchar *str)
|
||||
{
|
||||
char *p;
|
||||
const gchar *p;
|
||||
|
||||
for (p = str; *p; p++)
|
||||
if (*p == '_')
|
||||
*p = ' ';
|
||||
if (g_str_has_prefix (str, "XF86"))
|
||||
p = str + 4;
|
||||
else if (g_str_has_prefix (str, "ISO_"))
|
||||
p = str + 4;
|
||||
else
|
||||
p = str;
|
||||
|
||||
for ( ; *p; p++)
|
||||
{
|
||||
if (*p == '_')
|
||||
g_string_append_c (s, ' ');
|
||||
else
|
||||
g_string_append_c (s, *p);
|
||||
}
|
||||
}
|
||||
|
||||
/* On Mac, if the key has symbolic representation (e.g. arrow keys),
|
||||
|
|
@ -808,10 +826,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
|
|||
const gchar *str;
|
||||
str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
|
||||
if (str == tmp)
|
||||
{
|
||||
g_string_append (gstring, tmp);
|
||||
substitute_underscores (gstring->str);
|
||||
}
|
||||
append_without_underscores (gstring, tmp);
|
||||
else
|
||||
g_string_append (gstring, str);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1782,6 +1782,13 @@ gtk_entry_class_init (GtkEntryClass *class)
|
|||
gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
|
||||
"paste-clipboard", 0);
|
||||
|
||||
gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_SHIFT_MASK,
|
||||
"cut-clipboard", 0);
|
||||
gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, GDK_CONTROL_MASK,
|
||||
"copy-clipboard", 0);
|
||||
gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, GDK_SHIFT_MASK,
|
||||
"paste-clipboard", 0);
|
||||
|
||||
/**
|
||||
* GtkEntry::insert-emoji:
|
||||
* @entry: the object which received the signal
|
||||
|
|
@ -8979,6 +8986,7 @@ popup_targets_received (GtkClipboard *clipboard,
|
|||
gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem);
|
||||
|
||||
menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
|
||||
gtk_widget_set_sensitive (menuitem, gtk_entry_get_text_length (entry) > 0);
|
||||
g_signal_connect_swapped (menuitem, "activate",
|
||||
G_CALLBACK (gtk_entry_select_all), entry);
|
||||
gtk_widget_show (menuitem);
|
||||
|
|
|
|||
|
|
@ -1198,8 +1198,9 @@ gtk_im_context_simple_get_preedit_string (GtkIMContext *context,
|
|||
}
|
||||
}
|
||||
|
||||
/* in characters, not bytes */
|
||||
if (cursor_pos)
|
||||
*cursor_pos = len;
|
||||
*cursor_pos = g_utf8_strlen (outbuf, len);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1758,11 +1758,18 @@ static void
|
|||
gtk_label_set_text_internal (GtkLabel *label,
|
||||
gchar *str)
|
||||
{
|
||||
gboolean text_changed;
|
||||
|
||||
text_changed = g_strcmp0 (label->text, str) != 0;
|
||||
|
||||
g_free (label->text);
|
||||
|
||||
label->text = str;
|
||||
|
||||
gtk_label_select_region_index (label, 0, 0);
|
||||
/* Re-setting the same text for internal reasons (e.g. when the
|
||||
* mnemonics become visible upon Alt press) keeps the selection */
|
||||
if (text_changed)
|
||||
gtk_label_select_region_index (label, 0, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -4353,8 +4360,10 @@ gtk_label_button_release (GtkWidget *widget,
|
|||
info->selection_anchor == info->selection_end &&
|
||||
info->link_clicked)
|
||||
{
|
||||
emit_activate_link (label, info->active_link);
|
||||
/* reset first: a handler of ::activate-link may change the
|
||||
* text of the label, which can free @info */
|
||||
info->link_clicked = 0;
|
||||
emit_activate_link (label, info->active_link);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -4409,7 +4418,8 @@ drag_begin_cb (GtkWidget *widget,
|
|||
|
||||
label = GTK_LABEL (widget);
|
||||
|
||||
if ((label->select_info->selection_anchor !=
|
||||
if (label->select_info &&
|
||||
(label->select_info->selection_anchor !=
|
||||
label->select_info->selection_end) &&
|
||||
label->text)
|
||||
{
|
||||
|
|
@ -4631,7 +4641,9 @@ gtk_label_create_window (GtkLabel *label)
|
|||
GDK_POINTER_MOTION_MASK |
|
||||
GDK_POINTER_MOTION_HINT_MASK;
|
||||
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
|
||||
if (gtk_widget_is_sensitive (widget))
|
||||
/* the text cursor only where text can be selected, not over a label
|
||||
* that only has links (as gtk_label_update_cursor() does) */
|
||||
if (gtk_widget_is_sensitive (widget) && label->select_info->selectable)
|
||||
{
|
||||
attributes.cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
|
||||
GDK_XTERM);
|
||||
|
|
@ -4843,7 +4855,8 @@ static void
|
|||
gtk_label_set_selection_text (GtkLabel *label,
|
||||
GtkSelectionData *selection_data)
|
||||
{
|
||||
if ((label->select_info->selection_anchor !=
|
||||
if (label->select_info &&
|
||||
(label->select_info->selection_anchor !=
|
||||
label->select_info->selection_end) &&
|
||||
label->text)
|
||||
{
|
||||
|
|
@ -5898,7 +5911,12 @@ emit_activate_link (GtkLabel *label,
|
|||
gboolean handled;
|
||||
|
||||
g_signal_emit (label, signals[ACTIVATE_LINK], 0, link->uri, &handled);
|
||||
if (handled && label->track_links && !link->visited)
|
||||
|
||||
/* A handler may have changed the text of the label, freeing @link */
|
||||
if (handled && label->track_links &&
|
||||
label->select_info &&
|
||||
g_list_find (label->select_info->links, link) &&
|
||||
!link->visited)
|
||||
{
|
||||
link->visited = TRUE;
|
||||
/* FIXME: shouldn't have to redo everything here */
|
||||
|
|
|
|||
|
|
@ -384,6 +384,9 @@ copy_activate_cb (GtkWidget *widget,
|
|||
{
|
||||
GtkLinkButtonPrivate *priv = link_button->priv;
|
||||
|
||||
if (priv->uri == NULL)
|
||||
return;
|
||||
|
||||
gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (link_button),
|
||||
GDK_SELECTION_CLIPBOARD),
|
||||
priv->uri, -1);
|
||||
|
|
@ -451,7 +454,9 @@ gtk_link_button_button_press (GtkWidget *widget,
|
|||
if (!gtk_widget_has_focus (widget))
|
||||
gtk_widget_grab_focus (widget);
|
||||
|
||||
if (_gtk_button_event_triggers_context_menu (event))
|
||||
/* Don't popup the menu if there's no URI set, there is nothing to copy */
|
||||
if (_gtk_button_event_triggers_context_menu (event) &&
|
||||
GTK_LINK_BUTTON (widget)->priv->uri != NULL)
|
||||
{
|
||||
gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), event);
|
||||
|
||||
|
|
|
|||
|
|
@ -1617,12 +1617,45 @@ gtk_spin_button_default_input (GtkSpinButton *spin_button,
|
|||
gdouble *new_val)
|
||||
{
|
||||
gchar *err = NULL;
|
||||
const gchar *text;
|
||||
|
||||
*new_val = g_strtod (gtk_entry_get_text (GTK_ENTRY (spin_button)), &err);
|
||||
text = gtk_entry_get_text (GTK_ENTRY (spin_button));
|
||||
|
||||
*new_val = g_strtod (text, &err);
|
||||
if (*err)
|
||||
return GTK_INPUT_ERROR;
|
||||
else
|
||||
return FALSE;
|
||||
{
|
||||
/* a whole number in the digits of another script, such as
|
||||
* Arabic-Indic or Devanagari ones, typed with the keyboard of
|
||||
* that language */
|
||||
gdouble val = 0;
|
||||
gint sign = 1;
|
||||
gboolean have_digit = FALSE;
|
||||
const gchar *p;
|
||||
|
||||
for (p = text; *p; p = g_utf8_next_char (p))
|
||||
{
|
||||
gunichar ch = g_utf8_get_char (p);
|
||||
|
||||
if (p == text && ch == '-')
|
||||
{
|
||||
sign = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!g_unichar_isdigit (ch))
|
||||
break;
|
||||
|
||||
val = val * 10 + g_unichar_digit_value (ch);
|
||||
have_digit = TRUE;
|
||||
}
|
||||
|
||||
if (*p || !have_digit)
|
||||
return GTK_INPUT_ERROR;
|
||||
|
||||
*new_val = sign * val;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* "%0.*f" gives "-0.0" for small negative values; drop the sign then */
|
||||
|
|
|
|||
|
|
@ -5315,14 +5315,24 @@ _gtk_text_btree_get_iter_at_last_toggle (GtkTextBTree *tree,
|
|||
GtkTextIter *iter,
|
||||
GtkTextTag *tag)
|
||||
{
|
||||
gboolean found;
|
||||
|
||||
g_return_val_if_fail (iter != NULL, FALSE);
|
||||
g_return_val_if_fail (tree != NULL, FALSE);
|
||||
|
||||
_gtk_text_btree_get_end_iter (tree, iter);
|
||||
gtk_text_iter_backward_to_tag_toggle (iter, tag);
|
||||
|
||||
/* a tag reaching the end of the buffer toggles off at the end
|
||||
* iter itself: moving backward from there would find the
|
||||
* toggle on instead */
|
||||
if (gtk_text_iter_toggles_tag (iter, tag))
|
||||
found = TRUE;
|
||||
else
|
||||
found = gtk_text_iter_backward_to_tag_toggle (iter, tag);
|
||||
|
||||
check_invariants (iter);
|
||||
|
||||
return TRUE;
|
||||
return found;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
|
|
|||
|
|
@ -1760,6 +1760,7 @@ gtk_text_tag_get_property (GObject *object,
|
|||
case PROP_FOREGROUND:
|
||||
case PROP_PARAGRAPH_BACKGROUND:
|
||||
g_warning ("'foreground', 'background' and 'paragraph_background' properties are not readable, use 'foreground_gdk', 'background_gdk' and 'paragraph_background_gdk'");
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1298,6 +1298,13 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
|
|||
gtk_binding_entry_add_signal (binding_set, GDK_Insert, GDK_SHIFT_MASK,
|
||||
"paste-clipboard", 0);
|
||||
|
||||
gtk_binding_entry_add_signal (binding_set, GDK_KP_Delete, GDK_SHIFT_MASK,
|
||||
"cut-clipboard", 0);
|
||||
gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, GDK_CONTROL_MASK,
|
||||
"copy-clipboard", 0);
|
||||
gtk_binding_entry_add_signal (binding_set, GDK_KP_Insert, GDK_SHIFT_MASK,
|
||||
"paste-clipboard", 0);
|
||||
|
||||
/**
|
||||
* GtkTextView::insert-emoji:
|
||||
* @text_view: the object which received the signal
|
||||
|
|
@ -2391,7 +2398,7 @@ gtk_text_view_set_wrap_mode (GtkTextView *text_view,
|
|||
{
|
||||
text_view->wrap_mode = wrap_mode;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->wrap_mode = wrap_mode;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
|
|
@ -2451,8 +2458,12 @@ gtk_text_view_set_editable (GtkTextView *text_view,
|
|||
{
|
||||
gtk_text_layout_set_overwrite_mode (text_view->layout,
|
||||
text_view->overwrite_mode && text_view->editable);
|
||||
text_view->layout->default_style->editable = text_view->editable;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
/* default_style is still NULL while the layout is being set up */
|
||||
if (text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->editable = text_view->editable;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
}
|
||||
}
|
||||
|
||||
g_object_notify (G_OBJECT (text_view), "editable");
|
||||
|
|
@ -2494,7 +2505,7 @@ gtk_text_view_set_pixels_above_lines (GtkTextView *text_view,
|
|||
{
|
||||
text_view->pixels_above_lines = pixels_above_lines;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->pixels_above_lines = pixels_above_lines;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
|
|
@ -2539,7 +2550,7 @@ gtk_text_view_set_pixels_below_lines (GtkTextView *text_view,
|
|||
{
|
||||
text_view->pixels_below_lines = pixels_below_lines;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->pixels_below_lines = pixels_below_lines;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
|
|
@ -2584,7 +2595,7 @@ gtk_text_view_set_pixels_inside_wrap (GtkTextView *text_view,
|
|||
{
|
||||
text_view->pixels_inside_wrap = pixels_inside_wrap;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->pixels_inside_wrap = pixels_inside_wrap;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
|
|
@ -2629,7 +2640,7 @@ gtk_text_view_set_justification (GtkTextView *text_view,
|
|||
{
|
||||
text_view->justify = justification;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->justification = justification;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
|
|
@ -2674,7 +2685,7 @@ gtk_text_view_set_left_margin (GtkTextView *text_view,
|
|||
{
|
||||
text_view->left_margin = left_margin;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->left_margin = left_margin;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
|
|
@ -2719,7 +2730,7 @@ gtk_text_view_set_right_margin (GtkTextView *text_view,
|
|||
{
|
||||
text_view->right_margin = right_margin;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->right_margin = right_margin;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
|
|
@ -2764,7 +2775,7 @@ gtk_text_view_set_indent (GtkTextView *text_view,
|
|||
{
|
||||
text_view->indent = indent;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->indent = indent;
|
||||
gtk_text_layout_default_style_changed (text_view->layout);
|
||||
|
|
@ -2811,7 +2822,7 @@ gtk_text_view_set_tabs (GtkTextView *text_view,
|
|||
|
||||
text_view->tabs = tabs ? pango_tab_array_copy (tabs) : NULL;
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
/* some unkosher futzing in internal struct details... */
|
||||
if (text_view->layout->default_style->tabs)
|
||||
|
|
@ -4078,7 +4089,7 @@ gtk_text_view_direction_changed (GtkWidget *widget,
|
|||
{
|
||||
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
|
||||
|
||||
if (text_view->layout)
|
||||
if (text_view->layout && text_view->layout->default_style)
|
||||
{
|
||||
text_view->layout->default_style->direction = gtk_widget_get_direction (widget);
|
||||
|
||||
|
|
@ -6305,17 +6316,20 @@ typedef struct
|
|||
SelectionGranularity granularity;
|
||||
GtkTextMark *orig_start;
|
||||
GtkTextMark *orig_end;
|
||||
/* keeps the marks alive when the view drops its buffer
|
||||
* (e.g. is destroyed) during the drag */
|
||||
GtkTextBuffer *buffer;
|
||||
} SelectionData;
|
||||
|
||||
static void
|
||||
selection_data_free (SelectionData *data)
|
||||
{
|
||||
if (data->orig_start != NULL)
|
||||
gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_start),
|
||||
data->orig_start);
|
||||
gtk_text_buffer_delete_mark (data->buffer, data->orig_start);
|
||||
if (data->orig_end != NULL)
|
||||
gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (data->orig_end),
|
||||
data->orig_end);
|
||||
gtk_text_buffer_delete_mark (data->buffer, data->orig_end);
|
||||
if (data->buffer != NULL)
|
||||
g_object_unref (data->buffer);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
|
|
@ -6442,6 +6456,7 @@ gtk_text_view_start_selection_drag (GtkTextView *text_view,
|
|||
&orig_start, TRUE);
|
||||
data->orig_end = gtk_text_buffer_create_mark (buffer, NULL,
|
||||
&orig_end, TRUE);
|
||||
data->buffer = g_object_ref (buffer);
|
||||
|
||||
gtk_text_view_check_cursor_blink (text_view);
|
||||
|
||||
|
|
@ -8062,6 +8077,8 @@ popup_targets_received (GtkClipboard *clipboard,
|
|||
gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem);
|
||||
|
||||
menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
|
||||
gtk_widget_set_sensitive (menuitem,
|
||||
gtk_text_buffer_get_char_count (get_buffer (text_view)) > 0);
|
||||
g_signal_connect (menuitem, "activate",
|
||||
G_CALLBACK (select_all_cb), text_view);
|
||||
gtk_widget_show (menuitem);
|
||||
|
|
|
|||
Loading…
Reference in a new issue