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 = GMenuModel.html 27 * outPack = gio 28 * outFile = MenuModel 29 * strct = GMenuModel 30 * realStrct= 31 * ctorStrct= 32 * clss = MenuModel 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_menu_model_ 41 * omit structs: 42 * omit prefixes: 43 * - g_menu_attribute_iter_ 44 * - g_menu_link_iter_ 45 * omit code: 46 * omit signals: 47 * imports: 48 * - glib.Str 49 * - glib.Variant 50 * - glib.VariantType 51 * - gio.MenuAttributeIter 52 * - gio.MenuLinkIter 53 * structWrap: 54 * - GMenuAttributeIter* -> MenuAttributeIter 55 * - GMenuLinkIter* -> MenuLinkIter 56 * - GMenuModel* -> MenuModel 57 * - GVariant* -> Variant 58 * - GVariantType* -> VariantType 59 * module aliases: 60 * local aliases: 61 * overrides: 62 */ 63 64 module gio.MenuModel; 65 66 public import gtkc.giotypes; 67 68 private import gtkc.gio; 69 private import glib.ConstructionException; 70 private import gobject.ObjectG; 71 72 private import gobject.Signals; 73 public import gtkc.gdktypes; 74 private import glib.Str; 75 private import glib.Variant; 76 private import glib.VariantType; 77 private import gio.MenuAttributeIter; 78 private import gio.MenuLinkIter; 79 80 81 private import gobject.ObjectG; 82 83 /** 84 * GMenuModel represents the contents of a menu -- an ordered list of 85 * menu items. The items are associated with actions, which can be 86 * activated through them. Items can be grouped in sections, and may 87 * have submenus associated with them. Both items and sections usually 88 * have some representation data, such as labels or icons. The type of 89 * the associated action (ie whether it is stateful, and what kind of 90 * state it has) can influence the representation of the item. 91 * 92 * The conceptual model of menus in GMenuModel is hierarchical: 93 * sections and submenus are again represented by GMenuModels. 94 * Menus themselves do not define their own roles. Rather, the role 95 * of a particular GMenuModel is defined by the item that references 96 * it (or, in the case of the 'root' menu, is defined by the context 97 * in which it is used). 98 * 99 * As an example, consider the visible portions of the menu in 100 * Figure 2, “An example menu”. 101 * 102 * Figure 2. An example menu 103 * 104 * There are 8 "menus" visible in the screenshot: one menubar, two 105 * submenus and 5 sections: 106 * 107 * the toplevel menubar (containing 4 items) 108 * the View submenu (containing 3 sections) 109 * the first section of the View submenu (containing 2 items) 110 * the second section of the View submenu (containing 1 item) 111 * the final section of the View submenu (containing 1 item) 112 * the Highlight Mode submenu (containing 2 sections) 113 * the Sources section (containing 2 items) 114 * the Markup section (containing 2 items) 115 * 116 * Figure 3, “A menu model” illustrates the conceptual connection between 117 * these 8 menus. Each large block in the figure represents a menu and the 118 * smaller blocks within the large block represent items in that menu. Some 119 * items contain references to other menus. 120 * 121 * Figure 3. A menu model 122 * 123 * Notice that the separators visible in Figure 2, “An example menu” 124 * appear nowhere in Figure 3, “A menu model”. This is because 125 * separators are not explicitly represented in the menu model. Instead, 126 * a separator is inserted between any two non-empty sections of a menu. 127 * Section items can have labels just like any other item. In that case, 128 * a display system may show a section header instead of a separator. 129 * 130 * The motivation for this abstract model of application controls is 131 * that modern user interfaces tend to make these controls available 132 * outside the application. Examples include global menus, jumplists, 133 * dash boards, etc. To support such uses, it is necessary to 'export' 134 * information about actions and their representation in menus, which 135 * is exactly what the 136 * GActionGroup exporter 137 * and the 138 * GMenuModel exporter 139 * do for GActionGroup and GMenuModel. The client-side counterparts 140 * to make use of the exported information are GDBusActionGroup and 141 * GDBusMenuModel. 142 * 143 * The API of GMenuModel is very generic, with iterators for the 144 * attributes and links of an item, see g_menu_model_iterate_item_attributes() 145 * and g_menu_model_iterate_item_links(). The 'standard' attributes and 146 * link types have predefined names: G_MENU_ATTRIBUTE_LABEL, 147 * G_MENU_ATTRIBUTE_ACTION, G_MENU_ATTRIBUTE_TARGET, G_MENU_LINK_SECTION 148 * and G_MENU_LINK_SUBMENU. 149 * 150 * Items in a GMenuModel represent active controls if they refer to 151 * an action that can get activated when the user interacts with the 152 * menu item. The reference to the action is encoded by the string id 153 * in the G_MENU_ATTRIBUTE_ACTION attribute. An action id uniquely 154 * identifies an action in an action group. Which action group(s) provide 155 * actions depends on the context in which the menu model is used. 156 * E.g. when the model is exported as the application menu of a 157 * GtkApplication, actions can be application-wide or window-specific 158 * (and thus come from two different action groups). By convention, the 159 * application-wide actions have names that start with "app.", while the 160 * names of window-specific actions start with "win.". 161 * 162 * While a wide variety of stateful actions is possible, the following 163 * is the minimum that is expected to be supported by all users of exported 164 * menu information: 165 * 166 * an action with no parameter type and no state 167 * an action with no parameter type and boolean state 168 * an action with string parameter type and string state 169 * 170 * Stateless. 171 * A stateless action typically corresponds to an ordinary menu item. 172 * 173 * Selecting such a menu item will activate the action (with no parameter). 174 * 175 * Boolean State. 176 * An action with a boolean state will most typically be used with a "toggle" 177 * or "switch" menu item. The state can be set directly, but activating the 178 * action (with no parameter) results in the state being toggled. 179 * 180 * Selecting a toggle menu item will activate the action. The menu item should 181 * be rendered as "checked" when the state is true. 182 * 183 * String Parameter and State. 184 * Actions with string parameters and state will most typically be used to 185 * represent an enumerated choice over the items available for a group of 186 * radio menu items. Activating the action with a string parameter is 187 * equivalent to setting that parameter as the state. 188 * 189 * Radio menu items, in addition to being associated with the action, will 190 * have a target value. Selecting that menu item will result in activation 191 * of the action with the target value as the parameter. The menu item should 192 * be rendered as "selected" when the state of the action is equal to the 193 * target value of the menu item. 194 */ 195 public class MenuModel : ObjectG 196 { 197 198 /** the main Gtk struct */ 199 protected GMenuModel* gMenuModel; 200 201 202 /** Get the main Gtk struct */ 203 public GMenuModel* getMenuModelStruct() 204 { 205 return gMenuModel; 206 } 207 208 209 /** the main Gtk struct as a void* */ 210 protected override void* getStruct() 211 { 212 return cast(void*)gMenuModel; 213 } 214 215 /** 216 * Sets our main struct and passes it to the parent class 217 */ 218 public this (GMenuModel* gMenuModel) 219 { 220 super(cast(GObject*)gMenuModel); 221 this.gMenuModel = gMenuModel; 222 } 223 224 protected override void setStruct(GObject* obj) 225 { 226 super.setStruct(obj); 227 gMenuModel = cast(GMenuModel*)obj; 228 } 229 230 /** 231 */ 232 int[string] connectedSignals; 233 234 void delegate(gint, gint, gint, MenuModel)[] onItemsChangedListeners; 235 /** 236 * Emitted when a change has occured to the menu. 237 * The only changes that can occur to a menu is that items are removed 238 * or added. Items may not change (except by being removed and added 239 * back in the same location). This signal is capable of describing 240 * both of those changes (at the same time). 241 * The signal means that starting at the index position, removed 242 * items were removed and added items were added in their place. If 243 * removed is zero then only items were added. If added is zero 244 * then only items were removed. 245 * As an example, if the menu contains items a, b, c, d (in that 246 * order) and the signal (2, 1, 3) occurs then the new composition of 247 * the menu will be a, b, _, _, _, d (with each _ representing some 248 * new item). 249 * Signal handlers may query the model (particularly the added items) 250 * and expect to see the results of the modification that is being 251 * reported. The signal is emitted after the modification. 252 * See Also 253 * GActionGroup 254 */ 255 void addOnItemsChanged(void delegate(gint, gint, gint, MenuModel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 256 { 257 if ( !("items-changed" in connectedSignals) ) 258 { 259 Signals.connectData( 260 getStruct(), 261 "items-changed", 262 cast(GCallback)&callBackItemsChanged, 263 cast(void*)this, 264 null, 265 connectFlags); 266 connectedSignals["items-changed"] = 1; 267 } 268 onItemsChangedListeners ~= dlg; 269 } 270 extern(C) static void callBackItemsChanged(GMenuModel* modelStruct, gint position, gint removed, gint added, MenuModel _menuModel) 271 { 272 foreach ( void delegate(gint, gint, gint, MenuModel) dlg ; _menuModel.onItemsChangedListeners ) 273 { 274 dlg(position, removed, added, _menuModel); 275 } 276 } 277 278 279 /** 280 * Queries if model is mutable. 281 * An immutable GMenuModel will never emit the "items-changed" 282 * signal. Consumers of the model may make optimisations accordingly. 283 * Since 2.32 284 * Returns: TRUE if the model is mutable (ie: "items-changed" may be emitted). 285 */ 286 public int isMutable() 287 { 288 // gboolean g_menu_model_is_mutable (GMenuModel *model); 289 return g_menu_model_is_mutable(gMenuModel); 290 } 291 292 /** 293 * Query the number of items in model. 294 * Since 2.32 295 * Returns: the number of items 296 */ 297 public int getNItems() 298 { 299 // gint g_menu_model_get_n_items (GMenuModel *model); 300 return g_menu_model_get_n_items(gMenuModel); 301 } 302 303 /** 304 * Queries the item at position item_index in model for the attribute 305 * specified by attribute. 306 * If expected_type is non-NULL then it specifies the expected type of 307 * the attribute. If it is NULL then any type will be accepted. 308 * If the attribute exists and matches expected_type (or if the 309 * expected type is unspecified) then the value is returned. 310 * If the attribute does not exist, or does not match the expected type 311 * then NULL is returned. 312 * Since 2.32 313 * Params: 314 * itemIndex = the index of the item 315 * attribute = the attribute to query 316 * expectedType = the expected type of the attribute, or 317 * NULL. [allow-none] 318 * Returns: the value of the attribute. [transfer full] 319 */ 320 public Variant getItemAttributeValue(int itemIndex, string attribute, VariantType expectedType) 321 { 322 // GVariant * g_menu_model_get_item_attribute_value (GMenuModel *model, gint item_index, const gchar *attribute, const GVariantType *expected_type); 323 auto p = g_menu_model_get_item_attribute_value(gMenuModel, itemIndex, Str.toStringz(attribute), (expectedType is null) ? null : expectedType.getVariantTypeStruct()); 324 325 if(p is null) 326 { 327 return null; 328 } 329 330 return ObjectG.getDObject!(Variant)(cast(GVariant*) p); 331 } 332 333 /** 334 * Queries the item at position item_index in model for the link 335 * specified by link. 336 * If the link exists, the linked GMenuModel is returned. If the link 337 * does not exist, NULL is returned. 338 * Since 2.32 339 * Params: 340 * itemIndex = the index of the item 341 * link = the link to query 342 * Returns: the linked GMenuModel, or NULL. [transfer full] 343 */ 344 public MenuModel getItemLink(int itemIndex, string link) 345 { 346 // GMenuModel * g_menu_model_get_item_link (GMenuModel *model, gint item_index, const gchar *link); 347 auto p = g_menu_model_get_item_link(gMenuModel, itemIndex, Str.toStringz(link)); 348 349 if(p is null) 350 { 351 return null; 352 } 353 354 return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p); 355 } 356 357 /** 358 * Creates a GMenuAttributeIter to iterate over the attributes of 359 * the item at position item_index in model. 360 * You must free the iterator with g_object_unref() when you are done. 361 * Since 2.32 362 * Params: 363 * itemIndex = the index of the item 364 * Returns: a new GMenuAttributeIter. [transfer full] 365 */ 366 public MenuAttributeIter iterateItemAttributes(int itemIndex) 367 { 368 // GMenuAttributeIter * g_menu_model_iterate_item_attributes (GMenuModel *model, gint item_index); 369 auto p = g_menu_model_iterate_item_attributes(gMenuModel, itemIndex); 370 371 if(p is null) 372 { 373 return null; 374 } 375 376 return ObjectG.getDObject!(MenuAttributeIter)(cast(GMenuAttributeIter*) p); 377 } 378 379 /** 380 * Creates a GMenuLinkIter to iterate over the links of the item at 381 * position item_index in model. 382 * You must free the iterator with g_object_unref() when you are done. 383 * Since 2.32 384 * Params: 385 * itemIndex = the index of the item 386 * Returns: a new GMenuLinkIter. [transfer full] 387 */ 388 public MenuLinkIter iterateItemLinks(int itemIndex) 389 { 390 // GMenuLinkIter * g_menu_model_iterate_item_links (GMenuModel *model, gint item_index); 391 auto p = g_menu_model_iterate_item_links(gMenuModel, itemIndex); 392 393 if(p is null) 394 { 395 return null; 396 } 397 398 return ObjectG.getDObject!(MenuLinkIter)(cast(GMenuLinkIter*) p); 399 } 400 401 /** 402 * Requests emission of the "items-changed" signal on model. 403 * This function should never be called except by GMenuModel 404 * subclasses. Any other calls to this function will very likely lead 405 * to a violation of the interface of the model. 406 * The implementation should update its internal representation of the 407 * menu before emitting the signal. The implementation should further 408 * expect to receive queries about the new state of the menu (and 409 * particularly added menu items) while signal handlers are running. 410 * The implementation must dispatch this call directly from a mainloop 411 * entry and not in response to calls -- particularly those from the 412 * GMenuModel API. Said another way: the menu must not change while 413 * user code is running without returning to the mainloop. 414 * Since 2.32 415 * Params: 416 * position = the position of the change 417 * removed = the number of items removed 418 * added = the number of items added 419 */ 420 public void itemsChanged(int position, int removed, int added) 421 { 422 // void g_menu_model_items_changed (GMenuModel *model, gint position, gint removed, gint added); 423 g_menu_model_items_changed(gMenuModel, position, removed, added); 424 } 425 }