[gtkada] Question about Item_Factory and constraint error

Chip Richards chipr at niestu.com
Sat Feb 17 21:57:05 CET 2001


On Sat, Feb 17, 2001 at 02:09:01PM +0100, Arnaud Charlet wrote:

> You should look for type conversion in the GtkAda user's guide.

Okay, that's interesting info.  I assume you are talking about the text under
the heading "Type conversions from C to Ada widgets" in the section
"Object-oriented features".  Your referral was very useful, thanks!

But it raises a new question, and leaves my main original question unanswered:

1. It says "you will thus have to do an Uncheck_Cast to convert it back to the
type you want".  What is "Uncheck_Cast"?  Is it intending to refer to
Ada.Unchecked_Conversion?  Of *course* I could have done the type conversion
using this facility, but I wanted to understand why the error was occurring
before I just ignored it.  Heck, if I wanted to program that way, I'd just use
C. <grin>

I think I've figured out what's going on in my code, though, thanks to that
section of the doc.  I spent quite some time re-reading the bit that says "If
the widget was created implicitly ... then GtkAda will only be able to create
the corresponding type by default for the following widgets: ... Gtk_Menu_Item
..."  Okay, the widget whose pointer I'm fetching with Get_Item certainly
wasn't created by Ada code--it was created inside the C item-factory module.
And it isn't (directly) a Gtk_Menu_Item, it's a Gtk_Check_Menu_Item.  So both
of the above conditions hold, meaning I need to do an unchecked conversion on
it.  Though I'm not sure how a Gtk_Menu_Item would be treated differently.
But I don't care so much about that at this point; if Uncheck_Cast is really
Unchecked_Conversion, then that leaves only my original question.

2. My original question, which was probably obscured by the length of my
original explanation, was: Why does the conversion work in testgtk and not in
my code?  It's not like Create_Item and Create_Items are substantively
different on the Ada side--they're both just pass-throughs to the C code.  And
the C code for the array version just makes multiple calls to the singleton
version.

I thought perhaps that it was because the Create_Items call in testgtk has had
a chance to somehow "finish" the menu by having seen the Last_Branch item
before the Get_Item call, but inspecting the actual Gtk+ code, I see that the
last_branch flag makes very little difference in the handling of an added
item, and in no way "finishes" anything.

There's apparently some other difference that I'm not seeing.  I can certainly
make my code work as expected, with the somewhat unpleasant addition of an
unchecked conversion.  But I still don't understand the whole picture.

Thank you for your answer, Arnaud, and if you have any additional answers for
the above, I would appreciate them.

-- 
Chip




More information about the gtkada mailing list