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 = GtkActionGroup.html 27 * outPack = gtk 28 * outFile = ActionGroup 29 * strct = GtkActionGroup 30 * realStrct= 31 * ctorStrct= 32 * clss = ActionGroup 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - BuildableIF 40 * prefixes: 41 * - gtk_action_group_ 42 * - gtk_ 43 * omit structs: 44 * omit prefixes: 45 * omit code: 46 * omit signals: 47 * imports: 48 * - glib.Str 49 * - gtk.Action 50 * - glib.ListG 51 * - gtk.Widget 52 * - gtk.BuildableIF 53 * - gtk.BuildableT 54 * structWrap: 55 * - GList* -> ListG 56 * - GtkAction* -> Action 57 * - GtkWidget* -> Widget 58 * module aliases: 59 * local aliases: 60 * overrides: 61 */ 62 63 module gtk.ActionGroup; 64 65 public import gtkc.gtktypes; 66 67 private import gtkc.gtk; 68 private import glib.ConstructionException; 69 private import gobject.ObjectG; 70 71 private import gobject.Signals; 72 public import gtkc.gdktypes; 73 74 private import glib.Str; 75 private import gtk.Action; 76 private import glib.ListG; 77 private import gtk.Widget; 78 private import gtk.BuildableIF; 79 private import gtk.BuildableT; 80 81 82 83 private import gobject.ObjectG; 84 85 /** 86 * Description 87 * Actions are organised into groups. An action group is essentially a 88 * map from names to GtkAction objects. 89 * All actions that would make sense to use in a particular context 90 * should be in a single group. Multiple action groups may be used for a 91 * particular user interface. In fact, it is expected that most nontrivial 92 * applications will make use of multiple groups. For example, in an application 93 * that can edit multiple documents, one group holding global actions 94 * (e.g. quit, about, new), and one group per document holding actions that 95 * act on that document (eg. save, cut/copy/paste, etc). Each window's menus 96 * would be constructed from a combination of two action groups. 97 * Accelerators are handled by the GTK+ accelerator map. All actions are assigned an 98 * accelerator path (which normally has the form 99 * <Actions>/group-name/action-name) 100 * and a shortcut is associated with this accelerator path. All menuitems and 101 * toolitems take on this accelerator path. The GTK+ accelerator map code makes 102 * sure that the correct shortcut is displayed next to the menu item. 103 * GtkActionGroup as GtkBuildable 104 * The GtkActionGroup implementation of the GtkBuildable interface accepts 105 * GtkAction objects as <child> elements in UI definitions. 106 * Note that it is probably more common to define actions and action groups 107 * in the code, since they are directly related to what the code can do. 108 * The GtkActionGroup implementation of the GtkBuildable interface supports a 109 * custom <accelerator> element, which has attributes named key and 110 * modifiers and allows to specify accelerators. This is similar to the 111 * <accelerator> element of GtkWidget, the main difference is that 112 * it doesn't allow you to specify a signal. 113 * $(DDOC_COMMENT example) 114 */ 115 public class ActionGroup : ObjectG, BuildableIF 116 { 117 118 /** the main Gtk struct */ 119 protected GtkActionGroup* gtkActionGroup; 120 121 122 public GtkActionGroup* getActionGroupStruct() 123 { 124 return gtkActionGroup; 125 } 126 127 128 /** the main Gtk struct as a void* */ 129 protected override void* getStruct() 130 { 131 return cast(void*)gtkActionGroup; 132 } 133 134 /** 135 * Sets our main struct and passes it to the parent class 136 */ 137 public this (GtkActionGroup* gtkActionGroup) 138 { 139 super(cast(GObject*)gtkActionGroup); 140 this.gtkActionGroup = gtkActionGroup; 141 } 142 143 protected override void setStruct(GObject* obj) 144 { 145 super.setStruct(obj); 146 gtkActionGroup = cast(GtkActionGroup*)obj; 147 } 148 149 // add the Buildable capabilities 150 mixin BuildableT!(GtkActionGroup); 151 152 /** 153 */ 154 int[string] connectedSignals; 155 156 void delegate(Action, Widget, ActionGroup)[] onConnectProxyListeners; 157 /** 158 * The ::connect-proxy signal is emitted after connecting a proxy to 159 * an action in the group. Note that the proxy may have been connected 160 * to a different action before. 161 * This is intended for simple customizations for which a custom action 162 * class would be too clumsy, e.g. showing tooltips for menuitems in the 163 * statusbar. 164 * GtkUIManager proxies the signal and provides global notification 165 * just before any action is connected to a proxy, which is probably more 166 * convenient to use. 167 * Since 2.4 168 */ 169 void addOnConnectProxy(void delegate(Action, Widget, ActionGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 170 { 171 if ( !("connect-proxy" in connectedSignals) ) 172 { 173 Signals.connectData( 174 getStruct(), 175 "connect-proxy", 176 cast(GCallback)&callBackConnectProxy, 177 cast(void*)this, 178 null, 179 connectFlags); 180 connectedSignals["connect-proxy"] = 1; 181 } 182 onConnectProxyListeners ~= dlg; 183 } 184 extern(C) static void callBackConnectProxy(GtkActionGroup* actionGroupStruct, GtkAction* action, GtkWidget* proxy, ActionGroup _actionGroup) 185 { 186 foreach ( void delegate(Action, Widget, ActionGroup) dlg ; _actionGroup.onConnectProxyListeners ) 187 { 188 dlg(ObjectG.getDObject!(Action)(action), ObjectG.getDObject!(Widget)(proxy), _actionGroup); 189 } 190 } 191 192 void delegate(Action, Widget, ActionGroup)[] onDisconnectProxyListeners; 193 /** 194 * The ::disconnect-proxy signal is emitted after disconnecting a proxy 195 * from an action in the group. 196 * GtkUIManager proxies the signal and provides global notification 197 * just before any action is connected to a proxy, which is probably more 198 * convenient to use. 199 * Since 2.4 200 */ 201 void addOnDisconnectProxy(void delegate(Action, Widget, ActionGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 202 { 203 if ( !("disconnect-proxy" in connectedSignals) ) 204 { 205 Signals.connectData( 206 getStruct(), 207 "disconnect-proxy", 208 cast(GCallback)&callBackDisconnectProxy, 209 cast(void*)this, 210 null, 211 connectFlags); 212 connectedSignals["disconnect-proxy"] = 1; 213 } 214 onDisconnectProxyListeners ~= dlg; 215 } 216 extern(C) static void callBackDisconnectProxy(GtkActionGroup* actionGroupStruct, GtkAction* action, GtkWidget* proxy, ActionGroup _actionGroup) 217 { 218 foreach ( void delegate(Action, Widget, ActionGroup) dlg ; _actionGroup.onDisconnectProxyListeners ) 219 { 220 dlg(ObjectG.getDObject!(Action)(action), ObjectG.getDObject!(Widget)(proxy), _actionGroup); 221 } 222 } 223 224 void delegate(Action, ActionGroup)[] onPostActivateListeners; 225 /** 226 * The ::post-activate signal is emitted just after the action in the 227 * action_group is activated 228 * This is intended for GtkUIManager to proxy the signal and provide global 229 * notification just after any action is activated. 230 * Since 2.4 231 */ 232 void addOnPostActivate(void delegate(Action, ActionGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 233 { 234 if ( !("post-activate" in connectedSignals) ) 235 { 236 Signals.connectData( 237 getStruct(), 238 "post-activate", 239 cast(GCallback)&callBackPostActivate, 240 cast(void*)this, 241 null, 242 connectFlags); 243 connectedSignals["post-activate"] = 1; 244 } 245 onPostActivateListeners ~= dlg; 246 } 247 extern(C) static void callBackPostActivate(GtkActionGroup* actionGroupStruct, GtkAction* action, ActionGroup _actionGroup) 248 { 249 foreach ( void delegate(Action, ActionGroup) dlg ; _actionGroup.onPostActivateListeners ) 250 { 251 dlg(ObjectG.getDObject!(Action)(action), _actionGroup); 252 } 253 } 254 255 void delegate(Action, ActionGroup)[] onPreActivateListeners; 256 /** 257 * The ::pre-activate signal is emitted just before the action in the 258 * action_group is activated 259 * This is intended for GtkUIManager to proxy the signal and provide global 260 * notification just before any action is activated. 261 * Since 2.4 262 */ 263 void addOnPreActivate(void delegate(Action, ActionGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 264 { 265 if ( !("pre-activate" in connectedSignals) ) 266 { 267 Signals.connectData( 268 getStruct(), 269 "pre-activate", 270 cast(GCallback)&callBackPreActivate, 271 cast(void*)this, 272 null, 273 connectFlags); 274 connectedSignals["pre-activate"] = 1; 275 } 276 onPreActivateListeners ~= dlg; 277 } 278 extern(C) static void callBackPreActivate(GtkActionGroup* actionGroupStruct, GtkAction* action, ActionGroup _actionGroup) 279 { 280 foreach ( void delegate(Action, ActionGroup) dlg ; _actionGroup.onPreActivateListeners ) 281 { 282 dlg(ObjectG.getDObject!(Action)(action), _actionGroup); 283 } 284 } 285 286 287 /** 288 * Creates a new GtkActionGroup object. The name of the action group 289 * is used when associating keybindings 290 * with the actions. 291 * Since 2.4 292 * Params: 293 * name = the name of the action group. 294 * Throws: ConstructionException GTK+ fails to create the object. 295 */ 296 public this (string name) 297 { 298 // GtkActionGroup * gtk_action_group_new (const gchar *name); 299 auto p = gtk_action_group_new(Str.toStringz(name)); 300 if(p is null) 301 { 302 throw new ConstructionException("null returned by gtk_action_group_new(Str.toStringz(name))"); 303 } 304 this(cast(GtkActionGroup*) p); 305 } 306 307 /** 308 * Gets the name of the action group. 309 * Since 2.4 310 * Returns: the name of the action group. 311 */ 312 public string getName() 313 { 314 // const gchar * gtk_action_group_get_name (GtkActionGroup *action_group); 315 return Str.toString(gtk_action_group_get_name(gtkActionGroup)); 316 } 317 318 /** 319 * Returns TRUE if the group is sensitive. The constituent actions 320 * can only be logically sensitive (see gtk_action_is_sensitive()) if 321 * they are sensitive (see gtk_action_get_sensitive()) and their group 322 * is sensitive. 323 * Since 2.4 324 * Returns: TRUE if the group is sensitive. 325 */ 326 public int getSensitive() 327 { 328 // gboolean gtk_action_group_get_sensitive (GtkActionGroup *action_group); 329 return gtk_action_group_get_sensitive(gtkActionGroup); 330 } 331 332 /** 333 * Changes the sensitivity of action_group 334 * Since 2.4 335 * Params: 336 * sensitive = new sensitivity 337 */ 338 public void setSensitive(int sensitive) 339 { 340 // void gtk_action_group_set_sensitive (GtkActionGroup *action_group, gboolean sensitive); 341 gtk_action_group_set_sensitive(gtkActionGroup, sensitive); 342 } 343 344 /** 345 * Returns TRUE if the group is visible. The constituent actions 346 * can only be logically visible (see gtk_action_is_visible()) if 347 * they are visible (see gtk_action_get_visible()) and their group 348 * is visible. 349 * Since 2.4 350 * Returns: TRUE if the group is visible. 351 */ 352 public int getVisible() 353 { 354 // gboolean gtk_action_group_get_visible (GtkActionGroup *action_group); 355 return gtk_action_group_get_visible(gtkActionGroup); 356 } 357 358 /** 359 * Changes the visible of action_group. 360 * Since 2.4 361 * Params: 362 * visible = new visiblity 363 */ 364 public void setVisible(int visible) 365 { 366 // void gtk_action_group_set_visible (GtkActionGroup *action_group, gboolean visible); 367 gtk_action_group_set_visible(gtkActionGroup, visible); 368 } 369 370 /** 371 * Looks up an action in the action group by name. 372 * Since 2.4 373 * Params: 374 * actionName = the name of the action 375 * Returns: the action, or NULL if no action by that name exists. [transfer none] 376 */ 377 public Action getAction(string actionName) 378 { 379 // GtkAction * gtk_action_group_get_action (GtkActionGroup *action_group, const gchar *action_name); 380 auto p = gtk_action_group_get_action(gtkActionGroup, Str.toStringz(actionName)); 381 382 if(p is null) 383 { 384 return null; 385 } 386 387 return ObjectG.getDObject!(Action)(cast(GtkAction*) p); 388 } 389 390 /** 391 * Lists the actions in the action group. 392 * Since 2.4 393 * Returns: an allocated list of the action objects in the action group. [element-type GtkAction][transfer container] 394 */ 395 public ListG listActions() 396 { 397 // GList * gtk_action_group_list_actions (GtkActionGroup *action_group); 398 auto p = gtk_action_group_list_actions(gtkActionGroup); 399 400 if(p is null) 401 { 402 return null; 403 } 404 405 return ObjectG.getDObject!(ListG)(cast(GList*) p); 406 } 407 408 /** 409 * Adds an action object to the action group. Note that this function 410 * does not set up the accel path of the action, which can lead to problems 411 * if a user tries to modify the accelerator of a menuitem associated with 412 * the action. Therefore you must either set the accel path yourself with 413 * gtk_action_set_accel_path(), or use 414 * gtk_action_group_add_action_with_accel (..., NULL). 415 * Since 2.4 416 * Params: 417 * action = an action 418 */ 419 public void addAction(Action action) 420 { 421 // void gtk_action_group_add_action (GtkActionGroup *action_group, GtkAction *action); 422 gtk_action_group_add_action(gtkActionGroup, (action is null) ? null : action.getActionStruct()); 423 } 424 425 /** 426 * Adds an action object to the action group and sets up the accelerator. 427 * If accelerator is NULL, attempts to use the accelerator associated 428 * with the stock_id of the action. 429 * Accel paths are set to 430 * <Actions>/group-name/action-name. 431 * Since 2.4 432 * Params: 433 * action = the action to add 434 * accelerator = the accelerator for the action, in 435 * the format understood by gtk_accelerator_parse(), or "" for no accelerator, or 436 * NULL to use the stock accelerator. [allow-none] 437 */ 438 public void addActionWithAccel(Action action, string accelerator) 439 { 440 // void gtk_action_group_add_action_with_accel (GtkActionGroup *action_group, GtkAction *action, const gchar *accelerator); 441 gtk_action_group_add_action_with_accel(gtkActionGroup, (action is null) ? null : action.getActionStruct(), Str.toStringz(accelerator)); 442 } 443 444 /** 445 * Removes an action object from the action group. 446 * Since 2.4 447 * Params: 448 * action = an action 449 */ 450 public void removeAction(Action action) 451 { 452 // void gtk_action_group_remove_action (GtkActionGroup *action_group, GtkAction *action); 453 gtk_action_group_remove_action(gtkActionGroup, (action is null) ? null : action.getActionStruct()); 454 } 455 456 /** 457 * This is a convenience function to create a number of actions and add them 458 * to the action group. 459 * The "activate" signals of the actions are connected to the callbacks and 460 * their accel paths are set to 461 * <Actions>/group-name/action-name. 462 * Since 2.4 463 * Params: 464 * entries = an array of action descriptions 465 * userData = data to pass to the action callbacks 466 */ 467 public void addActions(GtkActionEntry[] entries, void* userData) 468 { 469 // void gtk_action_group_add_actions (GtkActionGroup *action_group, const GtkActionEntry *entries, guint n_entries, gpointer user_data); 470 gtk_action_group_add_actions(gtkActionGroup, entries.ptr, cast(int) entries.length, userData); 471 } 472 473 /** 474 * This variant of gtk_action_group_add_actions() adds a GDestroyNotify 475 * callback for user_data. 476 * Since 2.4 477 * Params: 478 * entries = an array of action descriptions 479 * userData = data to pass to the action callbacks 480 * destroy = destroy notification callback for user_data 481 */ 482 public void addActionsFull(GtkActionEntry[] entries, void* userData, GDestroyNotify destroy) 483 { 484 // void gtk_action_group_add_actions_full (GtkActionGroup *action_group, const GtkActionEntry *entries, guint n_entries, gpointer user_data, GDestroyNotify destroy); 485 gtk_action_group_add_actions_full(gtkActionGroup, entries.ptr, cast(int) entries.length, userData, destroy); 486 } 487 488 /** 489 * This is a convenience function to create a number of toggle actions and add them 490 * to the action group. 491 * The "activate" signals of the actions are connected to the callbacks and 492 * their accel paths are set to 493 * <Actions>/group-name/action-name. 494 * Since 2.4 495 * Params: 496 * entries = an array of toggle action descriptions 497 * userData = data to pass to the action callbacks 498 */ 499 public void addToggleActions(GtkToggleActionEntry[] entries, void* userData) 500 { 501 // void gtk_action_group_add_toggle_actions (GtkActionGroup *action_group, const GtkToggleActionEntry *entries, guint n_entries, gpointer user_data); 502 gtk_action_group_add_toggle_actions(gtkActionGroup, entries.ptr, cast(int) entries.length, userData); 503 } 504 505 /** 506 * This variant of gtk_action_group_add_toggle_actions() adds a 507 * GDestroyNotify callback for user_data. 508 * Since 2.4 509 * Params: 510 * entries = an array of toggle action descriptions 511 * userData = data to pass to the action callbacks 512 * destroy = destroy notification callback for user_data 513 */ 514 public void addToggleActionsFull(GtkToggleActionEntry[] entries, void* userData, GDestroyNotify destroy) 515 { 516 // void gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group, const GtkToggleActionEntry *entries, guint n_entries, gpointer user_data, GDestroyNotify destroy); 517 gtk_action_group_add_toggle_actions_full(gtkActionGroup, entries.ptr, cast(int) entries.length, userData, destroy); 518 } 519 520 /** 521 * This is a convenience routine to create a group of radio actions and 522 * add them to the action group. 523 * The "changed" signal of the first radio action is connected to the 524 * on_change callback and the accel paths of the actions are set to 525 * <Actions>/group-name/action-name. 526 * Since 2.4 527 * Params: 528 * entries = an array of radio action descriptions 529 * value = the value of the action to activate initially, or -1 if 530 * no action should be activated 531 * onChange = the callback to connect to the changed signal 532 * userData = data to pass to the action callbacks 533 */ 534 public void addRadioActions(GtkRadioActionEntry[] entries, int value, GCallback onChange, void* userData) 535 { 536 // void gtk_action_group_add_radio_actions (GtkActionGroup *action_group, const GtkRadioActionEntry *entries, guint n_entries, gint value, GCallback on_change, gpointer user_data); 537 gtk_action_group_add_radio_actions(gtkActionGroup, entries.ptr, cast(int) entries.length, value, onChange, userData); 538 } 539 540 /** 541 * This variant of gtk_action_group_add_radio_actions() adds a 542 * GDestroyNotify callback for user_data. 543 * Since 2.4 544 * Params: 545 * entries = an array of radio action descriptions 546 * value = the value of the action to activate initially, or -1 if 547 * no action should be activated 548 * onChange = the callback to connect to the changed signal 549 * userData = data to pass to the action callbacks 550 * destroy = destroy notification callback for user_data 551 */ 552 public void addRadioActionsFull(GtkRadioActionEntry[] entries, int value, GCallback onChange, void* userData, GDestroyNotify destroy) 553 { 554 // void gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group, const GtkRadioActionEntry *entries, guint n_entries, gint value, GCallback on_change, gpointer user_data, GDestroyNotify destroy); 555 gtk_action_group_add_radio_actions_full(gtkActionGroup, entries.ptr, cast(int) entries.length, value, onChange, userData, destroy); 556 } 557 558 /** 559 * Sets a function to be used for translating the label and tooltip of 560 * GtkActionGroupEntrys added by gtk_action_group_add_actions(). 561 * If you're using gettext(), it is enough to set the translation domain 562 * with gtk_action_group_set_translation_domain(). 563 * Since 2.4 564 * Params: 565 * func = a GtkTranslateFunc 566 * data = data to be passed to func and notify 567 * notify = a GDestroyNotify function to be called when action_group is 568 * destroyed and when the translation function is changed again 569 */ 570 public void setTranslateFunc(GtkTranslateFunc func, void* data, GDestroyNotify notify) 571 { 572 // void gtk_action_group_set_translate_func (GtkActionGroup *action_group, GtkTranslateFunc func, gpointer data, GDestroyNotify notify); 573 gtk_action_group_set_translate_func(gtkActionGroup, func, data, notify); 574 } 575 576 /** 577 * Sets the translation domain and uses g_dgettext() for translating the 578 * label and tooltip of GtkActionEntrys added by 579 * gtk_action_group_add_actions(). 580 * If you're not using gettext() for localization, see 581 * gtk_action_group_set_translate_func(). 582 * Since 2.4 583 * Params: 584 * domain = the translation domain to use for g_dgettext() calls 585 */ 586 public void setTranslationDomain(string domain) 587 { 588 // void gtk_action_group_set_translation_domain (GtkActionGroup *action_group, const gchar *domain); 589 gtk_action_group_set_translation_domain(gtkActionGroup, Str.toStringz(domain)); 590 } 591 592 /** 593 * Translates a string using the specified translate_func(). This 594 * is mainly intended for language bindings. 595 * Since 2.6 596 * Params: 597 * string = a string 598 * Returns: the translation of string 599 */ 600 public string translateString(string string) 601 { 602 // const gchar * gtk_action_group_translate_string (GtkActionGroup *action_group, const gchar *string); 603 return Str.toString(gtk_action_group_translate_string(gtkActionGroup, Str.toStringz(string))); 604 } 605 }