1 module webkit2.InputMethodContext;
2 
3 private import glib.ListG;
4 private import glib.Str;
5 private import gobject.ObjectG;
6 private import gobject.Signals;
7 private import std.algorithm;
8 private import webkit2.InputMethodUnderline;
9 private import webkit2.c.functions;
10 public  import webkit2.c.types;
11 
12 
13 /**
14  * WebKitInputMethodContext defines the interface to implement WebKit input methods.
15  * The input methods are used by WebKit, when editable content is focused, to map from
16  * key events to Unicode character strings.
17  * 
18  * An input method may consume multiple key events in sequence and finally
19  * output the composed result. This is called preediting, and an input method
20  * may provide feedback about this process by displaying the intermediate
21  * composition states as preedit text.
22  *
23  * Since: 2.28
24  */
25 public class InputMethodContext : ObjectG
26 {
27 	/** the main Gtk struct */
28 	protected WebKitInputMethodContext* webKitInputMethodContext;
29 
30 	/** Get the main Gtk struct */
31 	public WebKitInputMethodContext* getInputMethodContextStruct(bool transferOwnership = false)
32 	{
33 		if (transferOwnership)
34 			ownedRef = false;
35 		return webKitInputMethodContext;
36 	}
37 
38 	/** the main Gtk struct as a void* */
39 	protected override void* getStruct()
40 	{
41 		return cast(void*)webKitInputMethodContext;
42 	}
43 
44 	/**
45 	 * Sets our main struct and passes it to the parent class.
46 	 */
47 	public this (WebKitInputMethodContext* webKitInputMethodContext, bool ownedRef = false)
48 	{
49 		this.webKitInputMethodContext = webKitInputMethodContext;
50 		super(cast(GObject*)webKitInputMethodContext, ownedRef);
51 	}
52 
53 
54 	/** */
55 	public static GType getType()
56 	{
57 		return webkit_input_method_context_get_type();
58 	}
59 
60 	/**
61 	 * Allow @key_event to be handled by the input method. If %TRUE is returned, then no further processing should be
62 	 * done for the key event.
63 	 *
64 	 * Params:
65 	 *     keyEvent = the key event to filter
66 	 *
67 	 * Returns: %TRUE if the key event was handled, or %FALSE otherwise
68 	 *
69 	 * Since: 2.28
70 	 */
71 	public bool filterKeyEvent(GdkEventKey* keyEvent)
72 	{
73 		return webkit_input_method_context_filter_key_event(webKitInputMethodContext, keyEvent) != 0;
74 	}
75 
76 	/**
77 	 * Get the value of the #WebKitInputMethodContext:input-hints property.
78 	 *
79 	 * Returns: the #WebKitInputHints of the input associated with @context
80 	 *
81 	 * Since: 2.28
82 	 */
83 	public WebKitInputHints getInputHints()
84 	{
85 		return webkit_input_method_context_get_input_hints(webKitInputMethodContext);
86 	}
87 
88 	/**
89 	 * Get the value of the #WebKitInputMethodContext:input-purpose property.
90 	 *
91 	 * Returns: the #WebKitInputPurpose of the input associated with @context
92 	 *
93 	 * Since: 2.28
94 	 */
95 	public WebKitInputPurpose getInputPurpose()
96 	{
97 		return webkit_input_method_context_get_input_purpose(webKitInputMethodContext);
98 	}
99 
100 	/**
101 	 * Get the current preedit string for the @context, and a list of WebKitInputMethodUnderline to apply to the string.
102 	 * The string will be displayed inserted at @cursor_offset.
103 	 *
104 	 * Params:
105 	 *     text = location to store the preedit string
106 	 *     underlines = location to store the underlines as a #GList of #WebKitInputMethodUnderline
107 	 *     cursorOffset = location to store the position of cursor in preedit string
108 	 *
109 	 * Since: 2.28
110 	 */
111 	public void getPreedit(out string text, out ListG underlines, out uint cursorOffset)
112 	{
113 		char* outtext = null;
114 		GList* outunderlines = null;
115 
116 		webkit_input_method_context_get_preedit(webKitInputMethodContext, &outtext, &outunderlines, &cursorOffset);
117 
118 		text = Str.toString(outtext);
119 		underlines = new ListG(outunderlines);
120 	}
121 
122 	/**
123 	 * Notify @context that cursor area changed in input associated.
124 	 *
125 	 * Params:
126 	 *     x = the x coordinate of cursor location
127 	 *     y = the y coordinate of cursor location
128 	 *     width = the width of cursor area
129 	 *     height = the height of cursor area
130 	 *
131 	 * Since: 2.28
132 	 */
133 	public void notifyCursorArea(int x, int y, int width, int height)
134 	{
135 		webkit_input_method_context_notify_cursor_area(webKitInputMethodContext, x, y, width, height);
136 	}
137 
138 	/**
139 	 * Notify @context that input associated has gained focus.
140 	 *
141 	 * Since: 2.28
142 	 */
143 	public void notifyFocusIn()
144 	{
145 		webkit_input_method_context_notify_focus_in(webKitInputMethodContext);
146 	}
147 
148 	/**
149 	 * Notify @context that input associated has lost focus.
150 	 *
151 	 * Since: 2.28
152 	 */
153 	public void notifyFocusOut()
154 	{
155 		webkit_input_method_context_notify_focus_out(webKitInputMethodContext);
156 	}
157 
158 	/**
159 	 * Notify @context that the context surrounding the cursor has changed.
160 	 * If there's no selection @selection_index is the same as @cursor_index.
161 	 *
162 	 * Params:
163 	 *     text = text surrounding the insertion point
164 	 *     length = the length of @text, or -1 if @text is nul-terminated
165 	 *     cursorIndex = the byte index of the insertion cursor within @text.
166 	 *     selectionIndex = the byte index of the selection cursor within @text.
167 	 *
168 	 * Since: 2.28
169 	 */
170 	public void notifySurrounding(string text, int length, uint cursorIndex, uint selectionIndex)
171 	{
172 		webkit_input_method_context_notify_surrounding(webKitInputMethodContext, Str.toStringz(text), length, cursorIndex, selectionIndex);
173 	}
174 
175 	/**
176 	 * Reset the @context. This will typically cause the input to clear the preedit state.
177 	 *
178 	 * Since: 2.28
179 	 */
180 	public void reset()
181 	{
182 		webkit_input_method_context_reset(webKitInputMethodContext);
183 	}
184 
185 	/**
186 	 * Set whether @context should enable preedit to display feedback.
187 	 *
188 	 * Params:
189 	 *     enabled = whether to enable preedit
190 	 *
191 	 * Since: 2.28
192 	 */
193 	public void setEnablePreedit(bool enabled)
194 	{
195 		webkit_input_method_context_set_enable_preedit(webKitInputMethodContext, enabled);
196 	}
197 
198 	/** */
199 	public void setInputHints(WebKitInputHints hints)
200 	{
201 		webkit_input_method_context_set_input_hints(webKitInputMethodContext, hints);
202 	}
203 
204 	/**
205 	 * Set the value of the #WebKitInputMethodContext:input-purpose property.
206 	 *
207 	 * Params:
208 	 *     purpose = a #WebKitInputPurpose
209 	 *
210 	 * Since: 2.28
211 	 */
212 	public void setInputPurpose(WebKitInputPurpose purpose)
213 	{
214 		webkit_input_method_context_set_input_purpose(webKitInputMethodContext, purpose);
215 	}
216 
217 	/**
218 	 * Emitted when a complete input sequence has been entered by the user.
219 	 * This can be a single character immediately after a key press or the
220 	 * final result of preediting.
221 	 *
222 	 * Params:
223 	 *     text = the string result
224 	 *
225 	 * Since: 2.28
226 	 */
227 	gulong addOnCommitted(void delegate(string, InputMethodContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
228 	{
229 		return Signals.connect(this, "committed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
230 	}
231 
232 	/**
233 	 * Emitted when the input method wants to delete the context surrounding the cursor.
234 	 * If @offset is a negative value, it means a position before the cursor.
235 	 *
236 	 * Params:
237 	 *     offset = the character offset from the cursor position of the text to be deleted.
238 	 *     nChars = the number of characters to be deleted
239 	 *
240 	 * Since: 2.28
241 	 */
242 	gulong addOnDeleteSurrounding(void delegate(int, uint, InputMethodContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
243 	{
244 		return Signals.connect(this, "delete-surrounding", dlg, connectFlags ^ ConnectFlags.SWAPPED);
245 	}
246 
247 	/**
248 	 * Emitted whenever the preedit sequence currently being entered has changed.
249 	 * It is also emitted at the end of a preedit sequence, in which case
250 	 * webkit_input_method_context_get_preedit() returns the empty string.
251 	 *
252 	 * Since: 2.28
253 	 */
254 	gulong addOnPreeditChanged(void delegate(InputMethodContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
255 	{
256 		return Signals.connect(this, "preedit-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
257 	}
258 
259 	/**
260 	 * Emitted when a preediting sequence has been completed or canceled.
261 	 *
262 	 * Since: 2.28
263 	 */
264 	gulong addOnPreeditFinished(void delegate(InputMethodContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
265 	{
266 		return Signals.connect(this, "preedit-finished", dlg, connectFlags ^ ConnectFlags.SWAPPED);
267 	}
268 
269 	/**
270 	 * Emitted when a new preediting sequence starts.
271 	 *
272 	 * Since: 2.28
273 	 */
274 	gulong addOnPreeditStarted(void delegate(InputMethodContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
275 	{
276 		return Signals.connect(this, "preedit-started", dlg, connectFlags ^ ConnectFlags.SWAPPED);
277 	}
278 }