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 glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.EditableIF;
31 private import gtk.EditableT;
32 private import gtk.Widget;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 private import std.algorithm;
36 
37 
38 /**
39  * `GtkSearchEntry` is an entry widget that has been tailored for use
40  * as a search entry.
41  * 
42  * The main API for interacting with a `GtkSearchEntry` as entry
43  * is the `GtkEditable` interface.
44  * 
45  * ![An example GtkSearchEntry](search-entry.png)
46  * 
47  * It will show an inactive symbolic “find” icon when the search
48  * entry is empty, and a symbolic “clear” icon when there is text.
49  * Clicking on the “clear” icon will empty the search entry.
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 [signal@Gtk.SearchEntry::search-changed] signal which
55  * can be used instead of the [signal@Gtk.Editable::changed] signal.
56  * 
57  * The [signal@Gtk.SearchEntry::previous-match],
58  * [signal@Gtk.SearchEntry::next-match] and
59  * [signal@Gtk.SearchEntry::stop-search] signals can be used to
60  * implement moving between search results and ending the search.
61  * 
62  * Often, `GtkSearchEntry` will be fed events by means of being
63  * placed inside a [class@Gtk.SearchBar]. If that is not the case,
64  * you can use [method@Gtk.SearchEntry.set_key_capture_widget] to
65  * let it capture key input from another widget.
66  * 
67  * `GtkSearchEntry` provides only minimal API and should be used with
68  * the [iface@Gtk.Editable] API.
69  * 
70  * ## CSS Nodes
71  * 
72  * ```
73  * entry.search
74  * ╰── text
75  * ```
76  * 
77  * `GtkSearchEntry` has a single CSS node with name entry that carries
78  * a `.search` style class, and the text node is a child of that.
79  * 
80  * ## Accessibility
81  * 
82  * `GtkSearchEntry` uses the %GTK_ACCESSIBLE_ROLE_SEARCH_BOX role.
83  */
84 public class SearchEntry : Widget, EditableIF
85 {
86 	/** the main Gtk struct */
87 	protected GtkSearchEntry* gtkSearchEntry;
88 
89 	/** Get the main Gtk struct */
90 	public GtkSearchEntry* getSearchEntryStruct(bool transferOwnership = false)
91 	{
92 		if (transferOwnership)
93 			ownedRef = false;
94 		return gtkSearchEntry;
95 	}
96 
97 	/** the main Gtk struct as a void* */
98 	protected override void* getStruct()
99 	{
100 		return cast(void*)gtkSearchEntry;
101 	}
102 
103 	/**
104 	 * Sets our main struct and passes it to the parent class.
105 	 */
106 	public this (GtkSearchEntry* gtkSearchEntry, bool ownedRef = false)
107 	{
108 		this.gtkSearchEntry = gtkSearchEntry;
109 		super(cast(GtkWidget*)gtkSearchEntry, ownedRef);
110 	}
111 
112 	// add the Editable capabilities
113 	mixin EditableT!(GtkSearchEntry);
114 
115 
116 	/** */
117 	public static GType getType()
118 	{
119 		return gtk_search_entry_get_type();
120 	}
121 
122 	/**
123 	 * Creates a `GtkSearchEntry`.
124 	 *
125 	 * Returns: a new `GtkSearchEntry`
126 	 *
127 	 * Throws: ConstructionException GTK+ fails to create the object.
128 	 */
129 	public this()
130 	{
131 		auto __p = gtk_search_entry_new();
132 
133 		if(__p is null)
134 		{
135 			throw new ConstructionException("null returned by new");
136 		}
137 
138 		this(cast(GtkSearchEntry*) __p);
139 	}
140 
141 	/**
142 	 * Gets the widget that @entry is capturing key events from.
143 	 *
144 	 * Returns: The key capture widget.
145 	 */
146 	public Widget getKeyCaptureWidget()
147 	{
148 		auto __p = gtk_search_entry_get_key_capture_widget(gtkSearchEntry);
149 
150 		if(__p is null)
151 		{
152 			return null;
153 		}
154 
155 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
156 	}
157 
158 	/**
159 	 * Sets @widget as the widget that @entry will capture key
160 	 * events from.
161 	 *
162 	 * Key events are consumed by the search entry to start or
163 	 * continue a search.
164 	 *
165 	 * If the entry is part of a `GtkSearchBar`, it is preferable
166 	 * to call [method@Gtk.SearchBar.set_key_capture_widget] instead,
167 	 * which will reveal the entry in addition to triggering the
168 	 * search entry.
169 	 *
170 	 * Note that despite the name of this function, the events
171 	 * are only 'captured' in the bubble phase, which means that
172 	 * editable child widgets of @widget will receive text input
173 	 * before it gets captured. If that is not desired, you can
174 	 * capture and forward the events yourself with
175 	 * [method@Gtk.EventControllerKey.forward].
176 	 *
177 	 * Params:
178 	 *     widget = a #GtkWidget
179 	 */
180 	public void setKeyCaptureWidget(Widget widget)
181 	{
182 		gtk_search_entry_set_key_capture_widget(gtkSearchEntry, (widget is null) ? null : widget.getWidgetStruct());
183 	}
184 
185 	/**
186 	 * Emitted when the entry is activated.
187 	 *
188 	 * The keybindings for this signal are all forms of the Enter key.
189 	 */
190 	gulong addOnActivate(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
191 	{
192 		return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED);
193 	}
194 
195 	/**
196 	 * Emitted when the user initiates a move to the next match
197 	 * for the current search string.
198 	 *
199 	 * This is a [keybinding signal](class.SignalAction.html).
200 	 *
201 	 * Applications should connect to it, to implement moving
202 	 * between matches.
203 	 *
204 	 * The default bindings for this signal is Ctrl-g.
205 	 */
206 	gulong addOnNextMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
207 	{
208 		return Signals.connect(this, "next-match", dlg, connectFlags ^ ConnectFlags.SWAPPED);
209 	}
210 
211 	/**
212 	 * Emitted when the user initiates a move to the previous match
213 	 * for the current search string.
214 	 *
215 	 * This is a [keybinding signal](class.SignalAction.html).
216 	 *
217 	 * Applications should connect to it, to implement moving
218 	 * between matches.
219 	 *
220 	 * The default bindings for this signal is Ctrl-Shift-g.
221 	 */
222 	gulong addOnPreviousMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
223 	{
224 		return Signals.connect(this, "previous-match", dlg, connectFlags ^ ConnectFlags.SWAPPED);
225 	}
226 
227 	/**
228 	 * Emitted with a short delay of 150 milliseconds after the
229 	 * last change to the entry text.
230 	 */
231 	gulong addOnSearchChanged(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
232 	{
233 		return Signals.connect(this, "search-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
234 	}
235 
236 	/**
237 	 * Emitted when the user initiated a search on the entry.
238 	 */
239 	gulong addOnSearchStarted(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
240 	{
241 		return Signals.connect(this, "search-started", dlg, connectFlags ^ ConnectFlags.SWAPPED);
242 	}
243 
244 	/**
245 	 * Emitted when the user stops a search via keyboard input.
246 	 *
247 	 * This is a [keybinding signal](class.SignalAction.html).
248 	 *
249 	 * Applications should connect to it, to implement hiding
250 	 * the search entry in this case.
251 	 *
252 	 * The default bindings for this signal is Escape.
253 	 */
254 	gulong addOnStopSearch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
255 	{
256 		return Signals.connect(this, "stop-search", dlg, connectFlags ^ ConnectFlags.SWAPPED);
257 	}
258 }