1 // Generated by gmmproc 2.64.2 -- DO NOT MODIFY! 2 #ifndef _GIOMM_MENUMODEL_H 3 #define _GIOMM_MENUMODEL_H 4 5 #include <giommconfig.h> 6 7 8 #include <glibmm/ustring.h> 9 #include <sigc++/sigc++.h> 10 11 /* Copyright (C) 2012 The giomm Development Team 12 * 13 * This library is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU Lesser General Public 15 * License as published by the Free Software Foundation; either 16 * version 2.1 of the License, or (at your option) any later version. 17 * 18 * This library is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 * Lesser General Public License for more details. 22 * 23 * You should have received a copy of the GNU Lesser General Public 24 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 25 */ 26 27 28 #include <glibmm/object.h> 29 30 31 #ifndef DOXYGEN_SHOULD_SKIP_THIS 32 using GMenuModel = struct _GMenuModel; 33 using GMenuModelClass = struct _GMenuModelClass; 34 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 35 36 37 #ifndef DOXYGEN_SHOULD_SKIP_THIS 38 namespace Gio 39 { class GIOMM_API MenuModel_Class; } // namespace Gio 40 #endif //DOXYGEN_SHOULD_SKIP_THIS 41 42 namespace Gio 43 { 44 45 enum MenuAttribute 46 { 47 /// The "action" menu attribute. 48 MENU_ATTRIBUTE_ACTION, 49 50 /// The "label" menu attribute. 51 MENU_ATTRIBUTE_LABEL, 52 53 /// The "target" menu attribute. 54 MENU_ATTRIBUTE_TARGET 55 }; 56 57 enum MenuLink 58 { 59 /// The "section" menu link. 60 MENU_LINK_SECTION, 61 62 /// The "submenu" menu link. 63 MENU_LINK_SUBMENU 64 }; 65 66 class GIOMM_API MenuAttributeIter; 67 class GIOMM_API MenuLinkIter; 68 69 /** MenuModel - An abstract class representing the contents of a menu. 70 * MenuModel represents the contents of a menu -- an ordered list of menu 71 * items. The items are associated with actions, which can be activated through 72 * them. Items can be grouped in sections, and may have submenus associated 73 * with them. Both items and sections usually have some representation data, 74 * such as labels or icons. The type of the associated action (ie whether it is 75 * stateful, and what kind of state it has) can influence the representation of 76 * the item. 77 * 78 * The conceptual model of menus in MenuModel is hierarchical: sections and 79 * submenus are again represented by MenuModels. Menus themselves do not define 80 * their own roles. Rather, the role of a particular MenuModel is defined by 81 * the item that references it (or, in the case of the 'root' menu, is defined 82 * by the context in which it is used). 83 * 84 * The motivation for this abstract model of application controls is that 85 * modern user interfaces tend to make these controls available outside the 86 * application. Examples include global menus, jumplists, dash boards, etc. To 87 * support such uses, it is necessary to 'export' information about actions and 88 * their representation in menus, which is exactly what 89 * Gio::DBus::Connection::export_action_group() and the 90 * Gio::DBus::Connection::export_menu_model() do for ActionGroup and MenuModel. 91 * The client-side counterparts to make use of the exported information are 92 * Gio::DBus::ActionGroup and Gio::DBus::MenuModel. 93 * 94 * The API of MenuModel is very generic, with iterators for the attributes and 95 * links of an item, see iterate_item_attributes() and iterate_item_links(). 96 * The 'standard' attributes and link types have predefined names: 97 * Gio::MENU_ATTRIBUTE_LABEL, Gio::MENU_ATTRIBUTE_ACTION, 98 * Gio::MENU_ATTRIBUTE_TARGET, Gio::MENU_LINK_SECTION and 99 * Gio::MENU_LINK_SUBMENU. 100 * 101 * Items in a MenuModel represent active controls if they refer to an action 102 * that can get activated when the user interacts with the menu item. The 103 * reference to the action is encoded by the string id in the 104 * Gio::MENU_ATTRIBUTE_ACTION attribute. An action id uniquely identifies an 105 * action in an action group. Which action group(s) provide actions depends on 106 * the context in which the menu model is used. E.g. when the model is exported 107 * as the application menu of a Gtk::Application, actions can be 108 * application-wide or window-specific (and thus come from two different action 109 * groups). By convention, the application-wide actions have names that start 110 * with "app.", while the names of window-specific actions start with "win.". 111 * 112 * While a wide variety of stateful actions is possible, the following is the 113 * minimum that is expected to be supported by all users of exported menu 114 * information: 115 * 116 * - an action with no parameter type and no state 117 * - an action with no parameter type and boolean state 118 * - an action with string parameter type and string state 119 * 120 * <b>Stateless.</b> A stateless action typically corresponds to an ordinary 121 * menu item. Selecting such a menu item will activate the action (with no 122 * parameter). 123 * 124 * <b>Boolean State.</b> An action with a boolean state will most typically be 125 * used with a "toggle" or "switch" menu item. The state can be set directly, 126 * but activating the action (with no parameter) results in the state being 127 * toggled. Selecting a toggle menu item will activate the action. The menu 128 * item should be rendered as "checked" when the state is true. 129 * 130 * <b>String Parameter and State.</b> Actions with string parameters and state 131 * will most typically be used to represent an enumerated choice over the items 132 * available for a group of radio menu items. Activating the action with a 133 * string parameter is equivalent to setting that parameter as the state. Radio 134 * menu items, in addition to being associated with the action, will have a 135 * target value. Selecting that menu item will result in activation of the 136 * action with the target value as the parameter. The menu item should be 137 * rendered as "selected" when the state of the action is equal to the target 138 * value of the menu item. 139 * 140 * See the C API docs for a graphical example. 141 * @newin{2,32} 142 */ 143 144 class GIOMM_API MenuModel : public Glib::Object 145 { 146 147 #ifndef DOXYGEN_SHOULD_SKIP_THIS 148 149 public: 150 using CppObjectType = MenuModel; 151 using CppClassType = MenuModel_Class; 152 using BaseObjectType = GMenuModel; 153 using BaseClassType = GMenuModelClass; 154 155 // noncopyable 156 MenuModel(const MenuModel&) = delete; 157 MenuModel& operator=(const MenuModel&) = delete; 158 159 private: friend class MenuModel_Class; 160 static CppClassType menumodel_class_; 161 162 protected: 163 explicit MenuModel(const Glib::ConstructParams& construct_params); 164 explicit MenuModel(GMenuModel* castitem); 165 166 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 167 168 public: 169 170 MenuModel(MenuModel&& src) noexcept; 171 MenuModel& operator=(MenuModel&& src) noexcept; 172 173 ~MenuModel() noexcept override; 174 175 /** Get the GType for this class, for use with the underlying GObject type system. 176 */ 177 static GType get_type() G_GNUC_CONST; 178 179 #ifndef DOXYGEN_SHOULD_SKIP_THIS 180 181 182 static GType get_base_type() G_GNUC_CONST; 183 #endif 184 185 ///Provides access to the underlying C GObject. gobj()186 GMenuModel* gobj() { return reinterpret_cast<GMenuModel*>(gobject_); } 187 188 ///Provides access to the underlying C GObject. gobj()189 const GMenuModel* gobj() const { return reinterpret_cast<GMenuModel*>(gobject_); } 190 191 ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. 192 GMenuModel* gobj_copy(); 193 194 private: 195 196 197 protected: 198 MenuModel(); 199 200 public: 201 202 203 //TODO: When we can break ABI, remove the method overload and just make it const. 204 //It makes no sense to return const by value. 205 206 207 //TODO: Add a get_item_attribute() templated method to get values directly 208 //instead of returning a Glib::VariantBase? 209 210 211 /** Queries the item at position @a item_index in @a model for the attribute 212 * specified by @a attribute. 213 * 214 * If @a expected_type is non-<tt>nullptr</tt> then it specifies the expected type of 215 * the attribute. If it is <tt>nullptr</tt> then any type will be accepted. 216 * 217 * If the attribute exists and matches @a expected_type (or if the 218 * expected type is unspecified) then the value is returned. 219 * 220 * If the attribute does not exist, or does not match the expected type 221 * then <tt>nullptr</tt> is returned. 222 * 223 * @newin{2,32} 224 * 225 * @param item_index The index of the item. 226 * @param attribute The attribute to query. 227 * @param expected_type The expected type of the attribute, or 228 * <tt>nullptr</tt>. 229 * @return The value of the attribute. 230 */ 231 Glib::VariantBase get_item_attribute(int item_index, MenuAttribute attribute, const Glib::VariantType& expected_type); 232 233 /** Queries the item at position @a item_index in @a model for the attribute 234 * specified by @a attribute. 235 * 236 * If @a expected_type is non-<tt>nullptr</tt> then it specifies the expected type of 237 * the attribute. If it is <tt>nullptr</tt> then any type will be accepted. 238 * 239 * If the attribute exists and matches @a expected_type (or if the 240 * expected type is unspecified) then the value is returned. 241 * 242 * If the attribute does not exist, or does not match the expected type 243 * then <tt>nullptr</tt> is returned. 244 * 245 * @newin{2,32} 246 * 247 * @param item_index The index of the item. 248 * @param attribute The attribute to query. 249 * @param expected_type The expected type of the attribute, or 250 * <tt>nullptr</tt>. 251 * @return The value of the attribute. 252 */ 253 const Glib::VariantBase get_item_attribute(int item_index, MenuAttribute attribute, const Glib::VariantType& expected_type) const; 254 255 // Ignore varargs function 256 257 258 /** Queries the item at position @a item_index in @a model for the link 259 * specified by @a link. 260 * 261 * If the link exists, the linked MenuModel is returned. If the link 262 * does not exist, <tt>nullptr</tt> is returned. 263 * 264 * @newin{2,32} 265 * 266 * @param item_index The index of the item. 267 * @param link The link to query. 268 * @return The linked MenuModel, or <tt>nullptr</tt>. 269 */ 270 Glib::RefPtr<MenuModel> get_item_link(int item_index, MenuLink link); 271 272 /** Queries the item at position @a item_index in @a model for the link 273 * specified by @a link. 274 * 275 * If the link exists, the linked MenuModel is returned. If the link 276 * does not exist, <tt>nullptr</tt> is returned. 277 * 278 * @newin{2,32} 279 * 280 * @param item_index The index of the item. 281 * @param link The link to query. 282 * @return The linked MenuModel, or <tt>nullptr</tt>. 283 */ 284 Glib::RefPtr<const MenuModel> get_item_link(int item_index, MenuLink link) const; 285 286 287 /** Queries if @a model is mutable. 288 * 289 * An immutable MenuModel will never emit the MenuModel::signal_items_changed() 290 * signal. Consumers of the model may make optimisations accordingly. 291 * 292 * @newin{2,32} 293 * 294 * @return <tt>true</tt> if the model is mutable (ie: "items-changed" may be 295 * emitted). 296 */ 297 bool is_mutable() const; 298 299 /** Query the number of items in @a model. 300 * 301 * @newin{2,32} 302 * 303 * @return The number of items. 304 */ 305 int get_n_items() const; 306 307 308 /** Creates a MenuAttributeIter to iterate over the attributes of 309 * the item at position @a item_index in @a model. 310 * 311 * You must free the iterator with Glib::object_unref() when you are done. 312 * 313 * @newin{2,32} 314 * 315 * @param item_index The index of the item. 316 * @return A new MenuAttributeIter. 317 */ 318 Glib::RefPtr<MenuAttributeIter> iterate_item_attributes(int item_index); 319 320 /** Creates a MenuAttributeIter to iterate over the attributes of 321 * the item at position @a item_index in @a model. 322 * 323 * You must free the iterator with Glib::object_unref() when you are done. 324 * 325 * @newin{2,32} 326 * 327 * @param item_index The index of the item. 328 * @return A new MenuAttributeIter. 329 */ 330 Glib::RefPtr<const MenuAttributeIter> iterate_item_attributes(int item_index) const; 331 332 333 /** Creates a MenuLinkIter to iterate over the links of the item at 334 * position @a item_index in @a model. 335 * 336 * You must free the iterator with Glib::object_unref() when you are done. 337 * 338 * @newin{2,32} 339 * 340 * @param item_index The index of the item. 341 * @return A new MenuLinkIter. 342 */ 343 Glib::RefPtr<MenuLinkIter> iterate_item_links(int item_index); 344 345 /** Creates a MenuLinkIter to iterate over the links of the item at 346 * position @a item_index in @a model. 347 * 348 * You must free the iterator with Glib::object_unref() when you are done. 349 * 350 * @newin{2,32} 351 * 352 * @param item_index The index of the item. 353 * @return A new MenuLinkIter. 354 */ 355 Glib::RefPtr<const MenuLinkIter> iterate_item_links(int item_index) const; 356 357 358 /** Requests emission of the MenuModel::signal_items_changed() signal on @a model. 359 * 360 * This function should never be called except by MenuModel 361 * subclasses. Any other calls to this function will very likely lead 362 * to a violation of the interface of the model. 363 * 364 * The implementation should update its internal representation of the 365 * menu before emitting the signal. The implementation should further 366 * expect to receive queries about the new state of the menu (and 367 * particularly added menu items) while signal handlers are running. 368 * 369 * The implementation must dispatch this call directly from a mainloop 370 * entry and not in response to calls -- particularly those from the 371 * MenuModel API. Said another way: the menu must not change while 372 * user code is running without returning to the mainloop. 373 * 374 * @newin{2,32} 375 * 376 * @param position The position of the change. 377 * @param removed The number of items removed. 378 * @param added The number of items added. 379 */ 380 void items_changed(int position, int removed, int added); 381 382 // The items-changed signal can't have a default handler in glibmm, because it does not have one in glib. 383 384 /** 385 * @par Slot Prototype: 386 * <tt>void on_my_%items_changed(int position, int removed, int added)</tt> 387 * 388 * Flags: Run Last 389 * 390 * Emitted when a change has occured to the menu. 391 * 392 * The only changes that can occur to a menu is that items are removed 393 * or added. Items may not change (except by being removed and added 394 * back in the same location). This signal is capable of describing 395 * both of those changes (at the same time). 396 * 397 * The signal means that starting at the index @a position, @a removed 398 * items were removed and @a added items were added in their place. If 399 * @a removed is zero then only items were added. If @a added is zero 400 * then only items were removed. 401 * 402 * As an example, if the menu contains items a, b, c, d (in that 403 * order) and the signal (2, 1, 3) occurs then the new composition of 404 * the menu will be a, b, _, _, _, d (with each _ representing some 405 * new item). 406 * 407 * Signal handlers may query the model (particularly the added items) 408 * and expect to see the results of the modification that is being 409 * reported. The signal is emitted after the modification. 410 * 411 * @param position The position of the change. 412 * @param removed The number of items removed. 413 * @param added The number of items added. 414 */ 415 416 Glib::SignalProxy< void,int,int,int > signal_items_changed(); 417 418 419 public: 420 421 public: 422 //C++ methods used to invoke GTK+ virtual functions: 423 424 protected: 425 //GTK+ Virtual Functions (override these to change behaviour): 426 427 //Default Signal Handlers:: 428 429 430 }; 431 432 } // namespace Gio 433 434 435 namespace Glib 436 { 437 /** A Glib::wrap() method for this object. 438 * 439 * @param object The C instance. 440 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref. 441 * @result A C++ instance that wraps this C instance. 442 * 443 * @relates Gio::MenuModel 444 */ 445 GIOMM_API 446 Glib::RefPtr<Gio::MenuModel> wrap(GMenuModel* object, bool take_copy = false); 447 } 448 449 450 #endif /* _GIOMM_MENUMODEL_H */ 451 452