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.Menu; 26 27 private import gio.MenuItem; 28 private import gio.MenuModel; 29 private import glib.ConstructionException; 30 private import glib.Str; 31 private import gobject.ObjectG; 32 private import gtkc.gio; 33 public import gtkc.giotypes; 34 35 36 /** 37 * #GMenu is a simple implementation of #GMenuModel. 38 * You populate a #GMenu by adding #GMenuItem instances to it. 39 * 40 * There are some convenience functions to allow you to directly 41 * add items (avoiding #GMenuItem) for the common cases. To add 42 * a regular item, use g_menu_insert(). To add a section, use 43 * g_menu_insert_section(). To add a submenu, use 44 * g_menu_insert_submenu(). 45 * 46 * Since: 2.32 47 */ 48 public class Menu : MenuModel 49 { 50 /** the main Gtk struct */ 51 protected GMenu* gMenu; 52 53 /** Get the main Gtk struct */ 54 public GMenu* getMenuStruct() 55 { 56 return gMenu; 57 } 58 59 /** the main Gtk struct as a void* */ 60 protected override void* getStruct() 61 { 62 return cast(void*)gMenu; 63 } 64 65 protected override void setStruct(GObject* obj) 66 { 67 gMenu = cast(GMenu*)obj; 68 super.setStruct(obj); 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GMenu* gMenu, bool ownedRef = false) 75 { 76 this.gMenu = gMenu; 77 super(cast(GMenuModel*)gMenu, ownedRef); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return g_menu_get_type(); 85 } 86 87 /** 88 * Creates a new #GMenu. 89 * 90 * The new menu has no items. 91 * 92 * Return: a new #GMenu 93 * 94 * Since: 2.32 95 * 96 * Throws: ConstructionException GTK+ fails to create the object. 97 */ 98 public this() 99 { 100 auto p = g_menu_new(); 101 102 if(p is null) 103 { 104 throw new ConstructionException("null returned by new"); 105 } 106 107 this(cast(GMenu*) p, true); 108 } 109 110 /** 111 * Convenience function for appending a normal menu item to the end of 112 * @menu. Combine g_menu_item_new() and g_menu_insert_item() for a more 113 * flexible alternative. 114 * 115 * Params: 116 * label = the section label, or %NULL 117 * detailedAction = the detailed action string, or %NULL 118 * 119 * Since: 2.32 120 */ 121 public void append(string label, string detailedAction) 122 { 123 g_menu_append(gMenu, Str.toStringz(label), Str.toStringz(detailedAction)); 124 } 125 126 /** 127 * Appends @item to the end of @menu. 128 * 129 * See g_menu_insert_item() for more information. 130 * 131 * Params: 132 * item = a #GMenuItem to append 133 * 134 * Since: 2.32 135 */ 136 public void appendItem(MenuItem item) 137 { 138 g_menu_append_item(gMenu, (item is null) ? null : item.getMenuItemStruct()); 139 } 140 141 /** 142 * Convenience function for appending a section menu item to the end of 143 * @menu. Combine g_menu_item_new_section() and g_menu_insert_item() for a 144 * more flexible alternative. 145 * 146 * Params: 147 * label = the section label, or %NULL 148 * section = a #GMenuModel with the items of the section 149 * 150 * Since: 2.32 151 */ 152 public void appendSection(string label, MenuModel section) 153 { 154 g_menu_append_section(gMenu, Str.toStringz(label), (section is null) ? null : section.getMenuModelStruct()); 155 } 156 157 /** 158 * Convenience function for appending a submenu menu item to the end of 159 * @menu. Combine g_menu_item_new_submenu() and g_menu_insert_item() for a 160 * more flexible alternative. 161 * 162 * Params: 163 * label = the section label, or %NULL 164 * submenu = a #GMenuModel with the items of the submenu 165 * 166 * Since: 2.32 167 */ 168 public void appendSubmenu(string label, MenuModel submenu) 169 { 170 g_menu_append_submenu(gMenu, Str.toStringz(label), (submenu is null) ? null : submenu.getMenuModelStruct()); 171 } 172 173 /** 174 * Marks @menu as frozen. 175 * 176 * After the menu is frozen, it is an error to attempt to make any 177 * changes to it. In effect this means that the #GMenu API must no 178 * longer be used. 179 * 180 * This function causes g_menu_model_is_mutable() to begin returning 181 * %FALSE, which has some positive performance implications. 182 * 183 * Since: 2.32 184 */ 185 public void freeze() 186 { 187 g_menu_freeze(gMenu); 188 } 189 190 /** 191 * Convenience function for inserting a normal menu item into @menu. 192 * Combine g_menu_item_new() and g_menu_insert_item() for a more flexible 193 * alternative. 194 * 195 * Params: 196 * position = the position at which to insert the item 197 * label = the section label, or %NULL 198 * detailedAction = the detailed action string, or %NULL 199 * 200 * Since: 2.32 201 */ 202 public void insert(int position, string label, string detailedAction) 203 { 204 g_menu_insert(gMenu, position, Str.toStringz(label), Str.toStringz(detailedAction)); 205 } 206 207 /** 208 * Inserts @item into @menu. 209 * 210 * The "insertion" is actually done by copying all of the attribute and 211 * link values of @item and using them to form a new item within @menu. 212 * As such, @item itself is not really inserted, but rather, a menu item 213 * that is exactly the same as the one presently described by @item. 214 * 215 * This means that @item is essentially useless after the insertion 216 * occurs. Any changes you make to it are ignored unless it is inserted 217 * again (at which point its updated values will be copied). 218 * 219 * You should probably just free @item once you're done. 220 * 221 * There are many convenience functions to take care of common cases. 222 * See g_menu_insert(), g_menu_insert_section() and 223 * g_menu_insert_submenu() as well as "prepend" and "append" variants of 224 * each of these functions. 225 * 226 * Params: 227 * position = the position at which to insert the item 228 * item = the #GMenuItem to insert 229 * 230 * Since: 2.32 231 */ 232 public void insertItem(int position, MenuItem item) 233 { 234 g_menu_insert_item(gMenu, position, (item is null) ? null : item.getMenuItemStruct()); 235 } 236 237 /** 238 * Convenience function for inserting a section menu item into @menu. 239 * Combine g_menu_item_new_section() and g_menu_insert_item() for a more 240 * flexible alternative. 241 * 242 * Params: 243 * position = the position at which to insert the item 244 * label = the section label, or %NULL 245 * section = a #GMenuModel with the items of the section 246 * 247 * Since: 2.32 248 */ 249 public void insertSection(int position, string label, MenuModel section) 250 { 251 g_menu_insert_section(gMenu, position, Str.toStringz(label), (section is null) ? null : section.getMenuModelStruct()); 252 } 253 254 /** 255 * Convenience function for inserting a submenu menu item into @menu. 256 * Combine g_menu_item_new_submenu() and g_menu_insert_item() for a more 257 * flexible alternative. 258 * 259 * Params: 260 * position = the position at which to insert the item 261 * label = the section label, or %NULL 262 * submenu = a #GMenuModel with the items of the submenu 263 * 264 * Since: 2.32 265 */ 266 public void insertSubmenu(int position, string label, MenuModel submenu) 267 { 268 g_menu_insert_submenu(gMenu, position, Str.toStringz(label), (submenu is null) ? null : submenu.getMenuModelStruct()); 269 } 270 271 /** 272 * Convenience function for prepending a normal menu item to the start 273 * of @menu. Combine g_menu_item_new() and g_menu_insert_item() for a more 274 * flexible alternative. 275 * 276 * Params: 277 * label = the section label, or %NULL 278 * detailedAction = the detailed action string, or %NULL 279 * 280 * Since: 2.32 281 */ 282 public void prepend(string label, string detailedAction) 283 { 284 g_menu_prepend(gMenu, Str.toStringz(label), Str.toStringz(detailedAction)); 285 } 286 287 /** 288 * Prepends @item to the start of @menu. 289 * 290 * See g_menu_insert_item() for more information. 291 * 292 * Params: 293 * item = a #GMenuItem to prepend 294 * 295 * Since: 2.32 296 */ 297 public void prependItem(MenuItem item) 298 { 299 g_menu_prepend_item(gMenu, (item is null) ? null : item.getMenuItemStruct()); 300 } 301 302 /** 303 * Convenience function for prepending a section menu item to the start 304 * of @menu. Combine g_menu_item_new_section() and g_menu_insert_item() for 305 * a more flexible alternative. 306 * 307 * Params: 308 * label = the section label, or %NULL 309 * section = a #GMenuModel with the items of the section 310 * 311 * Since: 2.32 312 */ 313 public void prependSection(string label, MenuModel section) 314 { 315 g_menu_prepend_section(gMenu, Str.toStringz(label), (section is null) ? null : section.getMenuModelStruct()); 316 } 317 318 /** 319 * Convenience function for prepending a submenu menu item to the start 320 * of @menu. Combine g_menu_item_new_submenu() and g_menu_insert_item() for 321 * a more flexible alternative. 322 * 323 * Params: 324 * label = the section label, or %NULL 325 * submenu = a #GMenuModel with the items of the submenu 326 * 327 * Since: 2.32 328 */ 329 public void prependSubmenu(string label, MenuModel submenu) 330 { 331 g_menu_prepend_submenu(gMenu, Str.toStringz(label), (submenu is null) ? null : submenu.getMenuModelStruct()); 332 } 333 334 /** 335 * Removes an item from the menu. 336 * 337 * @position gives the index of the item to remove. 338 * 339 * It is an error if position is not in range the range from 0 to one 340 * less than the number of items in the menu. 341 * 342 * It is not possible to remove items by identity since items are added 343 * to the menu simply by copying their links and attributes (ie: 344 * identity of the item itself is not preserved). 345 * 346 * Params: 347 * position = the position of the item to remove 348 * 349 * Since: 2.32 350 */ 351 public void remove(int position) 352 { 353 g_menu_remove(gMenu, position); 354 } 355 356 /** 357 * Removes all items in the menu. 358 * 359 * Since: 2.38 360 */ 361 public void removeAll() 362 { 363 g_menu_remove_all(gMenu); 364 } 365 }