/* Set focus to actor */ static void _xfdashboard_viewpad_focusable_set_focus(XfdashboardFocusable *inFocusable) { XfdashboardViewpad *self; XfdashboardViewpadPrivate *priv; XfdashboardFocusableInterface *selfIface; XfdashboardFocusableInterface *parentIface; g_return_if_fail(XFDASHBOARD_IS_FOCUSABLE(inFocusable)); g_return_if_fail(XFDASHBOARD_IS_VIEWPAD(inFocusable)); self=XFDASHBOARD_VIEWPAD(inFocusable); priv=self->priv; /* Viewpad is just a proxy for the current active view. * So check if current active view is focusable and call its * virtual function. */ if(priv->activeView && XFDASHBOARD_IS_FOCUSABLE(priv->activeView)) { /* Call virtual function of view to set focus */ xfdashboard_focusable_set_focus(XFDASHBOARD_FOCUSABLE(priv->activeView)); /* Call parent class interface function of this actor */ selfIface=XFDASHBOARD_FOCUSABLE_GET_IFACE(inFocusable); parentIface=g_type_interface_peek_parent(selfIface); if(parentIface && parentIface->set_focus) { parentIface->set_focus(inFocusable); } } }
/* Set focus to actor */ static void _xfdashboard_text_box_focusable_set_focus(XfdashboardFocusable *inFocusable) { XfdashboardTextBox *self; XfdashboardTextBoxPrivate *priv; XfdashboardFocusableInterface *selfIface; XfdashboardFocusableInterface *parentIface; ClutterStage *stage; g_return_if_fail(XFDASHBOARD_IS_FOCUSABLE(inFocusable)); g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(inFocusable)); self=XFDASHBOARD_TEXT_BOX(inFocusable); priv=self->priv; /* Call parent class interface function */ selfIface=XFDASHBOARD_FOCUSABLE_GET_IFACE(inFocusable); parentIface=g_type_interface_peek_parent(selfIface); if(parentIface && parentIface->set_focus) { parentIface->set_focus(inFocusable); } /* Get stage of actor to tell it where the keyboard focus to set to */ stage=CLUTTER_STAGE(clutter_actor_get_stage(CLUTTER_ACTOR(self))); if(!stage) { g_warning(_("Focusable actor %s is not on a stage"), G_OBJECT_TYPE_NAME(self)); return; } clutter_stage_set_key_focus(stage, CLUTTER_ACTOR(priv->actorTextBox)); }
/* Call virtual function "set_focus" */ void xfdashboard_focusable_set_focus(XfdashboardFocusable *self) { XfdashboardFocusableInterface *iface; ClutterActor *selection; g_return_if_fail(XFDASHBOARD_IS_FOCUSABLE(self)); iface=XFDASHBOARD_FOCUSABLE_GET_IFACE(self); /* Call virtual function */ if(iface->set_focus) { iface->set_focus(self); } /* Style newly focused actor */ if(XFDASHBOARD_IS_STYLABLE(self)) { xfdashboard_stylable_add_class(XFDASHBOARD_STYLABLE(self), "focus"); } /* If actor supports selection get current selection and style it */ if(xfdashboard_focusable_supports_selection(self)) { /* Get current selection. If no selection is available then select first item. */ selection=xfdashboard_focusable_get_selection(self); if(!selection) { selection=xfdashboard_focusable_find_selection(self, NULL, XFDASHBOARD_SELECTION_TARGET_FIRST); if(selection) xfdashboard_focusable_set_selection(self, selection); } /* Style selection if available */ if(selection && XFDASHBOARD_IS_STYLABLE(selection)) { xfdashboard_stylable_add_pseudo_class(XFDASHBOARD_STYLABLE(selection), "selected"); } g_debug("Set selection to %s for focused actor %s", G_OBJECT_TYPE_NAME(self), selection ? G_OBJECT_TYPE_NAME(selection) : "<nil>"); } /* Emit signal */ g_signal_emit(self, XfdashboardFocusableSignals[SIGNAL_FOCUS_GAINED], 0, self); g_debug("Emitted signal 'focus-gained' for focused actor %s", G_OBJECT_TYPE_NAME(self)); }