implement overwrite mode

2001-06-01  Havoc Pennington  <hp@redhat.com>

	* gtk/gtkentry.c (gtk_entry_commit_cb): implement overwrite mode

	* gtk/gtktextview.c (gtk_text_view_commit_handler): don't
	overwrite in overwrite mode if we already deleted the selection
	and replaced it with new text.

	* gtk/gtklabel.c (gtk_label_select_region_index): if you set the
	selection to an empty range, clear the clipboard if we owned it.
	(gtk_label_set_selectable): give up selection if we become
	unselectable.
	(gtk_label_state_changed): override state changed to unselect text
	when insensitive
	(get_text_callback): add paranoia check that indexes aren't
	outside of label->text
	(gtk_label_select_region): make -1 for start_offset mean "end of
	label," for consistency with GtkEditable

	* gtk/gtkmessagedialog.c (gtk_message_dialog_new): honor
	GTK_DIALOG_NO_SEPARATOR flag
This commit is contained in:
Havoc Pennington 2001-06-01 19:26:01 +00:00 committed by Havoc Pennington
parent ad88113f34
commit fe3e516aa1
12 changed files with 301 additions and 13 deletions

View File

@ -1,3 +1,25 @@
2001-06-01 Havoc Pennington <hp@redhat.com>
* gtk/gtkentry.c (gtk_entry_commit_cb): implement overwrite mode
* gtk/gtktextview.c (gtk_text_view_commit_handler): don't
overwrite in overwrite mode if we already deleted the selection
and replaced it with new text.
* gtk/gtklabel.c (gtk_label_select_region_index): if you set the
selection to an empty range, clear the clipboard if we owned it.
(gtk_label_set_selectable): give up selection if we become
unselectable.
(gtk_label_state_changed): override state changed to unselect text
when insensitive
(get_text_callback): add paranoia check that indexes aren't
outside of label->text
(gtk_label_select_region): make -1 for start_offset mean "end of
label," for consistency with GtkEditable
* gtk/gtkmessagedialog.c (gtk_message_dialog_new): honor
GTK_DIALOG_NO_SEPARATOR flag
Fri Jun 1 11:47:11 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcombo.c (gtk_combo_set_use_arrows_always): Fix

View File

@ -1,3 +1,25 @@
2001-06-01 Havoc Pennington <hp@redhat.com>
* gtk/gtkentry.c (gtk_entry_commit_cb): implement overwrite mode
* gtk/gtktextview.c (gtk_text_view_commit_handler): don't
overwrite in overwrite mode if we already deleted the selection
and replaced it with new text.
* gtk/gtklabel.c (gtk_label_select_region_index): if you set the
selection to an empty range, clear the clipboard if we owned it.
(gtk_label_set_selectable): give up selection if we become
unselectable.
(gtk_label_state_changed): override state changed to unselect text
when insensitive
(get_text_callback): add paranoia check that indexes aren't
outside of label->text
(gtk_label_select_region): make -1 for start_offset mean "end of
label," for consistency with GtkEditable
* gtk/gtkmessagedialog.c (gtk_message_dialog_new): honor
GTK_DIALOG_NO_SEPARATOR flag
Fri Jun 1 11:47:11 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcombo.c (gtk_combo_set_use_arrows_always): Fix

View File

@ -1,3 +1,25 @@
2001-06-01 Havoc Pennington <hp@redhat.com>
* gtk/gtkentry.c (gtk_entry_commit_cb): implement overwrite mode
* gtk/gtktextview.c (gtk_text_view_commit_handler): don't
overwrite in overwrite mode if we already deleted the selection
and replaced it with new text.
* gtk/gtklabel.c (gtk_label_select_region_index): if you set the
selection to an empty range, clear the clipboard if we owned it.
(gtk_label_set_selectable): give up selection if we become
unselectable.
(gtk_label_state_changed): override state changed to unselect text
when insensitive
(get_text_callback): add paranoia check that indexes aren't
outside of label->text
(gtk_label_select_region): make -1 for start_offset mean "end of
label," for consistency with GtkEditable
* gtk/gtkmessagedialog.c (gtk_message_dialog_new): honor
GTK_DIALOG_NO_SEPARATOR flag
Fri Jun 1 11:47:11 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcombo.c (gtk_combo_set_use_arrows_always): Fix

