1 module webkit2.FindController; 2 3 private import glib.Str; 4 private import gobject.ObjectG; 5 private import gobject.Signals; 6 private import std.algorithm; 7 private import webkit2.WebView; 8 private import webkit2.c.functions; 9 public import webkit2.c.types; 10 11 12 /** 13 * A #WebKitFindController is used to search text in a #WebKitWebView. You 14 * can get a #WebKitWebView<!-- -->'s #WebKitFindController with 15 * webkit_web_view_get_find_controller(), and later use it to search 16 * for text using webkit_find_controller_search(), or get the 17 * number of matches using webkit_find_controller_count_matches(). The 18 * operations are asynchronous and trigger signals when ready, such as 19 * #WebKitFindController::found-text, 20 * #WebKitFindController::failed-to-find-text or 21 * #WebKitFindController::counted-matches<!-- -->. 22 */ 23 public class FindController : ObjectG 24 { 25 /** the main Gtk struct */ 26 protected WebKitFindController* webKitFindController; 27 28 /** Get the main Gtk struct */ 29 public WebKitFindController* getFindControllerStruct(bool transferOwnership = false) 30 { 31 if (transferOwnership) 32 ownedRef = false; 33 return webKitFindController; 34 } 35 36 /** the main Gtk struct as a void* */ 37 protected override void* getStruct() 38 { 39 return cast(void*)webKitFindController; 40 } 41 42 /** 43 * Sets our main struct and passes it to the parent class. 44 */ 45 public this (WebKitFindController* webKitFindController, bool ownedRef = false) 46 { 47 this.webKitFindController = webKitFindController; 48 super(cast(GObject*)webKitFindController, ownedRef); 49 } 50 51 52 /** */ 53 public static GType getType() 54 { 55 return webkit_find_controller_get_type(); 56 } 57 58 /** 59 * Counts the number of matches for @search_text found in the 60 * #WebKitWebView with the provided @find_options. The number of 61 * matches will be provided by the 62 * #WebKitFindController::counted-matches signal. 63 * 64 * Params: 65 * searchText = the text to look for 66 * findOptions = a bitmask with the #WebKitFindOptions used in the search 67 * maxMatchCount = the maximum number of matches allowed in the search 68 */ 69 public void countMatches(string searchText, uint findOptions, uint maxMatchCount) 70 { 71 webkit_find_controller_count_matches(webKitFindController, Str.toStringz(searchText), findOptions, maxMatchCount); 72 } 73 74 /** 75 * Gets the maximum number of matches to report during a text 76 * lookup. This number is passed as the last argument of 77 * webkit_find_controller_search() or 78 * webkit_find_controller_count_matches(). 79 * 80 * Returns: the maximum number of matches to report. 81 */ 82 public uint getMaxMatchCount() 83 { 84 return webkit_find_controller_get_max_match_count(webKitFindController); 85 } 86 87 /** 88 * Gets a bitmask containing the #WebKitFindOptions associated with 89 * the current search. 90 * 91 * Returns: a bitmask containing the #WebKitFindOptions associated 92 * with the current search. 93 */ 94 public uint getOptions() 95 { 96 return webkit_find_controller_get_options(webKitFindController); 97 } 98 99 /** 100 * Gets the text that @find_controller is currently searching 101 * for. This text is passed to either 102 * webkit_find_controller_search() or 103 * webkit_find_controller_count_matches(). 104 * 105 * Returns: the text to look for in the #WebKitWebView. 106 */ 107 public string getSearchText() 108 { 109 return Str.toString(webkit_find_controller_get_search_text(webKitFindController)); 110 } 111 112 /** 113 * Gets the #WebKitWebView this find controller is associated to. Do 114 * not dereference the returned instance as it belongs to the 115 * #WebKitFindController. 116 * 117 * Returns: the #WebKitWebView. 118 */ 119 public WebView getWebView() 120 { 121 auto __p = webkit_find_controller_get_web_view(webKitFindController); 122 123 if(__p is null) 124 { 125 return null; 126 } 127 128 return ObjectG.getDObject!(WebView)(cast(WebKitWebView*) __p); 129 } 130 131 /** 132 * Looks for @search_text in the #WebKitWebView associated with 133 * @find_controller since the beginning of the document highlighting 134 * up to @max_match_count matches. The outcome of the search will be 135 * asynchronously provided by the #WebKitFindController::found-text 136 * and #WebKitFindController::failed-to-find-text signals. 137 * 138 * To look for the next or previous occurrences of the same text 139 * with the same find options use webkit_find_controller_search_next() 140 * and/or webkit_find_controller_search_previous(). The 141 * #WebKitFindController will use the same text and options for the 142 * following searches unless they are modified by another call to this 143 * method. 144 * 145 * Note that if the number of matches is higher than @max_match_count 146 * then #WebKitFindController::found-text will report %G_MAXUINT matches 147 * instead of the actual number. 148 * 149 * Callers should call webkit_find_controller_search_finish() to 150 * finish the current search operation. 151 * 152 * Params: 153 * searchText = the text to look for 154 * findOptions = a bitmask with the #WebKitFindOptions used in the search 155 * maxMatchCount = the maximum number of matches allowed in the search 156 */ 157 public void search(string searchText, uint findOptions, uint maxMatchCount) 158 { 159 webkit_find_controller_search(webKitFindController, Str.toStringz(searchText), findOptions, maxMatchCount); 160 } 161 162 /** 163 * Finishes a find operation started by 164 * webkit_find_controller_search(). It will basically unhighlight 165 * every text match found. 166 * 167 * This method will be typically called when the search UI is 168 * closed/hidden by the client application. 169 */ 170 public void searchFinish() 171 { 172 webkit_find_controller_search_finish(webKitFindController); 173 } 174 175 /** 176 * Looks for the next occurrence of the search text. 177 * 178 * Calling this method before webkit_find_controller_search() or 179 * webkit_find_controller_count_matches() is a programming error. 180 */ 181 public void searchNext() 182 { 183 webkit_find_controller_search_next(webKitFindController); 184 } 185 186 /** 187 * Looks for the previous occurrence of the search text. 188 * 189 * Calling this method before webkit_find_controller_search() or 190 * webkit_find_controller_count_matches() is a programming error. 191 */ 192 public void searchPrevious() 193 { 194 webkit_find_controller_search_previous(webKitFindController); 195 } 196 197 /** 198 * This signal is emitted when the #WebKitFindController has 199 * counted the number of matches for a given text after a call 200 * to webkit_find_controller_count_matches(). 201 * 202 * Params: 203 * matchCount = the number of matches of the search text 204 */ 205 gulong addOnCountedMatches(void delegate(uint, FindController) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 206 { 207 return Signals.connect(this, "counted-matches", dlg, connectFlags ^ ConnectFlags.SWAPPED); 208 } 209 210 /** 211 * This signal is emitted when a search operation does not find 212 * any result for the given text. It will be issued if the text 213 * is not found asynchronously after a call to 214 * webkit_find_controller_search(), webkit_find_controller_search_next() 215 * or webkit_find_controller_search_previous(). 216 */ 217 gulong addOnFailedToFindText(void delegate(FindController) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 218 { 219 return Signals.connect(this, "failed-to-find-text", dlg, connectFlags ^ ConnectFlags.SWAPPED); 220 } 221 222 /** 223 * This signal is emitted when a given text is found in the web 224 * page text. It will be issued if the text is found 225 * asynchronously after a call to webkit_find_controller_search(), 226 * webkit_find_controller_search_next() or 227 * webkit_find_controller_search_previous(). 228 * 229 * Params: 230 * matchCount = the number of matches found of the search text 231 */ 232 gulong addOnFoundText(void delegate(uint, FindController) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 233 { 234 return Signals.connect(this, "found-text", dlg, connectFlags ^ ConnectFlags.SWAPPED); 235 } 236 }