Re: GtkTextView



Phil Krylov wrote:

> Hello, Jarek.
>
> 18 ХЧМЪ 2002 Ц., 20:26:07 you wrote:
>
> >> I have a GtkTextView packed in a GtkTable. I don't know beforehand how
> >> much text will be in that GtkTextView, but I would like it to display
> >> a vertical scrollbar if its height reaches 300 pixels (instead of
> >> growing more). How can I get this behaviour? Maybe I need to connect
> >> to some signal of GtkTextView or GtkTable?
> JD> Can't you just put the GtkTextView into a GtkScrolledWindow and the
> JD> scrolled window into the table? I've never used TextView so I don't know
> JD> if it can work with scrolled window, but you can give it a try.
> I tried to do this, but then, if I have initially a short string and I
> append more characters to it, the scrollbar appears immediately
> instead of increasing the height of a GtkTextView. I want the
> scrollbar to appear only when the height of the GtkTextView reaches
> the given maximum of, say, 300 pixels.
>

Well, as I know for now Gtk::ScrolledWindow and Gtk::TextView couldn't be
expanded automatically just when you've entered some data into. So, if you
would like to have your TextView took minimal space in your table and expand up
to 300 pixels height only when you've some data inside, you have to handle that
yourself.

1. Pack ScrolledWindow to Table. (scrolledwindow.set_policy(NEVER,AUTO))

2. Pack TextView to ScrolledWindow. (textview.set_wrap_mode(WRAP_<what>))

3. TextView::signal_insert_at_cursor().connect( slot<resize_handler> )
(probably, you will need to connect to few more signals as well).

4. In your resize_handler() (See Gtk namespace for TextView,TextBuffer API-s)
{
...
    RefPtr<TextBuffer> refTB = textview.get_text_buffer();
    TextIter iter = refTB::get_end_iter();
    textview.get_iter_location(iter, rect);
    if (rect.get_y() < 300 && rect.get_y() > MIN_HEIGHT)
    {
         resize...
         // Not sure if you should resize textview or scrolledwindow
         // probably, parent widget should resize automatically when you
resized
         // it's child.
    }
...
}

Hope this gonna help
Oh my... You're coding in C (GTK+)... My sample is for C++ (GTKMM). Sorry, I am
a bit busy atm to "unwrap" those code. I guess, it's not so hard to do it.
Russian guys are smart enough to do it yourself :).

-Andrew





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