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 glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gtk.EditableIF; 30 private import gtk.Widget; 31 private import gtk.c.functions; 32 public import gtk.c.types; 33 34 35 /** 36 * `GtkSearchBar` is a container made to have a search entry. 37 * 38 * ![An example GtkSearchBar](search-bar.png) 39 * 40 * It can also contain additional widgets, such as drop-down menus, 41 * or buttons. The search bar would appear when a search is started 42 * through typing on the keyboard, or the application’s search mode 43 * is toggled on. 44 * 45 * For keyboard presses to start a search, the search bar must be told 46 * of a widget to capture key events from through 47 * [method@Gtk.SearchBar.set_key_capture_widget]. This widget will 48 * typically be the top-level window, or a parent container of the 49 * search bar. Common shortcuts such as Ctrl+F should be handled as an 50 * application action, or through the menu items. 51 * 52 * You will also need to tell the search bar about which entry you 53 * are using as your search entry using [method@Gtk.SearchBar.connect_entry]. 54 * 55 * ## Creating a search bar 56 * 57 * The following example shows you how to create a more complex search 58 * entry. 59 * 60 * [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/master/examples/search-bar.c) 61 * 62 * # CSS nodes 63 * 64 * ``` 65 * searchbar 66 * ╰── revealer 67 * ╰── box 68 * ├── [child] 69 * ╰── [button.close] 70 * ``` 71 * 72 * `GtkSearchBar` has a main CSS node with name searchbar. It has a child 73 * node with name revealer that contains a node with name box. The box node 74 * contains both the CSS node of the child widget as well as an optional button 75 * node which gets the .close style class applied. 76 * 77 * # Accessibility 78 * 79 * `GtkSearchBar` uses the %GTK_ACCESSIBLE_ROLE_SEARCH role. 80 */ 81 public class SearchBar : Widget 82 { 83 /** the main Gtk struct */ 84 protected GtkSearchBar* gtkSearchBar; 85 86 /** Get the main Gtk struct */ 87 public GtkSearchBar* getSearchBarStruct(bool transferOwnership = false) 88 { 89 if (transferOwnership) 90 ownedRef = false; 91 return gtkSearchBar; 92 } 93 94 /** the main Gtk struct as a void* */ 95 protected override void* getStruct() 96 { 97 return cast(void*)gtkSearchBar; 98 } 99 100 /** 101 * Sets our main struct and passes it to the parent class. 102 */ 103 public this (GtkSearchBar* gtkSearchBar, bool ownedRef = false) 104 { 105 this.gtkSearchBar = gtkSearchBar; 106 super(cast(GtkWidget*)gtkSearchBar, ownedRef); 107 } 108 109 110 /** */ 111 public static GType getType() 112 { 113 return gtk_search_bar_get_type(); 114 } 115 116 /** 117 * Creates a `GtkSearchBar`. 118 * 119 * You will need to tell it about which widget is going to be your text 120 * entry using [method@Gtk.SearchBar.connect_entry]. 121 * 122 * Returns: a new `GtkSearchBar` 123 * 124 * Throws: ConstructionException GTK+ fails to create the object. 125 */ 126 public this() 127 { 128 auto __p = gtk_search_bar_new(); 129 130 if(__p is null) 131 { 132 throw new ConstructionException("null returned by new"); 133 } 134 135 this(cast(GtkSearchBar*) __p); 136 } 137 138 /** 139 * Connects the `GtkEditable widget passed as the one to be used in 140 * this search bar. 141 * 142 * The entry should be a descendant of the search bar. Calling this 143 * function manually is only required if the entry isn’t the direct 144 * child of the search bar (as in our main example). 145 * 146 * Params: 147 * entry = a `GtkEditable` 148 */ 149 public void connectEntry(EditableIF entry) 150 { 151 gtk_search_bar_connect_entry(gtkSearchBar, (entry is null) ? null : entry.getEditableStruct()); 152 } 153 154 /** 155 * Gets the child widget of @bar. 156 * 157 * Returns: the child widget of @bar 158 */ 159 public Widget getChild() 160 { 161 auto __p = gtk_search_bar_get_child(gtkSearchBar); 162 163 if(__p is null) 164 { 165 return null; 166 } 167 168 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 169 } 170 171 /** 172 * Gets the widget that @bar is capturing key events from. 173 * 174 * Returns: The key capture widget. 175 */ 176 public Widget getKeyCaptureWidget() 177 { 178 auto __p = gtk_search_bar_get_key_capture_widget(gtkSearchBar); 179 180 if(__p is null) 181 { 182 return null; 183 } 184 185 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 186 } 187 188 /** 189 * Returns whether the search mode is on or off. 190 * 191 * Returns: whether search mode is toggled on 192 */ 193 public bool getSearchMode() 194 { 195 return gtk_search_bar_get_search_mode(gtkSearchBar) != 0; 196 } 197 198 /** 199 * Returns whether the close button is shown. 200 * 201 * Returns: whether the close button is shown 202 */ 203 public bool getShowCloseButton() 204 { 205 return gtk_search_bar_get_show_close_button(gtkSearchBar) != 0; 206 } 207 208 /** 209 * Sets the child widget of @bar. 210 * 211 * Params: 212 * child = the child widget 213 */ 214 public void setChild(Widget child) 215 { 216 gtk_search_bar_set_child(gtkSearchBar, (child is null) ? null : child.getWidgetStruct()); 217 } 218 219 /** 220 * Sets @widget as the widget that @bar will capture key events 221 * from. 222 * 223 * If key events are handled by the search bar, the bar will 224 * be shown, and the entry populated with the entered text. 225 * 226 * Note that despite the name of this function, the events 227 * are only 'captured' in the bubble phase, which means that 228 * editable child widgets of @widget will receive text input 229 * before it gets captured. If that is not desired, you can 230 * capture and forward the events yourself with 231 * [method@Gtk.EventControllerKey.forward]. 232 * 233 * Params: 234 * widget = a `GtkWidget` 235 */ 236 public void setKeyCaptureWidget(Widget widget) 237 { 238 gtk_search_bar_set_key_capture_widget(gtkSearchBar, (widget is null) ? null : widget.getWidgetStruct()); 239 } 240 241 /** 242 * Switches the search mode on or off. 243 * 244 * Params: 245 * searchMode = the new state of the search mode 246 */ 247 public void setSearchMode(bool searchMode) 248 { 249 gtk_search_bar_set_search_mode(gtkSearchBar, searchMode); 250 } 251 252 /** 253 * Shows or hides the close button. 254 * 255 * Applications that already have a “search” toggle button should not 256 * show a close button in their search bar, as it duplicates the role 257 * of the toggle button. 258 * 259 * Params: 260 * visible = whether the close button will be shown or not 261 */ 262 public void setShowCloseButton(bool visible) 263 { 264 gtk_search_bar_set_show_close_button(gtkSearchBar, visible); 265 } 266 }