1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.SearchEntry;
26 
27 private import gdk.Event;
28 private import glib.ConstructionException;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.Entry;
32 private import gtk.Widget;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * #GtkSearchEntry is a subclass of #GtkEntry that has been
41  * tailored for use as a search entry.
42  * 
43  * It will show an inactive symbolic “find” icon when the search
44  * entry is empty, and a symbolic “clear” icon when there is text.
45  * Clicking on the “clear” icon will empty the search entry.
46  * 
47  * Note that the search/clear icon is shown using a secondary
48  * icon, and thus does not work if you are using the secondary
49  * icon position for some other purpose.
50  * 
51  * To make filtering appear more reactive, it is a good idea to
52  * not react to every change in the entry text immediately, but
53  * only after a short delay. To support this, #GtkSearchEntry
54  * emits the #GtkSearchEntry::search-changed signal which can
55  * be used instead of the #GtkEditable::changed signal.
56  * 
57  * The #GtkSearchEntry::previous-match, #GtkSearchEntry::next-match
58  * and #GtkSearchEntry::stop-search signals can be used to implement
59  * moving between search results and ending the search.
60  * 
61  * Often, GtkSearchEntry will be fed events by means of being
62  * placed inside a #GtkSearchBar. If that is not the case,
63  * you can use gtk_search_entry_handle_event() to pass events.
64  *
65  * Since: 3.6
66  */
67 public class SearchEntry : Entry
68 {
69 	/** the main Gtk struct */
70 	protected GtkSearchEntry* gtkSearchEntry;
71 
72 	/** Get the main Gtk struct */
73 	public GtkSearchEntry* getSearchEntryStruct(bool transferOwnership = false)
74 	{
75 		if (transferOwnership)
76 			ownedRef = false;
77 		return gtkSearchEntry;
78 	}
79 
80 	/** the main Gtk struct as a void* */
81 	protected override void* getStruct()
82 	{
83 		return cast(void*)gtkSearchEntry;
84 	}
85 
86 	/**
87 	 * Sets our main struct and passes it to the parent class.
88 	 */
89 	public this (GtkSearchEntry* gtkSearchEntry, bool ownedRef = false)
90 	{
91 		this.gtkSearchEntry = gtkSearchEntry;
92 		super(cast(GtkEntry*)gtkSearchEntry, ownedRef);
93 	}
94 
95 
96 	/** */
97 	public static GType getType()
98 	{
99 		return gtk_search_entry_get_type();
100 	}
101 
102 	/**
103 	 * Creates a #GtkSearchEntry, with a find icon when the search field is
104 	 * empty, and a clear icon when it isn't.
105 	 *
106 	 * Returns: a new #GtkSearchEntry
107 	 *
108 	 * Since: 3.6
109 	 *
110 	 * Throws: ConstructionException GTK+ fails to create the object.
111 	 */
112 	public this()
113 	{
114 		auto p = gtk_search_entry_new();
115 
116 		if(p is null)
117 		{
118 			throw new ConstructionException("null returned by new");
119 		}
120 
121 		this(cast(GtkSearchEntry*) p);
122 	}
123 
124 	/**
125 	 * This function should be called when the top-level window
126 	 * which contains the search entry received a key event. If
127 	 * the entry is part of a #GtkSearchBar, it is preferable
128 	 * to call gtk_search_bar_handle_event() instead, which will
129 	 * reveal the entry in addition to passing the event to this
130 	 * function.
131 	 *
132 	 * If the key event is handled by the search entry and starts
133 	 * or continues a search, %GDK_EVENT_STOP will be returned.
134 	 * The caller should ensure that the entry is shown in this
135 	 * case, and not propagate the event further.
136 	 *
137 	 * Params:
138 	 *     event = a key event
139 	 *
140 	 * Returns: %GDK_EVENT_STOP if the key press event resulted
141 	 *     in a search beginning or continuing, %GDK_EVENT_PROPAGATE
142 	 *     otherwise.
143 	 *
144 	 * Since: 3.16
145 	 */
146 	public bool handleEvent(Event event)
147 	{
148 		return gtk_search_entry_handle_event(gtkSearchEntry, (event is null) ? null : event.getEventStruct()) != 0;
149 	}
150 
151 	/**
152 	 * The ::next-match signal is a [keybinding signal][GtkBindingSignal]
153 	 * which gets emitted when the user initiates a move to the next match
154 	 * for the current search string.
155 	 *
156 	 * Applications should connect to it, to implement moving between
157 	 * matches.
158 	 *
159 	 * The default bindings for this signal is Ctrl-g.
160 	 *
161 	 * Since: 3.16
162 	 */
163 	gulong addOnNextMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
164 	{
165 		return Signals.connect(this, "next-match", dlg, connectFlags ^ ConnectFlags.SWAPPED);
166 	}
167 
168 	/**
169 	 * The ::previous-match signal is a [keybinding signal][GtkBindingSignal]
170 	 * which gets emitted when the user initiates a move to the previous match
171 	 * for the current search string.
172 	 *
173 	 * Applications should connect to it, to implement moving between
174 	 * matches.
175 	 *
176 	 * The default bindings for this signal is Ctrl-Shift-g.
177 	 *
178 	 * Since: 3.16
179 	 */
180 	gulong addOnPreviousMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
181 	{
182 		return Signals.connect(this, "previous-match", dlg, connectFlags ^ ConnectFlags.SWAPPED);
183 	}
184 
185 	/**
186 	 * The #GtkSearchEntry::search-changed signal is emitted with a short
187 	 * delay of 150 milliseconds after the last change to the entry text.
188 	 *
189 	 * Since: 3.10
190 	 */
191 	gulong addOnSearchChanged(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
192 	{
193 		return Signals.connect(this, "search-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
194 	}
195 
196 	/**
197 	 * The ::stop-search signal is a [keybinding signal][GtkBindingSignal]
198 	 * which gets emitted when the user stops a search via keyboard input.
199 	 *
200 	 * Applications should connect to it, to implement hiding the search
201 	 * entry in this case.
202 	 *
203 	 * The default bindings for this signal is Escape.
204 	 *
205 	 * Since: 3.16
206 	 */
207 	gulong addOnStopSearch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
208 	{
209 		return Signals.connect(this, "stop-search", dlg, connectFlags ^ ConnectFlags.SWAPPED);
210 	}
211 }