comp.lang.ada
 help / color / mirror / Atom feed
* GEntry with autocomplete
@ 2022-03-07  0:06 Gavin McCord
  2022-03-07  7:18 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 3+ messages in thread
From: Gavin McCord @ 2022-03-07  0:06 UTC (permalink / raw)


I'm looking at including a GEntry with autocomplete
in some code of mine, and have created a simple example,
test.adb, which I've constructed from tutorial examples
(though from other languages, such as Python and PHP).



with Gtk.Main;
with Gtk.Window;           use Gtk.Window;
with Gtk.GEntry;           use Gtk.Gentry;
with Gtk.List_Store;       use Gtk.List_Store;
with Gtk.Tree_Model;       use Gtk.Tree_Model;
with Gtk.Entry_Completion; use Gtk.Entry_Completion;
with Gtkada.Handlers;      use Gtkada.Handlers;
with Glib;                 use Glib;

with test_cb; use test_cb;

procedure Test is
   Win          : Gtk_Window;
   Entry_1      : Gtk_GEntry;
   List_1       : Gtk_Tree_Model;
   Iter_1       : Gtk_Tree_Iter;
   Completion_1 : Gtk_Entry_Completion;
   type Word_Array is Array (1 .. 3) of String (1 .. 5);
   Words        : Word_Array;
begin
   Gtk.Main.Init;
   Gtk_New (Win);
   Win.Set_Title ("Window");
   Win.On_Delete_Event (main_del'Access);
   Win.On_Destroy (main_quit'Access);
   Win.Set_Border_Width (10);

   Words(1) := "Alpha";
   Words(2) := "Bravo";
   Words(3) := "Delta";

   Gtk_New (List_1, (0 => GType_String)); -- 0 - the first column
   for Count in 1 .. 3 loop
      List_1.Append (Iter_1);
      Set (List_1, Iter_1, 0, Words(Count));
      -- 0 The first column
   end loop;

   Gtk_New (Completion_1);
   Completion_1.Set_Model (List_1);
   Completion_1.Set_Text_Column(0);

   Gtk_New (Entry_1);
   Entry_1.Set_Completion(Completion_1);
   Win.Add (Entry_1);

   Win.Show_All;

   Gtk.Main.Main;
end Test;




Compilation fails at line 40 "Completion_1.Set_Model (List_1)"
with the error

test.adb:40:28: error: expected private type "Gtk_Tree_Model" defined at
gtk-tree_model.ads:195
test.adb:40:28: error: found type "Gtk_List_Store" defined at
gtk-list_store.ads:139

Presumably, I've missed something in translation.

Thanks for any help.

Gavin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: GEntry with autocomplete
  2022-03-07  0:06 GEntry with autocomplete Gavin McCord
@ 2022-03-07  7:18 ` Dmitry A. Kazakov
  2022-03-08 23:46   ` Gavin McCord
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry A. Kazakov @ 2022-03-07  7:18 UTC (permalink / raw)


On 2022-03-07 01:06, Gavin McCord wrote:

> Compilation fails at line 40 "Completion_1.Set_Model (List_1)"
> with the error
> 
> test.adb:40:28: error: expected private type "Gtk_Tree_Model" defined at
> gtk-tree_model.ads:195
> test.adb:40:28: error: found type "Gtk_List_Store" defined at
> gtk-list_store.ads:139
> 
> Presumably, I've missed something in translation.

See To_Interface function that does the conversion.

[GTK interfaces are tagged Ada types. Since full MI is unfortunately not 
supported in Ada, explicit conversion are are needed]

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: GEntry with autocomplete
  2022-03-07  7:18 ` Dmitry A. Kazakov
@ 2022-03-08 23:46   ` Gavin McCord
  0 siblings, 0 replies; 3+ messages in thread
From: Gavin McCord @ 2022-03-08 23:46 UTC (permalink / raw)


On Mon, 7 Mar 2022 08:18:07 +0100, Dmitry A. Kazakov wrote:

> On 2022-03-07 01:06, Gavin McCord wrote:
> 
>> Compilation fails at line 40 "Completion_1.Set_Model (List_1)"
>> with the error
>> 
>> test.adb:40:28: error: expected private type "Gtk_Tree_Model" defined
>> at gtk-tree_model.ads:195 test.adb:40:28: error: found type
>> "Gtk_List_Store" defined at gtk-list_store.ads:139
>> 
>> Presumably, I've missed something in translation.
> 
> See To_Interface function that does the conversion.
> 
> [GTK interfaces are tagged Ada types. Since full MI is unfortunately not
> supported in Ada, explicit conversion are are needed]

Yes, that did the trick. Thank you.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-08 23:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07  0:06 GEntry with autocomplete Gavin McCord
2022-03-07  7:18 ` Dmitry A. Kazakov
2022-03-08 23:46   ` Gavin McCord

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox