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