View File

@ -1,3 +1,25 @@
2001-06-01 Havoc Pennington <hp@redhat.com>
* gtk/gtkentry.c (gtk_entry_commit_cb): implement overwrite mode
* gtk/gtktextview.c (gtk_text_view_commit_handler): don't
overwrite in overwrite mode if we already deleted the selection
and replaced it with new text.
* gtk/gtklabel.c (gtk_label_select_region_index): if you set the
selection to an empty range, clear the clipboard if we owned it.
(gtk_label_set_selectable): give up selection if we become
unselectable.
(gtk_label_state_changed): override state changed to unselect text
when insensitive
(get_text_callback): add paranoia check that indexes aren't
outside of label->text
(gtk_label_select_region): make -1 for start_offset mean "end of
label," for consistency with GtkEditable
* gtk/gtkmessagedialog.c (gtk_message_dialog_new): honor
GTK_DIALOG_NO_SEPARATOR flag
Fri Jun 1 11:47:11 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcombo.c (gtk_combo_set_use_arrows_always): Fix

View File

@ -1,3 +1,25 @@
2001-06-01 Havoc Pennington <hp@redhat.com>
* gtk/gtkentry.c (gtk_entry_commit_cb): implement overwrite mode
* gtk/gtktextview.c (gtk_text_view_commit_handler): don't
overwrite in overwrite mode if we already deleted the selection
and replaced it with new text.
* gtk/gtklabel.c (gtk_label_select_region_index): if you set the
selection to an empty range, clear the clipboard if we owned it.
(gtk_label_set_selectable): give up selection if we become
unselectable.
(gtk_label_state_changed): override state changed to unselect text
when insensitive
(get_text_callback): add paranoia check that indexes aren't
outside of label->text
(gtk_label_select_region): make -1 for start_offset mean "end of
label," for consistency with GtkEditable
* gtk/gtkmessagedialog.c (gtk_message_dialog_new): honor
GTK_DIALOG_NO_SEPARATOR flag
Fri Jun 1 11:47:11 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcombo.c (gtk_combo_set_use_arrows_always): Fix

View File

@ -1,3 +1,25 @@
2001-06-01 Havoc Pennington <hp@redhat.com>
* gtk/gtkentry.c (gtk_entry_commit_cb): implement overwrite mode
* gtk/gtktextview.c (gtk_text_view_commit_handler): don't
overwrite in overwrite mode if we already deleted the selection
and replaced it with new text.
* gtk/gtklabel.c (gtk_label_select_region_index): if you set the
selection to an empty range, clear the clipboard if we owned it.
(gtk_label_set_selectable): give up selection if we become
unselectable.
(gtk_label_state_changed): override state changed to unselect text
when insensitive
(get_text_callback): add paranoia check that indexes aren't
outside of label->text
(gtk_label_select_region): make -1 for start_offset mean "end of
label," for consistency with GtkEditable
* gtk/gtkmessagedialog.c (gtk_message_dialog_new): honor
GTK_DIALOG_NO_SEPARATOR flag
Fri Jun 1 11:47:11 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcombo.c (gtk_combo_set_use_arrows_always): Fix

View File

@ -1,3 +1,25 @@
2001-06-01 Havoc Pennington <hp@redhat.com>
* gtk/gtkentry.c (gtk_entry_commit_cb): implement overwrite mode
* gtk/gtktextview.c (gtk_text_view_commit_handler): don't
overwrite in overwrite mode if we already deleted the selection
and replaced it with new text.
* gtk/gtklabel.c (gtk_label_select_region_index): if you set the
selection to an empty range, clear the clipboard if we owned it.
(gtk_label_set_selectable): give up selection if we become
unselectable.
(gtk_label_state_changed): override state changed to unselect text
when insensitive
(get_text_callback): add paranoia check that indexes aren't
outside of label->text
(gtk_label_select_region): make -1 for start_offset mean "end of
label," for consistency with GtkEditable
* gtk/gtkmessagedialog.c (gtk_message_dialog_new): honor
GTK_DIALOG_NO_SEPARATOR flag
Fri Jun 1 11:47:11 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkcombo.c (gtk_combo_set_use_arrows_always): Fix

