st: Remove st-tooltip
StTooltip has been plagued by lots of issues, and we recently ditched it in the dash. Remove it for good. https://bugzilla.gnome.org/show_bug.cgi?id=670034
This commit is contained in:
parent
92ee17493c
commit
d81958a074
@ -79,17 +79,6 @@ StScrollBar StButton#vhandle:hover
|
||||
background-color: #292929;
|
||||
}
|
||||
|
||||
StTooltip StLabel {
|
||||
border: 1px solid rgba(255,255,255,0.6);
|
||||
border-radius: 5px;
|
||||
padding: 2px 12px;
|
||||
background-color: rgba(0,0,0,0.9);
|
||||
color: #ffffff;
|
||||
font-size: 0.8em;
|
||||
font-weight: normal;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.check-box ShellGenericContainer {
|
||||
spacing: .8em;
|
||||
}
|
||||
|
@ -30,7 +30,6 @@
|
||||
<xi:include href="xml/st-entry.xml"/>
|
||||
<xi:include href="xml/st-icon.xml"/>
|
||||
<xi:include href="xml/st-label.xml"/>
|
||||
<xi:include href="xml/st-tooltip.xml"/>
|
||||
</chapter>
|
||||
<chapter id="containers">
|
||||
<title>Containers</title>
|
||||
|
@ -103,8 +103,8 @@ const _Draggable = new Lang.Class({
|
||||
this._dragInProgress = false; // The drag has been started, and has not been dropped or cancelled yet.
|
||||
this._animationInProgress = false; // The drag is over and the item is in the process of animating to its original position (snapping back or reverting).
|
||||
|
||||
// During the drag, we eat enter/leave events so that actors don't prelight or show
|
||||
// tooltips. But we remember the actors that we first left/last entered so we can
|
||||
// During the drag, we eat enter/leave events so that actors don't prelight.
|
||||
// But we remember the actors that we first left/last entered so we can
|
||||
// fix up the hover state after the drag ends.
|
||||
this._firstLeaveActor = null;
|
||||
this._lastEnterActor = null;
|
||||
|
@ -190,7 +190,6 @@ function start() {
|
||||
let constraint = new Clutter.BindConstraint({ source: global.stage,
|
||||
coordinate: Clutter.BindCoordinate.SIZE });
|
||||
uiGroup.add_constraint(constraint);
|
||||
St.set_ui_root(global.stage, uiGroup);
|
||||
global.window_group.reparent(uiGroup);
|
||||
global.overlay_group.reparent(uiGroup);
|
||||
global.stage.add_actor(uiGroup);
|
||||
|
@ -215,13 +215,13 @@ Signals.addSignalMethods(Button.prototype);
|
||||
*
|
||||
* This class manages one System Status indicator (network, keyboard,
|
||||
* volume, bluetooth...), which is just a PanelMenuButton with an
|
||||
* icon and a tooltip
|
||||
* icon.
|
||||
*/
|
||||
const SystemStatusButton = new Lang.Class({
|
||||
Name: 'SystemStatusButton',
|
||||
Extends: Button,
|
||||
|
||||
_init: function(iconName, tooltipText, nameText) {
|
||||
_init: function(iconName, nameText) {
|
||||
this.parent(0.0, nameText);
|
||||
|
||||
this._iconActor = new St.Icon({ icon_name: iconName,
|
||||
@ -229,7 +229,6 @@ const SystemStatusButton = new Lang.Class({
|
||||
style_class: 'system-status-icon' });
|
||||
this.actor.add_actor(this._iconActor);
|
||||
this.actor.add_style_class_name('panel-status-button');
|
||||
this.setTooltip(tooltipText);
|
||||
},
|
||||
|
||||
setIcon: function(iconName) {
|
||||
@ -238,16 +237,5 @@ const SystemStatusButton = new Lang.Class({
|
||||
|
||||
setGIcon: function(gicon) {
|
||||
this._iconActor.gicon = gicon;
|
||||
},
|
||||
|
||||
setTooltip: function(text) {
|
||||
if (text != null) {
|
||||
this.tooltip = text;
|
||||
this.actor.has_tooltip = true;
|
||||
this.actor.tooltip_text = text;
|
||||
} else {
|
||||
this.actor.has_tooltip = false;
|
||||
this.tooltip = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -44,7 +44,7 @@ const ATIndicator = new Lang.Class({
|
||||
Extends: PanelMenu.SystemStatusButton,
|
||||
|
||||
_init: function() {
|
||||
this.parent('preferences-desktop-accessibility', null, _("Accessibility"));
|
||||
this.parent('preferences-desktop-accessibility', _("Accessibility"));
|
||||
|
||||
let highContrast = this._buildHCItem();
|
||||
this.menu.addMenuItem(highContrast);
|
||||
|
@ -28,7 +28,7 @@ const Indicator = new Lang.Class({
|
||||
Extends: PanelMenu.SystemStatusButton,
|
||||
|
||||
_init: function() {
|
||||
this.parent('bluetooth-disabled', null, _("Bluetooth"));
|
||||
this.parent('bluetooth-disabled', _("Bluetooth"));
|
||||
|
||||
this._applet = new GnomeBluetoothApplet.Applet();
|
||||
|
||||
|
@ -1538,7 +1538,7 @@ const NMApplet = new Lang.Class({
|
||||
Extends: PanelMenu.SystemStatusButton,
|
||||
|
||||
_init: function() {
|
||||
this.parent('network-error', null, _("Network"));
|
||||
this.parent('network-error', _("Network"));
|
||||
|
||||
this._client = NMClient.Client.new();
|
||||
|
||||
|
@ -56,7 +56,7 @@ const Indicator = new Lang.Class({
|
||||
Extends: PanelMenu.SystemStatusButton,
|
||||
|
||||
_init: function() {
|
||||
this.parent('battery-missing', null, _("Battery"));
|
||||
this.parent('battery-missing', _("Battery"));
|
||||
|
||||
this._proxy = new PowerManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH);
|
||||
|
||||
|
@ -22,7 +22,7 @@ const Indicator = new Lang.Class({
|
||||
Extends: PanelMenu.SystemStatusButton,
|
||||
|
||||
_init: function() {
|
||||
this.parent('audio-volume-muted', null, _("Volume"));
|
||||
this.parent('audio-volume-muted', _("Volume"));
|
||||
|
||||
this._control = new Gvc.MixerControl({ name: 'GNOME Shell Volume Control' });
|
||||
this._control.connect('state-changed', Lang.bind(this, this._onControlStateChanged));
|
||||
|
@ -70,7 +70,6 @@ st_source_h = \
|
||||
st/st-theme.h \
|
||||
st/st-theme-context.h \
|
||||
st/st-theme-node.h \
|
||||
st/st-tooltip.h \
|
||||
st/st-types.h \
|
||||
st/st-widget.h \
|
||||
st/st-widget-accessible.h \
|
||||
@ -128,7 +127,6 @@ st_source_c = \
|
||||
st/st-theme-node.c \
|
||||
st/st-theme-node-drawing.c \
|
||||
st/st-theme-node-transition.c \
|
||||
st/st-tooltip.c \
|
||||
st/st-widget.c \
|
||||
$(NULL)
|
||||
|
||||
|
@ -801,46 +801,6 @@ global_stage_after_paint (ClutterStage *stage,
|
||||
"clutter.stagePaintDone");
|
||||
}
|
||||
|
||||
static void
|
||||
constrain_tooltip (StTooltip *tooltip,
|
||||
const ClutterGeometry *geometry,
|
||||
ClutterGeometry *adjusted_geometry,
|
||||
gpointer data)
|
||||
{
|
||||
const ClutterGeometry *tip_area = st_tooltip_get_tip_area (tooltip);
|
||||
ShellGlobal *global = shell_global_get ();
|
||||
MetaScreen *screen = shell_global_get_screen (global);
|
||||
int n_monitors = meta_screen_get_n_monitors (screen);
|
||||
int i;
|
||||
|
||||
*adjusted_geometry = *geometry;
|
||||
|
||||
/* A point that determines what screen we'll constrain to */
|
||||
int x = tip_area->x + tip_area->width / 2;
|
||||
int y = tip_area->y + tip_area->height / 2;
|
||||
|
||||
for (i = 0; i < n_monitors; i++)
|
||||
{
|
||||
MetaRectangle rect;
|
||||
meta_screen_get_monitor_geometry (screen, i, &rect);
|
||||
if (x >= rect.x && x < rect.x + rect.width &&
|
||||
y >= rect.y && y < rect.y + rect.height)
|
||||
{
|
||||
if (adjusted_geometry->x + adjusted_geometry->width > rect.x + rect.width)
|
||||
adjusted_geometry->x = rect.x + rect.width - adjusted_geometry->width;
|
||||
if (adjusted_geometry->x < rect.x)
|
||||
adjusted_geometry->x = rect.x;
|
||||
|
||||
if (adjusted_geometry->y + adjusted_geometry->height > rect.y + rect.height)
|
||||
adjusted_geometry->y = rect.y + rect.height - adjusted_geometry->height;
|
||||
if (adjusted_geometry->y < rect.y)
|
||||
adjusted_geometry->y = rect.y;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_font_options (GtkSettings *settings,
|
||||
ClutterStage *stage)
|
||||
@ -870,8 +830,6 @@ update_font_options (GtkSettings *settings,
|
||||
else
|
||||
st_theme_context_set_default_resolution (context);
|
||||
|
||||
st_tooltip_set_constrain_func (stage, constrain_tooltip, NULL, NULL);
|
||||
|
||||
/* Clutter (as of 0.9) passes comprehensively wrong font options
|
||||
* override whatever set_font_flags() did above.
|
||||
*
|
||||
|
@ -163,8 +163,6 @@ st_button_button_press (ClutterActor *actor,
|
||||
StButton *button = ST_BUTTON (actor);
|
||||
StButtonMask mask = ST_BUTTON_MASK_FROM_BUTTON (event->button);
|
||||
|
||||
st_widget_hide_tooltip (ST_WIDGET (actor));
|
||||
|
||||
if (button->priv->button_mask & mask)
|
||||
{
|
||||
if (button->priv->grabbed == 0)
|
||||
@ -209,8 +207,6 @@ st_button_key_press (ClutterActor *actor,
|
||||
{
|
||||
StButton *button = ST_BUTTON (actor);
|
||||
|
||||
st_widget_hide_tooltip (ST_WIDGET (actor));
|
||||
|
||||
if (button->priv->button_mask & ST_BUTTON_ONE)
|
||||
{
|
||||
if (event->keyval == CLUTTER_KEY_space ||
|
||||
|
@ -1,525 +0,0 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* st-tooltip.c: Plain tooltip actor
|
||||
*
|
||||
* Copyright 2008, 2009 Intel Corporation
|
||||
* Copyright 2009 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU Lesser General Public License,
|
||||
* version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:st-tooltip
|
||||
* @short_description: A tooltip widget
|
||||
*
|
||||
* #StTooltip implements a single tooltip. It should not normally be created
|
||||
* by the application but by the widget implementing tooltip capabilities, for
|
||||
* example, #st_button_set_tooltip().
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#include "st-tooltip.h"
|
||||
|
||||
#include "st-widget.h"
|
||||
#include "st-label.h"
|
||||
#include "st-private.h"
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
|
||||
PROP_LABEL,
|
||||
PROP_TIP_AREA
|
||||
};
|
||||
|
||||
#define ST_TOOLTIP_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), ST_TYPE_TOOLTIP, StTooltipPrivate))
|
||||
|
||||
struct _StTooltipPrivate
|
||||
{
|
||||
StLabel *label;
|
||||
|
||||
ClutterGeometry *tip_area;
|
||||
};
|
||||
|
||||
extern gfloat st_slow_down_factor;
|
||||
|
||||
G_DEFINE_TYPE (StTooltip, st_tooltip, ST_TYPE_WIDGET);
|
||||
|
||||
static void st_tooltip_show (ClutterActor *self);
|
||||
static void st_tooltip_show_all (ClutterActor *self);
|
||||
static void st_tooltip_hide_all (ClutterActor *self);
|
||||
|
||||
static void st_tooltip_constrain (StTooltip *tooltip,
|
||||
const ClutterGeometry *geometry,
|
||||
ClutterGeometry *adjusted_geometry);
|
||||
|
||||
static void
|
||||
st_tooltip_set_property (GObject *gobject,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
StTooltip *tooltip = ST_TOOLTIP (gobject);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_LABEL:
|
||||
st_tooltip_set_label (tooltip, g_value_get_string (value));
|
||||
break;
|
||||
|
||||
case PROP_TIP_AREA:
|
||||
st_tooltip_set_tip_area (tooltip, g_value_get_boxed (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_get_property (GObject *gobject,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
StTooltipPrivate *priv = ST_TOOLTIP (gobject)->priv;
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, st_label_get_text (priv->label));
|
||||
break;
|
||||
|
||||
case PROP_TIP_AREA:
|
||||
g_value_set_boxed (value, priv->tip_area);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_get_preferred_width (ClutterActor *self,
|
||||
gfloat for_height,
|
||||
gfloat *min_width_p,
|
||||
gfloat *natural_width_p)
|
||||
{
|
||||
StTooltipPrivate *priv = ST_TOOLTIP (self)->priv;
|
||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||
gfloat label_height;
|
||||
|
||||
st_theme_node_adjust_for_height (theme_node, &for_height);
|
||||
|
||||
if (for_height > -1)
|
||||
{
|
||||
label_height = for_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
label_height = -1;
|
||||
}
|
||||
|
||||
clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->label),
|
||||
label_height,
|
||||
min_width_p,
|
||||
natural_width_p);
|
||||
|
||||
st_theme_node_adjust_preferred_width (theme_node, min_width_p, natural_width_p);
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_get_preferred_height (ClutterActor *self,
|
||||
gfloat for_width,
|
||||
gfloat *min_height_p,
|
||||
gfloat *natural_height_p)
|
||||
{
|
||||
StTooltipPrivate *priv = ST_TOOLTIP (self)->priv;
|
||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||
gfloat min_label_h, natural_label_h;
|
||||
|
||||
st_theme_node_adjust_for_width (theme_node, &for_width);
|
||||
|
||||
clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->label),
|
||||
for_width,
|
||||
&min_label_h,
|
||||
&natural_label_h);
|
||||
if (min_height_p)
|
||||
*min_height_p = min_label_h;
|
||||
|
||||
if (natural_height_p)
|
||||
*natural_height_p = natural_label_h;
|
||||
|
||||
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_allocate (ClutterActor *self,
|
||||
const ClutterActorBox *box,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
StTooltipPrivate *priv = ST_TOOLTIP (self)->priv;
|
||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||
ClutterActorBox content_box, child_box;
|
||||
|
||||
CLUTTER_ACTOR_CLASS (st_tooltip_parent_class)->allocate (self,
|
||||
box,
|
||||
flags);
|
||||
|
||||
st_theme_node_get_content_box (theme_node, box, &content_box);
|
||||
|
||||
child_box.x1 = child_box.y1 = 0;
|
||||
child_box.x2 = (box->x2 - box->x1);
|
||||
child_box.y2 = (box->y2 - box->y1);
|
||||
|
||||
child_box = content_box;
|
||||
|
||||
clutter_actor_allocate (CLUTTER_ACTOR (priv->label), &child_box, flags);
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_paint (ClutterActor *self)
|
||||
{
|
||||
StTooltipPrivate *priv = ST_TOOLTIP (self)->priv;
|
||||
|
||||
CLUTTER_ACTOR_CLASS (st_tooltip_parent_class)->paint (self);
|
||||
|
||||
clutter_actor_paint (CLUTTER_ACTOR (priv->label));
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_dispose (GObject *self)
|
||||
{
|
||||
StTooltipPrivate *priv = ST_TOOLTIP (self)->priv;
|
||||
|
||||
if (priv->label)
|
||||
{
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (priv->label));
|
||||
priv->label = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (st_tooltip_parent_class)->dispose (self);
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_class_init (StTooltipClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
g_type_class_add_private (klass, sizeof (StTooltipPrivate));
|
||||
|
||||
gobject_class->set_property = st_tooltip_set_property;
|
||||
gobject_class->get_property = st_tooltip_get_property;
|
||||
gobject_class->dispose = st_tooltip_dispose;
|
||||
|
||||
actor_class->get_preferred_width = st_tooltip_get_preferred_width;
|
||||
actor_class->get_preferred_height = st_tooltip_get_preferred_height;
|
||||
actor_class->allocate = st_tooltip_allocate;
|
||||
actor_class->paint = st_tooltip_paint;
|
||||
actor_class->show = st_tooltip_show;
|
||||
actor_class->show_all = st_tooltip_show_all;
|
||||
actor_class->hide_all = st_tooltip_hide_all;
|
||||
|
||||
pspec = g_param_spec_string ("label",
|
||||
"Label",
|
||||
"Label of the tooltip",
|
||||
NULL, G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_LABEL, pspec);
|
||||
|
||||
pspec = g_param_spec_boxed ("tip-area",
|
||||
"Tip Area",
|
||||
"Area on the stage the tooltip applies to",
|
||||
CLUTTER_TYPE_GEOMETRY,
|
||||
ST_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_TIP_AREA, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_init (StTooltip *tooltip)
|
||||
{
|
||||
tooltip->priv = ST_TOOLTIP_GET_PRIVATE (tooltip);
|
||||
|
||||
tooltip->priv->label = ST_LABEL (st_label_new (NULL));
|
||||
|
||||
tooltip->priv->tip_area = NULL;
|
||||
|
||||
clutter_actor_set_parent (CLUTTER_ACTOR (tooltip->priv->label),
|
||||
CLUTTER_ACTOR (tooltip));
|
||||
|
||||
g_object_set (tooltip, "show-on-set-parent", FALSE, NULL);
|
||||
|
||||
clutter_actor_set_reactive (CLUTTER_ACTOR (tooltip), FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_update_position (StTooltip *tooltip)
|
||||
{
|
||||
StTooltipPrivate *priv = tooltip->priv;
|
||||
ClutterGeometry *tip_area = tooltip->priv->tip_area;
|
||||
ClutterGeometry geometry;
|
||||
ClutterGeometry adjusted_geometry;
|
||||
gfloat tooltip_w, tooltip_h, tooltip_x, tooltip_y;
|
||||
|
||||
/* if no area set, just position ourselves top left */
|
||||
if (!priv->tip_area)
|
||||
{
|
||||
clutter_actor_set_anchor_point ((ClutterActor*) tooltip, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* we need to have a style in case there are padding/border values to take into
|
||||
* account when calculating width/height */
|
||||
st_widget_ensure_style ((StWidget *) tooltip);
|
||||
|
||||
/* find out the tooltip's size */
|
||||
clutter_actor_get_size ((ClutterActor*) tooltip, &tooltip_w, &tooltip_h);
|
||||
|
||||
/* attempt to place the tooltip */
|
||||
tooltip_x = (int)(tip_area->x + (tip_area->width / 2) - (tooltip_w / 2));
|
||||
tooltip_y = (int)(tip_area->y + tip_area->height);
|
||||
|
||||
geometry.x = tooltip_x;
|
||||
geometry.y = tooltip_y;
|
||||
geometry.width = ceil (tooltip_w);
|
||||
geometry.height = ceil (tooltip_h);
|
||||
|
||||
st_tooltip_constrain (tooltip, &geometry, &adjusted_geometry);
|
||||
|
||||
tooltip_x = adjusted_geometry.x;
|
||||
tooltip_y = adjusted_geometry.y;
|
||||
|
||||
/* Since we are updating the position out of st_widget_allocate(), we can't
|
||||
* call clutter_actor_set_position(), since that would trigger another
|
||||
* allocation cycle. Instead, we adjust the anchor position which moves
|
||||
* the tooltip actor on the screen without changing its allocation
|
||||
*/
|
||||
clutter_actor_set_anchor_point ((ClutterActor*) tooltip, -tooltip_x, -tooltip_y);
|
||||
}
|
||||
|
||||
/**
|
||||
* st_tooltip_get_label:
|
||||
* @tooltip: a #StTooltip
|
||||
*
|
||||
* Get the text displayed on the tooltip
|
||||
*
|
||||
* Returns: the text for the tooltip. This must not be freed by the application
|
||||
*/
|
||||
const gchar *
|
||||
st_tooltip_get_label (StTooltip *tooltip)
|
||||
{
|
||||
g_return_val_if_fail (ST_IS_TOOLTIP (tooltip), NULL);
|
||||
|
||||
return st_label_get_text (tooltip->priv->label);
|
||||
}
|
||||
|
||||
/**
|
||||
* st_tooltip_set_label:
|
||||
* @tooltip: a #StTooltip
|
||||
* @text: text to set the label to
|
||||
*
|
||||
* Sets the text displayed on the tooltip
|
||||
*/
|
||||
void
|
||||
st_tooltip_set_label (StTooltip *tooltip,
|
||||
const gchar *text)
|
||||
{
|
||||
StTooltipPrivate *priv;
|
||||
|
||||
g_return_if_fail (ST_IS_TOOLTIP (tooltip));
|
||||
|
||||
priv = tooltip->priv;
|
||||
|
||||
st_label_set_text (priv->label, text);
|
||||
|
||||
g_object_notify (G_OBJECT (tooltip), "label");
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_show (ClutterActor *self)
|
||||
{
|
||||
StTooltip *tooltip = ST_TOOLTIP (self);
|
||||
|
||||
st_tooltip_update_position (tooltip);
|
||||
|
||||
/* finally show the tooltip... */
|
||||
CLUTTER_ACTOR_CLASS (st_tooltip_parent_class)->show (self);
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_show_all (ClutterActor *self)
|
||||
{
|
||||
CLUTTER_ACTOR_CLASS (st_tooltip_parent_class)->show_all (self);
|
||||
|
||||
clutter_actor_show_all (CLUTTER_ACTOR (ST_TOOLTIP (self)->priv->label));
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_hide_all (ClutterActor *self)
|
||||
{
|
||||
CLUTTER_ACTOR_CLASS (st_tooltip_parent_class)->hide_all (self);
|
||||
|
||||
clutter_actor_hide_all (CLUTTER_ACTOR (ST_TOOLTIP (self)->priv->label));
|
||||
}
|
||||
|
||||
/**
|
||||
* st_tooltip_set_tip_area:
|
||||
* @tooltip: A #StTooltip
|
||||
* @area: A #ClutterGeometry
|
||||
*
|
||||
* Set the area on the stage that the tooltip applies to.
|
||||
*/
|
||||
void
|
||||
st_tooltip_set_tip_area (StTooltip *tooltip,
|
||||
const ClutterGeometry *area)
|
||||
{
|
||||
g_return_if_fail (ST_IS_TOOLTIP (tooltip));
|
||||
|
||||
if (tooltip->priv->tip_area)
|
||||
g_boxed_free (CLUTTER_TYPE_GEOMETRY, tooltip->priv->tip_area);
|
||||
tooltip->priv->tip_area = g_boxed_copy (CLUTTER_TYPE_GEOMETRY, area);
|
||||
|
||||
if (clutter_actor_get_stage (CLUTTER_ACTOR (tooltip)))
|
||||
st_tooltip_update_position (tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* st_tooltip_get_tip_area:
|
||||
* @tooltip: A #StTooltip
|
||||
*
|
||||
* Retrieve the area on the stage that the tooltip currently applies to
|
||||
*
|
||||
* Returns: the #ClutterGeometry, owned by the tooltip which must not be freed
|
||||
* by the application.
|
||||
*/
|
||||
const ClutterGeometry*
|
||||
st_tooltip_get_tip_area (StTooltip *tooltip)
|
||||
{
|
||||
g_return_val_if_fail (ST_IS_TOOLTIP (tooltip), NULL);
|
||||
|
||||
return tooltip->priv->tip_area;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
StTooltipConstrainFunc func;
|
||||
gpointer data;
|
||||
GDestroyNotify notify;
|
||||
} ConstrainFuncClosure;
|
||||
|
||||
static void
|
||||
constrain_func_closure_free (gpointer data)
|
||||
{
|
||||
ConstrainFuncClosure *closure = data;
|
||||
if (closure->notify)
|
||||
closure->notify (closure->data);
|
||||
g_slice_free (ConstrainFuncClosure, data);
|
||||
}
|
||||
|
||||
static GQuark
|
||||
st_tooltip_constrain_func_quark (void)
|
||||
{
|
||||
static GQuark value = 0;
|
||||
if (G_UNLIKELY (value == 0))
|
||||
value = g_quark_from_static_string ("st-tooltip-constrain-func");
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* st_tooltip_set_constrain_func:
|
||||
* @stage: a #ClutterStage
|
||||
* @func: (allow-none): function to be called to constrain tooltip position
|
||||
* @data: (allow-none): user data to pass to @func
|
||||
* @notify: (allow-none): function to be called when @data is no longer needed
|
||||
*
|
||||
* Sets a callback function that will be used to constrain the position
|
||||
* of tooltips within @stage. This can be used, for example, if the stage
|
||||
* spans multiple monitors and tooltips should be positioned not to cross
|
||||
* monitors.
|
||||
*/
|
||||
void
|
||||
st_tooltip_set_constrain_func (ClutterStage *stage,
|
||||
StTooltipConstrainFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
ConstrainFuncClosure *closure;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_STAGE (stage));
|
||||
|
||||
if (func)
|
||||
{
|
||||
closure = g_slice_new (ConstrainFuncClosure);
|
||||
closure->func = func;
|
||||
closure->data = data;
|
||||
closure->notify = notify;
|
||||
}
|
||||
else
|
||||
closure = NULL;
|
||||
|
||||
g_object_set_qdata_full (G_OBJECT (stage), st_tooltip_constrain_func_quark (),
|
||||
closure, constrain_func_closure_free);
|
||||
}
|
||||
|
||||
static void
|
||||
st_tooltip_constrain (StTooltip *tooltip,
|
||||
const ClutterGeometry *geometry,
|
||||
ClutterGeometry *adjusted_geometry)
|
||||
{
|
||||
ConstrainFuncClosure *closure;
|
||||
|
||||
ClutterActor *stage = clutter_actor_get_stage (CLUTTER_ACTOR (tooltip));
|
||||
|
||||
*adjusted_geometry = *geometry;
|
||||
|
||||
if (stage == NULL)
|
||||
return;
|
||||
|
||||
closure = g_object_get_qdata (G_OBJECT (stage), st_tooltip_constrain_func_quark ());
|
||||
if (closure)
|
||||
{
|
||||
closure->func (tooltip, geometry, adjusted_geometry, closure->data);
|
||||
}
|
||||
else
|
||||
{
|
||||
ClutterActor *parent;
|
||||
gfloat parent_w, parent_h;
|
||||
|
||||
parent = clutter_actor_get_parent ((ClutterActor *) tooltip);
|
||||
clutter_actor_get_size (parent, &parent_w, &parent_h);
|
||||
|
||||
/* make sure the tooltip is not off parent horizontally */
|
||||
if (adjusted_geometry->x < 0)
|
||||
adjusted_geometry->x = 0;
|
||||
else if (adjusted_geometry->x + adjusted_geometry->width > parent_w)
|
||||
adjusted_geometry->x = (int)(parent_w) - adjusted_geometry->width;
|
||||
|
||||
/* make sure the tooltip is not off parent vertically */
|
||||
if (adjusted_geometry->y + adjusted_geometry->height > parent_h)
|
||||
adjusted_geometry->y = parent_h - adjusted_geometry->height;
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* st-tooltip.h: Plain tooltip actor
|
||||
*
|
||||
* Copyright 2008, 2009 Intel Corporation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU Lesser General Public License,
|
||||
* version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if !defined(ST_H_INSIDE) && !defined(ST_COMPILATION)
|
||||
#error "Only <st/st.h> can be included directly.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ST_TOOLTIP_H__
|
||||
#define __ST_TOOLTIP_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#include <st/st-bin.h>
|
||||
|
||||
#define ST_TYPE_TOOLTIP (st_tooltip_get_type ())
|
||||
#define ST_TOOLTIP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ST_TYPE_TOOLTIP, StTooltip))
|
||||
#define ST_IS_TOOLTIP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ST_TYPE_TOOLTIP))
|
||||
#define ST_TOOLTIP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ST_TYPE_TOOLTIP, StTooltipClass))
|
||||
#define ST_IS_TOOLTIP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ST_TYPE_TOOLTIP))
|
||||
#define ST_TOOLTIP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ST_TYPE_TOOLTIP, StTooltipClass))
|
||||
|
||||
typedef struct _StTooltip StTooltip;
|
||||
typedef struct _StTooltipPrivate StTooltipPrivate;
|
||||
typedef struct _StTooltipClass StTooltipClass;
|
||||
|
||||
/**
|
||||
* StTooltip:
|
||||
*
|
||||
* The contents of this structure is private and should only be accessed using
|
||||
* the provided API.
|
||||
*/
|
||||
struct _StTooltip
|
||||
{
|
||||
/*< private >*/
|
||||
StWidget parent_instance;
|
||||
|
||||
StTooltipPrivate *priv;
|
||||
};
|
||||
|
||||
struct _StTooltipClass
|
||||
{
|
||||
StWidgetClass parent_class;
|
||||
};
|
||||
|
||||
GType st_tooltip_get_type (void) G_GNUC_CONST;
|
||||
|
||||
const gchar * st_tooltip_get_label (StTooltip *tooltip);
|
||||
void st_tooltip_set_label (StTooltip *tooltip,
|
||||
const gchar *text);
|
||||
|
||||
void st_tooltip_set_tip_area (StTooltip *tooltip,
|
||||
const ClutterGeometry *area);
|
||||
const ClutterGeometry* st_tooltip_get_tip_area (StTooltip *tooltip);
|
||||
|
||||
/**
|
||||
* StTooltipConstrainFunc:
|
||||
* @tooltip: the #StTooltip that is being positioned
|
||||
* @geometry: size and position of the tooltip without any constraints
|
||||
* @adjusted_geometry: (out): new position of the tooltip.
|
||||
* The width and height fields will be ignored.
|
||||
* @data: (closure): user data passed to st_tooltip_set_constrain_func()
|
||||
*/
|
||||
typedef void (*StTooltipConstrainFunc) (StTooltip *tooltip,
|
||||
const ClutterGeometry *geometry,
|
||||
ClutterGeometry *adjusted_geometry,
|
||||
gpointer data);
|
||||
|
||||
void st_tooltip_set_constrain_func (ClutterStage *stage,
|
||||
StTooltipConstrainFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __ST_TOOLTIP_H__ */
|
@ -38,7 +38,6 @@
|
||||
#include "st-private.h"
|
||||
#include "st-texture-cache.h"
|
||||
#include "st-theme-context.h"
|
||||
#include "st-tooltip.h"
|
||||
#include "st-theme-node-transition.h"
|
||||
|
||||
#include "st-widget-accessible.h"
|
||||
@ -57,11 +56,8 @@ struct _StWidgetPrivate
|
||||
gchar *inline_style;
|
||||
|
||||
StThemeNodeTransition *transition_animation;
|
||||
guint tooltip_timeout_id;
|
||||
|
||||
gboolean is_stylable : 1;
|
||||
gboolean has_tooltip : 1;
|
||||
gboolean show_tooltip : 1;
|
||||
gboolean is_style_dirty : 1;
|
||||
gboolean draw_bg_color : 1;
|
||||
gboolean draw_border_internal : 1;
|
||||
@ -69,8 +65,6 @@ struct _StWidgetPrivate
|
||||
gboolean hover : 1;
|
||||
gboolean can_focus : 1;
|
||||
|
||||
StTooltip *tooltip;
|
||||
|
||||
StTextDirection direction;
|
||||
|
||||
AtkObject *accessible;
|
||||
@ -98,8 +92,6 @@ enum
|
||||
PROP_STYLE_CLASS,
|
||||
PROP_STYLE,
|
||||
PROP_STYLABLE,
|
||||
PROP_HAS_TOOLTIP,
|
||||
PROP_TOOLTIP_TEXT,
|
||||
PROP_TRACK_HOVER,
|
||||
PROP_HOVER,
|
||||
PROP_CAN_FOCUS,
|
||||
@ -130,10 +122,6 @@ static gboolean st_widget_real_navigate_focus (StWidget *widget,
|
||||
|
||||
static AtkObject * st_widget_get_accessible (ClutterActor *actor);
|
||||
|
||||
static void st_widget_start_tooltip_timeout (StWidget *widget);
|
||||
static void st_widget_do_show_tooltip (StWidget *widget);
|
||||
static void st_widget_do_hide_tooltip (StWidget *widget);
|
||||
|
||||
static void
|
||||
st_widget_set_property (GObject *gobject,
|
||||
guint prop_id,
|
||||
@ -168,14 +156,6 @@ st_widget_set_property (GObject *gobject,
|
||||
}
|
||||
break;
|
||||
|
||||
case PROP_HAS_TOOLTIP:
|
||||
st_widget_set_has_tooltip (actor, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
case PROP_TOOLTIP_TEXT:
|
||||
st_widget_set_tooltip_text (actor, g_value_get_string (value));
|
||||
break;
|
||||
|
||||
case PROP_TRACK_HOVER:
|
||||
st_widget_set_track_hover (actor, g_value_get_boolean (value));
|
||||
break;
|
||||
@ -229,14 +209,6 @@ st_widget_get_property (GObject *gobject,
|
||||
g_value_set_boolean (value, priv->is_stylable);
|
||||
break;
|
||||
|
||||
case PROP_HAS_TOOLTIP:
|
||||
g_value_set_boolean (value, priv->has_tooltip);
|
||||
break;
|
||||
|
||||
case PROP_TOOLTIP_TEXT:
|
||||
g_value_set_string (value, st_widget_get_tooltip_text (actor));
|
||||
break;
|
||||
|
||||
case PROP_TRACK_HOVER:
|
||||
g_value_set_boolean (value, priv->track_hover);
|
||||
break;
|
||||
@ -291,19 +263,6 @@ st_widget_dispose (GObject *gobject)
|
||||
|
||||
st_widget_remove_transition (actor);
|
||||
|
||||
if (priv->tooltip_timeout_id)
|
||||
{
|
||||
g_source_remove (priv->tooltip_timeout_id);
|
||||
priv->tooltip_timeout_id = 0;
|
||||
}
|
||||
|
||||
if (priv->tooltip)
|
||||
{
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (priv->tooltip));
|
||||
g_object_unref (priv->tooltip);
|
||||
priv->tooltip = NULL;
|
||||
}
|
||||
|
||||
/* The real dispose of this accessible is done on
|
||||
* AtkGObjectAccessible weak ref callback
|
||||
*/
|
||||
@ -373,38 +332,6 @@ st_widget_get_preferred_height (ClutterActor *self,
|
||||
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
||||
}
|
||||
|
||||
static void
|
||||
st_widget_allocate (ClutterActor *actor,
|
||||
const ClutterActorBox *box,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
StWidget *self = ST_WIDGET (actor);
|
||||
StWidgetPrivate *priv = self->priv;
|
||||
ClutterActorClass *klass;
|
||||
ClutterGeometry area;
|
||||
ClutterVertex in_v, out_v;
|
||||
|
||||
klass = CLUTTER_ACTOR_CLASS (st_widget_parent_class);
|
||||
klass->allocate (actor, box, flags);
|
||||
|
||||
/* update tooltip position */
|
||||
if (priv->tooltip)
|
||||
{
|
||||
in_v.x = in_v.y = in_v.z = 0;
|
||||
clutter_actor_apply_transform_to_point (actor, &in_v, &out_v);
|
||||
area.x = out_v.x;
|
||||
area.y = out_v.y;
|
||||
|
||||
in_v.x = box->x2 - box->x1;
|
||||
in_v.y = box->y2 - box->y1;
|
||||
clutter_actor_apply_transform_to_point (actor, &in_v, &out_v);
|
||||
area.width = out_v.x - area.x;
|
||||
area.height = out_v.y - area.y;
|
||||
|
||||
st_tooltip_set_tip_area (priv->tooltip, &area);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
st_widget_paint (ClutterActor *actor)
|
||||
{
|
||||
@ -453,9 +380,6 @@ st_widget_map (ClutterActor *actor)
|
||||
CLUTTER_ACTOR_CLASS (st_widget_parent_class)->map (actor);
|
||||
|
||||
st_widget_ensure_style (self);
|
||||
|
||||
if (self->priv->show_tooltip)
|
||||
st_widget_do_show_tooltip (self);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -468,8 +392,6 @@ st_widget_unmap (ClutterActor *actor)
|
||||
|
||||
if (priv->track_hover && priv->hover)
|
||||
st_widget_set_hover (self, FALSE);
|
||||
|
||||
st_widget_do_hide_tooltip (self);
|
||||
}
|
||||
|
||||
static void notify_children_of_style_change (ClutterContainer *container);
|
||||
@ -696,19 +618,6 @@ st_widget_leave (ClutterActor *actor,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
st_widget_motion (ClutterActor *actor,
|
||||
ClutterMotionEvent *motion)
|
||||
{
|
||||
StWidget *widget = ST_WIDGET (actor);
|
||||
StWidgetPrivate *priv = widget->priv;
|
||||
|
||||
if (priv->has_tooltip)
|
||||
st_widget_start_tooltip_timeout (widget);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
st_widget_key_focus_in (ClutterActor *actor)
|
||||
{
|
||||
@ -740,18 +649,6 @@ st_widget_key_press_event (ClutterActor *actor,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
st_widget_hide (ClutterActor *actor)
|
||||
{
|
||||
StWidget *widget = (StWidget *) actor;
|
||||
|
||||
/* hide the tooltip, if there is one */
|
||||
if (widget->priv->tooltip)
|
||||
clutter_actor_hide (CLUTTER_ACTOR (widget->priv->tooltip));
|
||||
|
||||
CLUTTER_ACTOR_CLASS (st_widget_parent_class)->hide (actor);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
st_widget_get_paint_volume (ClutterActor *self,
|
||||
ClutterPaintVolume *volume)
|
||||
@ -804,7 +701,6 @@ st_widget_class_init (StWidgetClass *klass)
|
||||
|
||||
actor_class->get_preferred_width = st_widget_get_preferred_width;
|
||||
actor_class->get_preferred_height = st_widget_get_preferred_height;
|
||||
actor_class->allocate = st_widget_allocate;
|
||||
actor_class->paint = st_widget_paint;
|
||||
actor_class->get_paint_volume = st_widget_get_paint_volume;
|
||||
actor_class->parent_set = st_widget_parent_set;
|
||||
@ -813,11 +709,9 @@ st_widget_class_init (StWidgetClass *klass)
|
||||
|
||||
actor_class->enter_event = st_widget_enter;
|
||||
actor_class->leave_event = st_widget_leave;
|
||||
actor_class->motion_event = st_widget_motion;
|
||||
actor_class->key_focus_in = st_widget_key_focus_in;
|
||||
actor_class->key_focus_out = st_widget_key_focus_out;
|
||||
actor_class->key_press_event = st_widget_key_press_event;
|
||||
actor_class->hide = st_widget_hide;
|
||||
|
||||
actor_class->get_accessible = st_widget_get_accessible;
|
||||
|
||||
@ -893,35 +787,6 @@ st_widget_class_init (StWidgetClass *klass)
|
||||
PROP_STYLABLE,
|
||||
pspec);
|
||||
|
||||
/**
|
||||
* StWidget:has-tooltip:
|
||||
*
|
||||
* Determines whether the widget has a tooltip. If set to %TRUE, causes the
|
||||
* widget to monitor hover state (i.e. sets #ClutterActor:reactive and
|
||||
* #StWidget:track-hover).
|
||||
*/
|
||||
pspec = g_param_spec_boolean ("has-tooltip",
|
||||
"Has Tooltip",
|
||||
"Determines whether the widget has a tooltip",
|
||||
FALSE,
|
||||
ST_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_HAS_TOOLTIP,
|
||||
pspec);
|
||||
|
||||
|
||||
/**
|
||||
* StWidget:tooltip-text:
|
||||
*
|
||||
* text displayed on the tooltip
|
||||
*/
|
||||
pspec = g_param_spec_string ("tooltip-text",
|
||||
"Tooltip Text",
|
||||
"Text displayed on the tooltip",
|
||||
"",
|
||||
ST_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class, PROP_TOOLTIP_TEXT, pspec);
|
||||
|
||||
/**
|
||||
* StWidget:track-hover:
|
||||
*
|
||||
@ -1550,211 +1415,6 @@ st_widget_set_direction (StWidget *self, StTextDirection dir)
|
||||
st_widget_style_changed (self);
|
||||
}
|
||||
|
||||
static void
|
||||
st_widget_ensure_tooltip_parented (StWidget *widget, ClutterStage *stage)
|
||||
{
|
||||
StWidgetPrivate *priv;
|
||||
ClutterContainer *ui_root;
|
||||
ClutterActor *tooltip, *parent;
|
||||
|
||||
priv = widget->priv;
|
||||
|
||||
ui_root = st_get_ui_root (stage);
|
||||
|
||||
tooltip = CLUTTER_ACTOR (priv->tooltip);
|
||||
parent = clutter_actor_get_parent (tooltip);
|
||||
|
||||
if (G_UNLIKELY (parent != CLUTTER_ACTOR (ui_root)))
|
||||
{
|
||||
if (parent)
|
||||
clutter_container_remove_actor (CLUTTER_CONTAINER (parent), tooltip);
|
||||
|
||||
clutter_container_add_actor (ui_root, tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* st_widget_set_has_tooltip:
|
||||
* @widget: A #StWidget
|
||||
* @has_tooltip: %TRUE if the widget should display a tooltip
|
||||
*
|
||||
* Enables tooltip support on the #StWidget.
|
||||
*
|
||||
* Note that setting has-tooltip to %TRUE will cause
|
||||
* #ClutterActor:reactive and #StWidget:track-hover to be set %TRUE as
|
||||
* well, but you must clear these flags yourself (if appropriate) when
|
||||
* setting it %FALSE.
|
||||
*/
|
||||
void
|
||||
st_widget_set_has_tooltip (StWidget *widget,
|
||||
gboolean has_tooltip)
|
||||
{
|
||||
StWidgetPrivate *priv;
|
||||
ClutterActor *stage;
|
||||
|
||||
g_return_if_fail (ST_IS_WIDGET (widget));
|
||||
|
||||
priv = widget->priv;
|
||||
|
||||
priv->has_tooltip = has_tooltip;
|
||||
|
||||
if (has_tooltip)
|
||||
{
|
||||
clutter_actor_set_reactive ((ClutterActor*) widget, TRUE);
|
||||
st_widget_set_track_hover (widget, TRUE);
|
||||
|
||||
if (!priv->tooltip)
|
||||
{
|
||||
priv->tooltip = g_object_new (ST_TYPE_TOOLTIP, NULL);
|
||||
g_object_ref_sink (priv->tooltip);
|
||||
|
||||
stage = clutter_actor_get_stage (CLUTTER_ACTOR (widget));
|
||||
if (stage != NULL)
|
||||
st_widget_ensure_tooltip_parented (widget, CLUTTER_STAGE (stage));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (priv->tooltip_timeout_id)
|
||||
{
|
||||
g_source_remove (priv->tooltip_timeout_id);
|
||||
priv->tooltip_timeout_id = 0;
|
||||
}
|
||||
|
||||
if (priv->tooltip)
|
||||
{
|
||||
clutter_actor_destroy (CLUTTER_ACTOR (priv->tooltip));
|
||||
g_object_unref (priv->tooltip);
|
||||
priv->tooltip = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* st_widget_get_has_tooltip:
|
||||
* @widget: A #StWidget
|
||||
*
|
||||
* Returns the current value of the has-tooltip property. See
|
||||
* st_tooltip_set_has_tooltip() for more information.
|
||||
*
|
||||
* Returns: current value of has-tooltip on @widget
|
||||
*/
|
||||
gboolean
|
||||
st_widget_get_has_tooltip (StWidget *widget)
|
||||
{
|
||||
g_return_val_if_fail (ST_IS_WIDGET (widget), FALSE);
|
||||
|
||||
return widget->priv->has_tooltip;
|
||||
}
|
||||
|
||||
/**
|
||||
* st_widget_set_tooltip_text:
|
||||
* @widget: A #StWidget
|
||||
* @text: text to set as the tooltip
|
||||
*
|
||||
* Set the tooltip text of the widget. This will set StWidget::has-tooltip to
|
||||
* %TRUE. A value of %NULL will unset the tooltip and set has-tooltip to %FALSE.
|
||||
*
|
||||
*/
|
||||
void
|
||||
st_widget_set_tooltip_text (StWidget *widget,
|
||||
const gchar *text)
|
||||
{
|
||||
StWidgetPrivate *priv;
|
||||
|
||||
g_return_if_fail (ST_IS_WIDGET (widget));
|
||||
|
||||
priv = widget->priv;
|
||||
|
||||
if (text == NULL)
|
||||
st_widget_set_has_tooltip (widget, FALSE);
|
||||
else
|
||||
{
|
||||
st_widget_set_has_tooltip (widget, TRUE);
|
||||
st_tooltip_set_label (priv->tooltip, text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* st_widget_get_tooltip_text:
|
||||
* @widget: A #StWidget
|
||||
*
|
||||
* Get the current tooltip string
|
||||
*
|
||||
* Returns: The current tooltip string, owned by the #StWidget
|
||||
*/
|
||||
const gchar*
|
||||
st_widget_get_tooltip_text (StWidget *widget)
|
||||
{
|
||||
StWidgetPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (ST_IS_WIDGET (widget), NULL);
|
||||
priv = widget->priv;
|
||||
|
||||
if (!priv->has_tooltip)
|
||||
return NULL;
|
||||
|
||||
return st_tooltip_get_label (widget->priv->tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* st_widget_show_tooltip:
|
||||
* @widget: A #StWidget
|
||||
*
|
||||
* Force the tooltip for @widget to be shown
|
||||
*
|
||||
*/
|
||||
void
|
||||
st_widget_show_tooltip (StWidget *widget)
|
||||
{
|
||||
g_return_if_fail (ST_IS_WIDGET (widget));
|
||||
|
||||
widget->priv->show_tooltip = TRUE;
|
||||
if (CLUTTER_ACTOR_IS_MAPPED (widget))
|
||||
st_widget_do_show_tooltip (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
st_widget_do_show_tooltip (StWidget *widget)
|
||||
{
|
||||
ClutterActor *stage, *tooltip;
|
||||
|
||||
stage = clutter_actor_get_stage (CLUTTER_ACTOR (widget));
|
||||
g_return_if_fail (stage != NULL);
|
||||
|
||||
if (widget->priv->tooltip)
|
||||
{
|
||||
tooltip = CLUTTER_ACTOR (widget->priv->tooltip);
|
||||
st_widget_ensure_tooltip_parented (widget, CLUTTER_STAGE (stage));
|
||||
clutter_actor_raise (tooltip, NULL);
|
||||
clutter_actor_show_all (tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* st_widget_hide_tooltip:
|
||||
* @widget: A #StWidget
|
||||
*
|
||||
* Hide the tooltip for @widget
|
||||
*
|
||||
*/
|
||||
void
|
||||
st_widget_hide_tooltip (StWidget *widget)
|
||||
{
|
||||
g_return_if_fail (ST_IS_WIDGET (widget));
|
||||
|
||||
widget->priv->show_tooltip = FALSE;
|
||||
if (CLUTTER_ACTOR_IS_MAPPED (widget))
|
||||
st_widget_do_hide_tooltip (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
st_widget_do_hide_tooltip (StWidget *widget)
|
||||
{
|
||||
if (widget->priv->tooltip)
|
||||
clutter_actor_hide (CLUTTER_ACTOR (widget->priv->tooltip));
|
||||
}
|
||||
|
||||
/**
|
||||
* st_widget_set_track_hover:
|
||||
* @widget: A #StWidget
|
||||
@ -1798,7 +1458,7 @@ st_widget_set_track_hover (StWidget *widget,
|
||||
* @widget: A #StWidget
|
||||
*
|
||||
* Returns the current value of the track-hover property. See
|
||||
* st_tooltip_set_track_hover() for more information.
|
||||
* st_widget_set_track_hover() for more information.
|
||||
*
|
||||
* Returns: current value of track-hover on @widget
|
||||
*/
|
||||
@ -1810,36 +1470,13 @@ st_widget_get_track_hover (StWidget *widget)
|
||||
return widget->priv->track_hover;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
tooltip_timeout (gpointer data)
|
||||
{
|
||||
st_widget_show_tooltip (data);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
st_widget_start_tooltip_timeout (StWidget *widget)
|
||||
{
|
||||
StWidgetPrivate *priv = widget->priv;
|
||||
GtkSettings *settings = gtk_settings_get_default ();
|
||||
guint timeout;
|
||||
|
||||
if (priv->tooltip_timeout_id)
|
||||
g_source_remove (priv->tooltip_timeout_id);
|
||||
|
||||
g_object_get (settings, "gtk-tooltip-timeout", &timeout, NULL);
|
||||
priv->tooltip_timeout_id = g_timeout_add (timeout, tooltip_timeout, widget);
|
||||
}
|
||||
|
||||
/**
|
||||
* st_widget_set_hover:
|
||||
* @widget: A #StWidget
|
||||
* @hover: whether the pointer is hovering over the widget
|
||||
*
|
||||
* Sets @widget's hover property and adds or removes "hover" from its
|
||||
* pseudo class accordingly. If #StWidget:has-tooltip is %TRUE, this
|
||||
* will also show or hide the tooltip, as appropriate.
|
||||
* pseudo class accordingly.
|
||||
*
|
||||
* If you have set #StWidget:track-hover, you should not need to call
|
||||
* this directly. You can call st_widget_sync_hover() if the hover
|
||||
@ -1859,25 +1496,9 @@ st_widget_set_hover (StWidget *widget,
|
||||
{
|
||||
priv->hover = hover;
|
||||
if (priv->hover)
|
||||
{
|
||||
st_widget_add_style_pseudo_class (widget, "hover");
|
||||
if (priv->has_tooltip)
|
||||
st_widget_start_tooltip_timeout (widget);
|
||||
}
|
||||
st_widget_add_style_pseudo_class (widget, "hover");
|
||||
else
|
||||
{
|
||||
st_widget_remove_style_pseudo_class (widget, "hover");
|
||||
if (priv->has_tooltip)
|
||||
{
|
||||
if (priv->tooltip_timeout_id)
|
||||
{
|
||||
g_source_remove (priv->tooltip_timeout_id);
|
||||
priv->tooltip_timeout_id = 0;
|
||||
}
|
||||
|
||||
st_widget_hide_tooltip (widget);
|
||||
}
|
||||
}
|
||||
st_widget_remove_style_pseudo_class (widget, "hover");
|
||||
g_object_notify (G_OBJECT (widget), "hover");
|
||||
}
|
||||
}
|
||||
@ -2421,74 +2042,6 @@ on_can_focus_notify (GObject *gobject,
|
||||
ATK_STATE_FOCUSABLE, can_focus);
|
||||
}
|
||||
|
||||
static GQuark
|
||||
st_ui_root_quark (void)
|
||||
{
|
||||
static GQuark value = 0;
|
||||
if (G_UNLIKELY (value == 0))
|
||||
value = g_quark_from_static_string ("st-ui-root");
|
||||
return value;
|
||||
}
|
||||
|
||||
static void
|
||||
st_ui_root_destroyed (ClutterActor *actor,
|
||||
ClutterStage *stage)
|
||||
{
|
||||
st_set_ui_root (stage, NULL);
|
||||
g_signal_handlers_disconnect_by_func (actor, st_ui_root_destroyed, stage);
|
||||
}
|
||||
|
||||
/**
|
||||
* st_set_ui_root:
|
||||
* @stage: a #ClutterStage
|
||||
* @container: (allow-none): the new UI root
|
||||
*
|
||||
* Sets a #ClutterContainer to be the parent of all UI in the program.
|
||||
* This container is used when St needs to add new content outside the
|
||||
* widget hierarchy, for example, when it shows a tooltip over a widget.
|
||||
*/
|
||||
void
|
||||
st_set_ui_root (ClutterStage *stage,
|
||||
ClutterContainer *container)
|
||||
{
|
||||
ClutterContainer *previous;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_STAGE (stage));
|
||||
g_return_if_fail (CLUTTER_IS_CONTAINER (container));
|
||||
|
||||
previous = st_get_ui_root (stage);
|
||||
if (previous)
|
||||
g_signal_handlers_disconnect_by_func (container, st_ui_root_destroyed, stage);
|
||||
|
||||
if (container)
|
||||
{
|
||||
g_signal_connect (container, "destroy", G_CALLBACK (st_ui_root_destroyed), stage);
|
||||
g_object_set_qdata_full (G_OBJECT (stage), st_ui_root_quark (), g_object_ref (container), g_object_unref);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* st_get_ui_root:
|
||||
* @stage: a #ClutterStage
|
||||
*
|
||||
* Returns: (transfer none): the container which should be the parent of all user interface,
|
||||
* which can be set with st_set_ui_root(). If not set, returns @stage
|
||||
*/
|
||||
ClutterContainer *
|
||||
st_get_ui_root (ClutterStage *stage)
|
||||
{
|
||||
ClutterContainer *root;
|
||||
|
||||
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
|
||||
|
||||
root = g_object_get_qdata (G_OBJECT (stage), st_ui_root_quark ());
|
||||
|
||||
if (root != NULL)
|
||||
return root;
|
||||
else
|
||||
return CLUTTER_CONTAINER (stage);
|
||||
}
|
||||
|
||||
static void
|
||||
on_label_notify (GObject *gobject,
|
||||
GParamSpec *pspec,
|
||||
|
@ -117,16 +117,6 @@ void st_widget_set_theme (StWidget *acto
|
||||
StTheme *theme);
|
||||
StTheme * st_widget_get_theme (StWidget *actor);
|
||||
|
||||
void st_widget_set_has_tooltip (StWidget *widget,
|
||||
gboolean has_tooltip);
|
||||
gboolean st_widget_get_has_tooltip (StWidget *widget);
|
||||
void st_widget_set_tooltip_text (StWidget *widget,
|
||||
const gchar *text);
|
||||
const gchar* st_widget_get_tooltip_text (StWidget *widget);
|
||||
|
||||
void st_widget_show_tooltip (StWidget *widget);
|
||||
void st_widget_hide_tooltip (StWidget *widget);
|
||||
|
||||
void st_widget_set_track_hover (StWidget *widget,
|
||||
gboolean track_hover);
|
||||
gboolean st_widget_get_track_hover (StWidget *widget);
|
||||
@ -166,10 +156,6 @@ char *st_describe_actor (ClutterActor *actor);
|
||||
void st_set_slow_down_factor (gfloat factor);
|
||||
gfloat st_get_slow_down_factor (void);
|
||||
|
||||
void st_set_ui_root (ClutterStage *stage,
|
||||
ClutterContainer *container);
|
||||
ClutterContainer *st_get_ui_root (ClutterStage *stage);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __ST_WIDGET_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user