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 * Conversion parameters: 26 * inFile = GtkMenuItem.html 27 * outPack = gtk 28 * outFile = MenuItem 29 * strct = GtkMenuItem 30 * realStrct= 31 * ctorStrct= 32 * clss = MenuItem 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - ActivatableIF 40 * prefixes: 41 * - gtk_menu_item_ 42 * - gtk_ 43 * omit structs: 44 * omit prefixes: 45 * omit code: 46 * - gtk_menu_item_new_with_label 47 * - gtk_menu_item_new_with_mnemonic 48 * omit signals: 49 * imports: 50 * - glib.Str 51 * - gtk.Widget 52 * - gtk.AccelGroup 53 * - gtk.ActivatableT 54 * - gtk.ActivatableIF 55 * structWrap: 56 * - GtkWidget* -> Widget 57 * module aliases: 58 * local aliases: 59 * - activate -> itemActivate 60 * overrides: 61 * - select 62 * - deselect 63 */ 64 65 module gtk.MenuItem; 66 67 public import gtkc.gtktypes; 68 69 private import gtkc.gtk; 70 private import glib.ConstructionException; 71 private import gobject.ObjectG; 72 73 private import gobject.Signals; 74 public import gtkc.gdktypes; 75 76 private import glib.Str; 77 private import gtk.Widget; 78 private import gtk.AccelGroup; 79 private import gtk.ActivatableT; 80 private import gtk.ActivatableIF; 81 82 83 84 private import gtk.Item; 85 86 /** 87 * Description 88 * The GtkMenuItem widget and the derived widgets are the only valid 89 * childs for menus. Their function is to correctly handle highlighting, 90 * alignment, events and submenus. 91 * As it derives from GtkBin it can hold any valid child widget, altough 92 * only a few are really useful. 93 * GtkMenuItem as GtkBuildable 94 * The GtkMenuItem implementation of the GtkBuildable interface 95 * supports adding a submenu by specifying "submenu" as the "type" 96 * attribute of a <child> element. 97 * $(DDOC_COMMENT example) 98 */ 99 public class MenuItem : Item, ActivatableIF 100 { 101 102 /** the main Gtk struct */ 103 protected GtkMenuItem* gtkMenuItem; 104 105 106 public GtkMenuItem* getMenuItemStruct() 107 { 108 return gtkMenuItem; 109 } 110 111 112 /** the main Gtk struct as a void* */ 113 protected override void* getStruct() 114 { 115 return cast(void*)gtkMenuItem; 116 } 117 118 /** 119 * Sets our main struct and passes it to the parent class 120 */ 121 public this (GtkMenuItem* gtkMenuItem) 122 { 123 super(cast(GtkItem*)gtkMenuItem); 124 this.gtkMenuItem = gtkMenuItem; 125 } 126 127 protected override void setStruct(GObject* obj) 128 { 129 super.setStruct(obj); 130 gtkMenuItem = cast(GtkMenuItem*)obj; 131 } 132 133 /** store the action code passed in by the applcation */ 134 private string actionLabel; 135 136 // add the Activatable capabilities 137 mixin ActivatableT!(GtkMenuItem); 138 139 /** Gets the application set action code */ 140 public string getActionName() 141 { 142 if ( actionLabel is null ) 143 { 144 actionLabel = ""; 145 } 146 return actionLabel; 147 } 148 149 /** 150 * Creates a new menu item with a label and a listener and a action. 151 * used for backward compatibily with DUI. 152 */ 153 this(string label, void delegate(MenuItem)dlg, string action) 154 { 155 this(label); 156 this.actionLabel = action; 157 addOnActivate(dlg); 158 } 159 160 161 162 /** 163 * Creates a new Item associated with a "activate" delegate and with a action code 164 * and optionally accelGroup 165 */ 166 public this(void delegate(MenuItem) dlg, string label, string action, 167 bool mnemonic=true, 168 AccelGroup accelGroup=null, 169 char accelKey='\0', 170 GdkModifierType modifierType=GdkModifierType.CONTROL_MASK, 171 GtkAccelFlags accelFlags=GtkAccelFlags.VISIBLE 172 ) 173 { 174 this(label, mnemonic); 175 this.actionLabel = action; 176 addOnActivate(dlg); 177 if ( accelGroup !is null && accelKey != '\0' ) 178 { 179 addAccelerator("activate",accelGroup,accelKey,modifierType,accelFlags); 180 } 181 } 182 183 184 185 /** 186 * Creates a new Item associated with a "activate" delegate 187 */ 188 public this(void delegate(MenuItem) dlg, string label, bool mnemonic=true) 189 { 190 this(label, mnemonic); 191 addOnActivate(dlg); 192 } 193 194 /** 195 * Creates a new GtkMenuItem whose child is a GtkLabel. 196 * Params: 197 * label = the text for the label 198 * mnemonic = if true the label 199 * will be created using gtk_label_new_with_mnemonic(), so underscores 200 * in label indicate the mnemonic for the menu item. 201 * Throws: ConstructionException GTK+ fails to create the object. 202 */ 203 public this (string label, bool mnemonic=true) 204 { 205 GtkMenuItem* p; 206 207 if ( mnemonic ) 208 { 209 // GtkWidget* gtk_menu_item_new_with_mnemonic (const gchar *label); 210 p = cast(GtkMenuItem*)gtk_menu_item_new_with_mnemonic(Str.toStringz(label)); 211 } 212 else 213 { 214 // GtkWidget* gtk_menu_item_new_with_label (const gchar *label); 215 p = cast(GtkMenuItem*)gtk_menu_item_new_with_label(Str.toStringz(label)); 216 } 217 218 if(p is null) 219 { 220 throw new ConstructionException("null returned by gtk_menu_item_new_with_"); 221 } 222 223 this(p); 224 225 setName(label); 226 } 227 228 /** 229 */ 230 int[string] connectedSignals; 231 232 void delegate(MenuItem)[] onActivateListeners; 233 /** 234 * Emitted when the item is activated. 235 */ 236 void addOnActivate(void delegate(MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 237 { 238 if ( !("activate" in connectedSignals) ) 239 { 240 Signals.connectData( 241 getStruct(), 242 "activate", 243 cast(GCallback)&callBackActivate, 244 cast(void*)this, 245 null, 246 connectFlags); 247 connectedSignals["activate"] = 1; 248 } 249 onActivateListeners ~= dlg; 250 } 251 extern(C) static void callBackActivate(GtkMenuItem* menuitemStruct, MenuItem _menuItem) 252 { 253 foreach ( void delegate(MenuItem) dlg ; _menuItem.onActivateListeners ) 254 { 255 dlg(_menuItem); 256 } 257 } 258 259 void delegate(MenuItem)[] onActivateItemListeners; 260 /** 261 * Emitted when the item is activated, but also if the menu item has a 262 * submenu. For normal applications, the relevant signal is "activate". 263 */ 264 void addOnActivateItem(void delegate(MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 265 { 266 if ( !("activate-item" in connectedSignals) ) 267 { 268 Signals.connectData( 269 getStruct(), 270 "activate-item", 271 cast(GCallback)&callBackActivateItem, 272 cast(void*)this, 273 null, 274 connectFlags); 275 connectedSignals["activate-item"] = 1; 276 } 277 onActivateItemListeners ~= dlg; 278 } 279 extern(C) static void callBackActivateItem(GtkMenuItem* menuitemStruct, MenuItem _menuItem) 280 { 281 foreach ( void delegate(MenuItem) dlg ; _menuItem.onActivateItemListeners ) 282 { 283 dlg(_menuItem); 284 } 285 } 286 287 void delegate(gint, MenuItem)[] onToggleSizeAllocateListeners; 288 /** 289 */ 290 void addOnToggleSizeAllocate(void delegate(gint, MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 291 { 292 if ( !("toggle-size-allocate" in connectedSignals) ) 293 { 294 Signals.connectData( 295 getStruct(), 296 "toggle-size-allocate", 297 cast(GCallback)&callBackToggleSizeAllocate, 298 cast(void*)this, 299 null, 300 connectFlags); 301 connectedSignals["toggle-size-allocate"] = 1; 302 } 303 onToggleSizeAllocateListeners ~= dlg; 304 } 305 extern(C) static void callBackToggleSizeAllocate(GtkMenuItem* menuitemStruct, gint arg1, MenuItem _menuItem) 306 { 307 foreach ( void delegate(gint, MenuItem) dlg ; _menuItem.onToggleSizeAllocateListeners ) 308 { 309 dlg(arg1, _menuItem); 310 } 311 } 312 313 void delegate(void*, MenuItem)[] onToggleSizeRequestListeners; 314 /** 315 * See Also 316 * GtkBin 317 * for how to handle the child. 318 * GtkItem 319 * is the abstract class for all sorts of items. 320 * GtkMenuShell 321 * is always the parent of GtkMenuItem. 322 */ 323 void addOnToggleSizeRequest(void delegate(void*, MenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 324 { 325 if ( !("toggle-size-request" in connectedSignals) ) 326 { 327 Signals.connectData( 328 getStruct(), 329 "toggle-size-request", 330 cast(GCallback)&callBackToggleSizeRequest, 331 cast(void*)this, 332 null, 333 connectFlags); 334 connectedSignals["toggle-size-request"] = 1; 335 } 336 onToggleSizeRequestListeners ~= dlg; 337 } 338 extern(C) static void callBackToggleSizeRequest(GtkMenuItem* menuitemStruct, void* arg1, MenuItem _menuItem) 339 { 340 foreach ( void delegate(void*, MenuItem) dlg ; _menuItem.onToggleSizeRequestListeners ) 341 { 342 dlg(arg1, _menuItem); 343 } 344 } 345 346 347 /** 348 * Creates a new GtkMenuItem. 349 * Throws: ConstructionException GTK+ fails to create the object. 350 */ 351 public this () 352 { 353 // GtkWidget * gtk_menu_item_new (void); 354 auto p = gtk_menu_item_new(); 355 if(p is null) 356 { 357 throw new ConstructionException("null returned by gtk_menu_item_new()"); 358 } 359 this(cast(GtkMenuItem*) p); 360 } 361 362 /** 363 * Sets whether the menu item appears justified at the right 364 * side of a menu bar. This was traditionally done for "Help" menu 365 * items, but is now considered a bad idea. (If the widget 366 * layout is reversed for a right-to-left language like Hebrew 367 * or Arabic, right-justified-menu-items appear at the left.) 368 * Params: 369 * rightJustified = if TRUE the menu item will appear at the 370 * far right if added to a menu bar. 371 */ 372 public void setRightJustified(int rightJustified) 373 { 374 // void gtk_menu_item_set_right_justified (GtkMenuItem *menu_item, gboolean right_justified); 375 gtk_menu_item_set_right_justified(gtkMenuItem, rightJustified); 376 } 377 378 /** 379 * Gets whether the menu item appears justified at the right 380 * side of the menu bar. 381 * Returns: TRUE if the menu item will appear at the far right if added to a menu bar. 382 */ 383 public int getRightJustified() 384 { 385 // gboolean gtk_menu_item_get_right_justified (GtkMenuItem *menu_item); 386 return gtk_menu_item_get_right_justified(gtkMenuItem); 387 } 388 389 /** 390 * Sets text on the menu_item label 391 * Since 2.16 392 * Returns: The text in the menu_item label. This is the internal string used by the label, and must not be modified. 393 */ 394 public string getLabel() 395 { 396 // const gchar * gtk_menu_item_get_label (GtkMenuItem *menu_item); 397 return Str.toString(gtk_menu_item_get_label(gtkMenuItem)); 398 } 399 400 /** 401 * Sets text on the menu_item label 402 * Since 2.16 403 * Params: 404 * label = the text you want to set 405 */ 406 public void setLabel(string label) 407 { 408 // void gtk_menu_item_set_label (GtkMenuItem *menu_item, const gchar *label); 409 gtk_menu_item_set_label(gtkMenuItem, Str.toStringz(label)); 410 } 411 412 /** 413 * Checks if an underline in the text indicates the next character should be 414 * used for the mnemonic accelerator key. 415 * Since 2.16 416 * Returns: TRUE if an embedded underline in the label indicates the mnemonic accelerator key. 417 */ 418 public int getUseUnderline() 419 { 420 // gboolean gtk_menu_item_get_use_underline (GtkMenuItem *menu_item); 421 return gtk_menu_item_get_use_underline(gtkMenuItem); 422 } 423 424 /** 425 * If true, an underline in the text indicates the next character should be 426 * used for the mnemonic accelerator key. 427 * Since 2.16 428 * Params: 429 * setting = TRUE if underlines in the text indicate mnemonics 430 */ 431 public void setUseUnderline(int setting) 432 { 433 // void gtk_menu_item_set_use_underline (GtkMenuItem *menu_item, gboolean setting); 434 gtk_menu_item_set_use_underline(gtkMenuItem, setting); 435 } 436 437 /** 438 * Sets or replaces the menu item's submenu, or removes it when a NULL 439 * submenu is passed. 440 * Params: 441 * submenu = the submenu, or NULL. [allow-none] 442 */ 443 public void setSubmenu(Widget submenu) 444 { 445 // void gtk_menu_item_set_submenu (GtkMenuItem *menu_item, GtkWidget *submenu); 446 gtk_menu_item_set_submenu(gtkMenuItem, (submenu is null) ? null : submenu.getWidgetStruct()); 447 } 448 449 /** 450 * Gets the submenu underneath this menu item, if any. 451 * See gtk_menu_item_set_submenu(). 452 * Returns: submenu for this menu item, or NULL if none. [transfer none] 453 */ 454 public Widget getSubmenu() 455 { 456 // GtkWidget * gtk_menu_item_get_submenu (GtkMenuItem *menu_item); 457 auto p = gtk_menu_item_get_submenu(gtkMenuItem); 458 459 if(p is null) 460 { 461 return null; 462 } 463 464 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 465 } 466 467 /** 468 * Warning 469 * gtk_menu_item_remove_submenu has been deprecated since version 2.12 and should not be used in newly-written code. gtk_menu_item_remove_submenu() is deprecated and 470 * should not be used in newly written code. Use 471 * gtk_menu_item_set_submenu() instead. 472 * Removes the widget's submenu. 473 */ 474 public void removeSubmenu() 475 { 476 // void gtk_menu_item_remove_submenu (GtkMenuItem *menu_item); 477 gtk_menu_item_remove_submenu(gtkMenuItem); 478 } 479 480 /** 481 * Set the accelerator path on menu_item, through which runtime changes of the 482 * menu item's accelerator caused by the user can be identified and saved to 483 * persistant storage (see gtk_accel_map_save() on this). 484 * To setup a default accelerator for this menu item, call 485 * gtk_accel_map_add_entry() with the same accel_path. 486 * See also gtk_accel_map_add_entry() on the specifics of accelerator paths, 487 * and gtk_menu_set_accel_path() for a more convenient variant of this function. 488 * This function is basically a convenience wrapper that handles calling 489 * gtk_widget_set_accel_path() with the appropriate accelerator group for 490 * the menu item. 491 * Note that you do need to set an accelerator on the parent menu with 492 * gtk_menu_set_accel_group() for this to work. 493 * Note that accel_path string will be stored in a GQuark. Therefore, if you 494 * pass a static string, you can save some memory by interning it first with 495 * g_intern_static_string(). 496 * Params: 497 * accelPath = accelerator path, corresponding to this menu item's 498 * functionality, or NULL to unset the current path. [allow-none] 499 */ 500 public void setAccelPath(string accelPath) 501 { 502 // void gtk_menu_item_set_accel_path (GtkMenuItem *menu_item, const gchar *accel_path); 503 gtk_menu_item_set_accel_path(gtkMenuItem, Str.toStringz(accelPath)); 504 } 505 506 /** 507 * Retrieve the accelerator path that was previously set on menu_item. 508 * See gtk_menu_item_set_accel_path() for details. 509 * Since 2.14 510 * Returns: the accelerator path corresponding to this menu item's functionality, or NULL if not set 511 */ 512 public string getAccelPath() 513 { 514 // const gchar * gtk_menu_item_get_accel_path (GtkMenuItem *menu_item); 515 return Str.toString(gtk_menu_item_get_accel_path(gtkMenuItem)); 516 } 517 518 /** 519 * Emits the "select" signal on the given item. Behaves exactly like 520 * gtk_item_select. 521 */ 522 public override void select() 523 { 524 // void gtk_menu_item_select (GtkMenuItem *menu_item); 525 gtk_menu_item_select(gtkMenuItem); 526 } 527 528 /** 529 * Emits the "deselect" signal on the given item. Behaves exactly like 530 * gtk_item_deselect. 531 */ 532 public override void deselect() 533 { 534 // void gtk_menu_item_deselect (GtkMenuItem *menu_item); 535 gtk_menu_item_deselect(gtkMenuItem); 536 } 537 538 /** 539 * Emits the "activate" signal on the given item 540 */ 541 public void itemActivate() 542 { 543 // void gtk_menu_item_activate (GtkMenuItem *menu_item); 544 gtk_menu_item_activate(gtkMenuItem); 545 } 546 547 /** 548 * Emits the "toggle_size_request" signal on the given item. 549 * Params: 550 * requisition = the requisition to use as signal data. 551 */ 552 public void toggleSizeRequest(int* requisition) 553 { 554 // void gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item, gint *requisition); 555 gtk_menu_item_toggle_size_request(gtkMenuItem, requisition); 556 } 557 558 /** 559 * Emits the "toggle_size_allocate" signal on the given item. 560 * Params: 561 * allocation = the allocation to use as signal data. 562 */ 563 public void toggleSizeAllocate(int allocation) 564 { 565 // void gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item, gint allocation); 566 gtk_menu_item_toggle_size_allocate(gtkMenuItem, allocation); 567 } 568 }