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.ShortcutController;
26 
27 private import gio.ListModelIF;
28 private import gio.ListModelT;
29 private import glib.ConstructionException;
30 private import gobject.ObjectG;
31 private import gtk.BuildableIF;
32 private import gtk.BuildableT;
33 private import gtk.EventController;
34 private import gtk.Shortcut;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 
38 
39 /**
40  * `GtkShortcutController` is an event controller that manages shortcuts.
41  * 
42  * Most common shortcuts are using this controller implicitly, e.g. by
43  * adding a mnemonic underline to a `GtkLabel`, or by installing a key
44  * binding using gtk_widget_class_add_binding(), or by adding accelerators
45  * to global actions using gtk_application_set_accels_for_action().
46  * 
47  * But it is possible to create your own shortcut controller, and add
48  * shortcuts to it.
49  * 
50  * `GtkShortcutController` implements `GListModel` for querying the
51  * shortcuts that have been added to it.
52  * 
53  * # GtkShortcutController as a GtkBuildable
54  * 
55  * `GtkShortcutControllers` can be creates in ui files to set up
56  * shortcuts in the same place as the widgets.
57  * 
58  * An example of a UI definition fragment with `GtkShortcutController`:
59  * ```xml
60  * <object class='GtkButton'>
61  * <child>
62  * <object class='GtkShortcutController'>
63  * <property name='scope'>managed</property>
64  * <child>
65  * <object class='GtkShortcut'>
66  * <property name='trigger'>&amp;lt;Control&amp;gt;k</property>
67  * <property name='action'>activate</property>
68  * </object>
69  * </child>
70  * </object>
71  * </child>
72  * </object>
73  * ```
74  * 
75  * This example creates a [class@Gtk.ActivateAction] for triggering the
76  * `activate` signal of the `GtkButton`. See [ctor@Gtk.ShortcutAction.parse_string]
77  * for the syntax for other kinds of `GtkShortcutAction`. See
78  * [ctor@Gtk.ShortcutTrigger.parse_string] to learn more about the syntax
79  * for triggers.
80  */
81 public class ShortcutController : EventController, ListModelIF, BuildableIF
82 {
83 	/** the main Gtk struct */
84 	protected GtkShortcutController* gtkShortcutController;
85 
86 	/** Get the main Gtk struct */
87 	public GtkShortcutController* getShortcutControllerStruct(bool transferOwnership = false)
88 	{
89 		if (transferOwnership)
90 			ownedRef = false;
91 		return gtkShortcutController;
92 	}
93 
94 	/** the main Gtk struct as a void* */
95 	protected override void* getStruct()
96 	{
97 		return cast(void*)gtkShortcutController;
98 	}
99 
100 	/**
101 	 * Sets our main struct and passes it to the parent class.
102 	 */
103 	public this (GtkShortcutController* gtkShortcutController, bool ownedRef = false)
104 	{
105 		this.gtkShortcutController = gtkShortcutController;
106 		super(cast(GtkEventController*)gtkShortcutController, ownedRef);
107 	}
108 
109 	// add the ListModel capabilities
110 	mixin ListModelT!(GtkShortcutController);
111 
112 	// add the Buildable capabilities
113 	mixin BuildableT!(GtkShortcutController);
114 
115 
116 	/** */
117 	public static GType getType()
118 	{
119 		return gtk_shortcut_controller_get_type();
120 	}
121 
122 	/**
123 	 * Creates a new shortcut controller.
124 	 *
125 	 * Returns: a newly created shortcut controller
126 	 *
127 	 * Throws: ConstructionException GTK+ fails to create the object.
128 	 */
129 	public this()
130 	{
131 		auto __p = gtk_shortcut_controller_new();
132 
133 		if(__p is null)
134 		{
135 			throw new ConstructionException("null returned by new");
136 		}
137 
138 		this(cast(GtkShortcutController*) __p, true);
139 	}
140 
141 	/**
142 	 * Creates a new shortcut controller that takes its shortcuts from
143 	 * the given list model.
144 	 *
145 	 * A controller created by this function does not let you add or
146 	 * remove individual shortcuts using the shortcut controller api,
147 	 * but you can change the contents of the model.
148 	 *
149 	 * Params:
150 	 *     model = a `GListModel` containing shortcuts
151 	 *
152 	 * Returns: a newly created shortcut controller
153 	 *
154 	 * Throws: ConstructionException GTK+ fails to create the object.
155 	 */
156 	public this(ListModelIF model)
157 	{
158 		auto __p = gtk_shortcut_controller_new_for_model((model is null) ? null : model.getListModelStruct());
159 
160 		if(__p is null)
161 		{
162 			throw new ConstructionException("null returned by new_for_model");
163 		}
164 
165 		this(cast(GtkShortcutController*) __p, true);
166 	}
167 
168 	/**
169 	 * Adds @shortcut to the list of shortcuts handled by @self.
170 	 *
171 	 * If this controller uses an external shortcut list, this
172 	 * function does nothing.
173 	 *
174 	 * Params:
175 	 *     shortcut = a `GtkShortcut`
176 	 */
177 	public void addShortcut(Shortcut shortcut)
178 	{
179 		gtk_shortcut_controller_add_shortcut(gtkShortcutController, (shortcut is null) ? null : shortcut.getShortcutStruct());
180 	}
181 
182 	/**
183 	 * Gets the mnemonics modifiers for when this controller activates its shortcuts.
184 	 *
185 	 * Returns: the controller's mnemonics modifiers
186 	 */
187 	public GdkModifierType getMnemonicsModifiers()
188 	{
189 		return gtk_shortcut_controller_get_mnemonics_modifiers(gtkShortcutController);
190 	}
191 
192 	/**
193 	 * Gets the scope for when this controller activates its shortcuts. See
194 	 * gtk_shortcut_controller_set_scope() for details.
195 	 *
196 	 * Returns: the controller's scope
197 	 */
198 	public GtkShortcutScope getScope()
199 	{
200 		return gtk_shortcut_controller_get_scope(gtkShortcutController);
201 	}
202 
203 	/**
204 	 * Removes @shortcut from the list of shortcuts handled by @self.
205 	 *
206 	 * If @shortcut had not been added to @controller or this controller
207 	 * uses an external shortcut list, this function does nothing.
208 	 *
209 	 * Params:
210 	 *     shortcut = a `GtkShortcut`
211 	 */
212 	public void removeShortcut(Shortcut shortcut)
213 	{
214 		gtk_shortcut_controller_remove_shortcut(gtkShortcutController, (shortcut is null) ? null : shortcut.getShortcutStruct());
215 	}
216 
217 	/**
218 	 * Sets the controller to have the given @mnemonics_modifiers.
219 	 *
220 	 * The mnemonics modifiers determines which modifiers need to be pressed to allow
221 	 * activation of shortcuts with mnemonics triggers.
222 	 *
223 	 * GTK normally uses the Alt modifier for mnemonics, except in #GtkPopoverMenus,
224 	 * where mnemonics can be triggered without any modifiers. It should be very
225 	 * rarely necessary to change this, and doing so is likely to interfere with
226 	 * other shortcuts.
227 	 *
228 	 * This value is only relevant for local shortcut controllers. Global and managed
229 	 * shortcut controllers will have their shortcuts activated from other places which
230 	 * have their own modifiers for activating mnemonics.
231 	 *
232 	 * Params:
233 	 *     modifiers = the new mnemonics_modifiers to use
234 	 */
235 	public void setMnemonicsModifiers(GdkModifierType modifiers)
236 	{
237 		gtk_shortcut_controller_set_mnemonics_modifiers(gtkShortcutController, modifiers);
238 	}
239 
240 	/**
241 	 * Sets the controller to have the given @scope.
242 	 *
243 	 * The scope allows shortcuts to be activated outside of the normal
244 	 * event propagation. In particular, it allows installing global
245 	 * keyboard shortcuts that can be activated even when a widget does
246 	 * not have focus.
247 	 *
248 	 * With %GTK_SHORTCUT_SCOPE_LOCAL, shortcuts will only be activated
249 	 * when the widget has focus.
250 	 *
251 	 * Params:
252 	 *     scope_ = the new scope to use
253 	 */
254 	public void setScope(GtkShortcutScope scope_)
255 	{
256 		gtk_shortcut_controller_set_scope(gtkShortcutController, scope_);
257 	}
258 }