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.SearchEntry; 26 27 private import gdk.Event; 28 private import glib.ConstructionException; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Entry; 32 private import gtk.Widget; 33 public import gtkc.gdktypes; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 37 38 /** 39 * #GtkSearchEntry is a subclass of #GtkEntry that has been 40 * tailored for use as a search entry. 41 * 42 * It will show an inactive symbolic “find” icon when the search 43 * entry is empty, and a symbolic “clear” icon when there is text. 44 * Clicking on the “clear” icon will empty the search entry. 45 * 46 * Note that the search/clear icon is shown using a secondary 47 * icon, and thus does not work if you are using the secondary 48 * icon position for some other purpose. 49 * 50 * To make filtering appear more reactive, it is a good idea to 51 * not react to every change in the entry text immediately, but 52 * only after a short delay. To support this, #GtkSearchEntry 53 * emits the #GtkSearchEntry::search-changed signal which can 54 * be used instead of the #GtkEditable::changed signal. 55 * 56 * The #GtkSearchEntry::previous-match, #GtkSearchEntry::next-match 57 * and #GtkSearchEntry::stop-search signals can be uesd to implement 58 * moving between search results and ending the search. 59 * 60 * Often, GtkSearchEntry will be fed events by means of being 61 * placed inside a #GtkSearchEntry. If that is not the case, 62 * you can use gtk_search_entry_handle_event() to pass events. 63 */ 64 public class SearchEntry : Entry 65 { 66 /** the main Gtk struct */ 67 protected GtkSearchEntry* gtkSearchEntry; 68 69 /** Get the main Gtk struct */ 70 public GtkSearchEntry* getSearchEntryStruct() 71 { 72 return gtkSearchEntry; 73 } 74 75 /** the main Gtk struct as a void* */ 76 protected override void* getStruct() 77 { 78 return cast(void*)gtkSearchEntry; 79 } 80 81 protected override void setStruct(GObject* obj) 82 { 83 gtkSearchEntry = cast(GtkSearchEntry*)obj; 84 super.setStruct(obj); 85 } 86 87 /** 88 * Sets our main struct and passes it to the parent class. 89 */ 90 public this (GtkSearchEntry* gtkSearchEntry, bool ownedRef = false) 91 { 92 this.gtkSearchEntry = gtkSearchEntry; 93 super(cast(GtkEntry*)gtkSearchEntry, ownedRef); 94 } 95 96 /** 97 */ 98 99 public static GType getType() 100 { 101 return gtk_search_entry_get_type(); 102 } 103 104 /** 105 * Creates a #GtkSearchEntry, with a find icon when the search field is 106 * empty, and a clear icon when it isn't. 107 * 108 * Return: a new #GtkSearchEntry 109 * 110 * Since: 3.6 111 * 112 * Throws: ConstructionException GTK+ fails to create the object. 113 */ 114 public this() 115 { 116 auto p = gtk_search_entry_new(); 117 118 if(p is null) 119 { 120 throw new ConstructionException("null returned by new"); 121 } 122 123 this(cast(GtkSearchEntry*) p); 124 } 125 126 /** 127 * This function should be called when the top-level window 128 * which contains the search entry received a key event. If 129 * the entry is part of a #GtkSearchBar, it is preferable 130 * to call gtk_search_bar_handle_event() instead, which will 131 * reveal the entry in addition to passing the event to this 132 * function. 133 * 134 * If the key event is handled by the search entry and starts 135 * or continues a search, %GDK_EVENT_STOP will be returned. 136 * The caller should ensure that the entry is shown in this 137 * case, and not propagate the event further. 138 * 139 * Params: 140 * event = a key event 141 * 142 * Return: %GDK_EVENT_STOP if the key press event resulted 143 * in a search beginning or continuing, %GDK_EVENT_PROPAGATE 144 * otherwise. 145 * 146 * Since: 3.16 147 */ 148 public bool handleEvent(Event event) 149 { 150 return gtk_search_entry_handle_event(gtkSearchEntry, (event is null) ? null : event.getEventStruct()) != 0; 151 } 152 153 int[string] connectedSignals; 154 155 void delegate(SearchEntry)[] onNextMatchListeners; 156 /** 157 * The ::next-match signal is a [keybinding signal][GtkBindingSignal] 158 * which gets emitted when the user initiates a move to the next match 159 * for the current search string. 160 * 161 * Applications should connect to it, to implement moving between 162 * matches. 163 * 164 * The default bindings for this signal is Ctrl-g. 165 * 166 * Since: 3.16 167 */ 168 void addOnNextMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 169 { 170 if ( "next-match" !in connectedSignals ) 171 { 172 Signals.connectData( 173 this, 174 "next-match", 175 cast(GCallback)&callBackNextMatch, 176 cast(void*)this, 177 null, 178 connectFlags); 179 connectedSignals["next-match"] = 1; 180 } 181 onNextMatchListeners ~= dlg; 182 } 183 extern(C) static void callBackNextMatch(GtkSearchEntry* searchentryStruct, SearchEntry _searchentry) 184 { 185 foreach ( void delegate(SearchEntry) dlg; _searchentry.onNextMatchListeners ) 186 { 187 dlg(_searchentry); 188 } 189 } 190 191 void delegate(SearchEntry)[] onPreviousMatchListeners; 192 /** 193 * The ::previous-match signal is a [keybinding signal][GtkBindingSignal] 194 * which gets emitted when the user initiates a move to the previous match 195 * for the current search string. 196 * 197 * Applications should connect to it, to implement moving between 198 * matches. 199 * 200 * The default bindings for this signal is Ctrl-Shift-g. 201 * 202 * Since: 3.16 203 */ 204 void addOnPreviousMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 205 { 206 if ( "previous-match" !in connectedSignals ) 207 { 208 Signals.connectData( 209 this, 210 "previous-match", 211 cast(GCallback)&callBackPreviousMatch, 212 cast(void*)this, 213 null, 214 connectFlags); 215 connectedSignals["previous-match"] = 1; 216 } 217 onPreviousMatchListeners ~= dlg; 218 } 219 extern(C) static void callBackPreviousMatch(GtkSearchEntry* searchentryStruct, SearchEntry _searchentry) 220 { 221 foreach ( void delegate(SearchEntry) dlg; _searchentry.onPreviousMatchListeners ) 222 { 223 dlg(_searchentry); 224 } 225 } 226 227 void delegate(SearchEntry)[] onSearchChangedListeners; 228 /** 229 * The #GtkSearchEntry::search-changed signal is emitted with a short 230 * delay of 150 milliseconds after the last change to the entry text. 231 * 232 * Since: 3.10 233 */ 234 void addOnSearchChanged(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 235 { 236 if ( "search-changed" !in connectedSignals ) 237 { 238 Signals.connectData( 239 this, 240 "search-changed", 241 cast(GCallback)&callBackSearchChanged, 242 cast(void*)this, 243 null, 244 connectFlags); 245 connectedSignals["search-changed"] = 1; 246 } 247 onSearchChangedListeners ~= dlg; 248 } 249 extern(C) static void callBackSearchChanged(GtkSearchEntry* searchentryStruct, SearchEntry _searchentry) 250 { 251 foreach ( void delegate(SearchEntry) dlg; _searchentry.onSearchChangedListeners ) 252 { 253 dlg(_searchentry); 254 } 255 } 256 257 void delegate(SearchEntry)[] onStopSearchListeners; 258 /** 259 * The ::stop-search signal is a [keybinding signal][GtkBindingSignal] 260 * which gets emitted when the user stops a search via keyboard input. 261 * 262 * Applications should connect to it, to implement hiding the search 263 * entry in this case. 264 * 265 * The default bindings for this signal is Escape. 266 * 267 * Since: 3.16 268 */ 269 void addOnStopSearch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 270 { 271 if ( "stop-search" !in connectedSignals ) 272 { 273 Signals.connectData( 274 this, 275 "stop-search", 276 cast(GCallback)&callBackStopSearch, 277 cast(void*)this, 278 null, 279 connectFlags); 280 connectedSignals["stop-search"] = 1; 281 } 282 onStopSearchListeners ~= dlg; 283 } 284 extern(C) static void callBackStopSearch(GtkSearchEntry* searchentryStruct, SearchEntry _searchentry) 285 { 286 foreach ( void delegate(SearchEntry) dlg; _searchentry.onStopSearchListeners ) 287 { 288 dlg(_searchentry); 289 } 290 } 291 }