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 gio.MenuItem; 26 27 private import gio.IconIF; 28 private import gio.MenuModel; 29 private import gio.c.functions; 30 public import gio.c.types; 31 private import glib.ConstructionException; 32 private import glib.Str; 33 private import glib.Variant; 34 private import glib.VariantType; 35 private import gobject.ObjectG; 36 public import gtkc.giotypes; 37 38 39 /** 40 * #GMenuItem is an opaque structure type. You must access it using the 41 * functions below. 42 * 43 * Since: 2.32 44 */ 45 public class MenuItem : ObjectG 46 { 47 /** the main Gtk struct */ 48 protected GMenuItem* gMenuItem; 49 50 /** Get the main Gtk struct */ 51 public GMenuItem* getMenuItemStruct(bool transferOwnership = false) 52 { 53 if (transferOwnership) 54 ownedRef = false; 55 return gMenuItem; 56 } 57 58 /** the main Gtk struct as a void* */ 59 protected override void* getStruct() 60 { 61 return cast(void*)gMenuItem; 62 } 63 64 /** 65 * Sets our main struct and passes it to the parent class. 66 */ 67 public this (GMenuItem* gMenuItem, bool ownedRef = false) 68 { 69 this.gMenuItem = gMenuItem; 70 super(cast(GObject*)gMenuItem, ownedRef); 71 } 72 73 74 /** */ 75 public static GType getType() 76 { 77 return g_menu_item_get_type(); 78 } 79 80 /** 81 * Creates a new #GMenuItem. 82 * 83 * If @label is non-%NULL it is used to set the "label" attribute of the 84 * new item. 85 * 86 * If @detailed_action is non-%NULL it is used to set the "action" and 87 * possibly the "target" attribute of the new item. See 88 * g_menu_item_set_detailed_action() for more information. 89 * 90 * Params: 91 * label = the section label, or %NULL 92 * detailedAction = the detailed action string, or %NULL 93 * 94 * Returns: a new #GMenuItem 95 * 96 * Since: 2.32 97 * 98 * Throws: ConstructionException GTK+ fails to create the object. 99 */ 100 public this(string label, string detailedAction) 101 { 102 auto __p = g_menu_item_new(Str.toStringz(label), Str.toStringz(detailedAction)); 103 104 if(__p is null) 105 { 106 throw new ConstructionException("null returned by new"); 107 } 108 109 this(cast(GMenuItem*) __p, true); 110 } 111 112 /** 113 * Creates a #GMenuItem as an exact copy of an existing menu item in a 114 * #GMenuModel. 115 * 116 * @item_index must be valid (ie: be sure to call 117 * g_menu_model_get_n_items() first). 118 * 119 * Params: 120 * model = a #GMenuModel 121 * itemIndex = the index of an item in @model 122 * 123 * Returns: a new #GMenuItem. 124 * 125 * Since: 2.34 126 * 127 * Throws: ConstructionException GTK+ fails to create the object. 128 */ 129 public this(MenuModel model, int itemIndex) 130 { 131 auto __p = g_menu_item_new_from_model((model is null) ? null : model.getMenuModelStruct(), itemIndex); 132 133 if(__p is null) 134 { 135 throw new ConstructionException("null returned by new_from_model"); 136 } 137 138 this(cast(GMenuItem*) __p, true); 139 } 140 141 /** 142 * Queries the named @attribute on @menu_item. 143 * 144 * If @expected_type is specified and the attribute does not have this 145 * type, %NULL is returned. %NULL is also returned if the attribute 146 * simply does not exist. 147 * 148 * Params: 149 * attribute = the attribute name to query 150 * expectedType = the expected type of the attribute 151 * 152 * Returns: the attribute value, or %NULL 153 * 154 * Since: 2.34 155 */ 156 public Variant getAttributeValue(string attribute, VariantType expectedType) 157 { 158 auto __p = g_menu_item_get_attribute_value(gMenuItem, Str.toStringz(attribute), (expectedType is null) ? null : expectedType.getVariantTypeStruct()); 159 160 if(__p is null) 161 { 162 return null; 163 } 164 165 return new Variant(cast(GVariant*) __p, true); 166 } 167 168 /** 169 * Queries the named @link on @menu_item. 170 * 171 * Params: 172 * link = the link name to query 173 * 174 * Returns: the link, or %NULL 175 * 176 * Since: 2.34 177 */ 178 public MenuModel getLink(string link) 179 { 180 auto __p = g_menu_item_get_link(gMenuItem, Str.toStringz(link)); 181 182 if(__p is null) 183 { 184 return null; 185 } 186 187 return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) __p, true); 188 } 189 190 /** 191 * Sets or unsets the "action" and "target" attributes of @menu_item. 192 * 193 * If @action is %NULL then both the "action" and "target" attributes 194 * are unset (and @target_value is ignored). 195 * 196 * If @action is non-%NULL then the "action" attribute is set. The 197 * "target" attribute is then set to the value of @target_value if it is 198 * non-%NULL or unset otherwise. 199 * 200 * Normal menu items (ie: not submenu, section or other custom item 201 * types) are expected to have the "action" attribute set to identify 202 * the action that they are associated with. The state type of the 203 * action help to determine the disposition of the menu item. See 204 * #GAction and #GActionGroup for an overview of actions. 205 * 206 * In general, clicking on the menu item will result in activation of 207 * the named action with the "target" attribute given as the parameter 208 * to the action invocation. If the "target" attribute is not set then 209 * the action is invoked with no parameter. 210 * 211 * If the action has no state then the menu item is usually drawn as a 212 * plain menu item (ie: with no additional decoration). 213 * 214 * If the action has a boolean state then the menu item is usually drawn 215 * as a toggle menu item (ie: with a checkmark or equivalent 216 * indication). The item should be marked as 'toggled' or 'checked' 217 * when the boolean state is %TRUE. 218 * 219 * If the action has a string state then the menu item is usually drawn 220 * as a radio menu item (ie: with a radio bullet or equivalent 221 * indication). The item should be marked as 'selected' when the string 222 * state is equal to the value of the @target property. 223 * 224 * See g_menu_item_set_action_and_target() or 225 * g_menu_item_set_detailed_action() for two equivalent calls that are 226 * probably more convenient for most uses. 227 * 228 * Params: 229 * action = the name of the action for this item 230 * targetValue = a #GVariant to use as the action target 231 * 232 * Since: 2.32 233 */ 234 public void setActionAndTargetValue(string action, Variant targetValue) 235 { 236 g_menu_item_set_action_and_target_value(gMenuItem, Str.toStringz(action), (targetValue is null) ? null : targetValue.getVariantStruct()); 237 } 238 239 /** 240 * Sets or unsets an attribute on @menu_item. 241 * 242 * The attribute to set or unset is specified by @attribute. This 243 * can be one of the standard attribute names %G_MENU_ATTRIBUTE_LABEL, 244 * %G_MENU_ATTRIBUTE_ACTION, %G_MENU_ATTRIBUTE_TARGET, or a custom 245 * attribute name. 246 * Attribute names are restricted to lowercase characters, numbers 247 * and '-'. Furthermore, the names must begin with a lowercase character, 248 * must not end with a '-', and must not contain consecutive dashes. 249 * 250 * must consist only of lowercase 251 * ASCII characters, digits and '-'. 252 * 253 * If @value is non-%NULL then it is used as the new value for the 254 * attribute. If @value is %NULL then the attribute is unset. If 255 * the @value #GVariant is floating, it is consumed. 256 * 257 * See also g_menu_item_set_attribute() for a more convenient way to do 258 * the same. 259 * 260 * Params: 261 * attribute = the attribute to set 262 * value = a #GVariant to use as the value, or %NULL 263 * 264 * Since: 2.32 265 */ 266 public void setAttributeValue(string attribute, Variant value) 267 { 268 g_menu_item_set_attribute_value(gMenuItem, Str.toStringz(attribute), (value is null) ? null : value.getVariantStruct()); 269 } 270 271 /** 272 * Sets the "action" and possibly the "target" attribute of @menu_item. 273 * 274 * The format of @detailed_action is the same format parsed by 275 * g_action_parse_detailed_name(). 276 * 277 * See g_menu_item_set_action_and_target() or 278 * g_menu_item_set_action_and_target_value() for more flexible (but 279 * slightly less convenient) alternatives. 280 * 281 * See also g_menu_item_set_action_and_target_value() for a description of 282 * the semantics of the action and target attributes. 283 * 284 * Params: 285 * detailedAction = the "detailed" action string 286 * 287 * Since: 2.32 288 */ 289 public void setDetailedAction(string detailedAction) 290 { 291 g_menu_item_set_detailed_action(gMenuItem, Str.toStringz(detailedAction)); 292 } 293 294 /** 295 * Sets (or unsets) the icon on @menu_item. 296 * 297 * This call is the same as calling g_icon_serialize() and using the 298 * result as the value to g_menu_item_set_attribute_value() for 299 * %G_MENU_ATTRIBUTE_ICON. 300 * 301 * This API is only intended for use with "noun" menu items; things like 302 * bookmarks or applications in an "Open With" menu. Don't use it on 303 * menu items corresponding to verbs (eg: stock icons for 'Save' or 304 * 'Quit'). 305 * 306 * If @icon is %NULL then the icon is unset. 307 * 308 * Params: 309 * icon = a #GIcon, or %NULL 310 * 311 * Since: 2.38 312 */ 313 public void setIcon(IconIF icon) 314 { 315 g_menu_item_set_icon(gMenuItem, (icon is null) ? null : icon.getIconStruct()); 316 } 317 318 /** 319 * Sets or unsets the "label" attribute of @menu_item. 320 * 321 * If @label is non-%NULL it is used as the label for the menu item. If 322 * it is %NULL then the label attribute is unset. 323 * 324 * Params: 325 * label = the label to set, or %NULL to unset 326 * 327 * Since: 2.32 328 */ 329 public void setLabel(string label) 330 { 331 g_menu_item_set_label(gMenuItem, Str.toStringz(label)); 332 } 333 334 /** 335 * Creates a link from @menu_item to @model if non-%NULL, or unsets it. 336 * 337 * Links are used to establish a relationship between a particular menu 338 * item and another menu. For example, %G_MENU_LINK_SUBMENU is used to 339 * associate a submenu with a particular menu item, and %G_MENU_LINK_SECTION 340 * is used to create a section. Other types of link can be used, but there 341 * is no guarantee that clients will be able to make sense of them. 342 * Link types are restricted to lowercase characters, numbers 343 * and '-'. Furthermore, the names must begin with a lowercase character, 344 * must not end with a '-', and must not contain consecutive dashes. 345 * 346 * Params: 347 * link = type of link to establish or unset 348 * model = the #GMenuModel to link to (or %NULL to unset) 349 * 350 * Since: 2.32 351 */ 352 public void setLink(string link, MenuModel model) 353 { 354 g_menu_item_set_link(gMenuItem, Str.toStringz(link), (model is null) ? null : model.getMenuModelStruct()); 355 } 356 357 /** 358 * Sets or unsets the "section" link of @menu_item to @section. 359 * 360 * The effect of having one menu appear as a section of another is 361 * exactly as it sounds: the items from @section become a direct part of 362 * the menu that @menu_item is added to. See g_menu_item_new_section() 363 * for more information about what it means for a menu item to be a 364 * section. 365 * 366 * Params: 367 * section = a #GMenuModel, or %NULL 368 * 369 * Since: 2.32 370 */ 371 public void setSection(MenuModel section) 372 { 373 g_menu_item_set_section(gMenuItem, (section is null) ? null : section.getMenuModelStruct()); 374 } 375 376 /** 377 * Sets or unsets the "submenu" link of @menu_item to @submenu. 378 * 379 * If @submenu is non-%NULL, it is linked to. If it is %NULL then the 380 * link is unset. 381 * 382 * The effect of having one menu appear as a submenu of another is 383 * exactly as it sounds. 384 * 385 * Params: 386 * submenu = a #GMenuModel, or %NULL 387 * 388 * Since: 2.32 389 */ 390 public void setSubmenu(MenuModel submenu) 391 { 392 g_menu_item_set_submenu(gMenuItem, (submenu is null) ? null : submenu.getMenuModelStruct()); 393 } 394 }