1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::IconSize;
use crate::Widget;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// Basic tooltips can be realized simply by using [`WidgetExt::set_tooltip_text()`][crate::prelude::WidgetExt::set_tooltip_text()]
    /// or [`WidgetExt::set_tooltip_markup()`][crate::prelude::WidgetExt::set_tooltip_markup()] without any explicit tooltip object.
    ///
    /// When you need a tooltip with a little more fancy contents, like adding an
    /// image, or you want the tooltip to have different contents per [`TreeView`][crate::TreeView]
    /// row or cell, you will have to do a little more work:
    ///
    /// - Set the `property::Widget::has-tooltip` property to [`true`], this will make GTK+
    ///  monitor the widget for motion and related events which are needed to
    ///  determine when and where to show a tooltip.
    ///
    /// - Connect to the `signal::Widget::query-tooltip` signal. This signal will be
    ///  emitted when a tooltip is supposed to be shown. One of the arguments passed
    ///  to the signal handler is a GtkTooltip object. This is the object that we
    ///  are about to display as a tooltip, and can be manipulated in your callback
    ///  using functions like [`set_icon()`][Self::set_icon()]. There are functions for setting
    ///  the tooltip’s markup, setting an image from a named icon, or even putting in
    ///  a custom widget.
    ///
    ///  Return [`true`] from your query-tooltip handler. This causes the tooltip to be
    ///  show. If you return [`false`], it will not be shown.
    ///
    /// In the probably rare case where you want to have even more control over the
    /// tooltip that is about to be shown, you can set your own [`Window`][crate::Window] which
    /// will be used as tooltip window. This works as follows:
    ///
    /// - Set `property::Widget::has-tooltip` and connect to `signal::Widget::query-tooltip` as before.
    ///  Use [`WidgetExt::set_tooltip_window()`][crate::prelude::WidgetExt::set_tooltip_window()] to set a [`Window`][crate::Window] created by you as
    ///  tooltip window.
    ///
    /// - In the `signal::Widget::query-tooltip` callback you can access your window using
    ///  [`WidgetExt::tooltip_window()`][crate::prelude::WidgetExt::tooltip_window()] and manipulate as you wish. The semantics of
    ///  the return value are exactly as before, return [`true`] to show the window,
    ///  [`false`] to not show it.
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`]
    #[doc(alias = "GtkTooltip")]
    pub struct Tooltip(Object<ffi::GtkTooltip>);

    match fn {
        type_ => || ffi::gtk_tooltip_get_type(),
    }
}

impl Tooltip {
    /// Replaces the widget packed into the tooltip with
    /// `custom_widget`. `custom_widget` does not get destroyed when the tooltip goes
    /// away.
    /// By default a box with a [`Image`][crate::Image] and [`Label`][crate::Label] is embedded in
    /// the tooltip, which can be configured using [`set_markup()`][Self::set_markup()]
    /// and [`set_icon()`][Self::set_icon()].
    /// ## `custom_widget`
    /// a [`Widget`][crate::Widget], or [`None`] to unset the old custom widget.
    #[doc(alias = "gtk_tooltip_set_custom")]
    pub fn set_custom(&self, custom_widget: Option<&impl IsA<Widget>>) {
        unsafe {
            ffi::gtk_tooltip_set_custom(
                self.to_glib_none().0,
                custom_widget.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    /// Sets the icon of the tooltip (which is in front of the text) to be
    /// `pixbuf`. If `pixbuf` is [`None`], the image will be hidden.
    /// ## `pixbuf`
    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf], or [`None`]
    #[doc(alias = "gtk_tooltip_set_icon")]
    pub fn set_icon(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
        unsafe {
            ffi::gtk_tooltip_set_icon(self.to_glib_none().0, pixbuf.to_glib_none().0);
        }
    }

    /// Sets the icon of the tooltip (which is in front of the text)
    /// to be the icon indicated by `gicon` with the size indicated
    /// by `size`. If `gicon` is [`None`], the image will be hidden.
    /// ## `gicon`
    /// a [`gio::Icon`][crate::gio::Icon] representing the icon, or [`None`]
    /// ## `size`
    /// a stock icon size ([`IconSize`][crate::IconSize])
    #[doc(alias = "gtk_tooltip_set_icon_from_gicon")]
    pub fn set_icon_from_gicon(&self, gicon: Option<&impl IsA<gio::Icon>>, size: IconSize) {
        unsafe {
            ffi::gtk_tooltip_set_icon_from_gicon(
                self.to_glib_none().0,
                gicon.map(|p| p.as_ref()).to_glib_none().0,
                size.into_glib(),
            );
        }
    }

    /// Sets the icon of the tooltip (which is in front of the text) to be
    /// the icon indicated by `icon_name` with the size indicated
    /// by `size`. If `icon_name` is [`None`], the image will be hidden.
    /// ## `icon_name`
    /// an icon name, or [`None`]
    /// ## `size`
    /// a stock icon size ([`IconSize`][crate::IconSize])
    #[doc(alias = "gtk_tooltip_set_icon_from_icon_name")]
    pub fn set_icon_from_icon_name(&self, icon_name: Option<&str>, size: IconSize) {
        unsafe {
            ffi::gtk_tooltip_set_icon_from_icon_name(
                self.to_glib_none().0,
                icon_name.to_glib_none().0,
                size.into_glib(),
            );
        }
    }

    /// Sets the text of the tooltip to be `markup`, which is marked up
    /// with the [Pango text markup language][PangoMarkupFormat].
    /// If `markup` is [`None`], the label will be hidden.
    /// ## `markup`
    /// a markup string (see [Pango markup format][PangoMarkupFormat]) or [`None`]
    #[doc(alias = "gtk_tooltip_set_markup")]
    pub fn set_markup(&self, markup: Option<&str>) {
        unsafe {
            ffi::gtk_tooltip_set_markup(self.to_glib_none().0, markup.to_glib_none().0);
        }
    }

    /// Sets the text of the tooltip to be `text`. If `text` is [`None`], the label
    /// will be hidden. See also [`set_markup()`][Self::set_markup()].
    /// ## `text`
    /// a text string or [`None`]
    #[doc(alias = "gtk_tooltip_set_text")]
    pub fn set_text(&self, text: Option<&str>) {
        unsafe {
            ffi::gtk_tooltip_set_text(self.to_glib_none().0, text.to_glib_none().0);
        }
    }

    /// Sets the area of the widget, where the contents of this tooltip apply,
    /// to be `rect` (in widget coordinates). This is especially useful for
    /// properly setting tooltips on [`TreeView`][crate::TreeView] rows and cells, `GtkIconViews`,
    /// etc.
    ///
    /// For setting tooltips on [`TreeView`][crate::TreeView], please refer to the convenience
    /// functions for this: [`TreeViewExt::set_tooltip_row()`][crate::prelude::TreeViewExt::set_tooltip_row()] and
    /// [`TreeViewExt::set_tooltip_cell()`][crate::prelude::TreeViewExt::set_tooltip_cell()].
    /// ## `rect`
    /// a [`gdk::Rectangle`][crate::gdk::Rectangle]
    #[doc(alias = "gtk_tooltip_set_tip_area")]
    pub fn set_tip_area(&self, rect: &gdk::Rectangle) {
        unsafe {
            ffi::gtk_tooltip_set_tip_area(self.to_glib_none().0, rect.to_glib_none().0);
        }
    }

    /// Triggers a new tooltip query on `display`, in order to update the current
    /// visible tooltip, or to show/hide the current tooltip. This function is
    /// useful to call when, for example, the state of the widget changed by a
    /// key press.
    /// ## `display`
    /// a [`gdk::Display`][crate::gdk::Display]
    #[doc(alias = "gtk_tooltip_trigger_tooltip_query")]
    pub fn trigger_tooltip_query(display: &gdk::Display) {
        assert_initialized_main_thread!();
        unsafe {
            ffi::gtk_tooltip_trigger_tooltip_query(display.to_glib_none().0);
        }
    }
}

impl fmt::Display for Tooltip {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Tooltip")
    }
}