packing/unpacking of boxes AND colors -> segment violation



Dear List Humans,

I've just started to write an application in gtk (1.2.5, very current).
I have a fair amount of experience writing GUI applications with the Tk
widget set in both perl and tcl.  I am having a bit of trouble with the
gtk packer and I wonder if you could help -- I bought the New Riders
GTK+/GDK book and it doesn't seem to talk about "unpacking" at all.

If I create a vbox (added to the main window) and pack a widget into it,
the main window resizes to accomodate the widget, which is itself a vbox
with specific dimensions, say 100x100, containing widgets.  This widget
is created by selecting a checkbox from a menu.  Later, I want to be
able to unselect the checkbox item from the menu and have the widget go
away.  So I make the checkbox toggle the gtk_widget_destroy command on
the widget in question, and the widget does indeed go away.

HOWEVER, the vbox that contained the widget doesn't seem to resize back
to its size before the widget was added.  It "remembers" the 100x100 and
displays an ugly, empty, widgetless, 100x100 box.  In Tk I would have
called the packForget() method to unpack/hide the widget quite
independent of whether or not I wanted to actually destroy it (in
general I probably don't) but gtk_widget_hide doesn't seem to do
anything at all.

Examining and playing with, e.g. gnomines, this appears to be a pretty
common (and pretty serious) problem.  Is there any way in gtk to cause a
widget to go away (analogous to the Forget() Tk methods) and force a
resize of its container recursively back to the main window?  If not,
I'd count this as a pretty serious flaw and well worth putting at the
very top of a future features list.

Also, a bug report:  While playing with gtk, this time with text colors,
I noted that there were certain rather large color ranges that would
work within, e.g. gtk_text_insert as foreground colors IF netscape were
not running.  A particular code fragment is:

  fore.red=(guint) 0;
  fore.green=(guint) 35535;
  fore.blue=(guint) 0;
  back.red=back.green=back.blue= (guint) 65535;

  message=g_strdup_printf("--signal: marked\n values: marked (X,Y)=(%g,%g)\n",  value.x, value.y);
  gtk_text_insert(GTK_TEXT(text), text->style->font, &fore, &back,
                message, strlen(message));

With netscape not running, the text message is inserted correctly into
the box and is the correct color (a medium green).  With netscape
running, the color of the inserted text is mauve or blue (definitely NOT
green) and when the text box itself is destroyed, the application
crashes with a segment violation.

I would guess that this is a colormap collision problem, although the
range of green values that would -- or wouldn't -- produce the crash was
quite large given my only 8 bit color display.  I have two problems with
the way things are now:

  a) The code is clean enough and shouldn't ever cause an application
crash with no error message whatsoever, even if there is a colormap
switching problem.

  b) One would expect the application to have its own private colormap
and do colormap switching the more "usual" way -- flashing its
competitors into weird and ugly colors while the focus is on the
application, and causing it to use the wierd colors only when the focus
is elsewhere.  This doesn't occur.

I'm not yet in a position to personally solve either of these problems
-- the (apparent) lack of automatic resizing or the colormap bug --
since I'm (as I noted) writing my FIRST application in gtk.  If I can
help a more experienced gtk developer person, you have only to ask.

     rgb

Robert G. Brown	                       http://www.phy.duke.edu/~rgb/
Duke University Dept. of Physics, Box 90305
Durham, N.C. 27708-0305
Phone: 1-919-660-2567  Fax: 919-660-2525     email:rgb@phy.duke.edu





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