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 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * #GtkSearchEntry is a subclass of #GtkEntry that has been
40  * tailored for use as a search entry.
41  * 
42  * It will show an inactive symbolic “find” icon when the search
43  * entry is empty, and a symbolic “clear” icon when there is text.
44  * Clicking on the “clear” icon will empty the search entry.
45  * 
46  * Note that the search/clear icon is shown using a secondary
47  * icon, and thus does not work if you are using the secondary
48  * icon position for some other purpose.
49  * 
50  * To make filtering appear more reactive, it is a good idea to
51  * not react to every change in the entry text immediately, but
52  * only after a short delay. To support this, #GtkSearchEntry
53  * emits the #GtkSearchEntry::search-changed signal which can
54  * be used instead of the #GtkEditable::changed signal.
55  * 
56  * The #GtkSearchEntry::previous-match, #GtkSearchEntry::next-match
57  * and #GtkSearchEntry::stop-search signals can be uesd to implement
58  * moving between search results and ending the search.
59  * 
60  * Often, GtkSearchEntry will be fed events by means of being
61  * placed inside a #GtkSearchBar. If that is not the case,
62  * you can use gtk_search_entry_handle_event() to pass events.
63  */
64 public class SearchEntry : Entry
65 {
66 	/** the main Gtk struct */
67 	protected GtkSearchEntry* gtkSearchEntry;
68 
69 	/** Get the main Gtk struct */
70 	public GtkSearchEntry* getSearchEntryStruct()
71 	{
72 		return gtkSearchEntry;
73 	}
74 
75 	/** the main Gtk struct as a void* */
76 	protected override void* getStruct()
77 	{
78 		return cast(void*)gtkSearchEntry;
79 	}
80 
81 	protected override void setStruct(GObject* obj)
82 	{
83 		gtkSearchEntry = cast(GtkSearchEntry*)obj;
84 		super.setStruct(obj);
85 	}
86 
87 	/**
88 	 * Sets our main struct and passes it to the parent class.
89 	 */
90 	public this (GtkSearchEntry* gtkSearchEntry, bool ownedRef = false)
91 	{
92 		this.gtkSearchEntry = gtkSearchEntry;
93 		super(cast(GtkEntry*)gtkSearchEntry, ownedRef);
94 	}
95 
96 
97 	/** */
98 	public static GType getType()
99 	{
100 		return gtk_search_entry_get_type();
101 	}
102 
103 	/**
104 	 * Creates a #GtkSearchEntry, with a find icon when the search field is
105 	 * empty, and a clear icon when it isn't.
106 	 *
107 	 * Return: a new #GtkSearchEntry
108 	 *
109 	 * Since: 3.6
110 	 *
111 	 * Throws: ConstructionException GTK+ fails to create the object.
112 	 */
113 	public this()
114 	{
115 		auto p = gtk_search_entry_new();
116 		
117 		if(p is null)
118 		{
119 			throw new ConstructionException("null returned by new");
120 		}
121 		
122 		this(cast(GtkSearchEntry*) p);
123 	}
124 
125 	/**
126 	 * This function should be called when the top-level window
127 	 * which contains the search entry received a key event. If
128 	 * the entry is part of a #GtkSearchBar, it is preferable
129 	 * to call gtk_search_bar_handle_event() instead, which will
130 	 * reveal the entry in addition to passing the event to this
131 	 * function.
132 	 *
133 	 * If the key event is handled by the search entry and starts
134 	 * or continues a search, %GDK_EVENT_STOP will be returned.
135 	 * The caller should ensure that the entry is shown in this
136 	 * case, and not propagate the event further.
137 	 *
138 	 * Params:
139 	 *     event = a key event
140 	 *
141 	 * Return: %GDK_EVENT_STOP if the key press event resulted
142 	 *     in a search beginning or continuing, %GDK_EVENT_PROPAGATE
143 	 *     otherwise.
144 	 *
145 	 * Since: 3.16
146 	 */
147 	public bool handleEvent(Event event)
148 	{
149 		return gtk_search_entry_handle_event(gtkSearchEntry, (event is null) ? null : event.getEventStruct()) != 0;
150 	}
151 
152 	int[string] connectedSignals;
153 
154 	void delegate(SearchEntry)[] onNextMatchListeners;
155 	/**
156 	 * The ::next-match signal is a [keybinding signal][GtkBindingSignal]
157 	 * which gets emitted when the user initiates a move to the next match
158 	 * for the current search string.
159 	 *
160 	 * Applications should connect to it, to implement moving between
161 	 * matches.
162 	 *
163 	 * The default bindings for this signal is Ctrl-g.
164 	 *
165 	 * Since: 3.16
166 	 */
167 	void addOnNextMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
168 	{
169 		if ( "next-match" !in connectedSignals )
170 		{
171 			Signals.connectData(
172 				this,
173 				"next-match",
174 				cast(GCallback)&callBackNextMatch,
175 				cast(void*)this,
176 				null,
177 				connectFlags);
178 			connectedSignals["next-match"] = 1;
179 		}
180 		onNextMatchListeners ~= dlg;
181 	}
182 	extern(C) static void callBackNextMatch(GtkSearchEntry* searchentryStruct, SearchEntry _searchentry)
183 	{
184 		foreach ( void delegate(SearchEntry) dlg; _searchentry.onNextMatchListeners )
185 		{
186 			dlg(_searchentry);
187 		}
188 	}
189 
190 	void delegate(SearchEntry)[] onPreviousMatchListeners;
191 	/**
192 	 * The ::previous-match signal is a [keybinding signal][GtkBindingSignal]
193 	 * which gets emitted when the user initiates a move to the previous match
194 	 * for the current search string.
195 	 *
196 	 * Applications should connect to it, to implement moving between
197 	 * matches.
198 	 *
199 	 * The default bindings for this signal is Ctrl-Shift-g.
200 	 *
201 	 * Since: 3.16
202 	 */
203 	void addOnPreviousMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
204 	{
205 		if ( "previous-match" !in connectedSignals )
206 		{
207 			Signals.connectData(
208 				this,
209 				"previous-match",
210 				cast(GCallback)&callBackPreviousMatch,
211 				cast(void*)this,
212 				null,
213 				connectFlags);
214 			connectedSignals["previous-match"] = 1;
215 		}
216 		onPreviousMatchListeners ~= dlg;
217 	}
218 	extern(C) static void callBackPreviousMatch(GtkSearchEntry* searchentryStruct, SearchEntry _searchentry)
219 	{
220 		foreach ( void delegate(SearchEntry) dlg; _searchentry.onPreviousMatchListeners )
221 		{
222 			dlg(_searchentry);
223 		}
224 	}
225 
226 	void delegate(SearchEntry)[] onSearchChangedListeners;
227 	/**
228 	 * The #GtkSearchEntry::search-changed signal is emitted with a short
229 	 * delay of 150 milliseconds after the last change to the entry text.
230 	 *
231 	 * Since: 3.10
232 	 */
233 	void addOnSearchChanged(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
234 	{
235 		if ( "search-changed" !in connectedSignals )
236 		{
237 			Signals.connectData(
238 				this,
239 				"search-changed",
240 				cast(GCallback)&callBackSearchChanged,
241 				cast(void*)this,
242 				null,
243 				connectFlags);
244 			connectedSignals["search-changed"] = 1;
245 		}
246 		onSearchChangedListeners ~= dlg;
247 	}
248 	extern(C) static void callBackSearchChanged(GtkSearchEntry* searchentryStruct, SearchEntry _searchentry)
249 	{
250 		foreach ( void delegate(SearchEntry) dlg; _searchentry.onSearchChangedListeners )
251 		{
252 			dlg(_searchentry);
253 		}
254 	}
255 
256 	void delegate(SearchEntry)[] onStopSearchListeners;
257 	/**
258 	 * The ::stop-search signal is a [keybinding signal][GtkBindingSignal]
259 	 * which gets emitted when the user stops a search via keyboard input.
260 	 *
261 	 * Applications should connect to it, to implement hiding the search
262 	 * entry in this case.
263 	 *
264 	 * The default bindings for this signal is Escape.
265 	 *
266 	 * Since: 3.16
267 	 */
268 	void addOnStopSearch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
269 	{
270 		if ( "stop-search" !in connectedSignals )
271 		{
272 			Signals.connectData(
273 				this,
274 				"stop-search",
275 				cast(GCallback)&callBackStopSearch,
276 				cast(void*)this,
277 				null,
278 				connectFlags);
279 			connectedSignals["stop-search"] = 1;
280 		}
281 		onStopSearchListeners ~= dlg;
282 	}
283 	extern(C) static void callBackStopSearch(GtkSearchEntry* searchentryStruct, SearchEntry _searchentry)
284 	{
285 		foreach ( void delegate(SearchEntry) dlg; _searchentry.onStopSearchListeners )
286 		{
287 			dlg(_searchentry);
288 		}
289 	}
290 }