Permalink
Browse files

tile: Add primary/secondary-icon-clicked signals

Add signals for when the icons are clicked. I reconsidered doing anything
with this, so it's unused, but might come in handy later...
  • Loading branch information...
1 parent 7e4aa15 commit 1f9b4164a76f51e42b193259b27eb38fa4fbcfbf Chris Lord committed May 12, 2011
Showing with 132 additions and 24 deletions.
  1. +132 −24 mex/mex-tile.c
View
@@ -41,6 +41,14 @@ enum
PROP_IMPORTANT
};
+enum
+{
+ PRIMARY_ICON_CLICKED,
+ SECONDARY_ICON_CLICKED,
+
+ LAST_SIGNAL
+};
+
struct _MexTilePrivate
{
guint has_focus : 1;
@@ -56,6 +64,8 @@ struct _MexTilePrivate
ClutterAlpha *important_alpha;
};
+static guint signals[LAST_SIGNAL] = { 0, };
+
/* MxStylableIface */
@@ -155,11 +165,16 @@ mex_tile_set_property (GObject *object,
static void
mex_tile_dispose (GObject *object)
{
- MexTilePrivate *priv = MEX_TILE (object)->priv;
+ MexTile *self = MEX_TILE (object);
+ MexTilePrivate *priv = self->priv;
+
+ /* Use icon setting functions to disconnect from signal handlers */
+ mex_tile_set_primary_icon (self, NULL);
+ mex_tile_set_secondary_icon (self, NULL);
if (priv->table)
{
- /* Icons and label are in table, so no need to destroy them */
+ /* Label is in table, so no need to destroy it */
clutter_actor_unparent (priv->table);
priv->table = NULL;
}
@@ -469,6 +484,20 @@ mex_tile_class_init (MexTileClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_IMPORTANT, pspec);
+
+ signals[PRIMARY_ICON_CLICKED] = g_signal_new ("primary-icon-clicked",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[SECONDARY_ICON_CLICKED] = g_signal_new ("secondary-icon-clicked",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
static void
@@ -592,8 +621,52 @@ mex_tile_get_label (MexTile *tile)
return mx_label_get_text (MX_LABEL (tile->priv->label));
}
+static gboolean
+mex_tile_icon_button_release_cb (ClutterActor *icon,
+ ClutterButtonEvent *event,
+ MexTile *self)
+{
+ MexTilePrivate *priv = self->priv;
+
+ if (icon == priv->icon1)
+ g_signal_emit (self, signals[PRIMARY_ICON_CLICKED], 0);
+ else
+ g_signal_emit (self, signals[SECONDARY_ICON_CLICKED], 0);
+
+ return TRUE;
+}
+
+static gboolean
+mex_tile_icon_leave_event_cb (ClutterActor *icon,
+ ClutterCrossingEvent *event,
+ MexTile *self)
+{
+ g_signal_handlers_disconnect_by_func (icon,
+ mex_tile_icon_leave_event_cb,
+ self);
+ g_signal_handlers_disconnect_by_func (icon,
+ mex_tile_icon_button_release_cb,
+ self);
+
+ return FALSE;
+}
+
+static gboolean
+mex_tile_icon_button_press_cb (ClutterActor *icon,
+ ClutterButtonEvent *event,
+ MexTile *self)
+{
+ g_signal_connect (icon, "leave-event",
+ G_CALLBACK (mex_tile_icon_leave_event_cb), self);
+ g_signal_connect (icon, "button-release-event",
+ G_CALLBACK (mex_tile_icon_leave_event_cb), self);
+
+ return TRUE;
+}
+
void
-mex_tile_set_primary_icon (MexTile *tile, ClutterActor *icon)
+mex_tile_set_primary_icon (MexTile *tile,
+ ClutterActor *icon)
{
MexTilePrivate *priv;
@@ -604,17 +677,35 @@ mex_tile_set_primary_icon (MexTile *tile, ClutterActor *icon)
if (priv->icon1 != icon)
{
if (priv->icon1)
- clutter_container_remove_actor (CLUTTER_CONTAINER (priv->table),
- priv->icon1);
+ {
+ g_signal_handlers_disconnect_by_func (priv->icon1,
+ mex_tile_icon_button_press_cb,
+ tile);
+ g_signal_handlers_disconnect_by_func (priv->icon1,
+ mex_tile_icon_leave_event_cb,
+ tile);
+ g_signal_handlers_disconnect_by_func (priv->icon1,
+ mex_tile_icon_button_release_cb,
+ tile);
+ clutter_container_remove_actor (CLUTTER_CONTAINER (priv->table),
+ priv->icon1);
+ }
+
if (icon)
- mx_table_add_actor_with_properties (MX_TABLE (priv->table),
- icon, 0, 0,
- "x-expand", FALSE,
- "y-expand", FALSE,
- "x-fill", FALSE,
- "y-fill", FALSE,
- "x-align", MX_ALIGN_START,
- NULL);
+ {
+ mx_table_add_actor_with_properties (MX_TABLE (priv->table),
+ icon, 0, 0,
+ "x-expand", FALSE,
+ "y-expand", FALSE,
+ "x-fill", FALSE,
+ "y-fill", FALSE,
+ "x-align", MX_ALIGN_START,
+ NULL);
+
+ clutter_actor_set_reactive (icon, TRUE);
+ g_signal_connect (icon, "button-press-event",
+ G_CALLBACK (mex_tile_icon_button_press_cb), tile);
+ }
priv->icon1 = icon;
@@ -630,7 +721,8 @@ mex_tile_get_primary_icon (MexTile *tile)
}
void
-mex_tile_set_secondary_icon (MexTile *tile, ClutterActor *icon)
+mex_tile_set_secondary_icon (MexTile *tile,
+ ClutterActor *icon)
{
MexTilePrivate *priv;
@@ -641,17 +733,33 @@ mex_tile_set_secondary_icon (MexTile *tile, ClutterActor *icon)
if (priv->icon2 != icon)
{
if (priv->icon2)
- clutter_container_remove_actor (CLUTTER_CONTAINER (priv->table),
- priv->icon2);
+ {
+ g_signal_handlers_disconnect_by_func (priv->icon2,
+ mex_tile_icon_button_press_cb,
+ tile);
+ g_signal_handlers_disconnect_by_func (priv->icon2,
+ mex_tile_icon_leave_event_cb,
+ tile);
+ g_signal_handlers_disconnect_by_func (priv->icon2,
+ mex_tile_icon_button_release_cb,
+ tile);
+ clutter_container_remove_actor (CLUTTER_CONTAINER (priv->table),
+ priv->icon2);
+ }
+
if (icon)
- mx_table_add_actor_with_properties (MX_TABLE (priv->table),
- icon, 0, 2,
- "x-expand", FALSE,
- "y-expand", FALSE,
- "x-fill", FALSE,
- "y-fill", FALSE,
- "x-align", MX_ALIGN_END,
- NULL);
+ {
+ mx_table_add_actor_with_properties (MX_TABLE (priv->table),
+ icon, 0, 2,
+ "x-expand", FALSE,
+ "y-expand", FALSE,
+ "x-fill", FALSE,
+ "y-fill", FALSE,
+ "x-align", MX_ALIGN_END,
+ NULL);
+ g_signal_connect (icon, "button-press-event",
+ G_CALLBACK (mex_tile_icon_button_press_cb), tile);
+ }
priv->icon2 = icon;

0 comments on commit 1f9b416

Please sign in to comment.