Re: paned widget size



"Evin Robertson" <nitfol my-deja com> writes:
I want to create a horizontal paned widget with the top widget
occuping approximately 25% of the space and the lower widget having
the rest.  However, the gtk_paned_set_position function wants pixels,
so I need know how much space is allocated to the paned widget to set
its size.  I think this is supposed to be stored in
.allocation.height, but it contains 1 until everything has been
drawn...  How am I supposed to do this?

I'm not at all sure how you would do this... the stuff I can think of
offhand won't work. ;-) Well, you could definitely do it by
subclassing GtkPaned and overriding size_allocate to pick a 25%
default position if position is unset, but I don't know if you want to
go there.

GTK is really not about widgets having static sizes, they just have
sizes dynamically allocated to them from time to time. Normally you
want to do size-dependent things in response to size allocate. But
gtk_paned_set_position() queues a new resize cycle, so if you did that
in response to size_allocate you'd get some infinite loop action.

Also, for gtk 1.3.x text buffer, what's the recommended way to
convert latin-1 strings to utf-8?

g_convert() is the most general codeset conversion interface and can
be used for Latin-1. g_locale_to_utf8() converts from current C
library encoding (which might be Latin-1) to UTF-8. g_locale_to_utf8()
is right if you are reading files from disk.

On Linux the "iconv --list" command shows codeset names g_convert()
will work with, in this case "LATIN1".

Latin-1 conversion is really easy and can be done really quickly
though; there even used to be an internal function in GTK to do it. We
may still have it around.

All you need to know is that Latin-1 chars are a subset of Unicode
chars. So for fixed-width Unicode (UCS4) you do this:

 gunichar uni_string[100];
 guchar   latin1_string[100];
 /* imagine latin1_string is initialized */

 int i;
 i = 0;
 while (i < 100)
   {
      uni_string[i] = latin1_string[i];
      ++i; 
   }

So now you are done. For UTF-8, just add this line:

  gchar *utf8_string = g_ucs4_to_utf8 (uni_string, 100, NULL, NULL,
                                       NULL);

Or you could convert each UTF-8 char as you went along and avoid the
uni_string intermediate.

Havoc






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