1------------------------------------------------------------------------------
2--                                                                          --
3--      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       --
4--                     Copyright (C) 2000-2015, AdaCore                     --
5--                                                                          --
6-- This library is free software;  you can redistribute it and/or modify it --
7-- under terms of the  GNU General Public License  as published by the Free --
8-- Software  Foundation;  either version 3,  or (at your  option) any later --
9-- version. This library is distributed in the hope that it will be useful, --
10-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
11-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            --
12--                                                                          --
13-- As a special exception under Section 7 of GPL version 3, you are granted --
14-- additional permissions described in the GCC Runtime Library Exception,   --
15-- version 3.1, as published by the Free Software Foundation.               --
16--                                                                          --
17-- You should have received a copy of the GNU General Public License and    --
18-- a copy of the GCC Runtime Library Exception along with this program;     --
19-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
20-- <http://www.gnu.org/licenses/>.                                          --
21--                                                                          --
22------------------------------------------------------------------------------
23
24--  <description>
25--  Gtk.Search_Entry.Gtk_Search_Entry is a subclass of Gtk.GEntry.Gtk_Entry
26--  that has been tailored for use as a search entry.
27--
28--  It will show an inactive symbolic "find" icon when the search entry is
29--  empty, and a symbolic "clear" icon when there is text. Clicking on the
30--  "clear" icon will empty the search entry.
31--
32--  Note that the search/clear icon is shown using a secondary icon, and thus
33--  does not work if you are using the secondary icon position for some other
34--  purpose.
35--
36--  To make filtering appear more reactive, it is a good idea to not react to
37--  every change in the entry text immediately, but only after a short delay.
38--  To support this, Gtk.Search_Entry.Gtk_Search_Entry emits the
39--  Gtk.Search_Entry.Gtk_Search_Entry::search-changed signal which can be used
40--  instead of the Gtk.Editable.Gtk_Editable::changed signal.
41--
42--  </description>
43pragma Ada_2005;
44
45pragma Warnings (Off, "*is already use-visible*");
46with Gdk.Event;         use Gdk.Event;
47with Glib;              use Glib;
48with Glib.Object;       use Glib.Object;
49with Glib.Types;        use Glib.Types;
50with Gtk.Buildable;     use Gtk.Buildable;
51with Gtk.Cell_Editable; use Gtk.Cell_Editable;
52with Gtk.Editable;      use Gtk.Editable;
53with Gtk.GEntry;        use Gtk.GEntry;
54
55package Gtk.Search_Entry is
56
57   type Gtk_Search_Entry_Record is new Gtk_Entry_Record with null record;
58   type Gtk_Search_Entry is access all Gtk_Search_Entry_Record'Class;
59
60   ------------------
61   -- Constructors --
62   ------------------
63
64   procedure Gtk_New (Self : out Gtk_Search_Entry);
65   procedure Initialize
66      (Self : not null access Gtk_Search_Entry_Record'Class);
67   --  Creates a Gtk.Search_Entry.Gtk_Search_Entry, with a find icon when the
68   --  search field is empty, and a clear icon when it isn't.
69   --  Since: gtk+ 3.6
70
71   function Gtk_Search_Entry_New return Gtk_Search_Entry;
72   --  Creates a Gtk.Search_Entry.Gtk_Search_Entry, with a find icon when the
73   --  search field is empty, and a clear icon when it isn't.
74   --  Since: gtk+ 3.6
75
76   function Get_Type return Glib.GType;
77   pragma Import (C, Get_Type, "gtk_search_entry_get_type");
78
79   ---------------------------------------------
80   -- Inherited subprograms (from interfaces) --
81   ---------------------------------------------
82   --  Methods inherited from the Buildable interface are not duplicated here
83   --  since they are meant to be used by tools, mostly. If you need to call
84   --  them, use an explicit cast through the "-" operator below.
85
86   procedure Editing_Done
87      (Cell_Editable : not null access Gtk_Search_Entry_Record);
88
89   procedure Remove_Widget
90      (Cell_Editable : not null access Gtk_Search_Entry_Record);
91
92   procedure Start_Editing
93      (Cell_Editable : not null access Gtk_Search_Entry_Record;
94       Event         : Gdk.Event.Gdk_Event);
95
96   procedure Copy_Clipboard
97      (Editable : not null access Gtk_Search_Entry_Record);
98
99   procedure Cut_Clipboard
100      (Editable : not null access Gtk_Search_Entry_Record);
101
102   procedure Delete_Selection
103      (Editable : not null access Gtk_Search_Entry_Record);
104
105   procedure Delete_Text
106      (Editable  : not null access Gtk_Search_Entry_Record;
107       Start_Pos : Gint;
108       End_Pos   : Gint := -1);
109
110   function Get_Chars
111      (Editable  : not null access Gtk_Search_Entry_Record;
112       Start_Pos : Gint;
113       End_Pos   : Gint := -1) return UTF8_String;
114
115   function Get_Editable
116      (Editable : not null access Gtk_Search_Entry_Record) return Boolean;
117
118   procedure Set_Editable
119      (Editable    : not null access Gtk_Search_Entry_Record;
120       Is_Editable : Boolean);
121
122   function Get_Position
123      (Editable : not null access Gtk_Search_Entry_Record) return Gint;
124
125   procedure Set_Position
126      (Editable : not null access Gtk_Search_Entry_Record;
127       Position : Gint);
128
129   procedure Get_Selection_Bounds
130      (Editable      : not null access Gtk_Search_Entry_Record;
131       Start_Pos     : out Gint;
132       End_Pos       : out Gint;
133       Has_Selection : out Boolean);
134
135   procedure Insert_Text
136      (Editable        : not null access Gtk_Search_Entry_Record;
137       New_Text        : UTF8_String;
138       New_Text_Length : Gint;
139       Position        : in out Gint);
140
141   procedure Paste_Clipboard
142      (Editable : not null access Gtk_Search_Entry_Record);
143
144   procedure Select_Region
145      (Editable  : not null access Gtk_Search_Entry_Record;
146       Start_Pos : Gint;
147       End_Pos   : Gint := -1);
148
149   -------------
150   -- Signals --
151   -------------
152
153   type Cb_Gtk_Search_Entry_Void is not null access procedure
154     (Self : access Gtk_Search_Entry_Record'Class);
155
156   type Cb_GObject_Void is not null access procedure
157     (Self : access Glib.Object.GObject_Record'Class);
158
159   Signal_Search_Changed : constant Glib.Signal_Name := "search-changed";
160   procedure On_Search_Changed
161      (Self  : not null access Gtk_Search_Entry_Record;
162       Call  : Cb_Gtk_Search_Entry_Void;
163       After : Boolean := False);
164   procedure On_Search_Changed
165      (Self  : not null access Gtk_Search_Entry_Record;
166       Call  : Cb_GObject_Void;
167       Slot  : not null access Glib.Object.GObject_Record'Class;
168       After : Boolean := False);
169   --  The Gtk.Search_Entry.Gtk_Search_Entry::search-changed signal is emitted
170   --  with a short delay of 150 milliseconds after the last change to the
171   --  entry text.
172
173   ----------------
174   -- Interfaces --
175   ----------------
176   --  This class implements several interfaces. See Glib.Types
177   --
178   --  - "Buildable"
179   --
180   --  - "CellEditable"
181   --
182   --  - "Editable"
183
184   package Implements_Gtk_Buildable is new Glib.Types.Implements
185     (Gtk.Buildable.Gtk_Buildable, Gtk_Search_Entry_Record, Gtk_Search_Entry);
186   function "+"
187     (Widget : access Gtk_Search_Entry_Record'Class)
188   return Gtk.Buildable.Gtk_Buildable
189   renames Implements_Gtk_Buildable.To_Interface;
190   function "-"
191     (Interf : Gtk.Buildable.Gtk_Buildable)
192   return Gtk_Search_Entry
193   renames Implements_Gtk_Buildable.To_Object;
194
195   package Implements_Gtk_Cell_Editable is new Glib.Types.Implements
196     (Gtk.Cell_Editable.Gtk_Cell_Editable, Gtk_Search_Entry_Record, Gtk_Search_Entry);
197   function "+"
198     (Widget : access Gtk_Search_Entry_Record'Class)
199   return Gtk.Cell_Editable.Gtk_Cell_Editable
200   renames Implements_Gtk_Cell_Editable.To_Interface;
201   function "-"
202     (Interf : Gtk.Cell_Editable.Gtk_Cell_Editable)
203   return Gtk_Search_Entry
204   renames Implements_Gtk_Cell_Editable.To_Object;
205
206   package Implements_Gtk_Editable is new Glib.Types.Implements
207     (Gtk.Editable.Gtk_Editable, Gtk_Search_Entry_Record, Gtk_Search_Entry);
208   function "+"
209     (Widget : access Gtk_Search_Entry_Record'Class)
210   return Gtk.Editable.Gtk_Editable
211   renames Implements_Gtk_Editable.To_Interface;
212   function "-"
213     (Interf : Gtk.Editable.Gtk_Editable)
214   return Gtk_Search_Entry
215   renames Implements_Gtk_Editable.To_Object;
216
217end Gtk.Search_Entry;
218