gtk/auto/button.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6 Actionable, Align, Bin, Buildable, Container, IconSize, PositionType, ReliefStyle, ResizeMode,
7 Widget, ffi,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// The [`Button`][crate::Button] widget is generally used to trigger a callback function that is
19 /// called when the button is pressed. The various signals and how to use them
20 /// are outlined below.
21 ///
22 /// The [`Button`][crate::Button] widget can hold any valid child widget. That is, it can hold
23 /// almost any other standard [`Widget`][crate::Widget]. The most commonly used child is the
24 /// [`Label`][crate::Label].
25 ///
26 /// # CSS nodes
27 ///
28 /// GtkButton has a single CSS node with name button. The node will get the
29 /// style classes .image-button or .text-button, if the content is just an
30 /// image or label, respectively. It may also receive the .flat style class.
31 ///
32 /// Other style classes that are commonly used with GtkButton include
33 /// .suggested-action and .destructive-action. In special cases, buttons
34 /// can be made round by adding the .circular style class.
35 ///
36 /// Button-like widgets like [`ToggleButton`][crate::ToggleButton], [`MenuButton`][crate::MenuButton], [`VolumeButton`][crate::VolumeButton],
37 /// [`LockButton`][crate::LockButton], [`ColorButton`][crate::ColorButton], [`FontButton`][crate::FontButton] or [`FileChooserButton`][crate::FileChooserButton] use
38 /// style classes such as .toggle, .popup, .scale, .lock, .color, .font, .file
39 /// to differentiate themselves from a plain GtkButton.
40 ///
41 /// ## Properties
42 ///
43 ///
44 /// #### `always-show-image`
45 /// If [`true`], the button will ignore the [`gtk-button-images`][struct@crate::Settings#gtk-button-images]
46 /// setting and always show the image, if available.
47 ///
48 /// Use this property if the button would be useless or hard to use
49 /// without the image.
50 ///
51 /// Readable | Writable | Construct
52 ///
53 ///
54 /// #### `image`
55 /// The child widget to appear next to the button text.
56 ///
57 /// Readable | Writable
58 ///
59 ///
60 /// #### `image-position`
61 /// The position of the image relative to the text inside the button.
62 ///
63 /// Readable | Writable
64 ///
65 ///
66 /// #### `label`
67 /// Readable | Writable | Construct
68 ///
69 ///
70 /// #### `relief`
71 /// Readable | Writable
72 ///
73 ///
74 /// #### `use-stock`
75 /// Readable | Writable | Construct
76 ///
77 ///
78 /// #### `use-underline`
79 /// Readable | Writable | Construct
80 ///
81 ///
82 /// #### `xalign`
83 /// If the child of the button is a [`Misc`][crate::Misc] or `GtkAlignment`, this property
84 /// can be used to control its horizontal alignment. 0.0 is left aligned,
85 /// 1.0 is right aligned.
86 ///
87 /// Readable | Writable
88 ///
89 ///
90 /// #### `yalign`
91 /// If the child of the button is a [`Misc`][crate::Misc] or `GtkAlignment`, this property
92 /// can be used to control its vertical alignment. 0.0 is top aligned,
93 /// 1.0 is bottom aligned.
94 ///
95 /// Readable | Writable
96 /// <details><summary><h4>Container</h4></summary>
97 ///
98 ///
99 /// #### `border-width`
100 /// Readable | Writable
101 ///
102 ///
103 /// #### `child`
104 /// Writable
105 ///
106 ///
107 /// #### `resize-mode`
108 /// Readable | Writable
109 /// </details>
110 /// <details><summary><h4>Widget</h4></summary>
111 ///
112 ///
113 /// #### `app-paintable`
114 /// Readable | Writable
115 ///
116 ///
117 /// #### `can-default`
118 /// Readable | Writable
119 ///
120 ///
121 /// #### `can-focus`
122 /// Readable | Writable
123 ///
124 ///
125 /// #### `composite-child`
126 /// Readable
127 ///
128 ///
129 /// #### `double-buffered`
130 /// Whether the widget is double buffered.
131 ///
132 /// Readable | Writable
133 ///
134 ///
135 /// #### `events`
136 /// Readable | Writable
137 ///
138 ///
139 /// #### `expand`
140 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
141 ///
142 /// Readable | Writable
143 ///
144 ///
145 /// #### `focus-on-click`
146 /// Whether the widget should grab focus when it is clicked with the mouse.
147 ///
148 /// This property is only relevant for widgets that can take focus.
149 ///
150 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
151 /// GtkComboBox) implemented this property individually.
152 ///
153 /// Readable | Writable
154 ///
155 ///
156 /// #### `halign`
157 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
158 ///
159 /// Readable | Writable
160 ///
161 ///
162 /// #### `has-default`
163 /// Readable | Writable
164 ///
165 ///
166 /// #### `has-focus`
167 /// Readable | Writable
168 ///
169 ///
170 /// #### `has-tooltip`
171 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
172 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
173 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
174 /// whether it will provide a tooltip or not.
175 ///
176 /// Note that setting this property to [`true`] for the first time will change
177 /// the event masks of the GdkWindows of this widget to include leave-notify
178 /// and motion-notify events. This cannot and will not be undone when the
179 /// property is set to [`false`] again.
180 ///
181 /// Readable | Writable
182 ///
183 ///
184 /// #### `height-request`
185 /// Readable | Writable
186 ///
187 ///
188 /// #### `hexpand`
189 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
190 ///
191 /// Readable | Writable
192 ///
193 ///
194 /// #### `hexpand-set`
195 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
196 ///
197 /// Readable | Writable
198 ///
199 ///
200 /// #### `is-focus`
201 /// Readable | Writable
202 ///
203 ///
204 /// #### `margin`
205 /// Sets all four sides' margin at once. If read, returns max
206 /// margin on any side.
207 ///
208 /// Readable | Writable
209 ///
210 ///
211 /// #### `margin-bottom`
212 /// Margin on bottom side of widget.
213 ///
214 /// This property adds margin outside of the widget's normal size
215 /// request, the margin will be added in addition to the size from
216 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
217 ///
218 /// Readable | Writable
219 ///
220 ///
221 /// #### `margin-end`
222 /// Margin on end of widget, horizontally. This property supports
223 /// left-to-right and right-to-left text directions.
224 ///
225 /// This property adds margin outside of the widget's normal size
226 /// request, the margin will be added in addition to the size from
227 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
228 ///
229 /// Readable | Writable
230 ///
231 ///
232 /// #### `margin-left`
233 /// Margin on left side of widget.
234 ///
235 /// This property adds margin outside of the widget's normal size
236 /// request, the margin will be added in addition to the size from
237 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
238 ///
239 /// Readable | Writable
240 ///
241 ///
242 /// #### `margin-right`
243 /// Margin on right side of widget.
244 ///
245 /// This property adds margin outside of the widget's normal size
246 /// request, the margin will be added in addition to the size from
247 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
248 ///
249 /// Readable | Writable
250 ///
251 ///
252 /// #### `margin-start`
253 /// Margin on start of widget, horizontally. This property supports
254 /// left-to-right and right-to-left text directions.
255 ///
256 /// This property adds margin outside of the widget's normal size
257 /// request, the margin will be added in addition to the size from
258 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
259 ///
260 /// Readable | Writable
261 ///
262 ///
263 /// #### `margin-top`
264 /// Margin on top side of widget.
265 ///
266 /// This property adds margin outside of the widget's normal size
267 /// request, the margin will be added in addition to the size from
268 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
269 ///
270 /// Readable | Writable
271 ///
272 ///
273 /// #### `name`
274 /// Readable | Writable
275 ///
276 ///
277 /// #### `no-show-all`
278 /// Readable | Writable
279 ///
280 ///
281 /// #### `opacity`
282 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
283 /// more details about window opacity.
284 ///
285 /// Before 3.8 this was only available in GtkWindow
286 ///
287 /// Readable | Writable
288 ///
289 ///
290 /// #### `parent`
291 /// Readable | Writable
292 ///
293 ///
294 /// #### `receives-default`
295 /// Readable | Writable
296 ///
297 ///
298 /// #### `scale-factor`
299 /// The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
300 /// more details about widget scaling.
301 ///
302 /// Readable
303 ///
304 ///
305 /// #### `sensitive`
306 /// Readable | Writable
307 ///
308 ///
309 /// #### `style`
310 /// The style of the widget, which contains information about how it will look (colors, etc).
311 ///
312 /// Readable | Writable
313 ///
314 ///
315 /// #### `tooltip-markup`
316 /// Sets the text of tooltip to be the given string, which is marked up
317 /// with the [Pango text markup language][PangoMarkupFormat].
318 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
319 ///
320 /// This is a convenience property which will take care of getting the
321 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
322 /// will automatically be set to [`true`] and there will be taken care of
323 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
324 ///
325 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
326 /// are set, the last one wins.
327 ///
328 /// Readable | Writable
329 ///
330 ///
331 /// #### `tooltip-text`
332 /// Sets the text of tooltip to be the given string.
333 ///
334 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
335 ///
336 /// This is a convenience property which will take care of getting the
337 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
338 /// will automatically be set to [`true`] and there will be taken care of
339 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
340 ///
341 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
342 /// are set, the last one wins.
343 ///
344 /// Readable | Writable
345 ///
346 ///
347 /// #### `valign`
348 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
349 ///
350 /// Readable | Writable
351 ///
352 ///
353 /// #### `vexpand`
354 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
355 ///
356 /// Readable | Writable
357 ///
358 ///
359 /// #### `vexpand-set`
360 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
361 ///
362 /// Readable | Writable
363 ///
364 ///
365 /// #### `visible`
366 /// Readable | Writable
367 ///
368 ///
369 /// #### `width-request`
370 /// Readable | Writable
371 ///
372 ///
373 /// #### `window`
374 /// The widget's window if it is realized, [`None`] otherwise.
375 ///
376 /// Readable
377 /// </details>
378 /// <details><summary><h4>Actionable</h4></summary>
379 ///
380 ///
381 /// #### `action-name`
382 /// Readable | Writable
383 ///
384 ///
385 /// #### `action-target`
386 /// Readable | Writable
387 /// </details>
388 /// <details><summary><h4>Activatable</h4></summary>
389 ///
390 ///
391 /// #### `related-action`
392 /// The action that this activatable will activate and receive
393 /// updates from for various states and possibly appearance.
394 ///
395 /// > `GtkActivatable` implementors need to handle the this property and
396 /// > call `gtk_activatable_do_set_related_action()` when it changes.
397 ///
398 /// Readable | Writable
399 ///
400 ///
401 /// #### `use-action-appearance`
402 /// Whether this activatable should reset its layout
403 /// and appearance when setting the related action or when
404 /// the action changes appearance.
405 ///
406 /// See the `GtkAction` documentation directly to find which properties
407 /// should be ignored by the `GtkActivatable` when this property is [`false`].
408 ///
409 /// > `GtkActivatable` implementors need to handle this property
410 /// > and call `gtk_activatable_sync_action_properties()` on the activatable
411 /// > widget when it changes.
412 ///
413 /// Readable | Writable
414 /// </details>
415 ///
416 /// ## Signals
417 ///
418 ///
419 /// #### `activate`
420 /// The ::activate signal on GtkButton is an action signal and
421 /// emitting it causes the button to animate press then release.
422 /// Applications should never connect to this signal, but use the
423 /// [`clicked`][struct@crate::Button#clicked] signal.
424 ///
425 /// Action
426 ///
427 ///
428 /// #### `clicked`
429 /// Emitted when the button has been activated (pressed and released).
430 ///
431 /// Action
432 ///
433 ///
434 /// #### `enter`
435 /// Emitted when the pointer enters the button.
436 ///
437 ///
438 ///
439 ///
440 /// #### `leave`
441 /// Emitted when the pointer leaves the button.
442 ///
443 ///
444 ///
445 ///
446 /// #### `pressed`
447 /// Emitted when the button is pressed.
448 ///
449 ///
450 ///
451 ///
452 /// #### `released`
453 /// Emitted when the button is released.
454 ///
455 ///
456 /// <details><summary><h4>Container</h4></summary>
457 ///
458 ///
459 /// #### `add`
460 ///
461 ///
462 ///
463 /// #### `check-resize`
464 ///
465 ///
466 ///
467 /// #### `remove`
468 ///
469 ///
470 ///
471 /// #### `set-focus-child`
472 ///
473 /// </details>
474 /// <details><summary><h4>Widget</h4></summary>
475 ///
476 ///
477 /// #### `accel-closures-changed`
478 ///
479 ///
480 ///
481 /// #### `button-press-event`
482 /// The ::button-press-event signal will be emitted when a button
483 /// (typically from a mouse) is pressed.
484 ///
485 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the
486 /// widget needs to enable the [`gdk::EventMask::BUTTON_PRESS_MASK`][crate::gdk::EventMask::BUTTON_PRESS_MASK] mask.
487 ///
488 /// This signal will be sent to the grab widget if there is one.
489 ///
490 ///
491 ///
492 ///
493 /// #### `button-release-event`
494 /// The ::button-release-event signal will be emitted when a button
495 /// (typically from a mouse) is released.
496 ///
497 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the
498 /// widget needs to enable the [`gdk::EventMask::BUTTON_RELEASE_MASK`][crate::gdk::EventMask::BUTTON_RELEASE_MASK] mask.
499 ///
500 /// This signal will be sent to the grab widget if there is one.
501 ///
502 ///
503 ///
504 ///
505 /// #### `can-activate-accel`
506 /// Determines whether an accelerator that activates the signal
507 /// identified by `signal_id` can currently be activated.
508 /// This signal is present to allow applications and derived
509 /// widgets to override the default [`Widget`][crate::Widget] handling
510 /// for determining whether an accelerator can be activated.
511 ///
512 ///
513 ///
514 ///
515 /// #### `child-notify`
516 /// The ::child-notify signal is emitted for each
517 /// [child property][child-properties] that has
518 /// changed on an object. The signal's detail holds the property name.
519 ///
520 /// Detailed
521 ///
522 ///
523 /// #### `composited-changed`
524 /// The ::composited-changed signal is emitted when the composited
525 /// status of `widgets` screen changes.
526 /// See [`Screen::is_composited()`][crate::gdk::Screen::is_composited()].
527 ///
528 /// Action
529 ///
530 ///
531 /// #### `configure-event`
532 /// The ::configure-event signal will be emitted when the size, position or
533 /// stacking of the `widget`'s window has changed.
534 ///
535 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
536 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
537 /// automatically for all new windows.
538 ///
539 ///
540 ///
541 ///
542 /// #### `damage-event`
543 /// Emitted when a redirected window belonging to `widget` gets drawn into.
544 /// The region/area members of the event shows what area of the redirected
545 /// drawable was drawn into.
546 ///
547 ///
548 ///
549 ///
550 /// #### `delete-event`
551 /// The ::delete-event signal is emitted if a user requests that
552 /// a toplevel window is closed. The default handler for this signal
553 /// destroys the window. Connecting [`WidgetExtManual::hide_on_delete()`][crate::prelude::WidgetExtManual::hide_on_delete()] to
554 /// this signal will cause the window to be hidden instead, so that
555 /// it can later be shown again without reconstructing it.
556 ///
557 ///
558 ///
559 ///
560 /// #### `destroy`
561 /// Signals that all holders of a reference to the widget should release
562 /// the reference that they hold. May result in finalization of the widget
563 /// if all references are released.
564 ///
565 /// This signal is not suitable for saving widget state.
566 ///
567 ///
568 ///
569 ///
570 /// #### `destroy-event`
571 /// The ::destroy-event signal is emitted when a [`gdk::Window`][crate::gdk::Window] is destroyed.
572 /// You rarely get this signal, because most widgets disconnect themselves
573 /// from their window before they destroy it, so no widget owns the
574 /// window at destroy time.
575 ///
576 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
577 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
578 /// automatically for all new windows.
579 ///
580 ///
581 ///
582 ///
583 /// #### `direction-changed`
584 /// The ::direction-changed signal is emitted when the text direction
585 /// of a widget changes.
586 ///
587 ///
588 ///
589 ///
590 /// #### `drag-begin`
591 /// The ::drag-begin signal is emitted on the drag source when a drag is
592 /// started. A typical reason to connect to this signal is to set up a
593 /// custom drag icon with e.g. [`WidgetExt::drag_source_set_icon_pixbuf()`][crate::prelude::WidgetExt::drag_source_set_icon_pixbuf()].
594 ///
595 /// Note that some widgets set up a drag icon in the default handler of
596 /// this signal, so you may have to use `g_signal_connect_after()` to
597 /// override what the default handler did.
598 ///
599 ///
600 ///
601 ///
602 /// #### `drag-data-delete`
603 /// The ::drag-data-delete signal is emitted on the drag source when a drag
604 /// with the action [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE] is successfully completed. The signal
605 /// handler is responsible for deleting the data that has been dropped. What
606 /// "delete" means depends on the context of the drag operation.
607 ///
608 ///
609 ///
610 ///
611 /// #### `drag-data-get`
612 /// The ::drag-data-get signal is emitted on the drag source when the drop
613 /// site requests the data which is dragged. It is the responsibility of
614 /// the signal handler to fill `data` with the data in the format which
615 /// is indicated by `info`. See [`SelectionData::set()`][crate::SelectionData::set()] and
616 /// [`SelectionData::set_text()`][crate::SelectionData::set_text()].
617 ///
618 ///
619 ///
620 ///
621 /// #### `drag-data-received`
622 /// The ::drag-data-received signal is emitted on the drop site when the
623 /// dragged data has been received. If the data was received in order to
624 /// determine whether the drop will be accepted, the handler is expected
625 /// to call `gdk_drag_status()` and not finish the drag.
626 /// If the data was received in response to a [`drag-drop`][struct@crate::Widget#drag-drop] signal
627 /// (and this is the last target to be received), the handler for this
628 /// signal is expected to process the received data and then call
629 /// `gtk_drag_finish()`, setting the `success` parameter depending on
630 /// whether the data was processed successfully.
631 ///
632 /// Applications must create some means to determine why the signal was emitted
633 /// and therefore whether to call `gdk_drag_status()` or `gtk_drag_finish()`.
634 ///
635 /// The handler may inspect the selected action with
636 /// [`DragContext::selected_action()`][crate::gdk::DragContext::selected_action()] before calling
637 /// `gtk_drag_finish()`, e.g. to implement [`gdk::DragAction::ASK`][crate::gdk::DragAction::ASK] as
638 /// shown in the following example:
639 ///
640 ///
641 /// **⚠️ The following code is in C ⚠️**
642 ///
643 /// ```C
644 /// void
645 /// drag_data_received (GtkWidget *widget,
646 /// GdkDragContext *context,
647 /// gint x,
648 /// gint y,
649 /// GtkSelectionData *data,
650 /// guint info,
651 /// guint time)
652 /// {
653 /// if ((data->length >= 0) && (data->format == 8))
654 /// {
655 /// GdkDragAction action;
656 ///
657 /// // handle data here
658 ///
659 /// action = gdk_drag_context_get_selected_action (context);
660 /// if (action == GDK_ACTION_ASK)
661 /// {
662 /// GtkWidget *dialog;
663 /// gint response;
664 ///
665 /// dialog = gtk_message_dialog_new (NULL,
666 /// GTK_DIALOG_MODAL |
667 /// GTK_DIALOG_DESTROY_WITH_PARENT,
668 /// GTK_MESSAGE_INFO,
669 /// GTK_BUTTONS_YES_NO,
670 /// "Move the data ?\n");
671 /// response = gtk_dialog_run (GTK_DIALOG (dialog));
672 /// gtk_widget_destroy (dialog);
673 ///
674 /// if (response == GTK_RESPONSE_YES)
675 /// action = GDK_ACTION_MOVE;
676 /// else
677 /// action = GDK_ACTION_COPY;
678 /// }
679 ///
680 /// gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
681 /// }
682 /// else
683 /// gtk_drag_finish (context, FALSE, FALSE, time);
684 /// }
685 /// ```
686 ///
687 ///
688 ///
689 ///
690 /// #### `drag-drop`
691 /// The ::drag-drop signal is emitted on the drop site when the user drops
692 /// the data onto the widget. The signal handler must determine whether
693 /// the cursor position is in a drop zone or not. If it is not in a drop
694 /// zone, it returns [`false`] and no further processing is necessary.
695 /// Otherwise, the handler returns [`true`]. In this case, the handler must
696 /// ensure that `gtk_drag_finish()` is called to let the source know that
697 /// the drop is done. The call to `gtk_drag_finish()` can be done either
698 /// directly or in a [`drag-data-received`][struct@crate::Widget#drag-data-received] handler which gets
699 /// triggered by calling [`WidgetExt::drag_get_data()`][crate::prelude::WidgetExt::drag_get_data()] to receive the data for one
700 /// or more of the supported targets.
701 ///
702 ///
703 ///
704 ///
705 /// #### `drag-end`
706 /// The ::drag-end signal is emitted on the drag source when a drag is
707 /// finished. A typical reason to connect to this signal is to undo
708 /// things done in [`drag-begin`][struct@crate::Widget#drag-begin].
709 ///
710 ///
711 ///
712 ///
713 /// #### `drag-failed`
714 /// The ::drag-failed signal is emitted on the drag source when a drag has
715 /// failed. The signal handler may hook custom code to handle a failed DnD
716 /// operation based on the type of error, it returns [`true`] is the failure has
717 /// been already handled (not showing the default "drag operation failed"
718 /// animation), otherwise it returns [`false`].
719 ///
720 ///
721 ///
722 ///
723 /// #### `drag-leave`
724 /// The ::drag-leave signal is emitted on the drop site when the cursor
725 /// leaves the widget. A typical reason to connect to this signal is to
726 /// undo things done in [`drag-motion`][struct@crate::Widget#drag-motion], e.g. undo highlighting
727 /// with [`WidgetExt::drag_unhighlight()`][crate::prelude::WidgetExt::drag_unhighlight()].
728 ///
729 ///
730 /// Likewise, the [`drag-leave`][struct@crate::Widget#drag-leave] signal is also emitted before the
731 /// ::drag-drop signal, for instance to allow cleaning up of a preview item
732 /// created in the [`drag-motion`][struct@crate::Widget#drag-motion] signal handler.
733 ///
734 ///
735 ///
736 ///
737 /// #### `drag-motion`
738 /// The ::drag-motion signal is emitted on the drop site when the user
739 /// moves the cursor over the widget during a drag. The signal handler
740 /// must determine whether the cursor position is in a drop zone or not.
741 /// If it is not in a drop zone, it returns [`false`] and no further processing
742 /// is necessary. Otherwise, the handler returns [`true`]. In this case, the
743 /// handler is responsible for providing the necessary information for
744 /// displaying feedback to the user, by calling `gdk_drag_status()`.
745 ///
746 /// If the decision whether the drop will be accepted or rejected can't be
747 /// made based solely on the cursor position and the type of the data, the
748 /// handler may inspect the dragged data by calling [`WidgetExt::drag_get_data()`][crate::prelude::WidgetExt::drag_get_data()] and
749 /// defer the `gdk_drag_status()` call to the [`drag-data-received`][struct@crate::Widget#drag-data-received]
750 /// handler. Note that you must pass [`DestDefaults::DROP`][crate::DestDefaults::DROP],
751 /// [`DestDefaults::MOTION`][crate::DestDefaults::MOTION] or [`DestDefaults::ALL`][crate::DestDefaults::ALL] to [`WidgetExtManual::drag_dest_set()`][crate::prelude::WidgetExtManual::drag_dest_set()]
752 /// when using the drag-motion signal that way.
753 ///
754 /// Also note that there is no drag-enter signal. The drag receiver has to
755 /// keep track of whether he has received any drag-motion signals since the
756 /// last [`drag-leave`][struct@crate::Widget#drag-leave] and if not, treat the drag-motion signal as
757 /// an "enter" signal. Upon an "enter", the handler will typically highlight
758 /// the drop site with [`WidgetExt::drag_highlight()`][crate::prelude::WidgetExt::drag_highlight()].
759 ///
760 ///
761 /// **⚠️ The following code is in C ⚠️**
762 ///
763 /// ```C
764 /// static void
765 /// drag_motion (GtkWidget *widget,
766 /// GdkDragContext *context,
767 /// gint x,
768 /// gint y,
769 /// guint time)
770 /// {
771 /// GdkAtom target;
772 ///
773 /// PrivateData *private_data = GET_PRIVATE_DATA (widget);
774 ///
775 /// if (!private_data->drag_highlight)
776 /// {
777 /// private_data->drag_highlight = 1;
778 /// gtk_drag_highlight (widget);
779 /// }
780 ///
781 /// target = gtk_drag_dest_find_target (widget, context, NULL);
782 /// if (target == GDK_NONE)
783 /// gdk_drag_status (context, 0, time);
784 /// else
785 /// {
786 /// private_data->pending_status
787 /// = gdk_drag_context_get_suggested_action (context);
788 /// gtk_drag_get_data (widget, context, target, time);
789 /// }
790 ///
791 /// return TRUE;
792 /// }
793 ///
794 /// static void
795 /// drag_data_received (GtkWidget *widget,
796 /// GdkDragContext *context,
797 /// gint x,
798 /// gint y,
799 /// GtkSelectionData *selection_data,
800 /// guint info,
801 /// guint time)
802 /// {
803 /// PrivateData *private_data = GET_PRIVATE_DATA (widget);
804 ///
805 /// if (private_data->suggested_action)
806 /// {
807 /// private_data->suggested_action = 0;
808 ///
809 /// // We are getting this data due to a request in drag_motion,
810 /// // rather than due to a request in drag_drop, so we are just
811 /// // supposed to call gdk_drag_status(), not actually paste in
812 /// // the data.
813 ///
814 /// str = gtk_selection_data_get_text (selection_data);
815 /// if (!data_is_acceptable (str))
816 /// gdk_drag_status (context, 0, time);
817 /// else
818 /// gdk_drag_status (context,
819 /// private_data->suggested_action,
820 /// time);
821 /// }
822 /// else
823 /// {
824 /// // accept the drop
825 /// }
826 /// }
827 /// ```
828 ///
829 ///
830 ///
831 ///
832 /// #### `draw`
833 /// This signal is emitted when a widget is supposed to render itself.
834 /// The `widget`'s top left corner must be painted at the origin of
835 /// the passed in context and be sized to the values returned by
836 /// [`WidgetExt::allocated_width()`][crate::prelude::WidgetExt::allocated_width()] and
837 /// [`WidgetExt::allocated_height()`][crate::prelude::WidgetExt::allocated_height()].
838 ///
839 /// Signal handlers connected to this signal can modify the cairo
840 /// context passed as `cr` in any way they like and don't need to
841 /// restore it. The signal emission takes care of calling `cairo_save()`
842 /// before and `cairo_restore()` after invoking the handler.
843 ///
844 /// The signal handler will get a `cr` with a clip region already set to the
845 /// widget's dirty region, i.e. to the area that needs repainting. Complicated
846 /// widgets that want to avoid redrawing themselves completely can get the full
847 /// extents of the clip region with `gdk_cairo_get_clip_rectangle()`, or they can
848 /// get a finer-grained representation of the dirty region with
849 /// `cairo_copy_clip_rectangle_list()`.
850 ///
851 ///
852 ///
853 ///
854 /// #### `enter-notify-event`
855 /// The ::enter-notify-event will be emitted when the pointer enters
856 /// the `widget`'s window.
857 ///
858 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
859 /// to enable the [`gdk::EventMask::ENTER_NOTIFY_MASK`][crate::gdk::EventMask::ENTER_NOTIFY_MASK] mask.
860 ///
861 /// This signal will be sent to the grab widget if there is one.
862 ///
863 ///
864 ///
865 ///
866 /// #### `event`
867 /// The GTK+ main loop will emit three signals for each GDK event delivered
868 /// to a widget: one generic ::event signal, another, more specific,
869 /// signal that matches the type of event delivered (e.g.
870 /// [`key-press-event`][struct@crate::Widget#key-press-event]) and finally a generic
871 /// [`event-after`][struct@crate::Widget#event-after] signal.
872 ///
873 ///
874 ///
875 ///
876 /// #### `event-after`
877 /// After the emission of the [`event`][struct@crate::Widget#event] signal and (optionally)
878 /// the second more specific signal, ::event-after will be emitted
879 /// regardless of the previous two signals handlers return values.
880 ///
881 ///
882 ///
883 ///
884 /// #### `focus`
885 ///
886 ///
887 ///
888 /// #### `focus-in-event`
889 /// The ::focus-in-event signal will be emitted when the keyboard focus
890 /// enters the `widget`'s window.
891 ///
892 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
893 /// to enable the [`gdk::EventMask::FOCUS_CHANGE_MASK`][crate::gdk::EventMask::FOCUS_CHANGE_MASK] mask.
894 ///
895 ///
896 ///
897 ///
898 /// #### `focus-out-event`
899 /// The ::focus-out-event signal will be emitted when the keyboard focus
900 /// leaves the `widget`'s window.
901 ///
902 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
903 /// to enable the [`gdk::EventMask::FOCUS_CHANGE_MASK`][crate::gdk::EventMask::FOCUS_CHANGE_MASK] mask.
904 ///
905 ///
906 ///
907 ///
908 /// #### `grab-broken-event`
909 /// Emitted when a pointer or keyboard grab on a window belonging
910 /// to `widget` gets broken.
911 ///
912 /// On X11, this happens when the grab window becomes unviewable
913 /// (i.e. it or one of its ancestors is unmapped), or if the same
914 /// application grabs the pointer or keyboard again.
915 ///
916 ///
917 ///
918 ///
919 /// #### `grab-focus`
920 /// Action
921 ///
922 ///
923 /// #### `grab-notify`
924 /// The ::grab-notify signal is emitted when a widget becomes
925 /// shadowed by a GTK+ grab (not a pointer or keyboard grab) on
926 /// another widget, or when it becomes unshadowed due to a grab
927 /// being removed.
928 ///
929 /// A widget is shadowed by a [`WidgetExt::grab_add()`][crate::prelude::WidgetExt::grab_add()] when the topmost
930 /// grab widget in the grab stack of its window group is not
931 /// its ancestor.
932 ///
933 ///
934 ///
935 ///
936 /// #### `hide`
937 /// The ::hide signal is emitted when `widget` is hidden, for example with
938 /// [`WidgetExt::hide()`][crate::prelude::WidgetExt::hide()].
939 ///
940 ///
941 ///
942 ///
943 /// #### `hierarchy-changed`
944 /// The ::hierarchy-changed signal is emitted when the
945 /// anchored state of a widget changes. A widget is
946 /// “anchored” when its toplevel
947 /// ancestor is a [`Window`][crate::Window]. This signal is emitted when
948 /// a widget changes from un-anchored to anchored or vice-versa.
949 ///
950 ///
951 ///
952 ///
953 /// #### `key-press-event`
954 /// The ::key-press-event signal is emitted when a key is pressed. The signal
955 /// emission will reoccur at the key-repeat rate when the key is kept pressed.
956 ///
957 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
958 /// to enable the [`gdk::EventMask::KEY_PRESS_MASK`][crate::gdk::EventMask::KEY_PRESS_MASK] mask.
959 ///
960 /// This signal will be sent to the grab widget if there is one.
961 ///
962 ///
963 ///
964 ///
965 /// #### `key-release-event`
966 /// The ::key-release-event signal is emitted when a key is released.
967 ///
968 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
969 /// to enable the [`gdk::EventMask::KEY_RELEASE_MASK`][crate::gdk::EventMask::KEY_RELEASE_MASK] mask.
970 ///
971 /// This signal will be sent to the grab widget if there is one.
972 ///
973 ///
974 ///
975 ///
976 /// #### `keynav-failed`
977 /// Gets emitted if keyboard navigation fails.
978 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
979 ///
980 ///
981 ///
982 ///
983 /// #### `leave-notify-event`
984 /// The ::leave-notify-event will be emitted when the pointer leaves
985 /// the `widget`'s window.
986 ///
987 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
988 /// to enable the [`gdk::EventMask::LEAVE_NOTIFY_MASK`][crate::gdk::EventMask::LEAVE_NOTIFY_MASK] mask.
989 ///
990 /// This signal will be sent to the grab widget if there is one.
991 ///
992 ///
993 ///
994 ///
995 /// #### `map`
996 /// The ::map signal is emitted when `widget` is going to be mapped, that is
997 /// when the widget is visible (which is controlled with
998 /// [`WidgetExt::set_visible()`][crate::prelude::WidgetExt::set_visible()]) and all its parents up to the toplevel widget
999 /// are also visible. Once the map has occurred, [`map-event`][struct@crate::Widget#map-event] will
1000 /// be emitted.
1001 ///
1002 /// The ::map signal can be used to determine whether a widget will be drawn,
1003 /// for instance it can resume an animation that was stopped during the
1004 /// emission of [`unmap`][struct@crate::Widget#unmap].
1005 ///
1006 ///
1007 ///
1008 ///
1009 /// #### `map-event`
1010 /// The ::map-event signal will be emitted when the `widget`'s window is
1011 /// mapped. A window is mapped when it becomes visible on the screen.
1012 ///
1013 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1014 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
1015 /// automatically for all new windows.
1016 ///
1017 ///
1018 ///
1019 ///
1020 /// #### `mnemonic-activate`
1021 /// The default handler for this signal activates `widget` if `group_cycling`
1022 /// is [`false`], or just makes `widget` grab focus if `group_cycling` is [`true`].
1023 ///
1024 ///
1025 ///
1026 ///
1027 /// #### `motion-notify-event`
1028 /// The ::motion-notify-event signal is emitted when the pointer moves
1029 /// over the widget's [`gdk::Window`][crate::gdk::Window].
1030 ///
1031 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget
1032 /// needs to enable the [`gdk::EventMask::POINTER_MOTION_MASK`][crate::gdk::EventMask::POINTER_MOTION_MASK] mask.
1033 ///
1034 /// This signal will be sent to the grab widget if there is one.
1035 ///
1036 ///
1037 ///
1038 ///
1039 /// #### `move-focus`
1040 /// Action
1041 ///
1042 ///
1043 /// #### `parent-set`
1044 /// The ::parent-set signal is emitted when a new parent
1045 /// has been set on a widget.
1046 ///
1047 ///
1048 ///
1049 ///
1050 /// #### `popup-menu`
1051 /// This signal gets emitted whenever a widget should pop up a context
1052 /// menu. This usually happens through the standard key binding mechanism;
1053 /// by pressing a certain key while a widget is focused, the user can cause
1054 /// the widget to pop up a menu. For example, the [`Entry`][crate::Entry] widget creates
1055 /// a menu with clipboard commands. See the
1056 /// [Popup Menu Migration Checklist][checklist-popup-menu]
1057 /// for an example of how to use this signal.
1058 ///
1059 /// Action
1060 ///
1061 ///
1062 /// #### `property-notify-event`
1063 /// The ::property-notify-event signal will be emitted when a property on
1064 /// the `widget`'s window has been changed or deleted.
1065 ///
1066 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1067 /// to enable the [`gdk::EventMask::PROPERTY_CHANGE_MASK`][crate::gdk::EventMask::PROPERTY_CHANGE_MASK] mask.
1068 ///
1069 ///
1070 ///
1071 ///
1072 /// #### `proximity-in-event`
1073 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1074 /// to enable the [`gdk::EventMask::PROXIMITY_IN_MASK`][crate::gdk::EventMask::PROXIMITY_IN_MASK] mask.
1075 ///
1076 /// This signal will be sent to the grab widget if there is one.
1077 ///
1078 ///
1079 ///
1080 ///
1081 /// #### `proximity-out-event`
1082 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1083 /// to enable the [`gdk::EventMask::PROXIMITY_OUT_MASK`][crate::gdk::EventMask::PROXIMITY_OUT_MASK] mask.
1084 ///
1085 /// This signal will be sent to the grab widget if there is one.
1086 ///
1087 ///
1088 ///
1089 ///
1090 /// #### `query-tooltip`
1091 /// Emitted when [`has-tooltip`][struct@crate::Widget#has-tooltip] is [`true`] and the hover timeout
1092 /// has expired with the cursor hovering "above" `widget`; or emitted when `widget` got
1093 /// focus in keyboard mode.
1094 ///
1095 /// Using the given coordinates, the signal handler should determine
1096 /// whether a tooltip should be shown for `widget`. If this is the case
1097 /// [`true`] should be returned, [`false`] otherwise. Note that if
1098 /// `keyboard_mode` is [`true`], the values of `x` and `y` are undefined and
1099 /// should not be used.
1100 ///
1101 /// The signal handler is free to manipulate `tooltip` with the therefore
1102 /// destined function calls.
1103 ///
1104 ///
1105 ///
1106 ///
1107 /// #### `realize`
1108 /// The ::realize signal is emitted when `widget` is associated with a
1109 /// [`gdk::Window`][crate::gdk::Window], which means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called or the
1110 /// widget has been mapped (that is, it is going to be drawn).
1111 ///
1112 ///
1113 ///
1114 ///
1115 /// #### `screen-changed`
1116 /// The ::screen-changed signal gets emitted when the
1117 /// screen of a widget has changed.
1118 ///
1119 ///
1120 ///
1121 ///
1122 /// #### `scroll-event`
1123 /// The ::scroll-event signal is emitted when a button in the 4 to 7
1124 /// range is pressed. Wheel mice are usually configured to generate
1125 /// button press events for buttons 4 and 5 when the wheel is turned.
1126 ///
1127 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1128 /// to enable the [`gdk::EventMask::SCROLL_MASK`][crate::gdk::EventMask::SCROLL_MASK] mask.
1129 ///
1130 /// This signal will be sent to the grab widget if there is one.
1131 ///
1132 ///
1133 ///
1134 ///
1135 /// #### `selection-clear-event`
1136 /// The ::selection-clear-event signal will be emitted when the
1137 /// the `widget`'s window has lost ownership of a selection.
1138 ///
1139 ///
1140 ///
1141 ///
1142 /// #### `selection-get`
1143 ///
1144 ///
1145 ///
1146 /// #### `selection-notify-event`
1147 ///
1148 ///
1149 ///
1150 /// #### `selection-received`
1151 ///
1152 ///
1153 ///
1154 /// #### `selection-request-event`
1155 /// The ::selection-request-event signal will be emitted when
1156 /// another client requests ownership of the selection owned by
1157 /// the `widget`'s window.
1158 ///
1159 ///
1160 ///
1161 ///
1162 /// #### `show`
1163 /// The ::show signal is emitted when `widget` is shown, for example with
1164 /// [`WidgetExt::show()`][crate::prelude::WidgetExt::show()].
1165 ///
1166 ///
1167 ///
1168 ///
1169 /// #### `show-help`
1170 /// Action
1171 ///
1172 ///
1173 /// #### `size-allocate`
1174 ///
1175 ///
1176 ///
1177 /// #### `state-changed`
1178 /// The ::state-changed signal is emitted when the widget state changes.
1179 /// See `gtk_widget_get_state()`.
1180 ///
1181 ///
1182 ///
1183 ///
1184 /// #### `state-flags-changed`
1185 /// The ::state-flags-changed signal is emitted when the widget state
1186 /// changes, see [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
1187 ///
1188 ///
1189 ///
1190 ///
1191 /// #### `style-set`
1192 /// The ::style-set signal is emitted when a new style has been set
1193 /// on a widget. Note that style-modifying functions like
1194 /// `gtk_widget_modify_base()` also cause this signal to be emitted.
1195 ///
1196 /// Note that this signal is emitted for changes to the deprecated
1197 /// `GtkStyle`. To track changes to the [`StyleContext`][crate::StyleContext] associated
1198 /// with a widget, use the [`style-updated`][struct@crate::Widget#style-updated] signal.
1199 ///
1200 ///
1201 ///
1202 ///
1203 /// #### `style-updated`
1204 /// The ::style-updated signal is a convenience signal that is emitted when the
1205 /// [`changed`][struct@crate::StyleContext#changed] signal is emitted on the `widget`'s associated
1206 /// [`StyleContext`][crate::StyleContext] as returned by [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()].
1207 ///
1208 /// Note that style-modifying functions like `gtk_widget_override_color()` also
1209 /// cause this signal to be emitted.
1210 ///
1211 ///
1212 ///
1213 ///
1214 /// #### `touch-event`
1215 ///
1216 ///
1217 ///
1218 /// #### `unmap`
1219 /// The ::unmap signal is emitted when `widget` is going to be unmapped, which
1220 /// means that either it or any of its parents up to the toplevel widget have
1221 /// been set as hidden.
1222 ///
1223 /// As ::unmap indicates that a widget will not be shown any longer, it can be
1224 /// used to, for example, stop an animation on the widget.
1225 ///
1226 ///
1227 ///
1228 ///
1229 /// #### `unmap-event`
1230 /// The ::unmap-event signal will be emitted when the `widget`'s window is
1231 /// unmapped. A window is unmapped when it becomes invisible on the screen.
1232 ///
1233 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1234 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
1235 /// automatically for all new windows.
1236 ///
1237 ///
1238 ///
1239 ///
1240 /// #### `unrealize`
1241 /// The ::unrealize signal is emitted when the [`gdk::Window`][crate::gdk::Window] associated with
1242 /// `widget` is destroyed, which means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been
1243 /// called or the widget has been unmapped (that is, it is going to be
1244 /// hidden).
1245 ///
1246 ///
1247 ///
1248 ///
1249 /// #### `visibility-notify-event`
1250 /// The ::visibility-notify-event will be emitted when the `widget`'s
1251 /// window is obscured or unobscured.
1252 ///
1253 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1254 /// to enable the [`gdk::EventMask::VISIBILITY_NOTIFY_MASK`][crate::gdk::EventMask::VISIBILITY_NOTIFY_MASK] mask.
1255 ///
1256 ///
1257 ///
1258 ///
1259 /// #### `window-state-event`
1260 /// The ::window-state-event will be emitted when the state of the
1261 /// toplevel window associated to the `widget` changes.
1262 ///
1263 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget
1264 /// needs to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable
1265 /// this mask automatically for all new windows.
1266 ///
1267 ///
1268 /// </details>
1269 ///
1270 /// # Implements
1271 ///
1272 /// [`ButtonExt`][trait@crate::prelude::ButtonExt], [`BinExt`][trait@crate::prelude::BinExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ActionableExt`][trait@crate::prelude::ActionableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
1273 #[doc(alias = "GtkButton")]
1274 pub struct Button(Object<ffi::GtkButton, ffi::GtkButtonClass>) @extends Bin, Container, Widget, @implements Buildable, Actionable;
1275
1276 match fn {
1277 type_ => || ffi::gtk_button_get_type(),
1278 }
1279}
1280
1281impl Button {
1282 pub const NONE: Option<&'static Button> = None;
1283
1284 /// Creates a new [`Button`][crate::Button] widget. To add a child widget to the button,
1285 /// use [`ContainerExt::add()`][crate::prelude::ContainerExt::add()].
1286 ///
1287 /// # Returns
1288 ///
1289 /// The newly created [`Button`][crate::Button] widget.
1290 #[doc(alias = "gtk_button_new")]
1291 pub fn new() -> Button {
1292 assert_initialized_main_thread!();
1293 unsafe { Widget::from_glib_none(ffi::gtk_button_new()).unsafe_cast() }
1294 }
1295
1296 /// Creates a new button containing an icon from the current icon theme.
1297 ///
1298 /// If the icon name isn’t known, a “broken image” icon will be
1299 /// displayed instead. If the current icon theme is changed, the icon
1300 /// will be updated appropriately.
1301 ///
1302 /// This function is a convenience wrapper around [`new()`][Self::new()] and
1303 /// [`ButtonExt::set_image()`][crate::prelude::ButtonExt::set_image()].
1304 /// ## `icon_name`
1305 /// an icon name or [`None`]
1306 /// ## `size`
1307 /// an icon size ([`IconSize`][crate::IconSize])
1308 ///
1309 /// # Returns
1310 ///
1311 /// a new [`Button`][crate::Button] displaying the themed icon
1312 #[doc(alias = "gtk_button_new_from_icon_name")]
1313 #[doc(alias = "new_from_icon_name")]
1314 pub fn from_icon_name(icon_name: Option<&str>, size: IconSize) -> Button {
1315 assert_initialized_main_thread!();
1316 unsafe {
1317 Widget::from_glib_none(ffi::gtk_button_new_from_icon_name(
1318 icon_name.to_glib_none().0,
1319 size.into_glib(),
1320 ))
1321 .unsafe_cast()
1322 }
1323 }
1324
1325 /// Creates a [`Button`][crate::Button] widget with a [`Label`][crate::Label] child containing the given
1326 /// text.
1327 /// ## `label`
1328 /// The text you want the [`Label`][crate::Label] to hold.
1329 ///
1330 /// # Returns
1331 ///
1332 /// The newly created [`Button`][crate::Button] widget.
1333 #[doc(alias = "gtk_button_new_with_label")]
1334 #[doc(alias = "new_with_label")]
1335 pub fn with_label(label: &str) -> Button {
1336 assert_initialized_main_thread!();
1337 unsafe {
1338 Widget::from_glib_none(ffi::gtk_button_new_with_label(label.to_glib_none().0))
1339 .unsafe_cast()
1340 }
1341 }
1342
1343 /// Creates a new [`Button`][crate::Button] containing a label.
1344 /// If characters in `label` are preceded by an underscore, they are underlined.
1345 /// If you need a literal underscore character in a label, use “__” (two
1346 /// underscores). The first underlined character represents a keyboard
1347 /// accelerator called a mnemonic.
1348 /// Pressing Alt and that key activates the button.
1349 /// ## `label`
1350 /// The text of the button, with an underscore in front of the
1351 /// mnemonic character
1352 ///
1353 /// # Returns
1354 ///
1355 /// a new [`Button`][crate::Button]
1356 #[doc(alias = "gtk_button_new_with_mnemonic")]
1357 #[doc(alias = "new_with_mnemonic")]
1358 pub fn with_mnemonic(label: &str) -> Button {
1359 assert_initialized_main_thread!();
1360 unsafe {
1361 Widget::from_glib_none(ffi::gtk_button_new_with_mnemonic(label.to_glib_none().0))
1362 .unsafe_cast()
1363 }
1364 }
1365
1366 // rustdoc-stripper-ignore-next
1367 /// Creates a new builder-pattern struct instance to construct [`Button`] objects.
1368 ///
1369 /// This method returns an instance of [`ButtonBuilder`](crate::builders::ButtonBuilder) which can be used to create [`Button`] objects.
1370 pub fn builder() -> ButtonBuilder {
1371 ButtonBuilder::new()
1372 }
1373}
1374
1375impl Default for Button {
1376 fn default() -> Self {
1377 Self::new()
1378 }
1379}
1380
1381// rustdoc-stripper-ignore-next
1382/// A [builder-pattern] type to construct [`Button`] objects.
1383///
1384/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1385#[must_use = "The builder must be built to be used"]
1386pub struct ButtonBuilder {
1387 builder: glib::object::ObjectBuilder<'static, Button>,
1388}
1389
1390impl ButtonBuilder {
1391 fn new() -> Self {
1392 Self {
1393 builder: glib::object::Object::builder(),
1394 }
1395 }
1396
1397 /// If [`true`], the button will ignore the [`gtk-button-images`][struct@crate::Settings#gtk-button-images]
1398 /// setting and always show the image, if available.
1399 ///
1400 /// Use this property if the button would be useless or hard to use
1401 /// without the image.
1402 pub fn always_show_image(self, always_show_image: bool) -> Self {
1403 Self {
1404 builder: self
1405 .builder
1406 .property("always-show-image", always_show_image),
1407 }
1408 }
1409
1410 /// The child widget to appear next to the button text.
1411 pub fn image(self, image: &impl IsA<Widget>) -> Self {
1412 Self {
1413 builder: self.builder.property("image", image.clone().upcast()),
1414 }
1415 }
1416
1417 /// The position of the image relative to the text inside the button.
1418 pub fn image_position(self, image_position: PositionType) -> Self {
1419 Self {
1420 builder: self.builder.property("image-position", image_position),
1421 }
1422 }
1423
1424 pub fn label(self, label: impl Into<glib::GString>) -> Self {
1425 Self {
1426 builder: self.builder.property("label", label.into()),
1427 }
1428 }
1429
1430 pub fn relief(self, relief: ReliefStyle) -> Self {
1431 Self {
1432 builder: self.builder.property("relief", relief),
1433 }
1434 }
1435
1436 pub fn use_underline(self, use_underline: bool) -> Self {
1437 Self {
1438 builder: self.builder.property("use-underline", use_underline),
1439 }
1440 }
1441
1442 pub fn border_width(self, border_width: u32) -> Self {
1443 Self {
1444 builder: self.builder.property("border-width", border_width),
1445 }
1446 }
1447
1448 pub fn child(self, child: &impl IsA<Widget>) -> Self {
1449 Self {
1450 builder: self.builder.property("child", child.clone().upcast()),
1451 }
1452 }
1453
1454 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
1455 Self {
1456 builder: self.builder.property("resize-mode", resize_mode),
1457 }
1458 }
1459
1460 pub fn app_paintable(self, app_paintable: bool) -> Self {
1461 Self {
1462 builder: self.builder.property("app-paintable", app_paintable),
1463 }
1464 }
1465
1466 pub fn can_default(self, can_default: bool) -> Self {
1467 Self {
1468 builder: self.builder.property("can-default", can_default),
1469 }
1470 }
1471
1472 pub fn can_focus(self, can_focus: bool) -> Self {
1473 Self {
1474 builder: self.builder.property("can-focus", can_focus),
1475 }
1476 }
1477
1478 pub fn events(self, events: gdk::EventMask) -> Self {
1479 Self {
1480 builder: self.builder.property("events", events),
1481 }
1482 }
1483
1484 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
1485 pub fn expand(self, expand: bool) -> Self {
1486 Self {
1487 builder: self.builder.property("expand", expand),
1488 }
1489 }
1490
1491 /// Whether the widget should grab focus when it is clicked with the mouse.
1492 ///
1493 /// This property is only relevant for widgets that can take focus.
1494 ///
1495 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
1496 /// GtkComboBox) implemented this property individually.
1497 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1498 Self {
1499 builder: self.builder.property("focus-on-click", focus_on_click),
1500 }
1501 }
1502
1503 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
1504 pub fn halign(self, halign: Align) -> Self {
1505 Self {
1506 builder: self.builder.property("halign", halign),
1507 }
1508 }
1509
1510 pub fn has_default(self, has_default: bool) -> Self {
1511 Self {
1512 builder: self.builder.property("has-default", has_default),
1513 }
1514 }
1515
1516 pub fn has_focus(self, has_focus: bool) -> Self {
1517 Self {
1518 builder: self.builder.property("has-focus", has_focus),
1519 }
1520 }
1521
1522 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
1523 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
1524 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
1525 /// whether it will provide a tooltip or not.
1526 ///
1527 /// Note that setting this property to [`true`] for the first time will change
1528 /// the event masks of the GdkWindows of this widget to include leave-notify
1529 /// and motion-notify events. This cannot and will not be undone when the
1530 /// property is set to [`false`] again.
1531 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1532 Self {
1533 builder: self.builder.property("has-tooltip", has_tooltip),
1534 }
1535 }
1536
1537 pub fn height_request(self, height_request: i32) -> Self {
1538 Self {
1539 builder: self.builder.property("height-request", height_request),
1540 }
1541 }
1542
1543 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
1544 pub fn hexpand(self, hexpand: bool) -> Self {
1545 Self {
1546 builder: self.builder.property("hexpand", hexpand),
1547 }
1548 }
1549
1550 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
1551 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1552 Self {
1553 builder: self.builder.property("hexpand-set", hexpand_set),
1554 }
1555 }
1556
1557 pub fn is_focus(self, is_focus: bool) -> Self {
1558 Self {
1559 builder: self.builder.property("is-focus", is_focus),
1560 }
1561 }
1562
1563 /// Sets all four sides' margin at once. If read, returns max
1564 /// margin on any side.
1565 pub fn margin(self, margin: i32) -> Self {
1566 Self {
1567 builder: self.builder.property("margin", margin),
1568 }
1569 }
1570
1571 /// Margin on bottom side of widget.
1572 ///
1573 /// This property adds margin outside of the widget's normal size
1574 /// request, the margin will be added in addition to the size from
1575 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1576 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1577 Self {
1578 builder: self.builder.property("margin-bottom", margin_bottom),
1579 }
1580 }
1581
1582 /// Margin on end of widget, horizontally. This property supports
1583 /// left-to-right and right-to-left text directions.
1584 ///
1585 /// This property adds margin outside of the widget's normal size
1586 /// request, the margin will be added in addition to the size from
1587 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1588 pub fn margin_end(self, margin_end: i32) -> Self {
1589 Self {
1590 builder: self.builder.property("margin-end", margin_end),
1591 }
1592 }
1593
1594 /// Margin on start of widget, horizontally. This property supports
1595 /// left-to-right and right-to-left text directions.
1596 ///
1597 /// This property adds margin outside of the widget's normal size
1598 /// request, the margin will be added in addition to the size from
1599 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1600 pub fn margin_start(self, margin_start: i32) -> Self {
1601 Self {
1602 builder: self.builder.property("margin-start", margin_start),
1603 }
1604 }
1605
1606 /// Margin on top side of widget.
1607 ///
1608 /// This property adds margin outside of the widget's normal size
1609 /// request, the margin will be added in addition to the size from
1610 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1611 pub fn margin_top(self, margin_top: i32) -> Self {
1612 Self {
1613 builder: self.builder.property("margin-top", margin_top),
1614 }
1615 }
1616
1617 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1618 Self {
1619 builder: self.builder.property("name", name.into()),
1620 }
1621 }
1622
1623 pub fn no_show_all(self, no_show_all: bool) -> Self {
1624 Self {
1625 builder: self.builder.property("no-show-all", no_show_all),
1626 }
1627 }
1628
1629 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
1630 /// more details about window opacity.
1631 ///
1632 /// Before 3.8 this was only available in GtkWindow
1633 pub fn opacity(self, opacity: f64) -> Self {
1634 Self {
1635 builder: self.builder.property("opacity", opacity),
1636 }
1637 }
1638
1639 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
1640 Self {
1641 builder: self.builder.property("parent", parent.clone().upcast()),
1642 }
1643 }
1644
1645 pub fn receives_default(self, receives_default: bool) -> Self {
1646 Self {
1647 builder: self.builder.property("receives-default", receives_default),
1648 }
1649 }
1650
1651 pub fn sensitive(self, sensitive: bool) -> Self {
1652 Self {
1653 builder: self.builder.property("sensitive", sensitive),
1654 }
1655 }
1656
1657 /// Sets the text of tooltip to be the given string, which is marked up
1658 /// with the [Pango text markup language][PangoMarkupFormat].
1659 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1660 ///
1661 /// This is a convenience property which will take care of getting the
1662 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
1663 /// will automatically be set to [`true`] and there will be taken care of
1664 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
1665 ///
1666 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
1667 /// are set, the last one wins.
1668 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1669 Self {
1670 builder: self
1671 .builder
1672 .property("tooltip-markup", tooltip_markup.into()),
1673 }
1674 }
1675
1676 /// Sets the text of tooltip to be the given string.
1677 ///
1678 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1679 ///
1680 /// This is a convenience property which will take care of getting the
1681 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
1682 /// will automatically be set to [`true`] and there will be taken care of
1683 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
1684 ///
1685 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
1686 /// are set, the last one wins.
1687 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1688 Self {
1689 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1690 }
1691 }
1692
1693 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
1694 pub fn valign(self, valign: Align) -> Self {
1695 Self {
1696 builder: self.builder.property("valign", valign),
1697 }
1698 }
1699
1700 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
1701 pub fn vexpand(self, vexpand: bool) -> Self {
1702 Self {
1703 builder: self.builder.property("vexpand", vexpand),
1704 }
1705 }
1706
1707 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
1708 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1709 Self {
1710 builder: self.builder.property("vexpand-set", vexpand_set),
1711 }
1712 }
1713
1714 pub fn visible(self, visible: bool) -> Self {
1715 Self {
1716 builder: self.builder.property("visible", visible),
1717 }
1718 }
1719
1720 pub fn width_request(self, width_request: i32) -> Self {
1721 Self {
1722 builder: self.builder.property("width-request", width_request),
1723 }
1724 }
1725
1726 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
1727 Self {
1728 builder: self.builder.property("action-name", action_name.into()),
1729 }
1730 }
1731
1732 pub fn action_target(self, action_target: &glib::Variant) -> Self {
1733 Self {
1734 builder: self
1735 .builder
1736 .property("action-target", action_target.clone()),
1737 }
1738 }
1739
1740 // rustdoc-stripper-ignore-next
1741 /// Build the [`Button`].
1742 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1743 pub fn build(self) -> Button {
1744 assert_initialized_main_thread!();
1745 self.builder.build()
1746 }
1747}
1748
1749/// Trait containing all [`struct@Button`] methods.
1750///
1751/// # Implementors
1752///
1753/// [`Button`][struct@crate::Button], [`ColorButton`][struct@crate::ColorButton], [`FontButton`][struct@crate::FontButton], [`LinkButton`][struct@crate::LinkButton], [`LockButton`][struct@crate::LockButton], [`ModelButton`][struct@crate::ModelButton], [`ScaleButton`][struct@crate::ScaleButton], [`ToggleButton`][struct@crate::ToggleButton]
1754pub trait ButtonExt: IsA<Button> + 'static {
1755 /// Emits a [`clicked`][struct@crate::Button#clicked] signal to the given [`Button`][crate::Button].
1756 #[doc(alias = "gtk_button_clicked")]
1757 fn clicked(&self) {
1758 unsafe {
1759 ffi::gtk_button_clicked(self.as_ref().to_glib_none().0);
1760 }
1761 }
1762
1763 /// Returns whether the button will ignore the [`gtk-button-images`][struct@crate::Settings#gtk-button-images]
1764 /// setting and always show the image, if available.
1765 ///
1766 /// # Returns
1767 ///
1768 /// [`true`] if the button will always show the image
1769 #[doc(alias = "gtk_button_get_always_show_image")]
1770 #[doc(alias = "get_always_show_image")]
1771 #[doc(alias = "always-show-image")]
1772 fn must_always_show_image(&self) -> bool {
1773 unsafe {
1774 from_glib(ffi::gtk_button_get_always_show_image(
1775 self.as_ref().to_glib_none().0,
1776 ))
1777 }
1778 }
1779
1780 /// Returns the button’s event window if it is realized, [`None`] otherwise.
1781 /// This function should be rarely needed.
1782 ///
1783 /// # Returns
1784 ///
1785 /// `self`’s event window.
1786 #[doc(alias = "gtk_button_get_event_window")]
1787 #[doc(alias = "get_event_window")]
1788 fn event_window(&self) -> Option<gdk::Window> {
1789 unsafe {
1790 from_glib_none(ffi::gtk_button_get_event_window(
1791 self.as_ref().to_glib_none().0,
1792 ))
1793 }
1794 }
1795
1796 /// Gets the widget that is currenty set as the image of `self`.
1797 /// This may have been explicitly set by [`set_image()`][Self::set_image()]
1798 /// or constructed by `gtk_button_new_from_stock()`.
1799 ///
1800 /// # Returns
1801 ///
1802 /// a [`Widget`][crate::Widget] or [`None`] in case
1803 /// there is no image
1804 #[doc(alias = "gtk_button_get_image")]
1805 #[doc(alias = "get_image")]
1806 fn image(&self) -> Option<Widget> {
1807 unsafe { from_glib_none(ffi::gtk_button_get_image(self.as_ref().to_glib_none().0)) }
1808 }
1809
1810 /// Gets the position of the image relative to the text
1811 /// inside the button.
1812 ///
1813 /// # Returns
1814 ///
1815 /// the position
1816 #[doc(alias = "gtk_button_get_image_position")]
1817 #[doc(alias = "get_image_position")]
1818 #[doc(alias = "image-position")]
1819 fn image_position(&self) -> PositionType {
1820 unsafe {
1821 from_glib(ffi::gtk_button_get_image_position(
1822 self.as_ref().to_glib_none().0,
1823 ))
1824 }
1825 }
1826
1827 /// Fetches the text from the label of the button, as set by
1828 /// [`set_label()`][Self::set_label()]. If the label text has not
1829 /// been set the return value will be [`None`]. This will be the
1830 /// case if you create an empty button with [`Button::new()`][crate::Button::new()] to
1831 /// use as a container.
1832 ///
1833 /// # Returns
1834 ///
1835 /// The text of the label widget. This string is owned
1836 /// by the widget and must not be modified or freed.
1837 #[doc(alias = "gtk_button_get_label")]
1838 #[doc(alias = "get_label")]
1839 fn label(&self) -> Option<glib::GString> {
1840 unsafe { from_glib_none(ffi::gtk_button_get_label(self.as_ref().to_glib_none().0)) }
1841 }
1842
1843 /// Returns the current relief style of the given [`Button`][crate::Button].
1844 ///
1845 /// # Returns
1846 ///
1847 /// The current [`ReliefStyle`][crate::ReliefStyle]
1848 #[doc(alias = "gtk_button_get_relief")]
1849 #[doc(alias = "get_relief")]
1850 fn relief(&self) -> ReliefStyle {
1851 unsafe { from_glib(ffi::gtk_button_get_relief(self.as_ref().to_glib_none().0)) }
1852 }
1853
1854 /// Returns whether an embedded underline in the button label indicates a
1855 /// mnemonic. See gtk_button_set_use_underline ().
1856 ///
1857 /// # Returns
1858 ///
1859 /// [`true`] if an embedded underline in the button label
1860 /// indicates the mnemonic accelerator keys.
1861 #[doc(alias = "gtk_button_get_use_underline")]
1862 #[doc(alias = "get_use_underline")]
1863 #[doc(alias = "use-underline")]
1864 fn uses_underline(&self) -> bool {
1865 unsafe {
1866 from_glib(ffi::gtk_button_get_use_underline(
1867 self.as_ref().to_glib_none().0,
1868 ))
1869 }
1870 }
1871
1872 /// If [`true`], the button will ignore the [`gtk-button-images`][struct@crate::Settings#gtk-button-images]
1873 /// setting and always show the image, if available.
1874 ///
1875 /// Use this property if the button would be useless or hard to use
1876 /// without the image.
1877 /// ## `always_show`
1878 /// [`true`] if the menuitem should always show the image
1879 #[doc(alias = "gtk_button_set_always_show_image")]
1880 #[doc(alias = "always-show-image")]
1881 fn set_always_show_image(&self, always_show: bool) {
1882 unsafe {
1883 ffi::gtk_button_set_always_show_image(
1884 self.as_ref().to_glib_none().0,
1885 always_show.into_glib(),
1886 );
1887 }
1888 }
1889
1890 /// Set the image of `self` to the given widget. The image will be
1891 /// displayed if the label text is [`None`] or if
1892 /// [`always-show-image`][struct@crate::Button#always-show-image] is [`true`]. You don’t have to call
1893 /// [`WidgetExt::show()`][crate::prelude::WidgetExt::show()] on `image` yourself.
1894 /// ## `image`
1895 /// a widget to set as the image for the button, or [`None`] to unset
1896 #[doc(alias = "gtk_button_set_image")]
1897 #[doc(alias = "image")]
1898 fn set_image(&self, image: Option<&impl IsA<Widget>>) {
1899 unsafe {
1900 ffi::gtk_button_set_image(
1901 self.as_ref().to_glib_none().0,
1902 image.map(|p| p.as_ref()).to_glib_none().0,
1903 );
1904 }
1905 }
1906
1907 /// Sets the position of the image relative to the text
1908 /// inside the button.
1909 /// ## `position`
1910 /// the position
1911 #[doc(alias = "gtk_button_set_image_position")]
1912 #[doc(alias = "image-position")]
1913 fn set_image_position(&self, position: PositionType) {
1914 unsafe {
1915 ffi::gtk_button_set_image_position(
1916 self.as_ref().to_glib_none().0,
1917 position.into_glib(),
1918 );
1919 }
1920 }
1921
1922 /// Sets the text of the label of the button to `str`. This text is
1923 /// also used to select the stock item if `gtk_button_set_use_stock()`
1924 /// is used.
1925 ///
1926 /// This will also clear any previously set labels.
1927 /// ## `label`
1928 /// a string
1929 #[doc(alias = "gtk_button_set_label")]
1930 #[doc(alias = "label")]
1931 fn set_label(&self, label: &str) {
1932 unsafe {
1933 ffi::gtk_button_set_label(self.as_ref().to_glib_none().0, label.to_glib_none().0);
1934 }
1935 }
1936
1937 /// Sets the relief style of the edges of the given [`Button`][crate::Button] widget.
1938 /// Two styles exist, [`ReliefStyle::Normal`][crate::ReliefStyle::Normal] and [`ReliefStyle::None`][crate::ReliefStyle::None].
1939 /// The default style is, as one can guess, [`ReliefStyle::Normal`][crate::ReliefStyle::Normal].
1940 /// The deprecated value [`ReliefStyle::Half`][crate::ReliefStyle::Half] behaves the same as
1941 /// [`ReliefStyle::Normal`][crate::ReliefStyle::Normal].
1942 /// ## `relief`
1943 /// The GtkReliefStyle as described above
1944 #[doc(alias = "gtk_button_set_relief")]
1945 #[doc(alias = "relief")]
1946 fn set_relief(&self, relief: ReliefStyle) {
1947 unsafe {
1948 ffi::gtk_button_set_relief(self.as_ref().to_glib_none().0, relief.into_glib());
1949 }
1950 }
1951
1952 /// If true, an underline in the text of the button label indicates
1953 /// the next character should be used for the mnemonic accelerator key.
1954 /// ## `use_underline`
1955 /// [`true`] if underlines in the text indicate mnemonics
1956 #[doc(alias = "gtk_button_set_use_underline")]
1957 #[doc(alias = "use-underline")]
1958 fn set_use_underline(&self, use_underline: bool) {
1959 unsafe {
1960 ffi::gtk_button_set_use_underline(
1961 self.as_ref().to_glib_none().0,
1962 use_underline.into_glib(),
1963 );
1964 }
1965 }
1966
1967 /// The ::activate signal on GtkButton is an action signal and
1968 /// emitting it causes the button to animate press then release.
1969 /// Applications should never connect to this signal, but use the
1970 /// [`clicked`][struct@crate::Button#clicked] signal.
1971 #[doc(alias = "activate")]
1972 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1973 unsafe extern "C" fn activate_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
1974 this: *mut ffi::GtkButton,
1975 f: glib::ffi::gpointer,
1976 ) {
1977 unsafe {
1978 let f: &F = &*(f as *const F);
1979 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1980 }
1981 }
1982 unsafe {
1983 let f: Box_<F> = Box_::new(f);
1984 connect_raw(
1985 self.as_ptr() as *mut _,
1986 c"activate".as_ptr(),
1987 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1988 activate_trampoline::<Self, F> as *const (),
1989 )),
1990 Box_::into_raw(f),
1991 )
1992 }
1993 }
1994
1995 fn emit_activate(&self) {
1996 self.emit_by_name::<()>("activate", &[]);
1997 }
1998
1999 /// Emitted when the button has been activated (pressed and released).
2000 #[doc(alias = "clicked")]
2001 fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2002 unsafe extern "C" fn clicked_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
2003 this: *mut ffi::GtkButton,
2004 f: glib::ffi::gpointer,
2005 ) {
2006 unsafe {
2007 let f: &F = &*(f as *const F);
2008 f(Button::from_glib_borrow(this).unsafe_cast_ref())
2009 }
2010 }
2011 unsafe {
2012 let f: Box_<F> = Box_::new(f);
2013 connect_raw(
2014 self.as_ptr() as *mut _,
2015 c"clicked".as_ptr(),
2016 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2017 clicked_trampoline::<Self, F> as *const (),
2018 )),
2019 Box_::into_raw(f),
2020 )
2021 }
2022 }
2023
2024 fn emit_clicked(&self) {
2025 self.emit_by_name::<()>("clicked", &[]);
2026 }
2027
2028 #[doc(alias = "always-show-image")]
2029 fn connect_always_show_image_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2030 unsafe extern "C" fn notify_always_show_image_trampoline<
2031 P: IsA<Button>,
2032 F: Fn(&P) + 'static,
2033 >(
2034 this: *mut ffi::GtkButton,
2035 _param_spec: glib::ffi::gpointer,
2036 f: glib::ffi::gpointer,
2037 ) {
2038 unsafe {
2039 let f: &F = &*(f as *const F);
2040 f(Button::from_glib_borrow(this).unsafe_cast_ref())
2041 }
2042 }
2043 unsafe {
2044 let f: Box_<F> = Box_::new(f);
2045 connect_raw(
2046 self.as_ptr() as *mut _,
2047 c"notify::always-show-image".as_ptr(),
2048 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2049 notify_always_show_image_trampoline::<Self, F> as *const (),
2050 )),
2051 Box_::into_raw(f),
2052 )
2053 }
2054 }
2055
2056 #[doc(alias = "image")]
2057 fn connect_image_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2058 unsafe extern "C" fn notify_image_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
2059 this: *mut ffi::GtkButton,
2060 _param_spec: glib::ffi::gpointer,
2061 f: glib::ffi::gpointer,
2062 ) {
2063 unsafe {
2064 let f: &F = &*(f as *const F);
2065 f(Button::from_glib_borrow(this).unsafe_cast_ref())
2066 }
2067 }
2068 unsafe {
2069 let f: Box_<F> = Box_::new(f);
2070 connect_raw(
2071 self.as_ptr() as *mut _,
2072 c"notify::image".as_ptr(),
2073 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2074 notify_image_trampoline::<Self, F> as *const (),
2075 )),
2076 Box_::into_raw(f),
2077 )
2078 }
2079 }
2080
2081 #[doc(alias = "image-position")]
2082 fn connect_image_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2083 unsafe extern "C" fn notify_image_position_trampoline<
2084 P: IsA<Button>,
2085 F: Fn(&P) + 'static,
2086 >(
2087 this: *mut ffi::GtkButton,
2088 _param_spec: glib::ffi::gpointer,
2089 f: glib::ffi::gpointer,
2090 ) {
2091 unsafe {
2092 let f: &F = &*(f as *const F);
2093 f(Button::from_glib_borrow(this).unsafe_cast_ref())
2094 }
2095 }
2096 unsafe {
2097 let f: Box_<F> = Box_::new(f);
2098 connect_raw(
2099 self.as_ptr() as *mut _,
2100 c"notify::image-position".as_ptr(),
2101 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2102 notify_image_position_trampoline::<Self, F> as *const (),
2103 )),
2104 Box_::into_raw(f),
2105 )
2106 }
2107 }
2108
2109 #[doc(alias = "label")]
2110 fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2111 unsafe extern "C" fn notify_label_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
2112 this: *mut ffi::GtkButton,
2113 _param_spec: glib::ffi::gpointer,
2114 f: glib::ffi::gpointer,
2115 ) {
2116 unsafe {
2117 let f: &F = &*(f as *const F);
2118 f(Button::from_glib_borrow(this).unsafe_cast_ref())
2119 }
2120 }
2121 unsafe {
2122 let f: Box_<F> = Box_::new(f);
2123 connect_raw(
2124 self.as_ptr() as *mut _,
2125 c"notify::label".as_ptr(),
2126 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2127 notify_label_trampoline::<Self, F> as *const (),
2128 )),
2129 Box_::into_raw(f),
2130 )
2131 }
2132 }
2133
2134 #[doc(alias = "relief")]
2135 fn connect_relief_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2136 unsafe extern "C" fn notify_relief_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
2137 this: *mut ffi::GtkButton,
2138 _param_spec: glib::ffi::gpointer,
2139 f: glib::ffi::gpointer,
2140 ) {
2141 unsafe {
2142 let f: &F = &*(f as *const F);
2143 f(Button::from_glib_borrow(this).unsafe_cast_ref())
2144 }
2145 }
2146 unsafe {
2147 let f: Box_<F> = Box_::new(f);
2148 connect_raw(
2149 self.as_ptr() as *mut _,
2150 c"notify::relief".as_ptr(),
2151 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2152 notify_relief_trampoline::<Self, F> as *const (),
2153 )),
2154 Box_::into_raw(f),
2155 )
2156 }
2157 }
2158
2159 #[doc(alias = "use-underline")]
2160 fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2161 unsafe extern "C" fn notify_use_underline_trampoline<
2162 P: IsA<Button>,
2163 F: Fn(&P) + 'static,
2164 >(
2165 this: *mut ffi::GtkButton,
2166 _param_spec: glib::ffi::gpointer,
2167 f: glib::ffi::gpointer,
2168 ) {
2169 unsafe {
2170 let f: &F = &*(f as *const F);
2171 f(Button::from_glib_borrow(this).unsafe_cast_ref())
2172 }
2173 }
2174 unsafe {
2175 let f: Box_<F> = Box_::new(f);
2176 connect_raw(
2177 self.as_ptr() as *mut _,
2178 c"notify::use-underline".as_ptr(),
2179 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2180 notify_use_underline_trampoline::<Self, F> as *const (),
2181 )),
2182 Box_::into_raw(f),
2183 )
2184 }
2185 }
2186}
2187
2188impl<O: IsA<Button>> ButtonExt for O {}