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