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 "gtkaccessible.h"
|
|
|
|
#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"
|
|
|
|
|
2015-11-08 15:46:23 +00:00
|
|
|
struct _GtkTooltipWindow
|
|
|
|
{
|
|
|
|
GtkWindow parent_type;
|
|
|
|
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *custom_widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkTooltipWindowClass
|
|
|
|
{
|
|
|
|
GtkWindowClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkTooltipWindow, gtk_tooltip_window, GTK_TYPE_WINDOW)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_class_init (GtkTooltipWindowClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2015-11-08 17:10:00 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("tooltip"));
|
2015-11-08 15:46:23 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOOL_TIP);
|
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);
|
2015-11-08 15:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tooltip_window_init (GtkTooltipWindow *self)
|
|
|
|
{
|
|
|
|
GtkWindow *window = GTK_WINDOW (self);
|
|
|
|
|
2015-11-11 12:27:07 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2015-11-08 15:46:23 +00:00
|
|
|
|
2015-11-11 12:27:07 +00:00
|
|
|
gtk_window_set_use_subsurface (window, TRUE);
|
2015-11-08 15:46:23 +00:00
|
|
|
_gtk_window_request_csd (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_tooltip_window_new (void)
|
|
|
|
{
|
2015-11-10 11:34:15 +00:00
|
|
|
return g_object_new (GTK_TYPE_TOOLTIP_WINDOW,
|
|
|
|
"type", GTK_WINDOW_POPUP,
|
|
|
|
NULL);
|
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);
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
gtk_container_remove (GTK_CONTAINER (window->box), custom);
|
|
|
|
g_object_unref (custom);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (custom_widget != NULL)
|
|
|
|
{
|
|
|
|
window->custom_widget = g_object_ref (custom_widget);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (window->box), custom_widget);
|
|
|
|
gtk_widget_show (custom_widget);
|
|
|
|
}
|
|
|
|
}
|