Debian Codegraph @

gtk/src/button.hg

raw
1 /* Copyright (C) 1998-2002 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 #include <gtkmm/bin.h>
18 #include <gtkmm/activatable.h>
19
20 _DEFS(gtkmm,gtk)
21 _PINCLUDE(gtkmm/private/bin_p.h)
22
23 namespace Gtk
24 {
25
26 class GTKMM_API StockID; //deprecated
27
28 //TODO: Derive from (and implement) Actionable when we can break ABI.
29
30 /** A widget that creates a signal when clicked on.
31 *
32 * This widget is generally used with a signal handler that is called when the button is pressed.
33 * It can hold any valid child widget. The most commonly used child is the Gtk::Label.
34 *
35 * The Button widget looks like this:
36 * @image html button2.png
37 *
38 * @ingroup Widgets
39 */
40 class GTKMM_API Button
41 : public Bin,
42 public Activatable
43 {
44 _CLASS_GTKOBJECT(Button,GtkButton,GTK_BUTTON,Gtk::Bin,GtkBin,,,GTKMM_API)
45 _IMPLEMENTS_INTERFACE(Activatable)
46 public:
47
48 /** Create an empty button.
49 * With an empty button, you can Gtk::Button::add() a widget
50 * such as a Gtk::Image or Gtk::Box.
51 *
52 * If you just wish to add a Gtk::Label,
53 * you may want to
54 * use the Gtk::Button(const Glib::ustring& label) ctor
55 * directly instead.
56 */
57 _CTOR_DEFAULT
58
59
60 /** Simple Push Button with label.
61 * Create a button with the given label inside. You won't be able
62 * to add a widget in this button since it already has a Gtk::Label
63 * in it
64 */
65 explicit Button(const Glib::ustring& label, bool mnemonic = false);
66
67 //We don't wrap gtk_button_new_from_icon_name() to avoid a clash with the label constructor.
68 //But set_image_from_icon_name() is a replacement.
69 _IGNORE(gtk_button_new_from_icon_name)
70
71 #ifndef GTKMM_DISABLE_DEPRECATED
72 /** Creates a new Button containing the image and text from a stock item.
73 * Stock ids have identifiers like Gtk::Stock::OK and Gtk::Stock::APPLY.
74 * @param stock_id The stock item.
75 * @deprecated Use the constructor that takes a Glib::ustring label or set_image_from_icon_name() instead, because stock IDs are now deprecated.
76 */
77 explicit Button(const StockID& stock_id);
78 #endif //GTKMM_DISABLE_DEPRECATED
79
80 _WRAP_METHOD(void clicked(), gtk_button_clicked)
81 _IGNORE(gtk_button_pressed, gtk_button_released, gtk_button_enter, gtk_button_leave) //deprecated
82
83 _WRAP_METHOD(void set_relief(ReliefStyle relief), gtk_button_set_relief)
84 _WRAP_METHOD(ReliefStyle get_relief() const, gtk_button_get_relief)
85
86 _WRAP_METHOD(void set_label(const Glib::ustring& label), gtk_button_set_label)
87 _WRAP_METHOD(Glib::ustring get_label() const, gtk_button_get_label)
88 _WRAP_METHOD(void set_use_underline(bool use_underline = true), gtk_button_set_use_underline)
89 _WRAP_METHOD(bool get_use_underline() const, gtk_button_get_use_underline)
90 _WRAP_METHOD(void set_use_stock(bool use_stock = true), gtk_button_set_use_stock, deprecated "No replacement available.")
91 _WRAP_METHOD(bool get_use_stock() const, gtk_button_get_use_stock, deprecated "No replacement available.")
92
93 _WRAP_METHOD(void set_focus_on_click(bool focus_on_click = true), gtk_button_set_focus_on_click,
94 deprecated "Use Widget::set_focus_on_click() instead.")
95 _WRAP_METHOD(bool get_focus_on_click() const, gtk_button_get_focus_on_click,
96 deprecated "Use Widget::get_focus_on_click() instead.")
97
98 _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.")
99 _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.")
100
101 //TODO: When we can break ABI, combine the two set_image_from_icon_name() to
102 // void set_image_from_icon_name(const Glib::ustring& icon_name, IconSize size = ICON_SIZE_BUTTON, bool use_fallback = false);
103 /** Sets the image to an icon from the current icon theme.
104 * If the icon name isn't known, a "broken image" icon will be
105 * displayed instead. If the current icon theme is changed, the icon
106 * will be updated appropriately.
107 * The icon will be displayed if there is no label text or if
108 * Gtk::Button::property_always_show_image() is <tt>true</tt>.
109 *
110 * This is a convenience wrapper around Gtk::Image::set_from_icon_name() and
111 * Gtk::Button:set_image().
112 *
113 * @param icon_name An icon name.
114 * @param size An icon size. Can be either an IconSize or a BuiltinIconSize.
115 *
116 * @newin{3,10}
117 */
118 void set_image_from_icon_name(const Glib::ustring& icon_name, IconSize size = ICON_SIZE_BUTTON);
119
120 /** Sets the image to an icon from the current icon theme.
121 * If the icon name isn't known, a "broken image" icon will be
122 * displayed instead. If the current icon theme is changed, the icon
123 * will be updated appropriately.
124 * The icon will be displayed if there is no label text or if
125 * Gtk::Button::property_always_show_image() is <tt>true</tt>.
126 *
127 * This is a convenience wrapper around Gtk::Image::set_from_icon_name() and
128 * Gtk::Button:set_image().
129 *
130 * @param icon_name An icon name.
131 * @param size An icon size. Can be either an IconSize or a BuiltinIconSize.
132 * @param use_fallback Whether the icon displayed in the Gtk::Image will use
133 * standard icon names fallback. See also Gtk::ICON_LOOKUP_GENERIC_FALLBACK.
134 *
135 * @newin{3,12}
136 */
137 void set_image_from_icon_name(const Glib::ustring& icon_name, IconSize size, bool use_fallback);
138
139 /** Set the image of the button to the given widget.
140 *
141 * The @a image will be displayed if the property_label() text is empty or if
142 * property_always_show_image() is <tt>true</tt>. You don’t have to call
143 * Gtk::Widget::show() on the @a image yourself.
144 *
145 * The image can be unset by assigning <tt>nullptr</tt> to property_image().
146 *
147 * @newin{2,6}
148 *
149 * @param image A widget to set as the image for the button.
150 */
151 _WRAP_METHOD(void set_image(Widget& image), gtk_button_set_image)
152 _WRAP_METHOD(Widget* get_image(), gtk_button_get_image)
153 _WRAP_METHOD(const Widget* get_image() const, gtk_button_get_image, constversion)
154
155 _WRAP_METHOD(void set_image_position(PositionType position), gtk_button_set_image_position)
156 _WRAP_METHOD(PositionType get_image_position() const, gtk_button_get_image_position)
157
158 _WRAP_METHOD(void set_always_show_image(bool always_show = true), gtk_button_set_always_show_image)
159 _WRAP_METHOD(bool get_always_show_image(), gtk_button_get_always_show_image)
160
161 _WRAP_METHOD(Glib::RefPtr<Gdk::Window> get_event_window(), gtk_button_get_event_window, refreturn)
162 _WRAP_METHOD(Glib::RefPtr<const Gdk::Window> get_event_window() const, gtk_button_get_event_window, refreturn, constversion)
163
164 _WRAP_SIGNAL(void pressed(), "pressed", deprecated "Use Widget::signal_button_press_event() instead.")
165 _WRAP_SIGNAL(void released(), "released", deprecated "Use Widget::signal_button_release_event() instead.")
166 _WRAP_SIGNAL(void clicked(), "clicked")
167 _WRAP_SIGNAL(void enter(), "enter", deprecated "Use Widget::signal_enter_notify_event() instead.")
168 _WRAP_SIGNAL(void leave(), "leave", deprecated "Use Widget::signal_leave_notify_event() instead.")
169 _WRAP_SIGNAL(void activate(), "activate", deprecated "Use signal_clicked() instead.")
170
171 _WRAP_PROPERTY("label", Glib::ustring)
172 _WRAP_PROPERTY("relief", ReliefStyle)
173 _WRAP_PROPERTY("use-underline", bool)
174 _WRAP_PROPERTY("use-stock", bool, deprecated "No replacement available.")
175
176 // GtkButton:focus-on-click has been removed from gtk+.
177 // TODO: At ABI-break, remove it from gtkmm.
178 #ifndef GTKMM_DISABLE_DEPRECATED
179 /** Whether the button grabs focus when it is clicked with the mouse.
180 * @deprecated Use Widget::property_focus_on_click() instead.
181 *
182 * @return A PropertyProxy that allows you to get or set the value of the property,
183 * or receive notification when the value of the property changes.
184 */
185 Glib::PropertyProxy< bool > property_focus_on_click() ;
186
187 /** Whether the button grabs focus when it is clicked with the mouse.
188 * @deprecated Use Widget::property_focus_on_click() instead.
189 *
190 * @return A PropertyProxy_ReadOnly that allows you to get the value of the property,
191 * or receive notification when the value of the property changes.
192 */
193 Glib::PropertyProxy_ReadOnly< bool > property_focus_on_click() const;
194 #endif // GTKMM_DISABLE_DEPRECATED
195 //_WRAP_PROPERTY("focus-on-click", bool, deprecated "Use Widget::property_focus_on_click() instead.")
196
197 _WRAP_PROPERTY("xalign", float, deprecated "Access the child widget directly if you need to control its alignment.")
198 _WRAP_PROPERTY("yalign", float, deprecated "Access the child widget directly if you need to control its alignment.")
199 _WRAP_PROPERTY("image", Gtk::Widget*)
200 _WRAP_PROPERTY("image-position", PositionType)
201 _WRAP_PROPERTY("always-show-image", bool)
202 };
203
204 /*! A Gtk::Button example.
205 * Example 1: @link book/buttons/button/buttons.h @endlink
206 * Example 2: @link book/buttons/button/buttons.cc @endlink
207 * Example 3: @link book/buttons/button/main.cc @endlink
208 */
209
210 } // namespace Gtk