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