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 * Conversion parameters: 26 * inFile = GtkIMContext.html 27 * outPack = gtk 28 * outFile = IMContext 29 * strct = GtkIMContext 30 * realStrct= 31 * ctorStrct= 32 * clss = IMContext 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_im_context_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * - gdk.Window 48 * - pango.PgAttributeList 49 * structWrap: 50 * - GdkWindow* -> Window 51 * - PangoAttrList* -> PgAttributeList 52 * module aliases: 53 * local aliases: 54 * overrides: 55 */ 56 57 module gtk.IMContext; 58 59 public import gtkc.gtktypes; 60 61 private import gtkc.gtk; 62 private import glib.ConstructionException; 63 private import gobject.ObjectG; 64 65 private import gobject.Signals; 66 public import gtkc.gdktypes; 67 68 private import glib.Str; 69 private import gdk.Window; 70 private import pango.PgAttributeList; 71 72 73 74 private import gobject.ObjectG; 75 76 /** 77 * GtkIMContext defines the interface for GTK+ input methods. An input method 78 * is used by GTK+ text input widgets like GtkEntry to map from key events to 79 * Unicode character strings. 80 * 81 * The default input method can be set programmatically via the 82 * "gtk-im-module" GtkSettings property. Alternatively, you may set 83 * the GTK_IM_MODULE environment variable as documented in gtk-running. 84 * 85 * The GtkEntry "im-module" and GtkTextView "im-module" 86 * properties may also be used to set input methods for specific widget 87 * instances. For instance, a certain entry widget might be expected to contain 88 * certain characters which would be easier to input with a certain input 89 * method. 90 * 91 * An input method may consume multiple key events in sequence and finally 92 * output the composed result. This is called preediting, and an input method 93 * may provide feedback about this process by displaying the intermediate 94 * composition states as preedit text. For instance, the default GTK+ input 95 * method implements the input of arbitrary Unicode code points by holding down 96 * the Control and Shift keys and then typing "U" followed by the hexadecimal 97 * digits of the code point. When releasing the Control and Shift keys, 98 * preediting ends and the character is inserted as text. Ctrl+Shift+u20AC for 99 * example results in the € sign. 100 * 101 * Additional input methods can be made available for use by GTK+ widgets as 102 * loadable modules. An input method module is a small shared library which 103 * implements a subclass of GtkIMContext or GtkIMContextSimple and exports 104 * these four functions: 105 * 106 * $(DDOC_COMMENT example) 107 * 108 * This function should register the GType of the GtkIMContext subclass which 109 * implements the input method by means of g_type_module_register_type(). Note 110 * that g_type_register_static() cannot be used as the type needs to be 111 * registered dynamically. 112 * 113 * $(DDOC_COMMENT example) 114 * 115 * Here goes any cleanup code your input method might require on module unload. 116 * 117 * $(DDOC_COMMENT example) 118 * 119 * This function returns the list of input methods provided by the module. The 120 * example implementation above shows a common solution and simply returns a 121 * pointer to statically defined array of GtkIMContextInfo items for each 122 * provided input method. 123 * 124 * $(DDOC_COMMENT example) 125 * 126 * This function should return a pointer to a newly created instance of the 127 * GtkIMContext subclass identified by context_id. The context ID is the same 128 * as specified in the GtkIMContextInfo array returned by im_module_list(). 129 * 130 * After a new loadable input method module has been installed on the system, 131 * the configuration file gtk.immodules needs to be 132 * regenerated by gtk-query-immodules-3.0, 133 * in order for the new input method to become available to GTK+ applications. 134 */ 135 public class IMContext : ObjectG 136 { 137 138 /** the main Gtk struct */ 139 protected GtkIMContext* gtkIMContext; 140 141 142 public GtkIMContext* getIMContextStruct() 143 { 144 return gtkIMContext; 145 } 146 147 148 /** the main Gtk struct as a void* */ 149 protected override void* getStruct() 150 { 151 return cast(void*)gtkIMContext; 152 } 153 154 /** 155 * Sets our main struct and passes it to the parent class 156 */ 157 public this (GtkIMContext* gtkIMContext) 158 { 159 super(cast(GObject*)gtkIMContext); 160 this.gtkIMContext = gtkIMContext; 161 } 162 163 protected override void setStruct(GObject* obj) 164 { 165 super.setStruct(obj); 166 gtkIMContext = cast(GtkIMContext*)obj; 167 } 168 169 /** 170 */ 171 int[string] connectedSignals; 172 173 void delegate(string, IMContext)[] onCommitListeners; 174 /** 175 * The ::commit signal is emitted when a complete input sequence 176 * has been entered by the user. This can be a single character 177 * immediately after a key press or the final result of preediting. 178 */ 179 void addOnCommit(void delegate(string, IMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 180 { 181 if ( !("commit" in connectedSignals) ) 182 { 183 Signals.connectData( 184 getStruct(), 185 "commit", 186 cast(GCallback)&callBackCommit, 187 cast(void*)this, 188 null, 189 connectFlags); 190 connectedSignals["commit"] = 1; 191 } 192 onCommitListeners ~= dlg; 193 } 194 extern(C) static void callBackCommit(GtkIMContext* contextStruct, gchar* str, IMContext _iMContext) 195 { 196 foreach ( void delegate(string, IMContext) dlg ; _iMContext.onCommitListeners ) 197 { 198 dlg(Str.toString(str), _iMContext); 199 } 200 } 201 202 bool delegate(gint, gint, IMContext)[] onDeleteSurroundingListeners; 203 /** 204 * The ::delete-surrounding signal is emitted when the input method 205 * needs to delete all or part of the context surrounding the cursor. 206 * TRUE if the signal was handled. 207 */ 208 void addOnDeleteSurrounding(bool delegate(gint, gint, IMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 209 { 210 if ( !("delete-surrounding" in connectedSignals) ) 211 { 212 Signals.connectData( 213 getStruct(), 214 "delete-surrounding", 215 cast(GCallback)&callBackDeleteSurrounding, 216 cast(void*)this, 217 null, 218 connectFlags); 219 connectedSignals["delete-surrounding"] = 1; 220 } 221 onDeleteSurroundingListeners ~= dlg; 222 } 223 extern(C) static gboolean callBackDeleteSurrounding(GtkIMContext* contextStruct, gint offset, gint nChars, IMContext _iMContext) 224 { 225 foreach ( bool delegate(gint, gint, IMContext) dlg ; _iMContext.onDeleteSurroundingListeners ) 226 { 227 if ( dlg(offset, nChars, _iMContext) ) 228 { 229 return 1; 230 } 231 } 232 233 return 0; 234 } 235 236 void delegate(IMContext)[] onPreeditChangedListeners; 237 /** 238 * The ::preedit-changed signal is emitted whenever the preedit sequence 239 * currently being entered has changed. It is also emitted at the end of 240 * a preedit sequence, in which case 241 * gtk_im_context_get_preedit_string() returns the empty string. 242 */ 243 void addOnPreeditChanged(void delegate(IMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 244 { 245 if ( !("preedit-changed" in connectedSignals) ) 246 { 247 Signals.connectData( 248 getStruct(), 249 "preedit-changed", 250 cast(GCallback)&callBackPreeditChanged, 251 cast(void*)this, 252 null, 253 connectFlags); 254 connectedSignals["preedit-changed"] = 1; 255 } 256 onPreeditChangedListeners ~= dlg; 257 } 258 extern(C) static void callBackPreeditChanged(GtkIMContext* contextStruct, IMContext _iMContext) 259 { 260 foreach ( void delegate(IMContext) dlg ; _iMContext.onPreeditChangedListeners ) 261 { 262 dlg(_iMContext); 263 } 264 } 265 266 void delegate(IMContext)[] onPreeditEndListeners; 267 /** 268 * The ::preedit-end signal is emitted when a preediting sequence 269 * has been completed or canceled. 270 */ 271 void addOnPreeditEnd(void delegate(IMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 272 { 273 if ( !("preedit-end" in connectedSignals) ) 274 { 275 Signals.connectData( 276 getStruct(), 277 "preedit-end", 278 cast(GCallback)&callBackPreeditEnd, 279 cast(void*)this, 280 null, 281 connectFlags); 282 connectedSignals["preedit-end"] = 1; 283 } 284 onPreeditEndListeners ~= dlg; 285 } 286 extern(C) static void callBackPreeditEnd(GtkIMContext* contextStruct, IMContext _iMContext) 287 { 288 foreach ( void delegate(IMContext) dlg ; _iMContext.onPreeditEndListeners ) 289 { 290 dlg(_iMContext); 291 } 292 } 293 294 void delegate(IMContext)[] onPreeditStartListeners; 295 /** 296 * The ::preedit-start signal is emitted when a new preediting sequence 297 * starts. 298 */ 299 void addOnPreeditStart(void delegate(IMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 300 { 301 if ( !("preedit-start" in connectedSignals) ) 302 { 303 Signals.connectData( 304 getStruct(), 305 "preedit-start", 306 cast(GCallback)&callBackPreeditStart, 307 cast(void*)this, 308 null, 309 connectFlags); 310 connectedSignals["preedit-start"] = 1; 311 } 312 onPreeditStartListeners ~= dlg; 313 } 314 extern(C) static void callBackPreeditStart(GtkIMContext* contextStruct, IMContext _iMContext) 315 { 316 foreach ( void delegate(IMContext) dlg ; _iMContext.onPreeditStartListeners ) 317 { 318 dlg(_iMContext); 319 } 320 } 321 322 bool delegate(IMContext)[] onRetrieveSurroundingListeners; 323 /** 324 * The ::retrieve-surrounding signal is emitted when the input method 325 * requires the context surrounding the cursor. The callback should set 326 * the input method surrounding context by calling the 327 * gtk_im_context_set_surrounding() method. 328 * TRUE if the signal was handled. 329 */ 330 void addOnRetrieveSurrounding(bool delegate(IMContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 331 { 332 if ( !("retrieve-surrounding" in connectedSignals) ) 333 { 334 Signals.connectData( 335 getStruct(), 336 "retrieve-surrounding", 337 cast(GCallback)&callBackRetrieveSurrounding, 338 cast(void*)this, 339 null, 340 connectFlags); 341 connectedSignals["retrieve-surrounding"] = 1; 342 } 343 onRetrieveSurroundingListeners ~= dlg; 344 } 345 extern(C) static gboolean callBackRetrieveSurrounding(GtkIMContext* contextStruct, IMContext _iMContext) 346 { 347 foreach ( bool delegate(IMContext) dlg ; _iMContext.onRetrieveSurroundingListeners ) 348 { 349 if ( dlg(_iMContext) ) 350 { 351 return 1; 352 } 353 } 354 355 return 0; 356 } 357 358 359 /** 360 * Set the client window for the input context; this is the 361 * GdkWindow in which the input appears. This window is 362 * used in order to correctly position status windows, and may 363 * also be used for purposes internal to the input method. 364 * Params: 365 * window = the client window. This may be NULL to indicate 366 * that the previous client window no longer exists. [allow-none] 367 */ 368 public void setClientWindow(Window window) 369 { 370 // void gtk_im_context_set_client_window (GtkIMContext *context, GdkWindow *window); 371 gtk_im_context_set_client_window(gtkIMContext, (window is null) ? null : window.getWindowStruct()); 372 } 373 374 /** 375 * Retrieve the current preedit string for the input context, 376 * and a list of attributes to apply to the string. 377 * This string should be displayed inserted at the insertion 378 * point. 379 * Params: 380 * str = location to store the retrieved 381 * string. The string retrieved must be freed with g_free(). [out][transfer full] 382 * attrs = location to store the retrieved 383 * attribute list. When you are done with this list, you 384 * must unreference it with pango_attr_list_unref(). [out][transfer full] 385 * cursorPos = location to store position of cursor (in characters) 386 * within the preedit string. [out] 387 */ 388 public void getPreeditString(out string str, out PgAttributeList attrs, out int cursorPos) 389 { 390 // void gtk_im_context_get_preedit_string (GtkIMContext *context, gchar **str, PangoAttrList **attrs, gint *cursor_pos); 391 char* outstr = null; 392 PangoAttrList* outattrs = null; 393 394 gtk_im_context_get_preedit_string(gtkIMContext, &outstr, &outattrs, &cursorPos); 395 396 str = Str.toString(outstr); 397 attrs = ObjectG.getDObject!(PgAttributeList)(outattrs); 398 } 399 400 /** 401 * Allow an input method to internally handle key press and release 402 * events. If this function returns TRUE, then no further processing 403 * should be done for this key event. 404 * Params: 405 * event = the key event 406 * Returns: TRUE if the input method handled the key event. 407 */ 408 public int filterKeypress(GdkEventKey* event) 409 { 410 // gboolean gtk_im_context_filter_keypress (GtkIMContext *context, GdkEventKey *event); 411 return gtk_im_context_filter_keypress(gtkIMContext, event); 412 } 413 414 /** 415 * Notify the input method that the widget to which this 416 * input context corresponds has gained focus. The input method 417 * may, for example, change the displayed feedback to reflect 418 * this change. 419 */ 420 public void focusIn() 421 { 422 // void gtk_im_context_focus_in (GtkIMContext *context); 423 gtk_im_context_focus_in(gtkIMContext); 424 } 425 426 /** 427 * Notify the input method that the widget to which this 428 * input context corresponds has lost focus. The input method 429 * may, for example, change the displayed feedback or reset the contexts 430 * state to reflect this change. 431 */ 432 public void focusOut() 433 { 434 // void gtk_im_context_focus_out (GtkIMContext *context); 435 gtk_im_context_focus_out(gtkIMContext); 436 } 437 438 /** 439 * Notify the input method that a change such as a change in cursor 440 * position has been made. This will typically cause the input 441 * method to clear the preedit state. 442 */ 443 public void reset() 444 { 445 // void gtk_im_context_reset (GtkIMContext *context); 446 gtk_im_context_reset(gtkIMContext); 447 } 448 449 /** 450 * Notify the input method that a change in cursor 451 * position has been made. The location is relative to the client 452 * window. 453 * Params: 454 * area = new location 455 */ 456 public void setCursorLocation(ref Rectangle area) 457 { 458 // void gtk_im_context_set_cursor_location (GtkIMContext *context, const GdkRectangle *area); 459 gtk_im_context_set_cursor_location(gtkIMContext, &area); 460 } 461 462 /** 463 * Sets whether the IM context should use the preedit string 464 * to display feedback. If use_preedit is FALSE (default 465 * is TRUE), then the IM context may use some other method to display 466 * feedback, such as displaying it in a child of the root window. 467 * Params: 468 * usePreedit = whether the IM context should use the preedit string. 469 */ 470 public void setUsePreedit(int usePreedit) 471 { 472 // void gtk_im_context_set_use_preedit (GtkIMContext *context, gboolean use_preedit); 473 gtk_im_context_set_use_preedit(gtkIMContext, usePreedit); 474 } 475 476 /** 477 * Sets surrounding context around the insertion point and preedit 478 * string. This function is expected to be called in response to the 479 * GtkIMContext::retrieve_surrounding signal, and will likely have no 480 * effect if called at other times. 481 * Params: 482 * text = text surrounding the insertion point, as UTF-8. 483 * the preedit string should not be included within 484 * text. 485 * cursorIndex = the byte index of the insertion cursor within text. 486 */ 487 public void setSurrounding(string text, int cursorIndex) 488 { 489 // void gtk_im_context_set_surrounding (GtkIMContext *context, const gchar *text, gint len, gint cursor_index); 490 gtk_im_context_set_surrounding(gtkIMContext, cast(char*)text.ptr, cast(int) text.length, cursorIndex); 491 } 492 493 /** 494 * Retrieves context around the insertion point. Input methods 495 * typically want context in order to constrain input text based on 496 * existing text; this is important for languages such as Thai where 497 * only some sequences of characters are allowed. 498 * This function is implemented by emitting the 499 * GtkIMContext::retrieve_surrounding signal on the input method; in 500 * response to this signal, a widget should provide as much context as 501 * is available, up to an entire paragraph, by calling 502 * gtk_im_context_set_surrounding(). Note that there is no obligation 503 * for a widget to respond to the ::retrieve_surrounding signal, so input 504 * methods must be prepared to function without context. 505 * Params: 506 * text = location to store a UTF-8 encoded 507 * string of text holding context around the insertion point. 508 * If the function returns TRUE, then you must free the result 509 * stored in this location with g_free(). [out][transfer full] 510 * cursorIndex = location to store byte index of the insertion 511 * cursor within text. [out] 512 * Returns: TRUE if surrounding text was provided; in this case you must free the result stored in *text. 513 */ 514 public int getSurrounding(out string text, out int cursorIndex) 515 { 516 // gboolean gtk_im_context_get_surrounding (GtkIMContext *context, gchar **text, gint *cursor_index); 517 char* outtext = null; 518 519 auto p = gtk_im_context_get_surrounding(gtkIMContext, &outtext, &cursorIndex); 520 521 text = Str.toString(outtext); 522 return p; 523 } 524 525 /** 526 * Asks the widget that the input context is attached to to delete 527 * characters around the cursor position by emitting the 528 * GtkIMContext::delete_surrounding signal. Note that offset and n_chars 529 * are in characters not in bytes which differs from the usage other 530 * places in GtkIMContext. 531 * In order to use this function, you should first call 532 * gtk_im_context_get_surrounding() to get the current context, and 533 * call this function immediately afterwards to make sure that you 534 * know what you are deleting. You should also account for the fact 535 * that even if the signal was handled, the input context might not 536 * have deleted all the characters that were requested to be deleted. 537 * This function is used by an input method that wants to make 538 * subsitutions in the existing text in response to new input. It is 539 * not useful for applications. 540 * Params: 541 * offset = offset from cursor position in chars; 542 * a negative value means start before the cursor. 543 * nChars = number of characters to delete. 544 * Returns: TRUE if the signal was handled. 545 */ 546 public int deleteSurrounding(int offset, int nChars) 547 { 548 // gboolean gtk_im_context_delete_surrounding (GtkIMContext *context, gint offset, gint n_chars); 549 return gtk_im_context_delete_surrounding(gtkIMContext, offset, nChars); 550 } 551 }