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