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.SearchBar;
26 
27 private import gdk.Event;
28 private import glib.ConstructionException;
29 private import gobject.ObjectG;
30 private import gtk.Bin;
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 
37 
38 /**
39  * #GtkSearchBar is a container made to have a search entry (possibly
40  * with additional connex widgets, such as drop-down menus, or buttons)
41  * built-in. The search bar would appear when a search is started through
42  * typing on the keyboard, or the application’s search mode is toggled on.
43  * 
44  * For keyboard presses to start a search, events will need to be
45  * forwarded from the top-level window that contains the search bar.
46  * See gtk_search_bar_handle_event() for example code. Common shortcuts
47  * such as Ctrl+F should be handled as an application action, or through
48  * the menu items.
49  * 
50  * You will also need to tell the search bar about which entry you
51  * are using as your search entry using gtk_search_bar_connect_entry().
52  * The following example shows you how to create a more complex search
53  * entry.
54  * 
55  * # CSS nodes
56  * 
57  * GtkSearchBar has a single CSS node with name searchbar.
58  * 
59  * ## Creating a search bar
60  * 
61  * [A simple example](https://git.gnome.org/browse/gtk+/tree/examples/search-bar.c)
62  */
63 public class SearchBar : Bin
64 {
65 	/** the main Gtk struct */
66 	protected GtkSearchBar* gtkSearchBar;
67 
68 	/** Get the main Gtk struct */
69 	public GtkSearchBar* getSearchBarStruct(bool transferOwnership = false)
70 	{
71 		if (transferOwnership)
72 			ownedRef = false;
73 		return gtkSearchBar;
74 	}
75 
76 	/** the main Gtk struct as a void* */
77 	protected override void* getStruct()
78 	{
79 		return cast(void*)gtkSearchBar;
80 	}
81 
82 	protected override void setStruct(GObject* obj)
83 	{
84 		gtkSearchBar = cast(GtkSearchBar*)obj;
85 		super.setStruct(obj);
86 	}
87 
88 	/**
89 	 * Sets our main struct and passes it to the parent class.
90 	 */
91 	public this (GtkSearchBar* gtkSearchBar, bool ownedRef = false)
92 	{
93 		this.gtkSearchBar = gtkSearchBar;
94 		super(cast(GtkBin*)gtkSearchBar, ownedRef);
95 	}
96 
97 
98 	/** */
99 	public static GType getType()
100 	{
101 		return gtk_search_bar_get_type();
102 	}
103 
104 	/**
105 	 * Creates a #GtkSearchBar. You will need to tell it about
106 	 * which widget is going to be your text entry using
107 	 * gtk_search_bar_connect_entry().
108 	 *
109 	 * Returns: a new #GtkSearchBar
110 	 *
111 	 * Since: 3.10
112 	 *
113 	 * Throws: ConstructionException GTK+ fails to create the object.
114 	 */
115 	public this()
116 	{
117 		auto p = gtk_search_bar_new();
118 
119 		if(p is null)
120 		{
121 			throw new ConstructionException("null returned by new");
122 		}
123 
124 		this(cast(GtkSearchBar*) p);
125 	}
126 
127 	/**
128 	 * Connects the #GtkEntry widget passed as the one to be used in
129 	 * this search bar. The entry should be a descendant of the search bar.
130 	 * This is only required if the entry isn’t the direct child of the
131 	 * search bar (as in our main example).
132 	 *
133 	 * Params:
134 	 *     entry = a #GtkEntry
135 	 *
136 	 * Since: 3.10
137 	 */
138 	public void connectEntry(Entry entry)
139 	{
140 		gtk_search_bar_connect_entry(gtkSearchBar, (entry is null) ? null : entry.getEntryStruct());
141 	}
142 
143 	/**
144 	 * Returns whether the search mode is on or off.
145 	 *
146 	 * Returns: whether search mode is toggled on
147 	 *
148 	 * Since: 3.10
149 	 */
150 	public bool getSearchMode()
151 	{
152 		return gtk_search_bar_get_search_mode(gtkSearchBar) != 0;
153 	}
154 
155 	/**
156 	 * Returns whether the close button is shown.
157 	 *
158 	 * Returns: whether the close button is shown
159 	 *
160 	 * Since: 3.10
161 	 */
162 	public bool getShowCloseButton()
163 	{
164 		return gtk_search_bar_get_show_close_button(gtkSearchBar) != 0;
165 	}
166 
167 	/**
168 	 * This function should be called when the top-level
169 	 * window which contains the search bar received a key event.
170 	 *
171 	 * If the key event is handled by the search bar, the bar will
172 	 * be shown, the entry populated with the entered text and %GDK_EVENT_STOP
173 	 * will be returned. The caller should ensure that events are
174 	 * not propagated further.
175 	 *
176 	 * If no entry has been connected to the search bar, using
177 	 * gtk_search_bar_connect_entry(), this function will return
178 	 * immediately with a warning.
179 	 *
180 	 * ## Showing the search bar on key presses
181 	 *
182 	 * |[<!-- language="C" -->
183 	 * static gboolean
184 	 * on_key_press_event (GtkWidget *widget,
185 	 * GdkEvent  *event,
186 	 * gpointer   user_data)
187 	 * {
188 	 * GtkSearchBar *bar = GTK_SEARCH_BAR (user_data);
189 	 * return gtk_search_bar_handle_event (bar, event);
190 	 * }
191 	 *
192 	 * g_signal_connect (window,
193 	 * "key-press-event",
194 	 * G_CALLBACK (on_key_press_event),
195 	 * search_bar);
196 	 * ]|
197 	 *
198 	 * Params:
199 	 *     event = a #GdkEvent containing key press events
200 	 *
201 	 * Returns: %GDK_EVENT_STOP if the key press event resulted
202 	 *     in text being entered in the search entry (and revealing
203 	 *     the search bar if necessary), %GDK_EVENT_PROPAGATE otherwise.
204 	 *
205 	 * Since: 3.10
206 	 */
207 	public bool handleEvent(Event event)
208 	{
209 		return gtk_search_bar_handle_event(gtkSearchBar, (event is null) ? null : event.getEventStruct()) != 0;
210 	}
211 
212 	/**
213 	 * Switches the search mode on or off.
214 	 *
215 	 * Params:
216 	 *     searchMode = the new state of the search mode
217 	 *
218 	 * Since: 3.10
219 	 */
220 	public void setSearchMode(bool searchMode)
221 	{
222 		gtk_search_bar_set_search_mode(gtkSearchBar, searchMode);
223 	}
224 
225 	/**
226 	 * Shows or hides the close button. Applications that
227 	 * already have a “search” toggle button should not show a close
228 	 * button in their search bar, as it duplicates the role of the
229 	 * toggle button.
230 	 *
231 	 * Params:
232 	 *     visible = whether the close button will be shown or not
233 	 *
234 	 * Since: 3.10
235 	 */
236 	public void setShowCloseButton(bool visible)
237 	{
238 		gtk_search_bar_set_show_close_button(gtkSearchBar, visible);
239 	}
240 }