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