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