summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2001-06-01 19:26:01 +0000
committerHavoc Pennington <hp@src.gnome.org>2001-06-01 19:26:01 +0000
commitfe3e516aa1e2a7f793557b0b8094d5ee96653d40 (patch)
tree4e73ad11e926f612eebed3ab9c5af8de0536f9bc
parentad88113f34251c8686d3ae877c50757fdfb0a55e (diff)
downloadgtk+-fe3e516aa1e2a7f793557b0b8094d5ee96653d40.tar.gz
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
-rw-r--r--ChangeLog22
-rw-r--r--ChangeLog.pre-2-022
-rw-r--r--ChangeLog.pre-2-1022
-rw-r--r--ChangeLog.pre-2-222
-rw-r--r--ChangeLog.pre-2-422
-rw-r--r--ChangeLog.pre-2-622
-rw-r--r--ChangeLog.pre-2-822
-rw-r--r--gtk/gtkentry.c10
-rw-r--r--gtk/gtklabel.c137
-rw-r--r--gtk/gtklabel.h3
-rw-r--r--gtk/gtkmessagedialog.c3
-rw-r--r--gtk/gtktextview.c7
12 files changed, 301 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index e3377ac8e1..e4da124063 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index e3377ac8e1..e4da124063 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -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
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index e3377ac8e1..e4da124063 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -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
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index e3377ac8e1..e4da124063 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -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
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index e3377ac8e1..e4da124063 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -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
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index e3377ac8e1..e4da124063 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -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
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index e3377ac8e1..e4da124063 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -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
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 098b6b9ca5..b2e4d61349 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -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);
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 896d1e336a..aa90199320 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -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);
@@ -1912,6 +1962,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
* @x: location to store X offset of layout, or %NULL
diff --git a/gtk/gtklabel.h b/gtk/gtklabel.h
index ad676c650c..d41f4c5e78 100644
--- a/gtk/gtklabel.h
+++ b/gtk/gtklabel.h
@@ -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);
diff --git a/gtk/gtkmessagedialog.c b/gtk/gtkmessagedialog.c
index 41d135f756..06f954f121 100644
--- a/gtk/gtkmessagedialog.c
+++ b/gtk/gtkmessagedialog.c
@@ -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);
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 7b63a6796e..95b3b4b00a 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -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);