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() 104 { 105 return gtkAccelLabel; 106 } 107 108 /** the main Gtk struct as a void* */ 109 protected override void* getStruct() 110 { 111 return cast(void*)gtkAccelLabel; 112 } 113 114 protected override void setStruct(GObject* obj) 115 { 116 gtkAccelLabel = cast(GtkAccelLabel*)obj; 117 super.setStruct(obj); 118 } 119 120 /** 121 * Sets our main struct and passes it to the parent class. 122 */ 123 public this (GtkAccelLabel* gtkAccelLabel, bool ownedRef = false) 124 { 125 this.gtkAccelLabel = gtkAccelLabel; 126 super(cast(GtkLabel*)gtkAccelLabel, ownedRef); 127 } 128 129 130 /** */ 131 public static GType getType() 132 { 133 return gtk_accel_label_get_type(); 134 } 135 136 /** 137 * Creates a new #GtkAccelLabel. 138 * 139 * Params: 140 * str = the label string. Must be non-%NULL. 141 * 142 * Return: a new #GtkAccelLabel. 143 * 144 * Throws: ConstructionException GTK+ fails to create the object. 145 */ 146 public this(string str) 147 { 148 auto p = gtk_accel_label_new(Str.toStringz(str)); 149 150 if(p is null) 151 { 152 throw new ConstructionException("null returned by new"); 153 } 154 155 this(cast(GtkAccelLabel*) p); 156 } 157 158 /** 159 * Gets the keyval and modifier mask set with 160 * gtk_accel_label_set_accel(). 161 * 162 * Params: 163 * acceleratorKey = return location for the keyval 164 * acceleratorMods = return location for the modifier mask 165 * 166 * Since: 3.12 167 */ 168 public void getAccel(out uint acceleratorKey, out GdkModifierType acceleratorMods) 169 { 170 gtk_accel_label_get_accel(gtkAccelLabel, &acceleratorKey, &acceleratorMods); 171 } 172 173 /** 174 * Fetches the widget monitored by this accelerator label. See 175 * gtk_accel_label_set_accel_widget(). 176 * 177 * Return: the object monitored by the accelerator label, or %NULL. 178 */ 179 public Widget getAccelWidget() 180 { 181 auto p = gtk_accel_label_get_accel_widget(gtkAccelLabel); 182 183 if(p is null) 184 { 185 return null; 186 } 187 188 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 189 } 190 191 /** 192 * Returns the width needed to display the accelerator key(s). 193 * This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't 194 * be needed by applications. 195 * 196 * Return: the width needed to display the accelerator key(s). 197 */ 198 public uint getAccelWidth() 199 { 200 return gtk_accel_label_get_accel_width(gtkAccelLabel); 201 } 202 203 /** 204 * Recreates the string representing the accelerator keys. 205 * This should not be needed since the string is automatically updated whenever 206 * accelerators are added or removed from the associated widget. 207 * 208 * Return: always returns %FALSE. 209 */ 210 public bool refetch() 211 { 212 return gtk_accel_label_refetch(gtkAccelLabel) != 0; 213 } 214 215 /** 216 * Manually sets a keyval and modifier mask as the accelerator rendered 217 * by @accel_label. 218 * 219 * If a keyval and modifier are explicitly set then these values are 220 * used regardless of any associated accel closure or widget. 221 * 222 * Providing an @accelerator_key of 0 removes the manual setting. 223 * 224 * Params: 225 * acceleratorKey = a keyval, or 0 226 * acceleratorMods = the modifier mask for the accel 227 * 228 * Since: 3.6 229 */ 230 public void setAccel(uint acceleratorKey, GdkModifierType acceleratorMods) 231 { 232 gtk_accel_label_set_accel(gtkAccelLabel, acceleratorKey, acceleratorMods); 233 } 234 235 /** 236 * Sets the closure to be monitored by this accelerator label. The closure 237 * must be connected to an accelerator group; see gtk_accel_group_connect(). 238 * 239 * Params: 240 * accelClosure = the closure to monitor for accelerator changes. 241 */ 242 public void setAccelClosure(Closure accelClosure) 243 { 244 gtk_accel_label_set_accel_closure(gtkAccelLabel, (accelClosure is null) ? null : accelClosure.getClosureStruct()); 245 } 246 247 /** 248 * Sets the widget to be monitored by this accelerator label. 249 * 250 * Params: 251 * accelWidget = the widget to be monitored. 252 */ 253 public void setAccelWidget(Widget accelWidget) 254 { 255 gtk_accel_label_set_accel_widget(gtkAccelLabel, (accelWidget is null) ? null : accelWidget.getWidgetStruct()); 256 } 257 }