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 private import gtk.c.functions; 34 public import gtk.c.types; 35 public import gtkc.gtktypes; 36 private import std.algorithm; 37 38 39 /** 40 * #GtkSearchEntry is a subclass of #GtkEntry that has been 41 * tailored for use as a search entry. 42 * 43 * It will show an inactive symbolic “find” icon when the search 44 * entry is empty, and a symbolic “clear” icon when there is text. 45 * Clicking on the “clear” icon will empty the search entry. 46 * 47 * Note that the search/clear icon is shown using a secondary 48 * icon, and thus does not work if you are using the secondary 49 * icon position for some other purpose. 50 * 51 * To make filtering appear more reactive, it is a good idea to 52 * not react to every change in the entry text immediately, but 53 * only after a short delay. To support this, #GtkSearchEntry 54 * emits the #GtkSearchEntry::search-changed signal which can 55 * be used instead of the #GtkEditable::changed signal. 56 * 57 * The #GtkSearchEntry::previous-match, #GtkSearchEntry::next-match 58 * and #GtkSearchEntry::stop-search signals can be used to implement 59 * moving between search results and ending the search. 60 * 61 * Often, GtkSearchEntry will be fed events by means of being 62 * placed inside a #GtkSearchBar. If that is not the case, 63 * you can use gtk_search_entry_handle_event() to pass events. 64 */ 65 public class SearchEntry : Entry 66 { 67 /** the main Gtk struct */ 68 protected GtkSearchEntry* gtkSearchEntry; 69 70 /** Get the main Gtk struct */ 71 public GtkSearchEntry* getSearchEntryStruct(bool transferOwnership = false) 72 { 73 if (transferOwnership) 74 ownedRef = false; 75 return gtkSearchEntry; 76 } 77 78 /** the main Gtk struct as a void* */ 79 protected override void* getStruct() 80 { 81 return cast(void*)gtkSearchEntry; 82 } 83 84 protected override void setStruct(GObject* obj) 85 { 86 gtkSearchEntry = cast(GtkSearchEntry*)obj; 87 super.setStruct(obj); 88 } 89 90 /** 91 * Sets our main struct and passes it to the parent class. 92 */ 93 public this (GtkSearchEntry* gtkSearchEntry, bool ownedRef = false) 94 { 95 this.gtkSearchEntry = gtkSearchEntry; 96 super(cast(GtkEntry*)gtkSearchEntry, ownedRef); 97 } 98 99 100 /** */ 101 public static GType getType() 102 { 103 return gtk_search_entry_get_type(); 104 } 105 106 /** 107 * Creates a #GtkSearchEntry, with a find icon when the search field is 108 * empty, and a clear icon when it isn't. 109 * 110 * Returns: a new #GtkSearchEntry 111 * 112 * Since: 3.6 113 * 114 * Throws: ConstructionException GTK+ fails to create the object. 115 */ 116 public this() 117 { 118 auto p = gtk_search_entry_new(); 119 120 if(p is null) 121 { 122 throw new ConstructionException("null returned by new"); 123 } 124 125 this(cast(GtkSearchEntry*) p); 126 } 127 128 /** 129 * This function should be called when the top-level window 130 * which contains the search entry received a key event. If 131 * the entry is part of a #GtkSearchBar, it is preferable 132 * to call gtk_search_bar_handle_event() instead, which will 133 * reveal the entry in addition to passing the event to this 134 * function. 135 * 136 * If the key event is handled by the search entry and starts 137 * or continues a search, %GDK_EVENT_STOP will be returned. 138 * The caller should ensure that the entry is shown in this 139 * case, and not propagate the event further. 140 * 141 * Params: 142 * event = a key event 143 * 144 * Returns: %GDK_EVENT_STOP if the key press event resulted 145 * in a search beginning or continuing, %GDK_EVENT_PROPAGATE 146 * otherwise. 147 * 148 * Since: 3.16 149 */ 150 public bool handleEvent(Event event) 151 { 152 return gtk_search_entry_handle_event(gtkSearchEntry, (event is null) ? null : event.getEventStruct()) != 0; 153 } 154 155 protected class OnNextMatchDelegateWrapper 156 { 157 void delegate(SearchEntry) dlg; 158 gulong handlerId; 159 160 this(void delegate(SearchEntry) dlg) 161 { 162 this.dlg = dlg; 163 onNextMatchListeners ~= this; 164 } 165 166 void remove(OnNextMatchDelegateWrapper source) 167 { 168 foreach(index, wrapper; onNextMatchListeners) 169 { 170 if (wrapper.handlerId == source.handlerId) 171 { 172 onNextMatchListeners[index] = null; 173 onNextMatchListeners = std.algorithm.remove(onNextMatchListeners, index); 174 break; 175 } 176 } 177 } 178 } 179 OnNextMatchDelegateWrapper[] onNextMatchListeners; 180 181 /** 182 * The ::next-match signal is a [keybinding signal][GtkBindingSignal] 183 * which gets emitted when the user initiates a move to the next match 184 * for the current search string. 185 * 186 * Applications should connect to it, to implement moving between 187 * matches. 188 * 189 * The default bindings for this signal is Ctrl-g. 190 * 191 * Since: 3.16 192 */ 193 gulong addOnNextMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 194 { 195 auto wrapper = new OnNextMatchDelegateWrapper(dlg); 196 wrapper.handlerId = Signals.connectData( 197 this, 198 "next-match", 199 cast(GCallback)&callBackNextMatch, 200 cast(void*)wrapper, 201 cast(GClosureNotify)&callBackNextMatchDestroy, 202 connectFlags); 203 return wrapper.handlerId; 204 } 205 206 extern(C) static void callBackNextMatch(GtkSearchEntry* searchentryStruct, OnNextMatchDelegateWrapper wrapper) 207 { 208 wrapper.dlg(wrapper.outer); 209 } 210 211 extern(C) static void callBackNextMatchDestroy(OnNextMatchDelegateWrapper wrapper, GClosure* closure) 212 { 213 wrapper.remove(wrapper); 214 } 215 216 protected class OnPreviousMatchDelegateWrapper 217 { 218 void delegate(SearchEntry) dlg; 219 gulong handlerId; 220 221 this(void delegate(SearchEntry) dlg) 222 { 223 this.dlg = dlg; 224 onPreviousMatchListeners ~= this; 225 } 226 227 void remove(OnPreviousMatchDelegateWrapper source) 228 { 229 foreach(index, wrapper; onPreviousMatchListeners) 230 { 231 if (wrapper.handlerId == source.handlerId) 232 { 233 onPreviousMatchListeners[index] = null; 234 onPreviousMatchListeners = std.algorithm.remove(onPreviousMatchListeners, index); 235 break; 236 } 237 } 238 } 239 } 240 OnPreviousMatchDelegateWrapper[] onPreviousMatchListeners; 241 242 /** 243 * The ::previous-match signal is a [keybinding signal][GtkBindingSignal] 244 * which gets emitted when the user initiates a move to the previous match 245 * for the current search string. 246 * 247 * Applications should connect to it, to implement moving between 248 * matches. 249 * 250 * The default bindings for this signal is Ctrl-Shift-g. 251 * 252 * Since: 3.16 253 */ 254 gulong addOnPreviousMatch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 255 { 256 auto wrapper = new OnPreviousMatchDelegateWrapper(dlg); 257 wrapper.handlerId = Signals.connectData( 258 this, 259 "previous-match", 260 cast(GCallback)&callBackPreviousMatch, 261 cast(void*)wrapper, 262 cast(GClosureNotify)&callBackPreviousMatchDestroy, 263 connectFlags); 264 return wrapper.handlerId; 265 } 266 267 extern(C) static void callBackPreviousMatch(GtkSearchEntry* searchentryStruct, OnPreviousMatchDelegateWrapper wrapper) 268 { 269 wrapper.dlg(wrapper.outer); 270 } 271 272 extern(C) static void callBackPreviousMatchDestroy(OnPreviousMatchDelegateWrapper wrapper, GClosure* closure) 273 { 274 wrapper.remove(wrapper); 275 } 276 277 protected class OnSearchChangedDelegateWrapper 278 { 279 void delegate(SearchEntry) dlg; 280 gulong handlerId; 281 282 this(void delegate(SearchEntry) dlg) 283 { 284 this.dlg = dlg; 285 onSearchChangedListeners ~= this; 286 } 287 288 void remove(OnSearchChangedDelegateWrapper source) 289 { 290 foreach(index, wrapper; onSearchChangedListeners) 291 { 292 if (wrapper.handlerId == source.handlerId) 293 { 294 onSearchChangedListeners[index] = null; 295 onSearchChangedListeners = std.algorithm.remove(onSearchChangedListeners, index); 296 break; 297 } 298 } 299 } 300 } 301 OnSearchChangedDelegateWrapper[] onSearchChangedListeners; 302 303 /** 304 * The #GtkSearchEntry::search-changed signal is emitted with a short 305 * delay of 150 milliseconds after the last change to the entry text. 306 * 307 * Since: 3.10 308 */ 309 gulong addOnSearchChanged(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 310 { 311 auto wrapper = new OnSearchChangedDelegateWrapper(dlg); 312 wrapper.handlerId = Signals.connectData( 313 this, 314 "search-changed", 315 cast(GCallback)&callBackSearchChanged, 316 cast(void*)wrapper, 317 cast(GClosureNotify)&callBackSearchChangedDestroy, 318 connectFlags); 319 return wrapper.handlerId; 320 } 321 322 extern(C) static void callBackSearchChanged(GtkSearchEntry* searchentryStruct, OnSearchChangedDelegateWrapper wrapper) 323 { 324 wrapper.dlg(wrapper.outer); 325 } 326 327 extern(C) static void callBackSearchChangedDestroy(OnSearchChangedDelegateWrapper wrapper, GClosure* closure) 328 { 329 wrapper.remove(wrapper); 330 } 331 332 protected class OnStopSearchDelegateWrapper 333 { 334 void delegate(SearchEntry) dlg; 335 gulong handlerId; 336 337 this(void delegate(SearchEntry) dlg) 338 { 339 this.dlg = dlg; 340 onStopSearchListeners ~= this; 341 } 342 343 void remove(OnStopSearchDelegateWrapper source) 344 { 345 foreach(index, wrapper; onStopSearchListeners) 346 { 347 if (wrapper.handlerId == source.handlerId) 348 { 349 onStopSearchListeners[index] = null; 350 onStopSearchListeners = std.algorithm.remove(onStopSearchListeners, index); 351 break; 352 } 353 } 354 } 355 } 356 OnStopSearchDelegateWrapper[] onStopSearchListeners; 357 358 /** 359 * The ::stop-search signal is a [keybinding signal][GtkBindingSignal] 360 * which gets emitted when the user stops a search via keyboard input. 361 * 362 * Applications should connect to it, to implement hiding the search 363 * entry in this case. 364 * 365 * The default bindings for this signal is Escape. 366 * 367 * Since: 3.16 368 */ 369 gulong addOnStopSearch(void delegate(SearchEntry) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 370 { 371 auto wrapper = new OnStopSearchDelegateWrapper(dlg); 372 wrapper.handlerId = Signals.connectData( 373 this, 374 "stop-search", 375 cast(GCallback)&callBackStopSearch, 376 cast(void*)wrapper, 377 cast(GClosureNotify)&callBackStopSearchDestroy, 378 connectFlags); 379 return wrapper.handlerId; 380 } 381 382 extern(C) static void callBackStopSearch(GtkSearchEntry* searchentryStruct, OnStopSearchDelegateWrapper wrapper) 383 { 384 wrapper.dlg(wrapper.outer); 385 } 386 387 extern(C) static void callBackStopSearchDestroy(OnStopSearchDelegateWrapper wrapper, GClosure* closure) 388 { 389 wrapper.remove(wrapper); 390 } 391 }