2009-09-29 15:08:01 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2009-09-10 04:39:27 -04:00
|
|
|
/*
|
|
|
|
* st-label.c: Plain label actor
|
|
|
|
*
|
|
|
|
* Copyright 2008,2009 Intel Corporation
|
2010-11-10 17:00:45 -05:00
|
|
|
* Copyright 2009 Red Hat, Inc.
|
|
|
|
* Copyright 2010 Florian Müllner
|
2009-09-10 04:39:27 -04:00
|
|
|
*
|
|
|
|
* 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
|
2010-11-10 17:00:45 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-09-10 04:39:27 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:st-label
|
|
|
|
* @short_description: Widget for displaying text
|
|
|
|
*
|
|
|
|
* #StLabel is a simple widget for displaying text. It derives from
|
|
|
|
* #StWidget to add extra style and placement functionality over
|
|
|
|
* #ClutterText. The internal #ClutterText is publicly accessibly to allow
|
|
|
|
* applications to set further properties.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
#include "st-label.h"
|
2009-12-02 14:42:26 -05:00
|
|
|
#include "st-private.h"
|
2009-09-10 04:39:27 -04:00
|
|
|
#include "st-widget.h"
|
|
|
|
|
2011-01-20 07:02:14 -05:00
|
|
|
#include <st/st-widget-accessible.h>
|
|
|
|
|
2009-09-10 04:39:27 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
2009-09-21 19:22:31 -04:00
|
|
|
PROP_CLUTTER_TEXT,
|
|
|
|
PROP_TEXT
|
2009-09-10 04:39:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_LABEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ST_TYPE_LABEL, StLabelPrivate))
|
|
|
|
|
|
|
|
struct _StLabelPrivate
|
|
|
|
{
|
|
|
|
ClutterActor *label;
|
2010-07-24 19:05:43 -04:00
|
|
|
|
|
|
|
CoglHandle text_shadow_material;
|
|
|
|
float shadow_width;
|
|
|
|
float shadow_height;
|
2009-09-10 04:39:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (StLabel, st_label, ST_TYPE_WIDGET);
|
|
|
|
|
2011-01-20 07:02:14 -05:00
|
|
|
static GType st_label_accessible_get_type (void) G_GNUC_CONST;
|
|
|
|
|
2009-09-10 04:39:27 -04:00
|
|
|
static void
|
|
|
|
st_label_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StLabel *label = ST_LABEL (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2009-09-21 19:22:31 -04:00
|
|
|
case PROP_TEXT:
|
2009-09-10 04:39:27 -04:00
|
|
|
st_label_set_text (label, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StLabelPrivate *priv = ST_LABEL (gobject)->priv;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2009-09-21 19:22:31 -04:00
|
|
|
case PROP_CLUTTER_TEXT:
|
|
|
|
g_value_set_object (value, priv->label);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TEXT:
|
2009-09-10 04:39:27 -04:00
|
|
|
g_value_set_string (value, clutter_text_get_text (CLUTTER_TEXT (priv->label)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_style_changed (StWidget *self)
|
|
|
|
{
|
2009-12-02 14:42:26 -05:00
|
|
|
StLabelPrivate *priv = ST_LABEL(self)->priv;
|
|
|
|
|
2010-07-24 19:05:43 -04:00
|
|
|
if (priv->text_shadow_material != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
cogl_handle_unref (priv->text_shadow_material);
|
|
|
|
priv->text_shadow_material = COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2009-12-02 14:42:26 -05:00
|
|
|
_st_set_text_from_style ((ClutterText *)priv->label, st_widget_get_theme_node (self));
|
2009-09-10 04:39:27 -04:00
|
|
|
|
2009-09-19 21:10:15 -04:00
|
|
|
ST_WIDGET_CLASS (st_label_parent_class)->style_changed (self);
|
2009-09-10 04:39:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_get_preferred_width (ClutterActor *actor,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p)
|
|
|
|
{
|
|
|
|
StLabelPrivate *priv = ST_LABEL (actor)->priv;
|
2009-09-20 13:41:13 -04:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
2009-09-10 04:39:27 -04:00
|
|
|
|
2009-09-20 13:41:13 -04:00
|
|
|
st_theme_node_adjust_for_height (theme_node, &for_height);
|
2009-09-10 04:39:27 -04:00
|
|
|
|
|
|
|
clutter_actor_get_preferred_width (priv->label, for_height,
|
|
|
|
min_width_p,
|
|
|
|
natural_width_p);
|
|
|
|
|
2009-09-20 13:41:13 -04:00
|
|
|
st_theme_node_adjust_preferred_width (theme_node, min_width_p, natural_width_p);
|
2009-09-10 04:39:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_get_preferred_height (ClutterActor *actor,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
|
|
|
{
|
|
|
|
StLabelPrivate *priv = ST_LABEL (actor)->priv;
|
2009-09-20 13:41:13 -04:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
2009-09-10 04:39:27 -04:00
|
|
|
|
2009-09-20 13:41:13 -04:00
|
|
|
st_theme_node_adjust_for_width (theme_node, &for_width);
|
2009-09-10 04:39:27 -04:00
|
|
|
|
|
|
|
clutter_actor_get_preferred_height (priv->label, for_width,
|
|
|
|
min_height_p,
|
|
|
|
natural_height_p);
|
|
|
|
|
2009-09-20 13:41:13 -04:00
|
|
|
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
2009-09-10 04:39:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_allocate (ClutterActor *actor,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
ClutterAllocationFlags flags)
|
|
|
|
{
|
|
|
|
StLabelPrivate *priv = ST_LABEL (actor)->priv;
|
2009-09-20 13:41:13 -04:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
2009-09-10 04:39:27 -04:00
|
|
|
ClutterActorClass *parent_class;
|
2009-09-20 13:41:13 -04:00
|
|
|
ClutterActorBox content_box;
|
2009-09-10 04:39:27 -04:00
|
|
|
|
2009-09-20 13:41:13 -04:00
|
|
|
st_theme_node_get_content_box (theme_node, box, &content_box);
|
2009-09-10 04:39:27 -04:00
|
|
|
|
|
|
|
parent_class = CLUTTER_ACTOR_CLASS (st_label_parent_class);
|
|
|
|
parent_class->allocate (actor, box, flags);
|
|
|
|
|
2009-09-20 13:41:13 -04:00
|
|
|
clutter_actor_allocate (priv->label, &content_box, flags);
|
2009-09-10 04:39:27 -04:00
|
|
|
}
|
|
|
|
|
2009-10-08 14:53:46 -04:00
|
|
|
static void
|
2010-03-10 18:22:06 -05:00
|
|
|
st_label_dispose (GObject *object)
|
2009-10-08 14:53:46 -04:00
|
|
|
{
|
2010-03-10 18:22:06 -05:00
|
|
|
StLabelPrivate *priv = ST_LABEL (object)->priv;
|
2009-10-08 14:53:46 -04:00
|
|
|
|
|
|
|
if (priv->label)
|
|
|
|
{
|
|
|
|
clutter_actor_destroy (priv->label);
|
|
|
|
priv->label = NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-24 19:05:43 -04:00
|
|
|
if (priv->text_shadow_material != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
cogl_handle_unref (priv->text_shadow_material);
|
|
|
|
priv->text_shadow_material = COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2010-03-10 18:22:06 -05:00
|
|
|
G_OBJECT_CLASS (st_label_parent_class)->dispose (object);
|
2009-10-08 14:53:46 -04:00
|
|
|
}
|
|
|
|
|
2009-09-10 04:39:27 -04:00
|
|
|
static void
|
|
|
|
st_label_paint (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StLabelPrivate *priv = ST_LABEL (actor)->priv;
|
|
|
|
ClutterActorClass *parent_class;
|
2010-07-24 19:05:43 -04:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
|
|
|
StShadow *shadow_spec = st_theme_node_get_text_shadow (theme_node);
|
2009-09-10 04:39:27 -04:00
|
|
|
|
|
|
|
parent_class = CLUTTER_ACTOR_CLASS (st_label_parent_class);
|
|
|
|
parent_class->paint (actor);
|
|
|
|
|
2010-07-24 19:05:43 -04:00
|
|
|
if (shadow_spec)
|
|
|
|
{
|
|
|
|
ClutterActorBox allocation;
|
|
|
|
float width, height;
|
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (priv->label, &allocation);
|
|
|
|
clutter_actor_box_get_size (&allocation, &width, &height);
|
|
|
|
|
|
|
|
allocation.x1 = allocation.y1 = 0;
|
|
|
|
allocation.x2 = width;
|
|
|
|
allocation.y2 = height;
|
|
|
|
|
|
|
|
if (priv->text_shadow_material == COGL_INVALID_HANDLE ||
|
|
|
|
width != priv->shadow_width ||
|
|
|
|
height != priv->shadow_height)
|
|
|
|
{
|
|
|
|
CoglHandle material;
|
|
|
|
|
|
|
|
if (priv->text_shadow_material != COGL_INVALID_HANDLE)
|
|
|
|
cogl_handle_unref (priv->text_shadow_material);
|
|
|
|
|
|
|
|
material = _st_create_shadow_material_from_actor (shadow_spec,
|
|
|
|
priv->label);
|
|
|
|
|
|
|
|
priv->shadow_width = width;
|
|
|
|
priv->shadow_height = height;
|
|
|
|
priv->text_shadow_material = material;
|
|
|
|
}
|
|
|
|
|
2011-03-11 15:29:15 -05:00
|
|
|
if (priv->text_shadow_material != COGL_INVALID_HANDLE)
|
|
|
|
_st_paint_shadow_with_opacity (shadow_spec,
|
|
|
|
priv->text_shadow_material,
|
|
|
|
&allocation,
|
|
|
|
clutter_actor_get_paint_opacity (priv->label));
|
2010-07-24 19:05:43 -04:00
|
|
|
}
|
|
|
|
|
2009-09-10 04:39:27 -04:00
|
|
|
clutter_actor_paint (priv->label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_class_init (StLabelClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2009-09-19 21:10:15 -04:00
|
|
|
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
|
2009-09-10 04:39:27 -04:00
|
|
|
GParamSpec *pspec;
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (StLabelPrivate));
|
|
|
|
|
|
|
|
gobject_class->set_property = st_label_set_property;
|
|
|
|
gobject_class->get_property = st_label_get_property;
|
2009-10-08 14:53:46 -04:00
|
|
|
gobject_class->dispose = st_label_dispose;
|
2009-09-10 04:39:27 -04:00
|
|
|
|
|
|
|
actor_class->paint = st_label_paint;
|
|
|
|
actor_class->allocate = st_label_allocate;
|
|
|
|
actor_class->get_preferred_width = st_label_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = st_label_get_preferred_height;
|
|
|
|
|
2009-09-19 21:10:15 -04:00
|
|
|
widget_class->style_changed = st_label_style_changed;
|
2011-01-20 07:02:14 -05:00
|
|
|
widget_class->get_accessible_type = st_label_accessible_get_type;
|
2009-09-19 21:10:15 -04:00
|
|
|
|
2009-09-21 19:22:31 -04:00
|
|
|
pspec = g_param_spec_object ("clutter-text",
|
|
|
|
"Clutter Text",
|
|
|
|
"Internal ClutterText actor",
|
|
|
|
CLUTTER_TYPE_TEXT,
|
|
|
|
G_PARAM_READABLE);
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CLUTTER_TEXT, pspec);
|
|
|
|
|
2009-09-10 04:39:27 -04:00
|
|
|
pspec = g_param_spec_string ("text",
|
|
|
|
"Text",
|
|
|
|
"Text of the label",
|
|
|
|
NULL, G_PARAM_READWRITE);
|
2009-09-21 19:22:31 -04:00
|
|
|
g_object_class_install_property (gobject_class, PROP_TEXT, pspec);
|
2009-09-10 04:39:27 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_init (StLabel *label)
|
|
|
|
{
|
|
|
|
StLabelPrivate *priv;
|
|
|
|
|
|
|
|
label->priv = priv = ST_LABEL_GET_PRIVATE (label);
|
|
|
|
|
|
|
|
label->priv->label = g_object_new (CLUTTER_TYPE_TEXT,
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_END,
|
|
|
|
NULL);
|
2010-07-24 19:05:43 -04:00
|
|
|
label->priv->text_shadow_material = COGL_INVALID_HANDLE;
|
|
|
|
label->priv->shadow_width = -1.;
|
|
|
|
label->priv->shadow_height = -1.;
|
2009-09-10 04:39:27 -04:00
|
|
|
|
2012-02-13 15:22:53 -05:00
|
|
|
clutter_actor_add_child (CLUTTER_ACTOR (label), priv->label);
|
2009-09-10 04:39:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_label_new:
|
|
|
|
* @text: text to set the label to
|
|
|
|
*
|
|
|
|
* Create a new #StLabel with the specified label
|
|
|
|
*
|
|
|
|
* Returns: a new #StLabel
|
|
|
|
*/
|
|
|
|
StWidget *
|
|
|
|
st_label_new (const gchar *text)
|
|
|
|
{
|
|
|
|
if (text == NULL || *text == '\0')
|
|
|
|
return g_object_new (ST_TYPE_LABEL, NULL);
|
|
|
|
else
|
|
|
|
return g_object_new (ST_TYPE_LABEL,
|
|
|
|
"text", text,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_label_get_text:
|
|
|
|
* @label: a #StLabel
|
|
|
|
*
|
|
|
|
* Get the text displayed on the label
|
|
|
|
*
|
|
|
|
* Returns: the text for the label. This must not be freed by the application
|
|
|
|
*/
|
2011-03-13 09:29:13 -04:00
|
|
|
const gchar *
|
2009-09-10 04:39:27 -04:00
|
|
|
st_label_get_text (StLabel *label)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (ST_IS_LABEL (label), NULL);
|
|
|
|
|
|
|
|
return clutter_text_get_text (CLUTTER_TEXT (label->priv->label));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_label_set_text:
|
|
|
|
* @label: a #StLabel
|
|
|
|
* @text: text to set the label to
|
|
|
|
*
|
|
|
|
* Sets the text displayed on the label
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_label_set_text (StLabel *label,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
|
|
|
StLabelPrivate *priv;
|
2011-04-05 16:17:52 -04:00
|
|
|
ClutterText *ctext;
|
2009-09-10 04:39:27 -04:00
|
|
|
|
|
|
|
g_return_if_fail (ST_IS_LABEL (label));
|
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
|
|
|
priv = label->priv;
|
2011-04-05 16:17:52 -04:00
|
|
|
ctext = CLUTTER_TEXT (priv->label);
|
2009-09-10 04:39:27 -04:00
|
|
|
|
2011-04-05 16:17:52 -04:00
|
|
|
if (clutter_text_get_editable (ctext) ||
|
|
|
|
g_strcmp0 (clutter_text_get_text (ctext), text) != 0)
|
2010-07-24 19:05:43 -04:00
|
|
|
{
|
2011-04-05 16:17:52 -04:00
|
|
|
if (priv->text_shadow_material != COGL_INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
cogl_handle_unref (priv->text_shadow_material);
|
|
|
|
priv->text_shadow_material = COGL_INVALID_HANDLE;
|
|
|
|
}
|
2010-07-24 19:05:43 -04:00
|
|
|
|
2011-04-05 16:17:52 -04:00
|
|
|
clutter_text_set_text (ctext, text);
|
2009-09-10 04:39:27 -04:00
|
|
|
|
2011-04-05 16:17:52 -04:00
|
|
|
g_object_notify (G_OBJECT (label), "text");
|
|
|
|
}
|
2009-09-10 04:39:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_label_get_clutter_text:
|
|
|
|
* @label: a #StLabel
|
|
|
|
*
|
|
|
|
* Retrieve the internal #ClutterText so that extra parameters can be set
|
|
|
|
*
|
2009-09-16 19:07:23 -04:00
|
|
|
* Returns: (transfer none): ethe #ClutterText used by #StLabel. The label
|
|
|
|
* is owned by the #StLabel and should not be unref'ed by the application.
|
2009-09-10 04:39:27 -04:00
|
|
|
*/
|
|
|
|
ClutterActor*
|
|
|
|
st_label_get_clutter_text (StLabel *label)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (ST_LABEL (label), NULL);
|
|
|
|
|
|
|
|
return label->priv->label;
|
|
|
|
}
|
2011-01-20 07:02:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/*************************** ACCESSIBILITY SUPPORT ****************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
#define ST_TYPE_LABEL_ACCESSIBLE st_label_accessible_get_type ()
|
|
|
|
|
|
|
|
#define ST_LABEL_ACCESSIBLE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
|
|
|
ST_TYPE_LABEL_ACCESSIBLE, StLabelAccessible))
|
|
|
|
|
|
|
|
#define ST_IS_LABEL_ACCESSIBLE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
|
|
|
ST_TYPE_LABEL_ACCESSIBLE))
|
|
|
|
|
|
|
|
#define ST_LABEL_ACCESSIBLE_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
|
|
|
ST_TYPE_LABEL_ACCESSIBLE, StLabelAccessibleClass))
|
|
|
|
|
|
|
|
#define ST_IS_LABEL_ACCESSIBLE_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
|
|
|
|
ST_TYPE_LABEL_ACCESSIBLE))
|
|
|
|
|
|
|
|
#define ST_LABEL_ACCESSIBLE_GET_CLASS(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
|
|
|
ST_TYPE_LABEL_ACCESSIBLE, StLabelAccessibleClass))
|
|
|
|
|
|
|
|
typedef struct _StLabelAccessible StLabelAccessible;
|
|
|
|
typedef struct _StLabelAccessibleClass StLabelAccessibleClass;
|
|
|
|
|
|
|
|
struct _StLabelAccessible
|
|
|
|
{
|
|
|
|
StWidgetAccessible parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _StLabelAccessibleClass
|
|
|
|
{
|
|
|
|
StWidgetAccessibleClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void st_label_accessible_class_init (StLabelAccessibleClass *klass);
|
|
|
|
static void st_label_accessible_init (StLabelAccessible *label);
|
|
|
|
|
|
|
|
/* AtkObject */
|
|
|
|
static void st_label_accessible_initialize (AtkObject *obj,
|
|
|
|
gpointer data);
|
|
|
|
static const gchar * st_label_accessible_get_name (AtkObject *obj);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (StLabelAccessible, st_label_accessible, ST_TYPE_WIDGET_ACCESSIBLE)
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_accessible_class_init (StLabelAccessibleClass *klass)
|
|
|
|
{
|
|
|
|
AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
atk_class->initialize = st_label_accessible_initialize;
|
|
|
|
atk_class->get_name = st_label_accessible_get_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_label_accessible_init (StLabelAccessible *self)
|
|
|
|
{
|
|
|
|
/* initialization done on AtkObject->initialize */
|
|
|
|
}
|
|
|
|
|
2012-01-26 14:11:30 -05:00
|
|
|
static void
|
|
|
|
label_text_notify_cb (StLabel *label,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
AtkObject *accessible)
|
|
|
|
{
|
|
|
|
g_object_notify (G_OBJECT (accessible), "accessible-name");
|
|
|
|
}
|
|
|
|
|
2011-01-20 07:02:14 -05:00
|
|
|
static void
|
|
|
|
st_label_accessible_initialize (AtkObject *obj,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
ATK_OBJECT_CLASS (st_label_accessible_parent_class)->initialize (obj, data);
|
|
|
|
|
2012-01-26 14:11:30 -05:00
|
|
|
g_signal_connect (data, "notify::text",
|
|
|
|
G_CALLBACK (label_text_notify_cb),
|
|
|
|
obj);
|
|
|
|
|
2011-01-20 07:02:14 -05:00
|
|
|
obj->role = ATK_ROLE_LABEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
st_label_accessible_get_name (AtkObject *obj)
|
|
|
|
{
|
|
|
|
const gchar *name = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (ST_IS_LABEL_ACCESSIBLE (obj), NULL);
|
|
|
|
|
|
|
|
name = ATK_OBJECT_CLASS (st_label_accessible_parent_class)->get_name (obj);
|
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
ClutterActor *actor = NULL;
|
|
|
|
|
|
|
|
actor = CLUTTER_ACTOR (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (obj)));
|
|
|
|
|
|
|
|
if (actor == NULL) /* State is defunct */
|
|
|
|
name = NULL;
|
|
|
|
else
|
|
|
|
name = st_label_get_text (ST_LABEL (actor));
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|