1 /*
2  * This file is part of d-dazzle.
3  *
4  * d-dazzle 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  * d-dazzle 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 d-dazzle; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 module dazzle.ShortcutContext;
20 
21 private import dazzle.ShortcutChord;
22 private import dazzle.c.functions;
23 public  import dazzle.c.types;
24 private import glib.ArrayG;
25 private import glib.ConstructionException;
26 private import glib.ErrorG;
27 private import glib.GException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Value;
31 private import gtk.Widget;
32 
33 
34 /** */
35 public class ShortcutContext : ObjectG
36 {
37 	/** the main Gtk struct */
38 	protected DzlShortcutContext* dzlShortcutContext;
39 
40 	/** Get the main Gtk struct */
41 	public DzlShortcutContext* getShortcutContextStruct(bool transferOwnership = false)
42 	{
43 		if (transferOwnership)
44 			ownedRef = false;
45 		return dzlShortcutContext;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected override void* getStruct()
50 	{
51 		return cast(void*)dzlShortcutContext;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (DzlShortcutContext* dzlShortcutContext, bool ownedRef = false)
58 	{
59 		this.dzlShortcutContext = dzlShortcutContext;
60 		super(cast(GObject*)dzlShortcutContext, ownedRef);
61 	}
62 
63 
64 	/** */
65 	public static GType getType()
66 	{
67 		return dzl_shortcut_context_get_type();
68 	}
69 
70 	/** */
71 	public this(string name)
72 	{
73 		auto p = dzl_shortcut_context_new(Str.toStringz(name));
74 
75 		if(p is null)
76 		{
77 			throw new ConstructionException("null returned by new");
78 		}
79 
80 		this(cast(DzlShortcutContext*) p, true);
81 	}
82 
83 	/** */
84 	public DzlShortcutMatch activate(Widget widget, ShortcutChord chord)
85 	{
86 		return dzl_shortcut_context_activate(dzlShortcutContext, (widget is null) ? null : widget.getWidgetStruct(), (chord is null) ? null : chord.getShortcutChordStruct());
87 	}
88 
89 	/** */
90 	public void addAction(string accel, string detailedActionName)
91 	{
92 		dzl_shortcut_context_add_action(dzlShortcutContext, Str.toStringz(accel), Str.toStringz(detailedActionName));
93 	}
94 
95 	/** */
96 	public void addCommand(string accel, string command)
97 	{
98 		dzl_shortcut_context_add_command(dzlShortcutContext, Str.toStringz(accel), Str.toStringz(command));
99 	}
100 
101 	/** */
102 	public void addSignalVaList(string accel, string signalName, uint nArgs, void* args)
103 	{
104 		dzl_shortcut_context_add_signal_va_list(dzlShortcutContext, Str.toStringz(accel), Str.toStringz(signalName), nArgs, args);
105 	}
106 
107 	/**
108 	 * This is similar to dzl_shortcut_context_add_signal() but is easier to use
109 	 * from language bindings.
110 	 *
111 	 * Params:
112 	 *     accel = the accelerator for the shortcut
113 	 *     signalName = the name of the signal
114 	 *     values = The
115 	 *         values to use when calling the signal.
116 	 */
117 	public void addSignalv(string accel, string signalName, ArrayG values)
118 	{
119 		dzl_shortcut_context_add_signalv(dzlShortcutContext, Str.toStringz(accel), Str.toStringz(signalName), (values is null) ? null : values.getArrayGStruct());
120 	}
121 
122 	/** */
123 	public string getName()
124 	{
125 		return Str.toString(dzl_shortcut_context_get_name(dzlShortcutContext));
126 	}
127 
128 	/** */
129 	public bool loadFromData(string data, ptrdiff_t len)
130 	{
131 		GError* err = null;
132 
133 		auto p = dzl_shortcut_context_load_from_data(dzlShortcutContext, Str.toStringz(data), len, &err) != 0;
134 
135 		if (err !is null)
136 		{
137 			throw new GException( new ErrorG(err) );
138 		}
139 
140 		return p;
141 	}
142 
143 	/** */
144 	public bool loadFromResource(string resourcePath)
145 	{
146 		GError* err = null;
147 
148 		auto p = dzl_shortcut_context_load_from_resource(dzlShortcutContext, Str.toStringz(resourcePath), &err) != 0;
149 
150 		if (err !is null)
151 		{
152 			throw new GException( new ErrorG(err) );
153 		}
154 
155 		return p;
156 	}
157 
158 	/** */
159 	public bool remove(string accel)
160 	{
161 		return dzl_shortcut_context_remove(dzlShortcutContext, Str.toStringz(accel)) != 0;
162 	}
163 }