| 1 |
/* Copyright (C) 2003 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
_CONFIGINCLUDE(gtkmmconfig.h) |
| 18 |
|
| 19 |
#include <vector> |
| 20 |
|
| 21 |
#include <gtkmm/widget.h> |
| 22 |
#include <gtkmm/accelgroup.h> |
| 23 |
#include <giomm/icon.h> |
| 24 |
|
| 25 |
_DEFS(gtkmm,gtk) |
| 26 |
_PINCLUDE(glibmm/private/object_p.h) |
| 27 |
|
| 28 |
#m4 _PUSH(SECTION_CC_PRE_INCLUDES) |
| 29 |
#undef GTK_DISABLE_DEPRECATED |
| 30 |
#define GDK_DISABLE_DEPRECATION_WARNINGS 1 |
| 31 |
#m4 _POP() |
| 32 |
|
| 33 |
//TODO: Do this when we can stop using Gtk::Action in virtual functions in Gtk::Activatable, when we break ABI: |
| 34 |
//_IS_DEPRECATED // This whole file is deprecated. |
| 35 |
|
| 36 |
namespace Gtk |
| 37 |
{ |
| 38 |
|
| 39 |
class GTKMM_API ActionGroup; //deprecated |
| 40 |
class GTKMM_API Menu; |
| 41 |
class GTKMM_API MenuItem; |
| 42 |
class GTKMM_API ToolItem; |
| 43 |
class GTKMM_API Image; |
| 44 |
class GTKMM_API StockID; //deprecated |
| 45 |
|
| 46 |
/** A deprecated action which can be triggered by a menu or toolbar item. |
| 47 |
* |
| 48 |
* Actions represent operations that the user can perform, along with |
| 49 |
* some information about how it should be presented in the user interface. |
| 50 |
* Each action provides methods to create icons, menu items and toolbar |
| 51 |
* items representing itself. |
| 52 |
* |
| 53 |
* As well as the callback that is called when the action is activated, |
| 54 |
* the following is also associated with the action: |
| 55 |
* |
| 56 |
* - a name (not translated, for path lookup) |
| 57 |
* - a label (translated, for display) |
| 58 |
* - an accelerator |
| 59 |
* - whether the label indicates a stock id |
| 60 |
* - a tooltip (optional, translated) |
| 61 |
* - a toolbar label (optional, shorter than label) |
| 62 |
* |
| 63 |
* The action will also have some state information: |
| 64 |
* |
| 65 |
* - visible (shown/hidden) |
| 66 |
* - sensitive (enabled/disabled) |
| 67 |
* |
| 68 |
* Apart from regular actions, there are toggle actions, |
| 69 |
* which can be toggled between two states and radio actions, |
| 70 |
* of which only one in a group can be in the "active" state. |
| 71 |
* Other actions can be implemented as Gtk::Action subclasses. |
| 72 |
* |
| 73 |
* Each action can have one or more proxy menu item, toolbar button or other proxy widgets. |
| 74 |
* Proxies mirror the state of the action (text label, tooltip, icon, visible, sensitive, etc), |
| 75 |
* and should change when the action's state changes. When the proxy is activated, |
| 76 |
* it should activate its action. |
| 77 |
* |
| 78 |
* @deprecated Use Gio::Action and Gio::SimpleAction instead, and associate actions |
| 79 |
* with Gtk::Actionable widgets. Use Gio::MenuModel for creating menus with |
| 80 |
* Gtk::Menu(const Glib::RefPtr<Gio::MenuModel>& model).<br> |
| 81 |
* Some gtkmm widgets don't derive from Gtk::Actionable, although the corresponding |
| 82 |
* gtk+ widgets implement the GtkActionable interface. This discrepancy can't be |
| 83 |
* fixed until we can break ABI. You can sometimes work around this problem |
| 84 |
* by using a widget's %gobj() method and calling a gtk_actionable_*() method |
| 85 |
* directly. Several examples in the |
| 86 |
* <a href="https://gnome.pages.gitlab.gnome.org/gtkmm-documentation/">Programming with gtkmm</a> |
| 87 |
* book use Gio::SimpleAction, such as the menus and toolbars examples. |
| 88 |
* The online version of this tutorial describes gtkmm-4.0. |
| 89 |
*/ |
| 90 |
class GTKMM_API Action |
| 91 |
: public Glib::Object, |
| 92 |
public Buildable |
| 93 |
{ |
| 94 |
_CLASS_GOBJECT(Action, GtkAction, GTK_ACTION, Glib::Object, GObject, , , GTKMM_API) |
| 95 |
_IMPLEMENTS_INTERFACE(Buildable) |
| 96 |
|
| 97 |
protected: |
| 98 |
/** Creates an empty action. |
| 99 |
*/ |
| 100 |
_CTOR_DEFAULT |
| 101 |
|
| 102 |
_DEPRECATE_IFDEF_START |
| 103 |
/** Creates an action with a stock ID. |
| 104 |
* The stock ID is used to set a default icon, text and accelerator for the |
| 105 |
* action. |
| 106 |
* |
| 107 |
* @param name A unique name for the action. |
| 108 |
* @param stock_id The stock icon to display in widgets representing the |
| 109 |
* action. |
| 110 |
* @param label The label displayed in menu items and on buttons. |
| 111 |
* @param tooltip A tooltip for the action. |
| 112 |
* @deprecated There is no corresponding replacement when using Gio::Action. |
| 113 |
*/ |
| 114 |
explicit Action(const Glib::ustring& name, const StockID& stock_id = StockID(), const Glib::ustring& label = Glib::ustring(), const Glib::ustring& tooltip = Glib::ustring()); |
| 115 |
|
| 116 |
/** Creates an action with an icon name. |
| 117 |
* The action's icon will reflect the specified icon name in the user's |
| 118 |
* icon theme. |
| 119 |
* |
| 120 |
* @param name A unique name for the action. |
| 121 |
* @param icon_name An IconTheme icon name used for widgets representing the |
| 122 |
* action. |
| 123 |
* @param label The label displayed in menu items and on buttons. |
| 124 |
* @param tooltip A tooltip for the action. |
| 125 |
* @deprecated See set_icon_name(), set_label() and set_tooltip() for |
| 126 |
* replacements when using Gio::Action. |
| 127 |
*/ |
| 128 |
explicit Action(const Glib::ustring& name, const Glib::ustring& icon_name, const Glib::ustring& label = Glib::ustring(), const Glib::ustring& tooltip = Glib::ustring()); |
| 129 |
_DEPRECATE_IFDEF_END |
| 130 |
|
| 131 |
public: |
| 132 |
//Note that gtk_action_new() does not allow name to be NULL, which suggests that we should not have a default constructor, |
| 133 |
//but it's OK to set the name later: |
| 134 |
_WRAP_CREATE() |
| 135 |
|
| 136 |
_DEPRECATE_IFDEF_START |
| 137 |
/** Creates an action. |
| 138 |
* |
| 139 |
* @param name A unique name for the action. |
| 140 |
* @param label The label displayed in menu items and on buttons. |
| 141 |
* @param tooltip A tooltip for the action. |
| 142 |
* |
| 143 |
* @return A new Action. |
| 144 |
* @deprecated See set_label() and set_tooltip() for replacements when using Gio::Action. |
| 145 |
*/ |
| 146 |
static Glib::RefPtr<Action> create(const Glib::ustring& name, const Glib::ustring& label = Glib::ustring(), const Glib::ustring& tooltip = Glib::ustring()); |
| 147 |
|
| 148 |
/** Creates an action with a stock ID. |
| 149 |
* The stock ID is used to set a default icon, text and accelerator for the |
| 150 |
* action. |
| 151 |
* |
| 152 |
* @param name A unique name for the action. |
| 153 |
* @param stock_id The stock icon to display in widgets representing the |
| 154 |
* action. |
| 155 |
* @param label The label displayed in menu items and on buttons. |
| 156 |
* @param tooltip A tooltip for the action. |
| 157 |
* |
| 158 |
* @return A new Action. |
| 159 |
* @deprecated There is no corresponding replacement when using Gio::Action. |
| 160 |
*/ |
| 161 |
static Glib::RefPtr<Action> create(const Glib::ustring& name, const Gtk::StockID& stock_id, const Glib::ustring& label = Glib::ustring(), const Glib::ustring& tooltip = Glib::ustring()); |
| 162 |
|
| 163 |
/** Create an action with an icon name. |
| 164 |
* The action's icon will reflect the specified icon name in the user's |
| 165 |
* icon theme. |
| 166 |
* |
| 167 |
* @param name A unique name for the action. |
| 168 |
* @param icon_name An IconTheme icon name used for widgets representing the |
| 169 |
* action. |
| 170 |
* @param label The label displayed in menu items and on buttons. |
| 171 |
* @param tooltip A tooltip for the action. |
| 172 |
* |
| 173 |
* @return A new Action. |
| 174 |
* @deprecated See set_icon_name(), set_label() and set_tooltip() for |
| 175 |
* replacements when using Gio::Action. |
| 176 |
*/ |
| 177 |
static Glib::RefPtr<Action> create_with_icon_name(const Glib::ustring& name, const Glib::ustring& icon_name, const Glib::ustring& label, const Glib::ustring& tooltip); |
| 178 |
_DEPRECATE_IFDEF_END |
| 179 |
|
| 180 |
_WRAP_METHOD(Glib::ustring get_name() const, gtk_action_get_name, deprecated "Use Gio::Action::get_name() on a Gio::Action instead.") |
| 181 |
|
| 182 |
_WRAP_METHOD(bool is_sensitive() const, gtk_action_is_sensitive, deprecated "Use Gio::Action::get_enabled() on a Gio::Action instead.") |
| 183 |
_WRAP_METHOD(bool get_sensitive() const, gtk_action_get_sensitive, deprecated "Use Gio::Action::get_enabled() on a Gio::Action instead.") |
| 184 |
|
| 185 |
_WRAP_METHOD(void set_sensitive(bool sensitive = true), gtk_action_set_sensitive, deprecated "Use Gio::SimpleAction::set_enabled() on a Gio::SimpleAction instead.") |
| 186 |
|
| 187 |
_WRAP_METHOD(bool is_visible() const, gtk_action_is_visible, deprecated "Use Gio::Action instead, and control and monitor the state of Gtk::Actionable widgets directly.") |
| 188 |
_WRAP_METHOD(bool get_visible() const, gtk_action_get_visible, deprecated "Use Gio::Action instead, and control and monitor the state of Gtk::Actionable widgets directly.") |
| 189 |
_WRAP_METHOD(void set_visible(bool visible = true), gtk_action_set_visible, deprecated "Use Gio::Action instead, and control and monitor the state of Gtk::Actionable widgets directly.") |
| 190 |
|
| 191 |
_WRAP_METHOD(void activate(), gtk_action_activate, deprecated "Use Gio::ActionGroup::activate_action() on a Gio::Action instead.") |
| 192 |
_WRAP_METHOD(Image* create_icon(IconSize icon_size), gtk_action_create_icon, |
| 193 |
deprecated "Use Gio::MenuItem::set_icon() to set an icon on a Gio::MenuItem, or Gtk::Container::add() to add a Gtk::Image to a Gtk::Button.") |
| 194 |
_WRAP_METHOD(MenuItem* create_menu_item(), gtk_action_create_menu_item, deprecated "Use a Gio::MenuItem and associate it with a Gio::Action instead.") |
| 195 |
_WRAP_METHOD(ToolItem* create_tool_item(), gtk_action_create_tool_item, |
| 196 |
deprecated "Use a Gtk::ToolItem and associate it with a Gio::Action using Gtk::Actionable::set_action_name() instead. (Impossible until GtkToolItem implements the GActionable interface.)") |
| 197 |
_WRAP_METHOD(Menu* create_menu(), gtk_action_create_menu, deprecated "Use Gio::Action and Gio::MenuModel instead, and create a Gtk::Menu with Gtk::Menu(const Glib::RefPtr<Gio::MenuModel>& model).") |
| 198 |
|
| 199 |
#m4 dnl // This isn't in convert_gtk.m4, and the default behaviour is wrong. |
| 200 |
#m4 _CONVERSION(`GSList*', `std::vector<Widget*>', `Glib::SListHandler<Widget*>::slist_to_vector($3, Glib::OWNERSHIP_NONE)') |
| 201 |
#m4 _CONVERSION(`GSList*', `std::vector<const Widget*>', `Glib::SListHandler<const Widget*>::slist_to_vector($3, Glib::OWNERSHIP_NONE)') |
| 202 |
|
| 203 |
_WRAP_METHOD(std::vector<Widget*> get_proxies(), gtk_action_get_proxies, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 204 |
_WRAP_METHOD(std::vector<const Widget*> get_proxies() const, gtk_action_get_proxies, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 205 |
|
| 206 |
_WRAP_METHOD(void connect_accelerator(), gtk_action_connect_accelerator, deprecated "Use Gio::Action and the accelerator group on an associated Gtk::Menu instead.") |
| 207 |
_WRAP_METHOD(void disconnect_accelerator(), gtk_action_disconnect_accelerator, deprecated "Use Gio::Action and the accelerator group on an associated Gtk::Menu instead.") |
| 208 |
|
| 209 |
_WRAP_METHOD(Glib::ustring get_accel_path() const, gtk_action_get_accel_path, deprecated "Use Gio::Action and the accelerator path on an associated Gtk::Menu instead.") |
| 210 |
|
| 211 |
/// For instance, void on_activate(); |
| 212 |
typedef sigc::slot<void> SlotActivate; |
| 213 |
|
| 214 |
_WRAP_SIGNAL(void activate(), "activate", deprecated "Use Gio::SimpleAction::signal_activate() instead.") |
| 215 |
|
| 216 |
//Used by AccelGroup: |
| 217 |
_WRAP_METHOD(void set_accel_path(const Glib::ustring& accel_path), gtk_action_set_accel_path, |
| 218 |
deprecated "Use Gio::Action and the accelerator path on an associated Gtk::Menu instead.") |
| 219 |
_WRAP_METHOD(void set_accel_group(const Glib::RefPtr<AccelGroup>& accel_group), gtk_action_set_accel_group, |
| 220 |
deprecated "Use Gio::Action and the accelerator group on an associated Gtk::Menu instead.") |
| 221 |
|
| 222 |
_WRAP_METHOD(void set_label(const Glib::ustring& label), gtk_action_set_label, |
| 223 |
deprecated "Use Gio::Action instead, and set a label on a menu item with Gio::MenuItem::set_label(). For Gtk::Actionable widgets, use the widget-specific API to set a label.") |
| 224 |
_WRAP_METHOD(Glib::ustring get_label() const, gtk_action_get_label, |
| 225 |
deprecated "Use Gio::Action instead, and get a label from a menu item with Gio::MenuItem::get_attribute_value(). For Gtk::Actionable widgets, use the widget-specific API to get a label.") |
| 226 |
_WRAP_METHOD(void set_short_label(const Glib::ustring& short_label), gtk_action_set_short_label, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 227 |
_WRAP_METHOD(Glib::ustring get_short_label() const, gtk_action_get_short_label, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 228 |
_WRAP_METHOD(void set_tooltip(const Glib::ustring& tooltip), gtk_action_set_tooltip, |
| 229 |
deprecated "Use Gio::Action instead, and set tooltips on associated Gtk::Actionable widgets with Gtk::Widget::set_tooltip_text().") |
| 230 |
_WRAP_METHOD(Glib::ustring get_tooltip() const, gtk_action_get_tooltip, |
| 231 |
deprecated "Use Gio::Action instead, and get tooltips from associated Gtk::Actionable widgets with Gtk::Widget::get_tooltip_text().") |
| 232 |
_WRAP_METHOD(void set_stock_id(const StockID& stock_id), gtk_action_set_stock_id, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 233 |
_WRAP_METHOD(StockID get_stock_id() const, gtk_action_get_stock_id, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 234 |
_WRAP_METHOD(void set_gicon(const Glib::RefPtr<Gio::Icon>& icon), gtk_action_set_gicon, |
| 235 |
deprecated "Use Gio::Action instead, and Gio::MenuItem::set_icon() to set an icon on a Gio::MenuItem associated with a Gio::Action, or Gtk::Container::add() to add a Gtk::Image to a Gtk::Button.") |
| 236 |
_WRAP_METHOD(Glib::RefPtr<Gio::Icon> get_gicon(), gtk_action_get_gicon, refreturn, |
| 237 |
deprecated "Use Gio::Action instead, and Gio::MenuItem::get_attribute_value() to get an icon from a Gio::MenuItem associated with a Gio::Action.") |
| 238 |
_WRAP_METHOD(Glib::RefPtr<const Gio::Icon> get_gicon() const, gtk_action_get_gicon, refreturn, constversion, |
| 239 |
deprecated "Use Gio::Action instead, and Gio::MenuItem::get_attribute_value() to get an icon from a Gio::MenuItem associated with a Gio::Action.") |
| 240 |
_WRAP_METHOD(void set_icon_name(const Glib::ustring& icon_name), gtk_action_set_icon_name, |
| 241 |
deprecated "Use Gio::Action instead, and Gio::MenuItem::set_icon() to set an icon on a Gio::MenuItem associated with a Gio::Action, or Gtk::Container::add() to add a Gtk::Image to a Gtk::Button.") |
| 242 |
_WRAP_METHOD(Glib::ustring get_icon_name() const, gtk_action_get_icon_name, |
| 243 |
deprecated "Use Gio::Action instead, and Gio::MenuItem::get_attribute_value() to get an icon from a Gio::MenuItem associated with a Gio::Action.") |
| 244 |
_WRAP_METHOD(void set_visible_horizontal(bool visible_horizontal = true), gtk_action_set_visible_horizontal, |
| 245 |
deprecated "Use Gio::Action instead, and control and monitor the visibility of associated widgets and menu items directly.") |
| 246 |
_WRAP_METHOD(bool get_visible_horizontal() const, gtk_action_get_visible_horizontal, |
| 247 |
deprecated "Use Gio::Action instead, and control and monitor the visibility of associated widgets and menu items directly.") |
| 248 |
_WRAP_METHOD(void set_visible_vertical(bool visible_vertical = true), gtk_action_set_visible_vertical, |
| 249 |
deprecated "Use Gio::Action instead, and control and monitor the visibility of associated widgets and menu items directly.") |
| 250 |
_WRAP_METHOD(bool get_visible_vertical() const, gtk_action_get_visible_vertical, |
| 251 |
deprecated "Use Gio::Action instead, and control and monitor the visibility of associated widgets and menu items directly.") |
| 252 |
_WRAP_METHOD(void set_is_important(bool is_important = true), gtk_action_set_is_important, deprecated "Use Gio::Action instead, and control and monitor whether labels are shown directly.") |
| 253 |
_WRAP_METHOD(bool get_is_important() const, gtk_action_get_is_important, deprecated "Use Gio::Action instead, and control and monitor whether labels are shown directly.") |
| 254 |
|
| 255 |
_WRAP_METHOD(void set_always_show_image(bool always_show = true), gtk_action_set_always_show_image, deprecated "Use Gio::MenuItem::set_icon() on a Gio::MenuItem instead, if the item should have an image.") |
| 256 |
_WRAP_METHOD(bool get_always_show_image() const, gtk_action_get_always_show_image, deprecated "Use Gio::MenuItem::get_attribute_value() on a Gio::MenuItem instead.") |
| 257 |
|
| 258 |
_WRAP_METHOD(void block_activate(), gtk_action_block_activate, deprecated "Use Gio::SimpleAction::set_enabled() to disable the Gio::SimpleAction instead.") |
| 259 |
_WRAP_METHOD(void unblock_activate(), gtk_action_unblock_activate, deprecated "Use Gio::SimpleAction::set_enabled() to enable the Gio::SimpleAction instead.") |
| 260 |
|
| 261 |
//gtk_action_get_accel_closure() is too C-specific: |
| 262 |
_IGNORE(gtk_action_get_accel_closure) |
| 263 |
|
| 264 |
_WRAP_PROPERTY("name", Glib::ustring, deprecated "Use Gio::Action::property_name() instead.") |
| 265 |
_WRAP_PROPERTY("label", Glib::ustring, deprecated "Use the 'label' attribute on Gio::MenuItem instead.") |
| 266 |
_WRAP_PROPERTY("short_label", Glib::ustring, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 267 |
_WRAP_PROPERTY("tooltip", Glib::ustring, deprecated "Use Gtk::Widget::set_tooltip_text() and Gtk::Widget::get_tooltip_text() instead.") |
| 268 |
_WRAP_PROPERTY("stock_id", StockID, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 269 |
_WRAP_PROPERTY("gicon", Glib::RefPtr<Gio::Icon>, deprecated "Use the 'icon' attribute on Gio::MenuItem instead.") |
| 270 |
_WRAP_PROPERTY("icon_name", Glib::ustring, deprecated "Use the 'icon' attribute on Gio::MenuItem instead.") |
| 271 |
_WRAP_PROPERTY("visible_horizontal", bool, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 272 |
_WRAP_PROPERTY("visible_vertical", bool, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 273 |
_WRAP_PROPERTY("visible_overflown", bool, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 274 |
_WRAP_PROPERTY("is_important", bool, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 275 |
_WRAP_PROPERTY("hide_if_empty", bool, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 276 |
_WRAP_PROPERTY("sensitive", bool, deprecated "Use Gio::Action::property_enabled() and Gio::SimpleAction::property_enabled() instead.") |
| 277 |
_WRAP_PROPERTY("visible", bool, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 278 |
_WRAP_PROPERTY("action_group", Glib::RefPtr<ActionGroup>, deprecated "Lookup the Gio::Action using Gio::ActionMap::lookup_action() instead.") |
| 279 |
_WRAP_PROPERTY("always-show-image", bool, deprecated "There is no corresponding replacement when using Gio::Action.") |
| 280 |
|
| 281 |
protected: |
| 282 |
//Widget-creation routines: |
| 283 |
_WRAP_VFUNC(Widget* create_menu_item(), "create_menu_item") |
| 284 |
_WRAP_VFUNC(Widget* create_tool_item(), "create_tool_item") |
| 285 |
_WRAP_VFUNC(void connect_proxy(Widget* proxy), "connect_proxy") |
| 286 |
_WRAP_VFUNC(void disconnect_proxy(Widget* proxy), "disconnect_proxy") |
| 287 |
}; |
| 288 |
|
| 289 |
} // namespace Gtk |