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