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.ShortcutChord;
20 
21 private import dazzle.c.functions;
22 public  import dazzle.c.types;
23 private import glib.ConstructionException;
24 private import glib.Str;
25 private import gobject.ObjectG;
26 private import gtkd.Loader;
27 
28 
29 /** */
30 public class ShortcutChord
31 {
32 	/** the main Gtk struct */
33 	protected DzlShortcutChord* dzlShortcutChord;
34 	protected bool ownedRef;
35 
36 	/** Get the main Gtk struct */
37 	public DzlShortcutChord* getShortcutChordStruct(bool transferOwnership = false)
38 	{
39 		if (transferOwnership)
40 			ownedRef = false;
41 		return dzlShortcutChord;
42 	}
43 
44 	/** the main Gtk struct as a void* */
45 	protected void* getStruct()
46 	{
47 		return cast(void*)dzlShortcutChord;
48 	}
49 
50 	/**
51 	 * Sets our main struct and passes it to the parent class.
52 	 */
53 	public this (DzlShortcutChord* dzlShortcutChord, bool ownedRef = false)
54 	{
55 		this.dzlShortcutChord = dzlShortcutChord;
56 		this.ownedRef = ownedRef;
57 	}
58 
59 	~this ()
60 	{
61 		if ( Linker.isLoaded(LIBRARY_DAZZLE) && ownedRef )
62 			dzl_shortcut_chord_free(dzlShortcutChord);
63 	}
64 
65 
66 	/** */
67 	public static GType getType()
68 	{
69 		return dzl_shortcut_chord_get_type();
70 	}
71 
72 	/** */
73 	public this(GdkEventKey* event)
74 	{
75 		auto p = dzl_shortcut_chord_new_from_event(event);
76 
77 		if(p is null)
78 		{
79 			throw new ConstructionException("null returned by new_from_event");
80 		}
81 
82 		this(cast(DzlShortcutChord*) p);
83 	}
84 
85 	/** */
86 	public this(string accelerator)
87 	{
88 		auto p = dzl_shortcut_chord_new_from_string(Str.toStringz(accelerator));
89 
90 		if(p is null)
91 		{
92 			throw new ConstructionException("null returned by new_from_string");
93 		}
94 
95 		this(cast(DzlShortcutChord*) p);
96 	}
97 
98 	/** */
99 	public bool appendEvent(GdkEventKey* event)
100 	{
101 		return dzl_shortcut_chord_append_event(dzlShortcutChord, event) != 0;
102 	}
103 
104 	/** */
105 	public ShortcutChord copy()
106 	{
107 		auto p = dzl_shortcut_chord_copy(dzlShortcutChord);
108 
109 		if(p is null)
110 		{
111 			return null;
112 		}
113 
114 		return ObjectG.getDObject!(ShortcutChord)(cast(DzlShortcutChord*) p, true);
115 	}
116 
117 	/** */
118 	public void free()
119 	{
120 		dzl_shortcut_chord_free(dzlShortcutChord);
121 		ownedRef = false;
122 	}
123 
124 	/** */
125 	public string getLabel()
126 	{
127 		auto retStr = dzl_shortcut_chord_get_label(dzlShortcutChord);
128 
129 		scope(exit) Str.freeString(retStr);
130 		return Str.toString(retStr);
131 	}
132 
133 	/** */
134 	public uint getLength()
135 	{
136 		return dzl_shortcut_chord_get_length(dzlShortcutChord);
137 	}
138 
139 	/** */
140 	public void getNthKey(uint nth, uint* keyval, GdkModifierType* modifier)
141 	{
142 		dzl_shortcut_chord_get_nth_key(dzlShortcutChord, nth, keyval, modifier);
143 	}
144 
145 	/** */
146 	public bool hasModifier()
147 	{
148 		return dzl_shortcut_chord_has_modifier(dzlShortcutChord) != 0;
149 	}
150 
151 	/** */
152 	public DzlShortcutMatch match(ShortcutChord other)
153 	{
154 		return dzl_shortcut_chord_match(dzlShortcutChord, (other is null) ? null : other.getShortcutChordStruct());
155 	}
156 
157 	/** */
158 	public override string toString()
159 	{
160 		auto retStr = dzl_shortcut_chord_to_string(dzlShortcutChord);
161 
162 		scope(exit) Str.freeString(retStr);
163 		return Str.toString(retStr);
164 	}
165 
166 	/** */
167 	public static bool equal(void* data1, void* data2)
168 	{
169 		return dzl_shortcut_chord_equal(data1, data2) != 0;
170 	}
171 
172 	/** */
173 	public static uint hash(void* data)
174 	{
175 		return dzl_shortcut_chord_hash(data);
176 	}
177 }