[gtkada] Question about Item_Factory and constraint error

Chip Richards chipr at niestu.com
Sat Feb 17 12:24:24 CET 2001


I'm using code that was inspired by the Create_Item_Factory package from the
testgtk included with GtkAda 1.2.10.  The relevant piece of the original code
is this:

   Create_Items (Item_Factory, Menu_Items, null);
   Set_Active (Gtk_Check_Menu_Item (Get_Item
                (Item_Factory, "/Preferences/Shape/Oval")), True);

Works like a champ.  Now, due to the structure of my code, I don't use an
array and Create_Items, but instead make several individual calls to
Create_Item.  Which, inspecting the Gtk+ C source code, is exactly what
gtk_item_factory_create_items does itself.

My original code just did the Create_Item call shown below, and it worked
fine.  Then I added the Set_Active call, and started getting the problem.  My
current code:

   Create_Item (ItmFac, Gtk_New (Label_Str, "", CB'access,
                Radio_Item, Act), null, 1);
   if Selected then
      Set_Active (Gtk_Check_Menu_Item (Get_Item (ItmFac, Label_Str)),
                  true);
   end if;

That gets a CONSTRAINT_ERROR exception if Selected is ever true.  Through some
backtracking, I have discovered that it actually occurs on the type conversion
to Gtk_Check_Menu_Item.  More specifically, if I try to type-convert the
(apparently normal, non-null) widget pointer I get back from Get_Item to
*anything* in the object lineage between Gtk_Widget and Gtk_Check_Menu_Item,
starting with its first derivation, Gtk_Container, I get the same exception.
When I print the widget type name, it says "GtkRadioMenuItem", same as when I
print it in the testgtk code.  The function Gtk.Is_Created returns true for
the returned pointer.

So, why am I getting a constraint error here?  How can I track down which
constraint is being violated?  Clearly, I'm down a rathole and am overlooking
something dirt simple and obvious.  What?

(I've pasted below an example program that gives the error when run.)

-- 
Chip

==============================================================================

with Gtk.Accel_Group;      use Gtk.Accel_Group;
with Gtk.Check_Menu_Item;  use Gtk.Check_Menu_Item;
with Gtk.Enums;            use Gtk.Enums;
with Gtk.Item_Factory;     use Gtk.Item_Factory;
with Gtk.Main;             use Gtk.Main;
with Gtk.Menu_Bar;
with Gtk.Window;           use Gtk.Window;

procedure CMI is

Win:      Gtk_Window;
AccGrp:   Gtk_Accel_Group;
ItmFac:   Gtk_Item_Factory;

package Factory_Data is new Data_Item (integer);
use Factory_Data;

begin
   Init;
   Gtk_New (Win, Window_Toplevel);
   Gtk_New (AccGrp);
   Attach (AccGrp, Win);
   Gtk_New (ItmFac, Gtk.Menu_Bar.Get_Type, "<main>", AccGrp);
   Create_Item (ItmFac, Gtk_New ("/File", Item_Type => Branch), null, 1);
   Create_Item (ItmFac, Gtk_New ("/File/First", "", null, Radio_Item, 0), null, 1);
   Set_Active (Gtk_Check_Menu_Item (Get_Item (ItmFac, "/File/First")), true);
end CMI;

==============================================================================




More information about the gtkada mailing list