Gtk.Tree_Model.Nth_Child with Gtk.List_Store.Gtk_List_Store.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Gtk.Tree_Model.Nth_Child with Gtk.List_Store.Gtk_List_Store.

Pascal-68
Hello,

Here is a sample GTK C code:
(from http://scentric.net/tutorial/sec-treemodel-remove-row.html)
   gboolean
   list_store_remove_nth_row (GtkListStore *store, gint n)
   {
     GtkTreeIter  iter;

     g_return_val_if_fail (GTK_IS_LIST_STORE(store), FALSE);

     /* NULL means the parent is the virtual root node, so the
      *  n-th top-level element is returned in iter, which is
      *  the n-th row in a list store (as a list store only has
      *  top-level elements, and no children) */
     if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, n))
     {
       gtk_list_store_remove(store, &iter);
       return TRUE;
     }

     return FALSE;
   }

I want to do the same with GTKAda:
      function Remove (Store   : in Gtk.List_Store.Gtk_List_Store;
      N : in Natural) is
      Iter : Gtk.Tree_Model.Gtk_Tree_Iter := Gtk.Tree_Model.Nth_Child (Gtk.Tree_Model.Gtk_Tree_Model(Store), Gtk.Tree_Model.Null_Iter, Glib.Gint(N));
...

But GNAT complains:
invalid conversion, not compatible with type "Gtk_List_Store" defined at gtk-list_store.ads:173

Any idea?

Thanks, Pascal.
http://blady.pagesperso-orange.fr


_______________________________________________
gtkada mailing list
[hidden email]
http://lists.adacore.com/mailman/listinfo/gtkada
Reply | Threaded
Open this post in threaded view
|

Re: Gtk.Tree_Model.Nth_Child with Gtk.List_Store.Gtk_List_Store.

Emmanuel Briot
> I want to do the same with GTKAda:
>      function Remove (Store   : in Gtk.List_Store.Gtk_List_Store;
>      N : in Natural) is
>      Iter : Gtk.Tree_Model.Gtk_Tree_Iter := Gtk.Tree_Model.Nth_Child (Gtk.Tree_Model.Gtk_Tree_Model(Store), Gtk.Tree_Model.Null_Iter, Glib.Gint(N));
> ...
>
> But GNAT complains:
> invalid conversion, not compatible with type "Gtk_List_Store" defined at gtk-list_store.ads:173


Would help if you could quote the code correctly, this is really hard to read.

I assume the issue is

      Store : Gtk_List_Store;
      Gtk_Tree_Model (Store)

and indeed these two types are not compatible (A Gtk_Tree_Model is a gtk+ interface, which is
not mapped to an Ada interface for various reasons).

If you look at gtk-list_store.ads, there is a section named "Interfaces", which provides a "+"
iterator to do the conversion.

So you can simply use

    +Store

to get a Gtk_Tree_Model

Emmanuel
_______________________________________________
gtkada mailing list
[hidden email]
http://lists.adacore.com/mailman/listinfo/gtkada
Reply | Threaded
Open this post in threaded view
|

Re: Gtk.Tree_Model.Nth_Child with Gtk.List_Store.Gtk_List_Store.

Pascal-68
Thanks Emmanuel for your answer.
You guess right that was exactly what I looking for.

I try to port RAPID from GTKAda 2 to GTKAda 3.
Well, "Transitioning from GtkAda 2 to GtkAda 3" from GTKAda documentation is quite useful.
But GTK 3 C examples on Internet are not so obvious to translate in GTKAda.

At present I'm stuck with conversion of Gtk_Tree_Iter in row number to implements the followings:
(The original GTK 2 was based on Gtk.List.Gtk_List and Gtk.Widget.Widget_List.Glist see http://svn.savannah.gnu.org/viewvc/trunk/gtk_peer/peer-gtk_list.adb?root=rapid&view=markup)
   ------------------------------------------------
   -- function Count
   -- get number of items in Gtk.Tree_View.Gtk_Tree_View
   ------------------------------------------------
   function Count (Obj : in Gtk.Tree_View.Gtk_Tree_View) return Natural;
   ------------------------------------------------
   -- procedure Select_Item
   -- Select number item in Gtk.Tree_View.Gtk_Tree_View
   -- Use 0 to select nothing.
   ------------------------------------------------
   procedure Select_Item (Obj : in Gtk.Tree_View.Gtk_Tree_View; Number : in Natural);
   ------------------------------------------------
   -- function Get_Selected
   -- return number of selected item, or 0 if
   -- nothing selected
   ------------------------------------------------
   function Get_Selected (Obj : in Gtk.Tree_View.Gtk_Tree_View) return Natural;

Any tips would be appreciated.

Thanks, Pascal.
http://blady.pagesperso-orange.fr


> Le 10 mars 2016 à 10:22, Emmanuel Briot <[hidden email]> a écrit :
>
>> I want to do the same with GTKAda:
>>     function Remove (Store   : in Gtk.List_Store.Gtk_List_Store;
>>     N : in Natural) is
>>     Iter : Gtk.Tree_Model.Gtk_Tree_Iter := Gtk.Tree_Model.Nth_Child (Gtk.Tree_Model.Gtk_Tree_Model(Store), Gtk.Tree_Model.Null_Iter, Glib.Gint(N));
>> ...
>>
>> But GNAT complains:
>> invalid conversion, not compatible with type "Gtk_List_Store" defined at gtk-list_store.ads:173
>
>
> Would help if you could quote the code correctly, this is really hard to read.
>
> I assume the issue is
>
>      Store : Gtk_List_Store;
>      Gtk_Tree_Model (Store)
>
> and indeed these two types are not compatible (A Gtk_Tree_Model is a gtk+ interface, which is
> not mapped to an Ada interface for various reasons).
>
> If you look at gtk-list_store.ads, there is a section named "Interfaces", which provides a "+"
> iterator to do the conversion.
>
> So you can simply use
>
>    +Store
>
> to get a Gtk_Tree_Model
>
> Emmanuel

_______________________________________________
gtkada mailing list
[hidden email]
http://lists.adacore.com/mailman/listinfo/gtkada