2015-11-08 15:46:23 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright 2015 Emmanuele Bassi
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtktooltipwindowprivate.h"
|
|
|
|
|
|
|
|
#include "gtkprivate.h"
|
2015-11-08 17:10:00 +00:00
|
|
|
#include "gtkintl.h"
|
2015-11-08 15:46:23 +00:00
|
|
|
|
|
|
|
#include "gtkbox.h"
|
|
|
|
#include "gtkimage.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtksettings.h"
|
|
|
|
#include "gtksizerequest.h"
|
|
|
|
#include "gtkwindowprivate.h"
|
2015-11-08 17:10:00 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2020-08-13 23:21:05 +00:00
|
|
|
#include "gtknativeprivate.h"
|
2020-05-16 06:01:22 +00:00
|
|
|
#include "gtkcssboxesimplprivate.h"
|
2015-11-08 17:10:00 +00:00
|
|
|
|
2015-11-08 15:46:23 +00:00
|
|
|
struct _GtkTooltipWindow
|
|
|
|
{
|
2020-05-03 20:36:22 +00:00
|
|
|
GtkWidget parent_instance;
|
2015-11-08 15:46:23 +00:00
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
GdkSurface *surface;
|
|
|
|
GskRenderer *renderer;
|
|
|
|
|
|
|
|
GtkWidget *relative_to;
|
|
|
|
GdkRectangle rect;
|
|
|
|
GdkGravity rect_anchor;
|
|
|
|
GdkGravity surface_anchor;
|
|
|
|
GdkAnchorHints anchor_hints;
|
|
|
|
int dx;
|
|
|
|
int dy;
|
|
|
|
guint surface_transform_changed_cb;
|
|
|
|
|
2015-11-08 15:46:23 +00:00
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *custom_widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkTooltipWindowClass
|
|
|
|
{
|
2020-05-03 20:36:22 +00:00
|
|
|
GtkWidgetClass parent_class;
|
2015-11-08 15:46:23 +00:00
|
|
|
};
|
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
static void gtk_tooltip_window_native_init (GtkNativeInterface *iface);
|
|
|
|
|
2020-05-03 20:36:22 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkTooltipWindow, gtk_tooltip_window, GTK_TYPE_WIDGET,
|
2019-12-29 02:04:19 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_NATIVE,
|
|
|
|
gtk_tooltip_window_native_init))
|
|
|
|
|
|
|
|
|
|
|
|
static GdkSurface *
|
|
|
|
gtk_tooltip_window_native_get_surface (GtkNative *native)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (native);
|
|
|
|
|
|
|
|
return window->surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GskRenderer *
|
|
|
|
gtk_tooltip_window_native_get_renderer (GtkNative *native)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (native);
|
|
|
|
|
|
|
|
return window->renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_native_get_surface_transform (GtkNative *native,
|
2020-05-17 21:08:01 +00:00
|
|
|
double *x,
|
|
|
|
double *y)
|
2019-12-29 02:04:19 +00:00
|
|
|
{
|
2020-05-16 06:01:22 +00:00
|
|
|
GtkCssBoxes css_boxes;
|
|
|
|
const graphene_rect_t *margin_rect;
|
2019-12-29 02:04:19 +00:00
|
|
|
|
2020-05-16 06:01:22 +00:00
|
|
|
gtk_css_boxes_init (&css_boxes, GTK_WIDGET (native));
|
|
|
|
margin_rect = gtk_css_boxes_get_margin_rect (&css_boxes);
|
2019-12-29 02:04:19 +00:00
|
|
|
|
2020-05-16 06:01:22 +00:00
|
|
|
*x = - margin_rect->origin.x;
|
|
|
|
*y = - margin_rect->origin.y;
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 11:59:24 +00:00
|
|
|
static GdkPopupLayout *
|
|
|
|
create_popup_layout (GtkTooltipWindow *window)
|
|
|
|
{
|
|
|
|
GdkPopupLayout *layout;
|
|
|
|
|
|
|
|
layout = gdk_popup_layout_new (&window->rect,
|
|
|
|
window->rect_anchor,
|
|
|
|
window->surface_anchor);
|
|
|
|
gdk_popup_layout_set_anchor_hints (layout, window->anchor_hints);
|
|
|
|
gdk_popup_layout_set_offset (layout, window->dx, window->dy);
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
static void
|
2020-02-22 03:49:52 +00:00
|
|
|
gtk_tooltip_window_relayout (GtkTooltipWindow *window)
|
2019-12-29 02:04:19 +00:00
|
|
|
{
|
2020-02-22 03:49:52 +00:00
|
|
|
GtkRequisition req;
|
2020-02-16 11:59:24 +00:00
|
|
|
GdkPopupLayout *layout;
|
|
|
|
|
2020-02-22 03:49:52 +00:00
|
|
|
if (!gtk_widget_get_visible (GTK_WIDGET (window)) ||
|
|
|
|
window->surface == NULL)
|
2020-02-16 11:59:24 +00:00
|
|
|
return;
|
|
|
|
|
2020-02-22 03:49:52 +00:00
|
|
|
gtk_widget_get_preferred_size (GTK_WIDGET (window), NULL, &req);
|
2020-02-16 11:59:24 +00:00
|
|
|
layout = create_popup_layout (window);
|
2020-02-29 14:46:13 +00:00
|
|
|
gdk_popup_present (GDK_POPUP (window->surface),
|
|
|
|
MAX (req.width, 1),
|
|
|
|
MAX (req.height, 1),
|
|
|
|
layout);
|
2020-02-16 11:59:24 +00:00
|
|
|
gdk_popup_layout_unref (layout);
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 10:06:25 +00:00
|
|
|
void
|
|
|
|
gtk_tooltip_window_present (GtkTooltipWindow *window)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (window);
|
2019-12-29 02:04:19 +00:00
|
|
|
|
|
|
|
if (!_gtk_widget_get_alloc_needed (widget))
|
2020-05-03 20:36:22 +00:00
|
|
|
{
|
|
|
|
gtk_widget_ensure_allocate (widget);
|
|
|
|
}
|
2019-12-29 02:04:19 +00:00
|
|
|
else if (gtk_widget_get_visible (widget))
|
|
|
|
{
|
2020-02-22 03:49:52 +00:00
|
|
|
gtk_tooltip_window_relayout (window);
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 10:59:23 +00:00
|
|
|
static void
|
|
|
|
gtk_tooltip_window_native_layout (GtkNative *native,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (native);
|
|
|
|
|
|
|
|
if (gtk_widget_needs_allocate (widget))
|
|
|
|
gtk_widget_allocate (widget, width, height, -1, NULL);
|
|
|
|
else
|
|
|
|
gtk_widget_ensure_allocate (widget);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
static void
|
|
|
|
gtk_tooltip_window_native_init (GtkNativeInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_surface = gtk_tooltip_window_native_get_surface;
|
|
|
|
iface->get_renderer = gtk_tooltip_window_native_get_renderer;
|
|
|
|
iface->get_surface_transform = gtk_tooltip_window_native_get_surface_transform;
|
2020-12-02 10:59:23 +00:00
|
|
|
iface->layout = gtk_tooltip_window_native_layout;
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
gdk: Replace 'WITHDRAWN' state with async 'is-mapped' boolean
It was used by all surfaces to track 'is-mapped', but still part of the
GdkToplevelState, and is now replaced with a separate boolean in the
GdkSurface structure.
It also caused issues when a widget was unmapped, and due to that
unmapped a popover which hid its corresponding surface. When this
surface was hidden, it emitted a state change event, which would then go
back into GTK and queue a resize on popover widget, which would travel
back down to the widget that was originally unmapped, causing confusino
when doing future allocations.
To summarize, one should not hide widgets during allocation, and to
avoid this, make this new is-mapped boolean asynchronous when hiding a
surface, meaning the notification event for the changed mapped state
will be emitted in an idle callback. This avoids the above described
reentry issue.
2020-12-07 17:18:38 +00:00
|
|
|
mapped_changed (GdkSurface *surface,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkWidget *widget)
|
2019-12-29 02:04:19 +00:00
|
|
|
{
|
gdk: Replace 'WITHDRAWN' state with async 'is-mapped' boolean
It was used by all surfaces to track 'is-mapped', but still part of the
GdkToplevelState, and is now replaced with a separate boolean in the
GdkSurface structure.
It also caused issues when a widget was unmapped, and due to that
unmapped a popover which hid its corresponding surface. When this
surface was hidden, it emitted a state change event, which would then go
back into GTK and queue a resize on popover widget, which would travel
back down to the widget that was originally unmapped, causing confusino
when doing future allocations.
To summarize, one should not hide widgets during allocation, and to
avoid this, make this new is-mapped boolean asynchronous when hiding a
surface, meaning the notification event for the changed mapped state
will be emitted in an idle callback. This avoids the above described
reentry issue.
2020-12-07 17:18:38 +00:00
|
|
|
if (!gdk_surface_get_mapped (surface))
|
|
|
|
gtk_widget_hide (widget);
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
surface_render (GdkSurface *surface,
|
|
|
|
cairo_region_t *region,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_widget_render (widget, surface, region);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
surface_event (GdkSurface *surface,
|
|
|
|
GdkEvent *event,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_main_do_event (event);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
|
|
|
|
GdkSurface *parent;
|
|
|
|
|
|
|
|
parent = gtk_native_get_surface (gtk_widget_get_native (window->relative_to));
|
2020-02-21 20:13:09 +00:00
|
|
|
window->surface = gdk_surface_new_popup (parent, FALSE);
|
2019-12-29 02:04:19 +00:00
|
|
|
|
|
|
|
gdk_surface_set_widget (window->surface, widget);
|
|
|
|
|
gdk: Replace 'WITHDRAWN' state with async 'is-mapped' boolean
It was used by all surfaces to track 'is-mapped', but still part of the
GdkToplevelState, and is now replaced with a separate boolean in the
GdkSurface structure.
It also caused issues when a widget was unmapped, and due to that
unmapped a popover which hid its corresponding surface. When this
surface was hidden, it emitted a state change event, which would then go
back into GTK and queue a resize on popover widget, which would travel
back down to the widget that was originally unmapped, causing confusino
when doing future allocations.
To summarize, one should not hide widgets during allocation, and to
avoid this, make this new is-mapped boolean asynchronous when hiding a
surface, meaning the notification event for the changed mapped state
will be emitted in an idle callback. This avoids the above described
reentry issue.
2020-12-07 17:18:38 +00:00
|
|
|
g_signal_connect (window->surface, "notify::mapped", G_CALLBACK (mapped_changed), widget);
|
2019-12-29 02:04:19 +00:00
|
|
|
g_signal_connect (window->surface, "render", G_CALLBACK (surface_render), widget);
|
|
|
|
g_signal_connect (window->surface, "event", G_CALLBACK (surface_event), widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_tooltip_window_parent_class)->realize (widget);
|
|
|
|
|
|
|
|
window->renderer = gsk_renderer_new_for_surface (window->surface);
|
2020-12-02 10:59:23 +00:00
|
|
|
|
|
|
|
gtk_native_realize (GTK_NATIVE (window));
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
|
|
|
|
|
2020-12-02 10:59:23 +00:00
|
|
|
gtk_native_unrealize (GTK_NATIVE (window));
|
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_tooltip_window_parent_class)->unrealize (widget);
|
|
|
|
|
|
|
|
gsk_renderer_unrealize (window->renderer);
|
|
|
|
g_clear_object (&window->renderer);
|
|
|
|
|
gdk: Replace 'WITHDRAWN' state with async 'is-mapped' boolean
It was used by all surfaces to track 'is-mapped', but still part of the
GdkToplevelState, and is now replaced with a separate boolean in the
GdkSurface structure.
It also caused issues when a widget was unmapped, and due to that
unmapped a popover which hid its corresponding surface. When this
surface was hidden, it emitted a state change event, which would then go
back into GTK and queue a resize on popover widget, which would travel
back down to the widget that was originally unmapped, causing confusino
when doing future allocations.
To summarize, one should not hide widgets during allocation, and to
avoid this, make this new is-mapped boolean asynchronous when hiding a
surface, meaning the notification event for the changed mapped state
will be emitted in an idle callback. This avoids the above described
reentry issue.
2020-12-07 17:18:38 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (window->surface, mapped_changed, widget);
|
2019-12-29 02:04:19 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (window->surface, surface_render, widget);
|
|
|
|
g_signal_handlers_disconnect_by_func (window->surface, surface_event, widget);
|
|
|
|
gdk_surface_set_widget (window->surface, NULL);
|
|
|
|
gdk_surface_destroy (window->surface);
|
|
|
|
g_clear_object (&window->surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
unset_surface_transform_changed_cb (gpointer data)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (data);
|
|
|
|
|
|
|
|
window->surface_transform_changed_cb = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
surface_transform_changed_cb (GtkWidget *widget,
|
|
|
|
const graphene_matrix_t *transform,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
|
|
|
|
|
2020-02-22 03:49:52 +00:00
|
|
|
gtk_tooltip_window_relayout (window);
|
2019-12-29 02:04:19 +00:00
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
|
2020-02-16 11:59:24 +00:00
|
|
|
GdkPopupLayout *layout;
|
2019-12-29 02:04:19 +00:00
|
|
|
|
2020-02-16 11:59:24 +00:00
|
|
|
layout = create_popup_layout (window);
|
2020-02-29 14:46:13 +00:00
|
|
|
gdk_popup_present (GDK_POPUP (window->surface),
|
|
|
|
gdk_surface_get_width (window->surface),
|
|
|
|
gdk_surface_get_height (window->surface),
|
|
|
|
layout);
|
2020-02-16 11:59:24 +00:00
|
|
|
gdk_popup_layout_unref (layout);
|
2019-12-29 02:04:19 +00:00
|
|
|
|
|
|
|
window->surface_transform_changed_cb =
|
|
|
|
gtk_widget_add_surface_transform_changed_callback (window->relative_to,
|
|
|
|
surface_transform_changed_cb,
|
|
|
|
window,
|
|
|
|
unset_surface_transform_changed_cb);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_tooltip_window_parent_class)->map (widget);
|
|
|
|
|
2020-05-03 20:36:22 +00:00
|
|
|
if (gtk_widget_get_visible (window->box))
|
|
|
|
gtk_widget_map (window->box);
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
|
|
|
|
|
|
|
|
gtk_widget_remove_surface_transform_changed_callback (window->relative_to,
|
|
|
|
window->surface_transform_changed_cb);
|
|
|
|
window->surface_transform_changed_cb = 0;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_tooltip_window_parent_class)->unmap (widget);
|
|
|
|
gdk_surface_hide (window->surface);
|
|
|
|
|
2020-05-03 20:36:22 +00:00
|
|
|
gtk_widget_unmap (window->box);
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_measure (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
|
|
|
{
|
2020-05-03 20:36:22 +00:00
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
|
2019-12-29 02:04:19 +00:00
|
|
|
|
2020-05-03 20:36:22 +00:00
|
|
|
if (window->box)
|
|
|
|
gtk_widget_measure (window->box,
|
2019-12-29 02:04:19 +00:00
|
|
|
orientation, for_size,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (widget);
|
|
|
|
|
2020-05-03 20:36:22 +00:00
|
|
|
if (window->box)
|
|
|
|
gtk_widget_allocate (window->box, width, height, baseline, NULL);
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_show (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
_gtk_widget_set_visible_flag (widget, TRUE);
|
|
|
|
gtk_widget_realize (widget);
|
2020-12-04 10:18:09 +00:00
|
|
|
gtk_tooltip_window_present (GTK_TOOLTIP_WINDOW (widget));
|
2019-12-29 02:04:19 +00:00
|
|
|
gtk_widget_map (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_hide (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
_gtk_widget_set_visible_flag (widget, FALSE);
|
|
|
|
gtk_widget_unmap (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkTooltipWindow *window = GTK_TOOLTIP_WINDOW (object);
|
2020-05-03 20:36:22 +00:00
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
if (window->relative_to)
|
2020-05-06 02:11:55 +00:00
|
|
|
gtk_widget_unparent (GTK_WIDGET (window));
|
2019-12-29 02:04:19 +00:00
|
|
|
|
2020-05-03 20:36:22 +00:00
|
|
|
g_clear_pointer (&window->box, gtk_widget_unparent);
|
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
G_OBJECT_CLASS (gtk_tooltip_window_parent_class)->dispose (object);
|
|
|
|
}
|
2015-11-08 15:46:23 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_class_init (GtkTooltipWindowClass *klass)
|
|
|
|
{
|
2019-12-29 02:04:19 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2015-11-08 15:46:23 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
object_class->dispose = gtk_tooltip_window_dispose;
|
|
|
|
widget_class->realize = gtk_tooltip_window_realize;
|
|
|
|
widget_class->unrealize = gtk_tooltip_window_unrealize;
|
|
|
|
widget_class->map = gtk_tooltip_window_map;
|
|
|
|
widget_class->unmap = gtk_tooltip_window_unmap;
|
|
|
|
widget_class->measure = gtk_tooltip_window_measure;
|
|
|
|
widget_class->size_allocate = gtk_tooltip_window_size_allocate;
|
2020-05-03 20:36:22 +00:00
|
|
|
widget_class->show = gtk_tooltip_window_show;
|
|
|
|
widget_class->hide = gtk_tooltip_window_hide;
|
2019-12-29 02:04:19 +00:00
|
|
|
|
2015-11-08 17:10:00 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("tooltip"));
|
2015-11-11 12:27:07 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtktooltipwindow.ui");
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkTooltipWindow, box);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkTooltipWindow, image);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkTooltipWindow, label);
|
2019-12-29 02:04:19 +00:00
|
|
|
|
|
|
|
gtk_widget_class_set_css_name (widget_class, "tooltip");
|
2015-11-08 15:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_init (GtkTooltipWindow *self)
|
|
|
|
{
|
2015-11-11 12:27:07 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2015-11-08 15:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_tooltip_window_new (void)
|
|
|
|
{
|
2019-12-29 02:04:19 +00:00
|
|
|
return g_object_new (GTK_TYPE_TOOLTIP_WINDOW, NULL);
|
2015-11-08 15:46:23 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 23:00:18 +00:00
|
|
|
static void
|
|
|
|
update_label_width (GtkLabel *label)
|
|
|
|
{
|
|
|
|
const char *text;
|
|
|
|
|
|
|
|
text = gtk_label_get_text (label);
|
|
|
|
if (strchr (text, '\n'))
|
|
|
|
{
|
|
|
|
gtk_label_set_wrap (label, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = g_utf8_strlen (text, -1);
|
|
|
|
|
|
|
|
gtk_label_set_width_chars (label, MIN (len, 50));
|
|
|
|
gtk_label_set_max_width_chars (label, MIN (len, 50));
|
|
|
|
gtk_label_set_wrap (label, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-08 15:46:23 +00:00
|
|
|
void
|
|
|
|
gtk_tooltip_window_set_label_markup (GtkTooltipWindow *window,
|
|
|
|
const char *markup)
|
|
|
|
{
|
|
|
|
if (markup != NULL)
|
|
|
|
{
|
|
|
|
gtk_label_set_markup (GTK_LABEL (window->label), markup);
|
2020-05-27 23:00:18 +00:00
|
|
|
update_label_width (GTK_LABEL (window->label));
|
2015-11-08 15:46:23 +00:00
|
|
|
gtk_widget_show (window->label);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (window->label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_tooltip_window_set_label_text (GtkTooltipWindow *window,
|
|
|
|
const char *text)
|
|
|
|
{
|
|
|
|
if (text != NULL)
|
|
|
|
{
|
|
|
|
gtk_label_set_text (GTK_LABEL (window->label), text);
|
2020-05-27 23:00:18 +00:00
|
|
|
update_label_width (GTK_LABEL (window->label));
|
2015-11-08 15:46:23 +00:00
|
|
|
gtk_widget_show (window->label);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (window->label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_tooltip_window_set_image_icon (GtkTooltipWindow *window,
|
2018-03-16 02:38:50 +00:00
|
|
|
GdkPaintable *paintable)
|
2015-11-08 15:46:23 +00:00
|
|
|
{
|
2018-03-16 02:38:50 +00:00
|
|
|
if (paintable != NULL)
|
2015-11-08 15:46:23 +00:00
|
|
|
{
|
2018-03-16 02:38:50 +00:00
|
|
|
gtk_image_set_from_paintable (GTK_IMAGE (window->image), paintable);
|
2015-11-08 15:46:23 +00:00
|
|
|
gtk_widget_show (window->image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (window->image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_tooltip_window_set_image_icon_from_name (GtkTooltipWindow *window,
|
2017-01-20 01:02:44 +00:00
|
|
|
const char *icon_name)
|
2015-11-08 15:46:23 +00:00
|
|
|
{
|
|
|
|
if (icon_name)
|
|
|
|
{
|
2017-11-15 00:43:13 +00:00
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (window->image), icon_name);
|
2015-11-08 15:46:23 +00:00
|
|
|
gtk_widget_show (window->image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (window->image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_tooltip_window_set_image_icon_from_gicon (GtkTooltipWindow *window,
|
2017-01-20 01:02:44 +00:00
|
|
|
GIcon *gicon)
|
2015-11-08 15:46:23 +00:00
|
|
|
{
|
|
|
|
if (gicon != NULL)
|
|
|
|
{
|
2017-11-15 00:43:13 +00:00
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (window->image), gicon);
|
2015-11-08 15:46:23 +00:00
|
|
|
gtk_widget_show (window->image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_hide (window->image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_tooltip_window_set_custom_widget (GtkTooltipWindow *window,
|
|
|
|
GtkWidget *custom_widget)
|
|
|
|
{
|
|
|
|
/* No need to do anything if the custom widget stays the same */
|
|
|
|
if (window->custom_widget == custom_widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (window->custom_widget != NULL)
|
|
|
|
{
|
|
|
|
GtkWidget *custom = window->custom_widget;
|
|
|
|
|
|
|
|
/* Note: We must reset window->custom_widget first,
|
|
|
|
* since gtk_container_remove() will recurse into
|
|
|
|
* gtk_tooltip_set_custom()
|
|
|
|
*/
|
|
|
|
window->custom_widget = NULL;
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (window->box), custom);
|
2015-11-08 15:46:23 +00:00
|
|
|
g_object_unref (custom);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (custom_widget != NULL)
|
|
|
|
{
|
|
|
|
window->custom_widget = g_object_ref (custom_widget);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (window->box), custom_widget);
|
2015-11-08 15:46:23 +00:00
|
|
|
gtk_widget_show (custom_widget);
|
2019-12-29 02:04:19 +00:00
|
|
|
gtk_widget_hide (window->image);
|
|
|
|
gtk_widget_hide (window->label);
|
2015-11-08 15:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-29 02:04:19 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_tooltip_window_set_relative_to (GtkTooltipWindow *window,
|
|
|
|
GtkWidget *relative_to)
|
|
|
|
{
|
2019-12-30 14:52:13 +00:00
|
|
|
g_return_if_fail (GTK_WIDGET (window) != relative_to);
|
|
|
|
|
2019-12-29 02:04:19 +00:00
|
|
|
if (window->relative_to == relative_to)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_ref (window);
|
|
|
|
|
|
|
|
if (window->relative_to)
|
2020-05-06 02:11:55 +00:00
|
|
|
gtk_widget_unparent (GTK_WIDGET (window));
|
2019-12-29 02:04:19 +00:00
|
|
|
|
|
|
|
window->relative_to = relative_to;
|
|
|
|
|
|
|
|
if (window->relative_to)
|
2020-05-06 02:11:55 +00:00
|
|
|
gtk_widget_set_parent (GTK_WIDGET (window), relative_to);
|
2019-12-29 02:04:19 +00:00
|
|
|
|
|
|
|
g_object_unref (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_tooltip_window_position (GtkTooltipWindow *window,
|
|
|
|
GdkRectangle *rect,
|
|
|
|
GdkGravity rect_anchor,
|
|
|
|
GdkGravity surface_anchor,
|
|
|
|
GdkAnchorHints anchor_hints,
|
|
|
|
int dx,
|
|
|
|
int dy)
|
|
|
|
{
|
|
|
|
window->rect = *rect;
|
|
|
|
window->rect_anchor = rect_anchor;
|
|
|
|
window->surface_anchor = surface_anchor;
|
|
|
|
window->anchor_hints = anchor_hints;
|
|
|
|
window->dx = dx;
|
|
|
|
window->dy = dy;
|
|
|
|
|
2020-02-22 03:49:52 +00:00
|
|
|
gtk_tooltip_window_relayout (window);
|
2019-12-29 02:04:19 +00:00
|
|
|
}
|