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.AccelLabel;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.Closure;
30 private import gobject.ObjectG;
31 private import gtk.Label;
32 private import gtk.Widget;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 
36 
37 /**
38  * The #GtkAccelLabel widget is a subclass of #GtkLabel that also displays an
39  * accelerator key on the right of the label text, e.g. “Ctl+S”.
40  * It is commonly used in menus to show the keyboard short-cuts for commands.
41  * 
42  * The accelerator key to display is typically not set explicitly (although it
43  * can be, with gtk_accel_label_set_accel()). Instead, the #GtkAccelLabel displays
44  * the accelerators which have been added to a particular widget. This widget is
45  * set by calling gtk_accel_label_set_accel_widget().
46  * 
47  * For example, a #GtkMenuItem widget may have an accelerator added to emit
48  * the “activate” signal when the “Ctl+S” key combination is pressed.
49  * A #GtkAccelLabel is created and added to the #GtkMenuItem, and
50  * gtk_accel_label_set_accel_widget() is called with the #GtkMenuItem as the
51  * second argument. The #GtkAccelLabel will now display “Ctl+S” after its label.
52  * 
53  * Note that creating a #GtkMenuItem with gtk_menu_item_new_with_label() (or
54  * one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem)
55  * automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls
56  * gtk_accel_label_set_accel_widget() to set it up for you.
57  * 
58  * A #GtkAccelLabel will only display accelerators which have %GTK_ACCEL_VISIBLE
59  * set (see #GtkAccelFlags).
60  * A #GtkAccelLabel can display multiple accelerators and even signal names,
61  * though it is almost always used to display just one accelerator key.
62  * 
63  * ## Creating a simple menu item with an accelerator key.
64  * 
65  * |[<!-- language="C" -->
66  * GtkWidget *save_item;
67  * GtkAccelGroup *accel_group;
68  * 
69  * // Create a GtkAccelGroup and add it to the window.
70  * accel_group = gtk_accel_group_new ();
71  * gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
72  * 
73  * // Create the menu item using the convenience function.
74  * save_item = gtk_menu_item_new_with_label ("Save");
75  * gtk_widget_show (save_item);
76  * gtk_container_add (GTK_CONTAINER (menu), save_item);
77  * 
78  * // Now add the accelerator to the GtkMenuItem. Note that since we
79  * // called gtk_menu_item_new_with_label() to create the GtkMenuItem
80  * // the GtkAccelLabel is automatically set up to display the
81  * // GtkMenuItem accelerators. We just need to make sure we use
82  * // GTK_ACCEL_VISIBLE here.
83  * gtk_widget_add_accelerator (save_item, "activate", accel_group,
84  * GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
85  * ]|
86  * 
87  * # CSS nodes
88  * 
89  * |[<!-- language="plain" -->
90  * label
91  * ╰── accelerator
92  * ]|
93  * 
94  * Like #GtkLabel, GtkAccelLabel has a main CSS node with the name label.
95  * It adds a subnode with name accelerator.
96  */
97 public class AccelLabel : Label
98 {
99 	/** the main Gtk struct */
100 	protected GtkAccelLabel* gtkAccelLabel;
101 
102 	/** Get the main Gtk struct */
103 	public GtkAccelLabel* getAccelLabelStruct(bool transferOwnership = false)
104 	{
105 		if (transferOwnership)
106 			ownedRef = false;
107 		return gtkAccelLabel;
108 	}
109 
110 	/** the main Gtk struct as a void* */
111 	protected override void* getStruct()
112 	{
113 		return cast(void*)gtkAccelLabel;
114 	}
115 
116 	protected override void setStruct(GObject* obj)
117 	{
118 		gtkAccelLabel = cast(GtkAccelLabel*)obj;
119 		super.setStruct(obj);
120 	}
121 
122 	/**
123 	 * Sets our main struct and passes it to the parent class.
124 	 */
125 	public this (GtkAccelLabel* gtkAccelLabel, bool ownedRef = false)
126 	{
127 		this.gtkAccelLabel = gtkAccelLabel;
128 		super(cast(GtkLabel*)gtkAccelLabel, ownedRef);
129 	}
130 
131 
132 	/** */
133 	public static GType getType()
134 	{
135 		return gtk_accel_label_get_type();
136 	}
137 
138 	/**
139 	 * Creates a new #GtkAccelLabel.
140 	 *
141 	 * Params:
142 	 *     str = the label string. Must be non-%NULL.
143 	 *
144 	 * Returns: a new #GtkAccelLabel.
145 	 *
146 	 * Throws: ConstructionException GTK+ fails to create the object.
147 	 */
148 	public this(string str)
149 	{
150 		auto p = gtk_accel_label_new(Str.toStringz(str));
151 		
152 		if(p is null)
153 		{
154 			throw new ConstructionException("null returned by new");
155 		}
156 		
157 		this(cast(GtkAccelLabel*) p);
158 	}
159 
160 	/**
161 	 * Gets the keyval and modifier mask set with
162 	 * gtk_accel_label_set_accel().
163 	 *
164 	 * Params:
165 	 *     acceleratorKey = return location for the keyval
166 	 *     acceleratorMods = return location for the modifier mask
167 	 *
168 	 * Since: 3.12
169 	 */
170 	public void getAccel(out uint acceleratorKey, out GdkModifierType acceleratorMods)
171 	{
172 		gtk_accel_label_get_accel(gtkAccelLabel, &acceleratorKey, &acceleratorMods);
173 	}
174 
175 	/**
176 	 * Fetches the widget monitored by this accelerator label. See
177 	 * gtk_accel_label_set_accel_widget().
178 	 *
179 	 * Returns: the object monitored by the accelerator label, or %NULL.
180 	 */
181 	public Widget getAccelWidget()
182 	{
183 		auto p = gtk_accel_label_get_accel_widget(gtkAccelLabel);
184 		
185 		if(p is null)
186 		{
187 			return null;
188 		}
189 		
190 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
191 	}
192 
193 	/**
194 	 * Returns the width needed to display the accelerator key(s).
195 	 * This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't
196 	 * be needed by applications.
197 	 *
198 	 * Returns: the width needed to display the accelerator key(s).
199 	 */
200 	public uint getAccelWidth()
201 	{
202 		return gtk_accel_label_get_accel_width(gtkAccelLabel);
203 	}
204 
205 	/**
206 	 * Recreates the string representing the accelerator keys.
207 	 * This should not be needed since the string is automatically updated whenever
208 	 * accelerators are added or removed from the associated widget.
209 	 *
210 	 * Returns: always returns %FALSE.
211 	 */
212 	public bool refetch()
213 	{
214 		return gtk_accel_label_refetch(gtkAccelLabel) != 0;
215 	}
216 
217 	/**
218 	 * Manually sets a keyval and modifier mask as the accelerator rendered
219 	 * by @accel_label.
220 	 *
221 	 * If a keyval and modifier are explicitly set then these values are
222 	 * used regardless of any associated accel closure or widget.
223 	 *
224 	 * Providing an @accelerator_key of 0 removes the manual setting.
225 	 *
226 	 * Params:
227 	 *     acceleratorKey = a keyval, or 0
228 	 *     acceleratorMods = the modifier mask for the accel
229 	 *
230 	 * Since: 3.6
231 	 */
232 	public void setAccel(uint acceleratorKey, GdkModifierType acceleratorMods)
233 	{
234 		gtk_accel_label_set_accel(gtkAccelLabel, acceleratorKey, acceleratorMods);
235 	}
236 
237 	/**
238 	 * Sets the closure to be monitored by this accelerator label. The closure
239 	 * must be connected to an accelerator group; see gtk_accel_group_connect().
240 	 *
241 	 * Params:
242 	 *     accelClosure = the closure to monitor for accelerator changes.
243 	 */
244 	public void setAccelClosure(Closure accelClosure)
245 	{
246 		gtk_accel_label_set_accel_closure(gtkAccelLabel, (accelClosure is null) ? null : accelClosure.getClosureStruct());
247 	}
248 
249 	/**
250 	 * Sets the widget to be monitored by this accelerator label.
251 	 *
252 	 * Params:
253 	 *     accelWidget = the widget to be monitored.
254 	 */
255 	public void setAccelWidget(Widget accelWidget)
256 	{
257 		gtk_accel_label_set_accel_widget(gtkAccelLabel, (accelWidget is null) ? null : accelWidget.getWidgetStruct());
258 	}
259 }