View File

@ -1584,7 +1584,7 @@ gtk_entry_insert_text (GtkEditable *editable,
text[new_text_length] = '\0';
strncpy (text, new_text, new_text_length);
gtk_signal_emit (GTK_OBJECT (editable), signals[INSERT_TEXT], text, new_text_length, position);
gtk_signal_emit (GTK_OBJECT (editable), signals[CHANGED]);
@ -2017,7 +2017,13 @@ gtk_entry_commit_cb (GtkIMContext *context,
GtkEditable *editable = GTK_EDITABLE (entry);
gint tmp_pos = entry->current_pos;
gtk_editable_delete_selection (editable);
if (gtk_editable_get_selection_bounds (editable, NULL, NULL))
gtk_editable_delete_selection (editable);
else
{
if (entry->overwrite_mode)
gtk_entry_delete_from_cursor (entry, GTK_DELETE_CHARS, 1);
}
gtk_editable_insert_text (editable, str, strlen (str), &tmp_pos);
gtk_editable_set_position (editable, tmp_pos);

View File

@ -74,6 +74,8 @@ static void gtk_label_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_label_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_label_state_changed (GtkWidget *widget,
GtkStateType state);
static void gtk_label_style_set (GtkWidget *widget,
GtkStyle *previous_style);
static void gtk_label_direction_changed (GtkWidget *widget,
@ -175,6 +177,7 @@ gtk_label_class_init (GtkLabelClass *class)
widget_class->size_request = gtk_label_size_request;
widget_class->size_allocate = gtk_label_size_allocate;
widget_class->state_changed = gtk_label_state_changed;
widget_class->style_set = gtk_label_style_set;
widget_class->direction_changed = gtk_label_direction_changed;
widget_class->expose_event = gtk_label_expose;
@ -1156,6 +1159,21 @@ gtk_label_size_allocate (GtkWidget *widget,
}
}
static void
gtk_label_state_changed (GtkWidget *widget,
GtkStateType prev_state)
{
GtkLabel *label;
label = GTK_LABEL (widget);
if (label->select_info)
gtk_label_select_region (label, 0, 0);
if (GTK_WIDGET_CLASS (parent_class)->state_changed)
GTK_WIDGET_CLASS (parent_class)->state_changed (widget, prev_state);
}
static void
gtk_label_style_set (GtkWidget *widget,
GtkStyle *previous_style)
@ -1782,6 +1800,9 @@ gtk_label_set_selectable (GtkLabel *label,
{
if (label->select_info)
{
/* unselect, to give up the selection */
gtk_label_select_region (label, 0, 0);
if (label->select_info->window)
gtk_label_destroy_window (label);
@ -1821,12 +1842,21 @@ get_text_callback (GtkClipboard *clipboard,
label->text)
{
gint start, end;
gint len;
start = MIN (label->select_info->selection_anchor,
label->select_info->selection_end);
end = MAX (label->select_info->selection_anchor,
label->select_info->selection_end);
len = strlen (label->text);
if (end > len)
end = len;
if (start > len)
start = len;
str = g_strndup (label->text + start,
end - start);
@ -1877,19 +1907,39 @@ gtk_label_select_region_index (GtkLabel *label,
label->select_info->selection_end = end_index;
clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
gtk_clipboard_set_with_owner (clipboard,
targets,
G_N_ELEMENTS (targets),
get_text_callback,
clear_text_callback,
G_OBJECT (label));
if (anchor_index != end_index)
{
gtk_clipboard_set_with_owner (clipboard,
targets,
G_N_ELEMENTS (targets),
get_text_callback,
clear_text_callback,
G_OBJECT (label));
}
else
{
if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (label))
gtk_clipboard_clear (clipboard);
}
gtk_label_clear_layout (label);
gtk_widget_queue_draw (GTK_WIDGET (label));
}
}
/**
* gtk_label_select_region:
* @label: a #GtkLabel
* @start_offset: start offset (in characters not bytes)
* @end_offset: end offset (in characters not bytes)
*
* Selects a range of characters in the label, if the label is selectable.
* See gtk_label_set_selectable(). If the label is not selectable,
* this function has no effect. If @start_offset or
* @end_offset are -1, then the end of the label will be substituted.
*
**/
void
gtk_label_select_region (GtkLabel *label,
gint start_offset,
@ -1900,8 +1950,8 @@ gtk_label_select_region (GtkLabel *label,
if (label->text && label->select_info)
{
if (start_offset < 0)
start_offset = 0;
start_offset = g_utf8_strlen (label->text, -1);
if (end_offset < 0)
end_offset = g_utf8_strlen (label->text, -1);
@ -1911,6 +1961,73 @@ gtk_label_select_region (GtkLabel *label,
}
}
/**
* gtk_label_get_selection_bounds:
* @label: a #GtkLabel
* @start: return location for start of selection, as a character offset
* @end: return location for end of selection, as a character offset
*
* Gets the selected range of characters in the label, returning %TRUE
* if there's a selection.
*
* Return value: %TRUE if selection is non-empty
**/
gboolean
gtk_label_get_selection_bounds (GtkLabel *label,
gint *start,
gint *end)
{
g_return_val_if_fail (GTK_IS_LABEL (label), FALSE);
if (label->select_info == NULL)
{
/* not a selectable label */
if (start)
*start = 0;
if (end)
*end = 0;
return FALSE;
}
else
{
gint start_index, end_index;
gint start_offset, end_offset;
gint len;
start_index = MIN (label->select_info->selection_anchor,
label->select_info->selection_end);
end_index = MAX (label->select_info->selection_anchor,
label->select_info->selection_end);
len = strlen (label->text);
if (end_index > len)
end_index = len;
if (start_index > len)
start_index = len;
start_offset = g_utf8_strlen (label->text, start_index);
end_offset = g_utf8_strlen (label->text, end_index);
if (start_offset > end_offset)
{
gint tmp = start_offset;
start_offset = end_offset;
end_offset = tmp;
}
if (start)
*start = start_offset;
if (end)
*end = end_offset;
return start_offset != end_offset;
}
}
/**
* gtk_label_get_layout_offsets:
* @label: a #GtkLabel

View File

@ -108,6 +108,9 @@ gboolean gtk_label_get_selectable (GtkLabel *label);
void gtk_label_select_region (GtkLabel *label,
gint start_offset,
gint end_offset);
gboolean gtk_label_get_selection_bounds (GtkLabel *label,
gint *start,
gint *end);
void gtk_label_get_layout_offsets (GtkLabel *label,
gint *x,
gint *y);

View File

@ -214,6 +214,9 @@ gtk_message_dialog_new (GtkWindow *parent,
if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
if (flags & GTK_DIALOG_NO_SEPARATOR)
gtk_dialog_set_has_separator (dialog, FALSE);
setup_type (GTK_MESSAGE_DIALOG (dialog), type);

View File

@ -4906,8 +4906,13 @@ gtk_text_view_commit_handler (GtkIMContext *context,
const gchar *str,
GtkTextView *text_view)
{
gboolean had_selection;
gtk_text_buffer_begin_user_action (get_buffer (text_view));
had_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
NULL, NULL);
gtk_text_buffer_delete_selection (get_buffer (text_view), TRUE,
text_view->editable);
@ -4918,7 +4923,7 @@ gtk_text_view_commit_handler (GtkIMContext *context,
}
else
{
if (text_view->overwrite_mode)
if (!had_selection && text_view->overwrite_mode)
gtk_text_view_delete_from_cursor (text_view, GTK_DELETE_CHARS, 1);
gtk_text_buffer_insert_interactive_at_cursor (get_buffer (text_view), str, -1,
text_view->editable);