[gtkada] Signal handler
Op de Coul, Manuel
Manuel.op.de.Coul at eon.com
Tue Aug 2 17:33:34 CEST 2011
It works now, thanks very much again!
Arnaud, I have attached a patch for gtk-entry_completion.ads for you to review.
Best,
Manuel
-----Original Message-----
From: gtkada-bounces at lists.adacore.com [mailto:gtkada-bounces at lists.adacore.com] On Behalf Of Dmitry A. Kazakov
Sent: maandag 1 augustus 2011 18:50
To: gtkada
Subject: Re: [gtkada] Signal handler
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
_______________________________________________
gtkada mailing list
gtkada at lists.adacore.com
http://lists.adacore.com/mailman/listinfo/gtkada
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gtk-entry_completion.diff
Type: application/octet-stream
Size: 836 bytes
Desc: gtk-entry_completion.diff
Url : /pipermail/gtkada/attachments/20110802/e215603b/attachment.obj
More information about the gtkada
mailing list