[gtkada] Another question

Preben Randhol randhol at pvv.org
Thu Nov 15 13:51:19 CET 2001


At the moment I do this: I have a window with a menu a statusbar and a
vbox. Into the Vbox I pack different widgets depending where in the
program on is. To do this I add a function and a procedure in each
widget. I'm going to make this generic, but I haven't had time to do
code cleanup yet. 

If I want to show the List Widget with the Clist ++ I do List_Gui.Show
like below. I probably don't need to use a function and a procedure,
just one procedure, but I'll change things when I move to generic.

The change_Mode function in the Window_Gui will then remove the child
packed to the vbox in the Window and pack the new into it. If I call
Remove the Widget gets unrefed so I need to call Ref once when I create
the widget. However this means I need to do a manual Unref when I close
the program I guess.

The problem with this method is that if I press a button in the widget,
say a close button (so the widget is replaced by a new) and when I then
return to the widget later I get this button highlighted from when I
pressed it before. Is there a way to get the widget to refresh?

Thanks in advance.

PS: My method is probably to complicated, so if there is a better
solution I would like to hear it.

from the List_Gui package:

   function Get_GUI return Gtk_Widget is
   begin
      if Gui_Result = null then
         Gtk_New (Gui_List);
         Ref (Gui_List);
         -- Ref the GUI so that if one use Remove it will not be destroyed
      end if;
      return Gtk_Widget (Gui_List);
   end Get_GUI;

   procedure Show is
   begin
      Window_Gui.Change_Mode (List_Gui.Get_Gui); 
   end Show;


from the Window_Gui Package:

   ----------------------
   --   Change_Node    --
   ----------------------

   procedure Change_Mode (Child : Gtk_Widget) is
      Old_Child : Gtk_Widget;
   begin

      Old_Child := Get_Child (Gui_Window.Gui_Mode_Vbox,0);
      -- NOTE: Remember to Ref your Child before this.

      if Old_Child /= null then 
         Remove (Gui_Window.Gui_Mode_Vbox, Old_Child);
      end if;

      Pack_Start (Gui_Window.Gui_Mode_Vbox,
                  Child, True, True, 0);
      Show_All (Gui_Window.Gui_Mode_Vbox);

   end Change_Mode;

-- 
Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
                 «For me, Ada95 puts back the joy in programming.»




More information about the gtkada mailing list