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