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 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 * Return: 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 * Return: 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 * Return: 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 * g_signal_connect (window, 187 * "key-press-event", 188 * G_CALLBACK (on_key_press_event), 189 * search_bar); 190 * ]| 191 * 192 * Params: 193 * event = a #GdkEvent containing key press events 194 * 195 * Return: %GDK_EVENT_STOP if the key press event resulted 196 * in text being entered in the search entry (and revealing 197 * the search bar if necessary), %GDK_EVENT_PROPAGATE otherwise. 198 * 199 * Since: 3.10 200 */ 201 public bool handleEvent(Event event) 202 { 203 return gtk_search_bar_handle_event(gtkSearchBar, (event is null) ? null : event.getEventStruct()) != 0; 204 } 205 206 /** 207 * Switches the search mode on or off. 208 * 209 * Params: 210 * searchMode = the new state of the search mode 211 * 212 * Since: 3.10 213 */ 214 public void setSearchMode(bool searchMode) 215 { 216 gtk_search_bar_set_search_mode(gtkSearchBar, searchMode); 217 } 218 219 /** 220 * Shows or hides the close button. Applications that 221 * already have a “search” toggle button should not show a close 222 * button in their search bar, as it duplicates the role of the 223 * toggle button. 224 * 225 * Params: 226 * visible = whether the close button will be shown or not 227 * 228 * Since: 3.10 229 */ 230 public void setShowCloseButton(bool visible) 231 { 232 gtk_search_bar_set_show_close_button(gtkSearchBar, visible); 233 } 234 }