[gtkada] Signal handler
Dmitry A. Kazakov
mailbox at dmitry-kazakov.de
Mon Aug 1 18:49:31 CEST 2011
On Mon, 1 Aug 2011 15:32:34 +0200, you wrote:
> I was thinking that the problem might be in GtkAda's "ada_tree_iter_copy" called
> in the body of Gtk.Tree_Model.Get_Tree_Iter. Is there a reason why it was written
> in C and not Ada?
No, iterator can be copied in Ada, it is a plain C structure,
> Here's the example:
> --------- fill_entry.ads -------
>
> with Glib.Object;
> with Glib.Values; use Glib.Values;
>
> function Fill_Entry (Object : access Glib.Object.GObject_Record'Class;
> Params : in GValues) return Boolean;
>
> --------- fill_entry.adb -------
>
> with Gtk.Enums; use Gtk.Enums;
> with Gtk.Entry_Completion; use Gtk.Entry_Completion;
> with Gtk.GEntry; use Gtk.GEntry;
> with Gtk.Tree_Model; use Gtk.Tree_Model;
>
> function Fill_Entry (Object : access Glib.Object.GObject_Record'Class;
> Params : in GValues) return Boolean is
> Model : Gtk_Tree_Model;
> Iter : Gtk_Tree_Iter;
> begin
> Model := Get_Model(Gtk_Entry_Completion(Object));
> Get_Tree_Iter (Nth (Params, 1), Iter);
> Set_Text (Gtk_Entry(Get_Entry(Gtk_Entry_Completion(Object))), Get_String(Model, Iter, 1));
Two issues here:
1. The model passed to the handler is not the model of the completion
object. I didn't look in the sources, but I suspect they create a derived
model (sorted or filtered) and pass this model instead of the original one.
2. The iterator is the second argument.
Therefore it should be:
Model : aliased Gtk_Tree_Model_Record;
Iter : Gtk_Tree_Iter;
begin
Model.Set_Object (Get_Address (Nth (Params, 1))); -- Get the model
Get_Tree_Iter (Nth (Params, 2), Iter); -- Get the iterator
Set_Text
( Gtk_Entry (Get_Entry (Gtk_Entry_Completion (Object))),
Get_String (Model'Access, Iter, 1)
);
> return True;
> end Fill_Entry;
>
> --------- signal_match_test.adb -------
>
[...]
> Gtk_New (Compl);
> Set_Text_Column (Compl, 0);
> Set_Text_Column (Compl, 1);
> Set_Text_Column (Compl, 2);
> Set_Property (Compl, Text_Column_Property, 0);
> Set_Model (Compl, Gtk_Tree_Model(List));
Note that this leaks. Gtk_List_Store is not a floating object. After
Set_Model its reference count is 2. So you have to add:
Unref (List);
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
More information about the gtkada
mailing list