texttag: add gtk_text_tag_changed()

The function is useful for a GtkTextTag subclass that adds new
properties.

https://bugzilla.gnome.org/show_bug.cgi?id=755416
This commit is contained in:
Sébastien Wilmet 2015-09-24 10:59:32 +02:00 committed by Matthias Clasen
parent cc2224cc62
commit 5a561a8ddb
4 changed files with 44 additions and 15 deletions

View File

@ -3809,6 +3809,7 @@ gtk_text_tag_new
gtk_text_tag_get_priority gtk_text_tag_get_priority
gtk_text_tag_set_priority gtk_text_tag_set_priority
gtk_text_tag_event gtk_text_tag_event
gtk_text_tag_changed
GtkTextAttributes GtkTextAttributes
GtkTextAppearance GtkTextAppearance
gtk_text_attributes_new gtk_text_attributes_new

View File

@ -1822,20 +1822,12 @@ gtk_text_tag_set_property (GObject *object,
break; break;
} }
/* FIXME I would like to do this after all set_property in a single /* The signal is emitted for each set_property(). A possible optimization is
* g_object_set () have been called. But an idle function won't * to send the signal only once when several properties are set at the same
* work; we need to emit when the tag is changed, not when we get * time with e.g. g_object_set(). The signal could be emitted when the notify
* around to the event loop. So blah, we eat some inefficiency. * signal is thawed.
*/ */
gtk_text_tag_changed (text_tag, size_changed);
/* This is also somewhat weird since we emit another object's
* signal here, but the two objects are already tightly bound.
*/
if (priv->table)
g_signal_emit_by_name (priv->table,
"tag_changed",
text_tag, size_changed);
} }
static void static void
@ -2294,6 +2286,40 @@ gtk_text_tag_event (GtkTextTag *tag,
return retval; return retval;
} }
/**
* gtk_text_tag_changed:
* @tag: a #GtkTextTag.
* @size_changed: whether the change affects the #GtkTextView layout.
*
* Emits the #GtkTextTagTable::tag-changed signal on the #GtkTextTagTable where
* the tag is included.
*
* The signal is already emitted when setting a #GtkTextTag property. This
* function is useful for a #GtkTextTag subclass.
*
* Since: 3.20
*/
void
gtk_text_tag_changed (GtkTextTag *tag,
gboolean size_changed)
{
GtkTextTagPrivate *priv;
g_return_if_fail (GTK_IS_TEXT_TAG (tag));
priv = tag->priv;
/* This is somewhat weird since we emit another object's signal here, but the
* two objects are already tightly bound. If a GtkTextTag::changed signal is
* added, this would increase significantly the number of signal connections.
*/
if (priv->table != NULL)
g_signal_emit_by_name (priv->table,
"tag-changed",
tag,
size_changed);
}
static int static int
tag_sort_func (gconstpointer first, gconstpointer second) tag_sort_func (gconstpointer first, gconstpointer second)
{ {

View File

@ -112,7 +112,9 @@ gboolean gtk_text_tag_event (GtkTextTag *tag,
GObject *event_object, GObject *event_object,
GdkEvent *event, GdkEvent *event,
const GtkTextIter *iter); const GtkTextIter *iter);
GDK_AVAILABLE_IN_3_20
void gtk_text_tag_changed (GtkTextTag *tag,
gboolean size_changed);
G_END_DECLS G_END_DECLS

View File

@ -103,7 +103,7 @@ gtk_text_tag_table_class_init (GtkTextTagTableClass *klass)
* GtkTextTagTable::tag-changed: * GtkTextTagTable::tag-changed:
* @texttagtable: the object which received the signal. * @texttagtable: the object which received the signal.
* @tag: the changed tag. * @tag: the changed tag.
* @size_changed: whether the size has been changed. * @size_changed: whether the change affects the #GtkTextView layout.
*/ */
signals[TAG_CHANGED] = signals[TAG_CHANGED] =
g_signal_new (I_("tag-changed"), g_signal_new (I_("tag-changed"),