SetSelection on wxTextCtrl is intermittent
Ron Burkey
rburkey2005 at earthlink.net
Mon Mar 31 08:14:53 PDT 2008
On Mon, 2008-03-31 at 02:33 +0200, Vadim Zeitlin wrote:
> On Fri, 28 Mar 2008 15:24:00 -0500 Ron Burkey <rburkey2005 at earthlink.net> wrote:
> ...
> RB>
> RB> But sometimes gtk_text_buffer_move_mark() --- not
> RB> gtk_text_buffer_move_mark_by_name() --- is then somehow called an extra
> RB> time, and it moves the selection back to (8,8)!
>
> If you put a breakpoint on this function you should be able to see where
> is it called from by just looking at "bt" output -- could you please try
> doing it?
>
> I also (still) wonder if doing the selection in the natural direction
> (from "from" to "to" instead of vice versa) can help?
Hi Vadim,
I had already tried switching the order of the endpoints, but didn't
think it was worth reporting. It still failed from time to time, but it
ended up leaving the cursor at position 3 rather than position 8.
I have the backtrace info you suggested collecting. First, here is what
the backtrace looks like on success --- i.e., when the selection
actually changes to (3,8). I've clipped out most of it, but I've saved
the rest if you think it might be interesting
#0 IA__gtk_text_buffer_move_mark (buffer=0x9dcc588, mark=0x9dd7058,
where=0xbfa64acc) at gtktextbuffer.c:2112
#1 0x00679aea in IA__gtk_text_buffer_move_mark_by_name
(buffer=0x9dcc588, name=0xb64e62 "selection_bound", where=0xbfa64acc) at
gtktextbuffer.c:2236
#2 0x00a5a435 in wxTextCtrl::SetSelection (this=0x9dd6918, from=0x3,
to=0x8) at ./src/gtk/textctrl.cpp:1402
...
#42 0x08064058 in main (argc=0x2d908c, argv=0xdd34c0) at text.cpp:370
On the other hand, here's what it looks like on the spurious call to
gtk_text_buffer_move_mark that follows when the selection changes to
(8,8):
#0 IA__gtk_text_buffer_move_mark (buffer=0x9dcc588, mark=0x9dd7058,
where=0xbfa64354) at gtktextbuffer.c:2113
#1 0x00679a3e in clipboard_clear_selection_cb (clipboard=0x9de41a8,
data=0x9dcc588) at gtktextbuffer.c:3096
#2 0x0067cb74 in update_selection_clipboards (buffer=0x9dcc588) at
gtktextbuffer.c:3608
#3 0x0067cbef in gtk_text_buffer_real_mark_set (buffer=0x9dcc588,
iter=0x9e03e00, mark=0x9dd7058) at gtktextbuffer.c:2500
#4 0x005d108b in _gtk_marshal_VOID__BOXED_OBJECT (closure=0x9d7f420,
return_value=0x0, n_param_values=0x3, param_values=0xbfa646ec,
invocation_hint=0xbfa645fc, marshal_data=0x67cba0) at
gtkmarshalers.c:1422
#5 0x003c47f9 in g_type_class_meta_marshal (closure=0x9d7f420,
return_value=0x0, n_param_values=0x3, param_values=0xbfa646ec,
invocation_hint=0xbfa645fc, marshal_data=0x5c) at gclosure.c:567
#6 0x003c600b in IA__g_closure_invoke (closure=0x9d7f420,
return_value=0x0, n_param_values=0x3, param_values=0xbfa646ec,
invocation_hint=0xbfa645fc) at gclosure.c:490
#7 0x003d7163 in signal_emit_unlocked_R (node=0x9d7f468, detail=0x0,
instance=0x9dcc588, emission_return=0x0, instance_and_params=0xbfa646ec)
at gsignal.c:2478
#8 0x003d8027 in IA__g_signal_emit_valist (instance=0x9dcc588,
signal_id=0x7d, detail=0x0, var_args=0xbfa64934 "
#9 0x003d81e9 in IA__g_signal_emit (instance=0x9dcc588, signal_id=0x7d,
detail=0x0) at gsignal.c:2243
#10 0x0067603e in gtk_text_buffer_mark_set (buffer=0x9dcc588,
location=0xbfa64984, mark=0x9dd7058) at gtktextbuffer.c:1994
#11 0x0067981f in gtk_text_buffer_set_mark (buffer=0xbfa64984,
existing_mark=0x9dd7058, mark_name=0x0, iter=0xbfa64acc,
left_gravity=0x0, should_exist=0x1) at gtktextbuffer.c:2041
#12 0x00679aea in IA__gtk_text_buffer_move_mark_by_name
(buffer=0x9dcc588, name=0xb64e62 "selection_bound", where=0xbfa64acc) at
gtktextbuffer.c:2236
#13 0x00a5a435 in wxTextCtrl::SetSelection (this=0x9dd6918, from=0x3,
to=0x8) at ./src/gtk/textctrl.cpp:1402
...
#53 0x08064058 in main (argc=0x2d908c, argv=0xdd34c0) at text.cpp:370
You may ask whether this is the *same* call to SetSelection() and
gtk_text_buffer_move_mark() in these to backtraces, or whether there are
two different calls. In fact, I embedded a counter in SetSelection, in
gtk_text_buffer_move_mark_by_name, and gtk_text_buffer_move_mark, so
that I could serialize the calls to them, but those counters don't show
up in the backtraces. These two backtraces are from the same call to
SetSelection() and gtk_text_buffer_move_mark_by_name, and two successive
calls to gtk_text_buffer_move_mark.
(Recall that I'm using the wxWidgets sample program text.cpp, and
generating text insertions with that program's ctrl-R function.) My
theory is that what's happening is this: The text insertion which
precedes the SetSelection doesn't occur right away, and (perhaps)
operates somehow by generating a signal. If that signal is processed
before the SetSelection occurs, then everything comes out right. But if
the text insertion is cleaned up a little later instead, then one of the
side effects is a spurious gtk_text_buffer_move_mark() that happens
out-of-order with the actually-desired ones caused by the
SetSelection(). So what's needed a wait for the text insertion to
complete before proceeding with other operations.
-- Ron
More information about the wx-users
mailing list