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