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.ShortcutTrigger;
26 
27 private import gdk.Display;
28 private import gdk.Event;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import glib.StringG;
32 private import glib.c.functions;
33 private import gobject.ObjectG;
34 private import gtk.c.functions;
35 public  import gtk.c.types;
36 
37 
38 /**
39  * `GtkShortcutTrigger` tracks how a `GtkShortcut` should be activated.
40  * 
41  * To find out if a `GtkShortcutTrigger` triggers, you can call
42  * [method@Gtk.ShortcutTrigger.trigger] on a `GdkEvent`.
43  * 
44  * `GtkShortcutTriggers` contain functions that allow easy presentation
45  * to end users as well as being printed for debugging.
46  * 
47  * All `GtkShortcutTriggers` are immutable, you can only specify their
48  * properties during construction. If you want to change a trigger, you
49  * have to replace it with a new one.
50  */
51 public class ShortcutTrigger : ObjectG
52 {
53 	/** the main Gtk struct */
54 	protected GtkShortcutTrigger* gtkShortcutTrigger;
55 
56 	/** Get the main Gtk struct */
57 	public GtkShortcutTrigger* getShortcutTriggerStruct(bool transferOwnership = false)
58 	{
59 		if (transferOwnership)
60 			ownedRef = false;
61 		return gtkShortcutTrigger;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gtkShortcutTrigger;
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkShortcutTrigger* gtkShortcutTrigger, bool ownedRef = false)
74 	{
75 		this.gtkShortcutTrigger = gtkShortcutTrigger;
76 		super(cast(GObject*)gtkShortcutTrigger, ownedRef);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gtk_shortcut_trigger_get_type();
84 	}
85 
86 	/**
87 	 * Tries to parse the given string into a trigger.
88 	 *
89 	 * On success, the parsed trigger is returned.
90 	 * When parsing failed, %NULL is returned.
91 	 *
92 	 * The accepted strings are:
93 	 *
94 	 * - `never`, for `GtkNeverTrigger`
95 	 * - a string parsed by gtk_accelerator_parse(), for a `GtkKeyvalTrigger`, e.g. `<Control>C`
96 	 * - underscore, followed by a single character, for `GtkMnemonicTrigger`, e.g. `_l`
97 	 * - two valid trigger strings, separated by a `|` character, for a
98 	 * `GtkAlternativeTrigger`: `<Control>q|<Control>w`
99 	 *
100 	 * Note that you will have to escape the `<` and `>` characters when specifying
101 	 * triggers in XML files, such as GtkBuilder ui files. Use `&lt;` instead of
102 	 * `<` and `&gt;` instead of `>`.
103 	 *
104 	 * Params:
105 	 *     string_ = the string to parse
106 	 *
107 	 * Returns: a new `GtkShortcutTrigger`
108 	 *     or %NULL on error
109 	 *
110 	 * Throws: ConstructionException GTK+ fails to create the object.
111 	 */
112 	public this(string string_)
113 	{
114 		auto __p = gtk_shortcut_trigger_parse_string(Str.toStringz(string_));
115 
116 		if(__p is null)
117 		{
118 			throw new ConstructionException("null returned by parse_string");
119 		}
120 
121 		this(cast(GtkShortcutTrigger*) __p, true);
122 	}
123 
124 	/**
125 	 * The types of @trigger1 and @trigger2 are #gconstpointer only to allow
126 	 * use of this function as a #GCompareFunc.
127 	 *
128 	 * They must each be a `GtkShortcutTrigger`.
129 	 *
130 	 * Params:
131 	 *     trigger2 = a `GtkShortcutTrigger`
132 	 *
133 	 * Returns: An integer less than, equal to, or greater than zero if
134 	 *     @trigger1 is found, respectively, to be less than, to match,
135 	 *     or be greater than @trigger2.
136 	 */
137 	public int compare(ShortcutTrigger trigger2)
138 	{
139 		return gtk_shortcut_trigger_compare(gtkShortcutTrigger, (trigger2 is null) ? null : trigger2.getShortcutTriggerStruct());
140 	}
141 
142 	/**
143 	 * Checks if @trigger1 and @trigger2 trigger under the same conditions.
144 	 *
145 	 * The types of @one and @two are #gconstpointer only to allow use of this
146 	 * function with #GHashTable. They must each be a `GtkShortcutTrigger`.
147 	 *
148 	 * Params:
149 	 *     trigger2 = a `GtkShortcutTrigger`
150 	 *
151 	 * Returns: %TRUE if @trigger1 and @trigger2 are equal
152 	 */
153 	public bool equal(ShortcutTrigger trigger2)
154 	{
155 		return gtk_shortcut_trigger_equal(gtkShortcutTrigger, (trigger2 is null) ? null : trigger2.getShortcutTriggerStruct()) != 0;
156 	}
157 
158 	/**
159 	 * Generates a hash value for a `GtkShortcutTrigger`.
160 	 *
161 	 * The output of this function is guaranteed to be the same for a given
162 	 * value only per-process. It may change between different processor
163 	 * architectures or even different versions of GTK. Do not use this
164 	 * function as a basis for building protocols or file formats.
165 	 *
166 	 * The types of @trigger is #gconstpointer only to allow use of this
167 	 * function with #GHashTable. They must each be a `GtkShortcutTrigger`.
168 	 *
169 	 * Returns: a hash value corresponding to @trigger
170 	 */
171 	public uint hash()
172 	{
173 		return gtk_shortcut_trigger_hash(gtkShortcutTrigger);
174 	}
175 
176 	/**
177 	 * Prints the given trigger into a string for the developer.
178 	 * This is meant for debugging and logging.
179 	 *
180 	 * The form of the representation may change at any time
181 	 * and is not guaranteed to stay identical.
182 	 *
183 	 * Params:
184 	 *     string_ = a `GString` to print into
185 	 */
186 	public void print(StringG string_)
187 	{
188 		gtk_shortcut_trigger_print(gtkShortcutTrigger, (string_ is null) ? null : string_.getStringGStruct());
189 	}
190 
191 	/**
192 	 * Prints the given trigger into a string.
193 	 *
194 	 * This function is returning a translated string for presentation
195 	 * to end users for example in menu items or in help texts.
196 	 *
197 	 * The @display in use may influence the resulting string in
198 	 * various forms, such as resolving hardware keycodes or by
199 	 * causing display-specific modifier names.
200 	 *
201 	 * The form of the representation may change at any time and is
202 	 * not guaranteed to stay identical.
203 	 *
204 	 * Params:
205 	 *     display = `GdkDisplay` to print for
206 	 *     string_ = a `GString` to print into
207 	 *
208 	 * Returns: %TRUE if something was printed or %FALSE if the
209 	 *     trigger did not have a textual representation suitable
210 	 *     for end users.
211 	 */
212 	public bool printLabel(Display display, StringG string_)
213 	{
214 		return gtk_shortcut_trigger_print_label(gtkShortcutTrigger, (display is null) ? null : display.getDisplayStruct(), (string_ is null) ? null : string_.getStringGStruct()) != 0;
215 	}
216 
217 	/**
218 	 * Gets textual representation for the given trigger.
219 	 *
220 	 * This function is returning a translated string for
221 	 * presentation to end users for example in menu items
222 	 * or in help texts.
223 	 *
224 	 * The @display in use may influence the resulting string in
225 	 * various forms, such as resolving hardware keycodes or by
226 	 * causing display-specific modifier names.
227 	 *
228 	 * The form of the representation may change at any time and is
229 	 * not guaranteed to stay identical.
230 	 *
231 	 * Params:
232 	 *     display = `GdkDisplay` to print for
233 	 *
234 	 * Returns: a new string
235 	 */
236 	public string toLabel(Display display)
237 	{
238 		auto retStr = gtk_shortcut_trigger_to_label(gtkShortcutTrigger, (display is null) ? null : display.getDisplayStruct());
239 
240 		scope(exit) Str.freeString(retStr);
241 		return Str.toString(retStr);
242 	}
243 
244 	/**
245 	 * Prints the given trigger into a human-readable string.
246 	 *
247 	 * This is a small wrapper around [method@Gtk.ShortcutTrigger.print]
248 	 * to help when debugging.
249 	 *
250 	 * Returns: a new string
251 	 */
252 	public override string toString()
253 	{
254 		auto retStr = gtk_shortcut_trigger_to_string(gtkShortcutTrigger);
255 
256 		scope(exit) Str.freeString(retStr);
257 		return Str.toString(retStr);
258 	}
259 
260 	/**
261 	 * Checks if the given @event triggers @self.
262 	 *
263 	 * Params:
264 	 *     event = the event to check
265 	 *     enableMnemonics = %TRUE if mnemonics should trigger. Usually the
266 	 *         value of this property is determined by checking that the passed
267 	 *         in @event is a Key event and has the right modifiers set.
268 	 *
269 	 * Returns: Whether the event triggered the shortcut
270 	 */
271 	public GdkKeyMatch trigger(Event event, bool enableMnemonics)
272 	{
273 		return gtk_shortcut_trigger_trigger(gtkShortcutTrigger, (event is null) ? null : event.getEventStruct(), enableMnemonics);
274 	}
275 }