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 module gtk.EventControllerKey;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.EventController;
31 private import gtk.IMContext;
32 private import gtk.Widget;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 private import std.algorithm;
36 
37 
38 /**
39  * `GtkEventControllerKey` is an event controller that provides access
40  * to key events.
41  */
42 public class EventControllerKey : EventController
43 {
44 	/** the main Gtk struct */
45 	protected GtkEventControllerKey* gtkEventControllerKey;
46 
47 	/** Get the main Gtk struct */
48 	public GtkEventControllerKey* getEventControllerKeyStruct(bool transferOwnership = false)
49 	{
50 		if (transferOwnership)
51 			ownedRef = false;
52 		return gtkEventControllerKey;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)gtkEventControllerKey;
59 	}
60 
61 	/**
62 	 * Sets our main struct and passes it to the parent class.
63 	 */
64 	public this (GtkEventControllerKey* gtkEventControllerKey, bool ownedRef = false)
65 	{
66 		this.gtkEventControllerKey = gtkEventControllerKey;
67 		super(cast(GtkEventController*)gtkEventControllerKey, ownedRef);
68 	}
69 
70 
71 	/** */
72 	public static GType getType()
73 	{
74 		return gtk_event_controller_key_get_type();
75 	}
76 
77 	/**
78 	 * Creates a new event controller that will handle key events.
79 	 *
80 	 * Returns: a new `GtkEventControllerKey`
81 	 *
82 	 * Throws: ConstructionException GTK+ fails to create the object.
83 	 */
84 	public this()
85 	{
86 		auto __p = gtk_event_controller_key_new();
87 
88 		if(__p is null)
89 		{
90 			throw new ConstructionException("null returned by new");
91 		}
92 
93 		this(cast(GtkEventControllerKey*) __p, true);
94 	}
95 
96 	/**
97 	 * Forwards the current event of this @controller to a @widget.
98 	 *
99 	 * This function can only be used in handlers for the
100 	 * [signal@Gtk.EventControllerKey::key-pressed],
101 	 * [signal@Gtk.EventControllerKey::key-released]
102 	 * or [signal@Gtk.EventControllerKey::modifiers] signals.
103 	 *
104 	 * Params:
105 	 *     widget = a `GtkWidget`
106 	 *
107 	 * Returns: whether the @widget handled the event
108 	 */
109 	public bool forward(Widget widget)
110 	{
111 		return gtk_event_controller_key_forward(gtkEventControllerKey, (widget is null) ? null : widget.getWidgetStruct()) != 0;
112 	}
113 
114 	/**
115 	 * Gets the key group of the current event of this @controller.
116 	 *
117 	 * See [method@Gdk.KeyEvent.get_layout].
118 	 *
119 	 * Returns: the key group
120 	 */
121 	public uint getGroup()
122 	{
123 		return gtk_event_controller_key_get_group(gtkEventControllerKey);
124 	}
125 
126 	/**
127 	 * Gets the input method context of the key @controller.
128 	 *
129 	 * Returns: the `GtkIMContext`
130 	 */
131 	public IMContext getImContext()
132 	{
133 		auto __p = gtk_event_controller_key_get_im_context(gtkEventControllerKey);
134 
135 		if(__p is null)
136 		{
137 			return null;
138 		}
139 
140 		return ObjectG.getDObject!(IMContext)(cast(GtkIMContext*) __p);
141 	}
142 
143 	/**
144 	 * Sets the input method context of the key @controller.
145 	 *
146 	 * Params:
147 	 *     imContext = a `GtkIMContext`
148 	 */
149 	public void setImContext(IMContext imContext)
150 	{
151 		gtk_event_controller_key_set_im_context(gtkEventControllerKey, (imContext is null) ? null : imContext.getIMContextStruct());
152 	}
153 
154 	/**
155 	 * Emitted whenever the input method context filters away
156 	 * a keypress and prevents the @controller receiving it.
157 	 *
158 	 * See [method@Gtk.EventControllerKey.set_im_context] and
159 	 * [method@Gtk.IMContext.filter_keypress].
160 	 */
161 	gulong addOnImUpdate(void delegate(EventControllerKey) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
162 	{
163 		return Signals.connect(this, "im-update", dlg, connectFlags ^ ConnectFlags.SWAPPED);
164 	}
165 
166 	/**
167 	 * Emitted whenever a key is pressed.
168 	 *
169 	 * Params:
170 	 *     keyval = the pressed key.
171 	 *     keycode = the raw code of the pressed key.
172 	 *     state = the bitmask, representing the state of modifier keys and pointer buttons. See #GdkModifierType.
173 	 *
174 	 * Returns: %TRUE if the key press was handled, %FALSE otherwise.
175 	 */
176 	gulong addOnKeyPressed(bool delegate(uint, uint, GdkModifierType, EventControllerKey) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
177 	{
178 		return Signals.connect(this, "key-pressed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
179 	}
180 
181 	/**
182 	 * Emitted whenever a key is released.
183 	 *
184 	 * Params:
185 	 *     keyval = the released key.
186 	 *     keycode = the raw code of the released key.
187 	 *     state = the bitmask, representing the state of modifier keys and pointer buttons. See #GdkModifierType.
188 	 */
189 	gulong addOnKeyReleased(void delegate(uint, uint, GdkModifierType, EventControllerKey) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
190 	{
191 		return Signals.connect(this, "key-released", dlg, connectFlags ^ ConnectFlags.SWAPPED);
192 	}
193 
194 	/**
195 	 * Emitted whenever the state of modifier keys and pointer buttons change.
196 	 *
197 	 * Params:
198 	 *     keyval = the released key.
199 	 */
200 	gulong addOnModifiers(bool delegate(GdkModifierType, EventControllerKey) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
201 	{
202 		return Signals.connect(this, "modifiers", dlg, connectFlags ^ ConnectFlags.SWAPPED);
203 	}
204 }