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