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.ShortcutAction;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.StringG;
30 private import glib.Variant;
31 private import glib.c.functions;
32 private import gobject.ObjectG;
33 private import gtk.Widget;
34 private import gtk.c.functions;
35 public  import gtk.c.types;
36 
37 
38 /**
39  * `GtkShortcutAction` encodes an action that can be triggered by a
40  * keyboard shortcut.
41  * 
42  * `GtkShortcutActions` contain functions that allow easy presentation
43  * to end users as well as being printed for debugging.
44  * 
45  * All `GtkShortcutActions` are immutable, you can only specify their
46  * properties during construction. If you want to change a action, you
47  * have to replace it with a new one. If you need to pass arguments to
48  * an action, these are specified by the higher-level `GtkShortcut` object.
49  * 
50  * To activate a `GtkShortcutAction` manually, [method@Gtk.ShortcutAction.activate]
51  * can be called.
52  * 
53  * GTK provides various actions:
54  * 
55  * - [class@Gtk.MnemonicAction]: a shortcut action that calls
56  * gtk_widget_mnemonic_activate()
57  * - [class@Gtk.CallbackAction]: a shortcut action that invokes
58  * a given callback
59  * - [class@Gtk.SignalAction]: a shortcut action that emits a
60  * given signal
61  * - [class@Gtk.ActivateAction]: a shortcut action that calls
62  * gtk_widget_activate()
63  * - [class@Gtk.NamedAction]: a shortcut action that calls
64  * gtk_widget_activate_action()
65  * - [class@Gtk.NothingAction]: a shortcut action that does nothing
66  */
67 public class ShortcutAction : ObjectG
68 {
69 	/** the main Gtk struct */
70 	protected GtkShortcutAction* gtkShortcutAction;
71 
72 	/** Get the main Gtk struct */
73 	public GtkShortcutAction* getShortcutActionStruct(bool transferOwnership = false)
74 	{
75 		if (transferOwnership)
76 			ownedRef = false;
77 		return gtkShortcutAction;
78 	}
79 
80 	/** the main Gtk struct as a void* */
81 	protected override void* getStruct()
82 	{
83 		return cast(void*)gtkShortcutAction;
84 	}
85 
86 	/**
87 	 * Sets our main struct and passes it to the parent class.
88 	 */
89 	public this (GtkShortcutAction* gtkShortcutAction, bool ownedRef = false)
90 	{
91 		this.gtkShortcutAction = gtkShortcutAction;
92 		super(cast(GObject*)gtkShortcutAction, ownedRef);
93 	}
94 
95 
96 	/** */
97 	public static GType getType()
98 	{
99 		return gtk_shortcut_action_get_type();
100 	}
101 
102 	/**
103 	 * Tries to parse the given string into an action.
104 	 *
105 	 * On success, the parsed action is returned. When parsing
106 	 * failed, %NULL is returned.
107 	 *
108 	 * The accepted strings are:
109 	 *
110 	 * - `nothing`, for `GtkNothingAction`
111 	 * - `activate`, for `GtkActivateAction`
112 	 * - `mnemonic-activate`, for `GtkMnemonicAction`
113 	 * - `action(NAME)`, for a `GtkNamedAction` for the action named `NAME`
114 	 * - `signal(NAME)`, for a `GtkSignalAction` for the signal `NAME`
115 	 *
116 	 * Params:
117 	 *     string_ = the string to parse
118 	 *
119 	 * Returns: a new `GtkShortcutAction`
120 	 *     or %NULL on error
121 	 *
122 	 * Throws: ConstructionException GTK+ fails to create the object.
123 	 */
124 	public this(string string_)
125 	{
126 		auto __p = gtk_shortcut_action_parse_string(Str.toStringz(string_));
127 
128 		if(__p is null)
129 		{
130 			throw new ConstructionException("null returned by parse_string");
131 		}
132 
133 		this(cast(GtkShortcutAction*) __p, true);
134 	}
135 
136 	/**
137 	 * Activates the action on the @widget with the given @args.
138 	 *
139 	 * Note that some actions ignore the passed in @flags, @widget or @args.
140 	 *
141 	 * Activation of an action can fail for various reasons. If the action
142 	 * is not supported by the @widget, if the @args don't match the action
143 	 * or if the activation otherwise had no effect, %FALSE will be returned.
144 	 *
145 	 * Params:
146 	 *     flags = flags to activate with
147 	 *     widget = Target of the activation
148 	 *     args = arguments to pass
149 	 *
150 	 * Returns: %TRUE if this action was activated successfully
151 	 */
152 	public bool activate(GtkShortcutActionFlags flags, Widget widget, Variant args)
153 	{
154 		return gtk_shortcut_action_activate(gtkShortcutAction, flags, (widget is null) ? null : widget.getWidgetStruct(), (args is null) ? null : args.getVariantStruct()) != 0;
155 	}
156 
157 	/**
158 	 * Prints the given action into a string for the developer.
159 	 *
160 	 * This is meant for debugging and logging.
161 	 *
162 	 * The form of the representation may change at any time and is
163 	 * not guaranteed to stay identical.
164 	 *
165 	 * Params:
166 	 *     string_ = a `GString` to print into
167 	 */
168 	public void print(StringG string_)
169 	{
170 		gtk_shortcut_action_print(gtkShortcutAction, (string_ is null) ? null : string_.getStringGStruct());
171 	}
172 
173 	/**
174 	 * Prints the given action into a human-readable string.
175 	 *
176 	 * This is a small wrapper around [method@Gtk.ShortcutAction.print]
177 	 * to help when debugging.
178 	 *
179 	 * Returns: a new string
180 	 */
181 	public override string toString()
182 	{
183 		auto retStr = gtk_shortcut_action_to_string(gtkShortcutAction);
184 
185 		scope(exit) Str.freeString(retStr);
186 		return Str.toString(retStr);
187 	}
188 }