"delete-text" and has_selection bug or feature?



Hi it`s me again,

I just found a wired behavior when manualy deleting (read: deleting text
at runtime - selection s.th. with the mouse and the pressing DEL) text
in a GtkText widget. I added an event handler to "delete-text" (tried
both before and after) and in the handler I print out the current
selection (selection_start_pos, selection_end_pos) together with
has_selection.

Now the strange thing is that has_selection gives me True while the
selection range is 0-0 which is IMO not a valid region and thus
has_selection should be False.

This causes me troubles because we are doing a GTK wrapper for Eiffel
here. In Eiffel you use a lot of assertions (special build in the
language assertions btw) and I would like to do a postcondition to
has_selection like "has_selection implies selection_start_pos /=
selection_end_pos".

Can anybody shed some light on this? Is this a bug on GTK or just
undocumented behavior or I don`t know?

I also had a look into the source code and it seems like the function
that is called is gtk_editable_delete_selection in there it is clear why
the behavior is like this:

----
  start = editable->selection_start_pos;
  end = editable->selection_end_pos;

  editable->selection_start_pos = 0;
  editable->selection_end_pos = 0;

  if (start != end)
    gtk_editable_delete_text (editable, MIN (start, end), MAX
(start,end));

  if (editable->has_selection)
    {
      editable->has_selection = FALSE;
      if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == GTK_WIDGET
(editable)->window)
	gtk_selection_owner_set (NULL, GDK_SELECTION_PRIMARY,
GDK_CURRENT_TIME);
    }
----

Obviously the selected region and has_selection are not consitent while
gtk_editable_delete_text. Shouldn't this change to a well defined
behavior?



many thanks in advance,
Andreas

PS: I am using GTK and GLIB v 1.2.4
PS: Is this the right list to post such questions, or is there any
better?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]