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