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