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