Re: Question on gtk_label_set_selectable



On Fri, Oct 19, 2007 at 07:44:19PM +0800, Gregory Hosler wrote:
Gregory Hosler wrote:
Hi all,

I have labels, which I wish to allow the user to select the text for the purpose
of cut/pasting. So I set

    gtk_label_set_selectable (GTK_LABEL (dlabel), 1)

on the label.

The problem I have now is that when the label is created, not only is the text
selectable, but it is also SELECTED as an initial state. I would prefer for the
text to be selectable, BUT NOT selected (at least as a default state).

How might I turn off "selected" ?

any tips ?

After some exploring, and looking at the gtk samples, I have an answer.
I'm not happy with it. It seems (to me) like there is a bug, so let me
explain what works, and what doesn't work.

If I have a window (dwindow), and then create a label as follows:

        dlabel=gtk_label_new("");
        gtk_label_set_text(GTK_LABEL(dlabel), "my text");
        gtk_label_set_line_wrap(GTK_LABEL(dlabel),1);
        gtk_label_set_selectable (GTK_LABEL (dlabel), 1);

Then attach my label to the window and then:

        gtk_widget_show_all(dwindow);

My label will show up, as selectable, BUT the label text will be
initially selected.

If I change the above sequence to this:

        dlabel=gtk_label_new("");
        gtk_label_set_text(GTK_LABEL(dlabel), "my text");
        gtk_label_set_line_wrap(GTK_LABEL(dlabel),1);

Then attach my label to the window and then:

        gtk_widget_show_all(dwindow);
        gtk_label_set_selectable (GTK_LABEL (dlabel), 1);

i.e. setting the selectable attribute AFTER the label is realized,
created, etc. *then* the label text will NOT be selected (but it is
still selectable).

I do not understand why in one case the initial state of the text is
"selected" and in the 2nd case it is NOT "selected".

Is this a bug? Or is there a reason this is like this?

thoughts ?

I have not seen the code, but...

Your label the first widget in the window that accepts focus
(selectable labels can receive focus, unlike normal labels).
Therefore the label will get focus, which selects its text
-- at least this seems to be the default behaviour.

If you add the label after it's decided which widget should
receive focus, the label does not get focus and therefore
its text is not selected.

Yeti

--
http://gwyddion.net/



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