1/* $Id: toggleaction.hg,v 1.5 2004/07/01 08:55:45 murrayc Exp $ */ 2 3/* Copyright (C) 2003 The gtkmm Development Team 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library 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 GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 20#include <gtkmm/action.h> 21 22_DEFS(gtkmm,gtk) 23_PINCLUDE(gtkmm/private/action_p.h) 24 25 26namespace Gtk 27{ 28 29/** An action which can be toggled between two states. 30 * 31 * A Gtk::ToggleAction corresponds roughly to a Gtk::CheckMenuItem. 32 * It has an "active" state specifying whether the action has been checked or not. 33 * 34 */ 35class ToggleAction : public Gtk::Action 36{ 37 _CLASS_GOBJECT(ToggleAction, GtkToggleAction, GTK_TOGGLE_ACTION, Gtk::Action, GtkAction) 38 39protected: 40 /** Creates an empty toggle action. */ 41 _CTOR_DEFAULT 42 43 /** 44 * Creates a toggle action. 45 * 46 * @param name A unique name for the action. 47 * @param stock_id The stock icon to display in widgets representing the 48 * action. 49 * @param label The label displayed in menu items and on buttons. 50 * @param tooltip A tooltip for the action. 51 * @param is_active The default checked state of the action. 52 */ 53 explicit ToggleAction(const Glib::ustring& name, const StockID& stock_id = StockID(), const Glib::ustring& label = Glib::ustring(), const Glib::ustring& tooltip = Glib::ustring(), bool is_active = false); 54 55 /** Creates a toggle action with an icon name. 56 * The toggle action's icon will reflect the specified icon name in the 57 * user's icon theme. 58 * 59 * @param name A unique name for the action. 60 * @param icon_name An IconTheme icon name used for widgets representing the 61 * action. 62 * @param label The label displayed in menu items and on buttons. 63 * @param tooltip A tooltip for the action. 64 * @param is_active The default checked state of the action. 65 */ 66 explicit ToggleAction(const Glib::ustring& name, const Glib::ustring& icon_name, const Glib::ustring& label = Glib::ustring(), const Glib::ustring& tooltip = Glib::ustring(), bool is_active = false); 67 68public: 69 //Note that gtk_toggle_action_new() does not allow name to be NULL, which suggests that we should not have a default constructor, 70 //but it's OK to set the name later: 71 _WRAP_CREATE() 72 73 /** Creates a toggle action. 74 * 75 * @param name A unique name for the action. 76 * @param label The label displayed in menu items and on buttons. 77 * @param tooltip A tooltip for the action. 78 * @param is_active The default checked state of the action. 79 * 80 * @return A new ToggleAction. 81 */ 82 static Glib::RefPtr<ToggleAction> create(const Glib::ustring& name, const Glib::ustring& label = Glib::ustring(), const Glib::ustring& tooltip = Glib::ustring(), bool is_active = false); 83 84 /** Creates a toggle action with a stock ID. 85 * The tock ID is used to set a default icon, text and accelerator for 86 * the toggle action. 87 * 88 * @param name A unique name for the action. 89 * @param stock_id The stock icon to display in widgets representing the 90 * action. 91 * @param label The label displayed in menu items and on buttons. 92 * @param tooltip A tooltip for the action. 93 * @param is_active The default checked state of the action. 94 * 95 * @return A new ToggleAction. 96 */ 97 static Glib::RefPtr<ToggleAction> create(const Glib::ustring& name, const Gtk::StockID& stock_id, const Glib::ustring& label = Glib::ustring(), const Glib::ustring& tooltip = Glib::ustring(), bool is_active = false); 98 99 /** Creates a toggle action with an icon name. 100 * The toggle action's icon will reflect the specified icon name in the 101 * user's icon theme. 102 * 103 * @param name A unique name for the action. 104 * @param icon_name An IconTheme icon name used for widgets representing the 105 * action. 106 * @param label The label displayed in menu items and on buttons. 107 * @param tooltip A tooltip for the action. 108 * @param is_active The default checked state of the action. 109 * 110 * @return A new ToggleAction. 111 */ 112 static Glib::RefPtr<ToggleAction> create_with_icon_name(const Glib::ustring& name, const Glib::ustring& icon_name, const Glib::ustring& label, const Glib::ustring& tooltip, bool is_active = false); 113 114 _WRAP_METHOD(void toggled(), gtk_toggle_action_toggled) 115 _WRAP_METHOD(void set_active(bool is_active = true), gtk_toggle_action_set_active) 116 _WRAP_METHOD(bool get_active() const, gtk_toggle_action_get_active) 117 _WRAP_METHOD(void set_draw_as_radio(bool draw_as_radio = true), gtk_toggle_action_set_draw_as_radio) 118 _WRAP_METHOD(bool get_draw_as_radio() const, gtk_toggle_action_get_draw_as_radio) 119 120 _WRAP_SIGNAL(void toggled(), "toggled") 121 122 _WRAP_PROPERTY("draw_as_radio", bool) 123 _WRAP_PROPERTY("active", bool) 124}; 125 126} // namespace Gtk 127 128