/* Copyright (C) 1998-2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see .
*/
#include
#include
_DEFS(gtkmm,gtk)
_PINCLUDE(gtkmm/private/bin_p.h)
namespace Gtk
{
class GTKMM_API StockID; //deprecated
//TODO: Derive from (and implement) Actionable when we can break ABI.
/** A widget that creates a signal when clicked on.
*
* This widget is generally used with a signal handler that is called when the button is pressed.
* It can hold any valid child widget. The most commonly used child is the Gtk::Label.
*
* The Button widget looks like this:
* @image html button2.png
*
* @ingroup Widgets
*/
class GTKMM_API Button
: public Bin,
public Activatable
{
_CLASS_GTKOBJECT(Button,GtkButton,GTK_BUTTON,Gtk::Bin,GtkBin,,,GTKMM_API)
_IMPLEMENTS_INTERFACE(Activatable)
public:
/** Create an empty button.
* With an empty button, you can Gtk::Button::add() a widget
* such as a Gtk::Image or Gtk::Box.
*
* If you just wish to add a Gtk::Label,
* you may want to
* use the Gtk::Button(const Glib::ustring& label) ctor
* directly instead.
*/
_CTOR_DEFAULT
/** Simple Push Button with label.
* Create a button with the given label inside. You won't be able
* to add a widget in this button since it already has a Gtk::Label
* in it
*/
explicit Button(const Glib::ustring& label, bool mnemonic = false);
//We don't wrap gtk_button_new_from_icon_name() to avoid a clash with the label constructor.
//But set_image_from_icon_name() is a replacement.
_IGNORE(gtk_button_new_from_icon_name)
#ifndef GTKMM_DISABLE_DEPRECATED
/** Creates a new Button containing the image and text from a stock item.
* Stock ids have identifiers like Gtk::Stock::OK and Gtk::Stock::APPLY.
* @param stock_id The stock item.
* @deprecated Use the constructor that takes a Glib::ustring label or set_image_from_icon_name() instead, because stock IDs are now deprecated.
*/
explicit Button(const StockID& stock_id);
#endif //GTKMM_DISABLE_DEPRECATED
_WRAP_METHOD(void clicked(), gtk_button_clicked)
_IGNORE(gtk_button_pressed, gtk_button_released, gtk_button_enter, gtk_button_leave) //deprecated
_WRAP_METHOD(void set_relief(ReliefStyle relief), gtk_button_set_relief)
_WRAP_METHOD(ReliefStyle get_relief() const, gtk_button_get_relief)
_WRAP_METHOD(void set_label(const Glib::ustring& label), gtk_button_set_label)
_WRAP_METHOD(Glib::ustring get_label() const, gtk_button_get_label)
_WRAP_METHOD(void set_use_underline(bool use_underline = true), gtk_button_set_use_underline)
_WRAP_METHOD(bool get_use_underline() const, gtk_button_get_use_underline)
_WRAP_METHOD(void set_use_stock(bool use_stock = true), gtk_button_set_use_stock, deprecated "No replacement available.")
_WRAP_METHOD(bool get_use_stock() const, gtk_button_get_use_stock, deprecated "No replacement available.")
_WRAP_METHOD(void set_focus_on_click(bool focus_on_click = true), gtk_button_set_focus_on_click,
deprecated "Use Widget::set_focus_on_click() instead.")
_WRAP_METHOD(bool get_focus_on_click() const, gtk_button_get_focus_on_click,
deprecated "Use Widget::get_focus_on_click() instead.")
_WRAP_METHOD(void set_alignment(float xalign, float yalign), gtk_button_set_alignment, deprecated "Access the child widget directly if you need to control its alignment.")
_WRAP_METHOD(void get_alignment(float& xalign, float& yalign), gtk_button_get_alignment, deprecated "Access the child widget directly if you need to control its alignment.")
//TODO: When we can break ABI, combine the two set_image_from_icon_name() to
// void set_image_from_icon_name(const Glib::ustring& icon_name, IconSize size = ICON_SIZE_BUTTON, bool use_fallback = false);
/** Sets the image to an icon from the current icon theme.
* If the icon name isn't known, a "broken image" icon will be
* displayed instead. If the current icon theme is changed, the icon
* will be updated appropriately.
* The icon will be displayed if there is no label text or if
* Gtk::Button::property_always_show_image() is true.
*
* This is a convenience wrapper around Gtk::Image::set_from_icon_name() and
* Gtk::Button:set_image().
*
* @param icon_name An icon name.
* @param size An icon size. Can be either an IconSize or a BuiltinIconSize.
*
* @newin{3,10}
*/
void set_image_from_icon_name(const Glib::ustring& icon_name, IconSize size = ICON_SIZE_BUTTON);
/** Sets the image to an icon from the current icon theme.
* If the icon name isn't known, a "broken image" icon will be
* displayed instead. If the current icon theme is changed, the icon
* will be updated appropriately.
* The icon will be displayed if there is no label text or if
* Gtk::Button::property_always_show_image() is true.
*
* This is a convenience wrapper around Gtk::Image::set_from_icon_name() and
* Gtk::Button:set_image().
*
* @param icon_name An icon name.
* @param size An icon size. Can be either an IconSize or a BuiltinIconSize.
* @param use_fallback Whether the icon displayed in the Gtk::Image will use
* standard icon names fallback. See also Gtk::ICON_LOOKUP_GENERIC_FALLBACK.
*
* @newin{3,12}
*/
void set_image_from_icon_name(const Glib::ustring& icon_name, IconSize size, bool use_fallback);
/** Set the image of the button to the given widget.
*
* The @a image will be displayed if the property_label() text is empty or if
* property_always_show_image() is true. You don’t have to call
* Gtk::Widget::show() on the @a image yourself.
*
* The image can be unset by assigning nullptr to property_image().
*
* @newin{2,6}
*
* @param image A widget to set as the image for the button.
*/
_WRAP_METHOD(void set_image(Widget& image), gtk_button_set_image)
_WRAP_METHOD(Widget* get_image(), gtk_button_get_image)
_WRAP_METHOD(const Widget* get_image() const, gtk_button_get_image, constversion)
_WRAP_METHOD(void set_image_position(PositionType position), gtk_button_set_image_position)
_WRAP_METHOD(PositionType get_image_position() const, gtk_button_get_image_position)
_WRAP_METHOD(void set_always_show_image(bool always_show = true), gtk_button_set_always_show_image)
_WRAP_METHOD(bool get_always_show_image(), gtk_button_get_always_show_image)
_WRAP_METHOD(Glib::RefPtr get_event_window(), gtk_button_get_event_window, refreturn)
_WRAP_METHOD(Glib::RefPtr get_event_window() const, gtk_button_get_event_window, refreturn, constversion)
_WRAP_SIGNAL(void pressed(), "pressed", deprecated "Use Widget::signal_button_press_event() instead.")
_WRAP_SIGNAL(void released(), "released", deprecated "Use Widget::signal_button_release_event() instead.")
_WRAP_SIGNAL(void clicked(), "clicked")
_WRAP_SIGNAL(void enter(), "enter", deprecated "Use Widget::signal_enter_notify_event() instead.")
_WRAP_SIGNAL(void leave(), "leave", deprecated "Use Widget::signal_leave_notify_event() instead.")
_WRAP_SIGNAL(void activate(), "activate", deprecated "Use signal_clicked() instead.")
_WRAP_PROPERTY("label", Glib::ustring)
_WRAP_PROPERTY("relief", ReliefStyle)
_WRAP_PROPERTY("use-underline", bool)
_WRAP_PROPERTY("use-stock", bool, deprecated "No replacement available.")
// GtkButton:focus-on-click has been removed from gtk+.
// TODO: At ABI-break, remove it from gtkmm.
#ifndef GTKMM_DISABLE_DEPRECATED
/** Whether the button grabs focus when it is clicked with the mouse.
* @deprecated Use Widget::property_focus_on_click() instead.
*
* @return A PropertyProxy that allows you to get or set the value of the property,
* or receive notification when the value of the property changes.
*/
Glib::PropertyProxy< bool > property_focus_on_click() ;
/** Whether the button grabs focus when it is clicked with the mouse.
* @deprecated Use Widget::property_focus_on_click() instead.
*
* @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
* or receive notification when the value of the property changes.
*/
Glib::PropertyProxy_ReadOnly< bool > property_focus_on_click() const;
#endif // GTKMM_DISABLE_DEPRECATED
//_WRAP_PROPERTY("focus-on-click", bool, deprecated "Use Widget::property_focus_on_click() instead.")
_WRAP_PROPERTY("xalign", float, deprecated "Access the child widget directly if you need to control its alignment.")
_WRAP_PROPERTY("yalign", float, deprecated "Access the child widget directly if you need to control its alignment.")
_WRAP_PROPERTY("image", Gtk::Widget*)
_WRAP_PROPERTY("image-position", PositionType)
_WRAP_PROPERTY("always-show-image", bool)
};
/*! A Gtk::Button example.
* Example 1: @link book/buttons/button/buttons.h @endlink
* Example 2: @link book/buttons/button/buttons.cc @endlink
* Example 3: @link book/buttons/button/main.cc @endlink
*/
} // namespace Gtk