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