Re: How do I resize a GtkText Widget based on line length?

On Sun, Mar 25, 2001 at 11:15:24PM -0500, R. Bernstein wrote:
> I have command output that I accumulate in a GtkText buffer; afterwards
> I'd like to resize the lines to maybe the maximum line seen up to 
> some limit.
> The problem is figuring out from a line of text what size it occupies,
> and then resizing the widget. How do I do?

That's what I do to calculate my text window (though mine is staticly sized):


static const char lucida[] =

static const char fixed[] = "-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*";

        static const char* font_names[] = { lucida, fixed };

        /*--- Load a fixed font ---*/

        m_fixed_font = gdk_font_load (font_names[0]);

        /*--- Fall back to the standard font ---*/

        if (m_fixed_font == NULL) {
                m_fixed_font = gdk_font_load (font_names[1]);

          Brain-damaged way of calculating necessary
          window size (70x14) in pixels.
        string s (72, 'O');

        int t_width = gdk_string_width (m_fixed_font, s.c_str ());
        int t_height = (m_fixed_font->ascent + m_fixed_font->descent) * 14;

        /*--- Create text and set  messages window size ---*/

        m_widget = gtk_text_new (NULL, NULL);
        gtk_text_set_editable (GTK_TEXT (m_widget), FALSE);
        gtk_text_set_word_wrap (GTK_TEXT (m_widget), FALSE);
        gtk_widget_set_usize (m_widget, t_width, t_height);
and so on ...

If text line doesn't fit on the screen, you can either tell Text widget
to wrap the text or leave it unwrapped. However, the catch is if you
choose unwrapped mode, you cannot attach horizontal scroll bar to
do scrolling! I've heard it might be changed in upcoming GTK+ release.

You might also consider replacing Text widget with CList. That suppose to
give you better control of what is visible and what is not. 

> In order to make the task precise, see gnopstree from
> or download via
> build, and
> click on a process and look at the popup window in that.
> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list gnome org

Vladislav Grinchenko           e-mail: vgrinche integ com
Integral Systems, Inc.           http:

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