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.CheckMenuItem; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.MenuItem; 32 private import gtk.Widget; 33 public import gtkc.gdktypes; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 private import std.algorithm; 37 38 39 /** 40 * A #GtkCheckMenuItem is a menu item that maintains the state of a boolean 41 * value in addition to a #GtkMenuItem usual role in activating application 42 * code. 43 * 44 * A check box indicating the state of the boolean value is displayed 45 * at the left side of the #GtkMenuItem. Activating the #GtkMenuItem 46 * toggles the value. 47 * 48 * # CSS nodes 49 * 50 * |[<!-- language="plain" --> 51 * menuitem 52 * ├── check.left 53 * ╰── <child> 54 * ]| 55 * 56 * GtkCheckMenuItem has a main CSS node with name menuitem, and a subnode 57 * with name check, which gets the .left or .right style class. 58 */ 59 public class CheckMenuItem : MenuItem 60 { 61 /** the main Gtk struct */ 62 protected GtkCheckMenuItem* gtkCheckMenuItem; 63 64 /** Get the main Gtk struct */ 65 public GtkCheckMenuItem* getCheckMenuItemStruct() 66 { 67 return gtkCheckMenuItem; 68 } 69 70 /** the main Gtk struct as a void* */ 71 protected override void* getStruct() 72 { 73 return cast(void*)gtkCheckMenuItem; 74 } 75 76 protected override void setStruct(GObject* obj) 77 { 78 gtkCheckMenuItem = cast(GtkCheckMenuItem*)obj; 79 super.setStruct(obj); 80 } 81 82 /** 83 * Sets our main struct and passes it to the parent class. 84 */ 85 public this (GtkCheckMenuItem* gtkCheckMenuItem, bool ownedRef = false) 86 { 87 this.gtkCheckMenuItem = gtkCheckMenuItem; 88 super(cast(GtkMenuItem*)gtkCheckMenuItem, ownedRef); 89 } 90 91 /** 92 * Creates a new GtkCheckMenuItem with a label. 93 * Params: 94 * label = the string to use for the label. 95 * mnemonic = if true the label 96 * will be created using gtk_label_new_with_mnemonic(), so underscores 97 * in label indicate the mnemonic for the menu item. 98 * Throws: ConstructionException GTK+ fails to create the object. 99 */ 100 public this (string label, bool mnemonic=true) 101 { 102 GtkCheckMenuItem* p; 103 104 if ( mnemonic ) 105 { 106 // GtkWidget* gtk_check_menu_item_new_with_mnemonic (const gchar *label); 107 p = cast(GtkCheckMenuItem*)gtk_check_menu_item_new_with_mnemonic(Str.toStringz(label)); 108 } 109 else 110 { 111 // GtkWidget* gtk_check_menu_item_new_with_label (const gchar *label); 112 p = cast(GtkCheckMenuItem*)gtk_check_menu_item_new_with_label(Str.toStringz(label)); 113 } 114 115 if(p is null) 116 { 117 throw new ConstructionException("null returned by gtk_check_menu_item_new_with_"); 118 } 119 120 this(p); 121 } 122 123 /** 124 */ 125 126 /** */ 127 public static GType getType() 128 { 129 return gtk_check_menu_item_get_type(); 130 } 131 132 /** 133 * Creates a new #GtkCheckMenuItem. 134 * 135 * Return: a new #GtkCheckMenuItem. 136 * 137 * Throws: ConstructionException GTK+ fails to create the object. 138 */ 139 public this() 140 { 141 auto p = gtk_check_menu_item_new(); 142 143 if(p is null) 144 { 145 throw new ConstructionException("null returned by new"); 146 } 147 148 this(cast(GtkCheckMenuItem*) p); 149 } 150 151 /** 152 * Returns whether the check menu item is active. See 153 * gtk_check_menu_item_set_active (). 154 * 155 * Return: %TRUE if the menu item is checked. 156 */ 157 public bool getActive() 158 { 159 return gtk_check_menu_item_get_active(gtkCheckMenuItem) != 0; 160 } 161 162 /** 163 * Returns whether @check_menu_item looks like a #GtkRadioMenuItem 164 * 165 * Return: Whether @check_menu_item looks like a #GtkRadioMenuItem 166 * 167 * Since: 2.4 168 */ 169 public bool getDrawAsRadio() 170 { 171 return gtk_check_menu_item_get_draw_as_radio(gtkCheckMenuItem) != 0; 172 } 173 174 /** 175 * Retrieves the value set by gtk_check_menu_item_set_inconsistent(). 176 * 177 * Return: %TRUE if inconsistent 178 */ 179 public bool getInconsistent() 180 { 181 return gtk_check_menu_item_get_inconsistent(gtkCheckMenuItem) != 0; 182 } 183 184 /** 185 * Sets the active state of the menu item’s check box. 186 * 187 * Params: 188 * isActive = boolean value indicating whether the check box is active. 189 */ 190 public void setActive(bool isActive) 191 { 192 gtk_check_menu_item_set_active(gtkCheckMenuItem, isActive); 193 } 194 195 /** 196 * Sets whether @check_menu_item is drawn like a #GtkRadioMenuItem 197 * 198 * Params: 199 * drawAsRadio = whether @check_menu_item is drawn like a #GtkRadioMenuItem 200 * 201 * Since: 2.4 202 */ 203 public void setDrawAsRadio(bool drawAsRadio) 204 { 205 gtk_check_menu_item_set_draw_as_radio(gtkCheckMenuItem, drawAsRadio); 206 } 207 208 /** 209 * If the user has selected a range of elements (such as some text or 210 * spreadsheet cells) that are affected by a boolean setting, and the 211 * current values in that range are inconsistent, you may want to 212 * display the check in an “in between” state. This function turns on 213 * “in between” display. Normally you would turn off the inconsistent 214 * state again if the user explicitly selects a setting. This has to be 215 * done manually, gtk_check_menu_item_set_inconsistent() only affects 216 * visual appearance, it doesn’t affect the semantics of the widget. 217 * 218 * Params: 219 * setting = %TRUE to display an “inconsistent” third state check 220 */ 221 public void setInconsistent(bool setting) 222 { 223 gtk_check_menu_item_set_inconsistent(gtkCheckMenuItem, setting); 224 } 225 226 /** 227 * Emits the #GtkCheckMenuItem::toggled signal. 228 */ 229 public void toggled() 230 { 231 gtk_check_menu_item_toggled(gtkCheckMenuItem); 232 } 233 234 protected class OnToggledDelegateWrapper 235 { 236 void delegate(CheckMenuItem) dlg; 237 gulong handlerId; 238 ConnectFlags flags; 239 this(void delegate(CheckMenuItem) dlg, gulong handlerId, ConnectFlags flags) 240 { 241 this.dlg = dlg; 242 this.handlerId = handlerId; 243 this.flags = flags; 244 } 245 } 246 protected OnToggledDelegateWrapper[] onToggledListeners; 247 248 /** 249 * This signal is emitted when the state of the check box is changed. 250 * 251 * A signal handler can use gtk_check_menu_item_get_active() 252 * to discover the new state. 253 */ 254 gulong addOnToggled(void delegate(CheckMenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 255 { 256 onToggledListeners ~= new OnToggledDelegateWrapper(dlg, 0, connectFlags); 257 onToggledListeners[onToggledListeners.length - 1].handlerId = Signals.connectData( 258 this, 259 "toggled", 260 cast(GCallback)&callBackToggled, 261 cast(void*)onToggledListeners[onToggledListeners.length - 1], 262 cast(GClosureNotify)&callBackToggledDestroy, 263 connectFlags); 264 return onToggledListeners[onToggledListeners.length - 1].handlerId; 265 } 266 267 extern(C) static void callBackToggled(GtkCheckMenuItem* checkmenuitemStruct,OnToggledDelegateWrapper wrapper) 268 { 269 wrapper.dlg(wrapper.outer); 270 } 271 272 extern(C) static void callBackToggledDestroy(OnToggledDelegateWrapper wrapper, GClosure* closure) 273 { 274 wrapper.outer.internalRemoveOnToggled(wrapper); 275 } 276 277 protected void internalRemoveOnToggled(OnToggledDelegateWrapper source) 278 { 279 foreach(index, wrapper; onToggledListeners) 280 { 281 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 282 { 283 onToggledListeners[index] = null; 284 onToggledListeners = std.algorithm.remove(onToggledListeners, index); 285 break; 286 } 287 } 288 } 289 290 }