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